Commit Graph

44766 Commits

Author SHA1 Message Date
Simon Marchi 00ac85d375 gdb: is_linked_with_cygwin_dll: handle import table not at beginning of .idata section
When loading the file C:\Windows\SysWOW64\msvcrt.dll, taken from a
Windows 10 system, into GDB, we get the following warning:

    warning: Failed to parse .idata section: name's virtual address (0x0) is outside .idata section's range [0xb82b8, 0xb97f0[.

This uncovers an issue with how we parse the import table, part of the
.idata section.  Right now, we assume that the import table is located
at the beginning of the section.  That was the case in everything I had
tried so far, but this file is an example where that's not true.

We need to compute the offset of the import table within the .idata
section, and start there, instead of at the beginning of the .idata
section.  Using the file mentioned above, this is the values we have to
work with:

  A) bfd_section_vma (idata_section)    101b8000
  B) Import table's virtual address        b82b8
  C) Image base                         10100000

The virtual address that BFD returns us for the section has the image
base applied, so we need to subtract it first.  The offset of the table
in the section is therefore:

    B - (A - C)

This patch implements that.

gdb/ChangeLog:

	* windows-tdep.c (is_linked_with_cygwin_dll): Consider case where
	import table is not at beginning of .idata section.
2020-04-16 15:46:36 -04:00
Pedro Alves 381ce63f2f Refactor delete_program_space as a destructor
Currently, while the program_space's ctor adds the new pspace to the
pspaces list, the destructor doesn't remove the pspace from the pspace
list.  Instead, you're supposed to use delete_program_space, to both
remove the pspace from the list, and deleting the pspace.

This patch eliminates delete_program_space, and makes the pspace dtor
remove the deleted pspace from the pspace list itself, i.e., makes the
dtor do the mirror opposite of the ctor.

I found this helps with a following patch that will allocate a mock
program_space on the stack.  It's easier to just let the regular dtor
remove the mock pspace from the pspace list than arrange to call
delete_program_space instead of the pspace dtor in that situation.

While at it, move the ctor/dtor intro comments to the header file, and
make the ctor explicit.

gdb/ChangeLog:
2020-04-16  Pedro Alves  <palves@redhat.com>

	* inferior.c (delete_inferior): Use delete operator directly
	instead of delete_program_space.
	* progspace.c (add_program_space): New, factored out from
	program_space::program_space.
	(remove_program_space): New, factored out from
	delete_program_space.
	(program_space::program_space): Remove intro comment.  Rewrite.
	(program_space::~program_space): Remove intro comment.  Call
	remove_program_space.
	(delete_program_space): Delete.
	* progspace.h (program_space::program_space): Make explicit.  Move
	intro comment here, adjusted.
	(program_space::~program_space): Move intro comment here,
	adjusted.
	(delete_program_space): Remove.
2020-04-16 14:50:07 +01:00
Tom Tromey a010605fef Fix Cygwin gdb build
Simon pointed out that the windows-nat sharing series broke the Cygwin
build.  This patch fixes the problem, by moving the Cygwin-specific
code to a new handler function.  This approach is taken because this
code calls find_pc_partial_function, which isn't available in
gdbserver.

gdb/ChangeLog
2020-04-16  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat::handle_access_violation): New
	function.
	* nat/windows-nat.h (handle_access_violation): Declare.
	* nat/windows-nat.c (handle_exception): Move Cygwin code to
	windows-nat.c.  Call handle_access_violation.

gdbserver/ChangeLog
2020-04-16  Tom Tromey  <tromey@adacore.com>

	* win32-low.cc (windows_nat::handle_access_violation): New
	function.
2020-04-16 07:24:57 -06:00
Tom de Vries efba5c2319 [gdb/symtab] Handle PU without import in "save gdb-index"
Consider the test-case added in this patch, with resulting dwarf:
...
  Compilation Unit @ offset 0xc7:
   Length:        0x2c (32-bit)
   Version:       4
   Abbrev Offset: 0x64
   Pointer Size:  8
 <0><d2>: Abbrev Number: 2 (DW_TAG_partial_unit)
    <d3>   DW_AT_language    : 2        (non-ANSI C)
    <d4>   DW_AT_name        : imported_unit.c
 <1><e4>: Abbrev Number: 3 (DW_TAG_base_type)
    <e5>   DW_AT_byte_size   : 4
    <e6>   DW_AT_encoding    : 5        (signed)
    <e7>   DW_AT_name        : int
 <1><eb>: Abbrev Number: 4 (DW_TAG_subprogram)
    <ec>   DW_AT_name        : main
    <f1>   DW_AT_type        : <0xe4>
    <f5>   DW_AT_external    : 1
 <1><f6>: Abbrev Number: 0
  Compilation Unit @ offset 0xf7:
   Length:        0x2c (32-bit)
   Version:       4
   Abbrev Offset: 0x85
   Pointer Size:  8
 <0><102>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <103>   DW_AT_language    : 2       (non-ANSI C)
    <104>   DW_AT_name        : <artificial>
 <1><111>: Abbrev Number: 3 (DW_TAG_subprogram)
    <112>   DW_AT_abstract_origin: <0xeb>
    <116>   DW_AT_low_pc      : 0x4004a7
    <11e>   DW_AT_high_pc     : 0x4004b2
 <1><126>: Abbrev Number: 0
...

When run with target board cc-with-gdb-index, we run into:
...
(gdb) break main
warning: (Internal error: pc 0x4004a7 in read in CU, but not in symtab.)
<repeat>
warning: (Internal error: pc 0x4004ab in read in CU, but not in symtab.)
<repeat>
Breakpoint 1 at 0x4004ab
(gdb) PASS: gdb.dwarf2/imported-unit-runto-main.exp: setting breakpoint at main
run
Starting program: /data/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/imported-unit-runto-main/imported-unit-runto-main
warning: (Internal error: pc 0x4004a7 in read in CU, but not in symtab.)
<repeat>
warning: (Internal error: pc 0x4004ab in read in CU, but not in symtab.)
<repeat>

Breakpoint 1, warning: (Internal error: pc 0x4004ab in read in CU, but not in symtab.)
warning: (Internal error: pc 0x4004ab in read in CU, but not in symtab.)
<repeat>
0x00000000004004ab in main ()
warning: (Internal error: pc 0x4004ab in read in CU, but not in symtab.)
<repeat>
(gdb) FAIL: gdb.dwarf2/imported-unit-runto-main.exp: running to main in runto
...

Looking at the .gdb_index section contents using objdump --dwarf=gdb_index, we
have:
...
CU table:
[  0] 0x0 - 0x2d
[  1] 0x2e - 0xa4
[  2] 0xa5 - 0xc6
[  3] 0xf7 - 0x126
[  4] 0x127 - 0x2de
[  5] 0x2df - 0x300

Address table:
00000000004004a7 00000000004004b2 4

Symbol table:
[489] main: 4 [global, function]
...
We see that both the main symbol, and main address range map to CU 4, which has
offset range 0x127 - 0x2de, while main actually is contained in CU 3 at offset
range 0xf7 - 0x126.

This is caused by this continue in write_gdbindex, which triggers for the PU:
...
      /* CU of a shared file from 'dwz -m' may be unused by this main file.
        It may be referenced from a local scope but in such case it does not
        need to be present in .gdb_index.  */
      if (psymtab == NULL)
       continue;
...
The continue causes the PU to be skipped in the CU table (we can see that the
PU offset range 0xc7-0xf6 is missing) but the references are not taking that
into account.

I've tried fixing this in the optimal way, by updating the references, but ran
into trouble when follow_die_offset tries to find the CU for the inter-CU
ref.  Because the PU is missing from the CU table,
dwarf2_find_containing_comp_unit bisects to the wrong CU.

Fix this by not skipping the PU in the CU table.

Build and reg-tested on x86_64-linux, with native and target boards
cc-with-gdb-index, cc-with-dwz and cc-with-dwz-m.

gdb/ChangeLog:

2020-04-16  Tom de Vries  <tdevries@suse.de>

	PR symtab/25791
	* dwarf2/index-write.c (write_gdbindex): Generate CU table entries for
	CUs without psymtab.

gdb/testsuite/ChangeLog:

2020-04-16  Tom de Vries  <tdevries@suse.de>

	PR symtab/25791
	* gdb.dwarf2/gdb-add-index.exp (add_gdb_index): Move ...
	(ensure_gdb_index): and factor out and move ...
	* lib/gdb.exp (add_gdb_index, ensure_gdb_index): ... here.
	* gdb.dwarf2/imported-unit-runto-main.exp: New file.
2020-04-16 14:56:32 +02:00
Kevin Buettner 97ed802d15 Fix compilation of python/python.c for Python 3.9
This commit fixes a compilation warning/error when building GDB
with Python 3.9:

g++ -x c++  -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -DDNF_DEBUGINFO_INSTALL   -I. -I../../gdb -I../../gdb/config -DLOCALEDIR="\"/usr/share/locale\"" -DHAVE_CONFIG_H -I../../gdb/../include/opcode   -I../bfd -I../../gdb/../bfd -I../../gdb/../include -I../libdecnumber -I../../gdb/../libdecnumber  -I../../gdb/../gnulib/import -I../gnulib/import  -DTUI=1    -I/usr/include/guile/2.0 -pthread  -I/usr/include/python3.9 -I/usr/include/python3.9  -I../../gdb/.. -pthread -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-variable -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-error=maybe-uninitialized -Wno-mismatched-tags -Wsuggest-override -Wimplicit-fallthrough=3 -Wduplicated-cond -Wshadow=local -Wdeprecated-copy -Wdeprecated-copy-dtor -Wredundant-move -Wformat -Wformat-nonliteral -Wno-unused -Werror -c -o ser-tcp.o -MT ser-tcp.o -MMD -MP -MF ./.deps/ser-tcp.Tpo ../../gdb/ser-tcp.c
../../gdb/python/python.c: In function 'bool do_start_initialization()':
../../gdb/python/python.c:1621:23: error: 'void PyEval_InitThreads()' is deprecated [-Werror=deprecated-declarations]
 1621 |   PyEval_InitThreads ();
      |                       ^
In file included from /usr/include/python3.9/Python.h:141,
                 from ../../gdb/python/python-internal.h:86,
                 from ../../gdb/python/python.c:92:
/usr/include/python3.9/ceval.h:132:37: note: declared here
  132 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
      |                                     ^~~~~~~~~~~~~~~~~~

Information about the deprecated function can be found here:

https://docs.python.org/3.9/whatsnew/3.9.html#deprecated

Specifically, with regard to PyEval_InitThreads(), it says:

    The PyEval_InitThreads() and PyEval_ThreadsInitialized() functions
    are now deprecated and will be removed in Python 3.11.  Calling
    PyEval_InitThreads() now does nothing.  The GIL is initialized by
    Py_Initialize() since Python 3.7.  (Contributed by Victor Stinner
    in bpo-39877.)

I chose to disable the call with a #if test using PY_VERSION_HEX.
There is precedent for use of PY_VERSION_HEX; it's used in two places
in python-internal.h.  I noticed that under certain circumstances
python-internal.h defines PyEval_InitThreads to be nothing, which
accomplishes the same thing.  I considered doing something similar for
this case, but decided against it because, at some point in the future,
the presence of PyEval_InitThreads() without some explanation will be
confusing to a reader who won't be able to find PyEval_InitThreads in
the current (future for us) Python API.  IMO, use of the #if along
with an accompanying comment seemed more straightforward.

gdb/ChangeLog:

	* python/python.c (do_start_initialization): Don't call
	PyEval_InitThreads for Python 3.9 and beyond.

Change-Id: I0679fc10b6b76761a99538568f13188c6d8014e0
2020-04-16 05:13:47 -07:00
Tom de Vries d191d716f3 [gdb/testsuite] Fix maint-expand-symbols-header-file.exp for cc-with-gdb-index
With test-case gdb.base/maint-expand-symbols-header-file.exp and target board
cc-with-gdb-index, we have:
...
FAIL: gdb.base/maint-expand-symbols-header-file.exp: \
  verify no symtabs are expanded
...

By default, with partial symbols, we find the main function in the partial
symbols, and derive the initial language setting from that, without expanding
any psymtab.

But that doesn't work with the indices, because the indices don't store the
language with the symbols.  So instead, the main psymtab is expanded to get
the language of main, which causes the FAIL.

Fix this by manually setting the language.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-04-16  Tom de Vries  <tdevries@suse.de>

	* gdb.base/maint-expand-symbols-header-file.exp: Set language before
	loading exec.
2020-04-16 08:40:19 +02:00
Kamil Rytarowski c7d6480903 Fix OpenBSD build error.
This was likely introduced by 5b6d1e4fa4

gdb/ChangeLog:

2020-04-15  Kamil Rytarowski  <n54@gmx.com>

	* obsd-nat.c (obsd_nat_target::update_thread_list): Pass "this" to
	thread functions.
	(obsd_nat_target::wait): Likewise.

Change-Id: Ib8d11238c55e0ebdbcf127d1f28c9693c785527a
2020-04-15 14:59:44 -05:00
Tom Tromey ce127a96c9 Use debug_printf in windows-nat.c
While debugging a bug on Windows, I noticed that windows-nat.c is not
sending its debugging output to gdb_stdlog.  This is unfortunate
because it means that "set logging debugredirect" doesn't work
properly.

This patch fixes the problem by changing windows-nat.c to use
debug_printf.

Note that get_windows_debug_event also writes one debugging message
unconditionally.  It isn't clear to me if this really ought to use
DEBUG_EVENTS or not, since it seems like perhaps it is intended to
note an unexpected event occurring.  So, I didn't change this.

I'm checking this in.

gdb/ChangeLog
2020-04-15  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (DEBUG_EXEC, DEBUG_EVENTS, DEBUG_MEM)
	(DEBUG_EXCEPT): Use debug_printf.
2020-04-15 12:49:05 -06:00
Andrew Burgess 99f1bc6aaa gdb: Don't corrupt completions hash when expanding the hash table
Commit:

  commit 724fd9ba43
  Date:   Mon Jan 27 17:37:20 2020 +0000

      gdb: Restructure the completion_tracker class

caused the completion hash table to become corrupted if the table ever
needed to grow beyond its original size of 200 elements.

The hash table stores completion_tracker::completion_hash_entry
objects, but hashes them based on their name, which is only one field
of the object.

When possibly inserting a new element we compute the hash with
htab_hash_string of the new elements name, and then lookup matching
elements using htab_find_slot_with_hash.  If there's not matching
element we create a completion_hash_entry object within the hash
table.

However, when we allocate the hash we pass htab_hash_string to
htab_create_alloc as the hash function, and this is not OK.  This
means that when the hash table needs to grow, existing elements within
the hash are re-hashed by passing the completion_hash_entry pointer to
htab_hash_string, which obviously does not do what we expect.

The solution is to create a new hash function that takes a pointer to
a completion_hash_entry, and then calls htab_hash_string on the name
of the entry only.

This regression was spotted when running the gdb.base/completion.exp
test on the aarch64 target.

gdb/ChangeLog:

	* completer.c (class completion_tracker::completion_hash_entry)
	<hash_name>: New member function.
	(completion_tracker::discard_completions): New callback to hash a
	completion_hash_entry, pass this to htab_create_alloc.

gdb/testsuite/ChangeLog:

	* gdb.base/many-completions.exp: New file.
2020-04-15 16:36:28 +01:00
Jon Turney a0e9b53238
Better handling of realpath() failure in windows_make_so() on Cygwin
It seems Cygwin's realpath() can fail on certain DLLs (apparently some
AV software prevent it working on it's DLLs; See [1], [2]).  Warn rather
than stopping with an error if that occurs.

Based on an original patch from Tim Chick.

[1] https://cygwin.com/ml/cygwin/2014-08/msg00401.html
[2] https://cygwin.com/ml/cygwin/2015-11/msg00353.html

gdb/ChangeLog:

2016-01-20  Jon Turney  <jon.turney@dronecode.org.uk>

	* windows-nat.c (windows_make_so): Warn rather than stopping with
	an error if realpath() fails.
2020-04-15 15:07:02 +01:00
Artur Shepilko 0ca4866abe Fix makeinfo warnings in gdb.texinfo and python.texi docs
Building gdb-9.1 on a system that has an older version of makeinfo
(4.8) shows the following warnings:

-----------------
make[4]: Entering directory '/home/tester/gdb-9.1/build/gdb/doc'
makeinfo --split-size=5000000 --split-size=5000000   -I
../../../gdb/doc/../../readline/readline/doc -I ../../../gdb/doc/../mi
-I ../../../gdb/doc \
    -o gdb.info ../../../gdb/doc/gdb.texinfo
