Commit Graph

91685 Commits

Author SHA1 Message Date
Andreas Arnez 1b63490c91 S390: Add guarded-storage register support to GDB
Recognize targets with the new guarded-storage feature and then present
the guarded-storage registers and the Linux-specific guarded-storage
broadcast control block appropriately.

gdb/ChangeLog:

	* s390-linux-nat.c (have_regset_gs): New static variable.
	(s390_linux_fetch_inferior_registers): Handle guarded-storage
	control block and guarded-storage broadcast control regsets.
	(s390_read_description): Detect whether the target has
	guarded-storage support, return appropriate tdesc.
	* s390-linux-tdep.c (features/s390-gs-linux64.c): New include.
	(features/s390x-gs-linux64.c): Likewise.
	(struct gdbarch_tdep) <have_gs>: New field.
	(s390_regmap_gs, s390_regmap_gsbc, s390_gs_regset)
	(s390_gsbc_regset): New variables.
	(s390_iterate_over_regset_sections): Iterate over s390_gs_regset
	and s390_gsbc_regset, if applicable.
	(s390_core_read_description): Check whether core file was from a
	target with guarded-storage support; include appropriate regsets.
	(s390_gdbarch_init): Add registers for guarded-storage support.
	(_initialize_s390_tdep): Initialize new target descriptions that
	include registers for guarded-storage support.
	* s390-linux-tdep.h (HWCAP_S390_GS, S390_GSD_REGNUM)
	(S390_GSSM_REGNUM, S390_GSEPLA_REGNUM)
	(S390_BC_GSD_REGNUM, S390_BC_GSSM_REGNUM): New defines.
	(S390_NUM_REGS): Adjust macro definition.
	(s390_gs_regset, s390_gsbc_regset, tdesc_s390_gs_linux64)
	(tdesc_s390x_gs_linux64): New declarations.
2017-09-25 16:02:23 +02:00
Andreas Arnez 96235dc1ac S390: Add guarded-storage register definitions and tdescs
Newer Linux kernel versions offer two new register sets in support of the
z/Architecture's guarded storage facility.  This patch adds XML
descriptions and the respective autogenerated .c and .dat files for
s390/s390x targets with this feature.

gdb/ChangeLog:

	* features/s390-gs-linux64.xml: New file.
	* features/s390-gs.xml: New file.
	* features/s390-gsbc.xml: New file.
	* features/s390x-gs-linux64.xml: New file.
	* features/Makefile (WHICH): Add s390-gs-linux64 and
	s390x-gs-linux64.
	(s390-gs-linux64-expedite, s390x-gs-linux64-expedite): New macros.
	(XMLTOC): Add s390-gs-linux64.xml and s390x-linux64.xml.
	* features/s390-gs-linux64.c: New generated file.
	* features/s390x-gs-linux64.c: New file.
	* regformats/s390-gs-linux64.dat: New file.
	* regformats/s390x-gs-linux64.dat: New file.
2017-09-25 16:02:23 +02:00
Alan Modra 1da5c9a485 PR22202, buffer overflow in parse_die
There was a complete lack of sanity checking in dwarf1.c

	PR 22202
	* dwarf1.c (parse_die): Sanity check pointer against section limit
	before dereferencing.
	(parse_line_table): Likewise.
2017-09-25 22:01:47 +09:30
Alan Modra 11855d8a1f PR22201, DW_AT_name with out of bounds reference
DW_AT_name ought to always have a string value.

	PR 22201
	* dwarf2.c (scan_unit_for_symbols): Ignore DW_AT_name unless it
	has string form.
	(parse_comp_unit): Likewise.
2017-09-25 22:01:47 +09:30
Alan Modra c361faae8d PR22200, DWARF5 .debug_line sanity check
The format_count entry can't be zero unless the count is also zero.

	PR 22200
	* dwarf2.c (read_formatted_entries): Error on format_count zero.
2017-09-25 22:01:47 +09:30
Sergio Durigan Junior 57a024f465 Initialize 'imm' on opcodes/aarch64-opc.c:expand_fp_imm (and fix breakage on mingw)
Hi,

While compiling GDB using a mingw compiler from Fedora 26:

  ../gdb/configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 \
    --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim \
    --disable-gprof  --enable-targets=all

I stumbled upon a simple occurrence of -Werror=maybe-uninitialized:

  ../../gdb/opcodes/aarch64-opc.c: In function 'expand_fp_imm':
  ../../gdb/opcodes/aarch64-opc.c:2880:10: error: 'imm' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     return imm;
	    ^~~

It is the compiler's fault, because this function always assigns to
'imm' if the necessary conditions are met, and it calls "assert (0)"
otherwise, but I thought it'd be clearer to have 'imm' explicitly set
to zero anyway.

opcodes/ChangeLog:
2017-09-21  Sergio Durigan Junior  <sergiodj@redhat.com>

	* aarch64-opc.c (expand_fp_imm): Initialize 'imm'.
2017-09-25 01:46:23 -04:00
GDB Administrator 5b3fd0aac2 Automatic date update in version.in 2017-09-25 00:00:24 +00:00
Alan Modra 52b36c51e5 PR22197, buffer overflow in bfd_get_debug_link_info_1
PR 22197
	* opncls.c (bfd_get_debug_link_info_1): Properly check that crc is
	within section bounds.
