1 /**
2 * Copyright 2013 Robert Rossi <bob@brasko.net>
3 *
4 * This file is an amalgamation of the source files from GDBWIRE.
5 *
6 * It was created using gdbwire 1.0 and git revision 3c5983c.
7 *
8 * GDBWIRE is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * GDBWIRE is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GDBWIRE. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * SPDX-License-Identifier: GPL-3.0-or-later
22 */
23
24 /***** Begin file gdbwire_sys.c **********************************************/
25 #include <stdlib.h>
26 #include <string.h>
27
28 /***** Include gdbwire_sys.h in the middle of gdbwire_sys.c ******************/
29 /***** Begin file gdbwire_sys.h **********************************************/
30 #ifndef __GDBWIRE_SYS_H__
31 #define __GDBWIRE_SYS_H__
32
33 /**
34 * Supporting system functions.
35 */
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42 * Duplicate a string.
43 *
44 * @param str
45 * The string to duplicate
46 *
47 * @return
48 * An allocated string that must be freed.
49 * Null if out of memory or str is NULL.
50 */
51 char *gdbwire_strdup(const char *str);
52
53 #ifdef __cplusplus
54 }
55 #endif
56
57 #endif
58 /***** End of gdbwire_sys.h **************************************************/
59 /***** Continuing where we left off in gdbwire_sys.c *************************/
60
gdbwire_strdup(const char * str)61 char *gdbwire_strdup(const char *str)
62 {
63 char *result = NULL;
64
65 if (str) {
66 size_t length_to_allocate = strlen(str) + 1;
67 result = malloc(length_to_allocate * sizeof(char));
68 if (result) {
69 strcpy(result, str);
70 }
71 }
72
73 return result;
74 }
75 /***** End of gdbwire_sys.c **************************************************/
76 /***** Begin file gdbwire_string.c *******************************************/
77 #include <string.h>
78 #include <stdlib.h>
79 /***** Include gdbwire_string.h in the middle of gdbwire_string.c ************/
80 /***** Begin file gdbwire_string.h *******************************************/
81 #ifndef __GDBWIRE_STRING_H__
82 #define __GDBWIRE_STRING_H__
83
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
87
88 #include <stdlib.h>
89
90 /**
91 * A dynamic string representation.
92 *
93 * To create and destroy a string use gdbwire_string_create() and
94 * gdbwire_string_destroy() respectively.
95 *
96 * This string is an abstraction of a low level C string. It supports being
97 * used as a NULL terminated c string and also as an arbitrary array of
98 * bytes. You can append to this string in either of these modes using
99 * gdbwire_string_append_cstr() or gdbwire_string_append_data(). This string
100 * automatically grows as you append data to it. Please note, the size of
101 * the string will not include the NULL terminated character when using
102 * the gdbwire_string_append_cstr() function to append data.
103 *
104 * To get access to the underlying bytes associated with this string
105 * call gdbwire_string_data(). It is OK to modify the result as long as
106 * you are careful to stay in it's valid bounds.
107 *
108 * The size (or length) of the string can be accessed through the
109 * gdbwire_string_size() function. The character pointer returned from
110 * gdbwire_string_data() is valid from the index range of 0 to
111 * gdbwire_string_size() - 1.
112 */
113 struct gdbwire_string;
114
115 /**
116 * Create a string instance.
117 *
118 * @return
119 * A valid string instance or NULL on error.
120 */
121 struct gdbwire_string *gdbwire_string_create(void);
122
123 /**
124 * Destroy the string instance and it's resources.
125 *
126 * @param string
127 * The string to destroy.
128 */
129 void gdbwire_string_destroy(struct gdbwire_string *string);
130
131 /**
132 * Clear the contents of a string.
133 *
134 * Sets the string back to an empty string which also changes it's
135 * size back to zero.
136 *
137 * The capacity remains unchanged.
138 *
139 * @param string
140 * The string to clear
141 */
142 void gdbwire_string_clear(struct gdbwire_string *string);
143
144 /**
145 * Append a c string to the string instance.
146 *
147 * @param string
148 * The string instance to append the c string to.
149 *
150 * @param cstr
151 * The c string to append to the string instance.
152 *
153 * @return
154 * 0 on success or -1 on failure.
155 */
156 int gdbwire_string_append_cstr(struct gdbwire_string *string, const char *cstr);
157
158 /**
159 * Append a sequence of bytes to the string instance.
160 *
161 * @param string
162 * The string instance to append the sequence of bytes to.
163 *
164 * @param data
165 * The sequence of bytes to append to the string instance. This may
166 * contain NUL characters.
167 *
168 * @param size
169 * The number of bytes in data to append to the string instance.
170 *
171 * @return
172 * 0 on success or -1 on failure.
173 */
174 int gdbwire_string_append_data(struct gdbwire_string *string,
175 const char *data, size_t size);
176
177 /**
178 * Get the data associated with this string.
179 *
180 * The data could be formatted as a NULL terminated C string or
181 * as an arbitrary array of bytes. Use gdbwire_string_size() to
182 * determine the size (or length) of the result of this function.
183 *
184 * Modifying the return value of this function is acceptable as long as you
185 * stay in the string's valid bounds.
186 *
187 * @param string
188 * The string index to get the pointer data from.
189 *
190 * @return
191 * The data that has been added to this string instance or "" after
192 * creation or clear. The result is gdbwire_string_size() bytes long.
193 */
194 char *gdbwire_string_data(struct gdbwire_string *string);
195
196 /**
197 * Determine the size (the number of bytes) this string instance represents.
198 *
199 * Please note, the result of this function will not include the NULL
200 * terminated character when using the gdbwire_string_append_cstr() function
201 * to append data.
202 *
203 * @param string
204 * The string instance to get the size for.
205 *
206 * @return
207 * The number of bytes contained in this string instance. To access these
208 * bytes see gdbwire_string_data(). Will be 0 after creation or clear.
209 */
210 size_t gdbwire_string_size(struct gdbwire_string *string);
211
212 /**
213 * Determine the maximum capacity (number of bytes) this string may hold.
214 *
215 * The max capacity of the string is automatically increased when data
216 * is appended to this string through the gdbwire_string_append_*()
217 * family of functions.
218 *
219 * @param string
220 * The string to determine the capacity of.
221 *
222 * @return
223 * The max number of bytes this string may hold.
224 */
225 size_t gdbwire_string_capacity(struct gdbwire_string *string);
226
227 /**
228 * Search for the first character in chars occuring in this string.
229 *
230 * @param string
231 * The string to search for the characters in chars in.
232 *
233 * @param chars
234 * A null terminated string of characters. This string is not searched
235 * for directly but instead each individually character in the string
236 * is searched for.
237 *
238 * @return
239 * The index position of the first matched character in chars.
240 * Will return gdbwire_string_size() if not found.
241 */
242 size_t gdbwire_string_find_first_of(struct gdbwire_string *string,
243 const char *chars);
244
245 /**
246 * Erase characters from this string, reducing it's size.
247 *
248 * @param string
249 * The string to erase characters from.
250 *
251 * @param pos
252 * The index position of the first character to be erased.
253 *
254 * @param count
255 * The number of characters to erase starting at position pos.
256 * If count goes past the end of the string it is adjusted to erase
257 * until the end of the string. This allows the caller to pass in
258 * gdbwire_string_size() to erase the end of the string with out
259 * doing index arithmetic.
260 *
261 * @return
262 * On success 0 will be returned otherwise -1. The string will remain
263 * unmodified when an error occurs. Success can only occur if the entire
264 * requested range can be erased.
265 */
266 int gdbwire_string_erase(struct gdbwire_string *string, size_t pos,
267 size_t count);
268
269 #ifdef __cplusplus
270 }
271 #endif
272
273 #endif
274 /***** End of gdbwire_string.h ***********************************************/
275 /***** Continuing where we left off in gdbwire_string.c **********************/
276
277 struct gdbwire_string {
278 /* The bytes that make up the string. May contain NUL characters. */
279 char *data;
280 /* The number of bytes occuring in data at the moment. */
281 size_t size;
282 /* The max capacity of the string */
283 size_t capacity;
284 };
285
286 struct gdbwire_string *
gdbwire_string_create(void)287 gdbwire_string_create(void)
288 {
289 struct gdbwire_string *string;
290
291 string = calloc(1, sizeof (struct gdbwire_string));
292 if (string) {
293 if (gdbwire_string_append_cstr(string, "") == -1) {
294 gdbwire_string_destroy(string);
295 string = NULL;
296 }
297 }
298
299 return string;
300 }
301
302 void
gdbwire_string_destroy(struct gdbwire_string * string)303 gdbwire_string_destroy(struct gdbwire_string *string)
304 {
305 if (string) {
306 if (string->data) {
307 free(string->data);
308 string->data = NULL;
309 }
310 string->size = 0;
311 string->capacity = 0;
312 free(string);
313 }
314 }
315
316 void
gdbwire_string_clear(struct gdbwire_string * string)317 gdbwire_string_clear(struct gdbwire_string *string)
318 {
319 if (string) {
320 string->size = 0;
321 string->data[0] = '\0';
322 }
323 }
324
325 /**
326 * Increase the size of the string capacity.
327 *
328 * @param string
329 * The string to increase the capacity.
330 *
331 * @return
332 * 0 on success or -1 on error.
333 */
334 static int
gdbwire_string_increase_capacity(struct gdbwire_string * string)335 gdbwire_string_increase_capacity(struct gdbwire_string *string)
336 {
337 /**
338 * The algorithm chosen to increase the capacity is arbitrary.
339 * It starts at 128 bytes. It then doubles it's size in bytes like this,
340 * 128, 256, 512, 1024, 2048, 4096
341 * After it reaches 4096 it then grows by 4096 bytes at a time.
342 */
343 if (string->capacity == 0) {
344 string->capacity = 128;
345 } else if (string->capacity < 4096) {
346 string->capacity *= 2;
347 } else {
348 string->capacity += 4096;
349 }
350
351 /* At this point string->capacity is set to the new size, so realloc */
352 string->data = (char*)realloc(string->data, string->capacity);
353
354 return (string->data) ? 0 : -1;
355 }
356
357 int
gdbwire_string_append_cstr(struct gdbwire_string * string,const char * cstr)358 gdbwire_string_append_cstr(struct gdbwire_string *string, const char *cstr)
359 {
360 int result;
361
362 if (string && cstr) {
363 size_t length = strlen(cstr) + 1;
364 result = gdbwire_string_append_data(string, cstr, length);
365 /* Do not include the NUL character in the size for NULL terminated
366 * strings. This is documented in the interface. */
367 if (result == 0) {
368 string->size--;
369 }
370 } else {
371 result = -1;
372 }
373
374 return result;
375 }
376
377 int
gdbwire_string_append_data(struct gdbwire_string * string,const char * data,size_t size)378 gdbwire_string_append_data(struct gdbwire_string *string, const char *data,
379 size_t size)
380 {
381 int result = (string && data) ? 0 : -1;
382 size_t data_index = 0;
383
384 for (; string && data && data_index < size; ++data_index, ++string->size) {
385 if (string->size >= string->capacity) {
386 result = gdbwire_string_increase_capacity(string);
387 if (result == -1) {
388 break;
389 }
390 }
391
392 string->data[string->size] = data[data_index];
393 }
394
395 return result;
396 }
397
398 char *
gdbwire_string_data(struct gdbwire_string * string)399 gdbwire_string_data(struct gdbwire_string *string)
400 {
401 char *result = NULL;
402
403 if (string) {
404 result = string->data;
405 }
406
407 return result;
408 }
409
410 size_t
gdbwire_string_size(struct gdbwire_string * string)411 gdbwire_string_size(struct gdbwire_string *string)
412 {
413 return string->size;
414 }
415
416 size_t
gdbwire_string_capacity(struct gdbwire_string * string)417 gdbwire_string_capacity(struct gdbwire_string *string)
418 {
419 return string->capacity;
420 }
421
422 size_t
gdbwire_string_find_first_of(struct gdbwire_string * string,const char * chars)423 gdbwire_string_find_first_of(struct gdbwire_string *string, const char *chars)
424 {
425 size_t data_pos, data_size = 0;
426 char *data_cur;
427 const char *chars_cur;
428
429 if (string && chars) {
430 data_size = gdbwire_string_size(string);
431 data_cur = gdbwire_string_data(string);
432
433 for (data_pos = 0; data_pos < data_size; ++data_pos) {
434 char data_c = data_cur[data_pos];
435 for (chars_cur = chars; *chars_cur; ++chars_cur) {
436 if (data_c == *chars_cur) {
437 return data_pos;
438 }
439 }
440 }
441 }
442
443 return data_size;
444 }
445
446 int
gdbwire_string_erase(struct gdbwire_string * string,size_t pos,size_t count)447 gdbwire_string_erase(struct gdbwire_string *string, size_t pos, size_t count)
448 {
449 int result = -1;
450
451 if (string) {
452 size_t count_erased = count;
453 size_t data_size = gdbwire_string_size(string);
454 char *data = gdbwire_string_data(string);
455
456 /* The position index must be smaller than the data size to be valid */
457 if (pos < data_size) {
458 size_t from_pos = pos + count;
459
460 /**
461 * Check to see if anything needs to be copied.
462 * If not, just null terminate the position to be erased
463 * Null terminating the string ensures the c string and the data
464 * string approach are both safe. In the data mode, the nul
465 * character is unneeded.
466 */
467 if (from_pos >= data_size) {
468 data[pos] = 0;
469 count_erased = data_size - pos;
470 /* If so, move characters from the from position
471 to the to position */
472 } else {
473 char *to_cur = &data[pos], *from_cur = &data[from_pos];
474
475 /* shift everything after the erase request to the left */
476 for (; from_pos < data_size; ++from_pos, ++to_cur, ++from_cur) {
477 *to_cur = *from_cur;
478 }
479 }
480 string->size -= count_erased;
481 result = 0;
482 }
483 }
484
485 return result;
486 }
487 /***** End of gdbwire_string.c ***********************************************/
488 /***** Begin file gdbwire_logger.c *******************************************/
489 #include <stdio.h>
490 #include <stdlib.h>
491 #include <stdarg.h>
492
493 /***** Include gdbwire_logger.h in the middle of gdbwire_logger.c ************/
494 /***** Begin file gdbwire_logger.h *******************************************/
495 #ifndef __GDBWIRE_LOGGER_H__
496 #define __GDBWIRE_LOGGER_H__
497
498 /***** Include gdbwire_result.h in the middle of gdbwire_logger.h ************/
499 /***** Begin file gdbwire_result.h *******************************************/
500 #ifndef GDBWIRE_RESULT_H
501 #define GDBWIRE_RESULT_H
502
503 enum gdbwire_result {
504 /* The result of the operation was successful */
505 GDBWIRE_OK,
506
507 /**
508 * An assertion failed in the calling code.
509 *
510 * Functions are encouraged to assert expressions they expect
511 * to be true. The macro GDBWIRE_ASSERT and GDBWIRE_ASSERT_ERRNO
512 * are useful for asserting expressions, and upon failure, to
513 * automatically log the assertion expression and return
514 * this result status.
515 */
516 GDBWIRE_ASSERT,
517
518 /**
519 * An internal logic error has occurred.
520 *
521 * In general, this should be used when a function can no
522 * longer carry out it's contract and must abort.
523 *
524 * This happens, for instance, when a called function returns
525 * an error status, or when invalid input was provided, etc.
526 */
527 GDBWIRE_LOGIC,
528
529 /**
530 * The system is out of memory.
531 *
532 * Will occur when malloc, strdup, calloc, etc fail to allocate memory.
533 */
534 GDBWIRE_NOMEM
535 };
536
537 #endif /* GDBWIRE_RESULT_H */
538 /***** End of gdbwire_result.h ***********************************************/
539 /***** Continuing where we left off in gdbwire_logger.h **********************/
540
541 #ifdef __cplusplus
542 extern "C" {
543 #endif
544
545 enum gdbwire_logger_level {
546 GDBWIRE_LOGGER_DEBUG,
547 GDBWIRE_LOGGER_INFO,
548 GDBWIRE_LOGGER_WARN,
549 GDBWIRE_LOGGER_ERROR
550 };
551
552 /**
553 * Log a statement to the logger.
554 *
555 * This is typically not called directly. Use the below macros instead.
556 * The macros automatically supply the file, line and level arguments.
557 *
558 * @param file
559 * The filename the logger was invoked from.
560 *
561 * @param line
562 * The line number the logger was invoked from.
563 *
564 * @param level
565 * The level associated with the log message.
566 *
567 * @param fmt
568 * The format string for the message (printf formatting).
569 *
570 * @param ...
571 * Any additional format arguments.
572 */
573 void gdbwire_logger_log(const char *file, int line,
574 enum gdbwire_logger_level level, const char *fmt, ...)
575 #ifdef __GNUC__
576 __attribute__((__format__(__printf__, 4, 5)))
577 #endif
578 ;
579
580 /* The macros intended to be used for logging */
581 #define gdbwire_debug(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
582 GDBWIRE_LOGGER_DEBUG, fmt, ##__VA_ARGS__))
583 #define gdbwire_info(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
584 GDBWIRE_LOGGER_INFO, fmt, ##__VA_ARGS__))
585 #define gdbwire_warn(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
586 GDBWIRE_LOGGER_WARN, fmt, ##__VA_ARGS__))
587 #define gdbwire_error(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
588 GDBWIRE_LOGGER_ERROR, fmt, ##__VA_ARGS__))
589
590 #ifdef __cplusplus
591 }
592 #endif
593
594 #endif
595 /***** End of gdbwire_logger.h ***********************************************/
596 /***** Continuing where we left off in gdbwire_logger.c **********************/
597
598 static const char *gdbwire_logger_level_str[GDBWIRE_LOGGER_ERROR+1] = {
599 "DEBUG",
600 "INFO",
601 "WARN",
602 "ERROR"
603 };
604
605 void
gdbwire_logger_log(const char * file,int line,enum gdbwire_logger_level level,const char * fmt,...)606 gdbwire_logger_log(const char *file, int line, enum gdbwire_logger_level level,
607 const char *fmt, ...)
608 {
609 static int checked_env = 0;
610 static int gdbwire_debug_to_stderr;
611 char *buf;
612 int size;
613
614 if (fmt == NULL)
615 return;
616
617 va_list ap;
618 va_start(ap, fmt);
619
620 size = vsnprintf(0, 0, fmt, ap);
621 buf = malloc(sizeof(char)*size + 1);
622
623 va_start(ap, fmt);
624 size = vsnprintf(buf, size + 1, fmt, ap);
625 va_end(ap);
626
627 if (checked_env == 0) {
628 checked_env = 1;
629 gdbwire_debug_to_stderr = getenv("GDBWIRE_DEBUG_TO_STDERR") != NULL;
630 }
631
632 if (gdbwire_debug_to_stderr) {
633 fprintf(stderr, "gdbwire_logger_log: [%s] %s:%d %s\n",
634 gdbwire_logger_level_str[level], file, line, buf);
635 }
636
637 free(buf);
638 }
639 /***** End of gdbwire_logger.c ***********************************************/
640 /***** Begin file gdbwire_mi_parser.c ****************************************/
641 #include <stdlib.h>
642 #include <stdio.h>
643 #include <string.h>
644
645 /* #include "gdbwire_sys.h" */
646 /***** Include gdbwire_assert.h in the middle of gdbwire_mi_parser.c *********/
647 /***** Begin file gdbwire_assert.h *******************************************/
648 #ifndef GDBWIRE_ERROR_H
649 #define GDBWIRE_ERROR_H
650
651 /* #include "gdbwire_result.h" */
652 /* #include "gdbwire_logger.h" */
653
654 /**
655 * Validate that the expression evaluates to true.
656 *
657 * If the expression does not evaluate to true, log the error and
658 * return a GDBWIRE_ASSERT status code.
659 *
660 * Otherwise, if the expression does evaluate to true, do nothing.
661 *
662 * @param expr
663 * The expression to evaluate.
664 */
665 #define GDBWIRE_ASSERT(expr) \
666 do { \
667 if (!(expr)) { \
668 gdbwire_error("Assertion failure, expr[%s]", #expr); \
669 return GDBWIRE_ASSERT; \
670 } \
671 } while (0)
672
673 /**
674 * Validate that the expression evaluates to true.
675 *
676 * If the expression does not evaluate to true, log the error,
677 * set the variable provided to GDBWIRE_ASSERT and goto the label
678 * provided.
679 *
680 * Otherwise, if the expression does evaluate to true, do nothing.
681 *
682 * @param expr
683 * The expression to evaluate.
684 *
685 * @param variable
686 * The result variable to assign the value GDBWIRE_ASSERT to.
687 *
688 * @param label
689 * The label to jump to if the expression evaluates to False.
690 */
691 #define GDBWIRE_ASSERT_GOTO(expr, variable, label) \
692 do { \
693 if (!(expr)) { \
694 gdbwire_error("Assertion failure, expr[%s], " \
695 "label[%s]", #expr, #label); \
696 variable = GDBWIRE_ASSERT; \
697 goto label; \
698 } \
699 } while (0)
700
701 /**
702 * Validate that the expression evaluates to true.
703 *
704 * This particular assertion macro is used when a system library
705 * call fails and that library call has an associated errno status
706 * to describe the failure reason.
707 *
708 * If the expression does not evaluate to true, log the error,
709 * along with the errno value and message and return a GDBWIRE_ASSERT
710 * status code.
711 *
712 * Otherwise, if the expression does evaluate to true, do nothing.
713 *
714 * @param expr
715 * The expression to evaluate.
716 */
717 #define GDBWIRE_ASSERT_ERRNO(expr) \
718 do { \
719 if (!(expr)) { \
720 gdbwire_error("Assertion failure, expr[%s]," \
721 "errno[%d], strerror[%s]", \
722 #expr, errno, strerror(errno)); \
723 return GDBWIRE_ASSERT; \
724 } \
725 } while (0)
726
727 #endif /* GDBWIRE_ERROR_H */
728 /***** End of gdbwire_assert.h ***********************************************/
729 /***** Continuing where we left off in gdbwire_mi_parser.c *******************/
730 /***** Include gdbwire_mi_grammar.h in the middle of gdbwire_mi_parser.c *****/
731 /***** Begin file gdbwire_mi_grammar.h ***************************************/
732 /* A Bison parser, made by GNU Bison 3.0.4. */
733
734 /* Bison interface for Yacc-like parsers in C
735
736 Copyright 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
737
738 This program is free software: you can redistribute it and/or modify
739 it under the terms of the GNU General Public License as published by
740 the Free Software Foundation, either version 3 of the License, or
741 (at your option) any later version.
742
743 This program is distributed in the hope that it will be useful,
744 but WITHOUT ANY WARRANTY; without even the implied warranty of
745 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
746 GNU General Public License for more details.
747
748 You should have received a copy of the GNU General Public License
749 along with this program. If not, see <http://www.gnu.org/licenses/>. */
750
751 /* As a special exception, you may create a larger work that contains
752 part or all of the Bison parser skeleton and distribute that work
753 under terms of your choice, so long as that work isn't itself a
754 parser generator using the skeleton or a modified version thereof
755 as a parser skeleton. Alternatively, if you modify or redistribute
756 the parser skeleton itself, you may (at your option) remove this
757 special exception, which will cause the skeleton and the resulting
758 Bison output files to be licensed under the GNU General Public
759 License without this special exception.
760
761 This special exception was added by the Free Software Foundation in
762 version 2.2 of Bison. */
763
764 #ifndef YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
765 # define YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
766 /* Debug traces. */
767 #ifndef YYDEBUG
768 # define YYDEBUG 0
769 #endif
770 #if YYDEBUG
771 extern int gdbwire_mi_debug;
772 #endif
773 /* "%code requires" blocks. */
774
775
776 /* An opaque pointer. */
777 #ifndef YY_TYPEDEF_YY_SCANNER_T
778 #define YY_TYPEDEF_YY_SCANNER_T
779 typedef void *yyscan_t;
780 #endif
781
782 struct gdbwire_mi_output;
783
784
785 /* Token type. */
786 #ifndef YYTOKENTYPE
787 # define YYTOKENTYPE
788 enum yytokentype
789 {
790 OPEN_BRACE = 258,
791 CLOSED_BRACE = 259,
792 OPEN_PAREN = 260,
793 CLOSED_PAREN = 261,
794 ADD_OP = 262,
795 MULT_OP = 263,
796 EQUAL_SIGN = 264,
797 TILDA = 265,
798 AT_SYMBOL = 266,
799 AMPERSAND = 267,
800 OPEN_BRACKET = 268,
801 CLOSED_BRACKET = 269,
802 NEWLINE = 270,
803 INTEGER_LITERAL = 271,
804 STRING_LITERAL = 272,
805 CSTRING = 273,
806 COMMA = 274,
807 CARROT = 275
808 };
809 #endif
810 /* Tokens. */
811 #define OPEN_BRACE 258
812 #define CLOSED_BRACE 259
813 #define OPEN_PAREN 260
814 #define CLOSED_PAREN 261
815 #define ADD_OP 262
816 #define MULT_OP 263
817 #define EQUAL_SIGN 264
818 #define TILDA 265
819 #define AT_SYMBOL 266
820 #define AMPERSAND 267
821 #define OPEN_BRACKET 268
822 #define CLOSED_BRACKET 269
823 #define NEWLINE 270
824 #define INTEGER_LITERAL 271
825 #define STRING_LITERAL 272
826 #define CSTRING 273
827 #define COMMA 274
828 #define CARROT 275
829
830 /* Value type. */
831 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
832
833 union YYSTYPE
834 {
835
836 struct gdbwire_mi_output *u_output;
837 struct gdbwire_mi_oob_record *u_oob_record;
838 struct gdbwire_mi_result_record *u_result_record;
839 int u_result_class;
840 int u_async_record_kind;
841 struct gdbwire_mi_result_list *u_result_list;
842 struct gdbwire_mi_result *u_result;
843 char *u_token;
844 struct gdbwire_mi_async_record *u_async_record;
845 struct gdbwire_mi_stream_record *u_stream_record;
846 int u_async_class;
847 char *u_variable;
848 char *u_cstring;
849 struct gdbwire_mi_result *u_tuple;
850 struct gdbwire_mi_result *u_list;
851 int u_stream_record_kind;
852
853 };
854
855 typedef union YYSTYPE YYSTYPE;
856 # define YYSTYPE_IS_TRIVIAL 1
857 # define YYSTYPE_IS_DECLARED 1
858 #endif
859
860
861
862 #ifndef YYPUSH_MORE_DEFINED
863 # define YYPUSH_MORE_DEFINED
864 enum { YYPUSH_MORE = 4 };
865 #endif
866
867 typedef struct gdbwire_mi_pstate gdbwire_mi_pstate;
868
869 int gdbwire_mi_push_parse (gdbwire_mi_pstate *ps, int pushed_char, YYSTYPE const *pushed_val, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output);
870
871 gdbwire_mi_pstate * gdbwire_mi_pstate_new (void);
872 void gdbwire_mi_pstate_delete (gdbwire_mi_pstate *ps);
873
874 #endif /* !YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED */
875 /***** End of gdbwire_mi_grammar.h *******************************************/
876 /***** Continuing where we left off in gdbwire_mi_parser.c *******************/
877 /***** Include gdbwire_mi_parser.h in the middle of gdbwire_mi_parser.c ******/
878 /***** Begin file gdbwire_mi_parser.h ****************************************/
879 #ifndef GDBWIRE_MI_PARSER_H
880 #define GDBWIRE_MI_PARSER_H
881
882 #ifdef __cplusplus
883 extern "C" {
884 #endif
885
886 /* #include "gdbwire_result.h" */
887 /***** Include gdbwire_mi_pt.h in the middle of gdbwire_mi_parser.h **********/
888 /***** Begin file gdbwire_mi_pt.h ********************************************/
889 #ifndef GDBWIRE_MI_PT_H
890 #define GDBWIRE_MI_PT_H
891
892 #ifdef __cplusplus
893 extern "C" {
894 #endif
895
896 /**
897 * The position of a token in a GDB/MI line.
898 *
899 * Note that a string in C is zero based and the token column
900 * position is 1 based. For example,
901 * char *str = "hello world";
902 * The "hello" token would have a start_column as 1 and an end
903 * column as 5.
904 *
905 * The start_column and end_column will be the same column number for
906 * a token of size 1.
907 */
908 struct gdbwire_mi_position {
909 /* The starting column position of the token */
910 int start_column;
911 /* The ending column position of the token */
912 int end_column;
913 };
914
915 /** The gdbwire_mi output kinds. */
916 enum gdbwire_mi_output_kind {
917 /**
918 * The GDB/MI output contains an out of band record.
919 *
920 * The out of band record is not necessarily associated with any
921 * particular GDB/MI input command.
922 */
923 GDBWIRE_MI_OUTPUT_OOB,
924
925 /**
926 * The GDB/MI output contains a gdbwire_mi result record.
927 *
928 * This record typically contains the result data from a request
929 * made by the client in a previous GDB/MI input command.
930 */
931 GDBWIRE_MI_OUTPUT_RESULT,
932
933 /**
934 * The GDB/MI output represents a prompt. (ie. (gdb) )
935 *
936 * TODO: Document when GDB is ready to receive a command. Only if
937 * the prompt is received and at *stopped?
938 */
939 GDBWIRE_MI_OUTPUT_PROMPT,
940
941 /**
942 * A parse error occurred.
943 */
944 GDBWIRE_MI_OUTPUT_PARSE_ERROR
945 };
946
947 /**
948 * The GDB/MI output command.
949 *
950 * A GDB/MI output command is the main mechanism in which GDB
951 * corresponds with a front end.
952 */
953 struct gdbwire_mi_output {
954 enum gdbwire_mi_output_kind kind;
955
956 union {
957 /** When kind == GDBWIRE_MI_OUTPUT_OOB, never NULL. */
958 struct gdbwire_mi_oob_record *oob_record;
959 /** When kind == GDBWIRE_MI_OUTPUT_RESULT, never NULL. */
960 struct gdbwire_mi_result_record *result_record;
961 /** When kind == GDBWIRE_MI_OUTPUT_PARSE_ERROR, never NULL. */
962 struct {
963 /** The token the error occurred on */
964 char *token;
965 /** The position of the token where the error occurred. */
966 struct gdbwire_mi_position pos;
967 } error;
968 } variant;
969
970 /**
971 * The GDB/MI output line that was used to create this output instance.
972 *
973 * Each gdbwire_mi output structure is created from exactly one line of
974 * MI output from GDB. This field represents the line that created
975 * this particular output structure.
976 *
977 * This field is always available and never NULL, even for a parse error.
978 */
979 char *line;
980
981 /** The next GDB/MI output command or NULL if none */
982 struct gdbwire_mi_output *next;
983 };
984
985 /**
986 * A GDB/MI token.
987 *
988 * A string made up of one or more digits.
989 * The regular expression [0-9]+ will match this types contents.
990 */
991 typedef char *gdbwire_mi_token_t;
992
993 /**
994 * A GDB/MI output command may contain one of the following result indications.
995 */
996 enum gdbwire_mi_result_class {
997 /**
998 * The synchronous operation was successful (^done).
999 */
1000 GDBWIRE_MI_DONE,
1001
1002 /**
1003 * Equivalent to GDBWIRE_MI_DONE (^running).
1004 *
1005 * Historically, was output by GDB instead of ^done if the command
1006 * resumed the target.
1007 *
1008 * Do not rely on or use this result class in the front end to determine
1009 * the state of the target. Use the async *running output record to
1010 * determine which threads have resumed running.
1011 *
1012 * TODO: Ensure that early versions of GDB can depend on the async
1013 * *running or if front ends DO have to rely on ^running.
1014 */
1015 GDBWIRE_MI_RUNNING,
1016
1017 /**
1018 * GDB has connected to a remote target (^connected).
1019 *
1020 * This is in response to the -target-select command.
1021 *
1022 * A comment in the GDB source code says,
1023 * There's no particularly good reason why target-connect results
1024 * in not ^done. Should kill ^connected for MI3.
1025 *
1026 * With this in mind, it makes sense to assume that GDBWIRE_MI_CONNECTED
1027 * and GDBWIRE_MI_DONE are equivalent.
1028 */
1029 GDBWIRE_MI_CONNECTED,
1030
1031 /**
1032 * An error has occurred (^error).
1033 *
1034 * This can occur if the user provides an improper command to GDB.
1035 * In this case, the user will be provided the standard error output but
1036 * the front end will also be provided this information independently.
1037 */
1038 GDBWIRE_MI_ERROR,
1039
1040 /**
1041 * GDB has terminated (^exit).
1042 *
1043 * When GDB knows it is about to exit, it provides this notification
1044 * in the GDB/MI output command. However, on all other circumstances,
1045 * the front end should be prepared to have GDB exit and not provide
1046 * this information.
1047 */
1048 GDBWIRE_MI_EXIT,
1049
1050 /* An unsupported result class */
1051 GDBWIRE_MI_UNSUPPORTED
1052 };
1053
1054 /**
1055 * The GDB/MI result record in an output command.
1056 *
1057 * The result record represents the result data in the GDB/MI output
1058 * command sent by GDB. This typically contains the content the client
1059 * was requesting when it sent a GDB/MI input command to GDB.
1060 */
1061 struct gdbwire_mi_result_record {
1062 /**
1063 * The token associated with the corresponding GDB/MI input command.
1064 *
1065 * The client may provide a unique string of digits at the beginning of a
1066 * GDB/MI input command. For example,
1067 * 0000-foo
1068 * When GDB finally gets around to responding to the GDB/MI input command,
1069 * it takes the token provided in the input command and puts it into the
1070 * result record of the corresponding GDB/MI output command. For
1071 * example, the output commmand associated with the above input command is,
1072 * 0000^error,msg="Undefined MI command: foo",code="undefined-command"
1073 * and the result record would have the below token field set to "0000".
1074 *
1075 * This is intended to allow the front end to correlate the GDB/MI input
1076 * command it sent with the GDB/MI output command GDB responded with.
1077 *
1078 * This represents the token value the front end provided to the
1079 * corresponding GDB/MI input command or NULL if no token was provided.
1080 */
1081 gdbwire_mi_token_t token;
1082
1083 /** The result records result class. */
1084 enum gdbwire_mi_result_class result_class;
1085
1086 /**
1087 * An optional list of results for this result record.
1088 *
1089 * Will be NULL if there is no results for this result record.
1090 *
1091 * This is typically where the result data is that the client
1092 * is looking for.
1093 */
1094 struct gdbwire_mi_result *result;
1095 };
1096
1097 /** The out of band record kinds. */
1098 enum gdbwire_mi_oob_record_kind {
1099 /**
1100 * An asyncronous out of band record.
1101 *
1102 * An asyncronous record occurs when GDB would like to update the
1103 * client with information that it has not asked for.
1104 *
1105 * For instance, if the inferior has stopped, or a new thread has
1106 * started.
1107 */
1108 GDBWIRE_MI_ASYNC,
1109
1110 /**
1111 * A stream out of band record.
1112 *
1113 * This is the result of normal output from the console, target or GDB.
1114 */
1115 GDBWIRE_MI_STREAM
1116 };
1117
1118 /* This is an out of band record. */
1119 struct gdbwire_mi_oob_record {
1120 /** The kind of out of band record. */
1121 enum gdbwire_mi_oob_record_kind kind;
1122
1123 union {
1124 /** When kind == GDBWIRE_MI_ASYNC. */
1125 struct gdbwire_mi_async_record *async_record;
1126 /** When kind == GDBWIRE_MI_STREAM. */
1127 struct gdbwire_mi_stream_record *stream_record;
1128 } variant;
1129 };
1130
1131 /** The asynchronous out of band record kinds */
1132 enum gdbwire_mi_async_record_kind {
1133 /**
1134 * The asynchronous status record kind.
1135 *
1136 * Contains on-going status information about the progress of a slow
1137 * operation. It can be discarded.
1138 *
1139 * This output is prepended by the + character.
1140 */
1141 GDBWIRE_MI_STATUS,
1142
1143 /**
1144 * The asynchronous exec record kind.
1145 *
1146 * Contains asynchronous state change regarding the target:
1147 * (stopped, started, disappeared).
1148 *
1149 * This output is prepended by the * character.
1150 */
1151 GDBWIRE_MI_EXEC,
1152
1153 /**
1154 * The asyncronous notify record kind.
1155 *
1156 * Contains supplementary information that the client should handle
1157 * (e.g., a new breakpoint information).
1158 *
1159 * This output is prepended by the = character.
1160 */
1161 GDBWIRE_MI_NOTIFY
1162 };
1163
1164 /** The stream out of band record kinds */
1165 enum gdbwire_mi_stream_record_kind {
1166 /**
1167 * The console output.
1168 *
1169 * Output that should be displayed as is in the console.
1170 * It is the textual response to a CLI command.
1171 *
1172 * This output is prepended by the ~ character.
1173 */
1174 GDBWIRE_MI_CONSOLE,
1175
1176 /**
1177 * The target output.
1178 *
1179 * Output produced by the target program.
1180 *
1181 * This output is prepended by the @ character.
1182 */
1183 GDBWIRE_MI_TARGET,
1184
1185 /**
1186 * The GDB log output.
1187 *
1188 * Output text coming from GDB's internals. For instance messages
1189 * that should be displayed as part of an error log.
1190 *
1191 * This output is prepended by the & character.
1192 */
1193 GDBWIRE_MI_LOG
1194 };
1195
1196 /**
1197 * The GDB/MI asyncronous class.
1198 *
1199 *
1200 */
1201 enum gdbwire_mi_async_class {
1202 /**
1203 * Loading the executable onto the remote target.
1204 *
1205 * This was undocumented in the GDB manual as far as GDB 7.7.
1206 *
1207 * This occurs if the async record is GDBWIRE_MI_STATUS as +download.
1208 */
1209 GDBWIRE_MI_ASYNC_DOWNLOAD,
1210
1211 /**
1212 * The target has stopped.
1213 *
1214 * This occurs if the async record is GDBWIRE_MI_EXEC as *stopped.
1215 */
1216 GDBWIRE_MI_ASYNC_STOPPED,
1217
1218 /**
1219 * The target is now running.
1220 *
1221 * This occurs if the async record is GDBWIRE_MI_EXEC as *running.
1222 */
1223 GDBWIRE_MI_ASYNC_RUNNING,
1224
1225 /**
1226 * Reports that a thread group was added.
1227 *
1228 * When a thread group is added, it generally might not be associated
1229 * with a running process.
1230 *
1231 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1232 * as =thread-group-added.
1233 */
1234 GDBWIRE_MI_ASYNC_THREAD_GROUP_ADDED,
1235
1236 /**
1237 * Reports that a thread group was removed.
1238 *
1239 * When a thread group is removed, its id becomes invalid and cannot be
1240 * used in any way.
1241 *
1242 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1243 * as =thread-group-removed.
1244 */
1245 GDBWIRE_MI_ASYNC_THREAD_GROUP_REMOVED,
1246
1247 /**
1248 * Reports that a thread group was started.
1249 *
1250 * A thread group became associated with a running program.
1251 *
1252 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1253 * as =thread-group-started.
1254 */
1255 GDBWIRE_MI_ASYNC_THREAD_GROUP_STARTED,
1256
1257 /**
1258 * Reports that a thread group was exited.
1259 *
1260 * A thread group is no longer associated with a running program.
1261 *
1262 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1263 * as =thread-group-exited.
1264 */
1265 GDBWIRE_MI_ASYNC_THREAD_GROUP_EXITED,
1266
1267 /**
1268 * Reports that a thread was created.
1269 *
1270 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1271 * as =thread-created.
1272 */
1273 GDBWIRE_MI_ASYNC_THREAD_CREATED,
1274
1275 /**
1276 * Reports that a thread was exited.
1277 *
1278 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =thread-exited.
1279 */
1280 GDBWIRE_MI_ASYNC_THREAD_EXITED,
1281
1282 /**
1283 * Reports that a thread was selected.
1284 *
1285 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =thread-selected.
1286 */
1287 GDBWIRE_MI_ASYNC_THREAD_SELECTED,
1288
1289 /**
1290 * Reports that a new library was loaded.
1291 *
1292 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =library-loaded.
1293 */
1294 GDBWIRE_MI_ASYNC_LIBRARY_LOADED,
1295
1296 /**
1297 * Reports that a new library was unloaded.
1298 *
1299 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1300 * as =library-unloaded.
1301 */
1302 GDBWIRE_MI_ASYNC_LIBRARY_UNLOADED,
1303
1304 /**
1305 * Reports that a trace frame was changed.
1306 *
1307 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1308 * as =traceframe-changed.
1309 */
1310 GDBWIRE_MI_ASYNC_TRACEFRAME_CHANGED,
1311
1312 /**
1313 * Reports that a trace state variable was created.
1314 *
1315 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =tsv-created.
1316 */
1317 GDBWIRE_MI_ASYNC_TSV_CREATED,
1318
1319 /**
1320 * Reports that a trace state variable was modified.
1321 *
1322 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =tsv-modified.
1323 */
1324 GDBWIRE_MI_ASYNC_TSV_MODIFIED,
1325
1326 /**
1327 * Reports that a trace state variable was deleted.
1328 *
1329 * This occurs if the async record is GDBWIRE_MI_NOTIFY as =tsv-deleted.
1330 */
1331 GDBWIRE_MI_ASYNC_TSV_DELETED,
1332
1333 /**
1334 * Reports that a breakpoint was created.
1335 *
1336 * Only user-visible breakpoints are reported to the MI user.
1337 *
1338 * If a breakpoint is emitted in the result record of a
1339 * command, then it will not also be emitted in an async record.
1340 *
1341 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1342 * as =breakpoint-created.
1343 */
1344 GDBWIRE_MI_ASYNC_BREAKPOINT_CREATED,
1345
1346 /**
1347 * Reports that a breakpoint was modified.
1348 *
1349 * Only user-visible breakpoints are reported to the MI user.
1350 *
1351 * If a breakpoint is emitted in the result record of a
1352 * command, then it will not also be emitted in an async record.
1353 *
1354 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1355 * as =breakpoint-modified.
1356 */
1357 GDBWIRE_MI_ASYNC_BREAKPOINT_MODIFIED,
1358
1359 /**
1360 * Reports that a breakpoint was deleted.
1361 *
1362 * Only user-visible breakpoints are reported to the MI user.
1363 *
1364 * If a breakpoint is emitted in the result record of a
1365 * command, then it will not also be emitted in an async record.
1366 *
1367 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1368 * as =breakpoint-deleted.
1369 */
1370 GDBWIRE_MI_ASYNC_BREAKPOINT_DELETED,
1371
1372 /**
1373 * Reports that execution log recording was started on an inferior.
1374 *
1375 * This occurs if the async record is GDBWIRE_MI_NOTIF
1376 * as =record-started.
1377 */
1378 GDBWIRE_MI_ASYNC_RECORD_STARTED,
1379
1380 /**
1381 * Reports that execution log recording was stopped on an inferior.
1382 *
1383 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1384 * as =record-stopped.
1385 */
1386 GDBWIRE_MI_ASYNC_RECORD_STOPPED,
1387
1388 /**
1389 * Reports that a parameter of the command set param is changed to value.
1390 *
1391 * For example, when the user runs a command like 'set print pretty on',
1392 * this async command will be invoked with the parameter reported as
1393 * 'print pretty' and the value as 'on'.
1394 *
1395 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1396 * as =cmd-param-changed.
1397 */
1398 GDBWIRE_MI_ASYNC_CMD_PARAM_CHANGED,
1399
1400 /**
1401 * Reports that bytes from addr to data + len were written in an inferior.
1402 *
1403 * This occurs if the async record is GDBWIRE_MI_NOTIFY
1404 * as =memory-changed.
1405 */
1406 GDBWIRE_MI_ASYNC_MEMORY_CHANGED,
1407
1408 /* An unsupported async class */
1409 GDBWIRE_MI_ASYNC_UNSUPPORTED
1410 };
1411
1412 /**
1413 * The GDB/MI asyncronous record in an output command.
1414 *
1415 * An asyncronous record occurs when GDB would like to update the
1416 * client with information that it has not asked for.
1417 */
1418 struct gdbwire_mi_async_record {
1419 /**
1420 * The result record token.
1421 *
1422 * Please note that the GDB/MI manual says that asyncronous records
1423 * do not currently populate this token on output but reserve the right
1424 * to do so. For that reason, token here should always be NULL.
1425 *
1426 * From the GDB documentation:
1427 * Note that for all async output, while the token is allowed by the
1428 * grammar and may be output by future versions of gdb for select async
1429 * output messages, it is generally omitted. Frontends should treat all
1430 * async output as reporting general changes in the state of the target
1431 * and there should be no need to associate async output to any prior
1432 * command.
1433 *
1434 * After further investigation, I determined that newer GDB's will no
1435 * longer ever output this information. Older GDB's will. The commit
1436 * that made this change in GDB is 721c02de on April 24th, 2008.
1437 * The next GDB that was released was on October 6th, 2009, version 7.0.
1438 *
1439 * Before the above mentioned commit async *stopped commands would
1440 * sometimes output the token associated with the last token provided in
1441 * a GDB/MI input command. After that change, the token is never
1442 * associated with an async output command, even though the
1443 * documentation says it might be.
1444 *
1445 * Finally, even before that change when the token was output in the
1446 * async *stopped command, the developers of GDB felt that it was not
1447 * useful and should be avoided by front ends.
1448 *
1449 * With this information, I've determined that front ends should never
1450 * use this value to determine logic. However, the value is parsed in
1451 * order to accurately handle and represent the cases where this value
1452 * occurs.
1453 *
1454 * This represents the token value the front end provided to the
1455 * corresponding GDB/MI input command or NULL if no token was provided.
1456 */
1457 gdbwire_mi_token_t token;
1458
1459 /** The kind of asynchronous record. */
1460 enum gdbwire_mi_async_record_kind kind;
1461
1462 /** The asynchronous output class */
1463 enum gdbwire_mi_async_class async_class;
1464
1465 /**
1466 * An optional list of results for this async output.
1467 *
1468 * Will be NULL if there is no results.
1469 */
1470 struct gdbwire_mi_result *result;
1471 };
1472
1473 /** The GDB/MI result kind */
1474 enum gdbwire_mi_result_kind {
1475 /** The result is a cstring */
1476 GDBWIRE_MI_CSTRING,
1477 /** The result is a tuple */
1478 GDBWIRE_MI_TUPLE,
1479 /** The result is a list */
1480 GDBWIRE_MI_LIST
1481 };
1482
1483 /**
1484 * A GDB/MI result list.
1485 *
1486 * This is one of the important GDB/MI data structures. GDB communicates many
1487 * of it's values to the front end through this key/value data structure.
1488 *
1489 * It is basically a list of key/value pairs, where the key is a
1490 * variable name and the value expands to a string, a tuple of results or
1491 * a list of results.
1492 *
1493 * This can be thought of as a custom json object.
1494 */
1495 struct gdbwire_mi_result {
1496 /** The kind of result this represents. */
1497 enum gdbwire_mi_result_kind kind;
1498
1499 /** The key being described by the result. */
1500 char *variable;
1501
1502 union {
1503 /** When kind is GDBWIRE_MI_CSTRING */
1504 char *cstring;
1505
1506 /**
1507 * When kind is GDBWIRE_MI_TUPLE or GDBWIRE_MI_LIST.
1508 *
1509 * If kind is GDBWIRE_MI_TUPLE, each result in the tuple should have a
1510 * valid key according to the GDB/MI specification. That is, for
1511 * each result, result->variable should not be NULL.
1512 * Note: GDBWIRE currently relaxes the above rule. It allows tuple's
1513 * with out a key in each member. For instance, {key="value"}
1514 * is what the GDB/MI specification advocates for, but some
1515 * variations of GDB emit {"value"} and so GDBWIRE allows it.
1516 *
1517 * If kind is GDBWIRE_MI_LIST, the GDB/MI specification allows
1518 * results in this list to not have keys. That is, for each result,
1519 * result->variable may be NULL.
1520 *
1521 * Will be NULL if the tuple or list is empty.
1522 */
1523 struct gdbwire_mi_result *result;
1524 } variant;
1525
1526 /** The next result or NULL if none */
1527 struct gdbwire_mi_result *next;
1528 };
1529
1530 /**
1531 * An out of band GDB/MI stream record.
1532 *
1533 * A stream record is intended to provide the front end with information
1534 * from the console, the target or from GDB itself.
1535 */
1536 struct gdbwire_mi_stream_record {
1537 /** The kind of stream record. */
1538 enum gdbwire_mi_stream_record_kind kind;
1539 /** The buffer provided in this stream record. */
1540 char *cstring;
1541 };
1542
1543 void gdbwire_mi_output_free(struct gdbwire_mi_output *param);
1544
1545 struct gdbwire_mi_output *append_gdbwire_mi_output(
1546 struct gdbwire_mi_output *list, struct gdbwire_mi_output *item);
1547
1548 struct gdbwire_mi_result *append_gdbwire_mi_result(
1549 struct gdbwire_mi_result *list, struct gdbwire_mi_result *item);
1550
1551 #ifdef __cplusplus
1552 }
1553 #endif
1554
1555 #endif
1556 /***** End of gdbwire_mi_pt.h ************************************************/
1557 /***** Continuing where we left off in gdbwire_mi_parser.h *******************/
1558
1559 /* The opaque GDB/MI parser context */
1560 struct gdbwire_mi_parser;
1561
1562 /**
1563 * The primary mechanism to alert users of GDB/MI notifications.
1564 *
1565 * The flow is like this:
1566 * - create a parser context (gdbwire_mi_parser_create)
1567 * - push onto the parser arbitrary amounts of data (gdbwire_mi_parser_push)
1568 * - receive callbacks from inside gdbwire_mi_parser_push when
1569 * it discovers callbacks the user will find interesting
1570 * - destroy the parser (gdbwire_mi_parser_destroy)
1571 */
1572 struct gdbwire_mi_parser_callbacks {
1573 /**
1574 * An arbitrary pointer to associate with the callbacks.
1575 *
1576 * If the calling api is C++ it is useful to make this an instance
1577 * of an object you want to bind to the callback functions below.
1578 */
1579 void *context;
1580
1581 /**
1582 * A GDB/MI output command is available.
1583 *
1584 * @param context
1585 * The context pointer above.
1586 *
1587 * @param output
1588 * The gdbwire_mi output command. This output command is now owned by the
1589 * function being invoked and should be destroyed when necessary.
1590 */
1591 void (*gdbwire_mi_output_callback)(void *context,
1592 struct gdbwire_mi_output *output);
1593 };
1594
1595 /**
1596 * Create a GDB/MI parser context.
1597 *
1598 * @param callbacks
1599 * The callback functions to invoke upon discovery of parse data.
1600 *
1601 * @return
1602 * A new GDB/MI parser instance or NULL on error.
1603 */
1604 struct gdbwire_mi_parser *gdbwire_mi_parser_create(
1605 struct gdbwire_mi_parser_callbacks callbacks);
1606
1607 /**
1608 * Destroy a gdbwire_mi_parser context.
1609 *
1610 * This function will do nothing if parser is NULL.
1611 *
1612 * @param parser
1613 * The instance the parser to destroy
1614 */
1615 void gdbwire_mi_parser_destroy(struct gdbwire_mi_parser *parser);
1616
1617 /**
1618 * Push a null terminated string onto the parser.
1619 *
1620 * During this function, if a gdbwire_mi output command is discovered by
1621 * the parser (or any other useful GDB/MI notification), it will invoke
1622 * the appropriate callbacks assigned during parser creation.
1623 *
1624 * @param parser
1625 * The gdbwire_mi parser context to operate on.
1626 *
1627 * @param data
1628 * The parse data to push onto the parser.
1629 *
1630 * @return
1631 * GDBWIRE_OK on success or appropriate error result on failure.
1632 */
1633 enum gdbwire_result gdbwire_mi_parser_push(struct gdbwire_mi_parser *parser,
1634 const char *data);
1635
1636 /**
1637 * Push some parse data onto the parser.
1638 *
1639 * See gdbwire_mi_parser_push for details on function behavior.
1640 *
1641 * @param parser
1642 * The gdbwire_mi parser context to operate on.
1643 *
1644 * @param data
1645 * The parse data to push onto the parser.
1646 *
1647 * @param size
1648 * The size of the data to push onto the parser.
1649 *
1650 * @return
1651 * GDBWIRE_OK on success or appropriate error result on failure.
1652 */
1653 enum gdbwire_result gdbwire_mi_parser_push_data(
1654 struct gdbwire_mi_parser *parser, const char *data, size_t size);
1655
1656 #ifdef __cplusplus
1657 }
1658 #endif
1659
1660 #endif
1661 /***** End of gdbwire_mi_parser.h ********************************************/
1662 /***** Continuing where we left off in gdbwire_mi_parser.c *******************/
1663 /* #include "gdbwire_string.h" */
1664
1665 /* flex prototypes used in this unit */
1666 #ifndef YY_TYPEDEF_YY_SCANNER_T
1667 #define YY_TYPEDEF_YY_SCANNER_T
1668 typedef void *yyscan_t;
1669 #endif
1670
1671 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
1672 #define YY_TYPEDEF_YY_BUFFER_STATE
1673 typedef struct yy_buffer_state *YY_BUFFER_STATE;
1674 #endif
1675
1676 /* Lexer set/destroy buffer to parse */
1677 extern YY_BUFFER_STATE gdbwire_mi__scan_string(
1678 const char *yy_str, yyscan_t yyscanner);
1679 extern void gdbwire_mi__delete_buffer(YY_BUFFER_STATE state,
1680 yyscan_t yyscanner);
1681
1682 /* Lexer get token function */
1683 extern int gdbwire_mi_lex(yyscan_t yyscanner);
1684 extern char *gdbwire_mi_get_text(yyscan_t yyscanner);
1685 extern void gdbwire_mi_set_column(int column_no, yyscan_t yyscanner);
1686
1687 /* Lexer state create/destroy functions */
1688 extern int gdbwire_mi_lex_init(yyscan_t *scanner);
1689 extern int gdbwire_mi_lex_destroy(yyscan_t scanner);
1690
1691 struct gdbwire_mi_parser {
1692 /* The buffer pushed into the parser from the user */
1693 struct gdbwire_string *buffer;
1694 /* The GDB/MI lexer state */
1695 yyscan_t mils;
1696 /* The GDB/MI push parser state */
1697 gdbwire_mi_pstate *mipst;
1698 /* The client parser callbacks */
1699 struct gdbwire_mi_parser_callbacks callbacks;
1700 };
1701
1702 struct gdbwire_mi_parser *
gdbwire_mi_parser_create(struct gdbwire_mi_parser_callbacks callbacks)1703 gdbwire_mi_parser_create(struct gdbwire_mi_parser_callbacks callbacks)
1704 {
1705 struct gdbwire_mi_parser *parser;
1706
1707 parser = (struct gdbwire_mi_parser *)calloc(1,
1708 sizeof(struct gdbwire_mi_parser));
1709 if (!parser) {
1710 return NULL;
1711 }
1712
1713 /* Create a new buffer for the user to push parse data into */
1714 parser->buffer = gdbwire_string_create();
1715 if (!parser->buffer) {
1716 free(parser);
1717 return NULL;
1718 }
1719
1720 /* Create a new lexer state instance */
1721 if (gdbwire_mi_lex_init(&parser->mils) != 0) {
1722 gdbwire_string_destroy(parser->buffer);
1723 free(parser);
1724 return NULL;
1725 }
1726
1727 /* Create a new push parser state instance */
1728 parser->mipst = gdbwire_mi_pstate_new();
1729 if (!parser->mipst) {
1730 gdbwire_mi_lex_destroy(parser->mils);
1731 gdbwire_string_destroy(parser->buffer);
1732 free(parser);
1733 return NULL;
1734 }
1735
1736 /* Ensure that the callbacks are non null */
1737 if (!callbacks.gdbwire_mi_output_callback) {
1738 gdbwire_mi_pstate_delete(parser->mipst);
1739 gdbwire_mi_lex_destroy(parser->mils);
1740 gdbwire_string_destroy(parser->buffer);
1741 free(parser);
1742 return NULL;
1743 }
1744
1745 parser->callbacks = callbacks;
1746
1747 return parser;
1748 }
1749
gdbwire_mi_parser_destroy(struct gdbwire_mi_parser * parser)1750 void gdbwire_mi_parser_destroy(struct gdbwire_mi_parser *parser)
1751 {
1752 if (parser) {
1753 /* Free the parse buffer */
1754 if (parser->buffer) {
1755 gdbwire_string_destroy(parser->buffer);
1756 parser->buffer = NULL;
1757 }
1758
1759 /* Free the lexer instance */
1760 if (parser->mils) {
1761 gdbwire_mi_lex_destroy(parser->mils);
1762 parser->mils = 0;
1763 }
1764
1765 /* Free the push parser instance */
1766 if (parser->mipst) {
1767 gdbwire_mi_pstate_delete(parser->mipst);
1768 parser->mipst = NULL;
1769 }
1770
1771 free(parser);
1772 parser = NULL;
1773 }
1774 }
1775
1776 static struct gdbwire_mi_parser_callbacks
gdbwire_mi_parser_get_callbacks(struct gdbwire_mi_parser * parser)1777 gdbwire_mi_parser_get_callbacks(struct gdbwire_mi_parser *parser)
1778 {
1779 return parser->callbacks;
1780 }
1781
1782 /**
1783 * Parse a single line of output in GDB/MI format.
1784 *
1785 * The normal usage of this function is to call it over and over again with
1786 * more data lines and wait for it to return an mi output command.
1787 *
1788 * @param parser
1789 * The parser context to operate on.
1790 *
1791 * @param line
1792 * A line of output in GDB/MI format to be parsed.
1793 *
1794 * \return
1795 * GDBWIRE_OK on success or appropriate error result on failure.
1796 */
1797 static enum gdbwire_result
gdbwire_mi_parser_parse_line(struct gdbwire_mi_parser * parser,const char * line)1798 gdbwire_mi_parser_parse_line(struct gdbwire_mi_parser *parser,
1799 const char *line)
1800 {
1801 struct gdbwire_mi_parser_callbacks callbacks =
1802 gdbwire_mi_parser_get_callbacks(parser);
1803 struct gdbwire_mi_output *output = 0;
1804 YY_BUFFER_STATE state = 0;
1805 int pattern, mi_status;
1806
1807 GDBWIRE_ASSERT(parser && line);
1808
1809 /* Create a new input buffer for flex. */
1810 state = gdbwire_mi__scan_string(line, parser->mils);
1811 GDBWIRE_ASSERT(state);
1812 gdbwire_mi_set_column(1, parser->mils);
1813
1814 /* Iterate over all the tokens found in the scanner buffer */
1815 do {
1816 pattern = gdbwire_mi_lex(parser->mils);
1817 if (pattern == 0)
1818 break;
1819 mi_status = gdbwire_mi_push_parse(parser->mipst, pattern, NULL,
1820 parser->mils, &output);
1821 } while (mi_status == YYPUSH_MORE);
1822
1823 /* Free the scanners buffer */
1824 gdbwire_mi__delete_buffer(state, parser->mils);
1825
1826 /**
1827 * The push parser will return,
1828 * - 0 if parsing was successful (return is due to end-of-input).
1829 * - 1 if parsing failed because of invalid input, i.e., input
1830 * that contains a syntax error or that causes YYABORT to be invoked.
1831 * - 2 if parsing failed due to memory exhaustion.
1832 * - YYPUSH_MORE if more input is required to finish parsing the grammar.
1833 * Anything besides this would be unexpected.
1834 *
1835 * The grammar is designed to accept an infinate list of GDB/MI
1836 * output commands. For this reason, YYPUSH_MORE is the expected
1837 * return value of all the calls to gdbwire_mi_push_parse. However,
1838 * in reality, gdbwire only translates a line at a time from GDB.
1839 * When the line is finished, gdbwire_mi_lex returns 0, and the parsing
1840 * is done.
1841 */
1842
1843 /* Check mi_status, will be 1 on parse error, and YYPUSH_MORE on success */
1844 GDBWIRE_ASSERT(mi_status == 1 || mi_status == YYPUSH_MORE);
1845
1846 /* Each GDB/MI line should produce an output command */
1847 GDBWIRE_ASSERT(output);
1848 output->line = gdbwire_strdup(line);
1849
1850 callbacks.gdbwire_mi_output_callback(callbacks.context, output);
1851
1852 return GDBWIRE_OK;
1853 }
1854
1855 /**
1856 * Get the next line available in the buffer.
1857 *
1858 * @param buffer
1859 * The entire buffer the user has pushed onto the gdbwire_mi parser
1860 * through gdbwire_mi_parser_push. If a line is found, the returned line
1861 * will be removed from this buffer.
1862 *
1863 * @param line
1864 * Will return as an allocated line if a line is available or NULL
1865 * otherwise. If this function does not return GDBWIRE_OK then ignore
1866 * the output of this parameter. It is the callers responsibility to
1867 * free the memory.
1868 *
1869 * @return
1870 * GDBWIRE_OK on success or appropriate error result on failure.
1871 */
1872 static enum gdbwire_result
gdbwire_mi_parser_get_next_line(struct gdbwire_string * buffer,struct gdbwire_string ** line)1873 gdbwire_mi_parser_get_next_line(struct gdbwire_string *buffer,
1874 struct gdbwire_string **line)
1875 {
1876 enum gdbwire_result result = GDBWIRE_OK;
1877
1878 GDBWIRE_ASSERT(buffer && line);
1879
1880 char *data = gdbwire_string_data(buffer);
1881 size_t size = gdbwire_string_size(buffer);
1882 size_t pos = gdbwire_string_find_first_of(buffer, "\r\n");
1883
1884 /**
1885 * Search to see if a newline has been reached in gdb/mi.
1886 * If a line of data has been recieved, process it.
1887 */
1888 if (pos != size) {
1889 int status;
1890
1891 /**
1892 * We have the position of the newline character from
1893 * gdbwire_string_find_first_of. However, the length must be
1894 * calculated to make a copy of the line.
1895 *
1896 * This is either pos + 1 (for \r or \n) or pos + 1 + 1 for (\r\n).
1897 * Check for\r\n for the special case.
1898 */
1899 size_t line_length = (data[pos] == '\r' && (pos + 1 < size) &&
1900 data[pos + 1] == '\n') ? pos + 2 : pos + 1;
1901
1902 /**
1903 * - allocate the buffer
1904 * - append the new line
1905 * - append a null terminating character
1906 * - if successful, delete the new line found from buffer
1907 * - any failures cleanup and return an error
1908 */
1909 *line = gdbwire_string_create();
1910 GDBWIRE_ASSERT(*line);
1911
1912 status = gdbwire_string_append_data(*line, data, line_length);
1913 GDBWIRE_ASSERT_GOTO(status == 0, result, cleanup);
1914
1915 status = gdbwire_string_append_data(*line, "\0", 1);
1916 GDBWIRE_ASSERT_GOTO(status == 0, result, cleanup);
1917
1918 status = gdbwire_string_erase(buffer, 0, line_length);
1919 GDBWIRE_ASSERT_GOTO(status == 0, result, cleanup);
1920 }
1921
1922 return result;
1923
1924 cleanup:
1925 gdbwire_string_destroy(*line);
1926 *line = 0;
1927 return result;
1928
1929 }
1930
1931 enum gdbwire_result
gdbwire_mi_parser_push(struct gdbwire_mi_parser * parser,const char * data)1932 gdbwire_mi_parser_push(struct gdbwire_mi_parser *parser, const char *data)
1933 {
1934 return gdbwire_mi_parser_push_data(parser, data, strlen(data));
1935 }
1936
1937 enum gdbwire_result
gdbwire_mi_parser_push_data(struct gdbwire_mi_parser * parser,const char * data,size_t size)1938 gdbwire_mi_parser_push_data(struct gdbwire_mi_parser *parser, const char *data,
1939 size_t size)
1940 {
1941 struct gdbwire_string *line = 0;
1942 enum gdbwire_result result = GDBWIRE_OK;
1943 int has_newline = 0;
1944 size_t index;
1945
1946 GDBWIRE_ASSERT(parser && data);
1947
1948 /**
1949 * No need to parse an MI command until a newline occurs.
1950 *
1951 * A gdb/mi command may be a very long line. For this reason, it is
1952 * better to check the data passed into this function once for a newline
1953 * rather than checking all the data every time this function is called.
1954 * This optimizes the case where this function is called one character
1955 * at a time.
1956 */
1957 for (index = size; index > 0; --index) {
1958 if (data[index-1] == '\n' || data[index-1] == '\r') {
1959 has_newline = 1;
1960 break;
1961 }
1962 }
1963
1964 GDBWIRE_ASSERT(gdbwire_string_append_data(parser->buffer, data, size) == 0);
1965
1966 if (has_newline) {
1967 for (;;) {
1968 result = gdbwire_mi_parser_get_next_line(parser->buffer, &line);
1969 GDBWIRE_ASSERT_GOTO(result == GDBWIRE_OK, result, cleanup);
1970
1971 if (line) {
1972 result = gdbwire_mi_parser_parse_line(parser,
1973 gdbwire_string_data(line));
1974 gdbwire_string_destroy(line);
1975 line = 0;
1976 GDBWIRE_ASSERT_GOTO(result == GDBWIRE_OK, result, cleanup);
1977 } else {
1978 break;
1979 }
1980 }
1981 }
1982
1983 cleanup:
1984 return result;
1985 }
1986 /***** End of gdbwire_mi_parser.c ********************************************/
1987 /***** Begin file gdbwire_mi_pt_alloc.c **************************************/
1988 #include <stdlib.h>
1989
1990 /* #include "gdbwire_mi_pt.h" */
1991 /***** Include gdbwire_mi_pt_alloc.h in the middle of gdbwire_mi_pt_alloc.c **/
1992 /***** Begin file gdbwire_mi_pt_alloc.h **************************************/
1993 #ifndef GDBWIRE_MI_PT_ALLOC_H
1994 #define GDBWIRE_MI_PT_ALLOC_H
1995
1996 #ifdef __cplusplus
1997 extern "C" {
1998 #endif
1999
2000 /**
2001 * Responsible for allocating and deallocating gdbwire_mi_pt objects.
2002 */
2003
2004 /* struct gdbwire_mi_output */
2005 struct gdbwire_mi_output *gdbwire_mi_output_alloc(void);
2006 void gdbwire_mi_output_free(struct gdbwire_mi_output *param);
2007
2008 /* struct gdbwire_mi_result_record */
2009 struct gdbwire_mi_result_record *gdbwire_mi_result_record_alloc(void);
2010 void gdbwire_mi_result_record_free(struct gdbwire_mi_result_record *param);
2011
2012 /* struct gdbwire_mi_result */
2013 struct gdbwire_mi_result *gdbwire_mi_result_alloc(void);
2014 void gdbwire_mi_result_free(struct gdbwire_mi_result *param);
2015
2016 /* struct gdbwire_mi_oob_record */
2017 struct gdbwire_mi_oob_record *gdbwire_mi_oob_record_alloc(void);
2018 void gdbwire_mi_oob_record_free(struct gdbwire_mi_oob_record *param);
2019
2020 /* struct gdbwire_mi_async_record */
2021 struct gdbwire_mi_async_record *gdbwire_mi_async_record_alloc(void);
2022 void gdbwire_mi_async_record_free(struct gdbwire_mi_async_record *param);
2023
2024 /* struct gdbwire_mi_stream_record */
2025 struct gdbwire_mi_stream_record *gdbwire_mi_stream_record_alloc(void);
2026 void gdbwire_mi_stream_record_free(struct gdbwire_mi_stream_record *param);
2027
2028 #ifdef __cplusplus
2029 }
2030 #endif
2031
2032 #endif /* GDBWIRE_MI_PT_ALLOC_H */
2033 /***** End of gdbwire_mi_pt_alloc.h ******************************************/
2034 /***** Continuing where we left off in gdbwire_mi_pt_alloc.c *****************/
2035
2036 /* struct gdbwire_mi_output */
2037 struct gdbwire_mi_output *
gdbwire_mi_output_alloc(void)2038 gdbwire_mi_output_alloc(void)
2039 {
2040 return calloc(1, sizeof (struct gdbwire_mi_output));
2041 }
2042
2043 void
gdbwire_mi_output_free(struct gdbwire_mi_output * param)2044 gdbwire_mi_output_free(struct gdbwire_mi_output *param)
2045 {
2046 if (param) {
2047 switch (param->kind) {
2048 case GDBWIRE_MI_OUTPUT_OOB:
2049 gdbwire_mi_oob_record_free(param->variant.oob_record);
2050 param->variant.oob_record = NULL;
2051 break;
2052 case GDBWIRE_MI_OUTPUT_RESULT:
2053 gdbwire_mi_result_record_free(param->variant.result_record);
2054 param->variant.result_record = NULL;
2055 break;
2056 case GDBWIRE_MI_OUTPUT_PROMPT:
2057 break;
2058 case GDBWIRE_MI_OUTPUT_PARSE_ERROR:
2059 free(param->variant.error.token);
2060 param->variant.error.token = NULL;
2061 break;
2062 }
2063
2064 free(param->line);
2065 param->line = 0;
2066
2067 gdbwire_mi_output_free(param->next);
2068 param->next = NULL;
2069
2070 free(param);
2071 param = NULL;
2072 }
2073 }
2074
2075 /* struct gdbwire_mi_result_record */
2076 struct gdbwire_mi_result_record *
gdbwire_mi_result_record_alloc(void)2077 gdbwire_mi_result_record_alloc(void)
2078 {
2079 return calloc(1, sizeof (struct gdbwire_mi_result_record));
2080 }
2081
2082 void
gdbwire_mi_result_record_free(struct gdbwire_mi_result_record * param)2083 gdbwire_mi_result_record_free(struct gdbwire_mi_result_record *param)
2084 {
2085 if (param) {
2086 free(param->token);
2087
2088 gdbwire_mi_result_free(param->result);
2089 param->result = NULL;
2090
2091 free(param);
2092 param = NULL;
2093 }
2094 }
2095
2096 /* struct gdbwire_mi_result */
2097 struct gdbwire_mi_result *
gdbwire_mi_result_alloc(void)2098 gdbwire_mi_result_alloc(void)
2099 {
2100 return calloc(1, sizeof (struct gdbwire_mi_result));
2101 }
2102
2103 void
gdbwire_mi_result_free(struct gdbwire_mi_result * param)2104 gdbwire_mi_result_free(struct gdbwire_mi_result *param)
2105 {
2106 if (param) {
2107 if (param->variable) {
2108 free(param->variable);
2109 param->variable = NULL;
2110 }
2111
2112 switch (param->kind) {
2113 case GDBWIRE_MI_CSTRING:
2114 if (param->variant.cstring) {
2115 free(param->variant.cstring);
2116 param->variant.cstring = NULL;
2117 }
2118 break;
2119 case GDBWIRE_MI_TUPLE:
2120 case GDBWIRE_MI_LIST:
2121 gdbwire_mi_result_free(param->variant.result);
2122 param->variant.result = NULL;
2123 break;
2124 }
2125
2126 gdbwire_mi_result_free(param->next);
2127 param->next = NULL;
2128
2129 free(param);
2130 param = NULL;
2131 }
2132 }
2133
2134 /* struct gdbwire_mi_oob_record */
2135 struct gdbwire_mi_oob_record *
gdbwire_mi_oob_record_alloc(void)2136 gdbwire_mi_oob_record_alloc(void)
2137 {
2138 return calloc(1, sizeof (struct gdbwire_mi_oob_record));
2139 }
2140
2141 void
gdbwire_mi_oob_record_free(struct gdbwire_mi_oob_record * param)2142 gdbwire_mi_oob_record_free(struct gdbwire_mi_oob_record *param)
2143 {
2144 if (param) {
2145 switch(param->kind) {
2146 case GDBWIRE_MI_ASYNC:
2147 gdbwire_mi_async_record_free(param->variant.async_record);
2148 param->variant.async_record = NULL;
2149 break;
2150 case GDBWIRE_MI_STREAM:
2151 gdbwire_mi_stream_record_free(param->variant.stream_record);
2152 param->variant.stream_record = NULL;
2153 break;
2154 }
2155
2156 free(param);
2157 param = NULL;
2158 }
2159 }
2160
2161 /* struct gdbwire_mi_async_record */
2162 struct gdbwire_mi_async_record *
gdbwire_mi_async_record_alloc(void)2163 gdbwire_mi_async_record_alloc(void)
2164 {
2165 return calloc(1, sizeof (struct gdbwire_mi_async_record));
2166 }
2167
2168 void
gdbwire_mi_async_record_free(struct gdbwire_mi_async_record * param)2169 gdbwire_mi_async_record_free(struct gdbwire_mi_async_record *param)
2170 {
2171 if (param) {
2172 free(param->token);
2173
2174 gdbwire_mi_result_free(param->result);
2175 param->result = NULL;
2176
2177 free(param);
2178 param = NULL;
2179 }
2180 }
2181
2182 /* struct gdbwire_mi_stream_record */
2183 struct gdbwire_mi_stream_record *
gdbwire_mi_stream_record_alloc(void)2184 gdbwire_mi_stream_record_alloc(void)
2185 {
2186 return calloc(1, sizeof (struct gdbwire_mi_stream_record));
2187 }
2188
2189 void
gdbwire_mi_stream_record_free(struct gdbwire_mi_stream_record * param)2190 gdbwire_mi_stream_record_free(struct gdbwire_mi_stream_record *param)
2191 {
2192 if (param) {
2193 if (param->cstring) {
2194 free(param->cstring);
2195 param->cstring = NULL;
2196 }
2197
2198 free(param);
2199 param = NULL;
2200 }
2201 }
2202 /***** End of gdbwire_mi_pt_alloc.c ******************************************/
2203 /***** Begin file gdbwire_mi_pt.c ********************************************/
2204 #include <stdio.h>
2205 #include <stdlib.h>
2206
2207 /* #include "gdbwire_mi_pt.h" */
2208
2209 struct gdbwire_mi_output *
append_gdbwire_mi_output(struct gdbwire_mi_output * list,struct gdbwire_mi_output * item)2210 append_gdbwire_mi_output(struct gdbwire_mi_output *list,
2211 struct gdbwire_mi_output *item)
2212 {
2213 if (!item)
2214 return NULL;
2215
2216 if (!list)
2217 list = item;
2218 else {
2219 struct gdbwire_mi_output *cur = list;
2220
2221 while (cur->next)
2222 cur = cur->next;
2223
2224 cur->next = item;
2225 }
2226
2227 return list;
2228 }
2229
2230 struct gdbwire_mi_result *
append_gdbwire_mi_result(struct gdbwire_mi_result * list,struct gdbwire_mi_result * item)2231 append_gdbwire_mi_result(struct gdbwire_mi_result *list,
2232 struct gdbwire_mi_result *item)
2233 {
2234 if (!item)
2235 return NULL;
2236
2237 if (!list)
2238 list = item;
2239 else {
2240 struct gdbwire_mi_result *cur = list;
2241
2242 while (cur->next)
2243 cur = cur->next;
2244
2245 cur->next = item;
2246 }
2247
2248 return list;
2249 }
2250 /***** End of gdbwire_mi_pt.c ************************************************/
2251 /***** Begin file gdbwire_mi_command.c ***************************************/
2252 #include <stdlib.h>
2253 #include <string.h>
2254 #include <errno.h>
2255
2256 /* #include "gdbwire_sys.h" */
2257 /* #include "gdbwire_assert.h" */
2258 /***** Include gdbwire_mi_command.h in the middle of gdbwire_mi_command.c ****/
2259 /***** Begin file gdbwire_mi_command.h ***************************************/
2260 #ifndef GDBWIRE_MI_COMMAND_H
2261 #define GDBWIRE_MI_COMMAND_H
2262
2263 #ifdef __cplusplus
2264 extern "C" {
2265 #endif
2266
2267 /* #include "gdbwire_result.h" */
2268 /* #include "gdbwire_mi_pt.h" */
2269
2270 /**
2271 * An enumeration representing the supported GDB/MI commands.
2272 */
2273 enum gdbwire_mi_command_kind {
2274 /* -break-info */
2275 GDBWIRE_MI_BREAK_INFO,
2276
2277 /* -stack-info-frame */
2278 GDBWIRE_MI_STACK_INFO_FRAME,
2279
2280 /* -file-list-exec-source-file */
2281 GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILE,
2282 /* -file-list-exec-source-files */
2283 GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILES
2284 };
2285
2286 /** A linked list of source files. */
2287 struct gdbwire_mi_source_file {
2288 /** A relative path to a file, never NULL */
2289 char *file;
2290 /**An absolute path to a file, NULL if unavailable */
2291 char *fullname;
2292 /** The next file name or NULL if no more. */
2293 struct gdbwire_mi_source_file *next;
2294 };
2295
2296 /** The disposition of a breakpoint. What to do after hitting it. */
2297 enum gdbwire_mi_breakpoint_disp_kind {
2298 GDBWIRE_MI_BP_DISP_DELETE, /** Delete on next hit */
2299 GDBWIRE_MI_BP_DISP_DELETE_NEXT_STOP, /** Delete on next stop, hit or not */
2300 GDBWIRE_MI_BP_DISP_DISABLE, /** Disable on next hit */
2301 GDBWIRE_MI_BP_DISP_KEEP, /** Leave the breakpoint in place */
2302 GDBWIRE_MI_BP_DISP_UNKNOWN /** When GDB doesn't specify */
2303 };
2304
2305 /**
2306 * A linked list of breakpoints.
2307 *
2308 * A breakpoint is a breakpoint, a tracepoint, a watchpoing or a
2309 * catchpoint. The GDB breakpoint model is quite sophisticated.
2310 * This structure can be extended when necessary.
2311 */
2312 struct gdbwire_mi_breakpoint {
2313 /**
2314 * The breakpoint number.
2315 *
2316 * An integer, however, for a breakpoint that represents one location of
2317 * a multiple location breakpoint, this will be a dotted pair, like ‘1.2’.
2318 *
2319 * Never NULL.
2320 */
2321 char *number;
2322
2323 /**
2324 * Determines if this is a multiple location breakpoint.
2325 *
2326 * True for a multi-location breakpoint, false otherwise.
2327 *
2328 * It is possible that a breakpoint corresponds to several locations in
2329 * your program. For example, several functions may have the same name.
2330 * For the following source code,
2331 * int foo(int p) { return p; }
2332 * double foo(double p) { return p; }
2333 * int main() { int i = 1; double d = 2.3; return foo(i) + foo(d); }
2334 * If the user sets a breakpoint at foo by typing,
2335 * b foo
2336 * Then gdb will create 3 breakpoints. The multiple location breakpoint,
2337 * which is the parent of the two breakpoints created for each foo
2338 * function. Here is the output of gdb from the CLI perspective,
2339 * Num Type Disp Enb Address What
2340 * 1 breakpoint keep y <MULTIPLE>
2341 * 1.1 y 0x4004dd in foo(int) at main.cpp:1
2342 * 1.2 y 0x4004eb in foo(double) at main.cpp:2
2343 *
2344 * However, if the user created a breakpoint for main by typing,
2345 * b main
2346 * Then gdb will only create a single breakpoint which would look like,
2347 * 1 breakpoint keep y 0x4004fa in main() at main.cpp:3
2348 *
2349 * When this is true, the address field will be "<MULTIPLE>" and
2350 * the field multi_breakpoints will represent the breakpoints that this
2351 * multiple location breakpoint has created.
2352 */
2353 unsigned char multi:1;
2354
2355 /**
2356 * True for breakpoints of a multi-location breakpoint, otherwise false.
2357 *
2358 * For the example above, 1.1 and 1.2 would have this field set true.
2359 *
2360 * When this is true, the field multi_breakpoint will represent
2361 * the multiple location breakpoint that has created this breakpoint.
2362 */
2363 unsigned char from_multi:1;
2364
2365 /**
2366 * The breakpoint type.
2367 *
2368 * Typically "breakpoint", "watchpoint" or "catchpoint", but can be
2369 * a variety of different values. In gdb, see breakpoint.c:bptype_string
2370 * to see all the different possibilities.
2371 *
2372 * This will be NULL for breakpoints of a multiple location breakpoint.
2373 * In this circumstance, check the multi_breakpoint field for the
2374 * multiple location breakpoint type field.
2375 */
2376 char *type;
2377
2378 /**
2379 * The type of the catchpoint or NULL if not a catch point.
2380 *
2381 * This field is only valid when the breakpoint is a catchpoint.
2382 * Unfortuntely, gdb says the "type" of the breakpoint in the type field
2383 * is "breakpoint" not "catchpoint". So if this field is non-NULL, it is
2384 * safe to assume that this breakpoint represents at catch point.
2385 */
2386 char *catch_type;
2387
2388 /**
2389 * The breakpoint disposition.
2390 *
2391 * For multiple location breakpoints, this will be
2392 * GDBWIRE_MI_BP_DISP_UNKNOWN. In this circumstance, check the
2393 * multi_breakpoint field for the multiple location breakpoint
2394 * disposition field.
2395 */
2396 enum gdbwire_mi_breakpoint_disp_kind disposition;
2397
2398 /** True if enabled or False if disabled. */
2399 unsigned char enabled:1;
2400
2401 /**
2402 * The address of the breakpoint.
2403 *
2404 * This may be
2405 * - a hexidecimal number, representing the address
2406 * - the string ‘<PENDING>’ for a pending breakpoint
2407 * - the string ‘<MULTIPLE>’ for a breakpoint with multiple locations
2408 *
2409 * This field will be NULL if no address can be determined.
2410 * For example, a watchpoint does not have an address.
2411 */
2412 char *address;
2413
2414 /**
2415 * The name of the function or NULL if unknown.
2416 */
2417 char *func_name;
2418
2419 /**
2420 * A relative path to the file the breakpoint is in or NULL if unknown.
2421 */
2422 char *file;
2423
2424 /**
2425 * An absolute path to the file the breakpoint is in or NULL if unknown.
2426 */
2427 char *fullname;
2428
2429 /**
2430 * The line number the breakpoint is at or 0 if unkonwn.
2431 */
2432 unsigned long line;
2433
2434 /**
2435 * The number of times this breakpoint has been hit.
2436 *
2437 * For breakpoints of multi-location breakpoints, this will be 0.
2438 * Look at the multi-location breakpoint field instead.
2439 */
2440 unsigned long times;
2441
2442 /**
2443 * The location of the breakpoint as originally specified by the user.
2444 *
2445 * This may be NULL for instance, for breakpoints for multi-breakpoints.
2446 */
2447 char *original_location;
2448
2449 /**
2450 * True for a pending breakpoint, otherwise false.
2451 *
2452 * When this is true, the address field will be "<PENDING>".
2453 */
2454 unsigned char pending:1;
2455
2456 /**
2457 * The breakpoints for a multi-location breakpoint.
2458 *
2459 * If multi is true, this will be the breakpoints associated with the
2460 * multiple location breakpoint. Otherwise will be NULL.
2461 */
2462 struct gdbwire_mi_breakpoint *multi_breakpoints;
2463
2464 /**
2465 * A pointer to the multi location breakpoint that created this breakpoint.
2466 *
2467 * When the field from_multi is true, this will be a pointer to the
2468 * multi-location breakpoint that created this breakpoint. Otherwise NULL.
2469 *
2470 * For the example above in the multi field, breakpoints 1.1 and 1.2
2471 * would have this field pointing to the breakpoint 1.
2472 */
2473 struct gdbwire_mi_breakpoint *multi_breakpoint;
2474
2475
2476 /** The next breakpoint or NULL if no more. */
2477 struct gdbwire_mi_breakpoint *next;
2478 };
2479
2480 struct gdbwire_mi_stack_frame {
2481 /**
2482 * The frame number.
2483 *
2484 * Where 0 is the topmost frame, i.e., the innermost function.
2485 *
2486 * Always present.
2487 */
2488 unsigned level;
2489
2490 /**
2491 * The address ($pc value) of the frame.
2492 *
2493 * May be NULL if GDB can not determine the frame address.
2494 */
2495 char *address;
2496
2497 /**
2498 * The function name for the frame. May be NULL if unknown.
2499 */
2500 char *func;
2501
2502 /**
2503 * The file name for the frame. May be NULL if unknown.
2504 */
2505 char *file;
2506
2507 /**
2508 * The fullname name for the frame. May be NULL if unknown.
2509 */
2510 char *fullname;
2511
2512 /**
2513 * Line number corresponding to the $pc. Maybe be 0 if unknown.
2514 */
2515 int line;
2516
2517 /**
2518 * The shared library where this function is defined.
2519 *
2520 * This is only given if the frame's function is not known.
2521 * May be NULL if unknown.
2522 */
2523 char *from;
2524 };
2525
2526 /**
2527 * Represents a GDB/MI command.
2528 */
2529 struct gdbwire_mi_command {
2530 /**
2531 * The kind of mi command this represents.
2532 */
2533 enum gdbwire_mi_command_kind kind;
2534
2535 union {
2536 /** When kind == GDBWIRE_MI_BREAK_INFO */
2537 struct {
2538 /** The list of breakpoints, NULL if none exist. */
2539 struct gdbwire_mi_breakpoint *breakpoints;
2540 } break_info;
2541
2542 /** When kind == GDBWIRE_MI_STACK_INFO_FRAME */
2543 struct {
2544 struct gdbwire_mi_stack_frame *frame;
2545 } stack_info_frame;
2546
2547 /** When kind == GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILE */
2548 struct {
2549 /**
2550 * The line number the inferior is currently executing at.
2551 */
2552 int line;
2553
2554 /**
2555 * The filename the inferior is currently executing at.
2556 *
2557 * This is usually a relative path.
2558 */
2559 char *file;
2560
2561 /**
2562 * The filename the inferior is currently executing at.
2563 *
2564 * This is an absolute path.
2565 *
2566 * This command was addd in 2004, however, it was possible
2567 * at the time that only the "file" field would be put out and
2568 * the "fullname" field would be omitted. In 2012, in git commit,
2569 * f35a17b5, gdb was changed to always omit the "fullname" field.
2570 */
2571 char *fullname;
2572
2573 /**
2574 * Determines if the file includes preprocessor macro information.
2575 *
2576 * This command was added in 2004. However, the macro-info
2577 * field was added to the output in 2008 in git commit 17784837.
2578 *
2579 * Only check this field if macro_info_exists is true.
2580 */
2581 char macro_info:1;
2582
2583 /** True if macro-info field was in mi output, otherwise false */
2584 char macro_info_exists:1;
2585 } file_list_exec_source_file;
2586
2587 /** When kind == GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILES */
2588 struct {
2589 /**
2590 * A list of files that make up the inferior.
2591 *
2592 * When there are no files (if the gdb does not have an inferior
2593 * loaded) than files will be NULL.
2594 *
2595 * This command was addd in 2004, however, it was possible
2596 * at the time that only the "file" field would be put out and
2597 * the "fullname" field would be omitted. In 2012, in git commit,
2598 * f35a17b5, gdb was changed to always omit the "fullname" field.
2599 */
2600 struct gdbwire_mi_source_file *files;
2601 } file_list_exec_source_files;
2602
2603 } variant;
2604 };
2605
2606 /**
2607 * Get a gdbwire MI command from the result record.
2608 *
2609 * @param kind
2610 * The kind of command the result record is associated with.
2611 *
2612 * @param result_record
2613 * The result record to turn into a command.
2614 *
2615 * @param out_mi_command
2616 * Will return an allocated gdbwire mi command if GDBWIRE_OK is returned
2617 * from this function. You should free this memory with
2618 * gdbwire_mi_command_free when you are done with it.
2619 *
2620 * @return
2621 * The result of this function.
2622 */
2623 enum gdbwire_result gdbwire_get_mi_command(
2624 enum gdbwire_mi_command_kind kind,
2625 struct gdbwire_mi_result_record *result_record,
2626 struct gdbwire_mi_command **out_mi_command);
2627
2628 /**
2629 * Free the gdbwire mi command.
2630 *
2631 * @param mi_command
2632 * The mi command to free.
2633 */
2634 void gdbwire_mi_command_free(struct gdbwire_mi_command *mi_command);
2635
2636 #ifdef __cplusplus
2637 }
2638 #endif
2639
2640 #endif
2641 /***** End of gdbwire_mi_command.h *******************************************/
2642 /***** Continuing where we left off in gdbwire_mi_command.c ******************/
2643
2644 /**
2645 * Free a source file list.
2646 *
2647 * @param files
2648 * The source file list to free, OK to pass in NULL.
2649 */
2650 static void
gdbwire_mi_source_files_free(struct gdbwire_mi_source_file * files)2651 gdbwire_mi_source_files_free(struct gdbwire_mi_source_file *files)
2652 {
2653 struct gdbwire_mi_source_file *tmp, *cur = files;
2654 while (cur) {
2655 free(cur->file);
2656 free(cur->fullname);
2657 tmp = cur;
2658 cur = cur->next;
2659 free(tmp);
2660 }
2661 }
2662
2663 /**
2664 * Free a breakpoint list.
2665 *
2666 * @param breakpoints
2667 * The breakpoint list to free, OK to pass in NULL.
2668 */
2669 static void
gdbwire_mi_breakpoints_free(struct gdbwire_mi_breakpoint * breakpoints)2670 gdbwire_mi_breakpoints_free(struct gdbwire_mi_breakpoint *breakpoints)
2671 {
2672 struct gdbwire_mi_breakpoint *tmp, *cur = breakpoints;
2673 while (cur) {
2674 free(cur->original_location);
2675 free(cur->fullname);
2676 free(cur->file);
2677 free(cur->func_name);
2678 free(cur->address);
2679 free(cur->catch_type);
2680 free(cur->type);
2681 free(cur->number);
2682
2683 gdbwire_mi_breakpoints_free(cur->multi_breakpoints);
2684 cur->multi_breakpoint = 0;
2685
2686 tmp = cur;
2687 cur = cur->next;
2688 free(tmp);
2689 }
2690 }
2691
2692 /**
2693 * Free a stack frame.
2694 *
2695 * @param frame
2696 * The frame to free, OK to pass in NULL.
2697 */
2698 static void
gdbwire_mi_stack_frame_free(struct gdbwire_mi_stack_frame * frame)2699 gdbwire_mi_stack_frame_free(struct gdbwire_mi_stack_frame *frame)
2700 {
2701 free(frame->address);
2702 free(frame->func);
2703 free(frame->file);
2704 free(frame->fullname);
2705 free(frame->from);
2706 free(frame);
2707 }
2708
2709 /**
2710 * Convert a string to an unsigned long.
2711 *
2712 * @param str
2713 * The string to convert.
2714 *
2715 * @param num
2716 * If GDBWIRE_OK is returned, this will be returned as the number.
2717 *
2718 * @return
2719 * GDBWIRE_OK on success, and num is valid, or GDBWIRE_LOGIC on failure.
2720 */
2721 static enum gdbwire_result
gdbwire_string_to_ulong(char * str,unsigned long * num)2722 gdbwire_string_to_ulong(char *str, unsigned long *num)
2723 {
2724 enum gdbwire_result result = GDBWIRE_LOGIC;
2725 unsigned long int strtol_result;
2726 char *end_ptr;
2727
2728 GDBWIRE_ASSERT(str);
2729 GDBWIRE_ASSERT(num);
2730
2731 errno = 0;
2732 strtol_result = strtoul(str, &end_ptr, 10);
2733 if (errno == 0 && str != end_ptr && *end_ptr == '\0') {
2734 *num = strtol_result;
2735 result = GDBWIRE_OK;
2736 }
2737
2738 return result;
2739 }
2740
2741 /**
2742 * Handle breakpoints from the -break-info command.
2743 *
2744 * @param mi_result
2745 * The mi parse tree starting from bkpt={...}
2746 *
2747 * @param bkpt
2748 * Allocated breakpoint on way out on success. Otherwise NULL on way out.
2749 *
2750 * @return
2751 * GDBWIRE_OK on success and bkpt is an allocated breakpoint. Otherwise
2752 * the appropriate error code and bkpt will be NULL.
2753 */
2754 static enum gdbwire_result
break_info_for_breakpoint(struct gdbwire_mi_result * mi_result,struct gdbwire_mi_breakpoint ** bkpt)2755 break_info_for_breakpoint(struct gdbwire_mi_result *mi_result,
2756 struct gdbwire_mi_breakpoint **bkpt)
2757 {
2758 enum gdbwire_result result = GDBWIRE_OK;
2759
2760 struct gdbwire_mi_breakpoint *breakpoint = 0;
2761
2762 char *number = 0;
2763 int multi = 0;
2764 int from_multi = 0;
2765 char *catch_type = 0;
2766 int pending = 0;
2767 int enabled = 0;
2768 char *address = 0;
2769 char *type = 0;
2770 enum gdbwire_mi_breakpoint_disp_kind disp_kind = GDBWIRE_MI_BP_DISP_UNKNOWN;
2771 char *func_name = 0;
2772 char *file = 0;
2773 char *fullname = 0;
2774 unsigned long line = 0;
2775 unsigned long times = 0;
2776 char *original_location = 0;
2777
2778 GDBWIRE_ASSERT(mi_result);
2779 GDBWIRE_ASSERT(bkpt);
2780
2781 *bkpt = 0;
2782
2783 while (mi_result) {
2784 if (mi_result->kind == GDBWIRE_MI_CSTRING) {
2785 if (strcmp(mi_result->variable, "number") == 0) {
2786 number = mi_result->variant.cstring;
2787
2788 if (strstr(number, ".") != NULL) {
2789 from_multi = 1;
2790 }
2791 } else if (strcmp(mi_result->variable, "enabled") == 0) {
2792 enabled = mi_result->variant.cstring[0] == 'y';
2793 } else if (strcmp(mi_result->variable, "addr") == 0) {
2794 multi = strcmp(mi_result->variant.cstring, "<MULTIPLE>") == 0;
2795 pending = strcmp(mi_result->variant.cstring, "<PENDING>") == 0;
2796 address = mi_result->variant.cstring;
2797 } else if (strcmp(mi_result->variable, "catch-type") == 0) {
2798 catch_type = mi_result->variant.cstring;
2799 } else if (strcmp(mi_result->variable, "type") == 0) {
2800 type = mi_result->variant.cstring;
2801 } else if (strcmp(mi_result->variable, "disp") == 0) {
2802 if (strcmp(mi_result->variant.cstring, "del") == 0) {
2803 disp_kind = GDBWIRE_MI_BP_DISP_DELETE;
2804 } else if (strcmp(mi_result->variant.cstring, "dstp") == 0) {
2805 disp_kind = GDBWIRE_MI_BP_DISP_DELETE_NEXT_STOP;
2806 } else if (strcmp(mi_result->variant.cstring, "dis") == 0) {
2807 disp_kind = GDBWIRE_MI_BP_DISP_DISABLE;
2808 } else if (strcmp(mi_result->variant.cstring, "keep") == 0) {
2809 disp_kind = GDBWIRE_MI_BP_DISP_KEEP;
2810 } else {
2811 return GDBWIRE_LOGIC;
2812 }
2813 } else if (strcmp(mi_result->variable, "func") == 0) {
2814 func_name = mi_result->variant.cstring;
2815 } else if (strcmp(mi_result->variable, "file") == 0) {
2816 file = mi_result->variant.cstring;
2817 } else if (strcmp(mi_result->variable, "fullname") == 0) {
2818 fullname = mi_result->variant.cstring;
2819 } else if (strcmp(mi_result->variable, "line") == 0) {
2820 GDBWIRE_ASSERT(gdbwire_string_to_ulong(
2821 mi_result->variant.cstring, &line) == GDBWIRE_OK);
2822 } else if (strcmp(mi_result->variable, "times") == 0) {
2823 GDBWIRE_ASSERT(gdbwire_string_to_ulong(
2824 mi_result->variant.cstring, ×) == GDBWIRE_OK);
2825 } else if (strcmp(mi_result->variable, "original-location") == 0) {
2826 original_location = mi_result->variant.cstring;
2827 }
2828 }
2829
2830 mi_result = mi_result->next;
2831 }
2832
2833 /* Validate required fields before proceeding. */
2834 GDBWIRE_ASSERT(number);
2835
2836 /* At this point, allocate a breakpoint */
2837 breakpoint = calloc(1, sizeof(struct gdbwire_mi_breakpoint));
2838 if (!breakpoint) {
2839 return GDBWIRE_NOMEM;
2840 }
2841
2842 breakpoint->multi = multi;
2843 breakpoint->from_multi = from_multi;
2844 breakpoint->number = gdbwire_strdup(number);
2845 breakpoint->type = (type)?gdbwire_strdup(type):0;
2846 breakpoint->catch_type = (catch_type)?gdbwire_strdup(catch_type):0;
2847 breakpoint->disposition = disp_kind;
2848 breakpoint->enabled = enabled;
2849 breakpoint->address = (address)?gdbwire_strdup(address):0;
2850 breakpoint->func_name = (func_name)?gdbwire_strdup(func_name):0;
2851 breakpoint->file = (file)?gdbwire_strdup(file):0;
2852 breakpoint->fullname = (fullname)?gdbwire_strdup(fullname):0;
2853 breakpoint->line = line;
2854 breakpoint->times = times;
2855 breakpoint->original_location =
2856 (original_location)?gdbwire_strdup(original_location):0;
2857 breakpoint->pending = pending;
2858
2859 /* Handle the out of memory situation */
2860 if (!breakpoint->number ||
2861 (type && !breakpoint->type) ||
2862 (catch_type && !breakpoint->catch_type) ||
2863 (address && !breakpoint->address) ||
2864 (func_name && !breakpoint->func_name) ||
2865 (file && !breakpoint->file) ||
2866 (fullname && !breakpoint->fullname) ||
2867 (original_location && !breakpoint->original_location)) {
2868 gdbwire_mi_breakpoints_free(breakpoint);
2869 breakpoint = 0;
2870 result = GDBWIRE_NOMEM;
2871 }
2872
2873 *bkpt = breakpoint;
2874
2875 return result;
2876 }
2877
2878 /**
2879 * Handle the -break-info command.
2880 *
2881 * @param result_record
2882 * The mi result record that makes up the command output from gdb.
2883 *
2884 * @param out
2885 * The output command, null on error.
2886 *
2887 * @return
2888 * GDBWIRE_OK on success, otherwise failure and out is NULL.
2889 */
2890 static enum gdbwire_result
break_info(struct gdbwire_mi_result_record * result_record,struct gdbwire_mi_command ** out)2891 break_info(
2892 struct gdbwire_mi_result_record *result_record,
2893 struct gdbwire_mi_command **out)
2894 {
2895 enum gdbwire_result result = GDBWIRE_OK;
2896 struct gdbwire_mi_result *mi_result;
2897 struct gdbwire_mi_command *mi_command = 0;
2898 struct gdbwire_mi_breakpoint *breakpoints = 0, *cur_bkpt;
2899 int found_body = 0;
2900
2901 GDBWIRE_ASSERT(result_record);
2902 GDBWIRE_ASSERT(out);
2903
2904 *out = 0;
2905
2906 GDBWIRE_ASSERT(result_record->result_class == GDBWIRE_MI_DONE);
2907 GDBWIRE_ASSERT(result_record->result);
2908
2909 mi_result = result_record->result;
2910
2911 GDBWIRE_ASSERT(mi_result->kind == GDBWIRE_MI_TUPLE);
2912 GDBWIRE_ASSERT(strcmp(mi_result->variable, "BreakpointTable") == 0);
2913 GDBWIRE_ASSERT(mi_result->variant.result);
2914 GDBWIRE_ASSERT(!mi_result->next);
2915 mi_result = mi_result->variant.result;
2916
2917 /* Fast forward to the body */
2918 while (mi_result) {
2919 if (mi_result->kind == GDBWIRE_MI_LIST &&
2920 strcmp(mi_result->variable, "body") == 0) {
2921 found_body = 1;
2922 break;
2923 } else {
2924 mi_result = mi_result->next;
2925 }
2926 }
2927
2928 GDBWIRE_ASSERT(found_body);
2929 GDBWIRE_ASSERT(!mi_result->next);
2930 mi_result = mi_result->variant.result;
2931
2932 while (mi_result) {
2933 struct gdbwire_mi_breakpoint *bkpt;
2934 GDBWIRE_ASSERT_GOTO(
2935 mi_result->kind == GDBWIRE_MI_TUPLE, result, cleanup);
2936
2937 /**
2938 * GDB emits non-compliant MI when sending breakpoint information.
2939 * https://sourceware.org/bugzilla/show_bug.cgi?id=9659
2940 * In particular, instead of saying
2941 * bkpt={...},bkpt={...}
2942 * it puts out,
2943 * bkpt={...},{...}
2944 * skipping the additional bkpt for subsequent breakpoints. I've seen
2945 * this output for multiple location breakpoints as the bug points to.
2946 *
2947 * For this reason, only check bkpt for the first breakpoint and
2948 * assume it is true for the remaining.
2949 */
2950 if (mi_result->variable) {
2951 GDBWIRE_ASSERT_GOTO(
2952 strcmp(mi_result->variable, "bkpt") == 0, result, cleanup);
2953 }
2954
2955 result = break_info_for_breakpoint(mi_result->variant.result, &bkpt);
2956 if (result != GDBWIRE_OK) {
2957 goto cleanup;
2958 }
2959
2960 if (bkpt->from_multi) {
2961
2962 bkpt->multi_breakpoint = cur_bkpt;
2963
2964 /* Append breakpoint to the multiple location breakpoints */
2965 if (cur_bkpt->multi_breakpoints) {
2966 struct gdbwire_mi_breakpoint *multi =
2967 cur_bkpt->multi_breakpoints;
2968 while (multi->next) {
2969 multi = multi->next;
2970 }
2971 multi->next = bkpt;
2972 } else {
2973 cur_bkpt->multi_breakpoints = bkpt;
2974 }
2975 } else {
2976 /* Append breakpoint to the list of breakpoints */
2977 if (breakpoints) {
2978 cur_bkpt->next = bkpt;
2979 cur_bkpt = cur_bkpt->next;
2980 } else {
2981 breakpoints = cur_bkpt = bkpt;
2982 }
2983 }
2984
2985 mi_result = mi_result->next;
2986 }
2987
2988 mi_command = calloc(1, sizeof(struct gdbwire_mi_command));
2989 if (!mi_command) {
2990 result = GDBWIRE_NOMEM;
2991 goto cleanup;
2992 }
2993 mi_command->variant.break_info.breakpoints = breakpoints;
2994
2995 *out = mi_command;
2996
2997 return result;
2998
2999 cleanup:
3000 gdbwire_mi_breakpoints_free(breakpoints);
3001 return result;
3002 }
3003
3004 /**
3005 * Handle the -stack-info-frame command.
3006 *
3007 * @param result_record
3008 * The mi result record that makes up the command output from gdb.
3009 *
3010 * @param out
3011 * The output command, null on error.
3012 *
3013 * @return
3014 * GDBWIRE_OK on success, otherwise failure and out is NULL.
3015 */
3016 static enum gdbwire_result
stack_info_frame(struct gdbwire_mi_result_record * result_record,struct gdbwire_mi_command ** out)3017 stack_info_frame(
3018 struct gdbwire_mi_result_record *result_record,
3019 struct gdbwire_mi_command **out)
3020 {
3021 struct gdbwire_mi_stack_frame *frame;
3022 struct gdbwire_mi_result *mi_result;
3023 struct gdbwire_mi_command *mi_command = 0;
3024
3025 char *level = 0, *address = 0;
3026 char *func = 0, *file = 0, *fullname = 0, *line = 0, *from = 0;
3027
3028 *out = 0;
3029
3030 GDBWIRE_ASSERT(result_record->result_class == GDBWIRE_MI_DONE);
3031 GDBWIRE_ASSERT(result_record->result);
3032
3033 mi_result = result_record->result;
3034
3035 GDBWIRE_ASSERT(mi_result->kind == GDBWIRE_MI_TUPLE);
3036 GDBWIRE_ASSERT(strcmp(mi_result->variable, "frame") == 0);
3037 GDBWIRE_ASSERT(mi_result->variant.result);
3038 GDBWIRE_ASSERT(!mi_result->next);
3039 mi_result = mi_result->variant.result;
3040
3041 while (mi_result) {
3042 if (mi_result->kind == GDBWIRE_MI_CSTRING) {
3043 if (strcmp(mi_result->variable, "level") == 0) {
3044 level = mi_result->variant.cstring;
3045 } else if (strcmp(mi_result->variable, "addr") == 0) {
3046 address = mi_result->variant.cstring;
3047 } else if (strcmp(mi_result->variable, "func") == 0) {
3048 func = mi_result->variant.cstring;
3049 } else if (strcmp(mi_result->variable, "file") == 0) {
3050 file = mi_result->variant.cstring;
3051 } else if (strcmp(mi_result->variable, "fullname") == 0) {
3052 fullname = mi_result->variant.cstring;
3053 } else if (strcmp(mi_result->variable, "line") == 0) {
3054 line = mi_result->variant.cstring;
3055 } else if (strcmp(mi_result->variable, "from") == 0) {
3056 from = mi_result->variant.cstring;
3057 }
3058 }
3059
3060 mi_result = mi_result->next;
3061 }
3062
3063 GDBWIRE_ASSERT(level && address);
3064
3065 if (strcmp(address, "<unavailable>") == 0) {
3066 address = 0;
3067 }
3068
3069 frame = calloc(1, sizeof(struct gdbwire_mi_stack_frame));
3070 if (!frame) {
3071 return GDBWIRE_NOMEM;
3072 }
3073
3074 frame->level = atoi(level);
3075 frame->address = (address)?gdbwire_strdup(address):0;
3076 frame->func = (func)?gdbwire_strdup(func):0;
3077 frame->file = (file)?gdbwire_strdup(file):0;
3078 frame->fullname = (fullname)?gdbwire_strdup(fullname):0;
3079 frame->line = (line)?atoi(line):0;
3080 frame->from = (from)?gdbwire_strdup(from):0;
3081
3082 /* Handle the out of memory situation */
3083 if ((address && !frame->address) ||
3084 (func && !frame->func) ||
3085 (file && !frame->file) ||
3086 (fullname && !frame->fullname) ||
3087 (from && !frame->from)) {
3088 gdbwire_mi_stack_frame_free(frame);
3089 return GDBWIRE_NOMEM;
3090 }
3091
3092 mi_command = calloc(1, sizeof(struct gdbwire_mi_command));
3093 if (!mi_command) {
3094 gdbwire_mi_stack_frame_free(frame);
3095 return GDBWIRE_NOMEM;
3096 }
3097 mi_command->kind = GDBWIRE_MI_STACK_INFO_FRAME;
3098 mi_command->variant.stack_info_frame.frame = frame;
3099
3100 *out = mi_command;
3101
3102 return GDBWIRE_OK;
3103 }
3104
3105 /**
3106 * Handle the -file-list-exec-source-file command.
3107 *
3108 * @param result_record
3109 * The mi result record that makes up the command output from gdb.
3110 *
3111 * @param out
3112 * The output command, null on error.
3113 *
3114 * @return
3115 * GDBWIRE_OK on success, otherwise failure and out is NULL.
3116 */
3117 static enum gdbwire_result
file_list_exec_source_file(struct gdbwire_mi_result_record * result_record,struct gdbwire_mi_command ** out)3118 file_list_exec_source_file(
3119 struct gdbwire_mi_result_record *result_record,
3120 struct gdbwire_mi_command **out)
3121 {
3122 struct gdbwire_mi_result *mi_result;
3123 struct gdbwire_mi_command *mi_command = 0;
3124
3125 char *line = 0, *file = 0, *fullname = 0, *macro_info = 0;
3126
3127 *out = 0;
3128
3129 GDBWIRE_ASSERT(result_record->result_class == GDBWIRE_MI_DONE);
3130 GDBWIRE_ASSERT(result_record->result);
3131
3132 mi_result = result_record->result;
3133
3134 while (mi_result) {
3135 if (mi_result->kind == GDBWIRE_MI_CSTRING) {
3136 if (strcmp(mi_result->variable, "line") == 0) {
3137 line = mi_result->variant.cstring;
3138 } else if (strcmp(mi_result->variable, "file") == 0) {
3139 file = mi_result->variant.cstring;
3140 } else if (strcmp(mi_result->variable, "fullname") == 0) {
3141 fullname = mi_result->variant.cstring;
3142 } else if (strcmp(mi_result->variable, "macro-info") == 0) {
3143 macro_info = mi_result->variant.cstring;
3144 GDBWIRE_ASSERT(strlen(macro_info) == 1);
3145 GDBWIRE_ASSERT(macro_info[0] == '0' || macro_info[0] == '1');
3146 }
3147 }
3148
3149 mi_result = mi_result->next;
3150 }
3151
3152 GDBWIRE_ASSERT(line && file);
3153
3154 mi_command = calloc(1, sizeof(struct gdbwire_mi_command));
3155 if (!mi_command) {
3156 return GDBWIRE_NOMEM;
3157 }
3158
3159 mi_command->kind = GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILE;
3160 mi_command->variant.file_list_exec_source_file.line = atoi(line);
3161 mi_command->variant.file_list_exec_source_file.file = gdbwire_strdup(file);
3162 if (!mi_command->variant.file_list_exec_source_file.file) {
3163 gdbwire_mi_command_free(mi_command);
3164 return GDBWIRE_NOMEM;
3165 }
3166 mi_command->variant.file_list_exec_source_file.fullname =
3167 (fullname)?gdbwire_strdup(fullname):0;
3168 if (fullname &&
3169 !mi_command->variant.file_list_exec_source_file.fullname) {
3170 gdbwire_mi_command_free(mi_command);
3171 return GDBWIRE_NOMEM;
3172 }
3173 mi_command->variant.file_list_exec_source_file.macro_info_exists =
3174 macro_info != 0;
3175 if (macro_info) {
3176 mi_command->variant.file_list_exec_source_file.macro_info =
3177 atoi(macro_info);
3178 }
3179
3180 *out = mi_command;
3181
3182 return GDBWIRE_OK;
3183 }
3184
3185 /**
3186 * Handle the -file-list-exec-source-files command.
3187 *
3188 * @param result_record
3189 * The mi result record that makes up the command output from gdb.
3190 *
3191 * @param out
3192 * The output command, null on error.
3193 *
3194 * @return
3195 * GDBWIRE_OK on success, otherwise failure and out is NULL.
3196 */
3197 static enum gdbwire_result
file_list_exec_source_files(struct gdbwire_mi_result_record * result_record,struct gdbwire_mi_command ** out)3198 file_list_exec_source_files(
3199 struct gdbwire_mi_result_record *result_record,
3200 struct gdbwire_mi_command **out)
3201 {
3202 enum gdbwire_result result = GDBWIRE_OK;
3203 struct gdbwire_mi_result *mi_result;
3204 struct gdbwire_mi_source_file *files = 0, *cur_node, *new_node;
3205
3206 GDBWIRE_ASSERT(result_record->result_class == GDBWIRE_MI_DONE);
3207 GDBWIRE_ASSERT(result_record->result);
3208
3209 mi_result = result_record->result;
3210
3211 GDBWIRE_ASSERT(mi_result->kind == GDBWIRE_MI_LIST);
3212 GDBWIRE_ASSERT(strcmp(mi_result->variable, "files") == 0);
3213 GDBWIRE_ASSERT(!mi_result->next);
3214
3215 mi_result = mi_result->variant.result;
3216
3217 while (mi_result) {
3218 struct gdbwire_mi_result *tuple;
3219 char *file = 0, *fullname = 0;
3220 GDBWIRE_ASSERT_GOTO(mi_result->kind == GDBWIRE_MI_TUPLE, result, err);
3221 tuple = mi_result->variant.result;
3222
3223 /* file field */
3224 GDBWIRE_ASSERT_GOTO(tuple->kind == GDBWIRE_MI_CSTRING, result, err);
3225 GDBWIRE_ASSERT_GOTO(strcmp(tuple->variable, "file") == 0, result, err);
3226 file = tuple->variant.cstring;
3227
3228 if (tuple->next) {
3229 tuple = tuple->next;
3230
3231 /* fullname field */
3232 GDBWIRE_ASSERT_GOTO(tuple->kind == GDBWIRE_MI_CSTRING, result, err);
3233 GDBWIRE_ASSERT_GOTO(strcmp(tuple->variable, "fullname") == 0,
3234 result, err);
3235 fullname = tuple->variant.cstring;
3236 }
3237
3238 GDBWIRE_ASSERT(!tuple->next);
3239
3240 /* Create the new */
3241 new_node = calloc(1, sizeof(struct gdbwire_mi_source_file));
3242 GDBWIRE_ASSERT_GOTO(new_node, result, err);
3243
3244 new_node->file = gdbwire_strdup(file);
3245 new_node->fullname = (fullname)?gdbwire_strdup(fullname):0;
3246 new_node->next = 0;
3247
3248 /* Append the node to the list */
3249 if (files) {
3250 cur_node->next = new_node;
3251 cur_node = cur_node->next;
3252 } else {
3253 files = cur_node = new_node;
3254 }
3255
3256 GDBWIRE_ASSERT_GOTO(new_node->file && (new_node->fullname || !fullname),
3257 result, err);
3258
3259 mi_result = mi_result->next;
3260 }
3261
3262 *out = calloc(1, sizeof(struct gdbwire_mi_command));
3263 GDBWIRE_ASSERT_GOTO(*out, result, err);
3264 (*out)->kind = GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILES;
3265 (*out)->variant.file_list_exec_source_files.files = files;
3266
3267 return result;
3268
3269 err:
3270 gdbwire_mi_source_files_free(files);
3271
3272 return result;
3273 }
3274
3275 enum gdbwire_result
gdbwire_get_mi_command(enum gdbwire_mi_command_kind kind,struct gdbwire_mi_result_record * result_record,struct gdbwire_mi_command ** out)3276 gdbwire_get_mi_command(enum gdbwire_mi_command_kind kind,
3277 struct gdbwire_mi_result_record *result_record,
3278 struct gdbwire_mi_command **out)
3279 {
3280 enum gdbwire_result result = GDBWIRE_OK;
3281
3282 GDBWIRE_ASSERT(result_record);
3283 GDBWIRE_ASSERT(out);
3284
3285 *out = 0;
3286
3287 switch (kind) {
3288 case GDBWIRE_MI_BREAK_INFO:
3289 result = break_info(result_record, out);
3290 break;
3291 case GDBWIRE_MI_STACK_INFO_FRAME:
3292 result = stack_info_frame(result_record, out);
3293 break;
3294 case GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILE:
3295 result = file_list_exec_source_file(result_record, out);
3296 break;
3297 case GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILES:
3298 result = file_list_exec_source_files(result_record, out);
3299 break;
3300 }
3301
3302 return result;
3303 }
3304
gdbwire_mi_command_free(struct gdbwire_mi_command * mi_command)3305 void gdbwire_mi_command_free(struct gdbwire_mi_command *mi_command)
3306 {
3307 if (mi_command) {
3308 switch (mi_command->kind) {
3309 case GDBWIRE_MI_BREAK_INFO:
3310 gdbwire_mi_breakpoints_free(
3311 mi_command->variant.break_info.breakpoints);
3312 break;
3313 case GDBWIRE_MI_STACK_INFO_FRAME:
3314 gdbwire_mi_stack_frame_free(
3315 mi_command->variant.stack_info_frame.frame);
3316 break;
3317 case GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILE:
3318 free(mi_command->variant.file_list_exec_source_file.file);
3319 free(mi_command->variant.file_list_exec_source_file.fullname);
3320 break;
3321 case GDBWIRE_MI_FILE_LIST_EXEC_SOURCE_FILES:
3322 gdbwire_mi_source_files_free(
3323 mi_command->variant.file_list_exec_source_files.files);
3324 break;
3325 }
3326
3327 free(mi_command);
3328 }
3329 }
3330 /***** End of gdbwire_mi_command.c *******************************************/
3331 /***** Begin file gdbwire_mi_lexer.c *****************************************/
3332
3333
3334 #define YY_INT_ALIGNED short int
3335
3336 /* A lexical scanner generated by flex */
3337
3338 #define FLEX_SCANNER
3339 #define YY_FLEX_MAJOR_VERSION 2
3340 #define YY_FLEX_MINOR_VERSION 6
3341 #define YY_FLEX_SUBMINOR_VERSION 1
3342 #if YY_FLEX_SUBMINOR_VERSION > 0
3343 #define FLEX_BETA
3344 #endif
3345
3346 /* First, we deal with platform-specific or compiler-specific issues. */
3347
3348 /* begin standard C headers. */
3349 #include <stdio.h>
3350 #include <string.h>
3351 #include <errno.h>
3352 #include <stdlib.h>
3353
3354 /* end standard C headers. */
3355
3356 /* flex integer type definitions */
3357
3358 #ifndef FLEXINT_H
3359 #define FLEXINT_H
3360
3361 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
3362
3363 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
3364
3365 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
3366 * if you want the limit (max/min) macros for int types.
3367 */
3368 #ifndef __STDC_LIMIT_MACROS
3369 #define __STDC_LIMIT_MACROS 1
3370 #endif
3371
3372 #include <inttypes.h>
3373 typedef int8_t flex_int8_t;
3374 typedef uint8_t flex_uint8_t;
3375 typedef int16_t flex_int16_t;
3376 typedef uint16_t flex_uint16_t;
3377 typedef int32_t flex_int32_t;
3378 typedef uint32_t flex_uint32_t;
3379 #else
3380 typedef signed char flex_int8_t;
3381 typedef short int flex_int16_t;
3382 typedef int flex_int32_t;
3383 typedef unsigned char flex_uint8_t;
3384 typedef unsigned short int flex_uint16_t;
3385 typedef unsigned int flex_uint32_t;
3386
3387 /* Limits of integral types. */
3388 #ifndef INT8_MIN
3389 #define INT8_MIN (-128)
3390 #endif
3391 #ifndef INT16_MIN
3392 #define INT16_MIN (-32767-1)
3393 #endif
3394 #ifndef INT32_MIN
3395 #define INT32_MIN (-2147483647-1)
3396 #endif
3397 #ifndef INT8_MAX
3398 #define INT8_MAX (127)
3399 #endif
3400 #ifndef INT16_MAX
3401 #define INT16_MAX (32767)
3402 #endif
3403 #ifndef INT32_MAX
3404 #define INT32_MAX (2147483647)
3405 #endif
3406 #ifndef UINT8_MAX
3407 #define UINT8_MAX (255U)
3408 #endif
3409 #ifndef UINT16_MAX
3410 #define UINT16_MAX (65535U)
3411 #endif
3412 #ifndef UINT32_MAX
3413 #define UINT32_MAX (4294967295U)
3414 #endif
3415
3416 #endif /* ! C99 */
3417
3418 #endif /* ! FLEXINT_H */
3419
3420 /* TODO: this is always defined, so inline it */
3421 #define yyconst const
3422
3423 #if defined(__GNUC__) && __GNUC__ >= 3
3424 #define yynoreturn __attribute__((__noreturn__))
3425 #else
3426 #define yynoreturn
3427 #endif
3428
3429 /* Returned upon end-of-file. */
3430 #define YY_NULL 0
3431
3432 /* Promotes a possibly negative, possibly signed char to an unsigned
3433 * integer for use as an array index. If the signed char is negative,
3434 * we want to instead treat it as an 8-bit unsigned char, hence the
3435 * double cast.
3436 */
3437 #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
3438
3439 /* An opaque pointer. */
3440 #ifndef YY_TYPEDEF_YY_SCANNER_T
3441 #define YY_TYPEDEF_YY_SCANNER_T
3442 typedef void* yyscan_t;
3443 #endif
3444
3445 /* For convenience, these vars (plus the bison vars far below)
3446 are macros in the reentrant scanner. */
3447 #define yyin yyg->yyin_r
3448 #define yyout yyg->yyout_r
3449 #define yyextra yyg->yyextra_r
3450 #define yyleng yyg->yyleng_r
3451 #define yytext yyg->yytext_r
3452 #define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
3453 #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
3454 #define yy_flex_debug yyg->yy_flex_debug_r
3455
3456 /* Enter a start condition. This macro really ought to take a parameter,
3457 * but we do it the disgusting crufty way forced on us by the ()-less
3458 * definition of BEGIN.
3459 */
3460 #define BEGIN yyg->yy_start = 1 + 2 *
3461
3462 /* Translate the current start state into a value that can be later handed
3463 * to BEGIN to return to the state. The YYSTATE alias is for lex
3464 * compatibility.
3465 */
3466 #define YY_START ((yyg->yy_start - 1) / 2)
3467 #define YYSTATE YY_START
3468
3469 /* Action number for EOF rule of a given start state. */
3470 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
3471
3472 /* Special action meaning "start processing a new file". */
3473 #define YY_NEW_FILE gdbwire_mi_restart(yyin ,yyscanner )
3474
3475 #define YY_END_OF_BUFFER_CHAR 0
3476
3477 /* Size of default input buffer. */
3478 #ifndef YY_BUF_SIZE
3479 #ifdef __ia64__
3480 /* On IA-64, the buffer size is 16k, not 8k.
3481 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
3482 * Ditto for the __ia64__ case accordingly.
3483 */
3484 #define YY_BUF_SIZE 32768
3485 #else
3486 #define YY_BUF_SIZE 16384
3487 #endif /* __ia64__ */
3488 #endif
3489
3490 /* The state buf must be large enough to hold one state per character in the main buffer.
3491 */
3492 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
3493
3494 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
3495 #define YY_TYPEDEF_YY_BUFFER_STATE
3496 typedef struct yy_buffer_state *YY_BUFFER_STATE;
3497 #endif
3498
3499 #ifndef YY_TYPEDEF_YY_SIZE_T
3500 #define YY_TYPEDEF_YY_SIZE_T
3501 typedef size_t yy_size_t;
3502 #endif
3503
3504 #define EOB_ACT_CONTINUE_SCAN 0
3505 #define EOB_ACT_END_OF_FILE 1
3506 #define EOB_ACT_LAST_MATCH 2
3507
3508 #define YY_LESS_LINENO(n)
3509 #define YY_LINENO_REWIND_TO(ptr)
3510
3511 /* Return all but the first "n" matched characters back to the input stream. */
3512 #define yyless(n) \
3513 do \
3514 { \
3515 /* Undo effects of setting up yytext. */ \
3516 yy_size_t yyless_macro_arg = (n); \
3517 YY_LESS_LINENO(yyless_macro_arg);\
3518 *yy_cp = yyg->yy_hold_char; \
3519 YY_RESTORE_YY_MORE_OFFSET \
3520 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
3521 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
3522 } \
3523 while ( 0 )
3524
3525 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
3526
3527 #ifndef YY_STRUCT_YY_BUFFER_STATE
3528 #define YY_STRUCT_YY_BUFFER_STATE
3529 struct yy_buffer_state
3530 {
3531 FILE *yy_input_file;
3532
3533 char *yy_ch_buf; /* input buffer */
3534 char *yy_buf_pos; /* current position in input buffer */
3535
3536 /* Size of input buffer in bytes, not including room for EOB
3537 * characters.
3538 */
3539 int yy_buf_size;
3540
3541 /* Number of characters read into yy_ch_buf, not including EOB
3542 * characters.
3543 */
3544 int yy_n_chars;
3545
3546 /* Whether we "own" the buffer - i.e., we know we created it,
3547 * and can realloc() it to grow it, and should free() it to
3548 * delete it.
3549 */
3550 int yy_is_our_buffer;
3551
3552 /* Whether this is an "interactive" input source; if so, and
3553 * if we're using stdio for input, then we want to use getc()
3554 * instead of fread(), to make sure we stop fetching input after
3555 * each newline.
3556 */
3557 int yy_is_interactive;
3558
3559 /* Whether we're considered to be at the beginning of a line.
3560 * If so, '^' rules will be active on the next match, otherwise
3561 * not.
3562 */
3563 int yy_at_bol;
3564
3565 int yy_bs_lineno; /**< The line count. */
3566 int yy_bs_column; /**< The column count. */
3567
3568 /* Whether to try to fill the input buffer when we reach the
3569 * end of it.
3570 */
3571 int yy_fill_buffer;
3572
3573 int yy_buffer_status;
3574
3575 #define YY_BUFFER_NEW 0
3576 #define YY_BUFFER_NORMAL 1
3577 /* When an EOF's been seen but there's still some text to process
3578 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
3579 * shouldn't try reading from the input source any more. We might
3580 * still have a bunch of tokens to match, though, because of
3581 * possible backing-up.
3582 *
3583 * When we actually see the EOF, we change the status to "new"
3584 * (via gdbwire_mi_restart()), so that the user can continue scanning by
3585 * just pointing yyin at a new input file.
3586 */
3587 #define YY_BUFFER_EOF_PENDING 2
3588
3589 };
3590 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
3591
3592 /* We provide macros for accessing buffer states in case in the
3593 * future we want to put the buffer states in a more general
3594 * "scanner state".
3595 *
3596 * Returns the top of the stack, or NULL.
3597 */
3598 #define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
3599 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
3600 : NULL)
3601
3602 /* Same as previous macro, but useful when we know that the buffer stack is not
3603 * NULL or when we need an lvalue. For internal use only.
3604 */
3605 #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
3606
3607 void gdbwire_mi_restart (FILE *input_file ,yyscan_t yyscanner );
3608 void gdbwire_mi__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
3609 YY_BUFFER_STATE gdbwire_mi__create_buffer (FILE *file,int size ,yyscan_t yyscanner );
3610 void gdbwire_mi__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
3611 void gdbwire_mi__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
3612 void gdbwire_mi_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
3613 void gdbwire_mi_pop_buffer_state (yyscan_t yyscanner );
3614
3615 static void gdbwire_mi_ensure_buffer_stack (yyscan_t yyscanner );
3616 static void gdbwire_mi__load_buffer_state (yyscan_t yyscanner );
3617 static void gdbwire_mi__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
3618
3619 #define YY_FLUSH_BUFFER gdbwire_mi__flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
3620
3621 YY_BUFFER_STATE gdbwire_mi__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
3622 YY_BUFFER_STATE gdbwire_mi__scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
3623 YY_BUFFER_STATE gdbwire_mi__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
3624
3625 void *gdbwire_mi_alloc (yy_size_t ,yyscan_t yyscanner );
3626 void *gdbwire_mi_realloc (void *,yy_size_t ,yyscan_t yyscanner );
3627 void gdbwire_mi_free (void * ,yyscan_t yyscanner );
3628
3629 #define yy_new_buffer gdbwire_mi__create_buffer
3630
3631 #define yy_set_interactive(is_interactive) \
3632 { \
3633 if ( ! YY_CURRENT_BUFFER ){ \
3634 gdbwire_mi_ensure_buffer_stack (yyscanner); \
3635 YY_CURRENT_BUFFER_LVALUE = \
3636 gdbwire_mi__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
3637 } \
3638 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
3639 }
3640
3641 #define yy_set_bol(at_bol) \
3642 { \
3643 if ( ! YY_CURRENT_BUFFER ){\
3644 gdbwire_mi_ensure_buffer_stack (yyscanner); \
3645 YY_CURRENT_BUFFER_LVALUE = \
3646 gdbwire_mi__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
3647 } \
3648 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
3649 }
3650
3651 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
3652
3653 /* Begin user sect3 */
3654
3655 #define gdbwire_mi_wrap(yyscanner) (/*CONSTCOND*/1)
3656 #define YY_SKIP_YYWRAP
3657
3658 typedef unsigned char YY_CHAR;
3659
3660 typedef int yy_state_type;
3661
3662 #define yytext_ptr yytext_r
3663
3664 static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
3665 static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
3666 static int yy_get_next_buffer (yyscan_t yyscanner );
3667 static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
3668
3669 /* Done after the current pattern has been matched and before the
3670 * corresponding action - sets up yytext.
3671 */
3672 #define YY_DO_BEFORE_ACTION \
3673 yyg->yytext_ptr = yy_bp; \
3674 yyleng = (int) (yy_cp - yy_bp); \
3675 yyg->yy_hold_char = *yy_cp; \
3676 *yy_cp = '\0'; \
3677 yyg->yy_c_buf_p = yy_cp;
3678
3679 #define YY_NUM_RULES 23
3680 #define YY_END_OF_BUFFER 24
3681 /* This struct is not used in this scanner,
3682 but its presence is necessary. */
3683 struct yy_trans_info
3684 {
3685 flex_int32_t yy_verify;
3686 flex_int32_t yy_nxt;
3687 };
3688 static yyconst flex_int16_t yy_accept[33] =
3689 { 0,
3690 0, 0, 24, 21, 19, 15, 17, 21, 8, 13,
3691 14, 4, 3, 2, 18, 5, 7, 20, 9, 10,
3692 1, 11, 12, 6, 16, 0, 22, 0, 18, 20,
3693 20, 0
3694 } ;
3695
3696 static yyconst YY_CHAR yy_ec[256] =
3697 { 0,
3698 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
3699 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
3700 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3701 1, 2, 1, 5, 1, 1, 1, 6, 1, 7,
3702 8, 9, 10, 11, 12, 1, 1, 13, 13, 13,
3703 13, 13, 13, 13, 13, 13, 13, 1, 1, 1,
3704 14, 1, 1, 15, 16, 16, 16, 16, 16, 16,
3705 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
3706 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
3707 17, 18, 19, 20, 16, 1, 16, 16, 16, 16,
3708
3709 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
3710 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
3711 16, 16, 21, 1, 22, 23, 1, 1, 1, 1,
3712 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3713 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3714 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3715 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3716 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3717 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3718 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3719
3720 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3721 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3722 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3723 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3724 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3725 1, 1, 1, 1, 1
3726 } ;
3727
3728 static yyconst YY_CHAR yy_meta[24] =
3729 { 0,
3730 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3731 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3732 1, 1, 1
3733 } ;
3734
3735 static yyconst flex_uint16_t yy_base[34] =
3736 { 0,
3737 0, 0, 42, 43, 43, 43, 38, 19, 43, 43,
3738 43, 43, 43, 43, 26, 43, 43, 13, 43, 43,
3739 43, 43, 43, 43, 43, 22, 43, 35, 22, 18,
3740 20, 43, 27
3741 } ;
3742
3743 static yyconst flex_int16_t yy_def[34] =
3744 { 0,
3745 32, 1, 32, 32, 32, 32, 32, 33, 32, 32,
3746 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
3747 32, 32, 32, 32, 32, 33, 32, 33, 32, 32,
3748 32, 0, 32
3749 } ;
3750
3751 static yyconst flex_uint16_t yy_nxt[67] =
3752 { 0,
3753 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
3754 14, 4, 15, 16, 17, 18, 19, 4, 20, 21,
3755 22, 23, 24, 27, 30, 30, 27, 26, 31, 30,
3756 30, 30, 30, 30, 29, 31, 28, 32, 29, 28,
3757 25, 32, 3, 32, 32, 32, 32, 32, 32, 32,
3758 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
3759 32, 32, 32, 32, 32, 32
3760 } ;
3761
3762 static yyconst flex_int16_t yy_chk[67] =
3763 { 0,
3764 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3765 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3766 1, 1, 1, 8, 18, 18, 26, 33, 18, 30,
3767 30, 31, 31, 30, 29, 31, 8, 28, 15, 26,
3768 7, 3, 32, 32, 32, 32, 32, 32, 32, 32,
3769 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
3770 32, 32, 32, 32, 32, 32
3771 } ;
3772
3773 /* The intent behind this definition is that it'll catch
3774 * any uses of REJECT which flex missed.
3775 */
3776 #define REJECT reject_used_but_not_detected
3777 #define yymore() yymore_used_but_not_detected
3778 #define YY_MORE_ADJ 0
3779 #define YY_RESTORE_YY_MORE_OFFSET
3780 #define YY_NO_INPUT 1
3781 /* Avoids the use of fileno, which is POSIX and not compatible with c11 */
3782
3783 /* flex 2.6.0 produces a sign-compare warning */
3784 #pragma GCC diagnostic ignored "-Wsign-compare"
3785
3786 #include <stdio.h>
3787 /* #include "gdbwire_mi_grammar.h" */
3788 /* #include "gdbwire_mi_pt.h" */
3789
3790 /**
3791 * This macro sets the beginning and ending column position of each
3792 * token in the pure lexer. No global state is used.
3793 *
3794 * The parser can then use this position to determine the location
3795 * of any token it desires.
3796 *
3797 * Currently only the column is stored as the parser only uses
3798 * the lexer on a line at a time. Currently, the caller of the
3799 * lexer sets the column position back to 1 each time a new
3800 * line is set to be parsed in the lexer.
3801 */
3802 #define YY_USER_ACTION \
3803 { \
3804 struct gdbwire_mi_position pos = { yycolumn, yycolumn+yyleng-1 }; \
3805 yyextra = pos; \
3806 yycolumn += yyleng; \
3807 }
3808
3809 #define INITIAL 0
3810
3811 #ifndef YY_NO_UNISTD_H
3812 /* Special case for "unistd.h", since it is non-ANSI. We include it way
3813 * down here because we want the user's section 1 to have been scanned first.
3814 * The user has a chance to override it with an option.
3815 */
3816 #include <unistd.h>
3817 #endif
3818
3819 #define YY_EXTRA_TYPE struct gdbwire_mi_position
3820
3821 /* Holds the entire state of the reentrant scanner. */
3822 struct yyguts_t
3823 {
3824
3825 /* User-defined. Not touched by flex. */
3826 YY_EXTRA_TYPE yyextra_r;
3827
3828 /* The rest are the same as the globals declared in the non-reentrant scanner. */
3829 FILE *yyin_r, *yyout_r;
3830 size_t yy_buffer_stack_top; /**< index of top of stack. */
3831 size_t yy_buffer_stack_max; /**< capacity of stack. */
3832 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
3833 char yy_hold_char;
3834 int yy_n_chars;
3835 int yyleng_r;
3836 char *yy_c_buf_p;
3837 int yy_init;
3838 int yy_start;
3839 int yy_did_buffer_switch_on_eof;
3840 int yy_start_stack_ptr;
3841 int yy_start_stack_depth;
3842 int *yy_start_stack;
3843 yy_state_type yy_last_accepting_state;
3844 char* yy_last_accepting_cpos;
3845
3846 int yylineno_r;
3847 int yy_flex_debug_r;
3848
3849 char *yytext_r;
3850 int yy_more_flag;
3851 int yy_more_len;
3852
3853 }; /* end struct yyguts_t */
3854
3855 static int yy_init_globals (yyscan_t yyscanner );
3856
3857 int gdbwire_mi_lex_init (yyscan_t* scanner);
3858
3859 int gdbwire_mi_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
3860
3861 /* Accessor methods to globals.
3862 These are made visible to non-reentrant scanners for convenience. */
3863
3864 int gdbwire_mi_lex_destroy (yyscan_t yyscanner );
3865
3866 int gdbwire_mi_get_debug (yyscan_t yyscanner );
3867
3868 void gdbwire_mi_set_debug (int debug_flag ,yyscan_t yyscanner );
3869
3870 YY_EXTRA_TYPE gdbwire_mi_get_extra (yyscan_t yyscanner );
3871
3872 void gdbwire_mi_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
3873
3874 FILE *gdbwire_mi_get_in (yyscan_t yyscanner );
3875
3876 void gdbwire_mi_set_in (FILE * _in_str ,yyscan_t yyscanner );
3877
3878 FILE *gdbwire_mi_get_out (yyscan_t yyscanner );
3879
3880 void gdbwire_mi_set_out (FILE * _out_str ,yyscan_t yyscanner );
3881
3882 int gdbwire_mi_get_leng (yyscan_t yyscanner );
3883
3884 char *gdbwire_mi_get_text (yyscan_t yyscanner );
3885
3886 int gdbwire_mi_get_lineno (yyscan_t yyscanner );
3887
3888 void gdbwire_mi_set_lineno (int _line_number ,yyscan_t yyscanner );
3889
3890 int gdbwire_mi_get_column (yyscan_t yyscanner );
3891
3892 void gdbwire_mi_set_column (int _column_no ,yyscan_t yyscanner );
3893
3894 /* Macros after this point can all be overridden by user definitions in
3895 * section 1.
3896 */
3897
3898 #ifndef YY_SKIP_YYWRAP
3899 #ifdef __cplusplus
3900 extern "C" int gdbwire_mi_wrap (yyscan_t yyscanner );
3901 #else
3902 extern int gdbwire_mi_wrap (yyscan_t yyscanner );
3903 #endif
3904 #endif
3905
3906 #ifndef YY_NO_UNPUT
3907
3908 #endif
3909
3910 #ifndef yytext_ptr
3911 static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
3912 #endif
3913
3914 #ifdef YY_NEED_STRLEN
3915 static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
3916 #endif
3917
3918 #ifndef YY_NO_INPUT
3919
3920 #ifdef __cplusplus
3921 static int yyinput (yyscan_t yyscanner );
3922 #else
3923 static int input (yyscan_t yyscanner );
3924 #endif
3925
3926 #endif
3927
3928 /* Amount of stuff to slurp up with each read. */
3929 #ifndef YY_READ_BUF_SIZE
3930 #ifdef __ia64__
3931 /* On IA-64, the buffer size is 16k, not 8k */
3932 #define YY_READ_BUF_SIZE 16384
3933 #else
3934 #define YY_READ_BUF_SIZE 8192
3935 #endif /* __ia64__ */
3936 #endif
3937
3938 /* Copy whatever the last rule matched to the standard output. */
3939 #ifndef ECHO
3940 /* This used to be an fputs(), but since the string might contain NUL's,
3941 * we now use fwrite().
3942 */
3943 #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
3944 #endif
3945
3946 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
3947 * is returned in "result".
3948 */
3949 #ifndef YY_INPUT
3950 #define YY_INPUT(buf,result,max_size) \
3951 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
3952 { \
3953 int c = '*'; \
3954 int n; \
3955 for ( n = 0; n < max_size && \
3956 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
3957 buf[n] = (char) c; \
3958 if ( c == '\n' ) \
3959 buf[n++] = (char) c; \
3960 if ( c == EOF && ferror( yyin ) ) \
3961 YY_FATAL_ERROR( "input in flex scanner failed" ); \
3962 result = n; \
3963 } \
3964 else \
3965 { \
3966 errno=0; \
3967 while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
3968 { \
3969 if( errno != EINTR) \
3970 { \
3971 YY_FATAL_ERROR( "input in flex scanner failed" ); \
3972 break; \
3973 } \
3974 errno=0; \
3975 clearerr(yyin); \
3976 } \
3977 }\
3978 \
3979
3980 #endif
3981
3982 /* No semi-colon after return; correct usage is to write "yyterminate();" -
3983 * we don't want an extra ';' after the "return" because that will cause
3984 * some compilers to complain about unreachable statements.
3985 */
3986 #ifndef yyterminate
3987 #define yyterminate() return YY_NULL
3988 #endif
3989
3990 /* Number of entries by which start-condition stack grows. */
3991 #ifndef YY_START_STACK_INCR
3992 #define YY_START_STACK_INCR 25
3993 #endif
3994
3995 /* Report a fatal error. */
3996 #ifndef YY_FATAL_ERROR
3997 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
3998 #endif
3999
4000 /* end tables serialization structures and prototypes */
4001
4002 /* Default declaration of generated scanner - a define so the user can
4003 * easily add parameters.
4004 */
4005 #ifndef YY_DECL
4006 #define YY_DECL_IS_OURS 1
4007
4008 extern int gdbwire_mi_lex (yyscan_t yyscanner);
4009
4010 #define YY_DECL int gdbwire_mi_lex (yyscan_t yyscanner)
4011 #endif /* !YY_DECL */
4012
4013 /* Code executed at the beginning of each rule, after yytext and yyleng
4014 * have been set up.
4015 */
4016 #ifndef YY_USER_ACTION
4017 #define YY_USER_ACTION
4018 #endif
4019
4020 /* Code executed at the end of each rule. */
4021 #ifndef YY_BREAK
4022 #define YY_BREAK /*LINTED*/break;
4023 #endif
4024
4025 #define YY_RULE_SETUP \
4026 YY_USER_ACTION
4027
4028 /** The main scanner function which does all the work.
4029 */
4030 YY_DECL
4031 {
4032 yy_state_type yy_current_state;
4033 char *yy_cp, *yy_bp;
4034 int yy_act;
4035 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4036
4037 if ( !yyg->yy_init )
4038 {
4039 yyg->yy_init = 1;
4040
4041 #ifdef YY_USER_INIT
4042 YY_USER_INIT;
4043 #endif
4044
4045 if ( ! yyg->yy_start )
4046 yyg->yy_start = 1; /* first start state */
4047
4048 if ( ! yyin )
4049 yyin = stdin;
4050
4051 if ( ! yyout )
4052 yyout = stdout;
4053
4054 if ( ! YY_CURRENT_BUFFER ) {
4055 gdbwire_mi_ensure_buffer_stack (yyscanner);
4056 YY_CURRENT_BUFFER_LVALUE =
4057 gdbwire_mi__create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
4058 }
4059
4060 gdbwire_mi__load_buffer_state(yyscanner );
4061 }
4062
4063 {
4064
4065
4066
4067 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
4068 {
4069 yy_cp = yyg->yy_c_buf_p;
4070
4071 /* Support of yytext. */
4072 *yy_cp = yyg->yy_hold_char;
4073
4074 /* yy_bp points to the position in yy_ch_buf of the start of
4075 * the current run.
4076 */
4077 yy_bp = yy_cp;
4078
4079 yy_current_state = yyg->yy_start;
4080 yy_match:
4081 do
4082 {
4083 YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
4084 if ( yy_accept[yy_current_state] )
4085 {
4086 yyg->yy_last_accepting_state = yy_current_state;
4087 yyg->yy_last_accepting_cpos = yy_cp;
4088 }
4089 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
4090 {
4091 yy_current_state = (int) yy_def[yy_current_state];
4092 if ( yy_current_state >= 33 )
4093 yy_c = yy_meta[(unsigned int) yy_c];
4094 }
4095 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
4096 ++yy_cp;
4097 }
4098 while ( yy_current_state != 32 );
4099 yy_cp = yyg->yy_last_accepting_cpos;
4100 yy_current_state = yyg->yy_last_accepting_state;
4101
4102 yy_find_action:
4103 yy_act = yy_accept[yy_current_state];
4104
4105 YY_DO_BEFORE_ACTION;
4106
4107 do_action: /* This label is used only to access EOF actions. */
4108
4109 switch ( yy_act )
4110 { /* beginning of action switch */
4111 case 0: /* must back up */
4112 /* undo the effects of YY_DO_BEFORE_ACTION */
4113 *yy_cp = yyg->yy_hold_char;
4114 yy_cp = yyg->yy_last_accepting_cpos;
4115 yy_current_state = yyg->yy_last_accepting_state;
4116 goto yy_find_action;
4117
4118 case 1:
4119 YY_RULE_SETUP
4120 { return CARROT; }
4121 YY_BREAK
4122 case 2:
4123 YY_RULE_SETUP
4124 { return COMMA; }
4125 YY_BREAK
4126 case 3:
4127 YY_RULE_SETUP
4128 { return ADD_OP; }
4129 YY_BREAK
4130 case 4:
4131 YY_RULE_SETUP
4132 { return MULT_OP; }
4133 YY_BREAK
4134 case 5:
4135 YY_RULE_SETUP
4136 { return EQUAL_SIGN; }
4137 YY_BREAK
4138 case 6:
4139 YY_RULE_SETUP
4140 { return TILDA; }
4141 YY_BREAK
4142 case 7:
4143 YY_RULE_SETUP
4144 { return AT_SYMBOL; }
4145 YY_BREAK
4146 case 8:
4147 YY_RULE_SETUP
4148 { return AMPERSAND; }
4149 YY_BREAK
4150 case 9:
4151 YY_RULE_SETUP
4152 { return OPEN_BRACKET; }
4153 YY_BREAK
4154 case 10:
4155 YY_RULE_SETUP
4156 { return CLOSED_BRACKET; }
4157 YY_BREAK
4158 case 11:
4159 YY_RULE_SETUP
4160 { return OPEN_BRACE; }
4161 YY_BREAK
4162 case 12:
4163 YY_RULE_SETUP
4164 { return CLOSED_BRACE; }
4165 YY_BREAK
4166 case 13:
4167 YY_RULE_SETUP
4168 { return OPEN_PAREN; }
4169 YY_BREAK
4170 case 14:
4171 YY_RULE_SETUP
4172 { return CLOSED_PAREN; }
4173 YY_BREAK
4174 case 15:
4175 /* rule 15 can match eol */
4176 YY_RULE_SETUP
4177 { return NEWLINE; }
4178 YY_BREAK
4179 case 16:
4180 /* rule 16 can match eol */
4181 YY_RULE_SETUP
4182 { return NEWLINE; }
4183 YY_BREAK
4184 case 17:
4185 YY_RULE_SETUP
4186 { return NEWLINE; }
4187 YY_BREAK
4188 case 18:
4189 YY_RULE_SETUP
4190 { return INTEGER_LITERAL; }
4191 YY_BREAK
4192 case 19:
4193 YY_RULE_SETUP
4194 {}
4195 YY_BREAK
4196 case 20:
4197 YY_RULE_SETUP
4198 { return STRING_LITERAL; }
4199 YY_BREAK
4200 case 21:
4201 YY_RULE_SETUP
4202 { return STRING_LITERAL; }
4203 YY_BREAK
4204 case 22:
4205 /* rule 22 can match eol */
4206 YY_RULE_SETUP
4207 { return CSTRING; }
4208 YY_BREAK
4209 case 23:
4210 YY_RULE_SETUP
4211 ECHO;
4212 YY_BREAK
4213 case YY_STATE_EOF(INITIAL):
4214 yyterminate();
4215
4216 case YY_END_OF_BUFFER:
4217 {
4218 /* Amount of text matched not including the EOB char. */
4219 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
4220
4221 /* Undo the effects of YY_DO_BEFORE_ACTION. */
4222 *yy_cp = yyg->yy_hold_char;
4223 YY_RESTORE_YY_MORE_OFFSET
4224
4225 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
4226 {
4227 /* We're scanning a new file or input source. It's
4228 * possible that this happened because the user
4229 * just pointed yyin at a new source and called
4230 * gdbwire_mi_lex(). If so, then we have to assure
4231 * consistency between YY_CURRENT_BUFFER and our
4232 * globals. Here is the right place to do so, because
4233 * this is the first action (other than possibly a
4234 * back-up) that will match for the new input source.
4235 */
4236 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
4237 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
4238 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
4239 }
4240
4241 /* Note that here we test for yy_c_buf_p "<=" to the position
4242 * of the first EOB in the buffer, since yy_c_buf_p will
4243 * already have been incremented past the NUL character
4244 * (since all states make transitions on EOB to the
4245 * end-of-buffer state). Contrast this with the test
4246 * in input().
4247 */
4248 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
4249 { /* This was really a NUL. */
4250 yy_state_type yy_next_state;
4251
4252 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
4253
4254 yy_current_state = yy_get_previous_state( yyscanner );
4255
4256 /* Okay, we're now positioned to make the NUL
4257 * transition. We couldn't have
4258 * yy_get_previous_state() go ahead and do it
4259 * for us because it doesn't know how to deal
4260 * with the possibility of jamming (and we don't
4261 * want to build jamming into it because then it
4262 * will run more slowly).
4263 */
4264
4265 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
4266
4267 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
4268
4269 if ( yy_next_state )
4270 {
4271 /* Consume the NUL. */
4272 yy_cp = ++yyg->yy_c_buf_p;
4273 yy_current_state = yy_next_state;
4274 goto yy_match;
4275 }
4276
4277 else
4278 {
4279 yy_cp = yyg->yy_last_accepting_cpos;
4280 yy_current_state = yyg->yy_last_accepting_state;
4281 goto yy_find_action;
4282 }
4283 }
4284
4285 else switch ( yy_get_next_buffer( yyscanner ) )
4286 {
4287 case EOB_ACT_END_OF_FILE:
4288 {
4289 yyg->yy_did_buffer_switch_on_eof = 0;
4290
4291 if ( gdbwire_mi_wrap(yyscanner ) )
4292 {
4293 /* Note: because we've taken care in
4294 * yy_get_next_buffer() to have set up
4295 * yytext, we can now set up
4296 * yy_c_buf_p so that if some total
4297 * hoser (like flex itself) wants to
4298 * call the scanner after we return the
4299 * YY_NULL, it'll still work - another
4300 * YY_NULL will get returned.
4301 */
4302 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
4303
4304 yy_act = YY_STATE_EOF(YY_START);
4305 goto do_action;
4306 }
4307
4308 else
4309 {
4310 if ( ! yyg->yy_did_buffer_switch_on_eof )
4311 YY_NEW_FILE;
4312 }
4313 break;
4314 }
4315
4316 case EOB_ACT_CONTINUE_SCAN:
4317 yyg->yy_c_buf_p =
4318 yyg->yytext_ptr + yy_amount_of_matched_text;
4319
4320 yy_current_state = yy_get_previous_state( yyscanner );
4321
4322 yy_cp = yyg->yy_c_buf_p;
4323 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
4324 goto yy_match;
4325
4326 case EOB_ACT_LAST_MATCH:
4327 yyg->yy_c_buf_p =
4328 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
4329
4330 yy_current_state = yy_get_previous_state( yyscanner );
4331
4332 yy_cp = yyg->yy_c_buf_p;
4333 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
4334 goto yy_find_action;
4335 }
4336 break;
4337 }
4338
4339 default:
4340 YY_FATAL_ERROR(
4341 "fatal flex scanner internal error--no action found" );
4342 } /* end of action switch */
4343 } /* end of scanning one token */
4344 } /* end of user's declarations */
4345 } /* end of gdbwire_mi_lex */
4346
4347 /* yy_get_next_buffer - try to read in a new buffer
4348 *
4349 * Returns a code representing an action:
4350 * EOB_ACT_LAST_MATCH -
4351 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
4352 * EOB_ACT_END_OF_FILE - end of file
4353 */
yy_get_next_buffer(yyscan_t yyscanner)4354 static int yy_get_next_buffer (yyscan_t yyscanner)
4355 {
4356 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4357 char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
4358 char *source = yyg->yytext_ptr;
4359 yy_size_t number_to_move, i;
4360 int ret_val;
4361
4362 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
4363 YY_FATAL_ERROR(
4364 "fatal flex scanner internal error--end of buffer missed" );
4365
4366 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
4367 { /* Don't try to fill the buffer, so this is an EOF. */
4368 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
4369 {
4370 /* We matched a single character, the EOB, so
4371 * treat this as a final EOF.
4372 */
4373 return EOB_ACT_END_OF_FILE;
4374 }
4375
4376 else
4377 {
4378 /* We matched some text prior to the EOB, first
4379 * process it.
4380 */
4381 return EOB_ACT_LAST_MATCH;
4382 }
4383 }
4384
4385 /* Try to read more data. */
4386
4387 /* First move last chars to start of buffer. */
4388 number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
4389
4390 for ( i = 0; i < number_to_move; ++i )
4391 *(dest++) = *(source++);
4392
4393 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
4394 /* don't do the read, it's not guaranteed to return an EOF,
4395 * just force an EOF
4396 */
4397 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
4398
4399 else
4400 {
4401 int num_to_read =
4402 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
4403
4404 while ( num_to_read <= 0 )
4405 { /* Not enough room in the buffer - grow it. */
4406
4407 /* just a shorter name for the current buffer */
4408 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
4409
4410 int yy_c_buf_p_offset =
4411 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
4412
4413 if ( b->yy_is_our_buffer )
4414 {
4415 int new_size = b->yy_buf_size * 2;
4416
4417 if ( new_size <= 0 )
4418 b->yy_buf_size += b->yy_buf_size / 8;
4419 else
4420 b->yy_buf_size *= 2;
4421
4422 b->yy_ch_buf = (char *)
4423 /* Include room in for 2 EOB chars. */
4424 gdbwire_mi_realloc((void *) b->yy_ch_buf,(yy_size_t) (b->yy_buf_size + 2) ,yyscanner );
4425 }
4426 else
4427 /* Can't grow it, we don't own it. */
4428 b->yy_ch_buf = NULL;
4429
4430 if ( ! b->yy_ch_buf )
4431 YY_FATAL_ERROR(
4432 "fatal error - scanner input buffer overflow" );
4433
4434 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
4435
4436 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
4437 number_to_move - 1;
4438
4439 }
4440
4441 if ( num_to_read > YY_READ_BUF_SIZE )
4442 num_to_read = YY_READ_BUF_SIZE;
4443
4444 /* Read in more data. */
4445 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
4446 yyg->yy_n_chars, num_to_read );
4447
4448 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
4449 }
4450
4451 if ( yyg->yy_n_chars == 0 )
4452 {
4453 if ( number_to_move == YY_MORE_ADJ )
4454 {
4455 ret_val = EOB_ACT_END_OF_FILE;
4456 gdbwire_mi_restart(yyin ,yyscanner);
4457 }
4458
4459 else
4460 {
4461 ret_val = EOB_ACT_LAST_MATCH;
4462 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
4463 YY_BUFFER_EOF_PENDING;
4464 }
4465 }
4466
4467 else
4468 ret_val = EOB_ACT_CONTINUE_SCAN;
4469
4470 if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
4471 /* Extend the array by 50%, plus the number we really need. */
4472 int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
4473 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) gdbwire_mi_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,(yy_size_t) new_size ,yyscanner );
4474 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
4475 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
4476 }
4477
4478 yyg->yy_n_chars += number_to_move;
4479 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
4480 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
4481
4482 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
4483
4484 return ret_val;
4485 }
4486
4487 /* yy_get_previous_state - get the state just before the EOB char was reached */
4488
yy_get_previous_state(yyscan_t yyscanner)4489 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
4490 {
4491 yy_state_type yy_current_state;
4492 char *yy_cp;
4493 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4494
4495 yy_current_state = yyg->yy_start;
4496
4497 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
4498 {
4499 YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
4500 if ( yy_accept[yy_current_state] )
4501 {
4502 yyg->yy_last_accepting_state = yy_current_state;
4503 yyg->yy_last_accepting_cpos = yy_cp;
4504 }
4505 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
4506 {
4507 yy_current_state = (int) yy_def[yy_current_state];
4508 if ( yy_current_state >= 33 )
4509 yy_c = yy_meta[(unsigned int) yy_c];
4510 }
4511 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
4512 }
4513
4514 return yy_current_state;
4515 }
4516
4517 /* yy_try_NUL_trans - try to make a transition on the NUL character
4518 *
4519 * synopsis
4520 * next_state = yy_try_NUL_trans( current_state );
4521 */
yy_try_NUL_trans(yy_state_type yy_current_state,yyscan_t yyscanner)4522 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
4523 {
4524 int yy_is_jam;
4525 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
4526 char *yy_cp = yyg->yy_c_buf_p;
4527
4528 YY_CHAR yy_c = 1;
4529 if ( yy_accept[yy_current_state] )
4530 {
4531 yyg->yy_last_accepting_state = yy_current_state;
4532 yyg->yy_last_accepting_cpos = yy_cp;
4533 }
4534 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
4535 {
4536 yy_current_state = (int) yy_def[yy_current_state];
4537 if ( yy_current_state >= 33 )
4538 yy_c = yy_meta[(unsigned int) yy_c];
4539 }
4540 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
4541 yy_is_jam = (yy_current_state == 32);
4542
4543 (void)yyg;
4544 return yy_is_jam ? 0 : yy_current_state;
4545 }
4546
4547 #ifndef YY_NO_UNPUT
4548
4549 #endif
4550
4551 #ifndef YY_NO_INPUT
4552 #ifdef __cplusplus
yyinput(yyscan_t yyscanner)4553 static int yyinput (yyscan_t yyscanner)
4554 #else
4555 static int input (yyscan_t yyscanner)
4556 #endif
4557
4558 {
4559 int c;
4560 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4561
4562 *yyg->yy_c_buf_p = yyg->yy_hold_char;
4563
4564 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
4565 {
4566 /* yy_c_buf_p now points to the character we want to return.
4567 * If this occurs *before* the EOB characters, then it's a
4568 * valid NUL; if not, then we've hit the end of the buffer.
4569 */
4570 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
4571 /* This was really a NUL. */
4572 *yyg->yy_c_buf_p = '\0';
4573
4574 else
4575 { /* need more input */
4576 int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
4577 ++yyg->yy_c_buf_p;
4578
4579 switch ( yy_get_next_buffer( yyscanner ) )
4580 {
4581 case EOB_ACT_LAST_MATCH:
4582 /* This happens because yy_g_n_b()
4583 * sees that we've accumulated a
4584 * token and flags that we need to
4585 * try matching the token before
4586 * proceeding. But for input(),
4587 * there's no matching to consider.
4588 * So convert the EOB_ACT_LAST_MATCH
4589 * to EOB_ACT_END_OF_FILE.
4590 */
4591
4592 /* Reset buffer status. */
4593 gdbwire_mi_restart(yyin ,yyscanner);
4594
4595 /*FALLTHROUGH*/
4596
4597 case EOB_ACT_END_OF_FILE:
4598 {
4599 if ( gdbwire_mi_wrap(yyscanner ) )
4600 return 0;
4601
4602 if ( ! yyg->yy_did_buffer_switch_on_eof )
4603 YY_NEW_FILE;
4604 #ifdef __cplusplus
4605 return yyinput(yyscanner);
4606 #else
4607 return input(yyscanner);
4608 #endif
4609 }
4610
4611 case EOB_ACT_CONTINUE_SCAN:
4612 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
4613 break;
4614 }
4615 }
4616 }
4617
4618 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
4619 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
4620 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
4621
4622 return c;
4623 }
4624 #endif /* ifndef YY_NO_INPUT */
4625
4626 /** Immediately switch to a different input stream.
4627 * @param input_file A readable stream.
4628 * @param yyscanner The scanner object.
4629 * @note This function does not reset the start condition to @c INITIAL .
4630 */
gdbwire_mi_restart(FILE * input_file,yyscan_t yyscanner)4631 void gdbwire_mi_restart (FILE * input_file , yyscan_t yyscanner)
4632 {
4633 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4634
4635 if ( ! YY_CURRENT_BUFFER ){
4636 gdbwire_mi_ensure_buffer_stack (yyscanner);
4637 YY_CURRENT_BUFFER_LVALUE =
4638 gdbwire_mi__create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
4639 }
4640
4641 gdbwire_mi__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
4642 gdbwire_mi__load_buffer_state(yyscanner );
4643 }
4644
4645 /** Switch to a different input buffer.
4646 * @param new_buffer The new input buffer.
4647 * @param yyscanner The scanner object.
4648 */
gdbwire_mi__switch_to_buffer(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)4649 void gdbwire_mi__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
4650 {
4651 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4652
4653 /* TODO. We should be able to replace this entire function body
4654 * with
4655 * gdbwire_mi_pop_buffer_state();
4656 * gdbwire_mi_push_buffer_state(new_buffer);
4657 */
4658 gdbwire_mi_ensure_buffer_stack (yyscanner);
4659 if ( YY_CURRENT_BUFFER == new_buffer )
4660 return;
4661
4662 if ( YY_CURRENT_BUFFER )
4663 {
4664 /* Flush out information for old buffer. */
4665 *yyg->yy_c_buf_p = yyg->yy_hold_char;
4666 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
4667 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
4668 }
4669
4670 YY_CURRENT_BUFFER_LVALUE = new_buffer;
4671 gdbwire_mi__load_buffer_state(yyscanner );
4672
4673 /* We don't actually know whether we did this switch during
4674 * EOF (gdbwire_mi_wrap()) processing, but the only time this flag
4675 * is looked at is after gdbwire_mi_wrap() is called, so it's safe
4676 * to go ahead and always set it.
4677 */
4678 yyg->yy_did_buffer_switch_on_eof = 1;
4679 }
4680
gdbwire_mi__load_buffer_state(yyscan_t yyscanner)4681 static void gdbwire_mi__load_buffer_state (yyscan_t yyscanner)
4682 {
4683 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4684 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
4685 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
4686 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
4687 yyg->yy_hold_char = *yyg->yy_c_buf_p;
4688 }
4689
4690 /** Allocate and initialize an input buffer state.
4691 * @param file A readable stream.
4692 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
4693 * @param yyscanner The scanner object.
4694 * @return the allocated buffer state.
4695 */
gdbwire_mi__create_buffer(FILE * file,int size,yyscan_t yyscanner)4696 YY_BUFFER_STATE gdbwire_mi__create_buffer (FILE * file, int size , yyscan_t yyscanner)
4697 {
4698 YY_BUFFER_STATE b;
4699
4700 b = (YY_BUFFER_STATE) gdbwire_mi_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
4701 if ( ! b )
4702 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi__create_buffer()" );
4703
4704 b->yy_buf_size = size;
4705
4706 /* yy_ch_buf has to be 2 characters longer than the size given because
4707 * we need to put in 2 end-of-buffer characters.
4708 */
4709 b->yy_ch_buf = (char *) gdbwire_mi_alloc((yy_size_t) (b->yy_buf_size + 2) ,yyscanner );
4710 if ( ! b->yy_ch_buf )
4711 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi__create_buffer()" );
4712
4713 b->yy_is_our_buffer = 1;
4714
4715 gdbwire_mi__init_buffer(b,file ,yyscanner);
4716
4717 return b;
4718 }
4719
4720 /** Destroy the buffer.
4721 * @param b a buffer created with gdbwire_mi__create_buffer()
4722 * @param yyscanner The scanner object.
4723 */
gdbwire_mi__delete_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)4724 void gdbwire_mi__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
4725 {
4726 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4727
4728 if ( ! b )
4729 return;
4730
4731 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
4732 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
4733
4734 if ( b->yy_is_our_buffer )
4735 gdbwire_mi_free((void *) b->yy_ch_buf ,yyscanner );
4736
4737 gdbwire_mi_free((void *) b ,yyscanner );
4738 }
4739
4740 /* Initializes or reinitializes a buffer.
4741 * This function is sometimes called more than once on the same buffer,
4742 * such as during a gdbwire_mi_restart() or at EOF.
4743 */
gdbwire_mi__init_buffer(YY_BUFFER_STATE b,FILE * file,yyscan_t yyscanner)4744 static void gdbwire_mi__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
4745
4746 {
4747 int oerrno = errno;
4748 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4749
4750 gdbwire_mi__flush_buffer(b ,yyscanner);
4751
4752 b->yy_input_file = file;
4753 b->yy_fill_buffer = 1;
4754
4755 /* If b is the current buffer, then gdbwire_mi__init_buffer was _probably_
4756 * called from gdbwire_mi_restart() or through yy_get_next_buffer.
4757 * In that case, we don't want to reset the lineno or column.
4758 */
4759 if (b != YY_CURRENT_BUFFER){
4760 b->yy_bs_lineno = 1;
4761 b->yy_bs_column = 0;
4762 }
4763
4764 b->yy_is_interactive = 0;
4765
4766 errno = oerrno;
4767 }
4768
4769 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
4770 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
4771 * @param yyscanner The scanner object.
4772 */
gdbwire_mi__flush_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)4773 void gdbwire_mi__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
4774 {
4775 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4776 if ( ! b )
4777 return;
4778
4779 b->yy_n_chars = 0;
4780
4781 /* We always need two end-of-buffer characters. The first causes
4782 * a transition to the end-of-buffer state. The second causes
4783 * a jam in that state.
4784 */
4785 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
4786 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
4787
4788 b->yy_buf_pos = &b->yy_ch_buf[0];
4789
4790 b->yy_at_bol = 1;
4791 b->yy_buffer_status = YY_BUFFER_NEW;
4792
4793 if ( b == YY_CURRENT_BUFFER )
4794 gdbwire_mi__load_buffer_state(yyscanner );
4795 }
4796
4797 /** Pushes the new state onto the stack. The new state becomes
4798 * the current state. This function will allocate the stack
4799 * if necessary.
4800 * @param new_buffer The new state.
4801 * @param yyscanner The scanner object.
4802 */
gdbwire_mi_push_buffer_state(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)4803 void gdbwire_mi_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
4804 {
4805 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4806 if (new_buffer == NULL)
4807 return;
4808
4809 gdbwire_mi_ensure_buffer_stack(yyscanner);
4810
4811 /* This block is copied from gdbwire_mi__switch_to_buffer. */
4812 if ( YY_CURRENT_BUFFER )
4813 {
4814 /* Flush out information for old buffer. */
4815 *yyg->yy_c_buf_p = yyg->yy_hold_char;
4816 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
4817 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
4818 }
4819
4820 /* Only push if top exists. Otherwise, replace top. */
4821 if (YY_CURRENT_BUFFER)
4822 yyg->yy_buffer_stack_top++;
4823 YY_CURRENT_BUFFER_LVALUE = new_buffer;
4824
4825 /* copied from gdbwire_mi__switch_to_buffer. */
4826 gdbwire_mi__load_buffer_state(yyscanner );
4827 yyg->yy_did_buffer_switch_on_eof = 1;
4828 }
4829
4830 /** Removes and deletes the top of the stack, if present.
4831 * The next element becomes the new top.
4832 * @param yyscanner The scanner object.
4833 */
gdbwire_mi_pop_buffer_state(yyscan_t yyscanner)4834 void gdbwire_mi_pop_buffer_state (yyscan_t yyscanner)
4835 {
4836 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4837 if (!YY_CURRENT_BUFFER)
4838 return;
4839
4840 gdbwire_mi__delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
4841 YY_CURRENT_BUFFER_LVALUE = NULL;
4842 if (yyg->yy_buffer_stack_top > 0)
4843 --yyg->yy_buffer_stack_top;
4844
4845 if (YY_CURRENT_BUFFER) {
4846 gdbwire_mi__load_buffer_state(yyscanner );
4847 yyg->yy_did_buffer_switch_on_eof = 1;
4848 }
4849 }
4850
4851 /* Allocates the stack if it does not exist.
4852 * Guarantees space for at least one push.
4853 */
gdbwire_mi_ensure_buffer_stack(yyscan_t yyscanner)4854 static void gdbwire_mi_ensure_buffer_stack (yyscan_t yyscanner)
4855 {
4856 int num_to_alloc;
4857 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4858
4859 if (!yyg->yy_buffer_stack) {
4860
4861 /* First allocation is just for 2 elements, since we don't know if this
4862 * scanner will even need a stack. We use 2 instead of 1 to avoid an
4863 * immediate realloc on the next call.
4864 */
4865 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
4866 yyg->yy_buffer_stack = (struct yy_buffer_state**)gdbwire_mi_alloc
4867 (num_to_alloc * sizeof(struct yy_buffer_state*)
4868 , yyscanner);
4869 if ( ! yyg->yy_buffer_stack )
4870 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi_ensure_buffer_stack()" );
4871
4872 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
4873
4874 yyg->yy_buffer_stack_max = num_to_alloc;
4875 yyg->yy_buffer_stack_top = 0;
4876 return;
4877 }
4878
4879 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
4880
4881 /* Increase the buffer to prepare for a possible push. */
4882 yy_size_t grow_size = 8 /* arbitrary grow size */;
4883
4884 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
4885 yyg->yy_buffer_stack = (struct yy_buffer_state**)gdbwire_mi_realloc
4886 (yyg->yy_buffer_stack,
4887 num_to_alloc * sizeof(struct yy_buffer_state*)
4888 , yyscanner);
4889 if ( ! yyg->yy_buffer_stack )
4890 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi_ensure_buffer_stack()" );
4891
4892 /* zero only the new slots.*/
4893 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
4894 yyg->yy_buffer_stack_max = num_to_alloc;
4895 }
4896 }
4897
4898 /** Setup the input buffer state to scan directly from a user-specified character buffer.
4899 * @param base the character buffer
4900 * @param size the size in bytes of the character buffer
4901 * @param yyscanner The scanner object.
4902 * @return the newly allocated buffer state object.
4903 */
gdbwire_mi__scan_buffer(char * base,yy_size_t size,yyscan_t yyscanner)4904 YY_BUFFER_STATE gdbwire_mi__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
4905 {
4906 YY_BUFFER_STATE b;
4907
4908 if ( size < 2 ||
4909 base[size-2] != YY_END_OF_BUFFER_CHAR ||
4910 base[size-1] != YY_END_OF_BUFFER_CHAR )
4911 /* They forgot to leave room for the EOB's. */
4912 return NULL;
4913
4914 b = (YY_BUFFER_STATE) gdbwire_mi_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
4915 if ( ! b )
4916 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi__scan_buffer()" );
4917
4918 b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
4919 b->yy_buf_pos = b->yy_ch_buf = base;
4920 b->yy_is_our_buffer = 0;
4921 b->yy_input_file = NULL;
4922 b->yy_n_chars = b->yy_buf_size;
4923 b->yy_is_interactive = 0;
4924 b->yy_at_bol = 1;
4925 b->yy_fill_buffer = 0;
4926 b->yy_buffer_status = YY_BUFFER_NEW;
4927
4928 gdbwire_mi__switch_to_buffer(b ,yyscanner );
4929
4930 return b;
4931 }
4932
4933 /** Setup the input buffer state to scan a string. The next call to gdbwire_mi_lex() will
4934 * scan from a @e copy of @a str.
4935 * @param yystr a NUL-terminated string to scan
4936 * @param yyscanner The scanner object.
4937 * @return the newly allocated buffer state object.
4938 * @note If you want to scan bytes that may contain NUL values, then use
4939 * gdbwire_mi__scan_bytes() instead.
4940 */
gdbwire_mi__scan_string(yyconst char * yystr,yyscan_t yyscanner)4941 YY_BUFFER_STATE gdbwire_mi__scan_string (yyconst char * yystr , yyscan_t yyscanner)
4942 {
4943
4944 return gdbwire_mi__scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
4945 }
4946
4947 /** Setup the input buffer state to scan the given bytes. The next call to gdbwire_mi_lex() will
4948 * scan from a @e copy of @a bytes.
4949 * @param yybytes the byte buffer to scan
4950 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
4951 * @param yyscanner The scanner object.
4952 * @return the newly allocated buffer state object.
4953 */
gdbwire_mi__scan_bytes(yyconst char * yybytes,int _yybytes_len,yyscan_t yyscanner)4954 YY_BUFFER_STATE gdbwire_mi__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
4955 {
4956 YY_BUFFER_STATE b;
4957 char *buf;
4958 yy_size_t n;
4959 yy_size_t i;
4960
4961 /* Get memory for full buffer, including space for trailing EOB's. */
4962 n = (yy_size_t) _yybytes_len + 2;
4963 buf = (char *) gdbwire_mi_alloc(n ,yyscanner );
4964 if ( ! buf )
4965 YY_FATAL_ERROR( "out of dynamic memory in gdbwire_mi__scan_bytes()" );
4966
4967 for ( i = 0; i < _yybytes_len; ++i )
4968 buf[i] = yybytes[i];
4969
4970 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
4971
4972 b = gdbwire_mi__scan_buffer(buf,n ,yyscanner);
4973 if ( ! b )
4974 YY_FATAL_ERROR( "bad buffer in gdbwire_mi__scan_bytes()" );
4975
4976 /* It's okay to grow etc. this buffer, and we should throw it
4977 * away when we're done.
4978 */
4979 b->yy_is_our_buffer = 1;
4980
4981 return b;
4982 }
4983
4984 #ifndef YY_EXIT_FAILURE
4985 #define YY_EXIT_FAILURE 2
4986 #endif
4987
yy_fatal_error(yyconst char * msg,yyscan_t yyscanner)4988 static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
4989 {
4990 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
4991 (void)yyg;
4992 (void) fprintf( stderr, "%s\n", msg );
4993 exit( YY_EXIT_FAILURE );
4994 }
4995
4996 /* Redefine yyless() so it works in section 3 code. */
4997
4998 #undef yyless
4999 #define yyless(n) \
5000 do \
5001 { \
5002 /* Undo effects of setting up yytext. */ \
5003 yy_size_t yyless_macro_arg = (n); \
5004 YY_LESS_LINENO(yyless_macro_arg);\
5005 yytext[yyleng] = yyg->yy_hold_char; \
5006 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
5007 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
5008 *yyg->yy_c_buf_p = '\0'; \
5009 yyleng = yyless_macro_arg; \
5010 } \
5011 while ( 0 )
5012
5013 /* Accessor methods (get/set functions) to struct members. */
5014
5015 /** Get the user-defined data for this scanner.
5016 * @param yyscanner The scanner object.
5017 */
gdbwire_mi_get_extra(yyscan_t yyscanner)5018 YY_EXTRA_TYPE gdbwire_mi_get_extra (yyscan_t yyscanner)
5019 {
5020 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5021 return yyextra;
5022 }
5023
5024 /** Get the current line number.
5025 * @param yyscanner The scanner object.
5026 */
gdbwire_mi_get_lineno(yyscan_t yyscanner)5027 int gdbwire_mi_get_lineno (yyscan_t yyscanner)
5028 {
5029 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5030
5031 if (! YY_CURRENT_BUFFER)
5032 return 0;
5033
5034 return yylineno;
5035 }
5036
5037 /** Get the current column number.
5038 * @param yyscanner The scanner object.
5039 */
gdbwire_mi_get_column(yyscan_t yyscanner)5040 int gdbwire_mi_get_column (yyscan_t yyscanner)
5041 {
5042 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5043
5044 if (! YY_CURRENT_BUFFER)
5045 return 0;
5046
5047 return yycolumn;
5048 }
5049
5050 /** Get the input stream.
5051 * @param yyscanner The scanner object.
5052 */
gdbwire_mi_get_in(yyscan_t yyscanner)5053 FILE *gdbwire_mi_get_in (yyscan_t yyscanner)
5054 {
5055 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5056 return yyin;
5057 }
5058
5059 /** Get the output stream.
5060 * @param yyscanner The scanner object.
5061 */
gdbwire_mi_get_out(yyscan_t yyscanner)5062 FILE *gdbwire_mi_get_out (yyscan_t yyscanner)
5063 {
5064 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5065 return yyout;
5066 }
5067
5068 /** Get the length of the current token.
5069 * @param yyscanner The scanner object.
5070 */
gdbwire_mi_get_leng(yyscan_t yyscanner)5071 int gdbwire_mi_get_leng (yyscan_t yyscanner)
5072 {
5073 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5074 return yyleng;
5075 }
5076
5077 /** Get the current token.
5078 * @param yyscanner The scanner object.
5079 */
5080
gdbwire_mi_get_text(yyscan_t yyscanner)5081 char *gdbwire_mi_get_text (yyscan_t yyscanner)
5082 {
5083 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5084 return yytext;
5085 }
5086
5087 /** Set the user-defined data. This data is never touched by the scanner.
5088 * @param user_defined The data to be associated with this scanner.
5089 * @param yyscanner The scanner object.
5090 */
gdbwire_mi_set_extra(YY_EXTRA_TYPE user_defined,yyscan_t yyscanner)5091 void gdbwire_mi_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
5092 {
5093 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5094 yyextra = user_defined ;
5095 }
5096
5097 /** Set the current line number.
5098 * @param _line_number line number
5099 * @param yyscanner The scanner object.
5100 */
gdbwire_mi_set_lineno(int _line_number,yyscan_t yyscanner)5101 void gdbwire_mi_set_lineno (int _line_number , yyscan_t yyscanner)
5102 {
5103 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5104
5105 /* lineno is only valid if an input buffer exists. */
5106 if (! YY_CURRENT_BUFFER )
5107 YY_FATAL_ERROR( "gdbwire_mi_set_lineno called with no buffer" );
5108
5109 yylineno = _line_number;
5110 }
5111
5112 /** Set the current column.
5113 * @param _column_no column number
5114 * @param yyscanner The scanner object.
5115 */
gdbwire_mi_set_column(int _column_no,yyscan_t yyscanner)5116 void gdbwire_mi_set_column (int _column_no , yyscan_t yyscanner)
5117 {
5118 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5119
5120 /* column is only valid if an input buffer exists. */
5121 if (! YY_CURRENT_BUFFER )
5122 YY_FATAL_ERROR( "gdbwire_mi_set_column called with no buffer" );
5123
5124 yycolumn = _column_no;
5125 }
5126
5127 /** Set the input stream. This does not discard the current
5128 * input buffer.
5129 * @param _in_str A readable stream.
5130 * @param yyscanner The scanner object.
5131 * @see gdbwire_mi__switch_to_buffer
5132 */
gdbwire_mi_set_in(FILE * _in_str,yyscan_t yyscanner)5133 void gdbwire_mi_set_in (FILE * _in_str , yyscan_t yyscanner)
5134 {
5135 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5136 yyin = _in_str ;
5137 }
5138
gdbwire_mi_set_out(FILE * _out_str,yyscan_t yyscanner)5139 void gdbwire_mi_set_out (FILE * _out_str , yyscan_t yyscanner)
5140 {
5141 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5142 yyout = _out_str ;
5143 }
5144
gdbwire_mi_get_debug(yyscan_t yyscanner)5145 int gdbwire_mi_get_debug (yyscan_t yyscanner)
5146 {
5147 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5148 return yy_flex_debug;
5149 }
5150
gdbwire_mi_set_debug(int _bdebug,yyscan_t yyscanner)5151 void gdbwire_mi_set_debug (int _bdebug , yyscan_t yyscanner)
5152 {
5153 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5154 yy_flex_debug = _bdebug ;
5155 }
5156
5157 /* Accessor methods for yylval and yylloc */
5158
5159 /* User-visible API */
5160
5161 /* gdbwire_mi_lex_init is special because it creates the scanner itself, so it is
5162 * the ONLY reentrant function that doesn't take the scanner as the last argument.
5163 * That's why we explicitly handle the declaration, instead of using our macros.
5164 */
5165
gdbwire_mi_lex_init(yyscan_t * ptr_yy_globals)5166 int gdbwire_mi_lex_init(yyscan_t* ptr_yy_globals)
5167
5168 {
5169 if (ptr_yy_globals == NULL){
5170 errno = EINVAL;
5171 return 1;
5172 }
5173
5174 *ptr_yy_globals = (yyscan_t) gdbwire_mi_alloc ( sizeof( struct yyguts_t ), NULL );
5175
5176 if (*ptr_yy_globals == NULL){
5177 errno = ENOMEM;
5178 return 1;
5179 }
5180
5181 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
5182 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
5183
5184 return yy_init_globals ( *ptr_yy_globals );
5185 }
5186
5187 /* gdbwire_mi_lex_init_extra has the same functionality as gdbwire_mi_lex_init, but follows the
5188 * convention of taking the scanner as the last argument. Note however, that
5189 * this is a *pointer* to a scanner, as it will be allocated by this call (and
5190 * is the reason, too, why this function also must handle its own declaration).
5191 * The user defined value in the first argument will be available to gdbwire_mi_alloc in
5192 * the yyextra field.
5193 */
5194
gdbwire_mi_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t * ptr_yy_globals)5195 int gdbwire_mi_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
5196
5197 {
5198 struct yyguts_t dummy_yyguts;
5199
5200 gdbwire_mi_set_extra (yy_user_defined, &dummy_yyguts);
5201
5202 if (ptr_yy_globals == NULL){
5203 errno = EINVAL;
5204 return 1;
5205 }
5206
5207 *ptr_yy_globals = (yyscan_t) gdbwire_mi_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
5208
5209 if (*ptr_yy_globals == NULL){
5210 errno = ENOMEM;
5211 return 1;
5212 }
5213
5214 /* By setting to 0xAA, we expose bugs in
5215 yy_init_globals. Leave at 0x00 for releases. */
5216 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
5217
5218 gdbwire_mi_set_extra (yy_user_defined, *ptr_yy_globals);
5219
5220 return yy_init_globals ( *ptr_yy_globals );
5221 }
5222
yy_init_globals(yyscan_t yyscanner)5223 static int yy_init_globals (yyscan_t yyscanner)
5224 {
5225 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5226 /* Initialization is the same as for the non-reentrant scanner.
5227 * This function is called from gdbwire_mi_lex_destroy(), so don't allocate here.
5228 */
5229
5230 yyg->yy_buffer_stack = NULL;
5231 yyg->yy_buffer_stack_top = 0;
5232 yyg->yy_buffer_stack_max = 0;
5233 yyg->yy_c_buf_p = NULL;
5234 yyg->yy_init = 0;
5235 yyg->yy_start = 0;
5236
5237 yyg->yy_start_stack_ptr = 0;
5238 yyg->yy_start_stack_depth = 0;
5239 yyg->yy_start_stack = NULL;
5240
5241 /* Defined in main.c */
5242 #ifdef YY_STDINIT
5243 yyin = stdin;
5244 yyout = stdout;
5245 #else
5246 yyin = NULL;
5247 yyout = NULL;
5248 #endif
5249
5250 /* For future reference: Set errno on error, since we are called by
5251 * gdbwire_mi_lex_init()
5252 */
5253 return 0;
5254 }
5255
5256 /* gdbwire_mi_lex_destroy is for both reentrant and non-reentrant scanners. */
gdbwire_mi_lex_destroy(yyscan_t yyscanner)5257 int gdbwire_mi_lex_destroy (yyscan_t yyscanner)
5258 {
5259 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5260
5261 /* Pop the buffer stack, destroying each element. */
5262 while(YY_CURRENT_BUFFER){
5263 gdbwire_mi__delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
5264 YY_CURRENT_BUFFER_LVALUE = NULL;
5265 gdbwire_mi_pop_buffer_state(yyscanner);
5266 }
5267
5268 /* Destroy the stack itself. */
5269 gdbwire_mi_free(yyg->yy_buffer_stack ,yyscanner);
5270 yyg->yy_buffer_stack = NULL;
5271
5272 /* Destroy the start condition stack. */
5273 gdbwire_mi_free(yyg->yy_start_stack ,yyscanner );
5274 yyg->yy_start_stack = NULL;
5275
5276 /* Reset the globals. This is important in a non-reentrant scanner so the next time
5277 * gdbwire_mi_lex() is called, initialization will occur. */
5278 yy_init_globals( yyscanner);
5279
5280 /* Destroy the main struct (reentrant only). */
5281 gdbwire_mi_free ( yyscanner , yyscanner );
5282 yyscanner = NULL;
5283 return 0;
5284 }
5285
5286 /*
5287 * Internal utility routines.
5288 */
5289
5290 #ifndef yytext_ptr
yy_flex_strncpy(char * s1,yyconst char * s2,int n,yyscan_t yyscanner)5291 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
5292 {
5293 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5294 (void)yyg;
5295
5296 int i;
5297 for ( i = 0; i < n; ++i )
5298 s1[i] = s2[i];
5299 }
5300 #endif
5301
5302 #ifdef YY_NEED_STRLEN
yy_flex_strlen(yyconst char * s,yyscan_t yyscanner)5303 static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
5304 {
5305 int n;
5306 for ( n = 0; s[n]; ++n )
5307 ;
5308
5309 return n;
5310 }
5311 #endif
5312
gdbwire_mi_alloc(yy_size_t size,yyscan_t yyscanner)5313 void *gdbwire_mi_alloc (yy_size_t size , yyscan_t yyscanner)
5314 {
5315 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5316 (void)yyg;
5317 return malloc(size);
5318 }
5319
gdbwire_mi_realloc(void * ptr,yy_size_t size,yyscan_t yyscanner)5320 void *gdbwire_mi_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
5321 {
5322 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5323 (void)yyg;
5324
5325 /* The cast to (char *) in the following accommodates both
5326 * implementations that use char* generic pointers, and those
5327 * that use void* generic pointers. It works with the latter
5328 * because both ANSI C and C++ allow castless assignment from
5329 * any pointer type to void*, and deal with argument conversions
5330 * as though doing an assignment.
5331 */
5332 return realloc(ptr, size);
5333 }
5334
gdbwire_mi_free(void * ptr,yyscan_t yyscanner)5335 void gdbwire_mi_free (void * ptr , yyscan_t yyscanner)
5336 {
5337 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
5338 (void)yyg;
5339 free( (char *) ptr ); /* see gdbwire_mi_realloc() for (char *) cast */
5340 }
5341
5342 #define YYTABLES_NAME "yytables"
5343
5344
5345
5346
5347 /***** End of gdbwire_mi_lexer.c *********************************************/
5348 /***** Begin file gdbwire_mi_grammar.c ***************************************/
5349 /* A Bison parser, made by GNU Bison 3.0.4. */
5350
5351 /* Bison implementation for Yacc-like parsers in C
5352
5353 Copyright 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
5354
5355 This program is free software: you can redistribute it and/or modify
5356 it under the terms of the GNU General Public License as published by
5357 the Free Software Foundation, either version 3 of the License, or
5358 (at your option) any later version.
5359
5360 This program is distributed in the hope that it will be useful,
5361 but WITHOUT ANY WARRANTY; without even the implied warranty of
5362 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5363 GNU General Public License for more details.
5364
5365 You should have received a copy of the GNU General Public License
5366 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5367
5368 /* As a special exception, you may create a larger work that contains
5369 part or all of the Bison parser skeleton and distribute that work
5370 under terms of your choice, so long as that work isn't itself a
5371 parser generator using the skeleton or a modified version thereof
5372 as a parser skeleton. Alternatively, if you modify or redistribute
5373 the parser skeleton itself, you may (at your option) remove this
5374 special exception, which will cause the skeleton and the resulting
5375 Bison output files to be licensed under the GNU General Public
5376 License without this special exception.
5377
5378 This special exception was added by the Free Software Foundation in
5379 version 2.2 of Bison. */
5380
5381 /* C LALR(1) parser skeleton written by Richard Stallman, by
5382 simplifying the original so-called "semantic" parser. */
5383
5384 /* All symbols defined below should begin with yy or YY, to avoid
5385 infringing on user name space. This should be done even for local
5386 variables, as they might otherwise be expanded by user macros.
5387 There are some unavoidable exceptions within include files to
5388 define necessary library symbols; they are noted "INFRINGES ON
5389 USER NAME SPACE" below. */
5390
5391 /* Identify Bison output. */
5392 #define YYBISON 1
5393
5394 /* Bison version. */
5395 #define YYBISON_VERSION "3.0.4"
5396
5397 /* Skeleton name. */
5398 #define YYSKELETON_NAME "yacc.c"
5399
5400 /* Pure parsers. */
5401 #define YYPURE 1
5402
5403 /* Push parsers. */
5404 #define YYPUSH 1
5405
5406 /* Pull parsers. */
5407 #define YYPULL 0
5408
5409
5410 /* Substitute the variable and function names. */
5411 #define yypush_parse gdbwire_mi_push_parse
5412 #define yypstate_new gdbwire_mi_pstate_new
5413 #define yypstate_delete gdbwire_mi_pstate_delete
5414 #define yypstate gdbwire_mi_pstate
5415 #define yylex gdbwire_mi_lex
5416 #define yyerror gdbwire_mi_error
5417 #define yydebug gdbwire_mi_debug
5418 #define yynerrs gdbwire_mi_nerrs
5419
5420
5421 /* Copy the first part of user declarations. */
5422
5423 #include <string.h>
5424 #include <stdio.h>
5425 #include <stdlib.h>
5426 /* #include "gdbwire_sys.h" */
5427 /* #include "gdbwire_mi_grammar.h" */
5428 /* #include "gdbwire_mi_pt.h" */
5429 /* #include "gdbwire_mi_pt_alloc.h" */
5430
5431 char *gdbwire_mi_get_text(yyscan_t yyscanner);
5432 struct gdbwire_mi_position gdbwire_mi_get_extra(yyscan_t yyscanner);
5433
5434 /**
5435 * Used only in the parser to build a gdbwire_mi_result list.
5436 *
5437 * The grammar wants to build a list of gdbwire_mi_result pointers.
5438 * However, the gdbwire_mi_result is a traditional linked list and
5439 * standard append functionality (using next to get to end of list) is slow.
5440 *
5441 * This structure allows us to keep around the last result in the list
5442 * for fast insertion.
5443 */
5444 struct gdbwire_mi_result_list {
5445 /** The gdbwire_mi_result list that is being built */
5446 struct gdbwire_mi_result *head;
5447 /** The pointer to the last result in the list for fast insertion. */
5448 struct gdbwire_mi_result **tail;
5449 };
5450
5451 /**
5452 * Allocate a gdbwire_mi_result_list data structure.
5453 *
5454 * @return
5455 * The gdbwire_mi_result_list. Use free() to release the memory.
5456 */
gdbwire_mi_result_list_alloc(void)5457 struct gdbwire_mi_result_list *gdbwire_mi_result_list_alloc(void)
5458 {
5459 struct gdbwire_mi_result_list *result;
5460 result = calloc(1, sizeof(struct gdbwire_mi_result_list));
5461 result->tail = &result->head;
5462 return result;
5463 }
5464
5465 /**
5466 * Append an item to this list.
5467 *
5468 * @param list
5469 * The list to append to.
5470 *
5471 * @param result
5472 * The result to append to the end of the list.
5473 */
gdbwire_mi_result_list_push_back(struct gdbwire_mi_result_list * list,struct gdbwire_mi_result * result)5474 void gdbwire_mi_result_list_push_back(struct gdbwire_mi_result_list *list,
5475 struct gdbwire_mi_result *result)
5476 {
5477 *list->tail = result;
5478 list->tail = &result->next;
5479 }
5480
gdbwire_mi_error(yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output,const char * s)5481 void gdbwire_mi_error(yyscan_t yyscanner,
5482 struct gdbwire_mi_output **gdbwire_mi_output, const char *s)
5483 {
5484 char *text = gdbwire_mi_get_text(yyscanner);
5485 struct gdbwire_mi_position pos = gdbwire_mi_get_extra(yyscanner);
5486
5487 *gdbwire_mi_output = gdbwire_mi_output_alloc();
5488 (*gdbwire_mi_output)->kind = GDBWIRE_MI_OUTPUT_PARSE_ERROR;
5489 (*gdbwire_mi_output)->variant.error.token = gdbwire_strdup(text);
5490 (*gdbwire_mi_output)->variant.error.pos = pos;
5491 }
5492
5493 /**
5494 * GDB/MI escapes characters in the c-string rule.
5495 *
5496 * The c-string starts and ends with a ".
5497 * Each " in the c-string is escaped with a \. So GDB turns " into \".
5498 * Each \ in the string is then escaped with a \. So GDB turns \ into \\.
5499 *
5500 * Remove the GDB/MI escape characters to provide back to the user the
5501 * original characters that GDB was intending to transmit. So
5502 * \" -> "
5503 * \\ -> \
5504 * \n -> new line
5505 * \r -> carriage return
5506 * \t -> tab
5507 *
5508 * See gdbwire_mi_grammar.txt (GDB/MI Clarifications) for more information.
5509 *
5510 * @param str
5511 * The escaped GDB/MI c-string data.
5512 *
5513 * @return
5514 * An allocated strng representing str with the escaping undone.
5515 */
gdbwire_mi_unescape_cstring(char * str)5516 static char *gdbwire_mi_unescape_cstring(char *str)
5517 {
5518 char *result;
5519 size_t r, s, length;
5520
5521 /*assert(str);*/
5522
5523 result = gdbwire_strdup(str);
5524 length = strlen(str);
5525
5526 /* a CSTRING should start and end with a quote */
5527 /*assert(result);*/
5528 /*assert(length >= 2);*/
5529
5530 for (r = 0, s = 1; s < length - 1; ++s) {
5531 if (str[s] == '\\') {
5532 switch (str[s+1]) {
5533 case 'n':
5534 result[r++] = '\n';
5535 ++s;
5536 break;
5537 case 'r':
5538 result[r++] = '\r';
5539 ++s;
5540 break;
5541 case 't':
5542 result[r++] = '\t';
5543 ++s;
5544 break;
5545 case '"':
5546 result[r++] = '\"';
5547 ++s;
5548 break;
5549 case '\\':
5550 result[r++] = '\\';
5551 ++s;
5552 break;
5553 default:
5554 result[r++] = str[s];
5555 break;
5556 }
5557 } else {
5558 result[r++] = str[s];
5559 }
5560 }
5561
5562 result[r] = 0;
5563
5564 return result;
5565 }
5566
5567
5568
5569 # ifndef YY_NULLPTR
5570 # if defined __cplusplus && 201103L <= __cplusplus
5571 # define YY_NULLPTR nullptr
5572 # else
5573 # define YY_NULLPTR 0
5574 # endif
5575 # endif
5576
5577 /* Enabling verbose error messages. */
5578 #ifdef YYERROR_VERBOSE
5579 # undef YYERROR_VERBOSE
5580 # define YYERROR_VERBOSE 1
5581 #else
5582 # define YYERROR_VERBOSE 0
5583 #endif
5584
5585 /* In a future release of Bison, this section will be replaced
5586 by #include "y.tab.h". */
5587 #ifndef YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
5588 # define YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
5589 /* Debug traces. */
5590 #ifndef YYDEBUG
5591 # define YYDEBUG 0
5592 #endif
5593 #if YYDEBUG
5594 extern int gdbwire_mi_debug;
5595 #endif
5596 /* "%code requires" blocks. */
5597
5598
5599 /* An opaque pointer. */
5600 #ifndef YY_TYPEDEF_YY_SCANNER_T
5601 #define YY_TYPEDEF_YY_SCANNER_T
5602 typedef void *yyscan_t;
5603 #endif
5604
5605 struct gdbwire_mi_output;
5606
5607
5608 /* Token type. */
5609 #ifndef YYTOKENTYPE
5610 # define YYTOKENTYPE
5611 enum yytokentype
5612 {
5613 OPEN_BRACE = 258,
5614 CLOSED_BRACE = 259,
5615 OPEN_PAREN = 260,
5616 CLOSED_PAREN = 261,
5617 ADD_OP = 262,
5618 MULT_OP = 263,
5619 EQUAL_SIGN = 264,
5620 TILDA = 265,
5621 AT_SYMBOL = 266,
5622 AMPERSAND = 267,
5623 OPEN_BRACKET = 268,
5624 CLOSED_BRACKET = 269,
5625 NEWLINE = 270,
5626 INTEGER_LITERAL = 271,
5627 STRING_LITERAL = 272,
5628 CSTRING = 273,
5629 COMMA = 274,
5630 CARROT = 275
5631 };
5632 #endif
5633 /* Tokens. */
5634 #define OPEN_BRACE 258
5635 #define CLOSED_BRACE 259
5636 #define OPEN_PAREN 260
5637 #define CLOSED_PAREN 261
5638 #define ADD_OP 262
5639 #define MULT_OP 263
5640 #define EQUAL_SIGN 264
5641 #define TILDA 265
5642 #define AT_SYMBOL 266
5643 #define AMPERSAND 267
5644 #define OPEN_BRACKET 268
5645 #define CLOSED_BRACKET 269
5646 #define NEWLINE 270
5647 #define INTEGER_LITERAL 271
5648 #define STRING_LITERAL 272
5649 #define CSTRING 273
5650 #define COMMA 274
5651 #define CARROT 275
5652
5653 /* Value type. */
5654 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
5655
5656 union YYSTYPE
5657 {
5658
5659 struct gdbwire_mi_output *u_output;
5660 struct gdbwire_mi_oob_record *u_oob_record;
5661 struct gdbwire_mi_result_record *u_result_record;
5662 int u_result_class;
5663 int u_async_record_kind;
5664 struct gdbwire_mi_result_list *u_result_list;
5665 struct gdbwire_mi_result *u_result;
5666 char *u_token;
5667 struct gdbwire_mi_async_record *u_async_record;
5668 struct gdbwire_mi_stream_record *u_stream_record;
5669 int u_async_class;
5670 char *u_variable;
5671 char *u_cstring;
5672 struct gdbwire_mi_result *u_tuple;
5673 struct gdbwire_mi_result *u_list;
5674 int u_stream_record_kind;
5675
5676 };
5677
5678 typedef union YYSTYPE YYSTYPE;
5679 # define YYSTYPE_IS_TRIVIAL 1
5680 # define YYSTYPE_IS_DECLARED 1
5681 #endif
5682
5683
5684
5685 #ifndef YYPUSH_MORE_DEFINED
5686 # define YYPUSH_MORE_DEFINED
5687 enum { YYPUSH_MORE = 4 };
5688 #endif
5689
5690 typedef struct gdbwire_mi_pstate gdbwire_mi_pstate;
5691
5692 int gdbwire_mi_push_parse (gdbwire_mi_pstate *ps, int pushed_char, YYSTYPE const *pushed_val, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output);
5693
5694 gdbwire_mi_pstate * gdbwire_mi_pstate_new (void);
5695 void gdbwire_mi_pstate_delete (gdbwire_mi_pstate *ps);
5696
5697 #endif /* !YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED */
5698
5699 /* Copy the second part of user declarations. */
5700
5701
5702 #ifdef short
5703 # undef short
5704 #endif
5705
5706 #ifdef YYTYPE_UINT8
5707 typedef YYTYPE_UINT8 yytype_uint8;
5708 #else
5709 typedef unsigned char yytype_uint8;
5710 #endif
5711
5712 #ifdef YYTYPE_INT8
5713 typedef YYTYPE_INT8 yytype_int8;
5714 #else
5715 typedef signed char yytype_int8;
5716 #endif
5717
5718 #ifdef YYTYPE_UINT16
5719 typedef YYTYPE_UINT16 yytype_uint16;
5720 #else
5721 typedef unsigned short int yytype_uint16;
5722 #endif
5723
5724 #ifdef YYTYPE_INT16
5725 typedef YYTYPE_INT16 yytype_int16;
5726 #else
5727 typedef short int yytype_int16;
5728 #endif
5729
5730 #ifndef YYSIZE_T
5731 # ifdef __SIZE_TYPE__
5732 # define YYSIZE_T __SIZE_TYPE__
5733 # elif defined size_t
5734 # define YYSIZE_T size_t
5735 # elif ! defined YYSIZE_T
5736 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
5737 # define YYSIZE_T size_t
5738 # else
5739 # define YYSIZE_T unsigned int
5740 # endif
5741 #endif
5742
5743 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
5744
5745 #ifndef YY_
5746 # if defined YYENABLE_NLS && YYENABLE_NLS
5747 # if ENABLE_NLS
5748 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
5749 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
5750 # endif
5751 # endif
5752 # ifndef YY_
5753 # define YY_(Msgid) Msgid
5754 # endif
5755 #endif
5756
5757 #ifndef YY_ATTRIBUTE
5758 # if (defined __GNUC__ \
5759 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
5760 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
5761 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
5762 # else
5763 # define YY_ATTRIBUTE(Spec) /* empty */
5764 # endif
5765 #endif
5766
5767 #ifndef YY_ATTRIBUTE_PURE
5768 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
5769 #endif
5770
5771 #ifndef YY_ATTRIBUTE_UNUSED
5772 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
5773 #endif
5774
5775 #if !defined _Noreturn \
5776 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
5777 # if defined _MSC_VER && 1200 <= _MSC_VER
5778 # define _Noreturn __declspec (noreturn)
5779 # else
5780 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
5781 # endif
5782 #endif
5783
5784 /* Suppress unused-variable warnings by "using" E. */
5785 #if ! defined lint || defined __GNUC__
5786 # define YYUSE(E) ((void) (E))
5787 #else
5788 # define YYUSE(E) /* empty */
5789 #endif
5790
5791 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
5792 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
5793 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
5794 _Pragma ("GCC diagnostic push") \
5795 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
5796 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
5797 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
5798 _Pragma ("GCC diagnostic pop")
5799 #else
5800 # define YY_INITIAL_VALUE(Value) Value
5801 #endif
5802 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
5803 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
5804 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
5805 #endif
5806 #ifndef YY_INITIAL_VALUE
5807 # define YY_INITIAL_VALUE(Value) /* Nothing. */
5808 #endif
5809
5810
5811 #if ! defined yyoverflow || YYERROR_VERBOSE
5812
5813 /* The parser invokes alloca or malloc; define the necessary symbols. */
5814
5815 # ifdef YYSTACK_ALLOC
5816 /* Pacify GCC's 'empty if-body' warning. */
5817 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
5818 # ifndef YYSTACK_ALLOC_MAXIMUM
5819 /* The OS might guarantee only one guard page at the bottom of the stack,
5820 and a page size can be as small as 4096 bytes. So we cannot safely
5821 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
5822 to allow for a few compiler-allocated temporary stack slots. */
5823 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
5824 # endif
5825 # else
5826 # define YYSTACK_ALLOC YYMALLOC
5827 # define YYSTACK_FREE YYFREE
5828 # ifndef YYSTACK_ALLOC_MAXIMUM
5829 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
5830 # endif
5831 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
5832 && ! ((defined YYMALLOC || defined malloc) \
5833 && (defined YYFREE || defined free)))
5834 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
5835 # ifndef EXIT_SUCCESS
5836 # define EXIT_SUCCESS 0
5837 # endif
5838 # endif
5839 # ifndef YYMALLOC
5840 # define YYMALLOC malloc
5841 # if ! defined malloc && ! defined EXIT_SUCCESS
5842 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
5843 # endif
5844 # endif
5845 # ifndef YYFREE
5846 # define YYFREE free
5847 # if ! defined free && ! defined EXIT_SUCCESS
5848 void free (void *); /* INFRINGES ON USER NAME SPACE */
5849 # endif
5850 # endif
5851 # endif
5852 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
5853
5854
5855 #if (! defined yyoverflow \
5856 && (! defined __cplusplus \
5857 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
5858
5859 /* A type that is properly aligned for any stack member. */
5860 union yyalloc
5861 {
5862 yytype_int16 yyss_alloc;
5863 YYSTYPE yyvs_alloc;
5864 };
5865
5866 /* The size of the maximum gap between one aligned stack and the next. */
5867 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
5868
5869 /* The size of an array large to enough to hold all stacks, each with
5870 N elements. */
5871 # define YYSTACK_BYTES(N) \
5872 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
5873 + YYSTACK_GAP_MAXIMUM)
5874
5875 # define YYCOPY_NEEDED 1
5876
5877 /* Relocate STACK from its old location to the new one. The
5878 local variables YYSIZE and YYSTACKSIZE give the old and new number of
5879 elements in the stack, and YYPTR gives the new location of the
5880 stack. Advance YYPTR to a properly aligned location for the next
5881 stack. */
5882 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
5883 do \
5884 { \
5885 YYSIZE_T yynewbytes; \
5886 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
5887 Stack = &yyptr->Stack_alloc; \
5888 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
5889 yyptr += yynewbytes / sizeof (*yyptr); \
5890 } \
5891 while (0)
5892
5893 #endif
5894
5895 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
5896 /* Copy COUNT objects from SRC to DST. The source and destination do
5897 not overlap. */
5898 # ifndef YYCOPY
5899 # if defined __GNUC__ && 1 < __GNUC__
5900 # define YYCOPY(Dst, Src, Count) \
5901 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
5902 # else
5903 # define YYCOPY(Dst, Src, Count) \
5904 do \
5905 { \
5906 YYSIZE_T yyi; \
5907 for (yyi = 0; yyi < (Count); yyi++) \
5908 (Dst)[yyi] = (Src)[yyi]; \
5909 } \
5910 while (0)
5911 # endif
5912 # endif
5913 #endif /* !YYCOPY_NEEDED */
5914
5915 /* YYFINAL -- State number of the termination state. */
5916 #define YYFINAL 2
5917 /* YYLAST -- Last index in YYTABLE. */
5918 #define YYLAST 42
5919
5920 /* YYNTOKENS -- Number of terminals. */
5921 #define YYNTOKENS 21
5922 /* YYNNTS -- Number of nonterminals. */
5923 #define YYNNTS 22
5924 /* YYNRULES -- Number of rules. */
5925 #define YYNRULES 40
5926 /* YYNSTATES -- Number of states. */
5927 #define YYNSTATES 56
5928
5929 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
5930 by yylex, with out-of-bounds checking. */
5931 #define YYUNDEFTOK 2
5932 #define YYMAXUTOK 275
5933
5934 #define YYTRANSLATE(YYX) \
5935 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
5936
5937 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
5938 as returned by yylex, without out-of-bounds checking. */
5939 static const yytype_uint8 yytranslate[] =
5940 {
5941 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5942 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5943 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5944 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5945 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5946 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5947 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5948 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5949 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5950 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5951 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5952 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5953 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5954 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5955 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5956 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5957 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5958 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5959 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5960 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5961 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5962 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5963 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5964 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5965 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
5966 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5967 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
5968 15, 16, 17, 18, 19, 20
5969 };
5970
5971 #if YYDEBUG
5972 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
5973 static const yytype_uint16 yyrline[] =
5974 {
5975 0, 248, 248, 251, 254, 258, 262, 268, 274, 274,
5976 286, 293, 301, 307, 313, 321, 330, 334, 338, 342,
5977 359, 412, 416, 420, 425, 430, 437, 444, 451, 456,
5978 461, 465, 470, 474, 479, 485, 489, 493, 497, 501,
5979 505
5980 };
5981 #endif
5982
5983 #if YYDEBUG || YYERROR_VERBOSE || 0
5984 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
5985 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
5986 static const char *const yytname[] =
5987 {
5988 "$end", "error", "$undefined", "OPEN_BRACE", "CLOSED_BRACE",
5989 "OPEN_PAREN", "CLOSED_PAREN", "ADD_OP", "MULT_OP", "EQUAL_SIGN", "TILDA",
5990 "AT_SYMBOL", "AMPERSAND", "OPEN_BRACKET", "CLOSED_BRACKET", "NEWLINE",
5991 "INTEGER_LITERAL", "STRING_LITERAL", "CSTRING", "COMMA", "CARROT",
5992 "$accept", "output_list", "output", "output_variant", "$@1",
5993 "result_record", "oob_record", "async_record", "async_record_class",
5994 "result_class", "async_class", "opt_variable", "result_list", "result",
5995 "variable", "cstring", "tuple", "list", "stream_record",
5996 "stream_record_class", "opt_token", "token", YY_NULLPTR
5997 };
5998 #endif
5999
6000 # ifdef YYPRINT
6001 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
6002 (internal) symbol number NUM (which must be that of a token). */
6003 static const yytype_uint16 yytoknum[] =
6004 {
6005 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
6006 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
6007 275
6008 };
6009 # endif
6010
6011 #define YYPACT_NINF -19
6012
6013 #define yypact_value_is_default(Yystate) \
6014 (!!((Yystate) == (-19)))
6015
6016 #define YYTABLE_NINF -39
6017
6018 #define yytable_value_is_error(Yytable_value) \
6019 0
6020
6021 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
6022 STATE-NUM. */
6023 static const yytype_int8 yypact[] =
6024 {
6025 -19, 0, -19, 15, 11, -19, -19, -19, -19, -19,
6026 16, -19, -19, -19, -19, -3, 14, -19, -19, -19,
6027 -19, -19, -19, -19, -19, -19, -19, 12, 18, 27,
6028 -19, 17, -19, 19, -19, 11, 11, 1, 20, -19,
6029 28, 20, 9, -11, -19, -19, -19, 11, -19, -19,
6030 -2, -19, 13, -19, -19, -19
6031 };
6032
6033 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
6034 Performed when YYTABLE does not specify something else to do. Zero
6035 means the default is an error. */
6036 static const yytype_uint8 yydefact[] =
6037 {
6038 2, 0, 1, 0, 0, 35, 36, 37, 40, 3,
6039 0, 7, 6, 12, 13, 0, 0, 39, 5, 28,
6040 8, 4, 29, 34, 17, 16, 18, 0, 0, 0,
6041 19, 10, 20, 14, 9, 21, 21, 0, 11, 23,
6042 0, 15, 21, 21, 25, 26, 27, 21, 22, 30,
6043 0, 32, 0, 24, 31, 33
6044 };
6045
6046 /* YYPGOTO[NTERM-NUM]. */
6047 static const yytype_int8 yypgoto[] =
6048 {
6049 -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
6050 -19, -19, -18, -7, 37, 5, -19, -19, -19, -19,
6051 -19, -19
6052 };
6053
6054 /* YYDEFGOTO[NTERM-NUM]. */
6055 static const yytype_int8 yydefgoto[] =
6056 {
6057 -1, 1, 9, 10, 29, 11, 12, 13, 28, 31,
6058 33, 37, 38, 39, 40, 23, 45, 46, 14, 15,
6059 16, 17
6060 };
6061
6062 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
6063 positive, shift that token. If negative, reduce the rule whose
6064 number is the opposite. If YYTABLE_NINF, syntax error. */
6065 static const yytype_int8 yytable[] =
6066 {
6067 2, 3, 54, 51, 42, 4, 19, -38, -38, -38,
6068 5, 6, 7, 49, 43, 22, 8, 47, 41, 22,
6069 -38, 24, 25, 26, 50, 52, 19, 55, 19, 30,
6070 18, 21, 47, 34, 27, 32, 35, 48, 36, 47,
6071 53, 20, 44
6072 };
6073
6074 static const yytype_uint8 yycheck[] =
6075 {
6076 0, 1, 4, 14, 3, 5, 17, 7, 8, 9,
6077 10, 11, 12, 4, 13, 18, 16, 19, 36, 18,
6078 20, 7, 8, 9, 42, 43, 17, 14, 17, 17,
6079 15, 15, 19, 6, 20, 17, 19, 9, 19, 19,
6080 47, 4, 37
6081 };
6082
6083 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
6084 symbol of state STATE-NUM. */
6085 static const yytype_uint8 yystos[] =
6086 {
6087 0, 22, 0, 1, 5, 10, 11, 12, 16, 23,
6088 24, 26, 27, 28, 39, 40, 41, 42, 15, 17,
6089 35, 15, 18, 36, 7, 8, 9, 20, 29, 25,
6090 17, 30, 17, 31, 6, 19, 19, 32, 33, 34,
6091 35, 33, 3, 13, 36, 37, 38, 19, 9, 4,
6092 33, 14, 33, 34, 4, 14
6093 };
6094
6095 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
6096 static const yytype_uint8 yyr1[] =
6097 {
6098 0, 21, 22, 22, 23, 23, 24, 24, 25, 24,
6099 26, 26, 27, 27, 28, 28, 29, 29, 29, 30,
6100 31, 32, 32, 33, 33, 34, 34, 34, 35, 36,
6101 37, 37, 38, 38, 39, 40, 40, 40, 41, 41,
6102 42
6103 };
6104
6105 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
6106 static const yytype_uint8 yyr2[] =
6107 {
6108 0, 2, 0, 2, 2, 2, 1, 1, 0, 4,
6109 3, 5, 1, 1, 3, 5, 1, 1, 1, 1,
6110 1, 0, 2, 1, 3, 2, 2, 2, 1, 1,
6111 2, 3, 2, 3, 2, 1, 1, 1, 0, 1,
6112 1
6113 };
6114
6115
6116 #define yyerrok (yyerrstatus = 0)
6117 #define yyclearin (yychar = YYEMPTY)
6118 #define YYEMPTY (-2)
6119 #define YYEOF 0
6120
6121 #define YYACCEPT goto yyacceptlab
6122 #define YYABORT goto yyabortlab
6123 #define YYERROR goto yyerrorlab
6124
6125
6126 #define YYRECOVERING() (!!yyerrstatus)
6127
6128 #define YYBACKUP(Token, Value) \
6129 do \
6130 if (yychar == YYEMPTY) \
6131 { \
6132 yychar = (Token); \
6133 yylval = (Value); \
6134 YYPOPSTACK (yylen); \
6135 yystate = *yyssp; \
6136 goto yybackup; \
6137 } \
6138 else \
6139 { \
6140 yyerror (yyscanner, gdbwire_mi_output, YY_("syntax error: cannot back up")); \
6141 YYERROR; \
6142 } \
6143 while (0)
6144
6145 /* Error token number */
6146 #define YYTERROR 1
6147 #define YYERRCODE 256
6148
6149
6150
6151 /* Enable debugging if requested. */
6152 #if YYDEBUG
6153
6154 # ifndef YYFPRINTF
6155 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
6156 # define YYFPRINTF fprintf
6157 # endif
6158
6159 # define YYDPRINTF(Args) \
6160 do { \
6161 if (yydebug) \
6162 YYFPRINTF Args; \
6163 } while (0)
6164
6165 /* This macro is provided for backward compatibility. */
6166 #ifndef YY_LOCATION_PRINT
6167 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
6168 #endif
6169
6170
6171 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
6172 do { \
6173 if (yydebug) \
6174 { \
6175 YYFPRINTF (stderr, "%s ", Title); \
6176 yy_symbol_print (stderr, \
6177 Type, Value, yyscanner, gdbwire_mi_output); \
6178 YYFPRINTF (stderr, "\n"); \
6179 } \
6180 } while (0)
6181
6182
6183 /*----------------------------------------.
6184 | Print this symbol's value on YYOUTPUT. |
6185 `----------------------------------------*/
6186
6187 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output)6188 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output)
6189 {
6190 FILE *yyo = yyoutput;
6191 YYUSE (yyo);
6192 YYUSE (yyscanner);
6193 YYUSE (gdbwire_mi_output);
6194 if (!yyvaluep)
6195 return;
6196 # ifdef YYPRINT
6197 if (yytype < YYNTOKENS)
6198 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
6199 # endif
6200 YYUSE (yytype);
6201 }
6202
6203
6204 /*--------------------------------.
6205 | Print this symbol on YYOUTPUT. |
6206 `--------------------------------*/
6207
6208 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep,yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output)6209 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output)
6210 {
6211 YYFPRINTF (yyoutput, "%s %s (",
6212 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
6213
6214 yy_symbol_value_print (yyoutput, yytype, yyvaluep, yyscanner, gdbwire_mi_output);
6215 YYFPRINTF (yyoutput, ")");
6216 }
6217
6218 /*------------------------------------------------------------------.
6219 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
6220 | TOP (included). |
6221 `------------------------------------------------------------------*/
6222
6223 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)6224 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
6225 {
6226 YYFPRINTF (stderr, "Stack now");
6227 for (; yybottom <= yytop; yybottom++)
6228 {
6229 int yybot = *yybottom;
6230 YYFPRINTF (stderr, " %d", yybot);
6231 }
6232 YYFPRINTF (stderr, "\n");
6233 }
6234
6235 # define YY_STACK_PRINT(Bottom, Top) \
6236 do { \
6237 if (yydebug) \
6238 yy_stack_print ((Bottom), (Top)); \
6239 } while (0)
6240
6241
6242 /*------------------------------------------------.
6243 | Report that the YYRULE is going to be reduced. |
6244 `------------------------------------------------*/
6245
6246 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule,yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output)6247 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output)
6248 {
6249 unsigned long int yylno = yyrline[yyrule];
6250 int yynrhs = yyr2[yyrule];
6251 int yyi;
6252 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
6253 yyrule - 1, yylno);
6254 /* The symbols being reduced. */
6255 for (yyi = 0; yyi < yynrhs; yyi++)
6256 {
6257 YYFPRINTF (stderr, " $%d = ", yyi + 1);
6258 yy_symbol_print (stderr,
6259 yystos[yyssp[yyi + 1 - yynrhs]],
6260 &(yyvsp[(yyi + 1) - (yynrhs)])
6261 , yyscanner, gdbwire_mi_output);
6262 YYFPRINTF (stderr, "\n");
6263 }
6264 }
6265
6266 # define YY_REDUCE_PRINT(Rule) \
6267 do { \
6268 if (yydebug) \
6269 yy_reduce_print (yyssp, yyvsp, Rule, yyscanner, gdbwire_mi_output); \
6270 } while (0)
6271
6272 /* Nonzero means print parse trace. It is left uninitialized so that
6273 multiple parsers can coexist. */
6274 int yydebug;
6275 #else /* !YYDEBUG */
6276 # define YYDPRINTF(Args)
6277 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
6278 # define YY_STACK_PRINT(Bottom, Top)
6279 # define YY_REDUCE_PRINT(Rule)
6280 #endif /* !YYDEBUG */
6281
6282
6283 /* YYINITDEPTH -- initial size of the parser's stacks. */
6284 #ifndef YYINITDEPTH
6285 # define YYINITDEPTH 200
6286 #endif
6287
6288 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
6289 if the built-in stack extension method is used).
6290
6291 Do not make this value too large; the results are undefined if
6292 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
6293 evaluated with infinite-precision integer arithmetic. */
6294
6295 #ifndef YYMAXDEPTH
6296 # define YYMAXDEPTH 10000
6297 #endif
6298
6299
6300 #if YYERROR_VERBOSE
6301
6302 # ifndef yystrlen
6303 # if defined __GLIBC__ && defined _STRING_H
6304 # define yystrlen strlen
6305 # else
6306 /* Return the length of YYSTR. */
6307 static YYSIZE_T
yystrlen(const char * yystr)6308 yystrlen (const char *yystr)
6309 {
6310 YYSIZE_T yylen;
6311 for (yylen = 0; yystr[yylen]; yylen++)
6312 continue;
6313 return yylen;
6314 }
6315 # endif
6316 # endif
6317
6318 # ifndef yystpcpy
6319 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
6320 # define yystpcpy stpcpy
6321 # else
6322 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
6323 YYDEST. */
6324 static char *
yystpcpy(char * yydest,const char * yysrc)6325 yystpcpy (char *yydest, const char *yysrc)
6326 {
6327 char *yyd = yydest;
6328 const char *yys = yysrc;
6329
6330 while ((*yyd++ = *yys++) != '\0')
6331 continue;
6332
6333 return yyd - 1;
6334 }
6335 # endif
6336 # endif
6337
6338 # ifndef yytnamerr
6339 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
6340 quotes and backslashes, so that it's suitable for yyerror. The
6341 heuristic is that double-quoting is unnecessary unless the string
6342 contains an apostrophe, a comma, or backslash (other than
6343 backslash-backslash). YYSTR is taken from yytname. If YYRES is
6344 null, do not copy; instead, return the length of what the result
6345 would have been. */
6346 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)6347 yytnamerr (char *yyres, const char *yystr)
6348 {
6349 if (*yystr == '"')
6350 {
6351 YYSIZE_T yyn = 0;
6352 char const *yyp = yystr;
6353
6354 for (;;)
6355 switch (*++yyp)
6356 {
6357 case '\'':
6358 case ',':
6359 goto do_not_strip_quotes;
6360
6361 case '\\':
6362 if (*++yyp != '\\')
6363 goto do_not_strip_quotes;
6364 /* Fall through. */
6365 default:
6366 if (yyres)
6367 yyres[yyn] = *yyp;
6368 yyn++;
6369 break;
6370
6371 case '"':
6372 if (yyres)
6373 yyres[yyn] = '\0';
6374 return yyn;
6375 }
6376 do_not_strip_quotes: ;
6377 }
6378
6379 if (! yyres)
6380 return yystrlen (yystr);
6381
6382 return yystpcpy (yyres, yystr) - yyres;
6383 }
6384 # endif
6385
6386 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
6387 about the unexpected token YYTOKEN for the state stack whose top is
6388 YYSSP.
6389
6390 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
6391 not large enough to hold the message. In that case, also set
6392 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
6393 required number of bytes is too large to store. */
6394 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)6395 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
6396 yytype_int16 *yyssp, int yytoken)
6397 {
6398 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
6399 YYSIZE_T yysize = yysize0;
6400 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
6401 /* Internationalized format string. */
6402 const char *yyformat = YY_NULLPTR;
6403 /* Arguments of yyformat. */
6404 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
6405 /* Number of reported tokens (one for the "unexpected", one per
6406 "expected"). */
6407 int yycount = 0;
6408
6409 /* There are many possibilities here to consider:
6410 - If this state is a consistent state with a default action, then
6411 the only way this function was invoked is if the default action
6412 is an error action. In that case, don't check for expected
6413 tokens because there are none.
6414 - The only way there can be no lookahead present (in yychar) is if
6415 this state is a consistent state with a default action. Thus,
6416 detecting the absence of a lookahead is sufficient to determine
6417 that there is no unexpected or expected token to report. In that
6418 case, just report a simple "syntax error".
6419 - Don't assume there isn't a lookahead just because this state is a
6420 consistent state with a default action. There might have been a
6421 previous inconsistent state, consistent state with a non-default
6422 action, or user semantic action that manipulated yychar.
6423 - Of course, the expected token list depends on states to have
6424 correct lookahead information, and it depends on the parser not
6425 to perform extra reductions after fetching a lookahead from the
6426 scanner and before detecting a syntax error. Thus, state merging
6427 (from LALR or IELR) and default reductions corrupt the expected
6428 token list. However, the list is correct for canonical LR with
6429 one exception: it will still contain any token that will not be
6430 accepted due to an error action in a later state.
6431 */
6432 if (yytoken != YYEMPTY)
6433 {
6434 int yyn = yypact[*yyssp];
6435 yyarg[yycount++] = yytname[yytoken];
6436 if (!yypact_value_is_default (yyn))
6437 {
6438 /* Start YYX at -YYN if negative to avoid negative indexes in
6439 YYCHECK. In other words, skip the first -YYN actions for
6440 this state because they are default actions. */
6441 int yyxbegin = yyn < 0 ? -yyn : 0;
6442 /* Stay within bounds of both yycheck and yytname. */
6443 int yychecklim = YYLAST - yyn + 1;
6444 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
6445 int yyx;
6446
6447 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6448 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
6449 && !yytable_value_is_error (yytable[yyx + yyn]))
6450 {
6451 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
6452 {
6453 yycount = 1;
6454 yysize = yysize0;
6455 break;
6456 }
6457 yyarg[yycount++] = yytname[yyx];
6458 {
6459 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
6460 if (! (yysize <= yysize1
6461 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
6462 return 2;
6463 yysize = yysize1;
6464 }
6465 }
6466 }
6467 }
6468
6469 switch (yycount)
6470 {
6471 # define YYCASE_(N, S) \
6472 case N: \
6473 yyformat = S; \
6474 break
6475 YYCASE_(0, YY_("syntax error"));
6476 YYCASE_(1, YY_("syntax error, unexpected %s"));
6477 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
6478 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
6479 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
6480 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
6481 # undef YYCASE_
6482 }
6483
6484 {
6485 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
6486 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
6487 return 2;
6488 yysize = yysize1;
6489 }
6490
6491 if (*yymsg_alloc < yysize)
6492 {
6493 *yymsg_alloc = 2 * yysize;
6494 if (! (yysize <= *yymsg_alloc
6495 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
6496 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
6497 return 1;
6498 }
6499
6500 /* Avoid sprintf, as that infringes on the user's name space.
6501 Don't have undefined behavior even if the translation
6502 produced a string with the wrong number of "%s"s. */
6503 {
6504 char *yyp = *yymsg;
6505 int yyi = 0;
6506 while ((*yyp = *yyformat) != '\0')
6507 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
6508 {
6509 yyp += yytnamerr (yyp, yyarg[yyi++]);
6510 yyformat += 2;
6511 }
6512 else
6513 {
6514 yyp++;
6515 yyformat++;
6516 }
6517 }
6518 return 0;
6519 }
6520 #endif /* YYERROR_VERBOSE */
6521
6522 /*-----------------------------------------------.
6523 | Release the memory associated to this symbol. |
6524 `-----------------------------------------------*/
6525
6526 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep,yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output)6527 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output)
6528 {
6529 YYUSE (yyvaluep);
6530 YYUSE (yyscanner);
6531 YYUSE (gdbwire_mi_output);
6532 if (!yymsg)
6533 yymsg = "Deleting";
6534 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
6535
6536 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
6537 switch (yytype)
6538 {
6539 case 24: /* output_variant */
6540 { gdbwire_mi_output_free(((*yyvaluep).u_output)); }
6541 break;
6542
6543 case 32: /* opt_variable */
6544 { free(((*yyvaluep).u_variable)); }
6545 break;
6546
6547 case 33: /* result_list */
6548 { gdbwire_mi_result_free(((*yyvaluep).u_result_list)->head); free(((*yyvaluep).u_result_list)); }
6549 break;
6550
6551 case 34: /* result */
6552 { gdbwire_mi_result_free(((*yyvaluep).u_result)); }
6553 break;
6554
6555 case 35: /* variable */
6556 { free(((*yyvaluep).u_variable)); }
6557 break;
6558
6559 case 41: /* opt_token */
6560 { free(((*yyvaluep).u_token)); }
6561 break;
6562
6563
6564 default:
6565 break;
6566 }
6567 YY_IGNORE_MAYBE_UNINITIALIZED_END
6568 }
6569
6570
6571
6572 struct yypstate
6573 {
6574 /* Number of syntax errors so far. */
6575 int yynerrs;
6576
6577 int yystate;
6578 /* Number of tokens to shift before error messages enabled. */
6579 int yyerrstatus;
6580
6581 /* The stacks and their tools:
6582 'yyss': related to states.
6583 'yyvs': related to semantic values.
6584
6585 Refer to the stacks through separate pointers, to allow yyoverflow
6586 to reallocate them elsewhere. */
6587
6588 /* The state stack. */
6589 yytype_int16 yyssa[YYINITDEPTH];
6590 yytype_int16 *yyss;
6591 yytype_int16 *yyssp;
6592
6593 /* The semantic value stack. */
6594 YYSTYPE yyvsa[YYINITDEPTH];
6595 YYSTYPE *yyvs;
6596 YYSTYPE *yyvsp;
6597
6598 YYSIZE_T yystacksize;
6599 /* Used to determine if this is the first time this instance has
6600 been used. */
6601 int yynew;
6602 };
6603
6604 /* Initialize the parser data structure. */
6605 yypstate *
yypstate_new(void)6606 yypstate_new (void)
6607 {
6608 yypstate *yyps;
6609 yyps = (yypstate *) malloc (sizeof *yyps);
6610 if (!yyps)
6611 return YY_NULLPTR;
6612 yyps->yynew = 1;
6613 return yyps;
6614 }
6615
6616 void
yypstate_delete(yypstate * yyps)6617 yypstate_delete (yypstate *yyps)
6618 {
6619 #ifndef yyoverflow
6620 /* If the stack was reallocated but the parse did not complete, then the
6621 stack still needs to be freed. */
6622 if (!yyps->yynew && yyps->yyss != yyps->yyssa)
6623 YYSTACK_FREE (yyps->yyss);
6624 #endif
6625 free (yyps);
6626 }
6627
6628 #define gdbwire_mi_nerrs yyps->gdbwire_mi_nerrs
6629 #define yystate yyps->yystate
6630 #define yyerrstatus yyps->yyerrstatus
6631 #define yyssa yyps->yyssa
6632 #define yyss yyps->yyss
6633 #define yyssp yyps->yyssp
6634 #define yyvsa yyps->yyvsa
6635 #define yyvs yyps->yyvs
6636 #define yyvsp yyps->yyvsp
6637 #define yystacksize yyps->yystacksize
6638
6639
6640 /*---------------.
6641 | yypush_parse. |
6642 `---------------*/
6643
6644 int
yypush_parse(yypstate * yyps,int yypushed_char,YYSTYPE const * yypushed_val,yyscan_t yyscanner,struct gdbwire_mi_output ** gdbwire_mi_output)6645 yypush_parse (yypstate *yyps, int yypushed_char, YYSTYPE const *yypushed_val, yyscan_t yyscanner, struct gdbwire_mi_output **gdbwire_mi_output)
6646 {
6647 /* The lookahead symbol. */
6648 int yychar;
6649
6650
6651 /* The semantic value of the lookahead symbol. */
6652 /* Default value used for initialization, for pacifying older GCCs
6653 or non-GCC compilers. */
6654 YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
6655 YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
6656
6657 int yyn;
6658 int yyresult;
6659 /* Lookahead token as an internal (translated) token number. */
6660 int yytoken = 0;
6661 /* The variables used to return semantic value and location from the
6662 action routines. */
6663 YYSTYPE yyval;
6664
6665 #if YYERROR_VERBOSE
6666 /* Buffer for error messages, and its allocated size. */
6667 char yymsgbuf[128];
6668 char *yymsg = yymsgbuf;
6669 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
6670 #endif
6671
6672 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
6673
6674 /* The number of symbols on the RHS of the reduced rule.
6675 Keep to zero when no symbol should be popped. */
6676 int yylen = 0;
6677
6678 if (!yyps->yynew)
6679 {
6680 yyn = yypact[yystate];
6681 goto yyread_pushed_token;
6682 }
6683
6684 yyssp = yyss = yyssa;
6685 yyvsp = yyvs = yyvsa;
6686 yystacksize = YYINITDEPTH;
6687
6688 YYDPRINTF ((stderr, "Starting parse\n"));
6689
6690 yystate = 0;
6691 yyerrstatus = 0;
6692 yynerrs = 0;
6693 yychar = YYEMPTY; /* Cause a token to be read. */
6694 goto yysetstate;
6695
6696 /*------------------------------------------------------------.
6697 | yynewstate -- Push a new state, which is found in yystate. |
6698 `------------------------------------------------------------*/
6699 yynewstate:
6700 /* In all cases, when you get here, the value and location stacks
6701 have just been pushed. So pushing a state here evens the stacks. */
6702 yyssp++;
6703
6704 yysetstate:
6705 *yyssp = yystate;
6706
6707 if (yyss + yystacksize - 1 <= yyssp)
6708 {
6709 /* Get the current used size of the three stacks, in elements. */
6710 YYSIZE_T yysize = yyssp - yyss + 1;
6711
6712 #ifdef yyoverflow
6713 {
6714 /* Give user a chance to reallocate the stack. Use copies of
6715 these so that the &'s don't force the real ones into
6716 memory. */
6717 YYSTYPE *yyvs1 = yyvs;
6718 yytype_int16 *yyss1 = yyss;
6719
6720 /* Each stack pointer address is followed by the size of the
6721 data in use in that stack, in bytes. This used to be a
6722 conditional around just the two extra args, but that might
6723 be undefined if yyoverflow is a macro. */
6724 yyoverflow (YY_("memory exhausted"),
6725 &yyss1, yysize * sizeof (*yyssp),
6726 &yyvs1, yysize * sizeof (*yyvsp),
6727 &yystacksize);
6728
6729 yyss = yyss1;
6730 yyvs = yyvs1;
6731 }
6732 #else /* no yyoverflow */
6733 # ifndef YYSTACK_RELOCATE
6734 goto yyexhaustedlab;
6735 # else
6736 /* Extend the stack our own way. */
6737 if (YYMAXDEPTH <= yystacksize)
6738 goto yyexhaustedlab;
6739 yystacksize *= 2;
6740 if (YYMAXDEPTH < yystacksize)
6741 yystacksize = YYMAXDEPTH;
6742
6743 {
6744 yytype_int16 *yyss1 = yyss;
6745 union yyalloc *yyptr =
6746 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
6747 if (! yyptr)
6748 goto yyexhaustedlab;
6749 YYSTACK_RELOCATE (yyss_alloc, yyss);
6750 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
6751 # undef YYSTACK_RELOCATE
6752 if (yyss1 != yyssa)
6753 YYSTACK_FREE (yyss1);
6754 }
6755 # endif
6756 #endif /* no yyoverflow */
6757
6758 yyssp = yyss + yysize - 1;
6759 yyvsp = yyvs + yysize - 1;
6760
6761 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
6762 (unsigned long int) yystacksize));
6763
6764 if (yyss + yystacksize - 1 <= yyssp)
6765 YYABORT;
6766 }
6767
6768 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
6769
6770 if (yystate == YYFINAL)
6771 YYACCEPT;
6772
6773 goto yybackup;
6774
6775 /*-----------.
6776 | yybackup. |
6777 `-----------*/
6778 yybackup:
6779
6780 /* Do appropriate processing given the current state. Read a
6781 lookahead token if we need one and don't already have one. */
6782
6783 /* First try to decide what to do without reference to lookahead token. */
6784 yyn = yypact[yystate];
6785 if (yypact_value_is_default (yyn))
6786 goto yydefault;
6787
6788 /* Not known => get a lookahead token if don't already have one. */
6789
6790 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
6791 if (yychar == YYEMPTY)
6792 {
6793 if (!yyps->yynew)
6794 {
6795 YYDPRINTF ((stderr, "Return for a new token:\n"));
6796 yyresult = YYPUSH_MORE;
6797 goto yypushreturn;
6798 }
6799 yyps->yynew = 0;
6800 yyread_pushed_token:
6801 YYDPRINTF ((stderr, "Reading a token: "));
6802 yychar = yypushed_char;
6803 if (yypushed_val)
6804 yylval = *yypushed_val;
6805 }
6806
6807 if (yychar <= YYEOF)
6808 {
6809 yychar = yytoken = YYEOF;
6810 YYDPRINTF ((stderr, "Now at end of input.\n"));
6811 }
6812 else
6813 {
6814 yytoken = YYTRANSLATE (yychar);
6815 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
6816 }
6817
6818 /* If the proper action on seeing token YYTOKEN is to reduce or to
6819 detect an error, take that action. */
6820 yyn += yytoken;
6821 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
6822 goto yydefault;
6823 yyn = yytable[yyn];
6824 if (yyn <= 0)
6825 {
6826 if (yytable_value_is_error (yyn))
6827 goto yyerrlab;
6828 yyn = -yyn;
6829 goto yyreduce;
6830 }
6831
6832 /* Count tokens shifted since error; after three, turn off error
6833 status. */
6834 if (yyerrstatus)
6835 yyerrstatus--;
6836
6837 /* Shift the lookahead token. */
6838 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
6839
6840 /* Discard the shifted token. */
6841 yychar = YYEMPTY;
6842
6843 yystate = yyn;
6844 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
6845 *++yyvsp = yylval;
6846 YY_IGNORE_MAYBE_UNINITIALIZED_END
6847
6848 goto yynewstate;
6849
6850
6851 /*-----------------------------------------------------------.
6852 | yydefault -- do the default action for the current state. |
6853 `-----------------------------------------------------------*/
6854 yydefault:
6855 yyn = yydefact[yystate];
6856 if (yyn == 0)
6857 goto yyerrlab;
6858 goto yyreduce;
6859
6860
6861 /*-----------------------------.
6862 | yyreduce -- Do a reduction. |
6863 `-----------------------------*/
6864 yyreduce:
6865 /* yyn is the number of a rule to reduce with. */
6866 yylen = yyr2[yyn];
6867
6868 /* If YYLEN is nonzero, implement the default value of the action:
6869 '$$ = $1'.
6870
6871 Otherwise, the following line sets YYVAL to garbage.
6872 This behavior is undocumented and Bison
6873 users should not rely upon it. Assigning to YYVAL
6874 unconditionally makes the parser a bit smaller, and it avoids a
6875 GCC warning that YYVAL may be used uninitialized. */
6876 yyval = yyvsp[1-yylen];
6877
6878
6879 YY_REDUCE_PRINT (yyn);
6880 switch (yyn)
6881 {
6882 case 2:
6883 {
6884 }
6885 break;
6886
6887 case 3:
6888 {
6889 }
6890 break;
6891
6892 case 4:
6893 {
6894 *gdbwire_mi_output = (yyvsp[-1].u_output);
6895 }
6896 break;
6897
6898 case 5:
6899 {
6900 yyerrok;
6901 }
6902 break;
6903
6904 case 6:
6905 {
6906 (yyval.u_output) = gdbwire_mi_output_alloc();
6907 (yyval.u_output)->kind = GDBWIRE_MI_OUTPUT_OOB;
6908 (yyval.u_output)->variant.oob_record = (yyvsp[0].u_oob_record);
6909 }
6910 break;
6911
6912 case 7:
6913 {
6914 (yyval.u_output) = gdbwire_mi_output_alloc();
6915 (yyval.u_output)->kind = GDBWIRE_MI_OUTPUT_RESULT;
6916 (yyval.u_output)->variant.result_record = (yyvsp[0].u_result_record);
6917 }
6918 break;
6919
6920 case 8:
6921 {
6922 if (strcmp("gdb", (yyvsp[0].u_variable)) != 0) {
6923 /* Destructor will be called to free $2 on error */
6924 yyerror(yyscanner, gdbwire_mi_output, "");
6925 YYERROR;
6926 }
6927 }
6928 break;
6929
6930 case 9:
6931 {
6932 (yyval.u_output) = gdbwire_mi_output_alloc();
6933 (yyval.u_output)->kind = GDBWIRE_MI_OUTPUT_PROMPT;
6934 free((yyvsp[-2].u_variable));
6935 }
6936 break;
6937
6938 case 10:
6939 {
6940 (yyval.u_result_record) = gdbwire_mi_result_record_alloc();
6941 (yyval.u_result_record)->token = (yyvsp[-2].u_token);
6942 (yyval.u_result_record)->result_class = (yyvsp[0].u_result_class);
6943 (yyval.u_result_record)->result = NULL;
6944 }
6945 break;
6946
6947 case 11:
6948 {
6949 (yyval.u_result_record) = gdbwire_mi_result_record_alloc();
6950 (yyval.u_result_record)->token = (yyvsp[-4].u_token);
6951 (yyval.u_result_record)->result_class = (yyvsp[-2].u_result_class);
6952 (yyval.u_result_record)->result = (yyvsp[0].u_result_list)->head;
6953 free((yyvsp[0].u_result_list));
6954 }
6955 break;
6956
6957 case 12:
6958 {
6959 (yyval.u_oob_record) = gdbwire_mi_oob_record_alloc();
6960 (yyval.u_oob_record)->kind = GDBWIRE_MI_ASYNC;
6961 (yyval.u_oob_record)->variant.async_record = (yyvsp[0].u_async_record);
6962 }
6963 break;
6964
6965 case 13:
6966 {
6967 (yyval.u_oob_record) = gdbwire_mi_oob_record_alloc();
6968 (yyval.u_oob_record)->kind = GDBWIRE_MI_STREAM;
6969 (yyval.u_oob_record)->variant.stream_record = (yyvsp[0].u_stream_record);
6970 }
6971 break;
6972
6973 case 14:
6974 {
6975 (yyval.u_async_record) = gdbwire_mi_async_record_alloc();
6976 (yyval.u_async_record)->token = (yyvsp[-2].u_token);
6977 (yyval.u_async_record)->kind = (yyvsp[-1].u_async_record_kind);
6978 (yyval.u_async_record)->async_class = (yyvsp[0].u_async_class);
6979 (yyval.u_async_record)->result = NULL;
6980 }
6981 break;
6982
6983 case 15:
6984 {
6985 (yyval.u_async_record) = gdbwire_mi_async_record_alloc();
6986 (yyval.u_async_record)->token = (yyvsp[-4].u_token);
6987 (yyval.u_async_record)->kind = (yyvsp[-3].u_async_record_kind);
6988 (yyval.u_async_record)->async_class = (yyvsp[-2].u_async_class);
6989 (yyval.u_async_record)->result = (yyvsp[0].u_result_list)->head;
6990 free((yyvsp[0].u_result_list));
6991 }
6992 break;
6993
6994 case 16:
6995 {
6996 (yyval.u_async_record_kind) = GDBWIRE_MI_EXEC;
6997 }
6998 break;
6999
7000 case 17:
7001 {
7002 (yyval.u_async_record_kind) = GDBWIRE_MI_STATUS;
7003 }
7004 break;
7005
7006 case 18:
7007 {
7008 (yyval.u_async_record_kind) = GDBWIRE_MI_NOTIFY;
7009 }
7010 break;
7011
7012 case 19:
7013 {
7014 char *text = gdbwire_mi_get_text(yyscanner);
7015 if (strcmp("done", text) == 0) {
7016 (yyval.u_result_class) = GDBWIRE_MI_DONE;
7017 } else if (strcmp("running", text) == 0) {
7018 (yyval.u_result_class) = GDBWIRE_MI_RUNNING;
7019 } else if (strcmp("connected", text) == 0) {
7020 (yyval.u_result_class) = GDBWIRE_MI_CONNECTED;
7021 } else if (strcmp("error", text) == 0) {
7022 (yyval.u_result_class) = GDBWIRE_MI_ERROR;
7023 } else if (strcmp("exit", text) == 0) {
7024 (yyval.u_result_class) = GDBWIRE_MI_EXIT;
7025 } else {
7026 (yyval.u_result_class) = GDBWIRE_MI_UNSUPPORTED;
7027 }
7028 }
7029 break;
7030
7031 case 20:
7032 {
7033 char *text = gdbwire_mi_get_text(yyscanner);
7034 if (strcmp("download", text) == 0) {
7035 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_DOWNLOAD;
7036 } else if (strcmp("stopped", text) == 0) {
7037 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_STOPPED;
7038 } else if (strcmp("running", text) == 0) {
7039 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_RUNNING;
7040 } else if (strcmp("thread-group-added", text) == 0) {
7041 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_GROUP_ADDED;
7042 } else if (strcmp("thread-group-removed", text) == 0) {
7043 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_GROUP_REMOVED;
7044 } else if (strcmp("thread-group-started", text) == 0) {
7045 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_GROUP_STARTED;
7046 } else if (strcmp("thread-group-exited", text) == 0) {
7047 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_GROUP_EXITED;
7048 } else if (strcmp("thread-created", text) == 0) {
7049 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_CREATED;
7050 } else if (strcmp("thread-exited", text) == 0) {
7051 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_EXITED;
7052 } else if (strcmp("thread-selected", text) == 0) {
7053 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_THREAD_SELECTED;
7054 } else if (strcmp("library-loaded", text) == 0) {
7055 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_LIBRARY_LOADED;
7056 } else if (strcmp("library-unloaded", text) == 0) {
7057 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_LIBRARY_UNLOADED;
7058 } else if (strcmp("traceframe-changed", text) == 0) {
7059 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_TRACEFRAME_CHANGED;
7060 } else if (strcmp("tsv-created", text) == 0) {
7061 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_TSV_CREATED;
7062 } else if (strcmp("tsv-modified", text) == 0) {
7063 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_TSV_MODIFIED;
7064 } else if (strcmp("tsv-deleted", text) == 0) {
7065 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_TSV_DELETED;
7066 } else if (strcmp("breakpoint-created", text) == 0) {
7067 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_BREAKPOINT_CREATED;
7068 } else if (strcmp("breakpoint-modified", text) == 0) {
7069 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_BREAKPOINT_MODIFIED;
7070 } else if (strcmp("breakpoint-deleted", text) == 0) {
7071 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_BREAKPOINT_DELETED;
7072 } else if (strcmp("record-started", text) == 0) {
7073 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_RECORD_STARTED;
7074 } else if (strcmp("record-stopped", text) == 0) {
7075 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_RECORD_STOPPED;
7076 } else if (strcmp("cmd-param-changed", text) == 0) {
7077 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_CMD_PARAM_CHANGED;
7078 } else if (strcmp("memory-changed", text) == 0) {
7079 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_MEMORY_CHANGED;
7080 } else {
7081 (yyval.u_async_class) = GDBWIRE_MI_ASYNC_UNSUPPORTED;
7082 }
7083 }
7084 break;
7085
7086 case 21:
7087 {
7088 (yyval.u_variable) = 0;
7089 }
7090 break;
7091
7092 case 22:
7093 {
7094 (yyval.u_variable) = (yyvsp[-1].u_variable);
7095 }
7096 break;
7097
7098 case 23:
7099 {
7100 (yyval.u_result_list) = gdbwire_mi_result_list_alloc();
7101 gdbwire_mi_result_list_push_back((yyval.u_result_list), (yyvsp[0].u_result));
7102 }
7103 break;
7104
7105 case 24:
7106 {
7107 gdbwire_mi_result_list_push_back((yyvsp[-2].u_result_list), (yyvsp[0].u_result));
7108 (yyval.u_result_list) = (yyvsp[-2].u_result_list);
7109 }
7110 break;
7111
7112 case 25:
7113 {
7114 (yyval.u_result) = gdbwire_mi_result_alloc();
7115 (yyval.u_result)->variable = (yyvsp[-1].u_variable);
7116 (yyval.u_result)->kind = GDBWIRE_MI_CSTRING;
7117 (yyval.u_result)->variant.cstring = (yyvsp[0].u_cstring);
7118 }
7119 break;
7120
7121 case 26:
7122 {
7123 (yyval.u_result) = gdbwire_mi_result_alloc();
7124 (yyval.u_result)->variable = (yyvsp[-1].u_variable);
7125 (yyval.u_result)->kind = GDBWIRE_MI_TUPLE;
7126 (yyval.u_result)->variant.result = (yyvsp[0].u_tuple);
7127 }
7128 break;
7129
7130 case 27:
7131 {
7132 (yyval.u_result) = gdbwire_mi_result_alloc();
7133 (yyval.u_result)->variable = (yyvsp[-1].u_variable);
7134 (yyval.u_result)->kind = GDBWIRE_MI_LIST;
7135 (yyval.u_result)->variant.result = (yyvsp[0].u_list);
7136 }
7137 break;
7138
7139 case 28:
7140 {
7141 char *text = gdbwire_mi_get_text(yyscanner);
7142 (yyval.u_variable) = gdbwire_strdup(text);
7143 }
7144 break;
7145
7146 case 29:
7147 {
7148 char *text = gdbwire_mi_get_text(yyscanner);
7149 (yyval.u_cstring) = gdbwire_mi_unescape_cstring(text);
7150 }
7151 break;
7152
7153 case 30:
7154 {
7155 (yyval.u_tuple) = NULL;
7156 }
7157 break;
7158
7159 case 31:
7160 {
7161 (yyval.u_tuple) = (yyvsp[-1].u_result_list)->head;
7162 free((yyvsp[-1].u_result_list));
7163 }
7164 break;
7165
7166 case 32:
7167 {
7168 (yyval.u_list) = NULL;
7169 }
7170 break;
7171
7172 case 33:
7173 {
7174 (yyval.u_list) = (yyvsp[-1].u_result_list)->head;
7175 free((yyvsp[-1].u_result_list));
7176 }
7177 break;
7178
7179 case 34:
7180 {
7181 (yyval.u_stream_record) = gdbwire_mi_stream_record_alloc();
7182 (yyval.u_stream_record)->kind = (yyvsp[-1].u_stream_record_kind);
7183 (yyval.u_stream_record)->cstring = (yyvsp[0].u_cstring);
7184 }
7185 break;
7186
7187 case 35:
7188 {
7189 (yyval.u_stream_record_kind) = GDBWIRE_MI_CONSOLE;
7190 }
7191 break;
7192
7193 case 36:
7194 {
7195 (yyval.u_stream_record_kind) = GDBWIRE_MI_TARGET;
7196 }
7197 break;
7198
7199 case 37:
7200 {
7201 (yyval.u_stream_record_kind) = GDBWIRE_MI_LOG;
7202 }
7203 break;
7204
7205 case 38:
7206 {
7207 (yyval.u_token) = NULL;
7208 }
7209 break;
7210
7211 case 39:
7212 {
7213 (yyval.u_token) = (yyvsp[0].u_token);
7214 }
7215 break;
7216
7217 case 40:
7218 {
7219 char *text = gdbwire_mi_get_text(yyscanner);
7220 (yyval.u_token) = gdbwire_strdup(text);
7221 }
7222 break;
7223
7224
7225 default: break;
7226 }
7227 /* User semantic actions sometimes alter yychar, and that requires
7228 that yytoken be updated with the new translation. We take the
7229 approach of translating immediately before every use of yytoken.
7230 One alternative is translating here after every semantic action,
7231 but that translation would be missed if the semantic action invokes
7232 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
7233 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
7234 incorrect destructor might then be invoked immediately. In the
7235 case of YYERROR or YYBACKUP, subsequent parser actions might lead
7236 to an incorrect destructor call or verbose syntax error message
7237 before the lookahead is translated. */
7238 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
7239
7240 YYPOPSTACK (yylen);
7241 yylen = 0;
7242 YY_STACK_PRINT (yyss, yyssp);
7243
7244 *++yyvsp = yyval;
7245
7246 /* Now 'shift' the result of the reduction. Determine what state
7247 that goes to, based on the state we popped back to and the rule
7248 number reduced by. */
7249
7250 yyn = yyr1[yyn];
7251
7252 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
7253 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
7254 yystate = yytable[yystate];
7255 else
7256 yystate = yydefgoto[yyn - YYNTOKENS];
7257
7258 goto yynewstate;
7259
7260
7261 /*--------------------------------------.
7262 | yyerrlab -- here on detecting error. |
7263 `--------------------------------------*/
7264 yyerrlab:
7265 /* Make sure we have latest lookahead translation. See comments at
7266 user semantic actions for why this is necessary. */
7267 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
7268
7269 /* If not already recovering from an error, report this error. */
7270 if (!yyerrstatus)
7271 {
7272 ++yynerrs;
7273 #if ! YYERROR_VERBOSE
7274 yyerror (yyscanner, gdbwire_mi_output, YY_("syntax error"));
7275 #else
7276 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
7277 yyssp, yytoken)
7278 {
7279 char const *yymsgp = YY_("syntax error");
7280 int yysyntax_error_status;
7281 yysyntax_error_status = YYSYNTAX_ERROR;
7282 if (yysyntax_error_status == 0)
7283 yymsgp = yymsg;
7284 else if (yysyntax_error_status == 1)
7285 {
7286 if (yymsg != yymsgbuf)
7287 YYSTACK_FREE (yymsg);
7288 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
7289 if (!yymsg)
7290 {
7291 yymsg = yymsgbuf;
7292 yymsg_alloc = sizeof yymsgbuf;
7293 yysyntax_error_status = 2;
7294 }
7295 else
7296 {
7297 yysyntax_error_status = YYSYNTAX_ERROR;
7298 yymsgp = yymsg;
7299 }
7300 }
7301 yyerror (yyscanner, gdbwire_mi_output, yymsgp);
7302 if (yysyntax_error_status == 2)
7303 goto yyexhaustedlab;
7304 }
7305 # undef YYSYNTAX_ERROR
7306 #endif
7307 }
7308
7309
7310
7311 if (yyerrstatus == 3)
7312 {
7313 /* If just tried and failed to reuse lookahead token after an
7314 error, discard it. */
7315
7316 if (yychar <= YYEOF)
7317 {
7318 /* Return failure if at end of input. */
7319 if (yychar == YYEOF)
7320 YYABORT;
7321 }
7322 else
7323 {
7324 yydestruct ("Error: discarding",
7325 yytoken, &yylval, yyscanner, gdbwire_mi_output);
7326 yychar = YYEMPTY;
7327 }
7328 }
7329
7330 /* Else will try to reuse lookahead token after shifting the error
7331 token. */
7332 goto yyerrlab1;
7333
7334
7335 /*---------------------------------------------------.
7336 | yyerrorlab -- error raised explicitly by YYERROR. |
7337 `---------------------------------------------------*/
7338 yyerrorlab:
7339
7340 /* Pacify compilers like GCC when the user code never invokes
7341 YYERROR and the label yyerrorlab therefore never appears in user
7342 code. */
7343 if (/*CONSTCOND*/ 0)
7344 goto yyerrorlab;
7345
7346 /* Do not reclaim the symbols of the rule whose action triggered
7347 this YYERROR. */
7348 YYPOPSTACK (yylen);
7349 yylen = 0;
7350 YY_STACK_PRINT (yyss, yyssp);
7351 yystate = *yyssp;
7352 goto yyerrlab1;
7353
7354
7355 /*-------------------------------------------------------------.
7356 | yyerrlab1 -- common code for both syntax error and YYERROR. |
7357 `-------------------------------------------------------------*/
7358 yyerrlab1:
7359 yyerrstatus = 3; /* Each real token shifted decrements this. */
7360
7361 for (;;)
7362 {
7363 yyn = yypact[yystate];
7364 if (!yypact_value_is_default (yyn))
7365 {
7366 yyn += YYTERROR;
7367 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
7368 {
7369 yyn = yytable[yyn];
7370 if (0 < yyn)
7371 break;
7372 }
7373 }
7374
7375 /* Pop the current state because it cannot handle the error token. */
7376 if (yyssp == yyss)
7377 YYABORT;
7378
7379
7380 yydestruct ("Error: popping",
7381 yystos[yystate], yyvsp, yyscanner, gdbwire_mi_output);
7382 YYPOPSTACK (1);
7383 yystate = *yyssp;
7384 YY_STACK_PRINT (yyss, yyssp);
7385 }
7386
7387 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
7388 *++yyvsp = yylval;
7389 YY_IGNORE_MAYBE_UNINITIALIZED_END
7390
7391
7392 /* Shift the error token. */
7393 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
7394
7395 yystate = yyn;
7396 goto yynewstate;
7397
7398
7399 /*-------------------------------------.
7400 | yyacceptlab -- YYACCEPT comes here. |
7401 `-------------------------------------*/
7402 yyacceptlab:
7403 yyresult = 0;
7404 goto yyreturn;
7405
7406 /*-----------------------------------.
7407 | yyabortlab -- YYABORT comes here. |
7408 `-----------------------------------*/
7409 yyabortlab:
7410 yyresult = 1;
7411 goto yyreturn;
7412
7413 #if !defined yyoverflow || YYERROR_VERBOSE
7414 /*-------------------------------------------------.
7415 | yyexhaustedlab -- memory exhaustion comes here. |
7416 `-------------------------------------------------*/
7417 yyexhaustedlab:
7418 yyerror (yyscanner, gdbwire_mi_output, YY_("memory exhausted"));
7419 yyresult = 2;
7420 /* Fall through. */
7421 #endif
7422
7423 yyreturn:
7424 if (yychar != YYEMPTY)
7425 {
7426 /* Make sure we have latest lookahead translation. See comments at
7427 user semantic actions for why this is necessary. */
7428 yytoken = YYTRANSLATE (yychar);
7429 yydestruct ("Cleanup: discarding lookahead",
7430 yytoken, &yylval, yyscanner, gdbwire_mi_output);
7431 }
7432 /* Do not reclaim the symbols of the rule whose action triggered
7433 this YYABORT or YYACCEPT. */
7434 YYPOPSTACK (yylen);
7435 YY_STACK_PRINT (yyss, yyssp);
7436 while (yyssp != yyss)
7437 {
7438 yydestruct ("Cleanup: popping",
7439 yystos[*yyssp], yyvsp, yyscanner, gdbwire_mi_output);
7440 YYPOPSTACK (1);
7441 }
7442 #ifndef yyoverflow
7443 if (yyss != yyssa)
7444 YYSTACK_FREE (yyss);
7445 #endif
7446 yyps->yynew = 1;
7447
7448 yypushreturn:
7449 #if YYERROR_VERBOSE
7450 if (yymsg != yymsgbuf)
7451 YYSTACK_FREE (yymsg);
7452 #endif
7453 return yyresult;
7454 }
7455 /***** End of gdbwire_mi_grammar.c *******************************************/
7456 /***** Begin file gdbwire.c **************************************************/
7457 /**
7458 * Copyright 2013 Robert Rossi <bob@brasko.net>
7459 *
7460 * This file is part of GDBWIRE.
7461 *
7462 * GDBWIRE is free software: you can redistribute it and/or modify
7463 * it under the terms of the GNU General Public License as published by
7464 * the Free Software Foundation, either version 3 of the License, or
7465 * (at your option) any later version.
7466 *
7467 * GDBWIRE is distributed in the hope that it will be useful,
7468 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7469 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7470 * GNU General Public License for more details.
7471 *
7472 * You should have received a copy of the GNU General Public License
7473 * along with GDBWIRE. If not, see <http://www.gnu.org/licenses/>.
7474 */
7475
7476 #include <stdlib.h>
7477 #include <string.h>
7478
7479 /* #include "gdbwire_assert.h" */
7480 /***** Include gdbwire.h in the middle of gdbwire.c **************************/
7481 /***** Begin file gdbwire.h **************************************************/
7482 /**
7483 * Copyright 2013 Robert Rossi <bob@brasko.net>
7484 *
7485 * This file is part of GDBWIRE.
7486 *
7487 * GDBWIRE is free software: you can redistribute it and/or modify
7488 * it under the terms of the GNU General Public License as published by
7489 * the Free Software Foundation, either version 3 of the License, or
7490 * (at your option) any later version.
7491 *
7492 * GDBWIRE is distributed in the hope that it will be useful,
7493 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7494 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7495 * GNU General Public License for more details.
7496 *
7497 * You should have received a copy of the GNU General Public License
7498 * along with GDBWIRE. If not, see <http://www.gnu.org/licenses/>.
7499 */
7500
7501 #ifndef GDBWIRE_H
7502 #define GDBWIRE_H
7503
7504 #ifdef __cplusplus
7505 extern "C" {
7506 #endif
7507
7508 #include <stdlib.h>
7509 /* #include "gdbwire_result.h" */
7510 /* #include "gdbwire_mi_pt.h" */
7511 /* #include "gdbwire_mi_command.h" */
7512
7513 /* The opaque gdbwire context */
7514 struct gdbwire;
7515
7516 /**
7517 * The primary mechanism for gdbwire to send events to the caller.
7518 *
7519 * The flow is like this:
7520 * - create a gdbwire instance
7521 * - loop:
7522 * - call gdbwire functions to send commands to gdb
7523 * - receive callback events with results when they become available
7524 * - destroy the instance
7525 */
7526 struct gdbwire_callbacks {
7527 /**
7528 * An arbitrary pointer to associate with the events.
7529 *
7530 * This pointer will be passed back to the caller in each event.
7531 */
7532 void *context;
7533
7534 /**
7535 * A console, target or log output event has occured.
7536 *
7537 * @param context
7538 * The context pointer above.
7539 *
7540 * @param stream_record
7541 * The stream record to display to the user.
7542 */
7543 void (*gdbwire_stream_record_fn)(void *context,
7544 struct gdbwire_mi_stream_record *stream_record);
7545
7546 /**
7547 * An asynchronous output event.
7548 *
7549 * @param context
7550 * The context pointer above.
7551 *
7552 * @param async_record
7553 * The asychronous record output by GDB.
7554 */
7555 void (*gdbwire_async_record_fn)(void *context,
7556 struct gdbwire_mi_async_record *async_record);
7557
7558 /**
7559 * A result output event.
7560 *
7561 * @param context
7562 * The context pointer above.
7563 *
7564 * @param result_record
7565 * The result record output by GDB.
7566 */
7567 void (*gdbwire_result_record_fn)(void *context,
7568 struct gdbwire_mi_result_record *result_record);
7569
7570 /**
7571 * A prompt output event.
7572 *
7573 * @param context
7574 * The context pointer above.
7575 *
7576 * @param prompt
7577 * The prompt output to display to the user.
7578 */
7579 void (*gdbwire_prompt_fn)(void *context, const char *prompt);
7580
7581 /**
7582 * A gdbwire parse error occurred.
7583 *
7584 * If you receive this callback, that means the gdbwire parser
7585 * failed to parse some gdb/mi coming out of gdb.
7586 * Please send the parameters received in this callback to the
7587 * gdbwire develpment team.
7588 *
7589 * @param context
7590 * The context pointer above.
7591 *
7592 * @param mi
7593 * The mi string that gdbwire could not parse.
7594 *
7595 * @param token
7596 * The token the error occurred on.
7597 *
7598 * @param position
7599 * The position of the token the error occurred on.
7600 */
7601 void (*gdbwire_parse_error_fn)(void *context, const char *mi,
7602 const char *token, struct gdbwire_mi_position position);
7603 };
7604
7605 /**
7606 * Create a gdbwire context.
7607 *
7608 * Each gdbwire structure is capable of talking to a single gdb instance.
7609 *
7610 * @param callbacks
7611 * The callback functions for when events should be sent. Be sure to
7612 * initialize all of the callback functions. If a callback event is
7613 * initialized to NULL, it will not be called.
7614 *
7615 * @return
7616 * A new gdbwire instance or NULL on error.
7617 */
7618 struct gdbwire *gdbwire_create(struct gdbwire_callbacks callbacks);
7619
7620 /**
7621 * Destroy a gdbwire context.
7622 *
7623 * This function will do nothing if the instance is NULL.
7624 *
7625 * @param gdbwire
7626 * The instance of gdbwire to destroy
7627 */
7628 void gdbwire_destroy(struct gdbwire *wire);
7629
7630 /**
7631 * Push some GDB output characters to gdbwire for processing.
7632 *
7633 * Currently, the calling application is responsible for reading the
7634 * output of GDB and sending it to gdbwire. This may change in the future.
7635 * Call this function with output from GDB when it is available.
7636 *
7637 * During this function, callback events may be invoked to alert the
7638 * caller of useful gdbwire_mi events.
7639 *
7640 * @param wire
7641 * The gdbwire context to operate on.
7642 *
7643 * @param data
7644 * The data to push to gdbwire for interpretation.
7645 *
7646 * @param size
7647 * The size of the data to push to gdbwire.
7648 *
7649 * @return
7650 * GDBWIRE_OK on success or appropriate error result on failure.
7651 */
7652 enum gdbwire_result gdbwire_push_data(struct gdbwire *wire, const char *data,
7653 size_t size);
7654
7655 /**
7656 * Handle an interpreter-exec command.
7657 *
7658 * Typically, a front end would start gdb with the MI interface and create
7659 * a corresponding gdbwire instance. The front end would feed the gdbwire
7660 * instance all of the MI output. In this scenario, gdbwire triggers
7661 * callbacks when interesting events occur.
7662 *
7663 * Some GDB front ends use the annotate interface with gdb, and will
7664 * transition to using MI through the use of the interpreter-exec command.
7665 * In this scenario, the front end will send GDB a single interpreter-exec
7666 * command and will want to interpret the output of only that command.
7667 * For this use case, a gdbwire instance is not necessary for the front end,
7668 * nor any of the callbacks associated with that instance.
7669 *
7670 * This function provides a way for a front end to interpret the output
7671 * of a single interpreter-exec command with out the need for creating
7672 * a gdbwire instance or any gdbwire callbacks.
7673 *
7674 * @param interpreter_exec_output
7675 * The MI output from GDB for the interpreter exec command.
7676 *
7677 * @param kind
7678 * The interpreter-exec command kind.
7679 *
7680 * @param out_mi_command
7681 * Will return an allocated gdbwire mi command if GDBWIRE_OK is returned
7682 * from this function. You should free this memory with
7683 * gdbwire_mi_command_free when you are done with it.
7684 *
7685 * @return
7686 * The result of this function.
7687 */
7688 enum gdbwire_result gdbwire_interpreter_exec(
7689 const char *interpreter_exec_output,
7690 enum gdbwire_mi_command_kind kind,
7691 struct gdbwire_mi_command **out_mi_command);
7692
7693 #ifdef __cplusplus
7694 }
7695 #endif
7696
7697 #endif
7698 /***** End of gdbwire.h ******************************************************/
7699 /***** Continuing where we left off in gdbwire.c *****************************/
7700 /* #include "gdbwire_mi_parser.h" */
7701
7702 struct gdbwire
7703 {
7704 /* The gdbwire_mi parser. */
7705 struct gdbwire_mi_parser *parser;
7706
7707 /* The client callback functions */
7708 struct gdbwire_callbacks callbacks;
7709 };
7710
7711 static void
gdbwire_mi_output_callback(void * context,struct gdbwire_mi_output * output)7712 gdbwire_mi_output_callback(void *context, struct gdbwire_mi_output *output) {
7713 struct gdbwire *wire = (struct gdbwire *)context;
7714
7715 struct gdbwire_mi_output *cur = output;
7716
7717 while (cur) {
7718 switch (cur->kind) {
7719 case GDBWIRE_MI_OUTPUT_OOB: {
7720 struct gdbwire_mi_oob_record *oob_record =
7721 cur->variant.oob_record;
7722 switch (oob_record->kind) {
7723 case GDBWIRE_MI_ASYNC:
7724 if (wire->callbacks.gdbwire_async_record_fn) {
7725 wire->callbacks.gdbwire_async_record_fn(
7726 wire->callbacks.context,
7727 oob_record->variant.async_record);
7728 }
7729 break;
7730 case GDBWIRE_MI_STREAM:
7731 if (wire->callbacks.gdbwire_stream_record_fn) {
7732 wire->callbacks.gdbwire_stream_record_fn(
7733 wire->callbacks.context,
7734 oob_record->variant.stream_record);
7735 }
7736 break;
7737 }
7738 break;
7739 }
7740 case GDBWIRE_MI_OUTPUT_RESULT:
7741 if (wire->callbacks.gdbwire_result_record_fn) {
7742 wire->callbacks.gdbwire_result_record_fn(
7743 wire->callbacks.context, cur->variant.result_record);
7744 }
7745 break;
7746 case GDBWIRE_MI_OUTPUT_PROMPT:
7747 if (wire->callbacks.gdbwire_prompt_fn) {
7748 wire->callbacks.gdbwire_prompt_fn(
7749 wire->callbacks.context, cur->line);
7750 }
7751 break;
7752 case GDBWIRE_MI_OUTPUT_PARSE_ERROR:
7753 if (wire->callbacks.gdbwire_parse_error_fn) {
7754 wire->callbacks.gdbwire_parse_error_fn(
7755 wire->callbacks.context, cur->line,
7756 cur->variant.error.token,
7757 cur->variant.error.pos);
7758 }
7759 break;
7760 }
7761
7762 cur = cur->next;
7763 }
7764
7765 gdbwire_mi_output_free(output);
7766 }
7767
7768 struct gdbwire *
gdbwire_create(struct gdbwire_callbacks callbacks)7769 gdbwire_create(struct gdbwire_callbacks callbacks)
7770 {
7771 struct gdbwire *result = 0;
7772
7773 result = malloc(sizeof(struct gdbwire));
7774 if (result) {
7775 struct gdbwire_mi_parser_callbacks parser_callbacks =
7776 { result,gdbwire_mi_output_callback };
7777 result->callbacks = callbacks;
7778 result->parser = gdbwire_mi_parser_create(parser_callbacks);
7779 if (!result->parser) {
7780 free(result);
7781 result = 0;
7782 }
7783 }
7784
7785 return result;
7786 }
7787
7788 void
gdbwire_destroy(struct gdbwire * gdbwire)7789 gdbwire_destroy(struct gdbwire *gdbwire)
7790 {
7791 if (gdbwire) {
7792 gdbwire_mi_parser_destroy(gdbwire->parser);
7793 free(gdbwire);
7794 }
7795 }
7796
7797 enum gdbwire_result
gdbwire_push_data(struct gdbwire * wire,const char * data,size_t size)7798 gdbwire_push_data(struct gdbwire *wire, const char *data, size_t size)
7799 {
7800 enum gdbwire_result result;
7801 GDBWIRE_ASSERT(wire);
7802 result = gdbwire_mi_parser_push_data(wire->parser, data, size);
7803 return result;
7804 }
7805
7806 struct gdbwire_interpreter_exec_context {
7807 enum gdbwire_result result;
7808 enum gdbwire_mi_command_kind kind;
7809 struct gdbwire_mi_command *mi_command;
7810 };
7811
gdbwire_interpreter_exec_stream_record(void * context,struct gdbwire_mi_stream_record * stream_record)7812 static void gdbwire_interpreter_exec_stream_record(void *context,
7813 struct gdbwire_mi_stream_record *stream_record)
7814 {
7815 struct gdbwire_interpreter_exec_context *ctx =
7816 (struct gdbwire_interpreter_exec_context*)context;
7817 ctx->result = GDBWIRE_LOGIC;
7818 }
7819
gdbwire_interpreter_exec_async_record(void * context,struct gdbwire_mi_async_record * async_record)7820 static void gdbwire_interpreter_exec_async_record(void *context,
7821 struct gdbwire_mi_async_record *async_record)
7822 {
7823 struct gdbwire_interpreter_exec_context *ctx =
7824 (struct gdbwire_interpreter_exec_context*)context;
7825 ctx->result = GDBWIRE_LOGIC;
7826 }
7827
gdbwire_interpreter_exec_result_record(void * context,struct gdbwire_mi_result_record * result_record)7828 static void gdbwire_interpreter_exec_result_record(void *context,
7829 struct gdbwire_mi_result_record *result_record)
7830 {
7831 struct gdbwire_interpreter_exec_context *ctx =
7832 (struct gdbwire_interpreter_exec_context*)context;
7833
7834 if (ctx->result == GDBWIRE_OK) {
7835 ctx->result = gdbwire_get_mi_command(
7836 ctx->kind, result_record, &ctx->mi_command);
7837 }
7838 }
7839
gdbwire_interpreter_exec_prompt(void * context,const char * prompt)7840 static void gdbwire_interpreter_exec_prompt(void *context, const char *prompt)
7841 {
7842 struct gdbwire_interpreter_exec_context *ctx =
7843 (struct gdbwire_interpreter_exec_context*)context;
7844 ctx->result = GDBWIRE_LOGIC;
7845 }
7846
gdbwire_interpreter_exec_parse_error(void * context,const char * mi,const char * token,struct gdbwire_mi_position position)7847 static void gdbwire_interpreter_exec_parse_error(void *context,
7848 const char *mi, const char *token, struct gdbwire_mi_position
7849 position)
7850 {
7851 struct gdbwire_interpreter_exec_context *ctx =
7852 (struct gdbwire_interpreter_exec_context*)context;
7853 ctx->result = GDBWIRE_LOGIC;
7854 }
7855
7856
7857 enum gdbwire_result
gdbwire_interpreter_exec(const char * interpreter_exec_output,enum gdbwire_mi_command_kind kind,struct gdbwire_mi_command ** out_mi_command)7858 gdbwire_interpreter_exec(
7859 const char *interpreter_exec_output,
7860 enum gdbwire_mi_command_kind kind,
7861 struct gdbwire_mi_command **out_mi_command)
7862 {
7863 struct gdbwire_interpreter_exec_context context = {
7864 GDBWIRE_OK, kind, 0 };
7865 size_t len;
7866 enum gdbwire_result result = GDBWIRE_OK;
7867 struct gdbwire_callbacks callbacks = {
7868 &context,
7869 gdbwire_interpreter_exec_stream_record,
7870 gdbwire_interpreter_exec_async_record,
7871 gdbwire_interpreter_exec_result_record,
7872 gdbwire_interpreter_exec_prompt,
7873 gdbwire_interpreter_exec_parse_error
7874 };
7875 struct gdbwire *wire;
7876
7877 GDBWIRE_ASSERT(interpreter_exec_output);
7878 GDBWIRE_ASSERT(out_mi_command);
7879
7880 len = strlen(interpreter_exec_output);
7881
7882 wire = gdbwire_create(callbacks);
7883 GDBWIRE_ASSERT(wire);
7884
7885 result = gdbwire_push_data(wire, interpreter_exec_output, len);
7886 if (result == GDBWIRE_OK) {
7887 /* Honor function documentation,
7888 * When it returns GDBWIRE_OK - the command will exist.
7889 * Otherwise it will not. */
7890 if (context.result == GDBWIRE_OK && !context.mi_command) {
7891 result = GDBWIRE_LOGIC;
7892 } else if (context.result != GDBWIRE_OK && context.mi_command) {
7893 result = context.result;
7894 gdbwire_mi_command_free(context.mi_command);
7895 } else {
7896 result = context.result;
7897 *out_mi_command = context.mi_command;
7898 }
7899 }
7900
7901 gdbwire_destroy(wire);
7902 return result;
7903 }
7904 /***** End of gdbwire.c ******************************************************/
7905