Commit Graph

510 Commits

Author SHA1 Message Date
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
Tom Tromey
785545988c Fix crash in is_nocall_function
is_nocall_function anticipates only being called for a function or a
method.  However, PR gdb/29871 points out a situation where an unusual
expression -- but one that parses to a valid, if extremely weird,
function call -- breaks this assumption.

This patch changes is_nocall_function to remove this assert and
instead simply return 'false' in this case.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29871
2022-12-12 21:38:01 -07:00
Tom Tromey
4881fcd7c1 Add missing TYPE_CODE_* constants to Python
A user noticed that TYPE_CODE_FIXED_POINT was not exported by the gdb
Python layer.  This patch fixes the bug, and prevents future
occurences of this type of bug.
2022-10-31 12:47:36 -06:00
Tom Tromey
6c849804cf Fix bug in Ada packed array handling
A user found a bug where an array of packed arrays was printed
incorrectly.  The bug here is that the packed array has a bit stride,
but the outer array does not -- and should not.  However,
update_static_array_size does not distinguish between an array of
packed arrays and a multi-dimensional packed array, and for the
latter, only the innermost array will end up with a stride.

This patch fixes the problem by adding a flag to indicate whether a
given array type is a constituent of a multi-dimensional array.
2022-10-21 09:40:58 -06:00
Tom Tromey
bd2b40ac12 Change GDB to use frame_info_ptr
This changes GDB to use frame_info_ptr instead of frame_info *
The substitution was done with multiple sequential `sed` commands:

sed 's/^struct frame_info;/class frame_info_ptr;/'
sed 's/struct frame_info \*/frame_info_ptr /g' - which left some
    issues in a few files, that were manually fixed.
sed 's/\<frame_info \*/frame_info_ptr /g'
sed 's/frame_info_ptr $/frame_info_ptr/g' - used to remove whitespace
    problems.

The changed files were then manually checked and some 'sed' changes
undone, some constructors and some gets were added, according to what
made sense, and what Tromey originally did

Co-Authored-By: Bruno Larsen <blarsen@redhat.com>
Approved-by: Tom Tomey <tom@tromey.com>
2022-10-10 11:57:10 +02:00
Simon Marchi
df86565b31 gdb: remove TYPE_LENGTH
Remove the macro, replace all uses with calls to type::length.

Change-Id: Ib9bdc954576860b21190886534c99103d6a47afb
2022-09-21 11:05:21 -04:00
Simon Marchi
b6cdbc9a81 gdb: add type::length / type::set_length
Add the `length` and `set_length` methods on `struct type`, in order to remove
the `TYPE_LENGTH` macro.  In this patch, the macro is changed to use the
getter, so all the call sites of the macro that are used as a setter are
changed to use the setter method directly.  The next patch will remove the
macro completely.

Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
2022-09-21 10:59:51 -04:00
Simon Marchi
27710edb4e gdb: remove TYPE_TARGET_TYPE
Remove the macro, replace all uses by calls to type::target_type.

Change-Id: Ie51d3e1e22f94130176d6abd723255282bb6d1ed
2022-09-21 10:59:49 -04:00
Simon Marchi
8a50fdcefc gdb: add type::target_type / type::set_target_type
Add the `target_type` and `set_target_type` methods on `struct type`, in order
to remove the `TYPE_TARGET_TYPE` macro.  In this patch, the macro is changed to
use the getter, so all the call sites of the macro that are used as a setter
are changed to use the setter method directly.  The next patch will remove the
macro completely.

Change-Id: I85ce24d847763badd34fdee3e14b8c8c14cb3161
2022-09-21 10:53:55 -04:00
Tom Tromey
cb275538db Use registry in gdbarch
gdbarch implements its own registry-like approach.  This patch changes
it to instead use registry.h.  It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.

The main benefit of this change is that it introduces type safety to
the gdbarch registry.  It also removes a bunch of code.

One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup.  This
doesn't seem very important to me, though.
2022-08-04 13:28:04 -06:00
Tom Tromey
bde539c2f9 Change allocation of type-copying hash table
When an objfile is destroyed, types that are still in use and
allocated on that objfile are copied.  A temporary hash map is created
during this process, and it is allocated on the destroyed objfile's
obstack -- which normally is fine, as that is going to be destroyed
shortly anyway.

