public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Andrew Burgess <aburgess@redhat.com>,
	Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 04/21] gdb: make interp_lookup a method of struct ui
Date: Tue, 12 Sep 2023 10:38:26 -0400	[thread overview]
Message-ID: <608cf6cd-ab5c-46a4-b30e-1f3f8da754ed@efficios.com> (raw)
In-Reply-To: <87ledbkb19.fsf@redhat.com>

>> diff --git a/gdb/python/python.c b/gdb/python/python.c
>> index 6a978d632e9a..a1aaa29d0ce5 100644
>> --- a/gdb/python/python.c
>> +++ b/gdb/python/python.c
>> @@ -683,7 +683,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
>>  
>>  	/* Use the console interpreter uiout to have the same print format
>>  	   for console or MI.  */
>> -	interp = interp_lookup (current_ui, "console");
>> +	interp = current_ui->lookup_interp ("console");
> 
> Might as well take this opportunity to replace "console" with
> INTERP_CONSOLE which is what we use everywhere else.
Good find, I'll add a preparatory patch that fixes it first.

> 
>>  	current_uiout = interp->interp_ui_out ();
>>  
>>  	if (to_string)
>> diff --git a/gdb/ui.c b/gdb/ui.c
>> index 624187ac73c3..a7b81c077e9a 100644
>> --- a/gdb/ui.c
>> +++ b/gdb/ui.c
>> @@ -169,7 +169,30 @@ ui::add_interp (interp *interp)
>>    this->interp_list.push_back (*interp);
>>  }
>>  
>> -/* See top.h.  */
>> +/* See interps.h.  */
>> +
>> +interp *
>> +ui::lookup_interp (const char *name)
>> +{
>> +  if (name == nullptr || strlen (name) == 0)
>> +    return nullptr;
>> +
>> +  /* Only create each interpreter once per UI.  */
>> +  interp *interp = this->lookup_existing_interp (name);
>> +  if (interp != nullptr)
>> +    return interp;
>> +
>> +  const interp_factory *factory = find_interp_factory (name);
>> +  if (factory == nullptr)
>> +    return nullptr;
>> +
>> +  interp = factory->func (factory->name);
>> +  this->add_interp (interp);
>> +
>> +  return interp;
>> +}
> 
> Rather than exposing the interpreter factor stuff outside of interp.c, I
> think a better approach would be either move ui::lookup_interp into
> interp.c -- personally, I'm happy to see different parts of an object in
> different .c files when that makes sense.

I don't know, I really like having declarations and definitions in
matching .h and .c files.

> But if you prefer all to keep ui implementation in ui.c, rather than
> calling find_interp_factory and then factory->func, we could just have a
> new function `create_interp (name)` which creates an interpreter, or
> returns nullptr, then we can write:
> 
>   interp = create_interp (name);
>   if (interp != nullptr)
>     this->add_interp (interp);
>   return interp;
> 
> And all the factory stuff can remain private to interp.c.

Yes, that makes sense, I'll do that.

Simon


  reply	other threads:[~2023-09-12 14:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 18:22 [PATCH 00/21] ui / interp cleansup Simon Marchi
2023-09-08 18:22 ` [PATCH 01/21] gdb: use intrusive_list for struct ui linked list Simon Marchi
2023-09-08 18:22 ` [PATCH 02/21] gdb: make interp_lookup_existing a method of struct ui Simon Marchi
2023-09-08 18:22 ` [PATCH 03/21] gdb: make interp_add " Simon Marchi
2023-09-08 18:22 ` [PATCH 04/21] gdb: make interp_lookup " Simon Marchi
2023-09-12  9:15   ` Andrew Burgess
2023-09-12 14:38     ` Simon Marchi [this message]
2023-09-08 18:22 ` [PATCH 05/21] gdb: remove ui:::add_interp and ui::lookup_existing_interp Simon Marchi
2023-09-08 18:23 ` [PATCH 06/21] gdb: uncover some current_ui uses in interp_set Simon Marchi
2023-09-08 18:23 ` [PATCH 07/21] gdb: add backlink to ui in interp Simon Marchi
2023-09-08 18:23 ` [PATCH 08/21] gdb: pass ui down to gdb_setup_readline and gdb_disable_readline Simon Marchi
2023-09-08 18:23 ` [PATCH 09/21] gdb/python: use m_ui instead of current_ui in dap_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 10/21] gdb/mi: use m_ui instead of current_ui in mi_interp::init Simon Marchi
2023-09-08 18:23 ` [PATCH 11/21] gdb/cli: use m_ui instead of current_ui in cli_interp::resume Simon Marchi
2023-09-12 10:40   ` Andrew Burgess
2023-09-12 15:42     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 12/21] gdb/tui: use m_ui instead of current_ui in tui_interp::resume Simon Marchi
2023-09-12 10:41   ` Andrew Burgess
2023-09-08 18:23 ` [PATCH 13/21] gdb/mi: use m_ui instead of current_ui in mi_interp::resume Simon Marchi
2023-09-12 10:44   ` Andrew Burgess
2023-09-12 16:36     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 14/21] gdb/cli: use m_ui instead of current_ui in cli_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 15/21] gdb/tui: use m_ui instead of current_ui in tui_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 16/21] gdb/mi: use m_ui instead of current_ui in mi_interp::suspend Simon Marchi
2023-09-08 18:23 ` [PATCH 17/21] gdb: pass current_ui down to interp_set Simon Marchi
2023-09-12 10:54   ` Andrew Burgess
2023-09-12 17:17     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 18/21] gdb: make interp_set a method of struct ui Simon Marchi
2023-09-12 10:58   ` Andrew Burgess
2023-09-12 17:23     ` Simon Marchi
2023-09-12 13:41   ` Tom Tromey
2023-09-12 17:32     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 19/21] gdb: pass down current_ui to set_top_level_interpreter Simon Marchi
2023-09-11 15:15   ` Simon Marchi
2023-09-08 18:23 ` [PATCH 20/21] gdb: make set_top_level_interpreter a method of struct ui Simon Marchi
2023-09-12 11:20   ` Andrew Burgess
2023-09-12 17:41     ` Simon Marchi
2023-09-08 18:23 ` [PATCH 21/21] gdb: make top_level_interpreter " Simon Marchi
2023-09-12 11:35   ` Andrew Burgess
2023-09-12 17:54     ` Simon Marchi
2023-09-12 11:38 ` [PATCH 00/21] ui / interp cleansup Andrew Burgess
2023-09-12 17:51   ` Simon Marchi
2023-09-12 18:06   ` 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=608cf6cd-ab5c-46a4-b30e-1f3f8da754ed@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).