Commit Graph

43567 Commits

Author SHA1 Message Date
Andrew Burgess 3d63690a03 gdb/testsuite: Add gdb_test_name variable
This commit adds a new feature to gdb_test_multiple, an automatically
created variable gdb_test_name.  The idea is to make it easier to
write tests using gdb_test_multiple, and avoid places where the string
passed to pass/fail within an action element is different to the
message passed to the top level gdb_test_multiple.

As an example, previously you might write this:

    gdb_test_multiple "print foo" "test foo" {
       -re "expected output 1" {
           pass "test foo"
       }
       -re "expected output 2" {
           fail "test foo"
       }
    }

This is OK, but it's easy for the pass/fail strings to come out of
sync, or contain a typo.  A better version would look like this:

    set testname "test foo"
    gdb_test_multiple "print foo" $testname {
       -re "expected output 1" {
           pass $testname
       }
       -re "expected output 2" {
           fail $testname
       }
    }

This is better, but its a bit of a drag having to create a new
variable each time.

After this patch you can now write this:

    gdb_test_multiple "print foo" "test foo" {
       -re "expected output 1" {
           pass $gdb_test_name
       }
       -re "expected output 2" {
           fail $gdb_test_name
       }
    }

The $gdb_test_name is setup by gdb_test_multiple, and cleaned up once
the test has completed.  Nested calls to gdb_test_multiple are
supported, though $gdb_test_name will only ever contain the inner most
test message (which is probably what you want).

My only regret is that '$gdb_test_name' is so long, but I wanted
something that was unlikely to clash with any existing variable name,
or anything that a user is likely to want to use.

I've tested this on x86-64/GNU Linux and see no test regressions, and
I've converted one test script over to make use of this new technique
both as an example, and to ensure that the new facility doesn't get
broken.  I have no plans to convert all tests over to this technique,
but I hope others will find this useful for writing tests in the
future.

gdb/testsuite/ChangeLog:

	* lib/gdb.exp (gdb_test_multiple): Add gdb_test_name mechanism.
	* gdb.base/annota1.exp: Update to use gdb_test_name.
2019-10-07 11:26:11 +01:00
Tom de Vries 760f7560fd [gdb/doc] Fix some typos
Fix typos 'prevsiouly -> previously' and 'corresonding -> corresponding' in the
docs.

gdb/doc/ChangeLog:

2019-10-07  Tom de Vries  <tdevries@suse.de>

	* gdb.texinfo: Fix typo.
	* guile.texi: Same.
	* python.texi: Same.
2019-10-07 09:51:18 +02:00
Weimin Pan 30d1f01849 gdb: CTF support
This patch adds the CTF (Compact Ansi-C Type Format) support in gdb.
Two submissions on which this gdb work depends were posted earlier
in May:

 * On the binutils mailing list - adding libctf which creates, updates,
   reads, and manipulates the CTF data.
 * On the gcc mailing list - expanding gcc to directly emit the CFT data
   with a new command line option -gt.

CTF is a reduced form of debugging information whose main purpose is to
describe the type of C entities such as structures, unions, typedefs and
function arguments at the global scope only. It does not contain debug
information about source lines, location expressions, or local variables.
For more information on CTF, see the documentation in the libdtrace-ctf
source tree, available here:

<https://raw.githubusercontent.com/oracle/libdtrace-ctf/master/doc/ctf-format>.

This patch expands struct elfinfo by adding the .ctf section, which
contains CTF debugging info, and modifies elf_symfile_read() to read it.
If both DWARF and CTF exist in a program, only DWARF will be read. CTF data
will be read only when there is no DWARF. The two-stage symbolic reading
and setting strategy, partial and full, was used.

File ctfread.c contains functions to transform CTF data into gdb's internal
symbol table structures by iterately reading entries from CTF sections
of "data objects", "function info", "variable info", and "data types"
when setting up either partial or full symbol table. If the ELF symbol table
is available, e.g. not stripped, the CTF reader will associate the found
type information with these symbol entries. Due to the proximity between DWARF
and CTF (CTF being a much simplified subset of DWARF), some DWARF implementation
was reused to support CTF.

Test cases ctf-constvars.exp, ctf-cvexpr.exp, ctf-ptype.exp, and ctf-whatis.exp
have been added to verify the correctness of this support.

This patch has missing features and limitations which we will add and
address in the future patches.

gdb/ChangeLog
+2019-10-07  Weimin Pan  <weimin.pan@oracle.com>
+
+       * gdb/ctfread.c: New file.
+       * gdb/ctfread.h: New file.
+       * gdb/elfread.c: Include ctfread.h.
+       (struct elfinfo text_p): New member ctfsect.
+       (elf_locate_sections): Mark CTF section.
+       (elf_symfile_read): Call elfctf_build_psymtabs.
+       * gdb/Makefile.in (LIBCTF): Add.
+       (CLIBS): Use it.
+       (CDEPS): Likewise.
+       (DIST): Add ctfread.c.
+       * Makefile.def (dependencies): Add all-libctf to all-gdb
+       * Makefile.in: Add "all-gdb: maybe-all-libctf"
+
gdb/testsuite/ChangeLog
+2019-10-07  Weimin Pan  <weimin.pan@oracle.com>
+
+       * gdb.base/ctf-whatis.exp: New file.
+       * gdb.base/ctf-whatis.c: New file.
+       * gdb.base/ctf-ptype.exp: New file.
+       * gdb.base/ctf-ptype.c: New file.
+       * gdb.base/ctf-constvars.exp: New file.
+       * gdb.base/ctf-constvars.c: New file.
+       * gdb.base/ctf-cvexpr.exp: New file.
+
2019-10-07 02:26:27 +00:00
Weimin Pan 518fe38cd9 Renaming of ctf (the trace format) files 2019-10-07 01:44:45 +00:00
Joel Brobecker 225f296a02 Change gdb/version.in to 9.0.50.DATE-git (new version numbering scheme)
gdb/ChangeLog:

        * version.in: Change version number to "9.0.50.DATE-git".
2019-10-06 08:32:00 -07:00
Tom de Vries 4dbbb47c16 [gdb/testsuite] Fix local-static.exp with gcc-4.8
With gdb.cp/local-static.exp and gcc 4.8, I see:
...
gdb compile failed, src/gdb/testsuite/gdb.cp/local-static.c: In function 'main':
src/gdb/testsuite/gdb.cp/local-static.c:148:3: error: 'for' loop initial \
  declarations are only allowed in C99 mode
   for (int i = 0; i < 1000; i++)
   ^
src/gdb/testsuite/gdb.cp/local-static.c:148:3: note: use option -std=c99 or \
  -std=gnu99 to compile your code
UNTESTED: gdb.cp/local-static.exp: c: failed to prepare
...

Fix this by moving the declaration of int i out of the for loop.

gdb/testsuite/ChangeLog:

2019-10-04  Tom de Vries  <tdevries@suse.de>

	* gdb.cp/local-static.c (main): Move declaration of int i out of the
	for loop.
2019-10-04 16:23:24 +02:00
Tom Tromey 77c2dba3e8 Avoid crash on single-field union in Rust
PR rust/24976 points out a crash in gdb when a single-field union is
used in Rust.

The immediate problem was a NULL pointer dereference in
quirk_rust_enum.  However, that code is also erroneously treating a
single-field union as if it were a univariant enum.  Looking at the
output of an older Rust compiler, it turns out that univariant enums
are distinguished by having a single *anonymous* field.  This patch
changes quirk_rust_enum to limit its fixup to this case.

Tested with a new-enough version of the Rust compiler to cause the
crash; plus by using an older executable that uses the old univariant
encoding.

gdb/ChangeLog
2019-10-03  Tom Tromey  <tom@tromey.com>

	PR rust/24976:
	* dwarf2read.c (quirk_rust_enum): Handle single-element unions.

gdb/testsuite/ChangeLog
2019-10-03  Tom Tromey  <tom@tromey.com>

	PR rust/24976:
	* gdb.rust/simple.rs (Union2): New type.
	(main): Use Union2.
	* gdb.rust/simple.exp: Add test.
2019-10-03 20:56:22 -06:00
Andrew Burgess 179aed7fdc gdb/fortran: Allow for matching symbols with missing scope
This commit allows symbol matching within Fortran code without having
to specify all of the symbol's scope.  For example, given this Fortran
code:

    module aaa
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo
    end module aaa

    subroutine foo
      print *, "hello."
    end subroutine foo

    program test
      call foo
    contains
      subroutine foo
        print *, "hello."
      end subroutine foo

      subroutine bar
        use aaa
        call foo
      end subroutine bar
    end program test

The user can now do this:

    (gdb) b foo
    Breakpoint 1 at 0x4006c2: foo. (3 locations)
    (gdb) info breakpoints
    Num     Type           Disp Enb Address            What
    1       breakpoint     keep y   <MULTIPLE>
    1.1                         y   0x00000000004006c2 in aaa::foo at nest.f90:4
    1.2                         y   0x0000000000400730 in foo at nest.f90:9
    1.3                         y   0x00000000004007c3 in test::foo at nest.f90:16

The user asks for a breakpoint on 'foo' and is given a breakpoint on
all three possible 'foo' locations.  The user is, of course, still
able to specify the scope in order to place a single breakpoint on
just one of the foo functions (or use 'break -qualified foo' to break
on just the global foo).

gdb/ChangeLog:

	* f-lang.c (f_language_defn): Use cp_get_symbol_name_matcher and
	cp_search_name_hash.
	* NEWS: Add entry about nested function support.

gdb/testsuite/ChangeLog:

	* gdb.fortran/nested-funcs-2.exp: Run tests with and without the
	nested function prefix.
2019-10-03 21:25:22 +01:00
Andrew Burgess 0a4b09130a gdb/fortran: Nested subroutine support
This patch is a rebase and update of the following three patches:

   https://sourceware.org/ml/gdb-patches/2018-11/msg00298.html
   https://sourceware.org/ml/gdb-patches/2018-11/msg00302.html
   https://sourceware.org/ml/gdb-patches/2018-11/msg00301.html

I have merged these together into a single commit as the second patch,
adding scope support to nested subroutines, means that some of the
changes in the first patch are now no longer useful and would have to
be backed out.  The third patch is tightly coupled to the changes in
the second of these patches and I think deserves to live together with
it.

There is an extra change in cp-namespace.c that is new, this resolves
an issue with symbol lookup when placing breakpoints from within
nested subroutines.

There is also an extra test added to this commit 'nested-funcs-2.exp'
that was written by Richard Bunt from ARM, this offers some additional
testing of breakpoints on nested functions.

After this commit it is possible to place breakpoints on nested
Fortran subroutines and functions by using a fully scoped name, for
example, given this simple Fortran program:

    program greeting
      call message
    contains
      subroutine message
        print *, "Hello World"
      end subroutine message
    end program greeting

It is possible to place a breakpoint in 'message' with:

    (gdb) break greeting::message
    Breakpoint 1 at 0x4006c9: file basic.f90, line 5.

What doesn't work with this commit is placing a breakpoint like this:

    (gdb) break message
    Function "message" not defined.

Making this work will come in a later commit.

gdb/ChangeLog:

	* cp-namespace.c (cp_search_static_and_baseclasses): Only search
	for nested static variables when searchin VAR_DOMAIN.
	* dwarf2read.c (add_partial_symbol): Add nested subroutines to the
	global scope, update comment.
	(add_partial_subprogram): Call add_partial_subprogram recursively
	for nested subroutines when processinng Fortran.
	(load_partial_dies): Process the child entities of a subprogram
	when processing Fortran.
	(partial_die_parent_scope): Handle building scope
	for Fortran nested functions.
	(process_die): Record that nested functions have a scope.
	(new_symbol): Always record Fortran subprograms on the global
	symbol list.
	(determine_prefix): How to build the prefix for Fortran
	subprograms.

gdb/testsuite/ChangeLog:

	* gdb.fortran/nested-funcs.exp: Tests for placing breakpoints on
	nested functions.
	* gdb.fortran/nested-funcs.f90: Update expected results.
	* gdb.fortran/nested-funcs-2.exp: New file.
	* gdb.fortran/nested-funcs-2.f90: New file.

gdb/doc/ChangeLog:

	* doc/gdb.texinfo (Fortran Operators): Describe scope operator.
2019-10-03 21:25:22 +01:00
Andrew Burgess 082cce059d gdb/testsuite: Reduce test name duplication in gdb.python tests
This commit removes some, but not all, of the test name duplication
within the gdb.python tests.  On my local machine this takes the
number of duplicate test names in this set of tests from 174 to 85.
It is possible that different setups might encounter more duplicate
tests.

gdb/testsuite/ChangeLog:

	* gdb.python/py-parameter.exp: Make test names unique.
	* gdb.python/py-template.exp: Likewise.
	* gdb.python/py-value.exp: Likewise.
2019-10-03 17:48:03 +01:00
Andrew Burgess 2b74ba5a19 gdb/testsuite: Reduce test name duplication in gdb.base tests
This commit removes some, but not all, of the test name duplication
within the gdb.base tests.  On my local machine this takes the number
of duplicate test names in this set of tests from 454 to 145.  It is
possible that different setups might encounter more duplicate tests.

gdb/testsuite/ChangeLog:

	* gdb.base/break-interp.exp: Reduce test name duplication.
	* gdb.base/call-sc.exp: Likewise.
	* gdb.base/callfuncs.exp: Likewise.
	* gdb.base/charset.exp: Likewise.
	* gdb.base/dump.exp: Likewise.
	* gdb.base/ena-dis-br.exp: Likewise.
	* gdb.base/relational.exp: Likewise.
	* gdb.base/step-over-syscall.exp: Likewise.
	* gdb.base/structs.exp: Likewise.
2019-10-03 17:48:03 +01:00
Andrew Burgess 58eb20d527 gdb/testsuite: Make test names unique in gdb.linespec tests
Make test names unique in the gdb.linespec tests.  On my local machine
this removed 43 duplicate test names.  It is possible that different
setups might still encounter some duplicates.

gdb/testsuite/ChangeLog:

	* gdb.linespec/explicit.exp: Make test names unique.
	* gdb.linespec/ls-errs.exp: Likewise.
2019-10-03 17:48:02 +01:00
Andrew Burgess 4d4211478f gdb/testsuite: Make test names unique in gdb.reverse tests
Make test names unique in the gdb.reverse tests.  On my local machine
this removed 825 duplicate test names.  It is possible that different
setups might still encounter some duplicates.

gdb/testsuite/ChangeLog:

	* gdb.reverse/break-precsave.exp: Make test names unique.
	* gdb.reverse/break-reverse.exp: Likewise.
	* gdb.reverse/finish-precsave.exp: Likewise.
	* gdb.reverse/finish-reverse.exp: Likewise.
	* gdb.reverse/machinestate-precsave.exp: Likewise.
	* gdb.reverse/machinestate.exp: Likewise.
	* gdb.reverse/readv-reverse.exp: Likewise.
	* gdb.reverse/recvmsg-reverse.exp: Likewise.
	* gdb.reverse/sigall-precsave.exp: Likewise.
	* gdb.reverse/sigall-reverse.exp: Likewise.
	* gdb.reverse/step-indirect-call-thunk.exp: Likewise.
	* gdb.reverse/watch-precsave.exp: Likewise.
	* gdb.reverse/watch-reverse.exp: Likewise.
2019-10-03 17:48:02 +01:00
Andrew Burgess d8c06f22a3 gdb: Don't ignore all SIGSTOP when the signal handler is set to pass
It was observed that in a multi-threaded application on GNU/Linux,
that if the user has set the SIGSTOP to be pass (using GDB's handle
command) then the inferior would hang upon hitting a breakpoint.

What happens is that when a thread hits the breakpoint GDB tries to
stop all of the other threads by sending them a SIGSTOP and setting
the stop_requested flag in the target_ops structure - this can be seen
in infrun.c:stop_all_threads.

GDB then waits for all of the other threads to stop.

When the SIGSTOP event arrives we eventually end up in
linux-nat.c:linux_nat_filter_event, which has the job of deciding if
the event we're looking at (the SIGSTOP arriving in this case) is
something that should be reported back to the core of GDB.

One of the final actions of this function is to check if we stopped
due to a signal, and if we did, and the signal has been set to 'pass'
by the user then we ignore the event and resume the thread.

This code already has some conditions in place that mean the event is
reported to GDB even if the signal is in the set of signals to be
passed to the inferior.