2017-09-24 21:40:58 +09:30
Alan Modra a26a013f22 PR22191, memory leak in dwarf2.c
table->sequences is a linked list before it is replaced by a bfd_alloc
array in sort_line_sequences.

	PR 22191
	* dwarf2.c (decode_line_info): Properly free line sequences on error.
2017-09-24 21:01:30 +09:30
Alan Modra 52a93b95ec PR22187, infinite loop in find_abstract_instance_name
This patch prevents the simple case of infinite recursion in
find_abstract_instance_name by ensuring that the attributes being
processed are not the same as the previous call.

The patch also does a little cleanup, and leaves in place some changes
to the nested_funcs array that I made when I wrongly thought looping
might occur in scan_unit_for_symbols.

	PR 22187
	* dwarf2.c (find_abstract_instance_name): Add orig_info_ptr and
	pname param.  Return status.  Make name const.  Don't abort,
	return an error.  Formatting.  Exit if current info_ptr matches
	orig_info_ptr.  Update callers.
	(scan_unit_for_symbols): Start at nesting_level of zero.  Make
	nested_funcs an array of structs for extensibility.  Formatting.
2017-09-24 16:17:19 +09:30
Alan Modra d8010d3e75 PR22186, divide-by-zero in decode_line_info
PR 22186
	* dwarf2.c (decode_line_info): Fail on lh.line_range of zero
	rather than dividing by zero.
2017-09-24 16:17:19 +09:30
Alan Modra 515f23e63c PR22169, heap-based buffer overflow in read_1_byte
The .debug_line header length field doesn't include the length field
itself, ie. it's the size of the rest of .debug_line.

	PR 22169
	* dwarf2.c (decode_line_info): Correct .debug_line unit_length check.
2017-09-24 16:15:14 +09:30
Alan Modra 0d76029f92 PR22167, NULL pointer dereference in scan_unit_for_symbols
PR 22167
	* dwarf2.c (scan_unit_for_symbols): Check u.blk->data is non-NULL.
2017-09-24 14:35:33 +09:30
Alan Modra bd61e13549 PR22166, SHT_GNU_verneed memory allocation
The sanity check covers the previous minimim size, plus that the size
is at least enough for sh_info verneed entries.

Also, since we write all verneed fields or exit with an error, there
isn't any need to zero the memory allocated for verneed entries.

	PR 22166
	* elf.c (_bfd_elf_slurp_version_tables): Test sh_info on
	SHT_GNU_verneed section for sanity.  Don't zalloc memory for
	verref.
2017-09-24 14:34:57 +09:30
GDB Administrator 8d296e2d4d Automatic date update in version.in 2017-09-24 00:00:26 +00:00
Tom Tromey b4a7c69968 Removed unused declaration
An earlier patch of mine removed make_cleanup_override_quit_handler,
but neglected to remove the declaration.  This patch removes it.
Tested by rebuilding.  I'm committing this as obvious.

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

	* defs.h (make_cleanup_override_quit_handler): Don't declare.
2017-09-23 14:13:12 -06:00
GDB Administrator 4102159923 Automatic date update in version.in 2017-09-23 00:00:27 +00:00
Tom Tromey c2f97536b7 Change type of scoped_input_handler::m_quit_handler
Simon pointed out that scoped_input_handler::m_quit_handler must have
the correct scoped_restore_tmpl type, to avoid binding to a temporary.
This patch fixes the problem.

gdb/ChangeLog
2017-09-22  Tom Tromey  <tom@tromey.com>

	* utils.c (class scoped_input_handler) <m_quit_handler>: Change
	type to scoped_restore_tmpl.
	<scoped_input_handler>: Initialize m_quit_handler directly.

Reviewed-By: Pedro Alves <palves@redhat.com>
2017-09-22 15:51:28 -06:00
H.J. Lu 61e3bf5f83 x86: Guard against corrupted PLT
There should be only one entry in PLT for a given symbol.  Set howto to
NULL after processing a PLT entry to guard against corrupted PLT so that
the duplicated PLT entries are skipped.

	PR binutils/22170
	* elfxx-x86.c (_bfd_x86_elf_get_synthetic_symtab): Guard against
	corrupted PLT.
2017-09-22 14:18:20 -07:00
H.J. Lu 59ca4c1bbd Update ChangeLog entry for PR 22163 2017-09-22 14:10:59 -07:00
Alexandre Oliva 9f27220911 LVU: dump loclists with locviews
When dumping location lists, also dump locview lists that may be
interspersed with them, and bring view pairs next to the corresponding
location list entries.

This patch supports DW_AT_GNU_locviews as a separate attribute for
DWARF4- loc_lists and split (dwo) loclists, as well as DWARF5
loclists.

It also supports, in DWARF5 loclists, the proposed
DW_LLE_GNU_view_pair loclist entry type proposed for DWARF6.


The tests use 32-bit DWARF, even on 64-bit targets, resolving offsets
to constants so as to reduce the risk that relocations be created for
them, or that the offsets be rejected as nonconstants.


The patch also adds an xfail to an unrelated test, namely dw5, so that
no unexpected fails remain on nds32*-elf, one of the tested targets.


Reviewed-by: Alan Modra <amodra@gmail.com>


