Commit Graph

109654 Commits

Author SHA1 Message Date
Nick Clifton
8e6b353660 Rebase the zlib sources to the 1.2.12 release 2022-04-12 16:24:10 +01:00
Tom de Vries
63e0ee15a3 [gdb/testsuite] Fix gdb.base/stap-probe.exp with read1
When running test-case gdb.base/stap-probe.exp with make target check-read1, I
run into this and similar:
...
FAIL: gdb.base/stap-probe.exp: without semaphore, not optimized: \
  info probes stap (timeout)
...

Fix this by using gdb_test_lines instead of gdb_test.

Tested on x86_64-linux.
2022-04-12 16:36:31 +02:00
Tom Tromey
ce70f11ffe Add C++ "save gdb-index" test
I found a bug in the new DWARF reader series, related to the handling
of enumerator names.  This bug caused a crash, so this patch adds a
regression test for this particular case.  I'm checking this in.
2022-04-12 08:05:39 -06:00
Tom Tromey
dc262faf37 Remove "Ada Settings" node from the manual
A while back, I sent a patch to unify the Ada varsize-limit setting
with the more generic max-value-size:

https://sourceware.org/pipermail/gdb-patches/2021-September/182004.html

However, it turns out I somehow neglected to send part of the patch.
Internally, I also removed the "Ada Settings" node from the manual, as
it only documents the obsolete setting.

This patch removes this text.
2022-04-12 06:55:21 -06:00
Tom Tromey
44a29af963 Require GNAT debug info for some Ada tests
A few Ada tests require some debug info in the GNAT runtime.  When run
without this info, these tests can't pass.  This patch changes these
tests to detect this situation and stop with "untested".
2022-04-12 06:38:01 -06:00
Nick Clifton
278c98c830 Stop strip from removing debuglink sections.
PR 28992
	* objcopy.c (is_strip_section_1): Do not delete debuglink sections
	when stripping debug information.
2022-04-12 13:34:06 +01:00
Jan Beulich
66b39b8b9c gas: new_logical_line{,_flags}() can return "void"
With the sole user of the return value gone, convert the return type to
void. This in turn allows simplifying another construct, by moving it
slightly later in the function.
2022-04-12 09:04:42 +02:00
Jan Beulich
c39e89c3aa gas: drop .appfile and .appline
These were used originally to represent "# <line> <file>" constructs
inserted by (typically) compilers when pre-processing. Quite some time
ago they were replaced by .linefile though. Since the original
directives were never documented, we ought to be able to remove support
for them. As a result in a number of case function parameter aren't used
anymore and can hence be dropped.
2022-04-12 09:04:15 +02:00
Jan Beulich
657edeab38 gas: further adjust file/line handling for .macro
Commit 7992631e8c ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .macro, has
undue effects when the logical file/line pair was already overridden:
Line numbers would continuously increment while processing the expanded
macro, while the goal of the PR gas/16908 workaround is to keep the
expansion associated with the line invoking the macro. However, as soon
as enough state was overridden _inside_ the macro to cause as_where() to
no longer fall back top as_where_physical(), honor this by resuming the
bumping of the logical line number.

Note that from_sb_is_expansion's initializer was 1 for an unknown
reason. While renaming the variable and changing its type, also change
the initializer to "expanding_none", which would have been "0" in the
original code. Originally the initializer value itself wasn't ever used
anyway (requiring sb_index != -1), as it necessarily had changed in
input_scrub_include_sb() alongside setting sb_index to other than -1.

