Change call_site_target to use custom type and enum

call_site_target reuses field_loc_kind and field_location.  However,
it has never used the full range of the field_loc_kind enum.  In a
subsequent patch, I plan to add a new 'kind' here, so it seemed best
to avoid this reuse and instead introduce new types here.
This commit is contained in:
Tom Tromey
2021-11-18 11:25:29 -07:00
parent b8e92c571b
commit 7eb21cc702
2 changed files with 31 additions and 13 deletions

View File

@@ -643,7 +643,7 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
{ {
switch (call_site->target.loc_kind ()) switch (call_site->target.loc_kind ())
{ {
case FIELD_LOC_KIND_DWARF_BLOCK: case call_site_target::DWARF_BLOCK:
{ {
struct dwarf2_locexpr_baton *dwarf_block; struct dwarf2_locexpr_baton *dwarf_block;
struct value *val; struct value *val;
@@ -690,7 +690,7 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
return value_as_address (val); return value_as_address (val);
} }
case FIELD_LOC_KIND_PHYSNAME: case call_site_target::PHYSNAME:
{ {
const char *physname; const char *physname;
struct bound_minimal_symbol msym; struct bound_minimal_symbol msym;
@@ -713,7 +713,7 @@ call_site_to_target_addr (struct gdbarch *call_site_gdbarch,
return BMSYMBOL_VALUE_ADDRESS (msym); return BMSYMBOL_VALUE_ADDRESS (msym);
} }
case FIELD_LOC_KIND_PHYSADDR: case call_site_target::PHYSADDR:
{ {
dwarf2_per_objfile *per_objfile = call_site->per_objfile; dwarf2_per_objfile *per_objfile = call_site->per_objfile;
compunit_symtab *cust = per_objfile->get_symtab (call_site->per_cu); compunit_symtab *cust = per_objfile->get_symtab (call_site->per_cu);

View File

@@ -1824,52 +1824,70 @@ enum call_site_parameter_kind
struct call_site_target struct call_site_target
{ {
field_loc_kind loc_kind () const /* The kind of location held by this call site target. */
enum kind
{
/* An address. */
PHYSADDR,
/* A name. */
PHYSNAME,
/* A DWARF block. */
DWARF_BLOCK,
};
kind loc_kind () const
{ {
return m_loc_kind; return m_loc_kind;
} }
CORE_ADDR loc_physaddr () const CORE_ADDR loc_physaddr () const
{ {
gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSADDR); gdb_assert (m_loc_kind == PHYSADDR);
return m_loc.physaddr; return m_loc.physaddr;
} }
void set_loc_physaddr (CORE_ADDR physaddr) void set_loc_physaddr (CORE_ADDR physaddr)
{ {
m_loc_kind = FIELD_LOC_KIND_PHYSADDR; m_loc_kind = PHYSADDR;
m_loc.physaddr = physaddr; m_loc.physaddr = physaddr;
} }
const char *loc_physname () const const char *loc_physname () const
{ {
gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSNAME); gdb_assert (m_loc_kind == PHYSNAME);
return m_loc.physname; return m_loc.physname;
} }
void set_loc_physname (const char *physname) void set_loc_physname (const char *physname)
{ {
m_loc_kind = FIELD_LOC_KIND_PHYSNAME; m_loc_kind = PHYSNAME;
m_loc.physname = physname; m_loc.physname = physname;
} }
dwarf2_locexpr_baton *loc_dwarf_block () const dwarf2_locexpr_baton *loc_dwarf_block () const
{ {
gdb_assert (m_loc_kind == FIELD_LOC_KIND_DWARF_BLOCK); gdb_assert (m_loc_kind == DWARF_BLOCK);
return m_loc.dwarf_block; return m_loc.dwarf_block;
} }
void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block) void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block)
{ {
m_loc_kind = FIELD_LOC_KIND_DWARF_BLOCK; m_loc_kind = DWARF_BLOCK;
m_loc.dwarf_block = dwarf_block; m_loc.dwarf_block = dwarf_block;
} }
union field_location m_loc; union
{
/* Address. */
CORE_ADDR physaddr;
/* Mangled name. */
const char *physname;
/* DWARF block. */
struct dwarf2_locexpr_baton *dwarf_block;
} m_loc;
/* * Discriminant for union field_location. */ /* * Discriminant for union field_location. */
enum kind m_loc_kind;
ENUM_BITFIELD(field_loc_kind) m_loc_kind : 3;
}; };
union call_site_parameter_u union call_site_parameter_u