From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83703 invoked by alias); 21 Sep 2015 14:55:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 83617 invoked by uid 89); 21 Sep 2015 14:55:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,KAM_STOCKGEN,RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 21 Sep 2015 14:55:05 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 21 Sep 2015 07:54:47 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 21 Sep 2015 07:54:46 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t8LEsjHL014484; Mon, 21 Sep 2015 15:54:45 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id t8LEsjSv010506; Mon, 21 Sep 2015 16:54:45 +0200 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id t8LEsjM6010502; Mon, 21 Sep 2015 16:54:45 +0200 From: Markus Metzger 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 Message-Id: <1442847283-10200-6-git-send-email-markus.t.metzger@intel.com> In-Reply-To: <1442847283-10200-1-git-send-email-markus.t.metzger@intel.com> References: <1442847283-10200-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00509.txt.bz2 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 * 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