-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dbg.c
1470 lines (1268 loc) · 33.4 KB
/
Dbg.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
/* Dbg.c - Tcl Debugger - See cmdHelp() for commands
Written by: Don Libes, NIST, 3/23/93
Design and implementation of this program was paid for by U.S. tax
dollars. Therefore it is public domain. However, the author and NIST
would appreciate credit if this program or parts of it are used.
*/
#include <stdio.h>
#ifndef HAVE_STRCHR
#define strchr(s,c) index(s,c)
#endif /* HAVE_STRCHR */
#if 0
/* tclInt.h drags in stdlib. By claiming no-stdlib, force it to drag in */
/* Tcl's compat version. This avoids having to test for its presence */
/* which is too tricky - configure can't generate two cf files, so when */
/* Expect (or any app) uses the debugger, there's no way to get the info */
/* about whether stdlib exists or not, except pointing the debugger at */
/* an app-dependent .h file and I don't want to do that. */
#define NO_STDLIB_H
#endif
#include "tclInt.h"
/*#include <varargs.h> tclInt.h drags in varargs.h. Since Pyramid */
/* objects to including varargs.h twice, just */
/* omit this one. */
/*#include "string.h" tclInt.h drags this in, too! */
#include "tcldbg.h"
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
static int simple_interactor (Tcl_Interp *interp, ClientData data);
static int zero (Tcl_Interp *interp, char *string);
/* most of the static variables in this file may be */
/* moved into Tcl_Interp */
static Dbg_InterProc *interactor = &simple_interactor;
static ClientData interdata = 0;
static Dbg_IgnoreFuncsProc *ignoreproc = &zero;
static Dbg_OutputProc *printproc = 0;
static ClientData printdata = 0;
static int stdinmode;
static void print _ANSI_ARGS_(TCL_VARARGS(Tcl_Interp *,interp));
static int debugger_active = FALSE;
/* this is not externally documented anywhere as of yet */
char *Dbg_VarName = "dbg";
#define DEFAULT_COMPRESS 0
static int compress = DEFAULT_COMPRESS;
#define DEFAULT_WIDTH 75 /* leave a little space for printing */
/* stack level */
static int buf_width = DEFAULT_WIDTH;
static int main_argc = 1;
static char *default_argv = "application";
static char **main_argv = &default_argv;
static Tcl_Trace debug_handle;
static int step_count = 1; /* count next/step */
#define FRAMENAMELEN 10 /* enough to hold strings like "#4" */
static char viewFrameName[FRAMENAMELEN];/* destination frame name for up/down */
static CallFrame *goalFramePtr; /* destination for next/return */
static int goalNumLevel; /* destination for Next */
static enum debug_cmd {
none, step, next, ret, cont, up, down, where, Next
} debug_cmd = step;
/* info about last action to use as a default */
static enum debug_cmd last_action_cmd = next;
static int last_step_count = 1;
/* this acts as a strobe (while testing breakpoints). It is set to true */
/* every time a new debugger command is issued that is an action */
static int debug_new_action;
#define NO_LINE -1 /* if break point is not set by line number */
struct breakpoint {
int id;
Tcl_Obj *file; /* file where breakpoint is */
int line; /* line where breakpoint is */
int re; /* 1 if this is regexp pattern */
Tcl_Obj *pat; /* pattern defining where breakpoint can be */
Tcl_Obj *expr; /* expr to trigger breakpoint */
Tcl_Obj *cmd; /* cmd to eval at breakpoint */
struct breakpoint *next, *previous;
};
static struct breakpoint *break_base = 0;
static int breakpoint_max_id = 0;
static struct breakpoint *
breakpoint_new()
{
struct breakpoint *b = (struct breakpoint *)ckalloc(sizeof(struct breakpoint));
if (break_base) break_base->previous = b;
b->next = break_base;
b->previous = 0;
b->id = breakpoint_max_id++;
b->file = 0;
b->line = NO_LINE;
b->pat = 0;
b->re = 0;
b->expr = 0;
b->cmd = 0;
break_base = b;
return(b);
}
static
void
breakpoint_print(interp,b)
Tcl_Interp *interp;
struct breakpoint *b;
{
print(interp,"breakpoint %d: ",b->id);
if (b->re) {
print(interp,"-re \"%s\" ",Tcl_GetString(b->pat));
} else if (b->pat) {
print(interp,"-glob \"%s\" ",Tcl_GetString(b->pat));
} else if (b->line != NO_LINE) {
if (b->file) {
print(interp,"%s:",Tcl_GetString(b->file));
}
print(interp,"%d ",b->line);
}
if (b->expr)
print(interp,"if {%s} ",Tcl_GetString(b->expr));
if (b->cmd)
print(interp,"then {%s}",Tcl_GetString(b->cmd));
print(interp,"\n");
}
static void
save_re_matches(interp, re, objPtr)
Tcl_Interp *interp;
Tcl_RegExp re;
Tcl_Obj *objPtr;
{
Tcl_RegExpInfo info;
int i, start;
char name[20];
Tcl_RegExpGetInfo(re, &info);
for (i=0;i<=info.nsubs;i++) {
start = info.matches[i].start;
/* end = info.matches[i].end-1;*/
if (start == -1) continue;
sprintf(name,"%d",i);
Tcl_SetVar2Ex(interp, Dbg_VarName, name, Tcl_GetRange(objPtr,
info.matches[i].start, info.matches[i].end-1), 0);
}
}
/* return 1 to break, 0 to continue */
static int
breakpoint_test(interp,cmd,bp)
Tcl_Interp *interp;
char *cmd; /* command about to be executed */
struct breakpoint *bp; /* breakpoint to test */
{
if (bp->re) {
int found = 0;
Tcl_Obj *cmdObj;
Tcl_RegExp re = Tcl_GetRegExpFromObj(NULL, bp->pat,
TCL_REG_ADVANCED);
cmdObj = Tcl_NewStringObj(cmd,-1);
Tcl_IncrRefCount(cmdObj);
if (Tcl_RegExpExecObj(NULL, re, cmdObj, 0 /* offset */,
-1 /* nmatches */, 0 /* eflags */) > 0) {
save_re_matches(interp, re, cmdObj);
found = 1;
}
Tcl_DecrRefCount(cmdObj);
if (!found) return 0;
} else if (bp->pat) {
if (0 == Tcl_StringMatch(cmd,
Tcl_GetString(bp->pat))) return 0;
} else if (bp->line != NO_LINE) {
/* not yet implemented - awaiting support from Tcl */
return 0;
}
if (bp->expr) {
int value;
/* ignore errors, since they are likely due to */
/* simply being out of scope a lot */
if (TCL_OK != Tcl_ExprBooleanObj(interp,bp->expr,&value)
|| (value == 0)) return 0;
}
if (bp->cmd) {
Tcl_EvalObjEx(interp, bp->cmd, 0);
} else {
breakpoint_print(interp,bp);
}
return 1;
}
static char *already_at_top_level = "already at top level";
/* similar to TclGetFrame but takes two frame ptrs and a direction.
If direction is up, search up stack from curFrame
If direction is down, simulate searching down stack by
seaching up stack from origFrame
*/
static
int
TclGetFrame2(interp, origFramePtr, string, framePtrPtr, dir)
Tcl_Interp *interp;
CallFrame *origFramePtr; /* frame that is true top-of-stack */
char *string; /* String describing frame. */
CallFrame **framePtrPtr; /* Store pointer to frame here (or NULL
* if global frame indicated). */
enum debug_cmd dir; /* look up or down the stack */
{
Interp *iPtr = (Interp *) interp;
int level, result;
CallFrame *framePtr; /* frame currently being searched */
CallFrame *curFramePtr = iPtr->varFramePtr;
/*
* Parse string to figure out which level number to go to.
*/
result = 1;
if (*string == '#') {
if (Tcl_GetInt(interp, string+1, &level) != TCL_OK) {
return TCL_ERROR;
}
if (level < 0) {
levelError:
Tcl_AppendResult(interp, "bad level \"", string, "\"",
(char *) NULL);
return TCL_ERROR;
}
framePtr = origFramePtr; /* start search here */
} else if (isdigit(*string)) {
if (Tcl_GetInt(interp, string, &level) != TCL_OK) {
return TCL_ERROR;
}
if (dir == up) {
if (curFramePtr == 0) {
Tcl_SetResult(interp,already_at_top_level,TCL_STATIC);
return TCL_ERROR;
}
level = curFramePtr->level - level;
framePtr = curFramePtr; /* start search here */
} else {
if (curFramePtr != 0) {
level = curFramePtr->level + level;
}
framePtr = origFramePtr; /* start search here */
}
} else {
level = curFramePtr->level - 1;
result = 0;
}
/*
* Figure out which frame to use.
*/
if (level == 0) {
framePtr = NULL;
} else {
for (;framePtr != NULL; framePtr = framePtr->callerVarPtr) {
if (framePtr->level == level) {
break;
}
}
if (framePtr == NULL) {
goto levelError;
}
}
*framePtrPtr = framePtr;
return result;
}
static char *printify(s)
char *s;
{
static int destlen = 0;
char *d; /* ptr into dest */
unsigned int need;
static char buf_basic[DEFAULT_WIDTH+1];
static char *dest = buf_basic;
Tcl_UniChar ch;
if (s == 0) return("<null>");
/* worst case is every character takes 4 to printify */
need = strlen(s)*6;
if (need > destlen) {
if (dest && (dest != buf_basic)) ckfree(dest);
dest = (char *)ckalloc(need+1);
destlen = need;
}
for (d = dest;*s;) {
s += Tcl_UtfToUniChar(s, &ch);
if (ch == '\b') {
strcpy(d,"\\b"); d += 2;
} else if (ch == '\f') {
strcpy(d,"\\f"); d += 2;
} else if (ch == '\v') {
strcpy(d,"\\v"); d += 2;
} else if (ch == '\r') {
strcpy(d,"\\r"); d += 2;
} else if (ch == '\n') {
strcpy(d,"\\n"); d += 2;
} else if (ch == '\t') {
strcpy(d,"\\t"); d += 2;
} else if ((unsigned)ch < 0x20) { /* unsigned strips parity */
sprintf(d,"\\%03o",ch); d += 4;
} else if (ch == 0177) {
strcpy(d,"\\177"); d += 4;
} else if ((ch < 0x80) && isprint(UCHAR(ch))) {
*d = (char)ch; d += 1;
} else {
sprintf(d,"\\u%04x",ch); d += 6;
}
}
*d = '\0';
return(dest);
}
static
char *
print_argv(interp,argc,argv)
Tcl_Interp *interp;
int argc;
char *argv[];
{
static int buf_width_max = DEFAULT_WIDTH;
static char buf_basic[DEFAULT_WIDTH+1]; /* basic buffer */
static char *buf = buf_basic;
int space; /* space remaining in buf */
int len;
char *bufp;
int proc; /* if current command is "proc" */
int arg_index;
if (buf_width > buf_width_max) {
if (buf && (buf != buf_basic)) ckfree(buf);
buf = (char *)ckalloc(buf_width + 1);
buf_width_max = buf_width;
}
proc = (0 == strcmp("proc",argv[0]));
sprintf(buf,"%.*s",buf_width,argv[0]);
len = strlen(buf);
space = buf_width - len;
bufp = buf + len;
argc--; argv++;
arg_index = 1;
while (argc && (space > 0)) {
CONST char *elementPtr;
CONST char *nextPtr;
int wrap;
/* braces/quotes have been stripped off arguments */
/* so put them back. We wrap everything except lists */
/* with one argument. One exception is to always wrap */
/* proc's 2nd arg (the arg list), since people are */
/* used to always seeing it this way. */
if (proc && (arg_index > 1)) wrap = TRUE;
else {
(void) TclFindElement(interp,*argv,
#if TCL_MAJOR_VERSION >= 8
-1,
#endif
&elementPtr,&nextPtr,(int *)0,(int *)0);
if (*elementPtr == '\0') wrap = TRUE;
else if (*nextPtr == '\0') wrap = FALSE;
else wrap = TRUE;
}
/* wrap lists (or null) in braces */
if (wrap) {
sprintf(bufp," {%.*s}",space-3,*argv);
} else {
sprintf(bufp," %.*s",space-1,*argv);
}
len = strlen(buf);
space = buf_width - len;
bufp = buf + len;
argc--; argv++;
arg_index++;
}
if (compress) {
/* this copies from our static buf to printify's static buf */
/* and back to our static buf */
strncpy(buf,printify(buf),buf_width);
}
/* usually but not always right, but assume truncation if buffer is */
/* full. this avoids tiny but odd-looking problem of appending "}" */
/* to truncated lists during {}-wrapping earlier */
if (strlen(buf) == buf_width) {
buf[buf_width-1] = buf[buf_width-2] = buf[buf_width-3] = '.';
}
return(buf);
}
#if TCL_MAJOR_VERSION >= 8
static
char *
print_objv(interp,objc,objv)
Tcl_Interp *interp;
int objc;
Tcl_Obj *objv[];
{
char **argv;
int argc;
int len;
argv = (char **)ckalloc(objc+1 * sizeof(char *));
for (argc=0 ; argc<objc ; argc++) {
argv[argc] = Tcl_GetStringFromObj(objv[argc],&len);
}
argv[argc] = NULL;
return(print_argv(interp,argc,argv));
}
#endif
static
void
PrintStackBelow(interp,curf,viewf)
Tcl_Interp *interp;
CallFrame *curf; /* current FramePtr */
CallFrame *viewf; /* view FramePtr */
{
char ptr; /* graphically indicate where we are in the stack */
/* indicate where we are in the stack */
ptr = ((curf == viewf)?'*':' ');
if (curf == 0) {
print(interp,"%c0: %s\n",
ptr,print_argv(interp,main_argc,main_argv));
} else {
PrintStackBelow(interp,curf->callerVarPtr,viewf);
print(interp,"%c%d: %s\n",ptr,curf->level,
#if TCL_MAJOR_VERSION >= 8
print_objv(interp,curf->objc,curf->objv)
#else
print_argv(interp,curf->argc,curf->argv)
#endif
);
}
}
static
void
PrintStack(interp,curf,viewf,objc,objv,level)
Tcl_Interp *interp;
CallFrame *curf; /* current FramePtr */
CallFrame *viewf; /* view FramePtr */
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
char *level;
{
PrintStackBelow(interp,curf,viewf);
print(interp," %s: %s\n",level,print_objv(interp,objc,objv));
}
/* return 0 if goal matches current frame or goal can't be found */
/* anywere in frame stack */
/* else return 1 */
/* This catches things like a proc called from a Tcl_Eval which in */
/* turn was not called from a proc but some builtin such as source */
/* or Tcl_Eval. These builtin calls to Tcl_Eval lose any knowledge */
/* the FramePtr from the proc, so we have to search the entire */
/* stack frame to see if it's still there. */
static int
GoalFrame(goal,iptr)
CallFrame *goal;
Interp *iptr;
{
CallFrame *cf = iptr->varFramePtr;
/* if at current level, return success immediately */
if (goal == cf) return 0;
while (cf) {
cf = cf->callerVarPtr;
if (goal == cf) {
/* found, but since it's above us, fail */
return 1;
}
}
return 0;
}
#if 0
static char *cmd_print(cmdtype)
enum debug_cmd cmdtype;
{
switch (cmdtype) {
case none: return "cmd: none";
case step: return "cmd: step";
case next: return "cmd: next";
case ret: return "cmd: ret";
case cont: return "cmd: cont";
case up: return "cmd: up";
case down: return "cmd: down";
case where: return "cmd: where";
case Next: return "cmd: Next";
}
return "cmd: Unknown";
}
#endif
/* debugger's trace handler */
static int
debugger_trap _ANSI_ARGS_ ((
ClientData clientData,
Tcl_Interp *interp,
int level,
CONST char *command,
Tcl_Command commandInfo,
int objc,
struct Tcl_Obj * CONST * objv));
/*ARGSUSED*/
static int
debugger_trap(clientData,interp,level,command,commandInfo,objc,objv)
ClientData clientData; /* not used */
Tcl_Interp *interp;
int level; /* positive number if called by Tcl, -1 if */
/* called by Dbg_On in which case we don't */
/* know the level */
CONST char *command;
Tcl_Command commandInfo; /* Unused */
int objc;
struct Tcl_Obj * CONST * objv;
{
char level_text[6]; /* textual representation of level */
int break_status;
Interp *iPtr = (Interp *)interp;
CallFrame *trueFramePtr; /* where the pc is */
CallFrame *viewFramePtr; /* where up/down are */
int print_command_first_time = TRUE;
static int debug_suspended = FALSE;
struct breakpoint *b;
char* thecmd;
/* skip commands that are invoked interactively */
if (debug_suspended) return TCL_OK;
thecmd = Tcl_GetString (objv[0]);
/* skip debugger commands */
if (thecmd[1] == '\0') {
switch (thecmd[0]) {
case 'n':
case 's':
case 'c':
case 'r':
case 'w':
case 'b':
case 'u':
case 'd': return TCL_OK;
}
}
if ((*ignoreproc)(interp,thecmd)) return TCL_OK;
/* if level is unknown, use "?" */
sprintf(level_text,(level == -1)?"?":"%d",level);
/* save so we can restore later */
trueFramePtr = iPtr->varFramePtr;
/* do not allow breaking while testing breakpoints */
debug_suspended = TRUE;
/* test all breakpoints to see if we should break */
/* if any successful breakpoints, start interactor */
debug_new_action = FALSE; /* reset strobe */
break_status = FALSE; /* no successful breakpoints yet */
for (b = break_base;b;b=b->next) {
break_status |= breakpoint_test(interp,command,b);
}
if (break_status) {
if (!debug_new_action) {
goto start_interact;
}
/* if s or n triggered by breakpoint, make "s 1" */
/* (and so on) refer to next command, not this one */
/* step_count++;*/
goto end_interact;
}
switch (debug_cmd) {
case cont:
goto finish;
case step:
step_count--;
if (step_count > 0) goto finish;
goto start_interact;
case next:
/* check if we are back at the same level where the next */
/* command was issued. Also test */
/* against all FramePtrs and if no match, assume that */
/* we've missed a return, and so we should break */
/* if (goalFramePtr != iPtr->varFramePtr) goto finish;*/
if (GoalFrame(goalFramePtr,iPtr)) goto finish;
step_count--;
if (step_count > 0) goto finish;
goto start_interact;
case Next:
/* check if we are back at the same level where the next */
/* command was issued. */
if (goalNumLevel < iPtr->numLevels) goto finish;
step_count--;
if (step_count > 0) goto finish;
goto start_interact;
case ret:
/* same comment as in "case next" */
if (goalFramePtr != iPtr->varFramePtr) goto finish;
goto start_interact;
/* DANGER: unhandled cases! none, up, down, where */
}
start_interact:
if (print_command_first_time) {
print(interp,"%s: %s\n",
level_text,print_argv(interp,1,&command));
print_command_first_time = FALSE;
}
/* since user is typing a command, don't interrupt it immediately */
debug_cmd = cont;
debug_suspended = TRUE;
/* interactor won't return until user gives a debugger cmd */
(*interactor)(interp,interdata);
end_interact:
/* save this so it can be restored after "w" command */
viewFramePtr = iPtr->varFramePtr;
if (debug_cmd == up || debug_cmd == down) {
/* calculate new frame */
if (-1 == TclGetFrame2(interp,trueFramePtr,viewFrameName,
&iPtr->varFramePtr,debug_cmd)) {
print(interp,"%s\n",Tcl_GetStringResult (interp));
Tcl_ResetResult(interp);
}
goto start_interact;
}
/* reset view back to normal */
iPtr->varFramePtr = trueFramePtr;
#if 0
/* allow trapping */
debug_suspended = FALSE;
#endif
switch (debug_cmd) {
case cont:
case step:
goto finish;
case next:
goalFramePtr = iPtr->varFramePtr;
goto finish;
case Next:
goalNumLevel = iPtr->numLevels;
goto finish;
case ret:
goalFramePtr = iPtr->varFramePtr;
if (goalFramePtr == 0) {
print(interp,"nowhere to return to\n");
break;
}
goalFramePtr = goalFramePtr->callerVarPtr;
goto finish;
case where:
PrintStack(interp,iPtr->varFramePtr,viewFramePtr,objc,objv,level_text);
break;
}
/* restore view and restart interactor */
iPtr->varFramePtr = viewFramePtr;
goto start_interact;
finish:
debug_suspended = FALSE;
return TCL_OK;
}
/*ARGSUSED*/
static
int
cmdNext(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
debug_new_action = TRUE;
debug_cmd = *(enum debug_cmd *)clientData;
last_action_cmd = debug_cmd;
if (objc == 1) {
step_count = 1;
} else if (TCL_OK != Tcl_GetIntFromObj (interp, objv[1], &step_count)) {
return TCL_ERROR;
}
last_step_count = step_count;
return(TCL_RETURN);
}
/*ARGSUSED*/
static
int
cmdDir(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
char* frame;
debug_cmd = *(enum debug_cmd *)clientData;
if (objc == 1) {
frame = "1";
} else {
frame = Tcl_GetString (objv[1]);
}
strncpy(viewFrameName,frame,FRAMENAMELEN);
return TCL_RETURN;
}
/*ARGSUSED*/
static
int
cmdSimple(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
debug_new_action = TRUE;
debug_cmd = *(enum debug_cmd *)clientData;
last_action_cmd = debug_cmd;
return TCL_RETURN;
}
static
void
breakpoint_destroy(b)
struct breakpoint *b;
{
if (b->file) Tcl_DecrRefCount(b->file);
if (b->pat) Tcl_DecrRefCount(b->pat);
if (b->cmd) Tcl_DecrRefCount(b->cmd);
if (b->expr) Tcl_DecrRefCount(b->expr);
/* unlink from chain */
if ((b->previous == 0) && (b->next == 0)) {
break_base = 0;
} else if (b->previous == 0) {
break_base = b->next;
b->next->previous = 0;
} else if (b->next == 0) {
b->previous->next = 0;
} else {
b->previous->next = b->next;
b->next->previous = b->previous;
}
ckfree((char *)b);
}
static void
savestr(objPtr,str)
Tcl_Obj **objPtr;
char *str;
{
*objPtr = Tcl_NewStringObj(str, -1);
Tcl_IncrRefCount(*objPtr);
}
/*ARGSUSED*/
static
int
cmdWhere(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
static char* options [] = {
"-compress",
"-width",
NULL
};
enum options {
WHERE_COMPRESS,
WHERE_WIDTH
};
int i;
if (objc == 1) {
debug_cmd = where;
return TCL_RETURN;
}
/* Check and process switches */
for (i=1; i<objc; i++) {
char *name;
int index;
name = Tcl_GetString(objv[i]);
if (name[0] != '-') {
break;
}
if (Tcl_GetIndexFromObj(interp, objv[i], options, "flag", 0,
&index) != TCL_OK) {
goto usage;
}
switch ((enum options) index) {
case WHERE_COMPRESS:
i++;
if (i >= objc) {
print(interp,"%d\n",compress);
break;
}
if (TCL_OK != Tcl_GetBooleanFromObj (interp, objv[i], &buf_width))
goto usage;
break;
case WHERE_WIDTH:
i++;
if (i >= objc) {
print(interp,"%d\n",buf_width);
break;
}
if (TCL_OK != Tcl_GetIntFromObj (interp, objv[i], &buf_width))
goto usage;
break;
}
}
if (i < objc) goto usage;
return TCL_OK;
usage:
print(interp,"usage: w [-width #] [-compress 0|1]\n");
return TCL_ERROR;
}
#define breakpoint_fail(msg) {error_msg = msg; goto break_fail;}
/*ARGSUSED*/
static
int
cmdBreak(clientData, interp, objc, objv)
ClientData clientData;
Tcl_Interp *interp;
int objc;
Tcl_Obj *CONST objv[]; /* Argument objects. */
{
struct breakpoint *b;
char *error_msg;
static char* options [] = {
"-glob",
"-regexp",
"if",
"then",
NULL
};
enum options {
BREAK_GLOB,
BREAK_RE,
BREAK_IF,
BREAK_THEN
};
int i;
int index;
/* No arguments, list breakpoints */
if (objc == 1) {
for (b = break_base;b;b=b->next) breakpoint_print(interp,b);
return(TCL_OK);
}
/* Process breakpoint deletion (-, -x) */
/* Copied from exp_prog.h */
#define streq(x,y) (0 == strcmp((x),(y)))
if (objc == 2) {
int id;
if (streq (Tcl_GetString (objv[1]),"-")) {
while (break_base) {
breakpoint_destroy(break_base);
}
breakpoint_max_id = 0;
return(TCL_OK);
}
if ((Tcl_GetString (objv[1])[0] == '-') &&
(TCL_OK == Tcl_GetIntFromObj (interp, objv[1], &id))) {
id = -id;
for (b = break_base;b;b=b->next) {
if (b->id == id) {
breakpoint_destroy(b);
if (!break_base) breakpoint_max_id = 0;
return(TCL_OK);
}
}
Tcl_SetResult(interp,"no such breakpoint",TCL_STATIC);
return(TCL_ERROR);
}
}
b = breakpoint_new();
/* Process switches */
i = 1;
if (Tcl_GetIndexFromObj(interp, objv[i], options, "flag", 0,
&index) == TCL_OK) {
switch ((enum options) index) {
case BREAK_GLOB:
i++;
if (i == objc) breakpoint_fail("no pattern?");
savestr(&b->pat,Tcl_GetString (objv[i]));
i++;
break;
case BREAK_RE:
i++;
if (i == objc) breakpoint_fail("bad regular expression");
b->re = 1;
savestr(&b->pat,Tcl_GetString (objv[i]));
if (Tcl_GetRegExpFromObj(interp, b->pat, TCL_REG_ADVANCED) == NULL) {
breakpoint_destroy(b);
return TCL_ERROR;
}
i++;
break;
case BREAK_IF: break;
case BREAK_THEN: break;
}
} else {
/* look for [file:]line */
char *colon;
char *linep; /* pointer to beginning of line number */
char* ref = Tcl_GetString (objv[i]);
colon = strchr(ref,':');
if (colon) {