binutils-gdb.git
7 years ago[GDBserver] Use pre-generated tdesc as test
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
[GDBserver] Use pre-generated tdesc as test

Now, these *-generate.c files are only used in GDBserver for unit test.
If $development is false (in release), these *-generate.c files won't be
used at all.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* configure.srv: Set srv_i386_linux_regobj empty if $development
is false.
* linux-i386-ipa.c (initialize_low_tracepoint): Don't call
initialize_low_tdesc.
* linux-x86-low.c (initialize_low_arch): Wrap initialize_low_tdesc
with #if initialize_low_tdesc.
* linux-x86-tdesc-selftest.c: New file.
* linux-x86-tdesc.c: Move code to linux-x86-tdesc-selftest.c.

7 years agoRemove features/i386/i386-*linux.c
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
Remove features/i386/i386-*linux.c

Now, features/i386/i386-XXX-linux.c are not used, remove them.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* features/Makefile (XMLTOC): Remove i386/i386-XX-linux.xml.
* features/i386/i386-avx-avx512-linux.c: Remove.
* features/i386/i386-avx-linux.c: Remove.
* features/i386/i386-avx-mpx-avx512-pku-linux.c: Remove.
* features/i386/i386-avx-mpx-linux.c: Remove.
* features/i386/i386-linux.c: Remove.
* features/i386/i386-mmx-linux.c: Remove.
* features/i386/i386-mpx-linux.c: Remove.

7 years agoShare i386-linux target description between GDB and GDBserver
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
Share i386-linux target description between GDB and GDBserver

The code on creating i386-linux target descriptions are quite similar
between GDB and GDBserver, so this patch moves them into a shared file
arch/i386.c.  I didn't name it as i386-linux.c, because I want to reuse it
to create other i386 non-linux target descriptions later.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* Makefile.in (ALL_TARGET_OBS): Add i386.o.
(SFILES): Add arch/i386.c.
(HFILES_NO_SRCDIR): Add arch/i386.h.
* arch/i386.c: New file.
* arch/i386.h: New file.
* arch/tdesc.h (allocate_target_description): Declare.
(set_tdesc_architecture): Declare.
(set_tdesc_osabi): Declare.
* configure.tgt (i[34567]86-*-linux*): Add i386.o.
* i386-linux-tdep.c: Don't include ../features/i386/32bit-XXX.c.
include arch/i386.h.
(i386_linux_read_description): Remove code and call
i386_create_target_description.
(set_tdesc_architecture): New function.
(set_tdesc_osabi): New function.
* target-descriptions.h (allocate_target_description): Remove.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* Makefile.in (arch-i386.o): New rule.
* configure.srv (i[34567]86-*-linux*): Add arch-i386.o.
(x86_64-*-linux*): Likewise.
* linux-x86-tdesc.c: Don't include ../features/i386/32bit-XXX.c,
include arch/i386.h.
(i386_linux_read_description): Remove code and call
i386_create_target_description.
* tdesc.c (allocate_target_description): New function.
* tdesc.h (set_tdesc_architecture): Remove declaration.
(set_tdesc_osabi): Likewise.

7 years agoDynamically composite xml in reply to GDB
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
Dynamically composite xml in reply to GDB

GDBserver still uses pre-generated target descriptions in order to
reply to GDB's query on target description (see xml-builtin-generated.c
in GDBserver build directory).  This patch teaches GDBserver to
create XML contents according to the target descriptions rather than
using pre-generated ones.

First, change target feature c files to pass the feature xml file
name to tdesc_create_feature, so that target description in GDBserver
can record them, and create XML contents from these features in
buffer, like

  ...
  <xi:include href="$FEATURE1_XML_NAME"/>
  <xi:include href="$FEATURE2_XML_NAME"/>
  ...

and send this buffer back to GDB.

Note that this patch reuses target_desc.xmltarget a little bit, which is
to hold the XML contents dynamically generated in tdesc_get_features_xml.
However, it is not xfree'ed in ~target_desc, because we can't tell it is
from xstrdup or a literal string.  Since we don't delete target_desc,
there is no memory leak yet.  After we change all target descriptions to
the new style, target_desc.xmltarget is from xstrdup, then, we can safely
xfree it in ~target_desc.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* arch/tdesc.h (tdesc_create_feature): Add an argument xml.
* target-descriptions.c (tdesc_create_feature): Likewise, and
adjust code.
* features/i386/32bit-avx.c: Re-generated.
* features/i386/32bit-avx512.c: Re-generated.
* features/i386/32bit-core.c: Re-generated.
* features/i386/32bit-linux.c: Re-generated.
* features/i386/32bit-mpx.c: Re-generated.
* features/i386/32bit-pkeys.c: Re-generated.
* features/i386/32bit-sse.c: Re-generated.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* linux-x86-tdesc.c: Don't include <inttypes.h>.
(i386_linux_read_description) [!IN_PROCESS_AGENT]: Call
set_tdesc_architecture and set_tdesc_osabi.  Remove code setting
.xmltarget.
* server.c (get_features_xml): Call tdesc_get_features_xml.
* tdesc.c (set_tdesc_architecture): New function.
(set_tdesc_osabi): New function.
(tdesc_get_features_xml): New function.
(tdesc_create_feature): Add an argument.
* tdesc.h (struct target_desc) <features>: New field.
<arch, osabi>: New field.
(~target_desc): xfree features, arch, and osabi.
(target_desc::oerator==): Don't compare .xmltarget.
[!IN_PROCESS_AGENT] (set_tdesc_architecture): Declare.
(set_tdesc_osabi): Likewise.
(tdesc_get_features_xml): Likewise.

7 years ago[GDBserver] unit test to i386_tdesc
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
[GDBserver] unit test to i386_tdesc

This patch adds a unit test in GDBserver to test dynamically created
target descriptions equal these pre-generated ones.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* linux-x86-tdesc.c: Include selftest.h.
(i386_tdesc_test): New function.
(initialize_low_tdesc): Call selftests::register_test.
* tdesc.h: Include regdef.h.
(target_desc): Override operator == and !=.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* regformats/regdef.h (struct reg): Override operator == and !=.

7 years ago[GDBserver] Centralize tdesc for i386-linux
Yao Qi [Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)]
[GDBserver] Centralize tdesc for i386-linux

tdesc_i386_XXX_linux is used in many places in linux-x86-low.c and this
patch adds a new function i386_linux_read_description to return the right
tdesc according to xcr0.  i386_linux_read_description is quite similar to
the counterpart in GDB, and the following patch will share the duplicated
code, so this patch adds arch/tdesc.h includes the declarations of various
tdesc apis which are used by the shared code.  The generated c feature
files can include arch/tdesc.h only.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* configure.srv (srv_tgtobj): Append linux-x86-tdesc.o.
(ipa_obj): Likewise.
* linux-i386-ipa.c: Include common/x86-xstate.h
(get_ipa_tdesc): Call i386_linux_read_description.
(initialize_low_tracepoint): Don't call  init_registers_XXX
functions, call initialize_low_tdesc instead.
* linux-x86-low.c (x86_linux_read_description): Call
i386_linux_read_description.
(initialize_low_arch): Don't call init_registers_i386_XXX
functions, call initialize_low_tdesc.
* linux-x86-tdesc.c: New file.
* linux-x86-tdesc.h (x86_linux_tdesc): New X86_TDESC_LAST.
(i386_get_ipa_tdesc_idx): Declare.
(i386_get_ipa_tdesc): Declare.
(initialize_low_tdesc): Declare.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* arch/tdesc.h: New file.
* regformats/regdat.sh: Generate code using tdesc_create_reg.
* target-descriptions.c: Update comments.
* target-descriptions.h: Include "arch/tdesc.h".  Remove the
declarations.
* features/i386/32bit-avx.c: Re-generated.
* features/i386/32bit-avx512.c: Re-generated.
* features/i386/32bit-core.c: Re-generated.
* features/i386/32bit-linux.c: Re-generated.
* features/i386/32bit-mpx.c: Re-generated.
* features/i386/32bit-pkeys.c: Re-generated.
* features/i386/32bit-sse.c: Re-generated.

7 years agoReturn X86_TDESC_MMX in x86_get_ipa_tdesc_idx
Yao Qi [Tue, 5 Sep 2017 08:54:52 +0000 (09:54 +0100)]
Return X86_TDESC_MMX in x86_get_ipa_tdesc_idx

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* linux-x86-low.c (x86_get_ipa_tdesc_idx): Use X86_TDESC_MMX
instead of 0.

7 years agoUse VEC for target_desc.reg_defs
Yao Qi [Tue, 5 Sep 2017 08:54:52 +0000 (09:54 +0100)]
Use VEC for target_desc.reg_defs

Nowadays, target_desc.reg_defs is a pointer points to a pre-generated
array, which is not flexible.  This patch changes it from an array
to a VEC so that GDBserver can create target descriptions dynamically
later.  Instead of using pre-generated array, the -generated.c calls
VEC_safe_push to add each register to vector.

Since target_desc.reg_defs is used in IPA, we need to build common/vec.c
for IPA too.

gdb/gdbserver:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* Makefile.in (IPA_OBJS): Add vec-ipa.o
* regcache.c (get_thread_regcache): Use VEC_length.
(init_register_cache): Likewise.
(regcache_cpy): Likewise.
(registers_to_string): Iterate reg_defs via VEC_iterate.
(find_regno): Likewise.
(find_register_by_number): Use VEC_index.
(register_size): Call find_register_by_number.
(register_data): Call find_register_by_number.
(supply_regblock): Use VEC_length.
(regcache_raw_read_unsigned): Likewise.
* tdesc.c (init_target_desc): Iterate reg_defs via
VEC_iterate.
(default_description): Update initializer.
(copy_target_description): Don't update field num_registers.
* tdesc.h (struct target_desc) <reg_defs>: Change it to VEC.
<num_registers>: Remove.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* regformats/regdat.sh: Update generated code.

7 years agoAdjust code generated by regformats/regdat.sh
Yao Qi [Tue, 5 Sep 2017 08:54:52 +0000 (09:54 +0100)]
Adjust code generated by regformats/regdat.sh

regformats/regdat.sh generate some *-generated.c files when GDBserver
is built.  Each .c file has some static variables, which are only used
within function init_registers_XXX, like this,

