Commit Graph

42359 Commits

Author SHA1 Message Date
Andrew Burgess 4a270568d9 gdb/fortran: Use TYPE_CODE_CHAR for character types
Switch to using TYPE_CODE_CHAR for character types.  This appears to
have little impact on the test results as gFortran uses the
DW_TAG_string_type to represent all character variables (as far as I
can see).  The only place this has an impact is when the user casts a
variable to a character type, in which case GDB does now use the CHAR
type, and prints the variable as both a value and a character, for
example, before:

    (gdb) p ((character) 97)
    $1 = 97

and after:

    (gdb) p ((character) 97)
    $1 = 97 'a'

gdb/ChangeLog:

	* f-lang.c (build_fortran_types): Use TYPE_CODE_CHAR for character
	types.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp: Update expected results.
2019-03-06 18:11:31 +00:00
Andrew Burgess 067630bdb5 gdb/fortran: Add builtin 8-byte integer type with (kind=8) support
Add a new builtin type, an 8-byte integer, and allow GDB to parse
'integer (kind=8)', returning the new 8-byte integer.

gdb/ChangeLog:

	* f-exp.y (convert_to_kind_type): Handle integer (kind=8).
	* f-lang.c (build_fortran_types): Setup builtin_integer_s8.
	* f-lang.h (struct builtin_f_type): Add builtin_integer_s8 field.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp: Test new integer type kind.
2019-03-06 18:11:31 +00:00
Andrew Burgess 3be47f7aa9 gdb/fortran: Expand the set of types that support (kind=N)
Expand the number of types that can be adjusted with a (kind=N) type
extension.

gdb/ChangeLog:

	* f-exp.y (convert_to_kind_type): Handle more type kinds.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): New
	function.
	(test_basic_parsing_of_type_kinds): Expand types tested.
	(test_parsing_invalid_type_kinds): New function.
2019-03-06 18:11:31 +00:00
Andrew Burgess 4d00f5d8f6 gdb/fortran: Add Fortran 'kind' intrinsic and keyword
The 'kind' keyword has two uses in Fortran, it is the name of a
builtin intrinsic function, and it is also a keyword used to create a
type of a specific kind.

This commit adds support for using kind as an intrinsic function, and
also adds some initial support for using kind to create types of a
specific kind.

This commit only allows the creation of the type 'character(kind=1)',
however, it will be easy enough to extend this in future to support
more type kinds.

The kind of any expression can be queried using the kind intrinsic
function.  At the moment the kind returned corresponds to the size of
the type, this matches how gfortran handles kinds.  However, the
correspondence between kind and type size depends on the compiler
and/or the specific target, so this might not be correct for
everyone.  If we want to support different compilers/targets in future
the code to compute the kind from a type will need to be updated.

gdb/ChangeLog:

	* expprint.c (dump_subexp_body_standard): Support UNOP_KIND.
	* f-exp.y: Define 'KIND' token.
	(exp): New pattern for KIND expressions.
	(ptype): Handle types with a kind extension.
	(direct_abs_decl): Extend to spot kind extensions.
	(f77_keywords): Add 'kind' to the list.
	(push_kind_type): New function.
	(convert_to_kind_type): New function.
	* f-lang.c (evaluate_subexp_f): Support UNOP_KIND.
	* parse.c (operator_length_standard): Likewise.
	* parser-defs.h (enum type_pieces): Add tp_kind.
	* std-operator.def: Add UNOP_KIND.

gdb/testsuite/ChangeLog:

	* gdb.fortran/intrinsics.exp: New file.
	* gdb.fortran/intrinsics.f90: New file.
	* gdb.fortran/type-kinds.exp: New file.
2019-03-06 18:11:31 +00:00
Andrew Burgess e454224fa8 gdb/fortran: Enable debugging of the Fortran parser
This commit allows 'set debug parser on' to work for the Fortran
parser.

gdb/ChangeLog:

	* f-exp.y (f_parse): Set yydebug.
2019-03-06 18:11:31 +00:00
Andrew Burgess 9dad4a58a1 gdb/fortran: Add new function to evaluate Fortran expressions
This is an initial restructure, it adds a new function in which
Fortran specific expressions can be evaluated.  No Fortran specific
expressions are added with this commit though, so for now, the new
function just forwards all expressions to the default expression
handler, as such, there should be no user visible changes after this
commit.  However, the new function will be useful in later commits.

gdb/ChangeLog:

	* f-lang.c (evaluate_subexp_f): New function.
	(exp_descriptor_f): New global.
	(f_language_defn): Use exp_descriptor_f instead of
	exp_descriptor_standard.
2019-03-06 18:11:31 +00:00
Andrew Burgess c8f9160408 gdb/fortran: Simplify handling of Fortran dot operations and keywords
Use strncasecmp to compare Fortran dot operations (like .AND.) and for
the keywords list.  This allows for some duplication to be removed
from the token arrays.  I've also performed whitespace cleanup around
the code I've changed.

I have added some tests to ensure that upper and lowercase dot
operations are correctly tested.  The keywords list remains always
lowercase for now.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* f-exp.y (struct token): Add comments.
	(dot_ops): Remove uppercase versions and the end marker.
	(f77_keywords): Likewise.
	(yylex): Use ARRAY_SIZE to iterate over dot_ops, assert all
	entries in the dot_ops array are case insensitive, and use
	strncasecmp to compare strings.  Also some whitespace cleanup in
	this area.  Similar for the f77_keywords array, except entries in
	this list might be case sensitive.

gdb/testsuite/ChangeLog:

	* gdb.fortran/dot-ops.exp: New file.
2019-03-06 18:11:31 +00:00
Andrew Burgess dd9f2c763b gdb/fortran: Cleanup code for parsing logical constants
This patch cleans up the code used for parsing the Fortran logical
constants '.TRUE.' and '.FALSE.'.  Instead of listing both upper and
lowercase versions of these strings we now use strncasecmp.

I've also switched to use ARRAY_SIZE for the array iteration, and I've
cleaned up whitespace in the vicinity of the code I've changed.

Finally, I've added a test to ensure that both the upper and lower
case versions of the logical constants are understood by GDB,
something that was missing previously.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* f-exp.y (struct f77_boolean_val): Add comments.
	(boolean_values): Remove uppercase versions, and end marker.
	(yylex): Use ARRAY_SIZE for iterating over boolean_values array,
	and use strncasecmp to achieve case insensitivity.  Additionally,
	perform whitespace cleanup around this code.

gdb/testsuite/ChangeLog:

	* gdb.fortran/types.exp (test_logical_literal_types_accepted):
	Check upper and lower case logical literals.
2019-03-06 18:11:30 +00:00
Andrew Burgess 84ec972406 gdb/fortran: Remove some duplicate tests
Make the test names unique in gdb.fortran/types.exp by removing a few
duplicate tests.

gdb/testsuite/ChangeLog:

	* gdb.fortran/types.exp (test_float_literal_types_accepted):
	Remove duplicate tests.
