Commit Graph

36283 Commits

Author SHA1 Message Date
Joel Brobecker b30a0bc387 Make the "info dll" command available on all platform.
The "info dll", an alias of the "info sharedlibrary" command, is
currently only defined in windows native versions. This patch makes
it universally available by moving the alias declaration to solib.c,
and adjusts the documentation accordingly.

Making it universally available has two benefits:
  - Windows users moving to a Unix platforms are still able to use
    the same command for getting the list of shared libraries;
  - Unix to Windows cross debuggers now provide that command also.

gdb/ChangeLog:

        * solib.c (_initialize_solib): Add "info dll" alias creation.
        * windows-nat.c (set_windows_aliases): Delete.
        (_initialize_windows_nat): Remove deprecated_init_ui_hook
        assignment.
        * NEWS: Add news entry about "info dll" now being available
        on all platforms.

gdb/doc/ChangeLog:

        * gdb.texinfo (Files): Add "info dll" documentation.
        (Cygwin Native): Remove "info dll" documentation.
2015-05-06 10:47:20 -07:00
Joel Brobecker 7c5127443b Further document ada-lang.c::value_assign_to_component & fix whitespaces.
This patch improves the documentation of ada-lang.c's
value_assign_to_component to publish the fact that it also works
with not_lval values.

And touching this area of the code showed that there were a number
of whitespace issues, as well as a formatting issue of the main comment
(no leading '*' on each line). This patch fixes those while at it.

No functional change, however.

gdb/ChangeLog:

        * ada-lang.c (value_assign_to_component): Reformat and improve
        documentation. Remove all trailing spaces.
2015-05-05 11:21:10 -07:00
Joel Brobecker 0fa7fe506c out of line functions nested inside inline functions.
This patch improves the handling of out-of-line functions nested
inside functions that have been inlined.

Consider for instance a situation where function Foo_O224_021
has a function Child1 declared in it, which itself has a function
Child2 nested inside Child1. After compiling the program with
optimization on, Child1 gets inlined, but not Child2.

After inserting a breakpoint on Child2, and running the program
until reaching that breakpoint, we get the following backtrace:

    % gdb foo_o224_021
    (gdb) break foo_o224_021.child1.child2
    (gdb) run
    [...]
    Breakpoint 1, foo_o224_021 () at foo_o224_021.adb:28
    28          Child1;
    (gdb) bt
    #0  0x0000000000402400 in foo_o224_021 () at foo_o224_021.adb:28
    #1  0x00000000004027a4 in foo_o224_021.child1 () at foo_o224_021.adb:23
    #2  0x00000000004027a4 in foo_o224_021 () at foo_o224_021.adb:28

GDB reports the wrong function name for frame #0. We also get the same
kind of error in the "Breakpoint 1, foo_o224_021 () [...]" message.
In both cases, the function name should be foo_o224_021.child1.child2,
and the parameters should be "s=...".

What happens is that the inlined frame handling does not handle well
the case where an inlined function is calling an out-of-line function
which was declared inside the inlined function's scope.

In particular, looking first at the inlined-frame sniffer when applying
to frame #0:

        /* Calculate DEPTH, the number of inlined functions at this
           location.  */
        depth = 0;
        cur_block = frame_block;
        while (BLOCK_SUPERBLOCK (cur_block))
          {
            if (block_inlined_p (cur_block))
              depth++;
            cur_block = BLOCK_SUPERBLOCK (cur_block);
          }

What happens is that cur_block starts as the block associated
to child2, which is not inlined. We shoud be stopping here, but
instead, we keep walking the superblock chain, which takes us
all the way to Foo_O224_021's block, via Child2's block. And
since Child1 was inlined, we end up with a depth count of 1,
wrongly making GDB think that frame #0 is an inlined frame.

Same kind of issue inside skip_inline_frames.

The fix is to stop checking for inlined frames as soon as we see
a block corresponding to a function which is not inlined.  This is
the behavior we now obtain:

    (gdb) run
    [...]
    Breakpoint 1, foo_o224_021.child1.child2 (s=...) at foo_o224_021.adb:9
    9               function Child2 (S : String) return Boolean is
    (gdb) bt
    #0  0x0000000000402400 in foo_o224_021.child1.child2 (s=...)
        at foo_o224_021.adb:9
    #1  0x00000000004027a4 in foo_o224_021.child1 () at foo_o224_021.adb:23
    #2  0x00000000004027a4 in foo_o224_021 () at foo_o224_021.adb:28

gdb/ChangeLog:

        * inline-frame.c (inline_frame_sniffer, skip_inline_frames):
        Stop counting inlined frames as soon as an out-of-line function
        is found.

gdb/testsuite/ChangeLog:

        * gdb.ada/out_of_line_in_inlined.exp: Add run and "bt" tests.
2015-05-05 11:08:14 -07:00
Pierre-Marie de Rodat 3ea89b92fb DWARF: cannot break on out-of-line function nested inside inlined function.
Consider the following code, which defines a function, Child2,
which is itself nested inside Child1:

    procedure Foo_O224_021 is
        O1 : constant Object_Type := Get_Str ("Foo");
        procedure Child1 is
            O2 : constant Object_Type := Get_Str ("Foo");
            function Child2 (S : String) return Boolean is -- STOP
            begin
                for C of S loop
                    Do_Nothing (C);
                    if C = 'o' then
                        return True;
                    end if;
                end loop;
                return False;
            end Child2;
            R : Boolean;
        begin
            R := Child2 ("Foo");
            R := Child2 ("Bar");
            R := Child2 ("Foobar");
        end Child1;
    begin
        Child1;
    end Foo_O224_021;

On x86_64-linux, when compiled at -O2, GDB is unable to insert
a breakpoint on Child2:

    % gnatmake -g -O2 foo_o224_021
    % gdb foo_o224_021
    (gdb) b child2
    Function "child2" not defined.
    (gdb) b foo_o224_021.child1.child2
    Function "foo_o224_021.child1.child2" not defined.

The problem is caused by the fact that GDB did not create a symbol
for Child2, and this, in turn, is caused by the fact that the compiler
decided to inline Child1, but not Child2. The DWARF debugging info
first provides an abstract instance tree for Child1...

 <3><1b7b>: Abbrev Number: 29 (DW_TAG_subprogram)
    <1b7c>   DW_AT_name        : (indirect string, offset: 0x23f8): foo_o224_021__child1
    <1b82>   DW_AT_inline      : 1      (inlined)
    <1b83>   DW_AT_sibling     : <0x1c01>

... where that subprogram is given the DW_AT_inline attribute.
Inside that function there is a lexical block which has no PC
range (corresponding to the fact that this is the abstract tree):

 <4><1b87>: Abbrev Number: 30 (DW_TAG_lexical_block)

... inside which our subprogram Child2 is described:

 <5><1b92>: Abbrev Number: 32 (DW_TAG_subprogram)
    <1b93>   DW_AT_name        : (indirect string, offset: 0x2452): foo_o224_021__child1__child2
    <1b99>   DW_AT_type        : <0x1ab1>
    <1b9d>   DW_AT_low_pc      : 0x402300
    <1ba5>   DW_AT_high_pc     : 0x57
    [...]

Then, later on, we get the concrete instance tree, starting at:

 <3><1c5e>: Abbrev Number: 41 (DW_TAG_inlined_subroutine)
    <1c5f>   DW_AT_abstract_origin: <0x1b7b>
    <1c63>   DW_AT_entry_pc    : 0x4025fd
    <1c6b>   DW_AT_ranges      : 0x150

... which refers to Child1. One of that inlined subroutine children
is the concrete instance of the empty lexical block we saw above
(in the abstract instance tree), which gives the actual address
range for this inlined instance:

 <5><1c7a>: Abbrev Number: 43 (DW_TAG_lexical_block)
    <1c7b>   DW_AT_abstract_origin: <0x1b87>
    <1c7f>   DW_AT_ranges      : 0x180

This is the DIE which provides the context inside which we can
record Child2. But unfortunately, GDB does not take the abstract
origin into account when handling lexical blocks, causing it
to miss the fact that this block contains some symbols described
in the abstract instance tree. This is the first half of this patch:
modifying GDB to follow DW_AT_abstract_origin attributes for
lexical blocks.

But this not enough to fix the issue, as we're still unable to
break on Child2 with just that change. The second issue can be
traced to the way inherit_abstract_dies determines the list of
DIEs to inherit from. For that, it iterates over all the DIEs in
the concrete instance tree, and finds the list of DIEs from the
abstract instance tree that are not referenced from the concrete
instance tree. As it happens, there is one type of DIE in the
concrete instance tree which does reference Child2's DIE, but
in fact does otherwise define a concrete instance of the reference
DIE; that's (where <0x1b92> is Child2's DIE):

 <6><1d3c>: Abbrev Number: 35 (DW_TAG_GNU_call_site)
    <1d3d>   DW_AT_low_pc      : 0x4026a4
    <1d45>   DW_AT_abstract_origin: <0x1b92>

So, the second part of the patch is to modify inherit_abstract_dies
to ignore DW_TAG_GNU_call_site DIEs when iterating over the concrete
instance tree.

This patch also includes a testcase which can be used to reproduce
the issue. Unfortunately, for it to actually pass, a smal patch in
GCC is also necessary to make sure that GCC provides lexical blocks'
DW_AT_abstract_origin attributes from the concrete tree back to
the abstract tree. We hope to be able to submit and integrate that
patch in the GCC tree soon. Meanwhile, a setup_xfail has been added.

gdb/ChangeLog:

	2014-05-05  Pierre-Marie de Rodat  <derodat@adacore.com>
	* dwarf2read.c (inherit_abstract_dies): Skip
	DW_TAG_GNU_call_site dies while inheriting children of an
	abstract DIE into a scope.
	(read_lexical_block_scope): Inherit abstract DIE's for
	lexical scopes.

gdb/testsuite/ChangeLog:

        * gdb.ada/out_of_line_in_inlined: New testcase.
2015-05-05 11:06:09 -07:00
Joel Brobecker 2478d075da compare object sizes before comparing them with value_contents_eq
This is an issue which I noticed while working on trying to print
an array of variant records. For instance, trying to print "A1",
an array of elements whose size is variable, defined as follow
(see gdb.ada/var_rec_arr testcase):

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   function Ident (R : Record_Type) return Record_Type;

   type Array_Type is array (Integer range <>) of Record_Type;

   A1 : Array_Type := (1 => (I => 0, S => <>),
                       2 => (I => 1, S => "A"),
                       3 => (I => 2, S => "AB"));

The debugger sometimes prints the array as follow:

    (gdb) print A1
    $1 = ((i => 0, s => ""), (i => 0, s => ""), (i => 0, s => ""))

