public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCHv2 1/2] gdb: Split func_command into two parts.
Date: Tue, 08 May 2018 16:58:00 -0000	[thread overview]
Message-ID: <d34fc1596b3adba489de389eec14028982d85c40.1525797846.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1525797846.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1525797846.git.andrew.burgess@embecosm.com>

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);
-}
 \f
 /* 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<symtab_and_line> sals
-    = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
+    = decode_line_with_current_source (function_name,
+				       DECODE_LINE_FUNFIRSTLINE);
   gdb::def_vector<function_bounds> 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
-- 
2.14.3

  reply	other threads:[~2018-05-08 16:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 16:58 [PATCHv2 0/2] Changes to frame selection Andrew Burgess
2018-05-08 16:58 ` Andrew Burgess [this message]
2018-05-18 19:57   ` [PATCHv2 1/2] gdb: Split func_command into two parts Pedro Alves
2018-05-21 15:52     ` Andrew Burgess
2018-05-21 16:06       ` Pedro Alves
2018-05-08 16:59 ` [PATCHv2 2/2] gdb: Change how frames are selected for 'frame' and 'info frame' Andrew Burgess
2018-05-11 15:44   ` Eli Zaretskii
2018-05-21 12:16     ` Andrew Burgess
2018-05-21 17:46       ` Eli Zaretskii
2018-06-05 18:53         ` Andrew Burgess
2018-06-05 21:16           ` Philippe Waroquiers
2018-06-06  8:22             ` Andrew Burgess
2018-06-06 14:56               ` Eli Zaretskii
2018-06-07 16:19   ` [PATCHv3] " Andrew Burgess
2018-06-29 12:23     ` Andrew Burgess
2018-07-17 15:58     ` [PATCHv4] " Andrew Burgess
2018-07-23 20:46       ` Philippe Waroquiers
2018-07-25 18:14         ` Andrew Burgess
     [not found]           ` <cover.1534197765.git.andrew.burgess@embecosm.com>
2018-08-13 22:20             ` [PATCHv5_B 2/2] " Andrew Burgess
2018-08-13 22:20           ` [PATCHv5 0/2] " Andrew Burgess
2018-08-14 10:31             ` Philippe Waroquiers
2018-08-21 13:10               ` Joel Brobecker
2018-08-27 11:04             ` Andrew Burgess
2018-08-27 15:23               ` Eli Zaretskii
2018-08-28  8:43                 ` Andrew Burgess
2018-08-28  9:08                   ` Eli Zaretskii
2018-08-28 18:03                     ` [PATCHv6] " Andrew Burgess
2018-08-28 18:20                       ` Eli Zaretskii
2018-09-05  7:46                       ` PING: " Andrew Burgess
2018-09-13 18:02                       ` Pedro Alves
2018-09-18 23:01                         ` Andrew Burgess
2018-09-19 16:26                           ` Pedro Alves
2018-09-26 23:06                             ` Andrew Burgess
2018-09-27 20:58                               ` Pedro Alves
2018-08-13 22:20           ` [PATCHv5_A 1/2] " Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d34fc1596b3adba489de389eec14028982d85c40.1525797846.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).