public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Carl Love <carll@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Bug fix in commit for printing the function return value for non-trivial values
Date: Wed, 16 Nov 2022 16:12:14 +0000 (GMT)	[thread overview]
Message-ID: <20221116161214.5DB59395B43D@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d2bbd19d8e16370ebb853e2bf436e5b282177830

commit d2bbd19d8e16370ebb853e2bf436e5b282177830
Author: Carl Love <cel@us.ibm.com>
Date:   Tue Nov 15 10:57:32 2022 -0600

    Bug fix in commit for printing the function return value for non-trivial values
    
    The recent commit:
    
      commit a0eda3df5b750ae32576a9be092b361281a41787
      Author: Carl Love <cel@us.ibm.com>
      Date:   Mon Nov 14 16:22:37 2022 -0500
    
        PowerPC, fix support for printing the function return value for non-trivial values.
    
    Is generating a segmentation fault on x86_64-linux.
    
      segfault:
      ...
      PASS: gdb.asm/asm-source.exp: info source asmsrc1.s
      ERROR: GDB process no longer exists
      UNRESOLVED: gdb.asm/asm-source.exp: finish from foo3
      ...
    
      Reproduced on command line:
      ...
      $ gdb -q -batch -x outputs/gdb.asm/asm-source/gdb.in.1
      ...
    
      The problem seems to be that:
      ...
      Thread 1 "gdb" received signal SIGSEGV, Segmentation fault.
      0x000000000043de7a in symbol::type (this=0x0) at
      .../gdb_versions/devel/src/gdb/symtab.h:1287
      1287        return m_type;
      ...
      because:
      ...
      (gdb) up
      #1  0x0000000000852d94 in finish_command (arg=0x0, from_tty=0)
         at .../gdb_versions/devel/src/gdb/infcmd.c:1887
      1887        = check_typedef (sm->function->type ()->target_type ());
      (gdb) p sm->function
      $1 = (symbol *) 0x0
    
    The code is not checking if sm->function is NULL.  If sm->function is NULL
    the check for the return buffer should be skipped.

Diff:
---
 gdb/infcmd.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index b71dc10370b..a72df2d6a01 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1877,26 +1877,28 @@ finish_command (const char *arg, int from_tty)
   /* Find the function we will return from.  */
   frame_info_ptr callee_frame = get_selected_frame (NULL);
   sm->function = find_pc_function (get_frame_pc (callee_frame));
+  sm->return_buf = 0;    /* Initialize buffer address is not available.  */
 
   /* Determine the return convention.  If it is RETURN_VALUE_STRUCT_CONVENTION,
      attempt to determine the address of the return buffer.  */
-  enum return_value_convention return_value;
-  struct gdbarch *gdbarch = get_frame_arch (callee_frame);
+  if (sm->function != NULL)
+    {
+      enum return_value_convention return_value;
+      struct gdbarch *gdbarch = get_frame_arch (callee_frame);
 
-  struct type * val_type
-    = check_typedef (sm->function->type ()->target_type ());
+      struct type * val_type
+	= check_typedef (sm->function->type ()->target_type ());
 
-  return_value = gdbarch_return_value (gdbarch,
-				       read_var_value (sm->function, NULL,
-						       callee_frame),
-				       val_type, NULL, NULL, NULL);
+      return_value = gdbarch_return_value (gdbarch,
+					   read_var_value (sm->function, NULL,
+							   callee_frame),
+					   val_type, NULL, NULL, NULL);
 
-  if (return_value == RETURN_VALUE_STRUCT_CONVENTION
-      && val_type->code () != TYPE_CODE_VOID)
-    sm->return_buf = gdbarch_get_return_buf_addr (gdbarch, val_type,
-						  callee_frame);
-  else
-    sm->return_buf = 0;
+      if (return_value == RETURN_VALUE_STRUCT_CONVENTION
+	  && val_type->code () != TYPE_CODE_VOID)
+	sm->return_buf = gdbarch_get_return_buf_addr (gdbarch, val_type,
+						      callee_frame);
+    }
 
   /* Print info on the selected frame, including level number but not
      source.  */

                 reply	other threads:[~2022-11-16 16:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221116161214.5DB59395B43D@sourceware.org \
    --to=carll@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).