public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <andrew.burgess@embecosm.com>,
	Michael Weghorn <m.weghorn@posteo.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: Change init order so pretty printers are set in new_objfile event
Date: Tue, 23 Mar 2021 14:55:13 -0400	[thread overview]
Message-ID: <f1315204-7972-29b7-4e87-79f1d6c15641@polymtl.ca> (raw)
In-Reply-To: <20210211094234.GM265215@embecosm.com>

> I have a crazy thought, but I want to mention it in case it has any
> value.
> 
> The core of the idea is to modify the attach functions in
> gdbsupport/observable.h like this:P
> 
>   void attach (const func_type &f, int bias = 0)
>   {
>     m_observers.emplace_back (nullptr, f, bias);
>     if (m_sorted || bias != 0)
>       {
> 	m_sorted = true;
> 	std::sort (m_observers.begin (), m_observers.end (), sort_by_bias);
>       }
>   }
> 
> Where 'm_sorted' is just a boolean flag, and `sort_by_bias` just
> orders the observers from highest bias to lowest.  Then, if you have
> an observer that you want to run late in the process you just attach
> it with a low bias.  So in py-inferior.c:
> 
>   /* Pass a low bias to ensure this observer triggers after any
>      GDB internal observers.  */
>   gdb::observers::new_objfile.attach (python_new_objfile, -10);
> 

I had similar crazy thoughts once.  Except it wouldn't use arbitrary
numerical values.  It can be a bit obscure why a certain value is
assigned to a given observer.

Instead, when attaching an observer you tell which other observer you'd
like to run after.  So let's say subsystem bar uses features from
subsystem foo (so it necessarily knows about foo already), foo would do:

  // In foo.h
  extern observer_key foo_new_objfile_observer;

  // In foo.c, in _initialize_foo
  foo_new_objfile_observer = gdb::observers::new_objfile.attach (foo_new_objfile);

  // In bar.c, in _initialize_bar
  gdb::observers::new_objfile.attach (bar_new_objfile, &foo_new_objfile_observer);

We could then sort the observers in a way that they are all satisfied.
Unless there are some cycles, but we should detect those and abort.  I
think that by passing a pointer to the observer_key, it should be
possible to make it work regardless of in which order the two attach are
done (since we don't control the order of the _initialize calls).

Simon

  parent reply	other threads:[~2021-03-23 18:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 15:40 Michael Weghorn
2021-02-11  9:42 ` Andrew Burgess
2021-02-11 11:23   ` Michael Weghorn
2021-03-02  7:18     ` Michael Weghorn
2021-03-23 18:55   ` Simon Marchi [this message]
2021-03-24  9:45     ` Andrew Burgess
2021-03-24 13:51       ` Simon Marchi
2021-03-26  8:33         ` Michael Weghorn
2021-02-11 11:22 ` [PATCH v2] " Michael Weghorn
2021-03-23  8:01   ` [PING] " Michael Weghorn
2021-03-26  8:29 ` [PATCH v3] gdb: Do autoload before notifying Python side " Michael Weghorn
2021-04-12 13:37   ` [PING] " Michael Weghorn
2021-04-20 11:38     ` [PING 2] " Michael Weghorn
2021-04-20 21:57   ` Simon Marchi
2021-04-22 15:46     ` Michael Weghorn
2021-04-22 16:06       ` Simon Marchi
2021-04-23  6:41         ` Michael Weghorn
2021-04-23 10:48           ` Simon Marchi
2021-04-22 15:44 ` [PATCH v4 0/2] Make sure autoload happens " Michael Weghorn
2021-04-22 15:44   ` [PATCH v4 1/2] gdbsupport: Allow to specify dependencies between observers Michael Weghorn
2021-04-22 15:44   ` [PATCH v4 2/2] gdb: Do autoload before notifying Python side in new_objfile event Michael Weghorn
2021-04-25  1:46   ` [PATCH v4 0/2] Make sure autoload happens " Simon Marchi
2021-04-26  8:18     ` Michael Weghorn

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=f1315204-7972-29b7-4e87-79f1d6c15641@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=m.weghorn@posteo.de \
    /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).