Commit Graph

40336 Commits

Author SHA1 Message Date
Uros Bizjak 27e9ff87a6 Remove write-only assignment in rs6000-tdep.c
The result of this memory read is never used, so it can be removed.

gdb/ChangeLog:

	* rs6000-tdep.c (ppc_deal_with_atomic_sequence): Remove
	write-only assignment to "insn" variable.
2017-12-20 20:42:21 -05:00
Ulrich Weigand 396d3980f5 [Cell/B.E.] Fix regression due to gdbarch_significant_addr_bit
On Cell/B.E. multi-architecture debugging we use a "merged" address space
that encodes both the main PowerPC address space and the local store address
spaces of all active SPUs.  This will always occupy 64 bits.

However, gdbarch_addr_bit is set to 32 on SPU, and may be set to 32 as well
on PowerPC.  Since the new gdbarch_significant_addr_bit defaults to the
value of gdbarch_addr_bit, this means addresses may be improperly truncated.

Work around this problem by explicitly setting gdbarch_significant_addr_bit
to 64 both for the SPU target and also for PowerPC target that support
Cell/B.E. execution.

gdb/ChangeLog:
2017-12-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* spu-tdep.c (spu_gdbarch_init): Set set_gdbarch_significant_addr_bit
	to 64 bits.
	(ppc_linux_init_abi): Likewise, if Cell/B.E. is supported.
2017-12-20 13:59:14 +01:00
Simon Marchi 175654b9cd Fix ChangeLog formatting
Doing some unrelated grepping found that there were some missing
spaces, fix it.
2017-12-19 22:12:58 -05:00
Joel Brobecker eccab96d54 improved error message when getting an exception printing a variable
Consider the following Ada code defining a global variable whose
type is an array of static bounds (1 .. 2), but where its elements
are a variant record whose size is not statically known:

    type Ints is array (Natural range <>) of Integer;
    type Bounded_Ints (Max_Size : Natural) is record
       Length : Natural := 0;
       Objs   : Ints (1 .. Max_Size);
    end record;

    type Ints_Doubled is array (1 .. 2) of Bounded_Ints (Idem (0));

    Global : Ints_Doubled;

When compiling this program at -O2 using a GCC-6.4-based compiler
on x86_64-linux, trying to print the value of that global variable
yields:

    (gdb) p global
    $1 =

Let's look at the debugging info, which starts with the global
variable itself...

        .uleb128 0x19   # (DIE (0x25e) DW_TAG_variable)
        .long   .LASF32 # DW_AT_name: "fd__global"
        .long   0x273   # DW_AT_type

... its type is a reference to a typedef ...

        .uleb128 0x14   # (DIE (0x273) DW_TAG_reference_type)
        .byte   0x8     # DW_AT_byte_size
        .long   0x202   # DW_AT_type
        [...]
        .uleb128 0x15   # (DIE (0x202) DW_TAG_typedef)
        .long   .LASF19 # DW_AT_name: "fd__ints_doubled"
        .long   0x20d   # DW_AT_type

... of an array (1..2) ...

        .uleb128 0x2    # (DIE (0x20d) DW_TAG_array_type)
        .long   .LASF19 # DW_AT_name: "fd__ints_doubled"
        .long   0x15b   # DW_AT_type
        .long   0x221   # DW_AT_sibling
        .uleb128 0x16   # (DIE (0x21a) DW_TAG_subrange_type)
        .long   0x40    # DW_AT_type
        .sleb128 2      # DW_AT_upper_bound
        .byte   0       # end of children of DIE 0x20d

... of a struct whose name is fd__Tints_doubledC:

        .uleb128 0x10   # (DIE (0x15b) DW_TAG_structure_type)
        .long   .LASF11 # DW_AT_name: "fd__Tints_doubledC"
        .long   0x1e4   # DW_AT_GNAT_descriptive_type
                        # DW_AT_artificial
        .long   0x1e4   # DW_AT_sibling
        .uleb128 0x7    # (DIE (0x16a) DW_TAG_member)
        .long   .LASF4  # DW_AT_name: "max_size"
        [snip]

The error occurs while Ada evaluator is trying to "fix"
the element type inside the array, so as to determine its actual
size. For that, it searches for a parallel "XVZ" variable,
which, when found, contains the object's actual size.

Unfortunately in our case, the variable exists but has been
optimized out, as seen by the presence of a variable DIE in
the debugging info, but with no address attribute:

        .uleb128 0x18   # (DIE (0x24e) DW_TAG_variable)
        .long   .LASF31 # DW_AT_name: "fd__Tints_doubledC___XVZ"
        .long   0x257   # DW_AT_type
                        # DW_AT_artificial

Discussing this with some members of AdaCore's compiler team,
it is expected that the optimizer can get rid of this variable,
and we don't want to pessimize the code just to improve debuggability,
since -O2 is about performance. So, the idea of this patch is
not to make it work, but provide a bit more information to help
users understand what kind of error is preventing GDB from being
able to print the variable's value.

The first hurdle we had to clear was the fact that ada_val_print
traps all exceptions (including QUIT ones!), and does so completly
silently. So, the fix was to add a trace of the exception being
generated. While doing so, we fix an old XXX/FIXME by only catching
errors, letting QUIT exceptions go through.

Once this is done, we now get an error message, which gives a first
clue as to what was happening:

    (gdb) p fd.global
    $1 = <error reading variable: value has been optimized out>

However, it would be more useful to know which value it was
that was optimized out. For that purpose, we enhanced
ada-lang.c::ada_to_fixed_type_1 so as to re-throw the error
with a message which indicates which variable we failed to read.

With those changes, the new output is now:

    (gdb) p fd.global
    $1 = <error reading variable: unable to read value of fd__Tints_doubledC___XVZ (value has been optimized out)>

gdb/ChangeLog:

        * ada-lang.c (ada_to_fixed_type_1): Rethrow errors with
        a more detailed exception message when getting an exception
        while trying to read the value of an XVZ variable.
        * ada-valprint.c (ada_val_print): Only catch RETURN_MASK_ERROR
        exceptions.  Print an error message when an exception is caught.

gdb/testsuite/ChangeLog:

        * gdb.dwarf2/ada-valprint-error.c: New file.
        * gdb.dwarf2/ada-valprint-error.exp: New file.

Tested on x86_64-linux
2017-12-17 22:39:33 -05:00
Joel Brobecker 0e2da9f013 (Ada) crash assigning to record component which is an array
Consider the following code, which declares a variabled called "input"
of type "parameter", which is a record with one component called "u2",
where the type of that component is a simple 3-element array of
floating point values:

   type Float_Array_3 is array (1 .. 3) of Float;
   type parameters is record
      u2 : Float_Array_3;
   end record;
   input : parameters;

Trying to assign a value to input.u2 causes GDB to crash:

    (gdb) p input.u2 := (0.25,0.5,0.75)
    [1]    20228 segmentation fault (core dumped) [...]/gdb

The crash occurs because input.u2 is described in the debugging
info as a typedef of an array. Indeed, input's type is:

 <1><ae9>: Abbrev Number: 7 (DW_TAG_structure_type)
    <aea>   DW_AT_name        : (indirect string, offset: 0x1045): target_wrapper__parameters
    [...]
 <2><af5>: Abbrev Number: 8 (DW_TAG_member)
    <af6>   DW_AT_name        : u2
    [...]
    <afb>   DW_AT_type        : <0xaca>

and, looking at DIE 0xaca to get input.u2's type, we see:

 <1><aca>: Abbrev Number: 4 (DW_TAG_typedef)
    <acb>   DW_AT_name        : (indirect string, offset: 0x1060): target_wrapper__float_array_3
    [...]
    <ad1>   DW_AT_type        : <0xad5>

We can also confirm, following the DW_AT_type attribute (0xad5), that
it's a typedef of our array:

 <1><ad5>: Abbrev Number: 5 (DW_TAG_array_type)
    <ad6>   DW_AT_name        : (indirect string, offset: 0x1060): target_wrapper__float_array_3
    [...]

In fact, this scenario uncovered 2 areas where typedef handling
is missing, thus causing a crash. The first happens inside
assign_aggregate:

   if (ada_is_direct_array_type (lhs_type))
     {
       lhs = ada_coerce_to_simple_array (lhs);
       lhs_type = value_type (lhs);
       low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
       high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
     }

