Commit Graph

241 Commits

Author SHA1 Message Date
Yao Qi 9730e6ccc4 Compute the function length instead of hard coding it
In Dwarf::assemble in dwz.exp, 10 is hard-coded in it,

 	    subprogram {
 		{name main}
 		{low_pc main addr}
		{high_pc "main + 10" addr}
 	    }

however, the length of main function varies on architectures.  The
hard-coded 10 here causes dwz.exp fails on some targets, such as
nios2.

This patch is to add some code to compute the length of function main,
which is similar to what we are doing in entry-values.exp.

gdb/testsuite:

2014-04-26  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dwz.exp: Compile main.c to object.  Restart GDB
	and compute the length of function main.  Save it in
	$main_length.
	(Dwarf::assemble): Use $main_length instead of hard-coded 10.
	(top-level): Use gdb_compile to compile objects into
	executable and restart GDB.  Remove invocation to
	prepare_for_testing.
2014-04-26 10:45:06 +08:00
Yao Qi 4c2d33e7a2 Remove unused labels in dwarf assembler
I happen to see that 'double_label' isn't used in dwz.exp dwarf assembler.
Similarly, partial_label and double_label aren't used in dwzbuildid.exp.
This patch is to remove them.

gdb/testsuite:

2014-04-25  Yao Qi  <yao@codesourcery.com>

	* gdb.dwarf2/dwz.exp (Dwarf::assemble): Remove unused
	double_label.
	* gdb.dwarf2/dwzbuildid.exp (Dwarf::assemble): Remove
	partial_label and double_label.
2014-04-25 08:57:08 +08:00
Keith Seitz 22869d73e1 PR gdb/15827
Install some sanity checks that sibling DIE offsets are not beyond the
defined limits of the DWARF input buffer in read_partial_die and skip_one_die.

2014-03-20  Keith Seitz  <keiths@redhat.com>

	PR gdb/15827
	* dwarf2read.c (skip_one_die): Check that all relative-offset
	sibling DIEs fall within range of the current reader's buffer.
	(read_partial_die): Likewise.

2014-03-20  Keith Seitz  <keiths@redhat.com>

	PR gdb/15827
	* gdb.dwarf2/corrupt.c: New file.
	* gdb.dwarf2/corrupt.exp: New file.
2014-04-16 14:39:10 -07:00
Keith Seitz b50c861487 Remove symbol_matches_domain. This fixes
PR c++/16253.

symbol_matches_domain was permitting searches for a VAR_DOMAIN
symbol to also match STRUCT_DOMAIN symbols for languages like C++
where STRUCT_DOMAIN symbols also define a typedef of the same name,
e.g., "struct foo {}" introduces a typedef of the name "foo".

Problems occur if there exists both a VAR_DOMAIN and STRUCT_DOMAIN
symbol of the same name. Then it is essentially a race between which
symbol is found first. The other symbol is obscurred.
[This is a relatively common idiom: enum e { ... } e;]

This patchset moves this "language defines a typedef" logic to
lookup_symbol[_in_language], looking first for a symbol in the given
domain and falling back to searching STRUCT_DOMAIN when/if appropriate.

