From patchwork Wed Jul 19 04:05:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhouyi Zhou X-Patchwork-Id: 21676 Received: (qmail 122456 invoked by alias); 19 Jul 2017 04:05:38 -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 122441 invoked by uid 89); 19 Jul 2017 04:05:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pf0-f193.google.com Received: from mail-pf0-f193.google.com (HELO mail-pf0-f193.google.com) (209.85.192.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jul 2017 04:05:35 +0000 Received: by mail-pf0-f193.google.com with SMTP id o88so4954308pfk.1 for ; Tue, 18 Jul 2017 21:05:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0FlkMOwc3OvG78AVHDvypEIpMu2CAgJShzPUlB3cILk=; b=Ggg88svU1y63Fm2uCQqtmGPiKJ2cmbTfeMAbUsk+1sAOgjBk87I//QeWPfkke6g3NO qKq8731fH/XHD4RlXKx/rLZ2UqnFYMmorHyGsYVZsPKNb32WVWkGYEZvgpYwEQf3dgnb WP8wqDQLDBze/7Y9j/EIq1YOyUGXMUZByYeFRZpzdhwYHnNvJHZlZcXSX034HvZUIDH8 DevGME2JIDCw55DRGsYeUj4pCI68mSS5LTzx9tV2ucVIA5ybPzd4WLROnwCFkxZH5R7f tw4z+VhPCl5uSRcaGMtW7nMixkDM5/BLvLDOQj9qbBJOu+zT5aMfk1cPo8xJV8sQz35S dgTQ== X-Gm-Message-State: AIVw110D+XwYS2LyzhP5yfymVScLX96WX0Nd17WDh3VZ3HZ8EyVw4v2x J8Y4YMDmzGvs6rio X-Received: by 10.99.106.1 with SMTP id f1mr964564pgc.139.1500437134109; Tue, 18 Jul 2017 21:05:34 -0700 (PDT) Received: from localhost.localdomain ([124.16.128.66]) by smtp.gmail.com with ESMTPSA id n90sm8111561pfk.105.2017.07.18.21.05.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 21:05:33 -0700 (PDT) From: Zhouyi Zhou To: gdb-patches@sourceware.org, palves@redhat.com Cc: Zhouyi Zhou Subject: [PATCH v1 1/1] list actual code around more than one locations Date: Wed, 19 Jul 2017 12:05:20 +0800 Message-Id: <1500437120-3473-1-git-send-email-zhouzhouyi@gmail.com> When debugging following C++ code: int bar() { return 0;} int bar(int) { return 0; } GDB behaves as: (gdb) list bar file: "overload.cc", line number: 1 file: "overload.cc", line number: 2 However, it would be better for gdb to list the actual code around those two locations, not just print the location. Under the mentorship of Pedro Alves, I modify the function list_command so that GDB behaves more instructive: (gdb) list bar file: "overload.cc", line number: 1 1 int bar() { return 0;} 2 int bar(int) { return 0; } file: "overload.cc", line number: 2 1 int bar() { return 0;} 2 int bar(int) { return 0; } Tested on x86-64 GNU/Linux. Signed-off-by: Zhouyi Zhou gdb/ChangeLog: 2017-07-19 Zhouyi Zhou * cli-cmds.c (list_commands): list actual code around more than one locations. --- gdb/cli/cli-cmds.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index af750d3..87a89e2 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -980,6 +980,7 @@ list_command (char *arg, int from_tty) if (!have_full_symbols () && !have_partial_symbols ()) error (_("No symbol table is loaded. Use the \"file\" command.")); + sals.nelts = 0; arg1 = arg; if (*arg1 == ',') dummy_beg = 1; @@ -996,15 +997,8 @@ list_command (char *arg, int from_tty) /* C++ */ return; } - if (sals.nelts > 1) - { - ambiguous_line_spec (&sals); - xfree (sals.sals); - return; - } sal = sals.sals[0]; - xfree (sals.sals); } /* Record whether the BEG arg is all digits. */ @@ -1017,6 +1011,12 @@ list_command (char *arg, int from_tty) if (*arg1 == ',') { no_end = 0; + if (sals.nelts > 1) + { + ambiguous_line_spec (&sals); + xfree (sals.sals); + return; + } arg1++; while (*arg1 == ' ' || *arg1 == '\t') arg1++; @@ -1035,11 +1035,17 @@ list_command (char *arg, int from_tty) filter_sals (&sals_end); if (sals_end.nelts == 0) - return; + { + if (sals.nelts) + xfree (sals.sals); + return; + } if (sals_end.nelts > 1) { ambiguous_line_spec (&sals_end); xfree (sals_end.sals); + if (sals.nelts) + xfree (sals.sals); return; } sal_end = sals_end.sals[0]; @@ -1106,13 +1112,37 @@ list_command (char *arg, int from_tty) else if (no_end) { int first_line = sal.line - get_lines_to_list () / 2; + int i; if (first_line < 1) first_line = 1; + + if (sals.nelts > 1) + { + printf_filtered (_("file: \"%s\", line number: %d\n"), + symtab_to_filename_for_display (sal.symtab), + sal.line); + } print_source_lines (sal.symtab, first_line, first_line + get_lines_to_list (), 0); + if (sals.nelts > 1) + { + for (i = 1; i < sals.nelts; i++) + { + sal = sals.sals[i]; + first_line = sal.line - get_lines_to_list () / 2; + if (first_line < 1) first_line = 1; + printf_filtered (_("file: \"%s\", line number: %d\n"), + symtab_to_filename_for_display (sal.symtab), + sal.line); + print_source_lines (sal.symtab, + first_line, + first_line + get_lines_to_list (), + 0); + } + } } else print_source_lines (sal.symtab, sal.line, @@ -1120,6 +1150,8 @@ list_command (char *arg, int from_tty) ? sal.line + get_lines_to_list () : sal_end.line + 1), 0); + if (sals.nelts) + xfree (sals.sals); } /* Subroutine of disassemble_command to simplify it.