public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Michael Weghorn <m.weghorn@posteo.de>
To: Simon Marchi <simon.marchi@polymtl.ca>,
	Andrew Burgess <andrew.burgess@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: Change init order so pretty printers are set in new_objfile event
Date: Fri, 26 Mar 2021 09:33:35 +0100	[thread overview]
Message-ID: <15241ed0-5270-03de-4758-d73c061babe4@posteo.de> (raw)
In-Reply-To: <c12b0705-a760-3c06-e0d2-4131830448a9@polymtl.ca>

On 24/03/2021 14.51, Simon Marchi via Gdb-patches wrote:
>>> 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);

When trying to implement this, it was unclear to me
how to assign something useful to 'foo_new_objfile_observer' and make use
of that elsewhere (in particular since the call from '_initialize_bar' below
may happen before the one from '_initialize_foo' above, i.e. before the
assignment has happened).

I have still tried to implement the approach as I have understood it and am
currently passing the pointer to the key 'foo_new_objfile_observer' as another
param instead, i.e.

    std::vector<objfile_key *> deps;
    gdb::observers::new_objfile.attach (foo_new_objfile,
                                        &foo_new_objfile_observer, deps);

where the second param is now the optional key to use for the observer itself
and the third param is an optional vector of keys for dependencies (explicitly
given her for clarity).
The key is then used for sorting inside of the 'observable::attach' method
(so that observers depending on this one are moved to after it).

I have uploaded my approach as v3:
https://sourceware.org/pipermail/gdb-patches/2021-March/177251.html

I may well have missed or misunderstood something, so am happy for any hints.

>>>
>>>   // In bar.c, in _initialize_bar
>>>   gdb::observers::new_objfile.attach (bar_new_objfile, &foo_new_objfile_observer);
>>
>> That's fine, but I ran into a case just a couple of days ago where I
>> wanted observer ordering, but in that case there are two observers
>> that I would have wanted to be ordered before.
>>
>> I guess we could chain the dependencies, but I suspect this would
>> break if observers are detached (e.g. tui observers).
>>
>> I think the only reliable solution would be to allow for a vector of
>> dependencies, how would that sound?
> 
> Do you mean using a vector to be able to specify multiple dependencies
> on attach, like this?
> 
>     std::vector<objfile_key *> deps {&foo1_new_objfile_observer,
> 				     &foo2_new_objfile_observer};
>     gdb::observers::new_objfile.attach (bar_new_objfile, deps);
> 
> ?
> 
> If so, yes I think that makes sense.

v3 of the patch uses a vector for dependencies.
So far, I have only added the dependency for my original scenario and haven't
explicitly tested any more complex cases yet.
I can do so if the patch/approach is generally considered OK.

Michael

  reply	other threads:[~2021-03-26  8:33 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
2021-03-24  9:45     ` Andrew Burgess
2021-03-24 13:51       ` Simon Marchi
2021-03-26  8:33         ` Michael Weghorn [this message]
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=15241ed0-5270-03de-4758-d73c061babe4@posteo.de \
    --to=m.weghorn@posteo.de \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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).