public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lancelot.six@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <lsix@lancelotsix.com>, Lancelot SIX <lancelot.six@amd.com>
Subject: [PATCH v3 1/2] gdb: add a symbol* argument to get_return_value
Date: Wed, 2 Feb 2022 12:41:14 -0600	[thread overview]
Message-ID: <20220202184115.83396-2-lancelot.six@amd.com> (raw)
In-Reply-To: <20220202184115.83396-1-lancelot.six@amd.com>

Add an argument to the get_return_value function to indicate the symbol
of the function the debuggee is returning from.  This will be used by
the following patch.

No user visible change after this patch.

Tested on x86_64-linux.

Change-Id: Idf1279f1f7199f5022738a6679e0fa63fbd22edc
---
 gdb/infcmd.c                     |  5 +++--
 gdb/inferior.h                   |  3 ++-
 gdb/python/py-finishbreakpoint.c | 29 ++++++++++++++++++++---------
 3 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 994dd5b32a3..66667d67b21 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1410,7 +1410,8 @@ advance_command (const char *arg, int from_tty)
    right after an inferior call has finished.  */
 
 struct value *
-get_return_value (struct value *function, struct type *value_type)
+get_return_value (struct symbol *func_symbol, struct value *function,
+		  struct type *value_type)
 {
   regcache *stop_regs = get_current_regcache ();
   struct gdbarch *gdbarch = stop_regs->arch ();
@@ -1577,7 +1578,7 @@ finish_command_fsm::should_stop (struct thread_info *tp)
 	  struct value *func;
 
 	  func = read_var_value (function, NULL, get_current_frame ());
-	  rv->value = get_return_value (func, rv->type);
+	  rv->value = get_return_value (function, func, rv->type);
 	  if (rv->value != NULL)
 	    rv->value_history_index = record_latest_value (rv->value);
 	}
diff --git a/gdb/inferior.h b/gdb/inferior.h
index ec0fb6e8b16..5fdff0f9358 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -219,7 +219,8 @@ extern void detach_command (const char *, int);
 
 extern void notice_new_inferior (struct thread_info *, bool, int);
 
-extern struct value *get_return_value (struct value *function,
+extern struct value *get_return_value (struct symbol *func_symbol,
+				       struct value *function,
 				       struct type *value_type);
 
 /* Prepare for execution command.  TARGET is the target that will run
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 03bd4934506..a322918dfca 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -40,6 +40,8 @@ struct finish_breakpoint_object
 {
   /* gdb.Breakpoint base class.  */
   gdbpy_breakpoint_object py_bp;
+  /* gdb.Symbol object of the function finished by this breakpoint.  */
+  PyObject *func_symbol;
   /* gdb.Type object of the value return by the breakpointed function.
      May be NULL if no debug information was available or return type
      was VOID.  */
@@ -80,6 +82,7 @@ bpfinishpy_dealloc (PyObject *self)
   struct finish_breakpoint_object *self_bpfinish =
 	(struct finish_breakpoint_object *) self;
 
+  Py_XDECREF (self_bpfinish->func_symbol);
   Py_XDECREF (self_bpfinish->function_value);
   Py_XDECREF (self_bpfinish->return_type);
   Py_XDECREF (self_bpfinish->return_value);
@@ -104,11 +107,14 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
 
   try
     {
+      struct symbol *func_symbol =
+	symbol_object_to_symbol (self_finishbp->func_symbol);
       struct value *function =
 	value_object_to_value (self_finishbp->function_value);
       struct type *value_type =
 	type_object_to_type (self_finishbp->return_type);
-      struct value *ret = get_return_value (function, value_type);
+      struct value *ret =
+	get_return_value (func_symbol, function, value_type);
 
       if (ret)
 	{
@@ -165,7 +171,6 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   PyObject *internal = NULL;
   int internal_bp = 0;
   CORE_ADDR pc;
-  struct symbol *function;
 
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|OO", keywords,
 					&frame_obj, &internal))
@@ -239,16 +244,18 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
     }
 
   /* Find the function we will return from.  */
-  self_bpfinish->return_type = NULL;
-  self_bpfinish->function_value = NULL;
+  self_bpfinish->func_symbol = nullptr;
+  self_bpfinish->return_type = nullptr;
+  self_bpfinish->function_value = nullptr;
 
   try
     {
       if (get_frame_pc_if_available (frame, &pc))
 	{
-	  function = find_pc_function (pc);
-	  if (function != NULL)
+	  struct symbol *function = find_pc_function (pc);
+	  if (function != nullptr)
 	    {
+	      self_bpfinish->func_symbol = symbol_to_symbol_object (function);
 	      struct type *ret_type =
 		check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (function)));
 
@@ -274,14 +281,18 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	 remain NULL.  */
     }
 
-  if (self_bpfinish->return_type == NULL || self_bpfinish->function_value == NULL)
+  if (self_bpfinish->func_symbol == nullptr
+      || self_bpfinish->return_type == nullptr
+      || self_bpfinish->function_value == nullptr)
     {
       /* Won't be able to compute return value.  */
+      Py_XDECREF (self_bpfinish->func_symbol);
       Py_XDECREF (self_bpfinish->return_type);
       Py_XDECREF (self_bpfinish->function_value);
 
-      self_bpfinish->return_type = NULL;
-      self_bpfinish->function_value = NULL;
+      self_bpfinish->func_symbol = nullptr;
+      self_bpfinish->return_type = nullptr;
+      self_bpfinish->function_value = nullptr;
     }
 
   bppy_pending_object = &self_bpfinish->py_bp;
-- 
2.25.1


  reply	other threads:[~2022-02-02 18:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 18:41 [PATCH v3 0/2] Make GDB respect the DW_CC_nocall attribute Lancelot SIX
2022-02-02 18:41 ` Lancelot SIX [this message]
2022-02-02 21:01   ` [PATCH v3 1/2] gdb: add a symbol* argument to get_return_value Simon Marchi
2022-02-02 21:59     ` [PATCH v4] " Lancelot SIX
2022-02-03  1:03       ` Simon Marchi
2022-02-03 11:10         ` Six, Lancelot
2022-02-03 12:35           ` Simon Marchi
2022-02-03 15:46         ` Lancelot SIX
2022-02-03 18:28         ` [PATCH v5] " Lancelot SIX
2022-02-03 19:26           ` Simon Marchi
2022-02-03 22:34             ` Six, Lancelot
2022-02-02 18:41 ` [PATCH v3 2/2] gdb: Respect the DW_CC_nocall attribute Lancelot SIX
2022-02-08 14:27   ` Simon Marchi
2022-02-15 10:53     ` Lancelot SIX

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=20220202184115.83396-2-lancelot.six@amd.com \
    --to=lancelot.six@amd.com \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    /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).