From: Markus Metzger <markus.t.metzger@intel.com>
To: palves@redhat.com, dje@google.com
Cc: gdb-patches@sourceware.org
Subject: [PATCH 5/6] disasm: determine preceding lines independent of last_line
Date: Mon, 21 Sep 2015 14:55:00 -0000 [thread overview]
Message-ID: <1442847283-10200-6-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 check for source lines without code
between the last line that was printed and the next line to be printed.
We print those extra source lines before the line for the next instruction.
Since instructions can now be in any order, it is no longer guaranteed that
last_line corresponds to the previous instruction.
Change the boundary from last_line to the first line in the same function and
remove the first-line-to-be-printed check.
This will now print source lines without code also before the first
instruction.
2015-09-21 Markus Metzger <markus.t.metzger@intel.com>
* disasm.c: Include block.h
(first_line_in_pc_function): New.
(do_mixed_source_and_assembly): Search for lines without code until the
first line in the same function.
---
gdb/disasm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 56 insertions(+), 4 deletions(-)
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 32e4bc1..2503657 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -25,6 +25,7 @@
#include "gdbcore.h"
#include "dis-asm.h"
#include "source.h"
+#include "block.h"
/* Disassemble functions.
FIXME: We should get rid of all the duplicate code in gdb that does
@@ -63,6 +64,54 @@ line_has_code_p (struct symtab *symtab, int line)
return 0;
}
+/* Return the first line in the function that contains PC or zero if the line
+ can't be determined. */
+
+static int
+first_line_in_pc_function (struct symtab *symtab, CORE_ADDR pc)
+{
+ const struct symbol *sym;
+ const struct block *block;
+ struct linetable *ltable;
+ CORE_ADDR high, low;
+ int nlines, ix, first;
+
+ sym = find_pc_function (pc);
+ if (sym == NULL)
+ return 0;
+
+ block = SYMBOL_BLOCK_VALUE (sym);
+ if (block == NULL)
+ return 0;
+
+ ltable = SYMTAB_LINETABLE (symtab);
+ if (ltable == NULL)
+ return 0;
+
+ low = BLOCK_START (block);
+ high = BLOCK_END (block);
+ nlines = ltable->nitems;
+ first = INT_MAX;
+
+ /* Skip preceding functions. */
+ for (ix = 0; ix < nlines && ltable->item[ix].pc < low ; ++ix);
+
+ /* Determine the first line in the function PC range. */
+ for (; ix < nlines && ltable->item[ix].pc < high; ++ix)
+ {
+ int line = ltable->item[ix].line;
+
+ if (line != 0 && line < first)
+ first = line;
+ }
+
+ /* Return zero if we didn't find any line entry. */
+ if (first == INT_MAX)
+ first = 0;
+
+ return first;
+}
+
/* Like target_read_memory, but slightly different parameters. */
static int
dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
@@ -510,13 +559,16 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
/* Same source file as last time. */
if (sal.symtab != NULL)
{
- if (sal.line > last_line + 1 && last_line != 0)
+ int first_line;
+
+ /* Print preceding source lines not associated with code.
+ Restrict the search to the current function. */
+ first_line = first_line_in_pc_function (sal.symtab, insn->addr);
+ if (first_line > 0)
{
int l;
- /* Several preceding source lines. Print the trailing ones
- not associated with code that we'll print later. */
- for (l = sal.line - 1; l > last_line; --l)
+ for (l = sal.line - 1; l >= first_line; --l)
{
if (line_has_code_p (sal.symtab, l))
break;
--
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 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:54 ` [PATCH 1/6] disasm: change dump_insns to print a single instruction Markus Metzger
2015-09-21 14:55 ` Markus Metzger [this message]
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 ` [PATCH 4/6] disasm: use entire line table in line_has_code_p Markus Metzger
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-6-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