../../../gdb/doc/gdb.texinfo:21867: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21867: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21868: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21868: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21869: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21869: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21872: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21872: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21874: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21874: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21876: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21876: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21879: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21879: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21931: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21931: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21933: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21933: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21936: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21936: warning: unlikely character ] in @var.
../../../gdb/doc/gdb.texinfo:21939: warning: unlikely character [ in @var.
../../../gdb/doc/gdb.texinfo:21939: warning: unlikely character ] in @var.
../../../gdb/doc//python.texi:3297: warning: `.' or `,' must follow
@xref, not `A'.
make[4]: Leaving directory '/home/tester/gdb-9.1/build/gdb/doc'
-----------------

These are thrown by expressions like `@var{[host]}`, intended to
produce `[HOST]`.

In that context this should instead be changed to `[@var{host}]`, which
has the same effect but without the warnings.

As for the warning in `python.texi`, there's period missing at the end
of one `@xref{}` clause.  Added.

gdb/doc/ChangeLog:

2020-04-15  Artur Shepilko  <nomadbyte@gmail.com>

	* gdb.texinfo: Transform @var{[host]} to [@var{host}]; this
	clears makeinfo warnings.
	* python.texi: Add a missing period trailing an @xref{} clause;
	this clears a makeinfo warning.
2020-04-15 09:44:12 +02:00
Kamil Rytarowski 06ca5dd49a Implement IP_STAT+IP_STATUS (aliases of the same format) on NetBSD
Output based on FreeBSD with the following changes:
 - "utime+stime, children" merged from "utime, children" and
   "stime, children".
 - "Minor faults, children", "Major faults, children",
   "Virtual memory size" removed as not available in a direct
   equivalent.

No new values missing or skipped in FreeBSD are printed, although
there is a long list of potential candiates.

gdb/ChangeLog:

        * nbsd-nat.c (nbsd_pid_to_kinfo_proc2): New.
        (nbsd_nat_target::info_proc): Add do_status.
2020-04-14 17:35:56 +02:00
Tom de Vries 194d088fb1 [gdb] Fix missing symtab includes
[ The test-case requires commit c1a66c0629 "[gdb] Expand symbolless symtabs
using maint expand-symtabs". ]

Consider the debug info for the test-case included in this patch.  It consists
of a PU:
...
 <0><d2>: Abbrev Number: 2 (DW_TAG_partial_unit)
 <1><d3>: Abbrev Number: 0
...
imported by a CU:
...
 <0><df>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <e0>   DW_AT_language    : 2        (non-ANSI C)
    <e1>   DW_AT_stmt_list   : 0xe9
 <1><e5>: Abbrev Number: 3 (DW_TAG_imported_unit)
    <e6>   DW_AT_import      : <0xd2>   [Abbrev Number: 2]
 <1><ea>: Abbrev Number: 0
...
and the CU has a dw2-symtab-includes.h file in the .debug_line file name
table:
...
 The Directory Table (offset 0x101):
  1     /data/gdb_versions/devel/src/gdb/testsuite/gdb.dwarf2

 The File Name Table (offset 0x138):
  Entry Dir     Time    Size    Name
  1     1       0       0       dw2-symtab-includes.h
...

After expanding all symtabs, we can see the CU listed in the user field of the
PU, and vice-versa the PU listed in the includes of the CU:
...
$ gdb.sh -batch \
  -iex "set language c" \
  outputs/gdb.dwarf2/dw2-symtab-includes/dw2-symtab-includes \
  -ex "maint expand-symtabs" \
  -ex "maint info symtabs"
  ...
  { ((struct compunit_symtab *) 0x394dd60)
    debugformat DWARF 2
    producer (null)
    dirname (null)
    blockvector ((struct blockvector *) 0x394dea0)
    user ((struct compunit_symtab *) 0x394dba0)
  }
  { ((struct compunit_symtab *) 0x394dba0)
    debugformat DWARF 2
    producer (null)
    dirname (null)
    blockvector ((struct blockvector *) 0x394dd10)
    user ((struct compunit_symtab *) (null))
    ( includes
      ((struct compunit_symtab *) 0x394dd60)
    )
  }
...

But if we instead only expand the symtab for the dw2-symtab-includes.h file,
the includes and user links are gone:
...
$ gdb -batch \
  -iex "set language c" \
  outputs/gdb.dwarf2/dw2-symtab-includes/dw2-symtab-includes \
  -ex "maint expand-symtabs dw2-symtab-includes.h" \
  -ex "maint info symtabs"
  ...
  { ((struct compunit_symtab *) 0x2728210)
    debugformat DWARF 2
    producer (null)
    dirname (null)
    blockvector ((struct blockvector *) 0x2728350)
    user ((struct compunit_symtab *) (null))
  }
  { ((struct compunit_symtab *) 0x2728050)
    debugformat DWARF 2
    producer (null)
    dirname (null)
    blockvector ((struct blockvector *) 0x27281c0)
    user ((struct compunit_symtab *) (null))
  }
...

The includes are calculated by process_cu_includes in gdb/dwarf2/read.c.

In the case of expanding all symtabs:
- the CU partial symtab is expanded using psymtab_to_symtab
- psymtab_to_symtab calls dwarf2_psymtab::read_symtab
- dwarf2_psymtab::read_symtab calls dwarf2_psymtab::expand_psymtab
- dwarf2_psymtab::read_symtab calls process_cu_includes, and we have the
  includes

In the case of expanding the symtab for dw2-symtab-includes.h:
- the dw2-symtab-includes.h partial symtab is expanded using psymtab_to_symtab
- psymtab_to_symtab calls dwarf2_include_psymtab::read_symtab
- dwarf2_include_psymtab::read_symtab calls
  dwarf2_include_psymtab::expand_psymtab
- dwarf2_include_psymtab::expand_psymtab calls
  partial_symtab::expand_dependencies
- partial_symtab::expand_dependencies calls dwarf2_psymtab::expand_psymtab
  for the CU partial symtab
- the CU partial symtab is expanded using dwarf2_psymtab::expand_psymtab
- process_cu_includes is never called

Fix this by making sure in dwarf2_include_psymtab::read_symtab that
read_symtab is called for the CU partial symtab.

Tested on x86_64-linux, with native, and target board cc-with-dwz and
cc-with-dwz-m.

In addition, tested test-case with target boards cc-with-gdb-index.exp,
cc-with-debug-names.exp and readnow.exp.

gdb/ChangeLog:

2020-04-14  Simon Marchi  <simon.marchi@polymtl.ca>
	    Tom de Vries  <tdevries@suse.de>

	PR symtab/25718
	* psympriv.h (struct partial_symtab::read_symtab)
	(struct partial_symtab::expand_psymtab)
	(struct partial_symtab::read_dependencies): Update comments.
	* dwarf2/read.c (struct dwarf2_include_psymtab::read_symtab): Call
	read_symtab for includer.
	(struct dwarf2_include_psymtab::expand_psymtab): Assert false.
	(struct dwarf2_include_psymtab::readin_p): Call readin_p () for includer.
	(struct dwarf2_include_psymtab::m_readin): Remove.
	(struct dwarf2_include_psymtab::includer): New member function.
	(dwarf2_psymtab::expand_psymtab): Assert !readin.

gdb/testsuite/ChangeLog:

2020-04-14  Tom de Vries  <tdevries@suse.de>

	PR symtab/25718
	* gdb.dwarf2/dw2-symtab-includes.exp: New file.
2020-04-14 15:30:50 +02:00
Tom de Vries c1a66c0629 [gdb] Expand symbolless symtabs using maint expand-symtabs
Consider this test-case, consisting of header file hello.h:
...
inline static const char*
foo (void)
{
  return "foo";
}
...
and source file hello.c:
...
int
main (void)
{
  printf ("hello: %s\n", foo ());
  return 0;
}
...
compiled with -g:
...
$ gcc hello.c -g
...

When trying to expand the partial symtab for hello.h:
...
$ gdb -batch \
  -iex "set language c" \
  a.out \
  -ex "maint expand-symtabs hello.h" \
  -ex "maint info psymtabs"
...
we in fact find that the partial symtab for hello.h (and corresponding
includer partial symtab hello.c) have not been expanded:
...
  { psymtab hello.h ((struct partial_symtab *) 0x27cf070)
    readin no
  ...
  { psymtab hello.c ((struct partial_symtab *) 0x2cf09e0)
    readin no
...

This is due to the recursively_search_psymtabs call in
psym_expand_symtabs_matching:
...
      if (recursively_search_psymtabs (ps, objfile, domain,
                                      lookup_name, symbol_matcher))
...
which always returns false for symbolless partial symtabs.

The same problem occurs with CUs where the dwarf is generated by gas
--gdwarf-2 for a foo.S: if we read such a test-case with -readnow, we'll have
a symbolless symtab for foo.S.  But if we read the test-case with partial
symtabs, and expand those using "maint expand-symtabs", the foo.S psymtab
remains unexpanded.

Fix this by passing a NULL symbol_matcher and lookup_name to
expand_symtabs_matching in maintenance_expand_symtabs, and skipping the call
to recursively_search_psymtabs if symbol_matcher == NULL and
lookup_name == NULL.

Build and tested on x86_64-linux, with native.

In addition, tested test-case with target boards cc-with-gdb-index.exp,
cc-with-debug-names.exp and readnow.exp.

gdb/ChangeLog:

2020-04-14  Tom de Vries  <tdevries@suse.de>

	PR symtab/25720
	* symmisc.c (maintenance_expand_symtabs): Call expand_symtabs_matching
	with NULL symbol_matcher and lookup_name.
	* psymtab.c (psym_expand_symtabs_matching): Handle NULL symbol_matcher
	and lookup_name.
	* dwarf2/read.c (dw2_expand_symtabs_matching)
	(dw2_debug_names_expand_symtabs_matching): Same.
	* symfile.h (struct quick_symbol_functions::expand_symtabs_matching):
	Make lookup_name a pointer.  Update comment.
	* symtab.c (global_symbol_searcher::expand_symtabs): Handle
	lookup_name being a pointer.
	* symfile.c (expand_symtabs_matching): Same.
	* symfile-debug.c (debug_qf_expand_symtabs_matching): Same.
	* linespec.c (iterate_over_all_matching_symtabs): Same.

gdb/testsuite/ChangeLog:

2020-04-14  Tom de Vries  <tdevries@suse.de>

	PR symtab/25720
	* gdb.base/maint-expand-symbols-header-file.c: New test.
	* gdb.base/maint-expand-symbols-header-file.exp: New file.
	* gdb.base/maint-expand-symbols-header-file.h: New test.
2020-04-14 15:08:42 +02:00
Andrew Burgess 21b0982c77 gdb/testsuite: Move helper function into lib/dwarf.exp
Every time I write a test making use of the DWARF assembler I end up
copying in the function get_func_info.  Duplicating code is bad, so
lets put this function into lib/dwarf.exp and remove all of the
duplicates.

There should be no changes in the testsuite behaviour after this
commit.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-many-frames.exp (get_func_info): Delete.
	* gdb.dwarf2/dw2-inline-small-func.exp: Pass options to
	get_func_info.
	(get_func_info): Delete.
	* gdb.dwarf2/dw2-is-stmt-2.exp (get_func_info): Delete.
	* gdb.dwarf2/dw2-is-stmt.exp (get_func_info): Delete.
	* lib/dwarf.exp (get_func_info): New function.
2020-04-14 12:13:06 +01:00
Tom Tromey 400b5eca00 Move event-loop.[ch] to gdbsupport/
This moves event-loop.[ch] to gdbsupport/ and updates the uses in gdb.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* run-on-main-thread.c: Update include.
	* unittests/main-thread-selftests.c: Update include.
	* tui/tui-win.c: Update include.
	* tui/tui-io.c: Update include.
	* tui/tui-interp.c: Update include.
	* tui/tui-hooks.c: Update include.
	* top.h: Update include.
	* top.c: Update include.
	* ser-base.c: Update include.
	* remote.c: Update include.
	* remote-notif.c: Update include.
	* remote-fileio.c: Update include.
	* record-full.c: Update include.
	* record-btrace.c: Update include.
	* python/python.c: Update include.
	* posix-hdep.c: Update include.
	* mingw-hdep.c: Update include.
	* mi/mi-main.c: Update include.
	* mi/mi-interp.c: Update include.
	* main.c: Update include.
	* linux-nat.c: Update include.
	* interps.c: Update include.
	* infrun.c: Update include.
	* inf-loop.c: Update include.
	* event-top.c: Update include.
	* event-loop.c: Move to ../gdbsupport/.
	* event-loop.h: Move to ../gdbsupport/.
	* async-event.h: Update include.
	* Makefile.in (COMMON_SFILES, HFILES_NO_SRCDIR): Update.

gdbsupport/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* event-loop.h: Move from ../gdb/.
	* event-loop.cc: Move from ../gdb/.
2020-04-13 14:10:04 -06:00
Tom Tromey 93b54c8ed3 Introduce async-event.[ch]
This patch splits out some gdb-specific code from event-loop, into new
files async-event.[ch].  Strictly speaking this code could perhaps be
put into gdbsupport/, but because gdbserver does not currently use it,
it seemed better, for size reasons, to split it out.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c: Include async-event.h.
	* remote.c: Include async-event.h.
	* remote-notif.c: Include async-event.h.
	* record-full.c: Include async-event.h.
	* record-btrace.c: Include async-event.h.
	* infrun.c: Include async-event.h.
	* event-top.c: Include async-event.h.
	* event-loop.h: Move some declarations to async-event.h.
	* event-loop.c: Don't include ser-event.h or top.h.  Move some
	code to async-event.c.
	* async-event.h: New file.
	* async-event.c: New file.
	* Makefile.in (COMMON_SFILES): Add async-event.c.
	(HFILES_NO_SRCDIR): Add async-event.h.
2020-04-13 14:10:04 -06:00
Tom Tromey c1cd3163d9 Introduce and use flush_streams
Code in gdbsupport can't call gdb_flush, so this introduces a new
"flush_streams" function that must be supplied by the client.

Note that the similar gdb_flush_out_err exists, but it isn't defined
in quite the same way, so it wasn't clear to me whether the two could
be merged.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* utils.c (flush_streams): New function.
	* event-loop.c (gdb_wait_for_event): Call flush_streams.

gdbsupport/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* errors.h (flush_streams): Declare.
2020-04-13 14:10:04 -06:00
Tom Tromey 29f2bf4f22 Use warning in event-loop
Change event-loop.c to avoid printf_unfiltered in favor of warning.
warning is aleady available to code in gdbsupport/.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* event-loop.c (handle_file_event): Use warning, not
	printf_unfiltered.
2020-04-13 14:10:04 -06:00
Tom Tromey 98029d02d7 Include <chrono> in event-loop.c
Include <chrono> in event-loop.c, because it is used there.  Currently
it is included indirectly, but after the subsequent patches this will
no longer be the case.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* event-loop.c: Include <chrono>.
2020-04-13 14:10:03 -06:00
Tom Tromey 06cc9596e8 Move gdb_select.h to gdbsupport/
This moves gdb_select.h to gdbsupport/, so it can be used by other
code there.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* gdb_select.h: Move to ../gdbsupport/.
	* event-loop.c: Update include path.
	* top.c: Update include path.
	* ser-base.c: Update include path.
	* ui-file.c: Update include path.
	* ser-tcp.c: Update include path.
	* guile/scm-ports.c: Update include path.
	* posix-hdep.c: Update include path.
	* ser-unix.c: Update include path.
	* gdb_usleep.c: Update include path.
	* mingw-hdep.c: Update include path.
	* inflow.c: Update include path.
	* infrun.c: Update include path.
	* event-top.c: Update include path.

gdbsupport/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* gdb_select.h: Move from ../gdb/.
2020-04-13 14:10:03 -06:00
Tom Tromey 8ae8e19796 Move event-loop configury to common.m4
gdb_select.h and the event loop require some configure checks, so this
moves the needed checks to common.m4 and updates the configure
scripts.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Remove checks that are now in GDB_AC_COMMON.

gdbserver/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* config.in: Rebuild.

gdbsupport/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* config.in, configure: Rebuild.
	* common.m4 (GDB_AC_COMMON): Check for poll.h, sys/poll.h,
	sys/select.h, and poll.
2020-04-13 14:10:03 -06:00
Tom Tromey 58cf28e860 Move start_event_loop out of event-loop.c
A subsequent patch is going to move event-loop.c to gdbsupport.  In a
review of an earlier version of this series, Pedro pointed out that
the resulting code would be cleaner if start_event_loop were not
shared -- because gdb and gdbserver have some different needs here --
and so this moves start_event_loop to main.c.  Because the only caller
is there, it is also now static.

gdb/ChangeLog
2020-04-13  Tom Tromey  <tom@tromey.com>

	* event-loop.h (start_event_loop): Don't declare.
	* event-loop.c (start_event_loop): Move...
	* main.c (start_event_loop): ...here.  Now static.
2020-04-13 14:10:03 -06:00
Sergio Durigan Junior b7f999aee3 Update my email address on MAINTAINERS
Commit pushed under the obvious/trivial rule.

gdb/ChangeLog:
2020-04-13  Sergio Durigan Junior  <sergiodj@sergiodj.net>

	* MAINTAINERS: Update my email address.
2020-04-13 15:53:28 -04:00
Tom de Vries dd1cab0694 [gdb/testsuite] Fix gdb.ada/catch_ex_std.exp gnatlink FAIL
When running test-case gdb.ada/catch_ex.exp using system gnatmake, gnatmake is
invoked like this:
...
Executing on host: \
  gnatmake foo.adb -gnata -f -Isrc/gdb/testsuite/gdb.ada/catch_ex -g -lm \
    -o outputs/gdb.ada/catch_ex/foo
...

When I try to use a more recent gnatmake, by mocking up a combined build:
...
$ ls -la build/gcc/
lrwxrwxrwx  gfortran -> /usr/bin/gfortran-10
lrwxrwxrwx  gnatbind -> /usr/bin/gnatbind-10
lrwxrwxrwx  gnatlink -> /usr/bin/gnatlink-10
lrwxrwxrwx  gnatmake -> /usr/bin/gnatmake-10
lrwxrwxrwx  xg++ -> /usr/bin/g++-10
lrwxrwxrwx  xgcc -> /usr/bin/gcc-10
...
gnatmake is invoked like this:
...
Executing on host: \
  /data/gdb_versions/devel/build/gcc/gnatmake \
    -I/data/gdb_versions/devel/build/gcc/ada/rts \
    --GCC=/data/gdb_versions/devel/build/gcc/xgcc \
    --GNATBIND=/data/gdb_versions/devel/build/gcc/gnatbind \
    --GNATLINK=/data/gdb_versions/devel/build/gcc/gnatlink \
    -cargs -B/data/gdb_versions/devel/build/gcc \
    -largs --GCC=/data/gdb_versions/devel/build/gcc/xgcc \
    -B/data/gdb_versions/devel/build/gcc \
    -margs foo.adb -gnata -f -Isrc/gdb/testsuite/gdb.ada/catch_ex -g -lm \
    -o outputs/gdb.ada/catch_ex/foo
...

This is set up by this bit in find_gnatmake in
/usr/share/dejagnu/libgloss.exp:
...
    if {![is_remote host]} {
        set file [lookfor_file $tool_root_dir gnatmake]
        if { $file == "" } {
            set file [lookfor_file $tool_root_dir gcc/gnatmake]
        }
        if { $file != "" } {
            set root [file dirname $file]
            set CC "$file -I$root/ada/rts --GCC=$root/xgcc \
	      --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink \
	      -cargs -B$root \
	      -largs --GCC=$root/xgcc -B$root -margs"
        } else {
...

However, when running test-case gdb.ada/catch_ex_std.exp using the mockup
combined build, we get:
...
Executing on host: \
  /data/gdb_versions/devel/build/gcc/gnatlink foo \
    -Wl,-rpath,\$ORIGIN -Wl,-lsome_package

b~foo.adb:26:79: "SS_Stack" not declared in "Secondary_Stack"^M
b~foo.adb:26:89: incorrect constraint for this kind of type^M
b~foo.adb:121:56: "Runtime_Default_Sec_Stack_Size" not declared in "Parameters"^M
FAIL: gdb.ada/catch_ex_std.exp: gnatlink foo
...

The problem is caused by the fact that the test uses gnatlink directly
rather than using gnatmake.  The invoked gnatlink (which is gnatlink-10) calls
gcc-7, which are incompatible (see gcc PR86211).  This problem doesn't occur
with gnatmake because there the gcc to use is passed as an argument to
gnatlink.

Fix this by adding the -largs bit from find_gnatmake in find_ada_tool, for the
case that $tool == gnatlink.

Tested on x86_64-linux, with system gcc, and gcc-10.

gdb/testsuite/ChangeLog:

2020-04-13  Tom de Vries  <tdevries@suse.de>

	* lib/ada.exp (find_ada_tool): Pass --GCC and -B to gnatlink, similar
	to what find_gnatmake does.
2020-04-13 18:53:14 +02:00
Kamil Rytarowski 1085dfd4e1 Implement IP_MINIMAL and IP_ALL on NetBSD
gdb/ChangeLog:

       * nbsd-nat.c (nbsd_nat_target::info_proc): Add IP_MINIMAL and
       IP_ALL.
2020-04-13 11:49:36 +02:00
Kamil Rytarowski 49d1d1f53d Implement "info proc cmdline" for NetBSD
Add nbsd_pid_to_cmdline() to query the program command line.

gdb/ChangeLog:

        * nbsd-nat.c (nbsd_pid_to_cmdline): Add.
        (nbsd_nat_target::info_proc): Add do_cmdline.
2020-04-12 21:33:06 +02:00
Kamil Rytarowski b4848d2a7b Implement "info proc cwd" for NetBSD
Add nbsd_pid_to_cwd() to query the program current directory.

gdb/ChangeLog:

	* nbsd-nat.c (nbsd_pid_to_cwd): Add.
	(nbsd_nat_target::info_proc): Add do_cwd.
2020-04-12 20:15:00 +02:00
Kamil Rytarowski 51c133d547 Implement "info proc exe" for NetBSD
Use pid_to_exec_file() to query the program.

gdb/ChangeLog:

	* nbsd-nat.c (nbsd_nat_target::info_proc): Add do_exe.
2020-04-12 19:25:35 +02:00
Kamil Rytarowski 54b8cbd0e4 Implement "info proc mappings" for NetBSD
Define nbsd_nat_target::find_memory_regions and
nbsd_nat_target::info_proc. info_proc handles as of now only
the "mappings" command.

Define a local static function kinfo_get_vmmap() that reads
the process memory layout of a specified process.
kinfo_get_vmmap() wraps the sysctl(3) call.

nbsd-tdep.c defines now utility functions for printing the
process memory layout:
 * nbsd_info_proc_mappings_header()
 * nbsd_vm_map_entry_flags()
 * nbsd_info_proc_mappings_entry()

gdb/ChangeLog:

	* nbsd-nat.c; Include "nbsd-tdep.h" and "gdbarch.h".
	* nbsd-nat.c (nbsd_nat_target::find_memory_regions)
	(nbsd_nat_target::info_proc): New functions.
	* nbsd-nat.c (kinfo_get_vmmap): New function.
	* nbsd-nat.c (nbsd_nat_target::info_proc) Use
	nbsd_info_proc_mappings_header and nbsd_info_proc_mappings_entry.
	* nbsd-tdep.c (nbsd_info_proc_mappings_header)
	(nbsd_info_proc_mappings_entry, nbsd_vm_map_entry_flags): New
	functions.
	* nbsd-tdep.c (KINFO_VME_PROT_READ, KINFO_VME_PROT_WRITE)
	(KINFO_VME_PROT_EXEC, KINFO_VME_FLAG_COW)
	(KINFO_VME_FLAG_NEEDS_COPY, KINFO_VME_FLAG_NOCOREDUMP)
	(KINFO_VME_FLAG_PAGEABLE, KINFO_VME_FLAG_GROWS_UP)
	(KINFO_VME_FLAG_GROWS_DOWN): New.
2020-04-12 13:06:08 +02:00
Artur Shepilko cf83625da2 gdb: fix undefined behavior reported in copy_bitwise
gdb version 9.1, built with clang 8.0.0 on Ubuntu 18.04 (x86_64);
--enable-ubsan (for clang's undefined behavior sanitizer)

Executing command; `maint selftest copy_bitwise` bombs in runtime error:
../../gdb/utils.c:3432:28: runtime error: left shift of negative value -1

Closer look reveals the offending shift: `(~0 << nbits)`, apparently 0
is treated as signed int, resulting in negative complement. Explicitly
stating it unsigned 0U  fixes it and the `copy_bitwise` test passes
ok.
2020-04-10 21:04:03 -04:00
Tom Tromey 0c4311ab90 Avoid infinite recursion in get_msymbol_address
Sometimes, get_msymbol_address can cause infinite recursion, leading
to a crash.  This was reported previously here:

https://sourceware.org/pipermail/gdb-patches/2019-November/162154.html

A user on irc reported this as well, and with his help and the help of
a friend of his, we found that the problem occurred because, when
reloading a separate debug objfile, the objfile would lose the
OBJF_MAINLINE flag.  This would cause some symbols from this separate
debug objfile to be marked "maybe_copied" -- but then
get_msymbol_address could find the same symbol and fail as reported.

This patch fixes the bug by preserving OBJF_MAINLINE.

No test case, unfortunately, because I could not successfully make
one.

gdb/ChangeLog
2020-04-10  Tom Tromey  <tromey@adacore.com>

	* symfile.c (symbol_file_add_separate): Preserve OBJF_MAINLINE.
2020-04-10 07:21:16 -06:00
Tom Tromey 3e65b3e9af Skip separate debug files when handling copy relocations
get_symbol_address and get_msymbol_address call
lookup_minimal_symbol_linkage, which iterates over the separate debug
files of the objfile that is passed in.

This means that if these functions pass in a separate debug objfile,
then they are doing unnecessary work.

This patch avoids the extra work by skipping separate debug objfiles
in the loops.

gdb/ChangeLog
2020-04-10  Tom Tromey  <tromey@adacore.com>

	* symtab.c (get_symbol_address, get_msymbol_address): Skip
	separate debug files.
2020-04-10 07:21:16 -06:00
Hannes Domani 13302e956f Fix debugging of WOW64 processes
The new code regarding pending stops only checks for EXCEPTION_BREAKPOINT,
but for WOW64 processes STATUS_WX86_BREAKPOINT is necessary as well.

Also, ignore_first_breakpoint is used now in nat/windows-nat.c as well,
but was not available there.

gdb/ChangeLog:

2020-04-10  Hannes Domani  <ssbssa@yahoo.de>

	* nat/windows-nat.c (STATUS_WX86_BREAKPOINT, STATUS_WX86_SINGLE_STEP):
	Move to...
	* nat/windows-nat.h (STATUS_WX86_BREAKPOINT, STATUS_WX86_SINGLE_STEP):
	... here.
	* windows-nat.c (windows_nat_target::get_windows_debug_event):
	Check for STATUS_WX86_BREAKPOINT.
	(windows_nat_target::wait): Same.
2020-04-10 13:01:31 +02:00
Tom de Vries 71ea2b6be8 [gdb/testsuite] Fix -readnow FAIL in gdb.base/style.exp
When running test-case gdb.base/style.exp with target board readnow, we run
into:
...
FAIL: gdb.base/style.exp: filename is styled when loading symbol file
...

The problem is that with -readnow, an extra "Expanding full symbols" message
is generated:
...
(gdb) file $file^M
Reading symbols from $file...^M
Expanding full symbols from $file...^M
(gdb) FAIL: gdb.base/style.exp: filename is styled when loading symbol file
...
and the test does not expect this message.

Fix this by expecting the additional message for -readnow.

gdb/testsuite/ChangeLog:

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

	* gdb.base/style.exp: Expect "Expanding full symbols" message for
	-readnow.
2020-04-10 09:50:11 +02:00
Tom de Vries bdfc1e8a0b [gdb/cli] Don't let python colorize strip leading newlines
Consider the test-case gdb.base/async.exp.  Using the executable, I run to
main, and land on a line advertised as line 26:
...
$ gdb outputs/gdb.base/async/async -ex start
Reading symbols from outputs/gdb.base/async/async...
Temporary breakpoint 1 at 0x4004e4: file gdb.base/async.c, line 26.
Starting program: outputs/gdb.base/async/async

Temporary breakpoint 1, main () at gdb.base/async.c:26
26       y = foo ();
...

But actually, the line turns out to be line 28:
...
$ cat -n gdb.base/async.c
    ...
    26   y = 2;
    27   z = 9;
    28   y = foo ();
...

This is caused by the following: the python colorizer initializes the lexer
with default options (no second argument to get_lexer_for_filename):
...
    def colorize(filename, contents):
        # Don't want any errors.
        try:
            lexer = lexers.get_lexer_for_filename(filename)
            formatter = formatters.TerminalFormatter()
            return highlight(contents, lexer, formatter)
...
which include option stripnl=True, which strips leading and trailing newlines.

This causes the python colorizer to strip the two leading newlines of async.c.

Fix this by initializing the lexer with stripnl=False.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

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

	PR cli/25808
	* python/lib/gdb/__init__.py: Initialize lexer with stripnl=False.

gdb/testsuite/ChangeLog:

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

	PR cli/25808
	* gdb.base/style.c: Add leading newlines.
	* gdb.base/style.exp: Use gdb_get_line_number to get specific lines.
	Check listing of main's one-line body.
2020-04-10 09:29:52 +02:00
Simon Marchi f4460aec69 gdb: move Tom de Vries to Global Maintainers
gdb/ChangeLog:

	* MAINTAINERS (Global Maintainers): Add Tom de Vries.
	(Write After Approval): Remove Tom de Vries.
2020-04-09 19:06:16 -04:00
Bernd Edlinger a25198bba2 Partially revert my UB fix in record_line
This reverts the following commit partially:

commit 64dc2d4bd2
Author: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date:   Thu Mar 12 11:52:34 2020 +0100

    Fix an undefined behavior in record_line

    Additionally do not completely remove symbols
    at the same PC than the end marker, instead
    make them non-is-stmt breakpoints.

We keep the undefined behavoir fix,
but have to restore the original behavior
regarding deletion of the line entries.

2020-04-09  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	revert partially:
	2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

        * buildsym.c (record_line): Fix undefined behavior and preserve
        lines at eof.
2020-04-09 17:06:58 +02:00
Kamil Rytarowski 206c98a650 Add SVR4 psABI specific parser for AUXV entries
NetBSD and OpenBSD always use an int to store the type as
defined in the SVR4 psABI specifications rather than long
as assumed by the default parser.

Define svr4_auxv_parse() that shares code with default_auxv_parse().

Remove obsd_auxv_parse() and switch OpenBSD to svr4_auxv_parse().
Remove not fully accurate comment from obsd-tdep.c.

Use svr4_auxv_parse() on NetBSD.

gdb/ChangeLog:

	* auxv.h (svr4_auxv_parse): New.
	* auxv.c (default_auxv_parse): Split into default_auxv_parse
	and generic_auxv_parse.
	(svr4_auxv_parse): Add.
	* obsd-tdep.c: Include "auxv.h".
	(obsd_auxv_parse): Remove.
	(obsd_init_abi): Remove comment.
	(obsd_init_abi): Change set_gdbarch_auxv_parse passed argument
	from `obsd_auxv_parse' to `svr4_auxv_parse'.
	* nbsd-tdep.c: Include "auxv.h".
	(nbsd_init_abi): Call set_gdbarch_auxv_parse.
2020-04-09 13:17:29 +02:00
Tom Tromey 71fbdbafe0 Make last_wait_event static
Now that last_wait_event is entirely handled in nat/windows-nat.c, it
can be made static.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (last_wait_event): Don't declare.
	(wait_for_debug_event): Update comment.
	* nat/windows-nat.c (last_wait_event): Now static.
2020-04-08 14:47:59 -06:00
Tom Tromey 2c1d95e869 Move wait_for_debug_event to nat/windows-nat.c
This moves the wait_for_debug_event helper function to
nat/windows-nat.c, and changes gdbserver to use it.
wait_for_debug_event is a wrapper for WaitForDebugEvent that also sets
last_wait_event when appropriate.  This is needed to properly handle
queued stops.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (wait_for_debug_event): Move to
	nat/windows-nat.c.
	* nat/windows-nat.h (wait_for_debug_event): Declare.
	* nat/windows-nat.c (wait_for_debug_event): Move from
	windows-nat.c.  No longer static.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (win32_kill, get_child_debug_event): Use
	wait_for_debug_event.
2020-04-08 14:47:59 -06:00
Tom Tromey d2977bc425 Introduce fetch_pending_stop
This introduces a new "fetch_pending_stop" function and changes gdb to
use it.  This function removes the first matching pending stop from
the list of such stops.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (get_windows_debug_event): Use
	fetch_pending_stop.
	* nat/windows-nat.h (fetch_pending_stop): Declare.
	* nat/windows-nat.c (fetch_pending_stop): New function.
2020-04-08 14:47:59 -06:00
Tom Tromey e758e19c59 Share some inferior-related Windows code
This adds a couple of functions to nat/windows-nat.c and changes gdb
and gdbserver to use them.  One function checks the list of pending
stops for a match (not yet used by gdbserver, but will be in a
subsequent patch); and the other is a wrapper for ContinueDebugEvent
that always uses the last "real" stop event.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_continue): Use matching_pending_stop and
	continue_last_debug_event.
	* nat/windows-nat.h (matching_pending_stop)
	(continue_last_debug_event): Declare.
	* nat/windows-nat.c (DEBUG_EVENTS): New define.
	(matching_pending_stop, continue_last_debug_event): New
	functions.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (child_continue): Call continue_last_debug_event.
2020-04-08 14:47:59 -06:00
Tom Tromey 8d30e39577 Share handle_exception
Both gdb and gdbserver have a "handle_exception" function, the bulk of
which is shared between the two implementations.  This patch arranges
for the entire thing to be moved into nat/windows-nat.c, with the
differences handled by callbacks.  This patch introduces one more
callback to make this possible.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (MS_VC_EXCEPTION): Move to nat/windows-nat.c.
	(handle_exception_result): Move to nat/windows-nat.h.
	(DEBUG_EXCEPTION_SIMPLE): Remove.
	(windows_nat::handle_ms_vc_exception): New function.
	(handle_exception): Move to nat/windows-nat.c.
	(get_windows_debug_event): Update.
	(STATUS_WX86_BREAKPOINT, STATUS_WX86_SINGLE_STEP): Move to
	nat/windows-nat.c.
	* nat/windows-nat.h (handle_ms_vc_exception): Declare.
	(handle_exception_result): Move from windows-nat.c.
	(handle_exception): Declare.
	* nat/windows-nat.c (MS_VC_EXCEPTION, handle_exception)
	(STATUS_WX86_SINGLE_STEP, STATUS_WX86_BREAKPOINT): Move from
	windows-nat.c.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (handle_exception): Remove.
	(windows_nat::handle_ms_vc_exception): New function.
	(get_child_debug_event): Add "continue_status" parameter.
	Update.
	(win32_wait): Update.
2020-04-08 14:47:59 -06:00
Tom Tromey 29de418dee Remove some globals from windows-nat.c
windows-nat.c has a few "count" globals that don't seem to be used.
Possibly they were used for debugging at some point, but they no
longer seem useful to me.  Because they get in the way of some code
sharing, this patch removes them.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (exception_count, event_count): Remove.
	(handle_exception, get_windows_debug_event)
	(do_initial_windows_stuff): Update.
