1 /*
2  *      gdb_mi.h
3  *
4  *      Copyright 2014 Colomban Wendling <colomban@geany.org>
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program; if not, write to the Free Software
18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *      MA 02110-1301, USA.
20  */
21 
22 #ifndef GDB_MI_H
23 #define GDB_MI_H
24 
25 #include <glib.h>
26 
27 enum gdb_mi_value_type
28 {
29 	GDB_MI_VAL_STRING,
30 	GDB_MI_VAL_LIST
31 };
32 
33 struct gdb_mi_result;
34 struct gdb_mi_value
35 {
36 	enum gdb_mi_value_type type;
37 	union {
38 		gchar *string;
39 		struct gdb_mi_result *list;
40 	} v;
41 };
42 
43 struct gdb_mi_result
44 {
45 	gchar *var;
46 	struct gdb_mi_value *val;
47 	struct gdb_mi_result *next;
48 };
49 
50 enum gdb_mi_record_type
51 {
52 	GDB_MI_TYPE_PROMPT = 0,
53 	GDB_MI_TYPE_RESULT = '^',
54 	GDB_MI_TYPE_EXEC_ASYNC = '*',
55 	GDB_MI_TYPE_STATUS_ASYNC = '+',
56 	GDB_MI_TYPE_NOTIFY_ASYNC = '=',
57 	GDB_MI_TYPE_CONSOLE_STREAM = '~',
58 	GDB_MI_TYPE_TARGET_STREAM = '@',
59 	GDB_MI_TYPE_LOG_STREAM = '&'
60 };
61 
62 struct gdb_mi_record
63 {
64 	enum gdb_mi_record_type type;
65 	gchar *token;
66 	gchar *klass; /*< contains the async record class or the stream output */
67 	struct gdb_mi_result *first; /*< pointer to the first result (if any) */
68 };
69 
70 
71 void gdb_mi_value_free(struct gdb_mi_value *val);
72 void gdb_mi_result_free(struct gdb_mi_result *res, gboolean next);
73 void gdb_mi_record_free(struct gdb_mi_record *record);
74 struct gdb_mi_record *gdb_mi_record_parse(const gchar *line);
75 const void *gdb_mi_result_var(const struct gdb_mi_result *result, const gchar *name, enum gdb_mi_value_type type);
76 gboolean gdb_mi_record_matches(const struct gdb_mi_record *record, enum gdb_mi_record_type type, const gchar *klass, ...) G_GNUC_NULL_TERMINATED;
77 
78 #define gdb_mi_result_foreach(node_, result_) \
79 	for ((node_) = (result_); (node_); (node_) = (node_)->next)
80 
81 #define gdb_mi_result_foreach_matched(node_, result_, name_, type_) \
82 	gdb_mi_result_foreach ((node_), (result_)) \
83 		if (((name_) != NULL && (! (node_)->var || strcmp((node_)->var, (name_) ? (name_) : "") != 0)) || \
84 			((type_) >= 0 && (node_)->val->type != (type_))) \
85 			continue; \
86 		else
87 
88 #endif /* guard */
89