2009-03-02 23:14:15 +00:00
http://sourceware.org/gdb/wiki/ProjectArcher
http://sourceware.org/gdb/wiki/ArcherBranchManagement
GIT snapshot:
2013-05-21 11:54:33 +00:00
commit b1f8c6821303f6eb087fb7f57405483ac8812227
2009-03-02 23:14:15 +00:00
2013-03-10 16:12:43 +00:00
branch jankratochvil/fedora19 - the merge of branches:
jankratochvil/vla
tromey/python
2009-03-02 23:14:15 +00:00
2013-03-10 16:12:43 +00:00
diff --git a/README.archer b/README.archer
new file mode 100644
index 0000000..1f7ab48
--- /dev/null
+++ b/README.archer
@@ -0,0 +1,13 @@
+Merge for Fedora 19: http://pkgs.fedoraproject.org/cgit/gdb.git/
+
+jankratochvil/vla
+tromey/python
+
+================================================================
+This branch originally held the Python code for gdb. It still exists
+because a small amount of code here has not yet been merged upstream.
+
+================================================================
+C variable length arrays / DW_FORM_block / Fortran dynamic arrays.
+implementation plan: http://sourceware.org/ml/gdb/2012-11/msg00094.html
+explanation of its merge status: http://sourceware.org/ml/gdb/2011-03/msg00021.html
2012-01-03 15:00:12 +00:00
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
2013-02-18 17:14:00 +00:00
index ed30db5..4356be7 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
2013-02-18 17:14:00 +00:00
@@ -1313,6 +1313,12 @@ stamp-h: $(srcdir)/config.in config.status
2011-01-07 08:47:27 +00:00
CONFIG_LINKS= \
$(SHELL) config.status
+.gdbinit: $(srcdir)/gdbinit.in config.status
+ CONFIG_FILES=".gdbinit:gdbinit.in" \
+ CONFIG_COMMANDS= \
+ CONFIG_HEADERS= \
+ $(SHELL) config.status
+
config.status: $(srcdir)/configure configure.tgt configure.host
$(SHELL) config.status --recheck
2012-01-03 15:00:12 +00:00
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
2013-03-10 16:12:43 +00:00
index 75f1c3d..6243818 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
2013-03-10 16:12:43 +00:00
@@ -12287,6 +12287,7 @@ ada_operator_length (const struct expression *exp, int pc, int *oplenp,
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
static int
ada_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)
2010-01-21 16:09:11 +00:00
{
2013-03-10 16:12:43 +00:00
@@ -12301,12 +12302,15 @@ ada_operator_check (struct expression *exp, int pos,
2010-07-21 21:30:20 +00:00
break;
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
default:
- return operator_check_standard (exp, pos, objfile_func, data);
2009-08-04 05:37:29 +00:00
+ return operator_check_standard (exp, pos, type_func, objfile_func,
+ data);
2010-07-21 21:30:20 +00:00
}
/* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
- if (type && TYPE_OBJFILE (type)
2009-08-04 05:37:29 +00:00
+ if (type && type_func && (*type_func) (type, data))
+ return 1;
+ if (type && TYPE_OBJFILE (type) && objfile_func
2010-07-21 21:30:20 +00:00
&& (*objfile_func) (TYPE_OBJFILE (type), data))
return 1;
2010-01-28 22:26:15 +00:00
2012-01-03 15:00:12 +00:00
diff --git a/gdb/block.c b/gdb/block.c
2013-01-19 22:41:55 +00:00
index 2638de8..b296ae0 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/block.c
+++ b/gdb/block.c
2012-07-03 18:54:05 +00:00
@@ -692,3 +692,21 @@ block_iter_match_next (const char *name,
2009-06-10 13:05:57 +00:00
2012-06-03 17:40:44 +00:00
return block_iter_match_step (iterator, name, compare, 0);
2009-06-10 13:05:57 +00:00
}
2009-08-04 05:37:29 +00:00
+
+/* Return OBJFILE in which BLOCK is located or NULL if we cannot find it for
+ whatever reason. */
+
+struct objfile *
+block_objfile (const struct block *block)
+{
+ struct symbol *func;
+
+ if (block == NULL)
+ return NULL;
+
+ func = block_linkage_function (block);
+ if (func == NULL)
+ return NULL;
+
+ return SYMBOL_SYMTAB (func)->objfile;
+}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/block.h b/gdb/block.h
2013-01-19 22:41:55 +00:00
index 02e7e8b..2931401 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/block.h
+++ b/gdb/block.h
2012-06-03 17:40:44 +00:00
@@ -279,4 +279,6 @@ extern struct symbol *block_iter_match_next (const char *name,
(sym); \
(sym) = block_iterator_next (&(iter)))
2009-06-10 13:05:57 +00:00
2009-08-04 05:37:29 +00:00
+extern struct objfile *block_objfile (const struct block *block);
+
#endif /* BLOCK_H */
2012-01-03 15:00:12 +00:00
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
2013-03-10 16:12:43 +00:00
index d6f8bc5..8a14224 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
2013-03-10 16:12:43 +00:00
@@ -15653,6 +15653,24 @@ all_tracepoints (void)
2010-01-16 22:32:10 +00:00
return tp_vec;
2009-09-10 21:37:41 +00:00
}
2011-03-05 12:24:53 +00:00
+#if 0
2010-01-16 22:32:10 +00:00
+/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
2009-09-10 21:37:41 +00:00
+
+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));
+ }
+}
2011-03-05 12:24:53 +00:00
+#endif
2009-09-10 21:37:41 +00:00
+
2011-01-01 00:27:30 +00:00
/* This help string is used for the break, hbreak, tbreak and thbreak
commands. It is defined as a macro to prevent duplication.
2013-03-10 16:12:43 +00:00
@@ -16636,4 +16654,7 @@ agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
2009-09-10 21:37:41 +00:00
automatic_hardware_breakpoints = 1;
observer_attach_about_to_proceed (breakpoint_about_to_proceed);
2011-03-05 12:24:53 +00:00
+#if 0
2009-09-10 21:37:41 +00:00
+ observer_attach_mark_used (breakpoint_types_mark_used);
2011-03-05 12:24:53 +00:00
+#endif
2009-09-10 21:37:41 +00:00
}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
2013-02-18 17:14:00 +00:00
index ca8d89b..811ad72 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
2013-02-18 17:14:00 +00:00
@@ -689,7 +689,13 @@ c_type_print_varspec_suffix (struct type *type,
2010-07-22 10:49:58 +00:00
2013-01-19 22:41:55 +00:00
fprintf_filtered (stream, (is_vector ?
" __attribute__ ((vector_size(" : "["));
2010-11-17 02:58:16 +00:00
- if (get_array_bounds (type, &low_bound, &high_bound))
+ 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))
2013-01-19 22:41:55 +00:00
fprintf_filtered (stream, "%s",
plongest (high_bound - low_bound + 1));
fprintf_filtered (stream, (is_vector ? ")))" : "]"));
2012-01-03 15:00:12 +00:00
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
2013-05-21 11:54:33 +00:00
index d98ac77..f6a4b99 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
2013-05-21 11:54:33 +00:00
@@ -53,16 +53,21 @@ PYTHON_DIR = python
2011-01-07 08:47:27 +00:00
PYTHON_INSTALL_DIR = $(DESTDIR)$(GDB_DATADIR)/$(PYTHON_DIR)
PYTHON_FILES = \
gdb/__init__.py \
- gdb/types.py \
- gdb/printing.py \
2012-01-03 15:00:12 +00:00
- gdb/prompt.py \
2011-01-07 08:47:27 +00:00
gdb/command/__init__.py \
+ gdb/command/ignore_errors.py \
+ gdb/command/pahole.py \
2013-01-19 22:41:55 +00:00
gdb/command/type_printers.py \
2012-01-03 15:00:12 +00:00
gdb/command/pretty_printers.py \
2012-06-03 17:40:44 +00:00
gdb/command/prompt.py \
2013-01-19 22:41:55 +00:00
gdb/command/explore.py \
gdb/function/__init__.py \
- gdb/function/strfns.py
+ gdb/function/strfns.py \
2011-01-07 08:47:27 +00:00
+ gdb/function/__init__.py \
+ gdb/function/caller_is.py \
+ gdb/function/in_scope.py \
+ gdb/printing.py \
2012-01-03 15:00:12 +00:00
+ gdb/prompt.py \
2011-01-07 08:47:27 +00:00
+ gdb/types.py
FLAGS_TO_PASS = \
"prefix=$(prefix)" \
2012-01-03 15:00:12 +00:00
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
2013-03-10 16:12:43 +00:00
index a607166..6913628 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
2013-03-10 16:12:43 +00:00
@@ -1216,6 +1216,16 @@ for remote debugging.
2011-01-07 08:47:27 +00:00
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}
2013-03-10 16:12:43 +00:00
@@ -22804,8 +22814,6 @@ containing @code{end}. For example:
2011-01-07 08:47:27 +00:00
@smallexample
(@value{GDBP}) python
-Type python script
-End with a line saying just "end".
>print 23
>end
23
2013-03-10 16:12:43 +00:00
@@ -22819,6 +22827,14 @@ controlled using @code{set python print-stack}: if @code{full}, then
2012-01-03 15:00:12 +00:00
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.
2011-01-07 08:47:27 +00:00
+
+@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}
2013-03-10 16:12:43 +00:00
@@ -22840,6 +22856,14 @@ and thus is always available.
2011-01-07 08:47:27 +00:00
@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)}}.
+
+Functions and methods which have two or more optional arguments allow
+them to be specified using keyword syntax. This allows passing some
+optional arguments while skipping others. Example:
+@w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
+
@cindex python stdout
@cindex python pagination
At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
2012-01-03 15:00:12 +00:00
diff --git a/gdb/doc/gdbint.texinfo b/gdb/doc/gdbint.texinfo
2013-01-19 22:41:55 +00:00
index 4a75c26..91446fe 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/doc/gdbint.texinfo
+++ b/gdb/doc/gdbint.texinfo
2013-01-19 22:41:55 +00:00
@@ -2101,6 +2101,18 @@ time, and so we attempt to handle symbols incrementally. For instance,
2010-07-21 21:30:20 +00:00
we create @dfn{partial symbol tables} consisting of only selected
symbols, and only expand them to full symbol tables when necessary.
+@menu
+* Symbol Reading::
+* Partial Symbol Tables::
+* Types::
+* Object File Formats::
+* Debugging File Formats::
+* Adding a New Symbol Reader to GDB::
+* Memory Management for Symbol Files::
+* Memory Management for Types::
+@end menu
2009-08-04 05:37:29 +00:00
+
2010-07-21 21:30:20 +00:00
+@node Symbol Reading
@section Symbol Reading
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
@cindex symbol reading
2013-01-19 22:41:55 +00:00
@@ -2193,6 +2205,7 @@ symtab. Upon return, @code{pst->readin} should have been set to 1, and
2010-07-21 21:30:20 +00:00
zero if there were no symbols in that part of the symbol file.
@end table
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
+@node Partial Symbol Tables
@section Partial Symbol Tables
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
@value{GDBN} has three types of symbol tables:
2013-01-19 22:41:55 +00:00
@@ -2294,6 +2307,7 @@ and partial symbol tables behind a set of function pointers known as
2010-07-21 21:30:20 +00:00
the @dfn{quick symbol functions}. These are documented in
@file{symfile.h}.
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
+@node Types
@section Types
2009-03-02 00:11:35 +00:00
2010-07-21 21:30:20 +00:00
@unnumberedsubsec Fundamental Types (e.g., @code{FT_VOID}, @code{FT_BOOLEAN}).
2013-01-19 22:41:55 +00:00
@@ -2316,6 +2330,7 @@ types map to one @code{TYPE_CODE_*} type, and are distinguished by
2010-07-21 21:30:20 +00:00
other members of the type struct, such as whether the type is signed
or unsigned, and how many bits it uses.
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
+@anchor{Builtin Types}
@unnumberedsubsec Builtin Types (e.g., @code{builtin_type_void}, @code{builtin_type_char}).
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
These are instances of type structs that roughly correspond to
2013-01-19 22:41:55 +00:00
@@ -2330,6 +2345,7 @@ only one instance exists, while @file{c-lang.c} builds as many
2010-07-21 21:30:20 +00:00
@code{TYPE_CODE_INT} types as needed, with each one associated with
some particular objfile.
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
+@node Object File Formats
@section Object File Formats
@cindex object file formats
2010-01-21 16:09:11 +00:00
2013-01-19 22:41:55 +00:00
@@ -2415,6 +2431,7 @@ SOM, which is a cross-language ABI).
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
The SOM reader is in @file{somread.c}.
2010-07-11 18:06:33 +00:00
2010-07-21 21:30:20 +00:00
+@node Debugging File Formats
@section Debugging File Formats
2010-07-11 18:06:33 +00:00
2010-07-21 21:30:20 +00:00
This section describes characteristics of debugging information that
2013-01-19 22:41:55 +00:00
@@ -2486,6 +2503,7 @@ DWARF 3 is an improved version of DWARF 2.
2010-07-21 21:30:20 +00:00
@cindex SOM debugging info
Like COFF, the SOM definition includes debugging information.
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
+@node Adding a New Symbol Reader to GDB
@section Adding a New Symbol Reader to @value{GDBN}
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
@cindex adding debugging info reader
2013-01-19 22:41:55 +00:00
@@ -2508,6 +2526,7 @@ will only ever be implemented by one object file format may be called
2010-07-21 21:30:20 +00:00
directly. This interface should be described in a file
@file{bfd/lib@var{xyz}.h}, which is included by @value{GDBN}.
+@node Memory Management for Symbol Files
@section Memory Management for Symbol Files
Most memory associated with a loaded symbol file is stored on
2013-01-19 22:41:55 +00:00
@@ -2519,10 +2538,45 @@ released when the objfile is unloaded or reloaded. Therefore one
2010-07-21 21:30:20 +00:00
objfile must not reference symbol or type data from another objfile;
they could be unloaded at different times.
-User convenience variables, et cetera, have associated types. Normally
-these types live in the associated objfile. However, when the objfile
-is unloaded, those types are deep copied to global memory, so that
-the values of the user variables and history items are not lost.
+@node Memory Management for Types
+@section Memory Management for Types
+@cindex memory management for types
2010-01-28 22:26:15 +00:00
+
2010-07-21 21:30:20 +00:00
+@findex TYPE_OBJFILE
+@code{TYPE_OBJFILE} macro indicates the current memory owner of the type.
+Non-@code{NULL} value indicates it is owned by an objfile (specifically by its
+obstack) and in such case the type remains valid till the objfile is unloaded
+or reloaded. For such types with an associated objfile no reference counting
+is being made.
2010-01-28 22:26:15 +00:00
+
2010-07-21 21:30:20 +00:00
+User convenience variables, et cetera, have associated types. Normally these
+types live in the associated objfile. However, when the objfile is unloaded,
+those types are deep copied to global memory, so that the values of the user
+variables and history items are not lost. During the copy they will get their
+@code{TYPE_OBJFILE} set to @code{NULL} and become so-called @dfn{reclaimable}
+types.
2010-01-28 22:26:15 +00:00
+
2010-07-21 21:30:20 +00:00
+Types with null @code{TYPE_OBJFILE} can be either permanent types
+(@pxref{Builtin Types}) or reclaimable types which will be deallocated at the
+first idle @value{GDBN} moment if the last object referencing them is removed.
+Permanent types are allocated by the function @code{alloc_type} (and its
+derivations like @code{init_type}) specifying objfile as @code{NULL}. The
+reclaimable types are created the same way but moreover they need to have
+@code{type_init_group} called to start their tracking as being possibly
+deallocatable.
2010-01-28 22:26:15 +00:00
+
2010-07-21 21:30:20 +00:00
+@findex free_all_types
+When @value{GDBN} gets idle it always calls the @code{free_all_types} function
+which deallocates any unused types. All types currently not owned by an
+objfile must be marked as used on each @code{free_all_types} call as they would
+get deallocated as unused otherwise.
2010-01-28 22:26:15 +00:00
+
2010-07-21 21:30:20 +00:00
+@code{free_all_types} automatically checks for any cross-type references such
+as through @code{TYPE_TARGET_TYPE}, @code{TYPE_POINTER_TYPE} etc.@: and
+prevents early deallocation for any such existing references. Reclaimable
+types may reference any other reclaimable types or even permanent types. But
+permanent types must not reference reclaimable types (nor an objfile associated
+type).
2010-01-21 16:09:11 +00:00
2010-01-28 22:26:15 +00:00
2010-07-21 21:30:20 +00:00
@node Language Support
2012-01-03 15:00:12 +00:00
diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi
2013-02-18 17:14:00 +00:00
index adb7085..5ec5b5a 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/doc/observer.texi
+++ b/gdb/doc/observer.texi
2013-02-18 17:14:00 +00:00
@@ -249,6 +249,11 @@ The trace state variable @var{tsv} is deleted. If @var{tsv} is
The trace state value @var{tsv} is modified.
2010-07-21 21:30:20 +00:00
@end deftypefun
2010-01-28 22:26:15 +00:00
2011-03-05 12:24:53 +00:00
+@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
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
@deftypefun void test_notification (int @var{somearg})
This observer is used for internal testing. Do not use.
See testsuite/gdb.gdb/observer.exp.
2012-01-03 15:00:12 +00:00
diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2expr.c
2013-01-19 22:41:55 +00:00
index 752d782..ab0a3eb 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2expr.c
2013-01-19 22:41:55 +00:00
@@ -1479,6 +1479,14 @@ execute_stack_op (struct dwarf_expr_context *ctx,
2011-07-22 22:41:56 +00:00
}
break;
2010-07-21 21:30:20 +00:00
+ case DW_OP_push_object_address:
2011-07-22 22:41:56 +00:00
+ if (ctx->funcs->get_object_address == NULL)
2010-07-21 21:30:20 +00:00
+ error (_("DWARF-2 expression error: DW_OP_push_object_address must "
+ "have a value to push."));
2011-07-22 22:41:56 +00:00
+ result = (ctx->funcs->get_object_address) (ctx->baton);
+ result_val = value_from_ulongest (address_type, result);
2010-07-21 21:30:20 +00:00
+ break;
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
default:
error (_("Unhandled dwarf expression opcode 0x%x"), op);
2010-01-21 16:09:11 +00:00
}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2expr.h
2013-01-19 22:41:55 +00:00
index e85486a..e7ac799 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/dwarf2expr.h
+++ b/gdb/dwarf2expr.h
2013-01-19 22:41:55 +00:00
@@ -77,12 +77,8 @@ struct dwarf_expr_context_funcs
2012-06-03 17:40:44 +00:00
This can throw an exception if the index is out of range. */
CORE_ADDR (*get_addr_index) (void *baton, unsigned int index);
2011-07-22 22:41:56 +00:00
-#if 0
2012-06-03 17:40:44 +00:00
- /* Not yet implemented. */
-
2010-07-21 21:30:20 +00:00
/* Return the `object address' for DW_OP_push_object_address. */
CORE_ADDR (*get_object_address) (void *baton);
-#endif
2011-07-22 22:41:56 +00:00
};
2010-01-21 16:09:11 +00:00
2011-07-22 22:41:56 +00:00
/* The location of a value. */
2012-01-03 15:00:12 +00:00
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
2013-03-10 16:12:43 +00:00
index 8a61ae6..451a759 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
2013-02-18 17:14:00 +00:00
@@ -298,6 +298,9 @@ struct dwarf_expr_baton
2010-01-21 16:09:11 +00:00
{
2010-07-21 21:30:20 +00:00
struct frame_info *frame;
struct dwarf2_per_cu_data *per_cu;
+ /* From DW_TAG_variable's DW_AT_location (not DW_TAG_type's
+ DW_AT_data_location) for DW_OP_push_object_address. */
+ CORE_ADDR object_address;
};
2010-01-21 16:09:11 +00:00
2010-07-21 21:30:20 +00:00
/* Helper functions for dwarf2_evaluate_loc_desc. */
2013-02-18 17:14:00 +00:00
@@ -361,16 +364,14 @@ static void
2012-01-03 15:00:12 +00:00
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;
2010-07-21 21:30:20 +00:00
symbaton = SYMBOL_LOCATION_BATON (framefunc);
2011-01-01 00:27:30 +00:00
*start = dwarf2_find_location_expression (symbaton, length, pc);
2010-01-21 16:09:11 +00:00
}
2010-07-21 21:30:20 +00:00
- else
+ else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_locexpr_funcs)
2010-01-21 16:09:11 +00:00
{
2010-07-21 21:30:20 +00:00
struct dwarf2_locexpr_baton *symbaton;
2010-01-21 16:09:11 +00:00
2013-02-18 17:14:00 +00:00
@@ -383,10 +384,23 @@ dwarf_expr_frame_base_1 (struct symbol *framefunc, CORE_ADDR pc,
2012-01-03 15:00:12 +00:00
else
*length = 0;
2011-07-22 22:41:56 +00:00
}
2010-07-21 21:30:20 +00:00
+ else if (SYMBOL_COMPUTED_OPS (framefunc) == &dwarf2_missing_funcs)
+ {
+ struct dwarf2_locexpr_baton *symbaton;
+
+ symbaton = SYMBOL_LOCATION_BATON (framefunc);
+ gdb_assert (symbaton == NULL);
2012-01-03 15:00:12 +00:00
+ *length = 0;
2011-07-22 22:41:56 +00:00
+ }
2010-07-21 21:30:20 +00:00
+ else
+ internal_error (__FILE__, __LINE__,
+ _("Unsupported SYMBOL_COMPUTED_OPS %p for \"%s\""),
+ SYMBOL_COMPUTED_OPS (framefunc),
+ SYMBOL_PRINT_NAME (framefunc));
2010-01-21 16:09:11 +00:00
2012-01-03 15:00:12 +00:00
if (*length == 0)
2010-07-21 21:30:20 +00:00
error (_("Could not find the frame base for \"%s\"."),
- SYMBOL_NATURAL_NAME (framefunc));
+ SYMBOL_PRINT_NAME (framefunc));
2010-01-21 16:09:11 +00:00
}
2010-07-21 21:30:20 +00:00
/* Helper function for dwarf2_evaluate_loc_desc. Computes the CFA for
2013-02-18 17:14:00 +00:00
@@ -453,6 +467,85 @@ dwarf_expr_dwarf_call (struct dwarf_expr_context *ctx, cu_offset die_offset)
2011-07-22 22:41:56 +00:00
ctx->funcs->get_frame_pc, ctx->baton);
2010-07-11 18:06:33 +00:00
}
2010-07-21 21:30:20 +00:00
+static CORE_ADDR
+dwarf_expr_object_address (void *baton)
+{
+ struct dwarf_expr_baton *debaton = baton;
+
+ /* The message is suppressed in DWARF_BLOCK_EXEC. */
+ if (debaton->object_address == 0)
+ error (_("Cannot resolve DW_OP_push_object_address for a missing object"));
+
+ return debaton->object_address;
+}
+
+/* Address of the variable we are currently referring to. It is set from
+ DW_TAG_variable's DW_AT_location (not DW_TAG_type's DW_AT_data_location) for
+ DW_OP_push_object_address. */
+
+static CORE_ADDR object_address;
+
+/* Callers use object_address_set while their callers use the result set so we
+ cannot run the cleanup at the local block of our direct caller. Still we
+ should reset OBJECT_ADDRESS at least for the next GDB command. */
2010-07-11 18:06:33 +00:00
+
+static void
2010-07-21 21:30:20 +00:00
+object_address_cleanup (void *prev_save_voidp)
2010-07-11 18:06:33 +00:00
+{
2010-07-21 21:30:20 +00:00
+ CORE_ADDR *prev_save = prev_save_voidp;
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
+ object_address = *prev_save;
+ xfree (prev_save);
+}
+
+/* Set the base address - DW_AT_location - of a variable. It is being later
+ used to derive other object addresses by DW_OP_push_object_address.
+
+ It would be useful to sanity check ADDRESS - such as for some objects with
+ unset value_raw_address - but some valid addresses may be zero (such as first
+ objects in relocatable .o files). */
+
+void
+object_address_set (CORE_ADDR address)
+{
+ CORE_ADDR *prev_save;
+
+ prev_save = xmalloc (sizeof *prev_save);
+ *prev_save = object_address;
+ make_cleanup (object_address_cleanup, prev_save);
+
+ object_address = address;
2010-07-11 18:06:33 +00:00
+}
+
2011-07-22 22:41:56 +00:00
+/* 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 *
2013-03-10 16:12:43 +00:00
@@ -1156,10 +1249,12 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
2012-01-03 15:00:12 +00:00
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;
2013-03-10 16:12:43 +00:00
@@ -1167,10 +1262,95 @@ dwarf_expr_push_dwarf_reg_entry_value (struct dwarf_expr_context *ctx,
2012-01-03 15:00:12 +00:00
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;
2011-07-22 22:41:56 +00:00
}
2012-06-03 17:40:44 +00:00
+static CORE_ADDR dwarf_expr_get_addr_index (void *baton, unsigned int index);
+
2011-07-22 22:41:56 +00:00
+/* 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,
2012-01-03 15:00:12 +00:00
+ dwarf_expr_push_dwarf_reg_entry_value,
2012-06-03 17:40:44 +00:00
+ dwarf_expr_get_addr_index,
2011-07-22 22:41:56 +00:00
+ dwarf_expr_object_address
+};
+
2010-07-21 21:30:20 +00:00
+/* 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. */
+
2011-07-22 22:41:56 +00:00
+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)
2010-07-11 18:06:33 +00:00
+{
2010-07-21 21:30:20 +00:00
+ struct dwarf_expr_baton baton;
+ struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2011-03-20 20:44:20 +00:00
+ volatile struct gdb_exception ex;
2010-07-21 21:30:20 +00:00
+
+ baton.frame = frame;
+ baton.per_cu = per_cu;
+ baton.object_address = object_address;
+
+ ctx->gdbarch = get_objfile_arch (objfile);
+ ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2012-01-03 15:00:12 +00:00
+ ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
2010-07-21 21:30:20 +00:00
+ ctx->offset = dwarf2_per_cu_text_offset (per_cu);
+ ctx->baton = &baton;
2011-07-22 22:41:56 +00:00
+ ctx->funcs = &dwarf_expr_ctx_funcs;
2010-07-11 18:06:33 +00:00
+
2011-07-22 22:41:56 +00:00
+ dwarf_expr_eval (ctx, data, size);
2010-07-21 21:30:20 +00:00
+}
+
+/* Evaluate DWARF expression at DLBATON expecting it produces exactly one
+ CORE_ADDR result on the DWARF stack stack. */
+
+CORE_ADDR
+dwarf_locexpr_baton_eval (struct dwarf2_locexpr_baton *dlbaton)
+{
+ struct dwarf_expr_context *ctx;
+ CORE_ADDR retval;
2011-07-22 22:41:56 +00:00
+ 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);
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
+ if (ctx->num_pieces > 0)
+ error (_("DW_OP_*piece is unsupported for DW_FORM_block"));
2010-07-11 18:06:33 +00:00
+
2011-07-22 22:41:56 +00:00
+ retval = dwarf_expr_fetch_address (ctx, 0);
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
+ if (ctx->location == DWARF_VALUE_REGISTER)
2010-07-11 18:06:33 +00:00
+ {
2010-07-21 21:30:20 +00:00
+ /* Inlined dwarf_expr_read_reg as we no longer have the baton. */
+
+ int gdb_regnum = gdbarch_dwarf2_reg_to_regnum (ctx->gdbarch, retval);
+ struct type *type = builtin_type (ctx->gdbarch)->builtin_data_ptr;
+ struct frame_info *frame = get_selected_frame (NULL);
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
+ retval = address_from_register (type, gdb_regnum, frame);
2010-07-11 18:06:33 +00:00
+ }
+
2010-07-21 21:30:20 +00:00
+ do_cleanups (back_to);
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
+ return retval;
2010-07-11 18:06:33 +00:00
+}
2010-07-21 21:30:20 +00:00
+
2012-06-03 17:40:44 +00:00
/* Callback function for dwarf2_evaluate_loc_desc.
Fetch the address indexed by DW_OP_GNU_addr_index. */
2013-03-10 16:12:43 +00:00
@@ -2106,22 +2286,6 @@ invalid_synthetic_pointer (void)
2011-07-22 22:41:56 +00:00
"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,
2012-01-03 15:00:12 +00:00
- dwarf_expr_get_base_type,
2012-06-03 17:40:44 +00:00
- dwarf_expr_push_dwarf_reg_entry_value,
- dwarf_expr_get_addr_index
2011-07-22 22:41:56 +00:00
-};
-
/* 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
2013-03-10 16:12:43 +00:00
@@ -2134,7 +2298,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
2011-01-01 00:27:30 +00:00
LONGEST byte_offset)
2010-07-21 21:30:20 +00:00
{
struct value *retval;
- struct dwarf_expr_baton baton;
struct dwarf_expr_context *ctx;
2011-07-22 22:41:56 +00:00
struct cleanup *old_chain, *value_chain;
2012-01-03 15:00:12 +00:00
struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
2013-03-10 16:12:43 +00:00
@@ -2146,29 +2309,18 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
2011-07-22 22:41:56 +00:00
if (size == 0)
return allocate_optimized_out_value (type);
2010-07-11 18:06:33 +00:00
2010-07-21 21:30:20 +00:00
- baton.frame = frame;
- baton.per_cu = per_cu;
2011-03-20 20:44:20 +00:00
-
2011-07-22 22:41:56 +00:00
ctx = new_dwarf_expr_context ();
old_chain = make_cleanup_free_dwarf_expr_context (ctx);
value_chain = make_cleanup_value_free_to_mark (value_mark ());
2010-07-21 21:30:20 +00:00
- ctx->gdbarch = get_objfile_arch (objfile);
- ctx->addr_size = dwarf2_per_cu_addr_size (per_cu);
2012-01-03 15:00:12 +00:00
- ctx->ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
2010-07-21 21:30:20 +00:00
- ctx->offset = dwarf2_per_cu_text_offset (per_cu);
- ctx->baton = &baton;
2011-07-22 22:41:56 +00:00
- ctx->funcs = &dwarf_expr_ctx_funcs;
-
TRY_CATCH (ex, RETURN_MASK_ERROR)
2011-03-20 20:44:20 +00:00
{
2011-07-22 22:41:56 +00:00
- dwarf_expr_eval (ctx, data, size);
+ dwarf_expr_prep_ctx (ctx, frame, data, size, per_cu);
2011-03-20 20:44:20 +00:00
}
2011-07-22 22:41:56 +00:00
if (ex.reason < 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;
2013-03-10 16:12:43 +00:00
@@ -2232,6 +2384,16 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
2010-07-21 21:30:20 +00:00
int in_stack_memory = dwarf_expr_fetch_in_stack_memory (ctx, 0);
2009-08-04 05:37:29 +00:00
2011-07-22 22:41:56 +00:00
do_cleanups (value_chain);
+
2011-01-01 00:27:30 +00:00
+ /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */
+ make_cleanup_restore_selected_frame ();
+ select_frame (frame);
+
2010-07-21 21:30:20 +00:00
+ /* 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);
2009-08-04 05:37:29 +00:00
+
2011-01-17 15:31:43 +00:00
retval = allocate_value_lazy (type);
2010-07-21 21:30:20 +00:00
VALUE_LVAL (retval) = lval_memory;
2011-01-17 15:31:43 +00:00
if (in_stack_memory)
2013-03-10 16:12:43 +00:00
@@ -4148,8 +4310,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
2011-02-18 10:25:34 +00:00
dlbaton->per_cu);
2010-07-21 21:30:20 +00:00
}
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
-/* The set of location functions used with the DWARF-2 expression
- evaluator and location lists. */
+/* The set of location functions used with the DWARF-2 location lists. */
const struct symbol_computed_ops dwarf2_loclist_funcs = {
loclist_read_variable,
2012-01-03 15:00:12 +00:00
loclist_read_variable_at_entry,
2013-03-10 16:12:43 +00:00
@@ -4158,6 +4319,48 @@ const struct symbol_computed_ops dwarf2_loclist_funcs = {
2010-07-21 21:30:20 +00:00
loclist_tracepoint_var_ref
};
2012-01-03 15:00:12 +00:00
2010-07-21 21:30:20 +00:00
+static struct value *
+missing_read_variable (struct symbol *symbol, struct frame_info *frame)
+{
+ struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
+
+ gdb_assert (dlbaton == NULL);
+ error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
+}
+
+static int
+missing_read_needs_frame (struct symbol *symbol)
+{
+ return 0;
+}
+
+static void
+missing_describe_location (struct symbol *symbol, CORE_ADDR addr,
+ struct ui_file *stream)
+{
+ fprintf_filtered (stream, _("a variable we are unable to resolve"));
+}
+
+static void
+missing_tracepoint_var_ref (struct symbol *symbol, struct gdbarch *gdbarch,
+ struct agent_expr *ax, struct axs_value *value)
+{
+ struct dwarf2_loclist_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
+
+ gdb_assert (dlbaton == NULL);
+ error (_("Unable to resolve variable \"%s\""), SYMBOL_PRINT_NAME (symbol));
+}
+
+/* The set of location functions used with the DWARF-2 evaluator when we are
+ unable to resolve the symbols. */
+const struct symbol_computed_ops dwarf2_missing_funcs = {
+ missing_read_variable,
2012-01-03 15:00:12 +00:00
+ missing_read_variable, /* read_variable_at_entry */
2010-07-21 21:30:20 +00:00
+ missing_read_needs_frame,
+ missing_describe_location,
+ missing_tracepoint_var_ref
+};
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_dwarf2loc;
2012-01-03 15:00:12 +00:00
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2loc.h
2013-01-19 22:41:55 +00:00
index 36641b3..1394578 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2loc.h
2013-01-19 22:41:55 +00:00
@@ -132,6 +132,15 @@ struct dwarf2_loclist_baton
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
extern const struct symbol_computed_ops dwarf2_locexpr_funcs;
extern const struct symbol_computed_ops dwarf2_loclist_funcs;
+extern const struct symbol_computed_ops dwarf2_missing_funcs;
+
+extern void object_address_set (CORE_ADDR address);
+
+extern CORE_ADDR dwarf_locexpr_baton_eval
+ (struct dwarf2_locexpr_baton *dlbaton);
+
+extern int dwarf_loclist_baton_eval (struct dwarf2_loclist_baton *dllbaton,
+ struct type *type, CORE_ADDR *addrp);
2009-08-04 05:37:29 +00:00
2011-02-18 10:25:34 +00:00
/* Compile a DWARF location expression to an agent expression.
2012-01-03 15:00:12 +00:00
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
2013-03-10 16:12:43 +00:00
index df6298b..b11abf0 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
2013-02-18 17:14:00 +00:00
@@ -1624,6 +1624,9 @@ static void fill_in_loclist_baton (struct dwarf2_cu *cu,
2011-01-01 00:27:30 +00:00
struct dwarf2_loclist_baton *baton,
struct attribute *attr);
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
+static struct dwarf2_loclist_baton *dwarf2_attr_to_loclist_baton
+ (struct attribute *attr, struct dwarf2_cu *cu);
+
static void dwarf2_symbol_mark_computed (struct attribute *attr,
struct symbol *sym,
struct dwarf2_cu *cu);
2013-02-18 17:14:00 +00:00
@@ -1656,6 +1659,9 @@ static void age_cached_comp_units (void);
2009-08-04 05:37:29 +00:00
2012-06-03 17:40:44 +00:00
static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
+static void fetch_die_type_attrs (struct die_info *die, struct type *type,
+ struct dwarf2_cu *cu);
+
static struct type *set_die_type (struct die_info *, struct type *,
struct dwarf2_cu *);
2009-08-04 05:37:29 +00:00
2013-02-18 17:14:00 +00:00
@@ -1684,6 +1690,9 @@ static struct type *get_die_type_at_offset (sect_offset,
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu);
2009-08-04 05:37:29 +00:00
2010-07-21 21:30:20 +00:00
+static struct dwarf2_locexpr_baton *dwarf2_attr_to_locexpr_baton
+ (struct attribute *attr, struct dwarf2_cu *cu);
+
2010-11-17 02:58:16 +00:00
static void dwarf2_release_queue (void *dummy);
2012-06-03 17:40:44 +00:00
static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
2013-02-18 17:14:00 +00:00
@@ -11702,6 +11711,29 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
2013-01-19 22:41:55 +00:00
new_symbol (die, this_type, cu);
2012-07-03 18:54:05 +00:00
}
2013-01-19 22:41:55 +00:00
+/* Create a new array dimension referencing its target type TYPE.
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ Multidimensional arrays are internally represented as a stack of
+ singledimensional arrays being referenced by their TYPE_TARGET_TYPE. */
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+static struct type *
+create_single_array_dimension (struct type *type, struct type *range_type,
+ struct die_info *die, struct dwarf2_cu *cu)
2010-07-22 10:49:58 +00:00
+{
2013-01-19 22:41:55 +00:00
+ type = create_array_type (NULL, type, range_type);
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ /* 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);
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ /* 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);
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ return type;
2012-07-03 18:54:05 +00:00
+}
2013-01-19 22:41:55 +00:00
+
/* 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. */
2013-02-18 17:14:00 +00:00
@@ -11715,7 +11747,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
2013-01-19 22:41:55 +00:00
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;
2013-02-18 17:14:00 +00:00
const char *name;
2012-07-03 18:54:05 +00:00
2013-02-18 17:14:00 +00:00
@@ -11768,17 +11800,19 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
2013-01-19 22:41:55 +00:00
type = element_type;
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
if (read_array_order (die, cu) == DW_ORD_col_major)
- {
- int i = 0;
2012-07-03 18:54:05 +00:00
-
- 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);
+
+ /* 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
2013-02-18 17:14:00 +00:00
@@ -12413,29 +12447,114 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
2012-07-03 18:54:05 +00:00
struct gdbarch *gdbarch = get_objfile_arch (objfile);
struct type *type, *range_type, *index_type, *char_type;
struct attribute *attr;
2010-11-17 02:58:16 +00:00
- unsigned int length;
+ int length;
2009-03-02 00:11:35 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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);
2009-03-02 00:11:35 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* 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))
2011-04-29 08:04:45 +00:00
{
- length = DW_UNSND (attr);
2010-11-17 02:58:16 +00:00
+ /* 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);
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* Turn any single DW_OP_reg* into DW_OP_breg*(0) but clearing
+ DW_OP_deref* in such case. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ end = safe_read_uleb128 (&blk->data[1], &blk->data[blk->size],
+ &ulongest);
2010-11-17 02:58:16 +00:00
+ if (end == &blk->data[blk->size])
+ length_baton = dwarf2_attr_to_locexpr_baton (attr, cu);
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (length_baton == NULL)
+ {
+ struct attribute *size_attr;
+ gdb_byte *data;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* 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;
+ }
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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
{
2011-01-17 15:31:43 +00:00
- /* Check for the DW_AT_byte_size attribute. */
2010-11-17 02:58:16 +00:00
+ 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 */
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
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);
2013-02-18 17:14:00 +00:00
@@ -12739,7 +12858,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2013-03-10 16:12:43 +00:00
struct type *base_type, *orig_base_type;
2010-11-17 02:58:16 +00:00
struct type *range_type;
struct attribute *attr;
2012-06-03 17:40:44 +00:00
- LONGEST low, high;
2010-11-17 02:58:16 +00:00
+ LONGEST low;
2012-06-03 17:40:44 +00:00
int low_default_is_valid;
2013-02-18 17:14:00 +00:00
const char *name;
2010-11-17 02:58:16 +00:00
LONGEST negative_mask;
2013-03-10 16:12:43 +00:00
@@ -12798,42 +12917,6 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2012-06-03 17:40:44 +00:00
"- DIE at 0x%x [in module %s]"),
die->offset.sect_off, cu->objfile->name);
2010-11-17 02:58:16 +00:00
2012-06-03 17:40:44 +00:00
- 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.
-
- 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
2011-07-29 20:55:31 +00:00
- {
2012-06-03 17:40:44 +00:00
- 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;
- }
2011-07-29 20:55:31 +00:00
- }
2012-06-03 17:40:44 +00:00
-
/* 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
2013-03-10 16:12:43 +00:00
@@ -12872,24 +12955,163 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
2012-06-03 17:40:44 +00:00
}
}
- negative_mask =
2010-11-17 02:58:16 +00:00
+ /* LOW_BOUND and HIGH_BOUND are set for real below. */
2013-03-10 16:12:43 +00:00
+ range_type = create_range_type (NULL, orig_base_type, 0, -1);
2011-01-17 15:31:43 +00:00
+ TYPE_UNSIGNED (range_type) = 0;
2012-01-03 15:00:12 +00:00
+
2011-01-17 15:31:43 +00:00
+ negative_mask =
2012-06-03 17:40:44 +00:00
(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;
2013-03-10 16:12:43 +00:00
- range_type = create_range_type (NULL, orig_base_type, low, high);
2012-06-03 17:40:44 +00:00
+ /* Exclude language_ada from any TYPE_DYNAMIC constructs below. GDB Ada
+ supports implements the dynamic bounds in a non-DWARF way and the
2011-01-17 15:31:43 +00:00
+ existing DWARF dynamic bounds are invalid, leading to memory access
+ errors. */
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
- /* 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);
2010-11-17 02:58:16 +00:00
+ if (attr && attr_form_is_block (attr) && cu->language != language_ada)
2012-01-03 15:00:12 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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;
2011-07-29 20:55:31 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ else if (attr && is_ref_attr (attr) && cu->language != language_ada)
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ struct die_info *target_die;
+ struct dwarf2_cu *target_cu = cu;
+ struct attribute *target_loc_attr;
2013-01-19 22:41:55 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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);
2011-07-29 20:55:31 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2012-01-03 15:00:12 +00:00
+ }
+ else
2012-06-03 17:40:44 +00:00
+ {
2012-01-03 15:00:12 +00:00
+ if (attr && attr_form_is_constant (attr))
+ low = dwarf2_get_attr_constant_value (attr, 0);
2012-06-03 17:40:44 +00:00
+ else
2012-01-03 15:00:12 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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;
+ }
2012-01-03 15:00:12 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ 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;
2012-06-03 17:40:44 +00:00
+ }
2013-01-19 22:41:55 +00:00
- /* Ada expects an empty array on no boundary attributes. */
- if (attr == NULL && cu->language != language_ada)
- TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
2011-01-17 15:31:43 +00:00
+ attr = dwarf2_attr (die, DW_AT_upper_bound, cu);
2010-11-17 02:58:16 +00:00
+ if (!attr || (!attr_form_is_block (attr) && !attr_form_is_constant (attr)
+ && !is_ref_attr (attr)))
2012-06-03 17:40:44 +00:00
+ {
+ attr = dwarf2_attr (die, DW_AT_count, cu);
2010-11-17 02:58:16 +00:00
+ /* 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;
2012-06-03 17:40:44 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ /* Pass it now as the regular DW_AT_upper_bound. */
2010-07-21 21:30:20 +00:00
+ }
2010-07-11 18:06:33 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (attr && attr_form_is_block (attr) && cu->language != language_ada)
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-21 21:30:20 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2011-01-17 15:31:43 +00:00
+ }
+ else
+ {
2010-11-17 02:58:16 +00:00
+ LONGEST high;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (attr && attr_form_is_constant (attr))
+ high = dwarf2_get_attr_constant_value (attr, 0);
2012-06-03 17:40:44 +00:00
+ else
+ {
2010-11-17 02:58:16 +00:00
+ /* Ada expects an empty array on no boundary attributes. */
+ if (cu->language != language_ada)
+ TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1;
2012-06-03 17:40:44 +00:00
+ high = low - 1;
+ }
2010-11-17 02:58:16 +00:00
+ if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
+ high |= negative_mask;
+ TYPE_HIGH_BOUND (range_type) = high;
2012-06-03 17:40:44 +00:00
+ }
+
2010-11-17 02:58:16 +00:00
+ /* 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)
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ else if (attr && is_ref_attr (attr) && cu->language != language_ada)
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ struct die_info *target_die;
+ struct dwarf2_cu *target_cu = cu;
+ struct attribute *target_loc_attr;
2012-06-03 17:40:44 +00:00
+
2011-01-17 15:31:43 +00:00
+ 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);
2012-06-03 17:40:44 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-21 21:30:20 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ else if (attr && attr_form_is_constant (attr))
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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"));
2010-07-21 21:30:20 +00:00
+ }
2010-11-17 02:58:16 +00:00
name = dwarf2_name (die, cu);
if (name)
2013-03-10 16:12:43 +00:00
@@ -15749,10 +15971,12 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
2010-11-17 02:58:16 +00:00
(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
- or memory numbers show me otherwise. */
+ or memory numbers show me otherwise.
+
+ SYMBOL_CLASS may get overriden by dwarf2_symbol_mark_computed. */
- dwarf2_symbol_mark_computed (attr, sym, cu);
SYMBOL_CLASS (sym) = LOC_COMPUTED;
+ dwarf2_symbol_mark_computed (attr, sym, cu);
2011-07-29 20:55:31 +00:00
if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs)
cu->has_loclist = 1;
2013-03-10 16:12:43 +00:00
@@ -15793,6 +16017,8 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
2010-11-17 02:58:16 +00:00
else
sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
OBJSTAT (objfile, n_syms++);
+ /* 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_SET_LANGUAGE (sym, cu->language);
2013-03-10 16:12:43 +00:00
@@ -16602,6 +16828,9 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
2012-07-03 18:54:05 +00:00
break;
2010-11-17 02:58:16 +00:00
}
+ if (this_type)
+ finalize_type (this_type);
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
return this_type;
}
2013-03-10 16:12:43 +00:00
@@ -19046,62 +19275,100 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
2012-06-03 17:40:44 +00:00
baton->from_dwo = cu->dwo_unit != NULL;
2010-11-17 02:58:16 +00:00
}
-static void
-dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
- struct dwarf2_cu *cu)
+/* Convert DW_BLOCK into struct dwarf2_locexpr_baton. ATTR must be a DW_BLOCK
+ attribute type. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+static struct dwarf2_locexpr_baton *
+dwarf2_attr_to_locexpr_baton (struct attribute *attr, struct dwarf2_cu *cu)
2012-06-03 17:40:44 +00:00
+{
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
2012-01-03 15:00:12 +00:00
+ struct dwarf2_locexpr_baton *baton;
2012-06-03 17:40:44 +00:00
+
2011-02-18 10:25:34 +00:00
+ gdb_assert (attr_form_is_block (attr));
2012-01-03 15:00:12 +00:00
+
+ baton = obstack_alloc (&objfile->objfile_obstack, sizeof (*baton));
2010-11-17 02:58:16 +00:00
+ baton->per_cu = cu->per_cu;
+ gdb_assert (baton->per_cu);
2012-06-03 17:40:44 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* 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
+ that buffer, but when we do clean up properly this may
+ need to change. */
+ baton->size = DW_BLOCK (attr)->size;
+ baton->data = DW_BLOCK (attr)->data;
+ gdb_assert (baton->size == 0 || baton->data != NULL);
2012-06-03 17:40:44 +00:00
+
2011-01-17 15:31:43 +00:00
+ return baton;
+}
2012-06-03 17:40:44 +00:00
+
2010-11-17 02:58:16 +00:00
+static struct dwarf2_loclist_baton *
+dwarf2_attr_to_loclist_baton (struct attribute *attr, struct dwarf2_cu *cu)
2012-06-03 17:40:44 +00:00
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwarf2_section_info *section = cu_debug_loc_section (cu);
2010-11-17 02:58:16 +00:00
+ struct dwarf2_loclist_baton *baton;
2013-01-19 22:41:55 +00:00
- if (attr_form_is_section_offset (attr)
2010-11-17 02:58:16 +00:00
+ /* DW_AT_location of the referenced DIE may be missing if the referenced
+ variable has been optimized out. */
+ if (!attr)
+ return NULL;
2011-04-29 08:04:45 +00:00
+
2012-06-03 17:40:44 +00:00
+ dwarf2_read_section (dwarf2_per_objfile->objfile, section);
2013-01-19 22:41:55 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (!(attr_form_is_section_offset (attr)
2012-06-03 17:40:44 +00:00
/* .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)))
2010-11-17 02:58:16 +00:00
+ return NULL;
2012-06-03 17:40:44 +00:00
- baton = obstack_alloc (&objfile->objfile_obstack,
- sizeof (struct dwarf2_loclist_baton));
+ baton = obstack_alloc (&objfile->objfile_obstack,
2010-11-17 02:58:16 +00:00
+ sizeof (struct dwarf2_loclist_baton));
2012-06-03 17:40:44 +00:00
- fill_in_loclist_baton (cu, baton, attr);
2011-01-01 00:27:30 +00:00
+ fill_in_loclist_baton (cu, baton, attr);
2012-06-03 17:40:44 +00:00
- if (cu->base_known == 0)
- complaint (&symfile_complaints,
- _("Location list used without "
- "specifying the CU base address."));
2010-11-17 02:58:16 +00:00
+ if (cu->base_known == 0)
+ complaint (&symfile_complaints,
2011-01-07 08:47:27 +00:00
+ _("Location list used without "
+ "specifying the CU base address."));
2012-06-03 17:40:44 +00:00
+
2010-11-17 02:58:16 +00:00
+ return baton;
2010-07-22 10:49:58 +00:00
+}
2011-02-18 10:25:34 +00:00
+
2010-11-17 02:58:16 +00:00
+/* SYM may get its SYMBOL_CLASS overriden on invalid ATTR content. */
+
2010-07-22 10:49:58 +00:00
+static void
2010-11-17 02:58:16 +00:00
+dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
+ struct dwarf2_cu *cu)
2010-07-22 10:49:58 +00:00
+{
2010-11-17 02:58:16 +00:00
+ struct dwarf2_loclist_baton *loclist_baton;
2012-06-03 17:40:44 +00:00
2010-11-17 02:58:16 +00:00
+ loclist_baton = dwarf2_attr_to_loclist_baton (attr, cu);
+ if (loclist_baton)
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs;
- SYMBOL_LOCATION_BATON (sym) = baton;
+ SYMBOL_LOCATION_BATON (sym) = loclist_baton;
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ else if (attr_form_is_block (attr))
2010-07-21 21:30:20 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
+ SYMBOL_LOCATION_BATON (sym) = dwarf2_attr_to_locexpr_baton (attr, cu);
}
else
{
- struct dwarf2_locexpr_baton *baton;
+ dwarf2_invalid_attrib_class_complaint ("location description",
+ SYMBOL_NATURAL_NAME (sym));
2012-01-03 15:00:12 +00:00
- baton = obstack_alloc (&objfile->objfile_obstack,
2010-11-17 02:58:16 +00:00
- sizeof (struct dwarf2_locexpr_baton));
- baton->per_cu = cu->per_cu;
- gdb_assert (baton->per_cu);
+ /* Some methods are called w/o checking SYMBOL_COMPUTED_OPS validity. */
- if (attr_form_is_block (attr))
- {
- /* 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
- that buffer, but when we do clean up properly this may
- need to change. */
- baton->size = DW_BLOCK (attr)->size;
- baton->data = DW_BLOCK (attr)->data;
- }
- else
- {
- dwarf2_invalid_attrib_class_complaint ("location description",
- SYMBOL_NATURAL_NAME (sym));
- baton->size = 0;
- }
+ SYMBOL_COMPUTED_OPS (sym) = &dwarf2_missing_funcs;
+ SYMBOL_LOCATION_BATON (sym) = NULL;
- SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs;
- SYMBOL_LOCATION_BATON (sym) = baton;
+ /* For functions a missing DW_AT_frame_base does not optimize out the
+ whole function definition, only its frame base resolving. */
+ if (attr->name == DW_AT_location)
+ SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
}
}
2013-03-10 16:12:43 +00:00
@@ -19472,6 +19739,25 @@ per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs)
2013-01-19 22:41:55 +00:00
&& ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off);
}
2010-11-17 02:58:16 +00:00
+/* Fill in generic attributes applicable for type DIEs. */
2010-01-21 16:09:11 +00:00
+
2010-07-21 21:30:20 +00:00
+static void
2010-11-17 02:58:16 +00:00
+fetch_die_type_attrs (struct die_info *die, struct type *type,
+ struct dwarf2_cu *cu)
2010-07-21 21:30:20 +00:00
+{
2010-11-17 02:58:16 +00:00
+ struct attribute *attr;
2009-08-18 18:51:17 +00:00
+
2010-11-17 02:58:16 +00:00
+ attr = dwarf2_attr (die, DW_AT_allocated, cu);
+ if (attr_form_is_block (attr))
+ TYPE_ALLOCATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
+ gdb_assert (!TYPE_NOT_ALLOCATED (type));
2009-08-18 18:51:17 +00:00
+
2010-11-17 02:58:16 +00:00
+ attr = dwarf2_attr (die, DW_AT_associated, cu);
+ if (attr_form_is_block (attr))
+ TYPE_ASSOCIATED (type) = dwarf2_attr_to_locexpr_baton (attr, cu);
+ gdb_assert (!TYPE_NOT_ASSOCIATED (type));
2010-07-21 21:30:20 +00:00
+}
2010-07-11 18:06:33 +00:00
+
2011-04-11 20:48:13 +00:00
/* Set the type associated with DIE to TYPE. Save it in CU's hash
table if necessary. For convenience, return TYPE.
2013-03-10 16:12:43 +00:00
@@ -19496,6 +19782,8 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
2012-06-03 17:40:44 +00:00
struct dwarf2_per_cu_offset_and_type **slot, ofs;
2011-04-11 20:48:13 +00:00
struct objfile *objfile = cu->objfile;
+ fetch_die_type_attrs (die, type, cu);
2011-03-20 20:44:20 +00:00
+
2011-04-11 20:48:13 +00:00
/* 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
2012-01-03 15:00:12 +00:00
diff --git a/gdb/eval.c b/gdb/eval.c
2013-02-18 17:14:00 +00:00
index d7f80e2..8eca4c8 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/eval.c
+++ b/gdb/eval.c
2012-01-20 23:27:28 +00:00
@@ -41,6 +41,7 @@
#include "gdb_obstack.h"
2011-03-20 20:44:20 +00:00
#include "objfiles.h"
#include "python/python.h"
+#include "dwarf2loc.h"
#include "gdb_assert.h"
2013-01-19 22:41:55 +00:00
@@ -393,27 +394,217 @@ init_array_element (struct value *array, struct value *element,
2011-03-20 20:44:20 +00:00
}
static struct value *
-value_f90_subarray (struct value *array,
2011-01-17 15:31:43 +00:00
- 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;
2012-01-03 15:00:12 +00:00
-
2011-04-29 08:04:45 +00:00
- if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
- low_bound = TYPE_LOW_BOUND (range);
2012-01-03 15:00:12 +00:00
+ /* Type to use for the newly allocated value ARRAY. */
+ struct type *new_array_type;
+
2011-01-17 15:31:43 +00:00
+ /* Type being iterated for each dimension. */
2011-03-05 12:24:53 +00:00
+ struct type *type, *type_last_target;
2011-01-17 15:31:43 +00:00
+
+ /* Pointer in the last holder to the type of current dimension. */
+ struct type **typep = &new_array_type;
+
+ 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;
2011-03-05 12:24:53 +00:00
+ struct type **type_array;
2011-01-17 15:31:43 +00:00
+ 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);
+
+ copied_types = create_copied_types_hash (NULL);
+ type = copy_type_recursive (type, copied_types);
+ htab_delete (copied_types);
+
+ if (nargs != calc_f77_array_dims (type))
+ error (_("Wrong number of subscripts"));
+
+ if (TYPE_DATA_LOCATION_IS_ADDR (type))
+ {
+ value_byte_address = (TYPE_DATA_LOCATION_ADDR (type)
+ + value_offset (array));
+ TYPE_DATA_LOCATION_IS_ADDR (type) = 0;
2011-02-18 10:25:34 +00:00
+ TYPE_DATA_LOCATION_DWARF_BLOCK (type) = NULL;
2011-01-17 15:31:43 +00:00
+ }
else
- low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
2011-02-18 10:25:34 +00:00
+ {
+ gdb_assert (TYPE_DATA_LOCATION_DWARF_BLOCK (type) == NULL);
+ value_byte_address = value_address (array);
+ }
2011-01-17 15:31:43 +00:00
+
+ new_array_type = type;
+
+ subscript_array = alloca (sizeof (*subscript_array) * nargs);
+
+ 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++)
+ {
+ struct subscript_index *index = &subscript_array[i];
+
+ if (exp->elts[*pos].opcode == OP_F90_RANGE)
+ {
+ int pc = (*pos) + 1;
+ struct subscript_range *range;
+
+ index->kind = SUBSCRIPT_RANGE;
+ range = &index->range;
+
+ *pos += 3;
+ range->f90_range_type = longest_to_int (exp->elts[pc].longconst);
+
+ 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
+ {
+ struct value *val;
+
+ index->kind = SUBSCRIPT_NUMBER;
2011-03-05 12:24:53 +00:00
- if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
- high_bound = TYPE_HIGH_BOUND (range);
2011-01-17 15:31:43 +00:00
+ /* 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);
+ }
+ }
+
+ /* Internal type of array is arranged right to left. */
+ for (i = nargs - 1; i >= 0; i--)
+ {
+ struct subscript_index *index = &subscript_array[i];
+ struct type *range_type = TYPE_INDEX_TYPE (type);
2011-03-05 12:24:53 +00:00
+
2011-01-17 15:31:43 +00:00
+ 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;
+
+ case SUBSCRIPT_NUMBER:
+ {
+ CORE_ADDR byte_offset;
+
+ 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"));
+
+ byte_offset = ((index->number - TYPE_LOW_BOUND (range_type))
+ * TYPE_ARRAY_BYTE_STRIDE_VALUE (type));
+
+ type = TYPE_TARGET_TYPE (type);
+ *typep = type;
+ value_byte_offset += byte_offset;
+ }
+ break;
+ }
+ }
+
2011-03-05 12:24:53 +00:00
+ 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];
+
+ /* Force TYPE_LENGTH (type) recalculation. */
+ TYPE_TARGET_STUB (type) = 1;
+ check_typedef (type);
+ }
+
2011-01-17 15:31:43 +00:00
+ 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);
2012-01-03 15:00:12 +00:00
+
2011-01-17 15:31:43 +00:00
+ if (!value_lazy (saved_array))
+ {
+ allocate_value_contents (array);
+ set_value_lazy (array, 0);
2012-01-03 15:00:12 +00:00
- return value_slice (array, low_bound, high_bound - low_bound + 1);
2011-01-17 15:31:43 +00:00
+ memcpy (value_contents_writeable (array),
+ value_contents (saved_array) + value_byte_offset,
+ TYPE_LENGTH (new_array_type));
+ }
2011-03-05 12:24:53 +00:00
+
2011-01-17 15:31:43 +00:00
+ do_cleanups (old_chain);
+ return array;
}
2013-01-19 22:41:55 +00:00
@@ -710,6 +901,7 @@ evaluate_subexp_standard (struct type *expect_type,
2010-11-17 02:58:16 +00:00
int save_pos1;
struct symbol *function = NULL;
char *function_name = NULL;
+ struct cleanup *old_chain;
2010-01-21 16:09:11 +00:00
2010-11-17 02:58:16 +00:00
pc = (*pos)++;
op = exp->elts[pc].opcode;
2013-02-18 17:14:00 +00:00
@@ -1776,6 +1968,8 @@ evaluate_subexp_standard (struct type *expect_type,
2010-01-21 16:09:11 +00:00
2010-11-17 02:58:16 +00:00
/* 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);
2010-01-21 16:09:11 +00:00
2013-02-18 17:14:00 +00:00
@@ -1796,23 +1990,13 @@ evaluate_subexp_standard (struct type *expect_type,
2010-11-17 02:58:16 +00:00
code = TYPE_CODE (type);
}
}
+ do_cleanups (old_chain);
2010-01-21 16:09:11 +00:00
2010-11-17 02:58:16 +00:00
switch (code)
2010-07-21 21:30:20 +00:00
{
2011-01-17 15:31:43 +00:00
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);
2010-01-21 16:09:11 +00:00
2011-01-17 15:31:43 +00:00
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
2013-02-18 17:14:00 +00:00
@@ -2239,49 +2423,6 @@ evaluate_subexp_standard (struct type *expect_type,
2011-01-17 15:31:43 +00:00
}
return (arg1);
2010-07-21 21:30:20 +00:00
2011-01-17 15:31:43 +00:00
- 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];
-
2013-01-19 22:41:55 +00:00
- array = value_subscripted_rvalue (array, index,
- f77_get_lowerbound (array_type));
2011-01-17 15:31:43 +00:00
- }
-
- return array;
- }
-
2010-11-17 02:58:16 +00:00
case BINOP_LOGICAL_AND:
2011-01-17 15:31:43 +00:00
arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
if (noside == EVAL_SKIP)
2013-02-18 17:14:00 +00:00
@@ -2513,15 +2654,23 @@ evaluate_subexp_standard (struct type *expect_type,
2010-11-17 02:58:16 +00:00
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);
+ old_chain = make_cleanup (null_cleanup, 0);
+ object_address_set (value_raw_address (arg1));
type = check_typedef (value_type (arg1));
if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
|| TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
2011-01-07 08:47:27 +00:00
error (_("Attempt to dereference pointer "
"to member without an object"));
2010-11-17 02:58:16 +00:00
if (noside == EVAL_SKIP)
- goto nosideret;
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ do_cleanups (old_chain);
+ goto nosideret;
+ }
if (unop_user_defined_p (op, arg1))
- return value_x_unop (arg1, op, noside);
+ {
+ do_cleanups (old_chain);
+ return value_x_unop (arg1, op, noside);
+ }
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
type = check_typedef (value_type (arg1));
2013-02-18 17:14:00 +00:00
@@ -2530,12 +2679,18 @@ evaluate_subexp_standard (struct type *expect_type,
2010-11-17 02:58:16 +00:00
/* In C you can dereference an array to get the 1st elt. */
|| TYPE_CODE (type) == TYPE_CODE_ARRAY
)
- return value_zero (TYPE_TARGET_TYPE (type),
- lval_memory);
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ do_cleanups (old_chain);
+ return value_zero (TYPE_TARGET_TYPE (type),
+ lval_memory);
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
else if (TYPE_CODE (type) == TYPE_CODE_INT)
- /* GDB allows dereferencing an int. */
- return value_zero (builtin_type (exp->gdbarch)->builtin_int,
- lval_memory);
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ do_cleanups (old_chain);
+ /* GDB allows dereferencing an int. */
+ return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+ lval_memory);
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
else
error (_("Attempt to take contents of a non-pointer value."));
}
2013-02-18 17:14:00 +00:00
@@ -2545,9 +2700,14 @@ evaluate_subexp_standard (struct type *expect_type,
2010-11-17 02:58:16 +00:00
do. "long long" variables are rare enough that
BUILTIN_TYPE_LONGEST would seem to be a mistake. */
if (TYPE_CODE (type) == TYPE_CODE_INT)
- return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
- (CORE_ADDR) value_as_address (arg1));
- return value_ind (arg1);
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ do_cleanups (old_chain);
+ return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+ (CORE_ADDR) value_as_address (arg1));
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
+ arg1 = value_ind (arg1);
+ do_cleanups (old_chain);
+ return arg1;
2010-01-21 16:09:11 +00:00
2010-11-17 02:58:16 +00:00
case UNOP_ADDR:
/* C++: check for and handle pointer to members. */
2013-02-18 17:14:00 +00:00
@@ -2960,7 +3120,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
2010-11-17 02:58:16 +00:00
{
enum exp_opcode op;
int pc;
- struct value *val;
+ struct value *val = NULL;
struct symbol *var;
struct type *type;
2010-01-21 16:09:11 +00:00
2013-02-18 17:14:00 +00:00
@@ -2971,13 +3131,18 @@ evaluate_subexp_with_coercion (struct expression *exp,
2010-11-17 02:58:16 +00:00
{
case OP_VAR_VALUE:
var = exp->elts[pc + 2].symbol;
+ /* address_of_variable will call object_address_set for check_typedef.
+ Call it only if required as it can error-out on VAR in register. */
+ if (TYPE_DYNAMIC (SYMBOL_TYPE (var)))
+ 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;
- val = address_of_variable (var, exp->elts[pc + 1].block);
+ if (!val)
+ val = address_of_variable (var, exp->elts[pc + 1].block);
return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
val);
}
2013-02-18 17:14:00 +00:00
@@ -3035,9 +3200,13 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
2010-07-21 21:30:20 +00:00
2010-11-17 02:58:16 +00:00
case OP_VAR_VALUE:
(*pos) += 4;
- type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
- return
- value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
+ /* We do not need to call read_var_value but the object evaluation may
+ need to have executed object_address_set which needs valid
+ SYMBOL_VALUE_ADDRESS of the symbol. Still VALUE returned by
+ read_var_value we left as lazy. */
+ type = value_type (read_var_value (exp->elts[pc + 2].symbol,
+ deprecated_safe_get_selected_frame ()));
+ return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
2010-07-21 21:30:20 +00:00
2010-11-17 02:58:16 +00:00
default:
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2013-02-18 17:14:00 +00:00
@@ -3068,18 +3237,25 @@ parse_and_eval_type (char *p, int length)
2011-01-17 15:31:43 +00:00
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;
+
}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
2013-01-19 22:41:55 +00:00
index 846cc02..9283183 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
2013-01-19 22:41:55 +00:00
@@ -297,7 +297,9 @@ arglist : subrange
2011-01-17 15:31:43 +00:00
{ arglist_len = 1; }
;
-arglist : arglist ',' exp %prec ABOVE_COMMA
+arglist : arglist ',' exp %prec ABOVE_COMMA
+ { arglist_len++; }
+ | arglist ',' subrange %prec ABOVE_COMMA
{ arglist_len++; }
;
2012-01-03 15:00:12 +00:00
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
2013-01-19 22:41:55 +00:00
index 4ef1acf..8da016b 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
2013-01-19 22:41:55 +00:00
@@ -29,6 +29,10 @@ extern void f_error (char *); /* Defined in f-exp.y */
2010-11-17 02:58:16 +00:00
extern void f_print_type (struct type *, const char *, struct ui_file *, int,
2013-01-19 22:41:55 +00:00
int, const struct type_print_options *);
2010-01-21 16:09:11 +00:00
2010-11-17 02:58:16 +00:00
+extern const char *f_object_address_data_valid_print_to_stream
+ (struct type *type, struct ui_file *stream);
+extern void f_object_address_data_valid_or_error (struct type *type);
2010-07-22 10:49:58 +00:00
+
2012-06-03 17:40:44 +00:00
extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
struct ui_file *, int,
const struct value *,
2012-01-03 15:00:12 +00:00
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
2013-01-19 22:41:55 +00:00
index aa33231..df998c4 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
2013-01-19 22:41:55 +00:00
@@ -30,7 +30,7 @@
2010-11-17 02:58:16 +00:00
#include "gdbcore.h"
#include "target.h"
#include "f-lang.h"
-
+#include "dwarf2loc.h"
#include "gdb_string.h"
#include <errno.h>
2010-01-21 16:09:11 +00:00
2013-01-19 22:41:55 +00:00
@@ -47,6 +47,34 @@ void f_type_print_varspec_prefix (struct type *, struct ui_file *,
2010-11-17 02:58:16 +00:00
void f_type_print_base (struct type *, struct ui_file *, int, int);
+const char *
+f_object_address_data_valid_print_to_stream (struct type *type,
+ struct ui_file *stream)
+{
+ const char *msg;
+
+ msg = object_address_data_not_valid (type);
+ if (msg != NULL)
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ /* Assuming the content printed to STREAM should not be localized. */
+ fprintf_filtered (stream, "<%s>", msg);
2010-07-22 10:49:58 +00:00
+ }
+
2010-11-17 02:58:16 +00:00
+ return msg;
+}
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+void
+f_object_address_data_valid_or_error (struct type *type)
+{
+ const char *msg;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ msg = object_address_data_not_valid (type);
+ if (msg != NULL)
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ error (_("Cannot access it because the %s."), _(msg));
2010-07-22 10:49:58 +00:00
+ }
2010-11-17 02:58:16 +00:00
+}
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
/* LEVEL is the depth to indent lines by. */
void
2013-01-19 22:41:55 +00:00
@@ -56,6 +84,9 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
2010-11-17 02:58:16 +00:00
enum type_code code;
int demangled_args;
+ if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
+ return;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
f_type_print_base (type, stream, show, level);
code = TYPE_CODE (type);
if ((varstring != NULL && *varstring != '\0')
2013-01-19 22:41:55 +00:00
@@ -162,6 +193,9 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
QUIT;
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
+ if (TYPE_CODE (type) != TYPE_CODE_TYPEDEF)
+ CHECK_TYPEDEF (type);
+
switch (TYPE_CODE (type))
{
case TYPE_CODE_ARRAY:
2012-01-03 15:00:12 +00:00
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
2013-02-18 17:14:00 +00:00
index d01d6ec..8a21149 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
2013-01-19 22:41:55 +00:00
@@ -51,15 +51,17 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
2010-11-17 02:58:16 +00:00
/* The following macro gives us the size of the nth dimension, Where
2011-01-17 15:31:43 +00:00
n is 1 based. */
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
-#define F77_DIM_SIZE(n) (f77_array_offset_tbl[n][1])
+#define F77_DIM_COUNT(n) (f77_array_offset_tbl[n][1])
2010-07-22 10:49:58 +00:00
2011-01-17 15:31:43 +00:00
-/* 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. */
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
-#define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
+#define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
int
f77_get_lowerbound (struct type *type)
{
+ f_object_address_data_valid_or_error (type);
+
if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
error (_("Lower bound may not be '*' in F77"));
2010-07-22 10:49:58 +00:00
2013-01-19 22:41:55 +00:00
@@ -69,14 +71,17 @@ f77_get_lowerbound (struct type *type)
2010-11-17 02:58:16 +00:00
int
f77_get_upperbound (struct type *type)
{
+ f_object_address_data_valid_or_error (type);
+
if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
{
- /* We have an assumed size array on our hands. Assume that
- upper_bound == lower_bound so that we show at least 1 element.
- If the user wants to see more elements, let him manually ask for 'em
- and we'll subscript the array and show him. */
+ /* We have an assumed size array on our hands. As type_length_get
+ already assumes a length zero of arrays with underfined bounds VALADDR
+ passed to the Fortran functions does not contained the real inferior
+ memory content. User should request printing of specific array
+ elements instead. */
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
- return f77_get_lowerbound (type);
+ return f77_get_lowerbound (type) - 1;
2010-07-22 10:49:58 +00:00
}
2010-11-17 02:58:16 +00:00
return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
2013-01-19 22:41:55 +00:00
@@ -132,24 +137,29 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
2010-11-17 02:58:16 +00:00
upper = f77_get_upperbound (tmp_type);
lower = f77_get_lowerbound (tmp_type);
- F77_DIM_SIZE (ndimen) = upper - lower + 1;
+ F77_DIM_COUNT (ndimen) = upper - lower + 1;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ F77_DIM_BYTE_STRIDE (ndimen) =
+ TYPE_ARRAY_BYTE_STRIDE_VALUE (tmp_type);
tmp_type = TYPE_TARGET_TYPE (tmp_type);
ndimen++;
}
- /* Now we multiply eltlen by all the offsets, so that later we
+ /* 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
2011-01-17 15:31:43 +00:00
+ 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. */
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
ndimen--;
eltlen = TYPE_LENGTH (tmp_type);
- F77_DIM_OFFSET (ndimen) = eltlen;
+ if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
+ F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
while (--ndimen > 0)
{
- eltlen *= F77_DIM_SIZE (ndimen + 1);
- F77_DIM_OFFSET (ndimen) = eltlen;
+ eltlen *= F77_DIM_COUNT (ndimen + 1);
+ if (F77_DIM_BYTE_STRIDE (ndimen) == 0)
+ F77_DIM_BYTE_STRIDE (ndimen) = eltlen;
2010-07-22 10:49:58 +00:00
}
}
2013-01-19 22:41:55 +00:00
@@ -171,37 +181,35 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
if (nss != ndimensions)
{
2011-01-07 08:47:27 +00:00
- for (i = 0;
- (i < F77_DIM_SIZE (nss) && (*elts) < options->print_max);
- i++)
2010-11-17 02:58:16 +00:00
+ 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),
2011-01-25 21:51:27 +00:00
valaddr,
- embedded_offset + i * F77_DIM_OFFSET (nss),
+ embedded_offset + i * F77_DIM_BYTE_STRIDE (nss),
address,
2010-11-17 02:58:16 +00:00
stream, recurse, val, options, elts);
fprintf_filtered (stream, ") ");
}
- if (*elts >= options->print_max && i < F77_DIM_SIZE (nss))
+ if (*elts >= options->print_max && i < F77_DIM_COUNT (nss))
fprintf_filtered (stream, "...");
}
else
{
- for (i = 0; i < F77_DIM_SIZE (nss) && (*elts) < options->print_max;
+ for (i = 0; i < F77_DIM_COUNT (nss) && (*elts) < options->print_max;
i++, (*elts)++)
{
val_print (TYPE_TARGET_TYPE (type),
2011-01-25 21:51:27 +00:00
valaddr,
- embedded_offset + i * F77_DIM_OFFSET (ndimensions),
+ embedded_offset + i * F77_DIM_BYTE_STRIDE (ndimensions),
address, stream, recurse,
val, options, current_language);
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
- if (i != (F77_DIM_SIZE (nss) - 1))
+ if (i != (F77_DIM_COUNT (nss) - 1))
fprintf_filtered (stream, ", ");
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
if ((*elts == options->print_max - 1)
- && (i != (F77_DIM_SIZE (nss) - 1)))
+ && (i != (F77_DIM_COUNT (nss) - 1)))
fprintf_filtered (stream, "...");
}
2010-07-22 10:49:58 +00:00
}
2013-01-19 22:41:55 +00:00
@@ -267,6 +275,9 @@ f_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
2010-11-17 02:58:16 +00:00
CORE_ADDR addr;
int index;
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
+ if (f_object_address_data_valid_print_to_stream (type, stream) != NULL)
2012-06-03 17:40:44 +00:00
+ return;
2010-11-17 02:58:16 +00:00
+
2012-07-03 18:54:05 +00:00
CHECK_TYPEDEF (type);
switch (TYPE_CODE (type))
{
diff --git a/gdb/findvar.c b/gdb/findvar.c
2013-01-19 22:41:55 +00:00
index fb66e0f..45684f0 100644
2012-07-03 18:54:05 +00:00
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
2013-01-19 22:41:55 +00:00
@@ -34,6 +34,7 @@
2012-07-03 18:54:05 +00:00
#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
2013-01-19 22:41:55 +00:00
@@ -437,7 +438,10 @@ minsym_lookup_iterator_cb (struct objfile *objfile, void *cb_data)
2012-07-03 18:54:05 +00:00
}
/* 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. */
struct value *
default_read_var_value (struct symbol *var, struct frame_info *frame)
2013-01-19 22:41:55 +00:00
@@ -446,13 +450,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
struct type *type = SYMBOL_TYPE (var);
CORE_ADDR addr;
2013-01-19 22:41:55 +00:00
2012-07-03 18:54:05 +00:00
- /* 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);
-
if (symbol_read_needs_frame (var))
gdb_assert (frame);
2013-01-19 22:41:55 +00:00
@@ -492,7 +489,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
return v;
case LOC_STATIC:
- v = allocate_value_lazy (type);
if (overlay_debugging)
addr = symbol_overlayed_address (SYMBOL_VALUE_ADDRESS (var),
SYMBOL_OBJ_SECTION (var));
2013-01-19 22:41:55 +00:00
@@ -506,7 +502,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
error (_("Unknown argument list address for `%s'."),
SYMBOL_PRINT_NAME (var));
addr += SYMBOL_VALUE (var);
- v = allocate_value_lazy (type);
break;
case LOC_REF_ARG:
2013-01-19 22:41:55 +00:00
@@ -521,14 +516,12 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
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_LOCAL:
addr = get_frame_locals_address (frame);
addr += SYMBOL_VALUE (var);
- v = allocate_value_lazy (type);
break;
case LOC_TYPEDEF:
2013-01-19 22:41:55 +00:00
@@ -537,7 +530,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
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));
2013-01-19 22:41:55 +00:00
@@ -563,7 +555,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
SYMBOL_PRINT_NAME (var));
addr = value_as_address (regval);
- v = allocate_value_lazy (type);
}
else
{
2013-01-19 22:41:55 +00:00
@@ -612,7 +603,6 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
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;
2013-01-19 22:41:55 +00:00
@@ -625,6 +615,10 @@ default_read_var_value (struct symbol *var, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
break;
}
+ /* 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;
2013-01-19 22:41:55 +00:00
@@ -729,10 +723,11 @@ struct value *
2012-07-03 18:54:05 +00:00
value_from_register (struct type *type, int regnum, struct frame_info *frame)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct type *type1 = check_typedef (type);
struct value *v;
- if (gdbarch_convert_register_p (gdbarch, regnum, type1))
+ type = check_typedef (type);
+
+ if (gdbarch_convert_register_p (gdbarch, regnum, type))
{
int optim, unavail, ok;
2013-01-19 22:41:55 +00:00
@@ -747,7 +742,7 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
2012-07-03 18:54:05 +00:00
VALUE_LVAL (v) = lval_register;
VALUE_FRAME_ID (v) = get_frame_id (frame);
VALUE_REGNUM (v) = regnum;
- 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/gdb-gdb.gdb.in b/gdb/gdb-gdb.gdb.in
2013-03-10 16:12:43 +00:00
index 05a38b2..9801fdf 100644
2012-07-03 18:54:05 +00:00
--- 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
+# Set up the Python library and "require" command.
+python
+from os.path import abspath
+gdb.datadir = abspath ('@srcdir@/python/lib')
+gdb.pythonlibdir = gdb.datadir
+gdb.__path__ = [gdb.datadir + '/gdb']
+sys.path.insert(0, gdb.datadir)
+end
+source @srcdir@/python/lib/gdb/__init__.py
+
2013-03-10 16:12:43 +00:00
if !$gdb_init_done
set variable $gdb_init_done = 1
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
2013-02-18 17:14:00 +00:00
index 12730d7..5a614e0 100644
2013-01-19 22:41:55 +00:00
--- 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"
/* Initialize BADNESS constants. */
@@ -185,6 +188,43 @@ alloc_type (struct objfile *objfile)
return type;
}
+#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. */
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+static void
+set_type_as_discardable (struct type *type)
2012-07-03 18:54:05 +00:00
+{
2013-01-19 22:41:55 +00:00
+ void **slot;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ gdb_assert (!TYPE_DISCARDABLE (type));
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ TYPE_DISCARDABLE (type) = 1;
+ TYPE_DISCARDABLE_AGE (type) = type_discardable_age_current;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ slot = htab_find_slot (type_discardable_table, type, INSERT);
+ gdb_assert (!*slot);
+ *slot = type;
2012-07-03 18:54:05 +00:00
+}
2013-01-19 22:41:55 +00:00
+#endif
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+/* Allocate a new type like alloc_type but preserve for it the discardability
+ state of PARENT_TYPE. */
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+static struct type *
+alloc_type_as_parent (struct type *parent_type)
2012-07-03 18:54:05 +00:00
+{
2013-01-19 22:41:55 +00:00
+ struct type *new_type = alloc_type_copy (parent_type);
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+#if 0
+ if (TYPE_DISCARDABLE (parent_type))
+ set_type_as_discardable (new_type);
+#endif
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ return new_type;
2012-07-03 18:54:05 +00:00
+}
+
2013-01-19 22:41:55 +00:00
/* Allocate a new GDBARCH-associated type structure and fill it
with some defaults. Space for the type structure is allocated
on the heap. */
@@ -310,7 +350,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;
}
@@ -383,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;
}
@@ -806,6 +846,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;
@@ -926,6 +967,10 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
return 1;
}
+static LONGEST type_length_get (struct type *type, struct type *target_type,
+ int full_span);
2012-07-03 18:54:05 +00:00
+
+
2013-01-19 22:41:55 +00:00
/* Create an array type using either a blank type supplied in
RESULT_TYPE, or creating a new type, inheriting the objfile from
RANGE_TYPE.
@@ -949,26 +994,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
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ CHECK_TYPEDEF (element_type);
+ TYPE_LENGTH (result_type) = type_length_get (result_type, element_type,
+ 0);
2012-07-03 18:54:05 +00:00
+ }
2013-01-19 22:41:55 +00:00
if (TYPE_LENGTH (result_type) == 0)
- TYPE_TARGET_STUB (result_type) = 1;
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ /* The real size will be computed for specific instances by
+ CHECK_TYPEDEF. */
+ TYPE_TARGET_STUB (result_type) = 1;
2012-07-03 18:54:05 +00:00
+ }
2013-01-19 22:41:55 +00:00
return result_type;
}
@@ -1489,6 +1539,105 @@ stub_noname_complaint (void)
complaint (&symfile_complaints, _("stub type has NULL name"));
}
+/* Calculate the memory length of array TYPE.
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ 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. */
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+static LONGEST
+type_length_get (struct type *type, struct type *target_type, int full_span)
2012-07-03 18:54:05 +00:00
+{
2013-01-19 22:41:55 +00:00
+ struct type *range_type;
+ LONGEST byte_stride = 0; /* `= 0' for a false GCC warning. */
+ LONGEST count, element_size, retval;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ if (TYPE_CODE (type) != TYPE_CODE_ARRAY
+ && TYPE_CODE (type) != TYPE_CODE_STRING)
+ return TYPE_LENGTH (type);
+
+ /* 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;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ 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)
+ {
+ /* 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);
2012-07-03 18:54:05 +00:00
+ }
+ }
+
2013-01-19 22:41:55 +00:00
+ /* 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.
+ */
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ if (full_span)
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ retval = count * byte_stride;
+ if (count == 0 || retval / count != byte_stride || retval > UINT_MAX)
+ retval = 0;
+ return retval;
2012-07-03 18:54:05 +00:00
+ }
2013-01-19 22:41:55 +00:00
+ 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;
2012-07-03 18:54:05 +00:00
+}
+
2013-01-19 22:41:55 +00:00
+/* Prepare TYPE after being read in by the backend. Currently this function
+ only propagates the TYPE_DYNAMIC flag. */
2012-07-03 18:54:05 +00:00
+
+void
2013-01-19 22:41:55 +00:00
+finalize_type (struct type *type)
2012-07-03 18:54:05 +00:00
+{
2013-01-19 22:41:55 +00:00
+ int i;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ for (i = 0; i < TYPE_NFIELDS (type); ++i)
+ if (TYPE_FIELD_TYPE (type, i) && TYPE_DYNAMIC (TYPE_FIELD_TYPE (type, i)))
+ break;
2012-08-01 19:40:12 +00:00
+
2013-01-19 22:41:55 +00:00
+ /* 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;
2012-07-03 18:54:05 +00:00
+}
+
2013-01-19 22:41:55 +00:00
/* 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
@@ -1655,52 +1804,37 @@ 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))
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ htab_t copied_types;
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ copied_types = create_copied_types_hash (NULL);
+ type = copy_type_recursive (type, copied_types);
+ htab_delete (copied_types);
2012-07-03 18:54:05 +00:00
+
2013-01-19 22:41:55 +00:00
+ gdb_assert (TYPE_DYNAMIC (type) == 0);
+ /* Force TYPE_LENGTH (type) recalculation. */
+ TYPE_DYNAMIC (type) = 1;
2012-07-03 18:54:05 +00:00
+ }
+
2013-01-19 22:41:55 +00:00
+ 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))
{
/* 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)
@@ -1708,6 +1842,7 @@ check_typedef (struct type *type)
TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
TYPE_TARGET_STUB (type) = 0;
}
+ TYPE_DYNAMIC (type) = 0;
}
type = make_qualified_type (type, instance_flags, NULL);
2013-02-18 17:14:00 +00:00
@@ -3384,33 +3519,42 @@ type_pair_eq (const void *item_lhs, const void *item_rhs)
2013-01-19 22:41:55 +00:00
}
/* 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)
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ /* 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);
2012-07-03 18:54:05 +00:00
+ }
2013-01-19 22:41:55 +00:00
+ else
2012-07-03 18:54:05 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ /* 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);
2010-11-17 02:58:16 +00:00
+ }
}
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
-/* 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. */
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
-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;
2010-07-22 10:49:58 +00:00
2010-11-17 02:58:16 +00:00
- 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;
2013-02-18 17:14:00 +00:00
@@ -3425,9 +3569,10 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
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. */
2011-01-07 08:47:27 +00:00
- stored
- = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair));
2010-11-17 02:58:16 +00:00
+ 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;
2013-02-18 17:14:00 +00:00
@@ -3438,6 +3583,21 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
TYPE_OBJFILE_OWNED (new_type) = 0;
TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
2011-03-05 12:24:53 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+ /* 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);
2011-03-05 12:24:53 +00:00
+#endif
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* 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;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
if (TYPE_NAME (type))
TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type));
if (TYPE_TAG_NAME (type))
2013-02-18 17:14:00 +00:00
@@ -3446,12 +3606,48 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type);
TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
+ if (TYPE_ALLOCATED (new_type))
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ gdb_assert (!TYPE_NOT_ALLOCATED (new_type));
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (!dwarf_locexpr_baton_eval (TYPE_ALLOCATED (new_type)))
+ TYPE_NOT_ALLOCATED (new_type) = 1;
+ TYPE_ALLOCATED (new_type) = NULL;
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (TYPE_ASSOCIATED (new_type))
+ {
+ gdb_assert (!TYPE_NOT_ASSOCIATED (new_type));
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (!dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (new_type)))
+ TYPE_NOT_ASSOCIATED (new_type) = 1;
+ TYPE_ASSOCIATED (new_type) = NULL;
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ if (!TYPE_DATA_LOCATION_IS_ADDR (new_type)
+ && TYPE_DATA_LOCATION_DWARF_BLOCK (new_type))
+ {
+ if (TYPE_NOT_ALLOCATED (new_type)
+ || TYPE_NOT_ASSOCIATED (new_type))
+ TYPE_DATA_LOCATION_DWARF_BLOCK (new_type) = NULL;
+ else
2010-07-22 10:49:58 +00:00
+ {
2010-11-17 02:58:16 +00:00
+ 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));
2010-07-22 10:49:58 +00:00
+ }
+ }
+
2010-11-17 02:58:16 +00:00
/* 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);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
nfields = TYPE_NFIELDS (type);
+ TYPE_NFIELDS (new_type) = nfields;
TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
for (i = 0; i < nfields; i++)
{
2013-02-18 17:14:00 +00:00
@@ -3460,8 +3656,8 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
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));
2013-02-18 17:14:00 +00:00
@@ -3492,24 +3688,184 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
}
}
+ /* Both FIELD_LOC_KIND_DWARF_BLOCK and TYPE_RANGE_HIGH_BOUND_IS_COUNT were
+ possibly converted. */
+ TYPE_DYNAMIC (new_type) = 0;
2010-07-22 10:49:58 +00:00
+
2011-01-17 15:31:43 +00:00
/* For range types, copy the bounds information. */
2010-11-17 02:58:16 +00:00
- 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);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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
2011-01-17 15:31:43 +00:00
+ {
+ TYPE_LOW_BOUND (new_type) = dwarf_locexpr_baton_eval
2010-11-17 02:58:16 +00:00
+ (TYPE_RANGE_DATA (new_type)->low.u.dwarf_block);
2011-01-17 15:31:43 +00:00
+ if (TYPE_LOW_BOUND (new_type) >= 0)
+ TYPE_UNSIGNED (new_type) = 1;
+ }
2010-11-17 02:58:16 +00:00
+ TYPE_RANGE_DATA (new_type)->low.kind = RANGE_BOUND_KIND_CONSTANT;
+ break;
+ case RANGE_BOUND_KIND_DWARF_LOCLIST:
+ {
+ CORE_ADDR addr;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* `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))
2011-01-17 15:31:43 +00:00
+ {
+ TYPE_LOW_BOUND (new_type) = addr;
+ if (TYPE_LOW_BOUND (new_type) >= 0)
+ TYPE_UNSIGNED (new_type) = 1;
+ }
2010-11-17 02:58:16 +00:00
+ 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;
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* `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;
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ 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;
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* `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;
+ }
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* 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);
2011-01-17 15:31:43 +00:00
+
+ 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));
+ }
+
2010-11-17 02:58:16 +00:00
/* Maybe copy the type_specific bits.
NOTE drow/2005-12-09: We do not copy the C++-specific bits like
2013-02-18 17:14:00 +00:00
@@ -3526,6 +3882,17 @@ copy_type_recursive (struct objfile *objfile,
2010-11-17 02:58:16 +00:00
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. */
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+struct type *
+copy_type_recursive (struct type *type,
+ htab_t copied_types)
+{
+ return copy_type_recursive_1 (TYPE_OBJFILE (type), type, copied_types);
2010-07-22 10:49:58 +00:00
+}
+
2010-11-17 02:58:16 +00:00
/* Make a copy of the given TYPE, except that the pointer & reference
types are not preserved.
2013-02-18 17:14:00 +00:00
@@ -4090,6 +4457,13 @@ void
2010-11-17 02:58:16 +00:00
_initialize_gdbtypes (void)
{
gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init);
2010-01-16 22:32:10 +00:00
+
2011-03-05 12:24:53 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+ type_discardable_table = htab_create_alloc (20, type_discardable_hash,
+ type_discardable_equal, NULL,
+ xcalloc, xfree);
2011-03-05 12:24:53 +00:00
+#endif
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
objfile_type_data = register_objfile_data ();
2013-01-19 22:41:55 +00:00
add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug,
2012-01-03 15:00:12 +00:00
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
2013-02-18 17:14:00 +00:00
index 0ca7a87..c6029dc 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
2013-01-19 22:41:55 +00:00
@@ -226,6 +226,11 @@ enum type_instance_flag_value
2010-11-17 02:58:16 +00:00
#define TYPE_TARGET_STUB(t) (TYPE_MAIN_TYPE (t)->flag_target_stub)
+/* Type needs to be evaluated on each CHECK_TYPEDEF and its results must not be
+ sticky. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_DYNAMIC(t) (TYPE_MAIN_TYPE (t)->flag_dynamic)
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
/* Static type. If this is set, the corresponding type had
2011-01-17 15:31:43 +00:00
a static modifier.
Note: This may be unnecessary, since static data members
2013-01-19 22:41:55 +00:00
@@ -309,6 +314,50 @@ enum type_instance_flag_value
2010-11-17 02:58:16 +00:00
2012-01-20 23:27:28 +00:00
#define TYPE_FLAG_ENUM(t) (TYPE_MAIN_TYPE (t)->flag_flag_enum)
2010-11-17 02:58:16 +00:00
2011-03-05 12:24:53 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+/* 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. */
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_DISCARDABLE(t) (TYPE_MAIN_TYPE (t)->flag_discardable)
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
+/* 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. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_DISCARDABLE_AGE(t) (TYPE_MAIN_TYPE (t)->flag_discardable_age)
2011-03-05 12:24:53 +00:00
+#endif
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+/* Is HIGH_BOUND a low-bound relative count (1) or the high bound itself (0)? */
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_RANGE_HIGH_BOUND_IS_COUNT(range_type) \
+ (TYPE_MAIN_TYPE (range_type)->flag_range_high_bound_is_count)
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+/* 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. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_NOT_ALLOCATED(t) (TYPE_MAIN_TYPE (t)->flag_not_allocated)
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+/* 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. */
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_NOT_ASSOCIATED(t) (TYPE_MAIN_TYPE (t)->flag_not_associated)
+
+/* 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. */
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
+#define TYPE_DATA_LOCATION_IS_ADDR(t) \
+ (TYPE_MAIN_TYPE (t)->flag_data_location_is_addr)
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
/* Constant type. If this is set, the corresponding type has a
2011-01-17 15:31:43 +00:00
const modifier. */
2013-01-19 22:41:55 +00:00
@@ -425,6 +474,15 @@ struct main_type
2010-11-17 02:58:16 +00:00
/* True if this type was declared with "class" rather than
"struct". */
unsigned int flag_declared_class : 1;
2011-03-05 12:24:53 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+ unsigned int flag_discardable : 1;
+ unsigned int flag_discardable_age : 1;
2011-03-05 12:24:53 +00:00
+#endif
2010-11-17 02:58:16 +00:00
+ 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;
2012-01-20 23:27:28 +00:00
/* True if this is an enum type with disjoint values. This affects
how the enum is printed. */
2013-01-19 22:41:55 +00:00
@@ -505,6 +563,20 @@ struct main_type
2010-11-17 02:58:16 +00:00
struct type *target_type;
+ /* For DW_AT_data_location. */
+ union
+ {
+ struct dwarf2_locexpr_baton *dwarf_block;
+ CORE_ADDR addr;
+ }
+ data_location;
2010-07-21 21:30:20 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* For DW_AT_allocated. */
+ struct dwarf2_locexpr_baton *allocated;
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+ /* For DW_AT_associated. */
+ struct dwarf2_locexpr_baton *associated;
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
/* 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.
2013-01-19 22:41:55 +00:00
@@ -587,13 +659,34 @@ struct main_type
2010-11-17 02:58:16 +00:00
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;
+ }
2011-01-17 15:31:43 +00:00
/* Low bound of range. */
2010-11-17 02:58:16 +00:00
-
- LONGEST low;
-
+ low,
2011-01-17 15:31:43 +00:00
/* High bound of range. */
2010-11-17 02:58:16 +00:00
-
- LONGEST high;
+ high,
2011-01-17 15:31:43 +00:00
+ /* Byte stride of range. */
2010-11-17 02:58:16 +00:00
+ byte_stride;
/* Flags indicating whether the values of low and high are
valid. When true, the respective range value is
2013-01-19 22:41:55 +00:00
@@ -1053,9 +1146,9 @@ extern void allocate_gnat_aux_type (struct type *);
2010-11-17 02:58:16 +00:00
#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
2013-01-19 22:41:55 +00:00
@@ -1063,11 +1156,16 @@ extern void allocate_gnat_aux_type (struct type *);
2010-11-17 02:58:16 +00:00
#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) \
2013-01-19 22:41:55 +00:00
@@ -1084,7 +1182,14 @@ extern void allocate_gnat_aux_type (struct type *);
2010-11-17 02:58:16 +00:00
(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))
2009-08-04 05:37:29 +00:00
+
2010-11-17 02:58:16 +00:00
+/* 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++ */
2013-01-19 22:41:55 +00:00
@@ -1529,6 +1634,18 @@ extern struct type *create_array_type (struct type *, struct type *,
2010-11-17 02:58:16 +00:00
struct type *);
2013-01-19 22:41:55 +00:00
extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST);
2010-11-17 02:58:16 +00:00
+extern CORE_ADDR type_range_any_field_internal (struct type *range_type,
+ int fieldno);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+extern int type_range_high_bound_internal (struct type *range_type);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+extern int type_range_count_bound_internal (struct type *range_type);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+extern CORE_ADDR type_range_byte_stride_internal (struct type *range_type,
+ struct type *element_type);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
+extern void finalize_type (struct type *type);
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
extern struct type *create_string_type (struct type *, struct type *,
struct type *);
2013-01-19 22:41:55 +00:00
extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);
@@ -1574,6 +1691,10 @@ extern int is_public_ancestor (struct type *, struct type *);
2010-11-17 02:58:16 +00:00
extern int is_unique_ancestor (struct type *, struct value *);
2011-03-05 12:24:53 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+extern void type_mark_used (struct type *type);
2011-03-05 12:24:53 +00:00
+#endif
2010-07-22 10:49:58 +00:00
+
2010-11-17 02:58:16 +00:00
/* Overload resolution */
#define LENGTH_MATCH(bv) ((bv)->rank[0])
2013-01-19 22:41:55 +00:00
@@ -1652,8 +1773,7 @@ extern void maintenance_print_type (char *, int);
2010-11-17 02:58:16 +00:00
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);
2012-06-03 17:40:44 +00:00
diff --git a/gdb/main.c b/gdb/main.c
2013-02-18 17:14:00 +00:00
index 06f3feb..141a01b 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -37,6 +37,7 @@
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
#include "interps.h"
#include "main.h"
+#include "python/python.h"
#include "source.h"
#include "cli/cli-cmds.h"
#include "python/python.h"
2013-01-19 22:41:55 +00:00
@@ -314,6 +315,8 @@ captured_main (void *data)
2012-06-03 17:40:44 +00:00
char *cdarg = NULL;
char *ttyarg = NULL;
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
+ int python_script = 0;
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
/* These are static so that we can take their address in an
initializer. */
static int print_help;
2013-02-18 17:14:00 +00:00
@@ -504,10 +507,14 @@ captured_main (void *data)
2012-08-01 19:40:12 +00:00
{"args", no_argument, &set_args, 1},
{"l", required_argument, 0, 'l'},
2012-06-03 17:40:44 +00:00
{"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}
};
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
- while (1)
+ while (!python_script)
{
int option_index;
2012-01-03 15:00:12 +00:00
2013-02-18 17:14:00 +00:00
@@ -525,6 +532,9 @@ captured_main (void *data)
2012-06-03 17:40:44 +00:00
case 0:
/* Long option that just sets a flag. */
break;
+ case 'P':
+ python_script = 1;
+ break;
case OPT_SE:
symarg = optarg;
execarg = optarg;
2013-02-18 17:14:00 +00:00
@@ -733,7 +743,31 @@ captured_main (void *data)
2010-11-17 02:58:16 +00:00
2012-06-03 17:40:44 +00:00
/* 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)
2012-01-03 15:00:12 +00:00
+ {
2012-06-03 17:40:44 +00:00
+ /* The first argument is a python script to evaluate, and
+ subsequent arguments are passed to the script for
+ processing there. */
+ if (optind >= argc)
2011-01-01 00:27:30 +00:00
+ {
2012-06-03 17:40:44 +00:00
+ fprintf_unfiltered (gdb_stderr,
+ _("%s: Python script file name required\n"),
+ argv[0]);
+ exit (1);
2012-01-03 15:00:12 +00:00
+ }
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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;
2012-01-03 15:00:12 +00:00
+ }
2012-06-03 17:40:44 +00:00
+ 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
2013-02-18 17:14:00 +00:00
@@ -1013,7 +1047,8 @@ captured_main (void *data)
2010-11-17 02:58:16 +00:00
2012-06-03 17:40:44 +00:00
/* Read in the old history after all the command files have been
read. */
- init_history ();
+ if (!python_script)
+ init_history ();
2011-01-01 00:27:30 +00:00
2012-06-03 17:40:44 +00:00
if (batch_flag)
2011-01-01 00:27:30 +00:00
{
2013-02-18 17:14:00 +00:00
@@ -1024,13 +1059,25 @@ captured_main (void *data)
2012-06-03 17:40:44 +00:00
/* Show time and/or space usage. */
do_cleanups (pre_stat_chain);
2011-01-01 00:27:30 +00:00
2012-06-03 17:40:44 +00:00
- /* 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);
+ }
2012-01-03 15:00:12 +00:00
}
2012-06-03 17:40:44 +00:00
/* No exit -- exit is through quit_command. */
2012-01-03 15:00:12 +00:00
}
2013-02-18 17:14:00 +00:00
@@ -1062,7 +1109,12 @@ print_gdb_help (struct ui_file *stream)
2012-06-03 17:40:44 +00:00
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 (_("\
2013-02-18 17:14:00 +00:00
@@ -1104,7 +1156,13 @@ Options:\n\n\
2013-01-19 22:41:55 +00:00
fputs_unfiltered (_(" files.\n\
--nh Do not read "), stream);
2012-06-03 17:40:44 +00:00
fputs_unfiltered (gdbinit, stream);
2013-01-19 22:41:55 +00:00
- fputs_unfiltered (_(" file from home directory.\n\
+ fputs_unfiltered (_(" file from home directory.\n"), stream);
2012-06-03 17:40:44 +00:00
+#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/p-valprint.c b/gdb/p-valprint.c
2013-01-19 22:41:55 +00:00
index bcc055e..8a9d645 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
2013-01-19 22:41:55 +00:00
@@ -38,6 +38,7 @@
2012-06-03 17:40:44 +00:00
#include "cp-abi.h"
#include "cp-support.h"
#include "exceptions.h"
+#include "dwarf2loc.h"
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
/* Decorations for Pascal. */
2013-01-19 22:41:55 +00:00
@@ -73,8 +74,31 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
2012-06-03 17:40:44 +00:00
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)
2012-01-03 15:00:12 +00:00
+ {
2012-06-03 17:40:44 +00:00
+ fputs_filtered (object_address_data_not_valid (saved_type), stream);
+ gdb_flush (stream);
+ do_cleanups (back_to);
+ return;
2012-01-03 15:00:12 +00:00
+ }
2012-06-03 17:40:44 +00:00
+ if (address != saved_address + embedded_offset)
+ {
+ size_t length = TYPE_LENGTH (type);
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
- 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:
2013-01-19 22:41:55 +00:00
@@ -130,8 +154,8 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
2012-06-03 17:40:44 +00:00
{
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, "}");
}
2013-01-19 22:41:55 +00:00
@@ -169,6 +193,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
2012-06-03 17:40:44 +00:00
{
/* Try to print what function it points to. */
print_address_demangle (options, gdbarch, addr, stream, demangle);
+ do_cleanups (back_to);
return;
}
2012-01-03 15:00:12 +00:00
2013-01-19 22:41:55 +00:00
@@ -270,6 +295,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
2012-06-03 17:40:44 +00:00
}
}
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
+ do_cleanups (back_to);
return;
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
case TYPE_CODE_REF:
2013-01-19 22:41:55 +00:00
@@ -410,6 +436,7 @@ pascal_val_print (struct type *type, const gdb_byte *valaddr,
2012-06-03 17:40:44 +00:00
TYPE_CODE (type));
}
gdb_flush (stream);
+ do_cleanups (back_to);
}
void
diff --git a/gdb/parse.c b/gdb/parse.c
2013-01-19 22:41:55 +00:00
index 09c378b..93c434f 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/parse.c
+++ b/gdb/parse.c
2013-01-19 22:41:55 +00:00
@@ -1757,6 +1757,7 @@ parser_fprintf (FILE *x, const char *y, ...)
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
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)
2013-01-19 22:41:55 +00:00
@@ -1796,7 +1797,7 @@ operator_check_standard (struct expression *exp, int pos,
2012-06-03 17:40:44 +00:00
struct type *type = elts[pos + 2 + arg].type;
struct objfile *objfile = TYPE_OBJFILE (type);
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
- if (objfile && (*objfile_func) (objfile, data))
+ if (objfile && objfile_func && (*objfile_func) (objfile, data))
return 1;
2011-03-20 20:44:20 +00:00
}
2012-06-03 17:40:44 +00:00
}
2013-01-19 22:41:55 +00:00
@@ -1814,7 +1815,8 @@ operator_check_standard (struct expression *exp, int pos,
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
/* 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;
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
/* Check objfile where is placed the code touching the variable. */
2013-01-19 22:41:55 +00:00
@@ -1827,24 +1829,27 @@ operator_check_standard (struct expression *exp, int pos,
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
/* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL. */
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
- 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;
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
return 0;
2011-03-20 20:44:20 +00:00
}
2012-06-03 17:40:44 +00:00
-/* 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. */
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
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)
{
2013-01-19 22:41:55 +00:00
@@ -1859,7 +1864,9 @@ exp_iterate (struct expression *exp,
2011-03-20 20:44:20 +00:00
2012-06-03 17:40:44 +00:00
pos = endpos - oplen;
if (exp->language_defn->la_exp_desc->operator_check (exp, pos,
- objfile_func, data))
+ type_func,
+ objfile_func,
+ data))
return 1;
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
endpos = pos;
2013-01-19 22:41:55 +00:00
@@ -1890,8 +1897,29 @@ exp_uses_objfile (struct expression *exp, struct objfile *objfile)
2012-06-03 17:40:44 +00:00
{
gdb_assert (objfile->separate_debug_objfile_backlink == NULL);
2010-11-17 02:58:16 +00:00
2012-06-03 17:40:44 +00:00
- 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. */
2010-07-22 10:49:58 +00:00
+
2012-06-03 17:40:44 +00:00
+#if 0
2010-11-17 02:58:16 +00:00
+static int
2012-06-03 17:40:44 +00:00
+exp_types_mark_used_iter (struct type *type, void *unused)
2009-08-04 05:37:29 +00:00
+{
2012-06-03 17:40:44 +00:00
+ type_mark_used (type);
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* Continue the traversal. */
+ return 0;
2012-01-03 15:00:12 +00:00
+}
2010-07-22 10:49:58 +00:00
+
2012-06-03 17:40:44 +00:00
+/* Call type_mark_used for any type contained in EXP. */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+exp_types_mark_used (struct expression *exp)
2012-01-03 15:00:12 +00:00
+{
2012-06-03 17:40:44 +00:00
+ 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
2013-01-19 22:41:55 +00:00
index 8d25311..233ed46 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
2013-01-19 22:41:55 +00:00
@@ -244,6 +244,8 @@ extern void operator_length_standard (const struct expression *, int, int *,
2012-06-03 17:40:44 +00:00
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);
2013-01-19 22:41:55 +00:00
@@ -330,6 +332,7 @@ struct exp_descriptor
2012-06-03 17:40:44 +00:00
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);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
2013-02-18 17:14:00 +00:00
index 155703d..545a615 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
2013-02-18 17:14:00 +00:00
@@ -51,6 +51,7 @@
2012-06-03 17:40:44 +00:00
#include "cli/cli-utils.h"
2012-07-03 18:54:05 +00:00
#include "format.h"
2013-02-18 17:14:00 +00:00
#include "source.h"
2012-06-03 17:40:44 +00:00
+#include "dwarf2loc.h"
#ifdef TUI
#include "tui/tui.h" /* For tui_active et al. */
2013-02-18 17:14:00 +00:00
@@ -967,6 +968,11 @@ print_command_1 (char *exp, int voidprint)
2012-06-03 17:40:44 +00:00
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. */
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
if (voidprint || (val && value_type (val) &&
TYPE_CODE (value_type (val)) != TYPE_CODE_VOID))
{
2013-02-18 17:14:00 +00:00
@@ -1039,6 +1045,9 @@ output_command (char *exp, int from_tty)
2012-06-03 17:40:44 +00:00
val = evaluate_expression (expr);
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
+ if (VALUE_LVAL (val) == lval_memory)
+ object_address_set (value_raw_address (val));
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
annotate_value_begin (value_type (val));
get_formatted_print_options (&opts, format);
2013-02-18 17:14:00 +00:00
@@ -1467,6 +1476,24 @@ x_command (char *exp, int from_tty)
2012-06-03 17:40:44 +00:00
set_internalvar (lookup_internalvar ("__"), last_examine_value);
}
}
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+#if 0
+/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
+static void
+print_types_mark_used (void)
+{
+ struct display *d;
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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
+
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
/* Add an expression to the auto-display chain.
2013-02-18 17:14:00 +00:00
@@ -1964,6 +1991,10 @@ print_variable_and_value (const char *name, struct symbol *var,
2012-06-03 17:40:44 +00:00
struct value_print_options opts;
2012-01-03 15:00:12 +00:00
2012-06-03 17:40:44 +00:00
val = read_var_value (var, frame);
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ make_cleanup_restore_selected_frame ();
+ select_frame (frame);
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
get_user_print_options (&opts);
opts.deref_ref = 1;
common_val_print (val, stream, indent, &opts, current_language);
2013-02-18 17:14:00 +00:00
@@ -2613,4 +2644,8 @@ Show printing of source filename and line number with <symbol>."), NULL,
2012-06-03 17:40:44 +00:00
add_com ("eval", no_class, eval_command, _("\
Convert \"printf format string\", arg1, arg2, arg3, ..., argn to\n\
a command line, and call it."));
2010-07-22 10:49:58 +00:00
+
2013-01-19 22:41:55 +00:00
+#if 0
+ observer_attach_mark_used (print_types_mark_used);
+#endif
2012-07-03 18:54:05 +00:00
}
2012-06-03 17:40:44 +00:00
diff --git a/gdb/python/lib/gdb/command/ignore_errors.py b/gdb/python/lib/gdb/command/ignore_errors.py
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..6fa48ff
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/python/lib/gdb/command/ignore_errors.py
@@ -0,0 +1,37 @@
+# Ignore errors in user commands.
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+# Copyright (C) 2008 Free Software Foundation, Inc.
2011-01-07 08:47:27 +00:00
+
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+import gdb
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+class IgnoreErrorsCommand (gdb.Command):
+ """Execute a single command, ignoring all errors.
+Only one-line commands are supported.
+This is primarily useful in scripts."""
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ def __init__ (self):
+ super (IgnoreErrorsCommand, self).__init__ ("ignore-errors",
+ gdb.COMMAND_OBSCURE,
+ # FIXME...
+ gdb.COMPLETE_COMMAND)
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2013-01-19 22:41:55 +00:00
index 0000000..636f99d
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/python/lib/gdb/command/pahole.py
2013-01-19 22:41:55 +00:00
@@ -0,0 +1,81 @@
2012-06-03 17:40:44 +00:00
+# pahole command for gdb
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+# Copyright (C) 2008, 2009, 2012 Free Software Foundation, Inc.
2011-01-07 08:47:27 +00:00
+
+# 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
+
2012-06-03 17:40:44 +00:00
+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."""
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ def __init__ (self):
+ super (Pahole, self).__init__ ("pahole", gdb.COMMAND_NONE,
+ gdb.COMPLETE_SYMBOL)
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ def maybe_print_hole(self, bitpos, field_bitpos):
+ if bitpos != field_bitpos:
+ hole = field_bitpos - bitpos
+ print ' /* XXX %d bit hole, try to pack */' % hole
+
2012-06-03 17:40:44 +00:00
+ 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
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ ftype = field.type.strip_typedefs()
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ self.maybe_print_hole(bitpos, field.bitpos)
+ bitpos = field.bitpos
2012-06-03 17:40:44 +00:00
+ if field.bitsize > 0:
+ fieldsize = field.bitsize
+ else:
+ # TARGET_CHAR_BIT here...
+ fieldsize = 8 * ftype.sizeof
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ # TARGET_CHAR_BIT
+ print ' /* %3d %3d */' % (int (bitpos / 8), int (fieldsize / 8)),
+ bitpos = bitpos + fieldsize
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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)
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ if level == 0:
+ self.maybe_print_hole(bitpos, 8 * type.sizeof)
+
2012-06-03 17:40:44 +00:00
+ print ' ' * (14 + 2 * level),
+ print '} %s' % name
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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, '')
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+Pahole()
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.
2011-01-07 08:47:27 +00:00
+
+# 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
2012-06-03 17:40:44 +00:00
+import re
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+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."""
2011-01-07 08:47:27 +00:00
+
+ def __init__ (self):
2012-06-03 17:40:44 +00:00
+ super (CallerIs, self).__init__ ("caller_is")
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ def invoke (self, name, nframes = 1):
+ frame = gdb.selected_frame ()
+ while nframes > 0:
+ frame = frame.older ()
+ nframes = nframes - 1
+ return frame.name () == name.string ()
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+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."""
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ def __init__ (self):
+ super (CallerMatches, self).__init__ ("caller_matches")
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+CallerIs()
+CallerMatches()
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..debb3bb
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -0,0 +1,47 @@
+# In-scope function.
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+# Copyright (C) 2008 Free Software Foundation, Inc.
2011-01-07 08:47:27 +00:00
+
+# 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
+
2012-06-03 17:40:44 +00:00
+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."""
2011-01-07 08:47:27 +00:00
+
+ def __init__ (self):
2012-06-03 17:40:44 +00:00
+ super (InScope, self).__init__ ("in_scope")
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ def invoke (self, *vars):
+ if len (vars) == 0:
+ raise TypeError, "in_scope takes at least one argument"
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ # 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)
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ block = block.superblock
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ return wanted == found
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+InScope ()
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
2013-02-18 17:14:00 +00:00
index 051cff0..e2f2ebe 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
2013-01-19 22:41:55 +00:00
@@ -31,6 +31,8 @@
2012-06-03 17:40:44 +00:00
#include "bcache.h"
#include "dwarf2loc.h"
2013-01-19 22:41:55 +00:00
#include "typeprint.h"
2012-06-03 17:40:44 +00:00
+#include "observer.h"
+#include "gdb_assert.h"
typedef struct pyty_type_object
{
2013-01-19 22:41:55 +00:00
@@ -39,11 +41,19 @@ typedef struct pyty_type_object
2012-06-03 17:40:44 +00:00
/* 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.
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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;
2013-01-19 22:41:55 +00:00
+#if 0
+/* First element of a doubly-linked list of TYPE_DISCARDABLE Types. */
+static type_object *pyty_objects_discardable;
+#endif
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
static PyTypeObject type_object_type;
/* A Field object. */
@@ -1192,8 +1202,63 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
+/* 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)
2012-06-03 17:40:44 +00:00
+{
2013-01-19 22:41:55 +00:00
+ type_obj->prev = NULL;
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ if (type_obj->type && TYPE_OBJFILE (type_obj->type))
+ {
+ struct objfile *objfile = TYPE_OBJFILE (type_obj->type);
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ 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))
2012-06-03 17:40:44 +00:00
+ {
2013-01-19 22:41:55 +00:00
+ type_obj->next = pyty_objects_discardable;
+ if (type_obj->next)
+ type_obj->next->prev = type_obj;
+ pyty_objects_discardable = type_obj;
2012-06-03 17:40:44 +00:00
+ }
2013-01-19 22:41:55 +00:00
+#endif
+ else
+ type_obj->next = NULL;
2012-06-03 17:40:44 +00:00
+}
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+/* 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);
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ 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
2011-01-07 08:47:27 +00:00
+
2013-01-19 22:41:55 +00:00
+ if (type_obj->next)
+ type_obj->next->prev = type_obj->prev;
+}
+
static void
save_objfile_types (struct objfile *objfile, void *datum)
{
@@ -1211,12 +1276,13 @@ save_objfile_types (struct objfile *objfile, void *datum)
2012-07-03 18:54:05 +00:00
{
2013-01-19 22:41:55 +00:00
type_object *next = obj->next;
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
- htab_empty (copied_types);
+ gdb_assert (TYPE_OBJFILE (obj->type) == objfile);
+ typy_unlink (obj);
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
- obj->type = copy_type_recursive (objfile, obj->type, copied_types);
+ obj->type = copy_type_recursive (obj->type, copied_types);
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
- obj->next = NULL;
- obj->prev = NULL;
+ gdb_assert (TYPE_OBJFILE (obj->type) == NULL);
+ typy_link (obj);
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
obj = next;
2012-07-03 18:54:05 +00:00
}
2013-01-19 22:41:55 +00:00
@@ -1227,43 +1293,28 @@ save_objfile_types (struct objfile *objfile, void *datum)
2012-07-03 18:54:05 +00:00
}
2013-01-19 22:41:55 +00:00
static void
-set_type (type_object *obj, struct type *type)
+typy_dealloc (PyObject *obj)
2012-07-03 18:54:05 +00:00
{
2013-01-19 22:41:55 +00:00
- obj->type = type;
- obj->prev = NULL;
- if (type && TYPE_OBJFILE (type))
- {
- struct objfile *objfile = TYPE_OBJFILE (type);
+ type_object *type_obj = (type_object *) obj;
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
- 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);
2012-08-01 19:40:12 +00:00
+
2013-01-19 22:41:55 +00:00
+ type_obj->ob_type->tp_free (obj);
2012-08-01 19:40:12 +00:00
}
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
+#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;
2012-07-03 18:54:05 +00:00
-
2013-01-19 22:41:55 +00:00
- 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);
2012-07-03 18:54:05 +00:00
-
2013-01-19 22:41:55 +00:00
- if (objfile)
- set_objfile_data (objfile, typy_objfile_data_key, type->next);
- }
- if (type->next)
- type->next->prev = type->prev;
+ type_object *type_obj;
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
- Py_TYPE (type)->tp_free (type);
+ for (type_obj = pyty_objects_discardable;
+ type_obj != NULL;
+ type_obj = type_obj->next)
+ type_mark_used (type_obj->type);
2012-07-03 18:54:05 +00:00
}
2013-01-19 22:41:55 +00:00
+#endif
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
/* Return number of fields ("length" of the field dictionary). */
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
@@ -1483,7 +1534,10 @@ type_to_type_object (struct type *type)
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
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);
+ }
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
return (PyObject *) type_obj;
}
@@ -1563,6 +1617,10 @@ gdbpy_initialize_types (void)
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
Py_INCREF (&field_object_type);
PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
+
+#if 0
+ observer_attach_mark_used (typy_types_mark_used);
+#endif
}
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 11cc038..ef238f6 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"
2012-08-01 19:40:12 +00:00
2013-01-19 22:41:55 +00:00
#ifdef HAVE_PYTHON
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
@@ -1385,6 +1386,19 @@ gdbpy_is_value_object (PyObject *obj)
return PyObject_TypeCheck (obj, &value_object_type);
2012-07-03 18:54:05 +00:00
}
2013-01-19 22:41:55 +00:00
+#if 0
+/* 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));
+}
+#endif
+
void
gdbpy_initialize_values (void)
{
@@ -1395,6 +1409,10 @@ gdbpy_initialize_values (void)
PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
values_in_python = NULL;
+
+#if 0
+ observer_attach_mark_used (python_types_mark_used);
+#endif
}
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
diff --git a/gdb/python/python.c b/gdb/python/python.c
2013-03-10 16:12:43 +00:00
index cd8ddfb..e906c4f 100644
2013-01-19 22:41:55 +00:00
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
2013-03-10 16:12:43 +00:00
@@ -67,6 +67,8 @@ static const char *gdbpy_should_print_stack = python_excp_message;
2013-01-19 22:41:55 +00:00
#include "linespec.h"
#include "source.h"
#include "version.h"
+#include "inferior.h"
+#include "gdbthread.h"
#include "target.h"
#include "gdbthread.h"
#include "observer.h"
2013-03-10 16:12:43 +00:00
@@ -1099,6 +1101,53 @@ gdbpy_print_stack (void)
2012-07-03 18:54:05 +00:00
2013-01-19 22:41:55 +00:00
/* 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;
2012-08-01 19:40:12 +00:00
+
2013-01-19 22:41:55 +00:00
+ /* 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);
2012-08-01 19:40:12 +00:00
+ }
2013-01-19 22:41:55 +00:00
+ PyRun_SimpleFile (input, argv[0]);
+ fclose (input);
+ exit (0);
+}
+
+
+
static PyObject *
gdbpy_get_current_progspace (PyObject *unused1, PyObject *unused2)
2013-03-10 16:12:43 +00:00
@@ -1749,6 +1798,8 @@ static PyMethodDef GdbMethods[] =
2013-01-19 22:41:55 +00:00
"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 24e3077..0443087 100644
--- a/gdb/python/python.h
+++ b/gdb/python/python.h
@@ -34,6 +34,8 @@ void eval_python_from_control_command (struct command_line *);
2012-08-01 19:40:12 +00:00
2013-01-19 22:41:55 +00:00
void source_python_script (FILE *file, const char *filename);
2012-08-01 19:40:12 +00:00
2013-01-19 22:41:55 +00:00
+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,
2012-06-03 17:40:44 +00:00
diff --git a/gdb/stack.c b/gdb/stack.c
2013-03-10 16:12:43 +00:00
index f2aeb10..d20b2f1 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/stack.c
+++ b/gdb/stack.c
2013-03-10 16:12:43 +00:00
@@ -509,6 +509,10 @@ print_frame_args (struct symbol *func, struct frame_info *frame,
2012-06-03 17:40:44 +00:00
stb = mem_fileopen ();
old_chain = make_cleanup_ui_file_delete (stb);
2010-07-21 21:30:20 +00:00
2012-06-03 17:40:44 +00:00
+ /* Frame may be needed for check_typedef of TYPE_DYNAMIC. */
+ make_cleanup_restore_selected_frame ();
+ select_frame (frame);
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
if (func)
2010-07-21 21:30:20 +00:00
{
2012-06-03 17:40:44 +00:00
struct block *b = SYMBOL_BLOCK_VALUE (func);
diff --git a/gdb/testsuite/gdb.ada/packed_array.exp b/gdb/testsuite/gdb.ada/packed_array.exp
2013-01-19 22:41:55 +00:00
index e22cb3a..5e16186 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/testsuite/gdb.ada/packed_array.exp
+++ b/gdb/testsuite/gdb.ada/packed_array.exp
2013-01-19 22:41:55 +00:00
@@ -56,5 +56,11 @@ gdb_test_multiple "$test" "$test" {
2012-06-03 17:40:44 +00:00
# are. Observed with (FSF GNU Ada 4.5.3 20110124).
xfail $test
2010-07-21 21:30:20 +00:00
}
2012-06-03 17:40:44 +00:00
+ -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
2010-07-21 21:30:20 +00:00
+ }
}
2010-01-28 22:26:15 +00:00
2012-06-03 17:40:44 +00:00
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
2011-03-05 12:24:53 +00:00
+#endif
2012-06-03 17:40:44 +00:00
+ /* DW_AT_location: DW_FORM_block1: start */
+ .byte 0x3
+ .byte 0x91
+ .sleb128 -32
2011-03-05 12:24:53 +00:00
+#if 0
2012-06-03 17:40:44 +00:00
+ .byte 0x6 /* DW_OP_deref */
+#else
+ .byte 0x96 /* DW_OP_nop */
2011-03-05 12:24:53 +00:00
+#endif
2012-06-03 17:40:44 +00:00
+ /* 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..fe2c8f7
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.c
@@ -0,0 +1,43 @@
2010-07-21 21:30:20 +00:00
+/* This testcase is part of GDB, the GNU debugger.
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2009 Free Software Foundation, Inc.
2010-01-21 16:09:11 +00:00
+
2010-07-21 21:30:20 +00:00
+ 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.
2010-01-21 16:09:11 +00:00
+
2010-07-21 21:30:20 +00:00
+ 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.
2010-01-21 16:09:11 +00:00
+
2010-07-21 21:30:20 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+#if 0
2010-01-21 16:09:11 +00:00
+
2010-07-21 21:30:20 +00:00
+void
+foo (int size)
2010-01-21 16:09:11 +00:00
+{
2012-06-03 17:40:44 +00:00
+ typedef char array_t[size];
+ array_t array;
+ int i;
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+ for (i = 0; i < size; i++)
+ array[i] = i;
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+ array[0] = 0; /* break-here */
2010-07-21 21:30:20 +00:00
+}
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+#else
+
2010-01-21 16:09:11 +00:00
+int
2010-07-21 21:30:20 +00:00
+main (void)
+{
+ foo (26);
+ foo (78);
+ return 0;
2010-01-21 16:09:11 +00:00
+}
2012-06-03 17:40:44 +00:00
+
+#endif
diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..d243cf1
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.arch/x86_64-vla-pointer.exp
@@ -0,0 +1,66 @@
+# Copyright 2009 Free Software Foundation, Inc.
2010-01-21 16:09:11 +00:00
+
+# 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.
+#
2010-11-17 02:58:16 +00:00
+# 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/>.
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2010-11-17 02:58:16 +00:00
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
2012-06-03 17:40:44 +00:00
+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}] != "" } {
2010-11-17 02:58:16 +00:00
+ untested "Couldn't compile test program"
2010-07-21 21:30:20 +00:00
+ return -1
2010-01-21 16:09:11 +00:00
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
2010-11-17 02:58:16 +00:00
+if ![runto_main] {
2012-06-03 17:40:44 +00:00
+ untested x86_64-vla-pointer
2010-07-21 21:30:20 +00:00
+ return -1
2010-01-28 22:26:15 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+gdb_breakpoint "break_here"
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_continue_to_breakpoint "break_here"
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "first: whatis array"
+gdb_test "ptype array" "type = char \\(\\*\\)\\\[26\\\]" "first: ptype array"
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_test "whatis *array" "type = char \\\[26\\\]" "first: whatis *array"
+gdb_test "ptype *array" "type = char \\\[26\\\]" "first: ptype *array"
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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'"
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_continue_to_breakpoint "break_here"
2009-03-07 00:32:30 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_test "whatis array" "type = char \\(\\*\\)\\\[variable\\\]" "second: whatis array"
+gdb_test "ptype array" "type = char \\(\\*\\)\\\[78\\\]" "second: ptype array"
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..b809c4e
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.c
@@ -0,0 +1,43 @@
2010-07-11 18:06:33 +00:00
+/* This testcase is part of GDB, the GNU debugger.
+
2012-06-03 17:40:44 +00:00
+ Copyright 2008 Free Software Foundation, Inc.
2010-07-11 18:06:33 +00:00
+
+ 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/>. */
+
2012-06-03 17:40:44 +00:00
+#if 0
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+foo (int size)
+{
+ typedef char array_t[size];
+ array_t array;
+ int i;
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+ for (i = 0; i < size; i++)
+ array[i] = i;
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+ array[0] = 0; /* break-here */
+}
2010-07-21 21:30:20 +00:00
+
2012-06-03 17:40:44 +00:00
+#else
2011-01-25 21:51:27 +00:00
+
2012-06-03 17:40:44 +00:00
+int
+main (void)
+{
+ foo (26);
+ foo (78);
+ return 0;
+}
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+#endif
diff --git a/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..b05411e
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.arch/x86_64-vla-typedef.exp
@@ -0,0 +1,64 @@
+# Copyright 2009 Free Software Foundation, Inc.
2010-07-11 18:06:33 +00:00
+
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+# Test DW_AT_data_location accessed through DW_TAG_typedef intermediate.
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+if ![istarget "x86_64-*-*"] then {
+ verbose "Skipping over gdb.arch/x86_64-vla-typedef.exp test made only for x86_64."
+ return
2010-07-11 18:06:33 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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"
2010-07-11 18:06:33 +00:00
+ return -1
+}
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
2010-07-11 18:06:33 +00:00
+
2012-06-03 17:40:44 +00:00
+if ![runto_main] {
+ untested x86_64-vla-typedef
2010-07-11 18:06:33 +00:00
+ return -1
+}
+
2012-06-03 17:40:44 +00:00
+gdb_breakpoint "break_here"
2010-01-21 16:09:11 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_continue_to_breakpoint "break_here"
2011-01-25 21:51:27 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2013-01-19 22:41:55 +00:00
index 2cc935b..30c7f85 100644
2012-06-03 17:40:44 +00:00
--- 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
2013-01-19 22:41:55 +00:00
index 387b34f..d5956ce 100644
2012-06-03 17:40:44 +00:00
--- 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..eeb7b85
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/internal-var-field-address.c
@@ -0,0 +1,20 @@
2010-01-16 22:32:10 +00:00
+/* This testcase is part of GDB, the GNU debugger.
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2009 Free Software Foundation, Inc.
2009-03-02 00:11:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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
2012-06-03 17:40:44 +00:00
+ the Free Software Foundation; either version 3 of the License, or
2010-01-16 22:32:10 +00:00
+ (at your option) any later version.
2009-03-02 00:11:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2012-06-03 17:40:44 +00:00
+
2010-01-16 22:32:10 +00:00
+ You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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.
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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/>.
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2010-01-16 22:32:10 +00:00
+}
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+clean_restart $binfile
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+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.
+
+ 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/>. */
+
+#include <string.h>
2009-03-02 00:11:35 +00:00
+
+int
2012-06-03 17:40:44 +00:00
+main (int argc, char **argv)
2009-03-02 00:11:35 +00:00
+{
2012-06-03 17:40:44 +00:00
+ char s[2 + argc];
+ void (*f) (char *) = 0;
+
+ memset (s, 0, sizeof (s));
+ s[0] = 'X';
+
+ f (s);
2010-01-16 22:32:10 +00:00
+ return 0;
2009-03-02 00:11:35 +00:00
+}
2012-06-03 17:40:44 +00:00
diff --git a/gdb/testsuite/gdb.base/vla-frame.exp b/gdb/testsuite/gdb.base/vla-frame.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..47736c7
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/vla-frame.exp
@@ -0,0 +1,38 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
2009-03-02 00:11:35 +00:00
+# 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
2012-06-03 17:40:44 +00:00
+# the Free Software Foundation; either version 3 of the License, or
2009-03-02 00:11:35 +00:00
+# (at your option) any later version.
2012-06-03 17:40:44 +00:00
+#
2009-03-02 00:11:35 +00:00
+# 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.
2012-06-03 17:40:44 +00:00
+#
2009-03-02 00:11:35 +00:00
+# You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+set testfile vla-frame
+set executable ${testfile}
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [prepare_for_testing ${testfile}.exp ${executable}] } {
2010-01-16 22:32:10 +00:00
+ return -1
2009-08-04 05:37:29 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+if ![runto_main] {
+ return -1
2009-08-18 18:51:17 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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
+ }
2009-09-10 21:37:41 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..c5d5ee0
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/vla-overflow.c
@@ -0,0 +1,30 @@
2010-01-16 22:32:10 +00:00
+/* This testcase is part of GDB, the GNU debugger.
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2008 Free Software Foundation, Inc.
2009-08-10 13:22:51 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2009-08-10 13:22:51 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2009-08-10 13:22:51 +00:00
+
2010-01-16 22:32:10 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2009-08-10 13:22:51 +00:00
+
2012-06-03 17:40:44 +00:00
+#include <stdlib.h>
2009-08-18 18:51:17 +00:00
+
2012-06-03 17:40:44 +00:00
+int
+main (int argc, char **argv)
+{
+ int array[argc];
2009-08-18 18:51:17 +00:00
+
2012-06-03 17:40:44 +00:00
+ array[0] = array[0];
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ abort ();
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/vla-overflow.exp b/gdb/testsuite/gdb.base/vla-overflow.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..24a608f
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/vla-overflow.exp
@@ -0,0 +1,109 @@
+# Copyright 2008 Free Software Foundation, Inc.
2010-01-12 22:15:57 +00:00
+
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+# 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 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
2010-01-12 22:15:57 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+set f [open "|getconf PAGESIZE" "r"]
+gets $f pagesize
+close $f
2010-01-12 22:15:57 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2010-01-12 22:15:57 +00:00
+ return -1
+}
+
2012-06-03 17:40:44 +00:00
+# Get the GDB memory size when we stay at main.
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+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
+}
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+set pages_found [memory_v_pages_get]
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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"
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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]"
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_test "" "Program received signal SIGABRT, Aborted..*" "Enter abort()"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+verbose -log "kb_found in abort() = [expr [memory_v_pages_get] * $pagesize / 1024]"
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+# `abort' can get expressed as `*__GI_abort'.
+gdb_test "bt" "in \[^ \]*abort \\(.* in main \\(.*" "Backtrace after abort()"
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..e1f3ed1
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/vla.c
@@ -0,0 +1,55 @@
+/* This testcase is part of GDB, the GNU debugger.
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2008 Free Software Foundation, Inc.
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2009-09-03 19:45:38 +00:00
+
2012-06-03 17:40:44 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2009-08-10 13:22:51 +00:00
+
2012-06-03 17:40:44 +00:00
+#include <string.h>
2009-08-10 13:22:51 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+marker (void)
+{
+}
2009-08-10 13:22:51 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+bar (char *a, char *b, char *c, int size)
+{
+ memset (a, '1', size);
+ memset (b, '2', size);
+ memset (c, '3', 48);
+}
2009-08-10 13:22:51 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+foo (int size)
+{
+ char temp1[size];
+ char temp3[48];
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..5da7378
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.base/vla.exp
@@ -0,0 +1,62 @@
+# Copyright 2008 Free Software Foundation, Inc.
2011-01-01 00:27:30 +00:00
+
+# 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
2012-06-03 17:40:44 +00:00
+# the Free Software Foundation; either version 3 of the License, or
2011-01-01 00:27:30 +00:00
+# (at your option) any later version.
2012-06-03 17:40:44 +00:00
+#
2011-01-01 00:27:30 +00:00
+# 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.
2012-06-03 17:40:44 +00:00
+#
2011-01-01 00:27:30 +00:00
+# You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2011-01-01 00:27:30 +00:00
+ return -1
+}
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+if ![runto_main] {
+ untested vla
+ return -1
2011-01-01 00:27:30 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+gdb_breakpoint [gdb_get_line_number "break-here"]
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+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.dwarf2/dw2-bound-loclist.S b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..aac3baa
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.S
@@ -0,0 +1,246 @@
+/* This testcase is part of GDB, the GNU debugger.
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2010 Free Software Foundation, Inc.
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2009-08-11 18:07:06 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2009-08-11 18:07:06 +00:00
+
2012-06-03 17:40:44 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2009-08-11 18:07:06 +00:00
+
2012-06-03 17:40:44 +00:00
+/* Debug information */
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+/* We will `break *main' at the very first instruction. */
+#define main_length 1
2009-08-11 18:07:06 +00:00
+
2012-06-03 17:40:44 +00:00
+ .section .data
+vardata:
+ /* See DW_OP_lit3 + 1 (0-based). */
+ .string "seennotseen"
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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) */
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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 */
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+.Larray_type:
+ .uleb128 2 /* Abbrev: DW_TAG_array_type */
+ .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
2009-09-10 21:37:41 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* DW_AT_upper_bound is referencing register. */
+.Larrayreg_type:
+ .uleb128 2 /* Abbrev: DW_TAG_array_type */
+ .4byte .Lchar_type-.Lcu1_begin /* DW_AT_type */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+.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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+.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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+.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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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:
+
+ /* 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:
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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:
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .byte 0 /* End of children of CU */
+.Lcu1_end:
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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)
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
+
+ .byte 0x0 /* Terminator */
+
+/* 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..815ed93
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-bound-loclist.exp
@@ -0,0 +1,54 @@
+# Copyright 2010 Free Software Foundation, Inc.
2011-01-17 15:31:43 +00:00
+
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+# 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
2011-01-17 15:31:43 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2011-01-17 15:31:43 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+set testfile dw2-bound-loclist
+if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}.S main.c] {}] } {
+ return -1
2011-01-17 15:31:43 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+# Verify it behaves at least as an unbound array without inferior.
2011-02-18 10:25:34 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_test "p a_string" { = 0x[0-9a-f]+ "seennotseen"}
+gdb_test "ptype a_string" {type = char \[\]}
2011-02-18 10:25:34 +00:00
+
2012-06-03 17:40:44 +00:00
+# Not runto_main as dw2-bound-loclist.S handles only the first byte of main.
+if ![runto "*main"] {
+ return -1
2011-02-18 10:25:34 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+gdb_test "p a_string" { = "seen"}
+gdb_test "ptype a_string" {type = char \[4\]}
2011-01-17 15:31:43 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..1f02d90
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.c
@@ -0,0 +1,42 @@
+/* This testcase is part of GDB, the GNU debugger.
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2004 Free Software Foundation, Inc.
2011-03-20 20:44:20 +00:00
+
+ 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
2012-06-03 17:40:44 +00:00
+ the Free Software Foundation; either version 2 of the License, or
2011-03-20 20:44:20 +00:00
+ (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.
2012-06-03 17:40:44 +00:00
+
2011-03-20 20:44:20 +00:00
+ You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ USA. */
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+
+/* 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)
2011-03-20 20:44:20 +00:00
+{
2012-06-03 17:40:44 +00:00
+}
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+/* `func1' being traced into must have some arguments to dump. */
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+void
+func1(int a, int b)
+{
+ func0 (a,b);
+}
+
+int
+main(void)
+{
+ func1 (1, 2);
2011-03-20 20:44:20 +00:00
+ return 0;
+}
2012-06-03 17:40:44 +00:00
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..1c6e84a
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-stripped.exp
@@ -0,0 +1,79 @@
+# Copyright 2006 Free Software Foundation, Inc.
+
2011-03-20 20:44:20 +00:00
+# 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
2012-06-03 17:40:44 +00:00
+# the Free Software Foundation; either version 2 of the License, or
2011-03-20 20:44:20 +00:00
+# (at your option) any later version.
2012-06-03 17:40:44 +00:00
+#
2011-03-20 20:44:20 +00:00
+# 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.
2012-06-03 17:40:44 +00:00
+#
2011-03-20 20:44:20 +00:00
+# You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# Minimal DWARF-2 unit test
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2011-03-20 20:44:20 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+set testfile "dw2-stripped"
2011-03-20 20:44:20 +00:00
+set srcfile ${testfile}.c
2012-06-03 17:40:44 +00:00
+set binfile ${objdir}/${subdir}/${testfile}.x
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+remote_exec build "rm -f ${binfile}"
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# get the value of gcc_compiled
+if [get_compiler_info ${binfile}] {
+ return -1
+}
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# This test can only be run on gcc as we use additional_flags=FIXME
+if {$gcc_compiled == 0} {
+ return 0
+}
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-ggdb3}] != "" } {
+ return -1
+}
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+remote_exec build "objcopy -R .debug_loc ${binfile}"
+set strip_output [remote_exec build "objdump -h ${binfile}"]
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+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)"
2011-03-20 20:44:20 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+set test "stripping test file functionality"
+if [ regexp ".debug_loc " $strip_output] {
+ fail "$test (.debug_loc still present)"
+} else {
+ pass "$test (.debug_loc stripped)"
+}
2011-03-20 20:44:20 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# For C programs, "start" should stop in main().
+
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..5fcdd84
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.S
@@ -0,0 +1,83 @@
2011-01-01 00:27:30 +00:00
+/* This testcase is part of GDB, the GNU debugger.
+
2012-06-03 17:40:44 +00:00
+ Copyright 2009 Free Software Foundation, Inc.
2011-01-01 00:27:30 +00:00
+
+ 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/>. */
+
2012-06-03 17:40:44 +00:00
+/* Debug information */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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) */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+.Ltype_uchar:
+ .uleb128 2 /* Abbrev: DW_TAG_structure_type */
+ .ascii "some_struct\0" /* DW_AT_name */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ .uleb128 3 /* Abbrev: DW_TAG_member */
+ .ascii "field\0" /* DW_AT_name */
+ .byte 0 /* DW_AT_data_member_location */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ .byte 0 /* End of children of some_struct */
+
+ .byte 0 /* End of children of CU */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+.Lcu1_end:
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+/* 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 */
+
+ .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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..c41151c
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-struct-member-data-location.exp
@@ -0,0 +1,37 @@
+# Copyright 2009 Free Software Foundation, Inc.
+
2011-01-01 00:27:30 +00:00
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+# 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
2011-01-01 00:27:30 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+set testfile "dw2-struct-member-data-location"
+set srcfile ${testfile}.S
+set binfile ${testfile}.x
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objdir}/${subdir}/${binfile}" object {nodebug}] != "" } {
2011-01-01 00:27:30 +00:00
+ return -1
+}
+
2012-06-03 17:40:44 +00:00
+clean_restart $binfile
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..9dbbf3c
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.S
@@ -0,0 +1,121 @@
+/* This testcase is part of GDB, the GNU debugger.
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2012 Free Software Foundation, Inc.
2009-08-04 05:37:29 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2009-08-04 05:37:29 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2009-08-04 05:37:29 +00:00
+
2010-01-16 22:32:10 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+/* Debug information */
2009-08-04 05:37:29 +00:00
+
2012-06-03 17:40:44 +00:00
+ .section .data
+vardata:
+ .rept 129
+ .ascii "x"
+ .endr
+ .ascii "UNSEEN\0"
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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) */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ /* 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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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 */
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ .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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..a13e346
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.dwarf2/dw2-subrange-no-type.exp
@@ -0,0 +1,39 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
2010-01-16 22:32:10 +00:00
+# 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
2012-06-03 17:40:44 +00:00
+# the Free Software Foundation; either version 3 of the License, or
2010-01-16 22:32:10 +00:00
+# (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
2012-06-03 17:40:44 +00:00
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+load_lib dwarf.exp
2009-03-02 00:11:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2009-03-02 00:11:35 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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 {}] != "" } {
2010-01-16 22:32:10 +00:00
+ return -1
2009-03-02 00:11:35 +00:00
+}
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+clean_restart $executable
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..d7b8bea
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.fortran/dwarf-stride.exp
@@ -0,0 +1,42 @@
+# Copyright 2009 Free Software Foundation, Inc.
+
2010-01-16 22:32:10 +00:00
+# 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
2012-06-03 17:40:44 +00:00
+# the Free Software Foundation; either version 2 of the License, or
2010-01-16 22:32:10 +00:00
+# (at your option) any later version.
2012-06-03 17:40:44 +00:00
+#
2010-01-16 22:32:10 +00:00
+# 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.
2012-06-03 17:40:44 +00:00
+#
2010-01-16 22:32:10 +00:00
+# You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2010-07-21 21:30:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
2010-07-21 21:30:20 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2011-01-07 08:47:27 +00:00
+
2012-06-03 17:40:44 +00:00
+set testfile dwarf-stride
+set srcfile ${testfile}.f90
+
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
+ return -1
2011-01-07 08:47:27 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..e492b3a
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ 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.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+program repro
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+ type small_stride
+ character*40 long_string
+ integer small_pad
+ end type small_stride
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ type(small_stride), dimension (20), target :: unpleasant
+ character*40, pointer, dimension(:):: c40pt
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ integer i
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ do i = 0,19
+ unpleasant(i+1)%small_pad = i+1
+ unpleasant(i+1)%long_string = char (ichar('0') + i) // '-hello'
+ end do
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ c40pt => unpleasant%long_string
+
+ print *, c40pt ! break-here
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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..261ce17
--- /dev/null
+++ 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>.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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.
2012-01-03 15:00:12 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2010-01-16 22:32:10 +00:00
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+clean_restart ${executable}
+
+if ![runto bar_] then {
+ perror "couldn't run to bar_"
+ continue
+}
+
+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>.
+
+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..e79e94a
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/dynamic.exp
@@ -0,0 +1,152 @@
+# Copyright 2007 Free Software Foundation, Inc.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+set testfile "dynamic"
+set srcfile ${testfile}.f90
+set binfile ${objdir}/${subdir}/${testfile}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if ![runto MAIN__] then {
+ perror "couldn't run to breakpoint MAIN__"
+ continue
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+set test "output varx"
+gdb_test_multiple $test $test {
+ -re "^output varx\r\n\[() ,6789.\]*$gdb_prompt $" {
+ pass $test
+ }
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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\\."
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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, .\]*\\)"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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, .\]*\\)"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..0f43564
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ 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>.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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..39de2c4
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/string.exp
@@ -0,0 +1,59 @@
+# Copyright 2008 Free Software Foundation, Inc.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# This file was written by Jan Kratochvil <jan.kratochvil@redhat.com>.
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+# This file is part of the gdb testsuite. It contains tests for Fortran
+# strings with dynamic length.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+set testfile "string"
+set srcfile ${testfile}.f90
+set binfile ${objdir}/${subdir}/${testfile}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f90 quiet}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
2009-08-18 19:37:35 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if ![runto MAIN__] then {
+ perror "couldn't run to breakpoint MAIN__"
+ continue
2011-01-01 00:27:30 +00:00
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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."
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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..226dc5d
--- /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>.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+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.
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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/>.
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [skip_fortran_tests] } { return -1 }
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+set testfile "subrange"
+set srcfile ${testfile}.f90
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}] } {
+ return -1
2009-08-18 19:37:35 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+if ![runto MAIN__] {
+ perror "Couldn't run to MAIN__"
+ continue
+}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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\\))"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_breakpoint [gdb_get_line_number "break-static"]
+gdb_continue_to_breakpoint "break-static" ".*break-static.*"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+foreach var {a alloc ptr} {
+ global pf_prefix
+ set old_prefix $pf_prefix
+ lappend pf_prefix "$var:"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ set pf_prefix $old_prefix
2010-01-16 22:32:10 +00:00
+}
2012-06-03 17:40:44 +00:00
+
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..4747ea9
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ 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/>.
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2013-02-18 17:14:00 +00:00
index 55e13cf..441c28b 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/testsuite/gdb.gdb/selftest.exp
+++ b/gdb/testsuite/gdb.gdb/selftest.exp
2013-01-19 22:41:55 +00:00
@@ -91,6 +91,10 @@ proc do_steps_and_nexts {} {
2012-06-03 17:40:44 +00:00
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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..ebced3c
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.c
@@ -0,0 +1,26 @@
+/* Copyright 2011 Free Software Foundation, Inc.
2009-08-18 19:37:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ This file is part of GDB.
2009-08-18 19:37:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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
2012-06-03 17:40:44 +00:00
+ the Free Software Foundation; either version 3 of the License, or
2010-01-16 22:32:10 +00:00
+ (at your option) any later version.
2009-08-18 19:37:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ 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.
2009-08-18 19:37:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ You should have received a copy of the GNU General Public License
2012-06-03 17:40:44 +00:00
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+int
+main (int argc, char **argv)
2010-01-16 22:32:10 +00:00
+{
2012-06-03 17:40:44 +00:00
+ char vla[argc];
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+ vla[0] = 0; /* break-here */
2009-08-18 19:37:35 +00:00
+
2010-01-16 22:32:10 +00:00
+ return 0;
2009-08-18 19:37:35 +00:00
+}
2012-06-03 17:40:44 +00:00
diff --git a/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
2012-01-03 15:00:12 +00:00
new file mode 100644
2013-02-18 17:14:00 +00:00
index 0000000..99b6cc7
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.mi/mi2-var-stale-type.exp
@@ -0,0 +1,57 @@
+# Copyright 2011 Free Software Foundation, Inc.
2012-01-03 15:00:12 +00:00
+#
2009-08-18 19:37:35 +00:00
+# 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/>.
+
2012-06-03 17:40:44 +00:00
+load_lib mi-support.exp
+set MIFLAGS "-i=mi2"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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
+}
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+mi_gdb_test {-interpreter-exec console "maintenance set internal-error quit yes"} \
+ {\^done} \
+ "maintenance set internal-error quit yes"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+mi_gdb_test {-interpreter-exec console "maintenance set internal-error corefile yes"} \
+ {\^done} \
+ "maintenance set internal-error corefile yes"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+set line [gdb_get_line_number "break-here"]
+set func "main"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+mi_gdb_test "-break-insert -t $srcfile:$line" \
2013-02-18 17:14:00 +00:00
+ "\\^done,bkpt=\{number=\"\[0-9\]+\",type=\"breakpoint\",disp=\"del\",enabled=\"y\",addr=\"$hex\",func=\"$func\(\\\(.*\\\)\)?\",file=\".*\",fullname=\".*\",line=\"$line\",\[^\r\n\]*,original-location=\".*\"\}" \
2012-06-03 17:40:44 +00:00
+ "breakpoint at $func"
2009-08-18 19:37:35 +00:00
+
2012-06-03 17:40:44 +00:00
+if { [mi_run_cmd] < 0 } {
+ return -1
2009-08-18 19:37:35 +00:00
+}
2012-06-03 17:40:44 +00:00
+mi_expect_stop "breakpoint-hit" $func ".*" ".*" "\[0-9\]+" { "" "disp=\"del\"" } "stop after initializing vla"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+mi_create_varobj "vla" "vla" "create local variable vla"
2010-01-16 22:32:10 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..729f457
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.opt/array-from-register-func.c
@@ -0,0 +1,22 @@
+/* This file is part of GDB, the GNU debugger.
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2009 Free Software Foundation, Inc.
2011-01-01 00:27:30 +00:00
+
+ 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
2012-06-03 17:40:44 +00:00
+ the Free Software Foundation; either version 3 of the License, or
2011-01-01 00:27:30 +00:00
+ (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
2012-06-03 17:40:44 +00:00
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
2011-01-01 00:27:30 +00:00
+
2012-06-03 17:40:44 +00:00
+int
+func (int *arr)
+{
+ return arr[0];
+}
diff --git a/gdb/testsuite/gdb.opt/array-from-register.c b/gdb/testsuite/gdb.opt/array-from-register.c
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..3090e7e
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.opt/array-from-register.c
@@ -0,0 +1,28 @@
+/* This file is part of GDB, the GNU debugger.
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ Copyright 2009 Free Software Foundation, Inc.
2011-03-28 18:06:31 +00:00
+
+ 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/>. */
+
2012-06-03 17:40:44 +00:00
+extern int func (int *arr);
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+int
+main (void)
+{
+ int arr[] = { 42 };
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ func (arr);
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ return 0;
2011-03-28 18:06:31 +00:00
+}
2012-06-03 17:40:44 +00:00
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..f2de718
--- /dev/null
+++ 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.
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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
2011-03-28 18:06:31 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+if ![runto func] then {
+ return -1
2011-03-28 18:06:31 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+gdb_test "p arr" "\\$\[0-9\]+ = \\(int \\*\\) *0x\[0-9a-f\]+"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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
2012-01-03 15:00:12 +00:00
new file mode 100644
2012-06-03 17:40:44 +00:00
index 0000000..ccc6e1e
2012-01-03 15:00:12 +00:00
--- /dev/null
2012-06-03 17:40:44 +00:00
+++ b/gdb/testsuite/gdb.pascal/arrays.exp
@@ -0,0 +1,104 @@
+# Copyright 2008, 2009 Free Software Foundation, Inc.
+#
2011-03-28 18:06:31 +00:00
+# 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 $tracelevel then {
2012-06-03 17:40:44 +00:00
+ strace $tracelevel
2011-03-28 18:06:31 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+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"
+}
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+# 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"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
+ setup_xfail "*-*-*"
2011-03-28 18:06:31 +00:00
+}
2012-06-03 17:40:44 +00:00
+gdb_test "print s" ".* = 'test'#0'string'" "Print string containing null-char"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+if { $fpc_generates_dwarf_for_dynamic_arrays == 0} {
+ setup_xfail "*-*-*"
2011-03-28 18:06:31 +00:00
+}
2012-06-03 17:40:44 +00:00
+gdb_test "print DynArrChar" ".* = 'abcdefghijklm'" "Print dynamic array of char"
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
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.
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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.
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
2011-03-28 18:06:31 +00:00
+}
+
2012-06-03 17:40:44 +00:00
+program arrays;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+{$mode objfpc}{$h+}
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+uses sysutils;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ TStat2dArrInt = array[0..11,0..4] of integer;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+var StatArrInt: TStatArrInt;
+ StatArrInt_: Array[0..11] of integer;
+ DynArrInt: TDynArrInt;
+ DynArrInt_: Array of integer;
+ StatArrStr: TStatArrStr;
+ DynArrStr: TDynArrStr;
+ StatArrChar: TStatArrChar;
+ DynArrChar: TDynArrChar;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ Stat2dArrInt: TStat2dArrInt;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ s: string;
+
+ i,j : integer;
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+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]);
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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]);
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
+ 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
2013-02-18 17:14:00 +00:00
index 806da94..b22231a 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/testsuite/gdb.python/py-frame.exp
+++ b/gdb/testsuite/gdb.python/py-frame.exp
2013-02-18 17:14:00 +00:00
@@ -94,3 +94,5 @@ gdb_test "python print ('result = %s' % f0.read_var ('variable_which_surely_does
2013-01-19 22:41:55 +00:00
gdb_test "python print ('result = %s' % f0.read_var ('a'))" " = 1" "test Frame.read_var - success"
2012-06-03 17:40:44 +00:00
2013-01-19 22:41:55 +00:00
gdb_test "python print ('result = %s' % (gdb.selected_frame () == f1))" " = True" "test gdb.selected_frame"
2011-03-28 18:06:31 +00:00
+
2013-01-19 22:41:55 +00:00
+gdb_test "python print ('result = %s' % (f0.block ()))" "<gdb.Block object at 0x\[\[:xdigit:\]\]+>" "test Frame.block"
2012-06-03 17:40:44 +00:00
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
2013-01-19 22:41:55 +00:00
index 9142c72..2855220 100644
2012-06-03 17:40:44 +00:00
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
2013-01-19 22:41:55 +00:00
@@ -366,6 +366,15 @@ proc test_value_after_death {} {
2012-06-03 17:40:44 +00:00
"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"
+}
2011-03-28 18:06:31 +00:00
+
2012-06-03 17:40:44 +00:00
# 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.
2013-01-19 22:41:55 +00:00
@@ -492,6 +501,7 @@ test_value_in_inferior
2012-06-03 17:40:44 +00:00
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"
2012-01-03 15:00:12 +00:00
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
2013-01-19 22:41:55 +00:00
index 8b16b38..f6e59b0 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
2013-01-19 22:41:55 +00:00
@@ -143,6 +143,11 @@ proc gdb_unload {} {
2011-03-20 20:44:20 +00:00
send_gdb "y\n"
2011-01-17 15:31:43 +00:00
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
2012-01-03 15:00:12 +00:00
diff --git a/gdb/testsuite/lib/pascal.exp b/gdb/testsuite/lib/pascal.exp
2013-01-19 22:41:55 +00:00
index 569fb02..cacecf4 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/testsuite/lib/pascal.exp
+++ b/gdb/testsuite/lib/pascal.exp
2010-07-21 21:30:20 +00:00
@@ -37,6 +37,9 @@ proc pascal_init {} {
global pascal_compiler_is_fpc
global gpc_compiler
global fpc_compiler
+ global fpcversion_major
+ global fpcversion_minor
+ global fpcversion_release
global env
if { $pascal_init_done == 1 } {
@@ -64,6 +67,20 @@ proc pascal_init {} {
set pascal_compiler_is_fpc 1
verbose -log "Free Pascal compiler found"
2010-01-21 16:09:11 +00:00
}
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
+ # Detect the fpc-version
+ if { $pascal_compiler_is_fpc == 1 } {
+ set fpcversion_major 1
+ set fpcversion_minor 0
+ set fpcversion_release 0
+ set fpcversion [ remote_exec host $fpc_compiler "-iV" ]
+ if [regexp {.*([0-9]+)\.([0-9]+)\.([0-9]+).?} $fpcversion] {
+ regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\1} fpcversion_major
+ regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\2} fpcversion_minor
+ regsub {.*([0-9]+)\.([0-9]+)\.([0-9]+).?\n?.?} $fpcversion {\3} fpcversion_release
2009-08-04 05:37:29 +00:00
+ }
2010-07-21 21:30:20 +00:00
+ verbose -log "Freepascal version: $fpcversion_major.$fpcversion_minor.$fpcversion_release"
2009-08-04 05:37:29 +00:00
+ }
2010-07-21 21:30:20 +00:00
}
set pascal_init_done 1
}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/top.c b/gdb/top.c
2013-02-18 17:14:00 +00:00
index e9a40fc..de051c8 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/top.c
+++ b/gdb/top.c
2013-01-19 22:41:55 +00:00
@@ -350,6 +350,9 @@ prepare_execute_command (void)
2011-07-22 22:41:56 +00:00
mark = value_mark ();
cleanup = make_cleanup_value_free_to_mark (mark);
2011-03-05 12:24:53 +00:00
+#if 0
2009-08-04 05:37:29 +00:00
+ free_all_types ();
2011-03-05 12:24:53 +00:00
+#endif
2009-03-02 00:11:35 +00:00
2011-01-01 00:27:30 +00:00
/* With multiple threads running while the one we're examining is
stopped, the dcache can get stale without us being able to detect
2012-01-03 15:00:12 +00:00
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
2013-01-19 22:41:55 +00:00
index 2d5a6af..5251e3f 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
2013-01-19 22:41:55 +00:00
@@ -34,6 +34,7 @@
2009-08-04 05:37:29 +00:00
#include "gdb_string.h"
#include "exceptions.h"
#include "valprint.h"
+#include "dwarf2loc.h"
#include <errno.h>
2013-01-19 22:41:55 +00:00
#include <ctype.h>
#include "cli/cli-utils.h"
@@ -363,6 +364,9 @@ void
2012-06-03 17:40:44 +00:00
type_print (struct type *type, const char *varstring, struct ui_file *stream,
2009-08-04 05:37:29 +00:00
int show)
{
2012-01-03 15:00:12 +00:00
+ if (show >= 0 && current_language->la_language != language_ada)
2009-08-04 05:37:29 +00:00
+ type = check_typedef (type);
+
2013-01-19 22:41:55 +00:00
LA_PRINT_TYPE (type, varstring, stream, show, 0, &default_ptype_flags);
2009-08-04 05:37:29 +00:00
}
2009-03-02 00:11:35 +00:00
2013-01-19 22:41:55 +00:00
@@ -410,6 +414,7 @@ whatis_exp (char *exp, int show)
struct value_print_options opts;
struct type_print_options flags = default_ptype_flags;
2009-08-04 05:37:29 +00:00
+ /* Required at least for the object_address_set call. */
2013-01-19 22:41:55 +00:00
old_chain = make_cleanup (null_cleanup, NULL);
2009-08-04 05:37:29 +00:00
if (exp)
2013-01-19 22:41:55 +00:00
@@ -457,6 +462,7 @@ whatis_exp (char *exp, int show)
2009-08-04 05:37:29 +00:00
else
val = access_value_history (0);
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
+ object_address_set (value_raw_address (val));
type = value_type (val);
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
get_user_print_options (&opts);
2012-01-03 15:00:12 +00:00
diff --git a/gdb/utils.c b/gdb/utils.c
2013-03-10 16:12:43 +00:00
index 4c2f08c..d1c8710 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/utils.c
+++ b/gdb/utils.c
2013-03-10 16:12:43 +00:00
@@ -1805,6 +1805,36 @@ set_batch_flag_and_make_cleanup_restore_page_info (void)
2011-01-01 00:27:30 +00:00
return back_to;
}
+/* 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. */
2009-08-04 05:37:29 +00:00
static void
2013-01-19 22:41:55 +00:00
diff --git a/gdb/utils.h b/gdb/utils.h
2013-02-18 17:14:00 +00:00
index 52bcaff..6ab417b 100644
2013-01-19 22:41:55 +00:00
--- a/gdb/utils.h
+++ b/gdb/utils.h
2013-02-18 17:14:00 +00:00
@@ -375,4 +375,6 @@ extern int myread (int, char *, int);
2013-01-19 22:41:55 +00:00
extern ULONGEST align_up (ULONGEST v, int n);
extern ULONGEST align_down (ULONGEST v, int n);
+extern struct cleanup *make_cleanup_restore_selected_frame (void);
+
#endif /* UTILS_H */
2012-01-03 15:00:12 +00:00
diff --git a/gdb/valarith.c b/gdb/valarith.c
2013-02-18 17:14:00 +00:00
index 18c14fc..0a3a3aa 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
2013-01-19 22:41:55 +00:00
@@ -195,7 +195,10 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
2009-08-04 05:37:29 +00:00
struct type *array_type = check_typedef (value_type (array));
struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
2011-01-17 15:31:43 +00:00
unsigned int elt_size = TYPE_LENGTH (elt_type);
2009-08-04 05:37:29 +00:00
- unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
2011-01-17 15:31:43 +00:00
+ 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);
2009-08-04 05:37:29 +00:00
struct value *v;
2011-01-17 15:31:43 +00:00
if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
2013-01-19 22:41:55 +00:00
@@ -255,6 +258,10 @@ int
2010-07-21 21:30:20 +00:00
binop_user_defined_p (enum exp_opcode op,
struct value *arg1, struct value *arg2)
{
+ /* FIXME: We should support user defined ops for dynamic types. */
+ if (TYPE_DYNAMIC (value_type (arg1)) || TYPE_DYNAMIC (value_type (arg2)))
+ return 0;
2010-07-11 18:06:33 +00:00
+
2010-07-21 21:30:20 +00:00
return binop_types_user_defined_p (op, value_type (arg1), value_type (arg2));
}
2010-07-11 18:06:33 +00:00
2012-01-03 15:00:12 +00:00
diff --git a/gdb/valops.c b/gdb/valops.c
2013-02-18 17:14:00 +00:00
index 93c09d8..aef0991 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/valops.c
+++ b/gdb/valops.c
2012-01-20 23:27:28 +00:00
@@ -45,6 +45,7 @@
2011-02-18 10:25:34 +00:00
#include "objfiles.h"
#include "symtab.h"
#include "exceptions.h"
2009-08-04 05:37:29 +00:00
+#include "dwarf2loc.h"
2013-01-19 22:41:55 +00:00
extern unsigned int overload_debug;
2011-02-18 10:25:34 +00:00
/* Local functions. */
2013-02-18 17:14:00 +00:00
@@ -903,6 +904,65 @@ value_one (struct type *type)
2009-08-04 05:37:29 +00:00
return val;
2009-03-02 00:11:35 +00:00
}
2009-08-04 05:37:29 +00:00
+/* object_address_set must be already called before this function. */
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+const char *
+object_address_data_not_valid (struct type *type)
2009-03-02 00:11:35 +00:00
+{
2009-08-04 05:37:29 +00:00
+ /* Attributes are present only at the target type of a typedef. Make the
+ call conditional as it would otherwise loop through type_length_get. */
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ CHECK_TYPEDEF (type);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ /* DW_AT_associated has a preference over DW_AT_allocated. */
+ if (TYPE_NOT_ASSOCIATED (type)
+ || (TYPE_ASSOCIATED (type) != NULL
+ && 0 == dwarf_locexpr_baton_eval (TYPE_ASSOCIATED (type))))
+ return N_("object is not associated");
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ if (TYPE_NOT_ALLOCATED (type)
+ || (TYPE_ALLOCATED (type) != NULL
+ && 0 == dwarf_locexpr_baton_eval (TYPE_ALLOCATED (type))))
+ return N_("object is not allocated");
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ return NULL;
+}
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
+/* Return non-NULL check_typedef result on TYPE if the variable is valid. If
+ it is valid the function may store the data address (DW_AT_DATA_LOCATION) of
+ TYPE at *ADDRESS_RETURN. You must set *ADDRESS_RETURN from
+ value_raw_address (VAL) before calling this function. If no
+ DW_AT_DATA_LOCATION is present for TYPE the address at *ADDRESS_RETURN is
+ left unchanged. ADDRESS_RETURN must not be NULL, use
2009-08-04 05:37:29 +00:00
+ object_address_data_not_valid () for just the data validity check. */
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
+struct type *
2009-08-04 05:37:29 +00:00
+object_address_get_data (struct type *type, CORE_ADDR *address_return)
+{
+ gdb_assert (address_return != NULL);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ object_address_set (*address_return);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ /* TYPE_DATA_LOCATION_DWARF_BLOCK / TYPE_DATA_LOCATION_ADDR are present only
+ at the target type of a typedef. */
+ CHECK_TYPEDEF (type);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ if (object_address_data_not_valid (type) != NULL)
2009-03-02 00:11:35 +00:00
+ {
2009-08-04 05:37:29 +00:00
+ /* Do not try to evaluate DW_AT_data_location as it may even crash
+ (it would just return the value zero in the gfortran case). */
2010-07-21 21:30:20 +00:00
+ return NULL;
2009-03-02 00:11:35 +00:00
+ }
+
2009-08-04 05:37:29 +00:00
+ if (TYPE_DATA_LOCATION_IS_ADDR (type))
+ *address_return = TYPE_DATA_LOCATION_ADDR (type);
+ else if (TYPE_DATA_LOCATION_DWARF_BLOCK (type) != NULL)
+ *address_return
+ = dwarf_locexpr_baton_eval (TYPE_DATA_LOCATION_DWARF_BLOCK (type));
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
+ return type;
2009-03-02 00:11:35 +00:00
+}
+
2009-09-10 21:37:41 +00:00
/* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
2009-03-02 00:11:35 +00:00
2009-09-10 21:37:41 +00:00
static struct value *
2013-02-18 17:14:00 +00:00
@@ -965,7 +1025,8 @@ int
2012-06-03 17:40:44 +00:00
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
2013-02-18 17:14:00 +00:00
@@ -998,13 +1059,24 @@ value_fetch_lazy (struct value *val)
2009-03-02 00:11:35 +00:00
}
2009-08-04 05:37:29 +00:00
else if (VALUE_LVAL (val) == lval_memory)
{
- CORE_ADDR addr = value_address (val);
2013-01-19 22:41:55 +00:00
- struct type *type = check_typedef (value_enclosing_type (val));
2009-08-04 05:37:29 +00:00
+ CORE_ADDR addr = value_raw_address (val);
2009-09-10 21:37:41 +00:00
2013-01-19 22:41:55 +00:00
- if (TYPE_LENGTH (type))
2011-02-18 10:25:34 +00:00
- read_value_memory (val, 0, value_stack (val),
2013-01-19 22:41:55 +00:00
- addr, value_contents_all_raw (val),
- TYPE_LENGTH (type));
2009-08-04 05:37:29 +00:00
+ if (object_address_get_data (value_type (val), &addr))
2011-02-18 10:25:34 +00:00
+ {
2009-08-04 05:37:29 +00:00
+ struct type *type = value_enclosing_type (val);
+ int length = TYPE_LENGTH (check_typedef (type));
2009-09-10 21:37:41 +00:00
+
2009-08-04 05:37:29 +00:00
+ if (length)
+ {
2012-06-03 17:40:44 +00:00
+ /* Delay it after object_address_get_data above. */
+ allocate_value_contents (val);
2009-08-04 05:37:29 +00:00
+ addr += value_offset (val);
2011-02-18 10:25:34 +00:00
+ read_value_memory (val, 0, value_stack (val),
+ addr, value_contents_all_raw (val), length);
2009-08-04 05:37:29 +00:00
+ }
2011-02-18 10:25:34 +00:00
+ }
2012-06-03 17:40:44 +00:00
+ /* Just to be sure it has been called. */
+ allocate_value_contents (val);
2009-08-04 05:37:29 +00:00
}
else if (VALUE_LVAL (val) == lval_register)
2011-02-18 10:25:34 +00:00
{
2013-01-19 22:41:55 +00:00
@@ -1529,7 +1601,18 @@ address_of_variable (struct symbol *var, const struct block *b)
2009-08-04 05:37:29 +00:00
if ((VALUE_LVAL (val) == lval_memory && value_lazy (val))
|| TYPE_CODE (type) == TYPE_CODE_FUNC)
{
- CORE_ADDR addr = value_address (val);
+ CORE_ADDR addr;
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ if (VALUE_LVAL (val) == lval_memory)
+ {
+ addr = value_raw_address (val);
+ if (!object_address_get_data (type, &addr))
+ error (_("Can't take address of memory lvalue \"%s\"."),
+ SYMBOL_PRINT_NAME (var));
+ set_value_address (val, addr);
+ }
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ addr = value_address (val);
2010-07-21 21:30:20 +00:00
2009-08-04 05:37:29 +00:00
return value_from_pointer (lookup_pointer_type (type), addr);
2009-03-02 00:11:35 +00:00
}
2013-01-19 22:41:55 +00:00
@@ -1636,6 +1719,7 @@ struct value *
2009-08-04 05:37:29 +00:00
value_coerce_array (struct value *arg1)
{
struct type *type = check_typedef (value_type (arg1));
+ CORE_ADDR address;
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
/* 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
2013-01-19 22:41:55 +00:00
@@ -1645,8 +1729,12 @@ value_coerce_array (struct value *arg1)
2009-08-04 05:37:29 +00:00
if (VALUE_LVAL (arg1) != lval_memory)
error (_("Attempt to take address of value not located in memory."));
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
+ address = value_raw_address (arg1);
+ if (!object_address_get_data (type, &address))
+ error (_("Attempt to take address of non-valid value."));
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
- value_address (arg1));
+ address + value_offset (arg1));
}
/* Given a value which is a function, return a value which is a pointer
2013-02-18 17:14:00 +00:00
@@ -3721,6 +3809,8 @@ value_slice (struct value *array, int lowbound, int length)
2011-01-17 15:31:43 +00:00
TYPE_TARGET_TYPE (range_type),
lowbound,
lowbound + length - 1);
+ TYPE_BYTE_STRIDE (slice_range_type) = TYPE_BYTE_STRIDE (range_type);
+
2013-01-19 22:41:55 +00:00
2011-01-17 15:31:43 +00:00
{
2013-01-19 22:41:55 +00:00
struct type *element_type = TYPE_TARGET_TYPE (array_type);
2012-01-03 15:00:12 +00:00
diff --git a/gdb/valprint.c b/gdb/valprint.c
2013-03-10 16:12:43 +00:00
index 18cff49..89cb01a 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
2012-01-20 23:27:28 +00:00
@@ -37,6 +37,7 @@
2011-07-22 22:41:56 +00:00
#include "gdb_obstack.h"
#include "charset.h"
#include <ctype.h>
2010-07-21 21:30:20 +00:00
+#include "dwarf2loc.h"
#include <errno.h>
2013-01-19 22:41:55 +00:00
@@ -287,7 +288,6 @@ scalar_type_p (struct type *type)
2009-09-01 13:19:03 +00:00
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
case TYPE_CODE_SET:
- case TYPE_CODE_STRING:
return 0;
default:
2013-01-19 22:41:55 +00:00
return 1;
2013-02-18 17:14:00 +00:00
@@ -1604,6 +1604,7 @@ val_print_array_elements (struct type *type,
2010-07-21 21:30:20 +00:00
{
unsigned int things_printed = 0;
unsigned len;
+ struct type *saved_type = type;
struct type *elttype, *index_type;
unsigned eltlen;
/* Position of the array element we are examining to see
2013-02-18 17:14:00 +00:00
@@ -1612,9 +1613,33 @@ val_print_array_elements (struct type *type,
2010-07-21 21:30:20 +00:00
/* Number of repetitions we have detected so far. */
unsigned int reps;
2010-11-17 02:58:16 +00:00
LONGEST low_bound, high_bound;
2010-07-21 21:30:20 +00:00
+ struct cleanup *back_to;
+ CORE_ADDR saved_address = address;
+
+ back_to = make_cleanup (null_cleanup, 0);
+ type = object_address_get_data (type, &address);
+ if (!type)
+ {
+ fputs_filtered (object_address_data_not_valid (type), stream);
+ do_cleanups (back_to);
+ return;
+ }
+ if (address != saved_address)
+ {
+ size_t length = TYPE_LENGTH (type);
- elttype = TYPE_TARGET_TYPE (type);
- eltlen = TYPE_LENGTH (check_typedef (elttype));
+ valaddr = xmalloc (length);
+ make_cleanup (xfree, (gdb_byte *) valaddr);
+ read_memory (address, (gdb_byte *) valaddr, length);
+ }
+
+ /* Skip typedefs but do not resolve TYPE_DYNAMIC. */
+ elttype = saved_type;
+ while (TYPE_CODE (elttype) == TYPE_CODE_TYPEDEF)
+ elttype = TYPE_TARGET_TYPE (elttype);
+ elttype = TYPE_TARGET_TYPE (elttype);
+
+ eltlen = TYPE_ARRAY_BYTE_STRIDE_VALUE (type);
index_type = TYPE_INDEX_TYPE (type);
2009-08-04 05:37:29 +00:00
2010-11-17 02:58:16 +00:00
if (get_array_bounds (type, &low_bound, &high_bound))
2013-02-18 17:14:00 +00:00
@@ -1701,6 +1726,8 @@ val_print_array_elements (struct type *type,
2010-07-21 21:30:20 +00:00
{
fprintf_filtered (stream, "...");
}
+
+ do_cleanups (back_to);
}
/* Read LEN bytes of target memory at address MEMADDR, placing the
2012-01-03 15:00:12 +00:00
diff --git a/gdb/value.c b/gdb/value.c
2013-02-18 17:14:00 +00:00
index 4b70ece..7449c2a 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/value.c
+++ b/gdb/value.c
2012-06-03 17:40:44 +00:00
@@ -42,6 +42,7 @@
2011-03-05 12:24:53 +00:00
#include <ctype.h>
#include "tracepoint.h"
2012-06-03 17:40:44 +00:00
#include "cp-abi.h"
2009-08-04 05:37:29 +00:00
+#include "observer.h"
2011-03-05 12:24:53 +00:00
/* Prototypes for exported functions. */
2009-08-04 05:37:29 +00:00
2013-02-18 17:14:00 +00:00
@@ -1435,12 +1436,15 @@ void
2010-07-21 21:30:20 +00:00
set_value_component_location (struct value *component,
const struct value *whole)
2009-03-02 00:11:35 +00:00
{
2009-08-04 05:37:29 +00:00
+ CORE_ADDR addr;
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
if (whole->lval == lval_internalvar)
2009-08-04 05:37:29 +00:00
VALUE_LVAL (component) = lval_internalvar_component;
else
2010-07-21 21:30:20 +00:00
VALUE_LVAL (component) = whole->lval;
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
component->location = whole->location;
+
2010-07-21 21:30:20 +00:00
if (whole->lval == lval_computed)
2009-08-04 05:37:29 +00:00
{
2011-07-22 22:41:56 +00:00
const struct lval_funcs *funcs = whole->location.computed.funcs;
2013-02-18 17:14:00 +00:00
@@ -1448,6 +1452,12 @@ set_value_component_location (struct value *component,
2009-08-04 05:37:29 +00:00
if (funcs->copy_closure)
component->location.computed.closure = funcs->copy_closure (whole);
2009-03-02 00:11:35 +00:00
}
+
2009-08-04 05:37:29 +00:00
+ addr = value_raw_address (component);
+ object_address_get_data (value_type (whole), &addr);
2010-01-12 22:15:57 +00:00
+ if (component->lval != lval_internalvar
+ && component->lval != lval_internalvar_component)
+ set_value_address (component, addr);
2009-03-07 00:32:30 +00:00
}
2009-08-04 05:37:29 +00:00
2013-02-18 17:14:00 +00:00
@@ -1581,6 +1591,31 @@ show_values (char *num_exp, int from_tty)
2009-08-04 05:37:29 +00:00
num_exp[1] = '\0';
}
}
+
+/* Sanity check for memory leaks and proper types reference counting. */
+
2009-03-07 00:32:30 +00:00
+static void
2009-08-04 05:37:29 +00:00
+value_history_cleanup (void *unused)
2009-03-07 00:32:30 +00:00
+{
2009-08-04 05:37:29 +00:00
+ while (value_history_chain)
+ {
+ struct value_history_chunk *chunk = value_history_chain;
+ int i;
2009-03-07 00:32:30 +00:00
+
2009-08-04 05:37:29 +00:00
+ for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
+ value_free (chunk->values[i]);
2009-03-07 00:32:30 +00:00
+
2009-08-04 05:37:29 +00:00
+ value_history_chain = chunk->next;
+ xfree (chunk);
+ }
+ value_history_count = 0;
+
+ /* Free the unreferenced types above. */
+ free_all_values ();
2011-03-05 12:24:53 +00:00
+#if 0
2009-08-04 05:37:29 +00:00
+ free_all_types ();
2011-03-05 12:24:53 +00:00
+#endif
2009-08-04 05:37:29 +00:00
+}
/* Internal variables. These are variables within the debugger
that hold values assigned by debugger commands.
2013-02-18 17:14:00 +00:00
@@ -2116,6 +2151,38 @@ call_internal_function (struct gdbarch *gdbarch,
2009-08-04 05:37:29 +00:00
return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
2009-03-02 00:11:35 +00:00
}
2011-03-05 12:24:53 +00:00
+#if 0
2009-08-04 05:37:29 +00:00
+/* Call type_mark_used for any TYPEs referenced from this GDB source file. */
+
+static void
+value_types_mark_used (void)
+{
+ struct internalvar *var;
+ struct value_history_chunk *chunk;
+
+ for (var = internalvars; var != NULL; var = var->next)
+ switch (var->kind)
2009-03-02 00:11:35 +00:00
+ {
2009-08-04 05:37:29 +00:00
+ case INTERNALVAR_VALUE:
+ type_mark_used (value_type (var->u.value));
+ break;
2009-03-02 00:11:35 +00:00
+
2009-08-19 16:19:15 +00:00
+ case INTERNALVAR_INTEGER:
+ type_mark_used (var->u.integer.type);
2009-08-04 05:37:29 +00:00
+ break;
2009-03-02 00:11:35 +00:00
+ }
+
2009-08-04 05:37:29 +00:00
+ for (chunk = value_history_chain; chunk != NULL; chunk = chunk->next)
2009-03-02 00:11:35 +00:00
+ {
2009-08-04 05:37:29 +00:00
+ int i;
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ for (i = 0; i < ARRAY_SIZE (chunk->values); i++)
+ if (chunk->values[i])
+ type_mark_used (value_type (chunk->values[i]));
2009-03-02 00:11:35 +00:00
+ }
2009-08-04 05:37:29 +00:00
+}
2011-03-05 12:24:53 +00:00
+#endif
2009-08-04 05:37:29 +00:00
+
/* 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
2013-02-18 17:14:00 +00:00
@@ -2163,11 +2230,10 @@ preserve_one_value (struct value *value, struct objfile *objfile,
2009-08-04 05:37:29 +00:00
htab_t copied_types)
{
if (TYPE_OBJFILE (value->type) == objfile)
- value->type = copy_type_recursive (objfile, value->type, copied_types);
2009-08-10 13:22:51 +00:00
+ value->type = copy_type_recursive (value->type, copied_types);
2009-03-02 00:11:35 +00:00
2009-08-04 05:37:29 +00:00
if (TYPE_OBJFILE (value->enclosing_type) == objfile)
- value->enclosing_type = copy_type_recursive (objfile,
- value->enclosing_type,
2009-08-10 13:22:51 +00:00
+ value->enclosing_type = copy_type_recursive (value->enclosing_type,
copied_types);
2009-08-04 05:37:29 +00:00
}
2009-03-02 00:11:35 +00:00
2013-02-18 17:14:00 +00:00
@@ -2182,7 +2248,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
2009-08-19 16:19:15 +00:00
case INTERNALVAR_INTEGER:
if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
var->u.integer.type
- = copy_type_recursive (objfile, var->u.integer.type, copied_types);
+ = copy_type_recursive (var->u.integer.type, copied_types);
break;
2009-08-04 05:37:29 +00:00
case INTERNALVAR_VALUE:
2013-02-18 17:14:00 +00:00
@@ -3280,10 +3346,27 @@ readjust_indirect_value_type (struct value *value, struct type *enc_type,
2010-07-21 21:30:20 +00:00
struct value *
coerce_ref (struct value *arg)
{
- struct type *value_type_arg_tmp = check_typedef (value_type (arg));
+ struct type *value_type_arg_tmp;
2012-01-03 15:00:12 +00:00
struct value *retval;
2012-06-03 17:40:44 +00:00
struct type *enc_type;
2012-01-03 15:00:12 +00:00
2010-07-21 21:30:20 +00:00
+ if (TYPE_DYNAMIC (value_type (arg)))
2009-08-04 05:37:29 +00:00
+ {
2010-07-21 21:30:20 +00:00
+ struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
+ CORE_ADDR address;
2009-03-02 00:11:35 +00:00
+
2010-07-21 21:30:20 +00:00
+ value_type_arg_tmp = value_type (arg);
+ address = value_raw_address (arg);
+ value_type_arg_tmp = object_address_get_data (value_type_arg_tmp,
+ &address);
+ if (! value_type_arg_tmp)
+ error (_("Attempt to coerce non-valid value."));
+ arg = value_at_lazy (value_type_arg_tmp, address);
+ do_cleanups (cleanups);
2009-03-02 00:11:35 +00:00
+ }
2010-07-21 21:30:20 +00:00
+ else
+ value_type_arg_tmp = check_typedef (value_type (arg));
2012-01-03 15:00:12 +00:00
+
retval = coerce_ref_if_computed (arg);
if (retval)
return retval;
2013-02-18 17:14:00 +00:00
@@ -3405,4 +3488,10 @@ VARIABLE is already initialized."));
2009-08-04 05:37:29 +00:00
add_prefix_cmd ("function", no_class, function_command, _("\
Placeholder command for showing help on convenience functions."),
&functionlist, "function ", 0, &cmdlist);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
+ make_final_cleanup (value_history_cleanup, NULL);
2009-03-02 00:11:35 +00:00
+
2011-03-05 12:24:53 +00:00
+#if 0
2009-08-04 05:37:29 +00:00
+ observer_attach_mark_used (value_types_mark_used);
2011-03-05 12:24:53 +00:00
+#endif
2009-08-04 05:37:29 +00:00
}
2012-01-03 15:00:12 +00:00
diff --git a/gdb/value.h b/gdb/value.h
2013-02-18 17:14:00 +00:00
index c10c3ec..8d07348 100644
2012-01-03 15:00:12 +00:00
--- a/gdb/value.h
+++ b/gdb/value.h
2013-02-18 17:14:00 +00:00
@@ -537,6 +537,10 @@ extern struct value *value_from_decfloat (struct type *type,
2009-08-04 05:37:29 +00:00
const gdb_byte *decbytes);
2011-03-05 12:24:53 +00:00
extern struct value *value_from_history_ref (char *, char **);
2009-08-04 05:37:29 +00:00
+extern const char *object_address_data_not_valid (struct type *type);
2010-07-21 21:30:20 +00:00
+extern struct type *object_address_get_data (struct type *type,
+ CORE_ADDR *address_return);
2009-03-02 00:11:35 +00:00
+
2009-08-04 05:37:29 +00:00
extern struct value *value_at (struct type *type, CORE_ADDR addr);
extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);