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

« back to all changes in this revision

Viewing changes to geanygdb/src/gdb-io-read.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-read.c - Output reading functions for GDB wrapper library.
 
4
 *
 
5
 * See the file "gdb-io.h" for license information.
 
6
 */
 
7
 
 
8
 
 
9
#include <stdlib.h>
 
10
#include <sys/time.h>
 
11
 
 
12
#include <string.h>
 
13
#include <unistd.h>
 
14
#include <stdarg.h>
 
15
#include <glib.h>
 
16
 
 
17
#include "gdb-io-priv.h"
 
18
#include "support.h"
 
19
 
 
20
 
 
21
 
 
22
static GSList *source_files = NULL;
 
23
 
 
24
static gboolean starting = FALSE;
 
25
 
 
26
 
 
27
 
 
28
static void
 
29
free_string_list(GSList ** list)
 
30
{
 
31
        GSList *p;
 
32
        for (p = *list; p; p = p->next)
 
33
        {
 
34
                if (p->data)
 
35
                {
 
36
                        g_free(p->data);
 
37
                }
 
38
        }
 
39
        *list = NULL;
 
40
}
 
41
 
 
42
 
 
43
static void
 
44
free_source_list()
 
45
{
 
46
        free_string_list(&source_files);
 
47
}
 
48
 
 
49
 
 
50
 
 
51
static gint
 
52
find_file_and_fullname(gconstpointer data, gconstpointer user_data)
 
53
{
 
54
        GdbLxValue *v = (GdbLxValue *) data;
 
55
        gchar *ref = (gchar *) user_data;
 
56
        HSTR(v->hash, fullname);
 
57
        HSTR(v->hash, file);
 
58
        return (fullname && file
 
59
                && (g_str_equal(ref, file) || g_str_equal(ref, fullname))) ? 0 : -1;
 
60
}
 
61
 
 
62
 
 
63
 
 
64
static void
 
65
parse_file_list_cb(gpointer data, gpointer user_data)
 
66
{
 
67
        GdbLxValue *v = (GdbLxValue *) data;
 
68
        if (v && (v->type == vt_HASH))
 
69
        {
 
70
                HSTR(v->hash, fullname);
 
71
                HSTR(v->hash, file);
 
72
                if (file && !fullname)
 
73
                {
 
74
                        if (g_slist_find_custom((GSList *) user_data, file, find_file_and_fullname))
 
75
                        {
 
76
                                return;
 
77
                        }
 
78
                }
 
79
                if (fullname)
 
80
                {
 
81
                        file = fullname;
 
82
                }
 
83
                if (file)
 
84
                {
 
85
                        if (!g_slist_find_custom(source_files, file, (GCompareFunc) strcmp))
 
86
                        {
 
87
                                source_files = g_slist_append(source_files, g_strdup(file));
 
88
                        }
 
89
                }
 
90
        }
 
91
}
 
92
 
 
93
 
 
94
 
 
95
static void handle_response_line(gchar * str, gchar ** list);
 
96
 
 
97
 
 
98
static void
 
99
handle_response_lines(gchar ** list)
 
100
{
 
101
        if (list)
 
102
        {
 
103
                gint i;
 
104
                for (i = 0; list[i]; i++)
 
105
                {
 
106
                        handle_response_line(list[i], list);
 
107
                }
 
108
        }
 
109
}
 
110
 
 
111
 
 
112
 
 
113
static gboolean
 
114
response_is_error(gchar * resp, gchar ** list)
 
115
{
 
116
        if (strncmp(resp, "^error", 6) == 0)
 
117
        {
 
118
                handle_response_line(resp, list);
 
119
                return TRUE;
 
120
        }
 
121
        else
 
122
        {
 
123
                return FALSE;
 
124
        }
 
125
}
 
126
 
 
127
#define CHK_RESP_ERR(resp, list) if (response_is_error(resp,list)) { return; }
 
128
 
 
129
#define IsDigit g_ascii_isdigit
 
