~ubuntu-branches/debian/squeeze/geany-plugins/squeeze

« back to all changes in this revision

Viewing changes to geanygdb/src/gdb-io-break.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * gdb-io-break.c - Breakpoint management functions for GDB wrapper library.
 
4
 *
 
5
 * See the file "gdb-io.h" for license information.
 
6
 *
 
7
 */
 
8
 
 
9
 
 
10
#include <string.h>
 
11
#include <glib.h>
 
12
#include "gdb-io-priv.h"
 
13
#include "support.h"
 
14
 
 
15
 
 
16
static GdbListFunc gdbio_break_list_func = NULL;
 
17
 
 
18
static GSList *breakpoint_list = NULL;
 
19
 
 
20
 
 
21
static void
 
22
free_breakpoint_list()
 
23
{
 
24
        GSList *p;
 
25
        for (p = breakpoint_list; p; p = p->next)
 
26
        {
 
27
                GdbBreakPointInfo *bpi = p->data;
 
28
                if (bpi)
 
29
                {
 
30
                        g_free(bpi->addr);
 
31
                        g_free(bpi->disp);
 
32
                        g_free(bpi->enabled);
 
33
                        g_free(bpi->file);
 
34
                        g_free(bpi->fullname);
 
35
                        g_free(bpi->func);
 
36
                        g_free(bpi->line);
 
37
                        g_free(bpi->number);
 
38
                        g_free(bpi->times);
 
39
                        g_free(bpi->type);
 
40
                        g_free(bpi->what);
 
41
                        g_free(bpi->cond);
 
42
                        g_free(bpi->ignore);
 
43
                        g_free(bpi);
 
44
                }
 
45
        }
 
46
        g_slist_free(breakpoint_list);
 
47
        breakpoint_list = NULL;
 
48
}
 
49
 
 
50
 
 
51
 
 
52
#define populate(rec, hash, key) \
 