2019-03-06 18:11:30 +00:00
Tom Tromey 67a3048c0f Fix remote-sim.c build after warn-unused-result change
John Darrington pointed out that commit 18cb7c9f3 ("Introduce
ATTRIBUTE_UNUSED_RESULT and use it") broke the build:

/home/john/binutils-gdb/gdb/remote-sim.c: In function 'void gdbsim_target_open(const char*, int)':
/home/john/binutils-gdb/gdb/remote-sim.c:765:18: error: ignoring return value of 'char** gdb_argv::release()', declared with attribute warn_unused_result [-Werror=unused-result]

This patch fixes the problem by arranging to use the result of the
release method.

Tested by rebuilding with a simulator enabled.

gdb/ChangeLog
2019-03-06  Tom Tromey  <tromey@adacore.com>

	* remote-sim.c (gdbsim_target_open): Use result of
	gdb_argv::release.
2019-03-06 07:59:43 -07:00
Alan Hayward c3734e093a Testsuite: Ensure changing directory does not break the log file
get_compiler_info switches to a new log file before checking the compiler
to ensure the checks are not logged. Afterwards it restores back to using
the original log file. However, the logfile uses a relative path name -
if the current test has changed the current directory then all further
output for the test will be lost.  This can confuse the code that collates
the main gdb.log file at the end of a FORCE_PARALLEL run.

fullpath-expand.exp calls gdb_compile after changing the current directory.

The "Ensure stack protection is off for GCC" patch added a call to
get_compiler_info from inside of gdb_compile, causing log file collection
to break for FORCE_PARALLEL runs.

The ideal solution would be to ensure the log file is always created using
an absolute path name. However, this is set at multiple points in
Makefile.in and in some instances just relies on dejagnu common code to set
the log file directory to "."

The simpler and safer solution is to override the builtin cd function. The
new function checks the current log file and if the path is relative, then
it resets the logging using an absolute path. Finally it calls the builtin
cd.  This ensures get_compiler_info (and any other code) can correctly
backup and restore the current log file.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (builtin_cd): rename of cd.
	(cd): Override builtin.
2019-03-06 09:52:08 +00:00
Richard Bunt aa3cfbda2f Fortran function calls with arguments
Prior to this patch, calling functions on the inferior with arguments and
then using these arguments within a function resulted in an invalid
memory access. This is because Fortran arguments are typically passed as
pointers to values.

It is possible to call Fortran functions, but memory must be allocated in
the inferior, so a pointer can be passed to the function, and the
language must be set to C to enable C-style casting. This is cumbersome
and not a pleasant debug experience.

This patch implements the GNU Fortran argument passing conventions with
caveats. Firstly, it does not handle the VALUE attribute as there is
insufficient DWARF information to determine when this is the case.
Secondly, functions with optional parameters can only be called with all
parameters present. Both these cases are marked as KFAILS in the test.

Since the GNU Fortran argument passing convention has been implemented,
there is no guarantee that this patch will work correctly, in all cases,
with other compilers.

Despite these limitations, this patch improves the ease with which
functions can be called in many cases, without taking away the existing
approach of calling with the language set to C.

Regression tested on x86_64, aarch64 and POWER9 with GCC 7.3.0.
Regression tested with Ada on x86_64.
Regression tested with native-extended-gdbserver target board.

gdb/ChangeLog:

	* eval.c (evaluate_subexp_standard): Call Fortran argument
	wrapping logic.
	* f-lang.c (struct value): A value which can be passed into a
	Fortran function call.
	(fortran_argument_convert): Wrap Fortran arguments in a pointer
	where appropriate.
	(struct type): Value ready for a Fortran function call.
	(fortran_preserve_arg_pointer): Undo check_typedef, the pointer
	is needed.
	* f-lang.h (fortran_argument_convert): Declaration.
	(fortran_preserve_arg_pointer): Declaration.
	* infcall.c (value_arg_coerce): Call Fortran argument logic.

gdb/testsuite/ChangeLog:

	* gdb.fortran/function-calls.exp: New file.
	* gdb.fortran/function-calls.f90: New test.
2019-03-06 08:24:12 +00:00
Tom Tromey ea38e5df77 Remove some Python 3 #ifs
A recent patch from Kevin Buettner taught me that the PyBytes API is
available on Python 2.  This patch removes a couple of related #ifs in
the Python code.

Tested on x86-64 Fedora 29, using both Python 3.7 and Python 2.7.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* python/py-prettyprint.c (print_string_repr): Remove #if.
	* python/py-utils.c (unicode_to_encoded_string): Remove #if.
2019-03-05 15:01:59 -07:00
Tom Tromey 06b5b831a0 Change the_dummy_target to be a global
While debugging gdb, I printed the target stack and got:

    (top-gdb) p g_target_stack
    $10 = {
      m_top = thread_stratum,
      m_stack = {0x142b0b0, 0x13da600 <exec_ops>, 0x1c70690, 0x13d63b0 <ravenscar_ops>, 0x0, 0x0, 0x0}
    }

(This is clearly from before the change to make ravenscar
multi-target-capable.)

Here, 0x142b0b0 is the singleton dummy target.  It seems to me that
since this is always a singleton, it would be a bit nicer if it were a
global, so that it would be noted in the above.

This patch implements this idea, and now I get:

    (top-gdb) p g_target_stack
    $2 = {
      m_top = dummy_stratum,
      m_stack = {0x1f1b040 <the_dummy_target>, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
    }

I did not do the same for the debug target.  It didn't seem as useful
to me.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* target.c (the_dummy_target): Move later.  Change type to
	"dummy_target".
	(initialize_targets): Don't initialize the_dummy_target.
2019-03-05 14:11:17 -07:00
Simon Marchi ff6c8b354d Small fix to gdb.Value constructor doc
The synopsis of the two-parameters form of the gdb.Value constructor is
currently shown as

    Value.__init__ (val, [, type ])

in the documentation.

First, there is an extra comma, which I think we can remove in any
case.

Then, since the type parameter is not optional, I would not put in
between square brackets.  Those usually indicate that something is
optional.

With this patch, it appears as:

    Value.__init__ (val, type)

gdb/doc/ChangeLog:

	* python.texi (Values From Inferior): Change synopsys of the
	second form of Value.__init__.
2019-03-05 14:00:42 -05:00
Tom Tromey edbd9e45a9 Remove gdb_bfd_fdopenr
I noticed that gdb_bfd_fdopenr is no longer used, so this patch
removes it.  Tested by rebuilding and by grep.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* gdb_bfd.c (gdb_bfd_fdopenr): Remove.
	* gdb_bfd.h (gdb_bfd_fdopenr): Don't declare.
2019-03-05 09:06:18 -07:00
Tom Tromey c119e04082 Remove excess calls to gdb_flush
A customer noticed some mildly odd MI output, where CLI output was
split into multiple MI strings at unusual boundaries, like this:

    ~"$1 = (b => true"
    ~", p => 0x407260"

This is technically correct according to the MI spec, but still
unusual, in that there's no particular reason for the string to be
split where it is.

I tracked this down to a call to gdb_flush in generic_val_print.
Then, I went through all calls to gdb_flush and removed the ones I
thought were superfluous.  In particular:

* Any call in the value-printing code;
* Likewise the type-printing code (just a single call); and
* Any call that immediately followed a printf that obviously
  ended with a newline, my belief being that gdb's standard output
  streams are line buffered (by inheriting the behavior from stdio)

Regression tested on x86-64 Fedora 29.

I didn't add a new test case.  I tend to think we don't necessarily
want to specify this behavior in the tests.  Let me know what you
think of this.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat_target::attach)
	(windows_nat_target::detach): Don't call gdb_flush.
	* valprint.c (generic_val_print, val_print, val_print_string):
	Don't call gdb_flush.
	* utils.c (defaulted_query): Don't call gdb_flush.
	* typeprint.c (print_type_scalar): Don't call gdb_flush.
	* target.c (target_announce_detach): Don't call gdb_flush.
	* sparc64-tdep.c (adi_print_versions): Don't call gdb_flush.
	* remote.c (extended_remote_target::attach): Don't call
	gdb_flush.
	* procfs.c (procfs_target::detach): Don't call gdb_flush.
	* printcmd.c (do_examine): Don't call gdb_flush.
	(info_display_command): Don't call gdb_flush.
	* p-valprint.c (pascal_val_print): Don't call gdb_flush.
	* nto-procfs.c (nto_procfs_target::attach): Don't call gdb_flush.
	* memattr.c (info_mem_command): Don't call gdb_flush.
	* mdebugread.c (mdebug_build_psymtabs): Don't call gdb_flush.
	* m2-valprint.c (m2_val_print): Don't call gdb_flush.
	* infrun.c (follow_exec, handle_command): Don't call gdb_flush.
	* inf-ptrace.c (inf_ptrace_target::attach): Don't call gdb_flush.
	* hppa-tdep.c (unwind_command): Don't call gdb_flush.
	* gnu-nat.c (gnu_nat_target::attach): Don't call gdb_flush.
	(gnu_nat_target::detach): Don't call gdb_flush.
	* f-valprint.c (f_val_print): Don't call gdb_flush.
	* darwin-nat.c (darwin_nat_target::attach): Don't call gdb_flush.
	* cli/cli-script.c (read_command_lines): Don't call gdb_flush.
	* cli/cli-cmds.c (shell_escape, print_disassembly): Don't call
	gdb_flush.
	* c-valprint.c (c_val_print): Don't call gdb_flush.
	* ada-valprint.c (ada_print_scalar): Don't call gdb_flush.
2019-03-05 08:55:51 -07:00
Tom Tromey 895dafa679 Add ATTRIBUTE_UNUSED_RESULT to ref_ptr::release
This applies ATTRIBUTE_UNUSED_RESULT to ref_ptr::release and updates a
few spots to comply.  I believe one use in install_default_visualizer
was in error, fixed by this patch.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* varobj.c (update_dynamic_varobj_children): Update.
	(install_default_visualizer): Use reset, not release.
	* value.c (set_internalvar): Update.
	* dwarf2loc.c (value_of_dwarf_reg_entry): Update.
	* common/gdb_ref_ptr.h (class ref_ptr) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:40 -07:00
Tom Tromey 88a774b998 Add ATTRIBUTE_UNUSED_RESULT to scoped_remote_fd::release
This applies ATTRIBUTE_UNUSED_RESULT to scoped_remote_fd::release.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* remote.c (class scoped_remote_fd) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:40 -07:00
Tom Tromey 4e4a8b932b Add ATTRIBUTE_UNUSED_RESULT to macro_buffer
This applies ATTRIBUTE_UNUSED_RESULT to macro_buffer::release.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* macroexp.c (struct macro_buffer) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:40 -07:00
Tom Tromey 083eef1f89 Add ATTRIBUTE_UNUSED_RESULT to scoped_mmap
This applies ATTRIBUTE_UNUSED_RESULT to scoped_mmap::release and fixes
a couple of spots to comply.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* nat/linux-btrace.c (linux_enable_bts, linux_enable_pt): Update.
	* common/scoped_mmap.h (class scoped_mmap) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:40 -07:00
Tom Tromey 3cabd438f3 Add ATTRIBUTE_UNUSED_RESULT to scoped_fd
This applies ATTRIBUTE_UNUSED_RESULT to scoped_fd::release.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* common/scoped_fd.h (class scoped_fd) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:40 -07:00
Tom Tromey 41e3300aa7 Add ATTRIBUTE_UNUSED_RESULT to parser_state
This applies ATTRIBUTE_UNUSED_RESULT to parser_state::release.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* parser-defs.h (struct parser_state) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
2019-03-05 08:48:39 -07:00
Tom Tromey 18cb7c9f3a Introduce ATTRIBUTE_UNUSED_RESULT and use it
This introduces the new ATTRIBUTE_UNUSED_RESULT define, and applies it
to gdb_argv::release.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

	* utils.h (class gdb_argv) <release>: Add
	ATTRIBUTE_UNUSED_RESULT.
	* common/common-defs.h (ATTRIBUTE_UNUSED_RESULT): Define.
2019-03-05 08:48:39 -07:00
Sergio Durigan Junior 45950eb600 Use '$enable_unittest' instead of '$development' on gdbserver/configure.srv (for 'aarch64*-*-linux*' case)
On commit 8ecfd7bd4a ("Add parameter to
allow enabling/disabling selftests via configure") it seems that I
forgot to use the proper '$enable_unittest' variable when checking to
see whether to add selftest-related objects to 'srv_regobj'.  This
causes a build failure on Aarch64 when 'development=false' (which is
the case for the 8.3 branch) and 'enable_unittest=true'.

This patch fixes the problem by using '$enable_unittest' instead of
'$development' when performing the check.  As a reminder, it's
important to notice that '$enable_unittest's default value (i.e., when
the option '--enable-unit-tests' is not passed to configure) is the
same as '$development', so this patch doesn't affect the current
build.

I'd like to install this patch both on master and on the 8.3 branch.

OK?

gdb/gdbserver/ChangeLog:
2019-03-04  Sergio Durigan Junior  <sergiodj@redhat.com>

	* configure.srv: Use '$enable_unittest' instead of '$development'
	when checking whether to fill 'srv_regobj' on 'aarch64*-*-linux*'
	case.
2019-03-04 12:47:35 -05:00
Richard Bunt 7b63ad86ab gdbserver short-circuit-argument-list failures
This patch fixes test case failures observed when running
short-circuit-argument-list.exp with gdb server boards. Thanks to Sergio
Durigan Junior for pointing this out.

Assertions failed with the native{,-extended}-gdbserver boards as the
standard output from the test program appears in a different location
than observed on non-gdbserver boards. This standard output was used to
determine whether a function, which had been logically short-circuited,
was called or not. Since the location of the standard out cannot be
relied upon to verify this, a new mechanism was needed.

The test program now records function calls in variables named the same
as the function with a "_called" suffix. These variables can then be
queried from the test case to verify the occurrence of a call.

A method to reset the call counts has been included in the test case, so
that any future assertions added to this test can ensure a fresh set of
initial values before proceeding. Not resetting values between groups of
assertions creates a dependency between them, which increases the
likelihood that a single failure causes subsequent assertions to fail.

Regression tested on x86_64, aarch64 and ppc64le.
Regression tested with Ada on x86_64.
Regression tested with the native{,-extended}-gdbserver boards on x86_64.
2019-03-04 15:08:51 +00:00
Eli Zaretskii e3624a40ae Fix documentation of styles.
gdb/doc/ChangeLog:
2019-03-02  Eli Zaretskii  <eliz@gnu.org>

	* gdb.texinfo (Output Styling): Fix typos.  Document the default
	foreground colors of the available styles.
2019-03-02 21:42:54 +02:00
Eli Zaretskii a6a4b2c636 Avoid compilation warnings on MinGW.
gdb/ChangeLog:
2019-03-02  Eli Zaretskii  <eliz@gnu.org>

	* xml-syscall.c (xml_list_syscalls_by_group): Drop 'struct' from
	for-loop range, to avoid compiler warnings.

	* tui/tui.c (tui_enable) [__MINGW32__]: Don't declare 'cap', to
	avoid compiler warnings about unused variables.
2019-03-02 15:22:11 +02:00
Eli Zaretskii 742a7df5f4 GDB no longer supports Windows before XP.
gdb/ChangeLog:
2019-03-02  Eli Zaretskii  <eliz@gnu.org>

	* NEWS: Mention end of support for native debugging on MS-Windows
	before XP.
2019-03-02 15:18:32 +02:00
Eli Zaretskii 41fa577fbc Fix GDB compilation on MinGW (PR gdb/24292)
gdb/ChangeLog:

2019-03-02  Eli Zaretskii  <eliz@gnu.org>

	PR gdb/24292
	* common/netstuff.c:
	* gdbserver/gdbreplay.c
	* gdbserver/remote-utils.c:
	* ser-tcp.c:
	* unittests/parse-connection-spec-selftests.c [USE_WIN32API]:
	Include ws2tcpip.h instead of wsiapi.h and winsock2.h.  Redefine
	_WIN32_WINNT to 0x0501 if defined to a smaller value, as
	'getaddrinfo' and 'freeaddrinfo' were not available before
	Windows XP, and mingw.org's MinGW headers by default define
	_WIN32_WINNT to 0x500.
2019-03-02 15:13:54 +02:00
Gary Benson 827f438f66 Fix coff_start_symtab resource leak found by Coverity
This commit fixes a resource leak found by Coverity, where
coff_start_symtab performs an xstrdup that is now performed
within start_symtab by buildsym_compunit::buildsym_compunit.

gdb/ChangeLog:

	* coffread.c (coff_start_symtab): Remove unnecessary xstrdup.
2019-03-01 13:50:27 +00:00
Alan Hayward 01abb042af Testsuite: Catch gdbserver socket listen errors
When launching gdbserver, the testsuite checks for binding failure but
does not check for failure to listen to socket error (which can happen
due to another gdbserver binding to the socket at the same time).

When this error occurs, the test will ignore the error and connect GDB
to the failed port.  This may succeed and GDB will now be connected to
the gdbserver from another test.  This eventually causes both tests to
fail.

When running the tests suite with native-gdbserver across many cores,
this issue may happen once or twice, each causing random failures for
two .exp testscripts.

Example gdb.log output for the failure:

The testsuite sucessfully notices a failure to connect to port 2348.
It launches again with port 2349, which also fails.  The testsuite
ignores this error and uses gdb to connect to the port - which succeeds.

spawn /work/build/gdb/testsuite/../gdbserver/gdbserver --once localhost:2348 /work/build/gdb/testsuite/outputs/gdb.ada/arrayidx/p^M
Can't bind address: Address already in use.^M
Exiting^M
Port 2348 is already in use.
spawn /work/build/gdb/testsuite/../gdbserver/gdbserver --once localhost:2349 /work/build/gdb/testsuite/outputs/gdb.ada/arrayidx/p^M
Can't listen on socket: Address already in use.^M
Exiting^M
target remote localhost:2349^M
Remote debugging using localhost:2349^M
Reading /lib/ld-linux-aarch64.so.1 from remote target...^M
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.^M
Reading /lib/ld-linux-aarch64.so.1 from remote target...^M
Reading symbols from target:/lib/ld-linux-aarch64.so.1...^M
Reading /lib/ld-2.23.so from remote target...^M
Reading /lib/.debug/ld-2.23.so from remote target...^M
Reading /work/build/install/lib/debug//lib/ld-2.23.so from remote target...^M
Reading /work/build/install/lib/debug/lib//ld-2.23.so from remote target...^M
Reading target:/work/build/install/lib/debug/lib//ld-2.23.so from remote target...^M
(No debugging symbols found in target:/lib/ld-linux-aarch64.so.1)^M
0x0000ffffbf6d2cc0 in ?? () from target:/lib/ld-linux-aarch64.so.1^M
(gdb) continue^M
Continuing.^M
Reading /lib/aarch64-linux-gnu/libc.so.6 from remote target...^M
Reading /lib/aarch64-linux-gnu/libc-2.23.so from remote target...^M
Reading /lib/aarch64-linux-gnu/.debug/libc-2.23.so from remote target...^M
Reading /work/build/install/lib/debug//lib/aarch64-linux-gnu/libc-2.23.so from remote target...^M
Reading /work/build/install/lib/debug/lib/aarch64-linux-gnu//libc-2.23.so from remote target...^M
Reading target:/work/build/install/lib/debug/lib/aarch64-linux-gnu//libc-2.23.so from remote target...^M
[Inferior 1 (process 35351) exited normally]^M
(gdb) FAIL: gdb.ada/arrayidx.exp: can't run to main

Meanwhile, at the same time, in another test, gdbserver successfully
connects to port 2349.  GDB then tries to connect to the port, but it
times out because the GDB in the test above has already connected to it.

spawn /work/build/gdb/testsuite/../gdbserver/gdbserver --once localhost:2348 /work/build/gdb/testsuite/outputs/gdb.ada/rdv_wait/foo^M
Can't bind address: Address already in use.^M
Exiting^M
Port 2348 is already in use.
spawn /work/build/gdb/testsuite/../gdbserver/gdbserver --once localhost:2349 /work/build/gdb/testsuite/outputs/gdb.ada/rdv_wait/foo^M
Process /work/build/gdb/testsuite/outputs/gdb.ada/rdv_wait/foo created; pid = 65162^M
Listening on port 2349^M
Remote debugging from host 127.0.0.1, port 45154^M
target remote localhost:2349^M
localhost:2349: Connection timed out.^M
(gdb) ^CQuit^M
(gdb) task 2^M
Cannot inspect Ada tasks when program is not running^M

gdb/testsuite/ChangeLog:

	* lib/gdbserver-support.exp (gdbserver_start): Check for listen
	failure.
2019-02-28 17:20:53 +00:00
Rainer Orth 92137da015 Can't interrupt process without controlling terminal on Solaris (PR gdb/8527)
If gdb attaches to a process that either has no controlling terminal,
or the controlling terminal differs from the one gdb is running under,
break/^C doesn't interrupt the debugged process on Solaris.

Fixed as follows, analogous to what all all other targets do.  Patch from
the PR, recently re-submitted by Brian Vandenberg.

Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and
x86_64-pc-linux-gnu.

2019-02-28  Brian Vandenberg  <phantall@gmail.com>
	    Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gdb:
	PR gdb/8527
	* procfs.c (proc_wait_for_stop): Wrap write of PCWSTOP in
	set_sigint_trap, clear_sigint_trap.

	gdb/testsuite:
	PR gdb/8527
	* gdb.base/interrupt-daemon-attach.c,
	gdb.base/interrupt-daemon-attach.exp: New test.
2019-02-28 16:09:05 +01:00
Philippe Waroquiers 799efbe8e0 Fix regcache leak, and avoid possible regcache access after detach.
Valgrind reports leaks like the below in various tests,
e.g. gdb.threads/attach-slow-waitpid.exp, gdb.ada/task_switch_in_core.exp, ...

Fix the leak by clearing the regcache when detaching from an inferior.
Note that these leaks are 'created' when GDB exits,
when the regcache::current_regcache is destroyed : the elements
of the forward_list are pointers, and the 'pointed to' memory is not
deleted by the forward_list destructor.

Nevertheless, fixing this leak is good as it makes a bunch of
tests 'leak clean'.

Also, it seems strange to keep a register cache for a process from
which GDB detached : it is not clear if this cache is still valid
after detach.  And effectively, when clearing only the regcache,
(and not the frame cache), then the frame cache was still 'pointing'
at this regcache and was used when switching to the child process
in the test gdb.threads/watchpoint-fork.exp, which seems strange.

So, we solve the leak and avoid possible accesses to the regcache
and frame cache of the detached inferior, by clearing both the
regcache and the frame cache.

Tested on debian/amd64, natively, under Valgrind,
and with make check RUNTESTFLAGS="--target_board=native-gdbserver".

==27679== VALGRIND_GDB_ERROR_BEGIN
==27679== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,942 of 3,400
==27679==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==27679==    by 0x5CDF71: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330)
==27679==    by 0x5CE12A: get_thread_regcache (regcache.c:366)
==27679==    by 0x5CE12A: get_current_regcache() (regcache.c:372)
==27679==    by 0x4FF63D: post_create_inferior(target_ops*, int) (infcmd.c:452)
==27679==    by 0x43AF62: core_target_open(char const*, int) (corelow.c:458)
==27679==    by 0x408B68: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892)
...

