From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84615 invoked by alias); 21 Sep 2015 14:55:17 -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 84544 invoked by uid 89); 21 Sep 2015 14:55:16 -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_05,KAM_LAZY_DOMAIN_SECURITY,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:08 +0000 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 21 Sep 2015 07:54:48 -0700 X-ExtLoop1: 1 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.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 t8LEsjlW014479; 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 t8LEsjWK010499; Mon, 21 Sep 2015 16:54:45 +0200 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with œ id t8LEsjwb010495; 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 4/6] disasm: use entire line table in line_has_code_p Date: Mon, 21 Sep 2015 14:55:00 -0000 Message-Id: <1442847283-10200-5-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/msg00511.txt.bz2 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 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