for  include/ChangeLog

	* dwarf2.def (DW_AT_GNU_locviews): New.
	* dwarf2.h (enum dwarf_location_list_entry_type): Add
	DW_LLE_GNU_view_pair.
	(DW_LLE_view_pair): Define.

for  binutils/ChangeLog

	* dwarf.h (debug_info): Add loc_views and num_loc_views.
	* dwarf.c (vm1): New constant.
	(print_dwarf_view): New function.
	(read_and_display_attr_value): Support DW_AT_GNU_locviews.
	(process_debug_info): Keep num_loc_offsets and num_loc_views
	in sync.
	(display_view_pair_list): New function.
	(display_loc_list_dwo): Take vstart_ptr; update it.  Dump
	location view pairs before the range they apply to, when a
	viewlist augments the loc list.
	(display_loc_list): Likewise.  Check view numbers in range
	tests.
	(display_loclists_list): Likewise.  Handle view pair entries,
	and warn on trailing ones.
	(loc_views): New variable.
	(loc_offsets_compar): Compare loc_views if loc_offsets are the
	same.
	(display_debug_loc): Check and sort loc_views too.  Accept
	loc_view as expected_start.  Skip if lists and views are the
	same.  Dump locview list separately in order, and pass the
	locview list base to each list dump function.  Warn and skip
	overlap and hole checking if we find loclists and locviews to
	not be adjacent.
	* testsuite/binutils-all/locview-1.s: New.
	* testsuite/binutils-all/readelf.locview-1: New.
	* testsuite/binutils-all/locview-2.s: New.
	* testsuite/binutils-all/readelf.locview-2: New.
	* testsuite/binutils-all/readelf.exp: Run new tests.  Fix
	option spelling in pr18374 fail message.  XFAIL dw5 test on
	nds32*-elf.
2017-09-22 17:05:51 -03:00
Sergio Durigan Junior 43573013c9 Get rid of "gdb_dirbuf" and use "getcwd (NULL, 0)"
Currently we have "current_directory" and "gdb_dirbuf" globals, which
means that we basically have two possible places to consult when we
want to know GDB's current working directory.

This is not ideal and can lead to confusion.  Moreover, the way we're
using "gdb_difbuf" along with "getcwd" is problematic because we
declare the buffer with "1024" elements hardcoded, which does not take
into account longer pathnames that are possible in many filesystems.
Using "PATH_MAX" would also not be a solution because of portability
problems.  Therefore, the best solution is to rely on the fact that
"getcwd (NULL, 0)" will "do the right thing" and return a
heap-allocated string containing the full path.  With the new "getcwd"
module from gnulib, it is now possible to do that without worrying
about breaking some host.

With this patch "current_directory" is now the only place to check for
GDB's cwd.

Reviewed-by: Pedro Alves <palves@redhat.com>

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

	* cli/cli-cmds.c (pwd_command): Use "getcwd (NULL, 0)".
	(cd_command): Likewise.  Free "current_directory" before
	assigning to it.
	* main.c (captured_main_1): Use "getcwd (NULL, 0)".
	* mi/mi-cmd-env.c (mi_cmd_env_pwd): Likewise.
	* top.c (gdb_dirbuf): Remove global declaration.
	* top.h (gdb_dirbuf): Likewise.
2017-09-22 13:28:16 -04:00
Sergio Durigan Junior 6ec2e0f5bd Import "glob" and "getcwd" modules from gnulib
These two modules are necessary because of the rework that will be
done in the "change directory" logic on GDB/gdbserver in the next
commits.

First, we will get rid of the "gdb_dirbuf" global variable and instead
rely on the fact that "getcwd (NULL, 0)", which is a GNU extension,
returns a heap-allocated string with the necessary bytes to hold the
full path.  This is a good practice not only because globals are not
ideal but also because there is no good way to know beforehand the
size of the full pathname allowed in the filesystem ("PATH_MAX" is not
portable and does not reflect all the possible filesystems out there).

We will also have a way to "cd" to a directory also on gdbserver, but
in order to do that uniformly, there must be a way to do tilde
expansion on directories provided by the user.  Currently, GDB uses
"tilde_expand" from readline to do that, but gdbserver doesn't link
against readline and therefore cannot use this function.  The solution
is to use "glob" instead, which can perform tilde expansion as a GNU
extension.  Therefore, we need gnulib's version of "glob".