Here, lhs_type is a TYPE_CODE_TYPEDEF. ada_is_direct_array_type
knows how to handle it, but TYPE_ARRAY_LOWER_BOUND_VALUE assumes
that the given type is a TYPE_CODE_ARRAY. As such, it ends up
accessing some fields in lhs_type which it shouldn't, and kaboom.

We fixed this issue by making sure that the TYPE_CODE_TYPEDEF
layer gets stripped.

Once this is done, we hit a different kind of error, also leading to
a SEGV, this time in assign_component. The code looks like this:

  if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
    [...]
  else
    [...]

Because once again lhs is a TYPE_CODE_TYPEDEF, the check fail,
and we end up assuming that lhs is a struct, executing the "else"
block, which is:

  else
    {
      elt = ada_index_struct_field (index, lhs, 0, value_type (lhs));
      elt = ada_to_fixed_value (elt);
    }

Since lhs is not a struct, ada_index_struct_field returns NULL,
which ada_to_fixed_value does not handle well, hence another crash.

This patch fixes this other issue the same way, by stripping
TYPE_CODE_TYPEDEF layers.

gdb/ChangeLog:

        * ada-lang.c (assign_component): Strip any TYPE_CODE_TYPEDEF
        layer from lhs' type.
        (assign_aggregate): Likewise.

gdb/testsuite:

        * gdb.ada/assign_arr: New testcase.

Tested on x86_64-linux.
2017-12-17 22:11:40 -05:00
Xavier Roirand cb923fcc23 Ada: fix bad handling in ada_convert_actual
Using this small example:

procedure Foo is

   type Integer_Access is access all Integer;

   procedure P (A : Integer_Access) is
   begin
      null;
   end P;

begin
   P (null);
end Foo;

and doing this debug session:

(gdb) b p
Breakpoint 1 at 0x402d67: file foo.adb, line 7.
(gdb) print p(null)

Breakpoint 1, foo.p (a=0x641010) at foo.adb:10
...                  ^^^^^^^^^^

shows that something goes wrong between the initial null value and the
received parameter value in the 'f' function.
The value for the parameter 'a' we get is the address of the value we
would expect instead of the value itself. This can be checked by doing:

(gdb) p *a
$1 = 0

Before this fix, in ada_convert_value, this function was looking to the
actual value (the null value here) to determine if the formal (parameter
'a' in the procedure 'P' in this exemple) requires a pointer or not which
is a wrong assumption and leads to push the address of the value to the
inferior instead of the value itself.

This is fixed by this patch.

gdb/ChangeLog:

        * ada-lang.c (ada_convert_actual): Change the way actual value
        are passed to the inferior when the inferior expects a pointer type.

gdb/testsuite/ChangeLog:

        * gdb.ada/funcall_ptr: New testcase.

Tested on x86_64-linux.
2017-12-17 22:01:32 -05:00
Stafford Horne 38af182401 gdb: Fix function parameter alignments in or1k-tdep.c.
As suggested by Joel Brobecker <brobecker@adacore.com> and as per fsf
coding standards.  Also fix a few more issues with directly printing
pointers.

gdb/ChangeLog:

	* gdb/or1k-tdep.c (show_or1k_debug): Fix function parameter alignment.
	(or1k_analyse_inst): Likewise.
	(or1k_single_step_through_delay): Likewise.
	(or1k_frame_cache): Fix parameter alignment and use paddress()
	instead of %x.
2017-12-17 07:20:51 +09:00
Stafford Horne b282f0f2b5 gdb: Add news entries for new or1k target.
gdb/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	* NEWS (Changes since GDB 8.0): Mention new or1k target and new
	commands to set/show or1k debug.
2017-12-17 07:20:50 +09:00
Sergio Durigan Junior 46afe196ec Fix ARI warning on gdb/typeprint.c:whatis_exp
I forgot to indent the "if" clause properly and put the "&&" at the
beginning of the line, so ARI complained.  This commit fixed it.

gdb/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* typeprint.c (whatis_exp): Fix ARI warning and reindent "if"
	condition.
2017-12-15 22:33:07 -05:00
Sergio Durigan Junior 7c1618381f Implement pahole-like 'ptype /o' option
This commit implements the pahole-like '/o' option for 'ptype', which
prints the offsets and sizes of struct fields, reporting whenever
there is a hole found.

The output is heavily based on pahole(1), with a few modifications
here and there to adjust it to our reality.  Here's an example:

  /* offset    |  size */  type = struct wer : public tuv {
			   public:
  /*   32      |    24 */    struct tyu {
  /*   32:31   |     4 */        int a1 : 1;
  /*   32:28   |     4 */        int a2 : 3;
  /*   32: 5   |     4 */        int a3 : 23;
  /*   35: 3   |     1 */        char a4 : 2;
  /* XXX  3-bit hole   */
  /* XXX  4-byte hole  */
  /*   40      |     8 */        int64_t a5;
  /*   48:27   |     4 */        int a6 : 5;
  /*   48:56   |     8 */        int64_t a7 : 3;

				 /* total size (bytes):   24 */
			     } a1;

			     /* total size (bytes):   56 */
			   }

A big part of this patch handles the formatting logic of 'ptype',
which is a bit messy.  The code to handle bitfield offsets, however,
took some time to craft.  My thanks to Pedro Alves for figuring things
out and pointing me to the right direction, as well as coming up with
a way to inspect the layout of structs with bitfields (see testcase
for comments).

After many discussions both on IRC and at the mailing list, I tried to
implement printing vtables and inherited classes.  Unfortunately the
code grew too complex and there were still a few corner cases failing
so I had to drop the attempt.  This should be implemented in a future
patch.

This patch is the start of a long-term work I'll do to flush the local
patches we carry for Fedora GDB.  In this specific case, I'm aiming at
upstreaming the feature implemented by the 'pahole.py' script that is
shipped with Fedora GDB:

  <https://src.fedoraproject.org/rpms/gdb/blob/master/f/gdb-archer.patch#_311>

This has been regression-tested on the BuildBot.  There's a new
testcase for it, along with an update to the documentation.  I also
thought it was worth mentioning this feature in the NEWS file.

gdb/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	PR cli/16224
	* NEWS (Changes since GDB 8.0): Mention new '/o' flag.
	* c-typeprint.c (OFFSET_SPC_LEN): New define.
	(c_type_print_varspec_prefix): New argument 'struct
	print_offset_data *'.
	(c_type_print_base_1): New function and prototype.
	(c_print_type_1): New function, with code from 'c_print_type'.
	(c_print_type): Use 'c_print_type_1'.
	(c_type_print_varspec_prefix): New argument 'struct
	print_offset_data *'.  Use it.  Call 'c_type_print_base_1'
	instead of 'c_print_type_base'.
	(print_spaces_filtered_with_print_options): New function.
	(output_access_specifier): Take new argument FLAGS.  Modify
	function to call 'print_spaces_filtered_with_print_options'.
	(c_print_type_vtable_offset_marker): New function.
	(c_print_type_union_field_offset): New function.
	(c_print_type_struct_field_offset): New function.
	(c_print_type_no_offsets): New function.
	(c_type_print_base_struct_union): New argument 'struct
	print_offset_data *'.  Print offsets and sizes for
	struct/union/class fields.
	* typeprint.c (const struct type_print_options
	type_print_raw_options): Initialize 'print_offsets'.
	(static struct type_print_options default_ptype_flags):
	Likewise.
	(struct print_offset_data print_offset_default_data): New
	variable.
	(whatis_exp): Handle '/o' option.
	(_initialize_typeprint): Add '/o' flag to ptype's help.
	* typeprint.h (struct print_offset_data): New struct.
	(struct type_print_options) <print_offsets>: New field.

gdb/testsuite/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/16224
	* gdb.base/ptype-offsets.cc: New file.
	* gdb.base/ptype-offsets.exp: New file.

gdb/doc/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR cli/16224
	* gdb.texinfo (ptype): Add documentation for new flag '/o'.
2017-12-15 15:07:42 -05:00
Sergio Durigan Junior a27ed7d613 Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base'
While doing the 'ptype /o' work, I noticed that 'c_type_print_base'
was very long, with a big amount of code just to handle the case of
TYPE_CODE_{STRUCT,UNION}.  This made working with the function a bit
difficult, specially because of the level of indentation.

This commit moves this part of the code to their own functions.  Now
we have a 'c_type_print_base_struct_union' with most of the code, and
also 'need_access_label_p', which is a subset of the code that was
also a good candidate for having its own function.

