This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 8/9] gdb: Split func_command into two parts.
- From: Andrew Burgess <andrew dot burgess at embecosm dot com>
- To: gdb-patches at sourceware dot org
- Cc: Andrew Burgess <andrew dot burgess at embecosm dot com>
- Date: Fri, 11 Sep 2015 19:49:42 +0100
- Subject: [PATCH 8/9] gdb: Split func_command into two parts.
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1441996064 dot git dot andrew dot burgess at embecosm dot com>
- References: <cover dot 1441996064 dot git dot andrew dot burgess at embecosm dot 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);
-}
/* 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. */
--
2.5.1