In this commit I extend this condition such that:

  If the signal is a SIGSTOP, and the thread's stop_requested flag is
  set (indicating we're waiting for the thread to stop with a SIGSTOP)
  then we should report this SIGSTOP to GDB and not pass it to the
  inferior.

With this change in place the test now passes.  Regression tested on
x86-64 GNU/Linux with no regressions.

gdb/ChangeLog:

	* linux-nat.c (linux_nat_filter_event): Don't ignore SIGSTOP if we
	have just sent the thread a SIGSTOP and are waiting for it to
	arrive.

gdb/testsuite/ChangeLog:

	* gdb.threads/stop-with-handle.c: New file.
	* gdb.threads/stop-with-handle.exp: New file.
2019-10-03 16:12:02 +01:00
Tom de Vries 3a56ed8668 [gdb/testsuite] Fix list-missing-source.exp with gcc 4.8
With gcc 4.8.1, we see this FAIL:
...
(gdb) PASS: gdb.base/list-missing-source.exp: list
info source^M
Current source file is outputs/gdb.base/list-missing-source/main.c^M
Source language is c.^M
Producer is GNU C 4.8.5 -mtune=generic -march=x86-64 -g -fno-stack-protector.^M
Compiled with DWARF 2 debugging format.^M
Does not include preprocessor macro info.^M
(gdb) FAIL: gdb.base/list-missing-source.exp: info source
...

The problem is that a "Compilation directory is <dir>" line is expected, but
this is missing due to the fact the the compilation unit for main.c doesn't
contain a DW_AT_comp_dir in the DW_TAG_compile_unit DIE.

Fix this by allowing the "Compilation directory" line to be missing.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-10-03  Tom de Vries  <tdevries@suse.de>

	PR testsuite/25059
	* gdb.base/list-missing-source.exp: Allowing the "Compilation
	directory" line to be missing.
2019-10-03 16:22:09 +02:00
Tom de Vries 4227504491 [gdb/testsuite] Fix info-types.exp with gcc/g++ 4.8
The gdb.base/info-types.exp test-case FAILs with gcc/g++ 4.8 because the DWARF
record for the 'unsigned int' type is missing in the executables, while it is
present for gcc/g++ 7.4.1.

For a minimal example using gcc 7.4.1:
...
$ echo "enum enum_t { AA, BB, CC }; enum enum_t var;" > enum.c
$ gcc enum.c -c -g
...
we find that the enum type has DW_AT_encoding 'unsigned':
 <1><1d>: Abbrev Number: 2 (DW_TAG_enumeration_type)
    <1e>   DW_AT_name        : (indirect string, offset: 0x1f): enum_t
    <22>   DW_AT_encoding    : 7        (unsigned)
    <23>   DW_AT_byte_size   : 4
    <24>   DW_AT_type        : <0x3e>
    <28>   DW_AT_decl_file   : 1
    <29>   DW_AT_decl_line   : 1
    <2a>   DW_AT_sibling     : <0x3e>
...
and a DW_AT_type reference to the type 'unsigned int':
...
 <1><3e>: Abbrev Number: 4 (DW_TAG_base_type)
    <3f>   DW_AT_byte_size   : 4
    <40>   DW_AT_encoding    : 7        (unsigned)
    <41>   DW_AT_name        : (indirect string, offset: 0x26): unsigned int
...

With gcc 4.8.5 however, we have no 'unsigned' encoding, and no DW_AT_type:
...
 <1><1d>: Abbrev Number: 2 (DW_TAG_enumeration_type)
    <1e>   DW_AT_name        : (indirect string, offset: 0x1f): enum_t
    <22>   DW_AT_byte_size   : 4
    <23>   DW_AT_decl_file   : 1
    <24>   DW_AT_decl_line   : 1
    <25>   DW_AT_sibling     : <0x39>
...
as well as no record for 'unsigned int'.

Make the test-case pass with gcc/g++ 4.8 by making the presence of the
'unsigned int' type optional.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-10-03  Tom de Vries  <tdevries@suse.de>

	PR testsuite/25059
	* gdb.base/info-types.exp: Make the presence of the 'unsigned int'
	type optional.
2019-10-03 15:02:58 +02:00
Andrew Burgess a8b3b8e93e gdb: Remove whitespace in 'std::vector <...>'
In the following 3 commits:

    commit df07e2c772
    Date:   Wed Sep 25 16:10:50 2019 +0100

        gdb: Remove a use of VEC from dwarf2read.{c,h}

    commit 554ac434b0
    Date:   Thu Sep 19 13:17:59 2019 -0400

        gdb: Change a VEC to std::vector in btrace.{c,h}

    commit 46f29a9a26
    Date:   Mon Sep 16 09:12:27 2019 -0400

        gdb: Remove a VEC from gdbsupport/btrace-common.h

I incorrectly wrote 'std::vector <...>' instead of 'std::vector<...>',
this commit fixes this mistake.  There should be no user visible
changes after this commit.

gdb/ChangeLog:

	* btrace.c (btrace_add_pc): Remove whitespace before the template
	parameter in 'std::vector <...>'.
	(parse_xml_btrace_block): Likewise.
	(btrace_maint_decode_pt): Likewise.
	(btrace_maint_update_packets): Likewise.
	(btrace_maint_print_packets): Likewise.
	* btrace.h (struct btrace_maint_info): Likewise.
	* dwarf2read.c (struct type_unit_group): Likewise.
	(build_type_psymtabs_reader): Likewise.
	* gdbsupport/btrace-common.c (btrace_data_append): Likewise.
	* gdbsupport/btrace-common.h (struct btrace_data_bts): Likewise.
	* nat/linux-btrace.c (perf_event_read_bts): Likewise.
2019-10-03 09:42:42 +01:00
Tom de Vries 4d825eab2d [gdb] Fix set/show style metadata help text
There's a recent regression:
...
FAIL: gdb.gdb/unittest.exp: maintenance selftest
...

In more detail:
...
Running selftest help_doc_invariants.^M
help doc broken invariant: command 'set style metadata' help doc first line \
  is not terminated with a '.' character^M
help doc broken invariant: command 'show style metadata' help doc first line \
  is not terminated with a '.' character^M
Self test failed: self-test failed at gdb/unittests/help-doc-selftests.c:95^M
...

Fix this by adding a '.' at the end of the first line of the help text for
set/show style metadata.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-10-03  Tom de Vries  <tdevries@suse.de>

	* cli/cli-style.c (_initialize_cli_style): Adding a '.' at the end of
	the first line of the help text for set/show style metadata.
2019-10-03 10:15:39 +02:00
Christian Biesinger 3e6ec53ac1 Convert boolean globals in server.c to bool
Converts the int globals to bool.

gdb/gdbserver/ChangeLog:

2019-10-02  Christian Biesinger  <cbiesinger@google.com>

	* server.c (server_waiting): Change to bool.
	(extended_protocol): Likewise.
	(response_needed): Likewise.
	(exit_requested): Likewise.
	(run_once): Likewise.
	(report_no_resumed): Likewise.
	(non_stop): Likewise.
	(disable_packet_vCont): Likewise.
	(disable_packet_Tthread): Likewise.
	(disable_packet_qC): Likewise.
	(disable_packet_qfThreadInfo): Likewise.
	(handle_general_set): Update.
	(handle_detach): Update.
	(handle_monitor_command): Update.
	(handle_query): Update.
	(captured_main): Update.
	(process_serial_event): Update.
	* server.h (server_waiting): Change to bool.
	(disable_packet_vCont): Likewise.
	(disable_packet_Tthread): Likewise.
	(disable_packet_qC): Likewise.
	(disable_packet_qfThreadInfo): Likewise.
	(run_once): Likewise.
	(non_stop): Likewise.
	* target.c (target_stop_and_wait): Update.
2019-10-02 14:48:53 -05:00
Tom Tromey 80fd282641 Fix type of startup_with_shell in gdbserver
startup_with_shell was changed to be of "bool" type, but I noticed
that the definition in gdbserver disagreed.  This disagreement caused
some regressions on a big-endian machine.

This patch removes the redundant declaration and definition of
startup_with_shell and ensures that such clashes will be diagnosed.

This moves the declaration to common-inferior.h, and introduces a new
common-inferior.c, as suggested by Pedro.

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

	* Makefile.in (COMMON_SFILES): Add common-inferior.c.
	* gdbsupport/common-inferior.c: New file.
	* infcmd.c (startup_with_shell): Don't define.
	* nat/fork-inferior.h (startup_with_shell): Don't declare.
	* gdbsupport/common-inferior.h (startup_with_shell): Declare.
	* inferior.h (startup_with_shell): Don't declare.

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

	* Makefile.in (SFILES): Add common-inferior.c.
	(OBS): Add common-inferior.o.
	* server.c (startup_with_shell): Don't define.
2019-10-02 13:43:41 -06:00
Christian Biesinger 700545387d Add missing includes to gdb_assert.h and gdb_string_view.h
gdb::string_view uses gdb_assert, so it should include that header.
And gdb_assert uses internal_error, so it should include errors.h.

gdb/ChangeLog:

2019-10-02  Christian Biesinger  <cbiesinger@google.com>

	* gdbsupport/gdb_assert.h: Include errors.h.
	* gdbsupport/gdb_string_view.h: Include gdb_assert.h.
2019-10-02 13:33:09 -05:00
Andreas Arnez 9ef62df072 gdb/testsuite: Fix py-format-string.exp on big-endian platforms
GDB's py-format-string test case depends on endianness.  In particular it
relies on the first byte of the machine representation of 42 (as an int)
to be 42 as well.  While this is indeed the case for little-endian
machines, big-endian machines store a zero in the first byte instead.  The
wrong assumption leads to lots of FAILs on such architectures.

Fix this by filling the affected union with bytes of the same value, such
that endianness does not matter.  Use the value 42, to keep the character
in the first byte unchanged.

gdb/testsuite/ChangeLog:

	* gdb.python/py-format-string.c (string.h): New include.
	(main): Fill a_struct_with_union.the_union.an_int with bytes of
	the same value, for endianness-independence.
	* gdb.python/py-format-string.exp (default_regexp_dict)
	(test_pretty_structs, test_format): Adjust expected output to the
	changed initialization.
2019-10-02 20:01:44 +02:00
Tom Tromey 37f6a7f456 Add $_ada_exception convenience variable
This adds the $_ada_exception convenience variable.  It is set by the
Ada exception catchpoints, and holds the address of the exception
currently being thrown.  This is useful because it allows more
fine-grained filtering of exceptions than is possible using the
existing "catch" syntax.

This also simplifies Ada catchpoints somewhat; because the catchpoint
must now carry the "kind", it's possible to remove many helper
functions.

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

	* NEWS: Add $_ada_exception entry.
	* ada-lang.c (struct ada_catchpoint): Add constructor.
	<m_kind>: New member.
	(allocate_location_exception, re_set_exception): Remove
	"ex" parameter.
	(should_stop_exception): Compute $_ada_exception.
	(check_status_exception, print_it_exception)
	(print_one_exception, print_mention_exception): Remove
	"ex" parameter.
	(allocate_location_catch_exception, re_set_catch_exception)
	(check_status_exception, print_it_catch_exception)
	(print_one_catch_exception, print_mention_catch_exception)
	(print_recreate_catch_exception)
	(allocate_location_catch_exception_unhandled)
	(re_set_catch_exception_unhandled)
	(check_status_exception, print_it_catch_exception_unhandled)
	(print_one_catch_exception_unhandled)
	(print_mention_catch_exception_unhandled)
	(print_recreate_catch_exception_unhandled)
	(allocate_location_catch_assert, re_set_catch_assert)
	(check_status_assert, print_it_catch_assert)
	(print_one_catch_assert, print_mention_catch_assert)
	(print_recreate_catch_assert)
	(allocate_location_catch_handlers, re_set_catch_handlers)
	(check_status_handlers, print_it_catch_handlers)
	(print_one_catch_handlers, print_mention_catch_handlers)
	(print_recreate_catch_handlers): Remove.
	(create_ada_exception_catchpoint): Update.
	(initialize_ada_catchpoint_ops): Update.

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

	* gdb.texinfo (Set Catchpoints, Convenience Vars): Document
	$_ada_exception.

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

	* gdb.ada/catch_ex_std.exp: Add $_ada_exception test.
2019-10-02 09:53:17 -06:00
Tom Tromey fccf9de11f Back out earlier Ada exception change
commit 2ff0a9473 (Fix "catch exception" with dynamic linking) changed
how ada-lang.c creates expressions to determine if an exception
catchpoint should stop.

That patch is no longer needed now that copy relocations are handled
more directly.

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

	* ada-lang.c (ada_lookup_simple_minsyms): Remove.
	(create_excep_cond_exprs): Simplify exception string computation.
	(ada_exception_catchpoint_cond_string): Likewise.
2019-10-02 09:53:17 -06:00
Pedro Alves 1d58d6a26c Make print-file-var.exp test attribute visibility hidden, dlopen, and main symbol
Make gdb.base/print-file-var.exp test all combinations of:

  - attribute hidden in the this_version_id symbols or not
  - dlopen or not
  - this_version_id symbol in main file or not
  - C++

gdb/testsuite/ChangeLog
2019-10-02  Pedro Alves  <palves@redhat.com>
	    Andrew Burgess  <andrew.burgess@embecosm.com>

	* gdb.base/print-file-var-lib1.c: Include <stdio.h> and
	"print-file-var.h".
	(this_version_id) Use ATTRIBUTE_VISIBILITY.
	(get_version_1): Print this_version_id and its address.
	Add extern "C" wrappers around interface functions.
	* gdb.base/print-file-var-lib2.c: Include <stdio.h> and
	"print-file-var.h".
	(this_version_id) Use ATTRIBUTE_VISIBILITY.
	(get_version_2): Print this_version_id and its address.
	Add extern "C" wrappers around interface functions.
	* gdb.base/print-file-var-main.c: Include <dlfcn.h>, <assert.h>,
	<stddef.h> and "print-file-var.h".
	Add extern "C" wrappers around interface functions.
	[VERSION_ID_MAIN] (this_version_id): Define.
	(main): Define v0.  Use dlopen if SHLIB_NAME is defined.
	* gdb.base/print-file-var.h: Add some #defines to simplify setting
	up extern "C" blocks.
	* gdb.base/print-file-var.exp (test): New, factored out from top
	level.
	(top level): Test all combinations of attribute hidden or not,
	dlopen or not, and this_version_id symbol in main file or not.
	Compile tests as both C++ and C, make test names unique.
2019-10-02 09:53:17 -06:00
Tom Tromey 4b610737f0 Handle copy relocations
In ELF, if a data symbol is defined in a shared library and used by
the main program, it will be subject to a "copy relocation".  In this
scenario, the main program has a copy of the symbol in question, and a
relocation that tells ld.so to copy the data from the shared library.
Then the symbol in the main program is used to satisfy all references.

This patch changes gdb to handle this scenario.  Data symbols coming
from ELF shared libraries get a special flag that indicates that the
symbol's address may be subject to copy relocation.

I looked briefly into handling copy relocations by looking at the
actual relocations in the main program, but this seemed difficult to
do with BFD.

Note that no caching is done here.  Perhaps this could be changed if
need be; I wanted to avoid possible problems with either objfile
lifetimes and changes, or conflicts with the long-term (vapor-ware)
objfile splitting project.

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

	* symmisc.c (dump_msymbols): Don't use MSYMBOL_VALUE_ADDRESS.
	* ada-lang.c (lesseq_defined_than): Handle
	LOC_STATIC.
	* dwarf2read.c (dwarf2_per_objfile): Add can_copy
	parameter.
	(dwarf2_has_info): Likewise.
	(new_symbol): Set maybe_copied on symbol when
	appropriate.
	* dwarf2read.h (dwarf2_per_objfile): Add can_copy
	parameter.
	<can_copy>: New member.
	* elfread.c (record_minimal_symbol): Set maybe_copied
	on symbol when appropriate.
	(elf_symfile_read): Update call to dwarf2_has_info.
	* minsyms.c (lookup_minimal_symbol_linkage): New
	function.
	* minsyms.h (lookup_minimal_symbol_linkage): Declare.
	* symtab.c (get_symbol_address, get_msymbol_address):
	New functions.
	* symtab.h (get_symbol_address, get_msymbol_address):
	Declare.
	(SYMBOL_VALUE_ADDRESS, MSYMBOL_VALUE_ADDRESS): Handle
	maybe_copied.
	(struct symbol, struct minimal_symbol) <maybe_copied>:
	New member.
2019-10-02 09:53:17 -06:00
Tom Tromey 1dd5885077 Make current_source_* per-program-space
This changes current_source_symtab and current_source_line to be
per-program-space.  This ensures that switching inferiors will
preserve the current "list" location for that inferior, and also
ensures that the default expression evaluation context always comes
with the current inferior.

No test case, because the latter problem crops up with an existing
gdb.multi test case once this entire series has been applied.

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

	* source.c (struct current_source_location): New.
	(current_source_key): New global.
	(current_source_symtab, current_source_line)
	(current_source_pspace): Remove.
	(get_source_location): New function.
	(get_current_source_symtab_and_line)
	(set_default_source_symtab_and_line)
	(set_current_source_symtab_and_line)
	(clear_current_source_symtab_and_line, select_source_symtab)
	(info_source_command, print_source_lines_base)
	(info_line_command, search_command_helper, _initialize_source):
	Update.
2019-10-02 09:53:17 -06:00
Tom Tromey 5c281dbb24 Don't call decode_line_with_current_source from select_source_symtab
select_source_symtab currently calls decode_line_with_current_source.
However, this function iterates over all program spaces, and so it is
possible that it will return a "main" from some other program space.

This patch changes select_source_symtab to simply use the symbol it
already found in the current program space.

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

	* source.c (select_source_symtab): Don't call
	decode_line_with_current_source.
2019-10-02 09:53:17 -06:00
Andrew Burgess d3d323915c Search global block from basic_lookup_symbol_nonlocal
This changes lookup_global_symbol to look in the global block
of the passed-in block.  If no block was passed in, it reverts to the
previous behavior.

This change is needed to ensure that 'FILENAME'::NAME lookups work
properly.  As debugging Pedro's test case showed, this was not working
properly in the case where multiple identical names could be found
(the one situation where this feature is truly needed :-).

This also removes some old comments from basic_lookup_symbol_nonlocal
that no longer apply.

Note that the new test cases for this change will appear in a later
patch.  They are in gdb.base/print-file-var.exp.

gdb/ChangeLog
2019-10-02  Andrew Burgess  <andrew.burgess@embecosm.com>

	* symtab.c (lookup_global_symbol): Search global block.
2019-10-02 09:53:17 -06:00
Tom Tromey 38583298e0 Change SYMBOL_VALUE_ADDRESS to be an rvalue
This changes SYMBOL_VALUE_ADDRESS to be an rvalue.  The symbol readers
generally assign using this, so this also introduces
SET_SYMBOL_VALUE_ADDRESS and updates the readers.  Making this change
is useful in a subsequent patch, which redefined SYMBOL_VALUE_ADDRESS.

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

	* coffread.c (process_coff_symbol): Update.
	* dwarf2read.c (var_decode_location, new_symbol): Update.
	* mdebugread.c (parse_symbol): Update.
	* objfiles.c (relocate_one_symbol): Update.
	* stabsread.c (define_symbol, fix_common_block)
	(scan_file_globals): Update.
	* symtab.h (SYMBOL_VALUE_ADDRESS): Expand to an rvalue.
	(SET_SYMBOL_VALUE_ADDRESS): New macro.
	* xcoffread.c (process_xcoff_symbol): Update.
2019-10-02 09:53:17 -06:00
Andreas Arnez 9344c18feb Update my email address in gdb/MAINTAINERS
My email address at IBM has changed from arnez@linux.vnet.ibm.com to
arnez@linux.ibm.com.  Reflect that in the MAINTAINERS file.

gdb/ChangeLog:

	* MAINTAINERS: Update my email address.
2019-10-02 16:01:44 +02:00
Andrew Burgess df07e2c772 gdb: Remove a use of VEC from dwarf2read.{c,h}
Removes a use of VEC from dwarf2read.{c,h} and replaces it with
std::vector.  As far as possible this is a like for like replacement
with minimal refactoring.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* dwarf2read.c (struct type_unit_group) <tus>: Convert to
	std::vector.
	(build_type_psymtabs_reader): Update for std::vector.
	(build_type_psymtab_dependencies): Likewise.
	* dwarf2read.h: Remove use of DEF_VEC_P.
	(typedef sig_type_ptr): Delete.
2019-10-02 14:05:51 +01:00
Andrew Burgess 554ac434b0 gdb: Change a VEC to std::vector in btrace.{c,h}
Replace a VEC with a std::vector in btrace.h, and update btrace.c to
match.  It is worth noting that this code appears to be currently
untested by the GDB testsuite.  I've tried to do a like for like
replacement when moving to std::vector, with minimal refactoring to
try and avoid introducing any bugs.

As the new vector is inside a union I've currently used a pointer to
vector, which makes the code slightly uglier than it might otherwise
be, but again, due to lack of testing I'm reluctant to start
refactoring the code in a big way.

gdb/ChangeLog:

	* btrace.c (btrace_maint_clear): Update to handle change from VEC
	to std::vector.
	(btrace_maint_decode_pt): Likewise, and move allocation of the
	vector outside of the loop.
	(btrace_maint_update_packets): Update to handle change from VEC to
	std::vector.
	(btrace_maint_print_packets): Likewise.
	(maint_info_btrace_cmd): Likewise.
	* btrace.h: Remove use of DEF_VEC_O.
	(typedef btrace_pt_packet_s): Delete.
	(struct btrace_maint_info) <packets>: Change fromm VEC to
	std::vector.
	* gdbsupport/btrace-common.h: Remove 'vec.h' include.
2019-10-02 14:05:50 +01:00
Andrew Burgess 46f29a9a26 gdb: Remove a VEC from gdbsupport/btrace-common.h
Converts a VEC into a std::vector in gdbsupport/btrace-common.h.  This
commit just performs a mechanical conversion and doesn't do any
refactoring.  One consequence of this is that the std::vector must
actually be a pointer to std::vector as it is placed within a union.
It might be possible in future to refactor to a class hierarchy and
remove the need for a union, but I'd rather have that be a separate
change to make it easier to see the evolution of the code.

gdb/ChangeLog:

	* btrace.c (btrace_compute_ftrace_bts): Update for std::vector,
	make accesses into the vector constant references.
	(btrace_add_pc): Update for std::vector.
	(btrace_stitch_bts): Likewise.
	(parse_xml_btrace_block): Likewise.
	(btrace_maint_update_packets): Likewise.
	(btrace_maint_print_packets): Likewise.
	(maint_info_btrace_cmd): Likewise.
	* gdbsupport/btrace-common.c (btrace_data::fini): Update for
	std::vector.
	(btrace_data::empty): Likewise.
	(btrace_data_append): Likewise.
	* gdbsupport/btrace-common.h: Remove use of DEF_VEC_O.
	(typedef btrace_block_s): Delete.
	(struct btrace_block): Add constructor.
	(struct btrace_data_bts) <blocks>: Change to std::vector.
	* nat/linux-btrace.c (perf_event_read_bts): Update for
	std::vector.
	(linux_read_bts): Likewise.

gdb/gdbserver/ChangeLog:

	* linux-low.c (linux_low_read_btrace): Update for change to
	std::vector.
2019-10-02 14:05:49 +01:00
Tom Tromey d770d56f42 Use styled_string for "show logging filename"
This changes "show logging filename" to style its output.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* cli/cli-logging.c (show_logging_filename): Use styled_string.

gdb/testsuite/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Test "show logging filename".
2019-10-01 15:12:41 -06:00
Tom Tromey 9d636d67e0 Use styled_string in more places
This adds more uses of styled_string, changing gdb to style some
output that was previously left unstyled.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* stack.c (print_frame, info_frame_command_core): Use
	styled_string.
	* linux-thread-db.c (try_thread_db_load_1)
	(try_thread_db_load_from_pdir_1): Use styled_string.
	* auto-load.c (file_is_auto_load_safe, execute_script_contents)
	(auto_load_section_scripts, info_auto_load_local_gdbinit)
	(maybe_print_unsupported_script_warning)
	(maybe_print_script_not_found_warning): Use styled_string.
	* ada-lang.c (user_select_syms): Use styled_string.
2019-10-01 15:12:40 -06:00
Tom Tromey 7f6aba03b9 Introduce metadata style
This introduces a new "metadata" style and changes many places in gdb
to use it.  The idea here is to let the user distinguish gdb output
from output that (conceptually at least) comes directly from the
inferior.  The newly-styled category includes text that gdb
traditionally surrounds in "<...>", like "<unavailable>".

I only added a single test for this.  In many cases this output is
difficult to test.  Also, while developing this errors in the
implementation of the new printf formats showed up as regressions.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* p-lang.c (pascal_printstr): Use metadata style.
	* value.c (show_convenience): Use metadata style.
	* valprint.c (valprint_check_validity, val_print_optimized_out)
	(val_print_not_saved, val_print_unavailable)
	(val_print_invalid_address, generic_val_print, val_print)
	(value_check_printable, val_print_array_elements): Use metadata
	style.
	* ui-out.h (class ui_out) <field_fmt>: New overload.
	<do_field_fmt>: Add style parameter.
	* ui-out.c (ui_out::field_fmt): New overload.
	* typeprint.c (type_print_unknown_return_type)
	(val_print_not_allocated, val_print_not_associated): Use metadata
	style.
	* tui/tui-out.h (class tui_ui_out) <do_field_fmt>: Add style
	parameter.
	* tui/tui-out.c (tui_ui_out::do_field_fmt): Update.
	* tracepoint.c (tvariables_info_1): Use metadata style.
	* stack.c (print_frame_arg, print_frame_info, print_frame)
	(info_frame_command_core): Use metadata style.
	* skip.c (info_skip_command): Use metadata style.
	* rust-lang.c (rust_print_enum): Use metadata style.
	* python/py-prettyprint.c (print_stack_unless_memory_error): Use
	metadata style.
	* python/py-framefilter.c (py_print_single_arg): Use metadata
	style.
	* printcmd.c (do_one_display, print_variable_and_value): Use
	metadata style.
	* p-valprint.c (pascal_val_print)
	(pascal_object_print_value_fields): Use metadata style.
	* p-typeprint.c (pascal_type_print_base): Use metadata style.
	* mi/mi-out.h (class mi_ui_out) <do_field_fmt>: Add style
	parameter.
	* mi/mi-out.c (mi_ui_out::do_field_fmt): Update.
	* m2-valprint.c (m2_print_long_set): Use metadata style.
	* m2-typeprint.c (m2_print_type): Use metadata style.
	* infcmd.c (print_return_value_1): Use metadata style.
	* gnu-v3-abi.c (print_one_vtable): Use metadata style.
	* f-valprint.c (info_common_command_for_block): Use metadata
	style.
	* f-typeprint.c (f_type_print_base): Use metadata style.
	* expprint.c (print_subexp_standard): Use metadata style.
	* cp-valprint.c (cp_print_value_fields): Use metadata style.
	* cli/cli-style.h (class cli_style_option): Add constructor.
	(metadata_style): Declare.
	* cli/cli-style.c (metadata_style): New global.
	(_initialize_cli_style): Register metadata style.
	* cli-out.h (class cli_ui_out) <do_field_fmt>: Add style
	parameter.
	* cli-out.c (cli_ui_out::do_field_fmt): Update.
	* c-typeprint.c (c_type_print_base_struct_union)
	(c_type_print_base_1): Use metadata style.
	* breakpoint.c (watchpoint_value_print)
	(print_one_breakpoint_location): Use metadata style.
	* break-catch-syscall.c (print_one_catch_syscall): Use metadata
	style.
	* break-catch-sig.c (signal_catchpoint_print_one): Use metadata
	style.
	* ada-valprint.c (val_print_packed_array_elements, printstr)
	(print_field_values, ada_val_print_ref, ada_val_print): Use
	metadata style.
	* ada-typeprint.c (print_array_type, ada_print_type): Use metadata
	style.
	* ada-tasks.c (print_ada_task_info, info_task): Use metadata
	style.
	* ada-lang.c (user_select_syms): Use metadata style.

gdb/testsuite/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* lib/gdb-utils.exp (style): Handle "metadata" argument.
	* gdb.base/style.exp: Add metadata style test.
2019-10-01 15:12:40 -06:00
Tom Tromey 14309bb6bf Style "pwd" output
This changes the "pwd" command to style its output.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* cli/cli-cmds.c (pwd_command): Style output.

gdb/testsuite/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Test "pwd".
2019-10-01 15:12:39 -06:00
Pedro Alves 6a831f06e1 Use new %p format suffixes in gdb
This changes various spots in gdb to use the new %p format suffixes.

gdb/ChangeLog
2019-10-01  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* symtab.c (print_symbol_info): Use %ps.
	(print_msymbol_info): Use %ps.
	* symfile.c (symbol_file_add_with_addrs): Use %ps.
	* printcmd.c (print_variable_and_value): Use %ps.
	* macrocmd.c (show_pp_source_pos): Use %ps.
	* infrun.c (print_exited_reason): Use ui_out::message.
	* breakpoint.c (watchpoint_check, print_one_breakpoint_location)
	(describe_other_breakpoints): Use ui_out::message and new
	formats.
	(say_where): Use new formats.
	(bkpt_print_it, tracepoint_print_one_detail): Use ui_out::message
	and new formats.
2019-10-01 15:12:38 -06:00
Pedro Alves 2a3c1174c3 Introduce gdb-specific %p format suffixes
This introduces a few gdb-specific %p format suffixes.  This is useful
for emitting gdb-specific output in an ergonomic way.  It also yields
code that is more i18n-friendly.

The comment before ui_out::message explains the details.

Note that the tests had to change a little.  When using one of the gdb
printf functions with styling, there can be spurious style changes
emitted to the output.  This did not seem worthwhile to fix, as the
low-level output functions are rather spaghetti-ish already, and I
didn't want to make them even worse.

This change also necessitated adding support for "*" as precision and
width in format_pieces.  These are used in various spots in gdb, and
it seemed better to me to implement them than to remove the uses.

gdb/ChangeLog
2019-10-01  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* unittests/format_pieces-selftests.c: Add gdb_format parameter.
	(test_gdb_formats): New function.
	(run_tests): Call it.
	(test_format_specifier): Update.
	* utils.h (fputs_filtered): Update comment.
	(vfprintf_styled, vfprintf_styled_no_gdbfmt)
	(fputs_styled_unfiltered): Declare.
	* utils.c (fputs_styled_unfiltered): New function.
	(vfprintf_maybe_filtered): Add gdbfmt parameter.
	(vfprintf_filtered): Update.
	(vfprintf_unfiltered, vprintf_filtered): Update.
	(vfprintf_styled, vfprintf_styled_no_gdbfmt): New functions.
	* ui-out.h (enum ui_out_flag) <unfiltered_output,
	disallow_ui_out_field>: New constants.
	(enum class field_kind): New.
	(struct base_field_s, struct signed_field_s): New.
	(signed_field): New function.
	(struct string_field_s): New.
	(string_field): New function.
	(struct styled_string_s): New.
	(styled_string): New function.
	(class ui_out) <message>: Add comment.
	<vmessage, call_do_message>: New methods.
	<do_message>: Add style parameter.
	* ui-out.c (ui_out::call_do_message, ui_out::vmessage): New
	methods.
	(ui_out::message): Rewrite.
	* mi/mi-out.h (class mi_ui_out) <do_message>: Add style
	parameter.
	* mi/mi-out.c (mi_ui_out::do_message): Add style parameter.
	* gdbsupport/format.h (class format_pieces) <format_pieces>: Add
	gdb_extensions parameter.
	(class format_piece): Add parameter to constructor.
	(n_int_args): New field.
	* gdbsupport/format.c (format_pieces::format_pieces): Add
	gdb_extensions parameter.  Handle '*'.
	* cli-out.h (class cli_ui_out) <do_message>: Add style parameter.
	* cli-out.c (cli_ui_out::do_message): Add style parameter.  Call
	vfprintf_styled_no_gdbfmt.
	(cli_ui_out::do_field_string, cli_ui_out::do_spaces)
	(cli_ui_out::do_text, cli_ui_out::field_separator): Allow
	unfiltered output.
	* ui-style.h (struct ui_file_style) <ptr>: New method.

gdb/testsuite/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Update tests.
2019-10-01 15:12:38 -06:00
Tom Tromey 0dfe5bfbb7 Don't create empty literal pieces
I noticed that format_pieces can create an empty literal piece.
However, there's never a need for one, so this patch removes the
possibility.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* unittests/format_pieces-selftests.c: Update.  Add final format.
	* gdbsupport/format.c (format_pieces::format_pieces): Don't add
	empty literal pieces.
2019-10-01 15:12:37 -06:00
Tom Tromey e43b10e10e Remove the ui_out_style_kind enum
This removes the ui_out_style_kind enum, in favor of simply using
ui_file_style references.  This simplifies the code somewhat.

gdb/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* ui-out.h (enum class ui_out_style_kind): Remove.
	(class ui_out) <field_string, field_stsream, do_field_string>:
	Change type of "style".
	* ui-out.c (ui_out::field_core_addr, ui_out::field_stream)
	(ui_out::field_string): Update.
	* tui/tui-out.h (class tui_ui_out) <do_field_string>: Change type
	of "style".
	* tui/tui-out.c (tui_ui_out::do_field_string): Update.
	* tracepoint.c (print_one_static_tracepoint_marker): Update.
	* stack.c (print_frame_arg, print_frame_info, print_frame):
	Update.
	* source.c (print_source_lines_base): Update.
	* solib.c (info_sharedlibrary_command): Update.
	* skip.c (info_skip_command): Update.
	* record-btrace.c (btrace_call_history_src_line)
	(btrace_call_history): Update.
	* python/py-framefilter.c (py_print_frame): Update.
	* mi/mi-out.h (class mi_ui_out) <do_field_string>: Change type of
	"style".
	* mi/mi-out.c (mi_ui_out::do_table_header)
	(mi_ui_out::do_field_signed, mi_ui_out::do_field_unsigned)
	(mi_ui_out::do_field_string): Update.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Update.
	* cli-out.h (class cli_ui_out) <do_field_string>: Change type of
	"style".
	* cli-out.c (cli_ui_out::do_table_header)
	(cli_ui_out::do_field_signed, cli_ui_out::do_field_unsigned)
	(cli_ui_out::do_field_skip, cli_ui_out::do_field_string)
	(cli_ui_out::do_field_fmt): Update.
	* breakpoint.c (print_breakpoint_location): Update.
	(update_static_tracepoint): Update.
2019-10-01 15:12:37 -06:00
Andreas Arnez 53d666ecfb gdb/testsuite: Fix pretty-print.exp on big-endian platforms
The pretty-print test case fails on s390/s390x because it relies on a
little-endian representation of bit fields.  Little-endian architectures
typically allocate bit fields from least to most significant bit, but
big-endian architectures typically use the reverse order, allocating the
most significant bit first.  Thus the two bit fields in each of the test
case's unions overlap either in their lower or in their higher bits,
depending on the target's endianness:

    union {
      int three : 3;
      int four : 4;
    };

Now, when initializing 'three' with 3, 'four' will become 3 on little
endian targets, but 6 on big-endian targets, making it FAIL there.

Fix this by initializing the longer bit field instead and using an
all-ones bit pattern.  In this way the result does not depend on
endianness.  Use 'unsigned' instead of int for one of the bit fields in
each of the unions, to increase the variety of resulting values.

gdb/testsuite/ChangeLog:

	* gdb.base/pretty-print.c (struct s1_t): Change fields 'three' and
	'six' to unsigned.
	(s1): Initialize fields 'four' and 'six' instead of 'three' and
	'five'.  Use an all-ones bit pattern for each.
	* gdb.base/pretty-print.exp: Adjust expected output of "print s1"
	to its changed values.
2019-10-01 19:20:29 +02:00
Philippe Waroquiers cd7c32c36a Fix leak due to assigning a xstrdup-ed string to the std::string gdb_datadir
Valgrind reports the following leak:
==32623== 56 bytes in 1 blocks are definitely lost in loss record 1,099 of 6,654
==32623==    at 0x4835753: malloc (vg_replace_malloc.c:307)
==32623==    by 0x25CF67: xmalloc (alloc.c:60)
==32623==    by 0x65FBD9: xstrdup (xstrdup.c:34)
==32623==    by 0x413D9E: captured_main_1(captured_main_args*) (main.c:553)
==32623==    by 0x414FFA: captured_main (main.c:1172)
==32623==    by 0x414FFA: gdb_main(captured_main_args*) (main.c:1197)
==32623==    by 0x22531A: main (gdb.c:32)

Commit f2aec7f6d1 changed gdb_datadir to std::string.
So, xstrdup-ing the result of relocate_gdb_directory (returning a std::string)
is not needed and creates a leak.

Fix the leak by removing the xstrdup and the not needed c_str ().
Also removes a useless conversion of gdb_datadir to std::string.

gdb/ChangeLog
2019-10-01  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* main.c (relocate_gdbinit_path_maybe_in_datadir): Remove std::string
	conversion of gdb_datadir.
	(captured_main_1): Remove xstrdup when assigning to gdb_datadir,
	remove not needed c_str ().
2019-10-01 08:56:54 +02:00
Ali Tamur 8fe0f950f4 [PATCH v2 2/4] DWARF 5 support: Handle DW_FORM_strx
* Handle DW_FORM_strx forms everywhere.

Tested with CC=/usr/bin/gcc (version 8.3.0) against master branch (also with
-gsplit-dwarf and -gdwarf-4 flags) and there was no increase in the set of
tests that fails.

This is part of an effort to support DWARF 5 in gdb.

gdb/ChangeLog:

        * dwarf2read.c (skip_one_die): Handle DW_FORM_strx forms.
        (dwarf2_string_attr): Likewise.
2019-09-30 18:00:41 -07:00
Ali Tamur 5f48f8f3c3 Remove extra whitespaces at the end of lines.
gdb/ChangeLog:

	* dwarf2read.c (process_full_comp_unit): Remove whitespace at the EOL.
	(process_full_type_unit): Likewise.
	(dump_die_shallow): Likewise.
	(cu_debug_loc_section): Likewise.
2019-09-30 14:00:52 -07:00
Christian Biesinger 6fb08628e0 Use std::sort instead of qsort in minsyms.c
This has better typesafety and is also marginally faster (either
due to inlining or because it avoids indirection through a
function pointer).

Note that in this change:
-       return 1;               /* fn1 has no name, so it is "less".  */
+       return true;            /* fn1 has no name, so it is "less".  */
       else if (name1)          /* fn2 has no name, so it is "less".  */
-       return -1;
+       return false;
I am fairly sure the old code was wrong (ie. code didn't match the
comment and the comment seemed correct), so I fixed it.

gdb/ChangeLog:

2019-09-28  Christian Biesinger  <cbiesinger@google.com>

	* minsyms.c (compare_minimal_symbols): Rename to...
	(minimal_symbol_is_less_than): ...this, and adjust to STL
	conventions (return bool, take arguments as references)
	(minimal_symbol_reader::install): Call std::sort instead
	of qsort.
2019-09-30 13:32:32 -05:00
Tom Tromey 4a56a52007 Disable all warnings in gdb.rust/traits.rs
With rustc 1.37, I started seeing compiler warnings from the traits.rs
test case:

    warning: trait objects without an explicit `dyn` are deprecated

It seems to me that we generally do not want warnings in these test
cases.  At some point, we'll probably have to patch traits.rs to use
the "dyn" keyword; by that time I expect that all the Rust compilers
in common use will support it.  In the meantime it seemed simplest to
simply disable all warnings in this file.

gdb/testsuite/ChangeLog
2019-09-30  Tom Tromey  <tromey@adacore.com>

	* gdb.rust/traits.rs: Disable all warnings.
2019-09-30 10:34:36 -06:00
Christian Biesinger c7ee338a2d Improve some comments about msymbol handling
This just clarifies some comments about the hashtables involved
in msymbols.

gdb/ChangeLog:

2019-09-29  Christian Biesinger  <cbiesinger@google.com>

	* minsyms.h (msymbol_hash): Document that this is a case-insensitive
	hash and why.
	* objfiles.h (struct objfile_per_bfd_storage) <demangled_names_hash,
	msymbol_hash, msymbol_demangled_hash>: Improve comments.
2019-09-30 11:21:46 -05:00
Simon Marchi 703a86c2fa gdb: re-write add_psymbol_to_list doc, move it to header file
The comment above the add_psymbol_to_list function seems outdated and
misleading, here's an attempt at improving it.

gdb/ChangeLog:

	* psymtab.c (add_psymbol_to_list): Move comment to psympriv.h.
	* psympriv.h (add_psymbol_to_list): Move comment here and update
	it.
2019-09-30 11:49:57 -04:00
Tom de Vries 0df0352ad0 [gdb/contrib] cc-with-tweaks.sh: Create .dwz file in .tmp subdir
When running a test-case gdb.base/foo.exp with cc-with-dwz-m, a file
build/gdb/testsuite/outputs/gdb.base/foo/foo.dwz will be created, alongside
executable build/gdb/testsuite/outputs/gdb.base/foo/foo.

This can cause problems in f.i. test-cases that test file name completion.

Make these problems less likely by moving foo.dwz to a .tmp subdir:
build/gdb/testsuite/outputs/gdb.base/foo/.tmp/foo.dwz.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-09-29  Tom de Vries  <tdevries@suse.de>

	* contrib/cc-with-tweaks.sh (get_tmpdir): New function.
	Use $tmpdir/$(basename "$output_file").dwz instead of
	"${output_file}.dwz".

gdb/testsuite/ChangeLog:

2019-09-29  Tom de Vries  <tdevries@suse.de>

        * gdb.dwarf2/gdb-index.exp: Handle new location of .dwz file.
2019-09-29 23:58:21 +02:00
Tom de Vries 73d9a918c6 [gdb/testsuite] Make pass message unique in gdb-index.exp for cc-with-dwz-m
With cc-with-dwz-m, we get:
...
PASS: gdb.dwarf2/gdb-index.exp: objcopy
PASS: gdb.dwarf2/gdb-index.exp: objcopy
...

Make the pass message unique by using with_test_prefix:
...
PASS: gdb.dwarf2/gdb-index.exp: objcopy
PASS: gdb.dwarf2/gdb-index.exp: modify dwz file: objcopy
...

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-29  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/gdb-index.exp: Use with_test_prefix for second objcopy.
2019-09-29 23:51:50 +02:00
Simon Marchi ad75efa628 gdb: include gdbarch.h in hppa-linux-nat.c
hppa-linux-nat.c fails to build due to the gdbarch stuff not being
declared, for example:

    hppa-linux-nat.c: In function ‘void fetch_register(regcache*, int)’:
    hppa-linux-nat.c:230:7: error: ‘gdbarch_cannot_fetch_register’ was not declared in this scope
       if (gdbarch_cannot_fetch_register (gdbarch, regno))

Include gdbarch.h to fix it.

gdb/ChangeLog:

	PR gdb/25045
	* hppa-linux-nat.c: Include gdbarch.h.
2019-09-28 14:48:22 -04:00
Tom de Vries 060b3ab4ed [gdb/testsuite] Fix incomplete regexps in step-precsave.exp
The commit 68f7d34dd5 "[gdb/testsuite] Add KFAIL for missing support of
reverse-debugging of vmovd" rewrites a gdb_test into a gdb_test_multiple but
forgets to add the $gdb_prompt part in the regexp.

Add the missing parts of the regexps.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-27  Tom de Vries  <tdevries@suse.de>

	* gdb.reverse/step-precsave.exp: Add missing $gdb_prompt in regexps.
2019-09-27 17:04:59 +02:00
Tom de Vries 68f7d34dd5 [gdb/testsuite] Add KFAIL for missing support of reverse-debugging of vmovd
On my openSUSE Leap 15.1 system I run into:
...
(gdb) PASS: gdb.reverse/step-precsave.exp: turn on process record
break 76^M
Breakpoint 2 at 0x400654: file step-reverse.c, line 76.^M
(gdb) PASS: gdb.reverse/step-precsave.exp: breakpoint at end of main
continue^M
Continuing.^M
Process record does not support instruction 0xc5 at address 0x7ffff783fc70.^M
Process record: failed to record execution log.^M
^M
Program stopped.^M
0x00007ffff783fc70 in __memset_avx2_unaligned_erms () from /lib64/libc.so.6^M
(gdb) FAIL: gdb.reverse/step-precsave.exp: run to end of main
...

The problem is that the vmovd instruction is not supported in
reverse-debugging (PR record/23188).

Add a KFAIL for this PR.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-27  Tom de Vries  <tdevries@suse.de>

	PR record/23188
	* gdb.reverse/step-precsave.exp: Add kfail for PR record/23188.
2019-09-27 10:36:18 +02:00
Sergio Durigan Junior 50fa3001ce Revert "Improve ptrace-error detection on Linux targets"
This reverts commit 381beca614.

The patch hasn't been fully reviewed yet, and Pedro would like to see
more fixes.
2019-09-26 14:24:30 -04:00
Sergio Durigan Junior 381beca614 Improve ptrace-error detection on Linux targets
In Fedora GDB, we carry the following patch:

  8ac06474ff/f/gdb-attach-fail-reasons-5of5.patch

Its purpose is to try to detect a specific scenario where SELinux's
'deny_ptrace' option is enabled, which prevents GDB from ptrace'ing in
order to debug the inferior (PTRACE_ATTACH and PTRACE_TRACEME will
fail with EACCES in this case).

I like the idea of improving error detection and providing more
information to the user (a simple "Permission denied" can be really
frustrating), but I don't fully agree with the way the patch was
implemented: it makes GDB link against libselinux only for the sake of
consulting the 'deny_ptrace' setting, and then prints a warning if
ptrace failed and this setting is on.

My first thought (and attempt) was to make GDB print a generic warning
when a ptrace error happened; this message would just point the user
to our documentation, where she could find more information about
possible causes for the error (and try to diagnose/fix the problem).
This proved to be too simple, and I was convinced that it is actually
a good idea to go the extra kilometre and try to pinpoint the specific
problem (or problems) preventing ptrace from working, as well as
provide useful suggestions on how the user can fix things.

Here is the patch I came up with.  It implements a new function,
'linux_ptrace_restricted_fail_reason', which does a few things to
check what's wrong with ptrace:

  - It dlopen's "libselinux.so.1" and checks if the "deny_ptrace"
    option is enabled.

  - It reads the contents of "/proc/sys/kernel/yama/ptrace_scope" and
    checks if it's different than 0.

For each of these checks, if it succeeds, the user will see a message
informing about the restriction in place, and how it can be disabled.
For example, if "deny_ptrace" is enabled, the user will see:

  # gdb /usr/bin/true
  ...
  Starting program: /usr/bin/true
  warning: Could not trace the inferior process.
  warning: ptrace: Permission denied
  The SELinux 'deny_ptrace' option is enabled and preventing GDB
  from using 'ptrace'.  You can disable it by executing (as root):

    setsebool deny_ptrace off

  If you are debugging the inferior remotely, the ptrace restriction(s) need
  to be disabled in the target system (e.g., where GDBserver is running).
  During startup program exited with code 127.
  (gdb)

In case "/proc/sys/kernel/yama/ptrace_scope" is > 0:

  # gdb /usr/bin/true
  ...
  Starting program: /usr/bin/true
  warning: Could not trace the inferior process.
  warning: ptrace: Operation not permitted
  The Linux kernel's Yama ptrace scope is in effect, which can prevent
  GDB from using 'ptrace'.  You can disable it by executing (as root):

    echo 0 > /proc/sys/kernel/yama/ptrace_scope

  If you are debugging the inferior remotely, the ptrace restriction(s) need
  to be disabled in the target system (e.g., where GDBserver is running).
  During startup program exited with code 127.
  (gdb)

If both restrictions are enabled, both messages will show up.

This works for gdbserver as well, and actually fixes a latent bug I
found: when ptrace is restricted, gdbserver would hang due to an
unchecked ptrace call:

  # gdbserver :9988 /usr/bin/true
  gdbserver: linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: Operation not permitted
  gdbserver: linux_ptrace_test_ret_to_nx: status 256 is not WIFSTOPPED!
  gdbserver: linux_ptrace_test_ret_to_nx: failed to kill child pid 2668100 No such process
  [ Here you would have to issue a C-c ]

Now, you will see:

  # gdbserver :9988 /usr/bin/true
  gdbserver: linux_ptrace_test_ret_to_nx: Cannot PTRACE_TRACEME: Permission denied
  gdbserver: linux_ptrace_test_ret_to_nx: status 256 is not WIFSTOPPED!
  gdbserver: linux_ptrace_test_ret_to_nx: failed to kill child pid 2766868 No such process
  gdbserver: Could not trace the inferior process.
  gdbserver: ptrace: Permission denied
  The SELinux 'deny_ptrace' option is enabled and preventing GDB
  from using 'ptrace'.  You can disable it by executing (as root):

    setsebool deny_ptrace off

  If you are debugging the inferior remotely, the ptrace restriction(s) need
  to be disabled in the target system (e.g., where GDBserver is running).
  #

(I decided to keep all the other messages, even though I find them a
bit distracting).

If GDB can't determine the cause for the failure, it will still print
the generic error message which tells the user to check our
documentation:

  There might be restrictions preventing ptrace from working.  Please see
  the appendix "Linux kernel ptrace restrictions" in the GDB documentation
  for more details.
  If you are debugging the inferior remotely, the ptrace restriction(s) need
  to be disabled in the target system (e.g., where GDBserver is running).

This means that the patch expands our documentation and creates a new
appendix section named "Linux kernel ptrace restrictions", with
sub-sections for each possible restriction that might be in place.

Notice how, on every message, we instruct the user to "do the right
thing" if gdbserver is being used.  This is because if the user
started gdbserver *before* any ptrace restriction was in place, and
then, for some reason, one or more restrictions get enabled, then the
error message will be displayed both on gdbserver *and* on the
connected GDB.  Since the user will be piloting GDB, it's important to
explicitly say that the ptrace restrictions are enabled in the target,
where gdbserver is running.

The current list of possible restrictions is:

  - SELinux's 'deny_ptrace' option (detected).

  - YAMA's /proc/sys/kernel/yama/ptrace_scope setting (detected).

  - seccomp on Docker containers (I couldn't find how to detect).

It's important to mention that all of this is Linux-specific; as far
as I know, SELinux, YAMA and seccomp are Linux-only features.

I tested this patch locally, on my Fedora 30 machine (actually, a
Fedora Rawhide VM), but I'm not proposing a testcase for it because of
the difficulty of writing one.

WDYT?

gdb/doc/ChangeLog:
2019-09-26  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (Linux kernel ptrace restrictions): New appendix
	section.

gdb/ChangeLog:
2019-09-26  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdbsupport/gdb-dlfcn.h (gdb_dlopen): Update comment and
	mention that the function throws an error.
	* inf-ptrace.c (default_inf_ptrace_me_fail_reason): New
	function.
	(inf_ptrace_me_fail_reason): New variable.
	(inf_ptrace_me): Update call to 'trace_start_error_with_name'.
	* inf-ptrace.h (inf_ptrace_me_fail_reason): New variable.
	* linux-nat.c (attach_proc_task_lwp_callback): Call
	'linux_ptrace_attach_fail_reason_lwp'.
	(linux_nat_target::attach): Update call to
	'linux_ptrace_attach_fail_reason'.
	(_initialize_linux_nat): Set 'inf_ptrace_me_fail_reason'.
	* nat/fork-inferior.c (trace_start_error_with_name): Add
	optional 'append' argument.
	* nat/fork-inferior.h (trace_start_error_with_name): Update
	prototype.
	* nat/linux-ptrace.c: Include "gdbsupport/gdb-dlfcn.h",
	"gdbsupport/filestuff.h" and "nat/fork-inferior.h".
	(selinux_ftype): New typedef.
	(linux_ptrace_restricted_fail_reason): New function.
	(linux_ptrace_attach_fail_reason_1): New function.
	(linux_ptrace_attach_fail_reason): Change first argument type
	from 'ptid_t' to 'pid_t'.  Call
	'linux_ptrace_attach_fail_reason_1' and
	'linux_ptrace_restricted_fail_reason'.
	(linux_ptrace_attach_fail_reason_lwp): New function.
	(linux_ptrace_me_fail_reason): New function.
	(errno_pipe): New variable.
	(linux_fork_to_function): Initialize pipe before forking.
	(linux_child_function): Deal with errno-passing from child.
	Handle ptrace error.
	(linux_check_child_ptrace_errno): New function.
	(linux_check_child_ptrace_errno): Call
	'linux_check_child_ptrace_errno'.
	* nat/linux-ptrace.h (linux_ptrace_attach_fail_reason): Update
	prototype.
	(linux_ptrace_attach_fail_reason_lwp): New prototype.
	(linux_ptrace_me_fail_reason): New prototype.
	* remote.c (extended_remote_target::attach): Handle error
	message passed by the server when attach fails.

gdb/gdbserver/ChangeLog:
2019-09-26  Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* linux-low.c (linux_ptrace_fun): Call
	'linux_ptrace_me_fail_reason'.
	(attach_proc_task_lwp_callback): Call
	'linux_ptrace_attach_fail_reason_lwp'.
	(linux_attach): Call 'linux_ptrace_attach_fail_reason'.
	* server.c (handle_v_attach): Use try..catch when calling
	'attach_inferior', and send an error message to the client
	when needed.
	* thread-db.c (attach_thread): Call
	'linux_ptrace_attach_fail_reason_lwp'.
2019-09-26 13:48:58 -04:00
Christian Biesinger ececd218c5 Convert symtab.h function signatures to use bool instead of int
gdb/ChangeLog:

2019-09-26  Christian Biesinger  <cbiesinger@google.com>

	* blockframe.c (find_pc_partial_function): Change return type to bool.
	* elfread.c (elf_gnu_ifunc_resolve_name): Likewise.
	* minsyms.c (in_gnu_ifunc_stub): Likewise.
	(stub_gnu_ifunc_resolve_name): Likewise.
	* symtab.c (compare_filenames_for_search): Likewise.
	(compare_glob_filenames_for_search): Likewise.
	(matching_obj_sections): Likewise.
	(symbol_matches_domain): Likewise.
	(find_line_symtab): Change out param EXACT_MATCH to bool *.
	(find_line_pc): Change return type to bool.
	(find_line_pc_range): Likewise.
	(producer_is_realview): Likewise.
	* symtab.h (symbol_matches_domain): Likewise.
	(find_pc_partial_function): Likewise.
	(find_pc_line_pc_range): Likewise.
	(in_gnu_ifunc_stub): Likewise.
	(struct gnu_ifunc_fns) <gnu_ifunc_resolve_name>: Likewise.
	(find_line_pc): Likewise.
	(find_line_pc_range): Likewise.
	(matching_obj_sections): Likewise.
	(find_line_symtab): Change out parameter to bool.
	(producer_is_realview): Change return type to bool.
	(compare_filenames_for_search): Likewise.
	(compare_glob_filenames_for_search): Likewise.
2019-09-26 11:36:40 -05:00
Tom Tromey 27a900b865 Remove gdb_usleep.c
I noticed that gdb_usleep is unused, so this patch removes it.

gdb/ChangeLog
2019-09-26  Tom Tromey  <tom@tromey.com>

	* Makefile.in (COMMON_SFILES): Remove gdb_usleep.c.
	(HFILES_NO_SRCDIR): Remove gdb_usleep.h.
	* gdb_usleep.h: Remove.
	* gdb_usleep.c: Remove.
	* utils.c: Don't include gdb_usleep.h.
2019-09-26 08:43:15 -06:00
Tom Tromey 5d63b30afa Do not expose stub types to Python
dwarf2read.c will create stub types for Ada "Taft Amendment" types.
These stub types can currently be exposed to Python code, where they
show up as TYPE_CODE_VOID types (but that, mysteriously, can sometimes
be used in other ways).

While it's possible to work with such types by using strip_typedefs,
this seemed unpleasant to me.  This patch takes another approach
instead, which is to try not to expose stub types to Python users.

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

	* python/py-type.c (type_to_type_object): Call check_typedef
	for stub types.

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

	* gdb.ada/py_taft.exp: New file.
	* gdb.ada/py_taft/main.adb: New file.
	* gdb.ada/py_taft/pkg.adb: New file.
	* gdb.ada/py_taft/pkg.ads: New file.
2019-09-26 08:26:12 -06:00
Tom Tromey 12904d3729 Remove initialize_utils
initialize_utils only registers some commands, so it isn't necessary
to run it at any particular time during startup.  This patch removes
it and merges its contents into _initialize_utils.

Tested by the buildbot.

gdb/ChangeLog
2019-09-26  Tom Tromey  <tom@tromey.com>

	* utils.h (initialize_utils): Don't declare.
	* top.c (gdb_init): Don't call initialize_utils.
	* utils.c (initialize_utils): Remove.  Move contents...
	(_initialize_utils): ... here.
2019-09-26 07:35:00 -06:00
Tom Tromey 858f25f0dd Remove make_hex_string
I noticed that make_hex_string does essentially the same thing as
bin2hex, and furthermore is only called in a single spot.  This patch
removes make_hex_string.

Tested by the builtbot.

gdb/ChangeLog
2019-09-25  Tom Tromey  <tom@tromey.com>

	* python/py-objfile.c (objfpy_get_build_id): Use bin2hex.
	* utils.h (make_hex_string): Don't declare.
	* utils.c (make_hex_string): Remove.
2019-09-25 09:37:56 -06:00
Tom de Vries 3d4352200e [gdb/tdep] Handle mxcsr kernel bug on Intel Skylake CPUs
On my openSUSE Leap 15.1 x86_64 Skylake system with the default (4.12) kernel,
I run into:
...
FAIL: gdb.base/gcore.exp: corefile restored all registers
...

The problem is that there's a difference in the mxcsr register value before
and after the gcore command:
...
- mxcsr          0x0                 [ ]
+ mxcsr          0x400440            [ DAZ OM ]
...

This can be traced back to amd64_linux_nat_target::fetch_registers, where
xstateregs is partially initialized by the ptrace call:
...
          char xstateregs[X86_XSTATE_MAX_SIZE];
          struct iovec iov;

          amd64_collect_xsave (regcache, -1, xstateregs, 0);
          iov.iov_base = xstateregs;
          iov.iov_len = sizeof (xstateregs);
          if (ptrace (PTRACE_GETREGSET, tid,
                      (unsigned int) NT_X86_XSTATE, (long) &iov) < 0)
            perror_with_name (_("Couldn't get extended state status"));

          amd64_supply_xsave (regcache, -1, xstateregs);
...
after which amd64_supply_xsave is called.

The amd64_supply_xsave call is supposed to only use initialized parts of
xstateregs, but due to a kernel bug on intel skylake (fixed from 4.14 onwards
by commit 0852b374173b "x86/fpu: Add FPU state copying quirk to handle XRSTOR
failure on Intel Skylake CPUs") it can happen that the mxcsr part of
xstateregs is not initialized, while amd64_supply_xsave expects it to be
initialized, which explains the FAIL mentioned above.

Fix the undetermined behaviour by initializing xstateregs before calling
ptrace, which makes sure we get a 0x0 for mxcsr when this kernel bug occurs,
and which also happens to fix the FAIL.

Furthermore, add an xfail for this FAIL which triggers the same kernel bug:
...
FAIL: gdb.arch/amd64-init-x87-values.exp: check_setting_mxcsr_before_enable: \
  check new value of MXCSR is still in place
...

Both FAILs pass when using a 5.3 kernel instead on the system mentioned above.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-09-24  Tom de Vries  <tdevries@suse.de>

	PR gdb/23815
	* amd64-linux-nat.c (amd64_linux_nat_target::fetch_registers):
	Initialize xstateregs before ptrace PTRACE_GETREGSET call.

gdb/testsuite/ChangeLog:

2019-09-24  Tom de Vries  <tdevries@suse.de>

	PR gdb/24598
	* gdb.arch/amd64-init-x87-values.exp: Add xfail.
2019-09-24 23:38:49 +02:00
Dimitar Dimitrov ddd44b7053 sim: Add PRU simulator port
A simulator port for the TI PRU I/O processor.

v1: https://sourceware.org/ml/gdb-patches/2016-12/msg00143.html
v2: https://sourceware.org/ml/gdb-patches/2017-02/msg00397.html
v3: https://sourceware.org/ml/gdb-patches/2017-02/msg00516.html
v4: https://sourceware.org/ml/gdb-patches/2018-06/msg00484.html
v5: https://sourceware.org/ml/gdb-patches/2019-08/msg00584.html
v6: https://sourceware.org/ml/gdb-patches/2019-09/msg00036.html

gdb/ChangeLog:

	* NEWS: Mention new simulator port for PRU.

sim/ChangeLog:

	* MAINTAINERS: Add myself as PRU maintainer.
	* configure: Regenerated.
	* configure.tgt: Add PRU.

sim/common/ChangeLog:

	* gennltvals.sh: Add PRU libgloss target.
	* nltvals.def: Regenerate from the latest libgloss sources.

sim/pru/ChangeLog:

	* Makefile.in: New file.
	* aclocal.m4: Regenerated.
	* config.in: Regenerated.
	* configure: Regenerated.
	* configure.ac: New file.
	* interp.c: New file.
	* pru.h: New file.
	* pru.isa: New file.
	* sim-main.h: New file.
2019-09-23 22:11:02 +01:00
Christian Biesinger f945dedfd3 Make ada_decode not use a static buffer
This makes it safer to use in general, and also allows using it on a
background thread in the future.

Inspired by tromey's patch at:
1226cbdfa4
(however, implemented in a different way)

gdb/ChangeLog:

2019-09-23  Christian Biesinger  <cbiesinger@google.com>

	* ada-exp.y (write_object_remaining): Update.
	* ada-lang.c (ada_decode): Return a std::string instead of a char*
	and eliminate the static buffer.
	(ada_decode_symbol): Update.
	(ada_la_decode): Update.
	(ada_sniff_from_mangled_name): Update.
	(is_valid_name_for_wild_match): Update.
	(ada_lookup_name_info::matches): Update and simplify.
	(name_matches_regex): Update.
	(ada_add_global_exceptions): Update.
	* ada-lang.h (ada_decode): Update signature.
	* ada-varobj.c (ada_varobj_describe_simple_array_child): Update.
	* dwarf-index-write.c (debug_names::insert): Update.
2019-09-23 13:36:34 -05:00
Tom de Vries 77d036789a [gdb/testsuite] Allow some tests in gdb.base/restore.exp to be unsupported
We currently run into:
...
248       n = callee1 (n + l5);
(gdb) PASS: gdb.base/restore.exp: caller5 calls callee1; return callee now
print l1
$51 = <optimized out>
(gdb) FAIL: gdb.base/restore.exp: caller5 calls callee1; return restored l1 \
  to 32492
...

The problem is that we try to access the value of l1 in function caller5, but
variable l1 has no DW_AT_location attribute.  Since l1 is declared using the
register keyword, it's valid for gcc to emit no DW_AT_location at -O0.

Change the FAIL into an UNSUPPORTED.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-22  Tom de Vries  <tdevries@suse.de>

	* gdb.base/restore.exp: Allow register variables to be optimized out at
	-O0.
2019-09-22 06:14:29 +02:00
Simon Marchi 7ab78ccbbb gdb: fix formatting in solib-svr4.c
gdb/ChangeLog:

	* solib-svr4.c (svr4_iterate_over_objfiles_in_search_order): Fix
	formatting.
2019-09-21 22:13:49 -04:00
Simon Marchi 4c1d86d9a8 gdb: make watchpoint::val_valid a bool
gdb/ChangeLog:

	* breakpoint.h (struct watchpoint) <val_valid>: Change type to
	bool.
	* breakpoint.c (update_watchpoint): Assign false instead of 0,
	true instead of 1.
	(breakpoint_init_inferior): Likewise.
	(watchpoint_check): Likewise.
	(watch_command_1): Likewise.
	(invalidate_bp_value_on_memory_change): Likewise.
2019-09-21 20:03:08 -04:00
Simon Marchi 9252448ba9 gdb: change "nonzero" to "true" in comments
These int fields have been converted to bool, so their doc should say
"true" and not "nonzero".

gdb/ChangeLog:

	* breakpoint.h (bp_location) <inserted, permanent, duplicate>:
	Change "nonzero" to "true" in documentation.
2019-09-21 19:47:22 -04:00
Christian Biesinger 626ca2c06f Replace solib_global_lookup with gdbarch_iterate_over_objfiles_in_search_order
All implementations of either function use it for the same purpose (except
Darwin, which is a no-op): to prefer a symbol in the current objfile over
symbols with the same name in other objfiles. There does not seem to be a
reason to have both mechanisms for that purpose.

gdb/ChangeLog:

2019-09-20  Christian Biesinger  <cbiesinger@google.com>

	* solib-darwin.c (darwin_lookup_lib_symbol): Remove.
	(_initialize_darwin_solib): Don't set
	darwin_so_ops.lookup_lib_global_symbol.
	* solib-svr4.c (set_solib_svr4_fetch_link_map_offsets): Call
	set_gdbarch_iterate_over_objfiles_in_search_order.
	(elf_lookup_lib_symbol): Rename to...
	(svr4_iterate_over_objfiles_in_search_order): this, and update
	to iterate semantics.
	(_initialize_svr4_solib): Don't set lookup_lib_global_symbol.
	* solib.c (solib_global_lookup): Remove.
	* solist.h (struct target_so_ops): Remove lookup_lib_global_symbol.
	(solib_global_lookup): Remove.
	* symtab.c (lookup_global_or_static_symbol): Remove call to
	solib_global_lookup.
2019-09-20 21:09:15 -05:00
Christian Biesinger f9d949fb7b Move declarations of debug_threads and using_threads to header
Instead of declaring debug_threads and using_threads in several
.c files, declare them in debug.h.

gdb/gdbserver/ChangeLog:

2019-09-20  Christian Biesinger  <cbiesinger@google.com>

	* debug.c (debug_threads): Remove comment in favor of the header.
	* debug.h (using_threads): Add declaration.
	(debug_threads): Add comment.
	* linux-aarch64-low.c: Include debug.h and remove declaration of
	debug_threads.
	* nto-low.c: Likewise.
	* remote-utils.c: Likewise.
	* thread-db.c: Likewise.
2019-09-21 11:00:50 +09:00
Joel Brobecker 5a3a0d6304 gdb/NEWS: Move entries about MI v3 and multi-loc breakpoints after GDB 8.3
This is a followup on the following commit...

    commit b4be1b0648
    Date:   Wed Mar 13 15:13:03 2019 -0400
    Subject: Fix MI output for multi-location breakpoints

... which mistakenly added NEWS entries in the "in gdb-8.3" section,
rather than in the "since gdb-8.3" one.

gdb/ChangeLog:

	* NEWS: Move entries about default MI version now being
        version 3, and about the GDB/MI fix for multi-location
        breakpoints to the "since GDB 8.3" section.
2019-09-20 16:23:15 -07:00
Joel Brobecker ffea1427a7 Document the GDB 8.3.1 release in gdb/ChangeLog
gdb/ChangeLog:

	GDB 8.3.1 released.
2019-09-20 15:27:43 -07:00
Ulrich Weigand abf516c693 Remove Cell Broadband Engine debugging support
This patch implements removal of Cell/B.E. support, including
- Support for the spu-*-* target
- Support for native stand-alone SPU debugging
- Support for integrated debugging of combined PPU/SPU applications
- Remote debugging (gdbserver) support for all the above.

The patch also removes the TARGET_OBJECT_SPU target object type,
as this is available only on Cell/B.E. targets, including
- Native Linux support
- Core file support (including core file generation)
- Remote target support, including removal of the qXfer:spu:read
  and qXfer:spu:write remote protocal packets and associated
  support in gdbserver.

gdb/ChangeLog
2019-09-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* NEWS: Mention that Cell/B.E. debugging support was removed.
	* MAINTAINERS: Remove spu target.

	* config/djgpp/fnchange.lst: Remove entries for removed files.

	* Makefile.in (ALL_TARGET_OBS): Remove solib-spu.o,
	spu-multiarch.o, and spu-tdep.o.
	(HFILES_NO_SRCDIR): Remove solib-spu.h and spu-tdep.h.
	(ALLDEPFILES): Remove solib-spu.c, spu-linux-nat.c,
	spu-multiarch.c, and spu-tdep.c.
	* spu-linux-nat.c: Remove file.
	* spu-multiarch.c: Remove file.
	* spu-tdep.c: Remove file.
	* spu-tdep.h: Remove file.
	* solib-spu.c: Remove file.
	* solib-spu.h: Remove file.

	* configure.host (powerpc64*-*-linux*): Remove Cell/B.E. support.
	* configure.nat (spu-linux): Remove.
	* configure.tgt (powerpc*-*-linux*): Remove solib-spu.o and
	solib-multiarch.o from gdb_target_obs.
	(spu*-*-*): Remove.

	* arch/ppc-linux-common.h (struct ppc_linux_features): Remove "cell"
	feature flag.
	(ppc_linux_no_features): Update.
	* arch/ppc-linux-common.c (ppc_linux_match_description): Remove
	Cell/B.E. support.
	* arch/ppc-linux-tdesc.h (tdesc_powerpc_cell32l): Remove declaration.
	(tdesc_powerpc_cell64l): Likewise.
	* nat/ppc-linux.h (PPC_FEATURE_CELL): Remove.
	* ppc-linux-nat.c (ppc_linux_nat_target::read_description): Remove
	Cell/B.E. support.
	* ppc-linux-tdep.h: Do not include "solib-spu.h" or "spu-tdep.h".
	Do not include "features/rs6000/powerpc-cell32l.c" or
	"features/rs6000/powerpc-cell64l.c".
	(ppc_linux_spu_section): Remove.
	(ppc_linux_core_read_description): Remove Cell/B.E. support.
	(spe_context_objfile, spe_context_lm_addr, spe_context_offset,
	spe_context_cache_ptid, spe_context_cache_ptid): Remove.
	(ppc_linux_spe_context_lookup): Remove.
	(ppc_linux_spe_context_inferior_created): Remove.
	(ppc_linux_spe_context_solib_loaded): Remove.
	(ppc_linux_spe_context_solib_unloaded): Remove.
	(ppc_linux_spe_context): Remove.
	(struct ppu2spu_cache): Remove.
	(ppu2spu_prev_arch, ppu2spu_this_id, ppu2spu_prev_register): Remove.
	(struct ppu2spu_data): Remove.
	(ppu2spu_unwind_register, ppu2spu_sniffer, ppu2spu_dealloc_cache,
	ppu2spu_unwind): Remove.
	(ppc_linux_init_abi): Remove Cell/B.E. support.
	* rs6000-tdep.h (rs6000_gdbarch_init): Remove Cell/B.E. support.

	* features/Makefile (rs6000/powerpc-cell32l-expedite): Remove.
	(rs6000/powerpc-cell64l-expedite): Likewise
	(WHICH): Remove rs6000/powerpc-cell32l and rs6000/powerpc-cell64l.
	(XMLTOC): Remove rs6000/powerpc-cell32l.xml and
	rs6000/powerpc-cell64l.xml.
	* features/rs6000/powerpc-cell32l.xml: Remove.
	* features/rs6000/powerpc-cell64l.xml: Likewise.
	* features/rs6000/powerpc-cell32l.c: Remove generated file.
	* features/rs6000/powerpc-cell64l.c: Likewise.
	* regformats/rs6000/powerpc-cell32l.dat: Remove generated file.
	* regformats/rs6000/powerpc-cell64l.dat: Likewise.
	* regformats/reg-spu.dat: Remove.

	* target.h (enum target_object): Remove TARGET_OBJECT_SPU.
	* corelow.c (struct spuid_list): Remove.
	(add_to_spuid_list): Remove.
	(core_target::xfer_partial): Remove support for TARGET_OBJECT_SPU.
	* remote.c (PACKET_qXfer_spu_read, PACKET_qXfer_spu_write): Remove.
	(remote_protocol_features): Remove associated entries.
	(_initialize_remote): No longer initialize them.
	(remote_target::xfer_partial): Remove support for TARGET_OBJECT_SPU.
	* linux-nat.c (SPUFS_MAGIC): Remove.
	(linux_proc_xfer_spu): Remove.
	(spu_enumerate_spu_ids): Remove.
	(linux_nat_target::xfer_partial): Remove support for TARGET_OBJECT_SPU.
	* linux-tdep.c (-linux_spu_make_corefile_notes): Remove.
	(linux_make_corefile_notes): No longer call it.

	* regcache.c (cooked_read_test): Remove bfd_arch_spu special case.
	(cooked_write_test): Likewise.

gdb/doc/ChangeLog
2019-09-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* doc/gdb.texinfo (Remote Configuration): Remove documentation for
	qXfer:spu:read and qXfer:spu:write.
	(General Query Packets): Likewise.
	(Cell Broadband Engine SPU architecture): Remove subsection.

gdb/gdbserver/ChangeLog
2019-09-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* configure.srv (ipa_ppc_linux_regobj): Remove powerpc-cell32l-ipa.o
	and powerpc-cell64l-ipa.o.
	(powerpc*-*-linux*): Remove powerpc-cell32l.o and powerpc-cell64l.o
	from srv_regobj.  Remove rs6000/powerpc-cell32l.xml and
	rs6000/powerpc-cell64l.xml from srv_xmlfiles.
	(spu*-*-*): Remove.

	* spu-low.c: Remove file.

	* linux-ppc-low.c (INSTR_SC, NR_spu_run): Remove.
	(parse_spufs_run): Remove.
	(ppc_get_pc): Remove Cell/B.E. support.
	(ppc_set_pc): Likewise.
	(ppc_breakpoint_at): Likewise.
	(ppc_arch_setup): Likewise.
	(ppc_get_ipa_tdesc_idx): Do not handle tdesc_powerpc_cell64l or
	tdesc_powerpc_cell32l.
	(initialize_low_arch): Do not call init_registers_powerpc_cell64l
	or init_registers_powerpc_cell32l.
	* linux-ppc-ipa.c (get_ipa_tdesc): Do not handle PPC_TDESC_CELL.
	(initialize_low_tracepoint): Do not call init_registers_powerpc_cell64l
	or init_registers_powerpc_cell32l.
	* linux-ppc-tdesc-init.h (PPC_TDESC_CELL): Mark as unused.
	(init_registers_powerpc_cell32l): Remove prototype.
	(init_registers_powerpc_cell64l): Likewise.

	* target.h (struct target_ops): Remove qxfer_spu member.
	* server.c (handle_qxfer_spu): Remove.
	(qxfer_packets): Remove entry for "spu".
	(handle_query): No longer support qXfer:spu:read or qXfer:spu:write.
	* linux-low.c (SPUFS_MAGIC): Remove.
	(spu_enumerate_spu_ids): Remove.
	(linux_qxfer_spu): Remove.
	(linux_target_ops): Remove qxfer_spu member.
	* lynx-low.c (lynx_target_ops): Remove qxfer_spu member.
	* nto-low.c (nto_target_ops): Remove qxfer_spu member.
	* win32-low.c (win32_target_ops): Remove qxfer_spu member.

gdb/testsuite/ChangeLog
2019-09-20  Ulrich Weigand  <uweigand@de.ibm.com>

	* gdb.arch/spu-info.exp: Remove file.
	* gdb.arch/spu-info.c: Remove file.
	* gdb.arch/spu-ls.exp: Remove file.
	* gdb.arch/spu-ls.c: Remove file.

	* gdb.asm/asm-source.exp: Remove support for spu*-*-*.
	* gdb.asm/spu.inc: Remove file.

	* gdb.base/dump.exp: Remove support for spu*-*-*.
	* gdb.base/stack-checking.exp: Likewise.
	* gdb.base/overlays.exp: Likewise.
	* gdb.base/ovlymgr.c: Likewise.
	* gdb.base/spu.ld: Remove file.

	* gdb.cp/bs15503.exp: Remove support for spu*-*-*.
	* gdb.cp/cpexprs.exp: Likewise.
	* gdb.cp/exception.exp: Likewise.
	* gdb.cp/gdb2495.exp: Likewise.
	* gdb.cp/mb-templates.exp: Likewise.
	* gdb.cp/pr9167.exp: Likewise.
	* gdb.cp/userdef.exp: Likewise.

	* gdb.xml/tdesc-regs.exp: Remove support for spu*-*-*.

	* gdb.cell: Remove directory.
	* lib/cell.exp: Remove file.
2019-09-20 23:06:57 +02:00
Tom Tromey 78e8cb91cd Change TUI window commands to be case-sensitive
The TUI window-related commands like "focus" are case insensitive.
This is not the norm in gdb, and I don't see a good reason to have it
here.  This patch changes the TUI to be case sensitive, like the rest
of gdb.

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

	* NEWS: Mention case-sensitivity of TUI commands.
	* tui/tui-win.c (tui_set_focus_command): Now case-sensitive.
	(tui_set_win_height_command, parse_scrolling_args): Likewise.
	* tui/tui-layout.c (tui_layout_command): Now case-sensitive.
2019-09-20 13:49:12 -06:00
Tom Tromey f074b67ec8 Use make_unique_xstrdup in TUI
This changes a couple of spots in the TUI to use make_unique_xstrdup.
This simplifies the code slightly.

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

	* tui/tui-source.c (tui_source_window::set_contents): Use
	make_unique_xstrdup.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Use
	make_unique_xstrdup.
2019-09-20 13:49:12 -06:00
Tom Tromey 63c4bf1922 Remove separator comments from TUI
This removes various separator comments from the TUI.  These aren't
used elsewhere in gdb, and they were incorrect in some cases as well.

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

	* tui/tui-data.c: Remove separator comments.
	* tui/tui-layout.c: Remove separator comments.
	* tui/tui-win.c: Remove separator comments.
	* tui/tui-wingeneral.c: Remove separator comments.
2019-09-20 13:49:11 -06:00
Tom Tromey 43df9b2fcc Remove strcat_to_buf
An earlier patch in the series removed the last call to strcat_to_buf,
so this patch removes the function entirely.

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

	* tui/tui.h (strcat_to_buf): Don't declare.
	* tui/tui.c (strcat_to_buf): Remove.
2019-09-20 13:49:11 -06:00
Tom Tromey 7226433c44 Rename a private data member in tui_source_window
This renames tui_source_window::fullname to add the "m_" prefix, as it
is a private data member.

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

	* tui/tui-source.h (struct tui_source_window) <m_fullname>: Rename
	from "fullname".
	* tui/tui-source.c (tui_source_window::set_contents)
	(tui_source_window::location_matches_p)
	(tui_source_window::maybe_update): Update.
2019-09-20 13:49:11 -06:00
Tom Tromey 80df33379e Rename private data members of tui_data_window
As Pedro suggested, this patch renames the private data members of
tui_data_window to use the "m_" prefix.

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

	* tui/tui-regs.h (struct tui_data_window) <get_current_group>:
	Update.
	<m_regs_content, m_regs_column_count, m_current_group>: Add "m_"
	prefix.
	* tui/tui-regs.c (tui_data_window::last_regs_line_no)
	(tui_data_window::line_from_reg_element_no)
	(tui_data_window::first_reg_element_no_inline)
	(tui_data_window::show_registers)
	(tui_data_window::show_register_group)
	(tui_data_window::display_registers_from)
	(tui_data_window::display_registers_from_line)
	(tui_data_window::first_data_item_displayed)
	(tui_data_window::delete_data_content_windows)
	(tui_data_window::erase_data_content)
	(tui_data_window::do_scroll_vertical)
	(tui_data_window::refresh_window)
	(tui_data_window::check_register_values): Update.
2019-09-20 13:49:10 -06:00
Tom Tromey 9923f347c4 Change members of tui_locator_window to std::string
This changes two members of tui_locator_window to have type
std::string.  This removes a static limit.

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

	* tui/tui-stack.h (MAX_LOCATOR_ELEMENT_LEN): Remove define.
	(struct tui_locator_window) <full_name, proc_name>: Now
	std::string.
	* tui/tui-stack.c (tui_locator_window::make_status_line)
	(tui_locator_window::set_locator_fullname)
	(tui_locator_window::set_locator_info): Update.
	* tui/tui-source.c (tui_source_window::set_contents)
	(tui_source_window::showing_source_p): Update.
2019-09-20 13:49:10 -06:00
Tom Tromey b76251abaf Remove a call to tui_locator_win_info_ptr
Commit e594a5d1 ("Turn two locator functions into methods") turned
set_locator_fullname into a method on tui_locator_window.  I missed it
at the time, but this change allows for the removal of a call to
tui_locator_win_info_ptr.

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

	* tui/tui-stack.c (tui_locator_window::set_locator_fullname):
	Don't call tui_locator_win_info_ptr.
2019-09-20 13:49:09 -06:00
Tom Tromey 0891be0835 Don't call refresh in tui_resize_all
There's no reason to call refresh in tui_resize_all.  This call
flushes the curses window contents to the terminal -- but, because
we're about the resize all the windows, we're going to be sending more
data to the terminal momentarily.  This patch removes the call.

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

	* tui/tui-win.c (tui_resize_all): Don't call refresh.
2019-09-20 13:49:09 -06:00
Tom Tromey 1b935acf7e Set TUI locator height to 1
The TUI has long had code to resize the locator, using 2 as the
height.  However the code has "1" in a comment, like:

    locator->resize (2 /* 1 */ ,

This patch fixes the resizing code to set the height to 1.  Doing this
revealed what was probably the reason for setting the height to 2 in
the first place: this caused the locator window to scroll.  However,
this is easily handled by calling scrollok on the locator window.

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

	* tui/tui-win.c (tui_resize_all, tui_adjust_win_heights): Use 1 as
	height for locator.
	* tui/tui-stack.c (tui_locator_window::rerender): Call scrollok.
	* tui/tui-layout.c (show_source_disasm_command, show_data)
	(show_source_or_disasm_and_command): Use 1 as height for locator.
2019-09-20 13:49:08 -06:00
Tom Tromey 9abd8a65c1 Change "win_resized" to bool
This changes the "win_resized" global to be a bool and then updates
the uses.

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

	* tui/tui.c (tui_enable): Update.
	* tui/tui-win.c (tui_sigwinch_handler, tui_async_resize_screen):
	Update.
	* tui/tui-data.h (tui_win_resized, tui_set_win_resized_to):
	Update.
	* tui/tui-data.c (win_resized): Now bool.
	(tui_win_resized): Return bool.
	(tui_set_win_resized_to): Accept a bool.
2019-09-20 13:49:08 -06:00
Tom Tromey b545782674 Use "bool" in tui_data_window::show_register_group
This changes tui_data_window::show_register_group to use "bool" rather
than "int".

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

	* tui/tui-regs.h (struct tui_data_window) <show_register_group>:
	Change type of "refresh_values_only".
	* tui/tui-regs.c (tui_data_window::show_register_group): Change
	type of "refresh_values_only".
2019-09-20 13:49:07 -06:00
Tom Tromey 6b915f7d0c Simplify TUI disassembly
This simplifies TUI disassembly somewhat, by removing manual memory
management.

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

	* tui/tui-disasm.c (struct tui_asm_line) <addr_string, insn>: Now
	std::string.
	(tui_disassemble): Add "pos" parameter.
	(tui_disasm_window::set_contents): Simplify.
2019-09-20 13:49:07 -06:00
Tom Tromey 2ad52f6fb3 Simplify tui_source_window_base::show_source_content
tui_source_window_base::show_source_content is not used outside the
class any more, so this makes it private.  Examining the callers shows
that it can't be called without source contents, so it can be
simplified as well.

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

	* tui/tui-winsource.h (struct tui_source_window_base)
	<show_source_content>: Now private.
	* tui/tui-winsource.c
	(tui_source_window_base::show_source_content): Don't handle empty
	content case.
2019-09-20 13:49:06 -06:00
Tom Tromey b3b1bde658 Remove some explicit re-rendering from the TUI
A couple of spots in tui-layout.c still call the show_source_content
method.  However, now that re-rendering is done by the resize method,
these calls are no longer needed.

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

	* tui/tui-layout.c (show_source_disasm_command)
	(show_source_or_disasm_and_command): Don't call
	show_source_content.
2019-09-20 13:49:06 -06:00
Tom Tromey 71a25ed2e7 Change tui_make_status_line to be a method
This changes tui_make_status_line to be a method on
tui_locator_window.  This is a minor cleanup.

This also changes the new method to use the locator's width, rather
than the terminal width.  This is important if we ever want to allow
windows to be made more narrow.

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

	* tui/tui-stack.h (struct tui_locator_window) <make_status_line>:
	Declare.
	* tui/tui-stack.c (tui_locator_window::make_status_line): Rename
	from tui_make_status_line.
	(tui_locator_window::rerender): Update.
2019-09-20 13:49:05 -06:00
Tom Tromey f853215443 Change tui_make_status_line to return std::string
This changes tui_make_status_line to return std::string.  This cleans
it up a bit, and removes some explicit memory management.

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

	* tui/tui-stack.c (tui_make_status_line): Return std::string.
	(tui_locator_window::rerender): Update.
2019-09-20 13:49:05 -06:00
Tom Tromey 2d81b34998 Move "fullname" to tui_source_window
The "fullname" field in tui_source_window_base is only used by one
subclass.  This patch moves the field to that subclass, and changes it
to be a unique_xmalloc_ptr.

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

	* tui/tui-winsource.h (struct tui_source_window_base)
	<~tui_source_window_base>: Don't declare.
	<fullname>: Remove.
	* tui/tui-winsource.c (~tui_source_window_base): Remove.
	* tui/tui-source.h (struct tui_source_window) <fullname>: New
	member.
	* tui/tui-source.c (tui_source_window::set_contents): Update.
	(tui_source_window::location_matches_p)
	(tui_source_window::maybe_update): Update.
2019-09-20 13:49:05 -06:00
Tom Tromey f14bec587f Change tui_source_element::line to be a unique_xmalloc_ptr
This changes tui_source_element::line to be a unique_xmalloc_ptr,
removing some manual memory management.

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

	* tui/tui-winsource.h (~tui_source_element): Remove.
	(tui_source_element): Update.
	(struct tui_source_element) <line>: Now a unique_xmalloc_ptr.
	* tui/tui-winsource.c (tui_show_source_line): Update.
	* tui/tui-source.c (tui_source_window::set_contents): Update.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Update.
2019-09-20 13:49:04 -06:00
Tom Tromey 78d5933a43 Remove tui_clear_source_windows_detail
The calls to tui_clear_source_windows_detail in tui_add_win_to_layout
aren't needed, because (after the resize unification) resizing will
update the window contents.  Removing these calls lets us remove
several other things as well.

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

	* tui/tui-data.h (tui_clear_source_windows_detail): Don't
	declare.
	* tui/tui-layout.c (tui_add_win_to_layout): Don't call
	tui_clear_source_windows_detail.
	* tui/tui-winsource.h (struct tui_source_window_base)
	<clear_detail>: Don't declare.
	* tui/tui-winsource.c (tui_source_window_base::clear_detail):
	Remove.
	* tui/tui-data.c (tui_clear_source_windows_detail): Remove.
2019-09-20 13:49:04 -06:00
Tom Tromey d420769627 Fix crash in Ada "catch exception"
PR ada/24919 concerns a crash that Tom de Vries noticed when running
the "catch_ex" Ada test case.  He sent a test executable and tracked
this down to commit f21c2bd7b7 ("Fix Fortran regression with variables
in nested functions").

Looking at that patch, you can see the obvious error:

    -  return 0;
    +  return true;

Oops!  This patch fixes the bug.

Tested on x86-64 Fedora 29.

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

	PR ada/24919:
	* block.c (contained_in): Fix final return value.
2019-09-20 11:34:21 -06:00
Alan Modra 00f93c4492 bfd macro conversion to inline functions
This converts some of the macros that access struct bfd fields to
inline functions.

bfd/
	* archive.c (bfd_generic_archive_p): Use bfd_set_thin_archive.
	* bfd-in.h (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_target, bfd_get_flavour, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian, bfd_header_little_endian),
	(bfd_get_file_flags, bfd_applicable_file_flags),
	(bfd_applicable_section_flags, bfd_has_map, bfd_is_thin_archive),
	(bfd_valid_reloc_types, bfd_usrdata, bfd_get_start_address),
	(bfd_get_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_get_dynamic_symcount, bfd_get_symbol_leading_char): Delete.
	* bfd/bfd.c (bfd_get_filename, bfd_get_cacheable, bfd_get_format),
	(bfd_get_file_flags, bfd_get_start_address, bfd_get_symcount),
	(bfd_get_dynamic_symcount, bfd_get_outsymbols, bfd_count_sections),
	(bfd_has_map, bfd_is_thin_archive, bfd_set_thin_archive),
	(bfd_usrdata, bfd_set_usrdata): New inline functions.
	* targets.c (bfd_get_target, bfd_get_flavour),
	(bfd_applicable_file_flags, bfd_family_coff, bfd_big_endian),
	(bfd_little_endian, bfd_header_big_endian),
	(bfd_header_little_endian, bfd_applicable_section_flags),
	(bfd_get_symbol_leading_char): New inline functions.
	* bfd-in2.h: Regenerate.
binutils/
	* ar.c (write_archive): Use bfd_set_thin_archive.
gdb/
	* gdb_bfd.c (gdb_bfd_ref, gdb_bfd_unref): Use bfd_set_usrdata.
	* dwarf2read.c (dwarf2_read_gdb_index, dwarf2_read_debug_names),
	(read_indirect_string_from_dwz): Use bfd accessor.
	* dwarf2read.h (struct dwz_file <filename>): Likewise.
	* machoread.c (macho_symfile_read_all_oso): Likewise.
	* solib.c (solib_bfd_open): Likewise.
ld/
	* ldelf.c (ldelf_after_open, ldelf_place_orphan
	* ldlang.c (walk_wild_file, lang_process): Use bfd_usrdata.
	(load_symbols, ldlang_add_file): Use bfd_set_usrdata.
	* ldmain.c (add_archive_element): Use bfd_usrdata.
	* ldlang.h (bfd_input_just_syms): New inline function.
	* emultempl/aarch64elf.em (build_section_lists): Use it.
	* emultempl/mmo.em (mmo_place_orphan): Likewise.
	* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
	* emultempl/ppc64elf.em (build_section_lists): Likewise.
sim/
	* ppc/emul_generic.c (emul_add_tree_options): Delete old bfd code.
2019-09-20 18:04:02 +09:30
Christian Biesinger e4153ae630 Move declaration of overload_resolution to value.h
The variable is defined in valops.c and has an extern decl in
eval.c; move it to the header file.

gdb/ChangeLog:

2019-09-19  Christian Biesinger  <cbiesinger@google.com>

	* eval.c: Move declaration of overload_resolution to...
	* value.h: ...here.
2019-09-20 09:19:15 +09:00
Christian Biesinger c7ae7675cf Move arm_apcs_32 extern declaration to header
Instead of having several extern declarations for arm_apcs_32
in a few .c files, declare it in arm-tdep.h. This file is already
included from these .c files.

gdb/ChangeLog:

2019-09-19  Christian Biesinger  <cbiesinger@google.com>

	* arm-linux-nat.c: Remove extern declaration for arm_apcs_32.
	* arm-linux-tdep.c: Likewise.
	* arm-nbsd-nat.c: Likewise.
	* arm-tdep.h: Declare arm_apcs_32.
2019-09-20 09:17:49 +09:00
Christian Biesinger e86f08d28f Declare dwarf_always_disassemble in dwarf2read.h
And remove the declaration from dwarf2loc.c, for better typesafety.

gdb/ChangeLog:

2019-09-19  Christian Biesinger  <cbiesinger@google.com>

	* dwarf2loc.c: Remove extern declaration of dwarf_always_disassemble.
	* dwarf2read.h: Declare dwarf_always_disassemble.
2019-09-20 09:13:53 +09:00
Tom de Vries e452e88f54 [gdb/testsuite] Don't use FOOBAR pattern in gdb_test
If gdb_test is used with fewer than five arguments, then the question_string
defaults to "^FOOBAR$":
...
    if [llength $args]==5 {
       set question_string [lindex $args 3]
       set response_string [lindex $args 4]
    } else {
       set question_string "^FOOBAR$"
    }
...

This can however match "FOOBAR", so perhaps "\$FOOBAR^" would have been a
better choice.

Eliminate the FOOBAR pattern from gdb_test by instead of defining a default
regexp, conditionally appending the regexp matching to a user_code variable.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-19  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (gdb_test): Eliminate "^FOOBAR$" pattern.
2019-09-19 19:54:15 +02:00
Tom de Vries f64e2f4045 [gdb] Catch exception when constructing the highlighter
Currently in source_cache::ensure we catch the exception that triggers when
highlighter->highlight is called:
...
         try
           {
             std::istringstream input (contents);
             std::ostringstream output;
             highlighter->highlight (input, output, lang_name, fullname);
...
and the file used earlier in the construction of the highlighter:
...
             highlighter = new srchilite::SourceHighlight ("esc.outlang");
...
is missing.

The fact that this exception triggers when highlighter->highlight is called is
an implementation artefact of libsource-highlight.so though, and this could be
different for older or newer versions.

Make things more robust by also catching exceptions thrown during construction
of the highlighter.  This makes the handling on master equivalent with what
has been committed for 8.3.1.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-09-19  Tom de Vries  <tdevries@suse.de>

	PR gdb/25009
	* source-cache.c (source_cache::ensure): Catch exception thrown during
	construction of the highlighter.
2019-09-19 19:49:39 +02:00
Alan Modra fd3619828e bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions.  The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections.  Those sections shouldn't be modified
anyway.

The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma.  I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section.  This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.

bfd/
	* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
	(bfd_get_section_lma, bfd_get_section_alignment),
	(bfd_get_section_size, bfd_get_section_flags),
	(bfd_get_section_userdata): Delete.
	(bfd_section_name, bfd_section_size, bfd_section_vma),
	(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
	(bfd_section_flags, bfd_section_userdata): New.
	(bfd_is_com_section): Rename parameter.
	* section.c (bfd_set_section_userdata, bfd_set_section_vma),
	(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
	(bfd_set_section_size): Delete bfd parameter, rename section parameter.
	(bfd_set_section_lma): New.
	* bfd-in2.h: Regenerate.
	* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
	update callers.
	* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
	* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
	* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
	* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
	* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
	* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
	* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
	* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
	* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
	* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
	* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
	* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
	* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
	* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
	* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
	* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
	* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
	* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
	* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
	* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
	* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
	* xcofflink.c: Update throughout for bfd section macro and function
	changes.
binutils/
	* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
	* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
	* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
	* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
	throughout for bfd section macro and function changes.
gas/
	* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
	* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
	* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
	* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
	* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
	* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
	* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
	* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
	* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
	* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
	* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
	* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
	* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
	* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
	* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
	* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
	* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
	* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
	* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
	* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
	* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
	* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
	* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
	bfd section macro and function changes.
	* write.c (compress_debug): Use bfd_rename_section.
gdb/
	* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
	* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
	* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
	* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
	* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
	* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
	* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
	* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
	* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
	* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
	* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
	* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
	* solib-spu.c, * solib-svr4.c, * solib-target.c,
	* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
	* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
	* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
	* mi/mi-interp.c: Update throughout for bfd section macro and
	function changes.
	* gcore (gcore_create_callback): Use bfd_set_section_lma.
	* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
	* corefile.c, * symtab.c: Update throughout for bfd section
	macro and function changes.
ld/
	* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
	* emultempl/aarch64elf.em, * emultempl/aix.em,
	* emultempl/armcoff.em, * emultempl/armelf.em,
	* emultempl/cr16elf.em, * emultempl/cskyelf.em,
	* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
	* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
	* emultempl/mmo.em, * emultempl/msp430.em,
	* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
	throughout for bfd section macro and function changes.
libctf/
	* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
	* arc-ext.c: Update throughout for bfd section macro changes.
sim/
	* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
	* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
	* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
	* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
	* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-19 09:40:13 +09:30
Tom de Vries 8a6251301c [gdb/testsuite] Fix gdb_target_cmd
In commit 81dc3ab594 "[gdb/testsuite] Handle unreachable network in
server-connect.exp" a regression was introduced in gdb_target_cmd, causing
ERRORs like this:
...
ERROR: tcl error sourcing src/gdb/testsuite/gdb.server/abspath.exp.
ERROR: wrong # args: should be "gdb_target_cmd {$args}"
    while executing
"gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport"
...

Fix the argument passing in gdb_target_cmd.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-19  Tom de Vries  <tdevries@suse.de>

	* lib/gdbserver-support.exp (gdb_target_cmd): Fix argument passing.
2019-09-19 01:14:19 +02:00
Tom de Vries 81dc3ab594 [gdb/testsuite] Handle unreachable network in server-connect.exp
When running gdb.server/server-connect.exp I run into:
...
FAIL: gdb.server/server-connect.exp: tcp6: connect to gdbserver using tcp6:::1
FAIL: gdb.server/server-connect.exp: tcp6-with-brackets: connect to gdbserver \
  using tcp6:[::1]
FAIL: gdb.server/server-connect.exp: udp6: connect to gdbserver using udp6:::1
FAIL: gdb.server/server-connect.exp: udp6-with-brackets: connect to gdbserver \
  using udp6:[::1]
...

The FAIL is caused by the fact that the ipv6 loopback address is not available:
...
PASS: gdb.server/server-connect.exp: tcp6: start gdbserver
target remote tcp6:::1:2347^M
A program is being debugged already.  Kill it? (y or n) y^M
tcp6:::1:2347: Network is unreachable.^M
(gdb) FAIL: gdb.server/server-connect.exp: tcp6: connect to gdbserver using tcp6:::1
...
This should be marked UNSUPPORTED rather than FAIL.

Furthermore, the test-case takes about 4 minutes, because the 'Network is
unreachable' response is not explicitly handled in gdb_target_cmd, so instead
it runs into the timeout case.

Fix this by handling the 'Network is unreachable' response as UNSUPPORTED.
This reduces testing time from 4 minutes to about 2 seconds.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-19  Tom de Vries  <tdevries@suse.de>

	* lib/gdbserver-support.exp (gdb_target_cmd_ext): Return 2 (meaning
	UNSUPPORTED) for 'Network is unreachable' message.  Factor out of ...
	(gdb_target_cmd): ... here.
	* gdb.server/server-connect.exp: Use gdb_target_cmd_ext, handle return
	value 2.
2019-09-19 00:23:54 +02:00
Joel Brobecker a1726c38a9 Update ChangeLog entry of commit 677052f2a5c67f1d9b2e6d1b2a2149b5f0c20cd0...
... to include PR breakpoints/24541 (for documentation purposes).

For the reader's convenience, the commit in question was the following:

    commit 677052f2a5
    Author: Sergio Durigan Junior <sergiodj@redhat.com>
    Date:   Thu May 16 16:23:24 2019 -0400
    Subject: Make stap-probe.c:stap_parse_register_operand's "regname"
       an std::string
2019-09-18 14:42:24 -07:00
Tom Tromey 11061048d1 Give a name to the TUI SingleKey keymap
Readline 8.0 has a feature that lets an application name a keymap.
This in turn makes it simpler for users to bind keys in keymaps in
their .inputrc.

This patch gives a name to the TUI SingleKey keymap, so that
additional bindings can be made there.  For example:

    $if gdb
    set keymap SingleKey
    "X": "echo hello\\n\n"
    $endif

The call to rl_initialize, in tui_initialize_readline, had to be
removed so that .inputrc was not read too early.  Note that Readline
explicitly documents that this call is not needed.

gdb/ChangeLog
2019-09-18  Tom Tromey  <tom@tromey.com>

	* NEWS: Add entry.
	* tui/tui.c (tui_initialize_readline): Set name of keymap.  Do not
	call rl_initialize.
	(tui_enable): Do not call rl_initialize.

gdb/doc/ChangeLog
2019-09-18  Tom Tromey  <tom@tromey.com>

	* gdb.texinfo (Editing): Document readline application name.
	(TUI Single Key Mode): Document TUI SingleKey keymap name.
2019-09-18 15:03:29 -06:00
Christian Groessler 7a27b85f6d gdb: Fix native build on Linux/Alpha.
Fixes:

  CXX    alpha-linux-nat.o
alpha-linux-nat.c: In member function 'virtual CORE_ADDR alpha_linux_nat_target::register_u_offset(gdbarch*, int, int)':
alpha-linux-nat.c:93:16: error: 'gdbarch_pc_regnum' was not declared in this scope
   if (regno == gdbarch_pc_regnum (gdbarch))
                ^~~~~~~~~~~~~~~~~
alpha-linux-nat.c:93:16: note: suggested alternative: 'gdbarch_info'
   if (regno == gdbarch_pc_regnum (gdbarch))
                ^~~~~~~~~~~~~~~~~
                gdbarch_info
alpha-linux-nat.c:97:15: error: 'gdbarch_fp0_regnum' was not declared in this scope
   if (regno < gdbarch_fp0_regnum (gdbarch))
               ^~~~~~~~~~~~~~~~~~
alpha-linux-nat.c:97:15: note: suggested alternative: 'gdbarch_info'
   if (regno < gdbarch_fp0_regnum (gdbarch))
               ^~~~~~~~~~~~~~~~~~
               gdbarch_info
make[2]: *** [Makefile:1638: alpha-linux-nat.o] Error 1
make[2]: Leaving directory '/home/chris/tmp/binutils-gdb/gdb'

2019-09-12  Christian Groessler  <chris@groessler.org>

       * alpha-linux-nat.c: Include gdbarch.h.
2019-09-18 15:18:39 -04:00
Simon Marchi f64eea3a59 gdb: remove local extern declaration of cli_styling
Following the int -> bool conversion of boolean options (commit
491144b5e2 ("Change boolean options to bool instead of int")), I see
this ASAN error:

  ==357543==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55555b25d440 at pc 0x5555583ce9e1 bp 0x7fffffffd390 sp 0x7fffffffd380
  READ of size 4 at 0x55555b25d440 thread T0
      #0 0x5555583ce9e0 in term_cli_styling /home/simark/src/binutils-gdb/gdb/ui-file.c:111
      #1 0x5555583cf8b0 in stdio_file::can_emit_style_escape() /home/simark/src/binutils-gdb/gdb/ui-file.c:308
      #2 0x5555584450d2 in set_output_style /home/simark/src/binutils-gdb/gdb/utils.c:1442
      #3 0x5555584491af in fprintf_styled(ui_file*, ui_file_style const&, char const*, ...) /home/simark/src/binutils-gdb/gdb/utils.c:2143
      #4 0x5555582fa13c in print_gdb_version(ui_file*, bool) /home/simark/src/binutils-gdb/gdb/top.c:1339
      #5 0x555557b723ab in captured_main_1 /home/simark/src/binutils-gdb/gdb/main.c:981
      #6 0x555557b7353b in captured_main /home/simark/src/binutils-gdb/gdb/main.c:1172
      #7 0x555557b735d0 in gdb_main(captured_main_args*) /home/simark/src/binutils-gdb/gdb/main.c:1197
      #8 0x55555700a53d in main /home/simark/src/binutils-gdb/gdb/gdb.c:32
      #9 0x7ffff64c9ee2 in __libc_start_main (/usr/lib/libc.so.6+0x26ee2)
      #10 0x55555700a30d in _start (/home/simark/build/binutils-gdb/gdb/gdb+0x1ab630d)

  0x55555b25d441 is located 0 bytes to the right of global variable 'cli_styling' defined in '/home/simark/src/binutils-gdb/gdb/cli/cli-style.c:31:6' (0x55555b25d440) of size 1

The reason of this is that we have this declaration of cli_styling in cli/cli-style.h:

  extern bool cli_styling;

but ui-file.c uses its  own local declaration:

  extern int cli_styling;

Because of that, the code in ui-file.c thinks the variable is 4 bytes
long, when it is actually 1 byte long, so the generated code reads past
the variable.

Fix it by removing the declaration and making ui-file.c include
cli/cli-style.h.

gdb/ChangeLog:

	* ui-file.c: Include cli/cli-style.h.
	(term_cli_styling): Remove cli_styling declaration.
2019-09-18 13:33:33 -04:00
Andrew Burgess b078f3ac88 gdb/testsuite: Avoid directory names in test names
Give a test an actual name in order to avoid having a directory name
in the .sum file.

gdb/testsuite/ChangeLog:

	* gdb.base/source-dir.exp: Avoid having directory names in test
	names.
2019-09-18 12:36:05 -04:00
Alan Modra e6f7f6d14f bfd_asymbol_* macros
The main point of this patch is to give bfd_get_section a better name,
bfd_asymbol_section.

bfd/
	* bfd-in.h (bfd_asymbol_section): Rename from bfd_get_section.
	(bfd_get_output_section): Delete.
	(bfd_asymbol_base): Delete.
	(bfd_asymbol_section, bfd_asymbol_value, bfd_asymbol_name),
	(bfd_asymbol_bfd, bfd_asymbol_flavour): Tidy.
	(bfd_set_asymbol_name): New macro.
	* bfd-in2.h: Regenerate.
	* aout-cris.c: Update throughout to use bfd_asymbol_section.
	* aoutx.h: Likewise.
	* cofflink.c: Likewise.
	* dwarf2.c: Likewise.
	* ecoff.c: Likewise.
	* elf.c: Likewise.
	* elf32-arm.c: Likewise.
	* elf32-mips.c: Likewise.
	* elf32-score.c: Likewise.
	* elf32-score7.c: Likewise.
	* elfn32-mips.c: Likewise.
	* elfnn-aarch64.c: Likewise.
	* elfxx-mips.c: Likewise.
	* linker.c: Likewise.
	* pdp11.c: Likewise.
	* elf64-mmix.c (mmix_elf_reloc): Expand bfd_get_output_section.
binutils/
	* nm.c: Update bfd_get_section to bfd_asymbol_section throughout.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* rdcoff.c: Likewise.
	* objcopy.c (create_new_symbol): Use bfd_set_asymbol_name.
	(filter_symbols): Likewise.
gas/
	* symbols.c (S_IS_LOCAL): Update bfd_get_section to
	bfd_asymbol_section.
gdb/
	* arm-tdep.c (arm_record_special_symbol): Update bfd_get_section
	to bfd_asymbol_section.
ld/
	* ldcref.c (check_reloc_refs): Update bfd_get_section to
	bfd_asymbol_section.
2019-09-18 23:07:31 +09:30
Alan Modra 1d38e9d14c Constify target name, reloc name, and carsym name
bfd/
	* bfd-in.h (carsym.name): Make const.
	* reloc.c (struct reloc_howto_struct.name): Likewise.
	* targets.c (bfd_target.name): Likewise.!
	* bfd.c (bfd_get_sign_extend_vma): Make variable const.
	* som.c (som_bfd_fill_in_ar_symbols): Use an intermediary variable
	when setting carsym.name.
	* bfd-in2.h: Regenerate.
gdb/
	* amd64-dicos-tdep.c (amd64_dicos_osabi_sniffer): Constify target.
	* i386-cygwin-tdep.c (i386_cygwin_init_abi): Likewise.
	* i386-dicos-tdep.c (i386_dicos_osabi_sniffer): Likewise.
ld/
	* ldlang.c (stricpy, strcut, name_compare): Constify params.
	(get_first_input_target): Make return and "target" const.
2019-09-18 21:32:51 +09:30
Alan Modra 90d92a632a Use bfd_set_filename more
Fixes a few leaks in bfd and ld.

bfd/
	* mach-o.c (bfd_mach_o_fat_member_init): Likewise.  Replace
	xstrdup and xmalloc with bfd_strdup and bfd_malloc.  Return an
	error status.  Adjust calls.
	* vms-lib.c (_bfd_vms_lib_get_module): Test mhd->id earlier.
	Close bfd on failure.  Replace xstrdup/bfd_alloc use with
	bfd_malloc.  Use bfd_set_filename.
gdb/
	* solib-spu.c (spu_bfd_open): Use bfd_set_filename.
	* spu-linux-nat.c (spu_bfd_open): Likewise.
ld/
	* emultempl/pe.em (after_open): Use bfd_set_filename.
	* emultempl/pep.em (after_open): Use bfd_set_filename.
2019-09-18 21:32:51 +09:30
Christian Biesinger a3d181d2e7 Make extern declaration of dwarf_always_disassemble correct
This was an oversight in 491144b5e21bbfd41969c175aebb663976f59058;
dwarf2loc.c has an extern definition for dwarf_always_disassemble
that I missed. This patch updates it from int to bool to match
the definition in dwarf2read.c.

gdb/ChangeLog:

2019-09-18  Christian Biesinger  <cbiesinger@google.com>

	* dwarf2loc.c: Change extern declaration of dwarf_always_disassemble
	to bool to match definition in dwarf2read.c.
2019-09-18 13:54:48 +09:00
Christian Biesinger 491144b5e2 Change boolean options to bool instead of int
This is for add_setshow_boolean_cmd as well as the gdb::option interface.

gdb/ChangeLog:

2019-09-17  Christian Biesinger  <cbiesinger@google.com>

	* ada-lang.c (ada_ignore_descriptive_types_p): Change to bool.
	(print_signatures): Likewise.
	(trust_pad_over_xvs): Likewise.
	* arch/aarch64-insn.c (aarch64_debug): Likewise.
	* arch/aarch64-insn.h (aarch64_debug): Likewise.
	* arm-linux-nat.c (arm_apcs_32): Likewise.
	* arm-linux-tdep.c (arm_apcs_32): Likewise.
	* arm-nbsd-nat.c (arm_apcs_32): Likewise.
	* arm-tdep.c (arm_debug): Likewise.
	(arm_apcs_32): Likewise.
	* auto-load.c (debug_auto_load): Likewise.
	(auto_load_gdb_scripts): Likewise.
	(global_auto_load): Likewise.
	(auto_load_local_gdbinit): Likewise.
	(auto_load_local_gdbinit_loaded): Likewise.
	* auto-load.h (global_auto_load): Likewise.
	(auto_load_local_gdbinit): Likewise.
	(auto_load_local_gdbinit_loaded): Likewise.
	* breakpoint.c (disconnected_dprintf): Likewise.
	(breakpoint_proceeded): Likewise.
	(automatic_hardware_breakpoints): Likewise.
	(always_inserted_mode): Likewise.
	(target_exact_watchpoints): Likewise.
	(_initialize_breakpoint): Update.
	* breakpoint.h (target_exact_watchpoints): Change to bool.
	* btrace.c (maint_btrace_pt_skip_pad): Likewise.
	* cli/cli-cmds.c (trace_commands): Likewise.
	* cli/cli-cmds.h (trace_commands): Likewise.
	* cli/cli-decode.c (add_setshow_boolean_cmd): Change int* argument
	to bool*.
	* cli/cli-logging.c (logging_overwrite): Change to bool.
	(logging_redirect): Likewise.
	(debug_redirect): Likewise.
	* cli/cli-option.h (option_def) <boolean>: Change return type to bool*.
	(struct boolean_option_def) <get_var_address_cb_>: Change return type
	to bool.
	<boolean_option_def>: Update.
	(struct flag_option_def): Change default type of Context to bool
	from int.
	<flag_option_def>: Change return type of var_address_cb_ to bool*.
	* cli/cli-setshow.c (do_set_command): Cast to bool* instead of int*.
	(get_setshow_command_value_string): Likewise.
	* cli/cli-style.c (cli_styling): Change to bool.
	(source_styling): Likewise.
	* cli/cli-style.h (source_styling): Likewise.
	(cli_styling): Likewise.
	* cli/cli-utils.h (struct qcs_flags) <quiet, cont, silent>: Change
	to bool.
	* command.h (var_types): Update comment.
	(add_setshow_boolean_cmd): Change int* var argument to bool*.
	* compile/compile-cplus-types.c (debug_compile_cplus_types): Change to
	bool.
	(debug_compile_cplus_scopes): Likewise.
	* compile/compile-internal.h (compile_debug): Likewise.
	* compile/compile.c (compile_debug): Likewise.
	(struct compile_options) <raw>: Likewise.
	* cp-support.c (catch_demangler_crashes): Likewise.
	* cris-tdep.c (usr_cmd_cris_version_valid): Likewise.
	(usr_cmd_cris_dwarf2_cfi): Likewise.
	* csky-tdep.c (csky_debug): Likewise.
	* darwin-nat.c (enable_mach_exceptions): Likewise.
	* dcache.c (dcache_enabled_p): Likewise.
	* defs.h (info_verbose): Likewise.
	* demangle.c (demangle): Likewise.
	(asm_demangle): Likewise.
	* dwarf-index-cache.c (debug_index_cache): Likewise.
	* dwarf2-frame.c (dwarf2_frame_unwinders_enabled_p): Likewise.
	* dwarf2-frame.h (dwarf2_frame_unwinders_enabled_p): Likewise.
	* dwarf2read.c (check_physname): Likewise.
	(use_deprecated_index_sections): Likewise.
	(dwarf_always_disassemble): Likewise.
	* eval.c (overload_resolution): Likewise.
	* event-top.c (set_editing_cmd_var): Likewise.
	(exec_done_display_p): Likewise.
	* event-top.h (set_editing_cmd_var): Likewise.
	(exec_done_display_p): Likewise.
	* exec.c (write_files): Likewise.
	* fbsd-nat.c (debug_fbsd_lwp): Likewise
	(debug_fbsd_nat): Likewise.
	* frame.h (struct frame_print_options) <print_raw_frame_arguments>:
	Likewise.
	(struct set_backtrace_options) <backtrace_past_main>: Likewise.
	<backtrace_past_entry> Likewise.
	* gdb-demangle.h (demangle): Likewise.
	(asm_demangle): Likewise.
	* gdb_bfd.c (bfd_sharing): Likewise.
	* gdbcore.h (write_files): Likewise.
	* gdbsupport/common-debug.c (show_debug_regs): Likewise.
	* gdbsupport/common-debug.h (show_debug_regs): Likewise.
	* gdbthread.h (print_thread_events): Likewise.
	* gdbtypes.c (opaque_type_resolution): Likewise.
	(strict_type_checking): Likewise.
	* gnu-nat.c (gnu_debug_flag): Likewise.
	* guile/scm-auto-load.c (auto_load_guile_scripts): Likewise.
	* guile/scm-param.c (pascm_variable): Add boolval.
	(add_setshow_generic): Update.
	(pascm_param_value): Update.
	(pascm_set_param_value_x): Update.
	* hppa-tdep.c (hppa_debug): Change to bool..
	* infcall.c (may_call_functions_p): Likewise.
	(coerce_float_to_double_p): Likewise.
	(unwind_on_signal_p): Likewise.
	(unwind_on_terminating_exception_p): Likewise.
	* infcmd.c (startup_with_shell): Likewise.
	* inferior.c (print_inferior_events): Likewise.
	* inferior.h (startup_with_shell): Likewise.
	(print_inferior_events): Likewise.
	* infrun.c (step_stop_if_no_debug): Likewise.
	(detach_fork): Likewise.
	(debug_displaced): Likewise.
	(disable_randomization): Likewise.
	(non_stop): Likewise.
	(non_stop_1): Likewise.
	(observer_mode): Likewise.
	(observer_mode_1): Likewise.
	(set_observer_mode): Update.
	(sched_multi): Change to bool.
	* infrun.h (debug_displaced): Likewise.
	(sched_multi): Likewise.
	(step_stop_if_no_debug): Likewise.
	(non_stop): Likewise.
	(disable_randomization): Likewise.
	* linux-tdep.c (use_coredump_filter): Likewise.
	(dump_excluded_mappings): Likewise.
	* linux-thread-db.c (auto_load_thread_db): Likewise.
	(check_thread_db_on_load): Likewise.
	* main.c (captured_main_1): Update.
	* maint-test-options.c (struct test_options_opts) <flag_opt, xx1_opt,
	xx2_opt, boolean_opt>: Change to bool.
	* maint-test-settings.c (maintenance_test_settings_boolean): Likewise.
	* maint.c (maintenance_profile_p): Likewise.
	(per_command_time): Likewise.
	(per_command_space): Likewise.
	(per_command_symtab): Likewise.
	* memattr.c (inaccessible_by_default): Likewise.
	* mi/mi-main.c (mi_async): Likewise.
	(mi_async_1): Likewise.
	* mips-tdep.c (mips64_transfers_32bit_regs_p): Likewise.
	* nat/fork-inferior.h (startup_with_shell): Likewise.
	* nat/linux-namespaces.c (debug_linux_namespaces): Likewise.
	* nat/linux-namespaces.h (debug_linux_namespaces): Likewise.
	* nios2-tdep.c (nios2_debug): Likewise.
	* or1k-tdep.c (or1k_debug): Likewise.
	* parse.c (parser_debug): Likewise.
	* parser-defs.h (parser_debug): Likewise.
	* printcmd.c (print_symbol_filename): Likewise.
	* proc-api.c (procfs_trace): Likewise.
	* python/py-auto-load.c (auto_load_python_scripts): Likewise.
	* python/py-param.c (union parmpy_variable): Add "bool boolval" field.
	(set_parameter_value): Update.
	(add_setshow_generic): Update.
	* python/py-value.c (copy_py_bool_obj): Change argument from int*
	to bool*.
	* python/python.c (gdbpy_parameter_value): Cast to bool* instead of
	int*.
	* ravenscar-thread.c (ravenscar_task_support): Change to bool.
	* record-btrace.c (record_btrace_target::store_registers): Update.
	* record-full.c (record_full_memory_query): Change to bool.
	(record_full_stop_at_limit): Likewise.
	* record-full.h (record_full_memory_query): Likewise.
	* remote-notif.c (notif_debug): Likewise.
	* remote-notif.h (notif_debug): Likewise.
	* remote.c (use_range_stepping): Likewise.
	(interrupt_on_connect): Likewise.
	(remote_break): Likewise.
	* ser-tcp.c (tcp_auto_retry): Likewise.
	* ser-unix.c (serial_hwflow): Likewise.
	* skip.c (debug_skip): Likewise.
	* solib-aix.c (solib_aix_debug): Likewise.
	* spu-tdep.c (spu_stop_on_load_p): Likewise.
	(spu_auto_flush_cache_p): Likewise.
	* stack.c (struct backtrace_cmd_options) <full, no_filters, hide>:
	Likewise.
	(struct info_print_options) <quiet>: Likewise.
	* symfile-debug.c (debug_symfile): Likewise.
	* symfile.c (auto_solib_add): Likewise.
	(separate_debug_file_debug): Likewise.
	* symfile.h (auto_solib_add): Likewise.
	(separate_debug_file_debug): Likewise.
	* symtab.c (basenames_may_differ): Likewise.
	(struct filename_partial_match_opts) <dirname, basename>: Likewise.
	(struct info_print_options) <quiet, exclude_minsyms>: Likewise.
	(struct info_types_options) <quiet>: Likewise.
	* symtab.h (demangle): Likewise.
	(basenames_may_differ): Likewise.
	* target-dcache.c (stack_cache_enabled_1): Likewise.
	(code_cache_enabled_1): Likewise.
	* target.c (trust_readonly): Likewise.
	(may_write_registers): Likewise.
	(may_write_memory): Likewise.
	(may_insert_breakpoints): Likewise.
	(may_insert_tracepoints): Likewise.
	(may_insert_fast_tracepoints): Likewise.
	(may_stop): Likewise.
	(auto_connect_native_target): Likewise.
	(target_stop_and_wait): Update.
	(target_async_permitted): Change to bool.
	(target_async_permitted_1): Likewise.
	(may_write_registers_1): Likewise.
	(may_write_memory_1): Likewise.
	(may_insert_breakpoints_1): Likewise.
	(may_insert_tracepoints_1): Likewise.
	(may_insert_fast_tracepoints_1): Likewise.
	(may_stop_1): Likewise.
	* target.h (target_async_permitted): Likewise.
	(may_write_registers): Likewise.
	(may_write_memory): Likewise.
	(may_insert_breakpoints): Likewise.
	(may_insert_tracepoints): Likewise.
	(may_insert_fast_tracepoints): Likewise.
	(may_stop): Likewise.
	* thread.c (struct info_threads_opts) <show_global_ids>: Likewise.
	(make_thread_apply_all_options_def_group): Change argument from int*
	to bool*.
	(thread_apply_all_command): Update.
	(print_thread_events): Change to bool.
	* top.c (confirm): Likewise.
	(command_editing_p): Likewise.
	(history_expansion_p): Likewise.
	(write_history_p): Likewise.
	(info_verbose): Likewise.
	* top.h (confirm): Likewise.
	(history_expansion_p): Likewise.
	* tracepoint.c (disconnected_tracing): Likewise.
	(circular_trace_buffer): Likewise.
	* typeprint.c (print_methods): Likewise.
	(print_typedefs): Likewise.
	* utils.c (debug_timestamp): Likewise.
	(sevenbit_strings): Likewise.
	(pagination_enabled): Likewise.
	* utils.h (sevenbit_strings): Likewise.
	(pagination_enabled): Likewise.
	* valops.c (overload_resolution): Likewise.
	* valprint.h (struct value_print_options) <prettyformat_arrays,
	prettyformat_structs, vtblprint, unionprint, addressprint, objectprint,
	stop_print_at_null, print_array_indexes, deref_ref, static_field_print,
	pascal_static_field_print, raw, summary, symbol_print, finish_print>:
	Likewise.
	* windows-nat.c (new_console): Likewise.
	(cygwin_exceptions): Likewise.
	(new_group): Likewise.
	(debug_exec): Likewise.
	(debug_events): Likewise.
	(debug_memory): Likewise.
	(debug_exceptions): Likewise.
	(useshell): Likewise.
	* windows-tdep.c (maint_display_all_tib): Likewise.
	* xml-support.c (debug_xml): Likewise.
2019-09-18 09:35:12 +09:00
Mike Gulick f1b620e9b4 gdb: Look for compilation directory relative to directory search path
The 'directory' command allows the user to provide a list of filesystem
directories in which to search for source code.  The directories in this
search path are used as the base directory for the source filename from
the debug information (DW_AT_name).  Thus the directory search path
provides alternatives to the existing compilation directory from the
debug information (DW_AT_comp_dir).  Generally speaking, DW_AT_name
stores the filename argument passed to the compiler (including any
directory components), and DW_AT_comp_dir stores the current working
directory from which the compiler was executed.  For example:

    $ cd /path/to/project/subdir1
    $ gcc -c a/test.c -g

The corresponding debug information will look like this:

    DW_AT_name      : a/test.c
    DW_AT_comp_dir  : /path/to/project/subdir1

When compiling with the -fdebug-prefix-map GCC option, the compilation
directory can be arbitrarily rewritten.  In the above example, we may
rewrite the compilation directory as follows:

    $ gcc -c a/test.c -g -fdebug-prefix-map=/path/to/project=

In this case, the corresponding debug information will look like:

    DW_AT_name      : a/test.c
    DW_AT_comp_dir  : /subdir1

This prevents GDB from finding the corresponding source code based on
the debug information alone.  In some cases, a substitute-path command
can be used to re-map a consistent prefix in the rewritten compilation
directory to the real filesystem path.  However, there may not be a
consistent prefix remaining in the debug symbols (for example in a
project that has source code in many subdirectories under the project's
root), thereby requiring multiple substitute-path rules.  In this case,
it is easier to add the missing prefix to the directory search path via
the 'directory' command.

The function find_and_open_source currently searches in:

    SEARCH_PATH/FILENAME

where SEARCH_PATH corresponds to each individual entry in the directory
search path (which is guaranteed to contain the compilation directory
from the debug information, as well as the current working directory).
FILENAME corresponds to the source filename (DW_AT_name), which may have
directory components in it.  In addition, GDB searches in:

    SEARCH_PATH/FILE_BASENAME

where FILE_BASENAME is the basename of the DW_AT_name entry.

This change modifies find_and_open_source to additionally search in:

    SEARCH_PATH/COMP_DIR/FILENAME

where COMP_DIR is the compilation directory from the debug symbols.  In
the example given earlier, running:

    (gdb) directory /path/to/project

will now allow GDB to correctly locate the source code from the debug
information.

gdb/ChangeLog:

	* source.c (prepare_path_for_appending): New function.
	(openp): Make use of new function.
	(find_and_open_source): Search for the compilation directory and
	source file as a relative path beneath the directory search path.

gdb/doc/ChangeLog:

	* gdb.texinfo (Source Path): Additional text to better describe
	how the source path directory list is used when searching for
	source files.

gdb/testsuite/ChangeLog:

	* gdb.base/source-dir.exp: Add extra test for mapped compilation
	directory.
2019-09-17 16:20:19 -04:00
Andrew Burgess 67f3ed6afe gdb: Catch exceptions when accessing source cache
The source_cache::get_line_charpos function can currently throw an
exception if the source file is missing, which doesn't match the
expected behaviour documented in the functions header file.  The
documented behaviour is to return false on failure, and this is how
the function appears to be used throughout GDB.

I spotted this in the 'info source' command, currently for a missing
source file you'll see something like this:

  (gdb) info source
  Current source file is /path/to/src/file.c
  Compilation directory is /path/to/build/
  /path/to/src/file.c: No such file or directory.
  (gdb)

After this patch we see this:

  (gdb) info source
  Current source file is /path/to/src/file.c
  Compilation directory is /path/to/build/
  Source language is c.
  Producer is COMPILER VERSION AND FLAGS.
  Compiled with DWARF 2 debugging format.
  Does not include preprocessor macro info.

We don't currently indicate that the source file can't be found, and
maybe that would be something worth adding in the future.

gdb/ChangeLog:

	* source-cache.c (source_cache::get_line_charpos): Catch
	exceptions and return false, this matches the behaviour documented
	in the header file.

gdb/testsuite/ChangeLog:

	* gdb.base/list-missing-source.exp: New file.
2019-09-17 15:53:32 -04:00
Joel Brobecker 7433218996 (Ada) do not print Ada task names in quotes in "info tasks" output
A recent change enhanced a couple of notifications about Ada tasks to
include the task's name in addition to the task's number. That change
also modified the output of the "info tasks" when printing the detailed
information of one given task. I believe this change was unintentionally
left over from the initial version after it was decided that quoting
the task's name should not be done. This patch therefore undoes this
part of the patch.

gdb/ChangeLog:

        * ada-tasks.c (info_task): Remove quoting of the task's name.

Tested on x86_64-linux, with both the official testsuite as well as
AdaCore's testsuite.
2019-09-17 14:27:55 -04:00
Christian Biesinger f2f24aa9c4 Don't duplicate comment in symfile.c and .h
This just replaces the comment in the .c file with
"See symfile.h.".

gdb/ChangeLog:

2019-09-16  Christian Biesinger  <cbiesinger@google.com>

	* symfile.c (auto_solib_add): Replace comment with a reference
	to the header file.
2019-09-16 22:10:36 -05:00
Christian Biesinger 6a062a93d7 Add a NEWS entry that gdb can be compiled with py3 on Windows.
This was fixed in commit 272044897e.

2019-09-14  Christian Biesinger  <cbiesinger@google.com>

	* NEWS: Mention that gdb can now be compiled with Python 3
	on Windows.
2019-09-14 22:36:47 -04:00
Tom de Vries d1b70248bd [gdb/testsuite] Require gnatmake 8 for gdb.ada/rename_subscript_param.exp
When running gdb.ada/rename_subscript_param.exp with gnatmake 7.4.1, we get:
...
FAIL: gdb.ada/rename_subscript_param.exp: print rename_subscript_param_b \
  before changing its value
FAIL: gdb.ada/rename_subscript_param.exp: print rename_subscript_param_b \
  after changing its value
...

The commit last touching the test-case (afcfda091e) states:
...
    The test still fails with old compilers that do not properly
    generate debug info for this renaming:
...

Fix this by requiring at least gnatmake 8 for the test-case.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-14  Tom de Vries  <tdevries@suse.de>

	PR teststuite/24599
	* gdb.ada/rename_subscript_param.exp: Require gnatmake 8.
	* lib/ada.exp (gnatmake_version_at_least): New proc.
2019-09-14 10:35:48 +02:00
Andrew Burgess ec6c8338a8 gdb: Force use of float version of log10
This commit:

  commit aa17805fb9
  Date:   Sat Aug 31 23:44:40 2019 +0100

      gdb: Have 'maint info sections' print all sections again

introduced a use of log10 that took an int as a parameter.
Unfortunately this was causing a compilation error on Solaris, see:

  https://sourceware.org/ml/gdb-patches/2019-09/msg00230.html
  https://sourceware.org/ml/gdb-patches/2019-09/msg00231.html

because there was only a float, double, or long double version of
log10, and the compiler doesn't know which to choose.

This commit should resolve this issue by casting the argument to
float.

gdb/ChangeLog:

	* maint.c (maint_print_section_data::maint_print_section_data):
	Force use of 'float log10 (float)' by casting the argument to
	float.
2019-09-12 21:23:37 -04:00
Andrew Burgess 5fabdcd680 gdb/testsuite: Make use of exec_has_index_section function
Make use of exec_has_index_section library function rather than
manually checking in the 'maintenance info sections' output.  Should
make no difference to the test results, just makes the code easier to
read.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Use exec_has_index_section.
2019-09-12 20:31:29 -04:00
Andrew Burgess aa17805fb9 gdb: Have 'maint info sections' print all sections again
In this commit:

  commit 6eac171f06
  Date:   Fri Aug 16 00:25:14 2019 +0200

      [gdb] Make maint info sections print relocated addresses

A couple of things broke with the 'maintenance info sections' command,
here is some before output:

  (gdb) maintenance info sections
  Exec file:
      `/path/to/gdb/build/gdb/testsuite/outputs/gdb.base/maint/maint',
          file type elf64-x86-64.
   [0]     0x00400238->0x00400254 at 0x00000238: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
   [1]     0x00400254->0x00400274 at 0x00000254: .note.ABI-tag ALLOC LOAD READONLY DATA HAS_CONTENTS
   [2]     0x00400274->0x00400298 at 0x00000274: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
   [3]     0x00400298->0x004002bc at 0x00000298: .gnu.hash ALLOC LOAD READONLY DATA HAS_CONTENTS
   [4]     0x004002c0->0x00400380 at 0x000002c0: .dynsym ALLOC LOAD READONLY DATA HAS_CONTENTS
   [5]     0x00400380->0x004003e3 at 0x00000380: .dynstr ALLOC LOAD READONLY DATA HAS_CONTENTS
   [6]     0x004003e4->0x004003f4 at 0x000003e4: .gnu.version ALLOC LOAD READONLY DATA HAS_CONTENTS
   [7]     0x004003f8->0x00400418 at 0x000003f8: .gnu.version_r ALLOC LOAD READONLY DATA HAS_CONTENTS
   [8]     0x00400418->0x00400460 at 0x00000418: .rela.dyn ALLOC LOAD READONLY DATA HAS_CONTENTS
   [9]     0x00400460->0x004004c0 at 0x00000460: .rela.plt ALLOC LOAD READONLY DATA HAS_CONTENTS
   [10]     0x004004c0->0x004004d7 at 0x000004c0: .init ALLOC LOAD READONLY CODE HAS_CONTENTS
   [11]     0x004004e0->0x00400530 at 0x000004e0: .plt ALLOC LOAD READONLY CODE HAS_CONTENTS
   [12]     0x00400530->0x00400802 at 0x00000530: .text ALLOC LOAD READONLY CODE HAS_CONTENTS
   [13]     0x00400804->0x0040080d at 0x00000804: .fini ALLOC LOAD READONLY CODE HAS_CONTENTS
   [14]     0x00400810->0x0040084e at 0x00000810: .rodata ALLOC LOAD READONLY DATA HAS_CONTENTS
   [15]     0x00400850->0x004008c4 at 0x00000850: .eh_frame_hdr ALLOC LOAD READONLY DATA HAS_CONTENTS
   [16]     0x004008c8->0x00400ab8 at 0x000008c8: .eh_frame ALLOC LOAD READONLY DATA HAS_CONTENTS
   [17]     0x00600e00->0x00600e08 at 0x00000e00: .init_array ALLOC LOAD DATA HAS_CONTENTS
   [18]     0x00600e08->0x00600e10 at 0x00000e08: .fini_array ALLOC LOAD DATA HAS_CONTENTS
   [19]     0x00600e10->0x00600ff0 at 0x00000e10: .dynamic ALLOC LOAD DATA HAS_CONTENTS
   [20]     0x00600ff0->0x00601000 at 0x00000ff0: .got ALLOC LOAD DATA HAS_CONTENTS
   [21]     0x00601000->0x00601038 at 0x00001000: .got.plt ALLOC LOAD DATA HAS_CONTENTS
   [22]     0x00601038->0x0060103c at 0x00001038: .data ALLOC LOAD DATA HAS_CONTENTS
   [23]     0x00601040->0x006012c8 at 0x0000103c: .bss ALLOC
   [24]     0x00000000->0x0000002c at 0x0000103c: .comment READONLY HAS_CONTENTS
   [25]     0x00000000->0x00000060 at 0x00001068: .debug_aranges READONLY HAS_CONTENTS
   [26]     0x00000000->0x0000061b at 0x000010c8: .debug_info READONLY HAS_CONTENTS
   [27]     0x00000000->0x00000264 at 0x000016e3: .debug_abbrev READONLY HAS_CONTENTS
   [28]     0x00000000->0x000001e6 at 0x00001947: .debug_line READONLY HAS_CONTENTS
   [29]     0x00000000->0x00000487 at 0x00001b2d: .debug_str READONLY HAS_CONTENTS
  (gdb)

And here is the output after the above commit:

  (gdb) maintenance info sections
  +maintenance info sections
  Exec file:
      `/path/to/gdb/build/gdb/testsuite/outputs/gdb.base/maint/maint',
          file type elf64-x86-64.
      0x00400238->0x00400254 at 0x00000238: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400254->0x00400274 at 0x00000254: .note.ABI-tag ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400274->0x00400298 at 0x00000274: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400298->0x004002bc at 0x00000298: .gnu.hash ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x004002c0->0x00400380 at 0x000002c0: .dynsym ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400380->0x004003e3 at 0x00000380: .dynstr ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x004003e4->0x004003f4 at 0x000003e4: .gnu.version ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x004003f8->0x00400418 at 0x000003f8: .gnu.version_r ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400418->0x00400460 at 0x00000418: .rela.dyn ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400460->0x004004c0 at 0x00000460: .rela.plt ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x004004c0->0x004004d7 at 0x000004c0: .init ALLOC LOAD READONLY CODE HAS_CONTENTS
      0x004004e0->0x00400530 at 0x000004e0: .plt ALLOC LOAD READONLY CODE HAS_CONTENTS
      0x00400530->0x00400802 at 0x00000530: .text ALLOC LOAD READONLY CODE HAS_CONTENTS
      0x00400804->0x0040080d at 0x00000804: .fini ALLOC LOAD READONLY CODE HAS_CONTENTS
      0x00400810->0x0040084e at 0x00000810: .rodata ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00400850->0x004008c4 at 0x00000850: .eh_frame_hdr ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x004008c8->0x00400ab8 at 0x000008c8: .eh_frame ALLOC LOAD READONLY DATA HAS_CONTENTS
      0x00600e00->0x00600e08 at 0x00000e00: .init_array ALLOC LOAD DATA HAS_CONTENTS
      0x00600e08->0x00600e10 at 0x00000e08: .fini_array ALLOC LOAD DATA HAS_CONTENTS
      0x00600e10->0x00600ff0 at 0x00000e10: .dynamic ALLOC LOAD DATA HAS_CONTENTS
      0x00600ff0->0x00601000 at 0x00000ff0: .got ALLOC LOAD DATA HAS_CONTENTS
      0x00601000->0x00601038 at 0x00001000: .got.plt ALLOC LOAD DATA HAS_CONTENTS
      0x00601038->0x0060103c at 0x00001038: .data ALLOC LOAD DATA HAS_CONTENTS
      0x00601040->0x006012c8 at 0x0000103c: .bss ALLOC
      0x00000000->0x00000000 at 0x00000000: *COM* IS_COMMON
      0x00000000->0x00000000 at 0x00000000: *UND*
      0x00000000->0x00000000 at 0x00000000: *ABS*
      0x00000000->0x00000000 at 0x00000000: *IND*
  (gdb)

We lost the section index numbers, but more importantly, we lost the
information about the .debug* sections.  We also gained entries for
the "fake" sections *COM*, *UND*, *ABS*, and *IND*.

I noticed this when running:

  make check-gdb RUNTESTFLAGS="--target_board=cc-with-gdb-index gdb.base/maint.exp"

As this test relies on looking in the 'maint info sections' output to
see if we have a .debug_names or .gdb_index section, and these are
debug sections so they no longer show up in the 'main info sections'
output, the gdb.base/maint.exp test fails.

This commit restores the old behaviour while keeping the important
change that the above commit introduced, the addresses printed for
sections are the relocated addresses where appropriate.  The above
commit mentions using this test:

   make check-gdb RUNTESTFLAGS="CFLAGS_FOR_TARGET='-pie' gdb.base/compare-sections.exp"

And this still passes after this commit.

The output for 'maint info sections' now looks like this:

  (gdb) maintenance info sections
  Exec file:
      `/home/andrew/projects/binutils-gdb/build/gdb/testsuite/outputs/gdb.base/maint/maint',
          file type elf64-x86-64.
   [0]      0x00400238->0x00400254 at 0x00000238: .interp ALLOC LOAD READONLY DATA HAS_CONTENTS
   [1]      0x00400254->0x00400274 at 0x00000254: .note.ABI-tag ALLOC LOAD READONLY DATA HAS_CONTENTS
   [2]      0x00400274->0x00400298 at 0x00000274: .note.gnu.build-id ALLOC LOAD READONLY DATA HAS_CONTENTS
   [3]      0x00400298->0x004002bc at 0x00000298: .gnu.hash ALLOC LOAD READONLY DATA HAS_CONTENTS
   [4]      0x004002c0->0x00400380 at 0x000002c0: .dynsym ALLOC LOAD READONLY DATA HAS_CONTENTS
   [5]      0x00400380->0x004003e3 at 0x00000380: .dynstr ALLOC LOAD READONLY DATA HAS_CONTENTS
   [6]      0x004003e4->0x004003f4 at 0x000003e4: .gnu.version ALLOC LOAD READONLY DATA HAS_CONTENTS
   [7]      0x004003f8->0x00400418 at 0x000003f8: .gnu.version_r ALLOC LOAD READONLY DATA HAS_CONTENTS
   [8]      0x00400418->0x00400460 at 0x00000418: .rela.dyn ALLOC LOAD READONLY DATA HAS_CONTENTS
   [9]      0x00400460->0x004004c0 at 0x00000460: .rela.plt ALLOC LOAD READONLY DATA HAS_CONTENTS
   [10]     0x004004c0->0x004004d7 at 0x000004c0: .init ALLOC LOAD READONLY CODE HAS_CONTENTS
   [11]     0x004004e0->0x00400530 at 0x000004e0: .plt ALLOC LOAD READONLY CODE HAS_CONTENTS
   [12]     0x00400530->0x00400802 at 0x00000530: .text ALLOC LOAD READONLY CODE HAS_CONTENTS
   [13]     0x00400804->0x0040080d at 0x00000804: .fini ALLOC LOAD READONLY CODE HAS_CONTENTS
   [14]     0x00400810->0x0040084e at 0x00000810: .rodata ALLOC LOAD READONLY DATA HAS_CONTENTS
   [15]     0x00400850->0x004008c4 at 0x00000850: .eh_frame_hdr ALLOC LOAD READONLY DATA HAS_CONTENTS
   [16]     0x004008c8->0x00400ab8 at 0x000008c8: .eh_frame ALLOC LOAD READONLY DATA HAS_CONTENTS
   [17]     0x00600e00->0x00600e08 at 0x00000e00: .init_array ALLOC LOAD DATA HAS_CONTENTS
   [18]     0x00600e08->0x00600e10 at 0x00000e08: .fini_array ALLOC LOAD DATA HAS_CONTENTS
   [19]     0x00600e10->0x00600ff0 at 0x00000e10: .dynamic ALLOC LOAD DATA HAS_CONTENTS
   [20]     0x00600ff0->0x00601000 at 0x00000ff0: .got ALLOC LOAD DATA HAS_CONTENTS
   [21]     0x00601000->0x00601038 at 0x00001000: .got.plt ALLOC LOAD DATA HAS_CONTENTS
   [22]     0x00601038->0x0060103c at 0x00001038: .data ALLOC LOAD DATA HAS_CONTENTS
   [23]     0x00601040->0x006012c8 at 0x0000103c: .bss ALLOC
   [24]     0x00000000->0x0000002c at 0x0000103c: .comment READONLY HAS_CONTENTS
   [25]     0x00000000->0x00000060 at 0x00001068: .debug_aranges READONLY HAS_CONTENTS
   [26]     0x00000000->0x0000061b at 0x000010c8: .debug_info READONLY HAS_CONTENTS
   [27]     0x00000000->0x00000264 at 0x000016e3: .debug_abbrev READONLY HAS_CONTENTS
   [28]     0x00000000->0x000001e6 at 0x00001947: .debug_line READONLY HAS_CONTENTS
   [29]     0x00000000->0x00000487 at 0x00001b2d: .debug_str READONLY HAS_CONTENTS
  (gdb)

This is basically as it was before, except that the index numbers are
now padded so the section information all lines up.

When GDB has relocated a section then the relocated addresses will be
printed, otherwise the non-relocated addresses from the bfd will be
printed.

I've added a test to gdb.base/maint.exp to do some basic validation of
the output format.

gdb/ChangeLog:

	* maint.c: Add 'cmath' include.
	(struct maint_print_section_data): New structure.
	(print_section_index): New function.
	(print_bfd_section_info): Add header comment, small whitespace
	cleanup, and update to call new print_section_index function.
	(print_objfile_section_info): Likewise.
	(maint_obj_section_from_bfd_section): New function.
	(print_bfd_section_info_maybe_relocated): New function.
	(maintenance_info_sections): Add header comment, always use
	bfd_map_over_sections instead of ALL_OBJFILE_OSECTIONS.

gdb/testsuite/ChangeLog:

	* gdb.base/maint.exp: Add test for 'maint info sections'.
2019-09-12 20:31:29 -04:00
Andrew Burgess 3dd9bb4620 gdb: Don't fault for 'maint print psymbols' when using an index
I found that these tests:

  make check-gdb RUNTESTFLAGS="--target_board=cc-with-gdb-index gdb.base/maint.exp"
  make check-gdb RUNTESTFLAGS="--target_board=cc-with-debug-names gdb.base/maint.exp"

were causing GDB to segfault.  It turns out that this test runs this
command:

  maint print psymbols -pc main /path/to/some/file

which tries to lookup the partial_symtab for 'main'.  The problem is
that there is no partial_symtab for 'main' as we are using the
.gdb_index or .debug_names instead of partial_symtabs.

What happens is that maintenance_print_symbols calls
find_pc_sect_psymtab, which looks for the partial_symtab in the
objfile's objfile->partial_symtabs->psymtabs_addrmap.

This is a problem because when we are using the indexes
psymtabs_addrmap is reused to hold things other than partial_symtabs,
this can be seen in dwarf2read.c in create_addrmap_from_index and
create_addrmap_from_aranges.  If we then lookup in psymtabs_addrmap we
end up returning a pointer to something that isn't really a
partial_symtab, after which everything goes wrong.

Initially I simply added a check at the start of find_pc_sect_psymtab
that the objfile had some partial_symtabs, like:

  if (objfile->partial_symtabs->psymtabs == NULL)
    return NULL;

Figuring that if there were no partial_symtabs at all then this
function should always return NULL, however, this caused a failure in
the test gdb.python/py-event.exp which I didn't dig into too deeply,
but seems to be that in this tests there are initially no psymtabs,
but the second part of find_pc_sect_psymtab does manage to read some
in from somewhere, with the check I added the test fails as we
returned NULL here and this caused GDB to load in the full symtabs
earlier than was expected.

Instead I chose to guard only the access to psymtabs_addrmap with a
check that the function has some psymtabs.  This allows my original
tests to pass, and the py-event.exp test to pass too.

Now, a good argument can be made that we simply should never call
find_pc_sect_psymtab on an objfile that is using indexes instead of
partial_symtabs.  I did consider this approach, we could easily add an
assert into find_pc_sect_psymtab that if we find a partial_symtab in
psymtabs_addrmap then the psymtabs pointer must be non-null.  The
responsibility would then be on the user of find_pc_sect_psymtab to
ensure that the objfile being checked is suitable.  In the end I
didn't take this approach as the check in find_pc_sect_psymtab is
cheap and this ensures that any future miss-uses of the function will
not cause problems.

I also extended the comment on psymtabs_addrmap to indicate that it
holds more than just partial_symtabs as this was not at all clear from
the original comment, and caused me some confusion when I was
initially debugging this problem.

gdb/ChangeLog:

	* psymtab.c (find_pc_sect_psymtab): Move baseaddr local into more
	inner scope, add check that the objfile has psymtabs before
	checking psymtabs_addrmap.
	* psymtab.h (psymtab_storage) <psymtabs_addrmap>: Extend comment.
2019-09-12 20:31:29 -04:00
Tom de Vries 25e5c20918 [gdb/testsuite] Allow some tests in gdb.base/store.exp to be unsupported
The test-case gdb.base/store.exp fails with gcc 7.4.0:
...
nr of unexpected failures        27
...

The first FAIL:
...
110       l = add_float (l, r);
(gdb) PASS: gdb.base/store.exp: continue to wack_float
print l
$21 = <optimized out>
FAIL: gdb.base/store.exp: var float l; print old l, expecting -1
...
relates to this bit in the test-case (compiled at -O0):
...
   106  float
   107  wack_float (register float u, register float v)
   108  {
   109    register float l = u, r = v;
   110    l = add_float (l, r);
   111    return l + r;
   112  }
...
and it expects to be able to read and modify variable l before executing line
110, but it already fails to read the value, because l has no DW_AT_location
attribute in the debug info.

Variable l is declared with the register keyword, and GCC implements the
register keyword at -O0 like so:
...
the compiler allocates distinct stack memory for all variables that do not
have the register storage-class specifier; if register is specified, the
variable may have a shorter lifespan than the code would indicate and may
never be placed in memory.
...

The fact that l has no DW_AT_location attribute, matches with the documented
"variable may have a shorter lifespan that code would indicate", (though it
is the most extreme case of it) so the gcc behaviour is valid.  We can of
course improve gcc to generate better debuginfo (filed gcc PR91611), but
this not a wrong-debug problem.

[ The test-case passes with gcc 4.2.1, but for the failing test discussed
above, it passes simply because it doesn't store l in a register. ]

With the debug info missing for l, reading and setting l is unsupported, so
fix the FAIL by marking the test UNSUPPORTED instead.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-12  Tom de Vries  <tdevries@suse.de>

	* gdb.base/store.exp: Allow register variables to be optimized out at
	-O0.
2019-09-12 22:36:37 +02:00
Philippe Waroquiers 4993045d18 Output the Ada task name in more messages.
With this patch, we e.g. get:
      [Switching to task 2 "task_list(1)"]
      [Current task is 2 "task_list(1)"]
    instead of
      [Switching to task 2]
      [Current task is 2]

The logic to produce the taskno optionally followed
by the task name has been factorized in the task_to_str function.

Task names are output between double quotes in the new messages,
similarly to what GDB does for thread names.
However, no quotes are put around task names in 'info tasks' Name column.
This was discussed with Tom, that preferred no quotes there, while I
was more in favour of visual consistency.
I discussed with a few more users, which led to (exactly) 50% preferring
quotes and 50% preferring no quotes :).
To arrive to the decision to remove the quotes, the following "killing args"
were used:
 * To have quotes or to not have quotes, that is the question; yes
   but not *THE* question :).
 * If there is not a clear majority that prefers quotes, better to
   not disturb the existing user basis for a (somewhat) irrelevant
   aspect.
 * The opinion of the reviewer has more weight.

So, compared to the previous version, this version remotes the quotes
in 'info tasks'.

It improves the alignement of 'info tasks' output.
With this patch, we get:
      (gdb) info task
         ID           TID P-ID Pri State                  Name
      *   1  555555759030       48 Runnable               main_task
          2  555555759e30    1  48 Selective Wait         mit
      (gdb)
   instead of
      (gdb) info task
         ID       TID P-ID Pri State                  Name
      *   1 555555759030       48 Runnable               main_task
          2 555555759e30    1  48 Selective Wait         mit
      (gdb)
(e.g. the first one properly shows parent and priority under the
correct header).

This is version 4 of the 'task name' patch.
Compared to version 3, the changes are:
   output task names between quotes but not in 'info tasks'

gdb/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* NEWS: Announce that Ada task names are now shown at more places,
	and between quotes (except in info task output).
	* gdb/ada-tasks.c (task_to_str): New function.
	(display_current_task_id): Call task_to_str.
	(task_command_1): Likewise.
	(print_ada_task_info): In non-mi mode, Properly align headers and data
	when task-id length is > 9 (9 is the default for a 32 bits CORE_ADDR).

gdb/doc/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.texinfo (Ada Tasks): Tell the task name is printed, update
	examples.

gdb/testsuite/ChangeLog
2019-09-12  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.ada/rdv_wait.exp: Update to new task names.
	* gdb.base/task_switch_in_core.exp: Likewise.
	* gdb.base/info_sources_base.c: Likewise.
2019-09-12 21:57:10 +02:00
Rainer Orth 7a28970742 Fix signals reported for faults on Solaris
It's been a long-standing nuisance that gdb reported unaligned accesses
on Solaris/SPARC as SIGSEGV, contrary to the shells and truss which
correctly report SIGBUS instead.

I could trace this down to the fault handling code in procfs.c
(procfs_target::wait): when pr_why is set to PR_FAULTED, the current
code sets the signal based on the fault number.  For one, the code gets
this wrong for FLTACCESS (the unaligned access case) where it uses
SIGSEGV.  What's worse, it's completely unnecessary to make up the
signal number inside gdb.  Instead, it should just take what procfs
reports to avoid mismatches, which is what this patch does.  I've
completely removed the explicit handling of the various fault codes: for
one, the list has already been incomplete, lacking FLTCPCOVF which
existed since at least Solaris 8.  Besides, there's no reason to error
out on unknown fault codes: either the fault causes a signal which can
then be reported from procfs, or it doesn't (as for FLTPAGE) and no
reporting is necessary.

Tested on sparcv9-sun-solaris2.11 and x86_64-pc-solaris2.11.  Also
spot-checked manually for a couple of cases (unaligned access, division
by 0, NULL pointer dereference).

	* procfs.c (procfs_target::wait) <PR_FAULTED>: Get signal from
	prstatus.pr_lwp.pr_info instead of making it up.
2019-09-12 10:40:59 +02:00
Christian Biesinger f2aec7f6d1 Make relocate_{path,gdb_directory} return std::string
This simplifies memory management. I've also changed some global variables
to std::string accordingly (which store the result of these functions),
but not all because some are used with add_setshow_optional_filename_cmd
which requires a char*.

gdb/ChangeLog:

2019-09-11  Christian Biesinger  <cbiesinger@google.com>

	* auto-load.c (auto_load_expand_dir_vars): Update.
	* defs.h (gdb_datadir): Change to std::string.
	(python_libdir): Likewise.
	(relocate_gdb_directory): Change return type to std::string.
	* guile/guile.c (gdbscm_data_directory): Update.
	(initialize_scheme_side): Update.
	* jit.c (jit_reader_dir): Change to std::string.
	(jit_reader_load_command): Update.
	* main.c (gdb_datadir): Change to std::string.
	(python_libdir): Likewise.
	(set_gdb_data_directory): Update.
	(relocate_path): Change to return std::string.
	(relocate_gdb_directory): Change to return std::string.
	(relocate_gdbinit_path_maybe_in_datadir): Update.
	(captured_main_1): Update.
	* python/python.c (do_start_initialization): Update.
	* top.c (show_gdb_datadir): Update.
	* xml-syscall.c (xml_init_syscalls_info): Update.
	(init_syscalls_info): Update.
2019-09-11 16:31:36 -05:00
Christian Biesinger 9224a01377 Factor out the code to do the datadir-relocation for gdbinit
This simplifies get_init_files and makes it possible to reuse
this code in an upcoming patch for SYSTEM_GDBINIT_DIR.

gdb/ChangeLog:

2019-09-11  Christian Biesinger  <cbiesinger@google.com>

	* main.c (relocate_gdbinit_path_maybe_in_datadir): Factor this code
	out of get_init_files.
	(get_init_files): Update.
2019-09-11 16:30:00 -05:00
Christian Biesinger f48cd8368b Refactor get_init_files to use std::string
To avoid manual memory management.

Tested on buildbot.

gdb/ChangeLog:

2019-09-11  Christian Biesinger  <cbiesinger@google.com>

	* main.c (get_init_files): Change to use std::string.
	(captured_main_1): Update.
	(print_gdb_help): Update.
2019-09-11 16:29:10 -05:00
Ali Tamur 9cab7ecda2 Fix float to LONGEST conversion.
The code used to have undefined behaviour when template parameter is float and
host_float is NaN, because it attempted to convert NaN value to LONGEST at the
last statement. This frequently caused crashes on tests that checked "info
all-registers" (at least when the code is compiled with clang; I didn't test
with gdb).

gdb/ChangeLog:

	*target-float.c (host_float_ops<T>::to_longest): Update
	implementation.
2019-09-11 12:21:50 -07:00
Christian Biesinger 67547d896b Change the type of copy_names from int to bool
This parameter is really a boolean, so change the type accordingly
and update the callers.

This is for symbol_set_names, add_psymbol_to_bcache, and
add_psymbol_to_list.

minimal_symbol_reader::record_full was already passing a bool
to symbol_set_names.

gdb/ChangeLog:

2019-09-11  Christian Biesinger  <cbiesinger@google.com>

	* dbxread.c (read_dbx_symtab): Update.
	* dwarf2read.c (load_partial_dies): Update.
	* mdebugread.c (parse_partial_symbols): Update.
	(handle_psymbol_enumerators): Update.
	* psympriv.h (add_psymbol_to_list): Change type of copy_names to bool.
	* psymtab.c (add_psymbol_to_bcache): Likewise.
	(add_psymbol_to_list): Likewise.
	* symtab.c (symbol_set_names): Likewise.
	* symtab.h (symbol_set_names): Likewise.
	* xcoffread.c (scan_xcoff_symtab): Update.
2019-09-11 12:43:45 -05:00
Tom Tromey 64b2d4a0a4 Introduce bfd_set_filename
This introduces a new bfd_set_filename function, which is then used in
various spots in gdb.  This allows for the removal of some casts.

bfd/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

	* opncls.c (bfd_set_filename): New function.
	* bfd-in2.h: Regenerate.

gdb/ChangeLog
2019-09-11  Tom Tromey  <tom@tromey.com>

	* symfile-mem.c (symbol_file_add_from_memory): Use
	bfd_set_filename.
	* solib-darwin.c (darwin_bfd_open): Use bfd_set_filename.
	* solib-aix.c (solib_aix_bfd_open): Use bfd_set_filename.
2019-09-11 07:02:46 -06:00
Tom Tromey 2d60161648 Update "save gdb-index" documentation
This updates the "save gdb-index" documentation to reflect the new
state of Ada support.  It also corrects an existing grammatical error.

gdb/doc/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* gdb.texinfo (Index Files): Update Ada text.
2019-09-10 08:30:45 -06:00
Tom Tromey 8a51616424 Add Ada support to cc-with-tweaks.exp
This adds Ada support to the cc-with-tweaks.exp board file, so that we
can test Ada this way.  The cc-with-tweaks.sh script already works
reasonably well as a wrapper for gnatmake.

gdb/testsuite/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* boards/cc-with-tweaks.exp: Set GNATMAKE_FOR_TARGET.
2019-09-10 08:30:45 -06:00
Tom Tromey 3b00ef10a2 Add Ada support for .debug_names
This patch adds support for Ada to .debug_names.  I opted to leave
.gdb_index alone, because in my view it is a defunct format.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* dwarf-index-write.c (write_psymbols): Extend error message.
	(debug_names::insert): Add Ada code.
	(debug_names::write_psymbols): Remove Ada check.
	(debug_names) <m_string_obstack>: New member.
	* dwarf2read.c (gdb_index_symbol_name_matcher): Remove.
	(gdb_index_symbol_name_matcher::matches): Remove.
	(mapped_index_base::find_name_components_bounds): Add "lang"
	parameter.
	(mapped_index_base::build_name_components): Also split names
	according to Ada syntax.
	(dw2_expand_symtabs_matching_symbol): Loop over languages.  Change
	type of "match_callback".
	(check_match, check_find_bounds_finds)
	(dw2_expand_symtabs_matching): Update.
	(dw2_debug_names_iterator): Add new constructor.
	(dw2_debug_names_map_matching_symbols): New function.
	(dw2_debug_names_expand_symtabs_matching): Update.
	(dwarf2_debug_names_functions): Use
	dw2_debug_names_map_matching_symbols.
2019-09-10 08:30:45 -06:00
Tom Tromey aa39165480 Fix latent bug in .debug_names file-name handling
An internal Ada test case showed that the .debug_names code does not
compute the same list of file names as the partial symbol reader.  In
particular, the partial symbol reader uses the DW_AT_name of the CU:

  /* Allocate a new partial symbol table structure.  */
  filename = dwarf2_string_attr (comp_unit_die, DW_AT_name, cu);
  if (filename == NULL)
    filename = "";

  pst = create_partial_symtab (per_cu, filename);

This patch changes the .debug_names reader to follow.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c (dw2_get_file_names_reader): Add the
	CU's file name to the results.

gdb/testsuite/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/dgopt.exp: New file.
	* gdb.ada/dgopt/x.adb: New file.
2019-09-10 08:30:45 -06:00
Tom Tromey b054970d54 Change map_matching_symbols to take a lookup_name_info
This patch further simplifies the map_matching_symbols callback, by
having it take a lookup_name_info rather than a plain string.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (add_nonlocal_symbols): Combine calls to
	map_matching_symbols.  Update.
	* dwarf2read.c (dw2_map_matching_symbols): Update.
	* psymtab.c (match_partial_symbol): Change type; update.
	(psym_map_matching_symbols): Likewise.
	* symfile-debug.c (debug_qf_map_matching_symbols): Change
	type; update.
	* symfile.h (struct quick_symbol_functions)
	<map_matching_symbols>: Change "name" to be a lookup_name_info.
	Remove "match".
2019-09-10 08:30:45 -06:00
Tom Tromey 6a3dbf1bc6 Simplify psym_map_matching_symbols
This introduces a new helper function,
iterate_over_symbols_terminated, and changes psym_map_matching_symbols
to use it.  A subsequent patch will introduce a new user of this
function in the DWARF reader.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* psymtab.c (map_block): Remove.
	(psym_map_matching_symbols): Use iterate_over_symbols_terminated.
	* symtab.c (iterate_over_symbols_terminated): New function.
	* symtab.c (iterate_over_symbols_terminated): Declare.
2019-09-10 08:30:45 -06:00
Tom Tromey 6969f124b9 Change iterate_over_symbols to return bool
This changes iterate_over_symbols to return a bool.  This allows it to
be reused in another context in a subsequent patch.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_iterate_over_symbols): Return bool.
	* language.h (struct language_defn) <la_iterate_over_symbols>:
	Return bool.
	* symtab.c (iterate_over_symbols): Return bool.
	* symtab.h (iterate_over_symbols): Return bool.
2019-09-10 08:30:45 -06:00
Tom Tromey 199b4314ef Change map_matching_symbols to take a symbol_found_callback_ftype
This changes map_matching_symbols to take a
symbol_found_callback_ftype, rather than separate callback and data
parameters.  This enables a future patch to clean up some existing
code so that it can more readily be shared.

gdb/ChangeLog
2019-09-10  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (aux_add_nonlocal_symbols): Change type.
	(add_nonlocal_symbols): Update.
	* dwarf2read.c (dw2_map_matching_symbols): Change type.
	* psymtab.c (map_block, psym_map_matching_symbols): Change type.
	* symfile-debug.c (debug_qf_map_matching_symbols): Change type.
	* symfile.h (struct quick_symbol_functions) <map_matching_symbols>:
	Change type of "callback".  Remove "data".
2019-09-10 08:30:45 -06:00
Ali Tamur a084a2a6a1 DWARF 5 support: Handle dwo_id
* DW_UT_skeleton and DW_UT_split_compile compilation units have dwo ids
to match the compilation unit in the skeleton and .dwo files. The dwo_id is
in the header.

Tested with CC=/usr/bin/gcc (version 8.3.0) against master branch (also with
-gsplit-dwarf and -gdwarf-4 flags) and there was no increase in the set of
tests that fails.

This is part of an effort to support DWARF 5 in gdb.

gdb/ChangeLog:

        * dwarf2read.c (comp_unit_head): Update comment.
        (dwarf2_dwo_name): New function declaration.
        (dwarf_unit_type_name): New function declaration.
        (read_comp_unit_head): Add support for new compilation units,
        DW_UT_partial, DW_UT_skeleton, DW_UT_split_compile, DW_UT_split_type.
        Particularly, DW_UT_skeleton and DW_UT_split_compile have dwo_id
        (currently named as "signature") in their header. Also clarify error
        messages.
        (lookup_dwo_id): New function. Returns the dwo id of the given
        compile unit.
        (lookup_dwo_unit): Use the new lookup_dwo_id function.
        (init_cutu_and_read_dies): Use the new dwarf2_dwo_name and lookup_dwo_id
        functions.
        (create_dwo_cu_reader): Use the added lookup_dwo_id function.
        (dwarf2_dwo_name): Get the dwo name if present.
        (dwarf_unit_type_name): Convert DW_UT_* types to string for diagnostic
        purposes.
2019-09-09 18:35:43 -07:00
Tom Tromey 25a2915e8d Use ui_out for "info win"
This changes the "info win" command to use ui-out.  This yields
somewhat nicer table output.

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

	* tui/tui-win.c (tui_all_windows_info): Use ui_out.
2019-09-09 17:06:22 -06:00
Philippe Waroquiers e4df087431 Fix leak detected in python.c initialization code.
Valgrind reports the below leak.
Make the variable progname_copy static, so that Valgrind continues
to find a pointer to the memory given to Python.
Note that the comment in do_start_initialization and the Python documentation
indicates that the progname given to Py_SetProgramName cannot be freed.
However, in Python 3.7.4, Py_SetProgramName does:
void
Py_SetProgramName(const wchar_t *program_name)
{
    ...
    PyMem_RawFree(_Py_path_config.program_name);
    _Py_path_config.program_name = _PyMem_RawWcsdup(program_name);

So, it looks like 3.7.4 Python duplicates its argument, which explains
the leak found by Valgrind.
It looks better to respect the doc and not have GDB freeing the string
given to Py_SetProgramName, and avoid the leak error by declaring
the progname_copy static.
This will work with Python versions that really use this string without
duplicating it, and avoids a leak report for Python version that duplicates
it.

==4023== 200 bytes in 1 blocks are definitely lost in loss record 4,545 of 7,116^M
==4023==    at 0x4C29F33: malloc (vg_replace_malloc.c:307)^M
==4023==    by 0x446D27: xmalloc (alloc.c:60)^M
==4023==    by 0x657C77: do_start_initialization (python.c:1610)^M
==4023==    by 0x657C77: _initialize_python() (python.c:1823)^M
==4023==    by 0x75FE24: initialize_all_files() (init.c:231)^M
==4023==    by 0x708A94: gdb_init(char*) (top.c:2242)^M
==4023==    by 0x5E7460: captured_main_1 (main.c:857)^M
==4023==    by 0x5E7460: captured_main (main.c:1161)^M
==4023==    by 0x5E7460: gdb_main(captured_main_args*) (main.c:1186)^M
==4023==    by 0x4122D4: main (gdb.c:32)^M

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

	* python/python.c (do_start_initialization): Make progname_copy static,
	to avoid a leak report.
2019-09-09 23:50:37 +02:00
Tom Tromey 8634b4628e Truncate long TUI window titles
If a TUI window has a long title, it can overflow the title line.
This changes the TUI to use just the tail part of the title in this
case.

gdb/ChangeLog
2019-09-08  Tom Tromey  <tom@tromey.com>

	* tui/tui-wingeneral.c (box_win): Truncate long window titles.

gdb/testsuite/ChangeLog
2019-09-08  Tom Tromey  <tom@tromey.com>

	* gdb.tui/resize.exp: Remove setup_xfail.
	* gdb.tui/regs.exp: Remove setup_xfail.
	* gdb.tui/basic.exp: Remove setup_xfail.
2019-09-08 14:06:54 -06:00
Simon Marchi c7f839cbf0 Change lookup_symbol's block_index parameter type to block_enum
The only two values valid to pass to the block_index parameter of
quick_symbol_functions::lookup_symbol are GLOBAL_BLOCK and STATIC_BLOCK,
part of enum block_enum.  Change the type of that parameter to
block_enum.

Change also the block_index field of dw2_symtab_iterator in the same
way..  This makes it consistent with dw2_debug_names_iterator, which
already uses block_enum for its block_index field.

This is a follow-up to this thread:

https://sourceware.org/ml/gdb-patches/2019-08/msg00097.html

gdb/ChangeLog:

	* dwarf2read.c (struct dw2_symtab_iterator) <block_index>:
	Change type to gdb::optional<block_enum>.
	(dw2_symtab_iter_init): Change block_index parameter type
	to gdb::optional<block_enum>.
	(dw2_lookup_symbol): Change block_index parameter
	type to block_enum.c
	(dw2_debug_names_lookup_symbol): Likewise.
	* psymtab.c (psym_lookup_symbol): Likewise.
	* symfile-debug.c (debug_qf_lookup_symbol): Likewise.
	* symfile.h (struct quick_symbol_functions) <lookup_symbol>:
	Likewise.
2019-09-07 12:06:01 -04:00
David Blaikie 736b0f7618 un-XFAIL under Clang tests using labels
gdb/testsuite/
	* gdb.base/label.exp: un-XFAIL label related tests under Clang.
	* gdb.cp/cplabel.exp: Ditto.
	* gdb.linespec/ls-errs.exp: Ditto.
2019-09-06 14:17:36 -07:00
Christian Biesinger ead0e69a4a Change int to bool for the relocate_* functions
These parameters are only used as bools. This also
renames "flag" to "relocatable" to make it clearer
what it does.

gdb/ChangeLog:

2019-09-06  Christian Biesinger  <cbiesinger@google.com>

	* defs.h (relocate_gdb_directory): Change int to bool in
	signature and rename flag to relocatable.
	* main.c (relocate_path): Likewise.
	(relocate_gdb_directory): Likewise.
2019-09-06 14:34:00 -05:00
Alan Modra b16c44debc bfd_get_filename
This macro says:
/* Cast from const char * to char * so that caller can assign to
   a char * without a warning.  */

I reckon that isn't such a good idea since it can result in char*
variables where const char* is appropriate.  Not very many places
need the char* cast.

bfd/
	* aout-target.h (object_p): Formatting.
	* bfd-in.h (bfd_get_filename): Don't cast to char*.
	* corefile.c (generic_core_file_matches_executable_p): Constify
	variables and remove cast.
	* bfd-in2.h: Regenerate.
binutils/
	* nm.c (print_object_filename_bsd, print_object_filename_sysv),
	(print_object_filename_posix, print_archive_filename_bsd),
	(print_archive_filename_sysv, print_archive_filename_posix),
	(print_archive_member_bsd, print_archive_member_sysv),
	(print_archive_member_posix): Constify parameter.
	(struct output_fns <print_object_filename, print_archive_filename>),
	(<print_archive_member>): Likewise.
	* objcopy.c (copy_archive): Add cast for make_tempdir.
ld/
	* emultempl/elf32.em (gld${EMULATION_NAME}_search_needed): Constify
	variable.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
gdb/
	* coffread.c (coff_symfile_read): Constify filename variable.
	* dbxread.c (dbx_symfile_init, coffstab_build_psymtabs),
	(elfstab_build_psymtabs, stabsect_build_psymtabs): Likewise.
	* gdb_bfd.c (gdb_bfd_close_or_warn): Likewise.
	* solib.c (reload_shared_libraries_1): Likewise.
	* symfile.c (reread_symbols): Likewise.
	* solib-aix.c (solib_aix_bfd_open): Add cast for xfree of filename.
	* solib-darwin.c (darwin_bfd_open): Likewise.
	* symfile-mem.c (symbol_file_add_from_memory): Likewise.
sim/cris/
	* sim-if.c (sim_open): Constify filename variable.
2019-09-06 12:22:59 +09:30
Tom de Vries 30331a6ca0 [gdb/testsuite] Restore breakpoint command in ui-redirect.exp
In gdb.base/ui-redirect.exp, the "save breakpoint" command is used to write
the current breakpoints to a file, but the actual output is not verified.

Consequently, the test has regressed in that the "print 1" command associated
with a breakpoint on main is removed by a subsequent runto_main, which first
deletes all breakpoints:
...
(gdb) break main
Breakpoint 1 at 0x4004d7: file start.c, line 34.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
> PASS: gdb.base/ui-redirect.exp: commands
print 1
> PASS: gdb.base/ui-redirect.exp: print 1
end
(gdb) PASS: gdb.base/ui-redirect.exp: end
delete breakpoints
Delete all breakpoints? (y or n) y
...
and consequently the "save breakpoint" output is missing the breakpoint
command for main:
...
 break main
-  commands
-    print 1
-  end
 break foo
 break bar
...

Fix this by replacing "gdb_breakpoint main" with runto_main, and verifying the
"save breakpoints" output.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2019-09-05  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (cmp_file_string): New proc.
	* gdb.base/ui-redirect.exp: Replace "gdb_breakpoint main" with
	runto_main.  Verify save breakpoints output.
2019-09-05 14:33:10 +02:00