Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Vladimir Prus <vladimir@codesourcery.com>
To: Nick Roberts <nickrob@snap.net.nz>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [PATCH] Variable objects in multi-threaded programs
Date: Wed, 30 Jan 2008 08:51:00 -0000	[thread overview]
Message-ID: <200801301148.21305.vladimir@codesourcery.com> (raw)
In-Reply-To: <18336.11753.55351.293036@kahikatea.snap.net.nz>

On Wednesday 30 January 2008 10:57:29 Nick Roberts wrote:
>  > >  > > +static void
>  > >  > > +check_scope (struct varobj *var, int* scope)
>  > >  > > +{
>  > >  > 
>  > >  > This function needs a comment. 'check_scope', in
>  > >  > itself, can do just about anything.
>  > > 
>  > > This is a small function and I think it speaks for itself.
>  > 
>  > Not in my opinion. 'check_scope' can mean anything.
> 
> The function name doesn't speak for itself, but being only about twelve lines
> of code, it is easy to see what it does..

It might be easy to see what the function body does. But I don't know
what's the intended usage of the function is, and when the preconditions are
(for example, calling this function when varobj has no associated frame is
probably not going to work).

For example, here's what I'd write as comment:

	/* If the frame associated with this varobj exists,
           and the address in that frame is inside varobj's block,
	   switch to the frame and return 1.  Otherwise, return 0.
	   This function should be called only for variable object
	   that are associated with frame and block, and only in
           the thread associated with the frame.  */

These are 6 lines of english text, and one can understand everything
he needs to know about check_scope, without looking at 12 lines
of body, and without knowing anything about functions called in
that body.

> 
>  > > I don't 
>  > > know if GNU Coding standards dictate how much commenting there should be but
>  > > I think that in varobj.c there is too much and it makes the code harder to
>  > > read.
>  > 
>  > I disagree -- practice shows that the exact semantics of varobj
>  > logic is still not 100% clear.
> 
> But it looks like the coding standards allow us to choose our own style.

Yes, the GNU coding standards mostly have to do with brace placement, that's
why I don't understand why you use it as reference in this case.

I can only repeat that in practice, varobj.c proves hard to understand, which suggest
it needs more comments, not less.

>  > >  > > +        saved_frame_id = get_frame_id (get_selected_frame (NULL));
>  > >  > > +        old_cleanups = make_cleanup_restore_current_thread (inferior_ptid,
>  > >  > >				saved_frame_id); 
>  > >  > 
>  > >  > Presumably, we can move this to the top-level of c_value_of_root, and then
>  > >  > get rid of save/restore of selected frame in varobj_update?
>  > > 
>  > > No.  This is only necessary in the multi-threaded case.
>  > 
>  > make_cleanup_restore_current_thread arranges for two things to
>  > be restored:
>  >    - current thread
>  >    - selected frame
>  > 
>  > We now always save/restore selected frame in varobj_update. And
>  > changing/saving/restoring current thread is extremely fast. So,
>  > why not just save both thread and frame in all cases, and simplify
>  > the logic.
> 
> Then we presumably could remove the calls after value_of_root:
> 
>       /* Restore selected frame.  */
>       fi = frame_find_by_id (old_fid);
>       if (fi)
> 	select_frame (fi);
> 
> but I have no idea how fast do_restore_current_thread_cleanup is.  Indirectly,
> it calls functions like reinit_frame_cache.

Well:

	void
	switch_to_thread (ptid_t ptid)
	{
	  if (ptid_equal (ptid, inferior_ptid))
	    return;

	  inferior_ptid = ptid;
	  reinit_frame_cache ();
	  registers_changed ();
	  stop_pc = read_pc ();
	}

So in the case of non-threaded program, we exit early and pay no price.

- Volodya

 



      parent reply	other threads:[~2008-01-30  8:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-24  4:32 Nick Roberts
2008-01-24  6:36 ` Vladimir Prus
2008-01-24 12:41   ` Nick Roberts
2008-01-24 22:24     ` Nick Roberts
2008-01-29 17:43       ` Vladimir Prus
2008-01-30  1:49         ` Nick Roberts
2008-01-30  7:35           ` Vladimir Prus
     [not found]             ` <18336.11753.55351.293036@kahikatea.snap.net.nz>
2008-01-30  8:51               ` Vladimir Prus [this message]

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=200801301148.21305.vladimir@codesourcery.com \
    --to=vladimir@codesourcery.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=nickrob@snap.net.nz \
    /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