However, this approach requires that the objfile be passed to registry
destruction, and this won't be possible in the rewritten registry.
This patch changes the copied type hash table to simply use the heap
instead.  It also removes the 'objfile' parameter from
copy_type_recursive, to make this all more clear.

This patch also fixes an apparent bug in copy_type_recursive.
Previously it was copying the dynamic property list to the dying
objfile's obstack:

-      = copy_dynamic_prop_list (&objfile->objfile_obstack,

However I think this is incorrect -- that obstack is about to be
destroyed.
2022-07-28 14:16:50 -06: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
rupothar
df7a7bdd97 gdb: add support for Fortran's ASSUMED RANK arrays
This patch adds a new dynamic property DYN_PROP_RANK, this property is
read from the DW_AT_rank attribute and stored within the type just
like other dynamic properties.

As arrays with dynamic ranks make use of a single
DW_TAG_generic_subrange to represent all ranks of the array, support
for this tag has been added to dwarf2/read.c.

The final piece of this puzzle is to add support in gdbtypes.c so that
we can resolve an array type with dynamic rank.  To do this the
existing resolve_dynamic_array_or_string function is split into two,
there's a new resolve_dynamic_array_or_string_1 core that is
responsible for resolving each rank of the array, while the now outer
resolve_dynamic_array_or_string is responsible for figuring out the
array rank (which might require resolving a dynamic property) and then
calling the inner core.

The resolve_dynamic_range function now takes a rank, which is passed
on to the dwarf expression evaluator.  This rank will only be used in
the case where the array itself has dynamic rank, but we now pass the
rank in all cases, this should be harmless if the rank is not needed.

The only small nit is that resolve_dynamic_type_internal actually
handles resolving dynamic ranges itself, which now obviously requires
us to pass a rank value.  But what rank value to use?  In the end I
just passed '1' through here as a sane default, my thinking is that if
we are in resolve_dynamic_type_internal to resolve a range, then the
range isn't part of an array with dynamic rank, and so the range
should actually be using the rank value at all.

An alternative approach would be to make the rank value a
gdb::optional, however, this ends up adding a bunch of complexity to
the code (e.g. having to conditionally build the array to pass to
dwarf2_evaluate_property, and handling the 'rank - 1' in
resolve_dynamic_array_or_string_1) so I haven't done that, but could,
if people think that would be a better approach.

Finally, support for assumed rank arrays was only fixed very recently
in gcc, so you'll need the latest gcc in order to run the tests for
this.

Here's an example test program:

  PROGRAM arank
    REAL :: a1(10)
    CALL sub1(a1)

  CONTAINS

    SUBROUTINE sub1(a)
      REAL :: a(..)
      PRINT *, RANK(a)
    END SUBROUTINE sub1
  END PROGRAM arank

Compiler Version:
gcc (GCC) 12.0.0 20211122 (experimental)

Compilation command:
gfortran assumedrank.f90 -gdwarf-5 -o assumedrank

Without Patch:

  gdb -q assumedrank
  Reading symbols from assumedrank...
  (gdb) break sub1
  Breakpoint 1 at 0x4006ff: file assumedrank.f90, line 10.
  (gdb) run
  Starting program: /home/rupesh/STAGING-BUILD-2787/bin/assumedrank

  Breakpoint 1, arank::sub1 (a=<unknown type in /home/rupesh/STAGING-BUILD-2787
  /bin/assumedrank, CU 0x0, DIE 0xd5>) at assumedrank.f90:10
  10       PRINT *, RANK(a)
  (gdb) print RANK(a)
  'a' has unknown type; cast it to its declared type

With patch:

  gdb -q assumedrank
  Reading symbols from assumedrank...
  (gdb) break sub1
  Breakpoint 1 at 0x4006ff: file assumedrank.f90, line 10.
  (gdb) run
  Starting program: /home/rupesh/STAGING-BUILD-2787/bin/assumedrank

  Breakpoint 1, arank::sub1 (a=...) at assumedrank.f90:10
  10       PRINT *, RANK(a)
  (gdb) print RANK(a)
  $1 = 1
  (gdb) ptype a
  type = real(kind=4) (10)
  (gdb)

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
2022-04-03 17:18:20 +01:00
Tiezhu Yang
552f1157c6 gdb: rename floatformats_ia64_quad to floatformats_ieee_quad
It is better to rename floatformats_ia64_quad to floatformats_ieee_quad
to reflect the reality, and then we can clean up the related code.

As Tom Tromey said [1]:

  These files are maintained in gcc and then imported into the
  binutils-gdb repository, so any changes to them will have to
  be proposed there first.

the related changes have been merged into gcc master now [2], it is time
to do it for gdb.

[1] https://sourceware.org/pipermail/gdb-patches/2022-March/186569.html
[2] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b2dff6b2d9d6

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
2022-04-02 08:36:33 +08:00
Tom Tromey
48ac197b0c Handle multiple addresses in call_site_target
A large customer program has a function that is partitioned into hot
and cold parts.  A variable in a callee of this function is described
using DW_OP_GNU_entry_value, but gdb gets confused when trying to find
the caller.  I tracked this down to dwarf2_get_pc_bounds interpreting
the function's changes so that the returned low PC is the "wrong"
function.

Intead, when processing DW_TAG_call_site, the low PC of each range in
DW_AT_ranges should be preserved in the call_site_target.  This fixes
the variable lookup in the test case I have.

I didn't write a standalone test for this as it seemed excessively
complicated.
2022-03-28 13:31:22 -06:00
Tom Tromey
a0e0ca7044 Change call_site_target to iterate over addresses
In order to handle the case where a call site target might refer to
multiple addresses, we change the code to use a callback style.  Any
spot using call_site_target::address now passes in a callback function
that may be called multiple times.
2022-03-28 13:28:56 -06:00
Tom Tromey
797662d7ef Make call_site_target members private
This makes the data members of call_site_target 'private'.  This lets
us remove most of its public API.  call_site_to_target_addr is changed
to be a method of this type.  This is a preparatory refactoring for
the fix at the end of this series.
2022-03-28 13:07:42 -06:00
Tom Tromey
7eb21cc702 Change call_site_target to use custom type and enum
call_site_target reuses field_loc_kind and field_location.  However,
it has never used the full range of the field_loc_kind enum.  In a
subsequent patch, I plan to add a new 'kind' here, so it seemed best
to avoid this reuse and instead introduce new types here.
2022-03-28 13:07:41 -06:00
Lancelot SIX
0b35f123c2 gdb: Respect the DW_CC_nocall attribute
It is possible for a compiler to optimize a function in a such ways that
the function does not follow the calling convention of the target.  In
such situation, the compiler can use the DW_AT_calling_convention
attribute with the value DW_CC_nocall to tell the debugger that it is
unsafe to call the function.  The DWARF5 standard states, in 3.3.1.1:

  > If the value of the calling convention attribute is the constant
  > DW_CC_nocall, the subroutine does not obey standard calling
  > conventions, and it may not be safe for the debugger to call this
  > subroutine.

Non standard calling convention can affect GDB's assumptions in multiple
ways, including how arguments are passed to the function, how values are
returned, and so on.  For this reason, it is unsafe for GDB to try to do
the following operations on a function with marked with DW_CC_nocall:

- call / print an expression requiring the function to be evaluated,
- inspect the value a function returns using the 'finish' command,
- force the value returned by a function using the 'return' command.

This patch ensures that if a command which relies on GDB's knowledge of
the target's calling convention is used on a function marked nocall, GDB
prints an appropriate message to the user and does not proceed with the
operation which is unreliable.

Note that it is still possible for someone to use a vendor specific
value for the DW_AT_calling_convention attribute for example to indicate
the use of an alternative calling convention.  This commit does not
prevent this, and target dependent code can be adjusted if one wanted to
support multiple calling conventions.

Tested on x86_64-Linux, with no regression observed.

Change-Id: I72970dae68234cb83edbc0cf71aa3d6002a4a540
2022-02-15 09:52:37 +00:00
Bhuvanendra Kumar N
e951225303 gdb/fortran: support ptype and print commands for namelist variables
Gfortran supports namelists (a Fortran feature); it emits
DW_TAG_namelist and DW_TAG_namelist_item dies. But gdb does not
process these dies and does not support 'print' or 'ptype' commands on
namelist variables.

An attempt to print namelist variables results in gdb bailing out with
the error message as shown below.

  (gdb) print nml
  No symbol "nml" in current context.

This commit is to make the print and ptype commands work for namelist
variables and its items. Sample output of these commands is shared
below, with fixed gdb.

  (gdb) ptype nml
  type = Type nml
      integer(kind=4) :: a
      integer(kind=4) :: b
  End Type nml
  (gdb) print nml
  $1 = ( a = 10, b = 20 )
2022-02-11 15:26:25 +00:00
Tom Tromey
0589ca4e7b Introduce gdb-hashtab module in gdbsupport
gdb has some extensions and helpers for working with the libiberty
hash table.  This patch consolidates these and moves them to
gdbsupport.
2022-01-18 10:14:43 -07:00
Tom Tromey
bf31fd38f0 Move gdb obstack code to gdbsupport
This moves the gdb-specific obstack code -- both extensions like
obconcat and obstack_strdup, and things like auto_obstack -- to
gdbsupport.
2022-01-18 10:14:42 -07:00
Joel Brobecker
4a94e36819 Automatic Copyright Year update after running gdb/copyright.py
This commit brings all the changes made by running gdb/copyright.py
as per GDB's Start of New Year Procedure.

For the avoidance of doubt, all changes in this commits were
performed by the script.
2022-01-01 19:13:23 +04:00
Tom Tromey
ba0084966c Remove unusual use of core_addr_eq and core_addr_hash
gdbtypes.h uses core_addr_eq and core_addr_hash in a weird way: taking
the address of a member and then passing this (as a void*) to these
functions.

It seems better to simply inline the ordinary code here.  CORE_ADDR is
a scalar so it can be directly compared, and the identity hash
function seems safe to assume as well.

After this, core_addr_eq and core_addr_hash are unused, so this patch
removes them.
2021-12-29 10:24:05 -07:00
Simon Marchi
51e36a3aaa gdb: remove TYPE_FIELD_DWARF_BLOCK
Remove TYPE_FIELD_DWARF_BLOCK, replace with type::field +
field::loc_dwarf_block.

Change-Id: I10af9410bb5f46d342b8358a7956998c7e804b64
2021-10-29 16:44:45 -04:00
Simon Marchi
e06c3e112e gdb: remove TYPE_FIELD_STATIC_PHYSADDR
Remove TYPE_FIELD_STATIC_PHYSADDR replace with type::field +
field::loc_physaddr.

Change-Id: Ica9bc4a48f34750ec82ec86c298d3ecece81bcbd
2021-10-29 16:44:45 -04:00
Simon Marchi
fcbbbd90f0 gdb: remove TYPE_FIELD_STATIC_PHYSNAME
Remove TYPE_FIELD_STATIC_PHYSNAME, replace with type::field +
field::loc_physname.

Change-Id: Ie35d446b67dd1d02f39998b406001bdb7e6d5abb
2021-10-29 16:44:45 -04:00
Simon Marchi
970db51860 gdb: remove TYPE_FIELD_ENUMVAL
Remove TYPE_FIELD_ENUMVAL, replace with type::field +
field::loc_enumval.

Change-Id: I2ada73e4635aad3363ce2eb22c1dc52698ee2072
2021-10-29 16:44:45 -04:00
Simon Marchi
b610c04548 gdb: remove TYPE_FIELD_BITPOS
Remove TYPE_FIELD_BITPOS, replace its uses with type::field +
field::loc_bitpos.

Change-Id: Iccd8d5a77e5352843a837babaa6bd284162e0320
2021-10-29 16:44:44 -04:00
Simon Marchi
2ad53ea10c gdb: remove TYPE_FIELD_LOC_KIND
Remove TYPE_FIELD_LOC_KIND, replace its uses with type::field +
field::loc_kind.

Change-Id: Ib124a26365df82ac1d23df7962d954192913bd90
2021-10-29 16:44:21 -04:00
Simon Marchi
d8557c3d22 gdb: remove FIELD_DWARF_BLOCK macro
Remove FIELD_DWARF_BLOCK, replace its uses with field::loc_dwarf_block.

Change-Id: I66b7d6a960cb5e341e61e21bd3cc9a6ac26de6a8
2021-10-29 16:44:21 -04:00
Simon Marchi
31a1516a81 gdb: remove FIELD_STATIC_PHYSADDR macro
Remove FIELD_LOC_KIND_PHYSADDR, replace its uses with
field::loc_physaddr.

Change-Id: Ifd8b2bdaad75f42bfb1404ef8c396ffe7e10ac55
2021-10-29 16:44:21 -04:00
Simon Marchi
16654a591a gdb: remove FIELD_STATIC_PHYSNAME macro
Remove FIELD_STATIC_PHYSNAME, replace its uses with field::loc_physname.

Change-Id: Iaa8952410403b4eb5bbd68411feea27e2405d657
2021-10-29 16:44:21 -04:00
Simon Marchi
5d2038e3f5 gdb: remove FIELD_ENUMVAL macro
Remove FIELD_ENUMVAL, replace its uses with field::loc_enumval.

Change-Id: Id4861cee91a8bb583a9836f1aa5da0a320fbf4d9
2021-10-29 16:44:21 -04:00
Simon Marchi
3a543e211e gdb: remove FIELD_BITPOS macro
Remove FIELD_BITPOD, replace its uses with field::loc_bitpos.

Change-Id: Idb99297e0170661254276c206383a7e9bf1a935a
2021-10-29 16:44:21 -04:00
Simon Marchi
8d939e8ea4 gdb: remove FIELD_LOC_KIND macro
Remove FIELD_LOC_KIND, replace its uses with field::loc_kind or
call_site_target::loc_kind.

Change-Id: I0368d8c3ea269d491bb215aa70e32edbdf55f389
2021-10-29 16:44:20 -04:00
Tom Tromey
52429bbd71 Document resolve_dynamic_type oddity
Today I re-learned that resolve_dynamic_type can return a type for
which is_dynamic_type returns true.  This can happen for an array
whose elements have dynamic type -- the array is reported as dynamic,
but resolving the elements would be incorrect, because each element
might have a different type after resolution.

You can see the special case in resolve_dynamic_array_or_string:

  if (ary_dim != NULL && ary_dim->code () == TYPE_CODE_ARRAY)
...
  else
...

I looked into having the TYPE_CODE_ARRAY case in
is_dynamic_type_internal follow this same logic, but that breaks down
on the gdb.fortran/dynamic-ptype-whatis.exp test case.  In particular
this code in fortran_undetermined::evaluate:

  value *callee = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
  if (noside == EVAL_AVOID_SIDE_EFFECTS
      && is_dynamic_type (value_type (callee)))
    callee = std::get<0> (m_storage)->evaluate (nullptr, exp, EVAL_NORMAL);

... relies on is_dynamic_type returning true for such an array.

I wasn't really sure of the best way to fix this, so in the meantime I
wrote this patch, which documents the oddity so that I might have a
chance of remembering this in the future.
2021-10-29 07:33:13 -06:00
Tom Tromey
5a8edb756a Check index in type::field
This changes gdb to check the index that is passed to type::field.
This caught one bug in the Ada code when running the test suite
(actually I found the bug first, then realized that the check would
have helped), so this patch fixes that as well.

Regression tested on x86-64 Fedora 34.
2021-10-19 13:30:59 -06:00
Simon Marchi
cd3f655cc7 gdb: add accessors for field (and call site) location
Add accessors for the various location values in struct field.  This
lets us assert that when we get a location value of a certain kind (say,
bitpos), the field's location indeed contains a value of that kind.

Remove the SET_FIELD_* macros, instead use the new setters directly.
Update the FIELD_* macros used to access field locations to go through
the getters.  They will be removed in a subsequent patch.

There are places where the FIELD_* macros are used on call_site_target
structures, because it contains members of the same name (loc_kind and
loc).  For now, I have replicated the getters/setters in
call_site_target.  But we could perhaps eventually factor them in a
"location" structure that can be used at both places.

Note that the field structure, being zero-initialized, defaults to a
bitpos location with value 0.  While writing this patch, I tried to make
it default to an "unset" location, to catch places where we would miss
setting a field's location.  However, I found that some places relied on
the default being "bitpos 0", so I left it as-is.  This change could
always be done as follow-up work, making these places explicitly set the
"bitpos 0" location.

I found two issues to fix:

 - I got some failures in the gdb.base/infcall-nested-structs-c++.exp
   test.  They were caused by two functions in amd64-tdep.c using
   TYPE_FIELD_BITPOS before checking if the location is of the bitpos
   kind, which they do indirectly through `field_is_static`.  Simply
   move getting the bitpos below the field_is_static call.

 - I got a failure in gdb.xml/tdesc-regs.exp.  It turns out that in
   make_gdb_type_enum, we set enum field values using SET_FIELD_BITPOS,
   and later access them through FIELD_ENUMVAL.  Fix that by using
   set_loc_enumval to set the value.

Change-Id: I53d3734916c46457576ba11dd77df4049d2fc1e8
2021-10-07 11:03:54 -04:00
Simon Marchi
b0b8879e29 [gdb/symtab] Use unrelocated addresses in call_site
Consider test-case gdb.trace/entry-values.exp with target board
unix/-fPIE/-pie.

Using this command we have an abbreviated version, and can see the correct
@entry values for foo:
...
$ gdb -q -batch outputs/gdb.trace/entry-values/entry-values \
  -ex start \
  -ex "break foo" \
  -ex "set print entry-values both" \
  -ex continue
Temporary breakpoint 1 at 0x679

Temporary breakpoint 1, 0x0000555555554679 in main ()
Breakpoint 2 at 0x55555555463e

Breakpoint 2, 0x000055555555463e in foo (i=0, i@entry=2, j=2, j@entry=3)
...

Now, let's try the same again, but run directly to foo rather than stopping at
main:
...
$ gdb -q -batch outputs/gdb.trace/entry-values/entry-values \
  -ex "break foo" \
  -ex "set print entry-values both" \
  -ex run
Breakpoint 1 at 0x63e

Breakpoint 1, 0x000055555555463e in foo (i=0, i@entry=<optimized out>, \
  j=2, j@entry=<optimized out>)
...

So, what explains the difference?  Noteworthy, this is a dwarf assembly
test-case, with debug info for foo and bar, but not for main.

In the first case:
- we run to main
- this does not trigger expanding debug info, because there's none for main
- we set a breakpoint at foo
- this triggers expanding debug info.  Relocated addresses are used in
  call_site info (because the exec is started)
- we continue to foo, and manage to find the call_site info

In the second case:
- we set a breakpoint at foo
- this triggers expanding debug info.  Unrelocated addresses are used in
  call_site info (because the exec is not started)
- we run to foo
- this triggers objfile_relocate1, but it doesn't update the call_site
  info addresses
- we don't manage to find the call_site info

We could fix this by adding the missing call_site relocation in
objfile_relocate1.

This solution however is counter-trend in the sense that we're trying to
work towards the situation where when starting two instances of an executable,
we need only one instance of debug information, implying the use of
unrelocated addresses.

So, fix this instead by using unrelocated addresses in call_site info.

Tested on x86_64-linux.

This fixes all remaining unix/-fno-PIE/-no-pie vs unix/-fPIE/-pie
regressions, like f.i. PR24892.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24892

Co-Authored-By: Tom de Vries <tdevries@suse.de>
2021-10-04 18:16:40 +02:00
Simon Marchi
b84aaadaf8 [gdb/symtab] C++-ify call_site
- add constructor
- add member function call_site::pc ()

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
2021-10-04 18:16:40 +02:00
Tom de Vries
0dd8295da2 [gdb/symtab] Add call_site_eq and call_site_hash
In commit b4c919f752 "[gdb/symtab] Fix htab_find_slot call in
read_call_site_scope" , I removed the comment:
...
It must be the first field as we overload core_addr_hash and core_addr_eq for
it.
...
for field pc of struct call_site.

However, this was not tested, and when indeed moving field pc to the second
location, we run into a testsuite failure in gdb.trace/entry-values.exp.

This is caused by core_addr_eq (the eq_f function for the htab) being
called with a pointer to the pc field (as passed into htab_find_slot) and a
pointer to a hash table element.  Now that pc is no longer the first field,
the pointer to hash table element no longer points to the pc field.

This could be fixed by simply reinstating the comment, but we're trying to
get rid of this kind of tricks that make refactoring more difficult.

Instead, fix this by:
- reverting commit b4c919f752, apart from the comment removal, such that
  we're passing a pointer to element to htab_find_slot
- updating the htab_find_slot call in compunit_symtab::find_call_site
  in a similar manner
- adding a call_site_eq and call_site_hash, and using these in the hash table
  instead of core_addr_eq and core_addr_hash.

Tested on x86_64-linux, both with and without a trigger patch that moves pc to
the second location in struct call_site.
2021-10-04 18:16:40 +02:00
Simon Marchi
b4c919f752 [gdb/symtab] Fix htab_find_slot call in read_call_site_scope
In read_call_site_scope we have:
...
  call_site_local.pc = pc;
  slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT);
