Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Pedro Alves <palves@redhat.com>
Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
Subject: Re: [RFA] Convert observers to C++
Date: Sat, 10 Feb 2018 00:17:00 -0000	[thread overview]
Message-ID: <87zi4haeak.fsf@tromey.com> (raw)
In-Reply-To: <20f70b2b-bf93-a6b6-f2a4-82e14c807e05@redhat.com> (Pedro Alves's	message of "Tue, 7 Nov 2017 15:48:15 +0000")

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Responding to some old-ish mail...

>> This converts observers from using a special source-generating script
>> to be plain C++.
[...]

>> -Note that the @code{normal_stop} notification is not emitted when
>> -the execution stops due to a breakpoint, and this breakpoint has
>> -a condition that is not met.  If the breakpoint has any associated
>> -commands list, the commands are executed after the notification
>> -is emitted.

Pedro> Is all the documentation in this file preserved?  I couldn't find
Pedro> where this paragraph was moved to, for example.

I've now moved this paragraph in particular into a comment.  The rest is
either preserved or not relevant (IMO).  I've added some comments to the
public methods of the class.

Pedro> And then, you could even do:
Pedro>  #define DEFINE_OBSERVER(OBSERVER_NAME) \
Pedro>    decltype (OBSERVER_NAME) OBSERVER_NAME (#OBSERVER_NAME)
Pedro>  DEFINE_OBSERVER (normal_stop);

I did this.

Pedro> It'd be nicer if the self tests were under "namespace selftests",
Pedro> IMHO.

Done.

Pedro> OOC, is there some guideline you were following for preferring
Pedro> "namespace gdb_observers" over, say, "namespace gdb::observers" ?
Pedro> Just curiosity, don't feel the need to change anything.

Nope.  I went ahead and moved it to gdb::observers, since it was easy.

Pedro> You're going to hate me, but it'd be nice IMO if you
Pedro> switched to use /**/ consistently throughout, per GCC/GDB
Pedro> convention.

I did this.  This was actually easy too.

>> +    m_observers.erase (m_observers.begin () + f);

Pedro> Hmm, this looks incorrect.  "attach" returns an index
Pedro> as token.  And then detach uses "std::vector::erase()",
Pedro> which removes the element at the index and then shifts
Pedro> the rest of the elements left to fill in the space
Pedro> left over by the removed element(s).  So that invalidates
Pedro> all token after the element erased.

Yes, thanks for catching this.

I figure that observers aren't very space-sensitive, so I just put a
counter into the observer and then put the value into the vector, like:

  std::vector<std::pair<size_t, func_type>> m_observers;

Pedro> This could be constexpr and then defined in-class, right?

Did it.

Pedro> (I wonder about splitting core/lib from uses of the core.
Pedro> I.e., defining the struct observer core mechanism in one
Pedro> header, and then define the actual observers in a separate header.
Pedro> I'm basically pondering about e.g., using observers under common/
Pedro> or in gdbserver/.  Like e.g., "common/observer.h" and then
Pedro> "gdb/observers.h" and "gdbserver/observers.h", etc.  But we can cross
Pedro> that bridge when we get to it, too.)

I did this.  Also I realized that calling the class "observer" is
somewhat wrong, as the callback is the observer -- so I made
common/observable.h and I renamed the class to "class observable".

I'm running this through the buildbot again and when it is working I
will re-submit it.

Tom


  reply	other threads:[~2018-02-10  0:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-05  1:33 Tom Tromey
2017-11-07 15:48 ` Pedro Alves
2018-02-10  0:17   ` Tom Tromey [this message]
2018-02-10  3:38     ` Tom Tromey
2018-02-12 18:43       ` Pedro Alves
2018-02-12 18:37     ` Pedro Alves

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=87zi4haeak.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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