From patchwork Sat May 5 19:28:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 27125 Received: (qmail 15163 invoked by alias); 5 May 2018 19:28:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15031 invoked by uid 89); 5 May 2018 19:28:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=letters, silently, Usage, separated X-HELO: mailsec109.isp.belgacom.be Received: from mailsec109.isp.belgacom.be (HELO mailsec109.isp.belgacom.be) (195.238.20.105) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 May 2018 19:28:25 +0000 IronPort-PHdr: =?us-ascii?q?9a23=3AyxfCVBDTpcGBuWJ1GPZEUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSPT/r8bcNUDSrc9gkEXOFd2Cra4c0KyO6+jJYi8p2d65qncMcZhBBVcuqP?= =?us-ascii?q?49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6?= =?us-ascii?q?JvjvGo7Vks+7y/2+94fcbglUijexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfO?= =?us-ascii?q?pWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnM?= =?us-ascii?q?VhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Xymp4aV2Rx/ykC?= =?us-ascii?q?oJNyA3/nzZhMJzi6xUohyhqgdjz4LIeoyZKOBzcr/Bcd4cWGFPXtxRVytEAo6k?= =?us-ascii?q?dYUPD+sBPeJZr4nlv1sBswa1Cgm2C+P1zT9In2L23awk3OQ7CgHNwQstH8oOsH?= =?us-ascii?q?TVqNX1Nb8SUfirw6XSwzTMdelW2TDk6IjVcxAuv+uMXalrfMrKykkuFwXFgUuM?= =?us-ascii?q?qYD/JDyayP0Avm6G5ORjTeKik3Mrpx11rzS128shhJXFipgIxlza9Ch12pg5KN?= =?us-ascii?q?OmREN9fNWqCoFftzuAOItzWs4iRmZotzskxbAeop67eTQKyIwgxx7Cd/yLa4iI?= =?us-ascii?q?7QznVOaWOTp4gW9qdKi/hxa19Eiv1PXwVsiy0FlUsipIisTAumwJ2hDJ98SKRO?= =?us-ascii?q?dx8l281TqR1g3f8P9ILE4qmabDLp4u2L8wlp4dsUTZGS/2nV37jLeWdkUl/uio?= =?us-ascii?q?6vznYq34qZOGOY57kBv+MqM3msyiAOQ3LBIOX3OA9OSn173i/Uv5T6tWjvEsia?= =?us-ascii?q?bWrojWJd4Hqa6hHw9VzoEj5g6wDzi7y9sUhGEHI0hZeB2bj4jmJUrOLevjDfe4?= =?us-ascii?q?nlSsiitkyO7IP7L7GJXCMGLPkLD7fbZy80Rc0hY8zchD55JIDbEMOOrzWk/wtN?= =?us-ascii?q?zcDx85KxS0zPj9BNRzzIweQ2WPAraEMKPTr1CI/PkvLvKXZI8WuDf9LeYq5+L0?= =?us-ascii?q?gXAih1BONZWuiJQbYjWgF+htI0iCSWHrn80KHHgDpAd4S/bl23OYVjsGX3azW6?= =?us-ascii?q?Mk/jxzN4u8Cp7eR423m/TVxCe6GpxOfm0AFVmWFm71doieQN8XazOUL9MnmDFS?= =?us-ascii?q?BuvpcJMoyRz77Fyy8LFgNOeBoiA=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2CnCAAkBe5a/+h+gm1cHAEBAQQBAQoBA?= =?us-ascii?q?YNEgVuMdowVAYIpAUMakySBeAsrAYRAAoI3IjYWAQIBAQEBAQECAWsogjUiglI?= =?us-ascii?q?GJy8jED8SOR6FPqloM4RYg2mCOIl5P4EPglYHinUChxIihF6BH4pzCIFlhlKGC?= =?us-ascii?q?wuBNYNgh02QSYElIgExgVJtU4JEgh8Xjhk9gSgBGgGPIwEB?= X-IPAS-Result: =?us-ascii?q?A2CnCAAkBe5a/+h+gm1cHAEBAQQBAQoBAYNEgVuMdowVAYI?= =?us-ascii?q?pAUMakySBeAsrAYRAAoI3IjYWAQIBAQEBAQECAWsogjUiglIGJy8jED8SOR6FP?= =?us-ascii?q?qloM4RYg2mCOIl5P4EPglYHinUChxIihF6BH4pzCIFlhlKGCwuBNYNgh02QSYE?= =?us-ascii?q?lIgExgVJtU4JEgh8Xjhk9gSgBGgGPIwEB?= Received: from 232.126-130-109.adsl-dyn.isp.belgacom.be (HELO md.home) ([109.130.126.232]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 05 May 2018 21:28:17 +0200 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFC 3/5] Add -FLAGS... argument to thread apply Date: Sat, 5 May 2018 21:28:02 +0200 Message-Id: <20180505192804.12731-4-philippe.waroquiers@skynet.be> In-Reply-To: <20180505192804.12731-1-philippe.waroquiers@skynet.be> References: <20180505192804.12731-1-philippe.waroquiers@skynet.be> X-IsSubscribed: yes Also implements 2 new commands: taas COMMAND shortcut for 'thread apply all -s COMMAND' tfaas COMMAND shortcut for 'thread apply all -s frame apply all -s COMMAND' --- gdb/thread.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/gdb/thread.c b/gdb/thread.c index a09d7e0ba0..2fa075d4b1 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1581,6 +1581,41 @@ tp_array_compar (const thread_info *a, const thread_info *b) return (a->per_inf_num > b->per_inf_num); } +static void +thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty, + int print_what_v, + bool cont, bool silent) +{ + switch_to_thread (thr->ptid); + TRY + { + std::string cmd_result = execute_command_to_string (cmd, from_tty); + if (!silent || cmd_result.length() > 0) + { + if (print_what_v > 0) + printf_filtered (_("\nThread %s (%s):\n"), + print_thread_id (thr), + target_pid_to_str (inferior_ptid)); + printf_filtered ("%s", cmd_result.c_str ()); + } + } + CATCH (ex, RETURN_MASK_ERROR) + { + if (!silent) + { + if (print_what_v > 0) + printf_filtered (_("\nThread %s (%s):\n"), + print_thread_id (thr), + target_pid_to_str (inferior_ptid)); + if (cont) + printf_filtered ("%s\n", ex.message); + else + throw_exception (ex); + } + } + END_CATCH; +} + /* Apply a GDB command to a list of threads. List syntax is a whitespace separated list of numbers, or ranges, or the keyword `all'. Ranges consist of two numbers separated by a hyphen. Examples: @@ -1592,6 +1627,10 @@ tp_array_compar (const thread_info *a, const thread_info *b) static void thread_apply_all_command (const char *cmd, int from_tty) { + int print_what_v = 1; /* Print thread id/thread/lwp. */ + bool cont; + bool silent; + tp_array_compar_ascending = false; if (cmd != NULL && check_for_argument (&cmd, "-ascending", strlen ("-ascending"))) @@ -1600,8 +1639,13 @@ thread_apply_all_command (const char *cmd, int from_tty) tp_array_compar_ascending = true; } + if (cmd != NULL) + check_for_flags_vqcs ("thread apply all", &cmd, + &print_what_v, 1, + &cont, &silent); + if (cmd == NULL || *cmd == '\000') - error (_("Please specify a command following the thread ID list")); + error (_("Please specify a command at the end of thread apply all")); update_thread_list (); @@ -1637,14 +1681,9 @@ thread_apply_all_command (const char *cmd, int from_tty) for (thread_info *thr : thr_list_cpy) if (thread_alive (thr)) - { - switch_to_thread (thr->ptid); - printf_filtered (_("\nThread %s (%s):\n"), - print_thread_id (thr), - target_pid_to_str (inferior_ptid)); - - execute_command (cmd, from_tty); - } + thr_try_catch_cmd (thr, cmd, from_tty, + print_what_v, + cont, silent); } } @@ -1653,7 +1692,11 @@ thread_apply_all_command (const char *cmd, int from_tty) static void thread_apply_command (const char *tidlist, int from_tty) { + int print_what_v = 1; /* Print thread id/thread/lwp. */ + bool cont; + bool silent; const char *cmd = NULL; + const char *cmd_or_flags; tid_range_parser parser; if (tidlist == NULL || *tidlist == '\000') @@ -1671,6 +1714,12 @@ thread_apply_command (const char *tidlist, int from_tty) } } + cmd_or_flags = cmd; + if (cmd != NULL) + check_for_flags_vqcs ("thread apply", &cmd, + &print_what_v, 1, + &cont, &silent); + if (cmd == NULL) error (_("Please specify a command following the thread ID list")); @@ -1680,7 +1729,7 @@ thread_apply_command (const char *tidlist, int from_tty) scoped_restore_current_thread restore_thread; parser.init (tidlist, current_inferior ()->num); - while (!parser.finished () && parser.cur_tok () < cmd) + while (!parser.finished () && parser.cur_tok () < cmd_or_flags) { struct thread_info *tp = NULL; struct inferior *inf; @@ -1725,14 +1774,31 @@ thread_apply_command (const char *tidlist, int from_tty) continue; } - switch_to_thread (tp->ptid); - - printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp), - target_pid_to_str (inferior_ptid)); - execute_command (cmd, from_tty); + thr_try_catch_cmd (tp, cmd, from_tty, + print_what_v, + cont, silent); } } + +/* Implementation of the "taas" command. */ + +static void +taas_command (const char *cmd, int from_tty) +{ + std::string expanded = std::string ("thread apply all -s ") + std::string (cmd); + execute_command (expanded.c_str (), from_tty); +} + +/* Implementation of the "tfaas" command. */ + +static void +tfaas_command (const char *cmd, int from_tty) +{ + std::string expanded = std::string ("thread apply all -s frame apply all -s ") + std::string (cmd); + execute_command (expanded.c_str (), from_tty); +} + /* Switch to the specified thread, or print the current thread. */ void @@ -2027,22 +2093,44 @@ Use this command to switch between threads.\n\ The new thread ID must be currently known."), &thread_cmd_list, "thread ", 1, &cmdlist); +#define THREAD_APPLY_FLAGS_HELP "\ +FLAGS letters are v(increase verbosity), q(decrease verbosity)\n\ + c(continue), s(silent).\n\ +Verbosity (default 1) controls what to print for a thread:\n\ + 0 : no thread info is printed\n\ + 1 : print per-inferior thread number and target system's thread id\n\ +By default, if a COMMAND raises an error, thread apply is aborted.\n\ +Flag c indicates to print the error and continue.\n\ +Flag s indicates to silently ignore a COMMAND that raises an error\n\ +or produces no output." + add_prefix_cmd ("apply", class_run, thread_apply_command, _("Apply a command to a list of threads.\n\ -Usage: thread apply ID... COMMAND\n\ -ID is a space-separated list of IDs of threads to apply COMMAND on."), +Usage: thread apply ID... [-FLAGS...] COMMAND\n\ +ID is a space-separated list of IDs of threads to apply COMMAND on.\n" +THREAD_APPLY_FLAGS_HELP), &thread_apply_list, "thread apply ", 1, &thread_cmd_list); add_cmd ("all", class_run, thread_apply_all_command, _("\ Apply a command to all threads.\n\ \n\ -Usage: thread apply all [-ascending] COMMAND\n\ +Usage: thread apply all [-ascending] [-FLAGS...] COMMAND\n\ -ascending: Call COMMAND for all threads in ascending order.\n\ - The default is descending order.\ -"), + The default is descending order.\n" +THREAD_APPLY_FLAGS_HELP), &thread_apply_list); + add_com ("taas", class_run, taas_command, _("\ +Apply a command to all threads (ignoring errors and empty output)\n\ +Usage: taas COMMAND\n\ +shortcut for 'thread apply all -s COMMAND'")); + + add_com ("tfaas", class_run, tfaas_command, _("\ +Apply a command to all frames of all threads (ignoring errors and empty output)\n\ +Usage: tfaas COMMAND\n\ +shortcut for 'thread apply all -s frame apply all -s COMMAND'")); + add_cmd ("name", class_run, thread_name_command, _("Set the current thread's name.\n\ Usage: thread name [NAME]\n\