...

The call passes a call_site pointer as element.  OTOH, the hashtab is created
using hash_f == core_addr_hash and eq_f == core_addr_eq, so the element
will be accessed through a CORE_ADDR pointer.

This is not wrong (at least in C), given that pc is the first field in
call_site.

Nevertheless, as in call_site_for_pc, make the htab_find_slot call match the
used hash_f and eq_f by using &pc instead:
...
  slot = htab_find_slot (cu->call_site_htab, &pc, INSERT);
...

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
2021-10-01 17:15:20 +02:00
Simon Marchi
33d16dd987 gdb: remove TYPE_FIELD_NAME and FIELD_NAME macros
Remove the `TYPE_FIELD_NAME` and `FIELD_NAME` macros, changing all the
call sites to use field::name directly.

Change-Id: I6900ae4e1ffab1396e24fb3298e94bf123826ca6
2021-09-30 22:05:57 -04:00
Simon Marchi
d3fd12dfc5 gdb: add field::name / field::set_name
Add the `name` and `set_name` methods on `struct field`, in order to
remove `FIELD_NAME` and `TYPE_FIELD_NAME` macros.  In this patch, the
macros are changed to use `field::name`, so all the call sites that are
used to set the field's name are changed to use `field::set_name`.
The next patch will remove the macros completely.

