]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/gdbtypes.c
gdb: Respect the DW_CC_nocall attribute
authorLancelot SIX <lancelot.six@amd.com>
Mon, 17 Jan 2022 11:13:39 +0000 (06:13 -0500)
committerLancelot SIX <lancelot.six@amd.com>
Tue, 15 Feb 2022 09:52:37 +0000 (09:52 +0000)
commit0b35f123c200522998a81335dc218551ca7b3d92
tree9f964fa813c131514c01b362d233e2f5e1066207
parente6b3636709a19303859cb886f5212d5092837b27
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
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/infcall.c
gdb/infcmd.c
gdb/stack.c
gdb/testsuite/gdb.dwarf2/calling-convention.c [new file with mode: 0644]
gdb/testsuite/gdb.dwarf2/calling-convention.exp [new file with mode: 0644]