130
 
 
131
static void
 
132
parse_process_info(gint seq, gchar ** list, gchar * resp)
 
133
{
 
134
        CHK_RESP_ERR(resp, list);
 
135
        gdbio_pop_seq(seq);
 
136
        if (g_str_equal(resp, "^done"))
 
137
        {
 
138
                gchar *pidstr = strchr(list[0], ' ');
 
139
                if (pidstr)
 
140
                {
 
141
                        GPid pid = -1;
 
142
                        while (g_ascii_isspace(*pidstr))
 
143
                        {
 
144
                                pidstr++;
 
145
                        }
 
146
                        if (IsDigit(*pidstr))
 
147
                        {
 
148
                                gchar *end = pidstr;
 
149
                                while (IsDigit(*end))
 
150
                                {
 
151
                                        end++;
 
152
                                }
 
153
                                *end = '\0';
 
154
                                pid = gdbio_atoi(pidstr);
 
155
                                if ((pid > 0) && (!gdbio_get_target_pid()))
 
156
                                {
 
157
                                        gdbio_set_target_pid(pid);
 
158
                                        gdbio_send_cmd("-exec-continue\n");
 
159
                                }
 
160
                        }
 
161
                }
 
162
        }
 
163
}
 
164
 
 
165
 
 
166
GHashTable *
 
167
gdbio_get_results(gchar * resp, gchar ** list)
 
168
{
 
169
        if (strncmp(resp, "^error", 6) == 0)
 
170
        {
 
171
                if (resp[6] == ',')
 
172
                {
 
173
                        GHashTable *h = gdblx_parse_results(resp + 7);
 
174
                        HSTR(h, msg);
 
175
                        gchar *tmp = NULL;
 
176
                        if (msg)
 
177
                        {
 
178
                                if (g_str_equal(msg, "unknown error"))
 
179
                                {
 
180
                                        gint len = g_strv_length(list);
 
181
                                        if ((len > 1) && list[len - 2] && *list[len - 2])
 
182
                                        {
 
183
                                                tmp = list[len - 2];
 
184
                                                if (tmp[0] == '&')
 
185
                                                {
 
186
                                                        tmp++;
 
187
                                                }
 
188
                                                tmp = g_strcompress(tmp);
 
189
                                                g_strstrip(tmp);
 
190
                                                msg = tmp;
 
191
                                        }
 
192
                                }
 
193
                                gdbio_error_func(msg);
 
194
                                if (tmp)
 
195
                                {
 
196
                                        g_free(tmp);
 
197
                                }
 
198
                        }
 
199
                        if (h)
 
200
                        {
 
201
                                g_hash_table_destroy(h);
 
202
                        }
 
203
                }
 
204
                return NULL;
 
205
        }
 
206
        if (strncmp(resp, "^done,", 6) == 0)
 
207
                return gdblx_parse_results(resp + 6);
 
208
        if (strncmp(resp, "*stopped,", 9) == 0)
 
209
        {
 
210
                gdbio_do_status(GdbStopped);
 
211
                return gdblx_parse_results(resp + 9);
 
212
        }
 
213
        return NULL;
 
214
}
 
215
 
 
216
 
 
217
 
 
218
static void handle_response_line(gchar * str, gchar ** list);
 
219
 
 
220
 
 
221
void
 
222
gdbio_set_starting(gboolean s)
 
223
{
 
224
        starting = s;
 
225
}
 
226
 
 
227
void
 
228
gdbio_target_started(gint seq, gchar ** list, gchar * resp)
 
229
{
 
230
        if ((strncmp(resp, "^error", 6) == 0) && (!gdbio_get_target_pid()))
 
231
        {
 
232
                gdbio_error_func(_("Error starting target process!\n"));
 
233
                gdbio_do_status(GdbFinished);
 
234
        }
 
235
        else
 
236
        {
 
237
                handle_response_lines(list);
 
238
        }
 
239
}
 
240
 
 
241
 
 
242
 
 
243
static void
 
