Commit graph

268 commits

Author SHA1 Message Date
Tom de Vries
f947893689 [gdb/testsuite] Fix gdb.fortran/array-bounds.exp on arm
When running test-case gdb.fortran/array-bounds.exp on arm-linux, we run into:
...
(gdb) print &foo^M
$1 = (PTR TO -> ( real(kind=4) (0:1) )) 0xfffef008^M
(gdb) FAIL: gdb.fortran/array-bounds.exp: print &foo
print &bar^M
$2 = (PTR TO -> ( real(kind=4) (-1:0) )) 0xfffef010^M
(gdb) FAIL: gdb.fortran/array-bounds.exp: print &bar
...

This is due to gcc PR debug/54934.

The test-case contains a kfail for this, which is only activated for
x86_64/i386.

Fix this by enabling the kfail for all ilp32 targets.

Also:
- change the kfail into an xfail, because gdb is not at fault here, and
- limit the xfail to the gfortran compiler.

Tested on arm-linux.
2024-06-07 08:12:34 +02:00
Tom de Vries
9dd1e64208 [gdb/testsuite] Use save_vars to restore GDBFLAGS
There's a pattern of using:
...
set saved_gdbflags $GDBFLAGS
set GDBFLAGS "$GDBFLAGS ..."
<do something with GDBFLAGS>
set GDBFLAGS $saved_gdbflags
...

Simplify this by using save_vars:
...
save_vars { GDBFLAGS } {
    set GDBFLAGS "$GDBFLAGS ..."
    <do something with GDBFLAGS>
}
...

Tested on x86_64-linux.
2024-05-03 15:07:33 +02:00
Andrew Burgess
7879fba359 gdb: rename unwindonsignal to unwind-on-signal
We now have unwind-on-timeout and unwind-on-terminating-exception, and
then the odd one out unwindonsignal.

I'm not a great fan of these squashed together command names, so in
this commit I propose renaming this to unwind-on-signal.

Obviously I've added the hidden alias unwindonsignal so any existing
GDB scripts will keep working.

There's one test that I've extended to test the alias works, but in
most of the other test scripts I've changed over to use the new name.

The docs are updated to reference the new name.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Tested-By: Luis Machado <luis.machado@arm.com>
Tested-By: Keith Seitz <keiths@redhat.com>
2024-03-25 17:25:07 +00:00
Nils-Christian Kempke
6a67441983 gdb, testsuite, fortran: Fix sizeof intrinsic for Fortran pointers
For Fortran pointers gfortran/ifx emits DW_TAG_pointer_types like

<2><17d>: Abbrev Number: 22 (DW_TAG_variable)
   <180>   DW_AT_name        : (indirect string, offset: 0x1f1): fptr
   <184>   DW_AT_type        : <0x214>
...
<1><219>: Abbrev Number: 27 (DW_TAG_array_type)
   <21a>   DW_AT_type        : <0x10e>
   <216>   DW_AT_associated  : ...

The 'pointer property' in Fortran is implicitly modeled by adding a
DW_AT_associated to the type of the variable (see also the
DW_AT_associated description in DWARF 5).  A Fortran pointer is more
than an address and thus different from a C pointer.  It is a
self contained type having additional fields such as, e.g., the rank of
its underlying array.  This motivates the intended DWARF modeling of
Fortran pointers via the DW_AT_associated attribute.

This patch adds support for the sizeof intrinsic by simply dereferencing
pointer types when encountered during a sizeof evaluation.

The patch also adds a test for the sizeof intrinsic which was not tested
before.

Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Tom Tromey <tom@tromey.com>
2024-02-02 08:57:16 +01:00
Bernhard Heckel
f18fc7e56f gdb, types: Resolve pointer types dynamically
This commit allows pointers to be dynamic types (on the outmost
level).  Similar to references, a pointer is considered a dynamic type
if its target type is a dynamic type and it is on the outmost level.
Also this commit removes the redundant code inside function
"value_check_printable" for handling of DW_AT_associated type.

The pointer resolution follows the one of references.

This change generally makes the GDB output more verbose.  We are able to
print more details about a pointer's target like the dimension of an array.

In Fortran, if we have a pointer to a dynamic type

  type buffer
    real, dimension(:), pointer :: ptr
  end type buffer
  type(buffer), pointer :: buffer_ptr
  allocate (buffer_ptr)
  allocate (buffer_ptr%ptr (5))

which then gets allocated, we now resolve the dynamic type before
printing the pointer's type:

Before:

  (gdb) ptype buffer_ptr
  type = PTR TO -> ( Type buffer
    real(kind=4) :: alpha(:)
  End Type buffer )

After:

  (gdb) ptype buffer_ptr
  type = PTR TO -> ( Type buffer
    real(kind=4) :: alpha(5)
  End Type buffer )

Similarly in C++ we can dynamically resolve e.g. pointers to arrays:

  int len = 3;
  int arr[len];
  int (*ptr)[len];
  int ptr = &arr;

Once the pointer is assigned one gets:

Before:

  (gdb) p ptr
  $1 = (int (*)[variable length]) 0x123456
  (gdb) ptype ptr
  type = int (*)[variable length]

After:

  (gdb) p ptr
  $1 = (int (*)[3]) 0x123456
  (gdb) ptype ptr
  type = int (*)[3]

For more examples see the modified/added test cases.

Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Tom Tromey <tom@tromey.com>
2024-02-02 08:57:16 +01:00
Tom Tromey
974b36c2ae Use the new symbol domains
This patch changes the DWARF reader to use the new symbol domains.  It
also adjusts many bits of associated code to adapt to this change.

The non-DWARF readers are updated on a best-effort basis.  This is
somewhat simpler since most of them only support C and C++.  I have no
way to test a few of these.

I went back and forth a few times on how to handle the "tag"
situation.  The basic problem is that C has a special namespace for
tags, which is separate from the type namespace.  Other languages
don't do this.  So, the question is, should a DW_TAG_structure_type
end up in the tag domain, or the type domain, or should it be
language-dependent?

I settled on making it language-dependent using a thought experiment.
Suppose there was a Rust compiler that only emitted nameless
DW_TAG_structure_type objects, and specified all structure type names
using DW_TAG_typedef.  This DWARF would be correct, in that it
faithfully represents the source language -- but would not work with a
purely struct-domain implementation in gdb.  Therefore gdb would be
wrong.

Now, this approach is a little tricky for C++, which uses tags but
also enters a typedef for them.  I notice that some other readers --
like stabsread -- actually emit a typedef symbol as well.  And, I
think this is a reasonable approach.  It uses more memory, but it
makes the internals simpler.  However, DWARF never did this for
whatever reason, and so in the interest of keeping the series slightly
shorter, I've left some C++-specific hacks in place here.

Note that this patch includes language_minimal as a language that uses
tags.  I did this to avoid regressing gdb.dwarf2/debug-names-tu.exp,
which doesn't specify the language for a type unit.  Arguably this
test case is wrong.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30164
2024-01-28 10:58:16 -07:00
Andrew Burgess
1d506c26d9 Update copyright year range in header of all files managed by GDB
This commit is the result of the following actions:

  - Running gdb/copyright.py to update all of the copyright headers to
    include 2024,

  - Manually updating a few files the copyright.py script told me to
    update, these files had copyright headers embedded within the
    file,

  - Regenerating gdbsupport/Makefile.in to refresh it's copyright
    date,

  - Using grep to find other files that still mentioned 2023.  If
    these files were updated last year from 2022 to 2023 then I've
    updated them this year to 2024.