gdb/ChangeLog
2019-02-27  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* target.c (target_detach): Clear the regcache and the
	frame cache.
2019-02-27 22:41:16 +01:00
Tom Tromey 43ac54fca3 Handle \r\n in gdbreplay
I tried gdbreplay yesterday, but the remotelogfile I received was made
on Windows, so the lines were terminated with \r\n rather than plain
\n.

This patch changes gdbreplay to allow \r\n line termination when
reading the log file.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tromey@adacore.com>

	* gdbreplay.c (logchar): Handle \r\n.
2019-02-27 11:54:24 -07:00
Pedro Alves 5862844d0f Test "set width/height -1"
As a follow up to the previous commit, add a test for "set
width/height -1", to make sure we don't overflow in readline with
negative values either.

gdb/testsuite/ChangeLog:
2019-02-27  Pedro Alves  <palves@redhat.com>

	* gdb.base/page.exp: Add tests for "set width/height -1".
2019-02-27 18:48:37 +00:00
Pedro Alves 8ed252144a Make 'show width/height' display "unlimited" when capped for readline
When we cap the height/width sizes before passing to readline, tweak
the corresponding command variable to show "unlimited":

  (gdb) set height 0x8000
  (gdb) show height
  Number of lines gdb thinks are in a page is unlimited.

Instead of the current output:
  (gdb) set height 0x8000
  (gdb) show height
  Number of lines gdb thinks are in a page is 32768.

gdb/ChangeLog:
2019-02-27  Pedro Alves  <palves@redhat.com>

	* utils.c (set_screen_size): When we cap the height/width sizes,
	tweak the corresponding command variable to show "unlimited":

gdb/testsuite/ChangeLog:
2019-02-27  Pedro Alves  <palves@redhat.com>

	* gdb.base/page.exp: Add tests for "set/show width/height" with
	"infinite" values.
2019-02-27 18:48:36 +00:00
Saagar Jha 23031e3192 Prevent overflow in rl_set_screen_size
GDB calls rl_set_screen_size in readline with the current screen size,
measured in rows and columns.  To represent "infinite" sizes, GDB
passes in INT_MAX; however, since rl_set_screen_size internally
multiplies the number of rows and columns, this causes a signed
integer overflow.  To prevent this we can instead pass in the
approximate square root of INT_MAX (which is still reasonably large),
so that even when the number of rows and columns is "infinite" we
don't overflow.

gdb/ChangeLog:
2019-02-27  Saagar Jha  <saagar@saagarjha.com>
	    Pedro Alves  <palves@redhat.com>

	* utils.c (set_screen_size): Reduce "infinite" rows and columns
	before calling rl_set_screen_size.
2019-02-27 18:48:35 +00:00
Tom Tromey 6c28e44a35 Remove Python 2.4 and 2.5 support
This removes all the remainings spots I could find that work around
issues in Python 2.4 and 2.5.

I don't have a good way to test that Python 2.6 still works.

Tested by the buildbot.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tromey@adacore.com>

	* config.in, configure: Rebuild.
	* configure.ac (HAVE_LIBPYTHON2_4, HAVE_LIBPYTHON2_5): Never
	define.
	* python/py-value.c: Remove Python 2.4 workaround.
	* python/py-utils.c (gdb_pymodule_addobject): Remove Python 2.4
	workaround.
	* python/py-type.c (convert_field, gdbpy_initialize_types): Remove
	Python 2.4 workaround.
	* python/python-internal.h: Remove Python 2.4 comment.
	(Py_ssize_t): Don't define.
	(PyVarObject_HEAD_INIT, Py_TYPE): Don't define.
	(gdb_Py_DECREF): Remove Python 2.4 workaround.
	(gdb_PyObject_GetAttrString, PyObject_GetAttrString): Remove.
	(gdb_PyObject_HasAttrString, PyObject_HasAttrString): Remove.
	* python/python.c (do_start_initialization): Remove Python 2.4
	workaround.
	* python/py-prettyprint.c (class dummy_python_frame): Remove.
	(print_children): Remove Python 2.4 workaround.
	* python/py-inferior.c (buffer_procs): Remove Python 2.4
	workaround.
	(CHARBUFFERPROC_NAME): Remove.
	* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Remove
	Python 2.4 workaround.

gdb/testsuite/ChangeLog
2019-02-27  Tom Tromey  <tromey@adacore.com>

	* lib/gdb.exp (skip_python_tests_prompt): Don't check for Python
	2.4.
	* gdb.python/py-finish-breakpoint.exp: Remove Python 2.4
	workaround.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tromey@adacore.com>

	* config.in, configure: Rebuild.
	* configure.ac (HAVE_LIBPYTHON2_4, HAVE_LIBPYTHON2_5): Never
	define.
	* python/py-value.c: Remove Python 2.4 workaround.
	* python/py-utils.c (gdb_pymodule_addobject): Remove Python 2.4
	workaround.
	* python/py-type.c (convert_field, gdbpy_initialize_types): Remove
	Python 2.4 workaround.
	* python/python-internal.h: Remove Python 2.4 comment.
	(Py_ssize_t): Don't define.
	(PyVarObject_HEAD_INIT, Py_TYPE): Don't define.
	(gdb_Py_DECREF): Remove Python 2.4 workaround.
	(gdb_PyObject_GetAttrString, PyObject_GetAttrString): Remove.
	(gdb_PyObject_HasAttrString, PyObject_HasAttrString): Remove.
	* python/python.c (do_start_initialization): Remove Python 2.4
	workaround.
	* python/py-prettyprint.c (class dummy_python_frame): Remove.
	(print_children): Remove Python 2.4 workaround.
	* python/py-inferior.c (buffer_procs): Remove Python 2.4
	workaround.
	(CHARBUFFERPROC_NAME): Remove.
	* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Remove
	Python 2.4 workaround.