244
set_main_break(gint seq, gchar ** list, gchar * resp)
 
245
{
 
246
        GHashTable *h = gdbio_get_results(resp, list);
 
247
        HTAB(h, bkpt);
 
248
        gdbio_pop_seq(seq);
 
249
        if (bkpt)
 
250
        {
 
251
                if (gdblx_check_keyval(bkpt, "number", "1"))
 
252
                {
 
253
                        gdbio_do_status(GdbLoaded);
 
254
                }
 
255
        }
 
256
        if (h)
 
257
                g_hash_table_destroy(h);
 
258
}
 
259
 
 
260
 
 
261
void
 
262
gdbio_parse_file_list(gint seq, gchar ** list, gchar * resp)
 
263
{
 
264
        GHashTable *h = gdbio_get_results(resp, list);
 
265
        HLST(h, files);
 
266
        gdbio_pop_seq(seq);
 
267
        if (files)
 
268
        {
 
269
                free_source_list();
 
270
                g_slist_foreach(files, parse_file_list_cb, files);
 
271
                free_source_list();
 
272
                gdbio_send_seq_cmd(set_main_break, "-break-insert _start\n");
 
273
        }
 
274
        else
 
275
        {
 
276
                gdbio_error_func
 
277
                        (_("This executable does not appear to contain the required debugging information."));
 
278
        }
 
279
        if (h)
 
280
                g_hash_table_destroy(h);
 
281
}
 
282
 
 
283
 
 
284
 
 
285
 
 
286
 
 
287
static gboolean
 
288
do_step_func(GHashTable * h, gchar * reason)
 
289
{
 
290
        HTAB(h, frame);
 
291
        HSTR(frame, fullname);
 
292
        HSTR(frame, line);
 
293
        if (fullname && line)
 
294
        {
 
295
                if (gdbio_setup.step_func)
 
296
                {
 
297
                        gchar *p;
 
298
                        for (p = reason; *p; p++)
 
299
                        {
 
300
                                if (*p == '-')
 
301
                                {
 
302
                                        *p = ' ';
 
303
                                }
 
304
                        }
 
305
                        gdbio_setup.step_func(fullname, line, reason);
 
306
                }
 
307
                else
 
308
                {
 
309
                        gdbio_info_func("%s:%s", fullname, line);
 
310
                }
 
311
                return TRUE;
 
312
        }
 
313
        else
 
314
        {
 
315
                HSTR(frame, func);
 
316
                if (func)
 
317
                {
 
318
                        return TRUE;
 
319
                }
 
320
        }
 
321
        return FALSE;
 
322
}
 
323
 
 
324
 
 
325
 
 
326
#define reason_is(r) (r && reason && g_str_equal(reason, r))
 
327
 
 
328
static void
 
329
finish_function(gint seq, gchar ** list, gchar * resp)
 
330
{
 
331
        if (strncmp(resp, "^running", 8) == 0)
 
332
        {
 
333
                gdbio_set_running(TRUE);
 
334
                gdbio_do_status(GdbRunning);
 
335
        }
 
336
        else
 
337
        {
 
338
                GHashTable *h = gdbio_get_results(resp, list);
 
339
                HSTR(h, reason);
 
340
                gdbio_pop_seq(seq);
 
341
                if (reason_is("function-finished"))
 
342
                {
 
343
                        gdbio_do_status(GdbStopped);
 
344
                        do_step_func(h, reason);
 
345
                }
 
346
                else
 
347
                {
 
348
                        handle_response_lines(list);
 
349
                }
 
350
                if (h)
 
351
                        g_hash_table_destroy(h);
 
352
        }
 
353
}
 
354
 
 
355
 
 
356
static void
 
357
return_function(gint seq, gchar ** list, gchar * resp)
 
358
{
 
359
        GHashTable *h = gdbio_get_results(resp, list);
 
360
        gdbio_pop_seq(seq);
 
361
        if (h)
 
362
        {
 
363
                do_step_func(h, "returned");
 
364
        }
 
365
        else
 
366
        {
 
367
                handle_response_lines(list);
 
368
        }
 
369
}
 
