From patchwork Sun Aug 30 11:48:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 8518 Received: (qmail 60155 invoked by alias); 30 Aug 2015 11:48:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 60075 invoked by uid 89); 30 Aug 2015 11:48:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wi0-f169.google.com Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 30 Aug 2015 11:48:39 +0000 Received: by wicpl12 with SMTP id pl12so4939462wic.1 for ; Sun, 30 Aug 2015 04:48:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=WXtYXMGFMwyfxjrwi+hU6W+kCWx4yYOqglrnneXAMpc=; b=QIe3L9bAisLOg2aMusGFMJ+VGySMTrUYD0W/cU+sEMfMOzZsTFi/Z4H1AzXdBilbd6 J/JMseP3kr9DXsnh+V7cnqZra453+QlR4Jpu5pNtdErEymtSTra/LTLsrC+k3vwJ+awV Ib9X4e8trxFdhQ9SsXIhU58d70SnAKha7o8tAP2eRuG0w5/mdG4T1UDBaquYWtrfAi1f rGyvAkq704uQLj77jZiPWj43IE8pWash8K+Ljmfh9IVskhmChqk5LANkfPW8P215VlL8 8WJhgYJNkKUTqRzFtp4cT2rsQlfvvbsyAg33X4TUAcgo8uyRk1VrSLZ5BwP7PLrzrHer kv6g== X-Gm-Message-State: ALoCoQlc56CIO32g6yhXiKgUV2DrxZHG5+IYL+j5O0phTGtmTtxOWHQxDbHTxcCxjCeEX6lo27il X-Received: by 10.194.192.99 with SMTP id hf3mr20694313wjc.78.1440935316870; Sun, 30 Aug 2015 04:48:36 -0700 (PDT) Received: from localhost (host86-146-54-249.range86-146.btcentralplus.com. [86.146.54.249]) by smtp.gmail.com with ESMTPSA id fn8sm12859095wib.2.2015.08.30.04.48.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Aug 2015 04:48:36 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: Move common MI code to outer function. Date: Sun, 30 Aug 2015 12:48:31 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The disassembly code has a common entry function gdb_disassembly, and three handler functions which are called based on what type of disassembly we are performing. Each of the handler functions creates an MI list called asm_insns, which is required for the MI disassembly output. The commit moves the common asm_insns list to the outer level gdb_disassembly function, reducing duplicate code. gdb/ChangeLog: * disasm.c (do_mixed_source_and_assembly_deprecated): Remove asm_insns list. (do_mixed_source_and_assembly): Likewise. (do_assembly_only): Likewise. (gdb_disassembly): Create asm_insns list here. --- gdb/ChangeLog | 8 ++++++++ gdb/disasm.c | 22 ++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9dd591c..463b1b9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2015-08-30 Andrew Burgess + + * disasm.c (do_mixed_source_and_assembly_deprecated): Remove + asm_insns list. + (do_mixed_source_and_assembly): Likewise. + (do_assembly_only): Likewise. + (gdb_disassembly): Create asm_insns list here. + 2015-08-29 Doug Evans * symtab.h (struct symbol): Tweak comment. diff --git a/gdb/disasm.c b/gdb/disasm.c index 2b65c6a..3032090 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -291,7 +291,6 @@ do_mixed_source_and_assembly_deprecated int next_line = 0; int num_displayed = 0; enum print_source_lines_flags psl_flags = 0; - struct cleanup *ui_out_chain; struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0); struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0); @@ -355,8 +354,6 @@ do_mixed_source_and_assembly_deprecated they have been emitted before), followed by the assembly code for that line. */ - ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns"); - for (i = 0; i < newlines; i++) { /* Print out everything from next_line to the current line. */ @@ -429,7 +426,6 @@ do_mixed_source_and_assembly_deprecated if (how_many >= 0 && num_displayed >= how_many) break; } - do_cleanups (ui_out_chain); } /* The idea here is to present a source-O-centric view of a @@ -453,7 +449,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, int num_displayed = 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; CORE_ADDR pc; @@ -509,7 +504,8 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, 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". + name "src_and_asm_line". The outer "asm_insns" list is created in + the outer function gdb_disassembly. Each element is a tuple of source line specs (field names line, file, fullname), and field "line_asm_insn" which contains the disassembly. Field "line_asm_insn" is a list of tuples: address, func-name, offset, @@ -522,8 +518,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, 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 The tuples for each group of consecutive disassemblies. ui_out_list_chain @@ -532,8 +526,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, if (flags & DISASSEMBLY_FILENAME) psl_flags |= PRINT_SOURCE_LINES_FILENAME; - ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns"); - ui_out_tuple_chain = NULL; ui_out_list_chain = NULL; @@ -683,7 +675,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout, last_line = sal.line; } - do_cleanups (ui_out_chain); do_cleanups (cleanups); } @@ -694,14 +685,9 @@ do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout, int how_many, int flags, struct ui_file *stb) { int num_displayed = 0; - struct cleanup *ui_out_chain; - - ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns"); num_displayed = dump_insns (gdbarch, uiout, di, low, high, how_many, flags, stb, NULL); - - do_cleanups (ui_out_chain); } /* Initialize the disassemble info struct ready for the specified @@ -764,6 +750,10 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout, if (symtab != NULL && SYMTAB_LINETABLE (symtab) != NULL) nlines = SYMTAB_LINETABLE (symtab)->nitems; + /* This cleanup is inner to CLEANUPS, so we don't need a separate + variable to track it. */ + (void) make_cleanup_ui_out_list_begin_end (uiout, "asm_insns"); + if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE)) || nlines <= 0) do_assembly_only (gdbarch, uiout, &di, low, high, how_many, flags, stb);