1 /*
2  *      debug_module.h
3  *
4  *      Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru>
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 DEBUG_MODULE_H
23 #define DEBUG_MODULE_H
24 
25 #include <glib.h>
26 
27 #include "breakpoint.h"
28 
29 /* debug states enumeration */
30 enum dbs {
31 	DBS_IDLE,
32 	DBS_STOPPED,
33 	DBS_STOP_REQUESTED,
34 	DBS_RUNNING,
35 	DBS_RUN_REQUESTED,
36 };
37 
38 /* type to hold callbacks to call from debugger modules */
39 typedef struct _dbg_callbacks {
40 	void (*set_run) (void);
41 	void (*set_stopped) (int thread_id);
42 	void (*set_exited) (int code);
43 	void (*send_message) (const gchar* message, const gchar *color);
44 	void (*clear_messages) (void);
45 	void (*report_error) (const gchar* message);
46 	void (*add_thread) (int thread_id);
47 	void (*remove_thread) (int thread_id);
48 } dbg_callbacks;
49 
50 typedef enum _variable_type {
51 	VT_ARGUMENT,
52 	VT_LOCAL,
53 	VT_WATCH,
54 	VT_GLOBAL,
55 	VT_CHILD,
56 	VT_NONE
57 } variable_type;
58 
59 /* type to hold information about a variable */
60 typedef struct _variable {
61 	/* variable name */
62 	GString *name;
63 	/* internal name - GDB specific name to get information
64 	 * about a watch or local variable*/
65 	GString *internal;
66 	/* expression of a variable */
67 	GString *expression;
68 	/* variable type */
69 	GString *type;
70 	/* variable value */
71 	GString *value;
72 	/* flag indicating whether a variable has children */
73 	gboolean has_children;
74 	/* flag indicating whether getting variable value was successfull */
75 	gboolean evaluated;
76 	/* variable type */
77 	variable_type vt;
78 } variable;
79 
80 /* type to hold information about a stack frame */
81 typedef struct _frame {
82 	gint ref_count;
83 	gchar *address;
84 	gchar *function;
85 	gchar *file;
86 	gint line;
87 	gboolean have_source;
88 } frame;
89 
90 /* enumeration for module features */
91 typedef enum _module_features
92 {
93 	MF_ASYNC_BREAKS = 1 << 0
94 } module_features;
95 
96 /* enumeration for breakpoints activities */
97 typedef enum _break_set_activity {
98 	BSA_NEW_BREAK,
99 	BSA_UPDATE_ENABLE,
100 	BSA_UPDATE_CONDITION,
101 	BSA_UPDATE_HITS_COUNT,
102 	BSA_REMOVE
103 } break_set_activity;
104 
105 /* type to hold pointers to describe a debug module */
106 typedef struct _dbg_module {
107 
108 	gboolean (*run) (const gchar* target, const gchar* commandline, GList* env, GList *witer, GList *biter, const gchar* terminal_device, dbg_callbacks* callbacks);
109 	void (*restart) (void);
110 	void (*stop) (void);
111 	void (*resume) (void);
112 	void (*step_over) (void);
113 	void (*step_into) (void);
114 	void (*step_out) (void);
115 	void (*execute_until)(const gchar *file, int line);
116 
117 	gboolean (*set_break) (breakpoint* bp, break_set_activity bsa);
118 	gboolean (*remove_break) (breakpoint* bp);
119 
120 	GList* (*get_stack) (void);
121 
122 	void (*set_active_frame)(int frame_number);
123 	int (*get_active_frame)(void);
124 
125 	gboolean (*set_active_thread)(int thread_id);
126 	int (*get_active_thread)(void);
127 
128 	GList* (*get_autos) (void);
129 	GList* (*get_watches) (void);
130 
131 	GList* (*get_files) (void);
132 
133 	GList* (*get_children) (gchar* path);
134 	variable* (*add_watch)(gchar* expression);
135 	void (*remove_watch)(gchar* path);
136 
137 	gchar* (*evaluate_expression)(gchar *expression);
138 
139 	gboolean (*request_interrupt) (void);
140 	gchar* (*error_message) (void);
141 	module_features features;
142 
143 } dbg_module;
144 
145 /* helping macroes to declare and define degub module */
146 #define DBG_MODULE_DECLARE(name) extern dbg_module dbg_module##name
147 #define DBG_MODULE_DEFINE(name) dbg_module dbg_module_##name = { \
148 	run, \
149 	restart, \
150 	stop, \
151 	resume, \
152 	step_over, \
153 	step_into, \
154 	step_out, \
155 	execute_until, \
156 	set_break, \
157 	remove_break, \
158 	get_stack, \
159 	set_active_frame, \
160 	get_active_frame, \
161 	set_active_thread, \
162 	get_active_thread, \
163 	get_autos, \
164 	get_watches, \
165 	get_files, \
166 	get_children, \
167 	add_watch, \
168 	remove_watch, \
169 	evaluate_expression, \
170 	request_interrupt, \
171 	error_message, \
172 	MODULE_FEATURES }
173 
174 void		variable_free(variable *var);
175 variable*	variable_new(const gchar *name, variable_type vt);
176 variable*	variable_new2(const gchar *name, const gchar *internal, variable_type vt);
177 void		variable_reset(variable *var);
178 
179 frame*		frame_new(void);
180 frame*		frame_ref(frame* f);
181 void		frame_unref(frame* f);
182 
183 #endif /* guard */
184