I'm sure I've probably missed some dates.  Feel free to fix them up as
you spot them.
2024-01-12 15:49:57 +00:00
Nils-Christian Kempke
3396471b4c dwarf, fortran: add support for DW_TAG_entry_point
Fortran provides additional entry points for subroutines and functions.
These entry points may use only a subset (or a different set) of the
parameters of the original subroutine.  The entry points may be described
via the DWARF tag DW_TAG_entry_point.

This commit adds support for parsing the DW_TAG_entry_point DWARF tag.
Currently, between ifx/ifort/gfortran, only ifort is actually emitting
this tag.  Both, ifx and gfortran use the DW_TAG_subprogram tag as
workaround/alternative.  Thus, this patch really only adds more ifort
support.  Even so, some of the attached tests still fail for ifort, due
to some wrong line info generated for the entry points in ifort.

After this patch it is possible to set a breakpoint in gdb with the
ifort compiled example at the entry points 'foo' and 'foobar', which was not
possible before.

As gcc and ifx do not emit the tag I also added a test to gdb.dwarf2
which uses some underlying c compiled code and adds some Fortran style DWARF
to it emitting the DW_TAG_entry_point.  Before this patch it was not
possible to actually define breakpoint at the entry point tags.

For gfortran there actually exists a bug on bugzilla, asking for the use
of DW_TAG_entry_point over DW_TAG_subprogram:

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

This patch was originally posted here

https://sourceware.org/legacy-ml/gdb-patches/2017-07/msg00317.html

but its review/pinging got lost after a while.  I reworked it to fit the
current GDB.

Co-authored-by: Bernhard Heckel <bernhard.heckel@intel.com>
Co-authored-by: Tim Wiederhake  <tim.wiederhake@intel.com>
Approved-by: Tom Tromey <tom@tromey.com>
2023-12-29 11:31:10 +01:00
Tom de Vries
265687478b [gdb/exp] Clean up asap in value_print_array_elements
I've been running the test-suite on an i686-linux laptop with 1GB of memory,
and 1 GB of swap, and noticed problems after running gdb.base/huge.exp: gdb
not being able to spawn for a large number of test-cases afterwards.

So I investigated the memory usage, on my usual x86_64-linux development
platform.

The test-case is compiled with -DCRASH_GDB=2097152, so this:
...
static int a[CRASH_GDB], b[CRASH_GDB];
...
with sizeof (int) == 4 represents two arrays of 8MB each.

Say we add a loop around the "print a" command and print space usage
statistics:
...
gdb_test "maint set per-command space on"
for {set i 0} {$i < 100} {incr i} {
    gdb_test "print a"
}
...

This gets us:
...
(gdb) print a^M
$1 = {0 <repeats 2097152 times>}^M
Space used: 478248960 (+469356544 for this command)^M
(gdb) print a^M
$2 = {0 <repeats 2097152 times>}^M
Space used: 486629376 (+8380416 for this command)^M
(gdb) print a^M
$3 = {0 <repeats 2097152 times>}^M
Space used: 495009792 (+8380416 for this command)^M
  ...
(gdb) print a^M
$100 = {0 <repeats 2097152 times>}^M
Space used: 1308721152 (+8380416 for this command)^M
...

In other words, we start out at 8MB, and the first print costs us about 469MB,
and subsequent prints 8MB, which accumulates to 1.3 GB usage. [ On the
i686-linux laptop, the first print costs us 335MB. ]

The subsequent 8MBs are consistent with the values being saved into the value
history, but the usage for the initial print seems somewhat excessive.

There is a PR open about needing sparse representation of large arrays
(PR8819), but this memory usage points to an independent problem.

The function value_print_array_elements contains a scoped_value_mark to free
allocated values in the outer loop, but it doesn't prevent the inner loop from
allocating a lot of values.

Fix this by adding a scoped_value_mark in the inner loop, after which we have:
...
(gdb) print a^M
$1 = {0 <repeats 2097152 times>}^M
Space used: 8892416 (+0 for this command)^M
(gdb) print a^M
$2 = {0 <repeats 2097152 times>}^M
Space used: 8892416 (+0 for this command)^M
(gdb) print a^M
$3 = {0 <repeats 2097152 times>}^M
Space used: 8892416 (+0 for this command)^M
  ...
(gdb) print a^M
$100 = {0 <repeats 2097152 times>}^M
Space used: 8892416 (+0 for this command)^M
...

Note that the +0 here just means that the mallocs did not trigger an sbrk.
This is dependent on malloc (which can use either mmap or sbrk or some
pre-allocated memory) and will likely vary between different tunings, versions
and implementations, so this does not give us a reliable way detect the
problem in a minimal way.