2020-04-08 14:47:59 -06:00
Tom Tromey a816ba1897 Share handle_load_dll and handle_unload_dll declarations
This changes nat/windows-nat.h to declare handle_load_dll and
handle_unload_dll.  The embedding application is required to implement
these -- while the actual code was difficult to share due to some
other differences between the two programs, sharing the declaration
lets a subsequent patch share more code that uses these as callbacks.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat::handle_load_dll)
	(windows_nat::handle_unload_dll): Rename.  No longer static.
	* nat/windows-nat.h (handle_load_dll, handle_unload_dll):
	Declare.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (windows_nat::handle_load_dll): Rename from
	handle_load_dll.  No longer static.
	(windows_nat::handle_unload_dll): Rename from handle_unload_dll.
	No longer static.
2020-04-08 14:47:58 -06:00
Tom Tromey a00caa1279 Fix up complaints.h for namespace use
If 'complaint' is used in a namespace context, it will fail because
'stop_whining' is only declared at the top level.  This patch fixes
this problem in a simple way, by moving the declaration of
'stop_whining' out of the macro and to the top-level.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* complaints.h (stop_whining): Declare at top-level.
	(complaint): Don't declare stop_whining.
2020-04-08 14:47:58 -06:00
Tom Tromey d41b524f45 Normalize handle_output_debug_string API
This changes gdbserver's implementation of handle_output_debug_string
to have the same calling convention as that of gdb.  This allows for
sharing some more code in a subsequent patch.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_nat::handle_output_debug_string):
	Rename.  No longer static.
	* nat/windows-nat.h (handle_output_debug_string): Declare.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (handle_output_debug_string): Add parameter.  Change
	return type.
	(win32_kill, get_child_debug_event): Update.
2020-04-08 14:47:58 -06:00
Tom Tromey 3c76026df8 Share some Windows-related globals
This moves some Windows-related globals into nat/windows-nat.c,
sharing them between gdb and gdbserver.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (current_process_handle, current_process_id)
	(main_thread_id, last_sig, current_event, last_wait_event)
	(current_windows_thread, desired_stop_thread_id, pending_stops)
	(struct pending_stop, siginfo_er): Move to nat/windows-nat.c.
	(display_selectors, fake_create_process)
	(get_windows_debug_event): Update.
	* nat/windows-nat.h (current_process_handle, current_process_id)
	(main_thread_id, last_sig, current_event, last_wait_event)
	(current_windows_thread, desired_stop_thread_id, pending_stops)
	(struct pending_stop, siginfo_er): Move from windows-nat.c.
	* nat/windows-nat.c (current_process_handle, current_process_id)
	(main_thread_id, last_sig, current_event, last_wait_event)
	(current_windows_thread, desired_stop_thread_id, pending_stops)
	(siginfo_er): New globals.  Move from windows-nat.c.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (current_process_handle, current_process_id)
	(main_thread_id, last_sig, current_event, siginfo_er): Move to
	nat/windows-nat.c.
2020-04-08 14:47:58 -06:00
Tom Tromey 9d8679cc71 Share get_image_name between gdb and gdbserver
This moves get_image_name to nat/windows-nat.c so that it can be
shared between gdb and gdbserver.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (get_image_name): Move to nat/windows-nat.c.
	(handle_load_dll): Update.
	* nat/windows-nat.c (get_image_name): Move from windows-nat.c.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (get_image_name): Remove.
	(handle_load_dll): Update.
2020-04-08 14:47:58 -06:00
Tom Tromey 28688adf8f Share thread_rec between gdb and gdbserver
This changes gdb and gdbserver to use the same calling convention for
the "thread_rec" helper function.  Fully merging these is difficult
due to differences in how threads are managed by the enclosing
applications; but sharing a declaration makes it possible for future
shared code to call this method.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (enum thread_disposition_type): Move to
	nat/windows-nat.h.
	(windows_nat::thread_rec): Rename from thread_rec.  No longer
	static.
	(windows_add_thread, windows_nat_target::fetch_registers)
	(windows_nat_target::store_registers, handle_exception)
	(windows_nat_target::resume, get_windows_debug_event)
	(windows_nat_target::get_tib_address)
	(windows_nat_target::thread_name)
	(windows_nat_target::thread_alive): Update.
	* nat/windows-nat.h (enum thread_disposition_type): Move from
	windows-nat.c.
	(thread_rec): Declare.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (windows_nat::thread_rec): Rename from thread_rec.
	No longer static.  Change parameters.
	(child_add_thread, child_fetch_inferior_registers)
	(child_store_inferior_registers, win32_resume)
	(win32_get_tib_address): Update.
2020-04-08 14:47:58 -06:00
Tom Tromey 4834dad062 Wrap shared windows-nat code in windows_nat namespace
This wraps the shared windows-nat code in a windows_nat namespace.
This helps avoid name clashes.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c: Add "using namespace".
	* nat/windows-nat.h: Wrap contents in windows_nat namespace.
	* nat/windows-nat.c: Wrap contents in windows_nat namespace.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.h (struct win32_target_ops): Use qualified names where
	needed.
	* win32-i386-low.c: Add "using namespace".
	* win32-low.c: Add "using namespace".
	* win32-arm-low.c: Add "using namespace".
2020-04-08 14:47:58 -06:00
Tom Tromey 65bafd5b15 Call CloseHandle from ~windows_thread_info
Add a destructor to windows_thread_info that calls CloseHandle.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* nat/windows-nat.h (struct windows_thread_info): Declare
	destructor.
	* nat/windows-nat.c (~windows_thread_info): New.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (delete_thread_info): Don't call CloseHandle.
2020-04-08 14:47:58 -06:00
Tom Tromey 0a4afda3c6 Handle pending stops from the Windows kernel
PR gdb/22992 concerns an assertion failure in gdb when debugging a
certain inferior:

    int finish_step_over(execution_control_state*): Assertion `ecs->event_thread->control.trap_expected' failed.

Initially the investigation centered on the discovery that gdb was not
suspending other threads when attempting to single-step.  This
oversight is corrected in this patch: now, when stepping a thread, gdb
will call SuspendThread on all other threads.

However, the bug persisted even after this change.  In particular,
WaitForDebugEvent could see a stop for a thread that was ostensibly
suspended.  Our theory of what is happening here is that there are
actually simultaneous breakpoint hits, and the Windows kernel queues
the events, causing the second stop to be reported on a suspended
thread.

In Windows 10 or later gdb could use the DBG_REPLY_LATER flag to
ContinueDebugEvent to request that such events be re-reported later.
However, relying on that did not seem advisable, so this patch instead
arranges to queue such "pending" stops, and then to report them later,
once the step has completed.

In the PR, Pedro pointed out that it's best in this scenario to
implement the stopped_by_sw_breakpoint method, so this patch does this
as well.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	PR gdb/22992
	* windows-nat.c (current_event): Update comment.
	(last_wait_event, desired_stop_thread_id): New globals.
	(struct pending_stop): New.
	(pending_stops): New global.
	(windows_nat_target) <stopped_by_sw_breakpoint>
	<supports_stopped_by_sw_breakpoint>: New methods.
	(windows_fetch_one_register): Add assertions.  Adjust PC.
	(windows_continue): Handle pending stops.  Suspend other threads
	when stepping.  Use last_wait_event
	(wait_for_debug_event): New function.
	(get_windows_debug_event): Use wait_for_debug_event.  Handle
	pending stops.  Queue spurious stops.
	(windows_nat_target::wait): Set stopped_at_software_breakpoint.
	(windows_nat_target::kill): Use wait_for_debug_event.
	* nat/windows-nat.h (struct windows_thread_info)
	<stopped_at_software_breakpoint>: New field.
	* nat/windows-nat.c (windows_thread_info::resume): Clear
	stopped_at_software_breakpoint.
2020-04-08 14:47:58 -06:00
Tom Tromey 8e61ebec34 Change type of argument to windows-nat.c:thread_rec
windows-nat.c:thread_rec accepts an integer parameter whose
interpretation depends on whether it is less than, equal to, or
greater than zero.  I found this confusing at times, so this patch
replaces it with an enum instead.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (enum thread_disposition_type): New.
	(thread_rec): Replace "get_context" parameter with "disposition";
	change type.
	(windows_add_thread, windows_nat_target::fetch_registers)
	(windows_nat_target::store_registers, handle_exception)
	(windows_nat_target::resume, get_windows_debug_event)
	(windows_nat_target::get_tib_address)
	(windows_nat_target::thread_name)
	(windows_nat_target::thread_alive): Update.
2020-04-08 14:47:58 -06:00
Tom Tromey 98a0328732 Share Windows thread-suspend and -resume code
This adds "suspend" and "resume" methods to windows_thread_info, and
changes gdb and gdbserver to share this code.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (thread_rec): Use windows_thread_info::suspend.
	(windows_continue): Use windows_continue::resume.
	* nat/windows-nat.h (struct windows_thread_info) <suspend,
	resume>: Declare new methods.
	* nat/windows-nat.c: New file.
	* configure.nat (NATDEPFILES): Add nat/windows-nat.o when needed.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (win32_require_context, suspend_one_thread): Use
	windows_thread_info::suspend.
	(continue_one_thread): Use windows_thread_info::resume.
	* configure.srv (srv_tgtobj): Add windows-nat.o when needed.
2020-04-08 14:47:58 -06:00
Tom Tromey 7c7411bcab Use lwp, not tid, for Windows thread id
This changes windows-nat.c to put the Windows thread id into the "lwp"
field of ptid_t, not the "tid" field.  This is done for two reasons.

First, ptid.h has this to say:

   process_stratum targets that handle threading themselves should
   prefer using the ptid.lwp field, leaving the ptid.tid field for any
   thread_stratum target that might want to sit on top.

Second, this change brings gdb and gdbserver into sync here, which
makes sharing code simpler.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_add_thread, windows_delete_thread)
	(windows_nat_target::fetch_registers)
	(windows_nat_target::store_registers, fake_create_process)
	(windows_nat_target::resume, windows_nat_target::resume)
	(get_windows_debug_event, windows_nat_target::wait)
	(windows_nat_target::pid_to_str)
	(windows_nat_target::get_tib_address)
	(windows_nat_target::get_ada_task_ptid)
	(windows_nat_target::thread_name)
	(windows_nat_target::thread_alive): Use lwp, not tid.
2020-04-08 14:47:58 -06:00
Tom Tromey 2950fdf742 Make windows_thread_info::name a unique_xmalloc_ptr
This changes windows_thread_info::name to be a unique_xmalloc_ptr,
removing some manual memory management.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (handle_exception)
	(windows_nat_target::thread_name): Update.
	* nat/windows-nat.h (windows_thread_info): Remove destructor.
	<name>: Now unique_xmalloc_ptr.
2020-04-08 14:47:58 -06:00
Tom Tromey 62fe396b1c Change two windows_thread_info members to "bool"
This changes a couple of fields of windows_thread_info to have type
"bool".  It also updates the comment of another field, to clarify the
possible values it can hold.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (thread_rec)
	(windows_nat_target::fetch_registers): Update.
	* nat/windows-nat.h (struct windows_thread_info) <suspended>:
	Update comment.
	<debug_registers_changed, reload_context>: Now bool.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-i386-low.c (update_debug_registers)
	(i386_prepare_to_resume, i386_thread_added): Update.
2020-04-08 14:47:57 -06:00
Tom Tromey e9534bd257 Use new and delete for windows_thread_info
This adds a constructor, destructor, and member initializers to
windows_thread_info, and changes gdb and gdbserver to use new and
delete.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (windows_add_thread): Use new.
	(windows_init_thread_list, windows_delete_thread): Use delete.
	(get_windows_debug_event): Update.
	* nat/windows-nat.h (struct windows_thread_info): Add constructor,
	destructor, and initializers.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.c (child_add_thread): Use new.
	(delete_thread_info): Use delete.
2020-04-08 14:47:57 -06:00
Tom Tromey ae1f888075 Share windows_thread_info between gdb and gdbserver
This introduces a new file, nat/windows-nat.h, which holds the
definition of windows_thread_info.  This is now shared between gdb and
gdbserver.

Note that the two implementations different slightly.  gdb had a
couple of fields ("name" and "reload_context") that gdbserver did not;
while gdbserver had one field ("base_context") that gdb did not, plus
better comments.  The new file preserves all the fields, and the
comments.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (struct windows_thread_info): Remove.
	* nat/windows-nat.h: New file.

gdbserver/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* win32-low.h (struct windows_thread_info): Remove.
2020-04-08 14:47:57 -06:00
Tom Tromey 55a1e039f9 Rename windows_thread_info::id to "tid"
This changes the name of a field in windows_thread_info, bringing gdb
and gdbserver closer into sync.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (struct windows_thread_info) <tid>: Rename from "id".
	(thread_rec, windows_add_thread, windows_delete_thread)
	(windows_continue): Update.
2020-04-08 14:47:57 -06:00
Tom Tromey 93366324f5 Remove the "next" field from windows_thread_info
This changes windows_thread_info to remove the "next" field, replacing
the linked list of threads with a vector.  This is a prerequisite to
sharing this structure with gdbserver, which manages threads
differently.

gdb/ChangeLog
2020-04-08  Tom Tromey  <tromey@adacore.com>

	* windows-nat.c (struct windows_thread_info): Remove typedef.
	(thread_head): Remove.
	(thread_list): New global.
	(thread_rec, windows_add_thread, windows_init_thread_list)
	(windows_delete_thread, windows_continue): Update.
2020-04-08 14:47:57 -06:00
Simon Marchi 0f2265e246 gdb: stop using host-dependent signal numbers in windows-tdep.c
The signal enumeration in windows-tdep.c is defined differently whether
it is compiled on Cygwin or not.  This is problematic, since the code in
tdep files is not supposed to be influenced by the host platform (the
platform GDB itself runs on).

This makes a difference in windows_gdb_signal_to_target.  An obvious
example of clash is SIGABRT.  Let's pretend we are cross-debugging a
Cygwin process from a MinGW (non-Cygwin Windows) GDB.  If GDB needs to
translate the gdb signal number GDB_SIGNAL_ABRT into a target
equivalent, it would obtain the MinGW number (22), despite the target
being a Cygwin process.  Conversely, if debugging a MinGW process from a
Cygwin-hosted GDB, GDB_SIGNAL_ABRT would be converted to a Cygwin signal
number (6) despite the target being a MinGW process.  This is wrong,
since we want the result to depend on the target's platform, not GDB's
platform.

This known flaw was accepted because at the time we had a single OS ABI
(called Cygwin) for all Windows binaries (Cygwin ones and non-Cygwin
ones).  This limitation is now lifted, as we now have separate Windows
and Cygwin OS ABIs.  This means we are able to detect at runtime whether
the binary we are debugging is a Cygwin one or non-Cygwin one.

This patch splits the signal enum in two, one for the MinGW flavors and
one for Cygwin, removing all the ifdefs that made it depend on the host
platform.  It then makes two separate gdb_signal_to_target gdbarch
methods, that are used according to the OS ABI selected at runtime.

There is a bit of re-shuffling needed in how the gdbarch'es are
initialized, but nothing major.

gdb/ChangeLog:

	* windows-tdep.h (windows_init_abi): Add comment.
	(cygwin_init_abi): New declaration.
	* windows-tdep.c: Split signal enumeration in two, one for
	Windows and one for Cygwin.
	(windows_gdb_signal_to_target): Only deal with signal of the
	Windows OS ABI.
	(cygwin_gdb_signal_to_target): New function.
	(windows_init_abi): Rename to windows_init_abi_common, don't set
	gdb_signal_to_target gdbarch method.  Add new new function with
	this name.
	(cygwin_init_abi): New function.
	* amd64-windows-tdep.c (amd64_windows_init_abi_common): Add
	comment.  Don't call windows_init_abi.
	(amd64_windows_init_abi): Add comment, call windows_init_abi.
	(amd64_cygwin_init_abi): Add comment, call cygwin_init_abi.
	* i386-windows-tdep.c (i386_windows_init_abi): Rename to
	i386_windows_init_abi_common, don't call windows_init_abi.  Add
	a new function of this name.
	(i386_cygwin_init_abi): New function.
	(_initialize_i386_windows_tdep): Bind i386_cygwin_init_abi to
	OS ABI Cygwin.
2020-04-08 14:05:54 -04:00
Simon Marchi 3810f182ee Remove objfile parameter from read_gdb_index_from_buffer
I noticed this was unused, so remove it.

gdb/ChangeLog:

	* dwarf2/read.c (read_gdb_index_from_buffer): Remove objfile
	parameter.c.
	(dwarf2_read_gdb_index): Update.
2020-04-08 08:07:33 -04:00
Tom de Vries 14ca8ecfcb [gdb/testsuite] Fix imported-unit.exp FAIL without psymtabs
The test-case gdb.dwarf2/imported-unit.exp contains a test testing partial
symbols, so when we run the test-case using either target board readnow,
cc-with-gdb-index or cc-with-debug-names, we run into:
...
FAIL: gdb.dwarf2/imported-unit.exp: no static partial symbols in importing unit
...

Fix this by marking the test unsupported if there are no partial symbols.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-04-08  Tom de Vries  <tdevries@suse.de>

	* lib/gdb.exp (psymtabs_p): New proc.
	* gdb.dwarf2/imported-unit.exp: Mark "no static partial symbols in
	importing unit" unsupported if there are no partial symbols.
2020-04-08 12:05:34 +02:00
Tom de Vries e21d048f8a [gdb/testsuite] Add gcc/94469 xfails to gdb.ada/call_pn.exp
When running test-case gdb.ada/call_pn.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into:
...
(gdb) print last_node_id^M
Multiple matches for last_node_id^M
[0] cancel^M
[1] pck.last_node_id at gdb/testsuite/gdb.ada/call_pn/pck.adb:17^M
[2] pck.last_node_id at gdb/testsuite/gdb.ada/call_pn/foo.adb:17^M
> FAIL: gdb.ada/call_pn.exp: print last_node_id after calling pn (timeout)
...

This failure is due to a gcc bug that declares two instead of one symbols,
filed as PR gcc/94469.

Add an xfail at this test.  Also add a similar xfail at an earlier test, that
only triggers with -readnow.  Stabilize test results by making sure the
earlier xfail is always triggered, using "maint expand-symtabs".

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-04-08  Tom de Vries  <tdevries@suse.de>

	PR testsuite/25760
	* gdb.ada/call_pn.exp: Call "maint expand-symtabs".  Add xfails.
2020-04-08 06:57:56 +02:00
Kamil Rytarowski 063f8e80b0 Define NetBSD specific skip_solib_resolver
gdb/ChangeLog:

	* nbsd-tdep.c: Include "objfiles.h".
	(nbsd_skip_solib_resolver): New.
	(nbsd_init_abi): Call set_gdbarch_skip_solib_resolver().
2020-04-07 19:12:03 +02:00
nitachra 85a9510ccb DWARFv5: Info address command error in gdb with DWARFfv5.
GDB throws the error 'Unrecognized DWARF opcode 0x02 at 2' when running
Info address command with the executable file compiled with -gdwarf-5 flag.
This patch fixes this error.

Tested by running the testsuite before and after the patch and there is
no increase in the number of test cases that fails. Tested with both
-gdwarf-4 and -gdwarf-5 flags. Also tested -gslit-dwarf along with
-gdwarf-4 as well as -gdwarf-5 flags. Used clang version 10.0.0.
This is the test case used-

void bar(int arr[], int l, int m, int r) {
    int i, j, k, n1= m - l + 1, n2= r - m, L[n1], R[n2];
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];
}

int main()
{
    int arr[] = {12, 11};
    bar(arr,0,1,2);
    return 0;
}

clang -gdwarf-5 test.c -o test.out

gdb test.out
gdb> start
gdb> step
gdb> step
gdb> step
gdb> step
gdb> info address L
Symbol "L" is multi-location:
  Range 0x7c04007902bc5084-0x67fb876440700: a complex DWARF expression:
     0: DW_OP_breg16 1 [$rip]
Unrecognized DWARF opcode 0x02 at 2

gdb/ChangeLog:
2020-04-07  Nitika Achra  <Nitika.Achra@amd.com>

	* dwarf2/loc.c (loclist_describe_location): Call the function decode_debug_loclists_
	addresses if DWARF version is 5 or more because DW_LLE_start* or DW_LLE_offset_pair
	with DW_LLE_base_addressx are being emitted in DWARFv5.
	Add the newly added kind DW_LOC_OFFSET_PAIR also.
	The length of location description is an unsigned ULEB integer in DWARFv5 instead of
	unsigned integer.
2020-04-07 09:55:35 -06:00
nitachra 9fc3eaae69 DWARFv5: Handle location list for split dwarf.
GDB throws the error '<error reading variable: dwarf2_find_location_
expression: Corrupted DWARF expression.>' while printing the variable
value with executable file compiled with -gdwarf-5 and -gdwarf-split
flags. This is because DW_LLE_start* or DW_LLE_offset_pair with
DW_LLE_base_addressx are being emitted in DWARFv5 location list instead of
DW_LLE_GNU*. This patch fixes this error.

Tested by running the testsuite before and after the patch and there is no
increase in the number of test cases that fails. Tested with both -gdwarf-4
and -gdwarf-5 flags. Also tested -gslit-dwarf along with -gdwarf-4 as well as
-gdwarf-5 flags. Used clang version 10.0.0. This is the test case used-

void bar(int arr[], int l, int m, int r) {
    int i, j, k, n1= m - l + 1, n2= r - m, L[n1], R[n2];
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];
}

int main()
{
    int arr[] = {12, 11};
    bar(arr,0,1,2);
    return 0;
}

clang -gdwarf-5 -gsplit-dwarf test.c -o test.out

gdb test.out
gdb> start
gdb> step
gdb> step
gdb> step
gdb> step
gdb> p L[0]
dwarf2_find_location_expression: Corrupted DWARF expression.

gdb/ChangeLog:
2020-04-07  Nitika Achra  <Nitika.Achra@amd.com>

	* dwarf2/loc.c (enum debug_loc_kind): Add a new kind DEBUG_LOC_OFFSET_PAIR.
	(dwarf2_find_location_expression): Call the function decode_debug_loclists_
	addresses if DWARF version is 5 or more. DW_LLE_start* or DW_LLE_offset_pair
	with DW_LLE_base_addressx are being emitted in DWARFv5 instead of DW_LLE_GNU*.
	Add applicable base address if the entry is DW_LLE_offset_pair from DWO.
	(decode_debug_loclists_addresses): Return DEBUG_LOC_OFFSET_PAIR instead of
	DEBUG_LOC_START_END in case of DW_LLE_offset_pair.
2020-04-07 09:55:35 -06:00
nitachra 4114425321 Support for DW_AT_loclists_base and DW_FORM_loclistx.
Hi Tom,

This is the updated series with ChangeLogs edits.

Regards,
Nitika
2020-04-07 09:55:35 -06:00
Simon Marchi 9f4e76a4b3 gdb: small cleanups in dwarf2_psymtab constructors
I noticed that only one of the two dwarf2_psymtab constructors are
actually used.  The one that is used accepts an `addr` parameter (the
base text offset), but its sole caller passes a constant, 0.  We want to
keep calling the three-arguments standard_psymtab constructor form,
however, since it differs from the two-arguments form in subtle ways.

Also, I believe the dwarf2_per_cu_data associated to the created
dwarf2_psymtab should be passed as a constructor argument.  That will
help me in a future patchset, to convince myself that the `per_cu_data`
field can't be NULL.

So this patch:

- Removes the two-parameters constructor of dwarf2_psymtab, as it is
  unused.
- Removes the `addr` parameter of the remaining constructor, passing 0
  directly to the base class' constructor.
- Adds a `per_cu` parameter, to assign the `per_cu_data` field at
  construction.

gdb/ChangeLog:

	* dwarf2/read.h (struct dwarf2_psymtab): Remove two-parameters
	constructor.  Remove `addr` parameter from other constructor and
	add `per_cu` parameter.
	* dwarf2/read.c (create_partial_symtab): Update.
2020-04-07 11:48:46 -04:00
Tom de Vries 25c11acac3 [gdb/symtab] Add symbol with inherited DW_AT_const_value to psymtabs
Consider the test-case added in this patch, with resulting dwarf (related to
variable aaa):
...
 <0><d2>: Abbrev Number: 2 (DW_TAG_partial_unit)
 <1><eb>: Abbrev Number: 4 (DW_TAG_variable)
    <ec>   DW_AT_name        : aaa
    <f0>   DW_AT_type        : <0xe4>
    <f4>   DW_AT_const_value : 1
 <0><10c>: Abbrev Number: 2 (DW_TAG_compile_unit)
    <10e>   DW_AT_name        : <artificial>
 <1><11b>: Abbrev Number: 3 (DW_TAG_variable)
    <11c>   DW_AT_abstract_origin: <0xeb>
...

When running the test-case, we see:
...
(gdb) p aaa^M
No symbol "aaa" in current context.^M
(gdb) FAIL: gdb.dwarf2/imported-unit-abstract-const-value.exp: p aaa
...
while with target board readnow.exp, we have:
...
(gdb) p aaa^M
$1 = 1^M
...

This is due to the fact that there's no aaa symbol in the partial symtabs:
...
Partial symtab for source file <artificial>@0x101 (object 0x351cf40)^M
   ...
Global partial symbols:^M
    `main', function, 0x4004a7^M
^M
...
which is due to the fact that when attempting to add the symbol corresponding
to DIE 0x11b in add_partial_symbol:
...
(gdb) p /x pdi->sect_off
$4 = 0x11b
(gdb) p pdi.has_const_value
$5 = 0
...
it seems the DW_AT_const_value was not inherited from DIE 0xeb, and
consequently we leave without adding a partial symbol.

Fix this by making sure that partial_die_info::has_const_value is inherited
in partial_die_info::fixup.

Build and reg-tested on x86_64-linux.

Tested test-case with target boards readnow, cc-with-gdb-index and
cc-with-debug-names.  The "print aaa" test fails for cc-with-gdb-index, that's
PR25791, the test passes when applying the corresponding proposed patch.

gdb/ChangeLog:

