]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/tfile.c
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2010-2014 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* This program does two things; it generates valid trace files, and
19 it can also be traced so as to test trace file creation from
33 /* These globals are put in the trace buffer. */
37 int testglob2
= 271828;
39 /* But these below are not. */
41 const int constglob
= 10000;
43 int nonconstglob
= 14124;
46 start_trace_file (char *filename
)
50 fd
= open (filename
, O_WRONLY
|O_CREAT
|O_APPEND
,
51 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
);
56 /* Write a file header, with a high-bit-set char to indicate a
57 binary file, plus a hint as what this file is, and a version
58 number in case of future needs. */
59 write (fd
, "\x7fTRACE0\n", 8);
65 finish_trace_file (int fd
)
72 add_memory_block (char *addr
, int size
)
75 unsigned long long ll_x
;
77 *((char *) trptr
) = 'M';
79 ll_x
= (unsigned long) addr
;
80 memcpy (trptr
, &ll_x
, sizeof (unsigned long long));
81 trptr
+= sizeof (unsigned long long);
83 memcpy (trptr
, &short_x
, 2);
85 memcpy (trptr
, addr
, size
);
90 write_basic_trace_file (void)
95 fd
= start_trace_file (TFILE_DIR
"tfile-basic.tf");
97 /* The next part of the file consists of newline-separated lines
98 defining status, tracepoints, etc. The section is terminated by
101 /* Dump the size of the R (register) blocks in traceframes. */
102 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
103 write (fd
, spbuf
, strlen (spbuf
));
105 /* Dump trace status, in the general form of the qTstatus reply. */
106 snprintf (spbuf
, sizeof spbuf
, "status 0;tstop:0;tframes:1;tcreated:1;tfree:100;tsize:1000\n");
107 write (fd
, spbuf
, strlen (spbuf
));
109 /* Dump tracepoint definitions, in syntax similar to that used
110 for reconnection uploads. */
111 /* FIXME need a portable way to print function address in hex */
112 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
113 (long) &write_basic_trace_file
);
114 write (fd
, spbuf
, strlen (spbuf
));
115 /* (Note that we would only need actions defined if we wanted to
118 /* Empty line marks the end of the definition section. */
121 /* Make up a simulated trace buffer. */
122 /* (Encapsulate better if we're going to do lots of this; note that
123 buffer endianness is the target program's enddianness.) */
126 memcpy (trptr
, &short_x
, 2);
130 add_memory_block (&testglob
, sizeof (testglob
));
131 /* Divide a variable between two separate memory blocks. */
132 add_memory_block (&testglob2
, 1);
133 add_memory_block (((char*) &testglob2
) + 1, sizeof (testglob2
) - 1);
134 /* Go back and patch in the frame size. */
135 int_x
= trptr
- tfsizeptr
- sizeof (int);
136 memcpy (tfsizeptr
, &int_x
, 4);
138 /* Write end of tracebuffer marker. */
139 memset (trptr
, 0, 6);
142 write (fd
, trbuf
, trptr
- trbuf
);
144 finish_trace_file (fd
);
147 /* Convert number NIB to a hex digit. */
155 return 'a' + nib
- 10;
159 bin2hex (const char *bin
, char *hex
, int count
)
163 for (i
= 0; i
< count
; i
++)
165 *hex
++ = tohex ((*bin
>> 4) & 0xf);
166 *hex
++ = tohex (*bin
++ & 0xf);
173 write_error_trace_file (void)
176 const char made_up
[] = "made-up error";
177 int len
= sizeof (made_up
) - 1;
178 char *hex
= alloca (len
* 2 + 1);
180 fd
= start_trace_file (TFILE_DIR
"tfile-error.tf");
182 /* The next part of the file consists of newline-separated lines
183 defining status, tracepoints, etc. The section is terminated by
186 /* Dump the size of the R (register) blocks in traceframes. */
187 snprintf (spbuf
, sizeof spbuf
, "R %x\n", 500 /* FIXME get from arch */);
188 write (fd
, spbuf
, strlen (spbuf
));
190 bin2hex (made_up
, hex
, len
);
192 /* Dump trace status, in the general form of the qTstatus reply. */
193 snprintf (spbuf
, sizeof spbuf
,
196 "tframes:0;tcreated:0;tfree:100;tsize:1000\n",
198 write (fd
, spbuf
, strlen (spbuf
));
200 /* Dump tracepoint definitions, in syntax similar to that used
201 for reconnection uploads. */
202 /* FIXME need a portable way to print function address in hex */
203 snprintf (spbuf
, sizeof spbuf
, "tp T1:%lx:E:0:0\n",
204 (long) &write_basic_trace_file
);
205 write (fd
, spbuf
, strlen (spbuf
));
206 /* (Note that we would only need actions defined if we wanted to
209 /* Empty line marks the end of the definition section. */
214 /* Write end of tracebuffer marker. */
215 memset (trptr
, 0, 6);
218 write (fd
, trbuf
, trptr
- trbuf
);
220 finish_trace_file (fd
);
224 done_making_trace_files (void)
229 main (int argc
, char **argv
, char **envp
)
231 write_basic_trace_file ();
233 write_error_trace_file ();
235 done_making_trace_files ();