gdb/ChangeLog:
2017-12-15  Sergio Durigan Junior  <sergiodj@redhat.com>

	* c-typeprint.c (need_access_label_p): New function.
	(c_type_print_base_struct_union): New function.
	(c_type_print_base): Move code to handle
	TYPE_CODE_{STRUCT,UNION} to the functions mentioned above.
2017-12-15 15:06:26 -05:00
Richard Henderson 68f81d6019 Fix PR19061, gdb hangs/spins-on-cpu when debugging any program on Alpha
This fixes PR19061, where gdb hangs/spins-on-cpu when debugging any
program on Alpha.

(This patch is Uros' forward port of the patch from comment #5
of the PR [1].)

Patch was tested on alphaev68-linux-gnu, also tested with gcc's
testsuite, where it fixed all hangs in guality.exp and
simulate-thread.exp testcases.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=19061#c5

gdb/ChangeLog:
2017-12-15  Richard Henderson  <rth@redhat.com>
	    Uros Bizjak  <ubizjak@gmail.com>

	PR gdb/19061
	* alpha-tdep.c (alpha_software_single_step): Call
	alpha_deal_with_atomic_sequence here.
	(set_gdbarch_software_single_step): Set to
	alpha_software_single_step.
	* nat/linux-ptrace.h [__alpha__]: Define GDB_ARCH_IS_TRAP_BRKPT
	and GDB_ARCH_IS_TRAP_HWBKPT.
2017-12-15 18:19:42 +00:00
Yao Qi 1af17fd9cc Skip 'maintenance check xml-descriptions' if XML is disabled
I see the following test failure when gdb is configured without XML
support,

maintenance check xml-descriptions binutils-gdb/gdb/testsuite/../features
warning: Can not parse XML target description; XML support was disabled at compile time^M
Tested 29 XML files, 29 failed
(gdb) FAIL: gdb.gdb/unittest.exp: maintenance check xml-descriptions ${srcdir}/../features

gdb/testsuite:

2017-12-15  Yao Qi  <yao.qi@linaro.org>

	* gdb.gdb/unittest.exp: Skip 'maintenance check xml-descriptions'
	if XML is disabled.
2017-12-15 10:45:27 +00:00
Yao Qi 97d4fac10f Skip parse_memory_map_tests if XML is disabled
I find a fail in gdb unit test when gdb is configured without XML
support.

warning: Can not parse XML memory map; XML support was disabled at compile time^M
Self test failed: self-test failed at ../../binutils-gdb/gdb/unittests/memory-map-selftests.c:65
...
Ran 31 unit tests, 1 failed^M
(gdb) FAIL: gdb.gdb/unittest.exp: maintenance selftest

gdb:

2017-12-15  Yao Qi  <yao.qi@linaro.org>

	* unittests/memory-map-selftests.c: Wrap test with HAVE_LIBEXPAT.
2017-12-15 10:45:27 +00:00
Xavier Roirand 828d584679 (Ada) Handle same component names when searching in tagged types
Consider the following code:

   type Top_T is tagged record
      N : Integer := 1;
      U : Integer := 974;
      A : Integer := 48;
   end record;

   type Middle_T is new Top.Top_T with record
      N : Character := 'a';
      C : Integer := 3;
   end record;

  type Bottom_T is new Middle.Middle_T with record
     N : Float := 4.0;
     C : Character := '5';
     X : Integer := 6;
     A : Character := 'J';
  end record;

Tagged records in Ada provide object-oriented features, and what
is interesting in the code above is that a child tagged record
introduce additional components (fields) which sometimes have
the same name as one of the components in the parent. For instance,
Bottom_T introduces a component named "C", while at the same time
inheriting from Middle_T which also has a component named "C";
so, in essence, type Bottom_T has two components with the same name!

And before people start wondering why the language can possibly
be allowing that, this can only happen if the parent type has
a private definition. In our case, this was brought to our attention
when the parent was a generic paramenter.

With that in mind...  Let's say we now have a variable declared
and initialized as follow:

  TC : Top_A := new Bottom_T;

And then we use this variable to call this function

  procedure Assign (Obj: in out Top_T; TV : Integer);

  as follow:

  Assign (Top_T (B), 12);

Now, we're in the debugger, and we're inside that procedure
(Top.Assign in our gdb testcase), and we want to print
the value of obj.c:

Usually, the tagged record or one of the parent type owns the
component to print and there's no issue but in this particular
case, what does it mean to ask for Obj.C ? Since the actual
type for object is type Bottom_T, it could mean two things: type
component C from the Middle_T view, but also component C from
Bottom_T. So in that "undefined" case, when the component is
not found in the non-resolved type (which includes all the
components of the parent type), then resolve it and see if we
get better luck once expanded.

In the case of homonyms in the derived tagged type, we don't
guaranty anything, and pick the one that's easiest for us
to program.

This patch fixes the behavior like described above.

gdb/ChangeLog:

        * ada-lang.c (ada_value_primitive_field): Handle field search
        in case of homonyms.
        (find_struct_field): Ditto.
        (ada_search_struct_field): Ditto.
        (ada_value_struct_elt): Ditto.
        (ada_lookup_struct_elt_type): Ditto.

gdb/testsuite/ChangeLog:

        * gdb.ada/same_component_name: New testcase.

Tested on x86_64-linux.
2017-12-14 23:35:38 -05:00
Simon Marchi 8e557e52b3 py-breakpoint: Don't use the 'p' PyArg_ParseTupleAndKeywords format specifier
In Python 3, the 'p' format specifier can be passed to
PyArg_ParseTupleAndKeywords to test the argument for truth and convert
it to a boolean value (the p stands for predicate).  However, it is not
available in Python 2, causing this error:

  Traceback (most recent call last):
    File "test.py", line 1, in <module>
      b1 = gdb.Breakpoint("foo", qualified=False)
  TypeError: argument 10 (impossible<bad format char>)

This patch changes it to the 'O' specifier, which returns the Python
object passed in without transformation, and uses PyObject_IsTrue on it.
This is what is done for the other boolean parameters of this function
(internal and temporary).

This fixes the test gdb.python/py-breakpoint.exp for Python 2.

gdb/ChangeLog:

	* python/py-breakpoint.c (bppy_init): Use 'O' format specifier
	for "qualified" and use PyObject_IsTrue.
2017-12-14 15:46:47 -05:00
Jan Kratochvil 8af5c486ea DWARF-5 .debug_names DW_IDX_type_unit fix
The .debug_names completely misses its support as it did not even produce
DW_IDX_type_unit.

