From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13819 invoked by alias); 24 Jul 2012 16:11:44 -0000 Received: (qmail 13539 invoked by uid 22791); 24 Jul 2012 16:11:37 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Jul 2012 16:11:22 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1Sthhg-0006rJ-DF from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Tue, 24 Jul 2012 09:11:20 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Tue, 24 Jul 2012 09:11:19 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.1.289.1; Tue, 24 Jul 2012 09:11:17 -0700 From: Yao Qi To: Subject: [PATCH 4/6] new add_setshow_enum_cmd_with_notif and scheduler-locking. Date: Tue, 24 Jul 2012 16:11:00 -0000 Message-ID: <1343146252-22558-5-git-send-email-yao@codesourcery.com> In-Reply-To: <1343146252-22558-1-git-send-email-yao@codesourcery.com> References: <1343146252-22558-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain 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-07/txt/msg00489.txt.bz2 Hi, This patch is to add a new function add_setshow_enum_cmd_with_notif, a friend function of add_setshow_enum_cmd. If the command is registered by this function, a MI notification is sent to MI frontend when the option of command is changed. We choose "scheduler-locking" as one example of "enum" command, and write a test case for it. gdb: 2012-07-23 Yao Qi * cli/cli-decode.c (add_setshow_enum_cmd_with_notif): New. * command.h: Declare. * infrun.c (_initialize_infrun): Call add_setshow_enum_cmd_with_notif. gdb/testsuite: 2012-07-23 Yao Qi * gdb.mi/mi-cmd-opt-changed.exp: New. --- gdb/cli/cli-decode.c | 28 ++++++++++++ gdb/command.h | 12 +++++ gdb/infrun.c | 11 +++-- gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp | 61 +++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 6739aef..5d314db 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -431,6 +431,34 @@ add_setshow_enum_cmd (char *name, c->enums = enumlist; } +/* Same as add_setshow_enum_cmd except that observer 'command_option_change' + will be notified if command option is changed. */ + +void +add_setshow_enum_cmd_with_notif (char *name, + enum command_class class, + const char *const *enumlist, + const char **var, + const char *set_doc, + const char *show_doc, + const char *help_doc, + cmd_sfunc_ftype *set_func, + show_value_ftype *show_func, + struct cmd_list_element **set_list, + struct cmd_list_element **show_list) +{ + struct cmd_list_element *c; + + add_setshow_cmd_full (name, class, var_enum, var, + set_doc, show_doc, help_doc, + set_func, show_func, + set_list, show_list, + &c, NULL); + c->enums = enumlist; + + c->notify_observer_p = 1; +} + const char *auto_boolean_enums[] = { "on", "off", "auto", NULL }; /* Add an auto-boolean command named NAME to both the set and show diff --git a/gdb/command.h b/gdb/command.h index 88895bb..30c0eb2 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -245,6 +245,18 @@ extern void add_setshow_enum_cmd (char *name, struct cmd_list_element **set_list, struct cmd_list_element **show_list); +extern void add_setshow_enum_cmd_with_notif (char *name, + enum command_class class, + const char *const *enumlist, + const char **var, + const char *set_doc, + const char *show_doc, + const char *help_doc, + cmd_sfunc_ftype *set_func, + show_value_ftype *show_func, + struct cmd_list_element **set_list, + struct cmd_list_element **show_list); + extern void add_setshow_auto_boolean_cmd (char *name, enum command_class class, enum auto_boolean *var, diff --git a/gdb/infrun.c b/gdb/infrun.c index efc4162..1c5778c 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -7250,8 +7250,8 @@ By default, the debugger will use the same inferior."), show_follow_exec_mode_string, &setlist, &showlist); - add_setshow_enum_cmd ("scheduler-locking", class_run, - scheduler_enums, &scheduler_mode, _("\ + add_setshow_enum_cmd_with_notif ("scheduler-locking", class_run, + scheduler_enums, &scheduler_mode, _("\ Set mode for locking scheduler during execution."), _("\ Show mode for locking scheduler during execution."), _("\ off == no locking (threads may preempt at any time)\n\ @@ -7259,9 +7259,10 @@ on == full locking (no thread except the current thread may run)\n\ step == scheduler locked during every single-step operation.\n\ In this mode, no other thread may run during a step command.\n\ Other threads may run while stepping over a function call ('next')."), - set_schedlock_func, /* traps on target vector */ - show_scheduler_mode, - &setlist, &showlist); + /* traps on target vector */ + set_schedlock_func, + show_scheduler_mode, + &setlist, &showlist); add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\ Set mode for resuming threads of all processes."), _("\ diff --git a/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp new file mode 100644 index 0000000..a733017 --- /dev/null +++ b/gdb/testsuite/gdb.mi/mi-cmd-opt-changed.exp @@ -0,0 +1,61 @@ +# Copyright 2012 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib mi-support.exp +set MIFLAGS "-i=mi" + +set testfile "basics" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/mi-cmd-opt-changed + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { + untested mi-cmd-opt-changed.exp + return -1 +} + +proc test_command_option_change { } { with_test_prefix "cmd option" { + if [mi_gdb_start] { + return + } + mi_run_to_main + + foreach opt { "on" "off" "step" } { + mi_gdb_test "set scheduler-locking ${opt}" \ + ".*=option-changed,option=\"scheduler-locking\",value=\"${opt}\".*\\^done" \ + "\"set scheduler-locking ${opt}\"" + } + foreach opt { "on" "off" "step" } { + mi_gdb_test "interpreter-exec console \"set scheduler-locking ${opt}\"" \ + ".*=option-changed,option=\"scheduler-locking\",value=\"${opt}\".*\\^done" \ + "interpreter-exec \"set scheduler-locking ${opt}\"" + } + # Don't emit MI notification for request from MI. + mi_gdb_test "-gdb-set scheduler-locking on" \ + {\^done} \ + "\"set scheduler-locking on\" no event (requested by MI)" + + mi_gdb_test "interpreter-exec mi \"-gdb-set scheduler-locking step\"" \ + "\\&\"interpreter-exec mi .*\"-gdb-set scheduler-locking step.*\"\\\\n\"\r\n\\^done\r\n\\^done" \ + "\"set scheduler-locking step\" no event (requested by MI interp)" + mi_gdb_test "set scheduler-locking step" \ + "\\&\"set scheduler-locking step\\\\n\"\r\n\\^done" \ + "\"set scheduler-locking stepr\" no event" + + mi_gdb_exit +}} + +test_command_option_change + +return 0 -- 1.7.7.6