A more reliable way of detecting the problem is:
...
 void
 value_free_to_mark (const struct value *mark)
 {
+  size_t before = all_values.size ();
   auto iter = std::find (all_values.begin (), all_values.end (), mark);
   if (iter == all_values.end ())
     all_values.clear ();
   else
     all_values.erase (iter + 1, all_values.end ());
+  size_t after = all_values.size ();
+  if (before - after >= 1024)
+    fprintf (stderr, "value_free_to_mark freed %zu items\n", before - after);
...
which without the fix tells us:
...
+print a
value_free_to_mark freed 2097152 items
$1 = {0 <repeats 2097152 times>}
...

Fix a similar problem for Fortran:
...
+print array1
value_free_to_mark freed 4194303 items
$1 = (0, <repeats 2097152 times>)
...
in fortran_array_printer_impl::process_element.

The problem also exists for Ada:
...
+print Arr
value_free_to_mark freed 2097152 items
$1 = (0 <repeats 2097152 times>)
...
but is fixed by the fix for C.

Add Fortran and Ada variants of the test-case.  The *.exp files are similar
enough to the original to keep the copyright years range.

While writing the Fortran test-case, I ran into needing an additional print
setting to print the entire array in repeat form, filed as PR exp/30817.

I managed to apply the compilation loop for the Ada variant as well, but with
a cumbersome repetition style.  I noticed no other test-case uses gnateD, so
perhaps there's a better way of implementing this.

The regression test included in the patch is formulated in its weakest
form, to avoid false positive FAILs, which also means that smaller regressions
may not get detected.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2023-09-14 20:34:00 +02:00
Ijaz, Abdul B
2e2d1ccdc5 testsuite, fortran: Fix regression due to fix for ifort's 'start' behavior
Got a regression email due to merge of commit in CI config
tcwg_gdb_check/master-aarch64 :
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=41439185cd0075bbb1aedf9665685dba0827cfec

Begining of test "gdb.fortran/array-slices-bad.exp" was updated in above
commit to start the test from running to line with tag "First Breakpoint"
instead of "fortran_runto_main".  Reason of the regression is shared
libraries are still loaded after hitting the breakpoint as "nosharedlibrary"
is already called before hitting the breakpoint.

So now after this change test is updated accordingly to disable and unload
shared libraries symbols after hitting the first breakpoint.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2023-09-11 17:14:29 +02:00
Nils-Christian Kempke
056f6ae0f3 testsuite, fortran: make kfail gfortran specific
The modified test in function-calls.exp actually passes with ifort and
ifx.  The particular fail seems to be specific to gfortran.  When the
test was introduced it was only tested with gfortran (actually the
whole patch was written with gfortran and the GNU Fortran argument
passing convention in mind).

Approved-by: Tom Tromey <tom@tromey.com>
2023-09-08 00:35:18 +02:00
Nils-Christian Kempke
41439185cd testsuite, fortran: adapt tests for ifort's 'start' behavior
The modified tests array-slices-bad.exp and vla-type.exp both set a
breakpoint at the first real statement in the respective executables.

Normally, the expected behavior of fortran_runto_main for these would be
the stopping of the debugger at exactly the first statment in the code.

Strangely, neither gfortran nor ifx seem to do this for these tests.
Instead, issuing 'start' in ifx (for either of the 2 tests) lets GDB
stop at the 'program ...' line and gfortran stops at a variable
declaration line.  E.g. for vla-type it stops at

  41        type(five)               :: fivearr (2)

So, actually, ifort's behavior can be considered to be a bit more
'correct' here.  This patch remove the fortran_runto_main in the
two tests and instead uses runto to directly run to the first breakpoint
set at the first program statement.  This works with both compiler
behaviors and makes the tests more robust.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2023-09-08 00:35:18 +02:00
Nils-Christian Kempke
6fe8aea3c0 testsuite, fortran: Remove self assignment non-statements
There were a couple of places in the testsuite where instructions like

  var = var

were written in the source code of tests.  These were usually dummy
statements meant to generate a line table entry at that line on which
to break later on.

This worked fine for gfortran and ifx, but it seems that, when compiled
with ifort (2021.6.0) these statements do not actually create any
assmbler instructions and especially no line table entries.  Consider
the program

  program test
    Integer var :: var = 1
    var = var
  end program

compiled with gfortran (13.0.0, -O0 -g).  The linetable as emitted by
'objdump --dwarf=decodedline ./a.out' looks like

  test.f90:
  File name   Line number    Starting address    View    Stmt
  test.f90              1            0x401172               x
  test.f90              3            0x401176               x
  test.f90              4            0x401182               x
  test.f90              4            0x401185               x
  test.f90              4            0x401194               x
  test.f90              -            0x4011c0

actually containing line table info for line 3.  Running gdb, breaking
at 3 and checking the assembly we see

   0x0000000000401172 <+0>:     push   %rbp
   0x0000000000401173 <+1>:     mov    %rsp,%rbp
=> 0x0000000000401176 <+4>:     mov    0x2ebc(%rip),%eax   # 0x404038 <var.1>
   0x000000000040117c <+10>:    mov    %eax,0x2eb6(%rip)   # 0x404038 <var.1>
   0x0000000000401182 <+16>:    nop
   0x0000000000401183 <+17>:    pop    %rbp
   0x0000000000401184 <+18>:    ret

so two mov instructions are being issued for this assignment one copying
the value into a register and one writing it back to the same memory.
Ifort (2021.6.0, -O0 -g) on the other hand does not emit anything here
and also has no line table entry:

  test.f90:
  File name   Line number    Starting address    View    Stmt
  test.f90              1            0x4040f8               x
  test.f90              4            0x404109               x
  test.f90              4            0x40410e               x
  test.f90              -            0x404110

As I do not think that this is really a bug (on either side, gfortran/ifx or
ifort), and as I don't think this behavior is covered in the Fortran
standard, I changed these lines to become actual value assignments.

This removes a few FAILs in the testsuite when ran with ifort.

Approved-by: Tom Tromey <tom@tromey.com>
2023-09-08 00:35:18 +02:00
Nils-Christian Kempke
85832a8c3c testsuite, fortran: make mixed-lang-stack less compiler dependent
In the gdb.fortran/mixed-lang-stack.exp test when somewhere deep in a
bunch of nested function calls we issue and test a 'info args' command
for the mixed_func_1b function (when in that function's frame).

The signature of the function looks like

  subroutine mixed_func_1b(a, b, c, d, e, g)
    use type_module
    implicit none

    integer :: a
    real(kind=4) :: b
    real(kind=8) :: c
    complex(kind=4) :: d
    character(len=*) :: e
    character(len=:), allocatable :: f
    TYPE(MyType) :: g

and usually one would expect arguments a, b, c, d, e, and g to be
emitted here.  However, due to some compiler dependent treatment of the
e array the actual output in the test (with gfortran/ifx) is

  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = (4,5)
  e = 'abcdef'
  g = ( a = 1.5, b = 2.5 )
  _e = 6

where the compiler generated '_e' is emitted as the length of e.  While
ifort also generates an additional length argument, the naming (which is
up to the compilers here I think, I could not find anything in the
Fortran standard about this) is different and we see

  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = (4,5)
  e = 'abcdef'
  g = ( a = 1.5, b = 2.5 )
  .tmp.E.len_V$4a = 6

To make both outputs pass the test, I kept the additional argument for now and
made the regex for the emitted name of the last variable match any
arbitrary name.

Approved-by: Tom Tromey <tom@tromey.com>
2023-09-08 00:35:18 +02:00
Tom de Vries
62b28bd668 [gdb/testsuite] Handle some test-cases with older compiler
When running test-case gdb.mi/print-simple-values.exp with gcc 4.8.4, I run
into a compilation failure due to the test-case requiring c++11 and the
compiler defaulting to less than that.

Fix this by compiling with -std=c++11.

Likewise in a few other test-cases.

Tested on x86_64-linux.
2023-08-29 17:27:19 +02:00
Richard Bunt
2f98b09492 gdb/fortran: Align intrinsic/variable precedence
Fortran allows variables and function to be named after language defined
intrinsics as they are not reserved keywords. For example, the abs maths
intrinsic can be hidden by a user declaring a variable called abs.

The behavior before this patch was to favour the intrinsic, which meant
that any variables named, for example "allocated", could not be
inspected by GDB.

This patch inverts this priority to bring GDB's behaviour closer to the
Fortran language, where the user defined symbol can hide the intrinsic.

Special care was need to prevent any C symbols from overriding either
Fortran intrinsics or user defined variables. This was observed to be
the case when GDB has access to symbols for abs from libm. This was
solved by only allowing symbols not marked with language_fortran to be
overridden.

In total this brings the order of precedence to the following (highest
first):

    1. User defined Fortran variable or function.
    2. Fortran intrinsic.
    3. Symbols from languages other than Fortran.

The sizeof intrinsic is now case insensitive. This is closer to the
Fortran language.  I believe this change is safe enough as it increases
the acceptance of the grammar, rather than restricts it. I.e. it should
not break any existing scripts which rely on it. Unless of course they
rely on SIZEOF being rejected.

GDB built with GCC 13.

No test suite regressions detected. Compilers: GCC, ACfL, Intel, Intel
LLVM, NVHPC; Platforms: x86_64, aarch64.

Existing tests in gdb.fortran cover the invocation of intrinsics
including: intrinsics.exp, shape.exp, rank.exp, lbound-ubound.exp.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-07 09:13:14 +01:00
Tom de Vries
33b5899fc0 [gdb] Fix typos
Fix a few typos:
- implemention -> implementation
- convertion(s) -> conversion(s)
- backlashes -> backslashes
- signoring -> ignoring
- (un)ambigious -> (un)ambiguous
- occured -> occurred
- hidding -> hiding
- temporarilly -> temporarily
- immediatelly -> immediately
- sillyness -> silliness
- similiar -> similar
- porkuser -> pokeuser
- thats -> that
- alway -> always
- supercede -> supersede
- accomodate -> accommodate
- aquire -> acquire
- priveleged -> privileged
- priviliged -> privileged
- priviledges -> privileges
- privilige -> privilege
- recieve -> receive
- (p)refered -> (p)referred
- succesfully -> successfully
- successfuly -> successfully
- responsability -> responsibility
- wether -> whether
- wich -> which
- disasbleable -> disableable
- descriminant -> discriminant
- construcstor -> constructor
- underlaying -> underlying
- underyling -> underlying
- structureal -> structural
- appearences -> appearances
- terciarily -> tertiarily
- resgisters -> registers
- reacheable -> reachable
- likelyhood -> likelihood
- intepreter -> interpreter
- disassemly -> disassembly
- covnersion -> conversion
- conviently -> conveniently
- atttribute -> attribute
- struction -> struct
- resonable -> reasonable
- popupated -> populated
- namespaxe -> namespace
- intialize -> initialize
- identifer(s) -> identifier(s)
- expection -> exception
- exectuted -> executed
- dungerous -> dangerous
- dissapear -> disappear
- completly -> completely
- (inter)changable -> (inter)changeable
- beakpoint -> breakpoint
- automativ -> automatic
- alocating -> allocating
- agressive -> aggressive
- writting -> writing
- reguires -> requires
- registed -> registered
- recuding -> reducing
- opeartor -> operator
- ommitted -> omitted
- modifing -> modifying
- intances -> instances
- imbedded -> embedded
- gdbaarch -> gdbarch
- exection -> execution
- direcive -> directive
- demanged -> demangled
- decidely -> decidedly
- argments -> arguments
- agrument -> argument
- amespace -> namespace
- targtet -> target
- supress(ed) -> suppress(ed)
- startum -> stratum
- squence -> sequence
- prompty -> prompt
- overlow -> overflow
- memember -> member
- languge -> language
- geneate -> generate
- funcion -> function
- exising -> existing
- dinking -> syncing
- destroh -> destroy
- clenaed -> cleaned
- changep -> changedp (name of variable)
- arround -> around
- aproach -> approach
- whould -> would
- symobl -> symbol
- recuse -> recurse
- outter -> outer
- freeds -> frees
- contex -> context

Tested on x86_64-linux.

Reviewed-By: Tom Tromey <tom@tromey.com>
2023-06-03 22:43:57 +02:00
Richard Bunt
712872748d gdb: Remove redundant frame switching
547ce8f00b fixed an issue where dynamic types were not being resolved
correctly prior to printing a value. The same issue was discovered when
printing the value using mi-mode, which was not covered by the fix.
Porting the fix to the mi-mode code path resolved the issue.

However, it was discovered that a later patch series, ending
2fc3b8a4cb, independently fixed the issue in both the cli- and mi-mode
code paths, making the original fix unneeded.

This commit removes this extra frame switch and adds test coverage for
the mi-mode scenario to protect against any future divergence in this
area.

GDB built with GCC 11.

No test suite regressions detected. Compilers: GCC 12.1.0, ACfL 22.1,
Intel 22.1; Platforms: x86_64, aarch64.

Approved-By: Tom Tromey <tom@tromey.com>
2023-05-19 11:29:43 +01:00
Simon Marchi
2bf4cc2b92 gdb.fortran/lbound-ubound.exp: read expected lbound and ubound from function parameters (PR 30414)
gdb.fortran/lbound-ubound.exp reads the expected lbound and ubound
values by reading some output from the inferior.  This is racy when
running on boards where the inferior I/O is on a separate TTY than
GDB's, such as native-gdbserver.

I sometimes see this behavior:

    (gdb) continue
    Continuing.

    Breakpoint 2, do_test (lb=..., ub=...) at /home/jenkins/workspace/binutils-gdb_master_linuxbuild/platform/jammy-amd64/target_board/nati
    ve-gdbserver/src/binutils-gdb/gdb/testsuite/gdb.fortran/lbound-ubound.F90:45
    45        print *, ""   ! Test Breakpoint
    (gdb) Remote debugging from host ::1, port 37496

     Expected GDB Output:

    LBOUND = (-8, -10)
    UBOUND = (-1, -2)
    APB: Run a test here
    APB: Expected lbound '(-8, -10)'
    APB: Expected ubound ''

What happened is that expect read the output from GDB before the output
from the inferior, triggering this gdb_test_multiple clause:

    -re "$gdb_prompt $" {
        set found_prompt true

        if {$found_dealloc_breakpoint
            || ($expected_lbound != "" && $expected_ubound != "")} {
            # We're done.
        } else {
            exp_continue
        }
    }

So it set found_prompt, but the gdb_test_multiple kept going because
found_dealloc_breakpoint is false (this is the flag indicating that the
test is finished) and we still don't have expected_lbound and
expected_ubound.  Then, expect reads in the inferior I/O, triggering
this clause:

    -re ".*LBOUND = (\[^\r\n\]+)\r\n" {
        set expected_lbound $expect_out(1,string)
        if {!$found_prompt} {
            exp_continue
        }
    }

This sets expected_lbound, but since found_prompt is true, we don't do
exp_continue, and exit the gdb_test_multiple, without having an
expected_ubound.

Change the test to read the values from the lb and ub function
parameters instead.  As far as I understand, this still exercises what
we want to test.  These variables contain the return values of the
lbound and ubound functions as computed by the program.  We'll use them
to check the return values of the lbound and ubound functions as
computed by GDB.

Change-Id: I3c4d3d17d9291870a758a42301d15a007821ebb5
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30414
2023-05-18 13:22:30 -04:00
Richard Bunt
03d83cd5f5 GDB: Add `info main' command
Allow consumers of GDB to extract the name of the main method.  This is
most useful for Fortran programs which have a variable main method.

Used by both MAP and DDT e.g. it is used to detect the presence of debug
information.

Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
2023-03-31 15:31:40 +01:00
Richard Bunt
571eb2644c GDB: Favor full symbol main name for backtrace stop
In the case where a Fortran program has a program name of "main" and
there is also a minimal symbol called main, such as with programs built
with GCC version 4.4.7 or below, the backtrace will erroneously stop at
the minimal symbol rather than the user specified main, e.g.:

(gdb) bt
#0  bar () at .../gdb/testsuite/gdb.fortran/backtrace.f90:17
#1  0x0000000000402556 in foo () at .../gdb/testsuite/gdb.fortran/backtrace.f90:21
#2  0x0000000000402575 in main () at .../gdb/testsuite/gdb.fortran/backtrace.f90:31
#3  0x00000000004025aa in main ()
(gdb)

This patch fixes this issue by increasing the precedence of the full
symbol when the language of the current frame is Fortran.

Newer versions of GCC transform the program name to "MAIN__" in this
case, avoiding the problem.

Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
2023-03-31 15:31:40 +01:00
Tom Tromey
450d26c851 Use require with target_info
This changes many tests to use 'require' when checking target_info.
In a few spots, the require is hoisted to the top of the file, to
avoid doing any extra work when the test is going to be skipped
anyway.
2023-03-10 08:21:46 -07:00
Andrew Burgess
a0c0791577 GDB: Introduce limited array lengths while printing values
This commit introduces the idea of loading only part of an array in
order to print it, what I call "limited length" arrays.

The motivation behind this work is to make it possible to print slices
of very large arrays, where very large means bigger than
`max-value-size'.

Consider this GDB session with the current GDB:

  (gdb) set max-value-size 100
  (gdb) p large_1d_array
  value requires 400 bytes, which is more than max-value-size
  (gdb) p -elements 10 -- large_1d_array
  value requires 400 bytes, which is more than max-value-size

notice that the request to print 10 elements still fails, even though 10
elements should be less than the max-value-size.  With a patched version
of GDB:

  (gdb) p -elements 10 -- large_1d_array
  $1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}

So now the print has succeeded.  It also has loaded `max-value-size'
worth of data into value history, so the recorded value can be accessed
consistently:

  (gdb) p -elements 10 -- $1
  $2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
  (gdb) p $1
  $3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
    20, 21, 22, 23, 24, <unavailable> <repeats 75 times>}
  (gdb)

Accesses with other languages work similarly, although for Ada only
C-style [] array element/dimension accesses use history.  For both Ada
and Fortran () array element/dimension accesses go straight to the
inferior, bypassing the value history just as with C pointers.

Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
2023-02-10 23:49:19 +00:00
Tom Tromey
1d6704e0ce Use clean_restart in gdb.fortran
Change gdb.fortran to use clean_restart more consistently.
2023-01-26 18:28:32 -07:00
Tom Tromey
e1a772ad89 Remove some dead code in gdb.fortran/info-types.exp
An early "return" in this test case prevents a test from running.
This seems to have been intentional and has been in place since:

commit d57cbee932
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Tue Dec 3 13:18:43 2019 +0000

    gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+

This patch removes the dead code.
2023-01-26 18:28:31 -07:00
Tom Tromey
57b7402d20 Rename to allow_fortran_tests
This changes skip_fortran_tests to invert the sense, and renames it to
allow_fortran_tests.
2023-01-13 13:18:57 -07:00
Tom Tromey
e5bf39c507 Use require !gdb_debug_enabled
This changes some tests to use "require !gdb_debug_enabled".
2023-01-13 13:18:56 -07:00
Tom Tromey
8d0278eb40 Use require !skip_fortran_tests
This changes some tests to use "require !skip_fortran_tests".
2023-01-13 13:18:55 -07:00
Joel Brobecker
213516ef31 Update copyright year range in header of all files managed by GDB
This commit is the result of running the gdb/copyright.py script,
which automated the update of the copyright year range for all
source files managed by the GDB project to be updated to include
year 2023.
2023-01-01 17:01:16 +04:00
Simon Marchi
30add7ee24 gdb/testsuite: remove perror calls when failing to run
I noticed that when running these two tests in sequence:

    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/arrayptr.exp ...
    ERROR: GDB process no longer exists
    ERROR: Couldn't run foo-all
    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/assign_1.exp ...

The results in gdb.sum are:

    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/arrayptr.exp ...
    PASS: gdb.ada/arrayptr.exp: scenario=all: compilation foo.adb
    ERROR: GDB process no longer exists
    UNRESOLVED: gdb.ada/arrayptr.exp: scenario=all: gdb_breakpoint: set breakpoint at foo.adb:40 (eof)
    ERROR: Couldn't run foo-all
    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/assign_1.exp ...
    UNRESOLVED: gdb.ada/assign_1.exp: changing the language to ada
    PASS: gdb.ada/assign_1.exp: set convenience variable $xxx to 1

The UNRESOLVED for arrayptr.exp is fine, as GDB crashes in that test,
while trying to run to main.  However, the UNRESOLVED in assign_1.exp
doesn't make sense, GDB behaves as expected in that test:

    (gdb) set lang ada^M
    (gdb) UNRESOLVED: gdb.ada/assign_1.exp: changing the language to ada
    print $xxx := 1^M
    $1 = 1^M
    (gdb) PASS: gdb.ada/assign_1.exp: set convenience variable $xxx to 1

The problem is that arrayptr.exp calls perror when failing to run to
main, then returns.  perror makes it so that the next test (as in
pass/fail) will be recorded as UNRESOLVED.  However, here, the next test
(as in pass/fail) is in the next test (as in .exp).  Hence the spurious
UNRESOLVED in assign_1.exp.

These perror when failing to run to X are not really useful, especially
since runto records a FAIL on error, by default.  Remove all the
perrors on runto failure I could find.

When there wasn't one already, add a return statement when failing to
run, to avoid running the test of the test unnecessarily.

I thought of adding a check ran between test (in gdb_finish
probably) where we would emit a warning if errcnt > 0, meaning a test
quit and left a perror "active".  However, reading that variable would
poke into the DejaGNU internals, not sure it's a good idea.

Change-Id: I2203df6d06e199540b36f56470d1c5f1dc988f7b
2022-12-05 16:38:24 -05:00
Andrew Burgess
49bb47443c gdb/testsuite: remove use of then keyword from gdb.fortran/*.exp
The canonical form of 'if' in modern TCL is 'if {} {}'.  But there's
still a bunch of places in the testsuite where we make use of the
'then' keyword, and sometimes these get copies into new tests, which
just spreads poor practice.

This commit removes all use of the 'then' keyword from the gdb.fortran/
test script directory.

There should be no changes in what is tested after this commit.
2022-11-28 21:04:09 +00:00
Andrew Burgess
e2afece894 gdb/testsuite: remove DOS line endings from a test script
The gdb.fortran/nested-funcs.exp test script has DOS line endings.  I
can see no reason why this script needs DOS line endings.

Convert to UNIX line endings.

There should be no change in what is tested after this commit.
2022-11-28 21:04:09 +00:00
Andrew Burgess
1c01b23603 gdb/fortran/testsuite: print values and types of string variables
While looking through the Fortran tests, I couldn't find a test of GDB
printing the value and type of a Fortran string defined using the
'character*SIZE' notation.

This works fine in GDB right now, but I thought it wouldn't hurt to
have a test for this, so this commit adds such a test.

The test also includes printing a string that includes some embedded
special characters: \n \r \t \000 - that's right, as Fortran strings
are stored as an address and length, it is fine to include an embedded
null, so this test includes an example of that.

Standard Fortran doesn't support backslash escape sequences within
strings, the special characters must be generated using the `achar`
function.  However, when GDB prints the strings we currently print
using the standard C like backslash sequences.

I'm not currently proposing to change that behaviour, the backslash
sequences are more compact than the standard Fortran way of doing
things, and are so widely used that I suspect most Fortran programmers
will understand them.
2022-11-17 10:26:26 +00:00
Tom Tromey
1be8435c74 Fix latent quote char bug in generic_printstr
generic_printstr prints an empty string like:

      fputs_filtered ("\"\"", stream);

However, this seems wrong to me if the quote character is something
other than double quote.  This patch fixes this latent bug.  Thanks to
Andrew for the test case.

Co-authored-by: Andrew Burgess <aburgess@redhat.com>
2022-10-10 10:43:33 -06:00
Tom de Vries
2043638bf9 [gdb/testsuite] Skip gdb.fortran/namelist.exp for gfortran 4.8
The test-case gdb.fortran/namelist.exp uses a gfortran feature (emitting
DW_TAG_namelist in the debug info) that has been supported since gfortran 4.9,
see PR gcc/37132.

Skip the test for gfortran 4.8 and earlier.  Do this using gcc_major_version,
and update it to be able to handle "gcc_major_version {gfortran-*} f90".

Tested on x86_64-linux, with gfortran 4.8.5, 7.5.0, and 12.1.1.
2022-06-27 12:47:26 +02:00
Andrew Burgess
9704b8b4bc gdb/testsuite: remove unneeded calls to get_compiler_info
It is not necessary to call get_compiler_info before calling
test_compiler_info, and, after recent commits that removed setting up
the gcc_compiled, true, and false globals from get_compiler_info,
there is now no longer any need for any test script to call
get_compiler_info directly.

As a result every call to get_compiler_info outside of lib/gdb.exp is
redundant, and this commit removes them all.

There should be no change in what is tested after this commit.
2022-06-24 15:07:29 +01:00
Nils-Christian Kempke
ebad7c6613 gdb/testsuite: fixup common-block.exp for intel compilers
The order in which the variables in info common and info locals are
displayed is compiler (and dwarf) dependent.  While all symbols should
be displayed the order is not fixed.

I added a gdb_test_multiple that lets ifx and ifort pass in cases where
only the order differs.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
0df017fbca gdb, testsuite, fortran: fixup mixed-lang-stack for Intel/LLVM compilers
When value-printing a pointer within GDB by default GDB will look for
defined symbols residing at the address of the pointer.  For the given
test the Intel/LLVM compiler stacks both display a symbol associated
with a printed pointer while the gnu stack does not.  This leads to
failures in the test when running the test with CC_FOR_TARGET='clang'
CXX_FOR_TARGET='clang' F90_FOR_TARGET='flang'"

  (gdb) b 37
  (gdb) r
  (gdb) f 6
  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = 4 + 5i
  f = 0x419ed0 "abcdef"
  g = 0x4041a0 <.BSS4>

or CC_FOR_TARGET='icx' CXX_FOR_TARGET='icpx' F90_FOR_TARGET='ifx'"

  (gdb) b 37
  (gdb) r
  (gdb) f 6
  (gdb) info args
  a = 1
  b = 2
  c = 3
  d = 4 + 5i
  f = 0x52eee0 "abcdef"
  g = 0x4ca210 <mixed_func_1a_$OBJ>

For the compiled binary the Intel/LLVM compilers both decide to move the
local variable g into the .bss section of their executable.  The gnu
stack will keep the variable locally on the stack and not define a
symbol for it.

Since the behavior for Intel/LLVM is actually expected I adapted the
testcase at this point to be a bit more allowing for other outputs.
I added the optional "<SYMBOLNAME>" to the regex testing for g.

The given changes reduce the test fails for Intel/LLVM stack by 4 each.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
a60ead5ded gdb, testsuite, fortran: fix double free in mixed-lang-stack.exp
While testing mixed-lang-stack I realized that valgrind actually
complained about a double free in the test.

   All done
  ==2503051==
  ==2503051== HEAP SUMMARY:
  ==2503051==     in use at exit: 0 bytes in 0 blocks
  ==2503051==   total heap usage: 26 allocs, 27 frees, 87,343 bytes allocated
  ==2503051==
  ==2503051== All heap blocks were freed -- no leaks are possible
  ==2503051==
  ==2503051== For lists of detected and suppressed errors, rerun with: -s
  ==2503051== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Reason for this is that in mixed-lang-stack.cpp in mixed_func_1f an
object "derived_type obj" goes on the stack which is then passed-by-value
(so copied) to mixed_func_1g.  The default copy-ctor will be called but,
since derived_type contains a heap allocated string and the copy
constructor is not implemented it will only be able to shallow copy the
object.  Right after each of the functions the object gets freed - on the
other hand the d'tor of derived_type actually is implemented and calls
free on the heap allocated string which leads to a double free.  Instead
of obeying the rule of 3/5 I just got rid of all that since it does not
serve the test.  The string is now just a const char* = ".." object
member.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
6b7b705d7c testsuite, fortran: allow additional completions in module.exp
For ifort, ifx, and flang the tests "complete modm" and "complete
modmany" fail.  This is because all three emit additional completion
suggestions.  These additional suggestions have their origin in symbols
emitted by the compilers which can also be completed from the respective
incomplete word (modm or modmany).  For this specific example gfortran
does not emit any additional symbols.

For example, in this test the linkage name for var_a in ifx is
"modmany_mp_var_a_" while gfortran uses "__modmany_MOD_var_a" instead.
Since modmany_mp_var_a can be completed from modm and also modmany they
will get displayed, while gfortran's symbol starts with "__" and thus will
be ignored (it cannot be a completion of a word starting with "m").

Similar things happen in flang and ifort.  Some example output is shown
below:

FLANG
  (gdb) complete p modm
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p modmany_

IFX/IFORT
  (gdb) complete p modm
  p modmany
  p modmany._
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p modmany_mp_var_a_
  p modmany_mp_var_b_
  p modmany_mp_var_c_
  p modmany_mp_var_i_

GFORTRAN
  (gdb) complete p modm
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i

I want to emphasize: for Fortran (and also C/C++) the complete command
does not actually check whether its suggestions make sense - all it does
is look for any symbol (in the minimal symbols, partial symbols etc.)
that a given substring can be completed to (meaning that the given substring
is the beginning of the symbol).  One can easily produce a similar
output for the gfortran compiled executable.  For this look at the
slightly modified "complete p mod" in gfortran:

  (gdb) complete p mod
  p mod1
  p mod1::var_const
  ...
  p mod_1.c
  p modcounter
  p mode_t
  p modf
  ...
  p modify_ldt
  p modmany
  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i
  p module
  p module.f90
  p module_entry
  p moduse
  p moduse::var_x
  p moduse::var_y

Many of the displayed symbols do not actually work with print:

  (gdb) p mode_t
  Attempt to use a type name as an expression
  (gdb) p mod_1.c
  No symbol "mod_1" in current context.
  (gdb)

I think that in the given test the output for gfortran only looks nice
"by chance" rather than is actually expected.  Expected is any output
that also contains the completions

  p modmany

  p modmany::var_a
  p modmany::var_b
  p modmany::var_c
  p modmany::var_i

while anythings else can be displayed as well (depending on the
compiler and its emitted symbols).

This, I'd consider all three outputs as valid and expected - one is just
somewhat lucky that gfortran does not produce any additional symbols that
got matched.

The given patch improves test performance for all three compilers
by allowing additional suggested completions inbetween and after
the two given blocks in the test.  I did not allow additional print
within the modmany_list block since the output is ordered alphabetically
and there should normally not appear any additional symbols there.

For flang/ifx/ifort I each see 2 failures less (which are exactly the two
complete tests).

As a side note and since I mentioned C++ in the beginning: I also tried
the gdb.cp/completion.exp.  The output seems a bit more reasonable,
mainly since C++ actually has a demangler in place and linkage symbols
do not appear in the output of complete.  Still, with a poor enough
to-be-completed string one can easily produce similar results:

  (gdb) complete p t
  ...
  p typeinfo name for void
  p typeinfo name for void const*
  p typeinfo name for void*
  p typeinfo name for wchar_t
  p typeinfo name for wchar_t const*
  p typeinfo name for wchar_t*
  p t *** List may be truncated, max-completions reached. ***
  (gdb) p typeinfo name for void*
  No symbol "typeinfo" in current context.
  (gdb) complete p B
  p BACK_SLASH
  p BUF_FIRST
  p BUF_LAST
  ...
  p Base
  p Base::Base()
  p Base::get_foo()
  p bad_key_err
  p buf
  p buffer
  p buffer_size
  p buflen
  p bufsize
  p build_charclass.isra
  (gdb) p bad_key_err
  No symbol "bad_key_err" in current context.

(compiled with gcc/g++ and breaking at main).

This patch is only about making the referenced test more 'fair' for the
other compilers.  Generally, I find the behavior of complete a bit
confusing and maybe one wants to change this at some point but this
would be a bigger task.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
b8dd7ddff9 testsuite, fortran: fix info-types for intel compilers
This info-types.exp test case had a few issues that this patch fixes.

First, the emitted symbol character(kind=1)/character*1 (different
compilers use different naming converntions here) which is checkedin the
test is not actually expected given the test program.  There is no
variable of that type in the test.  Still, gfortran emits it for every
Fortran program there is.  The reason is the way gfortran handles Fortran's
named main program.  It generates a wrapper around the Fortran program
that is quite similar to a C main function.  This C-like wrapper has
argc and argv arguments for command line argument passing and the argv
pointer type has a base type character(kind=1) DIE emitted at CU scope.

Given the program

  program prog
  end program prog

the degbug info gfortran emits looks somewhat like

   <0><c>: Abbrev Number: 3 (DW_TAG_compile_unit)
      ...
   <1><2f>: Abbrev Number: 4 (DW_TAG_subprogram)
      <30>   DW_AT_external    : 1
      <30>   DW_AT_name        : (indirect string, ...): main
      ...
   <2><51>: Abbrev Number: 1 (DW_TAG_formal_parameter)
      <52>   DW_AT_name        : (indirect string, ...): argc
      ...
   <2><5d>: Abbrev Number: 1 (DW_TAG_formal_parameter)
      <5e>   DW_AT_name        : (indirect string, ...): argv
      ...
      <62>   DW_AT_type        : <0x77>
      ...
   <2><6a>: Abbrev Number: 0
   ...
   <1><77>: Abbrev Number: 6 (DW_TAG_pointer_type)
      <78>   DW_AT_byte_size   : 8
      <79>   DW_AT_type        : <0x7d>
   <1><7d>: Abbrev Number: 2 (DW_TAG_base_type)
      <7e>   DW_AT_byte_size   : 1
      <7f>   DW_AT_encoding    : 8        (unsigned char)
      <80>   DW_AT_name        : (indirect string, ...): character(kind=1)
   <1><84>: Abbrev Number: 7 (DW_TAG_subprogram)
      <85>   DW_AT_name        : (indirect string, ...): prog
   ...

Ifx and flang do not emit any debug info for a wrapper main method so
the type is missing here.  There was the possibility of actually adding
a character*1 type variable to the Fortran executable, but both, ifx and
gfortran chose to emit this variable's type as a DW_TAG_string_type of
length one (instead of a character(kind=1), or whatever the respective
compiler naming convention is).  While string types are printed as
character*LENGHT in the fortran language part (e.g. when issuing a
'ptype') they do not generate any symbols inside GDB.  In read.c it says

   /* These dies have a type, but processing them does not create
      a symbol or recurse to process the children.  Therefore we can
      read them on-demand through read_type_die.  */

So they did not add any output to 'info types'.  Only flang did emit a
character type here.
As adding a type would have a) not solved the problem for ifx and would
have b) somehow hidden the curious behavior of gfortran, instead, the
check for this character type was chagened to optional with the
check_optional_entry to allow for the symbols's absence and to allow
flang and ifx to pass this test as well.

Second, the line checked for s1 was hardcoded as 37 in the test.  Given
that the type is actually defined on line 41 (which is what is emitted by
ifx) it even seems wrong.  The line check for s1 was changed to actually
check for 41 and a gfortran bug has been filed here

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

The test is now marked as xfail for gfortran.

Third, the whole test of checking for the 'Type s1' in info types seemed
questionable.  The type s1 is declared iside the scope of the Fortran
program info_types_test.  Its DIE however is emitted as a child of the
whole compilation unit making it visible outside of the program's scope.
The 'info types' command checks for types stored in the GLOBAL_BLOCK,
or STATIC_BLOCKm wgucm according to block.h

   The GLOBAL_BLOCK contains all the symbols defined in this compilation
   whose scope is the entire program linked together.
   The STATIC_BLOCK contains all the symbols whose scope is the
   entire compilation excluding other separate compilations.

so for gfortran, the type shows up in the output of 'info types'.  For
flang and ifx on the other hand this is not the case.  The two compilers
emit the type (correctly) as a child of the Fortran program, thus not
adding it to either, the GLOBAL_BLOCK nor the LOCAL_BLOCK.  A bug has
been opened for the gfortran scoping issue:

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

While the most correct change might have been removing the check for s1,
the change made here was to only check for this type in case of gfortran
being used as the compiler, as this check also covers the declaration
line issue mentioned above.  A comment was added to maybe remove this
check once the scoping issue is resolved (and it starts to fail with
newer gfortran versions).  The one used to test these changes was 13.0.
2022-05-31 16:44:56 +02:00
Nils-Christian Kempke
15868bc883 testsuite, fortran: add compiler dependent types to dynamic-ptype-whatis
The test was earlier not using the compiler dependent type print system
in fortran.exp.  I changed this.  It should generally improve the test
performance for different compilers.  For ifx and gfortran I do not see
any failures.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
93bbd6c793 testsuite, fortran: add required external keyword
Currenlty, ifx/ifort cannot compile the given executable as it is not
valid Fortran.  It is missing the external keyword on the
no_arg_subroutine.  Gfortran compiles the example but this is actually
a bug and there is an open gcc ticket for this here:

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

Adding the keyword does not change the gfortran compiling of the example.
It will, however, prevent a future fail once 50377 has been addressed.
2022-05-31 16:44:55 +02:00
Nils-Christian Kempke
87364601b8 gdb/testsuite: disable charset.exp for intel compilers
The test specifically tests for the Fortran CHARACTER(KIND=4) which is
not available in ifx/ifort.

Since the other characters are also printed elsewhere, we disable this
test for the unsupported compilers.
2022-05-31 16:44:54 +02:00
Cristian Sandu
44d469c5f8 gdb/testsuite: add Fortran compiler identification to GDB
This commit adds a separate Fortran compiler identification mechanism to
the testsuite, similar to the existing one for C/C++.  Before this
change, the options and version for the Fortran compiler specified when
running the testsuite with F90_FOR_TARGET set, was detected via its
respective C compiler.  So running the testsuite as

  make check TEST=gdb.fortran/*.exp CC_FOR_TARGET=gcc F90_FOR_TARGET=ifx

or even

  make check TEST=gdb.fortran/*.exp F90_FOR_TARGET=ifx

would use the gcc compiler inside the procedures get_compiler_info and
test_compiler_info to identify compiler flags and the compiler version.
This could sometimes lead to unpredictable outputs.  It also limited
testsuite execution to combinations where C and Fortran compiler would
come from the same family of compiers (gcc/gfortran, icc/ifort, icx/ifx,
clang/flang ..).  This commit enables GDB to detect C and Fortran
compilers independently of each other.

As most/nearly all Fortran compilers have a mechanism for preprocessing
files in a C like fashion we added the exact same meachnism that already
existed for C/CXX.  We let GDB preprocess a file with the compilers
Fortran preprocessor and evaluate the preprocessor defined macros in that
file.

This enables GDB to properly run heterogeneous combinations of C and
Fortran compilers such as

  CC_FOR_TARGET='gcc' and F90_FOR_TARGET='ifort'

or enables one to run the testsuite without specifying a C compiler as in

  make check TESTS=gdb.fortran/*.exp F90_FOR_TARGET='ifx'
  make check TESTS=gdb.fortran/*.exp F90_FOR_TARGET='flang'

On the other hand this also requires one to always specify a
identification mechanism for Fortran compilers in the compiler.F90 file.

We added identification for GFORTRAN, FLANG (CLASSIC and LLVM) IFX,
IFORT, and ARMFLANG for now.

Classic and LLVM flang were each tested with their latest releases on
their respective release pages.  Both get recognized by the new compiler
identification and we introduced the two names flang-classic and
flang-llvm to distinguish the two.  While LLVM flang is not quite mature
enough yet for running the testsuite we still thought it would be a good
idea to include it already.  For this we added a case for the fortran_main
procedure.  LLVM flang uses 'MAIN__' as opposed to classic flang which
uses 'MAIN_' here.

We did not have the possibility to test ARMFLANG - the versioning scheme
here was extracted from its latest online documentation.

We changed the test_compiler_info procedure to take another optional
argument, the language string, which will be passed though to the
get_compiler_info procedure.  Passing 'f90' or 'c++' here will then
trigger the C++/Fortran compiler identification within
get_compiler_info.  The latter procedure was extended to also handle
the 'f90' argument (similarly to the already existing 'c++' one).

Co-authored-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
2022-05-31 16:44:54 +02:00
Bruno Larsen
cdd4206647 gdb/testsuite: fix "continue outside of loop" TCL errors
Many test cases had a few lines in the beginning that look like:

if { condition } {
  continue
}

Where conditions varied, but were mostly in the form of ![runto_main] or
[skip_*_tests], making it quite clear that this code block was supposed
to finish the test if it entered the code block. This generates TCL
errors, as most of these tests are not inside loops.  All cases on which
this was an obvious mistake are changed in this patch.
2022-05-16 10:07:43 -03:00
Nils-Christian Kempke
6dc7160b2d gdb/testsuite: fix testsuite regressions for unix/-m32 board
This commit fixes two regressions introduced by
891e4190ba.

Reason for the failures was, that on a 32 bit machine the maximum
array length as well as the maximum allocatable memory for arrays
(in bytes) both seem to be limited by the maximum value of a 4
byte (signed) Fortran integer.  This lead to compiler errors/unexpected
behavior when compiling/running the test with the -m32 board.  This
behavior is compiler dependent and can differ for different compiler
implementations, but generally, it seemed like a good idea to simply
avoid such situations.

The affected tests check for GDB's overflow behavior when using KIND
parameters with GDB implemented Fortran intrinsic functions.  If these
KIND parameters are too small to fit the actual intrinsic function's
result, an overflow is expected.  This was done for 1, 2, and 4
byte overflows.  The last one caused problems, as it tried to allocate
arrays of length/byte-size bigger than the 4 byte signed integers which
would then be used with the LBOUND/UBOUND/SIZE intrinsics.

The tests were adapted to only execute the 4 byte overflow tests when
running on targets with 64 bit.  For this, the compiled tests evaluate the
byte size of a C_NULL_PTR via C_SIZEOF, both defined in the ISO_C_BINDING
module.  The ISO_C_BINDING constant C_NULL_PTR is a Fortran 2003, the
C_SIZEOF a Fortran 2008 extension.  Both have been implemented in their
respective compilers for while (e.g. C_SIZEOF is available since
gfortran 4.6).  If this byte size evaluates to less than 8 we skip the
4 byte overflow tests in the compiled tests of size.f90 and
lbound-ubound.f90.  Similarly, in the lbound-ubound.exp testsfile we skip
the 4 byte overflow tests if the procedure is_64_target evaluates to false.

In size.f90, additionally, the to-be-allocated amount of bytes did not
fit into 4 byte signed integers for some of the arrays, as it was
approximately 4 times the maximum size of a 4 byte signed integer.  We
adapted the dimensions of the arrays in question as the meaningfulness
of the test does not suffer from this.

With this patch both test run fine with the unix/-m32 board and
gcc/gfortran (9.4) as well as the standard board file.

We also thought about completely removing the affected test from the
testsuite.  We decided against this as the 32 bit identification comes
with Fortran 2008 and removing tests would have decreased coverage.

A last change that happened with this patch was due to gfortran's and
ifx's type resolution when assigning big constants to Fortran Integer*8
variables.  Before the above changes this happened in a parameter
statement.  Here, both compilers happily accepted a line like

  integer*8, parameter :: var = 2147483647 + 5.

After this change the assignment is not done as a parameter
anymore, as this triggered compile time overflow errors.  Instead,
the assignment is done dynamically, depending on the kind of machine one
is on.  Sadly, just changing this line to

  integer*8 :: var
  var = 2147483647 + 5

does not work with ifx (or flang for that matter, they behave similarly
here).  It will create an integer overflow in the addition as ifx deduces
the type the additon is done in as Integer*4.  So var will actually
contain the value -2147483644 after this.  The lines

  integer*8 :: var
  var = 2147483652

on the other hand fail to compile with gfortran (9.4.0) as the compiler
identifies an Integer overflow here.  Finally, to make this work with
all three compilers an additional parameter has been introduced

  integer*8, parameter :: helper = 2147483647
  integer*8 :: var
  var = helper + 5.

This works on all 3 compilers as expected.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29053
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29054
2022-05-10 14:54:46 +02:00
rupothar
5f59e7e0c7 gdb/fortran: Support for assumed rank zero
If a variable is passed to function in FORTRAN as an argument the
variable is treated as an array with rank zero.  GDB currently does
not support the case for assumed rank 0.  This patch provides support
for assumed rank 0 and updates the testcase as well.

Without patch:
Breakpoint 1, arank::sub1 (a=<error reading variable:
  failed to resolve dynamic array rank>) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
failed to resolve dynamic array rank
(gdb) p rank(a)
failed to resolve dynamic array rank

With patch:
Breakpoint 1, arank::sub1 (a=0) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
$1 = 0
(gdb) p rank(a)
$2 = 0
2022-04-25 14:58:30 +05:30
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