2020-04-07  Tom de Vries  <tdevries@suse.de>

	PR symtab/25796
	* dwarf2/read.c (can_have_DW_AT_const_value_p): New function.
	(partial_die_info::fixup): Inherit has_const_value.

gdb/testsuite/ChangeLog:

2020-04-07  Tom de Vries  <tdevries@suse.de>

	PR symtab/25796
	* gdb.dwarf2/imported-unit-abstract-const-value.exp: New file.
2020-04-07 17:33:05 +02:00
Tom de Vries 5707e24baa [gdb/symtab] Fix check-psymtab failure for inline function
Consider test-case inline.c, containing an inline function foo:
...
static inline int foo (void) { return 0; }
int main (void) { return foo (); }
...

And the test-case compiled with -O2 and debug info:
...
$ gcc -g inline.c -O2
...

This results in a DWARF entry for foo without pc info:
...
<1><114>: Abbrev Number: 4 (DW_TAG_subprogram)
   <115>   DW_AT_name        : foo
   <119>   DW_AT_decl_file   : 1
   <11a>   DW_AT_decl_line   : 2
   <11b>   DW_AT_prototyped  : 1
   <11b>   DW_AT_type        : <0x10d>
   <11f>   DW_AT_inline      : 3       (declared as inline and inlined)
...

