From patchwork Wed Apr 5 09:20:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 67296 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6CC03857010 for ; Wed, 5 Apr 2023 09:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6CC03857010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680686446; bh=GzTlfb8GoyJhl0cGAeK+QKoSYMLDgN4bu6wsTUKp6sk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iTXt1RPb0muaNPOFow84057Fc817VP5T5FETyFC1JrOB0DhGuHMQjw2Y2iFC2Cf3F feJVU4wOnEY6N5jprMwlDt+zu3Icbf7dk65cJMCjOUDNgIayNrnV8zKBoVZOo787Ru 9VjC2TIp9XdkocfQcnaYYKGIYa5qIv3YpCPj0PhY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 7FCDD3858C2D for ; Wed, 5 Apr 2023 09:20:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FCDD3858C2D X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="428693580" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="428693580" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 02:20:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="663962969" X-IronPort-AV: E=Sophos;i="5.98,319,1673942400"; d="scan'208";a="663962969" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Apr 2023 02:20:20 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 1/3] gdb: pass info_threads_opts to print_thread_info_1 Date: Wed, 5 Apr 2023 11:20:00 +0200 Message-Id: <55dfbee4893c991606a28e6ae7bbb96c17b89c9f.1680686220.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tankut Baris Aktemur via Gdb-patches From: "Aktemur, Tankut Baris" Reply-To: Tankut Baris Aktemur Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The "info threads" command tracks its options in a struct named 'info_threads_opts', which currently has only one option. Pass the whole options object to helper functions, instead of passing the option value individually. This is a refactoring to make adding more options easier. --- gdb/thread.c | 61 +++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/gdb/thread.c b/gdb/thread.c index 4d97ed3f2d1..57b3f7611e2 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -951,6 +951,24 @@ pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread) && pc < thread->control.step_range_end); } +/* The options for the "info threads" command. */ + +struct info_threads_opts +{ + /* For "-gid". */ + bool show_global_ids = false; +}; + +static const gdb::option::option_def info_threads_option_defs[] = { + + gdb::option::flag_option_def { + "gid", + [] (info_threads_opts *opts) { return &opts->show_global_ids; }, + N_("Show global thread IDs."), + }, + +}; + /* Helper for print_thread_info. Returns true if THR should be printed. If REQUESTED_THREADS, a list of GDB ids/ranges, is not NULL, only print THR if its ID is included in the list. GLOBAL_IDS @@ -959,11 +977,13 @@ pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread) is a thread from the process PID. Otherwise, threads from all attached PIDs are printed. If both REQUESTED_THREADS is not NULL and PID is not -1, then the thread is printed if it belongs to the - specified process. Otherwise, an error is raised. */ + specified process. Otherwise, an error is raised. OPTS is the + options of the "info threads" command. */ static bool should_print_thread (const char *requested_threads, int default_inf_num, - int global_ids, int pid, struct thread_info *thr) + int global_ids, int pid, thread_info *thr, + info_threads_opts opts) { if (requested_threads != NULL && *requested_threads != '\0') { @@ -1014,12 +1034,12 @@ thread_target_id_str (thread_info *tp) /* Like print_thread_info, but in addition, GLOBAL_IDS indicates whether REQUESTED_THREADS is a list of global or per-inferior - thread ids. */ + thread ids. OPTS is the options of the "info threads" command. */ static void print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, int global_ids, int pid, - int show_global_ids) + info_threads_opts opts) { int default_inf_num = current_inferior ()->num; @@ -1055,7 +1075,7 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, for (thread_info *tp : all_threads ()) { if (!should_print_thread (requested_threads, default_inf_num, - global_ids, pid, tp)) + global_ids, pid, tp, opts)) continue; /* Switch inferiors so we're looking at the right @@ -1079,12 +1099,12 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, return; } - table_emitter.emplace (uiout, show_global_ids ? 5 : 4, + table_emitter.emplace (uiout, opts.show_global_ids ? 5 : 4, n_threads, "threads"); uiout->table_header (1, ui_left, "current", ""); uiout->table_header (4, ui_left, "id-in-tg", "Id"); - if (show_global_ids) + if (opts.show_global_ids) uiout->table_header (4, ui_left, "id", "GId"); uiout->table_header (target_id_col_width, ui_left, "target-id", "Target Id"); @@ -1102,7 +1122,7 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, current_exited = true; if (!should_print_thread (requested_threads, default_inf_num, - global_ids, pid, tp)) + global_ids, pid, tp, opts)) continue; ui_out_emit_tuple tuple_emitter (uiout, NULL); @@ -1117,7 +1137,7 @@ print_thread_info_1 (struct ui_out *uiout, const char *requested_threads, uiout->field_string ("id-in-tg", print_thread_id (tp)); } - if (show_global_ids || uiout->is_mi_like_p ()) + if (opts.show_global_ids || uiout->is_mi_like_p ()) uiout->field_signed ("id", tp->global_num); /* Switch to the thread (and inferior / target). */ @@ -1199,27 +1219,10 @@ void print_thread_info (struct ui_out *uiout, const char *requested_threads, int pid) { - print_thread_info_1 (uiout, requested_threads, 1, pid, 0); + info_threads_opts opts {false}; + print_thread_info_1 (uiout, requested_threads, 1, pid, opts); } -/* The options for the "info threads" command. */ - -struct info_threads_opts -{ - /* For "-gid". */ - bool show_global_ids = false; -}; - -static const gdb::option::option_def info_threads_option_defs[] = { - - gdb::option::flag_option_def { - "gid", - [] (info_threads_opts *opts) { return &opts->show_global_ids; }, - N_("Show global thread IDs."), - }, - -}; - /* Create an option_def_group for the "info threads" options, with IT_OPTS as context. */ @@ -1244,7 +1247,7 @@ info_threads_command (const char *arg, int from_tty) gdb::option::process_options (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp); - print_thread_info_1 (current_uiout, arg, 0, -1, it_opts.show_global_ids); + print_thread_info_1 (current_uiout, arg, 0, -1, it_opts); } /* Completer for the "info threads" command. */