A special note is necessary for gdb/ser-tcp.c.  It defines "close" as
"closesocket" on Win32 targets.  If we leave the code as is, this
would conflict with gnulib's definition of "close".  Therefore, in
order to keep the same code path from before this import, I decided to
"#undef close" first, and then let the original (re)definition of it
take place.

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

	* gnulib/aclocal.m4: Regenerate.
	* gnulib/config.in: Regenerate.
	* gnulib/configure: Regenerate.
	* gnulib/import/Makefile.am: Regenerate.
	* gnulib/import/Makefile.in: Regenerate.
	* gnulib/import/assure.h: New file.
	* gnulib/import/at-func.c: Likewise
	* gnulib/import/chdir-long.c: New file.
	* gnulib/import/chdir-long.h: New file.
	* gnulib/import/cloexec.c: New file.
	* gnulib/import/cloexec.h: New file.
	* gnulib/import/close.c: New file.
	* gnulib/import/closedir.c: New file.
	* gnulib/import/dirent-private.h: New file.
	* gnulib/import/dup-safer.c: New file.
	* gnulib/import/dup.c: New file.
	* gnulib/import/dup2.c: New file.
	* gnulib/import/error.c: New file.
	* gnulib/import/error.h: New file.
	* gnulib/import/exitfail.c: New file.
	* gnulib/import/exitfail.h: New file.
	* gnulib/import/fchdir.c: New file.
	* gnulib/import/fcntl.c: New file.
	* gnulib/import/fcntl.in.h: New file.
	* gnulib/import/fd-hook.c: New file.
	* gnulib/import/fd-hook.h: New file.
	* gnulib/import/fd-safer.c: New file.
	* gnulib/import/fdopendir.c: New file.
	* gnulib/import/filename.h: New file.
	* gnulib/import/filenamecat-lgpl.c: New file.
	* gnulib/import/filenamecat.h: New file.
	* gnulib/import/fstat.c: New file.
	* gnulib/import/fstatat.c: New file.
	* gnulib/import/getcwd-lgpl.c: New file.
	* gnulib/import/getcwd.c: New file.
	* gnulib/import/getdtablesize.c: New file.
	* gnulib/import/getlogin_r.c: New file.
	* gnulib/import/getprogname.c: New file.
	* gnulib/import/getprogname.h: New file.
	* gnulib/import/gettext.h: New file.
	* gnulib/import/glob-libc.h: New file.
	* gnulib/import/glob.c: New file.
	* gnulib/import/glob.in.h: New file.
	* gnulib/import/intprops.h: New file.
	* gnulib/import/m4/chdir-long.m4: New file.
	* gnulib/import/m4/close.m4: New file.
	* gnulib/import/m4/closedir.m4: New file.
	* gnulib/import/m4/d-ino.m4: New file.
	* gnulib/import/m4/d-type.m4: New file.
	* gnulib/import/m4/dup.m4: New file.
	* gnulib/import/m4/dup2.m4: New file.
	* gnulib/import/m4/error.m4: New file.
	* gnulib/import/m4/fchdir.m4: New file.
	* gnulib/import/m4/fcntl.m4: New file.
	* gnulib/import/m4/fcntl_h.m4: New file.
	* gnulib/import/m4/fdopendir.m4: New file.
	* gnulib/import/m4/filenamecat.m4: New file.
	* gnulib/import/m4/fstat.m4: New file.
	* gnulib/import/m4/fstatat.m4: New file.
	* gnulib/import/m4/getcwd-abort-bug.m4: New file.
	* gnulib/import/m4/getcwd-path-max.m4: New file.
	* gnulib/import/m4/getcwd.m4: New file.
	* gnulib/import/m4/getdtablesize.m4: New file.
	* gnulib/import/m4/getlogin_r.m4: New file.
	* gnulib/import/m4/getprogname.m4: New file.
	* gnulib/import/m4/glob.m4: New file.
	* gnulib/import/m4/gnulib-cache.m4: Regenerate.
	* gnulib/import/m4/gnulib-comp.m4: Regenerate.
	* gnulib/import/m4/mempcpy.m4: New file.
	* gnulib/import/m4/memrchr.m4: New file.
	* gnulib/import/m4/mode_t.m4: New file.
	* gnulib/import/m4/msvc-inval.m4: New file.
	* gnulib/import/m4/msvc-nothrow.m4: New file.
	* gnulib/import/m4/open.m4: New file.
	* gnulib/import/m4/openat.m4: New file.
	* gnulib/import/m4/opendir.m4: New file.
	* gnulib/import/m4/readdir.m4: New file.
	* gnulib/import/m4/realloc.m4: New file.
	* gnulib/import/m4/rewinddir.m4: New file.
	* gnulib/import/m4/save-cwd.m4: New file.
	* gnulib/import/m4/strdup.m4: New file.
	* gnulib/import/m4/strerror.m4: New file.
	* gnulib/import/m4/unistd-safer.m4: New file.
	* gnulib/import/mempcpy.c: New file.
	* gnulib/import/memrchr.c: New file.
	* gnulib/import/msvc-inval.c: New file.
	* gnulib/import/msvc-inval.h: New file.
	* gnulib/import/msvc-nothrow.c: New file.
	* gnulib/import/msvc-nothrow.h: New file.
	* gnulib/import/open.c: New file.
	* gnulib/import/openat-die.c: New file.
	* gnulib/import/openat-priv.h: New file.
	* gnulib/import/openat-proc.c: New file.
	* gnulib/import/openat.c: New file.
	* gnulib/import/openat.h: New file.
	* gnulib/import/opendir.c: New file.
	* gnulib/import/pipe-safer.c: New file.
	* gnulib/import/readdir.c: New file.
	* gnulib/import/realloc.c: New file.
	* gnulib/import/rewinddir.c: New file.
	* gnulib/import/save-cwd.c: New file.
	* gnulib/import/save-cwd.h: New file.
	* gnulib/import/strdup.c: New file.
	* gnulib/import/strerror-override.c: New file.
	* gnulib/import/strerror-override.h: New file.
	* gnulib/import/strerror.c: New file.
	* gnulib/import/unistd--.h: New file.
	* gnulib/import/unistd-safer.h: New file.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add
	"getcwd" and "glob".
	* ser-tcp.c: Undefine "close" before redefining it.