When loading the executable in gdb, we create a partial symbol for foo, but
after expansion into a full symbol table no actual symbol is created,
resulting in a maint check-psymtab failure:
...
(gdb) maint check-psymtab
Static symbol `foo' only found in inline.c psymtab
...

Fix this by skipping this type of partial symbol during the check.

Note that we're not fixing this by not creating the partial symbol, because
this breaks setting a breakpoint on an inlined inline function in a CU for
which the partial symtab has not been expanded (test-case
gdb.dwarf2/break-inline-psymtab.exp).

Tested on x86_64-linux.

gdb/ChangeLog:

2020-04-07  Tom de Vries  <tdevries@suse.de>

	* psymtab.c (maintenance_check_psymtabs): Skip static LOC_BLOCK
	symbols without address.

gdb/testsuite/ChangeLog:

2020-04-07  Tom de Vries  <tdevries@suse.de>

	* gdb.base/check-psymtab.c: New test.
	* gdb.base/check-psymtab.exp: New file.
2020-04-07 10:57:20 +02:00
Kamil Rytarowski 05f00e223d Implement basic threading support in the NetBSD target
Use sysctl(3) as the portable interface to prompt NetBSD threads on
all supported NetBSD versions. In future newer versions could switch
to PT_LWPSTATUS ptrace(2) API that will be supported on NetBSD 10.0
and newer.

Implement as part of nbsd_nat_target:
 - thread_name()         - read descriptive thread name
 - thread_alive()        - check whether a thread is alive
 - post_attach()         - updates the list of threads after attach
 - update_thread_list()  - updates the list of threads
 - pid_to_str()          - translates ptid to a descriptive string

There are two local static functions:
 - nbsd_thread_lister()  - generic LWP lister for a specified pid
 - nbsd_add_threads()    - utility to update the list of threads

Now, GDB on NetBSD can attach to a multithreaded process, spawn
a multithreaded process, list threads, print their LWP+PID numbers
and descriptive thread names.

gdb/ChangeLog:

       * nbsd-nat.h (struct thread_info): Add forward declaration.
       (nbsd_nat_target::thread_alive): Add.
       (nbsd_nat_target::thread_name): Likewise.
       (nbsd_nat_target::update_thread_list): Likewise.
       (update_thread_list::post_attach): Likewise.
       (post_attach::pid_to_str): Likewise.
       * nbsd-nat.c: Include "gdbthread.h" and "inferior.h".
       (nbsd_thread_lister): Add.
       (nbsd_nat_target::thread_alive): Likewise.
       (nbsd_nat_target::thread_name): Likewise.
       (nbsd_add_threads): Likewise.
       (update_thread_list::post_attach): Likewise.
       (nbsd_nat_target::update_thread_list): Likewise.
       (post_attach::pid_to_str): Likewise.
2020-04-06 23:04:36 +02:00
Tom Tromey 6ee448cc2d Select variant field when printing variant
When I updated the Ada variant-printing code to be value-based, I
neglected a couple of issues.  First, print_variant_part must first
extract the variant field before finding the active component; second,
print_field_values should pass in the field value as the outer value
when recursing.

This patch fixes both of these issues.

gdb/ChangeLog
2020-04-06  Tom Tromey  <tromey@adacore.com>

	* ada-valprint.c (print_variant_part): Extract the variant field.
	(print_field_values): Use the field as the outer value when
	recursing.

gdb/testsuite/ChangeLog
2020-04-06  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/variant-record/proc.adb: New file.
	* gdb.ada/variant-record/value.adb: New file.
	* gdb.ada/variant-record/value.s: New file.
	* gdb.ada/variant-record.exp: New file.
2020-04-06 12:59:57 -06:00
Tom Tromey dea34e8cc3 Fix build breakage in NetBSD tdep files
A recent patch caused some build failures in NetBSD tdep files.  I saw
this failure in my --enable-target=all build.

This patch fixes the problems.  Tested by rebuilding.
I am going to check this in.

gdb/ChangeLog
2020-04-06  Tom Tromey  <tromey@adacore.com>

	* sh-nbsd-tdep.c: Include nbsd-tdep.h.
	* ppc-nbsd-tdep.c: Include nbsd-tdep.h.
	* mips-nbsd-tdep.c (mipsnbsd_init_abi): Add missing ";".
	* arm-nbsd-tdep.c: Include nbsd-tdep.h.
	* hppa-nbsd-tdep.c: Include nbsd-tdep.h.
2020-04-06 12:42:40 -06:00
Tom Tromey 93689ce912 Handle complex error type in read_base_type
It turns out there was one more bug in the earlier complex series:
read_base_type could cause an assertion failure on some platforms.  I
found this running the AdaCore internal test suite, but you can also
see it by running gdb's "gdb.cp" tests for x86 (not x86-64).

In particular, the DW_ATE_complex_float case calls
dwarf2_init_complex_target_type, which calls dwarf2_init_float_type,
which can return a type using TYPE_CODE_ERROR.

This patch changes the DWARF reader to handle this case, the same way
that the f-lang.c patch did.  Perhaps init_complex_type really should
be changed to allow TYPE_CODE_ERROR?  I was not sure.

Tested on x86-64 Fedora 30, using an x86 build.  I'm checking this in.

gdb/ChangeLog
2020-04-06  Tom Tromey  <tromey@adacore.com>

	* dwarf2/read.c (read_base_type) <DW_ATE_complex_float>: Handle
	TYPE_CODE_ERROR.
2020-04-06 12:29:09 -06:00
Kamil Rytarowski 7974396223 Add signal number conversions for NetBSD
gdb/ChangeLog:

	* nbsd-tdep.c: Include "gdbarch.h".
	Define enum with NetBSD signal numbers.
	(nbsd_gdb_signal_from_target, nbsd_gdb_signal_to_target): New.
	* alpha-nbsd-tdep.c (alphanbsd_init_abi): Call nbsd_init_abi().
	* amd64-nbsd-tdep.c (amd64nbsd_init_abi): Likewise.
	* arm-nbsd-tdep.c (arm_netbsd_elf_init_abi): Likewise.
	* hppa-nbsd-tdep.c (hppanbsd_init_abi): Likewise.
	* i386-nbsd-tdep.c (i386nbsd_init_abi): Likewise.
	* mips-nbsd-tdep.c (nbsd_init_abi): Likewise.
	* ppc-nbsd-tdep.c (ppcnbsd_init_abi): Likewise.
	* sh-nbsd-tdep.c (shnbsd_init_abi): Likewise.
	* sparc-nbsd-tdep.c (sparc32nbsd_init_abi): Likewise.
	* sparc64-nbsd-tdep.c (sparc64nbsd_init_abi): Likewise.
	* vax-nbsd-tdep.c (vaxnbsd_elf_init_abi): Likewise.
2020-04-06 18:26:59 +02:00
Hannes Domani 9e7c9a03ee Fix attributes of typed enums of typedefs
For this enum:
typedef unsigned char byte;
enum byte_enum : byte
{
  byte_val = 128
};

The unsigned attribute is not set:
(gdb) p byte_val
$1 = -128

That's because it uses the attributes of the 'byte' typedef for the enum.
So this changes it to use the attributes of the underlying 'unsigned char'
instead.

gdb/ChangeLog:

2020-04-03  Hannes Domani  <ssbssa@yahoo.de>

	PR gdb/25325
	* dwarf2/read.c (read_enumeration_type): Fix typed enum attributes.

gdb/testsuite/ChangeLog:

2020-04-03  Hannes Domani  <ssbssa@yahoo.de>

	PR gdb/25325
	* gdb.cp/typed-enum.cc: New test.
	* gdb.cp/typed-enum.exp: New file.
2020-04-03 22:09:54 +02:00
Tom Tromey d9e49b6169 Fix DWARF disassembly of DW_OP_const_type
While debugging another issue, I noticed that disassembling a DWARF
expression using DW_OP_const_type did not work.
disassemble_dwarf_expression was not properly decoding this operation.

This patch fixes the problem.  Tested by re-debugging gdb.

I didn't write a test case because that seemed like overkill for
what's essentially a maintainer's helper.

The expression evaluator does decode this properly, so no other change
was needed.

gdb/ChangeLog
2020-04-03  Tom Tromey  <tromey@adacore.com>

	* dwarf2/loc.c (disassemble_dwarf_expression) <DW_OP_const_type>:
	Read constant block.
2020-04-03 09:15:41 -06:00
Simon Marchi e0fc5c3fcb gdb: use bfd_get_section_contents to read section contents in is_linked_with_cygwin_dll
The function is_linked_with_cygwin_dll currently uses
gdb_bfd_map_section to get some section contents.  This is not ideal
because that memory, which is only used in this function, can't be
released.  Instead, it was suggested to use
bfd_get_full_section_contents.

However, bfd_get_full_section_contents returns a newly allocated buffer,
which is not very practical to use with C++ automatic memory management
constructs.  I decided to make gdb_bfd_get_full_section_contents, a
small alternative to bfd_get_full_section_contents.  It is a small
wrapper around bfd_get_section_contents which returns the full contents
of the section in a gdb::byte_vector.

gdb_bfd_get_full_section_contents could be used at many places that
already allocate a vector of the size of the section and then call
bfd_get_section_contents.  I think these call sites can be updated over
time.

gdb/ChangeLog:

	* gdb_bfd.h: Include gdbsupport/byte-vector.h.
	(gdb_bfd_get_full_section_contents): New declaration.
	* gdb_bfd.c (gdb_bfd_get_full_section_contents): New function.
	* windows-tdep.c (is_linked_with_cygwin_dll): Use
	gdb_bfd_get_full_section_contents.
2020-04-02 15:49:06 -04:00
Simon Marchi e2ff18a0a5 gdb: replace some calls to internal_error with gdb_assert
There are a few spots using the pattern:

  if (condition)
    internal_error (__FILE__, __LINE__,
		    _("failed internal consistency check"));

The message brings no value, since it's pretty the description of a
failed assertion.  Replace a few of these that are obvious with
gdb_assert.

gdb/ChangeLog:

	* exec.c (build_section_table): Replace internal_error with
	gdb_assert.
	(section_table_xfer_memory_partial): Likewise.
	* mdebugread.c (parse_partial_symbols): Likewise.
	* psymtab.c (lookup_partial_symbol): Likewise.
	* utils.c (wrap_here): Likewise.
2020-04-02 15:43:41 -04:00
Tom Tromey 0830d30190 Avoid assertion failure due to complex type change
Tankut Baris Aktemur pointed out that the recent series to change how
complex types are handled introduced a regression.

This assert in init_complex_type was firing:

  gdb_assert (TYPE_CODE (target_type) == TYPE_CODE_INT
	      || TYPE_CODE (target_type) == TYPE_CODE_FLT);

The problem was that f-lang.c could call init_complex_type with a type
whose code was TYPE_CODE_ERROR.

It seemed best to me to fix this in f-lang.c, rather than to change
init_complex_type to accept error types.

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

gdb/ChangeLog
2020-04-02  Tom Tromey  <tromey@adacore.com>

	* f-lang.c (build_fortran_types): Use arch_type to initialize
	builtin_complex_s32 in the TYPE_CODE_ERROR case.
2020-04-02 13:17:27 -06:00
Tom Tromey e7da7f8f71 Micro-optimize partial_die_info::read
While profiling the DWARF reader, I noticed that
partial_die_info::read creates a vector to store attributes.  However,
the vector is not needed, as this code only processes a single
attribute at a time.

This patch removes the vector.  On my machine, this improves the time
of "./gdb ./gdb" from 2.22 seconds to 1.92 seconds (mean times over 10
runs).

Note that the attribute is initialized by read_attribute, so it does
not need any special initialization.  Avoiding this also improves
performance a bit.

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

gdb/ChangeLog
2020-04-02  Tom Tromey  <tromey@adacore.com>

	* dwarf2/read.c (partial_die_info::read): Do not create a vector
	of attributes.
2020-04-02 12:49:35 -06:00
Andrew Burgess c90d28ac89 gdb: Don't remove duplicate entries from the line table
In this commit:

  commit 8c95582da8
  Date:   Mon Dec 30 21:04:51 2019 +0000

      gdb: Add support for tracking the DWARF line table is-stmt field

A change was made in buildsym_compunit::record_line to remove
duplicate line table entries in some cases.  This was an invalid
change, as these duplicate line table entries are used in _some_ cases
as part of prologue detection (see skip_prologue_using_sal).

It might be possible to identify those line table entries that are
required by skip_prologue_using_sal and only keep those duplicates
around, however, I have not done this here.  The original duplicate
removal was done because (a) it was easy to implement, and (b) it
seemed obviously harmless.

As (b) is now known to be false, and implementation would be more
complex, and so (a) is also false.  As such, it seems better to keep
all duplicates until an actual reason presents itself for why we
should remove any.

The original regression was spotted on RISC-V, which makes use of
skip_prologue_using_sal as part of riscv_skip_prologue.  Originally I
created the test gdb.dwarf2/dw2-inline-small-func.exp, however, this
test will not compile on RISC-V as this target doesn't support
.uleb128 or .sleb128 assembler directives containing complex
expressions.  As a result I added the gdb.opt/inline-small-func.exp
test, which exposes the bug on RISC-V, but obviously depends on the
compiler to produce specific DWARF information in order to expose the
bug.  Still this test does ensure we always get the desired result,
even if the DWARF changes.

Originally the gdb.dwarf2/dw2-inline-small-func.exp test passed on
x86-64 even with the duplicate line table entries incorrectly
removed.  The reason for this is that when a compilation unit doesn't
have a 'producer' string then skip_prologue_using_sal is not used,
instead the prologue is always skipped using analysis of the assembler
code.

However, for Clang on x86-64 skip_prologue_using_sal is used, so I
modified the gdb.dwarf2/dw2-inline-small-func.exp test to include a
'producer' string that names the Clang compiler.  With this done the
test would fail on x86-64.

One thing to note is that the gdb.opt/inline-small-func.exp test might
fail on some targets.  For example, if we compare sparc to risc-v by
looking at sparc32_skip_prologue we see that this function doesn't use
skip_prologue_using_sal, but instead uses find_pc_partial_function
directly.  I don't know the full history behind why the code is like
it is, but it feels like sparc32_skip_prologue is an attempt to
duplicate some of the functionality of skip_prologue_using_sal, but
without all of the special cases.  If this is true then the new test
could easily fail on this target, this would suggest that sparc should
consider switching to use skip_prologue_using_sal like risc-v does.

gdb/ChangeLog:

	* buildsym.c (buildsym_compunit::record_line): Remove
	deduplication code.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-small-func-lbls.c: New file.
	* gdb.dwarf2/dw2-inline-small-func.c: New file.
	* gdb.dwarf2/dw2-inline-small-func.exp: New file.
	* gdb.dwarf2/dw2-inline-small-func.h: New file.
	* gdb.opt/inline-small-func.c: New file.
	* gdb.opt/inline-small-func.exp: New file.
	* gdb.opt/inline-small-func.h: New file.
2020-04-02 17:44:03 +01:00
Andrew Burgess 34e9a9fa0a gdb/testsuite: Add support for DW_LNS_set_file to DWARF compiler
Extend the Dejagnu DWARF compiler to support DW_LNS_set_file opcode.
This will be used in a later commit.  There should be no change in the
testsuite after this commit.

gdb/testsuite/ChangeLog:

	* lib/dwarf.exp (Dwarf::lines::program::DW_LNS_set_file): New
	function.
2020-04-02 17:44:03 +01:00
Andrew Burgess 6a35491162 gdb/testsuite: Add compiler options parameter to function_range helper
When using the Dejagnu DWARF compiler tests will often use the
function_range helper function to extract the extents of a function.
If the plan is to compiler the file with non-default compiler flags
then we must pass those same compiler flags through to the
function_range helper function.

This will be used in a later commit, there should be no change in the
testsuite behaviour after this commit.

gdb/testsuite/ChangeLog:

	* lib/dwarf.exp (function_range): Allow compiler options to be
	specified.
2020-04-02 17:44:03 +01:00
Tom de Vries 880d97770b [gdb/testsuite] Don't use O2 for inlining in break-inline-psymtab.exp
In test-case gdb.dwarf2/break-inline-psymtab.exp we use O2 to enable inlining
of bar into foo in break-inline-psymtab-2.c.

Instead, enforce inlining using __attribute__((always_inline)), to avoid any
optimization-related test issues.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/break-inline-psymtab-2.c (bar): Add
	__attribute__((always_inline)).
	* gdb.dwarf2/break-inline-psymtab.exp: Don't use -O2.
2020-04-02 17:12:49 +02:00
Tom de Vries f32682eaca [gdb/testsuite] Fix silent timeout in gdb.multi/multi-target.exp
While running test-case gdb.multi/multi-target.exp, I observed a silent
timeout related to "monitor exit".

By making the timeout explicit in an expect clause in gdbserver_gdb_exit:
...
+  timeout {
+    warning "Timed out waiting for EOF in server after $monitor_exit"
+  }
...
we get in the log:
...
monitor exit^M
"monitor" command not supported by this target.^M
(gdb) WARNING: Timed out waiting for EOF in server after monitor exit
...

What happens is the following:
- the inferior 5 is selected
- a breakpoint is set in inferior 1
- the breakpoint triggers and we switch to inferior 1
- setup is called by test_continue, which calls clean_restart, which calls
  gdbserver_gdb_exit (due to load_lib gdbserver-support.exp)
- gdbserver_gdb_exit issues "monitor exit"
- gdb responds with "not supported by this target" because inferior 1 is
  native

Fix this by keeping a list of server_spawn_id, and cleaning those up before
calling gdbserver_gdb_exit.

This reduces testing time from 1m22s to 32s.

gdb/testsuite/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	* lib/gdbserver-support.exp (gdbserver_exit): Factor out of ...
	(gdbserver_gdb_exit): ... here.  Add timeout warning.
	* gdb.multi/multi-target.exp (server_spawn_ids): New global var.
	(connect_target_extended_remote): Append new server_spawn_id to
	server_spawn_ids.
	(cleanup): New proc.
	(setup, <toplevel>): Call cleanup.
2020-04-02 09:46:00 +02:00
Tom de Vries 1aa98955b1 [gdb/ada] Fix -readnow FAILs
When running test-case gdb.ada/access_to_packed_array we have:
...
(gdb) print pack.a^M
$1 = (0 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)^M
...
but with target board readnow.exp, we have instead:
...
(gdb) print pack.a^M
'pack.a' has unknown type; cast it to its declared type^M
...

The symbol is normally found by the map_matching_symbols call in
ada-lang.c:add_nonlocal_symbols:
...
  for (objfile *objfile : current_program_space->objfiles ())
    {
      data.objfile = objfile;

      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
					     domain, global, callback,
					     (is_wild_match
					      ? NULL : compare_names));
...
which maps onto psym_map_matching_symbols.

Function psym_map_matching_symbols iterates over all the partial symtabs,
and:
- if not expanded, searches in the partial symtab:
  - if not found, continues to the next
  - if found, expands into full symtab
- searches in the full symtab

However, with -readnow the call maps onto dw2_map_matching_symbols instead,
which is unimplemented, and consequently no symbol is found.

Fix this by detecting -readnow in dw2_map_matching_symbols, and handling that
appropriately given that partial symtabs are not present, and full symtabs
are: iterate over all the symtabs and search them.

Tested on x86_64-linux, with native and target board -readnow.

This removes 217 FAILs with board -readnow.

gdb/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	PR ada/24671
	* dwarf2/read.c (dw2_map_matching_symbols): Handle -readnow.
2020-04-02 08:58:38 +02:00
Tom de Vries d321419811 [gdb] Use partial symbol table to find language for main
When language is set to auto, part of loading an executable is to update the
language accordingly.  This is implemented by set_initial_language.

The implementation of set_initial_language works as follows:
- check if any objfile in the progspace has name_of_main/language_of_main
  set, and if so, use the first one found. [ This is what you get f.i. when
  using dwarf with DW_AT_main_subprogram. ]
- otherwise, check for known names in the minimal symbols, and either:
- use the associated language if any (f.i. for ada), or
- lookup the symbol in the symtab for the name and use the symbol language
  (f.i. for c/c++).

The symbol lookup can be slow though.

In the case of the cc1 binary from PR23710 comment 1, getting to the initial
prompt takes ~8s:
...
$ time.sh gdb cc1 -batch -ex "show language"
The current source language is "auto; currently c++".
maxmem: 1272260
real: 8.05
user: 7.73
system: 0.38
...
but if we skip guessing the initial language by setting it instead, it takes
only ~4s:
...
$ time.sh gdb -iex "set language c++" cc1 -batch -ex "show language"
The current source language is "c++".
maxmem: 498272
real: 3.99
user: 3.90
system: 0.15
...

In both cases, we load the partial symbols for the executable, but in the
first case only we also do a lookup of main, which causes the corresponding
partial symtab to be expanded into a full symtab.

Ideally, we'd like to get the language of the symbol without triggering
expansion into a full symtab, and get the speedup without having to set the
language manually.

There's a related fixme in the header comment of set_initial_language:
...
/* Set the initial language.

   FIXME: A better solution would be to record the language in the
   psymtab when reading partial symbols, and then use it (if known) to
   set the language.  This would be a win for formats that encode the
   language in an easily discoverable place, such as DWARF.  For
   stabs, we can jump through hoops looking for specially named
   symbols or try to intuit the language from the specific type of
   stabs we find, but we can't do that until later when we read in
   full symbols.  */

void
set_initial_language (void)
...

Since we're already tracking the language of partial symbols, use this to set
the language for the main symbol.

Note that this search in partial symbol tables is not guaranteed to yield the
same result as the lookup_symbol_in_language call currently done in
set_initial_language.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	* dwarf2/read.c (dwarf2_gdb_index_functions,
	dwarf2_debug_names_functions): Init lookup_global_symbol_language with
	NULL.
	* psymtab.c (psym_lookup_global_symbol_language): New function.
	(psym_functions): Init psym_lookup_global_symbol_language with
	psym_lookup_global_symbol_language.
	* symfile-debug.c (debug_sym_quick_functions): Init
	lookup_global_symbol_language with NULL.
	* symfile.c (set_initial_language): Remove fixme comment.
	* symfile.h (struct quick_symbol_functions): Add
	lookup_global_symbol_language.
	* symtab.c (find_quick_global_symbol_language): New function.
	(find_main_name): Use find_quick_global_symbol_language.

gdb/testsuite/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	* gdb.base/main-psymtab.exp: New file.
2020-04-02 08:47:49 +02:00
Tom de Vries cc77ed241b [gdb/testsuite] Accept new complex print style in mixed-lang-stack.exp
Since commit 981c08ce72 "Change how complex types are printed in C", we see
these FAILs:
...
FAIL: gdb.fortran/mixed-lang-stack.exp: lang=auto: info args in frame #6
FAIL: gdb.fortran/mixed-lang-stack.exp: lang=c: info args in frame #6
FAIL: gdb.fortran/mixed-lang-stack.exp: lang=c: info args in frame #7
FAIL: gdb.fortran/mixed-lang-stack.exp: lang=c++: info args in frame #6
FAIL: gdb.fortran/mixed-lang-stack.exp: lang=c++: info args in frame #7
...

The problem is that printing of complex types has changed from:
...
d = 4 + 5 * I
...
to:
...
d = 4 + 5i
...
but the test-case still checks for the old printing style.

Fix this by updating the test-case to check for the new style.

gdb/testsuite/ChangeLog:

2020-04-02  Tom de Vries  <tdevries@suse.de>

	* gdb.fortran/mixed-lang-stack.exp: Accept new complex printing style.
2020-04-02 08:38:47 +02:00
Simon Marchi 2836752f8f gdb: fix style issues in is_linked_with_cygwin_dll
gdb/ChangeLog:

	* windows-tdep.c (is_linked_with_cygwin_dll): Fix style.
2020-04-01 17:42:24 -04:00
Bernd Edlinger 64dc2d4bd2 Fix an undefined behavior in record_line
Additionally do not completely remove symbols
at the same PC than the end marker, instead
make them non-is-stmt breakpoints.

2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* buildsym.c (record_line): Fix undefined behavior and preserve
	lines at eof.
2020-04-01 23:41:12 +02:00
Bernd Edlinger bbe3dc410b Fix the resizing condition of the line table
That was wasting one element.

2020-04-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* buildsym.c (record_line): Fix the resizing condition.
2020-04-01 23:37:46 +02:00
Tom Tromey 6b4a335bf7 Fix value_literal_complex comment
Christian pointed out that the value_literal_complex was still a bit
weird; this patch rewrites it and moves it to value.h.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* value.h (value_literal_complex): Add comment.
	* valops.c (value_literal_complex): Refer to value.h.
2020-04-01 14:09:53 -06:00
Tom Tromey 3638a098a2 Add _Complex type support to C parser
This changes the C parser to add support for complex types in casts.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* c-exp.y (FLOAT_KEYWORD, COMPLEX): New tokens.
	(scalar_type): New rule, from typebase.
	(typebase): Use scalar_type.  Recognize complex types.
	(field_name): Handle FLOAT_KEYWORD.
	(ident_tokens): Add _Complex and __complex__.

gdb/testsuite/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/complex-parts.exp: Add type tests.
2020-04-01 14:09:53 -06:00
Tom Tromey c34e871466 Implement complex arithmetic
This adds support for complex arithmetic to gdb.  Now something like
"print 23 + 7i" will work.

Addition, subtraction, multiplication, division, and equality testing
are supported binary operations.

Unary +, negation, and complement are supported.  Following GCC, the ~
operator computes the complex conjugate.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	PR exp/25299:
	* valarith.c (promotion_type, complex_binop): New functions.
	(scalar_binop): Handle complex numbers.  Use promotion_type.
	(value_pos, value_neg, value_complement): Handle complex numbers.

gdb/testsuite/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/complex-parts.exp: Add arithmetic tests.
2020-04-01 14:09:53 -06:00
Tom Tromey fa649bb7d3 Change the C parser to allow complex constants
This changes the C parser to allow complex constants.  Now something
like "print 23i" will work.

There are no tests in this patch; they come later.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* c-exp.y (COMPLEX_INT, COMPLEX_FLOAT): New tokens.
	(exp) <COMPLEX_INT, COMPLEX_FLOAT>: New rules.
	(parse_number): Handle complex numbers.
2020-04-01 14:09:53 -06:00
Tom Tromey 981c08ce72 Change how complex types are printed in C
GCC accepts the "i" suffix for complex numbers.  I think this is nicer
to read than the current output, so this patch changes the C code to
print complex numbers this way.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* c-valprint.c (c_decorations): Change complex suffix to "i".

gdb/testsuite/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* gdb.compile/compile.exp: Update.
	* gdb.compile/compile-cplus.exp: Update.
	* gdb.base/varargs.exp: Update.
	* gdb.base/floatn.exp: Update.
	* gdb.base/endianity.exp: Update.
	* gdb.base/callfuncs.exp (do_function_calls): Update.
	* gdb.base/funcargs.exp (complex_args, complex_integral_args)
	(complex_float_integral_args): Update.
	* gdb.base/complex.exp: Update.
	* gdb.base/complex-parts.exp: Update.
2020-04-01 14:09:53 -06:00
Tom Tromey 4c99290df0 Add accessors for members of complex numbers
This introduces two new functions that make it simpler to access the
components of a complex number.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* valprint.c (generic_value_print_complex): Use accessors.
	* value.h (value_real_part, value_imaginary_part): Declare.
	* valops.c (value_real_part, value_imaginary_part): New
	functions.
	* value.c (creal_internal_fn, cimag_internal_fn): Use accessors.
2020-04-01 14:09:52 -06:00
Tom Tromey 5b930b4538 Change how complex types are created
This patch changes how complex types are created.  init_complex_type
and arch_complex_type are unified, and complex types are reused, by
attaching them to the underlying scalar type.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tom@tromey.com>

	* stabsread.c (rs6000_builtin_type, read_sun_floating_type)
	(read_range_type): Update.
	* mdebugread.c (basic_type): Update.
	* go-lang.c (build_go_types): Use init_complex_type.
	* gdbtypes.h (struct main_type) <complex_type>: New member.
	(init_complex_type): Update.
	(arch_complex_type): Don't declare.
	* gdbtypes.c (init_complex_type): Remove "objfile" parameter.
	Make name if none given.  Use alloc_type_copy.  Look for cached
	complex type.
	(arch_complex_type): Remove.
	(gdbtypes_post_init): Use init_complex_type.
	* f-lang.c (build_fortran_types): Use init_complex_type.
	* dwarf2/read.c (read_base_type): Update.
	* d-lang.c (build_d_types): Use init_complex_type.
	* ctfread.c (read_base_type): Update.
2020-04-01 14:09:52 -06:00
Tom Tromey 3d1cfd43be Move Rust union tests to new file
I wanted to run the gdb.rust tests against older versions of the Rust
compiler, to ensure that changes I am making don't break debugging
when using older compilers.

However, this did not work because simple.rs now uses unchecked
unions, which were only added in Rust 1.19.

This patch splits the union code into its own file, so that simple.exp
can continue to work.  I tested this with selected rust versions back
to 1.12.

gdb/testsuite/ChangeLog
2020-04-01  Tom Tromey  <tromey@adacore.com>

	* gdb.rust/union.rs: New file.
	* gdb.rust/union.exp: New file.
	* gdb.rust/simple.rs (Union, Union2): Move to union.rs.
	(main): Update.
	* gdb.rust/simple.exp: Move union tests to union.exp.
2020-04-01 14:08:17 -06:00
Tom Tromey e033dfa92f Remove local variable from simple.rs test case
This removes the "y0" variable from simple.rs:main.  This variable
isn't needed by the test case, and it uses a form of initialization
that was added in rust 1.17.  Removing this makes it simpler to run
the gdb.rust tests against older versions of rustc.

gdb/testsuite/ChangeLog
2020-04-01  Tom Tromey  <tromey@adacore.com>

	* gdb.rust/simple.rs (main): Remove "y0".
2020-04-01 14:08:17 -06:00
Tankut Baris Aktemur 53cccef118 gdb/infrun: stop all threads if there exists a non-stop target
Stop all threads not only if the current target is non-stop, but also
if there exists a non-stop target.

The multi-target patch (5b6d1e4fa4 "Multi-target support") made the
following change to gdb/inf-child.c:

void
 inf_child_target::maybe_unpush_target ()
 {
-  if (!inf_child_explicitly_opened && !have_inferiors ())
+  if (!inf_child_explicitly_opened)
     unpush_target (this);
 }

If we are in all-stop mode with multiple inferiors, and an exit event
is received from an inferior, target_mourn_inferior() gets to this
point and without the have_inferiors() check, the target is unpushed.
This leads to having exec_ops as the top target.

Here is a test scenario.  Two executables, ./a.out returns
immediately; ./sleepy just sleeps.

  $ gdb ./sleepy
  (gdb) start
  ...
  (gdb) add-inferior -exec ./a.out
  ...
  (gdb) inferior 2
  [Switching to inferior 2..
  (gdb) start
  ...
  (gdb) set schedule-multiple on
  (gdb) set debug infrun 1
  (gdb) continue

At this point, the exit event is received from ./a.out.  Normally,
this would lead to stop_all_threads() to also stop ./sleepy, but this
doesn't happen, because target_is_non_stop_p() returns false.  And it
returns false because the top target is no longer the process target;
it is the exec_ops.

This patch modifies 'stop_waiting' to call 'stop_all_threads' if there
exists a non-stop target, not just when the current top target is
non-stop.

Tested on X86_64 Linux.

gdb/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* infrun.c (stop_all_threads): Update assertion, plus when
	stopping threads, take into account that we might be trying
	to stop an all-stop target.
	(stop_waiting): Call 'stop_all_threads' if there exists a
	non-stop target.

gdb/testsuite/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.multi/stop-all-on-exit.c: New test.
	* gdb.multi/stop-all-on-exit.exp: New file.
2020-04-01 21:33:06 +02:00
Tankut Baris Aktemur a0714d305f gdb: define convenience function 'exists_non_stop_target'
Define a predicate function that returns true if there exists an
inferior with a non-stop target.

gdb/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* target.h (exists_non_stop_target): New function declaration.
	* target.c (exists_non_stop_target): New function.
2020-04-01 21:33:05 +02:00
Hannes Domani 60e22c1eac Allow pointer arithmetic with integer references
Considering these variables:
int i = 3;
int &iref = i;

It's not possible to do any pointer arithmetic with iref:
(gdb) p &i+iref
Argument to arithmetic operation not a number or boolean.

So this adds checks for references to integers in pointer arithmetic.

gdb/ChangeLog:

2020-04-01  Hannes Domani  <ssbssa@yahoo.de>

	PR gdb/24789
	* eval.c (is_integral_or_integral_reference): New function.
	(evaluate_subexp_standard): Allow integer references in
	pointer arithmetic.

gdb/testsuite/ChangeLog:

2020-04-01  Hannes Domani  <ssbssa@yahoo.de>

	PR gdb/24789
	* gdb.cp/misc.cc: Add integer reference variable.
	* gdb.cp/misc.exp: Add test.
2020-04-01 19:15:03 +02:00
Tankut Baris Aktemur e139a727be gdb/remote: do not check for null_ptid in stop reply
A gdbserver does not report a ptid in a 'W' or 'X' packet if multi-process
extensions are not supported or turned off.  See

https://sourceware.org/gdb/current/onlinedocs/gdb/General-Query-Packets.html#multiprocess-extensions
https://sourceware.org/gdb/current/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-Reply-Packets

GDB's remote packet parser checks for whether a stop-reply packet
contains a ptid if the target is non-stop, and issues an error if no
ptid is included:

  if (target_is_non_stop_p () && event->ptid == null_ptid)
    error (_("No process or thread specified in stop reply: %s"), buf);

This leads to the following error when the non-stop
mode is turned on but multi-process extensions are off:

  $ gdb
  (gdb) set non-stop on
  (gdb) set remote multiprocess-feature-packet off
  (gdb) target remote | gdbserver - ./foo
  Remote debugging using | gdbserver - ./foo
  stdin/stdout redirected
  Process ./foo created; pid = 3712
  ...
  (gdb) continue
  Continuing.
  ...
  No process or thread specified in stop reply: W2a
  (gdb)

Because the check is done for stop reply packets in general, a similar
situation occurs if the 'T' or 'Tthread' packet is disabled in
gdbserver (i.e.  via --disable-packet=T).  E.g:

  $ gdb
  (gdb) set non-stop on
  (gdb) target remote | gdbserver --disable-packet=Tthread - ./foo
  ...
  No process or thread specified in stop reply: T0506:0000000000000000;07:10e2ffffff7f0000;10:9060ddf7ff7f0000;

or

  $ gdb
  (gdb) set non-stop on
  (gdb) target remote | gdbserver --disable-packet=T - ./foo
  ...
  No process or thread specified in stop reply: S05

The commit

  commit cada5fc921
  Date:   Wed Mar 11 12:30:13 2020 +0000

      gdb: Handle W and X remote packets without giving a warning

and its predecessor

  commit 24ed6739b6
  Date:   Thu Jan 30 14:35:40 2020 +0000

      gdb/remote: Restore support for 'S' stop reply packet

added warnings for when GDB has to make a guess for a missing ptid in
case of multiple threads/inferiors.  These warnings should suffice.
So, the simple solution is to remove the check completely.

Regression-tested on X86_64 Linux.

gdb/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* remote.c (remote_target::remote_parse_stop_reply): Remove the
	check for no ptid in the stop reply when the target is non-stop.

gdb/testsuite/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.server/stop-reply-no-thread.exp: Enhance the test
	scenario to cover execution until the end and also the case
	when no packet is disabled when starting gdbserver.
2020-04-01 16:57:39 +02:00
Tom Tromey e0802d5996 Avoid copying in lookup_name_info
lookup_name_info always copies the name that is passed in.  However,
normally a copy is not needed.  This patch changes this class to avoid
copying.  This required changing the "name" method to return something
else; I chose a gdb::string_view, to avoid excessive calls to strlen
in the code using the lookup_name_info.  However, as this class does
not allow an arbitrary string_view, I've also added a c_str method
that guarantees a \0-terminated result -- a pedantic difference but
one that respects the string_view contract, IMO.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tromey@adacore.com>

	* symtab.h (class lookup_name_info) <lookup_name_info>: Change
	"name" parameter to rvalue reference.  Initialize m_name_holder.
	<lookup_name_info>: New overloads.
	<name>: Return gdb::string_view.
	<c_str>: New method.
	<make_ignore_params>: Update.
	<search_name_hash>: Update.
	<language_lookup_name>: Return const char *.
	<m_name>: Change type.
	* symtab.c (demangle_for_lookup_info::demangle_for_lookup_info)
	(demangle_for_lookup_info::demangle_for_lookup_info): Update.
	(lookup_name_info::match_any): Update.
	* psymtab.c (match_partial_symbol, lookup_partial_symbol):
	Update.
	* minsyms.c (linkage_name_str): Update.
	* language.c (default_symbol_name_matcher): Update.
	* dwarf2/read.c (mapped_index_base::find_name_components_bounds):
	Update.
	* ada-lang.c (ada_fold_name): Change parameter to string_view.
	(ada_lookup_name_info::ada_lookup_name_info): Update.
	(literal_symbol_name_matcher): Update.
2020-04-01 07:47:13 -06:00
Tom Tromey 8c072cb6a1 Avoid some copying in psymtab.c
I noticed that psymtab.c was always copying the search string in
psymtab_search_name, even when it wasn't necessary.  This patch
removes this function in favor of using the make_ignore_params feature
of lookup_name_info.

Once I had done that, I noticed that lookup_partial_symbol was
creating a lookup_name_info.  However, this function called in loops,
causing even more excess allocation.  This patch further fixes this by
hosting the creation of the lookup_name_info into the callers.

gdb/ChangeLog
2020-04-01  Tom Tromey  <tromey@adacore.com>

	* psymtab.c (psymtab_search_name): Remove function.
	(psym_lookup_symbol): Create search name and lookup name here.
	(lookup_partial_symbol): Remove "name" parameter; add
	lookup_name.
	(psym_expand_symtabs_for_function): Update.
2020-04-01 07:47:13 -06:00
Tom Tromey 6f29a53415 Fix py-tui.c build problem
py-tui.c can fail to build if the ncurses development headers are not
installed, but if Python was built against ncurses.  In this case, the
Python headers will define HAVE_NCURSES_H, confusing gdb_curses.h.

This patch fixes the problem by moving this include inside
"#ifdef TUI".

gdb/ChangeLog
2020-03-31  Joel Jones  <joelkevinjones@gmail.com>

	PR tui/25597:
	* python/py-tui.c: Include gdb_curses.h inside of #ifdef TUI.
2020-03-31 14:09:36 -06:00
Tom Tromey af62665e13 Don't pass NULL to memcpy in gdb
I compiled gdb with -fsanitize=undefined and ran the test suite.

A couple of reports came from passing NULL to memcpy, e.g.:

[...]btrace-common.cc:176:13: runtime error: null pointer passed as argument 2, which is declared to never be null

While it would be better to fix this in the standard, in the meantime
it seems easy to avoid this error.

gdb/ChangeLog
2020-03-31  Tom Tromey  <tromey@adacore.com>

	* dwarf2/abbrev.c (abbrev_table::read): Conditionally call
	memcpy.

gdbsupport/ChangeLog
2020-03-31  Tom Tromey  <tromey@adacore.com>

	* btrace-common.cc (btrace_data_append): Conditionally call
	memcpy.
2020-03-31 07:29:53 -06:00
Tom de Vries 16b0db75af [gdb/testsuite] Fix c-linkage-name.exp with -flto
When running test-case gdb.base/c-linkage-name.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, I run into:
...
PASS: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: no
FAIL: gdb.base/c-linkage-name.exp: print symada__cS before partial symtab \
  expansion
...

The test-case tries to print a symbol before and after symtab expansion.

And it tries to ensure (since commit 13c3a74afb) that the symtab containing
the symbol is not yet expanded when doing the 'before' print, by placing the
symbol in a different CU (c-linkage-name-2.c) from the one containing main
(c-linkage-name.c), such that when we load the exec and expand the symtab
containing main, the symtab containing the symbol isn't.

The generated debug info for the test-case when using mentioned target board
however is structured like this:
...
 <0><d2>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <d8>   DW_AT_name        : <artificial>
 <1><f4>: Abbrev Number: 2 (DW_TAG_imported_unit)
    <f5>   DW_AT_import      : <0x16b>  [Abbrev Number: 1]
 <1><f9>: Abbrev Number: 2 (DW_TAG_imported_unit)
    <fa>   DW_AT_import      : <0x19c>  [Abbrev Number: 1]
 <1><fe>: Abbrev Number: 3 (DW_TAG_subprogram)
    <ff>   DW_AT_abstract_origin: <0x17d>
 <1><115>: Abbrev Number: 4 (DW_TAG_variable)
    <116>   DW_AT_abstract_origin: <0x1ce>
 <0><16b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <171>   DW_AT_name        : c-linkage-name.c
 <1><17d>: Abbrev Number: 2 (DW_TAG_subprogram)
    <17e>   DW_AT_name        : main
 <0><19c>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <1a2>   DW_AT_name        : c-linkage-name-2.c
 <1><1ce>: Abbrev Number: 5 (DW_TAG_variable)
    <1cf>   DW_AT_name        : mundane
    <1d6>   DW_AT_linkage_name: symada__cS
...

So, the CU named <artificial> contains both the concrete main and the concrete
symbol, which explains the FAIL.

The first test should fail, but passes for two reasons.

First of all, due to PR symtab/25700, we have two regular partial symtabs
c-linkage-name-2.c instead of one, and one of them is expanded, the other one
not:
...
  { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38d6f60)
    readin yes
  { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38d6fe0)
    readin no
...

And then there's the include symtab, which is also not expanded:
...
  { psymtab c-linkage-name-2.c ((struct partial_symtab *) 0x38143e0)
    readin no
...

Fix the FAIL by explicitly setting the language before load, changing the
language setting from auto/c to manual/c, such that the symtab containing main
is no longer expanded.

And make the symtab expansion testing more robust by using the output of
"maint info symtabs" instead of "maint info psymtabs".

Tested on x86_64-linux, using native and target boards cc-with-gdb-index.exp,
cc-with-debug-names.exp, readnow.exp and
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects.

gdb/testsuite/ChangeLog:

2020-03-31  Tom de Vries  <tdevries@suse.de>

	* gdb.base/c-linkage-name.exp: Fix test-case comment.  Set language to
	c.  Use "maint info symtabs" to check symtab expansion.
2020-03-31 12:17:27 +02:00
Nelson Chu d1a89da5de RISC-V: Update CSR to privileged spec 1.11.
gas/
	* testsuite/gas/riscv/alias-csr.d: Move this to priv-reg-pseudo.
	* testsuite/gas/riscv/alias-csr.s: Likewise.
	* testsuite/gas/riscv/no-aliases-csr.d: Move this
	to priv-reg-pseudo-noalias.
	* testsuite/gas/riscv/bad-csr.d: Rename to priv-reg-fail-nonexistent.
	* testsuite/gas/riscv/bad-csr.l: Likewise.
	* testsuite/gas/riscv/bad-csr.s: Likewise.
	* testsuite/gas/riscv/satp.d: Removed.  Already included in priv-reg.
	* testsuite/gas/riscv/satp.s: Likewise.
	* testsuite/gas/riscv/priv-reg-pseudo.d: New testcase for all pseudo
	csr instruction, including alias-csr testcase.
	* testsuite/gas/riscv/priv-reg-pseudo.s: Likewise.
	* testsuite/gas/riscv/priv-reg-pseudo-noalias.d: New testcase for all
	pseudo instruction with objdump -Mno-aliases.
	* testsuite/gas/riscv/priv-reg-fail-nonexistent.d: New testcase.
	* testsuite/gas/riscv/priv-reg-fail-nonexistent.l: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-nonexistent.s: Likewise.
	* testsuite/gas/riscv/priv-reg.d: Update CSR to 1.11.
	* testsuite/gas/riscv/priv-reg.s: Likewise.
	* testsuite/gas/riscv/priv-reg-fail-rv32-only.l: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.s: Likewise.

	include/
	* opcode/riscv-opc.h: Update CSR to 1.11.

	gdb/
	* features/riscv/32bit-csr.xml: Regenerated.
	* features/riscv/64bit-csr.xml: Regenerated.
2020-03-30 12:24:53 -07:00
Tom Tromey d8af906814 Change ada_which_variant_applies to value API
While debugging an Ada regression, I noticed that all the callers of
ada_which_variant_applies desconstruct a value, only to have it be
reconstructed by this function.

This patch removes this inefficiency in favor of simply passing in the
value directly.

Tested on x86-64 Fedora 30.

gdb/ChangeLog
2020-03-30  Tom Tromey  <tromey@adacore.com>

	* ada-valprint.c (print_variant_part): Update.
	* ada-lang.h (ada_which_variant_applies): Update.
	* ada-lang.c (ada_which_variant_applies): Remove outer_type and
	outer_valaddr parameters; replace with "outer" value parameter.
	(to_fixed_variant_branch_type): Update.
2020-03-30 11:54:50 -06:00
Pedro Franco de Carvalho 227c0bf4b3 [PowerPC] Fix debug register issues in ppc-linux-nat
This patch fixes some issues with debug register handling for the powerpc
linux native target.

Currently, the target methods for installing and removing hardware
breakpoints and watchpoints in ppc-linux-nat.c affect all threads known to
linux-nat, including threads of different processes.

This patch changes ppc-linux-nat.c so that only the process of
inferior_ptid is affected by these target methods, as GDB expects.

This is done in the same way as various other architectures.  The
install/remove target methods only register a hardware breakpoint or
watchpoint, and then send a stop signal to the threads.  The debug
registers are only changed with ptrace right before each thread is next
resumed, using low_prepare_to_resume.

There are two interfaces to modify debug registers for linux running on
powerpc, with different sets of ptrace requests:

- PPC_PTRACE_GETHWDBGINFO, PPC_PTRACE_SETHWDEBUG, and
  PPC_PTRACE_DELHWDEBUG.

   Or

- PTRACE_SET_DEBUGREG and PTRACE_GET_DEBUGREG

The first set (HWDEBUG) is the more flexible one and allows setting
watchpoints with a variable watched region length and, for certain
embedded processors, multiple types of debug registers (e.g. hardware
breakpoints and hardware-assisted conditions for watchpoints).
Currently, server processors only provide one watchpoint.  The second one
(DEBUGREG) only allows setting one debug register, a watchpoint, so we
only use it if the first one is not available.

The HWDEBUG interface handles debug registers with slot numbers.  Once a
hardware watchpoint or breakpoint is installed (with
PPC_PTRACE_SETHWDEBUG), ptrace returns a slot number.  This slot number
can then be used to remove the watchpoint or breakpoint from the inferior
(with PPC_PTRACE_DELHWDEBUG).  The first interface also provides a
bitmask of available debug register features, which can be obtained with
PPC_PTRACE_GETHWDBGINFO.

When GDB first tries to use debug registers, we try the first interface
with a ptrace call, and if it isn't available, we fall back to the second
one, if available.  We use EIO as an indicator that an interface is not
available in the kernel.  For simplicity, with any other error we
immediately assume no interface is available.  Unfortunately this means
that if a process is killed by a signal right before we try to detect the
interface, we might get an ESRCH, which would prevent debug registers to
be used in the GDB session.  However, it isn't clear that we can safely
raise an exception and try again in the future in all the contexts where
we try to detect the interface.

If the HWDEBUG interface works but provides no feature bits, the target
falls back to the DEBUGREG interface.  When the kernel is configured
without CONFIG_HW_BREAKPOINTS (selected by CONFIG_PERF_EVENTS), there is
a bug that causes watchpoints installed with the HWDEBUG interface not to
trigger.  When this is the case, the feature bits will be zero, which is
used as the indicator to fall back to the DEBUGREG interface.  This isn't
ideal, but has always been the behavior of GDB before this patch, so I
decided not to change it.

A flag indicates for each thread if its debug registers need to be
updated the next time it is resumed.  The flag is set whenever the upper
layers request or remove a hardware watchpoint or breakpoint, or when a
new thread is detected.  Because some kernel configurations disable
watchpoints after they are hit, we also use the last stop reason of the
LWP to determine whether we should update the debug registers.  It isn't
clear that this is also true of BookE hardware breakpoints, but we also
check their stop reason to be on the safe side, since it doesn't hurt.

A map from process numbers to hardware watchpoint or breakpoint objects
keeps track of what has been requested by the upper layers of GDB, since
for GDB installing a hardware watchpoint or breakpoint means doing so for
the whole process.

When using the HWDEBUG interface we also have to keep track of which
slots were last installed in each thread with a map from threads to the
slots, so that they can be removed when needed.  When resuming a thread,
we remove all the slots using this map, then we install all the hardware
watchpoints and breakpoints from the per-process map of requests, and
then update the per-thread map accordingly.

This per-thread state is also used for copying the debug register state
after a fork or a clone is detected.  The kernel might do this depending
on the configuration.  Recent kernels running on server processors that
were configured with CONFIG_PERF_EVENTS (and therefore
CONFIG_HW_BREAKPOINTS) don't copy debug registers across forks and
clones.  Recent kernels without CONFIG_HW_BREAKPOINTS copy this state.  I
believe that on embedded processors (e.g. a ppc440) the debug register
state is copied, but I haven't been able to test this.  To handle both
cases, the per-thread state is always copied when forks and clones are
detected, and when we resume the thread and delete the debug register
slots before updating them, we ignore ENOENT errors.

We don't need to handle this when using the DEBUGREG interface since it
only allows one hardware watchpoint and doesn't return slot numbers, we
just set or clear this watchpoint when needed.

Since we signal running threads to stop after a request is processed, so
that we can update their debug registers when they are next resumed,
there will be a time between signalling the threads and their stop during
which the debug registers haven't been updated, even if the target
methods completed.

The tests in gdb.threads/watchpoint-fork.exp no longer fail with this
patch.

gdb/ChangeLog:
2020-03-30  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* ppc-linux-nat.c: Include <algorithm>, <unordered_map>, and
	<list>.  Remove inclusion of observable.h.
	(PPC_DEBUG_CURRENT_VERSION): Move up define.
	(struct arch_lwp_info): New struct.
	(class ppc_linux_dreg_interface): New class.
	(struct ppc_linux_process_info): New struct.
	(struct ppc_linux_nat_target) <low_delete_thread, low_new_fork>
	<low_new_clone, low_forget_process, low_prepare_to_resume>
	<copy_thread_dreg_state, mark_thread_stale>
	<mark_debug_registers_changed, register_hw_breakpoint>
	<clear_hw_breakpoint, register_wp, clear_wp>
	<can_use_watchpoint_cond_accel, calculate_dvc, check_condition>
	<num_memory_accesses, get_trigger_type>
	<create_watchpoint_request, hwdebug_point_cmp>
	<init_arch_lwp_info, get_arch_lwp_info>
	<low_stopped_by_watchpoint, low_stopped_data_address>: Declare as
	methods.
	<struct ptid_hash>: New inner struct.
	<m_dreg_interface, m_process_info, m_installed_hw_bps>: Declare
	members.
	(saved_dabr_value, hwdebug_info, max_slots_number)
	(struct hw_break_tuple, struct thread_points, ppc_threads)
	(have_ptrace_hwdebug_interface)
	(hwdebug_find_thread_points_by_tid)
	(hwdebug_insert_point, hwdebug_remove_point): Remove.
	(ppc_linux_nat_target::can_use_hw_breakpoint): Use
	m_dreg_interface, remove call to PTRACE_SET_DEBUGREG.
	(ppc_linux_nat_target::region_ok_for_hw_watchpoint): Add comment,
	use m_dreg_interface.
	(hwdebug_point_cmp): Change to...
	(ppc_linux_nat_target::hwdebug_point_cmp): ...this method.  Use
	reference arguments instead of pointers.
	(ppc_linux_nat_target::ranged_break_num_registers): Use
	m_dreg_interface.
	(ppc_linux_nat_target::insert_hw_breakpoint): Add comment, use
	m_dreg_interface.  Call register_hw_breakpoint.
	(ppc_linux_nat_target::remove_hw_breakpoint): Add comment, use
	m_dreg_interface.  Call clear_hw_breakpoint.
	(get_trigger_type): Change to...
	(ppc_linux_nat_target::get_trigger_type): ...this method.  Add
	comment.
	(ppc_linux_nat_target::insert_mask_watchpoint): Update comment,
	use m_dreg_interface.  Call register_hw_breakpoint.
	(ppc_linux_nat_target::remove_mask_watchpoint): Update comment,
	use m_dreg_interface.  Call clear_hw_breakpoint.
	(can_use_watchpoint_cond_accel): Change to...
	(ppc_linux_nat_target::can_use_watchpoint_cond_accel): ...this
	method.  Update comment, use m_dreg_interface and
	m_process_info.
	(calculate_dvc): Change to...
	(ppc_linux_nat_target::calculate_dvc): ...this method.  Use
	m_dreg_interface.
	(num_memory_accesses): Change to...
	(ppc_linux_nat_target::num_memory_accesses): ...this method.
	(check_condition): Change to...
	(ppc_linux_nat_target::check_condition): ...this method.
	(ppc_linux_nat_target::can_accel_watchpoint_condition): Update
	comment, use m_dreg_interface.
	(create_watchpoint_request): Change to...
	(ppc_linux_nat_target::create_watchpoint_request): ...this
	method.  Use m_dreg_interface.
	(ppc_linux_nat_target::insert_watchpoint): Add comment, use
	m_dreg_interface.  Call register_hw_breakpoint or register_wp.
	(ppc_linux_nat_target::remove_watchpoint): Add comment, use
	m_dreg_interface.  Call clear_hw_breakpoint or clear_wp.
	(ppc_linux_nat_target::low_forget_process)
	(ppc_linux_nat_target::low_new_fork)
	(ppc_linux_nat_target::low_new_clone)
	(ppc_linux_nat_target::low_delete_thread)
	(ppc_linux_nat_target::low_prepare_to_resume): New methods.
	(ppc_linux_nat_target::low_new_thread): Remove previous logic,
	only call mark_thread_stale.
	(ppc_linux_thread_exit): Remove.
	(ppc_linux_nat_target::stopped_data_address): Change to...
	(ppc_linux_nat_target::low_stopped_data_address): This. Add
	comment, use m_dreg_interface and m_thread_hw_breakpoints.
	(ppc_linux_nat_target::stopped_by_watchpoint): Change to...
	(ppc_linux_nat_target::stopped_by_watchpoint): This.  Add
	comment.  Call low_stopped_data_address.
	(ppc_linux_nat_target::watchpoint_addr_within_range): Use
	m_dreg_interface.
	(ppc_linux_nat_target::masked_watch_num_registers): Use
	m_dreg_interface.
	(ppc_linux_nat_target::copy_thread_dreg_state)
	(ppc_linux_nat_target::mark_thread_stale)
	(ppc_linux_nat_target::mark_debug_registers_changed)
	(ppc_linux_nat_target::register_hw_breakpoint)
	(ppc_linux_nat_target::clear_hw_breakpoint)
	(ppc_linux_nat_target::register_wp)
	(ppc_linux_nat_target::clear_wp)
	(ppc_linux_nat_target::init_arch_lwp_info)
	(ppc_linux_nat_target::get_arch_lwp_info): New methods.
	(_initialize_ppc_linux_nat): Remove observer callback.
2020-03-30 12:10:13 -03:00
Pedro Franco de Carvalho 4db10d8f49 [PowerPC] Move up some register access routines
Keep the routines related to register access grouped together.

gdb/ChangeLog:
2020-03-30  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* ppc-linux-nat.c (ppc_linux_nat_target::store_registers)
	(ppc_linux_nat_target::auxv_parse)
	(ppc_linux_nat_target::read_description)
	(supply_gregset, fill_gregset, supply_fpregset, fill_fpregset):
	Move up.
2020-03-30 12:08:24 -03:00
Pedro Franco de Carvalho 1310c1b066 Add low_new_clone method to linux_nat_target.
This patch adds a low_new_clone method to linux_nat_target, called after
a PTRACE_EVENT_CLONE is detected, similar to how low_new_fork is called
after PTRACE_EVENT_(V)FORK.

This is useful for targets that need to copy state associated with a
thread that is inherited across clones.

gdb/ChangeLog:
2020-03-30  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-nat.h (low_new_clone): New method.
	* linux-nat.c (linux_handle_extended_wait): Call low_new_clone.
2020-03-30 12:06:43 -03:00
Tom de Vries c0502da688 [gdb/testsuite] Fix c-linkage-name.exp with {cc-with-gdb-index,readnow}.exp
When running test-case gdb.base/c-linkage-name.exp with target board
cc-with-gdb-index.exp, I see:
...
FAIL: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: no
FAIL: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: yes
...
The FAILs are due to the fact that partial symbol tables are not generated for
indexed executables.

When running the same test-case with target board readnow.exp, I see:
...
FAIL: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: no
FAIL: gdb.base/c-linkage-name.exp: print symada__cS before partial symtab \
  expansion
FAIL: gdb.base/c-linkage-name.exp: maint info psymtab: c-linkage-name-2.c: yes
...
The "maint info psymtab" FAILs are also due to fact that the partial symbol
tables not generated, but in this case it's because the symtabs are fully
expanded upon load due to using -readnow.  The "print symada__cS before
partial symtab expansion" test intends to test the state before symbol table
expansion, and with -readnow that's not possible.

Mark these FAILs as UNSUPPORTED.

Tested on x86_64-linux, with native, and target boards cc-with-gdb-index.exp,
cc-with-debug-names.exp and readnow.exp.

gdb/testsuite/ChangeLog:

2020-03-30  Tom de Vries  <tdevries@suse.de>

	* gdb.base/c-linkage-name.exp: Use readnow call to mark a test
	unsupported.
	(verify_psymtab_expanded): Move ...
	* lib/gdb.exp (verify_psymtab_expanded): ... here.  Add unsupported
	test.
	(readnow): New proc.
2020-03-30 10:52:59 +02:00
Simon Marchi 69b037c30c gdb: rename partial symtab expand functions of debug info readers using legacy_psymtab
As I am trying to understand the dynamic of partial_symtab::read_symtab
and partial_symtab::expand_psymtab, I think that renaming these
functions helps make it clear that they are effectively implementations
of the partial_symtab::expand_psymtab method.

gdb/ChangeLog:

	* dbxread.c (dbx_psymtab_to_symtab_1): Rename to...
	(dbx_expand_psymtab): ... this.
	(start_psymtab): Update.
	* mdebugread.c (psymtab_to_symtab_1): Rename to...
	(mdebug_expand_psymtab): ... this.
	(parse_partial_symbols): Update.
	(new_psymtab): Update.
	* xcoffread.c (xcoff_psymtab_to_symtab_1): Rename to...
	(xcoff_expand_psymtab): ... this.
	(xcoff_start_psymtab): Update.
2020-03-29 15:24:48 -04:00
Simon Marchi 48993951ce gdb: rename partial_symtab::read_dependencies to expand_dependencies
This method calls partial_symtab::expand_psymtab on all dependencies of
a psymtab.  Given that there is also a partial_symtab::read_symtab
method, I think it would be clearer to name this function
expand_dependencies, rather than read_dependencies.

gdb/ChangeLog:

	* psympriv.h (partial_symtab) <read_dependencies>: Rename to...
	<expand_dependencies>: ... this.
	* psymtab.c (partial_symtab::read_dependencies): Rename to...
	(partial_symtab::expand_dependencies): ... this.
	* dwarf2/read.c (dwarf2_include_psymtab) <expand_psymtab>:
	Update.
	(dwarf2_psymtab::expand_psymtab): Update.
	* dbxread.c (dbx_psymtab_to_symtab_1): Update.
	* mdebugread.c (psymtab_to_symtab_1): Update.
	* xcoffread.c (xcoff_psymtab_to_symtab_1): Update.
2020-03-29 15:23:48 -04:00
Simon Marchi 3ad830466f gdb: remove discard_psymtab function
This function does not add much value, compared to calling the method on
the psymtab_storage object directly.

gdb/ChangeLog:

	* psympriv.h (discard_psymtab): Remove.
	* dbxread.c (dbx_end_psymtab): Update.
	* xcoffread.c (xcoff_end_psymtab): Update.
2020-03-29 15:23:32 -04:00
Tom Tromey 4d1b9ab645 Fix comment in dwarf2/attribute.h
I noticed that a comment in dwarf2/attribute.h still referred to
dwarf2_get_attr_constant_value.  However, this is now a method on
struct attribute.

gdb/ChangeLog
2020-03-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/attribute.h (struct attribute) <form_is_constant>: Update
	comment.
2020-03-28 09:25:41 -06:00
Tom Tromey f1749218ff Fix formatting of read_attribute_reprocess
I noticed that the start of read_attribute_reprocess had the wrong
formatting.  This patch fixes it.

gdb/ChangeLog
2020-03-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_attribute_reprocess): Fix formatting.
2020-03-28 09:22:53 -06:00
Hannes Domani ebea762639 Always fix system DLL paths for 32bit programs
GetModuleFileNameEx might also return the 64bit system directory for 32bit
programs even for a 32bit gdb:

(gdb) info sharedlibrary
From        To          Syms Read   Shared Object Library
0x779d0000  0x77b34d20  Yes (*)     C:\Windows\SysWOW64\ntdll.dll
0x76850000  0x7694ad9c  Yes (*)     C:\Windows\syswow64\kernel32.dll
0x75421000  0x75466a18  Yes (*)     C:\Windows\syswow64\KernelBase.dll
0x6fbe1000  0x6fcca1c0  Yes (*)     C:\Windows\system32\dbghelp.dll
0x76d31000  0x76ddb2c4  Yes (*)     C:\Windows\syswow64\msvcrt.dll

So this makes the path conversion for all 32bit programs.

gdb/ChangeLog:

2020-03-27  Hannes Domani  <ssbssa@yahoo.de>

	* windows-nat.c (windows_add_all_dlls): Fix system dll paths.
2020-03-27 22:48:03 +01:00
John Baldwin a879b4d5a6 Support AT_BSDFLAGS on FreeBSD.
FreeBSD's kernel recently added a new ELF auxiliary vector entry
holding a mask of software features provided by the kernel.  This
change fixes 'info auxv' to report the name and description for this
vector entry instead of '???'.

include/ChangeLog:

	* elf/common.h (AT_FREEBSD_BSDFLAGS): Define.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_print_auxv_entry): Handle AT_FREEBSD_BSDFLAGS.
2020-03-26 09:48:28 -07:00
Tom Tromey 0826b30a9f Change two functions to be methods on struct attribute
This changes dwarf2_get_ref_die_offset and
dwarf2_get_attr_constant_value to be methods on struct attribute.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
	(mark_common_block_symbol_computed, read_tag_string_type)
	(attr_to_dynamic_prop, read_subrange_type): Update.
	(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
	to be methods on struct attribute.
	(skip_one_die, process_imported_unit_die, read_namespace_alias)
	(read_call_site_scope, partial_die_info::read)
	(partial_die_info::read, lookup_die_type, follow_die_ref):
	Update.
	* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
	from dwarf2_get_ref_die_offset.
	(attribute::constant_value): New method, from
	dwarf2_get_attr_constant_value.
	* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
	Declare method.
	<constant_value>: New method.
2020-03-26 09:28:28 -06:00
Tom Tromey 2b2558bfac Move DWARF-constant stringifying code to new file
This moves the DWARF debugging functions that stringify various
constants to a new file, dwarf2/stringify.c.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf_unit_type_name, dwarf_tag_name)
	(dwarf_attr_name, dwarf_form_name, dwarf_bool_name)
	(dwarf_type_encoding_name): Move to stringify.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/stringify.c.
	* dwarf2/stringify.c: New file.
	* dwarf2/stringify.h: New file.
2020-03-26 09:28:26 -06:00
Tom Tromey eeb647814f Rewrite new die_info methods
This rewrites the two new die_info methods to iterate over attributes
rather than to do two separate searches.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/die.h (struct die_info) <addr_base, ranges_base>:
	Rewrite.
2020-03-26 09:28:26 -06:00
Tom Tromey a39fdb411d Change two more functions to be methods on die_info
This changes lookup_addr_base and lookup_ranges_base to be methods on
die_info.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/die.h (struct die_info) <addr_base, ranges_base>: New
	methods.
	* dwarf2/read.c (lookup_addr_base): Move to die.h.
	(lookup_ranges_base): Likewise.
	(read_cutu_die_from_dwo, read_full_die_1): Update.
2020-03-26 09:28:25 -06:00
Tom Tromey 436c571c6a Remove sibling_die
The sibling_die helper function does not seem to add much value,
considering that many other fields of die_info are directly accessed.
So, this removes it.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_import_statement, read_file_scope)
	(read_type_unit_scope, inherit_abstract_dies, read_func_scope)
	(read_lexical_block_scope, read_call_site_scope)
	(dwarf2_get_subprogram_pc_bounds, get_scope_pc_bounds)
	(handle_struct_member_die, process_structure_scope)
	(update_enumeration_type_from_children)
	(process_enumeration_scope, read_array_type, read_common_block)
	(read_namespace, read_module, read_subroutine_type): Update.
	(sibling_die): Remove.
2020-03-26 09:28:23 -06:00
Tom Tromey 052c8bb83a Change dwarf2_attr_no_follow to be a method
This changes dwarf2_attr_no_follow to be a method on die_info.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (lookup_addr_base, lookup_ranges_base)
	(build_type_psymtabs_reader, read_structure_type)
	(read_enumeration_type, read_full_die_1): Update.
	(dwarf2_attr_no_follow): Move to die.h.
	* dwarf2/die.h (struct die_info) <attr>: New method.
2020-03-26 09:28:22 -06:00
Tom Tromey 2b24b6e4a6 Remove dwarf2_cu::base_known
This removes dwarf2_cu::base_known, changing base_address to be a
gdb::optional.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct dwarf2_cu) <base_known>: Remove.
	<base_address>: Now an optional.
	(dwarf2_find_base_address, dwarf2_rnglists_process)
	(dwarf2_ranges_process, fill_in_loclist_baton)
	(dwarf2_symbol_mark_computed): Update.
2020-03-26 09:28:21 -06:00
Tom Tromey c2d50fd0b3 Move die_info to new header
This moves struct die_info to a new header, dwarf2/die.h.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct die_info): Move to die.h.
	* dwarf2/die.h: New file.
2020-03-26 09:28:21 -06:00
Tom Tromey 0df7ad3a67 Move more code to line-header.c
This moves some more code out of read.c and into line-header.c.
dwarf_decode_line_header is split into two -- the part remaining in
read.c handles interfacing to the dwarf2_cu; while the part in
line-header.c (more or less) purely handles the actual decoding.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/line-header.h (dwarf_decode_line_header): Declare.
	* dwarf2/read.c
	(dwarf2_statement_list_fits_in_line_number_section_complaint):
	Move to line-header.c.
	(read_checked_initial_length_and_offset, read_formatted_entries):
	Likewise.
	(dwarf_decode_line_header): Split into two.
	* dwarf2/line-header.c
	(dwarf2_statement_list_fits_in_line_number_section_complaint):
	Move from read.c.
	(read_checked_initial_length_and_offset, read_formatted_entries):
	Likewise.
	(dwarf_decode_line_header): New function, split from read.c.
2020-03-26 09:28:20 -06:00
Tom Tromey 86c0bb4c57 Convert read_indirect_line_string to a method
This changes read_indirect_line_string to be a method on
dwarf2_per_objfile.  This makes it a bit simpler to share between
files.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_objfile) <read_line_string>:
	Declare method.
	* dwarf2/read.c (read_attribute_value): Update.
	(dwarf2_per_objfile::read_line_string): Rename from
	read_indirect_line_string.
	(read_formatted_entries): Update.
2020-03-26 09:28:19 -06:00
Tom Tromey 2ef46c2fbb Trivial fix in dwarf_decode_macro_bytes
One spot in dwarf_decode_macro_bytes could use the existing "objfile"
local variable.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/macro.c (dwarf_decode_macro_bytes): Use objfile local
	variable.
2020-03-26 09:28:18 -06:00
Tom Tromey 4f9c1eda9f Use a const dwarf2_section_info in macro reader
This changes the DWARF macro reader to use a const dwarf2_section_info.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/macro.h (dwarf_decode_macros): Make section parameter
	const.
	* dwarf2/macro.c (skip_form_bytes, skip_unknown_opcode)
	(dwarf_decode_macro_bytes, dwarf_decode_macros): Make section
	parameter const.
2020-03-26 09:28:17 -06:00
Tom Tromey 5a0e026fe1 Use a const line_header in macro reader
This changes the DWARF macro reader to use a const line_header.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf_decode_macros): Make "lh" const.
	* dwarf2/macro.h (dwarf_decode_macros): Constify "lh" parameter.
	* dwarf2/macro.c (macro_start_file): Constify "lh" parameter.
	(dwarf_decode_macro_bytes, dwarf_decode_macros): Likewise.
2020-03-26 09:28:16 -06:00
Tom Tromey 8844c11b8b Make some line_header methods const
This changes a few line_header methods to be const.  In some cases, a
const overload is added.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/line-header.h (struct line_header) <is_valid_file_index,
	file_names_size, file_full_name, file_file_name>: Use const.
	<file_name_at, file_names>: Add const overload.
	* dwarf2/line-header.c (line_header::file_file_name)
	(line_header::file_full_name): Update.
2020-03-26 09:28:15 -06:00
Tom Tromey c90ec28ae4 Move code to new file dwarf2/macro.c
This moves some more code out of dwarf2/read.c, introducing new files
dwarf2/macro.c and dwarf2/macro.h.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_macro_malformed_definition_complaint)
	(macro_start_file, consume_improper_spaces)
	(parse_macro_definition, skip_form_bytes, skip_unknown_opcode)
	(dwarf_parse_macro_header, dwarf_decode_macro_bytes)
	(dwarf_decode_macros): Move to macro.c.
	* dwarf2/macro.c: New file.
	* dwarf2/macro.h: New file.
	* Makefile.in (COMMON_SFILES): Add dwarf2/macro.c.
2020-03-26 09:28:15 -06:00
Tom Tromey 4f44ae6c69 Add dwarf2_section_info::read_string method
This moves a string-reading function to be a method on
dwarf2_section_info, and then updates the users.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/section.h (struct dwarf2_section_info) <read_string>: New
	method.
	* dwarf2/section.c: New method.  From
	read_indirect_string_at_offset_from.
	* dwarf2/read.c (mapped_debug_names::namei_to_name): Update.
	(read_indirect_string_at_offset_from): Move to section.c.
	(read_indirect_string_at_offset): Rewrite.
	(read_indirect_line_string_at_offset): Remove.
	(read_indirect_string, read_indirect_line_string)
	(dwarf_decode_macro_bytes): Update.
2020-03-26 09:28:14 -06:00
Tom Tromey a0194fa8f2 Convert dwarf2_section_buffer_overflow_complaint to a method
This changes dwarf2_section_buffer_overflow_complaint to be a method
on dwarf2_section_info.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/section.h (struct dwarf2_section_info)
	<overload_complaint>: Declare.
	(dwarf2_section_buffer_overflow_complaint): Don't declare.
	* dwarf2/section.c (dwarf2_section_info::overflow_complaint):
	Rename from dwarf2_section_buffer_overflow_complaint.
	* dwarf2/read.c (skip_one_die, partial_die_info::read)
	(skip_form_bytes, dwarf_decode_macro_bytes): Update.
2020-03-26 09:28:13 -06:00
Tom Tromey 3d27bbdb4b Move dwarf2_section_buffer_overflow_complaint to dwarf2/section.c
This moves dwarf2_section_buffer_overflow_complaint to
dwarf2/section.c.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/section.h (dwarf2_section_buffer_overflow_complaint):
	Declare.
	* dwarf2/section.c (dwarf2_section_buffer_overflow_complaint):
	Move from read.c.
	* dwarf2/read.c (dwarf2_section_buffer_overflow_complaint): Move
	to section.c.
2020-03-26 09:28:12 -06:00
Tom Tromey 9eac9650ce Split dwarf_decode_macros into two overloads
This splits dwarf_decode_macros into two overloads -- one that's
suitable for splitting into a separate file, and one that finds the
correct section and should remain in dwarf2/read.c.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf_decode_macros): Split into two overloads.
2020-03-26 09:28:11 -06:00
Tom Tromey bf80d71052 Change dwarf_decode_macro_bytes calling convention
This changes dwarf_decode_macro_bytes to accept a buildsym_compunit
rather than a dwarf2_cu.  This enables some subsequent changes; and
also makes the function accept a "more specific" parameter.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (macro_start_file): Change "cu" parameter to
	"builder".
	(dwarf_decode_macro_bytes): Likewise.  Add dwarf2_per_objfile
	parameter.
	(dwarf_decode_macros): Update.
2020-03-26 09:28:10 -06:00
Tom Tromey 0314b3901c Add dwz.c and dwz_file::read_string
This changes read_indirect_string_from_dwz to be a method on the
dwz_file, and adds a new dwarf2/dwz.c file.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_attribute_value): Update.
	(read_indirect_string_from_dwz): Move to dwz.c; change into
	method.
	(dwarf_decode_macro_bytes): Update.
	* dwarf2/dwz.h (struct dwz_file) <read_string>: Declare method.
	* dwarf2/dwz.c: New file.
	* Makefile.in (COMMON_SFILES): Add dwz.c.
2020-03-26 09:28:09 -06:00
Tom Tromey 9fda78b611 Introduce dwarf2/dwz.h
This moves "struct dwz_file" to a new header file, dwarf2/dwz.h.

gdb/ChangeLog
2020-03-26  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwz_file): Move to dwz.h.
	* dwarf2/read.c: Add include.
	* dwarf2/index-write.c: Add include.
	* dwarf2/index-cache.c: Add include.
	* dwarf2/dwz.h: New file.
2020-03-26 09:28:08 -06:00
Tom Tromey 33aa3c10f6 Fix error message in compile-object-load.c
I noticed that an error message in compile-object-load.c mentions the
wrong symbol name.  The loop just above the error is looking for
COMPILE_I_EXPR_VAL, but the error references COMPILE_I_EXPR_PTR_TYPE.

I'm checking this in as obvious.  I don't have a test case -- I
noticed it because another patch I'm working on caused this error to
be thrown, but that was due to regression in my patch.

gdb/ChangeLog
2020-03-25  Tom Tromey  <tom@tromey.com>

	* compile/compile-object-load.c (get_out_value_type): Mention
	correct symbol name in error message.
2020-03-25 11:24:08 -06:00
Hannes Domani d503b685c6 Fix WOW64 process system DLL paths
GetModuleFileNameEx returns for some DLLs of WOW64 processes
the path inside the 64bit system directory instead of the 32bit
syswow64 directory.

Problem happens e.g. with dbghelp.dll:

(gdb) start
Temporary breakpoint 1 at 0x415a00: file fiber.cpp, line 430.
Starting program: C:\src\tests\fiber.exe
warning: `C:\Windows\system32\dbghelp.dll': Shared library architecture i386:x86-64 is not compatible with target architecture i386.

