diff mbox

[8/9] gdb: Split func_command into two parts.

Message ID d753c5eb4c1cb61ca0d8db8a5f75c0019c042abd.1441996064.git.andrew.burgess@embecosm.com
State New
Headers show

Commit Message

Andrew Burgess Sept. 11, 2015, 6:49 p.m. UTC
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(-)

Comments

Pedro Alves Sept. 30, 2015, 1:52 p.m. UTC | #1
On 09/11/2015 07:49 PM, Andrew Burgess wrote:
> 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, 

Indeed.

> 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.

OK.

Thanks,
Pedro Alves
diff mbox

Patch

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);
-}
 
 /* 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);
+    }
+}
+
 
 
 /* Provide a prototype to silence -Wmissing-prototypes.  */