[PATCH 1/2] gdb/buildsym: Line record use a record flag
Lancelot SIX
lancelot.six@amd.com
Fri Mar 18 14:27:32 GMT 2022
Currently when recording a line entry (with
buildsym_compunit::record_line), a boolean argument argument is used
indicate that the is_stmt flag should be se for this particular record.
A later commit will add support for new flags to associate with line
table entries. Instead of adding a parameter to record_line for each
possible flag, transform the current is_stmt parameter into a enum flag
which fill support all required flags.
This enum flags type is not propagated into the linetable_entry type as
this would require a lot of changes across the codebase for no practical
gain (it currently uses a bitfield where each interesting flag only
occupy 1 bit in the structure).
Tested on x86_64-linux, no regression observed.
Change-Id: I5d061fa67bdb34918742505ff983d37453839d6a
---
gdb/buildsym-legacy.c | 2 +-
gdb/buildsym.c | 4 ++--
gdb/buildsym.h | 11 ++++++++++-
gdb/dwarf2/read.c | 37 ++++++++++++++++++++++---------------
4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c
index 7659f53cbe0..53cd3bd865b 100644
--- a/gdb/buildsym-legacy.c
+++ b/gdb/buildsym-legacy.c
@@ -254,7 +254,7 @@ record_line (struct subfile *subfile, int line, CORE_ADDR pc)
gdb_assert (buildsym_compunit != nullptr);
/* Assume every line entry is a statement start, that is a good place to
put a breakpoint for that line number. */
- buildsym_compunit->record_line (subfile, line, pc, true);
+ buildsym_compunit->record_line (subfile, line, pc, LEF_IS_STMT);
}
/* Start a new symtab for a new source file in OBJFILE. Called, for example,
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 999f632f401..a875eb5ce38 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -667,7 +667,7 @@ buildsym_compunit::pop_subfile ()
void
buildsym_compunit::record_line (struct subfile *subfile, int line,
- CORE_ADDR pc, bool is_stmt)
+ CORE_ADDR pc, linetable_entry_flags flags)
{
struct linetable_entry *e;
@@ -723,7 +723,7 @@ buildsym_compunit::record_line (struct subfile *subfile, int line,
e = subfile->line_vector->item + subfile->line_vector->nitems++;
e->line = line;
- e->is_stmt = is_stmt ? 1 : 0;
+ e->is_stmt = (flags & LEF_IS_STMT) != 0;
e->pc = pc;
}
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index 003d8a59719..09c2d563ec9 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -110,6 +110,15 @@ struct context_stack
};
+/* Flags associated with a linetable entry. */
+
+enum linetable_entry_flag : unsigned
+{
+ LEF_IS_STMT = 1 << 1,
+};
+DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
+
+
/* Buildsym's counterpart to struct compunit_symtab. */
struct buildsym_compunit
@@ -188,7 +197,7 @@ struct buildsym_compunit
const char *pop_subfile ();
void record_line (struct subfile *subfile, int line, CORE_ADDR pc,
- bool is_stmt);
+ linetable_entry_flags flags);
struct compunit_symtab *get_compunit_symtab ()
{
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 10550336063..e470fc6fd5d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20883,7 +20883,7 @@ class lnp_state_machine
/* Handle DW_LNS_negate_stmt. */
void handle_negate_stmt ()
{
- m_is_stmt = !m_is_stmt;
+ m_flags ^= LEF_IS_STMT;
}
/* Handle DW_LNS_const_add_pc. */
@@ -20942,7 +20942,7 @@ class lnp_state_machine
/* These are initialized in the constructor. */
CORE_ADDR m_address;
- bool m_is_stmt;
+ linetable_entry_flags m_flags;
unsigned int m_discriminator;
/* Additional bits of state we need to track. */
@@ -20957,9 +20957,9 @@ class lnp_state_machine
CORE_ADDR m_last_address;
/* Set to true when a previous line at the same address (using
- m_last_address) had m_is_stmt true. This is reset to false when a
- line entry at a new address (m_address different to m_last_address) is
- processed. */
+ m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false
+ when a line entry at a new address (m_address different to
+ m_last_address) is processed. */
bool m_stmt_at_address = false;
/* When true, record the lines we decode. */
@@ -21089,7 +21089,8 @@ dwarf_record_line_p (struct dwarf2_cu *cu,
static void
dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
- unsigned int line, CORE_ADDR address, bool is_stmt,
+ unsigned int line, CORE_ADDR address,
+ linetable_entry_flags flags,
struct dwarf2_cu *cu)
{
CORE_ADDR addr = gdbarch_addr_bits_remove (gdbarch, address);
@@ -21103,7 +21104,7 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile,
}
if (cu != nullptr)
- cu->get_builder ()->record_line (subfile, line, addr, is_stmt);
+ cu->get_builder ()->record_line (subfile, line, addr, flags);
}
/* Subroutine of dwarf_decode_lines_1 to simplify it.
@@ -21126,7 +21127,7 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
paddress (gdbarch, address));
}
- dwarf_record_line_1 (gdbarch, subfile, 0, address, true, cu);
+ dwarf_record_line_1 (gdbarch, subfile, 0, address, LEF_IS_STMT, cu);
}
void
@@ -21139,7 +21140,8 @@ lnp_state_machine::record_line (bool end_sequence)
" address %s, is_stmt %u, discrim %u%s\n",
m_line, m_file,
paddress (m_gdbarch, m_address),
- m_is_stmt, m_discriminator,
+ (m_flags & LEF_IS_STMT) != 0,
+ m_discriminator,
(end_sequence ? "\t(end sequence)" : ""));
}
@@ -21174,7 +21176,8 @@ lnp_state_machine::record_line (bool end_sequence)
= m_last_subfile != m_cu->get_builder ()->get_current_subfile ();
bool ignore_this_line
= ((file_changed && !end_sequence && m_last_address == m_address
- && !m_is_stmt && m_stmt_at_address)
+ && ((m_flags & LEF_IS_STMT) == 0)
+ && m_stmt_at_address)
|| (!end_sequence && m_line == 0));
if ((file_changed && !ignore_this_line) || end_sequence)
@@ -21185,7 +21188,9 @@ lnp_state_machine::record_line (bool end_sequence)
if (!end_sequence && !ignore_this_line)
{
- bool is_stmt = producer_is_codewarrior (m_cu) || m_is_stmt;
+ linetable_entry_flags lte_flags = m_flags;
+ if (producer_is_codewarrior (m_cu))
+ lte_flags |= LEF_IS_STMT;
if (dwarf_record_line_p (m_cu, m_line, m_last_line,
m_line_has_non_zero_discriminator,
@@ -21194,7 +21199,7 @@ lnp_state_machine::record_line (bool end_sequence)
buildsym_compunit *builder = m_cu->get_builder ();
dwarf_record_line_1 (m_gdbarch,
builder->get_current_subfile (),
- m_line, m_address, is_stmt,
+ m_line, m_address, m_flags,
m_currently_recording_lines ? m_cu : nullptr);
}
m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
@@ -21203,14 +21208,14 @@ lnp_state_machine::record_line (bool end_sequence)
}
}
- /* Track whether we have seen any m_is_stmt true at m_address in case we
+ /* Track whether we have seen any IS_STMT true at m_address in case we
have multiple line table entries all at m_address. */
if (m_last_address != m_address)
{
m_stmt_at_address = false;
m_last_address = m_address;
}
- m_stmt_at_address |= m_is_stmt;
+ m_stmt_at_address |= (m_flags & LEF_IS_STMT) != 0;
}
lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
@@ -21228,7 +21233,9 @@ lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
and also record it in case it needs it. This is currently used by MIPS
code, cf. `mips_adjust_dwarf2_line'. */
m_address = gdbarch_adjust_dwarf2_line (arch, 0, 0);
- m_is_stmt = lh->default_is_stmt;
+ m_flags = 0;
+ if (lh->default_is_stmt)
+ m_flags |= LEF_IS_STMT;
m_discriminator = 0;
m_last_address = m_address;
--
2.25.1
More information about the Gdb-patches
mailing list