public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix crash in is_nocall_function
@ 2022-12-11 19:53 Tom Tromey
  2022-12-12  2:45 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2022-12-11 19:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29871
---
 gdb/gdbtypes.c                   | 4 ++--
 gdb/gdbtypes.h                   | 4 +---
 gdb/testsuite/gdb.base/exprs.exp | 4 ++++
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 2166257f71e..30dd7744553 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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;
 }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index d7189ff9813..8fc5c97c95a 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -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);
 
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index 5bf03bf1320..b8698880339 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -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"
-- 
2.38.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix crash in is_nocall_function
  2022-12-11 19:53 [PATCH] Fix crash in is_nocall_function Tom Tromey
@ 2022-12-12  2:45 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2022-12-12  2:45 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

> diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
> index 5bf03bf1320..b8698880339 100644
> --- a/gdb/testsuite/gdb.base/exprs.exp
> +++ b/gdb/testsuite/gdb.base/exprs.exp
> @@ -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"
To avoid the trailing parenthesis to be considered not in the test name,
either remove the space, or give an explicit name to the test.

Otherwise, LGTM:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-12  2:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-11 19:53 [PATCH] Fix crash in is_nocall_function Tom Tromey
2022-12-12  2:45 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).