static struct reg regs_i386_linux[] = {
  { "eax", 0, 32 },
  { "ecx", 32, 32 },
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

void
init_registers_i386_linux (void)
{
  ...
}

This patch moves these static variables' definitions to function
init_registers_XXX, so the generated files look like this,

void
init_registers_i386_linux (void)
{
  static struct target_desc tdesc_i386_linux_s;
  struct target_desc *result = &tdesc_i386_linux_s;
static struct reg regs_i386_linux[] = {
  ...
};

static const char *expedite_regs_i386_linux[] = { "ebp", "esp", "eip", 0 };
static const char *xmltarget_i386_linux = "i386-linux.xml";

  ...
}

We want GDBserver create target descriptions dynamically in each
init_registers_XXXX functions, so this patch moves all the related code
into function init_registers_XXXX, so that the following patch can easily
change function init_registers_XXXX to create target description
dynamically, rather than using current pre-generated array.

gdb:

2017-09-05  Yao Qi  <yao.qi@linaro.org>

* regformats/regdat.sh: Adjust code order.

7 years agoexpprint: Fix format string warning
Simon Marchi [Tue, 5 Sep 2017 07:00:42 +0000 (09:00 +0200)]
expprint: Fix format string warning

My compiler (gcc 5.4.0, clang 3.8) gives this warning:

/home/emaisin/src/binutils-gdb/gdb/expprint.c: In lambda function:
/home/emaisin/src/binutils-gdb/gdb/expprint.c:1055:35: error: format not a string literal and no format arguments [-Werror=format-security]
      fprintf_filtered (stream, mod);
                                   ^

Fix it by not using the passed string as the format string.

gdb/ChangeLog:

* expprint.c (dump_subexp_body_standard): Use constant format
string in fprintf_filtered call.

7 years agoDefine an error function in the PPC simulator library.
John Baldwin [Tue, 5 Sep 2017 02:53:50 +0000 (19:53 -0700)]
Define an error function in the PPC simulator library.

Previously this used the error function from GDB directly when linked
against GDB instead of the error method in the host callbacks
structure.  This was exposed via a link error when GDB was converted
to C++.  The error function invokes the error callback similar to
sim_io_error.

Note that there are also error functions in sim/ppc/main.c and
sim/ppc/misc.c.  The ppc libsim.a expects each consumer to provide
several symbols used by the library including "error".  sim-calls.c
provides these symbols when the library is linked into gdb.  The dgen,
igen, tmp-filter, tmp-ld-decode, tmp-ld-cache, and tmp-ld-insn programs
use the functions from misc.c.  psim uses the functions from main.c.

sim/ppc/ChangeLog:

PR sim/20863
* sim_calls.c (error): New function.

7 years agoEnable support for x86 debug registers on NetBSD.
John Baldwin [Tue, 5 Sep 2017 02:34:48 +0000 (19:34 -0700)]
Enable support for x86 debug registers on NetBSD.

NetBSD recently added PT_GETDBREGS and PT_SETDBREGS ptrace operations
that match the existing ones supported by x86-bsd-nat.c.  NetBSD's
headers do not provide the DBREG_DRX helper macro, so define a local
version in x86-bsd-nat.c.  In addition, add the x86-nat.o and x86-dregs.o
object files to the native NetBSD x86 build targets.

gdb/ChangeLog:

* configure.nat: Add "x86-nat.o x86-dregs.o" for NetBSD/amd64 and
NetBSD/i386.
* x86-bsd-nat.c [!DBREG_DRX && __NetBSD__]: Define DBREG_DRX.

7 years agoMake <sys/user.h> include in bsd-kvm.c conditional on HAVE_SYS_USER_H.
John Baldwin [Tue, 5 Sep 2017 02:34:48 +0000 (19:34 -0700)]
Make <sys/user.h> include in bsd-kvm.c conditional on HAVE_SYS_USER_H.

NetBSD has recently removed <sys/user.h>.

gdb/ChangeLog:

* bsd-kvm.c: Make <sys/user.h> conditional on HAVE_SYS_USER_H.

7 years agoDefine _KMEMUSER before including BSD kernel headers.
John Baldwin [Tue, 5 Sep 2017 02:34:48 +0000 (19:34 -0700)]
Define _KMEMUSER before including BSD kernel headers.

Recent versions of NetBSD hide certain kernel structures needed by the
KVM target from userland unless this macro is defined.

gdb/ChangeLog:

* bsd-kvm.o: Define _KMEMUSER.
* configure.ac: Define _KMEMUSER when checking for "struct lwp".
* configure: Regenerate.

7 years agoInclude "x86-xstate.h" for X86_XSTATE_* constants.
John Baldwin [Tue, 5 Sep 2017 02:31:33 +0000 (19:31 -0700)]
Include "x86-xstate.h" for X86_XSTATE_* constants.

gdb/ChangeLog:

* amd64-fbsd-nat.c: Add include of "x86-xstate.h".
* i386-fbsd-nat.c: Likewise.

7 years agoAutomatic date update in version.in
GDB Administrator [Tue, 5 Sep 2017 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoMissing relocation R_PPC_VLE_ADDR20 and add VLE flag to details in readelf
Alexander Fedotov-B55613 [Mon, 4 Sep 2017 22:52:17 +0000 (08:22 +0930)]
Missing relocation R_PPC_VLE_ADDR20 and add VLE flag to details in readelf

include/
* elf/ppc.h (R_PPC_VLE_ADDR20): New relocation.
bfd/
* elf32-ppc.c (ppc_elf_howto_raw): Add R_PPC_VLE_ADDR20.
(ppc_elf_check_relocs): Handle it.
(ppc_elf_vle_split20): New function.
(ppc_elf_relocate_section): Handle R_PPC_VLE_ADDR20.
binutils/
* readelf.c (get_elf_section_flags): Add VLE.
(process_section_headers): Add VLE key to details.
gas/
* config/tc-ppc.c (md_parse_option): Handle "mno-vle" flag.
(ppc_elf_section_letter): New function.
* config/tc-ppc.h (md_elf_section_letter): New.
* testsuite/gas/elf/section10.d: Adjust for VLE.

7 years agoExplicitly include <array> for std::array<>.
John Baldwin [Mon, 4 Sep 2017 22:58:38 +0000 (15:58 -0700)]
Explicitly include <array> for std::array<>.

gdb/ChangeLog:

* unittests/array-view-selftests.c: Add include of <array>.

7 years agoCatch up to recent changes to call_function_by_hand().
John Baldwin [Mon, 4 Sep 2017 22:57:02 +0000 (15:57 -0700)]
Catch up to recent changes to call_function_by_hand().

gdb/ChangeLog:

* spu-tdep.c (flush_ea_cache): Add missing argument to
call_function_by_hand.

7 years agoDocument "no debug info debugging" improvements
Pedro Alves [Mon, 4 Sep 2017 19:21:16 +0000 (20:21 +0100)]
Document "no debug info debugging" improvements

Here's the documentation bits for all the improvements done in
previous commits.

Note that the original "weak alias functions" paragraph ends up
disappearing, because this patch, which I'm considering kind of part
of this series, makes the alias case Just Work:
  https://sourceware.org/ml/gdb-patches/2017-07/msg00018.html

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* NEWS (Safer support for debugging with no debug info): New.

gdb/doc/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (Variables) <Program Variables>: Document inspecting
no-debug-info variables.
(Symbols) <Examining the Symbol Table>: Document inspecting
no-debug-info types.
(Calling) <Calling functions with no debug info>: New subsection,
documenting calling no-debug-info functions.
(Non-debug DLL Symbols) <Working with Minimal Symbols>: Update.

7 years agoMake "p S::method() const::static_var" work too
Pedro Alves [Mon, 4 Sep 2017 19:21:16 +0000 (20:21 +0100)]
Make "p S::method() const::static_var" work too

Trying to print a function local static variable of a const-qualified
method still doesn't work after the previous fixes:

  (gdb) p 'S::method() const'::static_var
  $1 = {i1 = 1, i2 = 2, i3 = 3}
  (gdb) p S::method() const::static_var
  No symbol "static_var" in specified context.

The reason is that the expression parser/evaluator loses the "const",
and the above unquoted case is just like trying to print a variable of
the non-const overload, if it exists, even.  As if the above unquoted
case had been written as:

  (gdb) p S::method()::static_var
  No symbol "static_var" in specified context.

We can see the problem without static vars in the picture.  With:

 struct S
 {
    void method ();
    void method () const;
 };

Compare:

  (gdb) print 'S::method(void) const'
  $1 = {void (const S * const)} 0x400606 <S::method() const>
  (gdb) print S::method(void) const
  $2 = {void (S * const)} 0x4005d8 <S::method()>   # wrong method!

That's what we need to fix.  If we fix that, the function local static
case starts working.

The grammar production for function/method types is this one:

  exp:       exp '(' parameter_typelist ')' const_or_volatile

This results in a TYPE_INSTANCE expression evaluator operator.  For
the example above, we get something like this ("set debug expression 1"):

...
            0  TYPE_INSTANCE         1 TypeInstance: Type @0x560fda958be0 (void)
            5    OP_SCOPE              Type @0x560fdaa544d8 (S) Field name: `method'
...

While evaluating TYPE_INSTANCE, we end up in
value_struct_elt_for_reference, trying to find the method named
"method" that has the prototype recorded in TYPE_INSTANCE.  In this
case, TYPE_INSTANCE says that we're looking for a method that has
"(void)" as parameters (that's what "1 TypeInstance: Type
@0x560fda958be0 (void)" above means.  The trouble is that nowhere in
this mechanism do we communicate to value_struct_elt_for_reference
that we're looking for the _const_ overload.
value_struct_elt_for_reference only compared parameters, and the
non-const "method()" overload has matching parameters, so it's
considered the right match...

Conveniently, the "const_or_volatile" production in the grammar
already records "const" and "volatile" info in the type stack.  The
type stack is not used in this code path, but we can borrow the
information.  The patch converts the info in the type stack to an
"instance flags" enum, and adds that as another element in
TYPE_INSTANCE operators.  This type instance flags is then applied to
the temporary type that is passed to value_struct_elt_for_reference
for matching.

The other side of the problem is that methods in the debug info aren't
marked const/volatile, so with that in place, the matching never finds
const/volatile-qualified methods.

The problem is that in the DWARF, there's no indication at all whether
a method is const/volatile qualified...  For example (c++filt applied
to the linkage name for convenience):

   <2><d3>: Abbrev Number: 6 (DW_TAG_subprogram)
      <d4>   DW_AT_external    : 1
      <d4>   DW_AT_name        : (indirect string, offset: 0x3df): method
      <d8>   DW_AT_decl_file   : 1
      <d9>   DW_AT_decl_line   : 58
      <da>   DW_AT_linkage_name: (indirect string, offset: 0x5b2): S::method() const
      <de>   DW_AT_declaration : 1
      <de>   DW_AT_object_pointer: <0xe6>
      <e2>   DW_AT_sibling     : <0xec>

I see the same with both GCC and Clang.  The patch works around this
by extracting the cv qualification from the "const" and "volatile" in
the demangled name.  This will need further tweaking for "&" and
"const &" overloads, but we don't support them in the parser yet,
anyway.

The TYPE_CONST changes were necessary otherwise the comparisons in valops.c:

  if (TYPE_CONST (intype) != TYPE_FN_FIELD_CONST (f, j))
    continue;

would fail, because when both TYPE_CONST() TYPE_FN_FIELD_CONST() were
true, their values were different.

BTW, I'm recording the const/volatile-ness of methods in the
TYPE_FN_FIELD info because #1 - I'm not sure it's kosher to change the
method's type directly (vs having to call make_cv_type to create a new
type), and #2 it's what stabsread.c does:

...
    case 'A': /* Normal functions.  */
      new_sublist->fn_field.is_const = 0;
      new_sublist->fn_field.is_volatile = 0;
      (*pp)++;
      break;
    case 'B': /* `const' member functions.  */
      new_sublist->fn_field.is_const = 1;
      new_sublist->fn_field.is_volatile = 0;
...

After all this, this finally all works:

  print S::method(void) const
  $1 = {void (const S * const)} 0x400606 <S::method() const>
  (gdb) p S::method() const::static_var
  $2 = {i1 = 1, i2 = 2, i3 = 3}

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* c-exp.y (function_method, function_method_void): Add current
instance flags to TYPE_INSTANCE.
* dwarf2read.c (check_modifier): New.
(compute_delayed_physnames): Assert that only C++ adds delayed
physnames.  Mark fn_fields as const/volatile depending on
physname.
* eval.c (make_params): New type_instance_flags parameter.  Use
it as the new type's instance flags.
(evaluate_subexp_standard) <TYPE_INSTANCE>: Extract the instance
flags element and pass it to make_params.
* expprint.c (print_subexp_standard) <TYPE_INSTANCE>: Handle
instance flags element.
(dump_subexp_body_standard) <TYPE_INSTANCE>: Likewise.
* gdbtypes.h: Include "enum-flags.h".
(type_instance_flags): New enum-flags type.
(TYPE_CONST, TYPE_VOLATILE, TYPE_RESTRICT, TYPE_ATOMIC)
(TYPE_CODE_SPACE, TYPE_DATA_SPACE): Return boolean.
* parse.c (operator_length_standard) <TYPE_INSTANCE>: Adjust.
(follow_type_instance_flags): New function.
(operator_check_standard) <TYPE_INSTANCE>: Adjust.
* parser-defs.h (follow_type_instance_flags): Declare.
* valops.c (value_struct_elt_for_reference): const/volatile must
match too.

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

* gdb.base/func-static.c (S::method const, S::method volatile)
(S::method volatile const): New methods.
(c_s, v_s, cv_s): New instances.
(main): Call method() on them.
* gdb.base/func-static.exp (syntax_re, cannot_resolve_re): New variables.
(cannot_resolve): New procedure.
(cxx_scopes_list): Test cv methods.  Add print-scope-quote and
print-quote-unquoted columns.
(do_test): Test printing each scope too.

7 years agoHandle "p 'S::method()::static_var'" (quoted) in symbol lookup
Pedro Alves [Mon, 4 Sep 2017 19:21:16 +0000 (20:21 +0100)]
Handle "p 'S::method()::static_var'" (quoted) in symbol lookup

While the previous commit made "p method()::static_var" (no
single-quotes) Just Work, if users (or frontends) try wrapping the
expression with quotes, they'll get:

  (gdb) p 'S::method()::static_var'
  'S::method()::static_var' has unknown type; cast it to its declared type

even if we _do_ have debug info for that variable.  That's better than
the bogus/confusing value what GDB would print before the
stop-assuming-int patch:

  (gdb) p 'S::method()::static_var'
  $1 = 1

but I think it'd still be nice to make this case Just Work too.

In this case, due to the quoting, the C/C++ parser (c-exp.y)
interprets the whole expression/string as a single symbol name, and we
end up calling lookup_symbol on that name.  There's no debug symbol
with that fully-qualified name, but since the compiler gives the
static variable a mangled linkage name exactly like the above, it
appears in the mininal symbols:

  $ nm -A local-static | c++filt | grep static_var
  local-static:0000000000601040 d S::method()::static_var

... and that's what GDB happens to find/print.  This only happens in
C++, note, since for C the compiler uses different linkage names:

  local-static-c:0000000000601040 d static_var.1848

So while (in C++, not C) function local static variables are given a
mangled name that demangles to the same syntax that GDB
documents/expects as the way to access function local statics, there's
no global symbol in the debug info with that name at all.  The debug
info for a static local variable for a non-inline function looks like
this:

 <1><2a1>: Abbrev Number: 19 (DW_TAG_subprogram)
 ...
 <2><2f7>: Abbrev Number: 20 (DW_TAG_variable)
    <2f8>   DW_AT_name        : (indirect string, offset: 0x4e9): static_var
    <2fc>   DW_AT_decl_file   : 1
    <2fd>   DW_AT_decl_line   : 64
    <2fe>   DW_AT_type        : <0x25>
    <302>   DW_AT_location    : 9 byte block: 3 40 10 60 0 0 0 0 0      (DW_OP_addr: 601040)

and for an inline function, it looks like this (linkage name run
through c++filt for convenience):

 <2><21b>: Abbrev Number: 16 (DW_TAG_variable)
    <21c>   DW_AT_name        : (indirect string, offset: 0x21a): static_var
    <220>   DW_AT_decl_file   : 1
    <221>   DW_AT_decl_line   : 48
    <222>   DW_AT_linkage_name: (indirect string, offset: 0x200): S::inline_method()::static_var
    <226>   DW_AT_type        : <0x25>
    <22a>   DW_AT_external    : 1
    <22a>   DW_AT_location    : 9 byte block: 3 a0 10 60 0 0 0 0 0      (DW_OP_addr: 6010a0)

(The inline case makes the variable external so that the linker can
merge the different inlined copies.  It seems like GCC never outputs
the linkage name for non-extern globals.)

When we read the DWARF, we record the static_var variable as a regular
variable of the containing function's block.  This makes stopping in
the function and printing the variable as usual.  The variable just so
happens to have a memory address as location.

So one way to make "p 'S::method()::static_var'" work would be to
record _two_ copies of the symbols for these variables.  One in the
function's scope/block, with "static_var" as name, as we currently do,
and another in the static or global blocks (depending on whether the
symbol is external), with a fully-qualified name.  I wrote a prototype
patch for that, and it works.  For the non-inline case above, since
the debug info doesn't point to the linkage same, that patch built the
physname of the static local variable as the concat of the physname of
the containing function, plus "::", plus the variable's name.  We
could make that approach work for C too, though it kind of feels
awkward to record fake symbol names like that in C.

The other approach I tried is to change the C++ symbol lookup routines
instead.  This is the approach this commit takes.  We can already
lookup up symbol in namespaces and classes, so this feels like a good
fit, and was easy enough.  The advantage is that this doesn't require
recording extra symbols.

The test in gdb.cp/m-static.exp that exposed the need for this is
removed, since the same functionality is now covered by
gdb.cp/local-static.exp.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* cp-namespace.c (cp_search_static_and_baseclasses): Handle
function/method scopes; lookup the nested name as a function local
static variable.

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

* gdb.base/local-static.exp: Also test with
class::method::variable wholly quoted.
* gdb.cp/m-static.exp (class::method::variable): Remove test.

7 years agoHandle "p S::method()::static_var" in the C++ parser
Pedro Alves [Mon, 4 Sep 2017 19:21:15 +0000 (20:21 +0100)]
Handle "p S::method()::static_var" in the C++ parser

This commit makes "print S::method()::static_var" actually find the
debug symbol for static_var.  Currently, you get:

  (gdb) print S::method()::static_var
  A syntax error in expression, near `'.

Quoting the whole string would seemingly work before the previous
patch that made GDB stop assuming int for no-debug-info variables:

  (gdb) p 'S::method()::static_var'
  $1 = 1

... except that's incorrect output, because:

  (gdb) ptype 'S::method()::static_var'
  type = <data variable, no debug info>

The way to make it work correctly currently is by quoting the
function/method part, like this:

  (gdb) print 'S::method()'::static_var
  $1 = {i1 = 1, i2 = 2, i3 = 3}
  (gdb) ptype 'S::method()'::static_var
  type = struct aggregate {
      int i1;
      int i2;
      int i3;
  }

At least after the "stop assuming int" patch, this is what we
now get:

  (gdb) p 'S::method()::static_var'
  'S::method()::static_var' has unknown type; cast it to its declared type
  (gdb) p (struct aggregate) 'S::method()::static_var'
  $1 = {i1 = 1, i2 = 2, i3 = 3}

However, IMO, users shouldn't really have to care about any of this.
GDB should Just Work, without quoting, IMO.

So here's a patch that implements support for that in the C++ parser.
With this patch, you now get:

  (gdb) p S::method()::S_M_s_var_aggregate
  $1 = {i1 = 1, i2 = 2, i3 = 3}
  (gdb) ptype S::method()::S_M_s_var_aggregate
  type = struct aggregate {
      int i1;
      int i2;
      int i3;
  }

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

(%type <voidval>): Add function_method.
* c-exp.y (exp): New production for calls with no arguments.
(function_method, function_method_void_or_typelist): New
productions.
(exp): New production for "method()::static_var".
* eval.c (evaluate_subexp_standard): Handle OP_FUNC_STATIC_VAR.
* expprint.c (print_subexp_standard, dump_subexp_body_standard):
Handle OP_FUNC_STATIC_VAR.
* parse.c (operator_length_standard):
Handle OP_FUNC_STATIC_VAR.
* std-operator.def (OP_FUNC_STATIC_VAR): New.

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

* gdb.base/local-static.c: New.
* gdb.base/local-static.cc: New.
* gdb.base/local-static.exp:  New.

7 years agoEliminate UNOP_MEMVAL_TLS
Pedro Alves [Mon, 4 Sep 2017 19:21:15 +0000 (20:21 +0100)]
Eliminate UNOP_MEMVAL_TLS

Since minsym references now go via OP_VAR_MSYM_VALUE, UNOP_MEMVAL_TLS
is no longer used anywhere.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* eval.c (evaluate_subexp_standard): Remove UNOP_MEMVAL_TLS
handling.
* expprint.c (print_subexp_standard, dump_subexp_body_standard):
Ditto.
* parse.c (operator_length_standard, operator_check_standard):
Ditto.
* std-operator.def (UNOP_MEMVAL_TLS): Delete.

7 years agoStop assuming no-debug-info variables have type int
Pedro Alves [Mon, 4 Sep 2017 19:21:15 +0000 (20:21 +0100)]
Stop assuming no-debug-info variables have type int

An earlier commit made GDB no longer assume no-debug-info functions
return int.  This commit gives the same treatment to variables.

Currently, you can end misled by GDB over output like this:

  (gdb) p var
  $1 = -1
  (gdb) p /x var
  $2 = 0xffffffff

until you realize that GDB is assuming that the variable is an "int",
because:

  (gdb) ptype var
  type = <data variable, no debug info>

You may try to fix it by casting, but that doesn't really help:

  (gdb) p /x (unsigned long long) var
  $3 = 0xffffffffffffffff            # incorrect
         ^^

That's incorrect output, because the variable was defined like this:

  uint64_t var = 0x7fffffffffffffff;
                   ^^

What happened is that with the cast, GDB did an int -> 'unsigned long
long' conversion instead of reinterpreting the variable as the cast-to
type.  To get at the variable properly you have to reinterpret the
variable's address manually instead, with either:

  (gdb) p /x *(unsigned long long *) &var
  $4 = 0x7fffffffffffffff
  (gdb) p /x {unsigned long long} &var
  $5 = 0x7fffffffffffffff

After this commit GDB does it for you.  This is what you'll get
instead:

  (gdb) p var
  'var' has unknown type; cast it to its declared type
  (gdb) p /x (unsigned long long) var
  $1 = 0x7fffffffffffffff

As in the functions patch, the "compile" machinery doesn't currently
have the cast-to type handy, so it continues assuming no-debug
variables have int type, though now at least it warns.

The change to gdb.cp/m-static.exp deserves an explanation:

 - gdb_test "print 'gnu_obj_1::method()::sintvar'" "\\$\[0-9\]+ = 4" \
 + gdb_test "print (int) 'gnu_obj_1::method()::sintvar'" "\\$\[0-9\]+ = 4" \

That's printing the "sintvar" function local static of the
"gnu_obj_1::method()" method.

The problem with that test is that that "'S::method()::static_var'"
syntax doesn't really work in C++ as you'd expect.  The way to make it
work correctly currently is to quote the method part, not the whole
expression, like:

  (gdb) print 'gnu_obj_1::method()'::sintvar

If you wrap the whole expression in quotes, like in m-static.exp, what
really happens is that the parser considers the whole string as a
symbol name, but there's no debug symbol with that name.  However,
local statics have linkage and are given a mangled name that demangles
to the same string as the full expression, so that's what GDB prints.
After this commit, and without the cast, the print in m-static.exp
would error out saying that the variable has unknown type:

  (gdb) p 'gnu_obj_1::method()::sintvar'
  'gnu_obj_1::method()::sintvar' has unknown type; cast it to its declared type

TBC, if currently (even before this series) you try to print any
function local static variable of type other than int, you'll get
bogus results.  You can see that with m-static.cc as is, even.
Printing the "svar" local, which is a boolean (1 byte) still prints as
"int" (4 bytes):

  (gdb) p 'gnu_obj_1::method()::svar'
  $1 = 1
  (gdb) ptype 'gnu_obj_1::method()::svar'
  type = <data variable, no debug info>

This probably prints some random bogus value on big endian machines.

If 'svar' was of some aggregate type (etc.) we'd still print it as
int, so the problem would have been more obvious...  After this
commit, you'll get instead:

  (gdb) p 'gnu_obj_1::method()::svar'
  'gnu_obj_1::method()::svar' has unknown type; cast it to its declared type

... so at least GDB is no longer misleading.  Making GDB find the real
local static debug symbol is the subject of the following patches.  In
the end, it'll all "Just Work".

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* ax-gdb.c: Include "typeprint.h".
(gen_expr_for_cast): New function.
(gen_expr) <OP_CAST, OP_CAST_TYPE>: Use it.
<OP_VAR_VALUE, OP_MSYM_VAR_VALUE>: Error out if the variable's
type is unknown.
* dwarf2read.c (new_symbol_full): Fallback to int instead of
nodebug_data_symbol.
* eval.c: Include "typeprint.h".
(evaluate_subexp_standard) <OP_VAR_VALUE, OP_VAR_MSYM_VALUE>:
Error out if symbol has unknown type.
<UNOP_CAST, UNOP_CAST_TYPE>: Common bits factored out to
evaluate_subexp_for_cast.
(evaluate_subexp_for_address, evaluate_subexp_for_sizeof): Handle
OP_VAR_MSYM_VALUE.
(evaluate_subexp_for_cast): New function.
* gdbtypes.c (init_nodebug_var_type): New function.
(objfile_type): Use it to initialize types of variables with no
debug info.
* typeprint.c (error_unknown_type): New.
* typeprint.h (error_unknown_type): New declaration.
* compile/compile-c-types.c (convert_type_basic): Handle
TYPE_CODE_ERROR; warn and fallback to int for variables with
unknown type.

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

* gdb.asm/asm-source.exp: Add casts to int.
* gdb.base/nodebug.c (dataglobal8, dataglobal32_1, dataglobal32_2)
(dataglobal64_1, dataglobal64_2): New globals.
* gdb.base/nodebug.exp: Test different expressions involving the
new globals, with print, whatis and ptype.  Add casts to int.
* gdb.base/solib-display.exp: Add casts to int.
* gdb.compile/compile-ifunc.exp: Expect warning.  Add cast to int.
* gdb.cp/m-static.exp: Add cast to int.
* gdb.dwarf2/dw2-skip-prologue.exp: Add cast to int.
* gdb.threads/tls-nodebug.exp: Check that gdb errors out printing
tls variable with no debug info without a cast.  Test with a cast
to int too.
* gdb.trace/entry-values.exp: Add casts.

7 years agoevaluate_subexp_standard: Factor out OP_VAR_VALUE handling.
Pedro Alves [Mon, 4 Sep 2017 19:21:14 +0000 (20:21 +0100)]
evaluate_subexp_standard: Factor out OP_VAR_VALUE handling.

A following patch will want to call the new evaluate_var_value
function in another spot.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* eval.c (evaluate_var_value): New function, factored out from ...
(evaluate_subexp_standard): ... here.

7 years agoevaluate_subexp_standard: Remove useless assignments
Pedro Alves [Mon, 4 Sep 2017 19:21:14 +0000 (20:21 +0100)]
evaluate_subexp_standard: Remove useless assignments

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* eval.c (evaluate_subexp_standard) <UNOP_COMPLEMENT, UNOP_ADDR>:
Remove useless assignments to 'op'.

7 years agoevaluate_subexp_standard: Eliminate one goto
Pedro Alves [Mon, 4 Sep 2017 19:21:14 +0000 (20:21 +0100)]
evaluate_subexp_standard: Eliminate one goto

A following patch will want to factor out a bit of
evaluate_subexp_standard, and it'd be handy to reuse the code under the
"nosideret:" label there too.  This commits moves it to a separate
function as preparation for that.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* eval.c (eval_skip_value): New function.
(evaluate_subexp_standard): Use it.

7 years agoMake ptype/whatis print function name of functions with no debug info too
Pedro Alves [Mon, 4 Sep 2017 19:21:14 +0000 (20:21 +0100)]
Make ptype/whatis print function name of functions with no debug info too

The patch to make GDB stop assuming functions return int left GDB with
an inconsistency.  While with normal expression evaluation the
"unknown return type" error shows the name of the function that misses
debug info:

  (gdb) p getenv ("PATH")
  'getenv' has unknown return type; cast the call to its declared return type
   ^^^^^^

which is handy in more complicated expressions, "ptype" does not:

  (gdb) ptype getenv ("PATH")
  function has unknown return type; cast the call to its declared return type
  ^^^^^^^^

This commit builds on the new OP_VAR_MSYM_VALUE to fix it, by making
OP_FUNCALL extract the function name from the symbol stored in
OP_VAR_VALUE/OP_VAR_MSYM_VALUE.  We now get the same error in "print"
vs "ptype":

  (gdb) ptype getenv()
  'getenv' has unknown return type; cast the call to its declared return type
  (gdb) p getenv()
  'getenv' has unknown return type; cast the call to its declared return type

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* eval.c (evaluate_subexp_standard): <OP_FUNCALL>: Extract
function name from symbol/minsym and pass it to
error_call_unknown_return_type.

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

* gdb.base/nodebug.exp: Test that ptype's error about functions
with unknown return type includes the function name too.

7 years agoIntroduce OP_VAR_MSYM_VALUE
Pedro Alves [Mon, 4 Sep 2017 19:21:13 +0000 (20:21 +0100)]
Introduce OP_VAR_MSYM_VALUE

The previous patch left GDB with an inconsistency.  While with normal
expression evaluation the "unknown return type" error shows the name
of the function that misses debug info:

  (gdb) p getenv ("PATH")
  'getenv' has unknown return type; cast the call to its declared return type
   ^^^^^^

which can by handy in more complicated expressions, "ptype" does not:

  (gdb) ptype getenv ("PATH")
  function has unknown return type; cast the call to its declared return type
  ^^^^^^^^

This commit is a step toward fixing it.

The problem is that while evaluating the expression above, we have no
reference to the minimal symbol where we could extract the name from.
This is because the resulting expression tree has no reference to the
minsym at all.  During parsing, the type and address of the minsym are
extracted and an UNOP_MEMVAL / UNOP_MEMVAL_TLS operator is generated
(see write_exp_elt_msym).  With "set debug expression", here's what
you see:

            0  OP_FUNCALL            Number of args: 0
            3    UNOP_MEMVAL           Type @0x565334a51930 (<text variable, no debug info>)
            6      OP_LONG               Type @0x565334a51c60 (__CORE_ADDR), value 140737345035648 (0x7ffff7751d80)

The "print" case finds the function name, because
call_function_by_hand looks up the function by address again.
However, for "ptype", we don't reach that code, because obviously we
don't really call the function.

Unlike minsym references, references to variables with debug info have
a pointer to the variable's symbol in the expression tree, with
OP_VAR_VALUE:

  (gdb) ptype main()
  ...
            0  OP_FUNCALL            Number of args: 0
            3    OP_VAR_VALUE          Block @0x0, symbol @0x559bbbd9b358 (main(int, char**))
  ...

so I don't see why do minsyms need to be different.  So to prepare for
fixing the missing function name issue, this commit adds a new
OP_VAR_MSYM_VALUE operator that mimics OP_VAR_VALUE, except that it's
for minsyms instead of debug symbols.  For infcalls, we now get
expressions like these:

            0  OP_FUNCALL            Number of args: 0
            3    OP_VAR_MSYM_VALUE     Objfile @0x1e41bf0, msymbol @0x7fffe599b000 (getenv)

In the following patch, we'll make OP_FUNCALL extract the function
name from the symbol stored in OP_VAR_VALUE/OP_VAR_MSYM_VALUE.

OP_VAR_MSYM_VALUE will be used more in a later patch in the series
too.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* ada-lang.c (resolve_subexp): Handle OP_VAR_MSYM_VALUE.
* ax-gdb.c (gen_msym_var_ref): New function.
(gen_expr): Handle OP_VAR_MSYM_VALUE.
* eval.c (evaluate_var_msym_value): New function.
* eval.c (evaluate_subexp_standard): Handle OP_VAR_MSYM_VALUE.
<OP_FUNCALL>: Extract function name from symbol/minsym and pass it
to call_function_by_hand.
* expprint.c (print_subexp_standard, dump_subexp_body_standard):
Handle OP_VAR_MSYM_VALUE.
(union exp_element) <msymbol>: New field.
* minsyms.h (struct type): Forward declare.
(find_minsym_type_and_address): Declare.
* parse.c (write_exp_elt_msym): New function.
(write_exp_msymbol): Delete, refactored as ...
(find_minsym_type_and_address): ... this new function.
(write_exp_msymbol): Reimplement using OP_VAR_MSYM_VALUE.
(operator_length_standard, operator_check_standard): Handle
OP_VAR_MSYM_VALUE.
* std-operator.def (OP_VAR_MSYM_VALUE): New.

7 years agoStop assuming no-debug-info functions return int
Pedro Alves [Mon, 4 Sep 2017 19:21:13 +0000 (20:21 +0100)]
Stop assuming no-debug-info functions return int

The fact that GDB defaults to assuming that functions return int, when
it has no debug info for the function has been a recurring source of
user confusion.  Recently this came up on the errno pretty printer
discussions.  Shortly after, it came up again on IRC, with someone
wondering why does getenv() in GDB return a negative int:

  (gdb) p getenv("PATH")
  $1 = -6185

This question (with s/getenv/random-other-C-runtime-function) is a FAQ
on IRC.

The reason for the above is:

 (gdb) p getenv
 $2 = {<text variable, no debug info>} 0x7ffff7751d80 <getenv>
 (gdb) ptype getenv
 type = int ()

... which means that GDB truncated the 64-bit pointer that is actually
returned from getent to 32-bit, and then sign-extended it:

 (gdb) p /x -6185
 $6 = 0xffffe7d7

The workaround is to cast the function to the right type, like:

 (gdb) p ((char *(*) (const char *)) getenv) ("PATH")
 $3 = 0x7fffffffe7d7 "/usr/local/bin:/"...

IMO, we should do better than this.

I see the "assume-int" issue the same way I see printing bogus values
for optimized-out variables instead of "<optimized out>" -- I'd much
rather that the debugger tells me "I don't know" and tells me how to
fix it than showing me bogus misleading results, making me go around
tilting at windmills.

If GDB prints a signed integer when you're expecting a pointer or
aggregate, you at least have some sense that something is off, but
consider the case of the function actually returning a 64-bit integer.
For example, compile this without debug info:

 unsigned long long
 function ()
 {
   return 0x7fffffffffffffff;
 }

Currently, with pristine GDB, you get:

 (gdb) p function ()
 $1 = -1                      # incorrect
 (gdb) p /x function ()
 $2 = 0xffffffff              # incorrect

maybe after spending a few hours debugging you suspect something is
wrong with that -1, and do:

 (gdb) ptype function
 type = int ()

and maybe, just maybe, you realize that the function actually returns
unsigned long long.  And you try to fix it with:

(gdb) p /x (unsigned long long) function ()
 $3 = 0xffffffffffffffff      # incorrect

... which still produces the wrong result, because GDB simply applied
int to unsigned long long conversion.  Meaning, it sign-extended the
integer that it extracted from the return of the function, to 64-bits.

and then maybe, after asking around on IRC, you realize you have to
cast the function to a pointer of the right type, and call that.  It
won't be easy, but after a few missteps, you'll get to it:

.....  (gdb) p /x ((unsigned long long(*) ()) function) ()
 $666 = 0x7fffffffffffffff             # finally! :-)

So to improve on the user experience, this patch does the following
(interrelated) things:

 - makes no-debug-info functions no longer default to "int" as return
   type.  Instead, they're left with NULL/"<unknown return type>"
   return type.

    (gdb) ptype getenv
    type = <unknown return type> ()

 - makes calling a function with unknown return type an error.

    (gdb) p getenv ("PATH")
    'getenv' has unknown return type; cast the call to its declared return type

 - and then to make it easier to call the function, makes it possible
   to _only_ cast the return of the function to the right type,
   instead of having to cast the function to a function pointer:

    (gdb) p (char *) getenv ("PATH")                      # now Just Works
    $3 = 0x7fffffffe7d7 "/usr/local/bin:/"...

    (gdb) p ((char *(*) (const char *)) getenv) ("PATH")  # continues working
    $4 = 0x7fffffffe7d7 "/usr/local/bin:/"...

   I.e., it makes GDB default the function's return type to the type
   of the cast, and the function's parameters to the type of the
   arguments passed down.

After this patch, here's what you'll get for the "unsigned long long"
example above:

 (gdb) p function ()
 'function' has unknown return type; cast the call to its declared return type
 (gdb) p /x (unsigned long long) function ()
 $4 = 0x7fffffffffffffff     # correct!

Note that while with "print" GDB shows the name of the function that
has the problem:

  (gdb) p getenv ("PATH")
  'getenv' has unknown return type; cast the call to its declared return type

which can by handy in more complicated expressions, "ptype" does not:

  (gdb) ptype getenv ("PATH")
  function has unknown return type; cast the call to its declared return type

This will be fixed in the next patch.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* ada-lang.c (ada_evaluate_subexp) <TYPE_CODE_FUNC>: Don't handle
TYPE_GNU_IFUNC specially here.  Throw error if return type is
unknown.
* ada-typeprint.c (print_func_type): Handle functions with unknown
return type.
* c-typeprint.c (c_type_print_base): Handle functions and methods
with unknown return type.
* compile/compile-c-symbols.c (convert_symbol_bmsym)
<mst_text_gnu_ifunc>: Use nodebug_text_gnu_ifunc_symbol.
* compile/compile-c-types.c: Include "objfiles.h".
(convert_func): For functions with unknown return type, warn and
default to int.
* compile/compile-object-run.c (compile_object_run): Adjust call
to call_function_by_hand_dummy.
* elfread.c (elf_gnu_ifunc_resolve_addr): Adjust call to
call_function_by_hand.
* eval.c (evaluate_subexp_standard): Adjust calls to
call_function_by_hand.  Handle functions and methods with unknown
return type.  Pass expect_type to call_function_by_hand.
* f-typeprint.c (f_type_print_base): Handle functions with unknown
return type.
* gcore.c (call_target_sbrk): Adjust call to
call_function_by_hand.
* gdbtypes.c (objfile_type): Leave nodebug text symbol with NULL
return type instead of int.  Make nodebug_text_gnu_ifunc_symbol be
an integer address type instead of nodebug.
* guile/scm-value.c (gdbscm_value_call): Adjust call to
call_function_by_hand.
* infcall.c (error_call_unknown_return_type): New function.
(call_function_by_hand): New "default_return_type" parameter.
Pass it down.
(call_function_by_hand_dummy): New "default_return_type"
parameter.  Use it instead of defaulting to int.  If there's no
default and the return type is unknown, throw an error.  If
there's a default return type, and the called function has no
debug info, then assume the function is prototyped.
* infcall.h (call_function_by_hand, call_function_by_hand_dummy):
New "default_return_type" parameter.
(error_call_unknown_return_type): New declaration.
* linux-fork.c (call_lseek): Cast return type of lseek.
(inferior_call_waitpid, checkpoint_command): Adjust calls to
call_function_by_hand.
* linux-tdep.c (linux_infcall_mmap, linux_infcall_munmap): Adjust
calls to call_function_by_hand.
* m2-typeprint.c (m2_procedure): Handle functions with unknown
return type.
* objc-lang.c (lookup_objc_class, lookup_child_selector)
(value_nsstring, print_object_command): Adjust calls to
call_function_by_hand.
* p-typeprint.c (pascal_type_print_varspec_prefix): Handle
functions with unknown return type.
(pascal_type_print_func_varspec_suffix): New function.
(pascal_type_print_varspec_suffix) <TYPE_CODE_FUNC,
TYPE_CODE_METHOD>: Use it.
* python/py-value.c (valpy_call): Adjust call to
call_function_by_hand.
* rust-lang.c (rust_evaluate_funcall): Adjust call to
call_function_by_hand.
* valarith.c (value_x_binop, value_x_unop): Adjust calls to
call_function_by_hand.
* valops.c (value_allocate_space_in_inferior): Adjust call to
call_function_by_hand.
* typeprint.c (type_print_unknown_return_type): New function.
* typeprint.h (type_print_unknown_return_type): New declaration.

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

* gdb.base/break-main-file-remove-fail.exp (test_remove_bp): Cast
return type of munmap in infcall.
* gdb.base/break-probes.exp: Cast return type of foo in infcall.
* gdb.base/checkpoint.exp: Simplify using for loop.  Cast return
type of ftell in infcall.
* gdb.base/dprintf-detach.exp (dprintf_detach_test): Cast return
type of getpid in infcall.
* gdb.base/infcall-exec.exp: Cast return type of execlp in
infcall.
* gdb.base/info-os.exp: Cast return type of getpid in infcall.
Bail on failure to extract the pid.
* gdb.base/nodebug.c: #include <stdint.h>.
(multf, multf_noproto, mult, mult_noproto, add8, add8_noproto):
New functions.
* gdb.base/nodebug.exp (test_call_promotion): New procedure.
Change expected output of print/whatis/ptype with functions with
no debug info.  Test all supported languages.  Call
test_call_promotion.
* gdb.compile/compile.exp: Adjust expected output to expect
warning.
* gdb.threads/siginfo-threads.exp: Likewise.

7 years agoFix calling prototyped functions via function pointers
Pedro Alves [Mon, 4 Sep 2017 19:21:13 +0000 (20:21 +0100)]
Fix calling prototyped functions via function pointers

Calling a prototyped function via a function pointer with the right
prototype doesn't work correctly, if the called function requires
argument coercion...  Like, e.g., with:

  float mult (float f1, float f2) { return f1 * f2; }

  (gdb) p mult (2, 3.5)
  $1 = 7
  (gdb) p ((float (*) (float, float)) mult) (2, 3.5)
  $2 = 0

both calls should have returned the same, of course.  The problem is
that GDB misses marking the type of the function pointer target as
prototyped...

Without the fix, the new test fails like this:

 (gdb) p ((int (*) (float, float)) t_float_values2)(3.14159,float_val2)
 $30 = 0
 (gdb) FAIL: gdb.base/callfuncs.exp: p ((int (*) (float, float)) t_float_values2)(3.14159,float_val2)

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* gdbtypes.c (lookup_function_type_with_arguments): Mark function
types with more than one parameter as prototyped.

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

* gdb.base/callfuncs.exp (do_function_calls): New parameter
"prototypes".  Test calling float functions via prototyped and
unprototyped function pointers.
(perform_all_tests): New parameter "prototypes".  Pass it down.
(top level): Pass down "prototypes" parameter to
perform_all_tests.

7 years agogdb.base/commands.exp: Test loop_break and loop_continue in nested loops
Simon Marchi [Mon, 4 Sep 2017 19:19:17 +0000 (21:19 +0200)]
gdb.base/commands.exp: Test loop_break and loop_continue in nested loops

This patch improves the loop_break and loop_continue tests to verify
that they work as expected when multiple loops are nested (they affect
the inner loop).

gdb/testsuite/ChangeLog:

* gdb.base/commands.exp (loop_break_test, loop_continue_test):
Test with nested loops.

7 years agoIntroduce gdb_disassembly_flags
Pedro Alves [Mon, 4 Sep 2017 17:23:22 +0000 (18:23 +0100)]
Introduce gdb_disassembly_flags

For some reason I ended up staring at some of the "int flags" in
btrace-related code, and I got confused because I had no clue what the
flags where supposed to indicate.

Fix that by using enum_flags, so that:
  #1 - it's clear from the type what the flags are about, and
  #2 - the compiler can catch mismatching mistakes

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* cli/cli-cmds.c (print_disassembly, disassemble_current_function)
(disassemble_command): Use gdb_disassembly_flags instead of bare
int.
* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn)
(dump_insns, do_mixed_source_and_assembly_deprecated)
(do_mixed_source_and_assembly, do_assembly_only, gdb_disassembly):
Use gdb_disassembly_flags instead of bare int.
* disasm.h (DISASSEMBLY_SOURCE_DEPRECATED, DISASSEMBLY_RAW_INSN)
(DISASSEMBLY_OMIT_FNAME, DISASSEMBLY_FILENAME)
(DISASSEMBLY_OMIT_PC, DISASSEMBLY_SOURCE)
(DISASSEMBLY_SPECULATIVE): No longer macros.  Instead they're...
(enum gdb_disassembly_flag): ... values of this new enumeration.
(gdb_disassembly_flags): Define.
(gdb_disassembly)
(gdb_pretty_print_disassembler::pretty_print_insn): Use it.
* mi/mi-cmd-disas.c (mi_cmd_disassemble): Use
gdb_disassembly_flags instead of bare int.
* record-btrace.c (btrace_insn_history)
(record_btrace_insn_history, record_btrace_insn_history_range)
(record_btrace_insn_history_from): Use gdb_disassembly_flags
instead of bare int.
* record.c (get_insn_history_modifiers, cmd_record_insn_history):
Use gdb_disassembly_flags instead of bare int.
* target-debug.h (target_debug_print_gdb_disassembly_flags):
Define.
* target-delegates.c: Regenerate.
* target.c (target_insn_history, target_insn_history_from)
(target_insn_history_range): Use gdb_disassembly_flags instead of
bare int.
* target.h: Include "disasm.h".
(struct target_ops) <to_insn_history, to_insn_history_from,
to_insn_history_range>: Use gdb_disassembly_flags instead of bare
int.
(target_insn_history, target_insn_history_from)
(target_insn_history_range): Use gdb_disassembly_flags instead of
bare int.

7 years agoAdd tests for loop_break and loop_continue commands
Simon Marchi [Mon, 4 Sep 2017 17:15:59 +0000 (19:15 +0200)]
Add tests for loop_break and loop_continue commands

I grepped the testsuite for loop_break and loop_continue and didn't find
anything, so I wrote some simple tests for those.

gdb/testsuite/ChangeLog:

* gdb.base/commands.exp: Call the new procedures.
(loop_break_test, loop_continue_test): New procedures.

7 years agoError out immediatly when using if command without args in command list
Simon Marchi [Mon, 4 Sep 2017 17:13:08 +0000 (19:13 +0200)]
Error out immediatly when using if command without args in command list

When using "if" (or while) without args directly on gdb's command line,
you get this:

  (gdb) if
  if/while commands require arguments

When doing the same when entering a command list, you only get an error
when the command is executed, when parse_exp_in_context_1 fails to
evaluate the expression.

  (gdb) define foo
  Type commands for definition of "foo".
  End with a line saying just "end".
  >if
   >end
  >end
  (gdb) foo
  Argument required (expression to compute).

I think it would make more sense to error out when inputting the command
list directly:

  (gdb) define foo
  Type commands for definition of "foo".
  End with a line saying just "end".
  >if
  if/while commands require arguments.

The only required change is to check whether args is an empty string in
build_command_line.

gdb/ChangeLog:

* cli/cli-script.c (build_command_line): For if/while commands,
check whether args is empty.

gdb/testsuite/ChangeLog:

* gdb.base/commands.exp: Call new procedure.
(define_if_without_arg_test): New procedure.

7 years agoMove command lines types/declarations to cli-script.h
Simon Marchi [Mon, 4 Sep 2017 17:09:12 +0000 (19:09 +0200)]
Move command lines types/declarations to cli-script.h

I think it would make more sense if the types and function declarations
related to command lines were in cli-script.h rather than defs.h, since
the related function definitions are in cli-script.c.

I had to add a few includes here and there.  I also had to rename the
"lines" parameter of command_lines_deleter::operator(), because ncurses
has a "#define lines ..." that was interfering when cli-script.h is
included by some TUI source files that also include ncurses header files.

gdb/ChangeLog:

* cli/cli-script.h (enum misc_command_type): Move from defs.h.
(enum command_control_type): Likewise.
(struct command_line): Likewise.
(free_command_lines): Likewise.
(struct command_lines_deleter): Likewise.
(command_line_up): Likewise.
(read_command_lines): Likewise.
(read_command_lines_1): Likewise.
* defs.h (enum misc_command_type): Move to cli/cli-script.h.
(enum command_control_type): Likewise.
(struct command_line): Likewise.
(free_command_lines): Likewise.
(struct command_lines_deleter): Likewise.
(command_line_up): Likewise.
(read_command_lines): Likewise.
(read_command_lines_1): Likewise.
* breakpoint.h: Include cli/cli-script.h.
* extension-priv.h: Likewise.
* gdbcmd.h: Likewise.

7 years agogdbserver Makefile: don't delete intermediary files
Simon Marchi [Mon, 4 Sep 2017 17:02:56 +0000 (19:02 +0200)]
gdbserver Makefile: don't delete intermediary files

If you "make" from scratch in gdbserver/, you'll notice that make
deletes the files it considers as intermediary at the end:

  $ make clean && make
  ...
  rm i386-mmx-linux-generated.c x32-avx-avx512-linux-generated.c ...

Then, if you type make again, make will rebuild these files and rebuild
gdbserver.  To avoid this, we can add the .SECONDARY special target.  If
it has no pre-requisites, all intermediary files will be kept.

gdb/gdbserver/ChangeLog:

* Makefile.in (.SECONDARY): Define target.

7 years agoKill init_sal
Pedro Alves [Mon, 4 Sep 2017 16:10:13 +0000 (17:10 +0100)]
Kill init_sal

Instead, make symtab_and_line initialize its members itself.  Many
symtab_and_line declarations are moved to where the object is
initialized at the same time both for clarity and to avoid double
initialization.  A few functions, like e.g., find_frame_sal are
adjusted to return the sal using normal function return instead of an
output parameter likewise to avoid having to default-construct a sal
and then immediately have the object overwritten.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* ada-lang.c (is_known_support_routine): Move sal declaration to
where it is initialized.
* breakpoint.c (create_internal_breakpoint, init_catchpoint)
(parse_breakpoint_sals, decode_static_tracepoint_spec)
(clear_command, update_static_tracepoint): Remove init_sal
references.  Move declarations closer to initializations.
* cli/cli-cmds.c (list_command): Move sal declarations closer to
initializations.
* elfread.c (elf_gnu_ifunc_resolver_stop): Remove init_sal
references.  Move sal declarations closer to initializations.
* frame.c (find_frame_sal): Return a symtab_and_line via function
return instead of output parameter.  Remove init_sal references.
* frame.h (find_frame_sal): Return a symtab_and_line via function
return instead of output parameter.
* guile/scm-frame.c (gdbscm_frame_sal): Adjust.
* guile/scm-symtab.c (stscm_make_sal_smob): Use in-place new
instead of memset.
(gdbscm_find_pc_line): Remove init_sal reference.
* infcall.c (call_function_by_hand_dummy): Remove init_sal
references.  Move declarations closer to initializations.
* infcmd.c (set_step_frame): Update.  Move declarations closer to
initializations.
(finish_backward): Remove init_sal references.  Move declarations
closer to initializations.
* infrun.c (process_event_stop_test, handle_step_into_function)
(insert_hp_step_resume_breakpoint_at_frame)
(insert_step_resume_breakpoint_at_caller): Likewise.
* linespec.c (create_sals_line_offset, decode_digits_ordinary)
(symbol_to_sal): Likewise.
* probe.c (parse_probes_in_pspace): Remove init_sal reference.
* python/py-frame.c (frapy_find_sal): Move sal declaration closer
to its initialization.
* reverse.c (save_bookmark_command): Use new/delete.  Remove
init_sal references.  Move declarations closer to initializations.
* source.c (get_current_source_symtab_and_line): Remove brace
initialization.
(set_current_source_symtab_and_line): Now takes the sal by const
reference.  Remove brace initialization.
(line_info): Remove init_sal reference.
* source.h (set_current_source_symtab_and_line): Now takes a
symtab_and_line via const reference.
* stack.c (set_current_sal_from_frame): Adjust.
(print_frame_info): Adjust.
(get_last_displayed_sal): Return the sal via function return
instead of via output parameter.  Simplify.
(frame_info): Adjust.
* stack.h (get_last_displayed_sal): Return the sal via function
return instead of via output parameter.
* symtab.c (init_sal): Delete.
(find_pc_sect_line): Remove init_sal references.  Move
declarations closer to initializations.
(find_function_start_sal): Remove init_sal references.  Move
declarations closer to initializations.
* symtab.h (struct symtab_and_line): In-class initialize all
fields.
* tracepoint.c (set_traceframe_context)
(print_one_static_tracepoint_marker): Remove init_sal references.
Move declarations closer to initializations.
* tui/tui-disasm.c (tui_show_disassem_and_update_source): Adjust.
* tui/tui-stack.c (tui_show_frame_info): Adjust.  Move
declarations closer to initializations.
* tui/tui-winsource.c (tui_update_source_window_as_is): Remove
init_sal references.  Adjust.

7 years agostruct symtabs_and_lines -> std::vector<symtab_and_line>
Pedro Alves [Mon, 4 Sep 2017 16:10:13 +0000 (17:10 +0100)]
struct symtabs_and_lines -> std::vector<symtab_and_line>

This replaces "struct symtabs_and_lines" with
std::vector<symtab_and_line> in most cases.  This removes a number of
cleanups.

In some cases, the sals objects do not own the sals they point at.
Instead they point at some sal that lives on the stack.  Typically
something like this:

  struct symtab_and_line sal;
  struct symtabs_and_lines sals;

  // fill in sal

  sals.nelts = 1;
  sals.sals = &sal;

  // use sals

Instead of switching those cases to std::vector too, such usages are
replaced by gdb::array_view<symtab_and_line> instead.  This avoids
introducing heap allocations.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* ax-gdb.c (agent_command_1): Use range-for.
* break-catch-throw.c (re_set_exception_catchpoint): Update.
* breakpoint.c: Include "common/array-view.h".
(init_breakpoint_sal, create_breakpoint_sal): Change sals
parameter from struct symtabs_and_lines to
array_view<symtab_and_line>.  Adjust.  Use range-for.  Update.
(breakpoint_sals_to_pc): Change sals parameter from struct
symtabs_and_lines to std::vector reference.
(check_fast_tracepoint_sals): Change sals parameter from struct
symtabs_and_lines to std::array_view.  Use range-for.
(decode_static_tracepoint_spec): Return a std::vector instead of
symtabs_and_lines.  Update.
(create_breakpoint): Update.
(break_range_command, until_break_command, clear_command): Update.
(base_breakpoint_decode_location, bkpt_decode_location)
(bkpt_probe_create_sals_from_location)
(bkpt_probe_decode_location, tracepoint_decode_location)
(tracepoint_probe_decode_location)
(strace_marker_create_sals_from_location): Return a std::vector
instead of symtabs_and_lines.
(strace_marker_create_breakpoints_sal): Update.
(strace_marker_decode_location): Return a std::vector instead of
symtabs_and_lines.  Update.
(update_breakpoint_locations): Change struct symtabs_and_lines
parameters to gdb::array_view.  Adjust.
(location_to_sals): Return a std::vector instead of
symtabs_and_lines.  Update.
(breakpoint_re_set_default): Use std::vector instead of struct
symtabs_and_lines.
(decode_location_default): Return a std::vector instead of
symtabs_and_lines.  Update.
* breakpoint.h: Include "common/array-view.h".
(struct breakpoint_ops) <decode_location>: Now returns a
std::vector instead of returning a symtabs_and_lines via output
parameter.
(update_breakpoint_locations): Change sals parameters to use
gdb::array_view.
* cli/cli-cmds.c (edit_command, list_command): Update to use
std::vector and gdb::array_view.
(ambiguous_line_spec): Adjust to use gdb::array_view and
range-for.
(compare_symtabs): Rename to ...
(cmp_symtabs): ... this.  Change parameters to symtab_and_line
const reference and adjust.
(filter_sals): Rewrite using std::vector and standard algorithms.
* elfread.c (elf_gnu_ifunc_resolver_return_stop): Simplify.
(jump_command): Update to use std::vector.
* linespec.c (struct linespec_state) <canonical_names>: Update
comment.
(add_sal_to_sals_basic): Delete.
(add_sal_to_sals, filter_results, convert_results_to_lsals)
(decode_line_2, create_sals_line_offset)
(convert_address_location_to_sals, convert_linespec_to_sals)
(convert_explicit_location_to_sals, parse_linespec)
(event_location_to_sals, decode_line_full, decode_line_1)
(decode_line_with_current_source)
(decode_line_with_last_displayed, decode_objc)
(decode_digits_list_mode, decode_digits_ordinary, minsym_found)
(linespec_result::~linespec_result): Adjust to use std::vector
instead of symtabs_and_lines.
* linespec.h (linespec_sals::sals): Now a std::vector.
(struct linespec_result): Use std::vector, bool, and in-class
initialization.
(decode_line_1, decode_line_with_current_source)
(decode_line_with_last_displayed): Return std::vector.
* macrocmd.c (info_macros_command): Use std::vector.
* mi/mi-main.c (mi_cmd_trace_find): Use std::vector.
* probe.c (parse_probes_in_pspace, parse_probes): Adjust to use
std::vector.
* probe.h (parse_probes): Return a std::vector.
* python/python.c (gdbpy_decode_line): Use std::vector and
gdb::array_view.
* source.c (select_source_symtab, line_info): Use std::vector.
* stack.c (func_command): Use std::vector.
* symtab.h (struct symtabs_and_lines): Delete.
* tracepoint.c (tfind_line_command, scope_info): Use std::vector.

7 years agoIntroduce gdb::array_view
Pedro Alves [Mon, 4 Sep 2017 16:10:12 +0000 (17:10 +0100)]
Introduce gdb::array_view

An array_view is an abstraction that provides a non-owning view over a
sequence of contiguous objects.

A way to put it is that array_view is to std::vector (and std::array
and built-in arrays with rank==1) like std::string_view is to
std::string.

The main intent of array_view is to use it as function input parameter
type, making it possible to pass in any sequence of contiguous
objects, irrespective of whether the objects live on the stack or heap
and what actual container owns them.  Implicit construction from the
element type is supported too, making it easy to call functions that
expect an array of elements when you only have one element (usually on
the stack).  For example:

 struct A { .... };
 void function (gdb::array_view<A> as);

 std::vector<A> std_vec = ...;
 std::array<A, N> std_array = ...;
 A array[] = {...};
 A elem;

 function (std_vec);
 function (std_array);
 function (array);
 function (elem);

Views can be either mutable or const.  A const view is simply created
by specifying a const T as array_view template parameter, in which
case operator[] of non-const array_view objects ends up returning
const references.  (Making the array_view itself const is analogous to
making a pointer itself be const.  I.e., disables re-seating the
view/pointer.)  Normally functions will pass around array_views by
value.

Uses of gdb::array_view (other than the ones in the unit tests) will
be added in a follow up patch.

gdb/ChangeLog
2017-09-04  Pedro Alves  <palves@redhat.com>

* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
unittests/array-view-selftests.c.
(SUBDIR_UNITTESTS_OBS): Add array-view-selftests.o.
* common/array-view.h: New file.
* unittests/array-view-selftests.c: New file.

7 years agoClarify "list" output when specified lines are ambiguous
Pedro Alves [Mon, 4 Sep 2017 15:49:29 +0000 (16:49 +0100)]
Clarify "list" output when specified lines are ambiguous

Currently, with "list LINESPEC1,LINESPEC2", if one of the linespecs is
ambiguous, i.e., if it expands to multiple locations, you get this
seemingly odd output:

 (gdb) list foo,bar
 file: "file0.c", line number: 26
 file: "file1.c", line number: 29

Since "foo" above expands to multiple locations, the specified range
is indeterminate, and GDB is trying to be helpful by showing you what
was ambiguous.  It looks confusing to me, though.  I think it'd be
much more user friendly if GDB actually told you that, like this:

 (gdb) list foo,bar
 Specified first line 'foo' is ambiguous:
 file: "file0.c", line number: 26
 file: "file1.c", line number: 29

 (gdb) list bar,foo
 Specified last line 'foo' is ambiguous:
 file: "file0.c", line number: 26
 file: "file1.c", line number: 29

Note, I'm using "first" and "last" in the output because that's what
the manual uses:

 ~~~
 list first,last

     Print lines from first to last. [...]
 ~~~

Tested on x86-64 GNU/Linux.

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* cli/cli-cmds.c (edit_command): Pass message to
ambiguous_line_spec.
(list_command): Pass message to ambiguous_line_spec.  Say
"first"/"last" instead of "start" and "end" to be consistent with
the manual.
(ambiguous_line_spec): Add 'format' and vararg parameters.  Use
them to print formatted message.

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

* gdb.base/list-ambiguous.exp: New file.
* gdb.base/list-ambiguous0.c: New file.
* gdb.base/list-ambiguous1.c: New file.
* gdb.base/list.exp (test_list_range): Adjust expected output.

7 years agoFix build breakage when libipt is available
Pedro Alves [Mon, 4 Sep 2017 15:01:17 +0000 (16:01 +0100)]
Fix build breakage when libipt is available

Fix build regression introduced by 0860c437cbe4 ("btrace: Store
btrace_insn in an std::vector"):

  src/gdb/btrace.c: In function â€˜void ftrace_add_pt(btrace_thread_info*, pt_insn_decoder*, int*, std::vector<unsigned int>&)’:
  src/gdb/btrace.c:1329:38: error: invalid initialization of reference of type â€˜const btrace_insn&’ from expression of type â€˜btrace_insn*’
      ftrace_update_insns (bfun, &btinsn);
^
  src/gdb/btrace.c:648:1: note: in passing argument 2 of â€˜void ftrace_update_insns(btrace_function*, const btrace_insn&)’
   ftrace_update_insns (struct btrace_function *bfun, const btrace_insn &insn)
   ^

gdb/ChangeLog:
2017-09-04  Pedro Alves  <palves@redhat.com>

* btrace.c (ftrace_add_pt): Pass btrace_insn to
ftrace_update_insns by reference instead of pointer.

7 years agoFix simulator
Anthony Green [Mon, 4 Sep 2017 14:00:37 +0000 (10:00 -0400)]
Fix simulator

7 years agoLet i386_target_description return tdesc_i386_mmx
Yao Qi [Mon, 4 Sep 2017 10:33:56 +0000 (11:33 +0100)]
Let i386_target_description return tdesc_i386_mmx

This patch remove the usage of tdesc_i386_mmx in i386-go32-tdep.c, and use
i386_target_description to get it instead.

gdb:

2017-09-04  Yao Qi  <yao.qi@linaro.org>

* i386-go32-tdep.c: Include x86-xstate.h.
(i386_go32_init_abi): Call i386_target_description.
* i386-tdep.c (i386_target_description): Return tdesc_i386_mmx
if xcr0 is X86_XSTATE_X87_MASK.
* i386-tdep.h (tdesc_i386): Remove the declaration.
(tdesc_i386_mmx): Likewise.

7 years agoReturn X86_XSTATE_SSE_MASK instead of 0 in i386fbsd_core_read_xcr0
Yao Qi [Mon, 4 Sep 2017 10:33:56 +0000 (11:33 +0100)]
Return X86_XSTATE_SSE_MASK instead of 0 in i386fbsd_core_read_xcr0

i386fbsd_core_read_xcr0 reads the value of xcr0 from the corefile.  If
it fails, returns 0.  This makes its caller {i386,amd64}_target_description
has to handle this special value.  IMO, i386fbsd_core_read_xcr0 should
return the default xcr0 in case of error.

gdb:

2017-09-04  Yao Qi  <yao.qi@linaro.org>

* i386-fbsd-tdep.c (i386fbsd_core_read_xcr0): Return
X86_XSTATE_SSE_MASK instead of 0.

7 years agoUse i386_target_description to get tdesc_i386
Yao Qi [Mon, 4 Sep 2017 10:33:56 +0000 (11:33 +0100)]
Use i386_target_description to get tdesc_i386

GDB can call function i386_target_description to get the right target
description rather than tdesc_i386

gdb:

2017-09-04  Yao Qi  <yao.qi@linaro.org>

* amd64-fbsd-nat.c (amd64fbsd_read_description): Call
i386_target_description.
* i386-fbsd-nat.c (i386fbsd_read_description): Call
i386_target_description.
* i386-tdep.c (i386_gdbarch_init): Likewise.

7 years agoUse amd64_target_description to get tdesc_amd64
Yao Qi [Mon, 4 Sep 2017 10:33:56 +0000 (11:33 +0100)]
Use amd64_target_description to get tdesc_amd64

This patch changes amd64-*-tdep.c files to use function
amd64_target_description to get the right target description rather than
use the variable tdesd_amd64.

gdb:

2017-09-04  Yao Qi  <yao.qi@linaro.org>

* amd64-darwin-tdep.c: Include "x86-xstate.h".
(x86_darwin_init_abi_64): Call amd64_target_description.
* amd64-dicos-tdep.c: Likewise.
* amd64-fbsd-nat.c: Likewise.
* amd64-fbsd-tdep.c: Likewise.
* amd64-nbsd-tdep.c: Likewise.
* amd64-obsd-tdep.c: Likewise.
* amd64-sol2-tdep.c: Likewise.
* amd64-windows-tdep.c: Likewise.
* amd64-tdep.h (tdesc_amd64): Remove the declaration.

7 years agobtrace: Store btrace_insn in an std::vector
Simon Marchi [Mon, 4 Sep 2017 08:46:36 +0000 (10:46 +0200)]
btrace: Store btrace_insn in an std::vector

Because it contains a non-POD type field (flags), the type btrace_insn
should be new'ed/delete'd.  Replace the VEC (btrace_insn_s) in
btrace_function with an std::vector.

gdb/ChangeLog:

* btrace.h (btrace_insn_s, DEF_VEC_O (btrace_insn_s)): Remove.
(btrace_function) <insn>: Change type to use std::vector.
* btrace.c (ftrace_debug, ftrace_call_num_insn,
ftrace_find_call, ftrace_new_gap, ftrace_update_function,
ftrace_update_insns, ftrace_compute_global_level_offset,
btrace_stitch_bts, btrace_clear, btrace_insn_get,
btrace_insn_end, btrace_insn_next, btrace_insn_prev): Adjust to
change to std::vector.
(ftrace_update_insns): Adjust to change to std::vector, change
type of INSN parameter.
(btrace_compute_ftrace_bts): Adjust call to ftrace_update_insns.
* record-btrace.c (btrace_call_history_insn_range,
btrace_compute_src_line_range,
record_btrace_frame_prev_register): Adjust to change to
std::vector.
* python/py-record-btrace.c (recpy_bt_func_instructions): Adjust
to change to std::vector.

7 years agoAutomatic date update in version.in
GDB Administrator [Mon, 4 Sep 2017 00:00:29 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoUse std::string in reopen_exec_file
Tom Tromey [Mon, 14 Aug 2017 06:18:06 +0000 (00:18 -0600)]
Use std::string in reopen_exec_file

This changes reopen_exec_file to use a std::string, removing a
cleanup.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* corefile.c (reopen_exec_file): Use std::string.

7 years agoUse std::string and unique_xmalloc_ptr in compile/ code
Tom Tromey [Mon, 14 Aug 2017 06:03:02 +0000 (00:03 -0600)]
Use std::string and unique_xmalloc_ptr in compile/ code

Change various things in the compile/ code to use std::string or
unique_xmalloc_ptr as appropriate.  This allows the removal of some
cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* compile/compile.c (compile_register_name_mangled): Return
std::string.
* compile/compile-loc2c.c (pushf_register_address): Update.
(pushf_register): Update.
* compile/compile-c-types.c (convert_array): Update.
* compile/compile-c-symbols.c (generate_vla_size): Update.
(error_symbol_once): Use a gdb::unique_xmalloc_ptr.
(symbol_substitution_name): Return a gdb::unique_xmalloc_ptr.
(convert_one_symbol): Update.
(generate_c_for_for_one_variable): Update.
* compile/compile-c-support.c (c_get_range_decl_name): Return a
std::string.
(generate_register_struct): Update.
* compile/compile-internal.h (c_get_range_decl_name): Return a
std::string.
(compile_register_name_mangled): Return std::string.

7 years agoReturn std::string from perror_string
Tom Tromey [Mon, 14 Aug 2017 05:47:01 +0000 (23:47 -0600)]
Return std::string from perror_string

Change perror_string to return a std::string, removing a cleanup in
the process.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* utils.c (perror_string): Return a std::string.
(throw_perror_with_name, perror_warning_with_name): Update.

7 years agoUse std::string and unique_xmalloc_ptr in demangle_command
Tom Tromey [Mon, 14 Aug 2017 05:38:09 +0000 (23:38 -0600)]
Use std::string and unique_xmalloc_ptr in demangle_command

Change demangle_command to use std::string and unique_xmalloc_ptr,
removing some cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* demangle.c (demangle_command): Use std::string,
unique_xmalloc_ptr.

7 years agoUse std::string in do_set_command
Tom Tromey [Sun, 13 Aug 2017 20:45:17 +0000 (14:45 -0600)]
Use std::string in do_set_command

Change do_set_command to use std::string, removing a cleanup and some
manual resizing code.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* cli/cli-setshow.c (do_set_command): Use std::string.

7 years agoUse unique_xmalloc_ptr in cd_command
Tom Tromey [Sun, 13 Aug 2017 20:34:59 +0000 (14:34 -0600)]
Use unique_xmalloc_ptr in cd_command

Change cd_command to use unique_xmalloc_ptr, removing a cleanup.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* cli/cli-cmds.c (cd_command): Use gdb::unique_xmalloc_ptr.

7 years agoUse std::string in mi_cmd_interpreter_exec
Tom Tromey [Sun, 13 Aug 2017 17:04:37 +0000 (11:04 -0600)]
Use std::string in mi_cmd_interpreter_exec

Change mi_cmd_interpreter_exec to use std::string, removing a cleanup.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* mi/mi-interp.c (mi_cmd_interpreter_exec): Use std::string.

7 years agoUse unique_xmalloc_ptr in env_execute_cli_command
Tom Tromey [Sun, 13 Aug 2017 16:57:05 +0000 (10:57 -0600)]
Use unique_xmalloc_ptr in env_execute_cli_command

Change env_execute_cli_command to use unique_xmalloc_ptr, removing a
cleanup.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* mi/mi-cmd-env.c (env_execute_cli_command): Use
gdb::unique_xmalloc_ptr.

7 years agoUse std::string thread.c
Tom Tromey [Fri, 11 Aug 2017 20:48:17 +0000 (14:48 -0600)]
Use std::string thread.c

This changes a few spots in thread.c to use std::string, removing some
cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* thread.c (print_thread_info_1): Use string_printf.
(thread_apply_command, thread_apply_all_command): Use
std::string.

7 years agoReturn std::string from memory_error_message
Tom Tromey [Sat, 5 Aug 2017 22:23:18 +0000 (16:23 -0600)]
Return std::string from memory_error_message

This changes memory_error_message to return a std::string and fixes up
the callers.  This removes some cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

* valprint.c (val_print_string): Update.
* gdbcore.h (memory_error_message): Return std::string.
* corefile.c (memory_error_message): Return std::string.
(memory_error): Update.
* breakpoint.c (insert_bp_location): Update.

7 years agox86-64: Set tlsdesc_plt if GOT_TLS_GDESC_P is true
H.J. Lu [Sun, 3 Sep 2017 17:18:24 +0000 (10:18 -0700)]
x86-64: Set tlsdesc_plt if GOT_TLS_GDESC_P is true

We need to set tlsdesc_plt for x86-64 if GOT_TLS_GDESC_P is true when
allocating dynamic relocations so that _bfd_x86_elf_size_dynamic_sections
will generate TLSDESC_PLT and TLSDESC_GOT in x86-64 output.

bfd/

PR ld/22071
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Set tlsdesc_plt
for x86-64 if GOT_TLS_GDESC_P is true.

ld/

PR ld/22071
* testsuite/ld-x86-64/pr22071.d: New file.
* testsuite/ld-x86-64/pr22071.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr22071.

7 years agoPR22067, x86 check_relocs invalid read
Alan Modra [Sun, 3 Sep 2017 12:34:09 +0000 (22:04 +0930)]
PR22067, x86 check_relocs invalid read

PR 22067
* elfxx-x86.h (elf_x86_hash_table): Check is_elf_hash_table first.

7 years agoMake target_waitstatus_to_string return an std::string
Simon Marchi [Sun, 3 Sep 2017 08:23:31 +0000 (10:23 +0200)]
Make target_waitstatus_to_string return an std::string

A quite straightforward change.  It does "fix" leaks in record-btrace.c,
although since this is only used in debug printing code, it has no real
world impact.

gdb/ChangeLog:

* target/waitstatus.h (target_waitstatus_to_string): Change
return type to std::string.
* target/waitstatus.c (target_waitstatus_to_string): Return
std::string.
* target.h (target_waitstatus_to_string): Remove declaration.
* infrun.c (resume, clear_proceed_status_thread,
print_target_wait_results, do_target_wait, save_waitstatus,
stop_all_threads): Adjust.
* record-btrace.c (record_btrace_wait): Adjust.
* target-debug.h
(target_debug_print_struct_target_waitstatus_p): Adjust.

gdb/gdbserver/ChangeLog:

* linux-low.c (linux_wait_1): Adjust.
* server.c (queue_stop_reply_callback): Adjust.

7 years agoInitialize tls_get_addr for x86-64 in one place
H.J. Lu [Sun, 3 Sep 2017 05:14:58 +0000 (22:14 -0700)]
Initialize tls_get_addr for x86-64 in one place

* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
tls_get_addr for x86-64 in one place.

7 years agoAdd missing ChangeLog entries
H.J. Lu [Sun, 3 Sep 2017 05:10:39 +0000 (22:10 -0700)]
Add missing ChangeLog entries

7 years agoAdd elf64-x86-64.lo together with elfxx-x86.lo for 64-bit BFD
H.J. Lu [Sun, 3 Sep 2017 05:04:27 +0000 (22:04 -0700)]
Add elf64-x86-64.lo together with elfxx-x86.lo for 64-bit BFD

Since elfxx-x86.lo needs elf64-x86-64.lo with 64-bit BFD now, add
elf64-x86-64.lo together with elfxx-x86.lo to bfd_backends for 64-bit
BFD.

* configure.ac (bfd_backends): Add elf64-x86-64.lo together
with elfxx-x86.lo for 64-bit BFD.
* configure: Regenerated.

7 years agoAutomatic date update in version.in
GDB Administrator [Sun, 3 Sep 2017 00:00:30 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agox86: Add _bfd_x86_elf_size_dynamic_sections
H.J. Lu [Sat, 2 Sep 2017 14:37:05 +0000 (07:37 -0700)]
x86: Add _bfd_x86_elf_size_dynamic_sections

elf_i386_size_dynamic_sections and elf_x86_64_size_dynamic_sections are
very similar, except for the followings:

1. elf_i386_size_dynamic_sections checks GOT_TLS_IE and GOT_TLS_IE_BOTH.
elf_x86_64_size_dynamic_sections checks only GOT_TLS_IE.  Since
GOT_TLS_IE_BOTH is never true for x86-64, it is OK to check GOT_TLS_IE
for both i386 and x86-64.
2, x86-64 sets tlsdesc_plt, but i386 doesn't.  We set tlsdesc_plt only
if target_id == X86_64_ELF_DATA.
3. x86-64 has

  if (s != htab->elf.srelplt)
    s->reloc_count = 0;

and i386 has

  s->reloc_count = 0;

i386 did have

  if (s != htab->srelplt)
    s->reloc_count = 0;

in the original commit:

commit 67a4f2b710581acc83afecff55424af285ecbc28
Author: Alexandre Oliva <aoliva@redhat.com>
Date:   Wed Jan 18 21:07:51 2006 +0000

But it was removed by

commit 5ae0bfb60a576344d7f701605346282c1144499e
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Tue Feb 28 07:16:12 2006 +0000

    bfd/
            * elf32-i386.c (elf_i386_link_hash_table): Add next_tls_desc_index.
            (elf_i386_link_hash_table_create): Initialize it.
            (elf_i386_compute_jump_table_size): Use it instead of
            srelplt->reloc_count.
            (allocate_dynrelocs): Likewise.
            (elf_i386_size_dynamic_sections): Likewise.
            (elf_i386_relocate_section): Likewise.

A later commit:

commit e1f987424b7b3f5ac63a2a6ae044a202a44b8ff8
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 21 15:13:37 2011 +0000

    Put IRELATIVE relocations after JUMP_SLOT.

    bfd/

    2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>

            PR ld/13302
            * elf32-i386.c (elf_i386_link_hash_table): Add next_jump_slot_index
            and next_irelative_index.
            (elf_i386_link_hash_table_create): Initialize next_jump_slot_index
            and next_irelative_index.
            (elf_i386_allocate_dynrelocs): Increment reloc_count instead of
            next_tls_desc_index.
            (elf_i386_size_dynamic_sections): Set next_tls_desc_index and
            next_irelative_index from reloc_count.
            (elf_i386_finish_dynamic_symbol): Put R_386_IRELATIVE after
            R_386_JUMP_SLOT.

changed it back to use reloc_count again. So it is correct to use

  if (s != htab->elf.srelplt)
    s->reloc_count = 0;

for both i386 and x86-64 now.
4. i386 and x86-64 use different DT_XXXs.  They are handled by adding
them to elf_x86_link_hash_table.

With these changes, we can share _bfd_x86_elf_size_dynamic_sections in
elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (elf_i386_convert_load): Renamed to ...
(_bfd_i386_elf_convert_load): This.  Remove static.
(elf_i386_size_dynamic_sections): Removed.
(elf_backend_size_dynamic_sections): Likewise.
* elf64-x86-64.c (elf_x86_64_convert_load): Renamed to ...
(_bfd_x86_64_elf_convert_load): This.  Remove static.
(elf_x86_64_size_dynamic_sections): Removed.
(elf_backend_size_dynamic_sections): Likewise.
* elfxx-x86.c (_bfd_x86_elf_allocate_dynrelocs): Renamed to ...
(elf_x86_allocate_dynrelocs): This.  Make it static.
(_bfd_x86_elf_allocate_local_dynrelocs): Renamed to ...
(elf_x86_allocate_local_dynreloc): This.  Make it static.
(elf_i386_is_reloc_section): New function.
(elf_x86_64_is_reloc_section): Likewise.
(_bfd_x86_elf_link_hash_table_create): Initialize convert_load,
is_reloc_section, dt_reloc, dt_reloc_sz and dt_reloc_ent.
Rearrange got_entry_size initialization.
(_bfd_x86_elf_size_dynamic_sections): New function.
* elfxx-x86.h (elf_x86_link_hash_table): Add convert_load,
is_reloc_section, dt_reloc, dt_reloc_sz and dt_reloc_ent.
(_bfd_i386_elf_convert_load): New.
(_bfd_x86_64_elf_convert_load): Likewise.
(_bfd_x86_elf_size_dynamic_sections): Likewise.
(elf_backend_size_dynamic_sections): Likewise.
(_bfd_x86_elf_allocate_dynrelocs): Removed.
(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.

7 years agox86: Rearrange fields and update comments
H.J. Lu [Sat, 2 Sep 2017 20:05:49 +0000 (13:05 -0700)]
x86: Rearrange fields and update comments

* elfxx-x86.h (elf_x86_link_hash_table): Rearrange fields and
update comments.

7 years agoi386: Update sgotplt_jump_table_size setting
H.J. Lu [Sat, 2 Sep 2017 18:18:30 +0000 (11:18 -0700)]
i386: Update sgotplt_jump_table_size setting

elf_i386_size_dynamic_sections has

      htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
      htab->sgotplt_jump_table_size = htab->next_tls_desc_index * 4;

This patch changes it to

      htab->sgotplt_jump_table_size
= elf_x86_compute_jump_table_size (htab)

Since elf_x86_compute_jump_table_size is defined as

  ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size)

there is no change in output.  It makes elf_i386_size_dynamic_sections
the same as elf_x86_64_size_dynamic_sections.

* elf32-i386.c (elf_i386_size_dynamic_sections): Set
sgotplt_jump_table_size with elf_x86_compute_jump_table_size.

7 years agox86: Define PLT_CIE_LENGTH and PLT_FDE_* in elfxx-x86.h
H.J. Lu [Sat, 2 Sep 2017 18:10:51 +0000 (11:10 -0700)]
x86: Define PLT_CIE_LENGTH and PLT_FDE_* in elfxx-x86.h

Since PLT_CIE_LENGTH, PLT_FDE_LENGTH, PLT_FDE_START_OFFSET and
PLT_FDE_LEN_OFFSET are identical in elf32-i386.c and elf64-x86-64.c,
they can be defined in elfxx-x86.h.

* elf32-i386.c (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Moved to ...
* elfxx-x86.h (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Here.
* elf64-x86-64.c (PLT_CIE_LENGTH, PLT_FDE_LENGTH,
PLT_FDE_START_OFFSET, PLT_FDE_LEN_OFFSET): Removed.

7 years agox86: Add _bfd_x86_elf_allocate_dynrelocs
H.J. Lu [Sat, 2 Sep 2017 14:26:54 +0000 (07:26 -0700)]
x86: Add _bfd_x86_elf_allocate_dynrelocs

Share _bfd_x86_elf_allocate_dynrelocs in elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (elf_i386_allocate_dynrelocs): Removed.
(elf_i386_allocate_local_dynrelocs): Likewise.
(elf_i386_size_dynamic_sections): Replace
elf_i386_allocate_dynrelocs/elf_i386_allocate_local_dynrelocs
with _bfd_x86_elf_allocate_dynrelocs and
_bfd_x86_elf_allocate_local_dynrelocs.
* elf64-x86-64.c (elf_x86_64_allocate_dynrelocs): Removed.
(elf_x86_64_allocate_local_dynrelocs): Likewise.
(elf_x86_64_size_dynamic_sections): Replace
elf_x86_64_allocate_dynrelocs/elf_x86_64_allocate_local_dynrelocs
with _bfd_x86_elf_allocate_dynrelocs and
_bfd_x86_elf_allocate_local_dynrelocs.
* elfxx-x86.c (_bfd_x86_elf_allocate_dynrelocs): New function.
(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.
* elfxx-x86.h (_bfd_x86_elf_allocate_dynrelocs): New prototype.
(_bfd_x86_elf_allocate_local_dynrelocs): Likewise.

7 years agox86: Add is_x86_elf
H.J. Lu [Sat, 2 Sep 2017 14:23:46 +0000 (07:23 -0700)]
x86: Add is_x86_elf

Share is_x86_elf in elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (is_i386_elf): Removed.
(elf_i386_check_relocs): Replace is_i386_elf with is_x86_elf.
(elf_i386_size_dynamic_sections): Likewise.
(elf_i386_relocate_section): Likewise.
* elf64-x86-64.c (is_x86_64_elf): Removed.
(elf_x86_64_check_relocs): Replace is_x86_64_elf with
is_x86_elf.
(elf_x86_64_size_dynamic_sections): Likewise.
(elf_x86_64_relocate_section): Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
target_id.
* elfxx-x86.h (elf_x86_link_hash_table): Add target_id.
(is_x86_elf): New.

7 years agox86: Add elf_x86_compute_jump_table_size
H.J. Lu [Sat, 2 Sep 2017 14:16:33 +0000 (07:16 -0700)]
x86: Add elf_x86_compute_jump_table_size

Share elf_x86_compute_jump_table_size in elf32-i386.c and
elf64-x86-64.c.

* elf32-i386.c (elf_i386_compute_jump_table_size): Removed.
(elf_i386_allocate_dynrelocs): Replace
elf_i386_compute_jump_table_size with
elf_x86_compute_jump_table_size.
(elf_i386_size_dynamic_sections): Likewise.
* elf64-x86-64.c (elf_x86_64_compute_jump_table_size): Removed.
(elf_x86_64_allocate_dynrelocs): Replace
elf_x86_64_compute_jump_table_size with
elf_x86_compute_jump_table_size.
(elf_x86_64_size_dynamic_sections): Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
got_entry_size.
* elfxx-x86.h (elf_x86_link_hash_table): Add got_entry_size.
(elf_x86_compute_jump_table_size): New.

7 years agox86: Add sizeof_reloc to elf_x86_link_hash_table
H.J. Lu [Sat, 2 Sep 2017 12:55:25 +0000 (05:55 -0700)]
x86: Add sizeof_reloc to elf_x86_link_hash_table

Initialize htab->sizeof_reloc once, instead of computing it every time.

* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
sizeof_reloc.
(_bfd_x86_elf_adjust_dynamic_symbol): Use sizeof_reloc.
* elfxx-x86.h (elf_x86_link_hash_table): Add sizeof_reloc.

7 years agoi386: Check VxWorks with htab->is_vxworks
H.J. Lu [Sat, 2 Sep 2017 12:05:30 +0000 (05:05 -0700)]
i386: Check VxWorks with htab->is_vxworks

* elf32-i386.c (elf_i386_allocate_dynrelocs): Check VxWorks
with htab->is_vxworks.
(elf_i386_size_dynamic_sections): Likewise.
(elf_i386_relocate_section): Likewise.
(elf_i386_finish_dynamic_symbol): Likewise.
(elf_i386_finish_dynamic_sections): Likewise.

7 years agox86: Move GOT_TLS_* in elf32-i386.c to elfxx-x86.h
H.J. Lu [Sat, 2 Sep 2017 11:52:00 +0000 (04:52 -0700)]
x86: Move GOT_TLS_* in elf32-i386.c to elfxx-x86.h

elf64-x86-64.c can use GOT_TLS_* definitions in elf32-i386.c with
GOT_TLS_IE_POS, GOT_TLS_IE_NEG and GOT_TLS_IE_BOTH unused.

* elf32-i386.c (GOT_TLS_IE, GOT_TLS_IE_POS, GOT_TLS_IE_NEG,
GOT_TLS_IE_BOTH, GOT_TLS_GDESC, GOT_TLS_GD_BOTH_P,
GOT_TLS_GD_P, GOT_TLS_GDESC_P, GOT_TLS_GD_ANY_P): Moved to ...
* elfxx-x86.h (GOT_TLS_IE, GOT_TLS_IE_POS, GOT_TLS_IE_NEG,
GOT_TLS_IE_BOTH, GOT_TLS_GDESC, GOT_TLS_GD_BOTH_P,
GOT_TLS_GD_P, GOT_TLS_GDESC_P, GOT_TLS_GD_ANY_P): Here.
* elf64-x86-64.c (GOT_TLS_IE, GOT_TLS_GDESC, GOT_TLS_GD_BOTH_P,
GOT_TLS_GD_P, GOT_TLS_GDESC_P, GOT_TLS_GD_ANY_P): Removed.

7 years agoLTO rescan archives
Alan Modra [Sat, 2 Sep 2017 01:38:05 +0000 (11:08 +0930)]
LTO rescan archives

ld ought to be more clever about where it puts LTO recompiled objects.
Ideally the recompiled objects ought to be ordered to the same place
their IR objects were, and files extracted from archives on the second
pass ought to go in the same place as they would if extracted on the
first pass.  This patch addresses the archive problem.  Without this
fix, objects extracted from archives might be placed after the crt
files intended to go at the end of an executable or shared library,
possibly causing exception handling failures.

* ldlang.h (lang_input_statement_type): Expand comments.
(LANG_FOR_EACH_INPUT_STATEMENT): Rewrite without casts.
* ldlang.c (lang_for_each_input_file): Likewise.
(load_symbols): Set usrdata for archives.
(find_rescan_insertion): New function.
(lang_process): Trim off and reinsert entries added to file chain
when rescanning archives for LTO.
* ldmain.c (add_archive_element): Set my_archive input_statement
next pointer to last element added.

7 years agox86-64: Check ELF_COMMON_DEF_P for common symbols
H.J. Lu [Sat, 2 Sep 2017 01:53:26 +0000 (18:53 -0700)]
x86-64: Check ELF_COMMON_DEF_P for common symbols

bfd/

PR ld/22064
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.

ld/

PR ld/22064
* testsuite/ld-x86-64/pr22064a.S: New file.
* testsuite/ld-x86-64/pr22064b.c: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/22064 test.

7 years ago-Og warning fixes
Alan Modra [Sat, 2 Sep 2017 01:30:02 +0000 (11:00 +0930)]
-Og warning fixes

Found when building with gcc 4.9.4 using -Og.

bfd/
* elf-eh-frame.c (offset_adjust): Avoid false positive gcc warning.
* elflink.c (bfd_elf_size_dynsym_hash_dynstr): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
ld/
* emultempl/msp430.em (eval_upper_either_sections): Make base_sec_name
a const char*.
(eval_lower_either_sections): Likewise.
(msp430_elf_after_allocation): Likewise, and don't needlessly concat
and free.  Warning fix.

7 years agoAutomatic date update in version.in
GDB Administrator [Sat, 2 Sep 2017 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agox86: Add _bfd_x86_elf_gc_mark_hook
H.J. Lu [Fri, 1 Sep 2017 21:51:58 +0000 (14:51 -0700)]
x86: Add _bfd_x86_elf_gc_mark_hook

Since R_X86_64_GNU_VTINHERIT == R_386_GNU_VTINHERIT and
R_X86_64_GNU_VTENTRY == R_386_GNU_VTENTRY, we can share
_bfd_x86_elf_gc_mark_hook in elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (elf_i386_gc_mark_hook): Removed.
(elf_backend_gc_mark_hook): Likewise.
* elf64-x86-64.c (elf_x86_64_gc_mark_hook): Likewise.
(elf_backend_gc_mark_hook): Likewise.
* elfxx-x86.c (_bfd_x86_elf_gc_mark_hook): New function.
* elfxx-x86.h (_bfd_x86_elf_gc_mark_hook): New.
(elf_backend_gc_mark_hook): Likewise.

7 years agox86: Add _bfd_x86_elf_adjust_dynamic_symbol
H.J. Lu [Fri, 1 Sep 2017 20:03:40 +0000 (13:03 -0700)]
x86: Add _bfd_x86_elf_adjust_dynamic_symbol

Share _bfd_x86_elf_adjust_dynamic_symbol in elf32-i386.c and
elf64-x86-64.c.

* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Removed.
(elf_backend_adjust_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
(elf_backend_adjust_dynamic_symbol): Likewise.
* elfxx-x86.c (_bfd_x86_elf_adjust_dynamic_symbol): New function.
(_bfd_x86_elf_link_setup_gnu_properties): Copy is_vxworks.
* elfxx-x86.h (elf_x86_link_hash_table): Add is_vxworks.
(_bfd_x86_elf_adjust_dynamic_symbol): New.
(elf_backend_adjust_dynamic_symbol): Likewise.

7 years agoCorrect ChangeLog entry
H.J. Lu [Fri, 1 Sep 2017 20:01:23 +0000 (13:01 -0700)]
Correct ChangeLog entry

7 years agoelfxx-x86.h: Fix a typo in comments
H.J. Lu [Fri, 1 Sep 2017 19:39:38 +0000 (12:39 -0700)]
elfxx-x86.h: Fix a typo in comments

* elfxx-x86.h (elf_x86_plt_layout_table): Fix a typo in
comments.

7 years agox86: Add _bfd_x86_elf_mkobject
H.J. Lu [Fri, 1 Sep 2017 19:09:03 +0000 (12:09 -0700)]
x86: Add _bfd_x86_elf_mkobject

Share _bfd_x86_elf_mkobject in elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (elf_i386_mkobject): Removed.
(bfd_elf32_mkobject): Likewise.
* elf64-x86-64.c (elf_x86_64_mkobject): Likewise.
(bfd_elf64_mkobject): Likewise.
(bfd_elf32_mkobject): Likewise.
* elfxx-x86.c (_bfd_x86_elf_mkobject): New function.
(_bfd_x86_elf_mkobject): New.
(bfd_elf64_mkobject): Likewise.
(bfd_elf32_mkobject): Likewise.

7 years agox86: Add _bfd_x86_elf_link_setup_gnu_properties
H.J. Lu [Fri, 1 Sep 2017 15:00:36 +0000 (08:00 -0700)]
x86: Add _bfd_x86_elf_link_setup_gnu_properties

Extract the common parts of elf_i386_link_setup_gnu_properties and
elf_x86_64_link_setup_gnu_properties into a new function.

For x86-64, since PIC PLT layouts are the same as non-PIC PLT layouts,
initialize pic_plt0_entry and pic_plt_entry fields in PLT layouts with
the non-PIC PLT entries.

* elf32-i386.c (elf_i386_link_setup_gnu_properties): Updated.
Call _bfd_x86_elf_link_setup_gnu_properties.
* elf64-x86-64.c (elf_x86_lazy_plt_layout): Initialize
pic_plt0_entry and pic_plt_entry fields with the non-PIC PLT
entries.
(elf_x86_64_non_lazy_plt): Likewise.
(elf_x86_64_lazy_bnd_plt): Likewise.
(elf_x86_64_non_lazy_bnd_plt): Likewise.
(elf_x86_64_lazy_ibt_plt): Likewise.
(elf_x32_lazy_ibt_plt): Likewise.
(elf_x86_64_non_lazy_ibt_plt): Likewise.
(elf_x32_non_lazy_ibt_plt): Likewise.
(elf_x86_64_nacl_plt): Likewise.
(elf_x86_64_link_setup_gnu_properties): Updated.  Call
_bfd_x86_elf_link_setup_gnu_properties.
* elfxx-x86.c: Include elf-vxworks.h".
(_bfd_x86_elf_link_setup_gnu_properties): New function.
* elfxx-x86.h (elf_x86_lazy_plt_layout): Remove "for i386 only"
comments for pic_plt0_entry and pic_plt_entry.
(elf_x86_non_lazy_plt_layout): Likewise.
(elf_x86_plt_layout_table): New.
(_bfd_x86_elf_link_setup_gnu_properties): Likewise.

7 years agoImport latest fixes to libiberty from GCC
H.J. Lu [Fri, 1 Sep 2017 13:14:39 +0000 (06:14 -0700)]
Import latest fixes to libiberty from GCC

Fix warning for simple-object-elf.c.

2017-09-01  Martin Liska  <mliska@suse.cz>

* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
Remove duplicite declaration.

7 years agox86: Correct unwind information for the second PLT
H.J. Lu [Fri, 1 Sep 2017 13:11:54 +0000 (06:11 -0700)]
x86: Correct unwind information for the second PLT

For i386, generate unwind information for the second PLT.  For x32,
correct alignment of .eh_frame section for the second PLT.

bfd/

PR ld/22061
* elf32-i386.c (elf_i386_link_setup_gnu_properties): Create
.eh_frame section for the second PLT.
* elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Correct
alignment of .eh_frame section for the second PLT.

ld/

PR ld/22061
* testsuite/ld-i386/ibt-plt-1.d: Updated.
* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
* testsuite/ld-i386/ibt-plt-2b.d: Pass --hash-style=sysv to ld
and dump unwind information.
* testsuite/ld-i386/ibt-plt-2d.d: Likewise.
* testsuite/ld-i386/ibt-plt-3b.d: Likewise.
* testsuite/ld-i386/ibt-plt-3d.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2b-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2b.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2d-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-2d.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3b-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3b.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3d-x32.d: Likewise.
* testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.

7 years agoEnable support for the AArch64 dot-prod instruction in the Cortex A55 and A75 cpus.
Tamar Christina [Fri, 1 Sep 2017 10:43:51 +0000 (11:43 +0100)]
Enable support for the AArch64 dot-prod instruction in the Cortex A55 and A75 cpus.

* config/tc-aarch64.c (aarch64_cpus): Enable DOTPROD for
cortex-a55 and cortx-a75.

7 years agoPrevent an address violation parsing corrupt DWARF information by fixing the test...
Nick Clifton [Fri, 1 Sep 2017 10:20:51 +0000 (11:20 +0100)]
Prevent an address violation parsing corrupt DWARF information by fixing the test for an overlong debug line info structure.

PR 22059
* dwarf2.c (decode_line_info): Fix test for an overlong line info
structure.

7 years agoImport latest fixes to libiberty from GCC.
Nick Clifton [Fri, 1 Sep 2017 09:52:53 +0000 (10:52 +0100)]
Import latest fixes to libiberty from GCC.

PR lto/81968
* simple-object-elf.c (simple_object_elf_copy_lto_debug_section):
Keep names of removed global symbols.

* simple-object-xcoff.c (simple_object_xcoff_find_sections):
Improve .go_export csect handling.  Don't make assumptions
on containing section or number of auxiliary entries.

PR lto/81968
* simple-object-elf.c (simple_object_elf_copy_lto_debug_section):
Adjust field with for sh_type write, set SHF_EXCLUDE only for
removed sections.

PR lto/81925
* simple-object-elf.c (simple_object_elf_write_shdr): Adjust
type of sh_addralign and sh_entsize and properly write
sh_entsize as Elf_Addr.
(simple_object_elf_write_to_file): Read sh_entsize as Elf_Addr.

* simple-object-common.h (struct simple_object_functions): Add
copy_lto_debug_sections hook.
* simple-object.c: Include fcntl.h.
(handle_lto_debug_sections): New helper function.
(simple_object_copy_lto_debug_sections): New function copying
early LTO debug sections to regular debug sections in a new file.
(simple_object_start_write): Handle NULL segment_name.
* simple-object-coff.c (simple_object_coff_functions): Adjust
for not implemented copy_lto_debug_sections hook.
* simple-object-mach-o.c (simple_object_mach_o_functions): Likewise.
* simple-object-xcoff.c (simple_object_xcoff_functions): Likewise.
* simple-object-elf.c (SHT_NULL, SHT_SYMTAB, SHT_RELA, SHT_REL,
SHT_GROUP): Add various sectopn header types.
(SHF_EXCLUDE): Add flag.
(Elf32_External_Sym, Elf64_External_Sym): Add symbol struct.
(ELF_ST_BIND, ELF_ST_TYPE, ELF_ST_INFO): Add accessors.
(STT_OBJECT, STT_FUNC, STT_TLS, STT_GNU_IFUNC): Add Symbol types.
(STV_DEFAULT): Add symbol visibility.
(SHN_COMMON): Add special section index name.
(struct simple_object_elf_write): New.
(simple_object_elf_start_write): Adjust for new private data.
(simple_object_elf_write_shdr): Pass in values for all fields
we write.
(simple_object_elf_write_to_file): Adjust.  Copy from recorded
section headers if requested.
(simple_object_elf_release_write): Release private data.
(simple_object_elf_copy_lto_debug_sections): Copy and rename sections
as denoted by PFN and all their dependences, symbols and relocations
to the empty destination file.
(simple_object_elf_functions): Adjust for copy_lto_debug_sections hook.

* simple-object-xcoff.c (simple_object_xcoff_find_sections):
Search symbol table for .go_export symbol and apply pfn if found.

7 years agoFix buffer overrun when parsing an ELF attribute string that is not NUL terminated.
Nick Clifton [Fri, 1 Sep 2017 08:57:44 +0000 (09:57 +0100)]
Fix buffer overrun when parsing an ELF attribute string that is not NUL terminated.

PR 22058
* elf-attrs.c (_bfd_elf_parse_attributes): Ensure that the
attribute buffer is NUL terminated.

7 years agoPR gdb/22046: Fix T-stopped detach regression on old Linux kernels
Jan Kratochvil [Fri, 1 Sep 2017 04:13:40 +0000 (06:13 +0200)]
PR gdb/22046: Fix T-stopped detach regression on old Linux kernels

On <=RHEL6 hosts Fedora/RHEL GDB started to 'kill -STOP' all processes it
detached.  Even those not originally T-stopped.  This is a Fedora-specific
patch which is based on upstream GDB's PROC_STATE_STOPPED state.

I believe (I did not verify) this patch did regress it:
commit d617208bb06bd461b52ce041d89f7127e3044762
Author: Pedro Alves <palves@redhat.com>
Date:   Mon Jul 25 12:42:17 2016 +0100
    linux-procfs: Introduce enum proc_state

As originally there was strstr() but now there is strcmp() and so the missing
trailing '\n' no longer matches.

The Bug was found by Michal Kolar.

Reproducibility:
$ gdb -p $PID
(gdb) quit
$ ...

Actual results:
===
RHEL6.9 x86_64 # scl enable devtoolset-7 bash
RHEL6.9 x86_64 # which gdb
/opt/rh/devtoolset-7/root/usr/bin/gdb
RHEL6.9 x86_64 # ./testcase.sh
24737 pts/0    S+     0:00 /bin/sleep 4
24737 pts/0    T+     0:00 /bin/sleep 4
RHEL6.9 x86_64 #
===

Expected results:
===
RHEL6.9 x86_64 # which gdb
/usr/bin/gdb
RHEL6.9 x86_64 # ./testcase.sh
24708 pts/0    S+     0:00 /bin/sleep 4
24708 pts/0    S+     0:00 /bin/sleep 4
./testcase.sh: line 20: kill: (24708) - No such process
RHEL6.9 x86_64 #
===

gdb/ChangeLog
2017-09-01  Jan Kratochvil  <jan.kratochvil@redhat.com>

PR gdb/22046
* nat/linux-procfs.c (parse_proc_status_state): Fix PROC_STATE_STOPPED
detection.

7 years agoAutomatic date update in version.in
GDB Administrator [Fri, 1 Sep 2017 00:00:25 +0000 (00:00 +0000)]
Automatic date update in version.in

7 years agoImplement the ability to set/unset environment variables to GDBserver when starting...
Sergio Durigan Junior [Thu, 29 Jun 2017 19:06:07 +0000 (15:06 -0400)]
Implement the ability to set/unset environment variables to GDBserver when starting the inferior

This patch implements the ability to set/unset environment variables
on the remote target, mimicking what GDB already offers to the user.
There are two features present here: user-set and user-unset
environment variables.

User-set environment variables are only the variables that are
explicitly set by the user, using the 'set environment' command.  This
means that variables that were already present in the environment when
starting GDB/GDBserver are not transmitted/considered by this feature.

User-unset environment variables are variables that are explicitly
unset by the user, using the 'unset environment' command.

The idea behind this patch is to store user-set and user-unset
environment variables in two separate sets, both part of gdb_environ.
Then, when extended_remote_create_inferior is preparing to start the
inferior, it will iterate over the two sets and set/unset variables
accordingly.  Three new packets are introduced:

- QEnvironmentHexEncoded, which is used to set environment variables,
  and contains an hex-encoded string in the format "VAR=VALUE" (VALUE
  can be empty if the user set a variable with a null value, by doing
  'set environment VAR=').

- QEnvironmentUnset, which is used to unset environment variables, and
  contains an hex-encoded string in the format "VAR".

- QEnvironmentReset, which is always the first packet to be
  transmitted, and is used to reset the environment, i.e., discard any
  changes made by the user on previous runs.

The QEnvironmentHexEncoded packet is inspired on LLDB's extensions to
the RSP.  Details about it can be seen here:

  <https://raw.githubusercontent.com/llvm-mirror/lldb/master/docs/lldb-gdb-remote.txt>

I decided not to implement the QEnvironment packet because it is
considered deprecated by LLDB.  This packet, on LLDB, serves the same
purpose of QEnvironmentHexEncoded, but sends the information using a
plain text, non-hex-encoded string.

The other two packets are new.

This patch also includes updates to the documentation, testsuite, and
unit tests, without introducing regressions.

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

* NEWS (Changes since GDB 8.0): Add entry mentioning new support
for setting/unsetting environment variables on the remote target.
(New remote packets): Add entries for QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset.
* common/environ.c (gdb_environ::operator=): Extend method to
handle m_user_set_env_list and m_user_unset_env_list.
(gdb_environ::clear): Likewise.
(match_var_in_string): Change type of first parameter from 'char
*' to 'const char *'.
(gdb_environ::set): Extend method to handle
m_user_set_env_list and m_user_unset_env_list.
(gdb_environ::unset): Likewise.
(gdb_environ::clear_user_set_env): New method.
(gdb_environ::user_set_envp): Likewise.
(gdb_environ::user_unset_envp): Likewise.
* common/environ.h (gdb_environ): Handle m_user_set_env_list and
m_user_unset_env_list on move constructor/assignment.
(unset): Add new default parameter 'update_unset_list = true'.
(clear_user_set_env): New method.
(user_set_envp): Likewise.
(user_unset_envp): Likewise.
(m_user_set_env_list): New std::set.
(m_user_unset_env_list): Likewise.
* common/rsp-low.c (hex2str): New function.
(bin2hex): New overload for bin2hex function.
* common/rsp-low.c (hex2str): New prototype.
(str2hex): New overload prototype.
* remote.c: Include "environ.h". Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset.
(remote_protocol_features): Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packets.
(send_environment_packet): New function.
(extended_remote_environment_support): Likewise.
(extended_remote_create_inferior): Call
extended_remote_environment_support.
(_initialize_remote): Add QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packet configs.
* unittests/environ-selftests.c (gdb_selftest_env_var):
New variable.
(test_vector_initialization): New function.
(test_init_from_host_environ): Likewise.
(test_reinit_from_host_environ): Likewise.
(test_set_A_unset_B_unset_A_cannot_find_A_can_find_B):
Likewise.
(test_unset_set_empty_vector): Likewise.
(test_vector_clear): Likewise.
(test_std_move): Likewise.
(test_move_constructor):
(test_self_move): Likewise.
(test_set_unset_reset): Likewise.
(run_tests): Rewrite in terms of the functions above.

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

* server.c (handle_general_set): Handle QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset packets.
(handle_query): Inform remote that QEnvironmentHexEncoded,
QEnvironmentUnset and QEnvironmentReset are supported.

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

* gdb.texinfo (set environment): Add @anchor.  Explain that
environment variables set by the user are sent to GDBserver.
(unset environment): Likewise, but for unsetting variables.
(Connecting) <Remote Packet>: Add "environment-hex-encoded",
"QEnvironmentHexEncoded", "environment-unset", "QEnvironmentUnset",
"environment-reset" and "QEnvironmentReset" to the table.
(Remote Protocol) <QEnvironmentHexEncoded, QEnvironmentUnset,
QEnvironmentReset>: New item, explaining the packet.

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

* gdb.base/share-env-with-gdbserver.c: New file.
* gdb.base/share-env-with-gdbserver.exp: Likewise.

7 years agoFix buffer read overrun by ensuring that DWARF sections containing strings always...
Nick Clifton [Thu, 31 Aug 2017 16:03:23 +0000 (17:03 +0100)]
Fix buffer read overrun by ensuring that DWARF sections containing strings always end in a NUL byte.

PR 22047
* dwarf2.c (read_section): If necessary add a terminating NUL byte
to dwarf string sections.

7 years agoAdd updated French translations for opcodes and gprof
Nick Clifton [Thu, 31 Aug 2017 13:33:56 +0000 (14:33 +0100)]
Add updated French translations for opcodes and gprof

7 years agoAdd a test for PR ld/22048
H.J. Lu [Thu, 31 Aug 2017 10:53:44 +0000 (03:53 -0700)]
Add a test for PR ld/22048

PR ld/22048
* testsuite/ld-x86-64/pr22048.d: New file.
* testsuite/ld-x86-64/pr22048a.s: Likewise.
* testsuite/ld-x86-64/pr22048b.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr22048.

7 years agoRegen SRC-POTFILES.in
Alan Modra [Thu, 31 Aug 2017 10:37:13 +0000 (20:07 +0930)]
Regen SRC-POTFILES.in

* po/SRC-POTFILES.in: Regenerate.