1 /* This program does two things; it generates valid trace files, and
2 it can also be traced so as to test trace file creation from
18 int testglob2
= 271828;
20 const int constglob
= 10000;
23 start_trace_file (char *filename
)
27 fd
= open (filename
, O_WRONLY
|O_CREAT
|O_APPEND
,
28 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
);
33 /* Write a file header, with a high-bit-set char to indicate a
34 binary file, plus a hint as what this file is, and a version
35 number in case of future needs. */
36 write (fd
, "\x7fTRACE0\n", 8);
42 finish_trace_file (int fd
)
49 add_memory_block (char *addr
, int size
)
54 *((char *) trptr
) = 'M';
57 memcpy (trptr
, &ll_x
, sizeof (long long));
58 trptr
+= sizeof (long long);
60 memcpy (trptr
, &short_x
, 2);
62 memcpy (trptr
, addr
, size
);
67 write_basic_trace_file (void)
72 fd
= start_trace_file ("basic.tf");
74 /* The next part of the file consists of newline-separated lines
75 defining status, tracepoints, etc. The section is terminated by
78 /* Dump the size of the R (register) blocks in traceframes. */
79 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
80 write (fd
, spbuf
, strlen (spbuf
));
82 /* Dump trace status, in the general form of the qTstatus reply. */
83 snprintf (spbuf
, sizeof spbuf
, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n");
84 write (fd
, spbuf
, strlen (spbuf
));
86 /* Dump tracepoint definitions, in syntax similar to that used
87 for reconnection uploads. */
88 /* FIXME need a portable way to print function address in hex */
89 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
90 (long) &write_basic_trace_file
);
91 write (fd
, spbuf
, strlen (spbuf
));
92 /* (Note that we would only need actions defined if we wanted to
95 /* Empty line marks the end of the definition section. */
98 /* Make up a simulated trace buffer. */
99 /* (Encapsulate better if we're going to do lots of this; note that
100 buffer endianness is the target program's enddianness.) */
103 memcpy (trptr
, &short_x
, 2);
107 add_memory_block (&testglob
, sizeof (testglob
));
108 /* Divide a variable between two separate memory blocks. */
109 add_memory_block (&testglob2
, 1);
110 add_memory_block (((char*) &testglob2
) + 1, sizeof (testglob2
) - 1);
111 /* Go back and patch in the frame size. */
112 int_x
= trptr
- tfsizeptr
- sizeof (int);
113 memcpy (tfsizeptr
, &int_x
, 4);
115 /* Write end of tracebuffer marker. */
116 memset (trptr
, 0, 6);
119 write (fd
, trbuf
, trptr
- trbuf
);
121 finish_trace_file (fd
);
124 /* Convert number NIB to a hex digit. */
132 return 'a' + nib
- 10;
136 bin2hex (const char *bin
, char *hex
, int count
)
140 for (i
= 0; i
< count
; i
++)
142 *hex
++ = tohex ((*bin
>> 4) & 0xf);
143 *hex
++ = tohex (*bin
++ & 0xf);
150 write_error_trace_file (void)
153 const char made_up
[] = "made-up error";
154 int len
= sizeof (made_up
) - 1;
155 char *hex
= alloca (len
* 2 + 1);
157 fd
= start_trace_file ("error.tf");
159 /* The next part of the file consists of newline-separated lines
160 defining status, tracepoints, etc. The section is terminated by
163 /* Dump the size of the R (register) blocks in traceframes. */
164 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
165 write (fd
, spbuf
, strlen (spbuf
));
167 bin2hex (made_up
, hex
, len
);
169 /* Dump trace status, in the general form of the qTstatus reply. */
170 snprintf (spbuf
, sizeof spbuf
,
173 "tframes:0;tcreated:0;tfree:100;tsize:1000\n",
175 write (fd
, spbuf
, strlen (spbuf
));
177 /* Dump tracepoint definitions, in syntax similar to that used
178 for reconnection uploads. */
179 /* FIXME need a portable way to print function address in hex */
180 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
181 (long) &write_basic_trace_file
);
182 write (fd
, spbuf
, strlen (spbuf
));
183 /* (Note that we would only need actions defined if we wanted to
186 /* Empty line marks the end of the definition section. */
191 /* Write end of tracebuffer marker. */
192 memset (trptr
, 0, 6);
195 write (fd
, trbuf
, trptr
- trbuf
);
197 finish_trace_file (fd
);
201 done_making_trace_files (void)
206 main (int argc
, char **argv
, char **envp
)
208 write_basic_trace_file ();
210 write_error_trace_file ();
212 done_making_trace_files ();
This page took 0.045616 seconds and 4 git commands to generate.