370
 
 
371
 
 
372
 
 
373
 
 
374
static void
 
375
watchpoint_trigger(GHashTable * h, GHashTable * wp, gchar * reason)
 
376
{
 
377
        HTAB(h, value);
 
378
        HSTR(wp, exp);
 
379
        HSTR(wp, number);
 
380
        HSTR(value, new);
 
381
        HSTR(value, old);
 
382
        gchar *readval = gdblx_lookup_string(value, "value");
 
383
        if (new && old)
 
384
        {
 
385
                gdbio_info_func("%s #%s  expression:%s  old-value:%s  new-value:%s\n",
 
386
                                reason, number ? number : "?", exp ? exp : "?", old, new);
 
387
        }
 
388
        else
 
389
        {
 
390
                if (old)
 
391
                {
 
392
                        gdbio_info_func("%s #%s  expression:%s  value:%s", reason,
 
393
                                        number ? number : "?", exp ? exp : "?", old);
 
394
                }
 
395
                else
 
396
                {
 
397
                        if (new)
 
398
                        {
 
399
                                gdbio_info_func("%s #%s  expression:%s  value:%s", reason,
 
400
                                                number ? number : "?", exp ? exp : "?", new);
 
401
                        }
 
402
                        else
 
403
                        {
 
404
                                if (readval)
 
405
                                {
 
406
                                        gdbio_info_func("%s #%s  expression:%s  value:%s", reason,
 
407
                                                        number ? number : "?", exp ? exp : "?",
 
408
                                                        readval);
 
409
                                }
 
410
                                else
 
411
                                {
 
412
                                        gdbio_info_func("%s #%s  expression:%s", reason,
 
413
                                                        number ? number : "?", exp ? exp : "?");
 
414
                                }
 
415
                        }
 
416
                }
 
417
        }
 
418
}
 
419
 
 
420
static gboolean
 
421
handle_results_hash(GHashTable * h, gchar * rectype, gchar ** list)
 
