From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com, dje@google.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH 4/6] disasm: use entire line table in line_has_code_p
Date: Mon, 21 Sep 2015 14:55:00 -0000 [thread overview]
Message-ID: <1442847283-10200-5-git-send-email-markus.t.metzger@intel.com> (raw)
In-Reply-To: <1442847283-10200-1-git-send-email-markus.t.metzger@intel.com>
In do_mixed_source_and_assembly, we first collect all line entries matching
the to-be-printed PC range. In a second pass, we use the collected lines to
determine whether there is code for a given source line.
Given a consecutive range of instructions, we are guaranteed to have seen
all the relevant code.
Given a vector of non-consecutive instructions, however, we have seen only
a fraction of the relevant code.
Change line_has_code_p to consider the entire line table. This obsoletes the
first pass. Remove it.
This will make the line-has-code check a lot more expensive. I don't think
that the slowdown will be noticeable on today's processors, though.
2015-09-21 Markus Metzger <markus.t.metzger@intel.com>
gdb/
* disasm.c (struct dis_line_entry, hash_dis_line_entry)
(eq_dis_line_entry, allocate_dis_line_table)
(maybe_add_dis_line_entry): Remove.
(line_has_code_p): Remove table parameter. Update users.
Use entire line table.
(do_mixed_source_and_assembly): Remove first pass.
---
gdb/disasm.c | 112 ++++++++---------------------------------------------------
1 file changed, 14 insertions(+), 98 deletions(-)
diff --git a/gdb/disasm.c b/gdb/disasm.c
index f30ef4a..32e4bc1 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -43,80 +43,24 @@ struct deprecated_dis_line_entry
CORE_ADDR end_pc;
};
-/* This Structure is used to store line number information.
- We need a different sort of line table from the normal one cuz we can't
- depend upon implicit line-end pc's for lines to do the
- reordering in this function. */
-
-struct dis_line_entry
-{
- struct symtab *symtab;
- int line;
-};
-
-/* Hash function for dis_line_entry. */
-
-static hashval_t
-hash_dis_line_entry (const void *item)
-{
- const struct dis_line_entry *dle = item;
-
- return htab_hash_pointer (dle->symtab) + dle->line;
-}
-
-/* Equal function for dis_line_entry. */
+/* Return non-zero if LINE appears in SYMTAB's line table. */
static int
-eq_dis_line_entry (const void *item_lhs, const void *item_rhs)
+line_has_code_p (struct symtab *symtab, int line)
{
- const struct dis_line_entry *lhs = item_lhs;
- const struct dis_line_entry *rhs = item_rhs;
-
- return (lhs->symtab == rhs->symtab
- && lhs->line == rhs->line);
-}
+ struct linetable *ltable;
+ int nlines, ix;
-/* Create the table to manage lines for mixed source/disassembly. */
+ ltable = SYMTAB_LINETABLE (symtab);
+ if (ltable == NULL)
+ return 0;
-static htab_t
-allocate_dis_line_table (void)
-{
- return htab_create_alloc (41,
- hash_dis_line_entry, eq_dis_line_entry,
- xfree, xcalloc, xfree);
-}
+ nlines = ltable->nitems;
+ for (ix = 0; ix < nlines; ++ix)
+ if (ltable->item[ix].line == line)
+ return 1;
-/* Add DLE to TABLE.
- Returns 1 if added, 0 if already present. */
-
-static void
-maybe_add_dis_line_entry (htab_t table, struct symtab *symtab, int line)
-{
- void **slot;
- struct dis_line_entry dle, *dlep;
-
- dle.symtab = symtab;
- dle.line = line;
- slot = htab_find_slot (table, &dle, INSERT);
- if (*slot == NULL)
- {
- dlep = XNEW (struct dis_line_entry);
- dlep->symtab = symtab;
- dlep->line = line;
- *slot = dlep;
- }
-}
-
-/* Return non-zero if SYMTAB, LINE are in TABLE. */
-
-static int
-line_has_code_p (htab_t table, struct symtab *symtab, int line)
-{
- struct dis_line_entry dle;
-
- dle.symtab = symtab;
- dle.line = line;
- return htab_find (table, &dle) != NULL;
+ return 0;
}
/* Like target_read_memory, but slightly different parameters. */
@@ -481,39 +425,15 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
int out_of_order = 0;
int next_line = 0;
enum print_source_lines_flags psl_flags = 0;
- struct cleanup *cleanups;
struct cleanup *ui_out_chain;
struct cleanup *ui_out_tuple_chain;
struct cleanup *ui_out_list_chain;
struct symtab *last_symtab;
int last_line;
- htab_t dis_line_table;
struct disas_insn *insn;
unsigned int ix;
- /* First pass: collect the list of all source files and lines.
- We do this so that we can only print lines containing code once.
- We try to print the source text leading up to the next instruction,
- but if that text is for code that will be disassembled later, then
- we'll want to defer printing it until later with its associated code. */
-
- dis_line_table = allocate_dis_line_table ();
- cleanups = make_cleanup_htab_delete (dis_line_table);
-
- /* Add lines for every PC value. */
- for (ix = 0; VEC_iterate (disas_insn_t, insns, ix, insn); ++ix)
- {
- struct symtab_and_line sal;
-
- sal = find_pc_line (insn->addr, 0);
-
- if (sal.symtab != NULL)
- maybe_add_dis_line_entry (dis_line_table, sal.symtab, sal.line);
- }
-
- /* Second pass: print the disassembly.
-
- Output format, from an MI perspective:
+ /* Output format, from an MI perspective:
The result is a ui_out list, field name "asm_insns", where elements have
name "src_and_asm_line".
Each element is a tuple of source line specs (field names line, file,
@@ -525,9 +445,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
which is where we put file name and source line contents output.
Cleanup usage:
- cleanups:
- For things created at the beginning of this function and need to be
- kept until the end of this function.
ui_out_chain
Handles the outer "asm_insns" list.
ui_out_tuple_chain
@@ -601,7 +518,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
not associated with code that we'll print later. */
for (l = sal.line - 1; l > last_line; --l)
{
- if (line_has_code_p (dis_line_table, sal.symtab, l))
+ if (line_has_code_p (sal.symtab, l))
break;
}
if (l < sal.line - 1)
@@ -691,7 +608,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
}
do_cleanups (ui_out_chain);
- do_cleanups (cleanups);
}
static void
--
1.8.3.1
next prev parent reply other threads:[~2015-09-21 14:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-21 14:55 [PATCH 0/6] disasm, record: fix "record instruction-history /m" Markus Metzger
2015-09-21 14:54 ` [PATCH 6/6] btrace: use gdb_disassembly_vec and new source interleaving method Markus Metzger
2015-09-21 21:48 ` Andrew Burgess
2015-09-22 6:18 ` Metzger, Markus T
2015-09-21 14:54 ` [PATCH 1/6] disasm: change dump_insns to print a single instruction Markus Metzger
2015-09-21 14:54 ` [PATCH 2/6] disasm: add struct disas_insn to describe to-be-disassembled instruction Markus Metzger
2015-10-09 12:51 ` Pedro Alves
2015-10-12 8:44 ` Metzger, Markus T
2015-10-20 11:29 ` Pedro Alves
2015-09-21 14:55 ` [PATCH 5/6] disasm: determine preceding lines independent of last_line Markus Metzger
2015-09-21 14:55 ` [PATCH 3/6] disas: add gdb_disassembly_vec Markus Metzger
2015-10-09 12:49 ` Pedro Alves
2015-10-09 13:17 ` Metzger, Markus T
2015-10-12 8:59 ` Andrew Burgess
2015-10-18 20:39 ` Doug Evans
2015-09-21 14:55 ` Markus Metzger [this message]
2015-10-12 14:19 ` [PATCH 0/6] disasm, record: fix "record instruction-history /m" Metzger, Markus T
2015-10-18 21:17 ` Doug Evans
2015-10-19 9:35 ` Metzger, Markus T
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=1442847283-10200-5-git-send-email-markus.t.metzger@intel.com \
--to=markus.t.metzger@intel.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
/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