Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA 1/7] Use ui_out_emit_table and ui_out_emit_list in print_thread_info_1
Date: Sat, 09 Sep 2017 17:47:00 -0000	[thread overview]
Message-ID: <02d471158b96dd13bd7f998f8ec2a310@polymtl.ca> (raw)
In-Reply-To: <20170909153540.15008-2-tom@tromey.com>

On 2017-09-09 17:35, Tom Tromey wrote:
> 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.

LGTM.

I think overall this function is a bad example of how to share code 
between CLI and MI.  There are so many if (is_mi_like_p) that it's 
essentially two functions in one.  Apart from iterating on threads, the 
MI and CLI outputs don't share much...

> @@ -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<ui_out_emit_list> list_emitter;
> +    gdb::optional<ui_out_emit_table> 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 ();
> +      }

Actually, we could remove a lot of if (is_mi_like_p) from here, since 
they are already in an else branch of the same check.  I'll wait until 
this patch has been merged to clean that up, so you don't have a 
conflict.

Thanks,

Simon


  reply	other threads:[~2017-09-09 17:47 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-09 15:35 [RFA 0/7] more ui-out cleanup removal Tom Tromey
2017-09-09 15:35 ` [RFA 6/7] Remove make_cleanup_ui_out_redirect_pop Tom Tromey
2017-09-09 18:49   ` Simon Marchi
2017-09-09 15:35 ` [RFA 4/7] Use ui_out_emit_tuple in disasm.c Tom Tromey
2017-09-09 18:35   ` Simon Marchi
2017-10-12 15:37     ` Simon Marchi
2017-10-12 16:06       ` Simon Marchi
2017-10-12 16:11         ` Tom Tromey
2017-10-12 21:07           ` Tom Tromey
2017-10-13 16:13             ` Tom Tromey
2017-10-16 22:37               ` Simon Marchi
2017-10-16 22:59                 ` Tom Tromey
2017-09-09 15:35 ` [RFA 3/7] Use ui_out_emit_tuple in more places Tom Tromey
2017-09-09 18:32   ` Simon Marchi
2017-09-09 19:32     ` Tom Tromey
2017-09-09 15:35 ` [RFA 1/7] Use ui_out_emit_table and ui_out_emit_list in print_thread_info_1 Tom Tromey
2017-09-09 17:47   ` Simon Marchi [this message]
2017-09-09 18:36     ` Tom Tromey
2017-09-09 19:20       ` Matt Rice
2017-09-09 15:35 ` [RFA 5/7] Use ui_out_emit_list in more places Tom Tromey
2017-09-09 18:43   ` Simon Marchi
2017-09-09 15:46 ` [RFA 2/7] Remove make_cleanup_ui_out_table_begin_end Tom Tromey
2017-09-09 16:02   ` Tom Tromey
2017-09-09 18:22     ` Simon Marchi
2017-09-09 15:46 ` [RFA 7/7] Use ui_out_emit_list and ui_out_emit_tuple with gdb::optional Tom Tromey
2017-09-09 18:51   ` Simon Marchi
2017-09-09 19:44 ` [RFA 0/7] more ui-out cleanup removal Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=02d471158b96dd13bd7f998f8ec2a310@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox