From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5497 invoked by alias); 30 Nov 2012 14:31:29 -0000 Received: (qmail 5483 invoked by uid 22791); 30 Nov 2012 14:31:27 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_RG X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Nov 2012 14:31:20 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAUEVKX8009988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Nov 2012 09:31:20 -0500 Received: from localhost.localdomain (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qAUEVIXN029107 for ; Fri, 30 Nov 2012 09:31:19 -0500 Message-ID: <50B8C333.4070008@redhat.com> Date: Fri, 30 Nov 2012 14:31:00 -0000 From: Phil Muldoon MIME-Version: 1.0 To: "gdb-patches@sourceware.org" Subject: [patch][python] 2 of 5 - Frame filter MI code changes. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-11/txt/msg00926.txt.bz2 This email and patch covers the MI code changes for Python Frame Filters. 2012-11-30 Phil Muldoon * mi/mi-cmds.h : Add stack_enable_frame_filters extern. * mi/mi-cmd-var.c (mi_cmd_var_set_update_range): New function. * mi/mi-cmd-stack.c (mi_cmd_stack_list_frames): Add --no-frame-filter logic, and Python frame filter logic. (stack_enable_frame_filters): New function. (parse_no_frame_option): Ditto. (mi_cmd_stack_list_frames): Add --no-frame-filter and Python frame filter logic. (mi_cmd_stack_list_locals): Ditto. (mi_cmd_stack_list_args): Ditto. (mi_cmd_stack_list_variables): Ditto. -- diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c index fe3e0bf..7e3ef35 100644 --- a/gdb/mi/mi-cmd-stack.c +++ b/gdb/mi/mi-cmd-stack.c @@ -32,13 +32,33 @@ #include "language.h" #include "valprint.h" #include "exceptions.h" - +#include "utils.h" +#include "python/python.h" +#include enum what_to_list { locals, arguments, all }; static void list_args_or_locals (enum what_to_list what, enum print_values values, struct frame_info *fi); +/* True if we want to allow Python-based frame filters. */ +static int frame_filters = 0; + +void +stack_enable_frame_filters (void) +{ + frame_filters = 1; +} + +static int +parse_no_frames_option (char *arg) +{ + if (arg && (strcmp (arg, "--no-frame-filters") == 0)) + return 1; + + return 0; +} + /* Print a list of the stack frames. Args can be none, in which case we want to print the whole backtrace, or a pair of numbers specifying the frame numbers at which to start and stop the @@ -53,14 +73,20 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc) int i; struct cleanup *cleanup_stack; struct frame_info *fi; + int result = 0; + int raw_arg = 0; - if (argc > 2 || argc == 1) - error (_("-stack-list-frames: Usage: [FRAME_LOW FRAME_HIGH]")); + if (argc > 0) + raw_arg = parse_no_frames_option (argv[0]); - if (argc == 2) + if ((argc > 3 && ! raw_arg) || (argc == 1 && ! raw_arg) + || (argc == 2 && raw_arg)) + error (_("-stack-list-frames: Usage: [--no-frame-filters] [FRAME_LOW FRAME_HIGH]")); + + if (argc == 3 || argc == 2) { - frame_low = atoi (argv[0]); - frame_high = atoi (argv[1]); + frame_low = atoi (argv[0 + raw_arg]); + frame_high = atoi (argv[1 + raw_arg]); } else { @@ -82,16 +108,36 @@ mi_cmd_stack_list_frames (char *command, char **argv, int argc) cleanup_stack = make_cleanup_ui_out_list_begin_end (current_uiout, "stack"); - /* Now let's print the frames up to frame_high, or until there are - frames in the stack. */ - for (; - fi && (i <= frame_high || frame_high == -1); - i++, fi = get_prev_frame (fi)) + if (! raw_arg && frame_filters) + { + int count = frame_high; + int flags = PRINT_LEVEL | PRINT_FRAME_INFO; + + if (frame_high != -1) + count = (frame_high - frame_low) + 1; + + result = apply_frame_filter (fi, flags, 0, NULL, current_uiout, + count); + } + + /* Run the inbuilt backtrace if there are no filters registered, or + if there was an error in the Python backtracing output, or if + frame-filters are disabled. */ + if (! frame_filters || raw_arg || result == PY_BT_ERROR + || result == PY_BT_NO_FILTERS) + { - QUIT; - /* Print the location and the address always, even for level 0. - If args is 0, don't print the arguments. */ - print_frame_info (fi, 1, LOC_AND_ADDRESS, 0 /* args */ ); + /* Now let's print the frames up to frame_high, or until there are + frames in the stack. */ + for (; + fi && (i <= frame_high || frame_high == -1); + i++, fi = get_prev_frame (fi)) + { + QUIT; + /* Print the location and the address always, even for level 0. + If args is 0, don't print the arguments. */ + print_frame_info (fi, 1, LOC_AND_ADDRESS, 0 /* args */ ); + } } do_cleanups (cleanup_stack); @@ -148,13 +194,33 @@ void mi_cmd_stack_list_locals (char *command, char **argv, int argc) { struct frame_info *frame; + int raw_arg = 0; + int result = 0; + int print_value; - if (argc != 1) - error (_("-stack-list-locals: Usage: PRINT_VALUES")); + if (argc > 0) + raw_arg = parse_no_frames_option (argv[0]); + + if (argc < 1 || argc > 2 || (argc == 2 && ! raw_arg) + || (argc == 1 && raw_arg)) + error (_("-stack-list-locals: Usage: [--no-frame-filters] PRINT_VALUES")); frame = get_selected_frame (NULL); + print_value = parse_print_values (argv[raw_arg]); + + if (! raw_arg && frame_filters) + { + int flags = PRINT_LEVEL | PRINT_LOCALS; - list_args_or_locals (locals, parse_print_values (argv[0]), frame); + result = apply_frame_filter (frame, flags, print_value, + NULL, current_uiout, 1); + } + + if (! frame_filters || raw_arg || result == PY_BT_ERROR + || result == PY_BT_NO_FILTERS) + { + list_args_or_locals (locals, print_value, frame); + } } /* Print a list of the arguments for the current frame. With argument @@ -171,15 +237,20 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc) struct cleanup *cleanup_stack_args; enum print_values print_values; struct ui_out *uiout = current_uiout; + int raw_arg = 0; + int result = 0; + + if (argc > 0) + raw_arg = parse_no_frames_option (argv[0]); - if (argc < 1 || argc > 3 || argc == 2) - error (_("-stack-list-arguments: Usage: " - "PRINT_VALUES [FRAME_LOW FRAME_HIGH]")); + if (argc < 1 || (argc > 3 && ! raw_arg) || (argc == 2 && ! raw_arg)) + error (_("-stack-list-arguments: Usage: " \ + "[--no-frame-filters] PRINT_VALUES [FRAME_LOW FRAME_HIGH]")); - if (argc == 3) + if (argc >= 3) { - frame_low = atoi (argv[1]); - frame_high = atoi (argv[2]); + frame_low = atoi (argv[1 + raw_arg]); + frame_high = atoi (argv[2 + raw_arg]); } else { @@ -189,7 +260,7 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc) frame_high = -1; } - print_values = parse_print_values (argv[0]); + print_values = parse_print_values (argv[raw_arg]); /* Let's position fi on the frame at which to start the display. Could be the innermost frame if the whole stack needs @@ -204,21 +275,37 @@ mi_cmd_stack_list_args (char *command, char **argv, int argc) cleanup_stack_args = make_cleanup_ui_out_list_begin_end (uiout, "stack-args"); - /* Now let's print the frames up to frame_high, or until there are - frames in the stack. */ - for (; - fi && (i <= frame_high || frame_high == -1); - i++, fi = get_prev_frame (fi)) + if (! raw_arg && frame_filters) { - struct cleanup *cleanup_frame; + int count = frame_high; + int flags = PRINT_LEVEL | PRINT_ARGS; + + if (frame_high != -1) + count = (frame_high - frame_low) + 1; - QUIT; - cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); - ui_out_field_int (uiout, "level", i); - list_args_or_locals (arguments, print_values, fi); - do_cleanups (cleanup_frame); + result = apply_frame_filter (fi, flags, print_values, NULL, + current_uiout, count); } + if (! frame_filters || raw_arg || result == PY_BT_ERROR + || result == PY_BT_NO_FILTERS) + { + + /* Now let's print the frames up to frame_high, or until there are + frames in the stack. */ + for (; + fi && (i <= frame_high || frame_high == -1); + i++, fi = get_prev_frame (fi)) + { + struct cleanup *cleanup_frame; + + QUIT; + cleanup_frame = make_cleanup_ui_out_tuple_begin_end (uiout, "frame"); + ui_out_field_int (uiout, "level", i); + list_args_or_locals (arguments, print_values, fi); + do_cleanups (cleanup_frame); + } + } do_cleanups (cleanup_stack_args); } @@ -231,13 +318,35 @@ void mi_cmd_stack_list_variables (char *command, char **argv, int argc) { struct frame_info *frame; + int raw_arg = 0; + int result = 0; + int print_value; + + if (argc > 0) + raw_arg = parse_no_frames_option (argv[0]); + + if (argc < 1 || argc > 2 || (argc == 2 && ! raw_arg) + || (argc == 1 && raw_arg)) + error (_("-stack-list-arguments: Usage: " \ + "[--no-frame-filters] PRINT_VALUES")); + + frame = get_selected_frame (NULL); + print_value = parse_print_values (argv[raw_arg]); + + if (! raw_arg && frame_filters) + { + int flags = PRINT_LEVEL | PRINT_ARGS | PRINT_LOCALS; - if (argc != 1) - error (_("Usage: PRINT_VALUES")); + result = apply_frame_filter (frame, flags, print_value, NULL, + current_uiout, 1); + } - frame = get_selected_frame (NULL); + if (! frame_filters || raw_arg || result == PY_BT_ERROR + || result == PY_BT_NO_FILTERS) + { - list_args_or_locals (all, parse_print_values (argv[0]), frame); + list_args_or_locals (all, print_value, frame); + } } /* Print single local or argument. ARG must be already read in. For diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c index dc47bc1..3e7730e 100644 --- a/gdb/mi/mi-cmd-var.c +++ b/gdb/mi/mi-cmd-var.c @@ -845,6 +845,15 @@ mi_cmd_enable_pretty_printing (char *command, char **argv, int argc) } void +mi_cmd_enable_frame_filters (char *command, char **argv, int argc) +{ + if (argc != 0) + error (_("-enable-frame-filters: no arguments allowed")); + + stack_enable_frame_filters (); +} + +void mi_cmd_var_set_update_range (char *command, char **argv, int argc) { struct varobj *var; diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index 572625f..aa040a7 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -83,6 +83,7 @@ static struct mi_cmd mi_cmds[] = mi_cmd_data_write_register_values), DEF_MI_CMD_MI ("enable-timings", mi_cmd_enable_timings), DEF_MI_CMD_MI ("enable-pretty-printing", mi_cmd_enable_pretty_printing), + DEF_MI_CMD_MI ("enable-frame-filters", mi_cmd_enable_frame_filters), DEF_MI_CMD_MI ("environment-cd", mi_cmd_env_cd), DEF_MI_CMD_MI ("environment-directory", mi_cmd_env_dir), DEF_MI_CMD_MI ("environment-path", mi_cmd_env_path), diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index cf1a5eb..13e6221 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -117,6 +117,7 @@ extern mi_cmd_argv_ftype mi_cmd_var_show_attributes; extern mi_cmd_argv_ftype mi_cmd_var_show_format; extern mi_cmd_argv_ftype mi_cmd_var_update; extern mi_cmd_argv_ftype mi_cmd_enable_pretty_printing; +extern mi_cmd_argv_ftype mi_cmd_enable_frame_filters; extern mi_cmd_argv_ftype mi_cmd_var_set_update_range; /* Description of a single command. */ @@ -146,6 +147,9 @@ struct mi_cmd int *suppress_notification; }; +extern void +stack_enable_frame_filters (void); + /* Lookup a command in the MI command table. */ extern struct mi_cmd *mi_lookup (const char *command);