53
  rec->key=gdblx_lookup_string(hash, #key""); \
 
54
  if (rec->key) {rec->key=g_strdup(rec->key);}
 
55
 
 
56
 
 
57
 
 
58
static void
 
59
breakpoint_cb(gpointer data, gpointer user_data)
 
60
{
 
61
        GdbLxValue *v = (GdbLxValue *) data;
 
62
        if (v && (v->type == vt_HASH) && (v->hash))
 
63
        {
 
64
                GHashTable *bkpt = v->hash;
 
65
                if (bkpt)
 
66
                {
 
67
                        GdbBreakPointInfo *bpi = g_new0(GdbBreakPointInfo, 1);
 
68
                        populate(bpi, bkpt, addr);
 
69
                        populate(bpi, bkpt, disp);
 
70
                        populate(bpi, bkpt, enabled);
 
71
                        populate(bpi, bkpt, file);
 
72
                        populate(bpi, bkpt, fullname);
 
73
                        populate(bpi, bkpt, func);
 
74
                        populate(bpi, bkpt, line);
 
75
                        populate(bpi, bkpt, number);
 
76
                        populate(bpi, bkpt, times);
 
77
                        populate(bpi, bkpt, type);
 
78
                        populate(bpi, bkpt, what);
 
79
                        populate(bpi, bkpt, cond);
 
80
                        populate(bpi, bkpt, ignore);
 
81
                        breakpoint_list = g_slist_append(breakpoint_list, bpi);
 
82
                }
 
83
        }
 
84
}
 
85
 
 
86
 
 
87
static void
 
88
parse_break_list(gint seq, gchar ** list, gchar * resp)
 
89
{
 
90
        GHashTable *h = gdbio_get_results(resp, list);
 
91
        HTAB(h, BreakpointTable);
 
92
        gdbio_pop_seq(seq);
 
93
        if (BreakpointTable && gdbio_break_list_func)
 
94
        {
 
95
                HLST(BreakpointTable, body);
 
96
                if (body)
 
97
                {
 
98
                        free_breakpoint_list();
 
99
                        g_slist_foreach(body, breakpoint_cb, NULL);
 
100
                        gdbio_break_list_func(breakpoint_list);
 
101
                        free_breakpoint_list();
 
102
                }
 
103
                else
 
104
                {
 
105
                        gdbio_break_list_func(NULL);
 
106
                }
 
107
        }
 
108
        if (h)
 
109
                g_hash_table_destroy(h);
 
110
}
 
111
 
 
112
 
 
113
 
 
114
void
 
115
gdbio_show_breaks(GdbListFunc func)
 
116
{
 
117
        gdbio_break_list_func = func;
 
118
        if (func)
 
119
        {
 
120
                gdbio_send_seq_cmd(parse_break_list, "-break-list\n");
 
121
        }
 
122
}
 
123
 
 
124
 
 
125
 
 
126
static void
 
127
added_break(gint seq, gchar ** list, gchar * resp)
 
128
{
 
129
        GHashTable *h = gdbio_get_results(resp, list);
 
130
        gdbio_pop_seq(seq);
 
131
        if (h)
 
132
        {
 
133
                HTAB(h, bkpt);
 
134
                if (bkpt)
 
135
                {
 
136
                        HSTR(bkpt, file);
 
137
                        HSTR(bkpt, line);
 
138
                        HSTR(bkpt, func);
 
139
                        HSTR(bkpt, number);
 
140
                        if (func)
 
141
                        {
 
142
                                gdbio_info_func(_("Added breakpoint #%s in %s() at %s:%s\n"), number,
 
143
                                                func, file, line);
 
144
                        }
 
145
                        else
 
146
                        {
 
147
                                gdbio_info_func(_("Added breakpoint #%s at %s:%s\n"), number, file,
 
148
                                                line);
 
149
                        }
 
150
 
 
151
                }
 
152
                else
 
153
                {
 
154
                        HTAB(h, wpt);
 
155
                        if (wpt)
 
156
                        {
 
157
                                HSTR(wpt, exp);
 
158
                                HSTR(wpt, number);
 
159
                                gdbio_info_func(_("Added write watchpoint #%s for %s\n"), number, exp);
 
160
                        }
 
161
                        else
 
162
                        {
 
163
                                HTAB(h, hw_awpt);
 
164
                                if (hw_awpt)
 
165
                                {
 
166
                                        HSTR(hw_awpt, exp);
 
167
                                        HSTR(hw_awpt, number);
 
168
                                        gdbio_info_func(_("Added read/write watchpoint #%s for %s\n"),
 
169
                                                        number, exp);
 
170
                                }
 
171
                                else
 
172
                                {
 
173
                                        HTAB(h, hw_rwpt);
 
174
                                        if (hw_rwpt)
 
175
                                        {
 
176
                                                HSTR(hw_rwpt, exp);
 
177
                                                HSTR(hw_rwpt, number);
 
178
                                                gdbio_info_func
 
179
                                                        (_("Added read watchpoint #%s for %s\n"),
 
180
                                                         number, exp);
 
181
                                        }
 
182
                                }
 
183
                        }
 
184
                }
 
185
                g_hash_table_destroy(h);
 
186
        }
 
187
        if (gdbio_break_list_func)
 
188
        {
 
189
                gdbio_show_breaks(gdbio_break_list_func);
 
190
        }
 
191
}
 
192
 
 
193
/* opt is "-r" (read) or "-a" (r/w) or NULL or empty (write) */
 
194
void
 
195
gdbio_add_watch(GdbListFunc func, const gchar * option, const gchar * varname)
 
196
{
 
197
        gdbio_break_list_func = func;
 
198
        gdbio_send_seq_cmd(added_break, "-break-watch %s %s\n", option ? option : "", varname);
 
199
}
 
200
 
 
201
 
 
202
 
 
203
void
 
204
gdbio_add_break(GdbListFunc func, const gchar * filename, const gchar * locn)
 
205
{
 
206
        gdbio_break_list_func = func;
 
207
        if (filename && *filename)
 
208
        {
 
209
                gdbio_send_seq_cmd(added_break, "-break-insert %s:%s\n", filename, locn);
 
210
        }
 
211
        else
 
212
        {
 
213
                gdbio_send_seq_cmd(added_break, "-break-insert %s\n", locn);
 
214
        }
 
215
}
 
216
 
 
217
 
 
218
static void
 
219
deleted_break(gint seq, gchar ** list, gchar * resp)
 
220
{
 
221
        GHashTable *h = gdbio_get_results(resp, list);
 
222
        gdbio_pop_seq(seq);
 
223
        if (h)
 
224
        {
 
225
                g_hash_table_destroy(h);
 
226
                gdbio_info_func(_("Watch/breakpoint deleted.\n"));
 
227
        }
 
228
        if (gdbio_break_list_func)
 
229
        {
 
230
                gdbio_show_breaks(gdbio_break_list_func);
 
231
        }
 
232
}
 
233
 
 
234
 
 
235
 
 
236
static void
 
237
toggled_break(gint seq, gchar ** list, gchar * resp)
 
238
{
 
239
        gdbio_pop_seq(seq);
 
240
        if (strncmp(resp, "^error", 6) == 0)
 
241
        {
 
242
                if (resp[6] == ',')
 
243
                {
 
244
                        GHashTable *h = gdblx_parse_results(resp + 7);
 
245
                        HSTR(h, msg);
 
246
 
 
247
                        if (msg)
 
248
                        {
 
249
                                gchar *tmp =
 
250
                                        g_strconcat(_("Failed to toggle breakpoint -\n"), msg, NULL);
 
251
                                gdbio_error_func(tmp);
 
252
                                if (tmp)
 
253
                                {
 
254
                                        g_free(tmp);
 
255
                                }
 
256
                        }
 
257
                        else
 
258
                        {
 
259
                        }
 
260
                        if (h)
 
261
                        {
 
262
                                g_hash_table_destroy(h);
 
263
                        }
 
264
                }
 
265
        }
 
266
        else
 
267
        {
 
268
                gdbio_info_func(_("Watch/breakpoint toggled.\n"));
 
269
        }
 
270
}
 
271
 
 
272
 
 
273
 
 
274
static void
 
275
edited_break(gint seq, gchar ** list, gchar * resp)
 
276
{
 
277
        GHashTable *h = gdbio_get_results(resp, list);
 
278
        gdbio_pop_seq(seq);
 
279
        if (h)
 
280
        {
 
281
                g_hash_table_destroy(h);
 
282
                gdbio_info_func(_("Watch/breakpoint modified.\n"));
 
283
        }
 
284
}
 
285
 
 
286
 
 
287
void
 
288
gdbio_delete_break(GdbListFunc func, const gchar * number)
 
289
{
 
290
        gdbio_break_list_func = func;
 
291
        gdbio_send_seq_cmd(deleted_break, "-break-delete %s\n", number);
 
292
}
 
293
 
 
294
 
 
295
void
 
296
gdbio_enable_break(const gchar * number, gboolean enabled)
 
297
{
 
298
        gdbio_send_seq_cmd(toggled_break, "-break-%s %s\n", enabled ? "enable" : "disable", number);
 
299
}
 
300
 
 
301
 
 
302
void
 
303
gdbio_ignore_break(const gchar * number, const gchar * times)
 
304
{
 
305
        gdbio_send_seq_cmd(edited_break, "-break-after %s %s\n", number, times);
 
306
}
 
307
 
 
308
 
 
309
void
 
310
gdbio_break_cond(const gchar * number, const gchar * expr)
 
311
{
 
312
        gdbio_send_seq_cmd(edited_break, "-break-condition %s %s\n", number, expr);
 
313
}