From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91626 invoked by alias); 9 Sep 2017 15:35:57 -0000 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 Received: (qmail 91301 invoked by uid 89); 9 Sep 2017 15:35:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy3-pub.mail.unifiedlayer.com Received: from gproxy3-pub.mail.unifiedlayer.com (HELO gproxy3-pub.mail.unifiedlayer.com) (69.89.30.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Sep 2017 15:35:53 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy3.mail.unifiedlayer.com (Postfix) with ESMTP id 4B8714003F for ; Sat, 9 Sep 2017 09:35:52 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 7Tbo1w00h2f2jeq01TbrwP; Sat, 09 Sep 2017 09:35:52 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=20KFwNOVAAAA:8 a=4UbaajkVJEIz6JYzw_AA:9 a=HLe4JE5fsw6disU0:21 a=XSw_aE_y2aulBil6:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:59756 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dqhnQ-00381I-NS; Sat, 09 Sep 2017 09:35:48 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/7] Use ui_out_emit_table and ui_out_emit_list in print_thread_info_1 Date: Sat, 09 Sep 2017 15:35:00 -0000 Message-Id: <20170909153540.15008-2-tom@tromey.com> In-Reply-To: <20170909153540.15008-1-tom@tromey.com> References: <20170909153540.15008-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dqhnQ-00381I-NS X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:59756 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-09/txt/msg00229.txt.bz2 This changes print_thread_info_1 to use ui_out_emit_table and ui_out_emit_list. Which one is used depends on whether the ui-out is mi-like; so the emitters are wrapped in gdb::optional. ChangeLog 2017-09-09 Tom Tromey * thread.c (print_thread_info_1): Use ui_out_emit_table, ui_out_emit_list, gdb::optional. --- gdb/ChangeLog | 5 ++++ gdb/thread.c | 92 +++++++++++++++++++++++++++++------------------------------ 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 96369d5..b37089e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-09-09 Tom Tromey + + * thread.c (print_thread_info_1): Use ui_out_emit_table, + ui_out_emit_list, gdb::optional. + 2017-09-08 Keith Seitz * dwarf2read.c (struct field_info) : Remove unused diff --git a/gdb/thread.c b/gdb/thread.c index 8a0ed0c..e0ab7f0 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -45,6 +45,7 @@ #include "thread-fsm.h" #include "tid-parse.h" #include +#include "common/gdb_optional.h" /* Definition of struct thread_info exported to gdbthread.h. */ @@ -1247,55 +1248,55 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads, update_thread_list (); current_ptid = inferior_ptid; - struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); - - /* For backward compatibility, we make a list for MI. A table is - preferable for the CLI, though, because it shows table - headers. */ - if (uiout->is_mi_like_p ()) - make_cleanup_ui_out_list_begin_end (uiout, "threads"); - else - { - int n_threads = 0; + { + /* For backward compatibility, we make a list for MI. A table is + preferable for the CLI, though, because it shows table + headers. */ + gdb::optional list_emitter; + gdb::optional table_emitter; + + if (uiout->is_mi_like_p ()) + list_emitter.emplace (uiout, "threads"); + else + { + int n_threads = 0; - for (tp = thread_list; tp; tp = tp->next) - { - if (!should_print_thread (requested_threads, default_inf_num, - global_ids, pid, tp)) - continue; + for (tp = thread_list; tp; tp = tp->next) + { + if (!should_print_thread (requested_threads, default_inf_num, + global_ids, pid, tp)) + continue; - ++n_threads; - } + ++n_threads; + } - if (n_threads == 0) - { - if (requested_threads == NULL || *requested_threads == '\0') - uiout->message (_("No threads.\n")); - else - uiout->message (_("No threads match '%s'.\n"), - requested_threads); - do_cleanups (old_chain); - return; - } + if (n_threads == 0) + { + if (requested_threads == NULL || *requested_threads == '\0') + uiout->message (_("No threads.\n")); + else + uiout->message (_("No threads match '%s'.\n"), + requested_threads); + return; + } - if (show_global_ids || uiout->is_mi_like_p ()) - make_cleanup_ui_out_table_begin_end (uiout, 5, n_threads, "threads"); - else - make_cleanup_ui_out_table_begin_end (uiout, 4, n_threads, "threads"); + table_emitter.emplace (uiout, + (show_global_ids || uiout->is_mi_like_p ()) + ? 5 : 4, + n_threads, "threads"); - uiout->table_header (1, ui_left, "current", ""); + uiout->table_header (1, ui_left, "current", ""); - if (!uiout->is_mi_like_p ()) - uiout->table_header (4, ui_left, "id-in-tg", "Id"); - if (show_global_ids || uiout->is_mi_like_p ()) - uiout->table_header (4, ui_left, "id", "GId"); - uiout->table_header (17, ui_left, "target-id", "Target Id"); - uiout->table_header (1, ui_left, "frame", "Frame"); - uiout->table_body (); - } + if (!uiout->is_mi_like_p ()) + uiout->table_header (4, ui_left, "id-in-tg", "Id"); + if (show_global_ids || uiout->is_mi_like_p ()) + uiout->table_header (4, ui_left, "id", "GId"); + uiout->table_header (17, ui_left, "target-id", "Target Id"); + uiout->table_header (1, ui_left, "frame", "Frame"); + uiout->table_body (); + } - /* We'll be switching threads temporarily. */ - { + /* We'll be switching threads temporarily. */ scoped_restore_current_thread restore_thread; ALL_THREADS_BY_INFERIOR (inf, tp) @@ -1383,14 +1384,13 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads, core = target_core_of_thread (tp->ptid); if (uiout->is_mi_like_p () && core != -1) uiout->field_int ("core", core); - } + } /* This end scope restores the current thread and the frame - selected before the "info threads" command. */ + selected before the "info threads" command, and it finishes the + ui-out list or table. */ } - do_cleanups (old_chain); - if (pid == -1 && requested_threads == NULL) { if (uiout->is_mi_like_p () -- 2.9.4