gdb/ChangeLog
2017-12-14  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (dw2_debug_names_iterator::next): Support
	DW_IDX_type_unit.
	(debug_names::dwarf5_offset_size, unit_kind): New.
	(debug_names::insert): Add parameter kind.
	(debug_names::build): Support DW_IDX_type_unit.
	(debug_names::recursively_write_psymbols): Update
	(debug_names::write_psymbols caller.
	(debug_names::write_one_signatured_type_data)
	(debug_names::write_one_signatured_type): New.
	(debug_names::index_key, debug_names::symbol_value)
	(debug_names::write_psymbols): Add kind.
	(debug_names::write_one_signatured_type): New.
	(write_debug_names): Move dwarf5_offset_size to debug_names.
	Use debug_names::write_one_signatured_type for type units.
2017-12-14 10:02:09 +01:00
Joel Brobecker 79e8fcaafa Ada: unable to compare strings (Attempt to compare array with non-array)
Consider the following Ada Code:

   type Str is new String (1 .. 4);
   My_str : Str := "ABCD";

This simply declares a 4-character string type. Trying to perform
equality tests using it currently yield an error:

    (gdb) p my_str = my_str
    Attempt to compare array with non-array
    (gdb) p my_str = "ABCD"
    Attempt to compare array with non-array

The error occurs because my_str is defined as an object whose
type is a typdef to a TYPE_CODE_ARRAY, which ada_value_equal
is not expecting at all (yet). This patch fixes this oversight.

gdb/ChangeLog:

        * ada-lang.c (ada_value_equal): Add handling of typedef types
        when comparing array objects.

gdb/testsuite/ChangeLog:

        * gdb.ada/str_binop_equal: New testcase.

Tested on x86_64-linux.
2017-12-14 00:16:39 -05:00
Joel Brobecker e05fa6f9df (Ada) Add support for task switching when debugging core files
The reasons for not supporting task switching when debugging core files
appear to now mostly be OBE. In particular, on GNU/Linux, the thread
layer is now able to retrieve the same thread info as in the live
process. So, this patch is mostly about just removing the guard
that limited the use of task switching to live processes.

gdb/ChangeLog:

        * ada-tasks.c (read_atcb): Properly set task_info->ptid
        when !target_has_execution as well.
        (task_command): Remove error when !target_has_execution.

gdb/testsuite/ChangeLog:

        * gdb.ada/task_switch_in_core: New testcase.
2017-12-13 23:00:03 -05:00
Simon Marchi b89641bab5 python: Add qualified parameter to gdb.Breakpoint
This patch adds the possibility to pass a qualified=True|False parameter
when creating a breakpoint in Python.  It is equivalent to using
-qualified in a linespec.  The parameter actually accepts any Python
value, and converts it to boolean using Python's standard rules for
that (https://docs.python.org/3/library/stdtypes.html#truth).

Unlike the -source/-line/-function/-label parameters, it is possible to
use -qualified with a "normal" (non-explicit) linespec.  Therefore, it
is possible (unlike these other parameters) to use this new parameter
along with the spec parameter.

I updated the py-breakpoint.exp test.  To be able to test multiple
locations using a namespace, I had to switch the test case to compile as
C++.  If we really wanted to, we could run it as both C and C++, but
omit the C++-specific parts when running it as C.

gdb/ChangeLog:

	* location.h (string_to_event_location): Add match_type
	parameter.
	* location.c (string_to_event_location): Likewise.
	* python/py-breakpoint.c (bppy_init): Handle qualified
	parameter.

gdb/doc/ChangeLog:

	* python.texi (Manipulating breakpoints using Python): Document
	qualified parameter to gdb.Breakpoint.

gdb/testsuite/ChangeLog:

	* gdb.python/py-breakpoint.c (foo_ns::multiply): New function.
	* gdb.python/py-breakpoint.exp: Compile the test case as c++,
	call test_bkpt_qualified.
	(test_bkpt_qualified): New proc.
2017-12-13 11:44:28 -05:00
Pedro Alves 6892d2e4df Tighten regexp of lib/completion-support.exp:test_gdb_complete_tab_multiple
While writing the tests included in the previous commit, I noticed
that test_gdb_complete_tab_multiple would not FAIL if GDB happens to
show more completions than expected before the expected list.

E.g., with something like this, expecting "p foo" to complete to
"foo2" and "foo3":

 test_gdb_complete_tab_multiple "p foo" "" {
	"foo2"
	"foo3"
 }

and then if foo actually completes to:

 (gdb) p foo[TAB]
 foo1   foo2  foo3
 ^^^^

we'd still PASS.  (Note the spurious "foo1" above.)

This tightens the regexp with a beginning anchor thus making the
completions above cause a FAIL.  Other similar functions in
completion-support.exp already do something like this; I had just
missed this one originally.  Thankfully, this did not expose any
problems in the gdb.linespec/ tests.  Phew.

gdb/testsuite/ChangeLog:
2017-12-13  Pedro Alves  <palves@redhat.com>

	* lib/completion-support.exp (test_gdb_complete_tab_multiple):
	Tighten regexp by matching with an anchor.
2017-12-13 16:40:00 +00:00
Pedro Alves a22ecf7026 Fix regression: expression completer and scope operator (PR gdb/22584)
I noticed this regression in the expression completer:

 "(gdb) p std::[TAB]" => "(gdb) p std::std::"

obviously we should have not completed to "std::std::".

The problem is that in the earlier big completer rework, I missed
taking into account the fact that with expressions, the completion
word point is not always at the start of the symbol name (it is with
linespecs).

The fix is to run the common prefix / LCD string (what readline uses
to expand the input line) through make_completion_match_str too.

New testcase included, exercising both TAB completion and the complete
command.

gdb/ChangeLog:
2017-12-13  Pedro Alves  <palves@redhat.com>

	* completer.c (completion_tracker::maybe_add_completion): New
	'text' and 'word' parameters.  Use make_completion_match_str.
	(completion_tracker::add_completion): New 'text' and 'word'
	parameters.  Pass down.
	(completion_tracker::recompute_lowest_common_denominator): Change
	parameter type to gdb::unique_xmalloc_ptr rval ref.  Adjust.
	* completer.h (completion_tracker::add_completion): New 'text' and
	'word' parameters.
	(completion_tracker::recompute_lowest_common_denominator): Change
	parameter type to gdb::unique_xmalloc_ptr rval ref.
	(completion_tracker::recompute_lowest_common_denominator): Change
	parameter type to gdb::unique_xmalloc_ptr rval ref.
	* symtab.c (completion_list_add_name): Pass down 'text' and 'word'
	as well.

gdb/testsuite/ChangeLog:
2017-12-13  Pedro Alves  <palves@redhat.com>

	* gdb.cp/cpcompletion.exp: Load completion-support.exp.
	("expression with namespace"): New set of tests.
	* gdb.cp/pr9594.cc (Test_NS::foo, Test_NS::bar)
	(Nested::Test_NS::qux): New.
	* lib/completion-support.exp (test_gdb_complete_cmd_multiple): Add
	defaults to 'start_quote_char' and 'end_quote_char' parameters.
2017-12-13 16:38:50 +00:00
Pedro Alves 60a20c1907 Factor out final completion match string building
We have several places doing essentially the same thing; factor them
out to a central place.  Some of the places overallocate for no good
reason, or use strcat unnecessarily.  The centralized version is more
precise and to the point.

(I considered making the gdb::unique_xmalloc_ptr overload version of
make_completer_match_str try to realloc (not xrealloc) probably
avoiding an allocation in most cases, but that'd be probably overdoing
it, and also, now that I'm writing this I thought I'd try to see how
could we ever get to filename_completer with "text != word", but I
couldn't figure it out.  Running the testsuite with 'gdb_assert (text
== word);' never tripped on the assertion either.  So post gdb 8.1,
I'll probably propose a patch to simplify filename_completer a bit,
and the gdb::unique_xmalloc_str overload can be removed then.)

gdb/ChangeLog:
2017-12-13  Pedro Alves  <palves@redhat.com>

	* cli/cli-decode.c (complete_on_cmdlist, complete_on_enum): Use
	make_completion_match_str.
	* completer.c: Use gdb::unique_xmalloc_ptr and
	make_completion_match_str.
	(make_completion_match_str_1): New.
	(make_completion_match_str(const char *, const char *,
	const char *)): New.
	(make_completion_match_str(gdb::unique_xmalloc_ptr<char> &&,
	const char *, const char *)): New.
	* completer.h (make_completion_match_str(const char *,
	const char *, const char *)): New.
	(make_completion_match_str(gdb::unique_xmalloc_ptr<char> &&,
	const char *, const char *)): New.
	* interps.c (interpreter_completer): Use make_completion_match_str.
	* symtab.c (completion_list_add_name, add_filename_to_list): Use
	make_completion_match_str.
2017-12-13 16:38:49 +00:00
Simon Marchi 0b982d685e python doc: Rework Breakpoint.__init__ doc
I find the documentation of the gdb.Breakpoint constructor hard to read
and not very informative, especially since we have added the new
linespec parameters.  There are multiple problems (some are subjective):

- It's not clear that you should use either the spec string or the
  explicit arguments, not both.
- It's not clear what combination of parameters you can use.
- The big block of text describing the arguments is hard to read.
- Currently, it seems like the "spec" argument is mandatory, even though
  it is not (if you use explicit linespec).
- The square bracket nesting

    [arg1 [, arg2[, arg3]]]

  makes it seems like if you specify arg3, you must specify arg1 and
  arg2 (it's not the case here).

This patch tries to address these problems.

gdb/doc/ChangeLog:

	* python.texi (Manipulating breakpoints using Python): Split doc
	of Breakpoint.__init__ in two, split text in multiple
	paragraphs, don't nest parameter square brackets.
2017-12-13 11:27:04 -05:00
Stafford Horne 9664701462 gdb: Fix ARI warnings in or1k-tdep.c
Fix a few issues not using the gettext _() wrapper and issues where
we are using %p directly instead of the dedicated host/target functions.

gdb/ChangeLog:

yyyy-mm-dd  Stafford Horne  <shorne@gmail.com>

	* or1k-tdep.c (or1k_analyse_inst): Use _() wrapper for message
	strings.
	(or1k_unwind_pc): Use paddress() instead of %p.
	(or1k_unwind_sp): Likewise.
	(or1k_frame_cache): Use host_address_to_string()/paddress()
	instead of %p and use _() wrapper for message strings.
2017-12-14 00:00:51 +09:00
Simon Marchi 3bbd9f1877 Fix typo in gdb_ari.sh
gdb/ChangeLog:

	* contrib/ari/gdb_ari.sh: Fix typo in help.
2017-12-13 09:34:27 -05:00
Joel Brobecker 9937536c23 fix "server" command prefix handling (unexpected confirmation queries)
The "server" command prefix no longer turns confirmation queries off.
We can reproduce this with any program by tring to delete all breakpoints,
for instance:

    (gdb) break main
    Breakpoint 1 at 0x40049b: file /[...]/break-fun-addr1.c, line 21.
    (gdb) server delete breakpoints
    Delete all breakpoints? (y or n)

GDB should not be asking "Delete all breakpoints? (y or n)", but
instead just delete all breakpoints without asking for confirmation.

Looking at utils.c::defaulted_query gives a glimpse of how this feature
is expected to work:

  /* Automatically answer the default value if the user did not want
     prompts or the command was issued with the server prefix.  */
  if (!confirm || server_command)
    return def_value;

So, it relies on the server_command global to be set when the "server "
command prefix is used, which is no longer the case since the following
commit:

    commit b69d38afde
    Date:   Wed Mar 9 18:25:00 2016 +0000
    Subject: Command line input handling TLC

The patch was simplifying the handling for the command line, and
I believe there was just a small oversight of removing the setting
of the server_command global.

This patch restores that, and adds a testcase to make sure we test
that feature.

gdb/ChangeLog:

        * event-top.c (handle_line_of_input): Set server_command.

gdb/testsuite/ChangeLog:

        * gdb.base/server-del-break.c: New file.
        * gdb.base/server-del-break.exp: New file.

Tested on x86_64-linux, no regression.
2017-12-12 22:23:19 -05:00
Stafford Horne fe49c6f559 gdb: testsuite: Add or1k tdesc-regs.exp test support
gdb/testsuite/ChangeLog:

2017-12-12  Stafford Horne  <shorne@gmail.com>

	* gdb.xml/tdesc-regs.exp: Add or1k support.
2017-12-12 23:38:31 +09:00
Stafford Horne c3d186206b gdb: testsuite: Add or1k l.nop instruction
The test case requires adding a nop instruction.  For or1k the
instruction is `l.nop`. This change uses the correct operation.

gdb/testsuite/ChangeLog:

2017-12-12  Stafford Horne  <shorne@gmail.com>

	* gdb.base/bp-permanent.c: Define nop of or1k.
2017-12-12 23:37:04 +09:00
Franck Jullien a994fec4f8 gdb: Add OpenRISC or1k and or1knd target support
This patch prepares the current GDB port of the OpenRISC processor from
https://github.com/openrisc/binutils-gdb for upstream merging.

Testing has been done with a cgen sim provided in a separate patch. This
has been tested with 2 toolchains. GCC [1] 5.4.0 from the OpenRISC
project with Newlib [2] and GCC 5.4.0 with Musl [3] 1.1.4.

It supports or1knd (no delay slot target).
The default target is or1k (with delay slot).

You can change the target arch with:

(gdb) set architecture or1knd
The target architecture is assumed to be or1knd

[1] https://github.com/openrisc/or1k-gcc
[2] https://github.com/openrisc/newlib
[3] https://github.com/openrisc/musl-cross

gdb/doc/ChangeLog:

2017-12-12  Stafford Horne  <shorne@gmail.com>
	    Stefan Wallentowitz  <stefan@wallentowitz.de>
	    Franck Jullien  <franck.jullien@gmail.com>
	    Jeremy Bennett  <jeremy.bennett@embecosm.com>

	* gdb.texinfo: Add OpenRISC documentation.

gdb/ChangeLog:

2017-12-12  Stafford Horne  <shorne@gmail.com>
	    Stefan Wallentowitz  <stefan@wallentowitz.de>
	    Stefan Kristiansson  <stefan.kristiansson@saunalahti.fi>
	    Franck Jullien  <franck.jullien@gmail.com>
	    Jeremy Bennett  <jeremy.bennett@embecosm.com>

	* configure.tgt: Add targets for or1k and or1knd.
	* or1k-tdep.c: New file.
	* or1k-tdep.h: New file.
	* features/Makefile: Add or1k.xml to build.
	* features/or1k.xml: New file.
	* features/or1k-core.xml: New file.
	* features/or1k.c: Generated.
2017-12-12 23:36:00 +09:00
Alan Modra db9077b727 PR22576, ppc64_skip_trampoline_code uses wrong r2 for EXEC_REVERSE
The TOC pointer register, r2, on powerpc64 is generally not mentioned
in debug info.  It is saved and restored by call linkage code, and
set to the callee value either by call stub code (ELFv1) or in the
callee global entry point code (ELFv2).  A call stub uses the caller
TOC pointer to access the PLT.  So for gdb to read the correct PLT
entry in order to determine the destination of the trampoline, gdb
needs to know the caller r2.  When skipping over trampolines in the
normal forward direction, the caller r2 is simply the current value of
r2 (at the start of the trampoline).  However, when reversing over
trampolines the current value of r2 is that for the callee.  Using
that value results in wild reads of memory rather than the correct PLT
entry.

This patch corrects the value of r2 by using the value saved on the
stack for reverse execution.  Note that in reverse execution mode it
isn't really necessary for skip_trampoline_code to return the actual
destination, so we're doing a little more work than needed here.  Any
non-zero return value would do (and it would be nicer if the interface
was changed to return the start of the stub).

	PR tdep/22576
	* ppc64-tdep.c (ppc64_plt_entry_point): Rewrite to take TOC-relative
	PLT offset, and retrieve r2 from stack when executing in reverse.
	(ppc64_standard_linkage1_target): Drop pc param.  Calculate offset
	rather than PLT address.
	(ppc64_standard_linkage2_target): Likewise.
	(ppc64_standard_linkage3_target): Likewise.
	(ppc64_standard_linkage4_target): Likewise.
	(ppc64_skip_trampoline_code_1): Adjust to suit.
2017-12-12 23:23:38 +10:30
Simon Marchi a933405894 remote: Return NULL extra_info/name if they are empty
Commit

  remote: C++ify thread_item and threads_listing_context
  21fe1c752e

broke the test gdb.threads/names.exp.  The problem is that since we now
use an std::string to hold the extra_info, an empty string is returned
by target_extra_thread_info to print_thread_info_1 when the remote stub
didn't send any extra info, instead of NULL before.  Because of that,
print_thread_info_1 prints the extra info between parentheses, which
results in some spurious empty parentheses.

  Expected: * 1    Thread 22752.22752 "main" all_threads_ready () at ...
  Actual  : * 1    Thread 22752.22752 "main" () all_threads_ready () a ...

Since the bug was introduced by a behavior change in the remote target,
I chose to fix it on the remote target side by making it return NULL
when the extra string is empty.  This will avoid possibly changing the
behavior of the common code and affecting other targets.

The name field has the same problem.  If a remote stub returns no thread
names, remote_thread_name will return an empty string instead of NULL,
so print_thread_info_1 will show empty quotes ("") instead of nothing.

gdb/ChangeLog:

	PR gdb/22556
	* remote.c (remote_thread_name): Return NULL if name is empty.
	(remote_threads_extra_info): Return NULL if extra info is empty.
2017-12-11 21:05:30 -05:00
Pedro Alves 3c0aa29aab Unbreak build for non-ELF ports
As reported at
<https://sourceware.org/ml/gdb-patches/2017-12/msg00229.html>, this
commit:

~~~~
 commit abccd1e7b7
 Author:     Jan Kratochvil <jan.kratochvil@redhat.com>
 AuthorDate: Fri Dec 8 22:44:11 2017 +0000

     Change dwarf2_initialize_objfile's return value

     dwarf2_initialize_objfile was returning boolean whether it is psymtabs
     or .gdb_index while now it needs to return also whether it is
     .debug_names.
~~~~

breaks non-ELF-target builds:

 dwarf2read.o: In function `dwarf2_initialize_objfile(objfile*)':
 /home/yao.qi/SourceCode/gnu/binutils-gdb/gdb/dwarf2read.c:6486:
 undefined reference to `elf_sym_fns_gdb_index'
 /home/yao.qi/SourceCode/gnu/binutils-gdb/gdb/dwarf2read.c:6490:
 undefined reference to `elf_sym_fns_debug_names'
 /home/yao.qi/SourceCode/gnu/binutils-gdb/gdb/dwarf2read.c:6495:
 undefined reference to `elf_sym_fns_lazy_psyms'
 collect2: error: ld returned 1 exit status
	 Makefile:1920: recipe for target 'gdb' failed

because gdb/elfread.c is not included in the gdb build unless bfd also
includes elf support.

Fix this by reverting the patch mentioned above and at the same time
re-adding .debug_names support by adding a new output parameter to
dwarf2_initialize_objfile to indicate the index variant in use.  We
can reuse the new dw_index_kind enum in dwarf2read.c for that.

gdb/ChangeLog:
2017-12-11  Pedro Alves  <palves@redhat.com>

	* defs.h (elf_sym_fns_lazy_psyms, elf_sym_fns_gdb_index)
	(elf_sym_fns_debug_names): Move to elfread.c.
	* dwarf2read.c (dwarf2_initialize_objfile): Return a boolean
	instead of a sym_fns and add 'index_kind' output parameter.  Fill
	the latter in with the index variant kind if using an index.
	(enum dw_index_kind): Moved to symfile.h.
	* elfread.c (elf_sym_fns_gdb_index, elf_sym_fns_debug_names)
	(elf_sym_fns_lazy_psyms): Move from defs.h.
	(elf_symfile_read): Adjust to new dwarf2_initialize_objfile
	interface.
	* symfile.h (enum class dw_index_kind): New, moved from
	dwarf2read.c.
	(dwarf2_initialize_objfile): Change prototype.
2017-12-11 14:41:32 +00:00
Ulrich Weigand f2f9e7ecc1 [MPFR] Fix regression on 32-bit host systems
When converting parts of the mantissa to MPFR, we need to make sure to do
an *unsigned* conversion.  Since we convert at most 32 bits at a time,
stored in an unsigned long, this doesn't matter on systems where "long"
is larger than 32 bits.  But on systems where it is 32 bits, we can get
conversion errors.

gdb/ChangeLog
2017-12-11  Ulrich Weigand  <uweigand@de.ibm.com>

	* target-float.c (mpfr_float_ops::from_target): Use mpfr_set_ui
	instead of mpfr_set_si to convert mantissa bits.
2017-12-11 15:26:26 +01:00
Joel Brobecker c5f9cfc894 Adapt gdb.ada/variant_record_packed_array.exp to accept reordered components
Recent versions of GNAT are capable of reordering record components
to make their access for efficient. This patch adapts this test to
accept both cases (reordered or not).

gdb/testsuite/ChangeLog:

        * gdb.ada/variant_record_packed_array.exp: Adapt test to accept
        output with components being reordered.

Tested on x86_64-linux.
2017-12-11 00:58:30 -05:00
Xavier Roirand 08f49010a1 (Ada) change tagged types base_address computation
There was a difference between C++ dispatch table and Ada's in the
way the Offset_To_Top field is used to determined the base address
of an object:

* in C++ it is a negative offset, so converting abstract interface to
deriving object requires adding this offset to “this”;

* in Ada, it was a positive offset, so the same conversion required
subtracting the offset value.

So in ada, the base address for a tagged type was computed using this formula:

base_address = value_address (obj) - offset_to_top;

The offset_to_top value was previously set to 0 or a positive value.
With recent version of AdaCore's GNAT compiler, the offset has been
changed to match C++, which means it's set to zero or a negative value

As a result, the new formula has to be:

base_address = value_address (obj) + offset_to_top;

Because we want to support old code compiled before GNAT compiler change
done in 19.0w (20171023-64) with this version and future versions of gdb,
then we change the sign of the offset_to_top if required. Required here
means if offset_to_top is positive since it indicates that the code has
been compiled with an old GNAT compiler.

This patch changes the formula as described above.

Also, one side-effect of offset_to_top now being negative is that
we now have to worry about the sign when we read its value from the
inferior. Up to now, we have been reading its value using the data
address builtin type. But since addresses are not always signed, we
now need to make sure we use the proper type (type Storage_Offset
from System.Storage_Elements). Ideally, we would be looking this type
up from the inferior, and then use that type. However, it is not
guaranteed that this type always be described in the debugging
information, so this patch just builds our own, adding it to Ada's
list of primitive types.

gdb/ChangeLog:

        * ada-lang.c (ada_tag_value_at_base_address): Change the way
        tagged type base address is computed.
        (enum ada_primitive_types) <ada_primitive_type_storage_offset>:
        New enumerate.
        (ada_language_arch_info): Set the ada_primitive_type_storage_offset
        element of lai->primitive_type_vector.

Tested on x86_64-linux. Fixes the following tests when using the newer
version of the compiler.

    gdb.ada/iwide.exp: print My_Drawable
    gdb.ada/iwide.exp: print d_access.all
    gdb.ada/iwide.exp: print dp_access.all
    gdb.ada/mi_interface.exp: create ggg1 varobj (unexpected output)
    gdb.ada/mi_interface.exp: list ggg1's children (unexpected output)
    gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint) (unexpected output)
    gdb.mi/mi-var-rtti.exp: run to mi-var-rtti.cc:63 (set breakpoint)
2017-12-11 00:23:06 -05:00
Joel Brobecker a9c135fc7d Adapt gdb.ada/pkd_arr_elem.exp to accept reordered components
Recent versions of GNAT are capable of reordering record components
to make their access for efficient. This patch adapts this test to
accept both cases (reordered or not).

gdb/testsuite/ChangeLog:

        * gdb.ada/pkd_arr_elem.exp: Adapt "print test" test to accept
        output with components being reordered.
2017-12-11 00:16:31 -05:00
Pedro Alves a3c5fafd2e dwarf2read.c: Rewrite/simplify mock_mapped_index
Now that dw2_expand_symtabs_matching_symbol works with the abstract
mapped_index_base, we can make mock_mapped_index inherit
mapped_index_base too instead of having it pretend to be a real
.gdb_index table.

gdb/ChangeLog:
2017-12-08  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (mock_mapped_index): Reimplement as an extension of
	mapped_index_base.
	(check_match): Adjust to use mock_index directly.
	(check_find_bounds_finds)
	(test_mapped_index_find_name_component_bounds): Adjust to work
	with a mapped_index_base.
2017-12-08 23:38:41 +00:00
Pedro Alves 44ed8f3ed0 Support wildmatching in .debug_names too.
dw2_debug_names_expand_symtabs_matching currently doesn't support
symbol_name_match_type::WILD, it always matches symbol names fully.

The .gdb_index code supports via dw2_expand_symtabs_matching_symbol,
which builds the mapped_index::name_components table on demand, and
then binary searches that table.

The .debug_names names index is pretty much the same as the .gdb_index
names index, i.e., a list of fully-qualified names with no
parameter/overload info.  (There's no
what-is-the-language-of-symbol-name info in .debug_names either,
unfortunately.)

So this fixes .debug_names by factoring out the related .gdb_index
code out of the mapped_index class to a base class that is inherited
by both the .gdb_index (mapped_index) and .debug_names
(mapped_debug_names) map classes.

gdb/ChangeLog:
2017-12-08  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (struct mapped_index_base): New, partially factored
	out from ...
	(struct mapped_index): ... this.  Inherit mapped_index_base.
	(mapped_index::symbol_name_slot_invalid):
	(mapped_index::symbol_name_at): Add override marker.
	(mapped_index::symbol_name_count): New.
	(struct mapped_debug_names): Inherit mapped_index_base.
	(mapped_debug_names::symbol_name_at): New.
	(mapped_debug_names::symbol_name_count): New.
	(mapped_index::find_name_components_bounds): Rename to ...
	(mapped_index_base::find_name_components_bounds): ... this.
	(mapped_index::build_name_components): Rename to ...
	(mapped_index_base::build_name_components): ... this.  Adjust to
	use mapped_index_base::symbol_name_count and
	mapped_index_base::symbol_name_slot_invalid.
	(dw2_expand_symtabs_matching_symbol): Take a mapped_index_base
	instead of a mapped_index.  Use
	dw2_expand_symtabs_matching_symbol.
2017-12-08 23:38:19 +00:00
Pedro Alves f00a2de2a7 dwarf2read.c:mapped_index, use gdb::array_view, simplify symbol table
This replaces a couple ptr+size pairs with gdb::array_view in the
.gdb_index code, and simplifies things by using an aggregate for the
type of the symbol table hash bucket instead of having to consider the
distinction between size of table vs number of slots and access name
vs vec by index.

gdb/ChangeLog:
2017-12-08  Pedro Alves  <palves@redhat.com>

	* dwarf2read.c (mapped_index::symbol_table_slot): New.
	(mapped_index::address_table): Now a gdb::array_view of const
	gdb_byte.
	(mapped_index::symbol_table): Now a gdb::array_view of
	symbol_table_slot.
	(mapped_index::address_table_size)
	(mapped_index::symbol_table_slots): Delete.
	(create_addrmap_from_index): Adjust.
	(find_slot_in_mapped_hash): Adjust.
	(read_index_from_section): Adjust.
	(dwarf2_read_index): Adjust.
2017-12-08 23:37:42 +00:00
Jan Kratochvil 927aa2e778 DWARF-5: .debug_names index consumer
Some testcases needed to be updated as they were missing
.debug_aranges.  While that does not matter for no-index (as GDB
builds the mapping internally during dwarf2_build_psymtabs_hard) and
neither for .gdb_index (as GDB uses that internally built mapping
which it stores into .gdb_index) it does matter for .debug_names as
that simply assumes existing .debug_aranges from GCC.

gdb/ChangeLog:
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* defs.h (elf_sym_fns_debug_names): New declaration.
	* dwarf2read.c: Include "hash_enum.h".
	(mapped_debug_names): New.
	(struct dwarf2_per_objfile): Add debug_names, debug_aranges and
	debug_names_table.
	(dwarf2_elf_names): Add ".debug_names" and ".debug_aranges".
	(struct dwz_file): Add debug_names.
	(dwarf2_per_objfile::locate_sections): Handle debug_names and
	debug_aranges.
	(locate_dwz_sections): Handle debug_names.
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges): New.
	(dwarf2_read_index): Update function comment.
	(dwarf5_augmentation): Moved up.
	(read_debug_names_from_section, create_cus_from_debug_names_list)
	(create_cus_from_debug_names, dwarf2_read_debug_names): New.
	(dwarf5_djb_hash): Moved up.
	(dw2_debug_names_iterator): New.
	(read_indirect_string_at_offset): New declaration.
	(mapped_debug_names::namei_to_name)
	(dw2_debug_names_iterator::find_vec_in_debug_names)
	(dw2_debug_names_iterator::next, dw2_debug_names_lookup_symbol)
	(dw2_debug_names_dump, dw2_debug_names_expand_symtabs_for_function)
	(dw2_debug_names_expand_symtabs_matching, dwarf2_debug_names_functions):
	New.
	(dwarf2_initialize_objfile): Return also elf_sym_fns_debug_names.
	(debug_names::djb_hash): Rename it to dwarf5_djb_hash.
	(debug_names::build): Update djb_hash caller.
	(write_debug_names): Move out and rename augmentation to
	dwarf5_augmentation.
	* elfread.c (elf_sym_fns_debug_names): New.
	* psymtab.h (dwarf2_debug_names_functions): New declaration.
	* symfile.h (struct dwarf2_debug_sections): Add debug_names and
	debug_aranges.
	* xcoffread.c (dwarf2_xcoff_names): Add debug_names and debug_aranges.

gdb/testsuite/ChangeLog:
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/maint.exp (check for .gdb_index): Check also for
	.debug_names.
	* gdb.dlang/watch-loc.c (.debug_aranges): New.
	* gdb.dwarf2/dw2-case-insensitive-debug.S: Likewise.
	* gdb.dwarf2/gdb-index.exp (check if index present, .gdb_index used)
	(.gdb_index used after symbol reloading): Support also .debug_names.
	* gdb.mi/dw2-ref-missing-frame-func.c (.debug_aranges): New.
2017-12-08 23:37:31 +00:00
Pedro Alves e5fa6583a7 Add gdb::hash_enum
The DWARF-5 .debug_names consumer patch will want to use an
std::unordered_map with an enum as key type, like:

	std::unordered_map<sect_offset, dwarf2_per_cu_data*>

That doesn't work in C++11 in non-recent compilers due to a language
defect:

 http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148

~~~
  In file included from /usr/include/c++/5.3.1/bits/hashtable.h:35:0,
		   from /usr/include/c++/5.3.1/unordered_set:47,
		   from src/gdb/dwarf2read.c:79:
  /usr/include/c++/5.3.1/bits/hashtable_policy.h: In instantiation of ‘struct std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset> >’:
  /usr/include/c++/5.3.1/type_traits:137:12:   required from ‘struct std::__and_<std::__is_fast_hash<std::hash<sect_offset> >, std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset> > >’
  /usr/include/c++/5.3.1/type_traits:148:38:   required from ‘struct std::__not_<std::__and_<std::__is_fast_hash<std::hash<sect_offset> >, std::__detail::__is_noexcept_hash<sect_offset, std::hash<sect_offset> > > >’
  /usr/include/c++/5.3.1/bits/unordered_map.h💯66:   required from ‘class std::unordered_map<sect_offset, dwarf2_per_cu_data*>’
  src/gdb/dwarf2read.c:3260:30:   required from here
  /usr/include/c++/5.3.1/bits/hashtable_policy.h:85:34: error: no match for call to ‘(const std::hash<sect_offset>) (const sect_offset&)’
    noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
				    ^
  In file included from /usr/include/c++/5.3.1/bits/move.h:57:0,
		   from /usr/include/c++/5.3.1/bits/stl_pair.h:59,
		   from /usr/include/c++/5.3.1/bits/stl_algobase.h:64,
		   from /usr/include/c++/5.3.1/bits/char_traits.h:39,
		   from /usr/include/c++/5.3.1/string:40,
		   from /home/pedro/gdb/mygit/src/gdb/common/common-utils.h:23,
		   from /home/pedro/gdb/mygit/src/gdb/common/common-defs.h:78,
		   from /home/pedro/gdb/mygit/src/gdb/defs.h:28,
		   from /home/pedro/gdb/mygit/src/gdb/dwarf2read.c:31:
~~~

This commits adds a helper replacement.

gdb/ChangeLog:
2017-12-08  Pedro Alves  <palves@redhat.com>

	* common/hash_enum.h: New file.
2017-12-08 23:37:30 +00:00
Jan Kratochvil 4b514bc808 Refactor: Move some generic code out of .gdb_index code
Preparation for the next patch.

gdb/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwarf2read.c (create_cu_from_index_list): New from ...
	(create_cus_from_index_list): ... this function, use it.
	(dw_expand_symtabs_matching_file_matcher)
	(dw2_expand_symtabs_matching_one): New from ...
	(dw2_expand_symtabs_matching): ... this function, use them.
2017-12-08 23:37:30 +00:00
Jan Kratochvil abccd1e7b7 Change dwarf2_initialize_objfile's return value
dwarf2_initialize_objfile was returning boolean whether it is psymtabs
or .gdb_index while now it needs to return also whether it is
.debug_names.

gdb/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* defs.h (elf_sym_fns_lazy_psyms, elf_sym_fns_gdb_index): Move here
	declarations from elfread.c.
	(dwarf2_initialize_objfile): Change return value.
	* elfread.c (elf_sym_fns_lazy_psyms, elf_sym_fns_gdb_index): Move these
	declarations to defs.h.
	(elf_symfile_read): Adjust dwarf2_initialize_objfile caller.
	* symfile.h (dwarf2_initialize_objfile): Change return type.
2017-12-08 23:37:30 +00:00
Jan Kratochvil 437afbb81e DWARF-5: .debug_names index producer
This adds a new "-dwarf-5" switch to "save gdb-index" that makes it
generate index files with DWARF-5 .debug_names/.debug_str sections
instead of GDB's own .gdb_index.

We should probably add a command line option to
contrib/gdb-add-index.sh (incl. cc-with-tweaks.sh) for the new
-dwarf-5 GDB option, and a new target board to make it more convenient
to exercise this.  To be done later.

gdb/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* contrib/gdb-add-index.sh (index): Rename to ...
	(index4): ... here.
	(index5, debugstr, debugstrmerge, debugstrerr): New variables.
	Support also .debug_names and .debug_str.
	* dwarf2read.c: Include cmath, set, list.
	(INDEX_SUFFIX): Rename to ...
	(INDEX4_SUFFIX): ... here.
	(INDEX5_SUFFIX, DEBUG_STR_SUFFIX): New.
	(file_write(FILE *, const void *, size_t)): New.
	(file_write(FILE *, const std::vector<Elem, Alloc> &)): New.
	(data_buf::append_unsigned_leb128, data_buf::empty): New.
	(data_buf::file_write): Use ::file_write.
	(data_buf::c_str, dwarf5_djb_hash, debug_names)
	(check_dwarf64_offsets): New.
	(psyms_seen_size, write_gdbindex): New from
	write_psymtabs_to_index code.
	(dwarf5_gdb_augmentation, write_debug_names, assert_file_size)
	(enum dw_index_kind): New.
	(write_psymtabs_to_index): New parameter index_kind.  Support
	filename_str and out_file_str.  Move code to write_gdbindex,
	possibly call write_debug_names.
	(save_gdb_index_command): New parameter -dwarf-5.
	(_initialize_dwarf2_read): Document the new parameter -dwarf-5.

gdb/doc/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Index Files): Document .debug_names and -dwarf-5.
--

 gdb/contrib/gdb-add-index.sh |   53 ++
 gdb/doc/gdb.texinfo          |   24 +
 gdb/dwarf2read.c             |  919 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 935 insertions(+), 61 deletions(-)