422
{
 
423
        if (g_str_equal(rectype, "^error"))
 
424
        {
 
425
                HSTR(h, msg);
 
426
                gchar *tmp = NULL;
 
427
                if (msg)
 
428
                {
 
429
                        if (g_str_equal(msg, "unknown error"))
 
430
                        {
 
431
                                gint len = g_strv_length(list);
 
432
                                if ((len > 1) && list[len - 2] && *list[len - 2])
 
433
                                {
 
434
                                        tmp = list[len - 2];
 
435
                                        if (tmp[0] == '&')
 
436
                                        {
 
437
                                                tmp++;
 
438
                                        }
 
439
                                        tmp = g_strcompress(tmp);
 
440
                                        g_strstrip(tmp);
 
441
                                        msg = tmp;
 
442
                                }
 
443
                        }
 
444
                        gdbio_error_func(msg);
 
445
                        if (tmp)
 
446
                        {
 
447
                                g_free(tmp);
 
448
                        }
 
449
                        return TRUE;
 
450
                }
 
451
                else
 
452
                        return FALSE;
 
453
        }
 
454
        if (g_str_equal(rectype, "^done"))
 
455
        {
 
456
 
 
457
                HTAB(h, frame);
 
458
                if (frame)
 
459
                {
 
460
                        HSTR(frame, fullname);
 
461
                        HSTR(frame, line);
 
462
                        if (fullname && line)
 
463
                        {
 
464
                                return do_step_func(h, "done");
 
465
                        }
 
466
                }
 
467
                return FALSE;
 
468
        }
 
469
        if (g_str_equal(rectype, "*stopped"))
 
470
        {
 
471
                HSTR(h, reason);
 
472
                if (!reason)
 
473
                {
 
474
                        return FALSE;
 
475
                }
 
476
                if (reason_is("breakpoint-hit"))
 
477
                {
 
478
                        if (gdblx_check_keyval(h, "bkptno", "1"))
 
479
                        {
 
480
                                gdbio_send_seq_cmd(parse_process_info,
 
481
                                                   "-interpreter-exec console \"info proc\"\n");
 
482
                                return TRUE;
 
483
                        }
 
484
                        else
 
485
                        {
 
486
                                return (do_step_func(h, reason));
 
487
                        }
 
488
                        return FALSE;
 
489
                }
 
490
                gdbio_set_running(FALSE);
 
491
                if (reason_is("signal-received"))
 
492
                {
 
493
                        HSTR(h, signal_name);
 
494
                        HSTR(h, signal_meaning);
 
495
                        HSTR(h, thread_id);
 
496
                        HTAB(h, frame);
 
497
                        HSTR(frame, func);
 
498
                        HSTR(frame, file);
 
499
                        HSTR(frame, fullname);
 
500
                        HSTR(frame, line);
 
501
                        HSTR(frame, addr);
 
502
                        HSTR(frame, from);
 
503
                        HLST(frame, args);
 
504
                        if (!fullname)
 
505
                        {
 
506
                                fullname = "??";
 
507
                        }
 
508
                        if (!file)
 
509
                        {
 
510
                                file = "??";
 
511
                        }
 
512
                        if (!line)
 
513
                        {
 
514
                                line = "??";
 
515
                        }
 
516
                        if (!args)
 
517
                        {
 
518
                                args = NULL;
 
519
                        }
 
520
                        if (signal_name && signal_meaning && thread_id && frame &&
 
521
                            addr && func && file && fullname)
 
522
                        {
 
523
                                if (gdbio_setup.signal_func)
 
524
                                {
 
525
                                        GdbSignalInfo si;
 
526
                                        si.signal_name = signal_name;
 
527
                                        si.signal_meaning = signal_meaning;
 
528
                                        si.addr = addr;
 
529
                                        si.func = func;
 
530
                                        si.file = file;
 
531
                                        si.fullname = fullname;
 
532
                                        si.line = line;
 
533
                                        si.from = from;
 
534
                                        gdbio_setup.signal_func(&si);
 
535
                                }
 
536
                                else
 
537
                                {
 
538
                                        gdbio_info_func
 
539
                                                (_("Program received signal %s (%s) at %s in function %s() at %s:%s"),
 
540
                                                 signal_name, signal_meaning, addr, func, file,
 
541
                                                 line);
 
542
                                }
 
543
                                return TRUE;
 
544
                        }
 
545
                }
 
546
 
 
547
 
 
548
                if (reason_is("end-stepping-range"))
 
549
                {
 
550
                        return do_step_func(h, reason);
 
551
                }
 
552
                if (reason_is("function-finished"))
 
553
                {
 
554
                        return do_step_func(h, reason);
 
555
                }
 
556
                if (reason_is("location-reached"))
 
557
                {
 
558
                        return do_step_func(h, reason);
 
559
                }
 
560
                if (reason_is("watchpoint-trigger"))
 
561
                {
 
562
                        HTAB(h, wpt);
 
563
                        if (wpt)
 
564
                        {
 
565
                                watchpoint_trigger(h, wpt, reason);
 
566
                        }
 
567
                        return do_step_func(h, reason);
 
568
                }
 
569
                if (reason_is("access-watchpoint-trigger"))
 
570
                {
 
571
                        HTAB(h, hw_awpt);
 
572
                        if (hw_awpt)
 
573
                        {
 
574
                                watchpoint_trigger(h, hw_awpt, reason);
 
575
                        }
 
576
                        return do_step_func(h, reason);
 
577
                }
 
578
                if (reason_is("read-watchpoint-trigger"))
 
579
                {
 
580
                        HTAB(h, hw_rwpt);
 
581
                        if (hw_rwpt)
 
582
                        {
 
583
                                watchpoint_trigger(h, hw_rwpt, reason);
 
584
                        }
 
585
                        return do_step_func(h, reason);
 
586
                }
 
587
                if (reason_is("watchpoint-scope"))
 
588
                {
 
589
                        HSTR(h, wpnum);
 
590
                        gdbio_info_func(_("Watchpoint #%s out of scope"), wpnum ? wpnum : "?");
 
591
                        gdbio_send_cmd("-exec-continue\n");
 
592
                        return do_step_func(h, reason);
 
593
                }
 
594
 
 
595
                if (reason_is("exited-signalled"))
 
596
                {
 
597
                        HSTR(h, signal_name);
 
598
                        HSTR(h, signal_meaning);
 
599
                        gdbio_info_func(_("Program exited on signal %s (%s).\n"),
 
600
                                        signal_name ? signal_name : "UNKNOWN",
 
601
                                        signal_meaning ? signal_meaning : _("Unknown signal"));
 
602
                        gdbio_target_exited(signal_name);
 
603
                        return TRUE;
 
604
                }
 
605
                if (reason_is("exited"))
 
606
                {
 
607
                        HSTR(h, exit_code);
 
608
                        gchar *tail = NULL;
 
609
                        gint ec = -1;
 
610
                        if (exit_code)
 
611
                        {
 
612
                                ec = strtoull(exit_code, &tail, 8);
 
613
                                if ((!tail) || (*tail))
 
614
                                {
 
615
                                        ec = -1;
 
616
                                }
 
617
                        }
 
618
                        gdbio_info_func(_("Program exited with code %d [%s]\n"), ec,
 
619
                                        exit_code ? exit_code : _("(unknown)"));
 
620
                        gdbio_target_exited(exit_code);
 
621
                        return TRUE;
 
622
                }
 
623
                if (g_str_equal(reason, "exited-normally"))
 
624
                {
 
625
                        gdbio_info_func(_("Program exited normally.\n"));
 
626
                        gdbio_target_exited("0");
 
627
                        return TRUE;
 
628
                }
 
629
        }
 
630
        return FALSE;
 
631
}
 