2017-09-22 13:28:03 -04:00
Jim Wilson 0cf44ec826 [GOLD] Set non-exec stack for aarch64
GNU-stack notes added in 2004, aarch64 port added in 2012, so no old object
files with missing GNU-stack notes that we need to worry about.

	gold/
	* aarch64.cc (Target_aarch64::aarch64_info): Set
	is_default_stack_executable to false.
2017-09-22 07:58:28 -07:00
Simon Marchi cc4d742f4c gdbserver x86 on win32: call init_target_desc
When trying to run gdbserver compiled for x86 win32 under wine, I get:

  $ wine ./gdbserver/gdbserver.exe --once :1234 ./test
  /home/emaisin/src/binutils-gdb/gdb/gdbserver/regcache.c:177: A problem internal to GDBserver has been detected.
  regcache* new_register_cache(const target_desc*): Assertion `tdesc->registers_size != 0' failed.

It seems like on that platform, init_target_desc is never called, so
registers_size is never computed.

My first thought was to call init_target_desc somewhere in win32-low.c,
but it turns out that when using win32 on arm, the target description is
already initialized by the generated code.  My second thought was to
call it in {i386,amd64}_create_target_description, but those functions
are shared with GDB, and init_target_desc is gdbserver-specific.  So I
ended up with the simplest fix, calling it in i386_arch_setup.

Now I hit some other problem:

  $ wine ./gdbserver/gdbserver.exe --once :1234 ./test
  Killing process(es): 39
  No program to debug
  Exiting

but still, I think fixing the tdesc issue this is a step forward.

gdb/gdbserver/ChangeLog:

	* win32-i386-low.c (i386_arch_setup): Call init_target_desc.
2017-09-22 16:51:55 +02:00
H.J. Lu b69e9267d1 x86: Return -1 if bfd_canonicalize_dynamic_reloc returns 0
Stop if bfd_canonicalize_dynamic_reloc returns 0.

	PR ld/22163
	* elfxx-x86.c (_bfd_x86_elf_get_synthetic_symtab): Also return
	-1 if bfd_canonicalize_dynamic_reloc returns 0.
2017-09-22 07:25:16 -07:00
H.J. Lu be2b629f64 Add a test for PR ld/22150
PR ld/22150
	* testsuite/ld-elf/pr22150.vd: New file.
	* testsuite/ld-elf/pr22150.ver: Likewise.
	* testsuite/ld-elf/pr22150a.s: Likewise.
	* testsuite/ld-elf/pr22150b.s: Likewise.
	* testsuite/ld-elf/shared.exp: Run PR ld/22150 tests.
2017-09-22 07:05:53 -07:00
Pedro Alves b877d21f34 bfd/version.h: Add rationale for BFD_VERSION_DATE
bfd/ChangeLog:
2017-09-22  Pedro Alves  <palves@redhat.com>
	    Alan Modra  <amodra@gmail.com>

	* version.h: Add comment.
2017-09-22 14:57:52 +01:00
Simon Marchi 432ae719d3 Fix sometimes-uninitialized warning in gdbscm_value_address
I am getting this warning with clang:

/home/emaisin/src/binutils-gdb/gdb/guile/scm-value.c:439:11: error: variable 'address' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
      if (res_val != NULL)
          ^~~~~~~~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/guile/scm-value.c:444:32: note: uninitialized use occurs here
      if (gdbscm_is_exception (address))
                               ^~~~~~~
/home/emaisin/src/binutils-gdb/gdb/guile/scm-value.c:439:7: note: remove the 'if' if its condition is always true
      if (res_val != NULL)
      ^~~~~~~~~~~~~~~~~~~~
/home/emaisin/src/binutils-gdb/gdb/guile/scm-value.c:427:18: note: initialize the variable 'address' to silence this warning
      SCM address;
                 ^
                  = nullptr

We can get rid of it with a small refactoring.  I think it's a bit
cleaner/safer to initialize address with a pessimistic value and assign
it on success.  Then there's no chance of using it uninitialized.  If I
understand correctly, the NULL check on res_val was to check whether
value_addr threw, and that if value_addr returns without throwing, the
result will never be NULL.  If that's true, we can skip the res_val
variable.

Tested by running gdb.guile/*.exp locally.

gdb/ChangeLog:

	* guile/scm-value.c (gdbscm_value_address): Initialize address,
	get rid of res_val.
2017-09-22 10:47:19 +02:00
Rainer Orth 4fa7574eec Fix gdb 8.1 Solaris compilation
I just tried to compile gdb trunk on Solaris 11.4 (formerly 12), and
failed for a couple of reasons:

*

In file included from /usr/include/python2.7/Python.h:128:0,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/python/python-internal.h:94,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/python/py-instruction.h:23,
                 from /vol/src/gnu/gdb/gdb/dist/gdb/python/py-instruction.c:21:
/usr/include/python2.7/ceval.h:67:0: error: ignoring #pragma no_inline  [-Werror=unknown-pragmas]
 #pragma no_inline(PyEval_EvalFrameEx)
 ^

  New in Solaris 11.4: <python2.7/ceval.h> uses a Studio-only #pragma.
  I've disabled the warning in warnings.m4.

*

/vol/src/gnu/gdb/gdb/dist/gdb/ser-pipe.c: In function ‘int pipe_open(serial*, const char*)’:
/vol/src/gnu/gdb/gdb/dist/gdb/ser-pipe.c:77:9: error: ‘pid_t vfork()’ is deprecated (declared at /usr/include/unistd.h:659) [-Werror=deprecated-declarations]
   pid = vfork ();
         ^
/vol/src/gnu/gdb/gdb/dist/gdb/ser-pipe.c:77:16: error: ‘pid_t vfork()’ is deprecated (declared at /usr/include/unistd.h:659) [-Werror=deprecated-declarations]
   pid = vfork ();
                ^

  Since Solaris 11, vfork () is marked deprecated in <unistd.h>.

  cf. vfork(2):

       The  vfork()  and vforkx() functions are deprecated. Their sole legiti-
       mate use as a prelude to an immediate call to a function from the  exec
       family can be achieved safely by posix_spawn(3C) or posix_spawnp(3C).

  Again, I've disabled the warning.

*

/vol/src/gnu/gdb/gdb/dist/gdb/cli/cli-cmds.c: In function ‘void shell_escape(const char*, int)’:
/vol/src/gnu/gdb/gdb/dist/gdb/cli/cli-cmds.c:750:14: error: ‘pid_t vfork()’ is deprecated (declared at /usr/include/unistd.h:659) [-Werror=deprecated-declarations]
   if ((pid = vfork ()) == 0)
              ^
/vol/src/gnu/gdb/gdb/dist/gdb/cli/cli-cmds.c:750:21: error: ‘pid_t vfork()’ is deprecated (declared at /usr/include/unistd.h:659) [-Werror=deprecated-declarations]
   if ((pid = vfork ()) == 0)
                     ^

  Same problem.

*

/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c: In function ‘void procfs_init_inferior(target_ops*, int)’:
/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c:4380:30: error: ‘START_INFERIOR_TRAPS_EXPECTED’ was not declared in this scope
   gdb_startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED);
                              ^

  defined in nat/fork-inferior.h, need to include that header

/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c: In function ‘void procfs_create_inferior(target_ops*, const char*, const string&, char**, int)’:
/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c:4605:38: error: ‘fork_inferior’ was not declared in this scope
          NULL, NULL, shell_file, NULL);
                                      ^

  likewise

/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c: In function ‘void procfs_info_proc(target_ops*, const char*, info_proc_what)’:
/vol/src/gnu/gdb/gdb/dist/gdb/procfs.c:5124:20: error: ‘argv’ was not declared in this scope
   for (char *arg : argv)
                    ^

  Typo, should be built_argv instead!

*

Undefined                       first referenced
 symbol                             in file
fork_inferior(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char**, void (*)(), void (*)(int), void (*)(), char const*, void (*)(char const*, char* const*, char* const*)) procfs.o
startup_inferior(int, int, target_waitstatus*, ptid_t*) fork-child.o
ld: fatal: symbol referencing errors
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:2249: gdb] Error 1

  Need to add fork-inferior.o to NATDEPFILES.

With the changes below, I can build gdb on sparcv9-sun-solaris2.11 and
amd64-pc-solaris2.11 and a simple smoke test (gdb/gdb gdb/gdb) works.
2017-09-22 10:42:45 +02:00
Alan Modra 7790bd6c74 [GOLD] clone assert breakage
* resolve.cc (clone): Fix got_offset_list test.
2017-09-22 15:20:12 +09:30
Alan Modra ec76901011 [GOLD] Set non-exec stack for ppc64
gcc doesn't emit stack notes for ELFv1, since ELFv1 never needs an
executable stack.  Note that ELFv1 is usually big-endian and ELFv2
little-endian, but the ABI is really orthogonal to endiannes.

	* powerpc.cc (Target_powerpc<64,*>::powerpc_info): Set
	is_default_stack_executable false.
2017-09-22 11:47:02 +09:30
Alan Modra 11bb0c7abc readelf tests
We have multiple tests that report failure to assemble without saying
exactly what test is failing.

	* testsuite/binutils-all/readelf.exp: Don't perror and exit on
	bintest.s assembly failure.  Report tests unresolved instead.
	Likewise for version note test, pr18374, decompress, and dw5
	tests.
	(readelf_test): Set testname to include both option and binary
	file name.  Use for pass/fail.
2017-09-22 11:45:55 +09:30
GDB Administrator df52f331ed Automatic date update in version.in 2017-09-22 00:00:27 +00:00
Maciej W. Rozycki ef272caa74 readelf: Handle E_MIPS_MACH_5900
Fix commit e407c74b5b ("Support for MIPS R5900 (Sony Playstation 2)"),
<https://sourceware.org/ml/binutils/2012-12/msg00240.html>, and add the
handling of E_MIPS_MACH_5900, correctly showing `5900' among `Flags:' in
the output of `-h' rather than `unknown CPU'.

	binutils/
	* readelf.c (get_machine_flags) <E_MIPS_MACH_5900>: New case.

	gas/
	* testsuite/gas/mips/elf_mach_5900.d: New test.
	* testsuite/gas/mips/mips.exp: Run it.