Temporary breakpoint 1, main () at fiber.cpp:430
430     {
(gdb) info sharedlibrary
From        To          Syms Read   Shared Object Library
0x77070000  0x771d4d20  Yes (*)     C:\Windows\SysWOW64\ntdll.dll
0x74dc0000  0x74ebad9c  Yes (*)     C:\Windows\syswow64\kernel32.dll
0x75341000  0x75386a18  Yes (*)     C:\Windows\syswow64\KernelBase.dll
0x6f6a1000  0x6f7c48fc  Yes (*)     C:\Windows\system32\dbghelp.dll
0x74d01000  0x74dab2c4  Yes (*)     C:\Windows\syswow64\msvcrt.dll
(*): Shared library is missing debugging information.

This detects this situation and converts the DLL path to the
syswow64 equivalent.

gdb/ChangeLog:

2020-03-25  Hannes Domani  <ssbssa@yahoo.de>

	* windows-nat.c (windows_add_all_dlls): Fix system dll paths.
2020-03-25 15:31:09 +01:00
Tom de Vries 7b1eff95be [gdb] Print user/includes fields for maint commands
The type struct compunit_symtab contains two fields (disregarding field next)
that express relations with other compunit_symtabs: user and includes.

These fields are currently not printed with "maint info symtabs" and
"maint print symbols".

Fix this such that for "maint info symtabs" we print:
...
   { ((struct compunit_symtab *) 0x23e8450)
     debugformat DWARF 2
     producer (null)
     dirname (null)
     blockvector ((struct blockvector *) 0x23e8590)
+    user ((struct compunit_symtab *) 0x2336280)
+    ( includes
+      ((struct compunit_symtab *) 0x23e85e0)
+      ((struct compunit_symtab *) 0x23e8960)
+    )
         { symtab <unknown> ((struct symtab *) 0x23e85b0)
           fullname (null)
           linetable ((struct linetable *) 0x0)
         }
   }
...

And for "maint print symbols" we print:
...
-Symtab for file <unknown>
+Symtab for file <unknown> at 0x23e85b0
 Read from object file /data/gdb_versions/devel/a.out (0x233ccf0)
 Language: c

 Blockvector:

 block #000, object at 0x23e8530, 0 syms/buckets in 0x0..0x0
   block #001, object at 0x23e84d0 under 0x23e8530, 0 syms/buckets in 0x0..0x0

+Compunit user: 0x2336300
+Compunit include: 0x23e8900
+Compunit include: 0x23dd970
...
Note: for user and includes we don't list the actual compunit_symtab address,
but instead the corresponding symtab address, which allows us to find that
symtab elsewhere in the output (given that we also now print the address of
symtabs).

gdb/ChangeLog:

2020-03-25  Tom de Vries  <tdevries@suse.de>

	* symtab.h (is_main_symtab_of_compunit_symtab): New function.
	* symmisc.c (dump_symtab_1): Print user and includes fields.
	(maintenance_info_symtabs): Same.
2020-03-25 12:38:05 +01:00
Andrew Burgess dd8953924b gdb/riscv: Apply NaN boxing when writing return values into registers
When setting up function parameters we already perform NaN boxing, as
required by the RISC-V ABI, however, we don't do this when writing
values into registers as part of setting up a return value.

This commit moves the NaN boxing code into a small helper function,
and then makes use of this function when setting up function
parameters, and also when setting up return values.

This should resolve this failure:

  FAIL: gdb.base/return-nodebug.exp: float: full width of the returned result

gdb/ChangeLog:

	PR gdb/25489
	* riscv-tdep.c (riscv_arg_info::c_offset): Update comment.
	(riscv_regcache_cooked_write): New function.
	(riscv_push_dummy_call): Use new function.
	(riscv_return_value): Likewise.
2020-03-25 11:29:00 +00:00
Simon Marchi 5ab2fbf185 gdb: bool-ify follow_fork
Change parameters and return value of the various follow_fork
functions/methods from int to bool.

gdb/ChangeLog:

	* fbsd-nat.c (fbsd_nat_target::follow_fork): Change bool to int.
	* fbsd-nat.h (class fbsd_nat_target) <follow_fork>: Likewise.
	* inf-ptrace.c (inf_ptrace_target::follow_fork): Likewise.
	* inf-ptrace.h (struct inf_ptrace_target) <follow_fork>: Likewise.
	* infrun.c (follow_fork): Likewise.
	(follow_fork_inferior): Likewise.
	* linux-nat.c (linux_nat_target::follow_fork): Likewise.
	* linux-nat.h (class linux_nat_target): Likewise.
	* remote.c (class remote_target) <follow_fork>: Likewise.
	(remote_target::follow_fork): Likewise.
	* target-delegates.c: Re-generate.
	* target.c (default_follow_fork): Likewise.
	(target_follow_fork): Likewise.
	* target.h (struct target_ops) <follow_fork>: Likewise.
	(target_follow_fork): Likewise.
2020-03-24 13:45:21 -04:00
Tom de Vries a64fafb545 [gdb] Print user for maint info psymtabs
The type struct partial_symtab contains two fields (disregarding field next)
that express relations with other symtabs: user and dependencies.

When using "maint print psymbols", we see both the dependencies and the user
fields:
...
Partial symtab for source file  (object 0x35ef270)
  ...
  Depends on 0 other partial symtabs.
  Shared partial symtab with user 0x35d5f40
...

But with "maint info psymtabs", we only see dependencies:
...
  { psymtab  ((struct partial_symtab *) 0x35ef270)
    ...
    dependencies (none)
  }
...

Add printing of the user field for "maint info psymtabs", such that we have:
...
   { psymtab  ((struct partial_symtab *) 0x35ef270)
     ...
+    user hello.c ((struct partial_symtab *) 0x35d5f40)
     dependencies (none)
   }
...

Tested on x86_64-linux.

gdb/ChangeLog:

2020-03-24  Tom de Vries  <tdevries@suse.de>

	* psymtab.c (maintenance_info_psymtabs): Print user field.
2020-03-24 10:00:51 +01:00
Andrew Burgess 5935fd1530 gdb/testsuite: Remove hard coded addresses from expected results
In commit:

  commit 6b8c53f2f1
  Date:   Sat Feb 8 21:26:31 2020 +0000

      gdb/testsuite/fortran: Add mixed language stack test

The test incorrectly included two hard coded addresses in the expected
output, this commit replaces them with the $hex pattern.

gdb/testsuite/ChangeLog:

	* gdb.fortran/mixed-lang-stack.exp: Replace two hard coded address
	with $hex.
2020-03-23 12:01:08 +00:00
Tom Tromey fe26d3a34a Make dwarf2_evaluate_property parameter const
dwarf2_evaluate_property should not modify its "addr_stack"
parameter's contents.  This patch makes this part of the API, by
marking it const.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* dwarf2/loc.h (dwarf2_evaluate_property): Make "addr_stack"
	const.
	* dwarf2/loc.c (dwarf2_evaluate_property): Make "addr_stack"
	const.
2020-03-20 13:06:22 -06:00
Tom de Vries c623cc9089 [gdb/testsuite] Fix gdb.threads/omp-par-scope.exp XPASS
When running test-case gdb.threads/omp-par-scope.exp, I get this XPASS:
...
XPASS: gdb.threads/omp-par-scope.exp: nested_parallel: outer_threads: \
  outer stop: get valueof "num"
...
for test:
...
           set thread_num [get_valueof "" "num" "unknown"]
...

The intention of the test is to get the value of local variable num, which
has been set to:
...
    int num = omp_get_thread_num ();
...
but the actually printed value is 'num':
...
(gdb) print num^M
$76 = num^M
...

This is due to the fact that num is missing in the locals, so instead we find
the enum member 'num' of enum expression_operator in glibc/intl/plural-exp.h.

Fix this by getting the value using a new proc get_local_valueof, which uses
the "info locals" commands to get the value.

Tested on x86_64-linux, with gcc 7.5.0 (where the test xfails) and gcc
10.0.1 (where the test passes).
2020-03-20 19:32:07 +01:00
Simon Marchi c884cc4619 gdb: remove HAVE_DECL_PTRACE
I stumbled on this snippet in nat/gdb_ptrace.h:

    /* Some systems, in particular DEC OSF/1, Digital Unix, Compaq Tru64
       or whatever it's called these days, don't provide a prototype for
       ptrace.  Provide one to silence compiler warnings.  */

    #ifndef HAVE_DECL_PTRACE
    extern PTRACE_TYPE_RET ptrace();
    #endif

I believe this is unnecessary today and should be removed.  First, the
comment only mentions OSes we don't support (and to be honest, I had
never even heard of).