632
 
 
633
 
 
634
 
 
635
static void
 
636
handle_response_line(gchar * str, gchar ** list)
 
637
{
 
638
        gchar *rv = str;
 
639
        if (!rv)
 
640
        {
 
641
                return;
 
642
        }
 
643
        switch (rv[0])
 
644
        {
 
645
                case '~':
 
646
                case '@':
 
647
                case '&':
 
648
                        {
 
649
                                rv++;
 
650
                                if (rv[0] == '"')
 
651
                                {
 
652
                                        gint len = strlen(rv);
 
653
                                        memmove(rv, rv + 1, len);
 
654
                                        if (rv[len - 2] == '"')
 
655
                                        {
 
656
                                                rv[len - 2] = '\0';
 
657
                                        }
 
658
                                }
 
659
                                rv = g_strcompress(rv);
 
660
                                gdbio_info_func(rv);
 
661
                                g_free(rv);
 
662
                                break;
 
663
                        }
 
664
                case '^':
 
665
                case '*':
 
666
                        {
 
667
                                gchar *comma = strchr(rv, ',');
 
668
                                if (comma)
 
669
                                {
 
670
                                        GHashTable *h = gdblx_parse_results(comma + 1);
 
671
                                        *comma = '\0';
 
672
                                        if (g_str_equal(rv, "*stopped"))
 
673
                                        {
 
674
                                                gdbio_do_status(GdbStopped);
 
675
                                        }
 
676
                                        if (!handle_results_hash(h, rv, list))
 
677
                                        {
 
678
                                                gdblx_dump_table(h);
 
679
                                        }
 
680
                                        g_hash_table_destroy(h);
 
681
                                }
 
682
                                else
 
683
                                {
 
684
                                        if (g_str_equal(rv, "^running"))
 
685
                                        {
 
686
                                                if (starting)
 
687
                                                {
 
688
                                                        starting = FALSE;
 
689
                                                }
 
690
                                                else
 
691
                                                {
 
692
                                                        gdbio_do_status(GdbRunning);
 
693
                                                }
 
694
                                                gdbio_set_running(TRUE);
 
695
                                        }
 
696
                                }
 
697
                                break;
 
698
                        }
 
699
                default:
 
700
                        {
 
701
                                break;
 
702
                        }
 
703
        }
 
704
}
 