2014-04-14  Keith Seitz  <keiths@redhat.com>

	PR c++/16253
	* ada-lang.c (ada_symbol_matches_domain): Moved here and renamed
	from symbol_matches_domain in symtab.c. All local callers
	of symbol_matches_domain updated.
	(standard_lookup): If DOMAIN is VAR_DOMAIN and no symbol is found,
	search STRUCT_DOMAIN.
	(ada_find_any_type_symbol): Do not search STRUCT_DOMAIN
	independently.  standard_lookup will do that automatically.
	* cp-namespace.c (cp_lookup_symbol_nonlocal): Explain when/why
	VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
	(cp_lookup_symbol_in_namespace): Likewise.
	If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN.
	(cp_lookup_symbol_exports): Explain when/why VAR_DOMAIN searches
	may return a STRUCT_DOMAIN match.
	(lookup_symbol_file): Search for the class name in STRUCT_DOMAIN.
	* cp-support.c: Include language.h.
	(inspect_type): Explicitly search STRUCT_DOMAIN before searching
	VAR_DOMAIN.
	* psymtab.c (match_partial_symbol): Compare the requested
	domain with the symbol's domain directly.
	(lookup_partial_symbol): Likewise.
	* symtab.c (lookup_symbol_in_language): Explain when/why
	VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
	If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN for
	appropriate languages.
	(symbol_matches_domain): Renamed `ada_symbol_matches_domain'
	and moved to ada-lang.c
	(lookup_block_symbol): Explain that this function only returns
	symbol matching the requested DOMAIN.
	Compare the requested domain with the symbol's domain directly.
	(iterate_over_symbols): Compare the requested domain with the
	symbol's domain directly.
	* symtab.h (symbol_matches_domain): Remove.

2014-04-14  Keith Seitz  <keiths@redhat.com>

	PR c++/16253
	* gdb.cp/var-tag.cc: New file.
	* gdb.cp/var-tag.exp: New file.
	* gdb.dwarf2/dw2-ada-ffffffff.exp: Set the language to C++.
	* gdb.dwarf2/dw2-anon-mptr.exp: Likewise.
	* gdb.dwarf2/dw2-double-set-die-type.exp: Likewise.
	* gdb.dwarf2/dw2-inheritance.exp: Likewise.
2014-04-14 15:47:15 -07:00
Tom Tromey 3d567982ac implement support for "enum class"
This adds support for the C++11 "enum class" feature.  This is
PR c++/15246.

I chose to use the existing TYPE_DECLARED_CLASS rather than introduce
a new type code.  This seemed both simple and clear to me.

I made overloading support for the new enum types strict.  This is how
it works in C++; and it didn't seem like an undue burden to keep this,
particularly because enum constants are printed symbolically by gdb.

Built and regtested on x86-64 Fedora 20.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	PR c++/15246:
	* c-exp.y (type_aggregate_p): New function.
	(qualified_name, classify_inner_name): Use it.
	* c-typeprint.c (c_type_print_base): Handle TYPE_DECLARED_CLASS
	and TYPE_TARGET_TYPE of an enum type.
	* dwarf2read.c (read_enumeration_type): Set TYPE_DECLARED_CLASS on
	an enum type.
	(determine_prefix) <case DW_TAG_enumeration_type>: New case;
	handle TYPE_DECLARED_CLASS.
	* gdbtypes.c (rank_one_type): Handle TYPE_DECLARED_CLASS on enum
	types.
	* gdbtypes.h (TYPE_DECLARED_CLASS): Update comment.
	* valops.c (enum_constant_from_type): New function.
	(value_aggregate_elt): Use it.
	* cp-namespace.c (cp_lookup_nested_symbol): Handle
	TYPE_CODE_ENUM.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* gdb.cp/classes.exp (test_enums): Handle underlying type.
	* gdb.dwarf2/enum-type.exp: Add test for enum with underlying
	type.
	* gdb.cp/enum-class.exp: New file.
	* gdb.cp/enum-class.cc: New file.
2014-04-14 11:42:18 -06:00
Tom Tromey 0626fc76d1 handle DW_AT_type on an enumeration
DWARF allows an enumeration type to have a DW_AT_type.  GDB doesn't
recognize this, but there is a patch to change GCC to emit it, and a
DWARF proposal to further allow an enum type with a DW_AT_type to omit
the DW_AT_byte_size.  This patch changes gdb to implement this.

Built and regtested on x86-64 Fedora 20.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* dwarf2read.c (read_enumeration_type): Handle DW_AT_type.

2014-04-14  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/enum-type.exp: New file.
2014-04-14 11:42:17 -06:00
Sanimir Agovic 3dd170be25 test: cover subranges with present DW_AT_count attribute
The dwarf attribute DW_AT_count specifies the elements of a subrange.
This test covers subranges with present count but absent upper bound
attribute, both with static and dynamic attribute values.

testsuite/ChangeLog:

	* gdb.dwarf2/count.exp: New file.
2014-04-14 09:23:44 -07:00
Joel Brobecker 6b662e19e4 Revert the entire VLA series.
This reverts the following patch series, as they cause some regresssions.

commit 37c1ab67a3
type: add c99 variable length array support

	gdb/
	* dwarf2loc.c (dwarf2_locexpr_baton_eval): New function.
	(dwarf2_evaluate_property): New function.
	* dwarf2loc.h (dwarf2_evaluate_property): New function prototype.
	* dwarf2read.c (attr_to_dynamic_prop): New function.
	(read_subrange_type): Use attr_to_dynamic_prop to read high bound
	attribute.
	* gdbtypes.c: Include dwarf2loc.h.
	(is_dynamic_type): New function.
	(resolve_dynamic_type): New function.
	(resolve_dynamic_bounds): New function.
	(get_type_length): New function.
	(check_typedef): Use get_type_length to compute type length.
	* gdbtypes.h (TYPE_HIGH_BOUND_KIND): New macro.
	(TYPE_LOW_BOUND_KIND): New macro.
	(is_dynamic_type): New function prototype.
	* value.c (value_from_contents_and_address): Call resolve_dynamic_type
	to resolve dynamic properties of the type. Update comment.
	* valops.c (get_value_at, value_at, value_at_lazy): Update comment.

commit 26cb189f8b
vla: enable sizeof operator to work with variable length arrays

	gdb/
	* eval.c (evaluate_subexp_for_sizeof) <OP_VAR_VALUE>: If the type
	passed to sizeof is dynamic evaluate the argument to compute the length.

commit 04b19544ef
vla: enable sizeof operator for indirection

	gdb/
	* eval.c (evaluate_subexp_for_sizeof) <UNOP_IND>: Create an indirect
	value and retrieve the dynamic type size.

commit bcd629a44f
vla: update type from newly created value

	gdb/
	* ada-lang.c (ada_value_primitive_packed_val): Re-fetch type from value.
	(ada_template_to_fixed_record_type_1): Likewise.
	(ada_to_fixed_type_1): Likewise.
	* cp-valprint.c (cp_print_value_fields_rtti): Likewise.
	(cp_print_value): Likewise.
	* d-valprint.c (dynamic_array_type): Likewise.
	* eval.c (evaluate_subexp_with_coercion): Likewise.
	* findvar.c (address_of_variable): Likewise.
	* jv-valprint.c (java_value_print): Likewise.
	* valops.c (value_ind): Likewise.
	* value.c (coerce_ref): Likewise.

commit b86138fb04
vla: print "variable length" for unresolved dynamic bounds

	gdb/
	* c-typeprint.c (c_type_print_varspec_suffix): Added
	check for not yet resolved high bound. If unresolved, print
	"variable length" string to the console instead of random
	length.

commit e1969afbd4
vla: support for DW_AT_count

	gdb/
	* dwarf2read.c (read_subrange_type): Convert DW_AT_count to a dynamic
	property and store it as the high bound and flag the range accordingly.
	* gdbtypes.c (resolve_dynamic_bounds): If range is flagged as
	RANGE_UPPER_BOUND_IS_COUNT assign low + high - 1 as the new high bound.
	* gdbtypes.h (enum range_flags): New enum.
	(struct range_bounds): Add flags member.

commit 92b09522dc
vla: resolve dynamic bounds if value contents is a constant byte-sequence

	gdb/
	* findvar.c (default_read_var_value): Resolve dynamic bounds if location
	points to a constant blob.

commit 3bce82377f
vla: evaluate operand of sizeof if its type is a vla

	gdb/
	* eval.c (evaluate_subexp_for_sizeof): Add enum noside argument.
	(evaluate_subexp_standard): Pass noside argument.
	(evaluate_subexp_for_sizeof) <BINOP_SUBSCRIPT>: Handle subscript case
	if noside equals EVAL_NORMAL. If the subscript yields a vla type
	re-evaluate subscript operation with EVAL_NORMAL to enable sideffects.
	* gdbtypes.c (resolve_dynamic_bounds): Mark bound as evaluated.
	* gdbtypes.h (enum range_flags): Add RANGE_EVALUATED case.

	gdb/testsuite

	* gdb.base/vla-sideeffect.c: New file.
	* gdb.base/vla-sideeffect.exp: New file.

commit 504f34326e
test: cover subranges with present DW_AT_count attribute

	gdb/testsuite/
	* gdb.dwarf2/count.exp: New file.

commit 1a237e0ee5
test: multi-dimensional c99 vla.

	gdb/testsuite/
	* gdb.base/vla-multi.c: New file.
	* gdb.base/vla-multi.exp: New file.

commit 024e13b46f
test: evaluate pointers to C99 vla correctly.

	gdb/testsuite/
	* gdb.base/vla-ptr.c: New file.
	* gdb.base/vla-ptr.exp: New file.

commit c8655f75e2
test: basic c99 vla tests for C primitives

	gdb/testsuite/
	* gdb.base/vla-datatypes.c: New file.
	* gdb.base/vla-datatypes.exp: New file.

commit 58a84dcf29
test: add mi vla test

	gdb/testsuite/
	* gdb.mi/mi-vla-c99.exp: New file.
	* gdb.mi/vla.c: New file.
2014-04-11 15:26:21 -07:00
Sanimir Agovic 504f34326e test: cover subranges with present DW_AT_count attribute
The dwarf attribute DW_AT_count specifies the elements of a subrange.
This test covers subranges with present count but absent upper bound
attribute, both with static and dynamic attribute values.

testsuite:
	* gdb.dwarf2/count.exp: New file.
2014-04-11 13:43:56 +01:00
Doug Evans 5d1ef36157 * gdb.dwarf2/dw2-abs-hi-pc.exp: Build tests with "nodebug". 2014-03-27 11:38:30 -07:00
Andreas Arnez 646f441776 Fix dw2-ifort-parameter.exp on PPC64
On PPC64, 'func' and 'main' are function descriptors and don't point
to the actual code.  Thus the usage of these symbols in the DWARF
assembler source was broken.  The patch introduces new labels
func_start and func_end for this purpose.
2014-03-12 16:22:19 +01:00
Andreas Arnez 288c211f8c Migrate dw2-ifort-parameter.exp to Dwarf::assemble
A "side effect" of the migration to Dwarf::assemble is that the DWARF
address size is now automatically adjusted to the target architecture.
The original assembler source hard-coded the DWARF address size to 4,
even on 64-bit architectures.  This address size mismatch caused a
test case failure on s390x due to a wrong result from DW_OP_deref.
2014-03-12 16:22:19 +01:00
Andreas Arnez e0c0f156b4 Exploit 'prepare_for_testing' etc. for 'Dwarf::assemble'-generated files
Now that prepare_for_testing etc. can cope with absolute path names,
this can be exploited for test cases with generated source files.
This is just to simplify the code and shouldn't cause any functional
change.
2014-03-12 16:22:18 +01:00
Joel Brobecker 31aa7e4ee9 DWARF: Read constant-class addresses correctly
Starting with DWARF version 4, the description of the DW_AT_high_pc
attribute was amended to say:

   if it is of class constant, the value is an unsigned integer offset
   which when added to the low PC gives the address of the first
   location past the last instruction associated with the entity.

A change was made in Apr 27th, 2012 to reflect that change:

  | commit 91da14142c
  | Author: Mark Wielaard <mjw@redhat.com>
  | Date:   Fri Apr 27 18:55:19 2012 +0000
  |
  |     * dwarf2read.c (dwarf2_get_pc_bounds): Check DW_AT_high_pc form to
  |     see whether it is an address or a constant offset from DW_AT_low_pc.
  |     (dwarf2_record_block_ranges): Likewise.
  |     (read_partial_die): Likewise.

Unfortunately, this new interpretation is now used regardless of
the CU's DWARF version. It turns out that one of WindRiver's compilers
(FTR: Diabdata 4.4) is generating DWARF version 2 info with
DW_AT_high_pc attributes improperly using the data4 form. Because of
that, we miscompute all high PCs incorrectly. This leads to a lot of
symtabs having overlapping ranges, which in turn causes havoc in
pc-to-symtab-and-line translations.

One visible effect is when inserting a breakpoint on a given function:

    (gdb) b world
    Breakpoint 1 at 0x4005c4

The source location of the breakpoint is missing. The output should be:

    (gdb) b world
    Breakpoint 1 at 0x4005c8: file dw2-rel-hi-pc-world.c, line 24.

What happens in this case is that the pc-to-SAL translation first
starts be trying to find the symtab associated to our PC using
each symtab's ranges. Because of the high_pc miscomputation,
many symtabs end up matching, and the heuristic trying to select
the most probable one unfortunately returns one that is unrelated
(it really had no change in this case to do any better). Once we
have the wrong symtab, the start searching the associated linetable,
where the addresses are correct, thus finding no match, and therefore
no SAL.

This patch is an attempt at handling the situation as gracefully
as we can, without guarantees.  It introduces a new function
"attr_value_as_address" which uses the correct accessor for getting
the value of a given attribute.  It then adjust the code throughout
this unit to use this function instead of assuming that addresses always
have the DW_FORM_addr format.

It also fixes the original issue of miscomputing the high_pc
by limiting the new interpretation of constant form DW_AT_high_pc
attributes to units using DWARF version 4 or later.

gdb/ChangeLog:

        * dwarf2read.c (attr_value_as_address): New function.
        (dwarf2_find_base_address, read_call_site_scope): Use
        attr_value_as_address in place of DW_ADDR.
        (dwarf2_get_pc_bounds): Use attr_value_as_address to get
        the low and high addresses.  Slight rework of the handling
        of the high pc being a constant form, and limit it to
        DWARF verson 4 or higher.
        (dwarf2_record_block_ranges): Likewise.
        (read_partial_die): Likewise.
        (new_symbol_full): Use attr_value_as_address in place of DW_ADDR.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-abs-hi-pc-hello-dbg.S: New file.
        * gdb.dwarf2/dw2-abs-hi-pc-hello.c: New file.
        * gdb.dwarf2/dw2-abs-hi-pc-world-dbg.S: New file.
        * gdb.dwarf2/dw2-abs-hi-pc-world.c: New file.
        * gdb.dwarf2/dw2-abs-hi-pc.c: New file.
        * gdb.dwarf2/dw2-abs-hi-pc.exp: New file.

Tested on x86_64-linux.
2014-02-26 11:43:23 -08:00
Joel Brobecker 55426c9d52 DWARF: Set enum type "flag_enum" and "unsigned" flags at type creation.
Consider the following Ada code:

   --  An array whose index is an enumeration type with 128 enumerators.
   type Enum_T is (Enum_000, Enum_001, [...], Enum_128);
   type Table is array (Enum_T) of Boolean;

When the compiler is configured to generate pure DWARF debugging info,
trying to print type Table's description yields:

    ptype pck.table
    type = array (enum_000 .. -128) of boolean

The expected output was:

    ptype pck.table
    type = array (enum_000 .. enum_128) of boolean

The DWARF debugging info for our array looks like this:

    <1><44>: Abbrev Number: 5 (DW_TAG_array_type)
       <45>   DW_AT_name        : pck__table
       <50>   DW_AT_type        : <0x28>
    <2><54>: Abbrev Number: 6 (DW_TAG_subrange_type)
       <55>   DW_AT_type        : <0x5c>
       <59>   DW_AT_lower_bound : 0
       <5a>   DW_AT_upper_bound : 128

The array index type is, by construction with the DWARF standard,
a subrange of our enumeration type, defined as follow:

    <2><5b>: Abbrev Number: 0
    <1><5c>: Abbrev Number: 7 (DW_TAG_enumeration_type)
       <5d>   DW_AT_name        : pck__enum_t
       <69>   DW_AT_byte_size   : 1
    <2><6b>: Abbrev Number: 8 (DW_TAG_enumerator)
       <6c>   DW_AT_name        : pck__enum_000
       <7a>   DW_AT_const_value : 0
    [etc]

Therefore, while processing these DIEs, the array index type ends
up being a TYPE_CODE_RANGE whose target type is our enumeration type.
But the problem is that we read the upper bound as a negative value
(-128), which is then used as is by the type printer to print the
array upper bound. This negative value explains the "-128" in the
output.

To understand why the range type's upper bound is read as a negative
value, one needs to look at how it is determined, in read_subrange_type:

  orig_base_type = die_type (die, cu);
  base_type = check_typedef (orig_base_type);
  [... high is first correctly read as 128, but then ...]
  if (!TYPE_UNSIGNED (base_type) && (high & negative_mask))
    high |= negative_mask;

The negative_mask is applied, here, because BASE_TYPE->FLAG_UNSIGNED
is not set. And the reason for that is because the base_type was only
partially constructed during the call to die_type. While the enum
is constructed on the fly by read_enumeration_type, its flag_unsigned
flag is only set later on, while creating the symbols corresponding to
the enum type's enumerators (see process_enumeration_scope), after
we've already finished creating our range type - and therefore too
late.

My first naive attempt at fixing this problem consisted in extracting
the part in process_enumeration_scope which processes all enumerators,
to generate the associated symbols, but more importantly set the type's
various flags when necessary. However, this does not always work well,
because we're still in the subrange_type's scope, and it might be
different from the scope where the enumeration type is defined.

So, instead, what this patch does to fix the issue is to extract
from process_enumeration_scope the part that determines whether
the enumeration type should have the flag_unsigned and/or the
flag_flag_enum flags set. It turns out that, aside from the code
implementing the loop, this part is fairly independent of the symbol
creation. With that part extracted, we can then use it at the end
of our enumeration type creation, to produce a type which should now
no longer need any adjustment.

Once the enumeration type produced is correctly marked as unsigned,
the subrange type's upper bound is then correctly read as an unsigned
value, therefore giving us an upper bound of 128 instead of -128.

gdb/ChangeLog:

        * dwarf2read.c (update_enumeration_type_from_children): New
        function, mostly extracted from process_structure_scope.
        (read_enumeration_type): Call update_enumeration_type_from_children.
        (process_enumeration_scope): Do not set THIS_TYPE's flag_unsigned
        and flag_flag_enum fields.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/arr-subrange.c, gdb.dwarf2/arr-subrange.exp: New files.
2014-02-26 10:39:25 -08:00
Joel Brobecker dc53a7adb5 DWARF: Add array DW_AT_bit_stride and DW_AT_byte_stride support
Consider the following declarations in Ada...

   type Item is range -32 .. 31;
   for Item'Size use 6;

   type Table is array (Natural range 0 .. 4) of Item;
   pragma Pack (Table);

... which declare a packed array whose elements are 6 bits long.
The debugger currently does not notice that the array is packed,
and thus prints values of this type incorrectly. This can be seen
in the "ptype" output:

    (gdb) ptype table
    type = array (0 .. 4) of foo.item

Normally, the debugger should print:

    (gdb) ptype table
    type = array (0 .. 4) of foo.item <packed: 6-bit elements>

The debugging information for this array looks like this:

        .uleb128 0xf    # (DIE (0x15c) DW_TAG_array_type)
        .long   .LASF9  # DW_AT_name: "pck__table"
        .byte   0x6     # DW_AT_bit_stride
        .long   0x1a9   # DW_AT_type
        .uleb128 0x10   # (DIE (0x16a) DW_TAG_subrange_type)
        .long   0x3b    # DW_AT_type
        .byte   0       # DW_AT_lower_bound
        .byte   0x4     # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x15c

The interesting part is the DW_AT_bit_stride attribute, which tells
the size of the array elements is 6 bits, rather than the normal
element type's size.

This patch adds support for this attribute by first creating
gdbtypes.c::create_array_type_with_stride, which is an enhanced
version of create_array_type taking an extra parameter as the stride.
The old create_array_type can then be re-implemented very simply
by calling the new create_array_type_with_stride.

We can then use this new function from dwarf2read, to create
arrays with or without stride.

gdb/ChangeLog:

        * gdbtypes.h (create_array_type_with_stride): Add declaration.
        * gdbtypes.c (create_array_type_with_stride): New function,
        renaming create_array_type, but with an added parameter
        called "bit_stride".
        (create_array_type): Re-implement using
        create_array_type_with_stride.
        * dwarf2read.c (read_array_type): Add support for DW_AT_byte_stride
        and DW_AT_bit_stride attributes.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/arr-stride.c: New file.
        * gdb.dwarf2/arr-stride.exp: New file.

The test, relying purely on generating an assembly file, only
verifies the type description of our array. But I was also
able to verify manually that the debugger print values of these
types correctly as well (which was not the case prior to this
patch).
2014-02-26 06:32:39 -08:00
Jan Kratochvil e2f0d509b3 Fix dw2-icycle.exp -fsanitize=address GDB crash.
binutils readelf -wi:
 <4><a2>: Abbrev Number: 26 (DW_TAG_inlined_subroutine)
    <a3>   DW_AT_abstract_origin: <0x5a>
    <a7>   DW_AT_low_pc      : 0x400590
    <ab>   DW_AT_high_pc     : 0x4
    <af>   DW_AT_call_file   : 1
    <b0>   DW_AT_call_line   : 20
    <b1>   DW_AT_sibling     : <0xb8>
 <2><b8>: Abbrev Number: 35 (DW_TAG_inlined_subroutine)
    <b9>   DW_AT_abstract_origin: <0x5a>
    <bd>   DW_AT_low_pc      : 0x400590
    <c1>   DW_AT_high_pc     : 0x4
    <c5>   DW_AT_call_file   : 1
    <c6>   DW_AT_call_line   : 29

<b1> DW_AT_sibling points to the next DIE - but that DIE is 2 levels
upwards - definitely not a sibling.  This confuses GDB up to a crash:

==32143== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6024000198ac at pc 0xb4d104 bp 0x7fff63e96e70 sp
0x7fff63e96e60
READ of size 1 at 0x6024000198ac thread T0
    #0 0xb4d103 in read_unsigned_leb128 (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb4d103)
    #1 0xb15f3c in peek_die_abbrev (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb15f3c)
    #2 0xb46185 in load_partial_dies (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb46185)
    #3 0xb103fb in process_psymtab_comp_unit_reader (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb103fb)
    #4 0xb0d2a9 in init_cutu_and_read_dies (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb0d2a9)
    #5 0xb1115f in process_psymtab_comp_unit (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb1115f)
    #6 0xb1235f in dwarf2_build_psymtabs_hard (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb1235f)
    #7 0xb05536 in dwarf2_build_psymtabs (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0xb05536)
    #8 0x86d5a5 in read_psyms (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0x86d5a5)
    #9 0x9b1c37 in require_partial_symbols (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0x9b1c37)
    #10 0x9bf2d0 in read_symbols (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0x9bf2d0)
    #11 0x9c014c in syms_from_objfile_1 (/home/jkratoch/redhat/gdb-clean/gdb/gdb+0x9c014c)

gdb/testsuite/
2014-02-25  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix dw2-icycle.exp -fsanitize=address GDB crash.
	* gdb.dwarf2/dw2-icycle.S: Remove all DW_AT_sibling.

Message-ID: <20140224201011.GA28926@host2.jankratochvil.net>
2014-02-25 18:28:38 +01:00
Joel Brobecker 83deb43f87 Simplify .section in dw2-icycle.S
The arm-elf assembler chokes on the extra parameters in the .section
pseudo-op, so this patch removes them.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/dw2-icycle.S: Remove second and third parameters
        in .section pseudo-op.
2014-02-20 18:38:44 +01:00
Doug Evans adde2bff07 Fix PR symtab/16581
* dwarf2read.c (struct die_info): New member in_process.
	(reset_die_in_process): New function.
	(process_die): Set it at the start, reset when returning.
	(inherit_abstract_dies): Only call process_die if origin_child_die
	not already being processed.

	testsuite/
	* gdb.dwarf2/dw2-icycle.S: New file.
	* gdb.dwarf2/dw2-icycle.c: New file.
	* gdb.dwarf2/dw2-icycle.exp: New file.
2014-02-20 09:13:53 -08:00
Doug Evans 85f224e7e0 Test for binary,dwp symlinks into different directories.
* gdb.dwarf2/Makefile.in (EXECUTABLES): Add dwp-symlink.
	(MISCELLANEOUS): New variable.
	(clean): rm -rf $(MISCELLANEOUS).
	* gdb.dwarf2/dwp-symlink.exp: Test the case where the executable and
	dwp live in the same directory as symlinks, with each symlink pointed
	to a differently named file in a different directory.
2014-02-12 11:38:48 -08:00
Doug Evans 149b30ffe4 * gdb.dwarf2/dwp-symlink.exp: Rewrite to use remote_* commands instead
of Tcl file commands.
2014-02-11 15:48:44 -08:00
Andreas Arnez 20fa339009 Re-introduce '_start' labels and add alignment in dw2-dir-file-name test case.
On ppc64-linux a function symbol does not point to code, but to the
function descriptor.  Thus the previous change for this test case
broke it:

      https://sourceware.org/ml/gdb-patches/2014-01/msg00275.html

This patch reverts to the original method, re-introducing '_start'
symbols.  In addition, it adds sufficient alignment before the label,
such that the label never points into an alignment gap.

gdb/testsuite/ChangeLog:
	* gdb.dwarf2/dw2-dir-file-name.c (FUNC): Insert alignment and
	define "*_start" label.  Make "name" static.
	* gdb.dwarf2/dw2-dir-file-name.exp: Replace references to
	${name} by references to ${name}_start.
2014-01-22 17:02:13 +01:00
Omair Javaid 93a360cc5d Fix testsuite/gdb.dwarf2/dw2-dos-drive.exp on ARM.
This test currently fails on ARM:

  (gdb) PASS: gdb.dwarf2/dw2-dos-drive.exp: set breakpoint pending off
  break 'z:file.c':func
  Cannot access memory at address 0x0

The error is GDB trying to read the prologue at the breakpoint's
address, and failing:

  38 throw_error() exceptions.c:444 0x0016728c
  37 memory_error() corefile.c:204 0x001d1fcc
  36 read_memory() corefile.c:223 0x001d201a
  35 read_memory_unsigned_integer() corefile.c:312 0x001d2166
  34 arm_skip_prologue() arm-tdep.c:1452 0x00054270

  static CORE_ADDR
  arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  {
  ...
    for (skip_pc = pc; skip_pc < limit_pc; skip_pc += 4)
      {
        inst = read_memory_unsigned_integer (skip_pc, 4, byte_order_for_code);


The test doesn't execute the compiled object's code, so GDB will try
to read memory from the binary's sections.  Instructions on ARM are
4-byte wide, and thus ARM's prologue scanner reads in 4-byte chunks.
As the section 'func' is put at is only 1 byte long, and no other
section is allocated contiguously:

  ...
  Sections:
  Idx Name          Size      VMA       LMA       File off  Algn
    0 .text         00000001  00000000  00000000  00000034  2**0
                    CONTENTS, ALLOC, LOAD, READONLY, CODE
  ...

... the exec target fails the read the 4 bytes.

Fix this by increasing the function's size.

gdb/testsuite/ChangeLog:
2014-01-16  Omair Javaid  <Omair.Javaid@linaro.org>

	* gdb.dwarf2/dw2-dos-drive.S: Increase text section size to 4
	bytes.
2014-01-16 10:09:34 +00:00
Andreas Arnez 52d7fb1303 Since upstream gcc has recently increased the function alignment on
S390, the dw2-dir-file-name test case fails in the first
gdb_continue_to_breakpoint.  Indeed, the breakpoint is now placed into
the alignment gap *before* the actual function.

This happens because the test case declares the respective "*_start"
symbol as a "loose" label before the function definition, and the
compiler inserts the alignment between that label and the function
itself.

The "*_start" symbols were only necessary because FUNC made the
function static.  The fix makes the functions extern instead, thus
making the "*_start" labels unnecessary.

testsuite/
2014-01-10  Andreas Arnez  <arnez@linux.vnet.ibm.com>
	    Pedro Alves <palves@redhat.com>

	* gdb.dwarf2/dw2-dir-file-name.c (FUNC): Remove "*_start" symbol.
	Make "name" extern.
	* gdb.dwarf2/dw2-dir-file-name.exp (out_cu, out_line): Replace
	references to ${name}_start by references to ${name}.
2014-01-10 15:37:36 +00:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Pedro Alves 782d47dfbd Fix "info frame" in the outermost frame.
Doing "info frame" in the outermost frame, when that was indicated by
the next frame saying the unwound PC is undefined/not saved, results
in error and incomplete output:

 (gdb) bt
 #0  thread_function0 (arg=0x0) at threads.c:63
 #1  0x00000034cf407d14 in start_thread (arg=0x7ffff7fcb700) at pthread_create.c:309
 #2  0x000000323d4f168d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115

 (gdb) frame 2
 #2  0x000000323d4f168d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115
 115             call    *%rax

 (gdb) info frame
 Stack level 2, frame at 0x0:
  rip = 0x323d4f168d in clone (../sysdeps/unix/sysv/linux/x86_64/clone.S:115); saved rip Register 16 was not saved
 (gdb)

Not saved register values are treated as optimized out values
internally throughout.  stack.c:frame_info is handing unvailable
values, but not optimized out ones.  The patch deletes the
frame_unwind_caller_pc_if_available wrapper function and instead lets
errors propagate to frame_info (it's only user).

As frame_unwind_pc now needs to be able to handle and cache two
different error scenarios, the prev_pc.p variable is replaced with an
enumeration.

(FWIW, I looked into making gdbarch_unwind_pc or a variant return
struct value's instead, but it results in lots of boxing and unboxing
for no real gain -- e.g., the mips and arm implementations need to do
computation on the unboxed PC value.  Might as well throw an error on
first attempt to get at invalid contents.)

After the patch, we get:

 (gdb) info frame
 Stack level 2, frame at 0x0:
  rip = 0x323d4f168d in clone (../sysdeps/unix/sysv/linux/x86_64/clone.S:115); saved rip = <not saved>
  Outermost frame: outermost
  caller of frame at 0x7ffff7fcafc0
  source language asm.
  Arglist at 0x7ffff7fcafb8, args:
  Locals at 0x7ffff7fcafb8, Previous frame's sp is 0x7ffff7fcafc8
 (gdb)

A new test is added.  It's based off dw2-reg-undefined.exp, and tweaked to
mark the return address (rip) of "stop_frame" as undefined.

Tested on x86_64 Fedora 17.

gdb/
2013-12-06  Pedro Alves  <palves@redhat.com>

	* frame.c (enum cached_copy_status): New enum.
	(struct frame_info) <prev_pc.p>: Change type to enum
	cached_copy_status.
	(fprint_frame): Handle not saved and unavailable prev_pc values.
	(frame_unwind_pc_if_available): Delete and merge contents into ...
	(frame_unwind_pc): ... here.  Handle OPTIMIZED_OUT_ERROR.  Adjust
	to use enum cached_copy_status.
	(frame_unwind_caller_pc_if_available): Delete.
	(create_new_frame): Adjust.
	* frame.h (frame_unwind_caller_pc_if_available): Delete
	declaration.
	* stack.c (frame_info): Use frame_unwind_caller_pc instead of
	frame_unwind_caller_pc_if_available, and handle
	NOT_AVAILABLE_ERROR and OPTIMIZED_OUT_ERROR errors.
	* valprint.c (val_print_optimized_out): Use val_print_not_saved.
	(val_print_not_saved): New function.
	* valprint.h (val_print_not_saved): Declare.

gdb/testsuite/
2013-12-06  Pedro Alves  <palves@redhat.com>

	* gdb.dwarf2/dw2-undefined-ret-addr.S: New file.
	* gdb.dwarf2/dw2-undefined-ret-addr.c: New file.
	* gdb.dwarf2/dw2-undefined-ret-addr.exp: New file.
2013-12-06 19:50:10 +00:00
Jan Kratochvil 04affae3ef Record objfile->original_name as an absolute path
gdb/
2013-12-02  Doug Evans  <dje@google.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	* objfiles.c (allocate_objfile): Save original_name as an absolute
	path.
	* objfiles.h (struct objfile): Expand comment on original_name.
	* source.c (openp): Call gdb_abspath.
	* utils.c (gdb_abspath): New function.
	* utils.h (gdb_abspath): Declare.

gdb/testsuite/
2013-12-02  Doug Evans  <dje@google.com>

	* gdb.dwarf/dwp-symlink.c: Fake out gdb to not load debug info
	at start.
	* gdb.dwarf/dwp-symlink.exp: Test trying to load dwp when the binary
	has been specified with a relative path and we have chdir'd before
	accessing the debug info.
2013-12-02 22:24:32 +01:00
Tom Tromey 158599681f revert patch from 2013-11-22
This reverts da2b2fdf57 and some
follow-up patches.  They were incorrect.

2013-11-26  Tom Tromey  <tromey@redhat.com>

	* dwarf2-frame.c (dwarf2_frame_cache): Revert patch from
	2013-11-22.

2013-11-26  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/dw2-unspecified-ret-addr.S: Remove.
	* gdb.dwarf2/dw2-unspecified-ret-addr.c: Remove.
	* gdb.dwarf2/dw2-unspecified-ret-addr.exp: Remove.
2013-11-26 07:47:56 -07:00
Pedro Alves c0621699ff Rename gdb.dwarf2/dw2-bad-cfi.* to gdb.dwarf2/dw2-unspecified-ret-addr.*.
gdb/testsuite/
2013-11-22  Pedro Alves  <palves@redhat.com>

	* gdb.dwarf2/dw2-bad-cfi.S: Rename to ...
	* gdb.dwarf2/dw2-unspecified-ret-addr.S: ... this.  Adjust.
	* gdb.dwarf2/dw2-bad-cfi.c: Rename to ...
	* gdb.dwarf2/dw2-unspecified-ret-addr.c: ... this.
	* gdb.dwarf2/dw2-bad-cfi.exp: Rename to ...
	* gdb.dwarf2/dw2-unspecified-ret-addr.exp: ... this.
2013-11-22 19:19:13 +00:00
Tom Tromey f57e61cdf6 update comment in dw2-bad-cfi.S.
Pedro asked me to add a comment to dw2-bad-cfi.S explaining the nature
of the badness.

I'm checking this in.

2013-11-22  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/dw2-bad-cfi.S: Update comment.
2013-11-22 12:08:15 -07:00
Tom Tromey da2b2fdf57 handle an unspecified return address column
Debugging PR 16155 further, I found that the DWARF unwinder found the
function in question, but thought it had no registers saved
(fs->regs.num_regs == 0).

It seems to me that if a frame does not specify the return address
column, or if the return address column is explicitly marked as
DWARF2_FRAME_REG_UNSPECIFIED, then we should set the
"undefined_retaddr" flag and let the DWARF unwinder gracefully stop.

This patch implements that idea.

With this patch the backtrace works properly:

    (gdb) bt
    #0  0x0000007fb7ed485c in nanosleep () from /lib64/libc.so.6
    #1  0x0000007fb7ed4508 in sleep () from /lib64/libc.so.6
    #2  0x00000000004008bc in thread_function (arg=0x4) at threadapply.c:73
    #3  0x0000007fb7fad950 in start_thread () from /lib64/libpthread.so.0
    #4  0x0000007fb7f0956c in clone () from /lib64/libc.so.6

2013-11-22  Tom Tromey  <tromey@redhat.com>

	PR backtrace/16155:
	* dwarf2-frame.c (dwarf2_frame_cache): Set undefined_retaddr if
	the return address column is unspecified.

2013-11-22  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/dw2-bad-cfi.c: New file.
	* gdb.dwarf2/dw2-bad-cfi.exp: New file.
	* gdb.dwarf2/dw2-bad-cfi.S: New file.
2013-11-22 11:02:01 -07:00
Pedro Alves 33f8fe58b9 Don't let two frames with the same id end up in the frame chain.
The UNWIND_SAME_ID check is done between THIS_FRAME and the next frame
when we go try to unwind the previous frame.  But at this point, it's
already too late -- we ended up with two frames with the same ID in
the frame chain.  Each frame having its own ID is an invariant assumed
throughout GDB.  This patch applies the UNWIND_SAME_ID detection
earlier, right after the previous frame is unwound, discarding the dup
frame if a cycle is detected.

The patch includes a new test that fails before the change.  Before
the patch, the test causes an infinite loop in GDB, after the patch,
the UNWIND_SAME_ID logic kicks in and makes the backtrace stop with:

  Backtrace stopped: previous frame identical to this frame (corrupt stack?)

The test uses dwarf CFI to emulate a corrupted stack with a cycle.  It
has a function with registers marked DW_CFA_same_value (most
importantly RSP/RIP), so that GDB computes the same ID for that frame
and its caller.  IOW, something like this:

 #0 - frame_id_1
 #1 - frame_id_2
 #2 - frame_id_3
 #3 - frame_id_4
 #4 - frame_id_4  <<<< outermost (UNWIND_SAME_ID).

(The test's code is just a copy of dw2-reg-undefined.S /
dw2-reg-undefined.c, adjusted to use DW_CFA_same_value instead of
DW_CFA_undefined, and to mark a different set of registers.)

The infinite loop is here, in value_fetch_lazy:

      while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
	{
	  frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
...
	  new_val = get_frame_register_value (frame, regnum);
	}

get_frame_register_value can return a lazy register value pointing to
the next frame.  This means that the register wasn't clobbered by
FRAME; the debugger should therefore retrieve its value from the next
frame.

To be clear, get_frame_register_value unwinds the value in question
from the next frame:

 struct value *
 get_frame_register_value (struct frame_info *frame, int regnum)
 {
   return frame_unwind_register_value (frame->next, regnum);
                                       ^^^^^^^^^^^
 }

In other words, if we get a lazy lval_register, it should have the
frame ID of the _next_ frame, never of FRAME.

At this point in value_fetch_lazy, the whole relevant chunk of the
stack up to frame #4 has already been unwound.  The loop always
"unlazies" lval_registers in the "next/innermost" direction, not in
the "prev/unwind further/outermost" direction.

So say we're looking at frame #4.  get_frame_register_value in frame
#4 can return a lazy register value of frame #3.  So the next
iteration, frame_find_by_id tries to read the register from frame #3.
But, since frame #4 happens to have same id as frame #3,
frame_find_by_id returns frame #4 instead.  Rinse, repeat, and we have
an infinite loop.

This is an old latent problem, exposed by the recent addition of the
frame stash.  Before we had a stash, frame_find_by_id(frame_id_4)
would walk over all frames starting at the current frame, and would
always find #3 first.  The stash happens to return #4 instead:

struct frame_info *
frame_find_by_id (struct frame_id id)
{
  struct frame_info *frame, *prev_frame;

...
  /* Try using the frame stash first.  Finding it there removes the need
     to perform the search by looping over all frames, which can be very
     CPU-intensive if the number of frames is very high (the loop is O(n)
     and get_prev_frame performs a series of checks that are relatively
     expensive).  This optimization is particularly useful when this function
     is called from another function (such as value_fetch_lazy, case
     VALUE_LVAL (val) == lval_register) which already loops over all frames,
     making the overall behavior O(n^2).  */
  frame = frame_stash_find (id);
  if (frame)
    return frame;

  for (frame = get_current_frame (); ; frame = prev_frame)
    {

gdb/
2013-11-22  Pedro Alves  <palves@redhat.com>

	PR 16155
	* frame.c (get_prev_frame_1): Do the UNWIND_SAME_ID check between
	this frame and the new previous frame, not between this frame and
	the next frame.

gdb/testsuite/
2013-11-22  Pedro Alves  <palves@redhat.com>

	PR 16155
	* gdb.dwarf2/dw2-dup-frame.S: New file.
	* gdb.dwarf2/dw2-dup-frame.c: New file.
	* gdb.dwarf2/dw2-dup-frame.exp: New file.
2013-11-22 13:50:48 +00:00
Pedro Alves 8ad6489081 Revert "Don't let two frames with the same id end up in the frame chain."
This reverts commit be2c48b4d5.
2013-11-22 13:46:51 +00:00
Pedro Alves be2c48b4d5 Don't let two frames with the same id end up in the frame chain.
The UNWIND_SAME_ID check is done between THIS_FRAME and the next frame
when we go try to unwind the previous frame.  But at this point, it's
already too late -- we ended up with two frames with the same ID in
the frame chain.  Each frame having its own ID is an invariant assumed
throughout GDB.  This patch applies the UNWIND_SAME_ID detection
earlier, right after the previous frame is unwound, discarding the dup
frame if a cycle is detected.

The patch includes a new test that fails before the change.  Before
the patch, the test causes an infinite loop in GDB, after the patch,
the UNWIND_SAME_ID logic kicks in and makes the backtrace stop with:

  Backtrace stopped: previous frame identical to this frame (corrupt stack?)

The test uses dwarf CFI to emulate a corrupted stack with a cycle.  It
has a function with registers marked DW_CFA_same_value (most
importantly RSP/RIP), so that GDB computes the same ID for that frame
and its caller.  IOW, something like this:

 #0 - frame_id_1
 #1 - frame_id_2
 #2 - frame_id_3
 #3 - frame_id_4
 #4 - frame_id_4  <<<< outermost (UNWIND_SAME_ID).

(The test's code is just a copy of dw2-reg-undefined.S /
dw2-reg-undefined.c, adjusted to use DW_CFA_same_value instead of
DW_CFA_undefined, and to mark a different set of registers.)

The infinite loop is here, in value_fetch_lazy:

      while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val))
	{
	  frame = frame_find_by_id (VALUE_FRAME_ID (new_val));
...
	  new_val = get_frame_register_value (frame, regnum);
	}

get_frame_register_value can return a lazy register value pointing to
the next frame.  This means that the register wasn't clobbered by
FRAME; the debugger should therefore retrieve its value from the next
frame.

To be clear, get_frame_register_value unwinds the value in question
from the next frame:

 struct value *
 get_frame_register_value (struct frame_info *frame, int regnum)
 {
   return frame_unwind_register_value (frame->next, regnum);
                                       ^^^^^^^^^^^
 }

In other words, if we get a lazy lval_register, it should have the
frame ID of the _next_ frame, never of FRAME.

At this point in value_fetch_lazy, the whole relevant chunk of the
stack up to frame #4 has already been unwound.  The loop always
"unlazies" lval_registers in the "next/innermost" direction, not in
the "prev/unwind further/outermost" direction.

So say we're looking at frame #4.  get_frame_register_value in frame
#4 can return a lazy register value of frame #3.  So the next
iteration, frame_find_by_id tries to read the register from frame #3.
But, since frame #4 happens to have same id as frame #3,
frame_find_by_id returns frame #4 instead.  Rinse, repeat, and we have
an infinite loop.

This is an old latent problem, exposed by the recent addition of the
frame stash.  Before we had a stash, frame_find_by_id(frame_id_4)
would walk over all frames starting at the current frame, and would
always find #3 first.  The stash happens to return #4 instead:

struct frame_info *
frame_find_by_id (struct frame_id id)
{
  struct frame_info *frame, *prev_frame;

...
  /* Try using the frame stash first.  Finding it there removes the need
     to perform the search by looping over all frames, which can be very
     CPU-intensive if the number of frames is very high (the loop is O(n)
     and get_prev_frame performs a series of checks that are relatively
     expensive).  This optimization is particularly useful when this function
     is called from another function (such as value_fetch_lazy, case
     VALUE_LVAL (val) == lval_register) which already loops over all frames,
     making the overall behavior O(n^2).  */
  frame = frame_stash_find (id);
  if (frame)
    return frame;

  for (frame = get_current_frame (); ; frame = prev_frame)
    {

gdb/
2013-11-22  Pedro Alves  <palves@redhat.com>

	PR 16155
	* frame.c (get_prev_frame_1): Do the UNWIND_SAME_ID check between
	this frame and the new previous frame, not between this frame and
	the next frame.

gdb/testsuite/
2013-11-22  Pedro Alves  <palves@redhat.com>

	PR 16155
	* gdb.dwarf2/dw2-dup-frame.S: New file.
 	* gdb.dwarf2/dw2-dup-frame.c: New file.
 	* gdb.dwarf2/dw2-dup-frame.exp: New file.
2013-11-22 13:41:43 +00:00
Omair Javaid c7e8af9b3b testsuite/gdb.dwarf2: dw2-case-insensitive.exp: p fuNC_lang fails on arm
dw2-case-insensitive.exp: p fuNC_lang fails on arm. The problem occurs
when thumb mode code is generated. On ARM last bit of function pointer
value indicates whether the target function is an ARM (if 0) or Thumb
(if 1) routine. The PC address should refer to actual address in
either case. This patch adds new compile unit and function labels to
code which act as address ranges of compile unit and functions in
debug information. Therefore address ranges will have correct
addresses and not the ones with an incremented least significant bit.
This patch has been tested on x86_64 and arm machines.

gdb/testsuite/ChangeLog:

2013-11-14  Omair Javaid  <Omair.Javaid@linaro.org>

        * gdb.dwarf2/dw2-case-insensitive-debug.S: Updated compile unit
	and function label names.
        * gdb.dwarf2/dw2-case-insensitive.c: Created function and
	compile unit labels.
2013-11-14 15:18:17 +00:00
Tom Tromey c63ffa1f25 fix some fission tests
A couple of Fission tests rely on the current directory layout.  This
assumption is not valid in parallel mode.

This patch fixes the problem by removing the relative directory from
the .S files and instead having the tests set debug-file-directory
before opening the main file.

2013-11-04  Tom Tromey  <tromey@redhat.com>

	* gdb.dwarf2/fission-base.S: Remove "gdb.dwarf/".
	* gdb.dwarf2/fission-base.exp: Set debug-file-directory
	before loading binfile.
	* gdb.dwarf2/fission-loclists.S: Remove "gdb.dwarf/".
	* gdb.dwarf2/fission-loclists.exp: Set debug-file-directory
	before loading binfile.
2013-11-04 11:02:11 -07:00
Maciej W. Rozycki a1b0fbee1d gdb.dwarf2/dwzbuildid.exp: Avoid reserved variable name
* gdb.dwarf2/dwzbuildid.exp: Rename `outdir' variable to
	`debugdir'.
2013-11-01 20:34:49 +00:00
Tom Tromey 3db258f53b * gdb.dwarf2/dwzbuildid.exp (write_dwarf_file): Pass explicit test
name to gdb_test_no_output.
2013-10-14 16:20:13 +00:00
Tom Tromey dc294be54c fix PR symtab/15597
This patch fixes gdb PR symtab/15597.

The bug is that the .gnu_debugaltlink section includes the build-id of
the alt file, but gdb does not use it.

This patch fixes the problem by changing gdb to do what it ought to
always have done: verify the build id of the file found using the
filename in .gnu_debugaltlink; and if that does not match, try to find
the correct debug file using the build-id and debug-file-directory.

This patch touches BFD.  Previously, gdb had its own code for parsing
.gnu_debugaltlink; I changed it to use the BFD functions after those
were introduced.  However, the BFD functions are incorrect -- they
assume that .gnu_debugaltlink is formatted like .gnu_debuglink.
However, it it is not.  Instead, it consists of a file name followed
by the build-id -- no alignment, and the build-id is not a CRC.

Fixing this properly is a bit of a pain.  But, because
separate_alt_debug_file_exists just has a FIXME for the build-id case,
I did not fix it properly.  Instead I introduced a hack.  This leaves
BFD working just as well as it did before my patch.

I'm willing to do something better here but I could use some guidance
as to what.  It seems that the build-id code in BFD is largely punted
on.

FWIW gdb is the only user of bfd_get_alt_debug_link_info outside of
BFD itself.

I moved the build-id logic out of elfread.c and into a new file.
This seemed cleanest to me.

Writing a test case was a bit of a pain.  I added a couple new
features to the DWARF assembler to handle this.

Built and regtested on x86-64 Fedora 18.

	* bfd-in2.h: Rebuild.
	* opncls.c (bfd_get_alt_debug_link_info): Add buildid_len
	parameter.  Change type of buildid_out.  Update.
	(get_alt_debug_link_info_shim): New function.
	(bfd_follow_gnu_debuglink): Use it.

	* Makefile.in (SFILES): Add build-id.c.
	(HFILES_NO_SRCDIR): Add build-id.h.
	* build-id.c: New file, largely from elfread.c.  Modified
	most functions.
	* build-id.h: New file.
	* dwarf2read.c (dwarf2_get_dwz_file): Update for change to
	bfd_get_alt_debug_link_info.  Verify dwz file's build-id.
	Search for dwz file using build-id.
	* elfread.c (build_id_bfd_get, build_id_verify)
	(build_id_to_debug_filename, find_separate_debug_file): Remove.

	* gdb.dwarf2/dwzbuildid.exp: New file.
	* lib/dwarf.exp (Dwarf::_section): Add "flags" and "type"
	parameters.
	(Dwarf::_defer_output): Change "section" parameter to
	"section_spec"; update.
	(Dwarf::gnu_debugaltlink, Dwarf::_note, Dwarf::build_id): New
	procs.
2013-10-08 19:56:15 +00:00
Pedro Alves 901461f8eb Print registers not saved in the frame as "<not saved>" instead of "<optimized out>".
Currently, in some scenarios, GDB prints <optimized out> when printing
outer frame registers.  An <optimized out> register is a confusing
concept.  What this really means is that the register is
call-clobbered, or IOW, not saved by the callee.  This patch makes GDB
say that instead.

Before patch:

 (gdb) p/x $rax $1 = <optimized out>
 (gdb) info registers rax
 rax            <optimized out>

After patch:

 (gdb) p/x $rax
 $1 = <not saved>
 (gdb) info registers rax
 rax            <not saved>

However, if for some reason the debug info describes a variable as
being in such a register (**), we still want to print <optimized out>
when printing the variable.  IOW, <not saved> is reserved for
inspecting registers at the machine level.  The patch uses
lval_register+optimized_out to encode the not saved registers, and
makes it so that optimized out variables always end up in
!lval_register values.

** See <https://sourceware.org/ml/gdb-patches/2012-08/msg00787.html>.
Current/recent enough GCC doesn't mark variables/arguments as being in
call-clobbered registers in the ranges corresponding to function
calls, while older GCCs did.  Newer GCCs will just not say where the
variable is, so GDB will end up realizing the variable is optimized
out.

frame_unwind_got_optimized creates not_lval optimized out registers,
so by default, in most cases, we'll see <optimized out>.

value_of_register is the function eval.c uses for evaluating
OP_REGISTER (again, $pc, etc.), and related bits.  It isn't used for
anything else.  This function makes sure to return lval_register
values.  The patch makes "info registers" and the MI equivalent use it
too.  I think it just makes a lot of sense, as this makes it so that
when printing machine registers ($pc, etc.), we go through a central
function.

We're likely to need a different encoding at some point, if/when we
support partially saved registers.  Even then, I think
value_of_register will still be the spot to tag the intention to print
machine register values differently.

value_from_register however may also return optimized out
lval_register values, so at a couple places where we're computing a
variable's location from a dwarf expression, we convert the resulting
value away from lval_register to a regular optimized out value.

Tested on x86_64 Fedora 17

gdb/
2013-10-02  Pedro Alves  <palves@redhat.com>

	* cp-valprint.c (cp_print_value_fields): Adjust calls to
	val_print_optimized_out.
	* jv-valprint.c (java_print_value_fields): Likewise.
	* p-valprint.c (pascal_object_print_value_fields): Likewise.
	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full)
	<DWARF_VALUE_REGISTER>: If the register was not saved, return a
	new optimized out value.
	* findvar.c (address_from_register): Likewise.
	* frame.c (put_frame_register): Tweak error string to say the
	register was not saved, rather than optimized out.
	* infcmd.c (default_print_one_register_info): Adjust call to
	val_print_optimized_out.  Use value_of_register instead of
	get_frame_register_value.
	* mi/mi-main.c (output_register): Use value_of_register instead of
	get_frame_register_value.
	* valprint.c (valprint_check_validity): Likewise.
	(val_print_optimized_out): New value parameter.  If the value is
	lval_register, print <not saved> instead.
	(value_check_printable, val_print_scalar_formatted): Adjust calls
	to val_print_optimized_out.
	* valprint.h (val_print_optimized_out): New value parameter.
	* value.c (struct value) <optimized_out>: Extend comment.
	(error_value_optimized_out): New function.
	(require_not_optimized_out): Use it.  Use a different string for
	lval_register values.
	* value.h (error_value_optimized_out): New declaration.
	* NEWS: Mention <not saved>.

gdb/testsuite/
2013-10-02  Pedro Alves  <palves@redhat.com>

	* gdb.dwarf2/dw2-reg-undefined.exp <pattern_rax_rbx_rcx_print,
	pattern_rax_rbx_rcx_info>: Set to "<not saved>".
	* gdb.mi/mi-reg-undefined.exp (opt_out_pattern): Delete.
	(not_saved_pattern): New.
	Replace use of the former with the latter.

gdb/doc/
2013-10-02  Pedro Alves  <palves@redhat.com>

	* gdb.texinfo (Registers): Expand description of saved registers
	in frames.  Explain <not saved>.
2013-10-02 16:15:46 +00:00
Jan Kratochvil 82bf32bc61 Support .dwp with the name of symlinked binary file
gdb/
2013-09-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (open_and_init_dwp_file): Try open_dwp_file also with
	objfile->original_name.

gdb/testsuite/
2013-09-24  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.dwarf2/dwp-symlink.c: New file.
	* gdb.dwarf2/dwp-symlink.exp: New file.
2013-09-24 14:03:43 +00:00
Doug Evans 6b4646ced5 * lib/dwarf.exp (build_executable_from_fission_assembler): New proc.
* gdb.dwarf2/fission-base.S: Update.  Split out .dwo into separate
	file.
	* gdb.dwarf2/fission-loclists.S: Ditto.
	* gdb.dwarf2/fission-reread.S: Ditto.
	* gdb.dwarf2/fission-base.exp: Skip of remote host.  Compile with
	build_executable_from_fission_assembler.
	* gdb.dwarf2/fission-loclists.exp: Ditto.
	* gdb.dwarf2/fission-reread.exp: Ditto.
2013-09-20 22:43:28 +00:00
Doug Evans 4fa7d39097 * lib/future.exp (gdb_find_objcopy, gdb_find_readelf): New procs.
* lib/gdb.exp (build_id_debug_filename_get): Update to use them.
	(gdb_gnu_strip_debug): Ditto.
	* lib/prelink-support.exp (section_get, prelink_no): Ditto.
	* gdb.arch/altivec-abi.exp: Ditto.
	* gdb.base/attach-pie-misread.exp: Ditto.
	* gdb.base/comprdebug.exp: Ditto.
	* gdb.base/dup-sect.exp: Ditto.
	* gdb.base/gnu-debugdata.exp: Ditto.
	* gdb.base/step-symless.exp: Ditto.
	* gdb.dwarf2/dw2-inline-param.exp: Ditto.
	* gdb.dwarf2/dw2-skip-prologue.exp: Ditto.
	* gdb.dwarf2/gdb-index.exp: Ditto.
2013-09-20 21:47:06 +00:00
Andrew Burgess e4c6a2c42d Consistent display of "<optimized out>" for register values.
https://sourceware.org/ml/gdb-patches/2013-08/msg00170.html

gdb/ChangeLog

        * infcmd.c (default_print_one_register_info): Add detection of
        optimized out values.
        (default_print_registers_info): Switch to using
        get_frame_register_value.

gdb/testsuite/ChangeLog

        * gdb.dwarf2/dw2-reg-undefined.exp: Change pattern for info
        register to "<optimized out>", and also print the registers.
2013-09-18 14:02:31 +00:00
Tom Tromey 7893c16288 * gdb.dwarf2/gdb-index.exp (add_gdb_index): Use explicit test name
when saving index.
2013-08-28 14:20:43 +00:00
Doug Evans 779bd27081 PR symtab/15885
* dwarf2read.c (dw2_dump): Print some minimal information indicating
	.gdb_index is in use.
	* symfile.c (reread_symbols): Reset objfile->sf.

	testsuite/
	* gdb.dwarf2/Makefile.in (EXECUTABLES): Add gdb-index.
	(clean): rm -f *.gdb-index *.with-index.
	* gdb.dwarf2/gdb-index.exp: New testcase.
2013-08-26 18:43:40 +00:00
Tom Tromey 44ee81740e introduce gdb_remote_download and finish parallel fixes in gdb.dwarf2
This finishes making gdb.dwarf2 parallel-safe.

To do this, this patch introduces a new gdb_remote_download proc, that
works somewhat differently in the one specific case where it matters:
for a copy to "host", if no destination was given, and the host is not
actually remote, then standard_output_file is used.  In parallel mode
this guarantees that the resulting file will end up in a parallel-safe
location.

Tested on x86-64 Fedora 18.

	* gdb.dwarf2/dw2-basic.exp: Use gdb_remote_download.
	* gdb.dwarf2/dw2-compressed.exp: Use gdb_remote_download.
	* gdb.dwarf2/dw2-intercu.exp: Use gdb_remote_download.
	* gdb.dwarf2/dw2-intermix.exp: Use gdb_remote_download.
	* gdb.dwarf2/dw2-producer.exp: Use gdb_remote_download.
	* gdb.dwarf2/mac-fileno.exp: Use gdb_remote_download.
	* lib/gdb.exp (gdb_remote_download): New proc.
2013-08-22 13:44:16 +00:00
Tom Tromey 7a218f8865 fix some gdb.dwarf2 tests for parallel safety
This fixes a few gdb.dwarf2 tests to be more parallel-safe.  This
mostly amounts to changing them to write their files into the
directory designated by standard_output_file.

Built and regtested on x86-64 Fedora 18.

	* gdb.dwarf2/clztest.exp: Use standard_testfile.
	* gdb.dwarf2/dw2-minsym-in-cu.exp: Use standard_testfile.
	* gdb.dwarf2/fission-base.S: Remove directory from
	DW_AT_GNU_dwo_name.
	* gdb.dwarf2/fission-base.exp: Use build_executable.  Set
	debug-file-directory.
	* gdb.dwarf2/fission-reread.S: Remove directory from
	DW_AT_GNU_dwo_name.
	* gdb.dwarf2/fission-reread.exp: Use build_executable.  Set
	debug-file-directory.
2013-08-22 13:39:13 +00:00
Tom Tromey f9125b6c6c fix recursively_compute_inclusions and add dwz test case
Doug pointed out a while ago that in the final dwz -m patch, nothing
ever set symtab::user.

This patch fixes this oversight and adds a test case showing why it is
important.

Built and regtested (both ways) on x86-64 Fedora 18.
The new test unconditionally tests the partial unit machinery, which I
think is an added plus.

	* dwarf2read.c (recursively_compute_inclusions): Add
	"immediate_parent" argument.  Set symtab's "user" field
	if not set.
	(compute_symtab_includes): Update.

	* gdb.dwarf2/dwz.exp: New file.
2013-08-07 19:57:51 +00:00
Doug Evans 7ee85ab10c PR symtab/15691
* dwarf2read.c (struct dwarf2_per_cu_data): New member tu_read.
	(fill_in_sig_entry_from_dwo_entry): Reorganize asserts.
	Add assert of sig_entry->dwo_unit == NULL.
	(lookup_dwo_signatured_type): Don't assign TU to a DWO if the TU
	had already been read.
	(read_signatured_type): Set per_cu.tu_read.

	testsuite/
	* gdb.dwarf2/fission-mix.exp: New file.
	* gdb.dwarf2/fission-mix.h: New file.
	* gdb.dwarf2/fission-mix.c: New file.
	* gdb.dwarf2/fission-mix2.c: New file.
2013-08-02 00:33:07 +00:00