-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwe_debug.c
2602 lines (2455 loc) · 58.4 KB
/
we_debug.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
/* we_debug.c */
/* Copyright (C) 1993 Fred Kruse */
/* This is free software; you can redistribute it and/or */
/* modify it under the terms of the */
/* GNU General Public License, see the file COPYING. */
#include "messages.h"
#include "edit.h"
#ifndef NO_XWINDOWS
#include "WeXterm.h"
#endif
#ifdef DEBUGGER
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#ifndef TERMCAP
/* Because term.h defines "buttons" it messes up we_gpm.c if in edit.h */
#include <term.h>
#endif
#define D_CBREAK -2
#define CTRLC CtrlC
#define SVLINES 12
int e_d_delbreak(FENSTER *f);
int e_d_error(char *s);
#define MAXOUT 2 * MAXSCOL * MAXSLNS
char *e_debugger, *e_deb_swtch = NULL, *e_d_save_schirm;
int e_d_swtch = 0, rfildes[2], ofildes, e_d_pid = 0;
int e_d_nbrpts = 0, e_d_zwtchs = 0, *e_d_ybrpts, *e_d_nrbrpts;
/* number of watch expressions in Watches window */
int e_d_nwtchs = 0;
/* e_d_nrwtchs[i] is the y coordinate (count starts at 0) of the first line of
the i-th watch in the Watches window */
int *e_d_nrwtchs;
char **e_d_swtchs; /* e_d_swtchs[i] is the i-th watch expression (a char*) */
int e_d_nstack;
char e_d_file[128], **e_d_sbrpts;
char *e_d_out = NULL;
int e_deb_type = 0, e_deb_mode = 0;
char e_d_out_str[SVLINES][256];
char *e_d_sp[SVLINES];
char e_d_tty[80];
extern int wfildes[2], efildes[2];
extern struct termios otermio, ntermio, ttermio;
extern struct e_s_prog e_sv_prog;
extern BUFFER *e_p_w_buffer;
extern char *att_no;
extern char *e_tmp_dir;
#ifdef NOTPARM
char *tparm();
char *tgoto();
#endif
#ifdef DEFTPUTS
int tputs();
#endif
char *npipe[5] = { NULL, NULL, NULL, NULL, NULL };
char *e_d_msg[] = { "Ctrl C pressed\nQuit Debugger ?",
"Quit Debugger ?",
"End of Debugging",
"Program is not running",
"No symbol in current context\n",
"No Source-Code", /* Number 5 */
"Start Debugger",
"Can\'t start Debugger",
"Starting program:",
"Can\'t start Program",
"Program exited", /* Number 10 */
"Program terminated",
"Program received signal",
"Unknown Break\nQuit Debugger ?",
"Can\'t find file %s",
"Can\'t create named pipe", /* Number 15 */
"Breakpoint",
"(sig ",
"program exited",
"signal",
"interrupt", /* Number 20 */
"stopped in",
"BREAKPOINT",
"Child process terminated normally",
"software termination",
"Continuing.\n", /* Number 25 */
"No stack.",
"no process"
};
extern char *e_p_msg[];
int e_deb_inp(FENSTER *f)
{
ECNT *cn = f->ed;
int c = 0;
f = cn->f[cn->mxedt];
c = e_getch();
switch(c)
{
case 'p':
case ('p' - 'a' + 1):
e_deb_out(f);
break;
case 'o':
case ('o' - 'a' + 1):
e_deb_options(f);
break;
case 'b':
case ('b' - 'a' + 1):
e_breakpoint(f);
break;
case 'm':
case ('m' - 'a' + 1):
e_remove_breakpoints(f);
break;
case 'a':
case 1:
e_remove_all_watches(f);
break;
case 'd':
case ('d' - 'a' + 1):
e_delete_watches(f);
break;
case 'w':
case ('w' - 'a' + 1):
e_make_watches(f);
break;
case 'e':
case ('e' - 'a' + 1):
e_edit_watches(f);
break;
case 'k':
case ('k' - 'a' + 1):
e_deb_stack(f);
break;
case 't':
case ('t' - 'a' + 1):
e_deb_trace(f);
break;
case 's':
case ('s' - 'a' + 1):
e_deb_next(f);
break;
case 'r':
case 'c':
case ('r' - 'a' + 1):
case ('c' - 'a' + 1):
e_deb_run(f);
break;
case 'q':
case ('q' - 'a' + 1):
e_d_quit(f);
break;
case 'u':
case ('u'-'a'+1):
e_d_goto_cursor(f);
break;
case 'f':
case ('f'-'a'+1):
e_d_finish_func(f);
break;
default:
return(c);
}
return(0);
}
int e_d_q_quit(FENSTER *f)
{
int ret = e_message(1, e_d_msg[ERR_QUITDEBUG], f);
if (ret == 'Y')
e_d_quit(f);
return(0);
}
int e_debug_switch(FENSTER *f, int c)
{
switch (c)
{
case F7:
e_deb_trace(f);
break;
case F8:
e_deb_next(f);
break;
case CF10:
e_deb_run(f);
break;
case CF2:
e_d_q_quit(f);
break;
default:
if (f->ed->edopt & ED_CUA_STYLE)
{
switch (c)
{
case F5:
e_breakpoint(f);
break;
case CF5:
e_make_watches(f);
break;
case CF3:
e_deb_stack(f);
break;
default:
return(c);
}
}
else
{
switch (c)
{
case CF8:
e_breakpoint(f);
break;
case CF7:
e_make_watches(f);
break;
case CF6:
e_deb_stack(f);
break;
default:
return(c);
}
}
}
return(0);
}
/* Input Routines */
int e_e_line_read(int n, signed char *s, int max)
{
int i, ret = 0;
for (i = 0; i < max - 1; i++)
{
ret = read(n, s + i, 1);
if (ret != 1 || s[i] == EOF || s[i] == '\n'|| s[i] == '\0')
break;
}
if (ret != 1 && i == 0)
return(-1);
s[i+1] = '\0';
if (e_deb_type == 1 && s[i] == '*')
return(1);
if (e_deb_type == 3 && s[i] == '>')
return(1);
else if (e_deb_type == 2 && i > 4 && s[i] == ' ' && !strncmp(s+i-5, "(dbx)", 5))
return(1);
else if (e_deb_type == 0 && i > 4 && s[i] == ' ' && !strncmp(s+i-5, "(gdb)", 5))
return(1);
return(2);
}
int e_d_line_read(int n, signed char *s, int max, int sw, int esw)
{
static char wt = 0, esc_sv = 0, str[12];
int i, j, ret = 0, kbdflgs;
if (esw)
{ if((ret = e_e_line_read(efildes[0], s, max)) >= 0) return(ret); }
else
{ while(e_e_line_read(efildes[0], s, max) >= 0); }
for(i = 0; i < max - 1; i++)
{
if (esc_sv) { s[i] = WPE_ESC; esc_sv = 0; continue; }
kbdflgs = fcntl(n, F_GETFL, 0 );
fcntl( n, F_SETFL, kbdflgs | O_NONBLOCK);
while ((ret = read(n, s + i, 1)) <= 0 && i == 0 && wt >= sw)
if(e_d_getchar() == D_CBREAK) return(-1);
/* Read until no chars are left anymore
Return if buffer not empty
return(-1) if CBREAK
*/
fcntl( n, F_SETFL, kbdflgs & ~O_NONBLOCK);
if (ret == -1) break;
else if (ret != 1 || s[i] == EOF || s[i] == '\0') break;
else if(s[i] == '\n' || s[i] == WPE_CR) break;
else if(s[i] == WPE_ESC)
{ s[i] = '\0'; esc_sv = 1; break; }
}
if (ret != 1)
{
s[i] = '\0';
if(e_deb_type == 1 && i > 0 && s[i-1] == '*')
{ str[0] = 0; wt = 0; return(1); }
else if(e_deb_type == 3 && i > 0 && s[i-1] == '>')
{ str[0] = 0; wt = 0; return(1); }
else if(e_deb_type == 0)
{
if(i > 5 && !strncmp(s+i-6, "(gdb) ", 6))
{ str[0] = 0; wt = 0; return(1); }
else if(i < 6)
{
for (j = 0; j <= i; j++) str[6+j] = s[j];
if (!strncmp(str+i-6, "(gdb) ", 6))
{ str[0] = '\0'; wt = 0; return(1); }
}
}
else if (e_deb_type == 2)
{
if(i > 5 && !strncmp(s+i-6, "(dbx) ", 6))
{ str[0] = 0; wt = 0; return(1); }
else if(i < 6)
{
for(j = 0; j <= i; j++) str[6+j] = s[j];
if(!strncmp(str+i-6, "(dbx) ", 6))
{ str[0] = '\0'; wt = 0; return(1); }
}
}
}
else { s[i+1] = '\0'; }
if (i != 0) wt = 0;
else wt++;
if(i > 4) for(j = 0; j < 6; j++) str[j] = s[j+i-5];
return(0);
}
int e_d_dum_read()
{
char str[256];
int ret;
while ((ret = e_d_line_read(wfildes[0], str, 128, 0, 0)) == 0 || ret == 2)
if (ret == 2)
e_d_error(str);
return(ret);
}
/* Output Routines */
int e_d_p_exec(FENSTER *f)
{
ECNT *cn = f->ed;
BUFFER *b;
SCHIRM *s;
int ret, i, is, j;
char str[512];
for (i = cn->mxedt; i > 0 && strcmp(cn->f[i]->datnam, "Messages"); i--)
;
if (i <= 0)
{ e_edit(cn, "Messages"); i = cn->mxedt; }
f = cn->f[i];
b = cn->f[i]->b;
s = cn->f[i]->s;
if (b->bf[b->mxlines-1].len != 0)
e_new_line(b->mxlines, b);
for (j = 0, i = is = b->mxlines-1;
(ret = e_d_line_read(wfildes[0], str, 512, 0, 0)) == 0; )
{
if (ret == -1)
return(ret);
print_to_end_of_buffer(b, str, b->mx.x);
}
if (ret == 1)
{
e_new_line(i, b);
for (j = 0; j < NUM_COLS_ON_SCREEN_SAFE - 2 && str[j] != '\n' &&
str[j] != '\0'; j++)
*(b->bf[i].s+j) = str[j];
b->b.y = i;
b->b.x = b->bf[i].len = j;
b->bf[i].nrc = j;
}
b->b.y = b->mxlines-1;
b->b.x = 0;
e_rep_win_tree(cn);
return(ret);
}
/* Help Routines */
int e_d_getchar()
{
int i = 1, fd;
char c = 0, kbdflgs = 0;
if (WpeIsXwin()) fd = rfildes[0];
else fd = 0;
/* if(WpeIsXwin() || e_deb_mode) */
{
kbdflgs = fcntl(fd, F_GETFL, 0 );
fcntl( fd, F_SETFL, kbdflgs | O_NONBLOCK);
}
#ifndef NO_XWINDOWS
if (WpeIsXwin())
c = (*e_u_change)(NULL);
#endif
if (c || (i = read(fd, &c, 1)) == 1)
{
if (c == CTRLC)
{
/* if (WpeIsXwin() || e_deb_mode) */
fcntl(fd, F_SETFL, kbdflgs & ~O_NONBLOCK);
e_d_switch_out(0);
i = e_message(1, e_d_msg[ERR_CTRLCPRESS], WpeEditor->f[WpeEditor->mxedt]);
if (i == 'Y')
{
e_d_quit(WpeEditor->f[WpeEditor->mxedt]);
return(D_CBREAK);
}
else
return(c);
}
else
write(rfildes[1], &c, 1);
}
/* if (WpeIsXwin() || e_deb_mode) */
fcntl(fd, F_SETFL, kbdflgs & ~O_NONBLOCK);
return(i == 1 ? c : 0);
}
int e_d_is_watch(int c, FENSTER *f)
{
if (strcmp(f->datnam, "Watches"))
return(0);
if(c == EINFG)
return(e_make_watches(f));
else if (c == ENTF)
return(e_delete_watches(f));
else
return(0);
}
int e_d_quit_basic(FENSTER *f)
{
int i, kbdflgs;
if (!e_d_swtch)
return 0;
if (rfildes[1] >= 0)
{
if (e_deb_type == 0 || e_deb_type == 3)
write(rfildes[1], "q\ny\n", 4);
else if (e_deb_type == 1)
write(rfildes[1], "q\n", 2);
else if (e_deb_type == 2)
write(rfildes[1], "quit\n", 5);
}
kbdflgs = fcntl(0, F_GETFL, 0 );
fcntl(0, F_SETFL, kbdflgs & ~O_NONBLOCK);
e_d_swtch = 0;
if (e_d_pid)
{
kill(e_d_pid, 9);
e_d_pid = 0;
}
if (!WpeIsXwin())
{
if (e_d_out)
FREE(e_d_out);
e_d_out = NULL;
}
if (rfildes[1] >= 0)
close(rfildes[1]);
if (wfildes[0] >= 0)
close(wfildes[0]);
if (efildes[0] >= 0)
close(efildes[0]);
if (rfildes[0] >= 0)
close(rfildes[0]);
if (wfildes[1] >= 0)
close(wfildes[1]);
if (WpeIsXwin())
{
remove(npipe[0]);
remove(npipe[1]);
remove(npipe[2]);
remove(npipe[3]);
remove(npipe[4]);
}
else
{
if (efildes[1] >= 0)
close(efildes[1]);
if (!e_deb_mode)
e_g_sys_end();
else
{
e_d_switch_out(1);
fk_locate(MAXSCOL, MAXSLNS);
e_putp("\r\n");
e_putp(att_no);
e_d_switch_out(0);
}
}
}
int e_d_quit(FENSTER *f)
{
ECNT *cn = f->ed;
int i;
e_d_quit_basic(f);
e_d_p_message(e_d_msg[ERR_ENDDEBUG], f, 1);
WpeMouseChangeShape(WpeEditingShape);
e_d_delbreak(f);
for (i = cn->mxedt; i > 0; i--)
if (!strcmp(cn->f[i]->datnam, "Messages"))
{
e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
break;
}
if (i <= 0)
e_edit(cn, "Messages");
return(0);
}
/* Watches */
int e_d_add_watch(char *str, FENSTER *f)
{
int ret;
ret = e_add_arguments(str, "Add Watch", f, 0, AltA, &f->ed->wdf);
if (ret != WPE_ESC)
{
f->ed->wdf = e_add_df(str, f->ed->wdf);
}
fk_cursor(1);
return(ret);
}
int e_remove_all_watches(FENSTER *f)
{
ECNT *cn = f->ed;
int i, n;
if (e_d_nwtchs < 1) return(0);
for (n = 0; n < e_d_nwtchs;n++) FREE(e_d_swtchs[n]);
FREE(e_d_swtchs);
FREE(e_d_nrwtchs);
e_d_nwtchs = 0;
for (i = cn->mxedt; i > 0; i--)
{
if (!strcmp(cn->f[i]->datnam, "Watches"))
{
e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
e_close_window(cn->f[cn->mxedt]);
break;
}
}
e_close_buffer(e_p_w_buffer);
e_p_w_buffer = NULL;
return(0);
}
int e_delete_watches(FENSTER *f)
{
ECNT *cn = f->ed;
BUFFER *b = cn->f[cn->mxedt]->b;
int n;
f = cn->f[cn->mxedt];
if (e_d_nwtchs < 1 || strcmp(f->datnam, "Watches"))
return(0);
for (n = 0; n < e_d_nwtchs && e_d_nrwtchs[n] <= b->b.y; n++)
;
FREE(e_d_swtchs[n - 1]);
for (; n < e_d_nwtchs; n++)
e_d_swtchs[n - 1] = e_d_swtchs[n];
e_d_nwtchs--;
e_d_swtchs = REALLOC(e_d_swtchs, e_d_nwtchs * sizeof(char *));
e_d_nrwtchs = REALLOC(e_d_nrwtchs, e_d_nwtchs * sizeof(int));
e_d_p_watches(f, 0);
return(0);
}
int e_make_watches(FENSTER *f)
{
char str[128];
int i, y;
if ((f->ed->mxedt > 0) && (strcmp(f->datnam, "Watches") == 0))
{ /* sets y=number of watch we're inserting */
for(y = 0; y < e_d_nwtchs && e_d_nrwtchs[y] < f->b->b.y; y++)
;
}
else
y = e_d_nwtchs;
if (f->ed->wdf && f->ed->wdf->anz > 0)
strcpy(str, f->ed->wdf->name[0]);
else
str[0] = '\0';
if (e_d_add_watch(str, f))
{
e_d_nwtchs++;
if (e_d_nwtchs == 1)
{
e_d_swtchs = MALLOC(sizeof(char *));
e_d_nrwtchs = MALLOC(sizeof(int));
}
else
{
e_d_swtchs = REALLOC(e_d_swtchs, e_d_nwtchs * sizeof(char *));
e_d_nrwtchs = REALLOC(e_d_nrwtchs, e_d_nwtchs * sizeof(int));
}
/*
move watch number y and following up one position so that we can insert
at position y
*/
for (i = e_d_nwtchs - 1; i > y; i--)
{
e_d_swtchs[i] = e_d_swtchs[i-1];
/* The following instruction is pointless as e_d_nrwtchs[i] is invalidated
by inserting the new watch and has to be recomputed by e_d_p_watches()
*/
e_d_nrwtchs[i] = e_d_nrwtchs[i-1];
}
e_d_swtchs[y] = MALLOC(strlen(str) + 1); /* insert... */
strcpy(e_d_swtchs[y], str); /* ... new watch at pos y */
e_d_p_watches(f, 1);
return(0);
}
return(-1);
}
int e_edit_watches(FENSTER *f)
{
BUFFER *b = f->ed->f[f->ed->mxedt]->b;
char str[128];
int l;
if (strcmp(f->datnam, "Watches"))
return(0);
for (l = 0; l < e_d_nwtchs && e_d_nrwtchs[l] <= b->b.y; l++)
;
if (l == e_d_nwtchs && b->bf[b->b.y].len == 0)
return(e_make_watches(f));
strcpy(str, e_d_swtchs[l - 1]);
if (e_d_add_watch(str, f))
{
e_d_swtchs[l - 1] = REALLOC(e_d_swtchs[l - 1], strlen(str) + 1);
strcpy(e_d_swtchs[l - 1], str);
e_d_p_watches(f, 0);
return(0);
}
return(-1);
}
/* Among other things, e_d_p_watches() must recompute e_d_nrwtchs when
called from e_edit_watches(),
but has code paths that don't do this ==> possible BUG
*/
int e_d_p_watches(FENSTER *f, int sw)
{
ECNT *cn = f->ed;
BUFFER *b;
SCHIRM *s;
int iw, i, k = 0, l, ret;
char str1[256], *str; /* is 256 always large enough? */
char *str2;
e_d_switch_out(0);
if ((e_d_swtch > 2) && (e_d_p_stack(f, 0) == -1))
return(-1);
/* Find the watch window */
for (iw = cn->mxedt; iw > 0 && strcmp(cn->f[iw]->datnam, "Watches"); iw--);
if (iw == 0 && !e_d_nwtchs)
{ /* if no watches and the mysterious iw!=0 then just repaint window tree */
e_rep_win_tree(cn);
return(0);
}
else if (iw == 0)
{
if(e_edit(cn, "Watches"))
{
return(-1);
}
else
{
iw = cn->mxedt;
}
}
f = cn->f[iw];
b = cn->f[iw]->b;
s = cn->f[iw]->s;
/* free all lines of BUFFER b */
e_p_red_buffer(b);
FREE(b->bf[0].s);
b->mxlines=0;
for (i = 0, l = 0; l < e_d_nwtchs; l++)
{
str = str1;
/* Create appropriate command for the debugger */
if (e_deb_type == 0 || e_deb_type == 3)
{
sprintf(str1, "p %s\n", e_d_swtchs[l]);
}
else if (e_deb_type == 1)
{
sprintf(str1, "%s/\n", e_d_swtchs[l]);
}
else if (e_deb_type == 2)
{
sprintf(str1, "print %s\n", e_d_swtchs[l]);
}
/* Send command to debugger */
if(e_d_swtch)
{
write(rfildes[1], str1, strlen(str1));
}
/* If no debugger or no response, give message of no symbol in context */
if (!e_d_swtch || (ret = e_d_line_read(wfildes[0], str1, 256, 0, 0)) == 1)
{
strcpy(str1, e_d_msg[ERR_NOSYMBOL]);
k = 0;
}
else /* Debugger successfully returned a value */
{
if (ret == -1)
{
return(ret); /* BUG? e_d_nrwtchs not initialized if this return is taken */
}
str = MALLOC(strlen(str1) + 1);
strcpy(str, str1);
while ((ret = e_d_line_read(wfildes[0], str1, 256, 0, 0)) == 0 || ret == 2)
{
if (ret == -1) return(ret); /* BUG? e_d_nrwtchs not initialized if this return is taken */
if (ret == 2) e_d_error(str1);
str = REALLOC(str, (k = strlen(str)) + strlen(str1) + 1);
if (str[k-1] == '\n') str[k-1] = ' ';
strcat(str, str1);
}
/* Find the beginning of the information (depends on debugger output
format) */
if (e_deb_type == 0 || e_deb_type == 2 || e_deb_type == 3)
{
if (e_deb_type == 3 && str[0] == '0')
{
for(k = 1; str[k] != '\0' && !isspace(str[k]); k++);
}
else
for(k = 0; str[k] != '\0' && str[k] != '='; k++);
if (str[k] == '\0')
{
if (str != str1) FREE(str);
str = str1;
strcpy(str, e_d_msg[ERR_NOSYMBOL]);
k = 0;
}
for(k++; str[k] != '\0' && isspace(str[k]); k++);
}
else if(e_deb_type == 1)
{
for (k = 0; str[k] != '\0' && str[k] != ':'; k++);
if (str[k] == '\0') k = 0;
else k++;
}
}
/* Print variable name */
for ( ; str[k] != '\0' && isspace(str[k]); k++);
str2 = WpeMalloc(strlen(e_d_swtchs[l]) + strlen(str + k) + 4);
sprintf(str2, "%s: %s", e_d_swtchs[l], str + k);
e_d_nrwtchs[l] = b->mxlines;
print_to_end_of_buffer(b, str2, b->mx.x);
/* Free any allocated string */
WpeFree(str2);
if(str != str1)
{
FREE(str);
}
}
e_new_line(b->mxlines, b);
fk_cursor(1);
/* if (b->b.y > i || sw) b->b.y = i;*/
if (sw && iw != cn->mxedt) e_switch_window(cn->edt[iw], cn->f[cn->mxedt]);
else e_rep_win_tree(cn);
/* e_d_switch_out(0); */
return(0);
}
int e_p_show_watches(FENSTER *f)
{
int i;
for (i = f->ed->mxedt; i > 0; i--)
if (!strcmp(f->ed->f[i]->datnam, "Watches"))
{
e_switch_window(f->ed->edt[i], f->ed->f[f->ed->mxedt]);
break;
}
if (i <= 0 && e_edit(f->ed, "Watches"))
{
return(-1);
}
return(0);
}
/***************************************/
/*** reinitialize watches from prj ***/
int e_d_reinit_watches(FENSTER * f,char * prj)
{
int i,e,g,q,y,r;
char * prj2;
for(i = f->ed->mxedt; i > 0; i--)
{
if (!strcmp(f->ed->f[i]->datnam, "Watches"))
{
e_remove_all_watches(f->ed->f[f->ed->edt[i]]);
break;
}
}
g=strlen(prj);
prj2=MALLOC(sizeof(char)*(g+1));
strcpy(prj2,prj);
q=0;
y=0;
r=0;
while(q<g)
{
e=q;
while(prj2[e]!=';' && e<g) e++;
prj2[e]='\0';
q=e+1;
r++;
}
e_d_nwtchs=r;
e_d_swtchs = (char **) MALLOC(e_d_nwtchs * sizeof(char *));
e_d_nrwtchs =(int *) MALLOC(e_d_nwtchs * sizeof(int));
for(e=0,q=0;e<r;e++)
{
e_d_swtchs[e] = MALLOC(strlen(prj2+q)+1);
strcpy(e_d_swtchs[e], prj2+q);
q+=strlen(prj2+q)+1;
}
FREE(prj2);
e_d_p_watches(f, 1);
return 0;
}
/***************************************/
/* stack */
int e_deb_stack(FENSTER *f)
{
e_d_switch_out(0);
return(e_d_p_stack(f, 1));
}
int e_d_p_stack(FENSTER *f, int sw)
{
ECNT *cn = f->ed;
BUFFER *b;
SCHIRM *s;
int is, i, j, k, l, ret;
char str[256];
if (e_d_swtch < 3)
return(e_error(e_d_msg[ERR_NOTRUNNING], 0, f->fb));
for (i = 0; i < SVLINES; i++)
e_d_out_str[i][0] = '\0';
for (is = cn->mxedt; is > 0 && strcmp(cn->f[is]->datnam, "Stack"); is--)
;
if (!sw && is == 0)
return(0);
if(is == 0)
{
if (e_edit(cn, "Stack"))
return(-1);
else
is = cn->mxedt;
}
f = cn->f[is];
b = cn->f[is]->b;
s = cn->f[is]->s;
if (!e_d_swtch)
return(0);
if (e_deb_type == 0)
write(rfildes[1], "bt\n", 3);
else if (e_deb_type == 1 || e_deb_type == 3)
write(rfildes[1], "t\n", 2);
else if (e_deb_type == 2)
write(rfildes[1], "where\n", 6);
while ((ret = e_d_line_read(wfildes[0], str, 256, 0, 0)) == 2)
e_d_error(str);
if (ret == -1)
return(-1);
i = j = 0;
if (ret == 1)
{
e_d_error(e_d_msg[ERR_PROGEXIT]);
return(e_d_quit(f));
}
while(ret != 1)
{
k = 0;
do
{
if (i >= b->mxlines)
e_new_line(i, b);
if ((i > 0 && j == 0 && *(b->bf[i-1].s+b->bf[i-1].len-1) == '\\') ||
(!e_deb_type && j == 0 && (k > 0 || str[k] != '#')))
{
for(j = 0; j < 3; j++)
b->bf[i].s[j] = ' ';
}
for(; isspace(str[k]); k++)
;
for(; j < NUM_COLS_ON_SCREEN_SAFE - 2 && str[k] != '\n' && str[k] != '\0';
j++, k++)
*(b->bf[i].s+j) = str[k];
if (str[k] != '\0')
{
if (str[k] != '\n')
{
for(l = j-1; l > 2 && !isspace(b->bf[i].s[l]) && b->bf[i].s[l] != '=';
l--)
;
if (l > 2)
{
k -= (j - l - 1);
for (l++; l < j; l++)
b->bf[i].s[l] = ' ';
}
*(b->bf[i].s+j) = '\\';
*(b->bf[i].s+j+1) = '\n';
*(b->bf[i].s+j+2) = '\0';
j++;
}
else
{
*(b->bf[i].s+j) = '\n';
*(b->bf[i].s+j+1) = '\0';
}
}
b->bf[i].len = j;
b->bf[i].nrc = j + 1;
if (j != 0 && str[k] != '\0')
{
i++;
j = 0;
}
else
j--;
}
while (str[k] != '\n' && str[k] != '\0');
while ((ret = e_d_line_read(wfildes[0], str, 256, 0, 0)) == 2)
e_d_error(str);
if (ret == -1)
return(-1);
}
for (; i < b->mxlines; i++)
e_del_line(i, b, s);
if (sw && is != cn->mxedt)
e_switch_window(cn->edt[is], cn->f[cn->mxedt]);
e_rep_win_tree(cn);
return(0);
}
int e_make_stack(FENSTER *f)
{
char file[128], str[128], *tmpstr = MALLOC(1);
int i, ret, line = 0, dif;
BUFFER *b = f->ed->f[f->ed->mxedt]->b;
e_d_switch_out(0);
if(e_deb_type != 1)
{ tmpstr[0] = '\0';
if(e_deb_type == 0)
{ for(i = dif = 0; i <= b->b.y; i++)
if(b->bf[i].s[0] == '#') dif = atoi((char *) (b->bf[i].s + 1));
for(i = b->b.y; i >= 0 && b->bf[i].s[0] != '#'; i--);
if(i < 0) return(1);
for(; i < b->mxlines; i++)
{ if(!(tmpstr = REALLOC(tmpstr, strlen(tmpstr) + b->bf[i].len + 2)))
{ e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
strcat(tmpstr, (char *) b->bf[i].s);
if(i == b->mxlines-1 || b->bf[i+1].s[0] == '#') break;
else if(tmpstr[strlen(tmpstr)-2] == '\\')
tmpstr[strlen(tmpstr)-2] = '\0';