Commit | Line | Data |
---|---|---|
00bf0b85 SS |
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 | |
3 | GDB. */ | |
4 | ||
5 | #include <stdio.h> | |
6 | #include <string.h> | |
7 | #include <fcntl.h> | |
8 | #include <sys/stat.h> | |
9 | ||
10 | char spbuf[200]; | |
11 | ||
12 | char trbuf[1000]; | |
13 | char *trptr; | |
14 | char *tfsizeptr; | |
15 | ||
16 | int testglob = 31415; | |
17 | ||
18 | int | |
19 | start_trace_file (char *filename) | |
20 | { | |
21 | int fd; | |
22 | ||
23 | fd = open (filename, O_WRONLY|O_CREAT|O_APPEND, | |
24 | S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); | |
25 | ||
26 | if (fd < 0) | |
27 | return fd; | |
28 | ||
29 | /* Write a file header, with a high-bit-set char to indicate a | |
30 | binary file, plus a hint as what this file is, and a version | |
31 | number in case of future needs. */ | |
32 | write (fd, "\x7fTRACE0\n", 8); | |
33 | ||
34 | return fd; | |
35 | } | |
36 | ||
37 | void | |
38 | finish_trace_file (int fd) | |
39 | { | |
40 | close (fd); | |
41 | } | |
42 | ||
43 | void | |
44 | write_basic_trace_file () | |
45 | { | |
46 | int fd; | |
47 | ||
48 | fd = start_trace_file ("basic.tf"); | |
49 | ||
50 | /* The next part of the file consists of newline-separated lines | |
51 | defining status, tracepoints, etc. The section is terminated by | |
52 | an empty line. */ | |
53 | ||
54 | /* Dump the size of the R (register) blocks in traceframes. */ | |
55 | snprintf (spbuf, sizeof spbuf, "R %x\n", 500 /* FIXME get from arch */); | |
56 | write (fd, spbuf, strlen (spbuf)); | |
57 | ||
58 | /* Dump trace status, in the general form of the qTstatus reply. */ | |
59 | snprintf (spbuf, sizeof spbuf, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n"); | |
60 | write (fd, spbuf, strlen (spbuf)); | |
61 | ||
62 | /* Dump tracepoint definitions, in syntax similar to that used | |
63 | for reconnection uploads. */ | |
64 | snprintf (spbuf, sizeof spbuf, "tp T1:%lx:E:0:0\n", | |
65 | (long) &write_basic_trace_file); | |
66 | write (fd, spbuf, strlen (spbuf)); | |
67 | /* (Note that we would only need actions defined if we wanted to | |
68 | test tdump.) */ | |
69 | ||
70 | /* Empty line marks the end of the definition section. */ | |
71 | write (fd, "\n", 1); | |
72 | ||
73 | /* Make up a simulated trace buffer. */ | |
74 | /* (Encapsulate better if we're going to do lots of this.) */ | |
75 | trptr = trbuf; | |
76 | *((short *) trptr) = 1; | |
77 | trptr += sizeof (short); | |
78 | tfsizeptr = trptr; | |
79 | trptr += sizeof (int); | |
80 | *((char *) trptr) = 'M'; | |
81 | trptr += 1; | |
82 | *((long long *) trptr) = (long) &testglob; | |
83 | trptr += sizeof (long long); | |
84 | *((short *) trptr) = sizeof (testglob); | |
85 | trptr += sizeof (short); | |
86 | *((int *) trptr) = testglob; | |
87 | trptr += sizeof (testglob); | |
88 | /* Go back and patch in the frame size. */ | |
89 | *((int *) tfsizeptr) = trptr - tfsizeptr - sizeof (int); | |
90 | ||
91 | /* Write end of tracebuffer marker. */ | |
92 | *((short *) trptr) = 0; | |
93 | trptr += sizeof (short); | |
94 | *((int *) trptr) = 0; | |
95 | trptr += sizeof (int); | |
96 | ||
97 | write (fd, trbuf, trptr - trbuf); | |
98 | ||
99 | finish_trace_file (fd); | |
100 | } | |
101 | ||
102 | void | |
103 | done_making_trace_files (void) | |
104 | { | |
105 | } | |
106 | ||
107 | int | |
108 | main (int argc, char **argv, char **envp) | |
109 | { | |
110 | write_basic_trace_file (); | |
111 | ||
112 | done_making_trace_files (); | |
113 | ||
114 | return 0; | |
115 | } | |
116 |