]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix crash in is_nocall_function
authorTom Tromey <tom@tromey.com>
Sun, 11 Dec 2022 19:48:07 +0000 (12:48 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 13 Dec 2022 04:38:01 +0000 (21:38 -0700)
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

gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/testsuite/gdb.base/exprs.exp

index 2166257f71e576007cb037a526e2cff0117e2a26..30dd7744553c810e8c0dbc034b689ebaaa8e9016 100644 (file)
@@ -4037,8 +4037,8 @@ type_byte_order (const struct type *type)
 bool
 is_nocall_function (const struct type *type)
 {
-  gdb_assert (type->code () == TYPE_CODE_FUNC
-             || type->code () == TYPE_CODE_METHOD);
+  if (type->code () != TYPE_CODE_FUNC && type->code () != TYPE_CODE_METHOD)
+    return false;
 
   return TYPE_CALLING_CONVENTION (type) == DW_CC_nocall;
 }
index d7189ff9813fae686e282c1614345b03246daa2b..8fc5c97c95aa7a9f546250f0891f543a5fb4af31 100644 (file)
@@ -2845,9 +2845,7 @@ extern unsigned int overload_debug;
    to call by the debugger.
 
    This usually indicates that the function does not follow the target's
-   standard calling convention.
-
-   The TYPE argument must be of code TYPE_CODE_FUNC or TYPE_CODE_METHOD.  */
+   standard calling convention.  */
 
 extern bool is_nocall_function (const struct type *type);
 
index 5bf03bf1320b574b890d2d94536935f63bc4c484..7037ef0cd898380473ca002a763e5afb47f6c91d 100644 (file)
@@ -271,3 +271,7 @@ gdb_test "print & (void) v_char" "value not located in memory."
 # Regression test for "&&".
 gdb_test "print null_t_struct && null_t_struct->v_int_member == 0" \
     " = 0"
+
+# Regression test for unusual function-call parse that caused a crash.
+gdb_test "print v_short++(97)" \
+    "cast the call to its declared return type"