示例#1
0
void
write_basic_trace_file ()
{
  int fd;

  fd = start_trace_file ("basic.tf");

  /* The next part of the file consists of newline-separated lines
     defining status, tracepoints, etc.  The section is terminated by
     an empty line.  */

  /* Dump the size of the R (register) blocks in traceframes.  */
  snprintf (spbuf, sizeof spbuf, "R %x\n", 500 /* FIXME get from arch */);
  write (fd, spbuf, strlen (spbuf));

  /* Dump trace status, in the general form of the qTstatus reply.  */
  snprintf (spbuf, sizeof spbuf, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n");
  write (fd, spbuf, strlen (spbuf));

  /* Dump tracepoint definitions, in syntax similar to that used
     for reconnection uploads.  */
  snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n",
	    (long) &write_basic_trace_file);
  write (fd, spbuf, strlen (spbuf));
  /* (Note that we would only need actions defined if we wanted to
     test tdump.) */

  /* Empty line marks the end of the definition section.  */
  write (fd, "\n", 1);

  /* Make up a simulated trace buffer.  */
  /* (Encapsulate better if we're going to do lots of this.) */
  trptr = trbuf;
  *((short *) trptr) = 1;
  trptr += sizeof (short);
  tfsizeptr = trptr;
  trptr += sizeof (int);
  *((char *) trptr) = 'M';
  trptr += 1;
  *((long long *) trptr) = (long) &testglob;
  trptr += sizeof (long long);
  *((short *) trptr) = sizeof (testglob);
  trptr += sizeof (short);
  *((int *) trptr) = testglob;
  trptr += sizeof (testglob);
  /* Go back and patch in the frame size.  */
  *((int *) tfsizeptr) = trptr - tfsizeptr - sizeof (int);

  /* Write end of tracebuffer marker.  */
  *((short *) trptr) = 0;
  trptr += sizeof (short);
  *((int *) trptr) = 0;
  trptr += sizeof (int);

  write (fd, trbuf, trptr - trbuf);

  finish_trace_file (fd);
}
示例#2
0
void
write_basic_trace_file (void)
{
  int fd, int_x;
  short short_x;

  fd = start_trace_file ("basic.tf");

  /* The next part of the file consists of newline-separated lines
     defining status, tracepoints, etc.  The section is terminated by
     an empty line.  */

  /* Dump the size of the R (register) blocks in traceframes.  */
  snprintf (spbuf, sizeof spbuf, "R %x\n", 500 /* FIXME get from arch */);
  write (fd, spbuf, strlen (spbuf));

  /* Dump trace status, in the general form of the qTstatus reply.  */
  snprintf (spbuf, sizeof spbuf, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n");
  write (fd, spbuf, strlen (spbuf));

  /* Dump tracepoint definitions, in syntax similar to that used
     for reconnection uploads.  */
  /* FIXME need a portable way to print function address in hex */
  snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n",
	    (long) &write_basic_trace_file);
  write (fd, spbuf, strlen (spbuf));
  /* (Note that we would only need actions defined if we wanted to
     test tdump.) */

  /* Empty line marks the end of the definition section.  */
  write (fd, "\n", 1);

  /* Make up a simulated trace buffer.  */
  /* (Encapsulate better if we're going to do lots of this; note that
     buffer endianness is the target program's enddianness.) */
  trptr = trbuf;
  short_x = 1;
  memcpy (trptr, &short_x, 2);
  trptr += 2;
  tfsizeptr = trptr;
  trptr += 4;
  add_memory_block (&testglob, sizeof (testglob));
  /* Divide a variable between two separate memory blocks.  */
  add_memory_block (&testglob2, 1);
  add_memory_block (((char*) &testglob2) + 1, sizeof (testglob2) - 1);
  /* Go back and patch in the frame size.  */
  int_x = trptr - tfsizeptr - sizeof (int);
  memcpy (tfsizeptr, &int_x, 4);

  /* Write end of tracebuffer marker.  */
  memset (trptr, 0, 6);
  trptr += 6;

  write (fd, trbuf, trptr - trbuf);

  finish_trace_file (fd);
}
示例#3
0
void
write_error_trace_file (void)
{
  int fd;
  const char made_up[] = "made-up error";
  int len = sizeof (made_up) - 1;
  char *hex = alloca (len * 2 + 1);

  fd = start_trace_file ("error.tf");

  /* The next part of the file consists of newline-separated lines
     defining status, tracepoints, etc.  The section is terminated by
     an empty line.  */

  /* Dump the size of the R (register) blocks in traceframes.  */
  snprintf (spbuf, sizeof spbuf, "R %x\n", 500 /* FIXME get from arch */);
  write (fd, spbuf, strlen (spbuf));

  bin2hex (made_up, hex, len);

  /* Dump trace status, in the general form of the qTstatus reply.  */
  snprintf (spbuf, sizeof spbuf,
	    "status 0;"
	    "terror:%s:1;"
	    "tframes:0;tcreated:0;tfree:100;tsize:1000\n",
	    hex);
  write (fd, spbuf, strlen (spbuf));

  /* Dump tracepoint definitions, in syntax similar to that used
     for reconnection uploads.  */
  /* FIXME need a portable way to print function address in hex */
  snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n",
	    (long) &write_basic_trace_file);
  write (fd, spbuf, strlen (spbuf));
  /* (Note that we would only need actions defined if we wanted to
     test tdump.) */

  /* Empty line marks the end of the definition section.  */
  write (fd, "\n", 1);

  trptr = trbuf;

  /* Write end of tracebuffer marker.  */
  memset (trptr, 0, 6);
  trptr += 6;

  write (fd, trbuf, trptr - trbuf);

  finish_trace_file (fd);
}