2017-09-22 00:54:19 +01:00
James Cowgill 42c0794e96 PR gas/21762: MIPS: Fix .stabs directive marking labels as MIPS16
If a .stabs directive was used before another .set directive in a MIPS
source file, s_mips_stab would call mips_mark_labels without having
initialized the mips_opts structure yet.  Fix this by calling
file_mips_check_options which will initialize mips_opts if necessary.

gas/
	PR gas/21762
	* config/tc-mips.c (s_mips_stab): Insert call to
	file_mips_check_options.
	* testsuite/gas/mips/micromips@stabs-symbol-type.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.
	* testsuite/gas/mips/mips16@stabs-symbol-type.d: New test.
	* testsuite/gas/mips/stabs-symbol-type.d: New test.
	* testsuite/gas/mips/stabs-symbol-type.s: New test source.
2017-09-22 00:54:19 +01:00
Kevin Buettner 757bf54bb4 Test case for Inferior.thread_from_thread_handle
As the title says, this is a test case for
Inferior.thread_from_thread_handle, a python method which will,
given a thread library dependent thread handle, find the GDB thread
which corresponds to that thread handle (in the inferior under
consideration).

The C file for this test case causes the thread handles for the
main thread and two child threads to be placed into an array.  The
test case runs to one of the functions (do_something()) at which point,
it retrieves the thread handles from the array and attempts to find the
corresponding thread in GDB's internal thread list.

