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
16 /* These globals are put in the trace buffer. */
20 int testglob2
= 271828;
22 /* But these below are not. */
24 const int constglob
= 10000;
26 int nonconstglob
= 14124;
29 start_trace_file (char *filename
)
33 fd
= open (filename
, O_WRONLY
|O_CREAT
|O_APPEND
,
34 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
);
39 /* Write a file header, with a high-bit-set char to indicate a
40 binary file, plus a hint as what this file is, and a version
41 number in case of future needs. */
42 write (fd
, "\x7fTRACE0\n", 8);
48 finish_trace_file (int fd
)
55 add_memory_block (char *addr
, int size
)
58 unsigned long long ll_x
;
60 *((char *) trptr
) = 'M';
62 ll_x
= (unsigned long) addr
;
63 memcpy (trptr
, &ll_x
, sizeof (unsigned long long));
64 trptr
+= sizeof (unsigned long long);
66 memcpy (trptr
, &short_x
, 2);
68 memcpy (trptr
, addr
, size
);
73 write_basic_trace_file (void)
78 fd
= start_trace_file ("basic.tf");
80 /* The next part of the file consists of newline-separated lines
81 defining status, tracepoints, etc. The section is terminated by
84 /* Dump the size of the R (register) blocks in traceframes. */
85 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
86 write (fd
, spbuf
, strlen (spbuf
));
88 /* Dump trace status, in the general form of the qTstatus reply. */
89 snprintf (spbuf
, sizeof spbuf
, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n");
90 write (fd
, spbuf
, strlen (spbuf
));
92 /* Dump tracepoint definitions, in syntax similar to that used
93 for reconnection uploads. */
94 /* FIXME need a portable way to print function address in hex */
95 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
96 (long) &write_basic_trace_file
);
97 write (fd
, spbuf
, strlen (spbuf
));
98 /* (Note that we would only need actions defined if we wanted to
101 /* Empty line marks the end of the definition section. */
104 /* Make up a simulated trace buffer. */
105 /* (Encapsulate better if we're going to do lots of this; note that
106 buffer endianness is the target program's enddianness.) */
109 memcpy (trptr
, &short_x
, 2);
113 add_memory_block (&testglob
, sizeof (testglob
));
114 /* Divide a variable between two separate memory blocks. */
115 add_memory_block (&testglob2
, 1);
116 add_memory_block (((char*) &testglob2
) + 1, sizeof (testglob2
) - 1);
117 /* Go back and patch in the frame size. */
118 int_x
= trptr
- tfsizeptr
- sizeof (int);
119 memcpy (tfsizeptr
, &int_x
, 4);
121 /* Write end of tracebuffer marker. */
122 memset (trptr
, 0, 6);
125 write (fd
, trbuf
, trptr
- trbuf
);
127 finish_trace_file (fd
);
130 /* Convert number NIB to a hex digit. */
138 return 'a' + nib
- 10;
142 bin2hex (const char *bin
, char *hex
, int count
)
146 for (i
= 0; i
< count
; i
++)
148 *hex
++ = tohex ((*bin
>> 4) & 0xf);
149 *hex
++ = tohex (*bin
++ & 0xf);
156 write_error_trace_file (void)
159 const char made_up
[] = "made-up error";
160 int len
= sizeof (made_up
) - 1;
161 char *hex
= alloca (len
* 2 + 1);
163 fd
= start_trace_file ("error.tf");
165 /* The next part of the file consists of newline-separated lines
166 defining status, tracepoints, etc. The section is terminated by
169 /* Dump the size of the R (register) blocks in traceframes. */
170 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
171 write (fd
, spbuf
, strlen (spbuf
));
173 bin2hex (made_up
, hex
, len
);
175 /* Dump trace status, in the general form of the qTstatus reply. */
176 snprintf (spbuf
, sizeof spbuf
,
179 "tframes:0;tcreated:0;tfree:100;tsize:1000\n",
181 write (fd
, spbuf
, strlen (spbuf
));
183 /* Dump tracepoint definitions, in syntax similar to that used
184 for reconnection uploads. */
185 /* FIXME need a portable way to print function address in hex */
186 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
187 (long) &write_basic_trace_file
);
188 write (fd
, spbuf
, strlen (spbuf
));
189 /* (Note that we would only need actions defined if we wanted to
192 /* Empty line marks the end of the definition section. */
197 /* Write end of tracebuffer marker. */
198 memset (trptr
, 0, 6);
201 write (fd
, trbuf
, trptr
- trbuf
);
203 finish_trace_file (fd
);
207 done_making_trace_files (void)
212 main (int argc
, char **argv
, char **envp
)
214 write_basic_trace_file ();
216 write_error_trace_file ();
218 done_making_trace_files ();