[PATCH 3/4] [gdb/symtab] Add call_site::pc ()

Tom de Vries via Gdb-patches
2021-10-01T12:34:43Z

From: Simon Marchi <simon.marchi@polymtl.ca>

Add member function call_site::pc () and update all uses.

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
---
gdb/dwarf2/frame-tailcall.c | 4 ++--
gdb/dwarf2/loc.c | 18 +++++++++---------
gdb/dwarf2/read.c | 2 +-
gdb/gdbtypes.c | 9 +++++++++
gdb/gdbtypes.h | 6 +++++-
5 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/gdb/dwarf2/frame-tailcall.c b/gdb/dwarf2/frame-tailcall.c
index f112b4ecca4..9fe498b0924 100644
--- a/gdb/dwarf2/frame-tailcall.c
+++ b/gdb/dwarf2/frame-tailcall.c
@@ -240,14 +240,14 @@ pretend_pc (struct frame_info *this_frame, struct tailcall_cache *cache)
gdb_assert (next_levels >= 0);

if (next_levels < chain->callees)
- return chain->call_site[chain->length - next_levels - 1]->pc;
+ return chain->call_site[chain->length - next_levels - 1]->pc ();
next_levels -= chain->callees;

/* Otherwise CHAIN->CALLEES are already covered by CHAIN->CALLERS. */
if (chain->callees != chain->length)
{
if (next_levels < chain->callers)
- return chain->call_site[chain->callers - next_levels - 1]->pc;
+ return chain->call_site[chain->callers - next_levels - 1]->pc ();
next_levels -= chain->callers;
}

diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 2322a01f396..27a1c97682a 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -654,10 +654,10 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
{
struct bound_minimal_symbol msym;

- msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
+ msym = lookup_minimal_symbol_by_pc (call_site->pc () - 1);
throw_error (NO_ENTRY_VALUE_ERROR,
_("DW_AT_call_target is not specified at %s in %s"),
- paddress (call_site_gdbarch, call_site->pc),
+ paddress (call_site_gdbarch, call_site->pc ()),
(msym.minsym == NULL ? "???"
: msym.minsym->print_name ()));

@@ -666,12 +666,12 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
{
struct bound_minimal_symbol msym;

- msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
+ msym = lookup_minimal_symbol_by_pc (call_site->pc () - 1);
throw_error (NO_ENTRY_VALUE_ERROR,
_("DW_AT_call_target DWARF block resolving "
"requires known frame which is currently not "
"available at %s in %s"),
- paddress (call_site_gdbarch, call_site->pc),
+ paddress (call_site_gdbarch, call_site->pc ()),
(msym.minsym == NULL ? "???"
: msym.minsym->print_name ()));

@@ -700,11 +700,11 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
msym = lookup_minimal_symbol (physname, NULL, NULL);
if (msym.minsym == NULL)
{
- msym = lookup_minimal_symbol_by_pc (call_site->pc - 1);
+ msym = lookup_minimal_symbol_by_pc (call_site->pc () - 1);
throw_error (NO_ENTRY_VALUE_ERROR,
_("Cannot find function \"%s\" for a call site target "
"at %s in %s"),
- physname, paddress (call_site_gdbarch, call_site->pc),
+ physname, paddress (call_site_gdbarch, call_site->pc ()),
(msym.minsym == NULL ? "???"
: msym.minsym->print_name ()));

@@ -810,7 +810,7 @@ func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
static void
tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
{
- CORE_ADDR addr = call_site->pc;
+ CORE_ADDR addr = call_site->pc ();
struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (addr - 1);

fprintf_unfiltered (gdb_stdlog, " %s(%s)", paddress (gdbarch, addr),
@@ -986,7 +986,7 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,

if (target_call_site)
{
- if (addr_hash.insert (target_call_site->pc).second)
+ if (addr_hash.insert (target_call_site->pc ()).second)
{
/* Successfully entered TARGET_CALL_SITE. */

@@ -1005,7 +1005,7 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
call_site = chain.back ();
chain.pop_back ();

- size_t removed = addr_hash.erase (call_site->pc);
+ size_t removed = addr_hash.erase (call_site->pc ());
gdb_assert (removed == 1);

target_call_site = call_site->tail_call_next;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ac8460df9a4..d0460674d10 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -13405,7 +13405,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
+ (sizeof (*call_site->parameter) * (nparams - 1))));
*slot = call_site;
memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter));
- call_site->pc = pc;
+ call_site->m_pc = pc;

if (dwarf2_flag_true_p (die, DW_AT_call_tail_call, cu)
|| dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu))
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index be7c74ac6cf..500488adece 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -37,6 +37,7 @@
#include "cp-support.h"
#include "bcache.h"
#include "dwarf2/loc.h"
+#include "dwarf2/read.h"
#include "gdbcore.h"
#include "floatformat.h"
#include "f-lang.h"
@@ -6309,6 +6310,14 @@ objfile_type (struct objfile *objfile)
return objfile_type;
}

+/* See gdbtypes.h. */
+
+CORE_ADDR
+call_site::pc () const
+{
+ return m_pc;
+}
+
void _initialize_gdbtypes ();
void
_initialize_gdbtypes ()
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 84b751e82e3..7a17005229e 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1783,9 +1783,13 @@ struct call_site_parameter

struct call_site
{
+ /* As m_pc. */
+
+ CORE_ADDR pc () const;
+
/* Address of the first instruction after this call. */

- CORE_ADDR pc;
+ CORE_ADDR m_pc;

/* * List successor with head in FUNC_TYPE.TAIL_CALL_LIST. */

--
2.26.2