Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Yao Qi <yao@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Find the next matched trace file in 'tfile target'.
Date: Tue, 26 Feb 2013 19:53:00 -0000	[thread overview]
Message-ID: <512D129B.6040504@redhat.com> (raw)
In-Reply-To: <1361761061-9625-2-git-send-email-yao@codesourcery.com>

[-- Attachment #1: Type: text/plain, Size: 2557 bytes --]

On 02/25/2013 02:57 AM, Yao Qi wrote:
> The previous patch exposes a bug in tfile target when finding a trace
> frame.  Every time, GDB will scan tfile from the starting offset and
> initialize trace frame number to zero.  When TYPE is not tfind_number,
> it means GDB wants to find the *next* matched trace frame of current
> one.  So we need to check the tfile trace frame number iterator is
> greater than the current trace frame number (which means *next*).
> This is mainly what this patch does.

Thanks.  Good catch.

> diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
> index ca104aa..f7a3650 100644
> --- a/gdb/tracepoint.c
> +++ b/gdb/tracepoint.c
> @@ -4324,22 +4324,34 @@ tfile_trace_find (enum trace_find_type type, int num,
>  	  break;
>  	case tfind_pc:
>  	  tfaddr = tfile_get_traceframe_address (tframe_offset);
> -	  if (tfaddr == addr1)
> +	  if (tfaddr == addr1
> +	      /* Looks for the next trace frame if matched.  */
> +	      && (tfnum > traceframe_number
> +		  || (tfnum == traceframe_number && tfnum == 0)))
>  	    found = 1;
>  	  break;
>  	case tfind_tp:
>  	  tp = get_tracepoint (num);
> -	  if (tp && tpnum == tp->number_on_target)
> +	  if (tp && tpnum == tp->number_on_target
> +	      /* Looks for the next trace frame if matched.  */
> +	      && (tfnum > traceframe_number
> +		  || (tfnum == traceframe_number && tfnum == 0)))
>  	    found = 1;
>  	  break;
>  	case tfind_range:
>  	  tfaddr = tfile_get_traceframe_address (tframe_offset);
> -	  if (addr1 <= tfaddr && tfaddr <= addr2)
> +	  if (addr1 <= tfaddr && tfaddr <= addr2
> +	      /* Looks for the next trace frame if matched.  */
> +	      && (tfnum > traceframe_number
> +		  || (tfnum == traceframe_number && tfnum == 0)))
>  	    found = 1;
>  	  break;
>  	case tfind_outside:
>  	  tfaddr = tfile_get_traceframe_address (tframe_offset);
> -	  if (!(addr1 <= tfaddr && tfaddr <= addr2))
> +	  if (!(addr1 <= tfaddr && tfaddr <= addr2)
> +	      /* Looks for the next trace frame if matched.  */
> +	      && (tfnum > traceframe_number
> +		  || (tfnum == traceframe_number && tfnum == 0)))

I'm confused on why this bit of the predicate

 (tfnum == traceframe_number && tfnum == 0)

is necessary.  traceframe_number is -1 when not looking
at a traceframe yet, so "tfnum > traceframe_number"
should be sufficient, no?

I find it clearer to move the frame skipping a bit higher
up, even before the specific tfind tp/range/etc. matching.
Doing it this way also avoids unnecessary read/lseek system
calls done by tfile_get_traceframe_address.

WDYT?


[-- Attachment #2: tfile_find.diff --]
[-- Type: text/x-patch, Size: 3039 bytes --]

commit f837913c7a153a0e40a15f4a283deea201cbcbe7
Author: Pedro Alves <palves@redhat.com>
Date:   Tue Feb 26 19:43:21 2013 +0000

    Find the next matched trace file in 'tfile target'.
    
    The previous patch exposes a bug in the tfile target when finding a
    trace frame.  Every time, GDB will scan tfile from the starting offset
    and look for a matching trace frame starting from frame zero.  But,
    except when TYPE is tfind_number, GDB wants to find the *next* matched
    trace frame after the current selected frame.  So we need to check the
    tfile trace frame number iterator is greater than the current trace
    frame number (which means *next*), meaning skip all frames up to and
    including the current.
    
    Regression tested on x86_64 Fedora 17.
    
    gdb/
    2013-02-25  Yao Qi  <yao@codesourcery.com>
    	    Pedro Alves  <palves@redhat.com>
    
    	* tracepoint.c (tfile_trace_find): For tfind
    	pc/tp/range/outside, look for the next trace frame instead of
    	always starting from frame 0.

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index ca104aa..9a80aa3 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -4316,35 +4316,46 @@ tfile_trace_find (enum trace_find_type type, int num,
                                      ((gdb_byte *) &data_size, 4,
 				      gdbarch_byte_order (target_gdbarch ()));
       offset += 4;
-      switch (type)
+
+      if (type == tfind_number)
 	{
-	case tfind_number:
+	  /* Looking for a specific trace frame.  */
 	  if (tfnum == num)
 	    found = 1;
-	  break;
-	case tfind_pc:
-	  tfaddr = tfile_get_traceframe_address (tframe_offset);
-	  if (tfaddr == addr1)
-	    found = 1;
-	  break;
-	case tfind_tp:
-	  tp = get_tracepoint (num);
-	  if (tp && tpnum == tp->number_on_target)
-	    found = 1;
-	  break;
-	case tfind_range:
-	  tfaddr = tfile_get_traceframe_address (tframe_offset);
-	  if (addr1 <= tfaddr && tfaddr <= addr2)
-	    found = 1;
-	  break;
-	case tfind_outside:
-	  tfaddr = tfile_get_traceframe_address (tframe_offset);
-	  if (!(addr1 <= tfaddr && tfaddr <= addr2))
-	    found = 1;
-	  break;
-	default:
-	  internal_error (__FILE__, __LINE__, _("unknown tfind type"));
 	}
+      else
+	{
+	  /* Start from the _next_ trace frame.  */
+	  if (tfnum > traceframe_number)
+	    {
+	      switch (type)
+		{
+		case tfind_pc:
+		  tfaddr = tfile_get_traceframe_address (tframe_offset);
+		  if (tfaddr == addr1)
+		    found = 1;
+		  break;
+		case tfind_tp:
+		  tp = get_tracepoint (num);
+		  if (tp && tpnum == tp->number_on_target)
+		    found = 1;
+		  break;
+		case tfind_range:
+		  tfaddr = tfile_get_traceframe_address (tframe_offset);
+		  if (addr1 <= tfaddr && tfaddr <= addr2)
+		    found = 1;
+		  break;
+		case tfind_outside:
+		  tfaddr = tfile_get_traceframe_address (tframe_offset);
+		  if (!(addr1 <= tfaddr && tfaddr <= addr2))
+		    found = 1;
+		  break;
+		default:
+		  internal_error (__FILE__, __LINE__, _("unknown tfind type"));
+		}
+	    }
+	}
+
       if (found)
 	{
 	  if (tpp)

  reply	other threads:[~2013-02-26 19:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-25  2:58 [PATCH 1/2] Check trace data from trace file Yao Qi
2013-02-25  2:58 ` [PATCH 2/2] Find the next matched trace file in 'tfile target' Yao Qi
2013-02-26 19:53   ` Pedro Alves [this message]
2013-02-27  1:37     ` Yao Qi
2013-02-25  3:10 ` [PATCH 1/2] Check trace data from trace file Yao Qi
2013-02-26 18:44   ` Pedro Alves
2013-02-26 18:57   ` Pedro Alves
2013-02-27  1:54     ` Yao Qi
2013-02-27 15:23       ` Pedro Alves
2013-02-28  1:14         ` Yao Qi
2013-02-25 12:03 ` Abid, Hafiz
2013-02-25 14:10   ` Abid, Hafiz

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=512D129B.6040504@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=yao@codesourcery.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