This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/5] Look for the last matched 'V' block in trace frame


When we use "collect $tvar5 += 1" in tracepoint action, it will be
compiled to agent expression as below,

(gdb) tvariable $tvar5 = 15
Trace state variable $tvar5 created, with initial value 15.
(gdb) maintenance agent $tvar5 += 1
Scope: 0x8048692
Reg mask: 00
  0  getv 1
  3  tracev 1
  6  const8 1
  8  add
  9  ext 64
 11  setv 1
 14  tracev 1
 17  pop
 18  end

There are two 'tracev' instructions generated, which will record
the tsv in trace buffer twice.  As a result there will be two 'V'
blocks in the trace frame.  In the first one, the value is 15 and
in the second one, the value is 16.

Nowadays, when GDB or GDBserver looks for a 'V' block, it will
return the first matched one instead of the last matched one.
However, the value of the TSV is up to date in the last matched
block, so GDB or GDBserver will get the out-of-date value.

We can fix this problem by removing the first 'tracev' instruction,
as it is redundant.  However, existing AX code generator isn't
smart enough to do so.  So we fix this problem in another way that
force GDB or GDBserver to look for the last matched block.

gdb/gdbserver:

2013-03-07  Yao Qi  <yao@codesourcery.com>

	* tracepoint.c (traceframe_read_tsv): Look for the last matched
	'V' block in trace frame.

gdb:

2013-03-07  Yao Qi  <yao@codesourcery.com>

	* tracepoint.c (tfile_get_trace_state_variable_value): Look for
	the last matched 'V' blcok in trace frame.
---
 gdb/gdbserver/tracepoint.c |    8 +++++---
 gdb/tracepoint.c           |   10 +++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 0f83ae6..c6f4d54 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -5211,6 +5211,7 @@ traceframe_read_tsv (int tsvnum, LONGEST *val)
   unsigned char *database, *dataptr;
   unsigned int datasize;
   int vnum;
+  int found = 0;
 
   trace_debug ("traceframe_read_tsv");
 
@@ -5233,7 +5234,8 @@ traceframe_read_tsv (int tsvnum, LONGEST *val)
   datasize = tframe->data_size;
   database = dataptr = &tframe->data[0];
 
-  /* Iterate through a traceframe's blocks, looking for the tsv.  */
+  /* Iterate through a traceframe's blocks, looking for the last
+     matched tsv.  */
   while ((dataptr = traceframe_find_block_type (dataptr,
 						datasize
 						- (dataptr - database),
@@ -5248,7 +5250,7 @@ traceframe_read_tsv (int tsvnum, LONGEST *val)
       if (tsvnum == vnum)
 	{
 	  memcpy (val, dataptr, sizeof (*val));
-	  return 0;
+	  found = 1;
 	}
 
       /* Skip over this block.  */
@@ -5257,7 +5259,7 @@ traceframe_read_tsv (int tsvnum, LONGEST *val)
 
   trace_debug ("traceframe %d has no data for variable %d",
 	       tfnum, tsvnum);
-  return 1;
+  return !found;
 }
 
 /* Read a requested block of static tracepoint data from a trace
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 7da7aaa..3c906ca 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -5026,7 +5026,12 @@ static int
 tfile_get_trace_state_variable_value (int tsvnum, LONGEST *val)
 {
   int pos;
+  int found = 0;
 
+  /* Iterate over blocks in current frame and find the last 'V'
+     block in which tsv number is TSVNUM.  In one trace frame, there
+     may be multiple 'V' blocks created for a given trace variable,
+     and the last matched 'V' block contains the updated value.  */
   pos = 0;
   while ((pos = traceframe_find_block_type ('V', pos)) >= 0)
     {
@@ -5042,13 +5047,12 @@ tfile_get_trace_state_variable_value (int tsvnum, LONGEST *val)
 	  *val = extract_signed_integer ((gdb_byte *) val, 8,
 					 gdbarch_byte_order
 					 (target_gdbarch ()));
-	  return 1;
+	  found = 1;
 	}
       pos += (4 + 8);
     }
 
-  /* Didn't find anything.  */
-  return 0;
+  return found;
 }
 
 static int
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]