2017-12-08 23:33:27 +00:00
Jan Kratochvil 6432ec65a8 cc-with-tweaks.sh: Use gdb-add-index.sh
With DWARF-5 .debug_names, the commands to add the index to the symbol
file are more complicated, as now also .debug_str needs to be
modified.

Currently, contrib/cc-with-tweaks.sh calls objcopy to handle the '-i'
option instead of using contrib/gdb-add-index.sh which basically does
the same.  To help with .debug_names, this commit makes
contrib/cc-with-tweaks.sh reuse contrib/gdb-add-index.sh instead.

A problem this ran into is whether contrib/cc-with-tweaks.sh should
fail or not when no index is produced.

Currently, contrib/cc-with-tweaks.sh is more quiet (=successful) than
contrib/gdb-add-index.sh and so with no further changes testsuite runs
with an index would "regress".  This commit tries to keep the behavior
unchanged.  Some cases still error with:
	Ada is not currently supported by the index
But some cases (such as some trivial gdb.dwarf2/ testcases with no DWARF data
to index) produce no index while the testcases still PASS now instead of:
	-PASS: gdb.arch/i386-bp_permanent.exp: stack pointer value matches
	+gdb compile failed, gdb-add-index.sh: No index was created for gdb/testsuite.unix.-m64/outputs/gdb.arch/i386-bp_permanent/i386-bp_permanent
	+gdb-add-index.sh: [Was there no debuginfo? Was there already an index?]
	+UNTESTED: gdb.arch/i386-bp_permanent.exp: failed to compile