But most importantly, in C++, a declaration with empty parenthesis
declares a function that accepts no arguments, unlike in C.  So if this
declaration was really used, GDB wouldn't build, since all ptrace call
sites pass some arguments.  Since we haven't heard anything about this
causing some build failures since we have transitioned to C++, I
conclude that it's not used.

This patch removes it as well as the corresponding configure check.

gdb/ChangeLog:

	* ptrace.m4: Don't check for ptrace declaration.
	* config.in: Re-generate.
	* configure: Re-generate.
	* nat/gdb_ptrace.h: Don't declare ptrace if HAVE_DECL_PTRACE is
	not defined.

gdbserver/ChangeLog:

	* config.in: Re-generate.
	* configure: Re-generate.

gdbsupport/ChangeLog:

	* config.in: Re-generate.
	* configure: Re-generate.
2020-03-20 11:57:49 -04:00
Kamil Rytarowski 1ff700c202 Update the return type of gdb_ptrace to be more flexible
Linux returns long from ptrace(2) and BSDs int.

gdb/ChangeLog:

       * amd64-bsd-nat.c (gdb_ptrace): Change return type from `int' to
       `PTRACE_TYPE_RET'.
       * i386-bsd-nat.c (gdb_ptrace): Likewise.
       * sparc-nat.c (gdb_ptrace): Likewise.
       * x86-bsd-nat.c (gdb_ptrace): Likewise.
2020-03-20 15:51:16 +01:00
Tom Tromey f7d4f0b1b9 Fix assert in c-exp.y
The "restrict" patch added some asserts to c-exp.y, but one spot was
copy-pasted and referred to the wrong table.  This was pointed out by
-fsanitize=address.  This patch fixes the bug.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* c-exp.y (lex_one_token): Fix assert.
2020-03-20 08:31:17 -06:00
Tom Tromey f67210ff1c Avoid stringop-truncation errors
I configured with -fsanitize=address and built gdb.  linux-tdep.c and
ada-tasks.c failed to build due to some stringop-truncation errors,
e.g.:

