Mirror of the gdb-patches mailing list
 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: [PATCH 8/9] gdb: Split func_command into two parts.
Date: Fri, 11 Sep 2015 18:50:00 -0000	[thread overview]
Message-ID: <d753c5eb4c1cb61ca0d8db8a5f75c0019c042abd.1441996064.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1441996064.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1441996064.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   | 49 ++++++++++++++++++++++++++++++++-----------------
 2 files changed, 40 insertions(+), 17 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d530d06..9da954d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2015-09-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* 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.
+
+2015-09-11  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* stack.c (parse_frame_specification): Remove message parameter,
 	replace with fixed string in function body, update function
 	comment.
diff --git a/gdb/stack.c b/gdb/stack.c
index 9cde1e5..71e171a 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2211,15 +2211,6 @@ args_info (char *ignore, int from_tty)
 			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.
@@ -2507,8 +2498,11 @@ struct function_bounds
   CORE_ADDR low, high;
 };
 
-static void
-func_command (char *arg, int from_tty)
+/* Find stack frame for a function matching FUNCTION_NAME.  If there is no
+   matching stack frame then return NULL.  */
+
+static struct frame_info *
+find_frame_for_function (char *function_name)
 {
   struct frame_info *frame;
   int found = 0;
@@ -2518,11 +2512,11 @@ func_command (char *arg, int from_tty)
   struct function_bounds *func_bounds = NULL;
   struct cleanup *cleanups;
 
-  if (arg == NULL)
-    return;
+  gdb_assert (function_name != NULL);
 
   frame = get_current_frame ();
-  sals = decode_line_with_current_source (arg, DECODE_LINE_FUNFIRSTLINE);
+  sals = decode_line_with_current_source (function_name,
+					  DECODE_LINE_FUNFIRSTLINE);
   cleanups = make_cleanup (xfree, sals.sals);
   func_bounds = XNEWVEC (struct function_bounds, sals.nelts);
   make_cleanup (xfree, func_bounds);
@@ -2555,10 +2549,31 @@ func_command (char *arg, int from_tty)
   do_cleanups (cleanups);
 
   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 (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);
+    }
+}
+
 \f
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */
-- 
2.5.1


  parent reply	other threads:[~2015-09-11 18:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11 18:49 [PATCH 0/9] Changes to frame selection Andrew Burgess
2015-09-11 18:49 ` [PATCH 2/9] gdb: Select a frame for frame_info Andrew Burgess
2015-09-11 18:50 ` [PATCH 7/9] gdb: Simplify parse_frame_specification Andrew Burgess
2015-09-30 13:50   ` Pedro Alves
2015-09-11 18:50 ` [PATCH 6/9] gdb: Avoid unneeded calls to parse_frame_specification Andrew Burgess
2015-09-30 13:48   ` Pedro Alves
2015-09-11 18:50 ` [PATCH 4/9] gdb/doc: Restructure frame command documentation Andrew Burgess
2015-09-11 20:17   ` Eli Zaretskii
2015-09-11 18:50 ` [PATCH 9/9] gdb: Change how frames are selected for 'frame' and 'info frame' Andrew Burgess
2015-09-11 20:21   ` Eli Zaretskii
2015-09-15 10:41     ` Andrew Burgess
2015-09-15 10:50       ` Eli Zaretskii
2015-09-17 11:36         ` Andrew Burgess
2015-09-30 14:00   ` Pedro Alves
2015-09-11 18:50 ` Andrew Burgess [this message]
2015-09-30 13:52   ` [PATCH 8/9] gdb: Split func_command into two parts Pedro Alves
2015-09-11 18:50 ` [PATCH 3/9] gdb: Make use of safe-ctype.h header Andrew Burgess
2015-09-30 13:43   ` Pedro Alves
2015-09-11 18:50 ` [PATCH 1/9] gdb: Check the selected-frame in frame_find_by_id Andrew Burgess
2015-09-30 13:40   ` Pedro Alves
2015-09-11 18:50 ` [PATCH 5/9] gdb: Fix bug with dbx style func command Andrew Burgess
2015-09-30 13:47   ` Pedro Alves
2015-10-26 13:40     ` Thomas Preud'homme
2015-10-26 16:33       ` Andrew Burgess
2015-10-12 21:43 ` [PATCH 0/9] Changes to frame selection 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=d753c5eb4c1cb61ca0d8db8a5f75c0019c042abd.1441996064.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