-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgdbwire.c
8103 lines (6949 loc) · 231 KB
/
gdbwire.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (C) 2013 Robert Rossi <bob@brasko.net>
*
* This file is an amalgamation of the source files from GDBWIRE.
*
* It was created using gdbwire 1.0 and git revision d43423e.
*
* GDBWIRE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GDBWIRE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GDBWIRE. If not, see <http://www.gnu.org/licenses/>.
*/
/***** Begin file gdbwire_sys.c **********************************************/
#include <stdlib.h>
#include <string.h>
/***** Include gdbwire_sys.h in the middle of gdbwire_sys.c ******************/
/***** Begin file gdbwire_sys.h **********************************************/
#ifndef __GDBWIRE_SYS_H__
#define __GDBWIRE_SYS_H__
/**
* Supporting system functions.
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* Duplicate a string.
*
* @param str
* The string to duplicate
*
* @return
* An allocated string that must be freed.
* Null if out of memory or str is NULL.
*/
char *gdbwire_strdup(const char *str);
#ifdef __cplusplus
}
#endif
#endif
/***** End of gdbwire_sys.h **************************************************/
/***** Continuing where we left off in gdbwire_sys.c *************************/
char *gdbwire_strdup(const char *str)
{
char *result = NULL;
if (str) {
size_t length_to_allocate = strlen(str) + 1;
result = malloc(length_to_allocate * sizeof(char));
if (result) {
strcpy(result, str);
}
}
return result;
}
/***** End of gdbwire_sys.c **************************************************/
/***** Begin file gdbwire_string.c *******************************************/
#include <string.h>
#include <stdlib.h>
/***** Include gdbwire_string.h in the middle of gdbwire_string.c ************/
/***** Begin file gdbwire_string.h *******************************************/
#ifndef __GDBWIRE_STRING_H__
#define __GDBWIRE_STRING_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
/**
* A dynamic string representation.
*
* To create and destroy a string use gdbwire_string_create() and
* gdbwire_string_destroy() respectively.
*
* This string is an abstraction of a low level C string. It supports being
* used as a NULL terminated c string and also as an arbitrary array of
* bytes. You can append to this string in either of these modes using
* gdbwire_string_append_cstr() or gdbwire_string_append_data(). This string
* automatically grows as you append data to it. Please note, the size of
* the string will not include the NULL terminated character when using
* the gdbwire_string_append_cstr() function to append data.
*
* To get access to the underlying bytes associated with this string
* call gdbwire_string_data(). It is OK to modify the result as long as
* you are careful to stay in it's valid bounds.
*
* The size (or length) of the string can be accessed through the
* gdbwire_string_size() function. The character pointer returned from
* gdbwire_string_data() is valid from the index range of 0 to
* gdbwire_string_size() - 1.
*/
struct gdbwire_string;
/**
* Create a string instance.
*
* @return
* A valid string instance or NULL on error.
*/
struct gdbwire_string *gdbwire_string_create(void);
/**
* Destroy the string instance and it's resources.
*
* @param string
* The string to destroy.
*/
void gdbwire_string_destroy(struct gdbwire_string *string);
/**
* Clear the contents of a string.
*
* Sets the string back to an empty string which also changes it's
* size back to zero.
*
* The capacity remains unchanged.
*
* @param string
* The string to clear
*/
void gdbwire_string_clear(struct gdbwire_string *string);
/**
* Append a c string to the string instance.
*
* @param string
* The string instance to append the c string to.
*
* @param cstr
* The c string to append to the string instance.
*
* @return
* 0 on success or -1 on failure.
*/
int gdbwire_string_append_cstr(struct gdbwire_string *string, const char *cstr);
/**
* Append a sequence of bytes to the string instance.
*
* @param string
* The string instance to append the sequence of bytes to.
*
* @param data
* The sequence of bytes to append to the string instance. This may
* contain NUL characters.
*
* @param size
* The number of bytes in data to append to the string instance.
*
* @return
* 0 on success or -1 on failure.
*/
int gdbwire_string_append_data(struct gdbwire_string *string,
const char *data, size_t size);
/**
* Get the data associated with this string.
*
* The data could be formatted as a NULL terminated C string or
* as an arbitrary array of bytes. Use gdbwire_string_size() to
* determine the size (or length) of the result of this function.
*
* Modifying the return value of this function is acceptable as long as you
* stay in the string's valid bounds.
*
* @param string
* The string index to get the pointer data from.
*
* @return
* The data that has been added to this string instance or "" after
* creation or clear. The result is gdbwire_string_size() bytes long.
*/
char *gdbwire_string_data(struct gdbwire_string *string);
/**
* Determine the size (the number of bytes) this string instance represents.
*
* Please note, the result of this function will not include the NULL
* terminated character when using the gdbwire_string_append_cstr() function
* to append data.
*
* @param string
* The string instance to get the size for.
*
* @return
* The number of bytes contained in this string instance. To access these
* bytes see gdbwire_string_data(). Will be 0 after creation or clear.
*/
size_t gdbwire_string_size(struct gdbwire_string *string);
/**
* Determine the maximum capacity (number of bytes) this string may hold.
*
* The max capacity of the string is automatically increased when data
* is appended to this string through the gdbwire_string_append_*()
* family of functions.
*
* @param string
* The string to determine the capacity of.
*
* @return
* The max number of bytes this string may hold.
*/
size_t gdbwire_string_capacity(struct gdbwire_string *string);
/**
* Search for the first character in chars occuring in this string.
*
* @param string
* The string to search for the characters in chars in.
*
* @param chars
* A null terminated string of characters. This string is not searched
* for directly but instead each individually character in the string
* is searched for.
*
* @return
* The index position of the first matched character in chars.
* Will return gdbwire_string_size() if not found.
*/
size_t gdbwire_string_find_first_of(struct gdbwire_string *string,
const char *chars);
/**
* Erase characters from this string, reducing it's size.
*
* @param string
* The string to erase characters from.
*
* @param pos
* The index position of the first character to be erased.
*
* @param count
* The number of characters to erase starting at position pos.
* If count goes past the end of the string it is adjusted to erase
* until the end of the string. This allows the caller to pass in
* gdbwire_string_size() to erase the end of the string with out
* doing index arithmetic.
*
* @return
* On success 0 will be returned otherwise -1. The string will remain
* unmodified when an error occurs. Success can only occur if the entire
* requested range can be erased.
*/
int gdbwire_string_erase(struct gdbwire_string *string, size_t pos,
size_t count);
#ifdef __cplusplus
}
#endif
#endif
/***** End of gdbwire_string.h ***********************************************/
/***** Continuing where we left off in gdbwire_string.c **********************/
struct gdbwire_string {
/* The bytes that make up the string. May contain NUL characters. */
char *data;
/* The number of bytes occuring in data at the moment. */
size_t size;
/* The max capacity of the string */
size_t capacity;
};
struct gdbwire_string *
gdbwire_string_create(void)
{
struct gdbwire_string *string;
string = calloc(1, sizeof (struct gdbwire_string));
if (string) {
if (gdbwire_string_append_cstr(string, "") == -1) {
gdbwire_string_destroy(string);
string = NULL;
}
}
return string;
}
void
gdbwire_string_destroy(struct gdbwire_string *string)
{
if (string) {
if (string->data) {
free(string->data);
string->data = NULL;
}
string->size = 0;
string->capacity = 0;
free(string);
}
}
void
gdbwire_string_clear(struct gdbwire_string *string)
{
if (string) {
string->size = 0;
string->data[0] = '\0';
}
}
/**
* Increase the size of the string capacity.
*
* @param string
* The string to increase the capacity.
*
* @return
* 0 on success or -1 on error.
*/
static int
gdbwire_string_increase_capacity(struct gdbwire_string *string)
{
/**
* The algorithm chosen to increase the capacity is arbitrary.
* It starts at 128 bytes. It then doubles it's size in bytes like this,
* 128, 256, 512, 1024, 2048, 4096
* After it reaches 4096 it then grows by 4096 bytes at a time.
*/
if (string->capacity == 0) {
string->capacity = 128;
} else if (string->capacity < 4096) {
string->capacity *= 2;
} else {
string->capacity += 4096;
}
/* At this point string->capacity is set to the new size, so realloc */
string->data = (char*)realloc(string->data, string->capacity);
return (string->data) ? 0 : -1;
}
int
gdbwire_string_append_cstr(struct gdbwire_string *string, const char *cstr)
{
int result;
if (string && cstr) {
size_t length = strlen(cstr) + 1;
result = gdbwire_string_append_data(string, cstr, length);
/* Do not include the NUL character in the size for NULL terminated
* strings. This is documented in the interface. */
if (result == 0) {
string->size--;
}
} else {
result = -1;
}
return result;
}
int
gdbwire_string_append_data(struct gdbwire_string *string, const char *data,
size_t size)
{
int result = (string && data) ? 0 : -1;
size_t data_index = 0;
for (; string && data && data_index < size; ++data_index, ++string->size) {
if (string->size >= string->capacity) {
result = gdbwire_string_increase_capacity(string);
if (result == -1) {
break;
}
}
string->data[string->size] = data[data_index];
}
return result;
}
char *
gdbwire_string_data(struct gdbwire_string *string)
{
char *result = NULL;
if (string) {
result = string->data;
}
return result;
}
size_t
gdbwire_string_size(struct gdbwire_string *string)
{
return string->size;
}
size_t
gdbwire_string_capacity(struct gdbwire_string *string)
{
return string->capacity;
}
size_t
gdbwire_string_find_first_of(struct gdbwire_string *string, const char *chars)
{
size_t data_pos, data_size = 0;
char *data_cur;
const char *chars_cur;
if (string && chars) {
data_size = gdbwire_string_size(string);
data_cur = gdbwire_string_data(string);
for (data_pos = 0; data_pos < data_size; ++data_pos) {
char data_c = data_cur[data_pos];
for (chars_cur = chars; *chars_cur; ++chars_cur) {
if (data_c == *chars_cur) {
return data_pos;
}
}
}
}
return data_size;
}
int
gdbwire_string_erase(struct gdbwire_string *string, size_t pos, size_t count)
{
int result = -1;
if (string) {
size_t count_erased = count;
size_t data_size = gdbwire_string_size(string);
char *data = gdbwire_string_data(string);
/* The position index must be smaller than the data size to be valid */
if (pos < data_size) {
size_t from_pos = pos + count;
/**
* Check to see if anything needs to be copied.
* If not, just null terminate the position to be erased
* Null terminating the string ensures the c string and the data
* string approach are both safe. In the data mode, the nul
* character is unneeded.
*/
if (from_pos >= data_size) {
data[pos] = 0;
count_erased = data_size - pos;
/* If so, move characters from the from position
to the to position */
} else {
char *to_cur = &data[pos], *from_cur = &data[from_pos];
/* shift everything after the erase request to the left */
for (; from_pos < data_size; ++from_pos, ++to_cur, ++from_cur) {
*to_cur = *from_cur;
}
}
string->size -= count_erased;
result = 0;
}
}
return result;
}
/***** End of gdbwire_string.c ***********************************************/
/***** Begin file gdbwire_logger.c *******************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/***** Include gdbwire_logger.h in the middle of gdbwire_logger.c ************/
/***** Begin file gdbwire_logger.h *******************************************/
#ifndef __GDBWIRE_LOGGER_H__
#define __GDBWIRE_LOGGER_H__
/***** Include gdbwire_result.h in the middle of gdbwire_logger.h ************/
/***** Begin file gdbwire_result.h *******************************************/
#ifndef GDBWIRE_RESULT_H
#define GDBWIRE_RESULT_H
enum gdbwire_result {
/* The result of the operation was successful */
GDBWIRE_OK,
/**
* An assertion failed in the calling code.
*
* Functions are encouraged to assert expressions they expect
* to be true. The macro GDBWIRE_ASSERT and GDBWIRE_ASSERT_ERRNO
* are useful for asserting expressions, and upon failure, to
* automatically log the assertion expression and return
* this result status.
*/
GDBWIRE_ASSERT,
/**
* An internal logic error has occurred.
*
* In general, this should be used when a function can no
* longer carry out it's contract and must abort.
*
* This happens, for instance, when a called function returns
* an error status, or when invalid input was provided, etc.
*/
GDBWIRE_LOGIC,
/**
* The system is out of memory.
*
* Will occur when malloc, strdup, calloc, etc fail to allocate memory.
*/
GDBWIRE_NOMEM
};
#endif /* GDBWIRE_RESULT_H */
/***** End of gdbwire_result.h ***********************************************/
/***** Continuing where we left off in gdbwire_logger.h **********************/
#ifdef __cplusplus
extern "C" {
#endif
enum gdbwire_logger_level {
GDBWIRE_LOGGER_DEBUG,
GDBWIRE_LOGGER_INFO,
GDBWIRE_LOGGER_WARN,
GDBWIRE_LOGGER_ERROR
};
/**
* Log a statement to the logger.
*
* This is typically not called directly. Use the below macros instead.
* The macros automatically supply the file, line and level arguments.
*
* @param file
* The filename the logger was invoked from.
*
* @param line
* The line number the logger was invoked from.
*
* @param level
* The level associated with the log message.
*
* @param fmt
* The format string for the message (printf formatting).
*
* @param ...
* Any additional format arguments.
*/
void gdbwire_logger_log(const char *file, int line,
enum gdbwire_logger_level level, const char *fmt, ...)
#ifdef __GNUC__
__attribute__((__format__(__printf__, 4, 5)))
#endif
;
/* The macros intended to be used for logging */
#define gdbwire_debug(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
GDBWIRE_LOGGER_DEBUG, fmt, ##__VA_ARGS__))
#define gdbwire_info(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
GDBWIRE_LOGGER_INFO, fmt, ##__VA_ARGS__))
#define gdbwire_warn(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
GDBWIRE_LOGGER_WARN, fmt, ##__VA_ARGS__))
#define gdbwire_error(fmt, ...)(gdbwire_logger_log(__FILE__, __LINE__, \
GDBWIRE_LOGGER_ERROR, fmt, ##__VA_ARGS__))
#ifdef __cplusplus
}
#endif
#endif
/***** End of gdbwire_logger.h ***********************************************/
/***** Continuing where we left off in gdbwire_logger.c **********************/
static const char *gdbwire_logger_level_str[GDBWIRE_LOGGER_ERROR+1] = {
"DEBUG",
"INFO",
"WARN",
"ERROR"
};
void
gdbwire_logger_log(const char *file, int line, enum gdbwire_logger_level level,
const char *fmt, ...)
{
static int checked_env = 0;
static int gdbwire_debug_to_stderr;
char *buf;
int size;
va_list ap;
va_start(ap, fmt);
size = vsnprintf(0, 0, fmt, ap);
buf = malloc(sizeof(char)*size + 1);
va_start(ap, fmt);
size = vsnprintf(buf, size + 1, fmt, ap);
va_end(ap);
if (checked_env == 0) {
checked_env = 1;
gdbwire_debug_to_stderr = getenv("GDBWIRE_DEBUG_TO_STDERR") != NULL;
}
if (gdbwire_debug_to_stderr) {
fprintf(stderr, "gdbwire_logger_log: [%s] %s:%d %s\n",
gdbwire_logger_level_str[level], file, line, buf);
}
free(buf);
}
/***** End of gdbwire_logger.c ***********************************************/
/***** Begin file gdbwire_mi_parser.c ****************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* #include "gdbwire_sys.h" */
/***** Include gdbwire_assert.h in the middle of gdbwire_mi_parser.c *********/
/***** Begin file gdbwire_assert.h *******************************************/
#ifndef GDBWIRE_ERROR_H
#define GDBWIRE_ERROR_H
/* #include "gdbwire_result.h" */
/* #include "gdbwire_logger.h" */
/**
* Validate that the expression evaluates to true.
*
* If the expression does not evaluate to true, log the error and
* return a GDBWIRE_ASSERT status code.
*
* Otherwise, if the expression does evaluate to true, do nothing.
*
* @param expr
* The expression to evaluate.
*/
#define GDBWIRE_ASSERT(expr) \
do { \
if (!(expr)) { \
gdbwire_error("Assertion failure, expr[%s]", #expr); \
return GDBWIRE_ASSERT; \
} \
} while (0)
/**
* Validate that the expression evaluates to true.
*
* If the expression does not evaluate to true, log the error,
* set the variable provided to GDBWIRE_ASSERT and goto the label
* provided.
*
* Otherwise, if the expression does evaluate to true, do nothing.
*
* @param expr
* The expression to evaluate.
*
* @param variable
* The result variable to assign the value GDBWIRE_ASSERT to.
*
* @param label
* The label to jump to if the expression evaluates to False.
*/
#define GDBWIRE_ASSERT_GOTO(expr, variable, label) \
do { \
if (!(expr)) { \
gdbwire_error("Assertion failure, expr[%s], " \
"label[%s]", #expr, #label); \
variable = GDBWIRE_ASSERT; \
goto label; \
} \
} while (0)
/**
* Validate that the expression evaluates to true.
*
* This particular assertion macro is used when a system library
* call fails and that library call has an associated errno status
* to describe the failure reason.
*
* If the expression does not evaluate to true, log the error,
* along with the errno value and message and return a GDBWIRE_ASSERT
* status code.
*
* Otherwise, if the expression does evaluate to true, do nothing.
*
* @param expr
* The expression to evaluate.
*/
#define GDBWIRE_ASSERT_ERRNO(expr) \
do { \
if (!(expr)) { \
gdbwire_error("Assertion failure, expr[%s]," \
"errno[%d], strerror[%s]", \
#expr, errno, strerror(errno)); \
return GDBWIRE_ASSERT; \
} \
} while (0)
#endif /* GDBWIRE_ERROR_H */
/***** End of gdbwire_assert.h ***********************************************/
/***** Continuing where we left off in gdbwire_mi_parser.c *******************/
/***** Include gdbwire_mi_grammar.h in the middle of gdbwire_mi_parser.c *****/
/***** Begin file gdbwire_mi_grammar.h ***************************************/
/* A Bison parser, made by GNU Bison 3.1. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
# define YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int gdbwire_mi_debug;
#endif
/* "%code requires" blocks. */
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void *yyscan_t;
#endif
struct gdbwire_mi_output;
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
OPEN_BRACE = 258,
CLOSED_BRACE = 259,
OPEN_PAREN = 260,
CLOSED_PAREN = 261,
ADD_OP = 262,
MULT_OP = 263,
EQUAL_SIGN = 264,
TILDA = 265,
AT_SYMBOL = 266,
AMPERSAND = 267,
OPEN_BRACKET = 268,
CLOSED_BRACKET = 269,
NEWLINE = 270,
INTEGER_LITERAL = 271,
STRING_LITERAL = 272,
CSTRING = 273,
COMMA = 274,
CARROT = 275
};
#endif
/* Tokens. */
#define OPEN_BRACE 258
#define CLOSED_BRACE 259
#define OPEN_PAREN 260
#define CLOSED_PAREN 261
#define ADD_OP 262
#define MULT_OP 263
#define EQUAL_SIGN 264
#define TILDA 265
#define AT_SYMBOL 266
#define AMPERSAND 267
#define OPEN_BRACKET 268
#define CLOSED_BRACKET 269
#define NEWLINE 270
#define INTEGER_LITERAL 271
#define STRING_LITERAL 272
#define CSTRING 273
#define COMMA 274
#define CARROT 275
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
struct gdbwire_mi_output *u_output;
struct gdbwire_mi_oob_record *u_oob_record;
struct gdbwire_mi_result_record *u_result_record;
int u_result_class;
int u_async_record_kind;
struct gdbwire_mi_result_list *u_result_list;
struct gdbwire_mi_result *u_result;
char *u_token;
struct gdbwire_mi_async_record *u_async_record;
struct gdbwire_mi_stream_record *u_stream_record;
int u_async_class;
char *u_variable;
char *u_cstring;
struct gdbwire_mi_result *u_tuple;
struct gdbwire_mi_result *u_list;
int u_stream_record_kind;
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
#ifndef YYPUSH_MORE_DEFINED
# define YYPUSH_MORE_DEFINED
enum { YYPUSH_MORE = 4 };
#endif
typedef struct gdbwire_mi_pstate gdbwire_mi_pstate;
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);
gdbwire_mi_pstate * gdbwire_mi_pstate_new (void);
void gdbwire_mi_pstate_delete (gdbwire_mi_pstate *ps);
#endif /* !YY_GDBWIRE_MI_SRC_GDBWIRE_MI_GRAMMAR_H_INCLUDED */
/***** End of gdbwire_mi_grammar.h *******************************************/
/***** Continuing where we left off in gdbwire_mi_parser.c *******************/
/***** Include gdbwire_mi_parser.h in the middle of gdbwire_mi_parser.c ******/
/***** Begin file gdbwire_mi_parser.h ****************************************/
#ifndef GDBWIRE_MI_PARSER_H
#define GDBWIRE_MI_PARSER_H
#ifdef __cplusplus
extern "C" {
#endif
/* #include "gdbwire_result.h" */
/***** Include gdbwire_mi_pt.h in the middle of gdbwire_mi_parser.h **********/
/***** Begin file gdbwire_mi_pt.h ********************************************/
#ifndef GDBWIRE_MI_PT_H
#define GDBWIRE_MI_PT_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* The position of a token in a GDB/MI line.
*
* Note that a string in C is zero based and the token column
* position is 1 based. For example,
* char *str = "hello world";
* The "hello" token would have a start_column as 1 and an end
* column as 5.
*
* The start_column and end_column will be the same column number for
* a token of size 1.
*/
struct gdbwire_mi_position {
/* The starting column position of the token */
int start_column;
/* The ending column position of the token */
int end_column;
};
/** The gdbwire_mi output kinds. */
enum gdbwire_mi_output_kind {
/**
* The GDB/MI output contains an out of band record.
*
* The out of band record is not necessarily associated with any
* particular GDB/MI input command.
*/
GDBWIRE_MI_OUTPUT_OOB,
/**
* The GDB/MI output contains a gdbwire_mi result record.
*
* This record typically contains the result data from a request
* made by the client in a previous GDB/MI input command.
*/
GDBWIRE_MI_OUTPUT_RESULT,
/**
* The GDB/MI output represents a prompt. (ie. (gdb) )
*
* TODO: Document when GDB is ready to receive a command. Only if
* the prompt is received and at *stopped?
*/
GDBWIRE_MI_OUTPUT_PROMPT,
/**
* A parse error occurred.
*/
GDBWIRE_MI_OUTPUT_PARSE_ERROR
};
/**
* The GDB/MI output command.
*
* A GDB/MI output command is the main mechanism in which GDB
* corresponds with a front end.
*/
struct gdbwire_mi_output {
enum gdbwire_mi_output_kind kind;
union {
/** When kind == GDBWIRE_MI_OUTPUT_OOB, never NULL. */
struct gdbwire_mi_oob_record *oob_record;
/** When kind == GDBWIRE_MI_OUTPUT_RESULT, never NULL. */
struct gdbwire_mi_result_record *result_record;
/** When kind == GDBWIRE_MI_OUTPUT_PARSE_ERROR, never NULL. */
struct {
/** The token the error occurred on */
char *token;
/** The position of the token where the error occurred. */
struct gdbwire_mi_position pos;
} error;
} variant;
/**
* The GDB/MI output line that was used to create this output instance.
*
* Each gdbwire_mi output structure is created from exactly one line of
* MI output from GDB. This field represents the line that created
* this particular output structure.
*
* This field is always available and never NULL, even for a parse error.
*/
char *line;
/** The next GDB/MI output command or NULL if none */
struct gdbwire_mi_output *next;
};
/**
* A GDB/MI token.
*
* A string made up of one or more digits.
* The regular expression [0-9]+ will match this types contents.
*/
typedef char *gdbwire_mi_token_t;
/**
* A GDB/MI output command may contain one of the following result indications.
*/
enum gdbwire_mi_result_class {
/**
* The synchronous operation was successful (^done).
*/
GDBWIRE_MI_DONE,
/**
* Equivalent to GDBWIRE_MI_DONE (^running).
*
* Historically, was output by GDB instead of ^done if the command