In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘int linux_fill_prpsinfo(elf_internal_linux_prpsinfo*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1742:11,
    inlined from ‘char* linux_make_corefile_notes(gdbarch*, bfd*, int*)’ at ../../binutils-gdb/gdb/linux-tdep.c:1878:27:
/usr/include/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 81 equals destination size [-Werror=stringop-truncation]

This patch fixes the problem by using "sizeof - 1" in the call to
strndup, as recommended in the GCC manual.  This doesn't make a
difference here because the next line, in all cases, sets the final
element to '\0' anyway.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* ada-tasks.c (read_atcb): Use smaller length in strncpy call.
	* linux-tdep.c (linux_fill_prpsinfo): Use smaller length in
	strncpy call.
2020-03-20 08:31:17 -06:00
Tom Tromey 1773be9ea2 Fix column alignment in "maint info line-table"
Andrew Burgess pointed out on irc that "maint info line-table" doesn't
properly align the table headers.  This patch fixes the problem by
switching the table to use ui-out.

This required a small tweak to one test case, as ui-out will pad a
field using spaces, even at the end of a line.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* symmisc.c (maintenance_print_one_line_table): Use ui_out.

gdb/testsuite/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* gdb.dwarf2/dw2-ranges-base.exp: Update regular expressions.
2020-03-20 08:28:52 -06:00
Tom Tromey 70304be939 Fix Ada val_print removal regression
The removal of val_print caused a regression in the Ada code.  In one
scenario, a variant type would not be properly printed, because the
address of a component was lost.  This patch fixes the bug by changing
this API to be value-based.  This is cleaner and fixes the bug as a
side effect.

gdb/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* ada-valprint.c (print_variant_part): Remove parameters; switch
	to value-based API.
	(print_field_values): Likewise.
	(ada_val_print_struct_union): Likewise.
	(ada_value_print_1): Update.

gdb/testsuite/ChangeLog
2020-03-20  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/sub_variant/subv.adb: New file.
	* gdb.ada/sub_variant.exp: New file.
2020-03-20 08:28:11 -06:00
Kamil Rytarowski 9faa006d11 Inherit ppc_nbsd_nat_target from nbsd_nat_target
gdb/ChangeLog:

	* ppc-nbsd-nat.c (ppc_nbsd_nat_target): Inherit from
	nbsd_nat_target instead of inf_ptrace_target.
	* ppc-nbsd-nat.c: Include "nbsd-nat.h", as we are now using
	nbsd_nat_target.
2020-03-20 15:25:32 +01:00
Kamil Rytarowski 4a90f06205 Add support for NetBSD threads in hppa-nbsd-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

	* hppa-nbsd-nat.c (fetch_registers): New variable lwp and pass
	it to the ptrace call.
	* (store_registers): Likewise.
2020-03-20 15:16:03 +01:00
Tom de Vries 0dd7b8f788 [gdb/testsuite] Fix timeouts in gdb.threads/step-over-*.exp
When running test-cases gdb.threads/step-over-lands-on-breakpoint.exp and
gdb.threads/step-over-trips-on-watchpoint.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into timeouts
due not being able to set a breakpoint and then trying to continue to that
breakpoint.

In total, we run into 186 timeouts, which roughly corresponds to half an hour:
...
$ grep "FAIL.*(timeout)" gdb.sum \
  | awk '{print $2}' \
  | sort \
  | uniq -c
     66 gdb.threads/step-over-lands-on-breakpoint.exp:
    120 gdb.threads/step-over-trips-on-watchpoint.exp:
...

Fix this by bailing out if the first break fails.

Tested on x86_64-linux, both with native and with target board mentioned above.

gdb/testsuite/ChangeLog:

2020-03-20  Tom de Vries  <tdevries@suse.de>

	* gdb.threads/step-over-lands-on-breakpoint.exp (do_test): Bail out if
	first break fails.
	* gdb.threads/step-over-trips-on-watchpoint.exp: (do_test): Same.
2020-03-20 14:59:01 +01:00
Kamil Rytarowski c7da12c72c Add support for NetBSD threads in ppc-nbsd-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

	* ppc-nbsd-nat.c (fetch_registers): New variable lwp and pass
        it to the ptrace call.
        * (store_registers): Likewise.
2020-03-20 13:35:03 +01:00
Kamil Rytarowski f09db38094 Disable get_ptrace_pid for NetBSD
Unlike most other Operating Systems, NetBSD tracks both pid and lwp.
The process id on NetBSD is stored always in the pid field of ptid.

gdb/ChangeLog:

	* inf-ptrace.h: Disable get_ptrace_pid on NetBSD.
	* inf-ptrace.c: Likewise.
	* (gdb_ptrace): Add.
	* (inf_ptrace_target::resume): Update.
	* (inf_ptrace_target::xfer_partial): Likewise.
	* (inf_ptrace_peek_poke): Change argument `pid' to `ptid'.
	* (inf_ptrace_peek_poke): Update.
2020-03-19 22:20:03 +01:00
Luis Machado 2d07da271e [AArch64] When unavailable, fetch VG from ptrace.
I was doing some SVE tests on system QEMU and noticed quite a few failures
related to inferior function calls. Any attempt to do an inferior function
call would result in the following:

Unable to set VG register.: Success.

This happens because, after an inferior function call, GDB attempts to restore
the regcache state and updates the SVE register in order. Since the Z registers
show up before the VG register, VG is still INVALID by the time the first Z
register is being updated. So when executing the following code in
aarch64_sve_set_vq:

if (reg_buf->get_register_status (AARCH64_SVE_VG_REGNUM) != REG_VALID)
  return false;

By returning false, we signal something is wrong, then we get to this:

  /* First store vector length to the thread.  This is done first to ensure the
     ptrace buffers read from the kernel are the correct size.  */
  if (!aarch64_sve_set_vq (tid, regcache))
    perror_with_name (_("Unable to set VG register."));

Ideally we'd always have a valid VG before attempting to set the Z registers,
but in this case the ordering of registers doesn't make that possible.

I considered reordering the registers to put VG before the Z registers, like
the DWARF numbering, but that would break backwards compatibility with
existing implementations. Also, the Z register numbering is pinned to the V
registers, and adding VG before Z would create a gap for non-SVE targets,
since we wouldn't be able to undefine VG for non-SVE targets.

As a compromise, it seems we can safely fetch the VG register value from
ptrace. The value in the kernel is likely the updated value anyway.

This patch fixed all the failures i saw in the testsuite and caused no further
regressions.

gdb/ChangeLog:

2020-03-19  Luis Machado  <luis.machado@linaro.org>

	* nat/aarch64-sve-linux-ptrace.c (aarch64_sve_set_vq): If vg is not
	valid, fetch vg value from ptrace.
2020-03-19 12:51:31 -03:00
Kamil Rytarowski fcc7376e0a Avoid get_ptrace_pid() usage on NetBSD in x86-bsd-nat.c
Add gdb_ptrace() that wraps the ptrace(2) API and correctly passes
the pid,lwp pair to the calls on NetBSD; and the result of
get_ptrace_pid() on other BSD Operating Systems.

gdb/ChangeLog:

	* x86-bsd-nat.c (gdb_ptrace): New.
	* (x86bsd_dr_set): Add new argument `ptid'.
	* (x86bsd_dr_get, x86bsd_dr_set, x86bsd_dr_set_control,
	x86bsd_dr_set_addr): Update.
2020-03-19 14:49:06 +01:00
Andrew Burgess cada5fc921 gdb: Handle W and X remote packets without giving a warning
In this commit:

  commit 24ed6739b6
  Date:   Thu Jan 30 14:35:40 2020 +0000

      gdb/remote: Restore support for 'S' stop reply packet

A regression was introduced such that the W and X packets would give a
warning in some cases.  The warning was:

  warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread

This problem would arise when:

  1. The multi-process extensions to the remote protocol were not
  being used, and

  2. The inferior has multiple threads.

In this case when the W (or X) packet arrives the ptid of the
stop_reply is set to null_ptid, then when we arrive in
process_stop_reply GDB spots that we have multiple non-exited theads,
but the stop event didn't specify a thread-id.

The problem with this is that the W (and X) packets are actually
process wide events, they apply to all threads.  So not specifying a
thread-id is not a problem, in fact, the best these packets allow is
for the remote to specify a process-id, not a thread-id.

If we look at how the W (and X) packets deal with a specified
process-id, then what happens is GDB sets to stop_reply ptid to a
value which indicates all threads in the process, this is done by
creating a value `ptid_t (pid)`, which sets the pid field of the
ptid_t, but leaves the tid field as 0, indicating all threads.

So, this commit does the same thing for the case where there is not
process-id specified.  In process_stop_reply we not distinguish
between stop events that apply to all threads, and those that apply to
only one.  If the stop event applies to only one thread then we treat
it as before.  If, however, the stop event applies to all threads,
then we find the first non-exited thread, and use the pid from this
thread to create a `ptid_t (pid)` value.

If the target has multiple inferiors, and receives a process wide
event without specifying a process-id GDB now gives this warning:

  warning: multi-inferior target stopped without sending a process-id, using first non-exited inferior

gdb/ChangeLog:

	* remote.c (remote_target::process_stop_reply): Handle events for
	all threads differently.

gdb/testsuite/ChangeLog:

	* gdb.server/exit-multiple-threads.c: New file.
	* gdb.server/exit-multiple-threads.exp: New file.
2020-03-19 11:16:53 +00:00
Andrew Burgess 6b8c53f2f1 gdb/testsuite/fortran: Add mixed language stack test
This commit adds a test that builds a mixed language stack, the stack
contains frames of Fortran, C, and C++.  The test prints the backtrace
and explores the stack printing arguments of different types in frames
of different languages.

The core of the test is repeated with GDB's language set to auto,
fortran, c, and c++ in turn to ensure that GDB is happy to print
frames and frame arguments when the language is set to a value that
doesn't match the frame language.

This test currently passes, and there are no known bugs in this area.
The aim of this commit is simply to increase test coverage, as I don't
believe this functionality is currently tested.

gdb/testsuite/ChangeLog:

	* gdb.fortran/mixed-lang-stack.c: New file.
	* gdb.fortran/mixed-lang-stack.cpp: New file.
	* gdb.fortran/mixed-lang-stack.exp: New file.
	* gdb.fortran/mixed-lang-stack.f90: New file.
2020-03-19 11:11:51 +00:00
Andrew Burgess 19a2740f7f gdb: Remove C++ symbol aliases from completion list
Consider debugging the following C++ program:

  struct object
  { int a; };

  typedef object *object_p;

  static int
  get_value (object_p obj)
  {
    return obj->a;
  }

  int
  main ()
  {
    object obj;
    obj.a = 0;

    return get_value (&obj);
  }

Now in a GDB session:

  (gdb) complete break get_value
  break get_value(object*)
  break get_value(object_p)

Or:

  (gdb) break get_va<TAB>
  (gdb) break get_value(object<RETURN>
  Function "get_value(object" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n

The reason this happens is that we add completions based on the
msymbol names and on the symbol names.  For C++ both of these names
include the parameter list, however, the msymbol names have some
differences from the symbol names, for example:

  + typedefs are resolved,
  + whitespace rules are different around pointers,
  + the 'const' keyword is placed differently.

What this means is that the msymbol names and symbol names appear to
be completely different to GDB's completion tracker, and therefore to
readline when it offers the completions.

This commit builds on the previous commit which reworked the
completion_tracker class.  It is now trivial to add a
remove_completion member function, this is then used along with
cp_canonicalize_string_no_typedefs to remove the msymbol aliases from
the completion tracker as we add the symbol names.

Now, for the above program GDB only presents a single completion for
'get_value', which is 'get_value(object_p)'.

It is still possible to reference the symbol using the msymbol name,
so a user can manually type out 'break get_value (object *)' if they
wish and will get the expected behaviour.

I did consider adding an option to make this alias exclusion optional,
in the end I didn't bother as I didn't think it would be very useful,
but I can easily add such an option if people think it would be
useful.

gdb/ChangeLog:

	* completer.c (completion_tracker::remove_completion): Define new
	function.
	* completer.h (completion_tracker::remove_completion): Declare new
	function.
	* symtab.c (completion_list_add_symbol): Remove aliasing msymbols
	when adding a C++ function symbol.

gdb/testsuite/ChangeLog:

	* gdb.linespec/cp-completion-aliases.cc: New file.
	* gdb.linespec/cp-completion-aliases.exp: New file.

Change-Id: Ie5c7c9fc8ecf973072cfb4a9650867104bf7f50c
2020-03-19 08:23:30 +00:00
Andrew Burgess 724fd9ba43 gdb: Restructure the completion_tracker class
In this commit I rewrite how the completion tracker tracks the
completions, and builds its lowest common denominator (LCD) string.
The LCD string is now built lazily when required, and we only track
the completions in one place, the hash table, rather than maintaining
a separate vector of completions.

The motivation for these changes is that the next commit will add the
ability to remove completions from the list, removing a completion
will invalidate the LCD string, so we need to keep hold of enough
information to recompute the LCD string as needed.

Additionally, keeping the completions in a vector makes removing a
completion expensive, so better to only keep the completions in the
hash table.

This commit doesn't add any new functionality itself, and there should
be no user visible changes after this commit.

For testing, I ran the testsuite as usual, but I also ran some manual
completion tests under valgrind, and didn't get any reports about
leaked memory.

gdb/ChangeLog:

	* completer.c (completion_tracker::completion_hash_entry): Define
	new class.
	(advance_to_filename_complete_word_point): Call
	recompute_lowest_common_denominator.
	(completion_tracker::completion_tracker): Call discard_completions
	to setup the hash table.
	(completion_tracker::discard_completions): Allow for being called
	from the constructor, pass new equal function, and element deleter
	when constructing the hash table.  Initialise new class member
	variables.
	(completion_tracker::maybe_add_completion): Remove use of
	m_entries_vec, and store more information into m_entries_hash.
	(completion_tracker::recompute_lcd_visitor): New function, most
	content taken from...
	(completion_tracker::recompute_lowest_common_denominator):
	...here, this now just visits each item in the hash calling the
	above visitor.
	(completion_tracker::build_completion_result): Remove use of
	m_entries_vec, call recompute_lowest_common_denominator.
	* completer.h (completion_tracker::have_completions): Remove use
	of m_entries_vec.
	(completion_tracker::completion_hash_entry): Declare new class.
	(completion_tracker::recompute_lowest_common_denominator): Change
	function signature.
	(completion_tracker::recompute_lcd_visitor): Declare new function.
	(completion_tracker::m_entries_vec): Delete.
	(completion_tracker::m_entries_hash): Initialize to NULL.
	(completion_tracker::m_lowest_common_denominator_valid): New
	member variable.
	(completion_tracker::m_lowest_common_denominator_max_length): New
	member variable.

Change-Id: I9d1db52c489ca0041b8959ca0d53b7d3af8aea72
2020-03-19 08:23:30 +00:00
Tom de Vries d8c8b84859 [gdb/testsuite] Fix gdb.opt/inline-locals.exp KFAILs
When running test-case gdb.opt/inline-locals.exp, I get:
...
Running src/gdb/testsuite/gdb.opt/inline-locals.exp ...
KPASS: gdb.opt/inline-locals.exp: info locals above bar 2 (PRMS gdb/xyz)
KPASS: gdb.opt/inline-locals.exp: info locals above bar 3 (PRMS gdb/xyz)
...

I've opened PR25695 - 'abstract and concrete variable listed both with "info
locals"' to refer to in the PRMS field, and this patch adds that reference.

Furthermore, I noticed that while I see KPASSes, given the problem description
the tests should actually be KFAILs.  This patch also fixes that.

Tested on x86_64-linux.  With gcc 7.5.0, I get 2 KFAILs.  With clang 5.0.2,
the tests pass.

gdb/testsuite/ChangeLog:

2020-03-19  Tom de Vries  <tdevries@suse.de>

	* gdb.opt/inline-locals.exp: Add kfail PR number.  Make kfail matching
	more precise.
2020-03-19 08:44:04 +01:00
Tom de Vries a9933ccf46 [gdb/testsuite] Add test-case gdb.dwarf2/break-inline-psymtab.exp
Add a test-case that tests whether we can set a breakpoint on an inlined
inline function in CU for which the partial symtab has not yet been expanded.

Tested on x86_64-linux, with gcc 4.8.5, gcc-7.5.0, gcc-10.0.1, and clang
5.0.2.

gdb/testsuite/ChangeLog:

2020-03-18  Tom de Vries  <tdevries@suse.de>

	* gdb.dwarf2/break-inline-psymtab-2.c: New test.
	* gdb.dwarf2/break-inline-psymtab.c: New test.
	* gdb.dwarf2/break-inline-psymtab.exp: New file.
2020-03-18 14:40:49 +01:00
Kamil Rytarowski 5a82b8a12b Namespace the reg class to avoid clashes with OS headers
Fix build issues on NetBSD where the reg symbol exists in public headers.

regformats/regdef.h:22:8: error: redefinition struct
 struct reg
        ^~~
/usr/include/amd64/reg.h:51:8: note: previous definition struct
 struct reg {
        ^~~

gdb/ChangeLog:

	* regformats/regdef.h: Put reg in gdb namespace.

gdbserver/ChangeLog:

	* regcache.cc (find_register_by_number): Update.
	* tdesc.cc (init_target_desc): Likewise.
	* tdesc.h (target_desc::reg_defs): Likewise.
2020-03-18 03:36:25 +01:00
Kamil Rytarowski fb516a6913 Add support for NetBSD threads in i386-bsd-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

	* i386-bsd-nat.c (gdb_ptrace): New.
	* (i386bsd_fetch_inferior_registers,
	i386bsd_store_inferior_registers) Switch from pid_t to ptid_t.
	* (i386bsd_fetch_inferior_registers,
	i386bsd_store_inferior_registers) Use gdb_ptrace.
2020-03-18 02:40:50 +01:00
Kamil Rytarowski 1c0aa1fbb2 Add support for NetBSD threads in amd64-bsd-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

	* amd64-bsd-nat.c (gdb_ptrace): New.
	* (amd64bsd_fetch_inferior_registers,
	amd64bsd_store_inferior_registers) Switch from pid_t to ptid_t.
	* (amd64bsd_fetch_inferior_registers,
	amd64bsd_store_inferior_registers) Use gdb_ptrace.
2020-03-18 02:34:21 +01:00
Kamil Rytarowski 5ccd2fb722 Rename the read symbol to xread
This avoids clashes with macro read in the NetBSD headers.

gdb/ChangeLog:

	* user-regs.c (user_reg::read): Rename to...
	(user_reg::xread): ...this.
	* (append_user_reg): Rename argument `read' to `xread'.
	* (user_reg_add_builtin): Likewise.
	* (user_reg_add): Likewise.
	* (value_of_user_reg): Likewise.
2020-03-18 02:23:13 +01:00
Kamil Rytarowski 2108a63a5a Add support for NetBSD threads in sparc-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

Define gdb_ptrace() a wrapper function for ptrace(2) that properly passes
the pid,lwp pair on NetBSD and the result of get_ptrace_pid() for others.

gdb/ChangeLog:

	* sparc-nat.c (gdb_ptrace): New.
	* sparc-nat.c (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers) Remove obsolete comment.
	* sparc-nat.c (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers) Switch from pid_t to ptid_t.
	* sparc-nat.c (sparc_fetch_inferior_registers)
	(sparc_store_inferior_registers) Use gdb_ptrace.
2020-03-17 23:16:49 +01:00
Kamil Rytarowski a225c9a869 Add support for NetBSD threads in sh-nbsd-nat.c
NetBSD ptrace(2) accepts thread id (LWP) as the 4th argument for threads.

gdb/ChangeLog:

	* sh-nbsd-nat.c (fetch_registers): New variable lwp and pass
	it to the ptrace call.
	* sh-nbsd-nat.c (store_registers): Likewise.
2020-03-17 16:34:06 +01:00
Kamil Rytarowski 9809762324 Inherit sh_nbsd_nat_target from nbsd_nat_target
gdb/ChangeLog:

	* sh-nbsd-nat.c (sh_nbsd_nat_target): Inherit from
	nbsd_nat_target instead of inf_ptrace_target.
	* sh-nbsd-nat.c: Include "nbsd-nat.h", as we are now using
	nbsd_nat_target.
2020-03-17 15:10:34 +01:00
Kamil Rytarowski 9e38d61910 Include missing header to get missing declarations
CXX    amd64-bsd-nat.o
amd64-bsd-nat.c:42:1: error: no previous declaration void amd64bsd_fetch_inferior_registers(regcache*,  [-Werror=missing-declarations]
 amd64bsd_fetch_inferior_registers (struct regcache *regcache, int regnum)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amd64-bsd-nat.c:118:1: error: no previous declaration void amd64bsd_store_inferior_registers(regcache*,  [-Werror=missing-declarations]
 amd64bsd_store_inferior_registers (struct regcache *regcache, int regnum)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Detected on NetBSD/amd64 9.99.49.

gdb/ChangeLog:

	* amd64-bsd-nat.c: Include amd64-bsd-nat.h".
2020-03-17 10:24:08 +01:00
Kamil Rytarowski a2ecbe9fb7 Rewrite nbsd_nat_target::pid_to_exec_file to sysctl(3)
procfs on NetBSD is optional and not recommended.

	* nbsd-nat.c: Include <sys/types.h>, <sys/ptrace.h> and
	<sys/sysctl.h>.
	* nbsd-nat.c (nbsd_nat_target::pid_to_exec_file): Rewrite.
2020-03-17 10:22:51 +01:00
Tom de Vries 589902954d [gdb] Skip imports of c++ CUs
The DWARF standard appendix E.1 describes techniques that can be used for
compression and deduplication: DIEs can be factored out into a new compilation
unit, and referenced using DW_FORM_ref_addr.

Such a new compilation unit can either use a DW_TAG_compile_unit or
DW_TAG_partial_unit.  If a DW_TAG_compile_unit is used, its contents is
evaluated by consumers as though it were an ordinary compilation unit.  If a
DW_TAG_partial_unit is used, it's only considered by consumers in the context
of a DW_TAG_imported_unit.

An example of when DW_TAG_partial_unit is required is when the factored out
DIEs are not top-level, f.i. because they were children of a namespace.  In
such a case the corresponding DW_TAG_imported_unit will occur as child of the
namespace.

In the case of factoring out DIEs from c++ compilation units, we can factor
out into a new DW_TAG_compile_unit, and no DW_TAG_imported_unit is required.

This begs the question how to interpret a top-level DW_TAG_imported_unit of a
c++ DW_TAG_compile_unit compilation unit.  The semantics of
DW_TAG_imported_unit describe that the imported unit logically appears at the
point of the DW_TAG_imported_unit entry.  But it's not clear what the effect
should be in this case, since all the imported DIEs are already globally
visible anyway, due to the use of DW_TAG_compile_unit.

So, skip top-level imports of c++ DW_TAG_compile_unit compilation units in
process_imported_unit_die.

Using the cc1 binary from PR23710 comment 1 and setting a breakpoint on do_rpo_vn:
...
$ gdb \
    -batch \
    -iex "maint set dwarf max-cache-age 316" \
    -iex "set language c++" \
    -ex "b do_rpo_vn" \
    cc1
...
we get a 8.1% reduction in execution time, due to reducing the number of
partial symtabs expanded into full symtabs from 212 to 175.

Build and reg-tested on x86_64-linux.

gdb/ChangeLog:

2020-03-17  Tom de Vries  <tdevries@suse.de>

	PR gdb/23710
	* dwarf2/read.h (struct dwarf2_per_cu_data): Add unit_type and lang
	fields.
	* dwarf2/read.c (process_psymtab_comp_unit): Initialize unit_type and lang
	fields.
	(process_imported_unit_die): Skip import of c++ CUs.
2020-03-17 08:56:36 +01:00
Tom de Vries 7325b16ba4 [gdb/testsuite] Give up after consecutive timeouts in completion-support.exp
When running test-case gdb.linespec/cpcompletion.exp with target board
unix/-flto/-O0/-flto-partition=none/-ffat-lto-objects, we run into lots of
timeouts, in particular with this pattern:
...
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_st" (timeout)
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_st"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_str" (timeout)
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  cmd complete "b template2_str"
FAIL: gdb.linespec/cpcompletion.exp: template-ret-type: \
  tab complete "b template2_stru" (timeout)
...

Fix this by detecting timeouts in test_complete_prefix_range_re and giving up
after 3 consecutive timeouts.

This reduces testing time from ~39m to ~9m.

Tested on x86_64-linux.
2020-03-17 08:56:35 +01:00
Tom Tromey 771dd3a88b Initialize base_value in pascal_object_print_value
The val_print removal series introduced a new possibly-uninitialized
warning in p-valprint.c.  Examination of the code shows that the
warning does not indicate a real bug, so this patch silences the
warning by setting the variable in the catch clause of a try/catch.
(The obvious initialization did not work due to a "goto" in this
function.)

gdb/ChangeLog
2020-03-16  Tom Tromey  <tom@tromey.com>

	* p-valprint.c (pascal_object_print_value): Initialize
	base_value.
2020-03-16 18:35:11 -06:00
Anton Kolesov 817a758576 arc: Migrate to new target features
This patch replaces usage of target descriptions in ARC, where the whole
description is fixed in XML, with new target descriptions where XML describes
individual features, and GDB assembles those features into actual target
description.

v2:
Removed arc.c from ALLDEPFILES in gdb/Makefile.in.
Removed vim modeline from arc-tdep.c to have it in a separate patch.
Removed braces from one line "if/else".
Undid the type change for "jb_pc" (kept it as "int").
Joined the unnecessary line breaks into one line.
No more moving around arm targets in gdb/features/Makefile.
Changed pattern checking for ARC features from "arc/{aux,core}" to "arc/".

v3:
Added include gaurds to arc.h.
Added arc_read_description to _create_ target descriptions less.

v4:
Got rid of ARC_SYS_TYPE_NONE.
Renamed ARC_SYS_TYPE_INVALID to ARC_SYS_TYPE_NUM.
Fixed a few indentations/curly braces.
Converted arc_sys_type_to_str from a macro to an inline function.

gdb/ChangeLog:
2020-03-16  Anton Kolesov  <anton.kolesov@synopsys.com>
	    Shahab Vahedi  <shahab@synopsys.com>

	* Makefile.in: Add arch/arc.o
	* configure.tgt: Likewise.
	* arc-tdep.c (arc_tdesc_init): Use arc_read_description.
	(_initialize_arc_tdep): Don't initialize old target descriptions.
        (arc_read_description): New function to cache target descriptions.
	* arc-tdep.h (arc_read_description): Add proto type.
	* arch/arc.c: New file.
	* arch/arc.h: Likewise.
	* features/Makefile: Replace old target descriptions with new.
	* features/arc-arcompact.c: Remove.
	* features/arc-arcompact.xml: Likewise.
	* features/arc-v2.c: Likewise
	* features/arc-v2.xml: Likewise
	* features/arc/aux-arcompact.xml: New file.
	* features/arc/aux-v2.xml: Likewise.
	* features/arc/core-arcompact.xml: Likewise.
	* features/arc/core-v2.xml: Likewise.
	* features/arc/aux-arcompact.c: Generate.
	* features/arc/aux-v2.c: Likewise.
	* features/arc/core-arcompact.c: Likewise.
	* features/arc/core-v2.c: Likewise.
	* target-descriptions (maint_print_c_tdesc_cmd): Support ARC features.
2020-03-16 22:53:10 +01:00
Tom Tromey 67430cd00a Fix dwarf2_name caching bug
PR gdb/25663 points out that dwarf2_name will cache a value in the
bcache and then return a substring.  However, this substring return is
only done on the branch that caches the value -- so if the function is
called twice with the same arguments, it will return different values.

This patch fixes this problem.

This area is strange.  We cache the entire demangled string, but only
return the suffix.  I looked at caching just the suffix, but it turns
out that anonymous_struct_prefix assumes that the entire string is
stored.  Also weird is that this code is demangling the linkage name
and then storing the demangled form back into the linkage name
attribute -- that seems bad, because what if some code wants to find
the actual linkage name?

Fixing these issues was non-trivial, though; and in the meantime this
patch seems like an improvement.  Regression tested on x86-64
Fedora 30.

gdb/ChangeLog
2020-03-16  Tom Tromey  <tromey@adacore.com>

	PR gdb/25663:
	* dwarf2/read.c (dwarf2_name): Strip leading namespaces after
	putting value into bcache.
2020-03-16 15:03:30 -06:00
Simon Marchi 30efb6c7af gdb: define builtin long type to be 64 bits on amd64 Cygwin
On Windows x86-64 (when building with MinGW), the size of the "long"
type is 32 bits.  amd64_windows_init_abi therefore does:

    set_gdbarch_long_bit (gdbarch, 32);

This is also used when the chosen OS ABI is Cygwin, where the "long"
type is 64 bits.  GDB therefore gets sizeof(long) wrong when using the
builtin long type:

    $ ./gdb -nx --data-directory=data-directory -batch -ex "set architecture i386:x86-64" -ex "set osabi Cygwin" -ex "print sizeof(long)"
    The target architecture is assumed to be i386:x86-64
    $1 = 4

This patch makes GDB avoid setting the size of the long type to 32 bits
when using the Cygwin OS ABI.  it will inherit the value set in
amd64_init_abi.

With this patch, I get:

    $ ./gdb -nx --data-directory=data-directory -batch -ex "set architecture i386:x86-64" -ex "set osabi Cygwin" -ex "print sizeof(long)"
    The target architecture is assumed to be i386:x86-64
    $1 = 8

gdb/ChangeLog:

	PR gdb/21500
	* amd64-windows-tdep.c (amd64_windows_init_abi): Rename
	to...
	(amd64_windows_init_abi_common): ... this.  Don't set size of
	long type.
	(amd64_windows_init_abi): New function.
	(amd64_cygwin_init_abi): New function.
	(_initialize_amd64_windows_tdep): Use amd64_cygwin_init_abi for
	the Cygwin OS ABI.
	* i386-windows-tdep.c (_initialize_i386_windows_tdep): Clarify
	comment.
2020-03-16 16:56:36 -04:00
Simon Marchi 8db5243724 gdb: select "Cygwin" OS ABI for Cygwin binaries
Before this patch, the "Windows" OS ABI is selected for all Windows
executables, including Cygwin ones.  This patch makes GDB differentiate
Cygwin binaries from non-Cygwin ones, and selects the "Cygwin" OS ABI
for the Cygwin ones.

To check whether a Windows PE executable is a Cygwin one, we check the
library list in the .idata section, see if it contains "cygwin1.dll".

I had to add code to parse the .idata section, because BFD doesn't seem
to expose this information.  BFD does parse this information, but only
to print it in textual form (function pe_print_idata):

  https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/peXXigen.c;h=e42d646552a0ca1e856e082256cd3d943b54ddf0;hb=HEAD#l1261

Here's the relevant portion of the PE format documentation:

  https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#the-idata-section

This page was also useful:

  https://blog.kowalczyk.info/articles/pefileformat.html#9ccef823-67e7-4372-9172-045d7b1fb006

With this patch applied, this is what I get:

    (gdb) file some_mingw_x86_64_binary.exe
    Reading symbols from some_mingw_x86_64_binary.exe...
    (gdb) show osabi
    The current OS ABI is "auto" (currently "Windows").
    The default OS ABI is "GNU/Linux".

    (gdb) file some_mingw_i386_binary.exe
    Reading symbols from some_mingw_i386_binary.exe...
    (gdb) show osabi
    The current OS ABI is "auto" (currently "Windows").
    The default OS ABI is "GNU/Linux".

    (gdb) file some_cygwin_x86_64_binary.exe
    Reading symbols from some_cygwin_x86_64_binary.exe...
    (gdb) show osabi
    The current OS ABI is "auto" (currently "Cygwin").
    The default OS ABI is "GNU/Linux".

gdb/ChangeLog:

	* windows-tdep.h (is_linked_with_cygwin_dll): New declaration.
	* windows-tdep.c (CYGWIN_DLL_NAME): New.
	(pe_import_directory_entry): New struct type.
	(is_linked_with_cygwin_dll): New function.
	* amd64-windows-tdep.c (amd64_windows_osabi_sniffer): Select
	GDB_OSABI_CYGWIN if the BFD is linked with the Cygwin DLL.
	* i386-windows-tdep.c (i386_windows_osabi_sniffer): Likewise.
2020-03-16 16:56:36 -04:00
Simon Marchi 5982a56ab9 gdb: rename content of i386-windows-tdep.c, cygwin to windows
i386-cygwin-tdep.c has just been renamed to i386-windows-tdep.c, this
patch now renames everything in it that is not Cygwin-specific to
replace "cygwin" with "windows".

Note that I did not rename i386_cygwin_core_osabi_sniffer, since that
appears to be Cygwin-specific.

gdb/ChangeLog:

	* i386-windows-tdep.c: Mass-rename "cygwin" to "windows", except
	i386_cygwin_core_osabi_sniffer.
2020-03-16 16:56:35 -04:00
Simon Marchi 7a1998dffb gdb: rename i386-cygwin-tdep.c to i386-windows-tdep.c
Since this file contains things that apply not only to Cygwin binaries,
but also to non-Cygwin Windows binaries, I think it would make more
sense for it to be called i386-windows-tdep.c.  It is analogous to
amd64-windows-tdep.c, which we already have.

gdb/ChangeLog:

	* i386-cygwin-tdep.c: Rename to...
	* i386-windows-tdep.c: ... this.
	* Makefile.in (ALL_TARGET_OBS): Rename i386-cygwin-tdep.c to
	i386-windows-tdep.c.
	* configure.tgt: Likewise.
2020-03-16 16:56:35 -04:00
Simon Marchi 053205cc40 gdb: add Windows OS ABI
GDB currently uses the "Cygwin" OS ABI (GDB_OSABI_CYGWIN) for everything
related to Windows.  If you build a GDB for a MinGW or Cygwin target, it
will have "Cygwin" as the default OS ABI in both cases (see
configure.tgt).  If you load either a MinGW or Cygwin binary, the
"Cygwin" OS ABI will be selected in both cases.

This is misleading, because Cygwin binaries are a subset of the binaries
running on Windows.  When building something with MinGW, the resulting
binary has nothing to do with Cygwin.  Cygwin binaries are only special
in that they are Windows binaries that link to the cygwin1.dll library
(if my understanding is correct).

Looking at i386-cygwin-tdep.c, we can see that GDB does nothing
different when dealing with Cygwin binaries versus non-Cygwin Windows
binaries.  However, there is at least one known bug which would require
us to make a distinction between the two OS ABIs, and that is the size
of the built-in "long" type on x86-64.  On native Windows, this is 4,
whereas on Cygwin it's 8.

So, this patch adds a new OS ABI, "Windows", and makes GDB use it for
i386 and x86-64 PE executables, instead of the "Cygwin" OS ABI.  A
subsequent patch will improve the OS ABI detection so that GDB
differentiates the non-Cygwin Windows binaries from the Cygwin Windows
binaries, and applies the "Cygwin" OS ABI for the latter.

The default OS ABI remains "Cygwin" for the GDBs built with a Cygwin
target.

I've decided to split the i386_cygwin_osabi_sniffer function in two,
I think it's cleaner to have a separate sniffer for Windows binaries and
Cygwin cores, each checking one specific thing.

gdb/ChangeLog:

	* osabi.h (enum gdb_osabi): Add GDB_OSABI_WINDOWS.
	* osabi.c (gdb_osabi_names): Add "Windows".
	* i386-cygwin-tdep.c (i386_cygwin_osabi_sniffer): Return
	GDB_OSABI_WINDOWS when the binary's target is "pei-i386".
	(i386_cygwin_core_osabi_sniffer): New function, extracted from
	i386_cygwin_osabi_sniffer.
	(_initialize_i386_cygwin_tdep): Register OS ABI
	GDB_OSABI_WINDOWS for i386.
	* amd64-windows-tdep.c (amd64_windows_osabi_sniffer): Return
	GDB_OSABI_WINDOWS when the binary's target is "pei-x86-64".
	(_initialize_amd64_windows_tdep): Register OS ABI GDB_OSABI_WINDOWS
	for x86-64.
	* configure.tgt: Use GDB_OSABI_WINDOWS as the default OS ABI
	when the target matches '*-*-mingw*'.
2020-03-16 16:56:34 -04:00
Simon Marchi fe4b2ee65c gdb: move enum gdb_osabi to osabi.h
I think it makes sense to have it there instead of in the catch-all
defs.h.

gdb/ChangeLog:

	* defs.h (enum gdb_osabi): Move to...
	* osabi.h (enum gdb_osabi): ... here.
	* gdbarch.sh: Include osabi.h in gdbarch.h.
	* gdbarch.h: Re-generate.
2020-03-16 16:56:34 -04:00
Simon Marchi cb9b645d3e gdb: recognize 64 bits Windows executables as Cygwin osabi
If I generate two Windows PE executables, one 32 bits and one 64 bits:

    $ x86_64-w64-mingw32-gcc test.c -g3 -O0 -o test_64
    $ i686-w64-mingw32-gcc test.c -g3 -O0 -o test_32
    $ file test_64
    test_64: PE32+ executable (console) x86-64, for MS Windows
    $ file test_32
    test_32: PE32 executable (console) Intel 80386, for MS Windows

When I load the 32 bits binary in my GNU/Linux-hosted GDB, the osabi is
correctly recognized as "Cygwin":

    $ ./gdb --data-directory=data-directory -nx test_32
    (gdb) show osabi
    The current OS ABI is "auto" (currently "Cygwin").

When I load the 64 bits binary in GDB, the osabi is incorrectly
recognized as "GNU/Linux":

    $ ./gdb --data-directory=data-directory -nx test_64
    (gdb) show osabi
    The current OS ABI is "auto" (currently "GNU/Linux").

The 32 bits one gets recognized by the i386_cygwin_osabi_sniffer
function, by its target name:

    if (strcmp (target_name, "pei-i386") == 0)
      return GDB_OSABI_CYGWIN;

The target name for the 64 bits binaries is "pei-x86-64".  It doesn't
get recognized by any osabi sniffer, so GDB falls back on its default
osabi, "GNU/Linux".

This patch adds an osabi sniffer function for the Windows 64 bits
executables in amd64-windows-tdep.c.  With it, the osabi is recognized
as "Cygwin", just like with the 32 bits binary.

Note that it may seems strange to have a binary generated by MinGW
(which has nothing to do with Cygwin) be recognized as a Cygwin binary.
This is indeed not accurate, but at the moment GDB uses the Cygwin for
everything Windows.  Subsequent patches will add a separate "Windows" OS
ABI for Windows binaries that are not Cygwin binaries.

gdb/ChangeLog:

	* amd64-windows-tdep.c (amd64_windows_osabi_sniffer): New
	function.
	(_initialize_amd64_windows_tdep): Register osabi sniffer.
2020-03-16 16:56:33 -04:00
Tom de Vries 2f89101fe8 [gdb/testsuite] Add cache_verify option for gdb_caching_procs
Test-case gdb.base/gdb-caching-proc.exp tests whether procs declared using
gdb_caching_proc give the same results when called more than once.

While this tests consistency of the procs in the context of that test-case, it
doesn't test consistency across the call sites.

Add a local variable cache_verify to proc gdb_do_cache, that can be set to 1
to verify gdb_caching_proc consistency across the call sites.

Likewise, add a local variable cache_verify_proc to set to the name of the
gdb_caching_proc to verify.  This can f.i. be used when changing an existing
proc into a gdb_caching_proc.

Tested on x86_64-linux, with cache_verify set to both 0 and 1.

gdb/testsuite/ChangeLog:

2020-03-16  Tom de Vries  <tdevries@suse.de>

	* lib/cache.exp (gdb_do_cache): Add and handle local variables
	cache_verify and cache_verify_proc.
2020-03-16 14:39:07 +01:00
Tom de Vries 6b9374f1e0 [gdb/testsuite] Fix solib-list.exp test-case for exec with debug-info
Since commit a2fedca99c "Implement 'set/show exec-file-mismatch'.", I see the
following regression on openSUSE Leap 15.1:
...
FAIL: gdb.server/solib-list.exp: non-stop 0: target remote \
  (got interactive prompt)
FAIL: gdb.server/solib-list.exp: non-stop 1: target remote \
  (got interactive prompt)
...

The first FAIL in more detail:
...
(gdb) PASS: gdb.server/solib-list.exp: non-stop 0: file binfile
target remote localhost:2346
Remote debugging using localhost:2346
warning: Mismatch between current exec-file /data/gdb_versions/devel/build/\
  gdb/testsuite/outputs/gdb.server/solib-list/solib-list
and automatically determined exec-file /lib64/ld-2.26.so
exec-file-mismatch handling is currently "ask"
Load new symbol table from "/lib64/ld-2.26.so"? (y or n) n
warning: loading /lib64/ld-2.26.so Not confirmed.
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
warning: File transfers from remote targets can be slow. \
  Use "set sysroot" to access files locally instead.
Reading /lib64/ld-linux-x86-64.so.2 from remote target...
Reading symbols from target:/lib64/ld-linux-x86-64.so.2...
Reading /lib64/ld-2.26.so-2.26-lp151.18.7.x86_64.debug from remote target...
Reading /lib64/.debug/ld-2.26.so-2.26-lp151.18.7.x86_64.debug from remote \
  target...
Reading /data/gdb_versions/devel/install/lib64/debug//lib64/\
  ld-2.26.so-2.26-lp151.18.7.x86_64.debug from remote target...
Reading /data/gdb_versions/devel/install/lib64/debug/lib64/\
  /ld-2.26.so-2.26-lp151.18.7.x86_64.debug from remote target...
Reading target:/data/gdb_versions/devel/install/lib64/debug/lib64/\
  /ld-2.26.so-2.26-lp151.18.7.x86_64.debug from remote target...
(No debugging symbols found in target:/lib64/ld-linux-x86-64.so.2)
0x00007ffff7dd7ea0 in ?? ()
(gdb) FAIL: gdb.server/solib-list.exp: non-stop 0: target remote (got \
  interactive prompt)
...

The commit introduces the "Load new symbol table from" question, and
gdb_test_multiple defaults to answering "no" and reporting the
"got interactive prompt" FAIL.

This FAIL is not seen on f.i. debian 10.2.  The difference originates from the
fact that the solib-list executable has debug-info in the openSUSE case, while
it doesn't in the debian case.

We can prevent the failure on openSUSE by stripping the executable from
debug-info:
...
+ exec strip --strip-debug ${binfile}
...

The difference in behaviour is a bug or improvement opportunity in the
exec-file-mismatch, filed as PR25475.

This patch fixes the FAIL by handling the question in the test-case.

Tested on x86_64-linux.

Tested on x86_64-linux with the gdbserver part of the patch introducing the
test-case reverted to ensure that this still FAILs.

gdb/testsuite/ChangeLog:

2020-03-15  Tom de Vries  <tdevries@suse.de>

	* gdb.server/solib-list.exp: Handle
	'Load new symbol table from "/lib64/ld-2.26.so"? (y or n)'.
2020-03-15 15:15:56 +01:00