From patchwork Tue May 8 16:58:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 27155 Received: (qmail 53233 invoked by alias); 8 May 2018 16:58:56 -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 50816 invoked by uid 89); 8 May 2018 16:58:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:74.125.82.67, H*RU:74.125.82.67 X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 May 2018 16:58:53 +0000 Received: by mail-wm0-f67.google.com with SMTP id l1-v6so22886724wmb.2 for ; Tue, 08 May 2018 09:58:52 -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:in-reply-to :references:in-reply-to:references; bh=WzzeTrOahhQc2KqcxHYhlgdj3PRPGJ1nHHDhKPq4h1o=; b=HTHAUCeVR2R/CkAdTr52ihfvsZ1HQfvuOElvyWhWIhFT6eJLoeGw9SfGHhwGEzE7XS Rt2heEAoiCrie9Jj4lWZyDc5o8G+wz/DiqFBaIngyWdjKfNZKanOZojZ94FYrOVKxSFC Psoxr5ZWh1kEu9lHu/XKilJqzthY2aNZdliRRgbXo3pW/QUtgzch+JuuglPHczQ0gzWS bBXb05Ar54RjO+MM285AgoC2tPSaplNKk3RazHkgl4uhkzMjHOtNIfzrKPJfToEYDPyA mMzhvfOd3QaZbPlpvESmWYNhIvsaPiXaEcU/2hSiHdqwRWIk/WziMrGG7ICvljaec3V2 EL/g== X-Gm-Message-State: ALKqPwf8n6OQ7Y2mCKIaYjjb7T9U/BEhzEVTYqD4mo9Ay/GSV2IGmSm9 9vbzZsJAsHEpxEEgdmqPWSoKo76I X-Google-Smtp-Source: AB8JxZowFwFloPSZO5tDUWNoryRpB1ERnelN/g3H5YfpQvDCt2tUNDVeCjw8PApUK6qWOzGxvU+9Kw== X-Received: by 10.28.22.140 with SMTP id 134mr3894785wmw.53.1525798730902; Tue, 08 May 2018 09:58:50 -0700 (PDT) Received: from localhost (host81-147-175-127.range81-147.btcentralplus.com. [81.147.175.127]) by smtp.gmail.com with ESMTPSA id t196-v6sm10091406wme.11.2018.05.08.09.58.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 May 2018 09:58:50 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 1/2] gdb: Split func_command into two parts. Date: Tue, 8 May 2018 17:58:44 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The func_command function is used to emulate the dbx 'func' command. However, finding a stack frame based on function name might be a useful feature, and so the core of func_command is now split out into a separate function. gdb/ChangeLog: * stack.c (select_and_print_frame): Delete. (func_command): Most content moved into new function find_frame_for_function, use new function, print result, add function comment. (find_frame_for_function): New function, now returns a result. --- gdb/ChangeLog | 8 ++++++++ gdb/stack.c | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/gdb/stack.c b/gdb/stack.c index ecf1ee83793..5e99a42053c 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2157,16 +2157,6 @@ info_args_command (const char *ignore, int from_tty) print_frame_arg_vars (get_selected_frame (_("No frame selected.")), gdb_stdout); } - -/* Select frame FRAME. Also print the stack frame and show the source - if this is the tui version. */ -static void -select_and_print_frame (struct frame_info *frame) -{ - select_frame (frame); - if (frame) - print_stack_frame (frame, 1, SRC_AND_LOC, 1); -} /* Return the symbol-block in which the selected frame is executing. Can return zero under various legitimate circumstances. @@ -2460,19 +2450,19 @@ struct function_bounds CORE_ADDR low, high; }; -static void -func_command (const char *arg, int from_tty) +static struct frame_info * +find_frame_for_function (const char *function_name) { struct frame_info *frame; int found = 0; int level = 1; - if (arg == NULL) - return; + gdb_assert (function_name != NULL); frame = get_current_frame (); std::vector sals - = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE); + = decode_line_with_current_source (function_name, + DECODE_LINE_FUNFIRSTLINE); gdb::def_vector func_bounds (sals.size ()); for (size_t i = 0; (i < sals.size () && !found); i++) { @@ -2501,9 +2491,29 @@ func_command (const char *arg, int from_tty) while (!found && level == 0); if (!found) - printf_filtered (_("'%s' not within current stack frame.\n"), arg); - else if (frame != get_selected_frame (NULL)) - select_and_print_frame (frame); + frame = NULL; + + return frame; +} + +/* Implements the dbx 'func' command. */ + +static void +func_command (const char *arg, int from_tty) +{ + struct frame_info *frame; + + if (arg == NULL) + return; + + frame = find_frame_for_function (arg); + if (frame == NULL) + error (_("'%s' not within current stack frame.\n"), arg); + if (frame != get_selected_frame (NULL)) + { + select_frame (frame); + print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); + } } void