gdb/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* contrib/cc-with-tweaks.sh: Change interpreter to bash, incl. initial
	comment.
	(GDB_ADD_INDEX): New variable.
	<$want_index>: Call $GDB_ADD_INDEX.
2017-12-08 22:44:10 +00:00
Sergio Durigan Junior 92469284a6 Fix thinko on dtrace-probe.c:dtrace_process_dof_probe
While investigating PR gdb/22557 ("Regression:
gdb.base/dtrace-probe.exp"), I noticed that the code is wrongly
declaring a new "expression_up" variable inside the TRY block in
"dtrace_process_dof_probe".  This causes the outter "expr" variable to
be empty, which may have an impact later when evaluating the
expression.

This commit fixes that.  Unfortunately the script used to test DTrace
probes (gdb/testsuite/lib/pdtrace.in) is not very reliable so I cannot
say whether this commit fixes the PR mentioned above.  Nonetheless,
it's an obvious fix and should go in.

gdb/ChangeLog:
2017-12-08  Sergio Durigan Junior  <sergiodj@redhat.com>

	* dtrace-probe.c (dtrace_process_dof_probe): Do not declare a new
	"expression_up" inside the TRY block.
2017-12-08 15:33:55 -05:00
Yao Qi f17d947477 Clear non-significant bits of address in watchpoint
Nowadays, GDB can't set watchpoint on tagged address on AArch64,

(gdb) p p2
$1 = (int *) 0xf000fffffffff474
(gdb) watch *((int *) 0xf000fffffffff474)
Hardware watchpoint 2: *((int *) 0xf000fffffffff474)
(gdb) c
Continuing.
main () at
binutils-gdb/gdb/testsuite/gdb.arch/aarch64-tagged-pointer.c:45
45	  void (*func_ptr) (void) = foo;
Unexpected error setting hardware debug registers

This patch is about setting watchpoint on a tagged address.  Unlike
breakpoint, watchpoint record the expression rather than the address, and
when a watchpoint is fired, GDB checks the expression value changed
instead of matching address, so we can mask the watchpoint address by
getting rid of non-significant bits of address.

gdb:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (update_watchpoint): Call
	address_significant.

gdb/testsuite:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/aarch64-tagged-pointer.c (main): Update.
	* gdb.arch/aarch64-tagged-pointer.exp: Add tests for watchpoint.
2017-12-08 17:27:03 +00:00
Yao Qi a0de8c21ba Adjust breakpoint address by clearing non-significant bits
Tag in tagged address on AArch64 is treated as a non-significant bits of
address, which can be got by gdbarch method significant_addr_bit, and gdb
can clear these bits.

With this patch, when user sets a breakpoint on tagged address on AArch64,
GDB will drop the top byte of address, and put breakpoint at the new place,
as shown below,

(gdb) hbreak *func_ptr
warning: Breakpoint address adjusted from 0xf000000000400690 to 0x00400690.
Hardware assisted breakpoint 2 at 0x400690

(gdb) break *func_ptr
warning: Breakpoint address adjusted from 0xf000000000400690 to 0x00400690.
Breakpoint 3 at 0x400690

When program hits a breakpoint, the stopped pc reported by Linux kernel is
the address *without* tag, so it is better the address recorded in
breakpoint location is the one without tag too, so we can still match
breakpoint location address and stopped pc reported by Linux kernel, by
simple compare.

gdb:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* breakpoint.c (adjust_breakpoint_address): Call
	address_significant.

gdb/testsuite:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* gdb.arch/aarch64-tagged-pointer.c (main): Update.
	* gdb.arch/aarch64-tagged-pointer.exp: Add test for breakpoint.
2017-12-08 17:27:03 +00:00
Yao Qi a738ea1d41 Clear non-significant bits of address on memory access
ARMv8 supports tagged address, that is, the top one byte in address
is ignored.  It is always enabled on aarch64-linux.  See
https://www.kernel.org/doc/Documentation/arm64/tagged-pointers.txt

The tag in the tagged address is modeled as non-significant bits in
address, so this patch adds a new gdbarch method significant_addr_bit and
clear the non-significant bits (the top byte in ARMv8) of the virtual
address at the point before passing address to target cache layer.  IOW,
the address used in the target cache layer is already cleared.

Before this patch,
(gdb) x/x 0x0000000000411030
0x411030 <global>:	0x00000000
(gdb) x/x 0xf000000000411030
0xf000000000411030:	Cannot access memory at address 0xf000000000411030

After this patch,

(gdb) x/x 0x0000000000411030
0x411030 <global>:	0x00000000
(gdb) x/x 0xf000000000411030
0xf000000000411030:	0x00000000

Note that I used address_significant in paddress, but it causes a
regression gdb.base/long_long.exp, because gdb clears the non-significant
bits in address, but test still expects them.

p/a val.oct^M
$24 = 0x2ee53977053977^M
(gdb) FAIL: gdb.base/long_long.exp: p/a val.oct

so I defer the change there.

gdb:

2017-12-08  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c (aarch64_gdbarch_init): Install gdbarch
	significant_addr_bit.
	* gdbarch.sh (significant_addr_bit): New.
	* gdbarch.c, gdbarch.h: Re-generated.
	* target.c (memory_xfer_partial): Call address_significant.
	* utils.c (address_significant): New function.
	* utils.h (address_significant): Declare.

2017-12-08  Yao Qi  <yao.qi@linaro.org>

gdb/testsuite:

	* gdb.arch/aarch64-tagged-pointer.c: New file.
	* gdb.arch/aarch64-tagged-pointer.exp: New file.
2017-12-08 17:27:03 +00:00