From: Tom Tromey Date: Fri, 19 Nov 2021 15:02:38 +0000 (-0700) Subject: Constify chain_candidate X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=394d8c59ea961e1dcf89ec6c8b6d6606b361590a;p=binutils-gdb.git Constify chain_candidate 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. --- diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index acb7b863145..addf611d8f8 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 *resultp, - std::vector *chain) + const std::vector &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;