Strictly speaking input_scrub_insert_line() perhaps shouldn't use
expanding_none, yet none of the other enumerators fit there either. And
then strictly speaking that function probably shouldn't exist in the
first place. It's used only by tic54x.
2022-04-12 09:03:43 +02:00
Jan Beulich
2ee1792bec gas: further adjust file/line handling for .irp and alike
Commit 7992631e8c ("gas/Dwarf: improve debug info generation from .irp
and alike blocks"), while dealing okay with actual assembly source files
not using .file/.line and alike outside but not inside of .irp et al,
has undue effects when the logical file/line pair was already
overridden: Line numbers would continuously increment upon every
iteration, thus potentially getting far off. Furthermore it left it to
the user to actually insert .file/.line inside such constructs. Note
though that before aforementioned change things weren't pretty either:
Diagnostics (and debug info) would be associated with the directive
terminating the iteration construct, rather than with the actual lines.

Handle this automatically by simply latching the present line and then
re-instating coordinates first thing on every iteration; note that the
file can't change from what was previously pushed on the scrubber's
state stack, and hence can be taken from there by using a new flavor of
.linefile (which is far better memory-footprint-wise than recording the
full path in the inserted directive). (This then leaves undisturbed any
file/line control occurring in the body of the construct, as these will
only be seen and processed afterwards.)
2022-04-12 09:03:13 +02:00
Jan Beulich
1a42a9fe4e x86: make {disp16} work similarly to {disp32}
In a few places {disp32} was handled specially when really {disp16}
wants handling just the same.
2022-04-12 09:01:55 +02:00
Vladimir Mezentsev
50192212a7 gprofng doesn't build with gcc 5.5
gprofng/ChangeLog
2022-04-07  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	PR gprofng/29026
	* configure.ac: Check version of bison.
	* src/Makefile.am (QLParser.yy): Run bison
	* src/QLParser.yy: Adapted for bison 3.04 or later.
	* src/DbeSession.cc: make some params const.
	* src/DbeSession.h: Likewise.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
	* src/QLParser.tab.cc: Deleted.
	* src/QLParser.tab.hh: Deleted.
	* doc/Makefile.in: Regenerate.
	* gp-display-html/Makefile.in: Regenerate.
	* libcollector/configure: Regenerate.
2022-04-11 18:07:26 -07:00
GDB Administrator
5f437feef4 Automatic date update in version.in 2022-04-12 00:00:20 +00:00
John Baldwin
aa1402a95d i386-fbsd-nat: Remove two unused variables.
Earlier versions of the change in
1285ce8629 used this variable, but not
the final version that landed.
2022-04-11 11:01:43 -07:00
Simon Marchi
e165fcef1e gdb: remove MSYMBOL_TARGET_FLAG_{1,2} macros
Replace with equivalent getter/setter macros.

Change-Id: I1042564dd47347337374762bd64ec31b5c573ee2
2022-04-11 10:47:54 -04:00
Simon Marchi
5bbfd12dda gdb: remove minimal symbol size macros
Remove MSYMBOL_HAS_SIZE, MSYMBOL_SIZE and SET_MSYMBOL_SIZE, replace them
with equivalent methods.

Change-Id: I6ee1cf82df37e58dff52ea6568ceb4649c7d7538
2022-04-11 10:46:52 -04:00
Simon Marchi
60f62e2b83 gdb: remove MSYMBOL_TYPE macro
Add a getter and a setter for a minimal symbol's type.  Remove the
corresponding macro and adjust all callers.

Change-Id: I89900df5ffa5687133fe1a16b2e0d4684e67a77d
2022-04-11 10:46:07 -04:00
Simon Marchi
4aeddc50d7 gdb: remove symbol value macros
Remove all macros related to getting and setting some symbol value:

    #define SYMBOL_VALUE(symbol)           (symbol)->value.ivalue
    #define SYMBOL_VALUE_ADDRESS(symbol)                         \
    #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value)    \
    #define SYMBOL_VALUE_BYTES(symbol)     (symbol)->value.bytes
    #define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
    #define SYMBOL_BLOCK_VALUE(symbol)     (symbol)->value.block
    #define SYMBOL_VALUE_CHAIN(symbol)     (symbol)->value.chain
    #define MSYMBOL_VALUE(symbol)          (symbol)->value.ivalue
    #define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
    #define MSYMBOL_VALUE_ADDRESS(objfile, symbol)                         \
    #define BMSYMBOL_VALUE_ADDRESS(symbol) \
    #define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value)   \
    #define MSYMBOL_VALUE_BYTES(symbol)    (symbol)->value.bytes
    #define MSYMBOL_BLOCK_VALUE(symbol)    (symbol)->value.block

Replace them with equivalent methods on the appropriate objects.

Change-Id: Iafdab3b8eefc6dc2fd895aa955bf64fafc59ed50
2022-04-11 10:45:36 -04:00
Nils-Christian Kempke
96d368d104 gdb/doc: add section about Fortran intrinsic functions and types
The earlier version of this document had no sections about the
available Fortran intrinsic functions or the Fortran builtin types.

I added two sections 'Fortran intrinsics' and 'Fortran types' to
document the available Fortran language features.  The subsection
'Fortran Defaults' has been integrated into the Fortran subsection.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
27e8f72f35 gdb/fortran/testsuite: add complex from integers test
When working on the files I noted that there was no actual test for a
COMPLEX built from two INTEGERS.  I added that now for completion.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
891e4190ba gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND.  This
parameter determines the kind of the associated return value.  So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.

This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.

It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.

After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate.  E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function.  This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
04ba653650 gdb/fortran: rename f77_keywords to f_keywords
Rename f77_keywords to f_keywords since some of the introduced keywords
in the array are f90 only.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
87abd9825d gdb/fortran: Change GDB print for fortran default types
Currently, when asking GDB to print the type of a Fortran default type
such as INTEGER or REAL, GDB will return the default name of that type,
e.g. "integer"/"real":

   (gdb) ptype integer
   type = integer
   (gdb) ptype real
   type = real

For LOGICAL and COMPLEX it would return the actual underlying types

   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex
   type = complex*4

Similarly, GDB would print the default integer type for the underlying
default type:

   (gdb) ptype integer*4
   type = integer
   (gdb) ptype real*4
   type = real
   (gdb) ptype logical
   type = logical*4
   (gdb) ptype complex*4
   type = complex*4

This is inconsistent and a bit confusing.  Both options somehow indicate
what the internal underlying type for the default type is - but I think
the logical/complex version is a bit clearer.

Consider again:

   (gdb) ptype integer
   type = integer

This indicates to a user that the type of "integer" is Fortran's default
integer type.  Without examining "ptype integer*4" I would expect, that
any variable declared integer in the actual code would also fit into a
GDB integer.  But, since we cannot adapt out internal types to the
compiler flags used at compile time of a debugged binary, this might be
wrong.  Consider debugging Fortran code compiled with GNU and e.g. the
"-fdefault-integer-8" flag.  In this case the gfortran default integer
would be integer*8 while GDB internally still would use a builtin_integer,
so an integer of the size of an integer*4 type.  On the other hand having
GDB print

   (gdb) ptype integer
   type = integer*4

makes this clearer.  I would still be tempted to fit a variable declared
integer in the code into a GDB integer - but at least ptype would
directly tell me what is going on.  Note, that when debugging a binary
compiled with "-fdefault-integer-8" a user will always see the actual
underlying type of any variable declared "integer" in the Fortran code.
So having the code

   program test
     integer :: a = 5
     print *, a ! breakpt
   end program test

will, when breaking at breakpt print

   (gdb) ptype var
   type = integer(kind=4)

or

   (gdb) ptype var
   type = integer(kind=8)

depending on the compiler flag.

This patch changes the outputs for the REAL and INTEGER default types to
actually print the internally used type over the default type name.

The new behavior for the above examples is:

   (gdb) ptype integer
   type = integer*4
   (gdb) ptype integer*4
   type = integer*4

Existing testcases have been adapted to reflect the new behavior.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
adc29023a7 gdb/fortran: clean-up Fortran intrinsic types
The currently implemented intrinsic type handling for Fortran missed some
tokens and their parsing.  While still not all Fortran type kinds are
implemented this patch at least makes the currently handled types
consistent.  As an example for what this patch does, consider the
intrinsic type INTEGER.  GDB implemented the handling of the
keywords "integer" and "integer_2" but missed "integer_4" and "integer_8"
even though their corresponding internal types were already available as
the Fortran builtin types builtin_integer and builtin_integer_s8.
Similar problems applied to LOGICAL, REAL, and COMPLEX.  This patch adds
all missing tokens and their parsing.  Whenever a section containing the
type handling was touched, it also was reordered to be in a more easy to
grasp order.  All INTEGER/REAL/LOGICAL/COMPLEX types were grouped
together and ordered ascending in their size making a missing one more
easy to spot.

Before this change GDB would print the following when tyring to use the
INTEGER keywords:

   (gdb) set language fortran
   (gdb) ptype integer*1
   unsupported kind 1 for type integer
   (gdb) ptype integer_1
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer
   (gdb) ptype integer_4
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer
   type = integer

With this patch all keywords are available and the GDB prints:

   (gdb) set language fortran
   (gdb) ptype integer*1
   type = integer*1
   (gdb) ptype integer_1
   type = integer*1
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer*4
   (gdb) ptype integer_4
   type = integer*4
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   type = integer*8
   (gdb) ptype integer
   type = integer

The described changes have been applied to INTEGER, REAL, COMPLEX,
and LOGICAL. Existing testcases have been adapted to reflect the
new behavior.  Tests for formerly missing types have been added.
2022-04-11 14:06:56 +02:00
Nils-Christian Kempke
4ec8aa9e94 gdb/fortran: change default logical type to builtin_logical
According to the Fortran standard, logical is of the size of a
'single numeric storage unit' (just like real and integer). For
gfortran, flang and ifx/ifort this storage unit (or the default
logical type) is of size kind 4, actually occupying 4 bytes of
storage, and so the default type for logical expressions in
Fortran should probably also be Logical*4 and not Logical*2.  I
adapted GDB's behavior to be in line with
gfortran/ifort/ifx/flang.
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
ed9ec61174 gdb/fortran: reformat build_fortran_types in f-lang.c
Add a few newlines after the type definitions and remove some
unnecessary linebreaks.
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
4e436fdabe gdb/fortran: fix complex type in Fortran builtin types
Before this patch things like

  (gdb) ptype complex*8
  complex*16
  (gdb) ptype complex*4
  complex*8

were possible in GDB, which seems confusing for a user.  The reason
is a mixup in the implementation of the Fortran COMPLEX type.  In
Fortran the "*X" after a type would normally (I don't think this
is language required) specify the type's size in memory.  For the
COMPLEX type the kind parameters usually (at least for GNU, Intel, Flang)
specify not the size of the whole type but the size of the individual
two REALs used to form the COMPLEX.  Thus, a COMPLEX*4 will usually
consist of two REAL*4s.  Internally this type was represented by a
builtin_complex_s8 - but here I think the s8 actually meant the raw
size of the type.  This is confusing and I renamed the types (e.g.
builting_complex_s8 became builtin_complex_s4 according to its most
common useage) and their printed names to their language equivalent.
Additionally, I added the default COMPLEX type "COMPLEX" being the same
as a COMPLEX*4 (as is normally the case) and removed the latter.  I added
a few tests for this new behavior as well.

The new behavior is

  (gdb) ptype complex*8
  complex*8
  (gdb) ptype complex*4
  complex*4
2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
c08ec64081 gdb/f-lang: remove hidden ^L characters 2022-04-11 14:06:55 +02:00
Nils-Christian Kempke
d4c948427d gdb/f-lang: add Integer*1 to Fortran builtin types
Add builtin_integer_s1 of size TARGET_CHAR_BIT to Fortran builtin types.
2022-04-11 14:06:55 +02:00
Tom de Vries
04f4c17c7a [gdb/testsuite] Fix gdb.base/annota1.exp with pie
Since commit 359efc2d89 ("[gdb/testsuite] Make gdb.base/annota1.exp more
robust") we see this fail with target board unix/-fPIE/-pie:
...
FAIL: gdb.base/annota1.exp: run until main breakpoint (timeout)
...

The problem is that the commit makes the number and order of matched
annotations fixed, while between target boards unix and unix/-fPIE/-pie there
is a difference:
...
 \032\032post-prompt
 Starting program: outputs/gdb.base/annota1/annota1

+\032\032breakpoints-invalid
+
 \032\032starting

 \032\032frames-invalid
...

Fix this by optionally matching the additional annotation.

Tested on x86_64-linux.
2022-04-11 10:28:41 +02:00
Tom de Vries
e7be729233 [gdb/testsuite] Fix gdb.dwarf2/dw2-lines.exp for m32 pie
As reported in PR29043, when running test-case gdb.dwarf2/dw2-lines.exp with
target board unix/-m32/-fPIE/-pie, we run into:
...
Breakpoint 2, 0x56555540 in bar ()^M
(gdb) PASS: gdb.dwarf2/dw2-lines.exp: cv=2: cdw=32: lv=2: ldw=32: \
  continue to breakpoint: foo \(1\)
next^M
Single stepping until exit from function bar,^M
which has no line number information.^M
0x56555587 in main ()^M
(gdb) FAIL: gdb.dwarf2/dw2-lines.exp: cv=2: cdw=32: lv=2: ldw=32: \
  next to foo (2)
...

The problem is that the bar breakpoint ends up at an unexpected location
because:
- the synthetic debug info is incomplete and doesn't provide line info
  for the prologue part of the function, so consequently gdb uses the i386
  port prologue skipper to get past the prologue
- the i386 port prologue skipper doesn't get past a get_pc_thunk call.

Work around this in the test-case by breaking on bar_label instead.

Tested on x86_64-linux with target boards unix, unix/-m32, unix/-fPIE/-pie and
unix/-m32/-fPIE/-pie.
2022-04-11 10:17:31 +02:00
GDB Administrator
2a722c6460 Automatic date update in version.in 2022-04-11 00:00:10 +00:00
GDB Administrator
f190d13c78 Automatic date update in version.in 2022-04-10 00:00:22 +00:00
Tom Tromey
bd1c798f0a Remove MSYMBOL_VALUE_CHAIN
I noticed that MSYMBOL_VALUE_CHAIN is unused, so this patch removes it.
2022-04-09 08:33:11 -06:00
Alan Modra
57594b6a75 Rearrange struct bfd_section a little
For better packing on 64-bit hosts.

	* section.c (struct bfd_section): Move next and prev field earlier.
	Move alignment_power later.
	(BFD_FAKE_SECTION): Adjust to suit.
	* bfd-in2.h: Regenerate.
2022-04-09 15:34:24 +09:30
Alan Modra
480a4dd5f3 Don't run pr27228 test for hppa
As the comment says, hppa doesn't support use of BFD_RELOC_* in
.reloc directives.  Using xfail can result in a spurious XPASS result
as BFD_RELOC values change.

	* testsuite/gas/elf/pr27228.d: Change xfail to notarget for hppa.
2022-04-09 15:26:25 +09:30
Alan Modra
81c5e3764b Correct nds32 readelf reloc numbers
* readelf.c (is_32bit_abs_reloc, is_16bit_abs_reloc): Comment fixes.
	(is_none_reloc): Correct nds32 reloc numbers.
2022-04-09 14:49:11 +09:30
GDB Administrator
680e019e5a Automatic date update in version.in 2022-04-09 00:00:16 +00:00
Fangrui Song
a3a7f5e158 gas: Port "copy st_size only if unset" to aarch64 and riscv
And disable the new test gas/elf/size.s for alpha which uses its own
.set, for hppa*-*-hpux* which does not allow .size before declaration.
2022-04-08 14:06:36 -07:00
Vladimir Mezentsev
9f184a64f5 gprofng: fprintf_styled_func not inizialized for disassembler
gprofng/ChangeLog
2022-04-07  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* libcollector/unwind.c: inizialize fprintf_styled_func.
	* src/Disasm.cc: Likewise.
2022-04-08 09:05:37 -07:00
Vladimir Mezentsev
c10622fef4 gprofng: zlib handling
gprofng/ChangeLog
2022-04-06  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* configure.ac: Add AM_ZLIB.
	* src/Makefile.am: Add $(ZLIBINC) and $(ZLIB).
	* gprofng/src/DbeSession.h: Likewise.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
	* doc/Makefile.in: Regenerate.
	* gp-display-html/Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
2022-04-08 09:05:37 -07:00
Pedro Alves
6849c6a2b8 gdb: Avoid undefined shifts, fix Go shifts
I noticed that a build of GDB with GCC + --enable-ubsan, testing
against GDBserver showed this GDB crash:

  (gdb) PASS: gdb.trace/trace-condition.exp: trace: 0x00abababcdcdcdcd << 46 == 0x7373400000000000: advance to trace begin
  tstart
  ../../src/gdb/valarith.c:1365:15: runtime error: left shift of 48320975398096333 by 46 places cannot be represented in type 'long int'
  ERROR: GDB process no longer exists
  GDB process exited with wait status 269549 exp9 0 1
  UNRESOLVED: gdb.trace/trace-condition.exp: trace: 0x00abababcdcdcdcd << 46 == 0x7373400000000000: start trace experiment

The problem is that, "0x00abababcdcdcdcd << 46" is an undefined signed
left shift, because the result is not representable in the type of the
lhs, which is signed.  This actually became defined in C++20, and if
you compile with "g++ -std=c++20 -Wall", you'll see that GCC no longer
warns about it, while it warns if you specify prior language versions.

While at it, there are a couple other situations that are undefined
(and are still undefined in C++20) and result in GDB dying: shifting
by a negative ammount, or by >= than the bit size of the promoted lhs.
For the latter, GDB shifts using (U)LONGEST internally, so you have to
shift by >= 64 bits to see it:

 $ gdb --batch -q -ex "p 1 << -1"
 ../../src/gdb/valarith.c:1365:15: runtime error: shift exponent -1 is negative
 $ # gdb exited

 $ gdb --batch -q -ex "p 1 << 64"
 ../../src/gdb/valarith.c:1365:15: runtime error: shift exponent 64 is too large for 64-bit type 'long int'
 $ # gdb exited

Also, right shifting a negative value is implementation-defined
(before C++20, after which it is defined).  For this, I chose to
change nothing in GDB other than adding tests, as I don't really know
whether we need to do anything.  AFAIK, most implementations do an
arithmetic right shift, and it may be we don't support any host or
target that behaves differently.  Plus, this becomes defined in C++20
exactly as arithmetic right shift.

Compilers don't error out on such shifts, at best they warn, so I
think GDB should just continue doing the shifts anyhow too.

Thus:

- Adjust scalar_binop to avoid the undefined paths, either by adding
  explicit result paths, or by casting the lhs of the left shift to
  unsigned, as appropriate.

  For the shifts by a too-large count, I made the result be what you'd
  get if you split the large count in a series of smaller shifts.
  Thus:

     Left shift, positive or negative lhs:

       V << 64
	 =>  V << 16 << 16 << 16 << 16
	   => 0

     Right shift, positive lhs:

       Vpos >> 64
	 =>  Vpos >> 16 >> 16 >> 16 >> 16
	   => 0

     Right shift, negative lhs:

       Vneg >> 64
	 =>  Vneg >> 16 >> 16 >> 16 >> 16
	   => -1

  This is actually Go's semantics (the compiler really emits
  instructions to make it so that you get 0 or -1 if you have a
  too-large shift).  So for that language GDB does the shift and
  nothing else.  For other C-like languages where such a shift is
  undefined, GDB warns in addition to performing the shift.

  For shift by a negative count, for Go, this is a hard error.  For
  other languages, since their compilers only warn, I made GDB warn
  too.  The semantics I chose (we're free to pick them since this is
  undefined behavior) is as-if you had shifted by the count cast to
  unsigned, thus as if you had shifted by a too-large count, thus the
  same as the previous scenario illustrated above.

  Examples:

    (gdb) set language go
    (gdb) p 1 << 100
    $1 = 0
    (gdb) p -1 << 100
    $2 = 0
    (gdb) p 1 >> 100
    $3 = 0
    (gdb) p -1 >> 100
    $4 = -1
    (gdb) p -2 >> 100
    $5 = -1
    (gdb) p 1 << -1
    left shift count is negative

    (gdb) set language c
    (gdb) p -2 >> 100
    warning: right shift count >= width of type
    $6 = -1
    (gdb) p -2 << 100
    warning: left shift count >= width of type
    $7 = 0
    (gdb) p 1 << -1
    warning: left shift count is negative
    $8 = 0
    (gdb) p -1 >> -1
    warning: right shift count is negative
    $9 = -1

- The warnings' texts are the same as what GCC prints.

- Add comprehensive tests in a new gdb.base/bitshift.exp testcase, so
  that we exercise all these scenarios.

Change-Id: I8bcd5fa02de3114b7ababc03e65702d86ec8d45d
2022-04-08 16:19:15 +01:00
Pedro Alves
01772c548b Fix undefined behavior in the Fortran, Go and Pascal number parsers
This commit ports these two fixes to the C parser:

  commit ebf13736b4
  CommitDate: Thu Sep 4 21:46:28 2014 +0100

      parse_number("0") reads uninitialized memory

  commit 20562150d8
  CommitDate: Wed Oct 3 15:19:06 2018 -0600

      Avoid undefined behavior in parse_number

... to the Fortran, Go, and Fortran number parsers, fixing the same
problems there.

Also add a new testcase that exercises printing 0xffffffffffffffff
(max 64-bit) in all languages, which crashes a GDB built with UBsan
without the fix.

I moved get_set_option_choices out of all-architectures.exp.tcl to
common code to be able to extract all the supported languages.  I did
a tweak to it to generalize it a bit -- you now have to pass down the
"set" part of the command as well.  This is so that the proc can be
used with "maintenance set" commands as well in future.

Change-Id: I8e8f2fdc1e8407f63d923c26fd55d98148b9e16a
2022-04-08 16:19:15 +01:00
Nick Clifton
7d41169b6d Debug info for function in Windows PE binary on wrong instruction
PR 29038
	* coffgen.c (coff_find_nearest_line_with_names): Fix typo
	retrieving saved bias.
2022-04-08 16:04:22 +01:00
Simon Marchi
de83289ef3 Pass PKG_CONFIG_PATH down from top-level Makefile
[Sending to binutils, gdb-patches and gcc-patches, since it touches the
top-level Makefile/configure]

I have my debuginfod library installed in a non-standard location
(/opt/debuginfod), which requires me to set
PKG_CONFIG_PATH=/opt/debuginfod/lib/pkg-config.  If I just set it during
configure:

    $ PKG_CONFIG_PATH=/opt/debuginfod/lib/pkg-config ./configure --with-debuginfod
    $ make

or

    $ ./configure --with-debuginfod PKG_CONFIG_PATH=/opt/debuginfod/lib/pkg-config
    $ make

Then PKG_CONFIG_PATH is only present (and ignored) during the top-level
configure.  When running make (which runs gdb's and binutils'
configure), PKG_CONFIG_PATH is not set, which results in their configure
script not finding the library:

    checking for libdebuginfod >= 0.179... no
    configure: error: "--with-debuginfod was given, but libdebuginfod is missing or unusable."

Change the top-level configure/Makefile system to capture the value
passed when configuring the top-level and pass it down to
subdirectories (similar to CFLAGS, LDFLAGS, etc).

I don't know much about the top-level build system, so I really don't
know if I did this correctly.  The changes are:

 - Use AC_SUBST(PKG_CONFIG_PATH) in configure.ac, so that
   @PKG_CONFIG_PATH@ gets replaced with the actual PKG_CONFIG_PATH value
   in config files (i.e. Makefile)
 - Add a PKG_CONFIG_PATH Makefile variable in Makefile.tpl, initialized
   to @PKG_CONFIG_PATH@
 - Add PKG_CONFIG_PATH to HOST_EXPORTS in Makefile.tpl, which are the
   variables set when running the sub-configures

I initially added PKG_CONFIG_PATH to flags_to_pass, in Makefile.def, but
I don't think it's needed.  AFAIU, this defines the flags to pass down
when calling "make" in subdirectories.  We only need PKG_CONFIG_PATH to
be passed down during configure.  After that, it's captured in
gdb/config.status, so even if a "make" causes a re-configure later
(because gdb/configure has changed, for example), the PKG_CONFIG_PATH
value will be remembered.

ChangeLog:

	* configure.ac: Add AC_SUBST(PKG_CONFIG_PATH).
	* configure: Re-generate.
	* Makefile.tpl (HOST_EXPORTS): Pass PKG_CONFIG_PATH.
	(PKG_CONFIG_PATH): New.
	* Makefile.in: Re-generate.

Change-Id: I91138dfca41c43b05e53e445f62e4b27882536bf
2022-04-08 10:56:41 -04:00
Simon Marchi
0c80fce42a gdb/testsuite: use nopie in gdb.dwarf2/dw2-inline-param.exp
I see this failure:

    (gdb) run ^M
    Starting program: /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.dwarf2/dw2-inline-param/dw2-inline-param ^M
    Warning:^M
    Cannot insert breakpoint 1.^M
    Cannot access memory at address 0x113b^M
    ^M
    (gdb) FAIL: gdb.dwarf2/dw2-inline-param.exp: runto: run to *0x113b

The test loads the binary in GDB, grabs the address of a symbol, strips
the binary, reloads it in GDB, runs the program, and then tries to place
a breakpoint at that address.  The problem is that the binary is built
as position independent, so the address GDB grabs in the first place
isn't where the code ends up after running.

Fix this by linking the binary as non-position-independent.  The
alternative would be to compute the relocated address where to place the
breakpoint, but that's not very straightforward, unfortunately.

I was confused for a while, I was trying to load the binary in GDB
manually to get the symbol address, but GDB was telling me the symbol
could not be found.  Meanwhile, it clearly worked in gdb.log.  The thing
is that GDB strips the binary in-place, so we don't have access to the
intermediary binary with symbols.  Change the test to output the
stripped binary to a separate file instead.

Change-Id: I66c56293df71b1ff49cf748d6784bd0e935211ba
2022-04-08 09:55:29 -04:00
Alan Modra
129f0aaa9d gdb maintainer commit rights
Formalise what ought to be obvious.  The top level of the binutils-gdb
repository isn't owned by binutils.

	* MAINTAINERS: Spelling fix.  GDB global maintainer rights.
2022-04-08 20:47:55 +09:30
Bernhard Heckel
110aae55a8 gdb/fortran: print fortran extended types with ptype
Add the print of the base-class of an extended type to the output of
ptype.  This requires the Fortran compiler to emit DW_AT_inheritance
for the extended type.

Co-authored-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
2022-04-08 12:17:13 +02:00
Bernhard Heckel
87e10e9c28 gdb/fortran: add support for accessing fields of extended types
Fortran 2003 supports type extension.  This patch allows access
to inherited members by using their fully qualified name as described
in the Fortran standard.

In doing so the patch also fixes a bug in GDB when trying to access the
members of a base class in a derived class via the derived class' base
class member.

This patch fixes PR22497 and PR26373 on GDB side.

Using the example Fortran program from PR22497

program mvce
  implicit none

  type :: my_type
     integer :: my_int
  end type my_type

  type, extends(my_type) :: extended_type
  end type extended_type

  type(my_type) :: foo
  type(extended_type) :: bar

  foo%my_int = 0
  bar%my_int = 1

  print*, foo, bar

end program mvce

and running this with GDB and setting a BP at 17:

Before:
(gdb) p bar%my_type
A syntax error in expression, near `my_type'.
(gdb) p bar%my_int
There is no member named my_int.
(gdb) p bar%my_type%my_int
A syntax error in expression, near `my_type%my_int'.
(gdb) p bar
$1 = ( my_type = ( my_int = 1 ) )

After:
(gdb) p bar%my_type
$1 = ( my_int = 1 )
(gdb) p bar%my_int
$2 = 1                 # this line requires DW_TAG_inheritance to work
(gdb) p bar%my_type%my_int
$3 = 1
(gdb) p bar
$4 = ( my_type = ( my_int = 1 ) )

In the above example "p bar%my_int" requires the compiler to emit
information about the inheritance relationship between extended_type
and my_type which gfortran and flang currently do not de.  The
respective issue gcc/49475 has been put as kfail.

Co-authored-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26373
     https://sourceware.org/bugzilla/show_bug.cgi?id=22497
2022-04-08 12:17:13 +02:00
Nils-Christian Kempke
916c9be4a3 gdb: add Nils-Christian Kempke to gdb/MAINTAINERS
Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
2022-04-08 12:03:45 +02:00