705
 
 
706
 
 
707
 
 
708
 
 
709
#define prompt "\n(gdb) \n"
 
710
#define prlen 8
 
711
 
 
712
 
 
713
#define starts_with_token(resp) \
 
714
  ( IsDigit(resp[0]) && IsDigit(resp[1]) && \
 
715
    IsDigit(resp[2]) && IsDigit(resp[3]) && \
 
716
    IsDigit(resp[4]) && IsDigit(resp[5]) && \
 
717
    strchr("^*=+", resp[6]) )
 
718
 
 
719
 
 
720
void
 
721
gdbio_consume_response(GString * recv_buf)
 
722
{
 
723
        gchar *eos = NULL;
 
724
        do
 
725
        {
 
726
                if (recv_buf->len)
 
727
                {
 
728
                        eos = strstr(recv_buf->str, prompt);
 
729
                }
 
730
                else
 
731
                {
 
732
                        eos = NULL;
 
733
                }
 
734
                if (eos)
 
735
                {
 
736
                        gint seq = -1;
 
737
                        gchar seqbuf[SEQ_LEN + 2];
 
738
                        ResponseHandler handler = NULL;
 
739
                        gchar **lines;
 
740
                        gint len;
 
741
                        *eos = '\0';
 
742
                        lines = g_strsplit(recv_buf->str, "\n", 0);
 
743
                        *eos = '\n';
 
744
                        len = g_strv_length(lines);
 
745
                        g_string_erase(recv_buf, 0, (eos - recv_buf->str) + 8);
 
746
                        if (len)
 
747
                        {
 
748
                                gchar *resp = lines[len - 1];
 
749
                                if (starts_with_token(resp))
 
750
                                {
 
751
                                        strncpy(seqbuf, resp, SEQ_LEN);
 
752
                                        seqbuf[SEQ_LEN] = '\0';
 
753
                                        seq = gdbio_atoi(seqbuf);
 
754
                                        if (seq >= 0)
 
755
                                        {
 
756
                                                handler = gdbio_seq_lookup(seq);
 
757
                                                if (handler)
 
758
                                                {
 
759
                                                        memmove(resp, resp + SEQ_LEN,
 
760
                                                                strlen(resp + SEQ_LEN) + 1);
 
761
                                                        g_strstrip(resp);
 
762
                                                        handler(seq, lines, resp);
 
763
                                                        g_strfreev(lines);
 
764
                                                        do_loop();
 
765
                                                        continue;
 
766
                                                }
 
767
                                                else
 
768
                                                {
 
769
                                                        g_printerr
 
770
                                                                ("***Error: Could not find handler for token #%s\n",
 
771
                                                                 seqbuf);
 
772
                                                }
 
773
                                        }
 
774
                                }
 
775
                        }
 
776
                        if (lines)
 
777
                        {
 
778
                                handle_response_lines(lines);
 
779
                                g_strfreev(lines);
 
780
                        }
 
781
                }
 
782
                do_loop();
 
783
        }
 
784
        while (eos);
 
785
}
 
786
 
 
787
 
 
788
 
 
789
 
 
790
 
 
791
void
 
792
gdbio_continue()
 
793
{
 
794
        gdbio_send_cmd("-exec-continue\n");
 
795
}
 
796
 
 
797
 
 
798
 
 
799
 
 
800
void
 
801
gdbio_return()
 
802
{
 
803
        gdbio_send_seq_cmd(return_function, "-exec-return\n");
 
804
}
 
805
 
 
806
 
 
807
void
 
808
gdbio_finish()
 
809
{
 
810
        gdbio_send_seq_cmd(finish_function, "-exec-finish\n");
 
811
}