public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 3/6] Constify chain_candidate
Date: Wed,  1 Dec 2021 15:04:29 -0700	[thread overview]
Message-ID: <20211201220432.4105152-4-tromey@adacore.com> (raw)
In-Reply-To: <20211201220432.4105152-1-tromey@adacore.com>

While investigating this bug, I wasn't sure if chain_candidate might
update 'chain'.  I changed it to accept a const reference, making it
clear that it cannot.  This simplifies the code a tiny bit as well.
---
 gdb/dwarf2/loc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 7a3fda5eac1..e793bbffd05 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -835,9 +835,9 @@ tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
 static void
 chain_candidate (struct gdbarch *gdbarch,
 		 gdb::unique_xmalloc_ptr<struct call_site_chain> *resultp,
-		 std::vector<struct call_site *> *chain)
+		 const std::vector<struct call_site *> &chain)
 {
-  long length = chain->size ();
+  long length = chain.size ();
   int callers, callees, idx;
 
   if (*resultp == NULL)
@@ -850,8 +850,8 @@ chain_candidate (struct gdbarch *gdbarch,
 		    + sizeof (*result->call_site) * (length - 1)));
       result->length = length;
       result->callers = result->callees = length;
-      if (!chain->empty ())
-	memcpy (result->call_site, chain->data (),
+      if (!chain.empty ())
+	memcpy (result->call_site, chain.data (),
 		sizeof (*result->call_site) * length);
       resultp->reset (result);
 
@@ -870,7 +870,7 @@ chain_candidate (struct gdbarch *gdbarch,
     {
       fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
       for (idx = 0; idx < length; idx++)
-	tailcall_dump (gdbarch, chain->at (idx));
+	tailcall_dump (gdbarch, chain[idx]);
       fputc_unfiltered ('\n', gdb_stdlog);
     }
 
@@ -878,7 +878,7 @@ chain_candidate (struct gdbarch *gdbarch,
 
   callers = std::min ((long) (*resultp)->callers, length);
   for (idx = 0; idx < callers; idx++)
-    if ((*resultp)->call_site[idx] != chain->at (idx))
+    if ((*resultp)->call_site[idx] != chain[idx])
       {
 	(*resultp)->callers = idx;
 	break;
@@ -889,7 +889,7 @@ chain_candidate (struct gdbarch *gdbarch,
   callees = std::min ((long) (*resultp)->callees, length);
   for (idx = 0; idx < callees; idx++)
     if ((*resultp)->call_site[(*resultp)->length - 1 - idx]
-	!= chain->at (length - 1 - idx))
+	!= chain[length - 1 - idx])
       {
 	(*resultp)->callees = idx;
 	break;
@@ -970,7 +970,7 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 
       if (target_func_addr == callee_pc)
 	{
-	  chain_candidate (gdbarch, &retval, &chain);
+	  chain_candidate (gdbarch, &retval, chain);
 	  if (retval == NULL)
 	    break;
 
-- 
2.31.1


  parent reply	other threads:[~2021-12-01 22:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-01 22:04 [PATCH 0/6] Handle split functions in call site chains Tom Tromey
2021-12-01 22:04 ` [PATCH 1/6] Change call_site_target to use custom type and enum Tom Tromey
2021-12-01 22:04 ` [PATCH 2/6] Make call_site_target members private Tom Tromey
2021-12-01 22:04 ` Tom Tromey [this message]
2021-12-01 22:04 ` [PATCH 4/6] Change call_site_find_chain_1 to work recursively Tom Tromey
2021-12-01 22:04 ` [PATCH 5/6] Change call_site_target to iterate over addresses Tom Tromey
2021-12-01 22:04 ` [PATCH 6/6] Handle multiple addresses in call_site_target Tom Tromey
2022-02-28 18:34 ` [PATCH 0/6] Handle split functions in call site chains Tom Tromey
2022-03-28 19:54   ` Tom Tromey

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=20211201220432.4105152-4-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@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).