The problem happens inside the part of the loop printing the array's
elements, while trying to count the number of consecutive elements
that have the same value (in order to replace them by the "<repeats
nnn times>" message when the number exceeds a threshold). In particular,
in ada-valprint.c::val_print_packed_array_elements:

  elttype = TYPE_TARGET_TYPE (type);
  eltlen = TYPE_LENGTH (check_typedef (elttype));

  while (...)
    {
          if (!value_contents_eq (v0, value_embedded_offset (v0),
                                  v1, value_embedded_offset (v1),
                                  eltlen))
            break;

The value comparison is performed using value_contents_eq but makes
the assumption that elttype is not dynamic, which is not always true.
In particular, in the case above, elttype is dynamic and therefore
its TYPE_LENGTH changes from element to element.

As it happens in this case, the eltlen is zero, which causes the call
to value_contents_eq to return true, and therefore GDB thinks all
3 elements of the array are equal.

This patch fixes the issue by making sure that both v0 and v1, which
are values whose type we expect to be resolved, have identical lengths.
If not, then the two elements of the array cannot possibly have the
same value and we do not even need to do the binary comparison.

Unfortunately, this is still not enough to get GDB to print the correct
value for our array, because the assumption that v0 and v1 have a type
which has been resolved is actually not met. So, the second part of
the patch modifies the function that constructed the values to make
sure dynamic types do get resolved.

gdb/ChangeLog:

        * ada-valprint.c (val_print_packed_array_elements): Delete
        variable "len".  Add a type-length check when comparing two
        consecutive elements of the array.  Use the element's actual
        length in call to value_contents_eq.
        * ada-lang.c (ada_value_primitive_packed_val): Always return
        a value whose type has been resolved.
2015-05-05 10:51:38 -07:00
Joel Brobecker 87b8eff03f testsuite/gdb.ada/var_rec_arr: New testcase.
gdb/testsuite/ChangeLog:

        * gdb.ada/var_rec_arr: New testcase.
2015-05-05 10:48:21 -07:00
Joel Brobecker fc958966e4 GDB crash trying to subscript array of variant record.
Consider the following declarations:

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   A2 : Array_Type := (1 => (I => 2, S => "AB"),
                       2 => (I => 1, S => "A"),
                       3 => (I => 0, S => <>));

Compiled with -fgnat-encodings=minimal, and trying to print
one element of our array, valgrind reports an invalid memory
access. On certain GNU/Linux boxes, malloc even reports it as
well, and causes GDB to crash.

    (gdb) print a2(1)
     *** glibc detected *** /[...]/gdb:
         malloc(): memory corruption: 0x0a30ba48 ***
    [crash]

The invalid memory access occurs because of a simple buffer
overflow in ada_value_primitive_packed_val. When this function
is called, it is given a bit_size of 128 (or 16 bytes), which
corresponds to the stride of our array. But the actual size of
each element depends on its value. In particular, A2(1) is a record
whose size is only 6 bytes.

What happens in our example is that we start building a new value
(v) where the element is to be unpacked, with any of its dynamic
properties getting resolved as well. We then unpack the data into
this value's buffer:

  unpacked = (unsigned char *) value_contents (v);
  [...]
  nsrc = len;
  [...]
  while (nsrc > 0)
    {
      [...]
          unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT);
          [...]
          targ += delta;
      [...]
      nsrc -= 1;
      [...]
    }

In the loop above, targ starts at zero (for LE architectures),
and len is 16. With delta being +1, we end up iterating 16 times,
writing 16 bytes into a 6-bytes buffer.

This patch fixes the issue by adjusting BIT_SIZE and recomputing
LEN after having resolved our type if the resolved type turns out
to be smaller than bit_size.

gdb/ChangeLog:

        * ada-lang.c (ada_value_primitive_packed_val): Recompute
        BIT_SIZE and LEN if the size of the resolved type is smaller
        than BIT_SIZE * HOST_CHAR_BIT.
2015-05-05 10:47:44 -07:00
Joel Brobecker ca34b84ff6 [Ada] array of variant record subscripting
Consider the following (Ada) array...

   A1 : Array_Type := (1 => (I => 0, S => <>),
                       2 => (I => 1, S => "A"),
                       3 => (I => 2, S => "AB"));

... where Array_Type is declared as follow:

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   type Array_Type is array (Integer range <>) of Record_Type;

Trying to print the value of each element individually does not
always work. Printing the value of the first one does:

(gdb) p a1(1)
    $1 = (i => 0, s => "")

But printing the value of the subsequent ones often does not.
For instance:

    (gdb) p a1(2)
    $2 = (i => 1, s => "")  <<<--- s should be "A"
    (gdb) p a1(3)
    $3 = (i => 2, s => "")  <<<--- s should be "AB"

I traced the problem to ada_value_primitive_packed_val,
which is trying to perform the array subscripting by
extracting the value of the corresponding array element
into a buffer where the contents is now byte-aligned.

The element type that ada_value_primitive_packed_val gets passed
is a dynamic type. As it happens, that dynamic type can get resolved
thanks to:

      v = value_at (type, value_address (obj));
      type = value_type (v);

However, obj represents the array, so the address given in the call
to value_at represents the value of the first element. As a result,
the solution of component S's upper bound always gets resolved based
on the value of component I in the  first element of the array, whose
value is 0, thus leading to GDB mistakely resolving the element type
where S's upper bound is always 0.

The proper fix would be to systematically resolve the element type
first. But, this requires us to extract-and-realign the element's
value so as to be able to pass it as "valaddr" to resolve_dynamic_type.
In the meantime, it's easy to make the situation a little better by
passing "value_address (obj) + offset" as the object address. This
only works when BIT_OFFSET is nul, but that should be the case when
the element type is anything but a scalar, which seems to be the only
situation where it seems important to resolve the type now. And we're
not that worse off otherwise.

But we'll try to find a better solution in a separate patch.

gdb/ChangeLog:

        * ada-lang.c (ada_value_primitive_packed_val): Use a more
        correct address in call to value_at.  Adjust call to
        value_address accordingly.
2015-05-05 10:46:42 -07:00
Joel Brobecker 62c67f3c1a [Ada] Resolve dynamic type before trying to print it.
This is another required step towards trying to print the value of
an array of variant records. For instance:

   A1 : Array_Type := (1 => (I => 0, S => <>),
                       2 => (I => 1, S => "A"),
                       3 => (I => 2, S => "AB"));

... where Array_Type is an array of records whose size is variable:

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   type Array_Type is array (Integer range <>) of Record_Type;

What happens is that the ada-valprint modules gets passed an array
whose element type is not resolved yet (since each element of the
array needs to be resolved separately). the module then recurses,
and eventually gets called with the first element of the array.
But because the element hasn't been resolved yet, we end up having
trouble printing its value soon after.

This patch fixes the issue by calling resolve_dynamic_type before
trying to print it.

With this patch, GDB is finally able to print the complete value
for variable "A1":

     (gdb) p a1
     $1 = ((i => 0, s => ""), (i => 1, s => "A"), (i => 2, s => "AB"))

gdb/ChangeLog:

        * ada-valprint.c (ada_val_print_1): Resolve TYPE before trying
        to print it.
2015-05-05 10:46:12 -07:00
Joel Brobecker c334512419 Add valaddr support in dynamic property resolution.
This is the second part of enhancing the debugger to print the value
of arrays of records whose size is variable when only standard DWARF
info is available (no GNAT encoding). For instance:

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   type Array_Type is array (Integer range <>) of Record_Type;

   A1 : Array_Type := (1 => (I => 0, S => <>),
                       2 => (I => 1, S => "A"),
                       3 => (I => 2, S => "AB"));

Currently, GDB prints the following output:

        (gdb) p a1
        $1 = (

The error happens while the ada-valprint module is trying to print
the value of an element of our array. Because of the fact that
the array's element (type Record_Type) has a variant size, the DWARF
info for our array provide the array's stride:

     <1><749>: Abbrev Number: 10 (DW_TAG_array_type)
        <74a>   DW_AT_name        : (indirect string, offset: 0xb6d): pck__T18s
        <74e>   DW_AT_byte_stride : 16
        <74f>   DW_AT_type        : <0x6ea>

And because our array has a stride, ada-valprint treats it the same
way as packed arrays (see ada-valprint.c::ada_val_print_array):

  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
    val_print_packed_array_elements (type, valaddr, offset_aligned,
                                     0, stream, recurse,
                                     original_value, options);

The first thing that we should notice in the call above is that
the "valaddr" buffer and the associated offset (OFFSET_ALIGNED)
is passed, but that the corresponding array's address is not.
This can be explained by looking inside val_print_packed_array_elements,
where we see that the function unpacks each element of our array from
the buffer alone (ada_value_primitive_packed_val), and then prints
the resulting artificial value instead:

      v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
                                           (i0 * bitsize) / HOST_CHAR_BIT,
                                           (i0 * bitsize) % HOST_CHAR_BIT,
                                           bitsize, elttype);

      [...]
              val_print (elttype, value_contents_for_printing (v0),
                         value_embedded_offset (v0), 0, stream,
                         recurse + 1, v0, &opts, current_language);

Of particular interest, here, is the fact that we call val_print
with a null address, which is OK, since we're providing a buffer
instead (value_contents_for_printing). Also, providing an address
might not always possible, since packing could place elements at
boundaries that are not byte-aligned.

Things go south when val_print tries to see if there is a pretty-printer
that could be applied. In particular, one of the first things that
the Python pretty-printer does is to create a value using our buffer,
and the given address, which in this case is null (see call to
value_from_contents_and_address in gdbpy_apply_val_pretty_printer).

value_from_contents_and_address, in turn immediately tries to resolve
the type, using the given address, which is null. But, because our
array element is a record containing an array whose bound is the value
of one of its elements (the "s" component), the debugging info for
the array's upper bound is a reference...

 <3><71a>: Abbrev Number: 7 (DW_TAG_subrange_type)
    <71b>   DW_AT_type        : <0x724>
    <71f>   DW_AT_upper_bound : <0x703>

... to component "i" of our record...

 <2><703>: Abbrev Number: 5 (DW_TAG_member)
    <704>   DW_AT_name        : i
    <706>   DW_AT_decl_file   : 2
    <707>   DW_AT_decl_line   : 6
    <708>   DW_AT_type        : <0x6d1>
    <70c>   DW_AT_data_member_location: 0

... where that component is located at offset 0 of the start
of the record. dwarf2_evaluate_property correctly determines
the offset where to load the value of the bound from, but then
tries to read that value from inferior memory using the address
that was given, which is null. See case PROP_ADDR_OFFSET in
dwarf2_evaluate_property:

        val = value_at (baton->offset_info.type,
                        pinfo->addr + baton->offset_info.offset);

This triggers a memory error, which then causes the printing to terminate.

Since there are going to be situations where providing an address
alone is not going to be sufficient (packed arrays where array elements
are not stored at byte boundaries), this patch fixes the issue by
enhancing the type resolution to take both address and data. This
follows the same principle as the val_print module, where both
address and buffer ("valaddr") can be passed as arguments. If the data
has already been fetched from inferior memory (or provided by the
debugging info in some form -- Eg a constant), then use that data
instead of reading it from inferior memory.

Note that this should also be a good step towards being able to handle
dynamic types whose value is stored outside of inferior memory
(Eg: in a register).

With this patch, GDB isn't able to print all of A1, but does perform
a little better:

    (gdb) p a1
    $1 = ((i => 0, s => , (i => 1, s => , (i => 2, s => )

There is another issue which is independent of this one, and will
therefore be patched separately.

gdb/ChangeLog:

        * dwarf2loc.h (struct property_addr_info): Add "valaddr" field.
        * dwarf2loc.c (dwarf2_evaluate_property): Add handling of
        pinfo->valaddr.
        * gdbtypes.h (resolve_dynamic_type): Add "valaddr" parameter.
        * gdbtypes.c (resolve_dynamic_struct): Set pinfo.valaddr.
        (resolve_dynamic_type_internal): Set pinfo.valaddr.
        Add handling of addr_stack->valaddr.
        (resolve_dynamic_type): Add "valaddr" parameter.
        Set pinfo.valaddr field.
        * ada-lang.c (ada_discrete_type_high_bound): Update call to
        resolve_dynamic_type.
        (ada_discrete_type_low_bound): Likewise.
        * findvar.c (default_read_var_value): Likewise.
        * value.c (value_from_contents_and_address): Likewise.
2015-05-05 10:43:35 -07:00
Joel Brobecker 75ea58593b preserve the bit stride when resolving an array type.
Consider the following (Ada) variable...

   A1 : Array_Type := (1 => (I => 0, S => <>),
                       2 => (I => 1, S => "A"),
                       3 => (I => 2, S => "AB"));

... where Array_Type is an array of records whose size is variable:

   subtype Small_Type is Integer range 0 .. 10;
   type Record_Type (I : Small_Type := 0) is record
      S : String (1 .. I);
   end record;
   type Array_Type is array (Integer range <>) of Record_Type;

Trying to print the value of this array currently results in the following
error:

    (gdb) p a1
    Cannot access memory at address 0x61c000

What happens in this case, is that the compiler describes our array
as an array with a specific stride (and bounds being static 1..3):

 <1><749>: Abbrev Number: 10 (DW_TAG_array_type)
    <74a>   DW_AT_name        : (indirect string, offset: 0xb6d): pck__T18s
    <74e>   DW_AT_byte_stride : 16
    <74f>   DW_AT_type        : <0x6ea>
 <2><757>: Abbrev Number: 11 (DW_TAG_subrange_type)
    <758>   DW_AT_type        : <0x75e>
    <75c>   DW_AT_upper_bound : 3

This is because we cannot use, in this case, the size of the record
to determine that stride, since the size of the record depends on
its contents. So the compiler helps us by providing that stride.

The problems start when trying to resolve that type. Because the elements
contained in that array type are dynamic, the array itself is considered
dynamic, and thus we end up creating a resolved version of that array.
And during that resolution, we were not handling the case where the array
had a stride. See gdbtypes.c::resolve_dynamic_array...

  return create_array_type (copy_type (type),
                            elt_type,
                            range_type);

As a result, we created an array whose stride was based on the size
of elt_type, which a record whose size isn't static and irrelevant
regardless.

This patch fixes is by calling create_array_type_with_stride instead.

As it happens, there is another issue for us to be able to print
the value of our array, but those are independent of this patch
and will be handled separately. For now, the patch allows us to
get rid of the first error, and the output is now:

     (gdb) p a1
     $1 = (

gdb/ChangeLog:

	* gdbtypes.c (resolve_dynamic_array): Use
	create_array_type_with_stride instead of create_array_type.
2015-05-05 10:42:07 -07:00
DJ Delorie 0952813b0b Make RL78 disassembler and simulator respect ISA for mul/div
[gas]
	* config/rl78-defs.h (rl78_isa_g10): New.
	(rl78_isa_g13): New.
	(rl78_isa_g14): New.
	* config/rl78-parse.y (ISA_G10): New.
	(ISA_G13): New.
	(ISA_G14): New.
	(MULHU, MULH, MULU, DIVHU, DIVWU, MACHU, MACH): Use them.
	* config/tc-rl78.c (rl78_isa_g10): New.
	(rl78_isa_g13): New.
	(rl78_isa_g14): New.

[gdb]
	* rl78-tdep.c (rl78_analyze_prologue): Pass RL78_ISA_DEFAULT to
	rl78_decode_opcode

[include]
	* dis-asm.h (print_insn_rl78_g10): New.
	(print_insn_rl78_g13): New.
	(print_insn_rl78_g14): New.
	(rl78_get_disassembler): New.
	* opcode/rl78.h (RL78_Dis_Isa): New.
	(rl78_decode_opcode): Add ISA parameter.

[opcodes]
	* disassemble.c (disassembler): Choose suitable disassembler based
	on E_ABI.
	* rl78-decode.opc (rl78_decode_opcode): Take ISA parameter.  Use
	it to decode mul/div insns.
	* rl78-decode.c: Regenerate.
	* rl78-dis.c (print_insn_rl78): Rename to...
	(print_insn_rl78_common): ...this, take ISA parameter.
	(print_insn_rl78): New.
	(print_insn_rl78_g10): New.
	(print_insn_rl78_g13): New.
	(print_insn_rl78_g14): New.
	(rl78_get_disassembler): New.

[sim]
	* rl78/cpu.c (g14_multiply): New.
	* rl78/cpu.h (g14_multiply): New.
	* rl78/load.c (rl78_load): Decode ISA completely.
	* rl78/main.c (main): Expand -M to include other ISAs.
	* rl78/rl78.c (decode_opcode): Decode based on ISA.
	* rl78/trace.c (rl78_disasm_fn): New.
	(sim_disasm_init): Reset it.
	(sim_disasm_one): Get correct disassembler for ISA.
2015-04-30 15:25:49 -04:00
Yao Qi 5fccc63539 Skip setting HW watchpoint if skip_hw_watchpoint_multi_tests in gdb.base/break-idempotent.exp
Hi,
I see this fails below on arm linux native testing and remote testing
with "set remote hardware-watchpoint-limit 1",

 rwatch global^M
 There are not enough available hardware resources for this watchpoint.^M
 (gdb) FAIL: gdb.base/break-idempotent.exp: always-inserted off: rwatch: twice: rwatch global

gdb.base/break-idempotent.exp sets two breakpoints/watchpoints on the
same address.  GDB isn't smart enough calculate these two HW
watchpoints can fit in one HW debug register, so the error message
above isn't necessary (there is one HW watchpoint register on arm).
Because target_ops interface can_use_hardware_watchpoint doesn't
pass enough information to the target backend.

Note that if I don't "set remote hardware-watchpoint-limit 1" in
remote testing, this test passes without fails.  However without
"set remote hardware-watchpoint-limit 1", many other watchpoint
tests fail.

This patch is to add a check to skip_hw_watchpoint_multi_tests
for rwatch and awatch.  We can add such check for watch as well,
but GDB is able to switch to software watchpoint if HW resource
isn't available, it doesn't cause any fail, I decide not to skip.

gdb/testsuite:

2015-04-30  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/break-idempotent.exp: If
	skip_hw_watchpoint_multi_tests returns true, skip the tests
	on "rwatch" and "awatch".
2015-04-30 10:08:10 +01:00
Yao Qi 42d38f42dc Skip gdb.base/relativedebug.exp if libc doesn't have debug info
Hi,
I see the fail in gdb.base/relativedebug.exp on aarch64 box on which
glibc doesn't have debug info,

 bt^M
 #0 0x0000002000061a88 in raise () from /lib/aarch64-linux-gnu/libc.so.6^M
 #1 0x0000002000064efc in abort () from /lib/aarch64-linux-gnu/libc.so.6^M
 #2 0x0000000000400640 in handler (signo=14) at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:25^M
 #3 <signal handler called>^M
 #4 0x00000020000cc478 in ?? () from /lib/aarch64-linux-gnu/libc.so.6^M
 #5 0x0000000000400664 in main () at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:32^M
 (gdb) FAIL: gdb.base/relativedebug.exp: pause found in backtrace

if glibc has debug info, this test doesn't fail.

In sysdeps/unix/sysv/linux/generic/pause.c, __libc_pause calls
__syscall_pause,

  static int
  __syscall_pause (void)
  {
    sigset_t set;

    int rc =
      INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, _NSIG / 8);
    if (rc == 0)
      rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8);

    return rc;
  }

  int
  __libc_pause (void)
  {
    if (SINGLE_THREAD_P)
      return __syscall_pause ();     <--- tail call

    int oldtype = LIBC_CANCEL_ASYNC ();

    int result = __syscall_pause ();

    LIBC_CANCEL_RESET (oldtype);

    return result;
  }

and GDB unwinder is confused by the GCC optimized code,

(gdb) disassemble pause
Dump of assembler code for function pause:
   0x0000007fb7f274c4 <+0>:     stp     x29, x30, [sp,#-32]!
   0x0000007fb7f274c8 <+4>:     mov     x29, sp
   0x0000007fb7f274cc <+8>:     adrp    x0, 0x7fb7fd2000
   0x0000007fb7f274d0 <+12>:    ldr     w0, [x0,#364]
   0x0000007fb7f274d4 <+16>:    stp     x19, x20, [sp,#16]
   0x0000007fb7f274d8 <+20>:    cbnz    w0, 0x7fb7f274e8 <pause+36>

   0x0000007fb7f274dc <+24>:    ldp     x19, x20, [sp,#16]
   0x0000007fb7f274e0 <+28>:    ldp     x29, x30, [sp],#32
   0x0000007fb7f274e4 <+32>:    b       0x7fb7f27434    <---- __syscall_pause

   0x0000007fb7f274e8 <+36>:    bl      0x7fb7f5e080

Note that the program stops in __syscall_pause, but its symbol is
stripped in glibc, so GDB doesn't know where the program stops.
__syscall_pause is a tail call in __libc_pause, so it returns to main
instead of __libc_pause.  As a result, the backtrace is like,

 #0  0x0000007fb7ebca88 in raise () from /lib/aarch64-linux-gnu/libc.so.6
 #1  0x0000007fb7ebfefc in abort () from /lib/aarch64-linux-gnu/libc.so.6
 #2  0x0000000000400640 in handler (signo=14) at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:25
 #3  <signal handler called>
 #4  0x0000007fb7f27478 in ?? () from /lib/aarch64-linux-gnu/libc.so.6   <-- [in __syscall_pause]
 #5  0x0000000000400664 in main () at ../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.c:32

looks GDB does nothing wrong here.  I looked back at the test case
gdb.base/relativedebug.exp, which was added
https://sourceware.org/ml/gdb-patches/2006-10/msg00305.html
This test was indented to test the problem that "backtraces no longer
display some libc functions" after separate debug info is installed.
IOW, it makes few sense to test against libc which doesn't have debug
info at all, such as my case.

This patch is to tweak the test case to catch the output of
"info shared", if "(*)" is found for libc.so, which means libc doesn't
have debug info, then skip the test.

gdb/testsuite:

2015-04-30  Yao Qi  <yao.qi@linaro.org>

	* gdb.base/relativedebug.exp: Invoke gdb command
	"info sharedlibrary", and if libc.so doesn't have debug info,
	skip the test.
2015-04-30 09:55:06 +01:00
Doug Evans 2ce1cdbf84 PR python/18285
gdb/ChangeLog:

	PR python/18285
	* NEWS: Document new gdb.XMethodWorker.get_result_type method.
	* eval.c (evaluate_subexp_standard) <OP_FUNCALL>: Handle
	EVAL_AVOID_SIDE_EFFECTS for xmethods.
	* extension-priv.h (struct extension_language_ops)
	<get_xmethod_result_type>: New member.
	* extension.c (get_xmethod_result_type): New function.
	* extension.h (get_xmethod_result_type): Declare.
	* python/py-xmethods.c (get_result_type_method_name): New static
	global.
	(py_get_result_type_method_name): Ditto.
	(gdbpy_get_xmethod_result_type): New function.
	(gdbpy_initialize_xmethods): Initialize py_get_result_type_method_name.
	* python/python-internal.h (gdbpy_get_xmethod_result_type): Declare.
	* python/python.c (python_extension_ops): Add
	gdbpy_get_xmethod_result_type.
	* python/lib/gdb/xmethod.py (XMethodWorker): Add get_result_type.
	* valarith.c (value_x_binop): Handle EVAL_AVOID_SIDE_EFFECTS for
	xmethods.
	(value_x_unop): Ditto.
	* value.c (result_type_of_xmethod): New function.
	* value.h (result_type_of_xmethod): Declare.

gdb/testsuite/ChangeLog:

	* gdb.python/py-xmethods.exp: Add ptype tests.
	* gdb.python/py-xmethods.py (E_method_char_worker): Add
	get_result_type method.

gdb/doc/ChangeLog:

	* python.texi (Xmethod API) <gdb.XMethodWorker.get_result_type>:
	Document.
	(Writing an Xmethod): Add get_result_type to example.
2015-04-29 13:24:21 -07:00
Luis Machado f24a38c514 Use software watchpoints if hardware watchpoints are not available when testing gdb.base/watch-bitfields.exp
There are targets GDB thinks support hardware watchpoints, but in reality they
don't.  Though it may seem that hardware watchpoint creation was successful,
the actual insertion of such watchpoint will fail when GDB moves the inferior.

(gdb) watch -location q.a^M
Hardware watchpoint 2: -location q.a^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: watch -location q.a
watch -location q.e^M
Hardware watchpoint 3: -location q.e^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: watch -location q.e
print q.a^M
$1 = 0^M
(gdb) PASS: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: print expression before
continue^M
Continuing.^M
Warning:^M
Could not insert hardware watchpoint 2.^M
Could not insert hardware watchpoint 3.^M
Could not insert hardware breakpoints:^M
You may have requested too many hardware breakpoints/watchpoints.^M
^M
(gdb) FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: continue

This leads to a number of FAILs:

FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 0->1: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 0->5: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 0->5: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 1->0: print expression before
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.a: 1->0: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: print expression before
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: continue
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: q.e: 5->4: print expression after
FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: continue until exit
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 0->4: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 0->4: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 4->10: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 10->3: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 3->2: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 2->1: print expression after
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 1->0: print expression before
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: q.d + q.f + q.g: 1->0: continue
FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: continue until exit

We can avoid these errors/FAILs by checking the board data and switching to
software watchpoints if the board does not support hardware watchpoints.

gdb/testsuite/ChangeLog:

2015-04-29  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/watch-bitfields.exp: Switch to software watchpoints if
	the target does not support hardware watchpoints.
2015-04-29 12:22:24 -03:00
Luis Machado ecbf2b3c4f Handle memory write errors on gdb.base/break-always.exp
This is another case of the testcase not handling memory write errors that
happen on some targets (QEMU) when GDB attempts to modify an address that
should contain a breakpoint, for example.

The following patch handles this and prevents spurious failures from
happening. It also adds a foreach loop to avoid duplication of code
and hardcoded patterns.

gdb/testsuite/ChangeLog:

2015-04-29  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/break-always.exp: Abort testing if writing to memory
	causes an error.
2015-04-29 12:09:40 -03:00
Gary Benson 998d2a3ef3 Allow passing fd == NULL to exec_file_find and solib_find
This commit allows NULL to be passed as the int *fd argument
to exec_file_find and solib_find to simplify use cases where
the caller does not require the file to be opened.

gdb/ChangeLog:

	* solib.c (solib_find_1): Allow fd argument to be NULL.
	(exec_file_find): Update comment.
	(solib_find): Likewise.
	* exec.c (exec_file_locate_attach): Use NULL as fd
	argument to exec_file_find to avoid having to close
	the opened file.
	* infrun.c (follow_exec): Likewise.
2015-04-29 15:20:22 +01:00
Doug Evans 34f5f757b3 PR python/18299
gdb/ChangeLog:

	PR python/18299
	* python/lib/gdb/printing.py (register_pretty_printer): Handle
	name or __name__ attributes.  Handle gdb module as first argument.

gdb/testsuite/ChangeLog:

	* gdb.python/py-pp-maint.py: Move "replace" testing to ...
	* gdb.python/py-pp-registration.exp: ... here.  New file.
	* gdb.python/py-pp-registration.c: New file.
	* gdb.python/py-pp-registration.py: New file.
2015-04-28 22:14:23 -07:00
Doug Evans 69b4374a87 PR python/18089
gdb/ChangeLog:

	PR python/18089
	* python/py-prettyprint.c (print_children): Verify result of children
	iterator.  Provide better error message.
	* python/python-internal..h (gdbpy_print_python_errors_p): Declare.
	* python/python.c (gdbpy_print_python_errors_p): New function.

gdb/testsuite/ChangeLog:

	* gdb.python/py-bad-printers.c: New file.
	* gdb.python/py-bad-printers.py: New file.
	* gdb.python/py-bad-printers.exp: New file.
2015-04-28 21:53:54 -07:00
Doug Evans 5e7cf0784c * gdbtypes.h (struct cplus_struct_type) <n_baseclasses>: Fix comment.
gdb/ChangeLog:

	* gdbtypes.h (struct cplus_struct_type) <n_baseclasses>: Fix comment.
2015-04-28 21:23:24 -07:00
Sasha Smundak 59fb7612dd Add gdb.Type.optimized_out method.
gdb/ChangeLog:

	* NEWS: Mention gdb.Type.optimized_out method.
	* python/py-type.c (typy_optimized_out):  New function.

gdb/doc/ChangeLog:

	* python.texi: New method documented.

gdb/testsuite/ChangeLog:

	* gdb.python/py-type.exp: New test.
2015-04-28 17:41:09 -07:00
John Baldwin cea6e4f13a Use "gdb_wait.h" instead of <sys/wait.h>.
gdb/ChangeLog:
	* fbsd-nat.c: Include "gdb_wait.h" instead of <sys/wait.h>.
2015-04-28 14:44:07 -04:00
Patrick Palka 24b73f8e74 Disable readline's SIGWINCH handler
We no longer need it as we handle SIGWINCH ourselves.  Also move the
call to init_page_info() from initialize_utils() to the latter
function's only caller, gdb_init().

gdb/ChangeLog:

	* utils.c (init_page_info): Set rl_catch_sigwinch to zero.
	(initialize_utils): Move call of init_page_info() to ...
	* top.c (gdb_init): ... here.
2015-04-28 08:51:03 -04:00
Patrick Palka a88d0bb33c Update our idea of our terminal's dimensions even outside of TUI
When in the CLI, GDB's "width" and "height" variables are not kept in sync
when the underlying terminal gets resized.

This patch fixes this issue by making sure sure to update GDB's "width"
and "height" variables in the !tui_active case of our SIGWINCH handler.

gdb/ChangeLog:

	* tui/tui-win.c (tui_sigwinch_handler): Remove now-stale comment.
	(tui_sigwinch_handler): Still update our idea of
	the terminal's width and height even when TUI is not active.
2015-04-28 08:50:11 -04:00
Patrick Palka d6e5e7f7fd Introduce function for directly updating GDB's screen dimensions
... to replace the roundabout pattern of

  execute_command ("set width %d");
  execute_command ("set height %d");

for doing the same thing.

gdb/ChangeLog:

	* utils.h (set_screen_width_and_height): Declare.
	* utils.c (set_screen_width_and_height): Define.
	* tui/tui-win.c (tui_update_gdb_sizes): Use it.
2015-04-28 08:46:28 -04:00
Gary Benson ff862be47e Use exec_file_find to prepend gdb_sysroot in follow_exec
This commit updates follow_exec to use exec_file_find to prefix
the new executable's filename with gdb_sysroot rather than doing
it longhand.

gdb/ChangeLog:

	* infrun.c (solist.h): New include.
	(follow_exec): Use exec_file_find to prefix execd_pathname
	with gdb_sysroot.
2015-04-28 12:21:32 +01:00
Andy Wingo 2631b16a57 Fix py-parameter.exp and scm-parameter.exp path matching
gdb/testsuite/ChangeLog:

	* gdb.python/py-parameter.exp:
	* gdb.guile/scm-parameter.exp: Escape the path that we are
	matching against, as it might contain characters that are special
	to regular expressions.
2015-04-28 11:15:47 +02:00
Patrick Palka 2eb639cbe4 TUI: avoid calling strcpy() on identical string objects
In tui_set_source_content(), when offset == 0 the source and destination
pointers of the call to strcpy() are actually the same.  In this case
not only is strcpy() unnecessary but it is also UB when the two strings
overlap.

gdb/ChangeLog:

	* tui/tui-source.c (tui_set_source_content): Avoid calling
	strcpy() when offset is 0.
2015-04-27 21:19:58 -04:00
Patrick Palka 9720679936 Fix PR gdb/18155
For no good reason the function tui_free_window() is freeing the locator
window when we pass it an SRC_WIN or a DISASSEM_WIN.  This behavior
doesn't make much sense because the locator window is always visible and
its contents do not change when the main window changes.

This behavior triggers the above PR because when we switch from one TUI
window to another (in the PR, from the src window to the asm window) we
call tui_free_window() on the previously active window (in the PR, the
src window).  The function then frees the src window along with the
locator window and later we segfault when the now-active asm window
tries to query the locator window about the inferior's PC.

This patch fixes this apparently wrong behavior by changing
tui_free_window() to not free the locator window when we pass it an
SRC_WIN or a DISASSEM_WIN.

gdb/ChangeLog:

	PR gdb/18155
	* tui/tui-data.c (tui_free_window): Don't free the locator
	window when passed an SRC_WIN or a DISASSEM_WIN.
2015-04-27 21:19:58 -04:00
Patrick Palka 63ed81829e Make type-safe the 'content' field of struct tui_gen_win_info
The 'content' field of struct tui_gen_win_info currently has type
void ** but the field always stores an object of type tui_win_content.
Instead of unnecessarily casting to and from void ** we should just give
the field the type tui_win_content in the first place.

This patch does this and also eliminates all now-redundant casts
involving the 'content' struct field that I could find.

gdb/ChangeLog:

	* tui/tui-data.h (struct tui_win_element): Forward-declare.
	(tui_win_content): Move declaration.
	(struct tui_gen_win_info): Give 'content' field the
	type tui_win_content.
	* tui/tui-data.c (init_content_element): Remove redundant and
	erroneous casts.
	(tui_add_content_elements): Remove erroneous cast.
	* tui/tui-disasm.c (tui_set_disassem_content): Remove redundant
	casts.
	(tui_get_begin_asm_address): Likewise.
	* tui/tui-regs.c (tui_show_registers): Likewise.
	(tui_show_register_group): Likewise.
	(tui_display_registers_from): Likewise.
	(tui_check_register_values): Likewise.
	* tui/tui-source.c (tui_set_source_content): Likewise.
	(tui_set_source_content_nil): Likewise.
	(tui_source_is_displayed): Likewise.
	* tui/tui-stack.c (tui_show_locator_content): Likewise.
	(tui_set_locator_fullname): Likewise.
	(tui_set_locator_info): Likewise.
	(tui_show_frame_info): Likewise.
	* tui/tui-winsource.c (tui_clear_source_content): Likewise.
	(tui_show_source_line): Likewise.
	(tui_horizontal_source_scroll): Likewise.
	(tui_update_breakpoint_info): Likewise.
	(tui_set_exec_info_content): Likewise.
	(tui_show_exec_info_content): Likewise.
	(tui_alloc_source_buffer): Likewise.
	(tui_line_is_displayed): Likewise.
	(tui_addr_is_displayed): Likewise.
2015-04-27 21:19:53 -04:00
John Baldwin d2b41ca0f9 Add support for catching exec events on FreeBSD.
FreeBSD kernels that support fork tracing always stop a process to
report events for exec.  Such a process will have the PL_FLAG_EXEC
flag set in the pl_flags field of the ptrace_lwpinfo struct returned
by PT_LWPINFO.  The structure does not include the pathname passed to
exec, so use fbsd_pid_to_exec_file to query the pathname of the
process' executable.

gdb/ChangeLog:

	* fbsd-nat.c: (fbsd_wait) [PL_FLAG_EXEC]: Report TARGET_WAITKIND_EXECD
	event if PL_FLAG_EXEC is set.
	[PL_FLAG_EXEC] (fbsd_insert_exec_catchpoint): New function.
	[PL_FLAG_EXEC] (fbsd_remove_exec_catchpoint): New function.
	(fbsd_nat_add_target) [PL_FLAG_EXEC]: Set
	"to_insert_exec_catchpoint" to "fbsd_insert_exec_catchpoint".
	Set "to_remove_exec_catchpoint" to "fbsd_remove_exec_catchpoint".
2015-04-27 19:27:04 -04:00
John Baldwin e58e05d677 Enable fork tracing for native FreeBSD targets.
Enable PT_FOLLOW_FORK on all processes.  When this is enabled, both
the parent and child process stop when a fork or vfork occurs.

A target operation for wait uses PT_LWPINFO to fetch more detailed
information about the state of a stopped process.  A parent process
sets the PL_FLAG_FORKED flag in the pl_flags field of the structure
returned by PT_LWPINFO as well as the pid of the new child process.
The child process sets the PL_FLAG_CHILD flag in the pl_flags field.

When a fork is detected, the wait hook waits for both processes to
report their respective events.  It then reports the fork to GDB as
a single TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED event.
The kernel does not guarantee the order the events are reported in.
If the parent process' event is reported first, then the wait hook
explicitly waits for the child process.  If the child process' event
is reported first, the event is recorded on an internal list of
pending child events and the wait hook waits for another event.
Later when the parent process' event is reported, the parent will
use the previously-recorded child process event instead of explicitly
waiting on the child process.

To distinguish vfork events from fork events, the external process
structure for the child process is extracted from the kernel.  The
P_PPWAIT flag is set in the ki_flags field of this structure if the
process was created via vfork, but it is not set for a regular fork.

gdb/ChangeLog:

	* fbsd-nat.c: [PT_LWPINFO] New variable super_wait.
	[TDP_RFPPWAIT] New variable fbsd_pending_children.
	[TDP_RFPPWAIT] (fbsd_remember_child): New function.
	[TDP_RFPPWAIT] (fbsd_is_child_pending): New function.
	[TDP_RFPPWAIT] (fbsd_fetch_kinfo_proc): New function.
	[PT_LWPINFO] (fbsd_wait): New function.
	[TDP_RFPPWAIT] (fbsd_follow_fork): New function.
	[TDP_RFPPWAIT] (fbsd_insert_fork_catchpoint): New function.
	[TDP_RFPPWAIT] (fbsd_remove_fork_catchpoint): New function.
	[TDP_RFPPWAIT] (fbsd_insert_vfork_catchpoint): New function.
	[TDP_RFPPWAIT] (fbsd_remove_vfork_catchpoint): New function.
	[TDP_RFPPWAIT] (fbsd_enable_follow_fork): New function.
	[TDP_RFPPWAIT] (fbsd_post_startup_inferior): New function.
	[TDP_RFPPWAIT] (fbsd_post_attach): New function.
	(fbsd_nat_add_target) [PT_LWPINFO] Set "to_wait" to
	"fbsd_wait".
	[TDP_RFPPWAIT] Set "to_follow_fork" to "fbsd_follow_fork".
	Set "to_insert_fork_catchpoint" to "fbsd_insert_fork_catchpoint".
	Set "to_remove_fork_catchpoint" to "fbsd_remove_fork_catchpoint".
	Set "to_insert_vfork_catchpoint" to "fbsd_insert_vfork_catchpoint".
	Set "to_remove_vfork_catchpoint" to "fbsd_remove_vfork_catchpoint".
	Set "to_post_startup_inferior" to "fbsd_post_startup_inferior".
	Set "to_post_attach" to "fbsd_post_attach".
2015-04-27 19:26:17 -04:00
John Baldwin 8f60fe014d Add fbsd_nat_add_target.
Add a wrapper for add_target in fbsd-nat.c to override target operations
common to all native FreeBSD targets.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_pid_to_exec_file): Mark static.
	(fbsd_find_memory_regions): Mark static.
	(fbsd_nat_add_target): New function.
	* fbsd-nat.h: Export fbsd_nat_add_target and remove prototypes for
	fbsd_pid_to_exec_file and fbsd_find_memory_regions.
	* amd64fbsd-nat.c (_initialize_amd64fbsd_nat): Use fbsd_nat_add_target.
	* i386fbsd-nat.c (_initialize_i386fbsd_nat): Likewise.
	* ppcfbsd-nat.c (_initialize_ppcfbsd_nat): Likewise.
	* sparc64fbsd-nat.c (_initialize_sparc64fbsd_nat): Likewise.
2015-04-27 19:24:18 -04:00
Gary Benson 5fbae7d108 Do not manipulate "target:" filenames as local paths
This commit alters two places that manipulate object file filenames
to detect "target:" filenames and to not attempt to manipulate them
as paths on the local filesystem:

 - allocate_objfile is updated to not attempt to expand "target:"
   filenames with gdb_abspath.

 - load_auto_scripts_for_objfile is updated to not attempt to load
   auto-load scripts for object files with "target:" filenames.

gdb/ChangeLog:

	* objfiles.c (allocate_objfile): Do not attempt to expand name
	if name is a "target:" filename.
	* auto-load.c (load_auto_scripts_for_objfile): Do not attempt
	to load auto-load scripts for objfiles with "target:" filenames.
2015-04-27 15:39:46 +01:00
Andreas Arnez 417c80f9e4 S390: Vector ABI support
With the S390 vector ABI, vector registers are used for passing vector
arguments and for returning a vector.  Support this ABI in inferior
function calls and when setting or retrieving a function's return
value.

gdb/ChangeLog:

	* s390-linux-tdep.c: Include "elf/s390.h" and "elf-bfd.h".
	(enum s390_vector_abi_kind): New enum.
	(struct gdbarch_tdep)<vector_abi>: New field.
	(s390_effective_inner_type): Add parameter min_size.  Stop
	unwrapping if the inner type is smaller than min_size.
	(s390_function_arg_float): Adjust call to
	s390_effective_inner_type.
	(s390_function_arg_vector): New function.
	(s390_function_arg_integer): Adjust comment.
	(struct s390_arg_state)<vr>: New field.
	(s390_handle_arg): Add parameter 'is_unnamed'.  Pass vector
	arguments according to vector ABI when appropriate.
	(s390_push_dummy_call): Initialize the argument state's field
	'vr'.  Adjust calls to s390_handle_arg.
	(s390_register_return_value): Handle vector return values.
	(s390_return_value): Apply the "register" return value convention
	to a vector when appropriate.
	(s390_gdbarch_init): Initialize tdep->vector_abi.
	* NEWS: Announce S390 vector ABI support.
2015-04-27 11:38:47 +02:00
Andreas Arnez 4e65a17e62 S390: Re-arrange implementation of s390_return_value
Move related logic in the implementation of s390_return_value closer
together.  This makes it easier to read and extend.

gdb/ChangeLog:

	* s390-linux-tdep.c (s390_return_value_convention): Remove
	function.  Inline its logic...
	(s390_return_value): ...here.  Instead, move the handling of the
	"register" return value convention...
	(s390_register_return_value): ...here.  New function.
2015-04-27 11:38:47 +02:00
Andreas Arnez 80f7532016 S390: Restructure s390_push_dummy_call
Simplify the structure of s390_push_dummy_call and its various helper
functions.  This reduces the code and makes it easier to extend.  The
new code should be functionally equivalent to the old one, except that
copies created by the caller are now always aligned on an 8-byte
boundary.

gdb/ChangeLog:

	* s390-linux-tdep.c
	(is_float_singleton): Remove function.  Move the "singleton" part
	of the logic...
	(s390_effective_inner_type): ...here.  New function.
	(is_float_like): Remove function.  Inline its logic...
	(s390_function_arg_float): ...here.
	(is_pointer_like, is_integer_like, is_struct_like): Remove
	functions.  Inline their logic...
	(s390_function_arg_integer): ...here.
	(s390_function_arg_pass_by_reference): Remove function.
	(extend_simple_arg): Remove function.
	(alignment_of): Remove function.
	(struct s390_arg_state): New structure.
	(s390_handle_arg): New function.
	(s390_push_dummy_call): Move parameter placement logic to the new
	function s390_handle_arg.  Call it for calculating the stack area
	sizes first, and again for actually writing the parameters.
2015-04-27 11:38:46 +02:00
Andreas Arnez 6dbc9c0457 S390: For zero, let is_power_of_two() return false
This fixes a minor issue with the helper function is_power_of_two(),
which returned non-zero ("true") if the argument was zero.  This led
to a wrong decision when passing a zero-sized struct in an inferior
function call.

gdb/ChangeLog:

	* s390-linux-tdep.c (is_power_of_two): Add comment.  Return
	  false if the argument is zero.
2015-04-27 11:38:46 +02:00
Pierre-Marie de Rodat 9e19566105 [Ada] Cache all static structures and reset cache during resolution
Currently, ada-lang.c:template_to_static_fixed_type (working on
structure types only) caches its result into the unused TYPE_TARGET_TYPE
field. This introduces inconsistencies when the input type is
specialized, for instance during type resolution: the cached static
fixed type is copied along with the original type, but it's no longer
adapted to the copy once the copy is modified:
template_to_static_fixed_type has to compute another static fixed type
for it.

This change first introduces a cache reset during type resolution for
structure types so that this inconsistency does not happen anymore. It
also makes template_to_static_fixed_type smarter with respect to types
that do not need static fixed copies so that less computations is done
in general.

This inconsistency was spotted thanks to code reading, not because of
any sort of failure and we did not manage to exhibit a failure yet, so
no testcase for this.

gdb/ChangeLog:

	* ada-lang.c (template_to_static_fixed_type): Return input type
	when it is already fixed. Cache the input type itself when not
	creating a static fixed copy. Make it explicit that we never
	molestate the input type.
	* gdbtypes.c (resolve_dynamic_struct): Reset the
	TYPE_TARGET_TYPE field for resolved copies.
2015-04-27 11:06:07 +02:00
Joel Brobecker 460efde16c [Ada] Preserve typedef layer when getting struct element
Consider the following declarations:

   type Int_Access is access Integer;
   type Record_Type is record
      IA : Int_Access;
   end record;

   R : Record_Type;

Printing the type name of "R.IA" yields:

    (gdb) whatis r.ia
    type = access integer

It should be:

    (gdb) whatis r.ia
    type = bar.int_access

Looking at the debugging info, field "r.ia" is defined as
a typedef which has the name of the field type:

        .uleb128 0x3    # (DIE (0x4e) DW_TAG_typedef)
        .long   .LASF4  # DW_AT_name: "bar__int_access"
        .long   0x8b    # DW_AT_type

... with the typedef's target type being an anonymous pointer
type:

        .uleb128 0x7    # (DIE (0x8b) DW_TAG_pointer_type)
        .byte   0x8     # DW_AT_byte_size
        .long   0x91    # DW_AT_type

What happens here is that a couple of function in ada-lang.c
always start by stripping all typedef layers when handling
struct fields, with the effect of making us lose the type name
in this case.

We did not understand this at the time the code was written,
but typedefs should be stripped only when we know we do not
need them. So this patch, adjust the code to avoid the stripping
while handling the fields, and adds it back in the lone place
which handles the result of processing and didn't know how to
handle typedefs struct fields yet.

gdb/ChangeLog:

        * ada-lang.c (ada_is_tagged_type): Add call to ada_check_typedef.
        (ada_lookup_struct_elt_type): Remove calls to ada_check_typedef.
        (template_to_static_fixed_type): Call ada_check_typedef only
        when necessary.

gdb/testsuite/ChangeLog:

        * gdb.ada/rec_comp: New testcase.
2015-04-27 11:04:47 +02:00
Sergio Durigan Junior 2d369d8e97 Clear variable "coredump_var_addr" before using it on gdb.base/coredump-filter.exp
This commit is a continuation of the fix committed on:

  commit 8cd8f2f8ac
  Author: Sergio Durigan Junior <sergiodj@redhat.com>
  Date:   Mon Apr 13 02:40:08 2015 -0400

      Rename variable "addr" to "coredump_var_addr" in gdb.base/coredump-filter.exp

Pedro pointed out that this fix was not complete, because the
testsuite could be run several times in a row (for example), which
means that it is not enough to just make the variable name unique: it
also needs to be cleared out if it is global.

This commit does that.  It is actually just a commit made to make
things totally correct; this specific test does not fail if you run it
several times in a row.

gdb/testsuite/ChangeLog:
2015-04-26  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/coredump-filter.exp: Clear variable "coredump_var_addr"
	before using it.
2015-04-26 15:34:29 -04:00
Andrew Burgess 6faec16b1c gdb: Add internationalization support to a few strings.
Spotted a few strings that were missing internationalization support.

gdb/ChangeLog:

	* cli/cli-dump.c (srec_dump_command): Add internationalization
	mark ups.
	(ihex_dump_command): Likewise.
	(tekhex_dump_command): Likewise.
	(binary_dump_command): Likewise.
	(binary_append_command): Likewise.
2015-04-24 22:49:59 +01:00
Andrew Burgess cf75d6c37e gdb: Add support for dumping to verilog hex format.
Extend the gdb 'dump' command to allow creating output in verilog hex
format.  Add some tests to cover new functionality.  As bfd does not
currently support reading in verilog hex formats the tests only cover
the 'dump' command, not the 'restore' command.

gdb/ChangeLog:

	* cli/cli-dump.c (verilog_cmdlist): New variable.
	(dump_verilog_memory): New function.
	(dump_verilog_value): New function.
	(verilog_dump_command): New function.
	(_initialize_cli_dump): Add new commands to support verilog dump
	format.
	* NEWS: Add entry for "dump verilog".

gdb/doc/ChangeLog:

	* gdb.texinfo (Dump/Restore Files): Add detail about verilog dump
	format.

gdb/testsuite/ChangeLog:

	* gdb.base/dump.exp: Add *.verilog files to all_files list.  Add
	new tests for verilog output.
2015-04-24 22:49:59 +01:00
Doug Evans 897c3d327e * python.texi (Xmethods In Python): Fix name of method to call the xmethod.
gdb/doc/ChangeLog:

	* python.texi (Xmethods In Python): Fix name of method to call the
	xmethod.
2015-04-24 11:16:12 -07:00
Pierre-Marie de Rodat 8cd00c5973 Fix printing for GNAT stuff for types that do not have descr. types
gdb/ChangeLog:
2015-04-24  Pierre-Marie de Rodat  <derodat@adacore.com>

	* gdbtypes.c (print_gnat_stuff): Do not recurse on the
	descriptive type when there is none.
2015-04-24 16:14:17 +02:00
Yao Qi 8dbe7ca5a5 A new board file remote-gdbserver-on-localhost.exp
This patch is to add a new board file that does real remote gdbserver
testing on localhost.  This board file can be used to reproduce PR 18208.

gdb/testsuite

2015-04-24  Yao Qi  <yao.qi@linaro.org>

	* boards/remote-gdbserver-on-localhost.exp: New file.
2015-04-24 11:00:14 +01:00
Pedro Alves 4ef9fb2f07 Fix gdb.base/interrupt.exp racy fail against gdbserver
Currently, against gdbserver, interrupt.exp occasionaly fails like
this:

 ERROR: Process no longer exists
 UNRESOLVED: gdb.base/interrupt.exp: send end of file

The problem is that we see gdbserver exiting before we match gdb's
output:

 expect: does "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n" (spawn_id exp8) match regular expression "end of file"? Gate "end of file"? gate=no
 expect: read eof
 expect: set expect_out(spawn_id) "exp8"
 expect: set expect_out(buffer) "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n"

Fix this by removing $inferior_spawn_id from the set of spawn ids
expect is watching as soon as we see the "end of file" string out of
the inferior spawn id, using an indirect spawn id list.

Tested on x86-64 Fedora 20, native and gdbserver (both target remote
and extended-remote).

gdb/testsuite/ChangeLog:
2015-04-23  Pedro Alves  <palves@redhat.com>

	* gdb.base/interrupt.exp: Use an indirect spawn id list holding
	$inferior_spawn_id instead of $inferior_spawn_id directly.  On
	"end of file", remove $inferior_spawn_id from the indirect list.
2015-04-23 15:48:27 +01:00
Pedro Alves 0a8031692e gdb.base/interrupt.exp: Rename saw_eof to saw_end_of_file
To avoid confusion between "end of file" string matching and eof
matching, as in process exit.

gdb/testsuite/ChangeLog:
2015-04-23  Pedro Alves  <palves@redhat.com>

	* gdb.base/interrupt.exp: Rename saw_eof to saw_end_of_file.
2015-04-23 15:48:27 +01:00
Pedro Alves 749ef8f891 gdb_test_multiple match eof of any spawn_id
Since silent handling of eof is usually the wrong thing to do, this
patch makes gdb_test_multiple handle it for all $any_spawn_id.

Currently, against gdbserver, interrupt.exp occasionaly fails like
this:

 FAIL: gdb.base/interrupt.exp: send end of file

gdb.log with expect debug output enabled shows:

 expect: does "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n" (spawn_id exp8) match regular expression "end of file"? Gate "end of file"? gate=no
 expect: read eof
 expect: set expect_out(spawn_id) "exp8"
 expect: set expect_out(buffer) "\r\n\r\nChild exited with status 0\r\nGDBserver exiting\r\n"
 FAIL: gdb.base/interrupt.exp: send end of file

Note "expect: read eof" for spawn_id=exp8.  exp8 is
inferior_spawn_id/gdbserver_spawn_id.  That means
expect/gdb_test_multiple saw gdbserver exit before we got the expected
gdb output.  Since there's no explicit pattern for "eof", expect (and
thus gdb_test_multiple) just returns.

After this commit, we get instead:

 ERROR: Process no longer exists
 UNRESOLVED: gdb.base/interrupt.exp: send end of file

Note that before we still got an FAIL because $saw_inferior_exit is 0
when we get to:

	gdb_assert { $saw_eof && $saw_inferior_exit } $msg

Fixing the fail (now unresolved) will be the subject of a separate
patch.

gdb/testsuite/ChangeLog:
2015-04-23  Pedro Alves  <palves@redhat.com>

	* lib/gdb.exp (gdb_test_multiple): Match eof/full_buffer/timeout
	on $any_spawn_id instead of only on $gdb_spawn_id.
2015-04-23 15:48:26 +01:00
Patrick Palka 8900d71e38 Explicitly call rl_resize_terminal() in TUI's SIGWINCH handler
In readline 6.3, the semantics of SIGWINCH handling has changed.
When a SIGWINCH signal is raised, readline's rl_sigwinch_handler() now
does not immediately call rl_resize_terminal().  Instead it sets a flag
that is checked by RL_CHECK_SIGNALS() at a point where readline has
control, and calls rl_resize_terminal() if said flag is set.

This change is item (c) in https://cnswww.cns.cwru.edu/php/chet/readline/CHANGES

  c.  Fixed a bug that caused readline to try and run code to modify its idea
      of the screen size in a signal handler context upon receiving a SIGWINCH.

This change in behavior is important to us because TUI's
tui_sigwinch_handler() relies on the assumption that by the time it's
called, readline will have updated its knowledge of the terminal
dimensions via rl_resize_terminal().  Since this assumption no longer
holds true, TUI's SIGWINCH handling does not work correctly with
readline 6.3.

To fix this issue this patch makes TUI explicitly call
rl_resize_terminal() in tui_async_resize_screen() at the point where
current terminal dimensions are needed.  (We could call it in
tui_sigwinch_handler too, but since readline avoids doing it, we are
probably safer off avoiding to call it in signal handler context as
well.)  After this change, SIGWINCH handling continues to work properly
with both readline 6.2 and 6.3.

Since we no longer need it, we could now explicitly disable readline's
SIGWINCH handler by setting rl_catch_sigwinch to zero early on in the
program startup but I can't seem to find a good spot to place this
assignment (the first call to rl_initialize() occurs in
tui_initialize_readline() so the assignment should occur before then),
and the handler is harmless anyway.

gdb/ChangeLog:

	* tui/tui-win.c (tui_async_resize_screen): Call
	rl_resize_terminal().
2015-04-23 08:00:55 -04:00
Jon Turney f16eab5ffb windows-nat: Don't change current_event.dwThreadId in handle_output_debug_string()
Using the 'catch-signal' test from the testsuite, on x86_64 Cygwin:

    $ ./gdb testsuite/outputs/gdb.base/catch-signal/catch-signal.exe
    [...]
    (gdb) catch signal
    Catchpoint 1 (standard signals)
    (gdb) r
    [...]
    Catchpoint 1 (signal SIGHUP), main () at
    ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    (gdb) c
    Continuing.
    main () at ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    Failed to resume program execution (ContinueDebugEvent failed, error 87)
    (gdb)

This error occurs because when handle_output_debug_string processes a Cygwin
signal message, it re-writes current_event.dwThreadId to reflect the thread that
the signal will be delivered to, which can be different to the thread reporting
the signal.

Altering current_event.dwThreadId() will cause ContinueDebugEvent() to be
applied to the wrong thread and fail.

So, rather than re-writing the thread id in current_event, use the thread
id by returning it.

With this patch applied this test now yields the expected result:

    $ ./gdb testsuite/outputs/gdb.base/catch-signal/catch-signal.exe
    [...]
    (gdb) catch signal
    Catchpoint 1 (standard signals)
    (gdb) r
    [...]
    Catchpoint 1 (signal SIGHUP), main () at
    ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    (gdb) c
    Continuing.
    Catchpoint 1 (signal SIGHUP), main () at
    ../../../gdb/testsuite/gdb.base/catch-signal.c:42
    42        raise (SIGHUP);               /* third HUP */
    (gdb)

gdb/ChangeLog:

2015-04-22  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (handle_output_debug_string): Don't change
	current_event.dwThreadId.
	(get_windows_debug_event): Use thread_id, rather than relying on
	current_event.dwThreadId being changed.
2015-04-22 19:54:22 +01:00
Jon Turney 68ffc90245 windows-nat: Report an error if ContinueDebugEvent() fails
Using the 'catch-signal' test from the testsuite, on x86_64 Cygwin:

    $ ./gdb testsuite/outputs/gdb.base/catch-signal/catch-signal.exe
    [...]
    (gdb) catch signal
    Catchpoint 1 (standard signals)
    (gdb) r
    [...]
    Catchpoint 1 (signal SIGHUP), main () at
    ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    (gdb) c
    Continuing.
    [hangs]

This is due to a defect in the way Cygwin signals are handled: When
handle_output_debug_string processes a Cygwin signal message, it re-writes
current_event.dwThreadId to reflect the thread that the signal will be delivered
to.

Subsequently, the call to ContinueDebugEvent will fail, because we're trying to
resume the wrong thread.  GDB is then stuck waiting forever for another event
that will never come.

This patch doesn't fix the problem, it just adds appropriate error handling.

Using error() seems appropriate here, if ContinueDebugEvent() fails, the
inferior is in an unknown state and we will probably not be debugging it
anymore.

With this patch applied, resuming the execution of the program now yields:

    $ ./gdb testsuite/outputs/gdb.base/catch-signal/catch-signal.exe
    [...]
    (gdb) catch signal
    Catchpoint 1 (standard signals)
    (gdb) r
    [...]
    Catchpoint 1 (signal SIGHUP), main () at
    ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    (gdb) c
    Continuing.
    main () at ../../../gdb/testsuite/gdb.base/catch-signal.c:40
    40        raise (SIGHUP);               /* second HUP */
    Failed to resume program execution (ContinueDebugEvent failed, error 87)
    (gdb)

gdb/ChangeLog:

2015-04-22  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (windows_continue): Report an error if
	ContinueDebugEvent() fails.
2015-04-22 19:40:11 +01:00
Jon Turney 23942819fc windows-nat: Fix misspelling in debug output
gdb/ChangeLog:

2015-04-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (windows_resume): Fix misspelling in debug output.
2015-04-22 18:30:56 +01:00
Jon Turney e6ad66bd09 windows-nat: Cleanups in get_windows_debug_event
gdb/ChangeLog:

2015-04-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (get_windows_debug_event): Replace retval with
	thread_id throughout.  Update stale comment.
2015-04-22 18:30:54 +01:00
Jon Turney 776704b917 windows-nat: Don't use ternary conditional operator in get_windows_debug_event
gdb/ChangeLog:

2015-04-16  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (get_windows_debug_event): Don't use ternary
	conditional operator.
2015-04-22 18:30:52 +01:00
Pierre Muller 8aae434443 Fix pascal behavior for class fields with testcase
Problem reported as PR pascal/17815

Part 1/3: Remember the case pattern that allowed finding a field of this.
File gdb/p-exp.y modified

  This is the fix in the pascal parser (p-exp.y),
to avoid the error that GDB does find normal variables
case insensitively, but not fields of this,
inside a class or object method.

Part 2/3: Add "class" option for pascal compiler
File gdb/testsuite/lib/pascal.exp

This part of the patch series is unchanged.
It adds class option to pascal compiler
which adds the required command line option to
accept pascal class types.

Part 3/3:
New file: gdb/testsuite/gdb.pascal/case-insensitive-symbols.exp
New file: gdb/testsuite/gdb.pascal/case-insensitive-symbols.pas

  Here is an updated version of this test, using Pedro's suggestions.
Test to check that PR 17815 is fixed.
2015-04-21 22:10:08 +02:00
Gary Benson 819843c702 Introduce new shared function fileio_to_host_openflags
This commit introduces a new shared function to replace identical
functions in GDB and gdbserver.
2015-04-21 12:09:24 +01:00
Kevin Buettner 0bca7f99d8 Extend rl78 prologue analyzer to recognize more complicated prologues
This patch extends the rl78 prologue analyzer so that it can recognize
this kind of prologue:

   0x119f <main>:       movw    ax, sp
   0x11a1 <main+2>:     subw    ax, #0x1fa6
   0x11a4 <main+5>:     movw    sp, ax

The test case for gdb.base/miscexprs.exp is now compiled to generate
that sequence instead of a much longer and more inefficient sequence.

gdb/ChangeLog:

	* rl78-tdep.c (RL78_SP_ADDR): Define.
	(opc_reg_to_gdb_regnum): New static function.
	(rl78_analyze_prologue): Recognize instructions forming slightly
	more interesting prologues.
2015-04-20 23:44:19 -07:00
Pierre-Marie de Rodat e771e4be13 Revert "Do not consider reference types as dynamic"
This reverts commit 961f416025.

Note that the revert is partial: it keeps the new testcases
gdb.ada/funcall_ref.exp.
2015-04-20 16:25:12 +02:00
Pierre-Marie de Rodat ee715b5a6c Revert "gdbtypes.c: remove the usuned "top_level" parameter"
This reverts commit 25755e2b85.
2015-04-20 16:25:12 +02:00
Gary Benson 1586c8fbaf Fix three test failures with extended remote targets
This commit fixes three gdb.base/attach.exp failures when using
extended remote targets.  The failures occurred because GDB now
locates and loads files when attaching on remote targets if the
remote target supports qXfer:exec-file:read; the filenames were
shown but with "target:" prefixes which the test has been updated
to handle.

gdb/testsuite/ChangeLog:

	* gdb.base/attach.exp: Fix three extended remote failures.
2015-04-20 11:36:02 +01:00
Gabriel Krisman Bertazi e31d7699a0 Remove duplicated xmalloc in update_dprintf_command_list
Code in update_dprintf_command_list performed a duplicated memory
allocation which caused an obvious memory leak.  This removes the
duplication.

gdb/
2015-04-19  Gabriel Krisman Bertazi  <gabriel@krisman.be>

	* breakpoint.c (update_dprintf_command_list): Remove duplicated
	xmalloc.
2015-04-19 20:07:33 -03:00
Thomas Schwinge 110f91128c [GDB] Hurd: Robustify the reply_mig_hack.awk script.
..., so that it also works with the GNU MIG 1.5 just released.

	gdb/
	* reply_mig_hack.awk: Robustify parsing.
2015-04-20 00:31:54 +02:00
Thomas Schwinge d214e5e79e [GDB] Hurd: Simplify the reply_mig_hack.awk script.
gdb/
	* reply_mig_hack.awk: Don't bother to declare an intermediate
	function pointer variable.

... allowing us to simplify the parsing a little bit.  And, instead of
"warning: initialization from incompatible pointer type", we now get "warning:
function called through a non-compatible type".  Oh well.
2015-04-20 00:22:32 +02:00
Doug Evans 8f61baf802 solib-svr4.c (svr4_exec_displacement): Rename outer "displacement".
gdb/ChangeLog:

	* solib-svr4.c (svr4_exec_displacement): Rename outer "displacement"
	to "exec_displacement" to avoid confusion with inner use of the name.
2015-04-17 10:57:45 -07:00
Max Filippov a2d5a9d76f gdbserver/xtensa: fix typo in XCHAL_HAVE_LOOPS
This fixes lbeg/lend/lcount registers handling through gdbserver.

2015-04-17  Max Filippov  <jcmvbkbc@gmail.com>
gdb/gdbserver/
	* linux-xtensa-low.c (xtensa_fill_gregset)
	(xtensa_store_gregset): Check XCHAL_HAVE_LOOPS instead of
	XCHAL_HAVE_LOOP.
2015-04-17 17:19:48 +03:00
Max Filippov deb44829ec gdbserver/xtensa: drop xtensa_usrregs_info
xtensa_usrregs_info refers to undefined variables xtensa_num_regs and
xtensa_regmap. Drop xtensa_usrregs_info and replace pointer to usrregs
in regs_info with NULL since all registers are read/set through regsets.

2015-04-17  Max Filippov  <jcmvbkbc@gmail.com>
gdb/gdbserver/
	* linux-xtensa-low.c (xtensa_usrregs_info): Remove.
	(regs_info): Replace usrregs pointer with NULL.
2015-04-17 17:18:43 +03:00
Yao Qi dbbf180a81 return zero in arm_linux_can_use_hw_breakpoint if HW point isn't supported
This patch is to cherry-pick part of Pedro's patch here
https://sourceware.org/ml/gdb-patches/2015-04/msg00527.html in which
zero is returned if the HW point isn't supported.

In arm-linux native gdb testing on a board doesn't support HW breakpoint,
without this patch, the output in gdb.base/breakpoint-in-ro-region.exp is like:

(gdb) hbreak *0x83bc^M
Hardware breakpoints used exceeds limit.^M
(gdb) PASS: gdb.base/breakpoint-in-ro-region.exp: probe hbreak support (support)

with this patch, the output becomes:

(gdb) hbreak *0x83bc^M
No hardware breakpoint support in the target.^M
(gdb) PASS: gdb.base/breakpoint-in-ro-region.exp: probe hbreak support (no support)

As a result, the following fails are fixed.

-FAIL: gdb.base/breakpoint-in-ro-region.exp: always-inserted off: auto-hw on: step in ro region (cannot insert hw break)
-FAIL: gdb.base/breakpoint-in-ro-region.exp: always-inserted off: auto-hw on: thread advanced
-FAIL: gdb.base/breakpoint-in-ro-region.exp: always-inserted on: auto-hw on: step in ro region (cannot insert hw break)
-FAIL: gdb.base/breakpoint-in-ro-region.exp: always-inserted on: auto-hw on: thread advanced

gdb:

2015-04-17  Pedro Alves  <palves@redhat.com>

	* arm-linux-nat.c (arm_linux_can_use_hw_breakpoint): Return zero
	if HW point of TYPE isn't supported.
2015-04-17 13:52:44 +01:00
Yao Qi 059790a0c8 Update comments to target_can_use_hardware_watchpoint
The return value of target_can_use_hardware_watchpoint isn't well
documented, so this patch is to update the comments to reflect the
fact.  This patch also removes a trailing ";" which is picked up
from Pedro's patch https://sourceware.org/ml/gdb-patches/2015-04/msg00527.html

gdb:

2015-04-17  Yao Qi  <yao.qi@linaro.org>
	    Pedro Alves  <palves@redhat.com>

	* target.h (target_can_use_hardware_watchpoint): Update comments.
	Remove trailing ";".
2015-04-17 13:46:24 +01:00
Gary Benson 1b6e6f5c7f Access executable from remote system when first inferior appears
This commit modifies remote_add_inferior to take an extra argument
try_open_exec.  If this is nonzero, remote_add_inferior will attempt
to open this inferior's executable as the main executable if no main
executable is open already.  Callers are updated appropriately.

With this commit, remote debugging can now be initiated using only a
"target remote" or "target extended-remote" command; no "set sysroot"
or "file" commands are required, e.g.

  bash$ gdb -q
  (gdb) target remote | gdbserver - /bin/sh
  Remote debugging using | gdbserver - /bin/sh
  Process /bin/sh created; pid = 32166
  stdin/stdout redirected
  Remote debugging using stdio
  Reading symbols from target:/bin/bash...

One testcase required updating as a result of this commit.  The test
checked that GDB's "info files" command does not crash if no main
executable is open, and relied on GDB's inability to access the main
executable over the remote protocol.  The test was updated to inhibit
this new behavior.

gdb/ChangeLog:

	* remote.c (remote_add_inferior): New argument try_open_exec.
	If nonzero, attempt to open the inferior's executable file as
	the main executable if no main executable is open already.
	All callers updated.
	* NEWS: Mention that GDB now supports automatic location and
	retrieval of executable + files from remote targets.

gdb/doc/ChangeLog:

	* gdb.texinfo (Connecting to a Remote Target): Mention that
	GDB can access program files from remote targets that support
	qXfer:exec-file:read and Host I/O packets.

gdb/testsuite/ChangeLog:

	* gdb.server/server-exec-info.exp: Inhibit GDB from accessing
	the main executable over the remote protocol.
2015-04-17 09:47:30 +01:00
Gary Benson e57f1de3b3 Implement qXfer:exec-file:read in gdbserver
This commit implements the "qXfer:exec-file:read" packet in gdbserver.

gdb/gdbserver/ChangeLog:

	* target.h (struct target_ops) <pid_to_exec_file>: New field.
	* linux-low.c (linux_target_ops): Initialize pid_to_exec_file.
	* server.c (handle_qxfer_exec_file): New function.
	(qxfer_packets): Add exec-file entry.
	(handle_query): Report qXfer:exec-file:read as supported packet.
2015-04-17 09:47:30 +01:00
Gary Benson c78fa86a21 Implement remote_pid_to_exec_file using qXfer:exec-file:read
This commit adds a new packet "qXfer:exec-file:read" to the remote
protocol that can be used to obtain the pathname of the file that
was executed to create a process on the remote system.  Support for
this packet is added to GDB and remote_ops.to_pid_to_exec_file is
implemented using it.

gdb/ChangeLog:

	* target.h (TARGET_OBJECT_EXEC_FILE): New enum value.
	* remote.c (PACKET_qXfer_exec_file): Likewise.
	(remote_protocol_features): Register the
	"qXfer:exec-file:read" feature.
	(remote_xfer_partial): Handle TARGET_OBJECT_EXEC_FILE.
	(remote_pid_to_exec_file): New function.
	(init_remote_ops): Initialize to_pid_to_exec_file.
	(_initialize_remote): Register new "set/show remote
	pid-to-exec-file-packet" command.
	* NEWS: Announce new qXfer:exec-file:read packet.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote pid-to-exec-file-packet" command.
	(General Query Packets): Document the qXfer:exec-file:read
	qSupported features.  Document the qXfer:exec-file:read packet.
2015-04-17 09:47:30 +01:00
Gary Benson e0d86d2cbd Introduce linux_proc_pid_to_exec_file
This commit introduces a new function linux_proc_pid_to_exec_file
that shared Linux code can use to discover the filename of the
executable that was run to create a process on the system.

gdb/ChangeLog:

	* nat/linux-procfs.h (linux_proc_pid_to_exec_file):
	New declaration.
	* nat/linux-procfs.c (linux_proc_pid_to_exec_file):
	New function, factored out from...
	* linux-nat.c (linux_child_pid_to_exec_file): ...here.
2015-04-17 09:47:30 +01:00
Gary Benson a9a5a3d1d2 Use gdb_sysroot for main executable on attach
This commit updates exec_file_locate_attach to use exec_file_find
to compute the full pathname of the main executable in some cases.
The net effect of this is that the main executable's path will be
prefixed with gdb_sysroot in the same way that shared library paths
currently are.

gdb/ChangeLog:

	* exec.c (solist.h): New include.
	(exec_file_locate_attach): Prefix absolute executable
	paths with gdb_sysroot if set.
	* NEWS: Mention that executable paths may be prepended
	with sysroot.

gdb/doc/ChangeLog:

	* gdb.texinfo (set sysroot): Document that "set sysroot" also
	applies to executable paths if supplied to GDB as absolute.
2015-04-17 09:47:30 +01:00
Gary Benson af1900b01b Introduce exec_file_find
This commit adds a new function, exec_file_find, which computes the
full pathname of the main executable in much the same way solib_find
does for pathnames of shared libraries.  The bulk of the existing
solib_find was moved into a new static function solib_find_1, with
exec_file_find and solib_find being small wrappers for solib_find_1.

gdb/ChangeLog:

	* solist.h (exec_file_find): New declaration.
	* solib.c (solib_find_1): New function, factored out from...
	(solib_find): ...here.
	(exec_file_find): New function.
2015-04-17 09:47:30 +01:00
Gary Benson a10de6046f Introduce exec_file_locate_attach
This commit adds a new function, exec_file_locate_attach, which works
like exec_file_attach except that, instead of a filename argument, it
takes an integer process ID and attempts to determine the executable
filename from that.

gdb/ChangeLog:

	* gdbcore.h (exec_file_locate_attach): New declaration.
	* exec.c (exec_file_locate_attach): New function, factored
	out from...
	* infcmd.c (attach_command_post_wait): ...here.
2015-04-17 09:47:30 +01:00
Mike Frysinger 92209ddfdc gdb: add myself to blackfin/write-after-approval 2015-04-17 03:20:49 -04:00
Pedro Alves e797481d53 Fix {mi-tracepoint-changed, mi-tsv-changed}.exp with native-extended-gdbserver
Fixes:

 -FAIL: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint created
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint on marker is installed
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1


 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

These tests do something like this:

 #0 - start gdb/gdbserver normally
 #1 - setup some things in the debug session
 #2 - disconnect from gdbserver
 #3 - restart gdb
 #4 - reconnect to gdbserver

The problem is that the native-extended-gdbserver board always spawns
a new gdbserver instance in #3 (and has gdb connect to that).  So when
the test gets to #4, it connects to that new instance instead of the
old one:

 (gdb) spawn ../gdbserver/gdbserver --multi :2354
 Listening on port 2354
 target extended-remote localhost:2354
 Remote debugging using localhost:2354
 ...
 spawn ../gdbserver/gdbserver --multi :2355
 Listening on port 2355
 47-target-select extended-remote localhost:2355
 =tsv-created,name="trace_timestamp",initial="0"\n
 47^connected
 (gdb)
 ...
 47-target-select extended-remote localhost:2355
 47^connected
 (gdb)
 FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

testsuite/ChangeLog:
2015-04-16  Pedro Alves  <palves@redhat.com>

	* boards/native-extended-gdbserver.exp (mi_gdb_start): Don't start
	a new gdbserver if gdbserver_reconnect_p is set.
2015-04-16 14:36:52 +01:00
Pedro Alves 1ca99c4299 Fix gdbserver_reconnect_p handling
Commit 6423214f (testsuite: Don't use expect_background to reap
gdbserver) broke a couple tests that set gdbserver_reconnect_p and
restart gdb before reconnecting, because a gdb_exit (e.g., through
clean_restart) exits gdbserver unconditionally.

Fixes, with --target_board=native-gdbserver:

 -FAIL: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint created
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: tracepoint on marker is installed
 +PASS: gdb.trace/mi-tracepoint-changed.exp: reconnect: break-info 1

 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 -FAIL: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv1 created
 +PASS: gdb.trace/mi-tsv-changed.exp: upload: tsv2 created

gdb/testsuite/
2015-04-16  Pedro Alves  <palves@redhat.com>

	* lib/gdbserver-support.exp (gdb_exit): If gdbserver_reconnect_p
	is set, don't exit gdbserver.
2015-04-16 14:26:59 +01:00
Yao Qi 8550d3b32f Honour software single step in fallback of displaced stepping
Hi,
When I run gdb.threads/non-stop-fair-events.exp on arm-linux target,
I see the following message in the debugging log,

  displaced: breakpoint is gone: Thread 22518, step(1)^M
  Sending packet: $vCont;s:p57f3.57f6#9d...
                  ^^^^^^^^^
GDB sends vCont;s by mistake, and GDBserver fails on assert.  GDB
doesn't consider software single step in infrun.c:displaced_step_fixup,

	  /* Go back to what we were trying to do.  */
	  step = currently_stepping (tp);

	  if (debug_displaced)
	    fprintf_unfiltered (gdb_stdlog,
				"displaced: breakpoint is gone: %s, step(%d)\n",
				target_pid_to_str (tp->ptid), step);

	  target_resume (ptid, step, GDB_SIGNAL_0);

The patch is to let GDB consider software single step here.  It fixes
fails in gdb.threads/non-stop-fair-events.exp on arm.

gdb:

2015-04-16  Yao Qi  <yao.qi@linaro.org>

	* infrun.c (maybe_software_singlestep): Declare.
	(displaced_step_fixup): Call maybe_software_singlestep.
2015-04-16 13:48:10 +01:00
Andreas Arnez af9fd6f863 s390-vregs.exp: Avoid compile errors with older GCCs and on 31-bit targets
The test case s390-vregs.exp yields compile errors on 31-bit targets
as well as when using a GCC that defaults to an older "-march=".  This
patch fixes these issues.

gdb/testsuite/ChangeLog:

	* gdb.arch/s390-vregs.S (change_vrs): Replace exrl by an
	appropriate .insn, such that an older assembler can be used.
	* gdb.arch/s390-vregs.exp: Add the compile flag -mzarch, to enable
	the z/Architecture instruction set on 31-bit targets as well.
2015-04-16 13:03:48 +02:00
Andreas Arnez 04ff1e612e GDB tests for Go language support: remove unnecessary first breakpoint
On s390x targets some of the Go test cases fail because the first
breakpoint happens to be at the same spot as the breakpoint at
main.main.  When such a test case tries to continue to the first
breakpoint, the program runs until the end instead, and the test fails
like this:

FAIL: gdb.go/handcall.exp: Going to first breakpoint (the program exited)

This patch removes all the handling related to the first breakpoint in
those cases.  After applying the patch, the tests run successfully on
s390x.

gdb/testsuite/ChangeLog:

	* gdb.go/handcall.exp: Remove all logic related to the first
	breakpoint and rely on go_runto_main instead.
	* gdb.go/strings.exp: Likewise.
	* gdb.go/unsafe.exp: Likewise.
	* gdb.go/hello.exp: Likewise.  Also rename the remaining
	breakpoint marker to "breakpoint 1".
	* gdb.go/handcall.go: Remove comment "set breakpoint 1 here".
	* gdb.go/strings.go: Likewise.
	* gdb.go/unsafe.go: Likewise.
	* gdb.go/hello.go: Likewise.  Also remove the second occurrence of
	"set breakpoint 2 here" and rename the remaining breakpoint marker
	to "breakpoint 1".
2015-04-16 13:03:47 +02:00
Doug Evans 30b3dd9d47 Make info fun|var|types interruptable for psyms.
gdb/ChangeLog:

	* psymtab.c (psym_expand_symtabs_matching): Add QUIT call.
2015-04-15 14:04:35 -07:00
Doug Evans 61d96d7e2e Make info fun|var|types interruptable.
"info fun foo" can be a pain when it's not interruptable,
especially if you're not exactly sure of what you're looking for
and provide something that matches too much.

gdb/ChangeLog:

	* dwarf2read.c (dw2_expand_symtabs_matching): Add some QUIT calls.
2015-04-15 13:25:42 -07:00
Romain Naour 6282837972 gdbserver: fix uClibc build whithout MMU.
Since commit d86d4aafd4, the pid
must be retrieved from current_thread.

The change has not been made in the function linux_read_offsets().

Fixes:
http://autobuild.buildroot.net/results/9e4/9e4df085319e346803c26c65478accb27eb950ae/build-end.log

2015-04-14  Romain Naour <romain.naour@openwide.fr>  (tiny change)

	* linux-low.c (linux_read_offsets): Remove get_thread_lwp.

Signed-off-by: Romain Naour <romain.naour@openwide.fr>
2015-04-15 16:59:47 +01:00
Simon Marchi 40d2f8d62e Some Python 3 fixes
Some missing parentheses and one itertools.imap (Py2) vs map (Py3) issue.

gdb/ChangeLog:

	* python/lib/gdb/command/unwinders.py: Add parentheses.

gdb/testsuite/ChangeLog:

	* gdb.python/py-framefilter.py (ErrorFilter.filter): Use map function
	if itertools.imap is not present.
	* gdb.python/py-objfile.exp: Add parentheses.
	* gdb.python/py-type.exp: Same.
	* gdb.python/py-unwind-maint.py: Same.
2015-04-15 11:54:33 -04:00
Yao Qi 6bbbba9ba5 [arm] Update displaced stepping debug message
When I "set debug displaced 1" to fix fail in
gdb.base/disp-step-syscall.exp, the debug message is wrong.  This
patch is to fix it.

gdb:

2015-04-15  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-tdep.c (arm_linux_copy_svc): Update debug message.
2015-04-15 15:28:17 +01:00
Yao Qi 2bb2dcab45 Fix code indentation
gdb:

2015-04-15  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-tdep.c (arm_linux_copy_svc): Fix indentation.
2015-04-15 15:28:12 +01:00
Yao Qi 41f071ef33 [arm] Fix fails in gdb.base/disp-step-syscall.exp
Hi,
I see this fail on arm-linux target,

 FAIL: gdb.base/disp-step-syscall.exp: fork: single step over fork final pc

which is caused by the PC isn't expected after displaced stepping the
svc instruction.  The code is:

=> 0xb6ead9a4 <__libc_do_syscall+4>:    svc     0
   0xb6ead9a6 <__libc_do_syscall+6>:    pop     {r7, pc}
   0xb6ead9a8:  nop.w^M
   0xb6ead9ac:  nop.w

after single step svc instruction, pc should be 0xb6ead9a6, but the
actual value of pc is 0xb6ead9a8.  The problem is illustrated by
turning on debug message of displaced stepping,

stepi^M
displaced: stepping Thread 12031 now^M
displaced: saved 0x8574: 02 bc 6a 46 04 b4 01 b4 df f8 10 c0 4d f8 04 cd 03 48 04 4b ff f7 d2 ef ff f7 e8 ef 0d 87 00 00 ^M
displaced: process thumb insn df00 at b6ead9a4^M
displaced: copying svc insn df00^M
displaced: read r7 value 00000078^M
displaced: sigreturn/rt_sigreturn SVC call not in signal trampoline frame^M
displaced: writing insn df00 at 00008574^M
displaced: copy 0xb6ead9a4->0x8574: displaced: check mode of b6ead9a4 instead of 00008574^M
displaced: displaced pc to 0x8574^M
displaced: run 0x8574: 00 df 01 de ^M
displaced: restored Thread 12031 0x8574^M
displaced: PC is apparently 00008576 after SVC step (within scratch space)^M
displaced: writing pc b6ead9a8  <----- WRONG ADDRESS

GDB writes the wrong address back to pc because GDB thinks the
instruction size is 4, which isn't true for thumb instruction.
This patch is to replace 4 with dsc->insn_size.

gdb:

2015-04-15  Yao Qi  <yao.qi@linaro.org>

	* arm-linux-tdep.c (arm_linux_cleanup_svc): Use
	dsc->insn_size instead of 4.
2015-04-15 15:14:37 +01:00
Yao Qi 8cbc97c629 Fix fails in gdb.dwarf2/dynarr-ptr.exp
I see many fails in gdb.dwarf2/dynarr-ptr.exp on arm-linux target,
started from this

print foo.three_ptr.all^M
Cannot access memory at address 0x107c8^M
(gdb) FAIL: gdb.dwarf2/dynarr-ptr.exp: print foo.three_ptr.all
print foo.three_ptr.all(1)^M
Cannot access memory at address 0x107c8

It turns out that ":$ptr_size" is used incorrectly.

             array_ptr_label: DW_TAG_pointer_type {
                 {DW_AT_byte_size :$ptr_size }
                                  ^^^^^^^^^^
                 {DW_AT_type :$array_label}
             }

Since the FORM isn't given, and it starts with the ":", it is regarded
as a label reference by dwarf assembler.  The generated asm file on
x86_64 is

        .uleb128        6               /* Abbrev (DW_TAG_pointer_type) */
        .4byte        8 - .Lcu1_begin   <----- WRONG
        .4byte        .Llabel2 - .Lcu1_begin

Looks .Lcu1_begin is 0 on x86_64 and that is why this test passes on
x86_64.  On arm, .Lcu1_begin is an address somewhere, and the value
of DW_AT_byte_size is a very large number, so memory read request
of such large length failed.

This patch is to remove ":" and set the form explicitly.  The generated
asm file on x86_64 becomes

        .uleb128        6               /* Abbrev (DW_TAG_pointer_type) */
        .byte        8
        .4byte        .Llabel2 - .Lcu1_begin

gdb/testsuite:

2015-04-15  Yao Qi  <yao.qi@linaro.org>

	* gdb.dwarf2/dynarr-ptr.exp (assemble): Use $ptr_size instead
	of ":$ptr_size" and set its form explicitly.
2015-04-15 14:05:07 +01:00
Yao Qi 45fd756caf Increase timeout in watch-bitfields.exp for software watchpoint
I see the following two timeout fails on pandaboard (arm-linux target),

 FAIL: gdb.base/watch-bitfields.exp: -location watch against bitfields: continue until exit (timeout)
 FAIL: gdb.base/watch-bitfields.exp: regular watch against bitfields: continue until exit (timeout)

In this test, more than one watchpoint is used, so the following
watchpoint requests fall back to software watchpoint, so that GDB
will single step all the way and it is very slow.

This patch is to copy the fix from

  [PATCH] GDB/testsuite: Correct gdb.base/watchpoint-solib.exp timeout tweak
  https://sourceware.org/ml/gdb-patches/2014-07/msg00716.html

I find the left-over of this patch review is to factor out code into
a procedure, so I do that in this patch.

Re-run tests watch-bitfields.exp, watchpoint-solib.exp, sigall-reverse.exp,
and until-precsave.exp on pandaboard, no regression.

gdb/testsuite:

2015-04-15  Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao.qi@linaro.org>

	* gdb.base/watch-bitfields.exp (test_watch_location): Increase
	timeout by factor of 4.
	(test_regular_watch): Likewise.
	* gdb.base/watchpoint-solib.exp: Use with_timeout_factor.
	* gdb.reverse/sigall-reverse.exp: Likewise.
	* gdb.reverse/until-precsave.exp: Likewise.
	* lib/gdb.exp (with_timeout_factor): New proc.
	(gdb_expect): Move some code to ...
	(get_largest_timeout): ... here.  New procedure.
2015-04-15 12:46:58 +01:00
Luis Machado 9e811bc379 Harden gdb.base/bp-permanent.exp
Reinstate test message and replace hardcoded test command with a variable.

gdb/testsuite/ChangeLog:
2015-04-14  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/bp-permanent.exp (test): Reinstate correct test message.
2015-04-14 09:25:27 -03:00
Gary Benson 326a5c7e36 Zero supplied stat buffers in functions that pretend to stat
GDB has five places where it pretends to stat for bfd_openr_iovec.
Four of these only set the incoming buffer's st_size, leaving the
other fields unchanged, which is to say very likely populated with
random values from the stack.  remote_bfd_iovec_stat was fixed in
0a93529c56714b1da3d7106d3e0300764f8bb81c; this commit fixes the
other four.

gdb/ChangeLog:

	* jit.c (mem_bfd_iovec_stat): Zero supplied buffer.
	* minidebug.c (lzma_stat): Likewise.
	* solib-spu.c (spu_bfd_iovec_stat): Likewise.
	* spu-linux-nat.c (spu_bfd_iovec_stat): Likewise.
2015-04-14 12:35:30 +01:00
Stan Shebs dd177e81b4 * MAINTAINERS: Update my email address.
diff --git a/gdb/MAINTAINERS b/gdb/MAINTAINERS
index a67a1a8..0fdd8e5 100644
--- a/gdb/MAINTAINERS
+++ b/gdb/MAINTAINERS
@@ -156,7 +156,7 @@ Doug Evans                  dje@google.com
 Daniel Jacobowitz              drow@false.org
 Mark Kettenis                  kettenis@gnu.org
 Yao Qi                         yao.qi@arm.com
-Stan Shebs                     stan@codesourcery.com
+Stan Shebs                     stanshebs@google.com
 Ulrich Weigand                 Ulrich.Weigand@de.ibm.com
 Elena Zannoni                  elena.zannoni@oracle.com
 Eli Zaretskii                  eliz@gnu.org
@@ -631,7 +631,7 @@ Keith Seitz                                 keiths@redhat.com
 Carlos Eduardo Seo                             cseo@linux.vnet.ibm.com
 Ozkan Sezer                                    sezeroz@gmail.com
 Marcus Shawcroft                               marcus.shawcroft@arm.com
-Stan Shebs                                     stan@codesourcery.com
+Stan Shebs                                     stanshebs@google.com
 Joel Sherrill                                  joel.sherrill@oarcorp.com
 Mark Shinwell                                  shinwell@codesourcery.com
 Craig Silverstein                              csilvers@google.com
2015-04-13 14:21:47 -07:00
John Baldwin 97de3545ca Add support for the x86 XSAVE extended state on FreeBSD/x86.
Recognize NT_X86_XSTATE notes in FreeBSD process cores.  Recent
FreeBSD versions include a note containing the XSAVE state for each
thread in the process when XSAVE is in use.  The note stores a copy of
the current XSAVE mask in a reserved section of the machine-defined
XSAVE state at the same offset as Linux's NT_X86_XSTATE note.

For native processes, use the PT_GETXSTATE_INFO ptrace request to
determine if XSAVE is enabled, and if so the active XSAVE state mask
(that is, the value of %xcr0 for the target process) as well as the
size of XSAVE state area.  Use the PT_GETXSTATE and PT_SETXSTATE requests
to fetch and store the XSAVE state, respectively, in the BSD x86
native targets.

In addition, the FreeBSD amd64 and i386 native targets now include
"read_description" target methods to determine the correct x86 target
description for the current XSAVE mask.  On FreeBSD amd64 this also
properly returns an i386 target description for 32-bit binaries which
allows the 64-bit GDB to run 32-bit binaries.

Note that the ptrace changes are in the BSD native targets, not the
FreeBSD-specific native targets since that is where the other ptrace
register accesses occur.  Of the other BSDs, NetBSD and DragonFly use
XSAVE in the kernel but do not currently export the extended state via
ptrace(2).  OpenBSD does not currently support XSAVE.

bfd/ChangeLog:

	* elf.c (elfcore_grok_note): Recognize NT_X86_XSTATE on
	FreeBSD.
	(elfcore_write_xstatereg): Use correct note name on FreeBSD.

gdb/ChangeLog:

	* amd64-tdep.c (amd64_target_description): New function.
	* amd64-tdep.h: Export amd64_target_description and tdesc_amd64.
	* amd64bsd-nat.c [PT_GETXSTATE_INFO]: New variable amd64bsd_xsave_len.
	(amd64bsd_fetch_inferior_registers) [PT_GETXSTATE_INFO]: Handle
	x86 extended save area.
	(amd64bsd_store_inferior_registers) [PT_GETXSTATE_INFO]: Likewise.
	* amd64bsd-nat.h: Export amd64bsd_xsave_len.
	* amd64fbsd-nat.c (amd64fbsd_read_description): New function.
	(_initialize_amd64fbsd_nat): Set "to_read_description" to
	"amd64fbsd_read_description".
	* amd64fbsd-tdep.c (amd64fbsd_core_read_description): New function.
	(amd64fbsd_supply_xstateregset): New function.
	(amd64fbsd_collect_xstateregset): New function.
	Add "amd64fbsd_xstateregset".
	(amd64fbsd_iterate_over_regset_sections): New function.
	(amd64fbsd_init_abi): Set "xsave_xcr0_offset" to
	"I386_FBSD_XSAVE_XCR0_OFFSET".
	Add "iterate_over_regset_sections" gdbarch method.
	Add "core_read_description" gdbarch method.
	* i386-tdep.c (i386_target_description): New function.
	* i386-tdep.h: Export i386_target_description and tdesc_i386.
	* i386bsd-nat.c [PT_GETXSTATE_INFO]: New variable i386bsd_xsave_len.
	(i386bsd_fetch_inferior_registers) [PT_GETXSTATE_INFO]: Handle
	x86 extended save area.
	(i386bsd_store_inferior_registers) [PT_GETXSTATE_INFO]: Likewise.
	* i386bsd-nat.h: Export i386bsd_xsave_len.
	* i386fbsd-nat.c (i386fbsd_read_description): New function.
	(_initialize_i386fbsd_nat): Set "to_read_description" to
	"i386fbsd_read_description".
	* i386fbsd-tdep.c (i386fbsd_core_read_xcr0): New function.
	(i386fbsd_core_read_description): New function.
	(i386fbsd_supply_xstateregset): New function.
	(i386fbsd_collect_xstateregset): New function.
	Add "i386fbsd_xstateregset".
	(i386fbsd_iterate_over_regset_sections): New function.
	(i386fbsd4_init_abi): Set "xsave_xcr0_offset" to
	"I386_FBSD_XSAVE_XCR0_OFFSET".
	Add "iterate_over_regset_sections" gdbarch method.
	Add "core_read_description" gdbarch method.
	* i386fbsd-tdep.h: New file.
2015-04-13 16:07:01 -04:00
Luis Machado 0ff6fcb2f0 Harden gdb.base/bp-permanent.exp
This testcase does not work as expected in QEMU (aarch64 QEMU in my case). It
fails when trying to manually write the breakpoint instruction to a certain
PC address.

(gdb) p /x addr_bp[0] = buffer[0]^M
Cannot access memory at address 0x400834^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[0] = buffer[0]
p /x addr_bp[1] = buffer[1]^M
Cannot access memory at address 0x400835^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[1] = buffer[1]
p /x addr_bp[2] = buffer[2]^M
Cannot access memory at address 0x400836^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[2] = buffer[2]
p /x addr_bp[3] = buffer[3]^M
Cannot access memory at address 0x400837^M
(gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[3] = buffer[3]

The following patch prevents a number of failures by detecting this and bailing out in case the target has such a restriction. Writing to .text from within the program isn't any better. It just leads to a SIGSEGV.

Before the patch:

                === gdb Summary ===

After the patch:

                === gdb Summary ===

gdb/testsuite/ChangeLog:
2015-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/bp-permanent.exp (test): Handle the case of being unable
	to write to the .text section.
2015-04-13 14:45:56 -03:00
Luis Machado 7578d5f72c Harden gdb.base/coredump-filter.exp
This testcase seems to assume the target is running Linux, so bare metal,
simulators and other debugging stubs running different OS' will have a
hard time executing some of the commands the testcase issues.

Even restricting the testcase to Linux systems (which the patch below does),
there are still problems with, say, QEMU not providing PID information when
"info inferior" is issued. As a consequence, the subsequent tests will either
fail or will not make much sense.

The attached patch checks if PID information is available. If not, it just
bails out and avoids running into a number of failures.

gdb/testsuite/ChangeLog:
2015-04-13  Luis Machado  <lgustavo@codesourcery.com>

	* gdb.base/coredump-filter.exp: Restrict test to Linux systems only.
	Handle the case of targets that do not provide PID information.
2015-04-13 14:42:48 -03:00
Yao Qi 2efe15c428 Catch exception in lib/gdbserver-support.exp:gdb_exit
I see the error when I run gdb-sigterm.exp with native-gdbserver
on x86_64-linux.

infrun: prepare_to_wait^M
Cannot execute this command while the target is running.^M
Use the "interrupt" command to stop the target^M
and then try again.^M
gdb.base/gdb-sigterm.exp: expect eof #0: got eof
gdb.base/gdb-sigterm.exp: expect eof #0: stepped 12 times
ERROR OCCURED: : spawn id exp8 not open
    while executing
"expect {
-i exp8 -timeout 10
            -re "$gdb_prompt $" {
                exp_continue
            }
            -i "$server_spawn_id" eof {
                wait -i $expect_out(spawn_id)
                unse..."
    ("uplevel" body line 1)
    invoked from within

In gdb-sigterm.exp, SIGTERM is sent to GDB and it exits.  However,
Dejagnu or tcl doesn't know this.

This patch is to catch the exception, but error messages are still
shown in the console and gdb.log.  In order to avoid this, we also
replace gdb_expect with expect.

gdb/testsuite:

2015-04-13  Yao Qi  <yao.qi@linaro.org>

	* lib/gdbserver-support.exp (gdb_exit): Catch exception
	and use expect instead of gdb_expect.
2015-04-13 15:46:11 +01:00
Sergio Durigan Junior 8cd8f2f8ac Rename variable "addr" to "coredump_var_addr" in gdb.base/coredump-filter.exp
This commit renames the global array variable "addr" to an unique name
"coredump_var_addr" in the test gdb.base/coredump-filter.exp.  This is
needed because global arrays can have name conflicts between tests.
For example, this specific test was conflicting with dmsym.exp,
causing errors like:

  ERROR: tcl error sourcing ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp.
  ERROR: can't set "addr": variable is array
      while executing
  "set addr "0x\[0-9a-zA-Z\]+""
      (file "../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp" line 45)
      invoked from within
  "source ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp"
      ("uplevel" body line 1)
      invoked from within
  "uplevel #0 source ../../../../../binutils-gdb/gdb/testsuite/gdb.base/dmsym.exp"
      invoked from within
  "catch "uplevel #0 source $test_file_name""

This problem was reported by Yao Qi at:

  <https://sourceware.org/ml/gdb-patches/2015-04/msg00373.html>
  Message-Id: <1428666671-12926-1-git-send-email-qiyaoltc@gmail.com>

gdb/testsuite/ChangeLog:
2015-04-13  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/coredump-filter.exp: Rename variable "addr" to
	"coredump_var_addr" to avoid naming conflict with other testcases.
2015-04-13 02:45:16 -04:00