Note that because of the name clash between the existing field named
`name` and the new method, I renamed the field `m_name`.  It is not
private per-se, because we can't make `struct field` a non-POD yet, but
it should be considered private anyway (not accessed outside `struct
field`).

Change-Id: If16ddbca4e0c39d0ff9da420bb5cdebe5b9b0896
2021-09-30 22:05:46 -04:00
Tom Tromey
809f3be12c Change pointer_type to a method of struct type
I noticed that pointer_type is declared in language.h and defined in
language.c.  However, it really has to do with types, so it should
have been in gdbtypes.h all along.

This patch changes it to be a method on struct type.  And, I went
through uses of TYPE_IS_REFERENCE and updated many spots to use the
new method as well.  (I didn't update ones that were in arch-specific
code, as I couldn't readily test that.)
2021-09-23 15:11:00 -06:00
George Barrett
b5b591a865 guile: fix make-value with pointer type
Calling the `make-value' procedure with an integer value and a pointer
type for the #:type argument triggers a failed assertion in
`get_unsigned_type_max', as that function doesn't consider pointers to
be an unsigned type. This commit fixes the issue by adding a separate
code path for pointers.

As previously suggested, range checking is done using a new helper
function in gdbtypes.

gdb/ChangeLog:

2021-07-30  George Barrett  <bob@bob131.so>

	* gdbtypes.h (get_pointer_type_max): Add declaration.
	* gdbtypes.c (get_pointer_type_max): Add definition for new
	helper function.
	* guile/scm-math.c (vlscm_convert_typed_number): Add code path
	for handling conversions to pointer types without failing an
	assert.

gdb/testsuite/ChangeLog:

2021-07-30  George Barrett  <bob@bob131.so>

	* gdb.guile/scm-math.exp (test_value_numeric_ops): Add test
	for creating pointers with make-value.
	(test_make_pointer_value, test_pointer_numeric_range): Add
	test procedures containing checks for integer-to-pointer
	validation.

Change-Id: I9994dd1c848840a3d995f745e6d72867732049f0
2021-07-29 12:55:16 -04:00
George Barrett
c3c1e6459f gdbtypes: return value from get_unsigned_type_max
Changes the signature of get_unsigned_type_max to return the computed
value rather than returning void and writing the value into a pointer
passed by the caller.

gdb/ChangeLog:

2021-07-30  George Barrett  <bob@bob131.so>

	* gdbtypes.h (get_unsigned_type_max): Change signature to
	return the result instead of accepting a pointer argument in
	which to store the result.
	* gdbtypes.c (get_unsigned_type_max): Likewise.
	* guile/scm-math.c (vlscm_convert_typed_number): Update caller
	of get_unsigned_type_max.
	(vlscm_integer_fits_p): Likewise.

Change-Id: Ibb1bf0c0fa181fac7853147dfde082a7d1ae2323
2021-07-29 12:54:14 -04:00
Tom Tromey
cc9d6997a5 Fix array stride bug
Investigation of using the Python API with an Ada program showed that
an array of dynamic types was not being handled properly.  I tracked
this down to an oddity of how array strides are handled.

In gdb, an array stride can be attached to the range type, via the
range_bounds object.  However, the stride can also be put into the
array's first field.  From create_range_type_with_stride:

  else if (bit_stride > 0)
    TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride;

It's hard to be sure why this is done, but I would guess a combination
of historical reasons plus a desire (mentioned in a comment somewhere)
to avoid modifying the range type.

This patch fixes the problem by changing type::bit_stride to
understand this convention.  It also fixes one spot that reproduces
this logic.

Regression tested on x86-64 Fedora 32.
2021-07-16 08:23:47 -06:00
Tom Tromey
386de171cb Add PROP_VARIABLE_NAME
With -fgnat-encodings=minimal, an internal version (these patches will
be upstreamed in the near future) of the Ada compiler can emit DWARF
for an array where the bound comes from a variable, like:

 <1><12a7>: Abbrev Number: 7 (DW_TAG_array_type)
    <12a8>   DW_AT_name        : (indirect string, offset: 0x1ae9): pck__my_array
[...]
 <2><12b4>: Abbrev Number: 8 (DW_TAG_subrange_type)
    <12b5>   DW_AT_type        : <0x1294>
    <12b9>   DW_AT_upper_bound : <0x1277>

With the upper bound DIE being:

 <1><1277>: Abbrev Number: 2 (DW_TAG_variable)
    <1278>   DW_AT_name        : (indirect string, offset: 0x1a4d): pck__my_length___U
    <127c>   DW_AT_type        : <0x128f>
    <1280>   DW_AT_external    : 1
    <1280>   DW_AT_artificial  : 1
    <1280>   DW_AT_declaration : 1

Note that the variable is just a declaration -- in this situation, the
variable comes from another compilation unit, and must be found when
trying to compute the array bound.

This patch adds a new PROP_VARIABLE_NAME kind, to enable this search.

This same scenario can occur with DW_OP_GNU_variable_value, so this
patch adds support for that as well.

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

	* dwarf2/read.h (dwarf2_fetch_die_type_sect_off): Add 'var_name'
	parameter.
	* dwarf2/loc.c (dwarf2_evaluate_property) <case
	PROP_VARIABLE_NAME>: New case.
	(compute_var_value): New function.
	(sect_variable_value): Use compute_var_value.
	* dwarf2/read.c (attr_to_dynamic_prop): Handle DW_TAG_variable.
	(var_decl_name): New function.
	(dwarf2_fetch_die_type_sect_off): Add 'var_name' parameter.
	* gdbtypes.h (enum dynamic_prop_kind) <PROP_VARIABLE_NAME>: New
	constant.
	(union dynamic_prop_data) <variable_name>: New member.
	(struct dynamic_prop) <variable_name, set_variable_name>: New
	methods.

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

	* gdb.ada/array_of_symbolic_length.exp: New file.
	* gdb.ada/array_of_symbolic_length/foo.adb: New file.
	* gdb.ada/array_of_symbolic_length/gl.adb: New file.
	* gdb.ada/array_of_symbolic_length/gl.ads: New file.
	* gdb.ada/array_of_symbolic_length/pck.adb: New file.
	* gdb.ada/array_of_symbolic_length/pck.ads: New file.
2021-06-04 13:51:23 -06:00