This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 0/2] Aarch64: Fix segfault when casting dummy calls


This is a reworking of a patch I posted in March.
V1 had a long discussion which was then paused to wait for
Pedro's IFUNC rewrite.


Prevent the int cast in the following causing a segfault on aarch64:
(gdb) b foo if (int)strcmp(name,"abc") == 0
(gdb) run


This is because to aarch64_push_dummy_call determines the return type
of the function and then does not check for null pointer.

A null pointer for the return type means either 1) the call has a
cast or 2) an error has occured.
You can see this in infcall.c:call_function_by_hand_dummy():

  CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype);

  if (values_type == NULL)
    values_type = default_return_type;
  if (values_type == NULL)
    {
      const char *name = get_function_name (funaddr,
					    name_buf, sizeof (name_buf));
      error (_("'%s' has unknown return type; "
	       "cast the call to its declared return type"),
	     name);
    }

In aarch64_push_dummy_call we do not have default_return_type, so cannot
determine between the two cases.

(In addition, aarch64_push_dummy_call incorrectly resolves the return
type for IFUNC).


However, aarch64_push_dummy_call only requires the return value in order
to calculate lang_struct_return ... which has previously been calculated
in the caller:

     This is slightly awkward, ideally the flag "lang_struct_return"
     would be passed to the targets implementation of push_dummy_call.
     Rather that change the target interface we call the language code
     directly ourselves.

The fix is simple:
Patch 1: Update gdbarch interface to pass lang_struct_return.
Patch 2: Remove incorrect code and use the passed in lang_struct_return.

Built on x86 target all build and tested on aarch64.



Alan Hayward (2):
  Add lang_struct_return to _push_dummy_call
  Aarch64: Fix segfault when casting dummy calls

 gdb/aarch64-tdep.c                            | 29 +-----
 gdb/alpha-tdep.c                              |  3 +-
 gdb/amd64-tdep.c                              |  3 +-
 gdb/amd64-windows-tdep.c                      |  3 +-
 gdb/arc-tdep.c                                |  2 +-
 gdb/arm-tdep.c                                |  2 +-
 gdb/avr-tdep.c                                |  3 +-
 gdb/bfin-tdep.c                               |  1 +
 gdb/cris-tdep.c                               |  3 +-
 gdb/csky-tdep.c                               |  3 +-
 gdb/frv-tdep.c                                |  3 +-
 gdb/gdbarch.c                                 |  4 +-
 gdb/gdbarch.h                                 |  4 +-
 gdb/gdbarch.sh                                |  2 +-
 gdb/h8300-tdep.c                              |  3 +-
 gdb/hppa-tdep.c                               |  6 +-
 gdb/i386-darwin-tdep.c                        |  3 +-
 gdb/i386-tdep.c                               |  2 +-
 gdb/ia64-tdep.c                               |  3 +-
 gdb/infcall.c                                 |  3 +-
 gdb/iq2000-tdep.c                             |  3 +-
 gdb/lm32-tdep.c                               |  3 +-
 gdb/m32c-tdep.c                               |  2 +-
 gdb/m32r-tdep.c                               |  2 +-
 gdb/m68hc11-tdep.c                            |  3 +-
 gdb/m68k-tdep.c                               |  2 +-
 gdb/mep-tdep.c                                |  2 +-
 gdb/mips-tdep.c                               | 15 +--
 gdb/mn10300-tdep.c                            |  1 +
 gdb/msp430-tdep.c                             |  3 +-
 gdb/nds32-tdep.c                              |  3 +-
 gdb/nios2-tdep.c                              |  3 +-
 gdb/or1k-tdep.c                               |  3 +-
 gdb/ppc-sysv-tdep.c                           |  6 +-
 gdb/ppc-tdep.h                                |  2 +
 gdb/riscv-tdep.c                              |  1 +
 gdb/rl78-tdep.c                               |  3 +-
 gdb/rs6000-aix-tdep.c                         |  3 +-
 gdb/rs6000-lynx178-tdep.c                     |  3 +-
 gdb/rx-tdep.c                                 |  2 +-
 gdb/s390-tdep.c                               |  3 +-
 gdb/score-tdep.c                              |  3 +-
 gdb/sh-tdep.c                                 |  2 +
 gdb/sparc-tdep.c                              |  3 +-
 gdb/sparc64-tdep.c                            |  3 +-
 gdb/spu-tdep.c                                |  3 +-
 gdb/testsuite/gdb.base/condbreak-solib-lib.cc | 21 +++++
 .../gdb.base/condbreak-solib-main.cc          | 33 +++++++
 gdb/testsuite/gdb.base/condbreak-solib.exp    | 93 +++++++++++++++++++
 gdb/tic6x-tdep.c                              |  3 +-
 gdb/tilegx-tdep.c                             |  1 +
 gdb/v850-tdep.c                               |  1 +
 gdb/vax-tdep.c                                |  2 +-
 gdb/xstormy16-tdep.c                          |  1 +
 gdb/xtensa-tdep.c                             |  1 +
 55 files changed, 246 insertions(+), 77 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/condbreak-solib-lib.cc
 create mode 100644 gdb/testsuite/gdb.base/condbreak-solib-main.cc
 create mode 100644 gdb/testsuite/gdb.base/condbreak-solib.exp

-- 
2.17.1 (Apple Git-112)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]