2019-02-27 11:43:06 -07:00
Kevin Buettner 2c3fc25dd1 Document fact that mininum Python version is now 2.6
gdb/ChangeLog:

	* NEWS: Note minimum Python version.

gdb/doc/ChangeLog:

	* gdb.texinfo (Configure Options): Document minimum python
	version.
2019-02-27 11:13:47 -07:00
Kevin Buettner 6ca6222221 Use Python 2.[67] / 3.X / PEP 3118 buffer protocol
This patch removes the non-IS_PY3K code in infpy_write_memory()
and infpy_search_memory().  In both cases, the remaining code
from these ifdefs is related to use of the PEP 3118 buffer protocol.
(Deleted code is either due to simplification or related to use of the
old buffer protocol.)  PEP 3118 is sometimes referred to as the "new"
buffer protocol, though it's not that new anymore.

The link below describes new features in Python 2.6.  In particular,
it says that the buffer protocol described by PEP 3118 is in Python
2.6.  It also says (at the top of the page) that Python 2.6 was
released on Oct 1, 2008.

https://docs.python.org/3/whatsnew/2.6.html#pep-3118-revised-buffer-protocol

The last security release for the Python 2.6 series was 2.6.9.  It was
released on Oct 29, 2013.  According to this document...

https://www.python.org/download/releases/2.6.9/

...support for the 2.6 series has ended:

    With the 2.6.9 release, and five years after its first release,
    the Python 2.6 series is now officially retired.  All official
    maintenance for Python 2.6, including security patches, has ended.
    For ongoing maintenance releases, please see the Python 2.7
    series.

As noted earlier, Python 2.6, Python 2.7, and Python 3.X all have
support for the PEP 3118 buffer protocol.  Python releases prior
to 2.6 use an older buffer protocol.  Since Python 2.6 has been
retired for a good while now, it seems reasonable to me to remove
code using the older buffer protocol from GDB.

I have also simplified some of the code via use of the Py_buffer
unique_ptr specialization which I introduced in the two argument
gdb.Value constructor patch series.  Therefore, there is a dependency
on patch #1 from that series.

I have tested against both Python 2.7.15 and 3.7.2.  I see no
regressions among the non-racy tests.  I've also verified that
PyBuffer_Release is being called when the affected functions exit
while running the tests in gdb.python/py-inferior.exp by hand.  I've
also tried running valgrind on GDB while running this test, but I'm
puzzled by the results that I'm seeing - I'm seeing no additional
leaks when I comment out the Py_buffer_up lines that I introduced.
That said, I'm not seeing any leaks that obviously originate from
either infpy_write_memory() or infpy_search_memory().

gdb/ChangeLog:

	* python/py-inferior.c (infpy_write_memory): Remove non-IS_PY3K
	code from these functions.  Remove corresponding ifdefs.  Use
	Py_buffer_up instead of explicit calls to PyBuffer_Release.
	Remove gotos and target of gotos.
	(infpy_search_memory): Likewise.
2019-02-27 11:10:52 -07:00
Andrew Burgess f4bc7d2cde gdb/hppa: Use default gdbarch method default_dummy_id.
Make use of the default gdbarch method for gdbarch_dummy_id.