I use barriers to make sure that both threads have actually started;
execution will stop when one of the threads breaks at do_something.

Thanks to Simon Marchi for suggestions for forcing the thread
numbering to be stable.

gdb/testsuite/ChangeLog:

	* gdb.python/py-thrhandle.c, gdb.python/py-thrhandle.exp: New
	files.
2017-09-21 11:49:48 -07:00
Kevin Buettner f2ff95c583 Documentation for qXfer:threads:read handle attribute
gdb/doc/ChangeLog:

	* gdb.texinfo (qXfer:threads:read): Add documentation for handle
	attribute.
2017-09-21 11:49:48 -07:00
Kevin Buettner f6327dcbf0 Add thread_handle_to_thread_info support for remote targets
This patch adds support to remote targets for converting a thread
handle to a thread_info struct pointer.

A thread handle is fetched via a "handle" attribute which has been
added to the qXfer:threads:read query packet.  An implementation is
provided in gdbserver for targets using the Linux kernel.

gdb/gdbserver/ChangeLog:

	* linux-low.h (struct lwp_info): Add new field, thread_handle.
	(thread_db_thread_handle): Declare.
	* linux-low.c (linux_target_ops): Initialize thread_handle.
	* server.c (handle_qxfer_threads_worker): Add support for
	"handle" attribute.
	* target.h (struct target_ops): Add new function pointer,
	thread_handle.
	(target_thread_handle): Define.
	* thread-db.c (find_one_thread, attach_thread): Set thread_handle
	field in lwp.
	(thread_db_thread_handle): New function.

gdb/ChangeLog:

	* remote.c (vector): Include.
	(struct private_thread_info): Add field, thread_handle.
	(free_private_thread_info): Deallocate storage associated with
	thread handle.
	(get_private_info_thread): Initialize `thread_handle' field.
	(struct thread_item): Add field, thread_handle.
	(clear_threads_listing_context): Deallocate storage associated
	with thread handle.
	(start_thread): Add support for "handle" attribute.
	(thread_attributes): Add "handle".
	(remote_get_threads_with_qthreadinfo): Initialize thread_handle
	field.
	(remote_update_thread_list): Update thread_handle.
	(remote_thread_handle_to_thread_info): New function.
	(init_remote_ops): Initialize to_thread_handle_to_thread_info.
2017-09-21 11:49:47 -07:00
Kevin Buettner 8629910955 Add thread_db_notice_clone to gdbserver
While working on a patch for fetching a thread handle in gdbserver, I
ran into a circumstance in which tests in gdb.mi/mi-nsmoribund.exp
would occasionally fail.  Over a large enough number of runs, it would
fail roughly 2% of the time.

That thread handle patch caused find_one_thread() to be called on
every stop.  find_one_thread() calls td_ta_map_lwp2thr() which, in
turn, can cause ps_get_thread_area() to be called.
ps_get_thread_area() makes a call to ptrace() for getting the thread
area address.  If this should happen when the thread is not stopped,
the call to ptrace will return error which in turn propogates back to
find_one_thread().  find_one_thread() calls error() in this instance
which causes the program to die.

This patch causes find_one_thread() to be called upon reciept of a
clone event.  Since the clone is stopped, the circumstances described
above cannot occur.

gdb/gdbserver/ChangeLog:

	* linux-low.c (handle_extended_wait): Call thread_db_notice_clone().
	* linux-low.h (thread_db_notice_clone): Declare.
	* thread-db.c (thread_db_notice_clone): New function.
2017-09-21 11:49:47 -07:00
Kevin Buettner da2c323bff Documentation for Inferior.thread_from_thread_handle
gdb/doc/ChangeLog:

	* python.texi (Inferiors In Python): Add description for method
	Inferior.thread_from_thread_handle.
2017-09-21 11:49:46 -07:00
Kevin Buettner fbbe5337a6 Add `thread_from_thread_handle' method to (Python) gdb.Inferior
gdb/ChangeLog:
	* python/py-inferior.c (gdbpy_thread_from_thread_handle): New
	function.
	(inferior_object_methods): Add gdbpy_thread_from_thread_handle.
	* python/python-internal.h (thread_object_type): Declare.
2017-09-21 11:20:51 -07:00
Kevin Buettner e04ee09e24 Add target method for converting thread handle to thread_info struct pointer
This patch adds a target method named `to_thread_handle_to_thread_info'.
It is intended to map a thread library specific thread handle (such as
pthread_t for the pthread library) to the corresponding GDB internal
thread_info struct (pointer).

An implementation is provided for Linux pthreads; see linux-thread-db.c.

gdb/ChangeLog:

	* target.h (struct target_ops): Add to_thread_handle_to_thread_info.
	(target_thread_handle_to_thread_info): Declare.
	* target.c (target_thread_handle_to_thread_info): New function.
	* target-delegates.c: Regenerate.
	* gdbthread.h (find_thread_by_handle): Declare.
	* thread.c (find_thread_by_handle): New function.
	* linux-thread-db.c (thread_db_thread_handle_to_thread_info): New
	function.
	(init_thread_db_ops): Register thread_db_thread_handle_to_thread_info.
2017-09-21 11:19:10 -07:00
Pedro Alves f557a88ab1 gdbserver: Remove traces of ancient Hc handling
Back in commit f0db101d98 ("gdbserver: don't pick a random thread if
the current thread dies"), a couple years ago, the last references to
set_desired_thread(0) [select the Hc thread] were removed, and all the
remaining calls to set_desired_thread pass '1', meaning general
thread.  This means we can simplify set_desired_thread.

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

	* server.c (gdb_read_memory, handle_status, process_serial_event)
	(handle_serial_event, handle_target_event): Adjust to
	set_desired_thread prototype change.
	* target.c (set_desired_thread): Remove 'use_general' parameter
	and adjust.
	* target.h (set_desired_thread): Remove 'use_general' parameter.
2017-09-21 16:52:33 +01:00
Andreas Arnez 8fe09d7421 S/390: Fix Elf note swap s390_gs_bc vs. s390_gs_cb
Fix two typos that resulted in swapping the BFD names for the core note
register sections NT_S390_GS_CB and NT_S390_GS_BC.

bfd/ChangeLog:

	* elf.c (elfcore_grok_note): For the cases NT_S390_GS_CB and
	NT_S390_GS_BC, correct the previously swapped invocations of
	elfcore_grok_s390_gs_bc and elfcore_grok_s390_gs_cb.
2017-09-21 17:45:18 +02:00
Alan Modra ba52cbb9d0 Reduce excessive .eh_frame alignment for powerpc
PowerPC64 .cfi directives use DW_EH_PE_sdata4 encoding for .eh_frame,
so there is no real reason why .eh_frame should be 8 byte aligned.

gas/
	* config/tc-ppc.h (EH_FRAME_ALIGNMENT): Define.
ld/
	* testsuite/ld-powerpc/tlsopt5.wf: Update for reduced alignment.
2017-09-21 23:17:44 +09:30
Simon Marchi 1e5b66ed42 linux-waitpid: Get rid of format string warning
Clang gives this warning:

/home/emaisin/src/binutils-gdb/gdb/gdbserver/../nat/linux-waitpid.c:45:25: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
      vfprintf (stderr, format, args);
                        ^~~~~~

Get rid of it by adding ATTRIBUTE_PRINTF.

gdb/ChangeLog:

	* nat/linux-waitpid.c (linux_debug): Add ATTRIBUTE_PRINTF.
2017-09-21 15:19:40 +02:00
Simon Marchi ebe48ba085 microblaze-tdep: Add ATTRIBUTE_PRINTF to microblaze_debug
I am getting this warning with clang:

/home/emaisin/src/binutils-gdb/gdb/microblaze-tdep.c:94:28: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
       vprintf_unfiltered (fmt, args);
                           ^~~

Adding ATTRIBUTE_PRINTF to microblaze_debug gets rid of it.  Strangely,
gcc doesn't warn about non-literal format strings when calling vprintf
(or a vprintf-style function, like vprintf_unfiltered).  I filed this
gcc bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82206

gdb/ChangeLog:

	* microblaze-tdep.c (microblaze_debug): Add ATTRIBUTE_PRINTF.
2017-09-21 14:09:33 +02:00
Yao Qi 0a0bf5dc14 Fix aarch64-freebsd build failure
I happen to see that fbsd-tdep.o is missing for target aarch64-freebsd,
and it causes the build failure,

aarch64-fbsd-tdep.o: In function `aarch64_fbsd_init_abi(gdbarch_info, gdbarch*)':
binutils-gdb/gdb/aarch64-fbsd-tdep.c:186: undefined reference to `fbsd_init_abi(gdbarch_info, gdbarch*)'
binutils-gdb/gdb/aarch64-fbsd-tdep.c:189: undefined reference to `svr4_lp64_fetch_link_map_offsets()'
binutils-gdb/gdb/aarch64-fbsd-tdep.c:189: undefined reference to `set_solib_svr4_fetch_link_map_offsets(gdbarch*, link_map_offsets* (*)())'

This patch fixed it.

gdb:

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

	* configure.tgt (aarch64*-*-freebsd*): Add fbsd-tdep.o solib-svr4.o
	to gdb_target_obs.
2017-09-21 09:20:05 +01:00
Nick Clifton ea5cf0fe29 oops - changelog entry omitted from previous delta 2017-09-21 09:07:11 +01:00