I have not tested this change but, by inspecting the code, I believe
the default method is equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/hppa-tdep.c (hppa_dummy_id): Delete.
	(hppa_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:44 +02:00
Andrew Burgess 9734a58667 gdb/h8300: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/h8300-tdep.c (h8300_unwind_pc): Delete.
	(h8300_unwind_sp): Delete.
	(h8300_dummy_id): Delete.
	(h8300_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:44 +02:00
Andrew Burgess 68b867f30e gdb/ft32: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/ft32-tdep.c (ft32_dummy_id): Delete.
	(ft32_unwind_pc): Delete.
	(ft32_unwind_sp): Delete.
	(ft32_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:44 +02:00
Andrew Burgess 2fbe7ad059 gdb/frv: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/frv-tdep.c (frv_dummy_id): Delete.
	(frv_unwind_pc): Delete.
	(frv_unwind_sp): Delete.
	(frv_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess 76055cbe88 gdb/riscv: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

This change has been tested with no regressions.

gdb/ChangeLog:

	* gdb/riscv-tdep.c (riscv_dummy_id): Delete.
	(riscv_unwind_pc): Delete.
	(riscv_unwind_sp): Delete.
	(riscv_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess 4133e5a13f gdb/csky: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/csky-tdep.c (csky_dummy_id): Delete.
	(csky_unwind_pc): Delete.
	(csky_unwind_sp): Delete.
	(csky_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess 8010f57641 gdb/cris: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/cris-tdep.c (cris_dummy_id): Delete.
	(cris_unwind_pc): Delete.
	(cris_unwind_sp): Delete.
	(cris_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess b56bf08443 gdb/bfin: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
and gdbarch_unwind_pc.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/bfin-tdep.c (bfin_dummy_id): Delete.
	(bfin_unwind_pc): Delete.
	(bfin_gdbarch_init): Don't register deleted functions with gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess a19a650fcc gdb/arm: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/arm-tdep.c (arm_dummy_id): Delete.
	(arm_unwind_pc): Delete.
	(arm_unwind_sp): Delete.
	(arm_gdbarch_init): Don't register deleted functions with gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess f8278c3c7e gdb/arc: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.  The
only difference is that the old ARC specific methods had additional
debugging, however, this was discussed on the mailing list[1] and it
was agreed these methods could be removed.

[1] https://sourceware.org/ml/gdb-patches/2018-12/msg00386.html

gdb/ChangeLog:

	* gdb/arc-tdep.c (arc_dummy_id): Delete.
	(arc_unwind_pc): Delete.
	(arc_unwind_sp): Delete.
	(arc_gdbarch_init): Don't register deleted functions with gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess 480e46cfc5 gdb/alpha: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id, and
gdbarch_unwind_pc.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/alpha-tdep.c (alpha_dummy_id): Delete.
	(alpha_unwind_pc): Delete.
	(alpha_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:43 +02:00
Andrew Burgess 7a995095f3 gdb/aarch64: Use default gdbarch methods where possible
Make use of the default gdbarch methods for gdbarch_dummy_id,
gdbarch_unwind_pc, and gdbarch_unwind_sp where possible.

I have not tested this change but, by inspecting the code, I believe
the default methods are equivalent to the code being deleted.

gdb/ChangeLog:

	* gdb/aarch64-tdep.c (aarch64_dummy_id): Delete.
	(aarch64_unwind_pc): Delete.
	(aarch64_unwind_sp): Delete.
	(aarch64_gdbarch_init): Don't register deleted functions with
	gdbarch.
2019-02-27 16:54:42 +02:00
Andrew Burgess bf9a735e23 gdb: Handle alignment for C++ structures with static members
In 'type_align' when computing the alignment of a structure we should
not consider the alignment of static structure members, these are
usually stored outside of the structure and therefore don't have any
impact on the structures alignment requirements.

I've extended the existing alignment calculating test to compile in
both C and C++ now so that we can create structures with static
members.

gdb/ChangeLog:

	* gdbtypes.c (type_align): Don't consider static members when
	computing structure alignment.

gdb/testsuite/ChangeLog:

	* gdb.base/align.exp: Extend to compile in both C and C++, and add
	tests for structs with static members.
2019-02-27 10:38:17 +02:00
Andrew Burgess 5561fc304f gdb: Restructure type_align and gdbarch_type_align
This commit restructures the relationship between the type_align
function and the gdbarch_type_align method.

The problem being addressed with this commit is this; previously the
type_align function was structured so that for "basic" types (int,
float, etc) the gdbarch_type_align hook was called, which for
"compound" types (arrays, structs, etc) the common type_align code has
a fixed method for how to extract a "basic" type and would then call
itself on that "basic" type.

The problem is that if an architecture wants to modify the alignment
rules for a "compound" type then this is not currently possible.

In the revised structure, all types pass through the
gdbarch_type_align method.  If this method returns 0 then this
indicates that the architecture has no special rules for this type,
and GDB should apply the default rules for alignment.  However, the
architecture is free to provide an alignment for any type, both
"basic" and "compound".

After this commit the default alignment rules now all live in the
type_align function, the default_type_align only ever returns 0,
meaning apply the default rules.

I've updated the 3 targets (arc, i386, and nios2) that already
override the gdbarch_type_align method to fit the new scheme.

Tested on X86-64/GNU Linux with no regressions.

gdb/ChangeLog:

	* arc-tdep.c (arc_type_align): Provide alignment for basic types,
	return 0 for other types.
	* arch-utils.c (default_type_align): Always return 0.
	* gdbarch.h: Regenerate.
	* gdbarch.sh (type_align): Extend comment.
	* gdbtypes.c (type_align): Add additional comments, always call
	gdbarch_type_align before applying the default rules.
	* i386-tdep.c (i386_type_align): Return 0 as the default rule,
	generic code will then apply a suitable default.
	* nios2-tdep.c (nios2_type_align): Provide alignment for basic
	types, return 0 for other types.
2019-02-27 10:38:15 +02:00
Joel Brobecker 9335e75a61 Update NEWS post GDB 8.3 branch creation.
gdb/ChangeLog:

	* NEWS: Create a new section for the next release branch.
	Rename the section of the current branch, now that it has
	been cut.
2019-02-27 08:59:50 +04:00
Joel Brobecker 3d34d8de5e Bump version to 8.3.50.DATE-git.
Now that the GDB 8.3 branch has been created, we can
bump the version number.

gdb/ChangeLog:

	GDB 8.3 branch created (143420fb0d):
	* version.in: Bump version to 8.3.50.DATE-git.
2019-02-27 08:53:14 +04:00
Simon Marchi 143420fb0d Fix build errors in aix-thread.c
This patch fixes a few instances of unused variable and shadowed local
variable errors.

gdb/ChangeLog:

	* aix-thread.c (ptid_cmp): Remove unused variable.
	(get_signaled_thread): Likewise.
	(store_regs_user_thread): Likewise.
	(store_regs_kernel_thread): Likewise.
	(fetch_regs_kernel_thread): Remove shadowed variable.
2019-02-26 23:45:50 -05:00
Andrew Burgess 172fb711a2 gdb/riscv: Use legacy register numbers in default target description
When the target description support was added to RISC-V, the register
numbers assigned to the fflags, frm, and fcsr control registers in the
default target descriptions didn't match the register numbers used by
GDB before the target description support was added.

What this means is that if a tools exists in the wild that is using
hard-coded register number, setup to match GDB's old numbering, then
this will have been broken (for fflags, frm, and fcsr) by the move to
target descriptions.  QEMU is such a tool.

There are a couple of solutions that could be used to work around this
issue:

 - The user can create their own xml description file with the
   register numbers setup to match their old tool, then load this by
   telling GDB 'set tdesc filename FILENAME'.

 - Update their old tool to use the newer default numbering scheme, or
   better yet add proper target description support to their tool.

 - We could have RISC-V GDB change to maintain the old defaults.

This patch changes GDB back to using the old numbering scheme.

This change is only visible to remote targets that don't supply their
own xml description file and instead rely on GDB's default numbering.

Note that even though 32bit-cpu.xml and 64bit-cpu.xml have changed,
the corresponding .c file has not, this is because the numbering added
to the registers in the xml files is number 0, this doesn't result in
any new C code being generated .

gdb/ChangeLog:

	* features/riscv/32bit-cpu.xml: Add register numbers.
	* features/riscv/32bit-fpu.c: Regenerate.
	* features/riscv/32bit-fpu.xml: Add register numbers.
	* features/riscv/64bit-cpu.xml: Add register numbers.
	* features/riscv/64bit-fpu.c: Regenerate.
	* features/riscv/64bit-fpu.xml: Add register numbers.
2019-02-26 22:57:35 +02:00
Tom Tromey 8791793caa Fix new py-value.exp test case
The new test case in py-value.exp fails -- the code was changed to
throw ValueError, but the test still checks for TypeError.  This patch
fixes the problem.

I'm checking this in.  Tested on x86-64 Fedora 29.

gdb/testsuite/ChangeLog
2019-02-26  Tom Tromey  <tromey@adacore.com>

	* gdb.python/py-value.exp (test_value_from_buffer): Check for
	ValueError, not TypeError.
2019-02-26 12:13:26 -07:00
Kevin Buettner af54ade989 Document two argument form of gdb.Value constructor
gdb/ChangeLog:

	* NEWS: Mention two argument form of gdb.Value constructor.

gdb/doc/ChangeLog:

	* python.texi (Values From Inferior): Document second form
	of Value.__init__.
2019-02-26 10:28:05 -07:00
Kevin Buettner bc2a507e6e Add tests for gdb.Value(bufobj, type) constructor
gdb/testsuite/ChangeLog:

	* gdb.python/py-value.exp (test_value_from_buffer): New proc with
	call from main program.
2019-02-26 10:25:40 -07:00
Kevin Buettner fe07eca59d Define gdb.Value(bufobj, type) constructor
Provided a buffer BUFOBJ and a type TYPE, construct a gdb.Value object
with type TYPE, where the value's contents are taken from BUFOBJ.

E.g...

(gdb) python import struct
(gdb) python unsigned_int_type=gdb.lookup_type('unsigned int')
(gdb) python b=struct.pack('=I',0xdeadbeef)
(gdb) python v=gdb.Value(b, unsigned_int_type) ; print("%#x" % v)
0xdeadbeef

This two argument form of the gdb.Value constructor may also be used
to obtain gdb values from selected portions of buffers read with
Inferior.read_memory().  The test case (which is in a separate patch)
demonstrates this use case.

gdb/ChangeLog:

	* python/py-value.c (convert_buffer_and_type_to_value): New
	function.
	(valpy_new): Parse arguments via gdb_PyArg_ParseTupleAndKeywords.
	Add support for handling an optional second argument.  Call
	convert_buffer_and_type_to_value as appropriate.
2019-02-26 10:23:23 -07:00
Kevin Buettner 26c897821b Define unique_ptr specialization for Py_buffer.
This patch causes PyBuffer_Release() to be called when the associated
buffer goes out of scope.  I've been using it as follows:

 ...
 Py_buffer_up buffer_up;
 Py_buffer py_buf;

 if (PyObject_CheckBuffer (obj)
     && PyObject_GetBuffer (obj, &py_buf, PyBUF_SIMPLE) == 0)
   {
      /* Got a buffer, py_buf, out of obj.  Cause it to released
         when it goes out of scope.  */
     buffer_up.reset (&py_buf);
   }
   ...

This snippet of code was taken directly from an upcoming patch to
python-value.c.

gdb/ChangeLog:

	* python/python-internal.h (Py_buffer_deleter): New struct.
	(Py_buffer_up): New typedef.
2019-02-26 10:21:22 -07:00
John Baldwin 0f58c9e88e Fix BFD leak in dwarf2_get_dwz_file.
Previously if build_id_verify failed, dwz_bfd was cleared to NULL via
release(), but the BFD object was not destroyed.  Use reset() with
nullptr instead to delete the BFD.

gdb/ChangeLog:

	* dwarf2read.c (dwarf2_get_dwz_file): Reset dwz_bfd to nullptr
	instead of releasing ownership.
2019-02-25 14:25:01 -08:00
Jordan Rupprecht 0a0f4c0179 Fix crash when loading dwp files
When loading dwp files, we create an array of ELF sections indexed by the ELF
section index in the dwp file. The size of this array is calculated by
section_count, as returned by bfd_count_sections, plus 1 (to account for the
null section at index 0). However, when loading the bfd file, strtab/symtab
sections are not added to the list, nor do they increment section_count, so
section_count is actually smaller than the number of ELF sections.

This happens to work when using GNU dwp, which lays out .debug section first,
with sections like .shstrtab coming at the end. Other tools, like llvm-dwp, put
.strtab first, and gdb crashes when loading those dwp files.

For instance, with the current state of gdb, loading a file like this:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .debug_foo PROGBITS ...
[ 2] .strtab    STRTAB ...

... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 1 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which passes the
assertion that 1 < 2.

However, using a dwp file produced by llvm-dwp:
$ readelf -SW <file.dwp>
[ 0] <empty>
[ 1] .strtab    STRTAB ...
[ 2] .debug_foo PROGBITS ...

... results in section_count = 2 (.debug is the only thing placed into
bfd->sections, so section_count + 1 == 2), and sectp->this_idx = 2 when mapping
over .debug_foo in dwarf2_locate_common_dwp_sections, which fails the assertion
that 2 < 2.

The assertion hit is:

gdb/dwarf2read.c:13009: internal-error: void dwarf2_locate_common_dwp_sections(bfd*, asection*, void*): Assertion `elf_section_nr < dwp_file->num_sections' failed.

This patch changes the calculation of section_count to use elf_numsections,
which should return the actual number of ELF sections.
2019-02-25 15:51:39 -05:00
Tom Tromey cd5a152ceb Fix BFD leak in solib-darwin.c
commit 192b62ce0b ("Use class to manage
BFD reference counts") changed darwin_get_dyld_bfd to use:

+	dyld_bfd.release ();

rather than

-      do_cleanups (cleanup);

However, using release here leaks the BFD.  Instead, simply assigning
"sub" to "dyld_bfd" achieves what was meant.

gdb/ChangeLog
2019-02-25  Tom Tromey  <tromey@adacore.com>

	* solib-darwin.c (darwin_get_dyld_bfd): Don't release dyld_bfd.
2019-02-25 06:55:02 -07:00
Sergio Durigan Junior 8a6a85134d Use '--readnever' when invoking GDB from gcore.in
Back when I proposed the '--readnever' feature, I somehow forgot or
decided not to include the bits related to gcore.in in the original
patch.  This patch finally updates the gcore script to invoke GDB
using '--readnever'.

We've been carrying this patch on Fedora GDB for quite some time, and
as expected the corefiles generated by gcore on Fedora don't have
problems, which I think is the best indicator that the it's safe to
generate corefiles using '--readnever'.

gdb/ChangeLog:
2019-02-23  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gcore.in: Add '--readnever' option when invoking GDB.
2019-02-23 10:05:19 -05:00
Joel Brobecker e0e7d3bd21 Update copyright year range in gdb.ada/mi_ref_changeable testcase
This patch fixes the copyright year range which escaped
the 2019 update, because the patch was submitted in 2018, but
only really pushed in 2019.

    Pushed: https://www.sourceware.org/ml/gdb-patches/2019-02/msg00109.html
    Submitted: https://www.sourceware.org/ml/gdb-patches/2018-12/msg00444.html

We normally are pretty good at remembering those little things,
but this one fell through the cracks. This commit fixes this,
by re-running the copyright.py script and checking in the changes
made by that script.

gdb/testsuite/ChangeLog:

	* gdb.ada/mi_ref_changeable.exp: Update copyright year range.
	* gdb.ada/mi_ref_changeable/foo_rb20_056.adb: Likewise.
	* gdb.ada/mi_ref_changeable/pck.adb: Likewise.
	* gdb.ada/mi_ref_changeable/pck.ads: Likewise.
	* gdb.dwarf2/inlined_subroutine-inheritance.exp: Likewise.
2019-02-23 16:27:30 +04:00
Joel Brobecker c97a773961 Update copyright year range in gdb.texinfo and refcard.tex
I missed those files which need to be updated manually when I did
the copyright year range update. The copyright.py script reminds
us of that fact with the following message at the end...

    REMINDER: Multiple copyright headers must be updated by hand:
       gdb/doc/gdb.texinfo
       gdb/doc/refcard.tex
       gdb/gdbarch.sh

... and somehow I missed this. This commit makes the change for
gdb.texinfo and refcard.tex. gdbarch.sh is being updated separately
by Andrew Burgess.

gdb/doc/ChangeLog:

	* gdb.texinfo: Update copyright year ranges.
	* refcard.tex: Likewise.
2019-02-23 16:19:57 +04:00
Simon Marchi 04dcda9cb0 Update my email address
Since this is my last day at Ericsson, I am changing my email for my
personal one in the MAINTAINERS file.
2019-02-22 15:56:05 -05:00
Simon Marchi 07bc701d03 Look for build-id-based separate debug files under the sysroot
When looking for a separate debug file that matches a given build-id,
GDB only looks in the host's debug dir (typically /usr/lib/debug).  This
patch makes it look in the sysroot as well.  This is to match the
behavior of GDB when using debuglink-based separate debug files,
introduced in :

402d2bfec4 ("Look for separate debug files in debug directories under a sysroot.")

In the following example, my sysroot is "/tmp/sysroot" and I am trying
to load symbols for
/tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so.  This is
the current behavior:

    (gdb) file /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
    Reading symbols from /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so...

    Looking for separate debug info (build-id) for /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
      Trying /usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... no, unable to compute real path

    <snip>
    (No debugging symbols found in /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so)

With this patch:

    (gdb) file /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
    Reading symbols from /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so...

    Looking for separate debug info (build-id) for /tmp/sysroot/usr/lib/arm-linux-gnueabihf/gconv/EBCDIC-AT-DE.so
      Trying /usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... no, unable to compute real path
      Trying /tmp/sysroot/usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug... yes!
    Reading symbols from /tmp/sysroot/usr/lib/debug/.build-id/f3/d6594d2600e985812cd4ba2ad083ac2aceae22.debug...

In the original code, there is a suspicious "abfd.release ()" in
build_id_to_debug_bfd, that I don't understand.  If a file with the
right name exists but its build-id note doesn't match, we release (leak)
our reference, meaning the file will stay open?  I removed it in the new
code, so that the reference is dropped if we end up not using that file.
I tested briefly by corrupting a separate debug file to trigger this
code, nothing exploded.

gdb/ChangeLog:

	* build-id.c (build_id_to_debug_bfd_1): New function.
	(build_id_to_debug_bfd): Look for separate debug file in
	sysroot.
2019-02-22 15:49:57 -05:00
Andrew Burgess c6f4a5d0ed gdb: Update copyright year range generated by gdbarch.sh
The copyright year that gdbarch.sh places into the generated files
gdbarch.{c,h} wasn't updated at the start of the year.  After this
commit the gdbarch.{c,h} files regenerate as the currently are in the
tree.

gdb/ChangeLog:

	* gdbarch.sh: Update the copyright year range that is placed into
	generated files.
2019-02-22 20:17:37 +00:00
Keith Seitz 9600246deb Add missing ChangeLog entries for commit bb995d00b3 2019-02-22 12:05:37 -08:00
Keith Seitz bb995d00b3 Fix symtab/23853: symlinked default symtab
This patch attempts to fix a bug dealing with setting breakpoints
in default symtabs that are symlinks.  For example:

(gdb) list
11	   GNU General Public License for more details.
12
13	   You should have received a copy of the GNU General Public License
14	   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16	static int
17	foo (void)
18	{
19	  return 0; /* break here  */
20	}
(gdb)
21
22	int
23	main (void)
24	{
25	  return foo ();
26	}
(gdb) b 19
No line 19 in the current file.
Make breakpoint pending on future shared library load? (y or [n])

The problem here is that when create_sals_line_offset sets the default
symtab, it immediately calls symtab_to_fullname, passing that fullname
to collect_symtabs_from_filename to find all matching symtabs.  This
fails because we end up looking for a symtab with the name of the
actual file on disk (which is different in this case because of the
symlink) instead of the one stored in the debug info.

Since we already have the lookup name of the default symtab, use it
instead of the fullname. [This fullname thing was originally added
in 2007 in a series dealing with *displaying* absolute file names.
Clearly, this instance has nothing to do with the display of file names.]

gdb/ChangeLog

	PR symtab/23853
	* linespec.c (create_sals_line_offset): Search for the default
	symtab's filename instead of its fullname.

gdb/testsuite/ChangeLog

	PR symtab/23853
	* gdb.base/symlink-sourcefile.c: New file.
	* gdb.base/symlink-sourcefile.exp: New file.
2019-02-22 11:19:27 -08:00
Alan Hayward 7557a51431 Document style behavior in batch mode.
Style is disabled when running in batch mode.

gdb/ChangeLog:

	* NEWS: Update style defaults.

gdb/doc/ChangeLog:

	* gdb.texinfo: Update style defaults.
2019-02-21 18:20:21 +00:00
Tom Tromey 2d8b68309f Fix typo in "show remotelogfile" docs
I noticed a trailing "." in the @item for "show remotelogfile".
This removes it.  Committing as obvious.

gdb/doc/ChangeLog
2019-02-21  Tom Tromey  <tromey@adacore.com>

	* gdb.texinfo (Remote Configuration): Remove trailing "." from
	@item.
2019-02-21 07:26:52 -07:00
Alan Hayward ee2bcb0c35 Disable styling when running in batch mode
The GCC Guality testsuite within GCC compiles C/C++ files in GCC at
various optimization levels then debugs them in GDB, checking that
program values can be read.  This is done within the dejagnu framework.

The new style options in GDB have broken many of the tests due to the
testsuite being unable to process the new control characters.  The fix
in Guality is to either to improve the string matching or to disable
styling on the cli or init file (after checking gdb is recent enough
to support styling).

This fix will also need making an any other testsuites in the wild
that use GDB.

An alternative would be to automatically disable styling when using GDB
in batch mode.  The reasoning here is that batch mode is only used when
automating GDB and any output will be processed later either with text
processing tools or viewed in text editors, many of these will not
correctly handle the control characters by default.  This ensures GDB
continues to work as expected.  Anyone who explicitly wants styling in
batch mode can enable it either in the init file or adding to the batch
file - but that would not be the standard use case.

Patch simply disables style after reading the batch command flag, before
reading in the init file or batch file.

gdb/ChangeLog:

	* main.c (captured_main_1): Disable styling in batch mode.
2019-02-21 13:18:26 +00:00
Tom Tromey 0c95f9ed6c Fix typos in symtab_symbol_info
symtab_symbol_info has a couple of messages that say "regulation
expression".  I think "regular expression" was meant, so this patch
changes it.

gdb/ChangeLog
2019-02-20  Tom Tromey  <tom@tromey.com>

	* symtab.c (symtab_symbol_info): Fix typos.

gdb/testsuite/ChangeLog
2019-02-20  Tom Tromey  <tom@tromey.com>

	* gdb.base/info_qt.exp: Update.
2019-02-20 11:21:38 -07:00
Tom Tromey c763b89433 Use upper case for metasyntactic variables in "help find"
While answering a user's question on irc, I realized that the
metasyntactic variables in "help find" are not in upper case.  As you
know this is one of my pet quests, so here is a patch to fix this.
Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-02-20  Tom Tromey  <tromey@adacore.com>

	* findcmd.c (_initialize_mem_search): Use upper case for
	metasyntactic variables.
2019-02-20 08:21:46 -07:00
Alan Hayward 0ef8a082c3 AArch64: Add default reggroups
AArch64 does not define any reggroups.  This causes "maintenance print
reggroups" to dump the default set (which is ok).

However, if a new group is added via an xml file, then this now becomes
the only group.

Fixes gdb.xml/tdesc-regs.exp on AArch64.

gdb/ChangeLog:

	* aarch64-tdep.c (aarch64_add_reggroups): New function
	(aarch64_gdbarch_init): Call aarch64_add_reggroups.
2019-02-20 11:56:23 +00:00
Simon Marchi 6caa91b6e5 Fix error message and use-after-free on errors in nested sourced files
Errors that happen in nested sourced files (when a sourced file sources
another file) lead to a wrong error message, or use-after-free.

For example, if I put this in "a.gdb":

    command_that_doesnt_exist

and this in "b.gdb":

   source a.gdb

and try to "source b.gdb" in GDB, the result may look like this:

    (gdb) source b.gdb
    b.gdb:1: Error in sourced command file:
    _that_doesnt_exist:1: Error in sourced command file:
    Undefined command: "command_that_doesnt_exist".  Try "help".

Notice the wrong file name where "a.gdb" should be.  The exact result
may differ, depending on the feelings of the memory allocator.

What happens is:

- The "source a.gdb" command is saved by command_line_append_input_line
  in command_line_input's static buffer.
- Since we are sourcing a file, the script_from_file function stores the
  script name (a.gdb) in the source_file_name global.  However, it doesn't
  do a copy, it just saves a pointer to command_line_input's static buffer.
- The "command_that_doesnt_exist" command is saved by
  command_line_append_input_line in command_line_input's static buffer.
  Depending on what xrealloc does, source_file_name may now point to
  freed memory, or at the minimum the data it was pointing to was
  overwritten.
- When the error is handled in script_from_file, we dererence
  source_file_name to print the name of the file in which the error
  occured.

To fix it, I made source_file_name an std::string, so that keeps a copy of
the file name instead of pointing to a buffer with a too small
lifetime.

With this patch, the expected filename is printed, and no use-after-free
occurs:

    (gdb) source b.gdb
    b.gdb:1: Error in sourced command file:
    a.gdb:1: Error in sourced command file:
    Undefined command: "command_that_doesnt_exist".  Try "help".

I passed explicit template parameters to make_scoped_restore
(<std::string, const std::string &>), so that the second parameter is
passed by reference and avoid a copy.

It was not as obvious as I first thought to change gdb.base/source.exp
to test this, because source commands inside sourced files are
interpreted relative to GDB's current working directory, not the
directory of the currently sourced file.  As a workaround, I moved the
snippet that tests errors after the snippet that adds the source
directory to the search path.  This way, the "source source-error-1.gdb"
line in source-error.exp manages to find the file.

For reference, here is what ASAN reports when use-after-free occurs:

(gdb) source b.gdb
=================================================================
==18498==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000019847 at pc 0x7f1d3645de8e bp 0x7ffdcb892e50 sp 0x7ffdcb8925c8
READ of size 6 at 0x60c000019847 thread T0
    #0 0x7f1d3645de8d in printf_common /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:546
    #1 0x7f1d36477175 in __interceptor_vasprintf /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1525
    #2 0x5632eaffa277 in xstrvprintf(char const*, __va_list_tag*) /home/simark/src/binutils-gdb/gdb/common/common-utils.c:122
    #3 0x5632eaff96d1 in throw_it /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:351
    #4 0x5632eaff98df in throw_verror(errors, char const*, __va_list_tag*) /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:379
    #5 0x5632eaff9a2a in throw_error(errors, char const*, ...) /home/simark/src/binutils-gdb/gdb/common/common-exceptions.c:394
    #6 0x5632eafca21a in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1553
    #7 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
    #8 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
    #9 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
    #10 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
    #11 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
    #12 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
    #13 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
    #14 0x5632ebf3cf09 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:425
    #15 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
    #16 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
    #17 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
    #18 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
    #19 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
    #20 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
    #21 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
    #22 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
    #23 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
    #24 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
    #25 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
    #26 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
    #27 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
    #28 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511
    #29 0x5632eb3aa6a9 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
    #30 0x5632eb3aaf41 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
    #31 0x5632eb3a88ea in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:347
    #32 0x5632eb3a89bf in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
    #33 0x5632eb76fbfc in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:330
    #34 0x5632eb772ea8 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1176
    #35 0x5632eb773071 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1192
    #36 0x5632eabfe7f9 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #37 0x7f1d3554f222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)
    #38 0x5632eabfe5dd in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x195d5dd)

0x60c000019847 is located 7 bytes inside of 128-byte region [0x60c000019840,0x60c0000198c0)
freed by thread T0 here:
    #0 0x7f1d36502491 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
    #1 0x5632eaff9f47 in xrealloc /home/simark/src/binutils-gdb/gdb/common/common-utils.c:62
    #2 0x5632eaff6b44 in buffer_grow(buffer*, char const*, unsigned long) /home/simark/src/binutils-gdb/gdb/common/buffer.c:40
    #3 0x5632eb3b271d in command_line_append_input_line /home/simark/src/binutils-gdb/gdb/event-top.c:614
    #4 0x5632eb3b28c6 in handle_line_of_input(buffer*, char const*, int, char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:654
    #5 0x5632ebf402a6 in command_line_input(char const*, char const*) /home/simark/src/binutils-gdb/gdb/top.c:1252
    #6 0x5632ebf3cee9 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:422
    #7 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
    #8 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
    #9 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
    #10 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
    #11 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
    #12 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
    #13 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
    #14 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
    #15 0x5632ebf3cf09 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:425
    #16 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
    #17 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
    #18 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
    #19 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
    #20 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
    #21 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
    #22 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
    #23 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
    #24 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
    #25 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
    #26 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
    #27 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
    #28 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
    #29 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511

previously allocated by thread T0 here:
    #0 0x7f1d36502491 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
    #1 0x5632eaff9f47 in xrealloc /home/simark/src/binutils-gdb/gdb/common/common-utils.c:62
    #2 0x5632eaff6b44 in buffer_grow(buffer*, char const*, unsigned long) /home/simark/src/binutils-gdb/gdb/common/buffer.c:40
    #3 0x5632eb3b271d in command_line_append_input_line /home/simark/src/binutils-gdb/gdb/event-top.c:614
    #4 0x5632eb3b28c6 in handle_line_of_input(buffer*, char const*, int, char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:654
    #5 0x5632ebf402a6 in command_line_input(char const*, char const*) /home/simark/src/binutils-gdb/gdb/top.c:1252
    #6 0x5632ebf3cee9 in read_command_file(_IO_FILE*) /home/simark/src/binutils-gdb/gdb/top.c:422
    #7 0x5632eafca054 in script_from_file(_IO_FILE*, char const*) /home/simark/src/binutils-gdb/gdb/cli/cli-script.c:1547
    #8 0x5632eaf8a500 in source_script_from_stream /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:569
    #9 0x5632eaf8a735 in source_script_with_search /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:605
    #10 0x5632eaf8ab20 in source_command /home/simark/src/binutils-gdb/gdb/cli/cli-cmds.c:664
    #11 0x5632eafa8b4a in do_const_cfunc /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:106
    #12 0x5632eafb0687 in cmd_func(cmd_list_element*, char const*, int) /home/simark/src/binutils-gdb/gdb/cli/cli-decode.c:1892
    #13 0x5632ebf3dd87 in execute_command(char const*, int) /home/simark/src/binutils-gdb/gdb/top.c:630
    #14 0x5632eb3b25d3 in command_handler(char const*) /home/simark/src/binutils-gdb/gdb/event-top.c:583
    #15 0x5632eb3b2f87 in command_line_handler(std::unique_ptr<char, gdb::xfree_deleter<char> >&&) /home/simark/src/binutils-gdb/gdb/event-top.c:770
    #16 0x5632eb3b0fe1 in gdb_rl_callback_handler /home/simark/src/binutils-gdb/gdb/event-top.c:213
    #17 0x5632ec1c8729 in rl_callback_read_char /home/simark/src/binutils-gdb/readline/callback.c:220
    #18 0x5632eb3b0b8f in gdb_rl_callback_read_char_wrapper_noexcept /home/simark/src/binutils-gdb/gdb/event-top.c:175
    #19 0x5632eb3b0da1 in gdb_rl_callback_read_char_wrapper /home/simark/src/binutils-gdb/gdb/event-top.c:192
    #20 0x5632eb3b2186 in stdin_event_handler(int, void*) /home/simark/src/binutils-gdb/gdb/event-top.c:511
    #21 0x5632eb3aa6a9 in handle_file_event /home/simark/src/binutils-gdb/gdb/event-loop.c:733
    #22 0x5632eb3aaf41 in gdb_wait_for_event /home/simark/src/binutils-gdb/gdb/event-loop.c:859
    #23 0x5632eb3a88ea in gdb_do_one_event() /home/simark/src/binutils-gdb/gdb/event-loop.c:347
    #24 0x5632eb3a89bf in start_event_loop() /home/simark/src/binutils-gdb/gdb/event-loop.c:371
    #25 0x5632eb76fbfc in captured_command_loop /home/simark/src/binutils-gdb/gdb/main.c:330
    #26 0x5632eb772ea8 in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1176
    #27 0x5632eb773071 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1192
    #28 0x5632eabfe7f9 in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
    #29 0x7f1d3554f222 in __libc_start_main (/usr/lib/libc.so.6+0x24222)

SUMMARY: AddressSanitizer: heap-use-after-free /build/gcc/src/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:546 in printf_common

gdb/ChangeLog:

	* top.h (source_file_name): Change to std::string.
	* top.c (source_file_name): Likewise.
	(command_line_input): Adjust.
	* cli/cli-script.c (script_from_file): Adjust.

gdb/testsuite/ChangeLog:

	* gdb.base/source.exp: Move "error in sourced script" code to
	the end.
	* gdb.base/source-error.gdb: Move contents to
	source-error-1.gdb.  Add new code to source source-error-1.gdb.
	* gdb.base/source-error-1.gdb: New file, from previous
	source-error.gdb.
2019-02-19 21:13:21 -05:00
Tom Tromey 98814c6c11 Minor Ada task cleanups
While working on the Ada task code, I noticed a few things that could
be cleaned up:

* task_list_valid_p was not set in all cases in ada_build_task_list.
  This causes many needless re-fetches of the task list.

* task_list_valid_p can be bool, and various functions can also return
  bool.

* Nothing checks the return value of read_known_tasks, so it can be
  changed to return void.

* The call to ada_build_task_list in
  ravenscar_thread_target::update_thread_list is redundant, because
  this is the first thing done by iterate_over_live_ada_tasks.

Tested using the internal AdaCore test suite against a ravenscar
target.

gdb/ChangeLog
2019-02-19  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c
	(ravenscar_thread_target::update_thread_list): Don't call
	ada_build_task_list.
	* ada-lang.h (ada_build_task_list): Don't declare.
	* ada-tasks.c (struct ada_tasks_inferior_data)
	<task_list_valid_p>: Now bool.
	(read_known_tasks, ada_task_list_changed)
	(ada_tasks_invalidate_inferior_data): Update.
	(read_known_tasks_array): Return bool.
	(read_known_tasks_list): Likewise.
	(read_known_tasks): Return void.
	(ada_build_task_list): Now static.
2019-02-19 12:26:37 -07:00
Andrew Burgess 70cd633e87 gdb: Allow gdbarch to override alignment for method and member pointers
The code in type_align (gdbtypes.c) currently hard-codes the rules for
aligning method and member pointers.  It would seem better to forward
these types through the gdbarch hook, so that an architecture could
override the alignment of these types if needed.

Only 3 architectures currently override the gdbarch alignment hook,
these are arc, i386, and nio2.

For arc and nios the alignment rules are that alignment is the minimum
of 4-bytes and the type length.  As pointers are 4-bytes on these
targets, then (assuming method and members pointers are also 4-bytes)
there should be no change to the alignment after this patch.

For i386 the gdbarch alignment hook overrides for some INT and FLOAT
types only.  For method and member pointers we align on the type size
still, so there should be no change to the alignment after this patch.

I tested this on x86-64 GNU Linux with no regressions.

gdb/ChangeLog:

	* gdbtypes.c (type_align): Allow alignment of TYPE_CODE_METHODPTR
	and TYPE_CODE_MEMBERPTR to be overridden by the gdbarch.
2019-02-18 23:24:53 +00:00
Philippe Waroquiers 040b3e95e4 Fix leaks of 'per program space' and 'per inferior' ada task data.
Valgrind reports leaks such as the below.
Fix these leaks by changing ada_tasks_pspace_data_handle
and ada_tasks_inferior_data_handle to use the 'with_cleanup' register variant.

Tested on debian/amd64 natively and under Valgrind.

==26346== 56 bytes in 1 blocks are definitely lost in loss record 631 of 3,249
==26346==    at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344)
==26346==    by 0x38F911: get_ada_tasks_inferior_data(inferior*) (ada-tasks.c:281)
==26346==    by 0x38FA3F: ada_tasks_invalidate_inferior_data (ada-tasks.c:1362)
==26346==    by 0x38FA3F: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1411)
==26346==    by 0x60CBC5: operator() (functional:2127)
==26346==    by 0x60CBC5: notify (observable.h:106)
==26346==    by 0x60CBC5: clear_symtab_users(enum_flags<symfile_add_flag>) (symfile.c:2903)
...

==26346== 104 bytes in 1 blocks are definitely lost in loss record 984 of 3,249
==26346==    at 0x4C2E0BC: calloc (vg_replace_malloc.c:762)
==26346==    by 0x4056F0: xcalloc (common-utils.c:84)
==26346==    by 0x38F8AE: xcnew<ada_tasks_pspace_data> (poison.h:122)
==26346==    by 0x38F8AE: get_ada_tasks_pspace_data(program_space*) (ada-tasks.c:253)
==26346==    by 0x38FA77: ada_tasks_invalidate_pspace_data (ada-tasks.c:1354)
==26346==    by 0x38FA77: ada_tasks_new_objfile_observer(objfile*) (ada-tasks.c:1394)
==26346==    by 0x60CBC5: operator() (functional:2127)
==26346==    by 0x60CBC5: notify (observable.h:106)
...

gdb/ChangeLog
2019-02-18  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* ada-task.c (_initialize_tasks): Use 'with_cleanup' register
	variant for ada_tasks_pspace_data_handle and
	ada_tasks_inferior_data_handle.
	(ada_tasks_pspace_data_cleanup): New function.
	(ada_tasks_inferior_data_cleanup): New function.
2019-02-18 22:14:59 +01:00
Tom Tromey 9409233b0e Change macro_source_fullname to return a std::string
While working on the previous patch, I noticed that if
macro_source_fullname returned a std::string, then the callers would
be simplified.  This patch implements this idea.

gdb/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* macrotab.h (macro_source_fullname): Return a std::string.
	* macrotab.c (macro_include, check_for_redefinition)
	(macro_undef, macro_lookup_definition, foreach_macro)
	(foreach_macro_in_scope): Update.
	(macro_source_fullname): Return a std::string.
	* macrocmd.c (show_pp_source_pos): Update.
2019-02-17 16:28:38 -07:00
Tom Tromey 6506371f06 Add styling to macro commands
This adds filename styling to "info macro".

gdb/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* macrocmd.c (show_pp_source_pos): Style the file names.

gdb/testsuite/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Use -g3 to compile when possible.  Add test
	for macro styling.
	* gdb.base/style.c (SOME_MACRO): New macro.
2019-02-17 16:28:38 -07:00
Tom Tromey 0c820d6793 Fix some valgrind errors in the TUI
The styling series introduced some new errors in the TUI -- the series
changed how source lines are allocated, without updating
tui_set_source_content_nil.

There are several failures but a typical one looks like:

==6274== Use of uninitialised value of size 8
==6274==    at 0x4E4A095: wclrtoeol (in /usr/lib64/libncursesw.so.6.1)
==6274==    by 0x4E47617: waddch (in /usr/lib64/libncursesw.so.6.1)
==6274==    by 0x8325CB: tui_puts_internal(_win_st*, char const*, int*) (tui-io.c:393)
==6274==    by 0x82E89D: tui_file::puts(char const*) (tui-file.c:39)
==6274==    by 0x84BF5F: vfprintf_unfiltered(ui_file*, char const*, __va_list_tag*) (utils.c:2026)

This patch rewrites tui_set_source_content_nil, fixing the bug.

This was also reported as PR tui/24197.

Verified by running valgrind before and after on x86-64 Fedora 29.

gdb/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	PR tui/24197:
	* tui/tui-source.c (tui_set_source_content_nil): Rewrite.
2019-02-17 10:39:45 -07:00
Tom Tromey a008792038 Fix pager bugs with style output
I believe this fixes all the pager output problems with styling that
Philippe pointed out, plus at least one more.  The patch is somewhat
hard to reason about, so you may wish to give it a try.  Even writing
the tests was hard.

This removes the style caching, because it was difficult to keep the
style cache correct in all cases.  Since this would cause more style
escapes to be emitted, instead it changes fputs_styled to try to avoid
unnecessary changes.

Another bug was that the wrap buffer was not flushed in the case where
wrap_column==0.  In the old (pre-patch series) code, characters were
directly emitted in this case; so flushing the wrap buffer here
restores this behavior.

On error the wrap buffer must be emptied.  Otherwise, interrupting
output can leave characters in the buffer that will be emitted later.

As discussed on gdb-patches, this fixes the ada-lang.c problem where
filtered and unfiltered printing were mixed.  Now user_select_syms
uses filtered printing, which is what its callees were already doing.

Finally, it was possible for source line highlighting to be garbled
(and invalid escape sequences emitted) if the pager was invoked at the
wrong spot.  To fix this, the patch arranges for source line escapes
to always be emitted as a unit.

gdb/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (user_select_syms): Use filtered printing.
	* utils.c (wrap_style): New global.
	(desired_style): Remove.
	(emit_style_escape): Add stream parameter.
	(set_output_style, reset_terminal_style, prompt_for_continue):
	Update.
	(flush_wrap_buffer): Only flush gdb_stdout.
	(wrap_here): Set wrap_style.
	(fputs_maybe_filtered): Clear the wrap buffer on exception.  Don't
	treat escape sequences as a character.  Change when wrap buffer is
	flushed.
	(fputs_styled): Do not set the output style when the default is
	requested.
	* ui-style.h (struct ui_file_style) <is_default>: New method.
	* source.c (print_source_lines_base): Emit escape sequences in one
	piece.

gdb/testsuite/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Add line-wrapping tests.
	* gdb.base/page.exp: Add test for quitting during pagination.
2019-02-17 08:35:14 -07:00
Joel Brobecker 75ba10dc55 type_align: handle range types the same as ints and enums
This commit enhances type_align to handle TYPE_CODE_RANGE types
the same as integers and enums, rather than returning zero,
which means for this function that it could not determine its
alignment.

gdb/ChangeLog:

	* gdbtypes.c (type_align): Handle TYPE_CODE_RANGE the same as
        integers and enumeration types.

Tested on x86_64-linux. Also tested on a variety of platforms
(with CPUs being ARM, AArch64, Leon3 (SPARC-like), PowerPC,
PowerPC64, RV64, Visium, x86, x86_64).
2019-02-17 10:04:57 -05:00
Joel Brobecker a2cd4f1475 (Ada) fix GDB crash printing packed array
Trying to print a packed array sometimes leads to a crash (see
attached testcase for an example of when this happens):

  | (gdb) p bad
  | [1]    65571 segmentation fault  gdb -q foo

Variable "bad" is declared in the debug information as an array where
the array's type name has an XPnnn suffix:

  | .uleb128 0xc    # (DIE (0x566) DW_TAG_typedef)
  | .long   .LASF200        # DW_AT_name: "pck__t___XP1"
  | [loc info attributes snipped]
  | .long   0x550   # DW_AT_type
  | .byte   0x1     # DW_AT_alignment

The signals to GDB that the debugging information follows a GNAT encoding
used for packed arrays, and an in order to decode it, we need to find
the type whose name is the same minus the "___XPnnn" suffix: "pck__t".

For that, we make a call to ada-lang.c::standard_lookup, which is
a simple function which essentially does:

  | /* Return the result of a standard (literal, C-like) lookup of NAME in
  |    given DOMAIN, visible from lexical block BLOCK.  */
  |
  |   [...]
  |   sym = lookup_symbol_in_language (name, block, domain, language_c, 0);

Unfortunately for us, while the intent of this call was to perform
an exact-match lookup, in our case, it returns ... type pck__t___XP1
instead! In other words, it finds itself back. The reason why it finds
this type is a confluence of two factors:

  (1) Forcing the lookup into language_c currently does not affect
      how symbol matching is done anymore, because we look at the symbol's
      language to determine which kind of matching should be done;

  (2) The lookup searches the local context (via block) first, beforei
      doing a more general lookup. And looking at the debug info for
      the main subprogram, we see that type "pck__t" is not declared
      there, only in the debug info for pck.ads. In other words,
      there is no way that we accidently find "pck__t" by random chance.

I believe Pedro added a new function called ada_lookup_encoded_symbol
for that specific purpose, so I started by replacing the lookup
by language above by this. Unfortunately, still no joy.

This was because, even though ada_lookup_encoded_symbol puts angle-
brackets around the search name to signal that we want a verbatim
search, we end up losing that information in the function called
to compare a symbol with the search name:

  | static bool
  | do_full_match (const char *symbol_search_name,
  |                const lookup_name_info &lookup_name,
  |                completion_match_result *comp_match_res)
  | {
  |   return full_match (symbol_search_name, ada_lookup_name (lookup_name));
                                             ^^^^^^^^^^^^^^^
                                                    |
                                    <=> lookup_name.m_ada.m_encoded_name
                                           (no angle brackets)

The way I fixed this was by introducing a new function called
do_exact_match, and then adjust ada_get_symbol_name_matcher to
return that function when seeing that we have a verbatim non-wild-match
search.

As it happens, this fixes an incorrect test in gdb.ada/homony.exp,
where we were inserting a breakpoint on a symbol using the angle-brackets
notation, and got 2 locations for that breakpoint...

    (gdb) b <homonym__get_value>
    Breakpoint 1 at 0x4029fc: <homonym__get_value>. (2 locations)

...  each location being in a different function:

    (gdb) info break
    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   <MULTIPLE>
    1.1                         y   0x00000000004029fc in homonym.get_value
                                    at /[...]/homonym.adb:32
    1.2                         y   0x0000000000402a3a in homonym.get_value
                                    at /[...]/homonym.adb:50
    (gdb) x /i 0x00000000004029fc
       0x4029fc <homonym__get_value+8>:     movl   $0x1d,-0x4(%rbp)
    (gdb) x /i 0x0000000000402a3a
       0x402a3a <homonym__get_value__2+8>:  movl   $0x11,-0x4(%rbp)

Since we used angle-brackets, we shouldn't be matching the second one,
something this patch fixes.

gdb/ChangeLog:

        * ada-lang.c (standard_lookup): Use ada_lookup_encoded_symbol
        instead of lookup_symbol_in_language
        (do_exact_match): New function.
        (ada_get_symbol_name_matcher): Return do_exact_match when
        doing a verbatim match.

gdb/testsuite/ChangeLog:

        * gdb.ada/big_packed_array: New testcase.
        * gdb.ada/homonym.exp: Fix incorrect expected output for
        "break <homonym__get_value>" test.

Tested on x86_64-linux.
2019-02-17 08:32:45 -05:00
Tom Tromey 485b851b68 Special-case wildcard requests in ravenscar-thread.c
ravenscar-thread.c intercepts resume and wait target requests and
replaces the requested ptid with the ptid of the underlying CPU.
However, this is incorrect when a request is made with a wildcard
ptid.

This patch adds a special case to ravenscar-thread.c for
minus_one_ptid.  I don't believe a special case for process wildcards
is necessary, so I have not added that.

Joel's description explains the bug well:

At the user level, we noticed the issue because we had a test were
we insert a breakpoint one some code which is only run from, say,
CPU #2, whereas we unfortunately resumed the execution after having
stopped somewhere in CPU #1. As a result, we sent an order to resume
CPU #1, which starves CPU #2 forever, because the code in CPU #1
waits for some of the Ada tasks allocated to CPU #2 (and we never
reach our breakpoint either).

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (ravenscar_thread_target::resume)
	(ravenscar_thread_target::wait): Special case wildcard requests.
2019-02-15 13:53:43 -07:00
Tom Tromey 0b790b1eeb Make the ravenscar thread target multi-target-ready
This changes ravenscar-thread.c to make it ready for multi-target.
This is done by moving globals into the target, and then arranging to
allocate the target with "new" and delete the target in its "close"
method.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (base_ptid): Remove.
	(struct ravenscar_thread_target) <close>: New method.
	<m_base_ptid>: New member.
	<update_inferior_ptid, active_task, task_is_currently_active,
	runtime_initialized>: Declare methods.
	<ravenscar_thread_target>: Add constructor.
	(ravenscar_thread_target::task_is_currently_active)
	(ravenscar_thread_target::update_inferior_ptid)
	(ravenscar_runtime_initialized): Rename.  Now methods.
	(ravenscar_thread_target::resume, ravenscar_thread_target::wait)
	(ravenscar_thread_target::update_thread_list): Update.
	(ravenscar_thread_target::active_task): Now method.
	(ravenscar_thread_target::store_registers)
	(ravenscar_thread_target::prepare_to_store)
	(ravenscar_thread_target::prepare_to_store)
	(ravenscar_thread_target::mourn_inferior): Update.
	(ravenscar_inferior_created): Use "new" to create target.
	(ravenscar_thread_target::get_ada_task_ptid): Update.
	(_initialize_ravenscar): Don't initialize base_ptid.
	(ravenscar_ops): Remove global.
2019-02-15 13:53:43 -07:00
Tom Tromey dea57a6263 Add push_target overload
This adds a push_target overload that takes a "target_ops_up &&".
This removes some calls to release a target_ops_up, and makes the
intent here clearer.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* target.h (push_target): Declare new overload.
	* target.c (push_target): New overload, taking an rvalue reference.
	* remote.c (remote_target::open_1): Use push_target overload.
	* corelow.c (core_target_open): Use push_target overload.
2019-02-15 13:53:43 -07:00
Tom Tromey 989f3c583d Minor C++-ification in ravenscar-thread.c
This changes some functions in ravenscar-thread.c to return "bool"
rather than int, where appropriate, and also changes "(void)" to "()".

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (is_ravenscar_task)
	(ravenscar_task_is_currently_active): Return bool.
	(ravenscar_update_inferior_ptid, get_running_thread_msymbol)
	(_initialize_ravenscar): Remove "(void)".
	(has_ravenscar_runtime, ravenscar_runtime_initialized): Likewise.
	Return bool.
2019-02-15 13:53:43 -07:00
Tom Tromey 6cbcc006e9 Fix formatting in ravenscar-thread.c
This fixes some incorrect formatting in ravenscar-thread.c.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (ravenscar_runtime_initializer)
	(has_ravenscar_runtime, get_running_thread_id)
	(ravenscar_thread_target::resume): Fix indentation.
2019-02-15 13:53:42 -07:00
Tom Tromey 7657f14df7 C++-ify ravenscar_arch_ops
This turns ravenscar_arch_ops into an abstract base class and updates
all the places where it is used.  This is an improvement because it
avoids any possibility of forgetting to set one of the function
pointers.  It also makes clear that these functions aren't intended to
be changed dynamically.

This version of the patch removes the prepare_to_store method, as it
is unused, and it is easy enough to add if it is ever needed.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* sparc-ravenscar-thread.c (struct sparc_ravenscar_ops): Derive
	from ravenscar_arch_ops.
	(sparc_ravenscar_ops::fetch_registers)
	(sparc_ravenscar_ops::store_registers): Now methods.
	(sparc_ravenscar_prepare_to_store): Remove.
	(sparc_ravenscar_ops): Redefine.
	* ravenscar-thread.h (struct ravenscar_arch_ops): Add virtual
	methods and destructor.  Remove members.
	* ravenscar-thread.c (ravenscar_thread_target::fetch_registers)
	(ravenscar_thread_target::store_registers)
	(ravenscar_thread_target::prepare_to_store): Update.
	* ppc-ravenscar-thread.c (ppc_ravenscar_generic_prepare_to_store):
	Remove.
	(struct ppc_ravenscar_powerpc_ops): Derive from
	ravenscar_arch_ops.
	(ppc_ravenscar_powerpc_ops::fetch_registers)
	(ppc_ravenscar_powerpc_ops::store_registers): Now methods.
	(ppc_ravenscar_powerpc_ops): Redefine.
	(struct ppc_ravenscar_e500_ops): Derive from ravenscar_arch_ops.
	(ppc_ravenscar_e500_ops::fetch_registers)
	(ppc_ravenscar_e500_ops::store_registers): Now methods.
	(ppc_ravenscar_e500_ops): Redefine.
	* aarch64-ravenscar-thread.c
	(aarch64_ravenscar_generic_prepare_to_store): Remove.
	(struct aarch64_ravenscar_ops): Derive from ravenscar_arch_ops.
	(aarch64_ravenscar_fetch_registers)
	(aarch64_ravenscar_store_registers): Now methods.
	(aarch64_ravenscar_ops): Redefine.
2019-02-15 13:53:42 -07:00
Tom Tromey 5b6ea500d5 Exception safety in ravenscar-thread.c
This changes some code in ravenscar-thread.c to use scoped_restore.  I
am not sure if it matters in practice, but this makes these methods
exception-safe in case the methods lower in the target stack can
throw.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c (ravenscar_thread_target::stopped_by_sw_breakpoint)
	(ravenscar_thread_target::stopped_by_hw_breakpoint)
	(ravenscar_thread_target::stopped_by_watchpoint)
	(ravenscar_thread_target::stopped_data_address)
	(ravenscar_thread_target::core_of_thread): Use scoped_restore.
2019-02-15 13:53:42 -07:00
Tom Tromey e397fd39c6 Fix some typos in ravenscar-thread.c
This fixes some typos I noticed in ravenscar-thread.c.

gdb/ChangeLog
2019-02-15  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c: Fix some typos.
2019-02-15 13:53:42 -07:00
Tom Tromey cc12f4a8f9 Fix memory leak in create_ada_exception_catchpoint
Phillipe noticed that create_ada_exception_catchpoint was not freeing
the "addr_string" memory:

==14141== 114 bytes in 4 blocks are definitely lost in loss record 1,054 of 3,424
==14141==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==14141==    by 0x405107: xmalloc (common-utils.c:44)
==14141==    by 0x7563F9: xstrdup (xstrdup.c:34)
==14141==    by 0x381B21: ada_exception_sal (ada-lang.c:13217)
==14141==    by 0x381B21: create_ada_exception_catchpoint(gdbarch*, ada_exception_catchpoint_kind, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, int) (ada-lang.c:13251)
==14141==    by 0x3820A8: catch_ada_exception_command(char const*, int, cmd_list_element*) (ada-lang.c:13285)
==14141==    by 0x3F4828: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1892)

This patch fixes the problem by changing ada_exception_sal to return a
std::string via its out parameter.

gdb/ChangeLog
2019-02-15  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
	    Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_exception_sal): Change addr_string to a
	std::string.
	(create_ada_exception_catchpoint): Update.
2019-02-15 13:21:39 -07:00