-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtmldb2.cpp
1441 lines (1228 loc) · 40.9 KB
/
htmldb2.cpp
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
#ifdef RCSID
static char RCSid[] =
"$Header$";
#endif
/*
* Copyright (c) 1999 by Michael J. Roberts. All Rights Reserved.
*
* Please see the accompanying license file, LICENSE.TXT, for information
* on using and copying this software.
*/
/*
Name
htmldb2.cpp - debugger helper class - TADS 2 Interface
Function
This module contains the helper class interfaces to the TADS 2 debugger
internal engine API.
The code in this module is separated from the main debugger helper class
so that the main helper class is independent of the underlying VM engine
and its debugger API. This allows the main debugger helper to be shared
by different engines; in particular, this allows the main debugger helper
class to be used for TADS 2 and T3 debuggers. Because the UI code uses
the helper class to access the VM engine (the UI code never calls the
engine directly - it always uses the helper class instead), the UI code
is also independent of the underlying engine.
Notes
Modified
10/11/99 MJRoberts - Creation
*/
#include <string.h>
/* include necessary TADS interfaces */
#include <dbg.h>
#include <err.h>
#include <lin.h>
#include <linf.h>
#include <dat.h>
#include <os.h>
#include <bif.h>
#include <obj.h>
#ifndef TADSHTML_H
#include "tadshtml.h"
#endif
#ifndef HTMLDBG_H
#include "htmldbg.h"
#endif
#ifndef HTMLSYS_H
#include "htmlsys.h"
#endif
#ifndef HTMLPRS_H
#include "htmlprs.h"
#endif
#ifndef HTMLTAGS_H
#include "htmltags.h"
#endif
#ifndef HTMLDISP_H
#include "htmldisp.h"
#endif
/* ------------------------------------------------------------------------ */
/*
* Debugger entrypoints
*/
/*
* initialize
*/
void dbguini(dbgcxdef *ctx, const char *game_filename)
{
void *ui_obj;
/* call the UI implementation */
ui_obj = html_dbgui_ini(ctx, game_filename);
/* store the UI object in the engine context */
ctx->dbgcxui = ui_obj;
}
/*
* initialize, phase two
*/
void dbguini2(dbgcxdef *ctx)
{
html_dbgui_ini2(ctx, ctx->dbgcxui);
}
/*
* determine if we can resume from an error
*/
int dbgu_err_resume(dbgcxdef *ctx)
{
return html_dbgui_err_resume(ctx, ctx->dbgcxui);
}
/*
* find a source file
*/
int dbgu_find_src(const char *origname, int origlen,
char *fullname, size_t full_len, int must_find_file)
{
return html_dbgui_find_src(origname, origlen, fullname, full_len,
must_find_file);
}
/*
* main command loop entrypoint
*/
void dbgucmd(struct dbgcxdef *ctx,
int bphit, int err, unsigned int *exec_ofs)
{
html_dbgui_cmd(ctx, ctx->dbgcxui, bphit, err, exec_ofs);
}
/*
* quitting game
*/
void dbguquitting(struct dbgcxdef *ctx)
{
html_dbgui_quitting(ctx, ctx->dbgcxui);
}
/*
* terminating
*/
void dbguterm(struct dbgcxdef *ctx)
{
/* tell the UI we're shutting down */
html_dbgui_term(ctx, ctx->dbgcxui);
/* clear the UI object in the engine debug context */
ctx->dbgcxui = 0;
}
/*
* display an error
*/
void dbguerr(struct dbgcxdef *ctx, int errnum, char *msg)
{
html_dbgui_err(ctx, ctx->dbgcxui, errnum, msg);
}
/* ------------------------------------------------------------------------ */
/*
* Helper class extension. This class encapsulates VM-specific private
* functions. These functions are called by the vm_xxx code and are
* private to the vm_xxx code - the generic debugger helper class
* doesn't call any of these functions.
*
* This class isn't ever instantiated; all of the methods are static.
* The only real reason we need this class at all is so that we can make
* it a friend of CHtmlDebugHelper, so that our private vm_xxx
* implementation functions can call back into the CHtmlDebugHelper
* private parts; this is a valid need because CHtmlDebugHelperVM is
* effectively an extension of CHtmlDebugHelper, but couldn't be part of
* CHtmlDebugHelper because of the need to keep the VM-specific
* functions out of the public interface. (In particular, each VM
* implementation will have its own set of functions in
* CHtmlDebugHelperVM, so we can't come up with a set in
* CHtmlDebugHelper that will serve everyone.)
*/
class CHtmlDebugHelperVM
{
public:
/* toggle the enabled status of the breakpoint at the given location */
static void toggle_bp_disable(CHtmlDebugHelper *helper,
struct dbgcxdef *ctx,
int source_id, unsigned long linenum,
objnum line_objn, int line_ofs);
/* set or clear a breakpoint at the given source location */
static int toggle_breakpoint(CHtmlDebugHelper *helper,
struct dbgcxdef *ctx,
int source_id, unsigned long linenum,
objnum line_objn, uint line_ofs,
const textchar_t *cond, int set_only);
/* given a source location, get the code address */
static int srcofs_to_code(CHtmlDebugHelper *helper,
dbgcxdef *ctx, IDebugWin *win,
unsigned long *linenum,
CHtmlDbg_win_link **win_link,
objnum *line_objn, uint *line_ofs);
/* given a source location, get the code address */
static int srcofs_to_code(dbgcxdef *ctx, int source_id,
unsigned long *linenum,
objnum *line_objn, uint *line_ofs);
};
/* ------------------------------------------------------------------------ */
/*
* hidden output status - this is a global variable defined by the TADS
* 2 debugger engine
*/
extern "C" int dbghid;
/* ------------------------------------------------------------------------ */
/*
* Hidden output tracking. The TADS 2 engine requires that the debugger
* UI implement these functions.
*/
/*
* Turn hidden output tracking on/off
*/
void trchid()
{
outflushn(1);
os_printz("---Hidden output---");
outflushn(1);
}
void trcsho()
{
outflushn(1);
os_printz("---End of hidden output, normal output resumes---");
outflushn(1);
}
/* ------------------------------------------------------------------------ */
/*
* Flush output to the main game text window
*/
void CHtmlDebugHelper::vm_flush_main_output(struct dbgcxdef *)
{
outflushn(0);
}
/* ------------------------------------------------------------------------ */
/*
* Get the object and p-code offset for the current selection in the
* given window. Returns zero on success, non-zero on failure. On
* return, *fpos will be changed to reflect the actual source file
* location closest to the input fpos value that contains a line start.
* *win_link is filled in with a pointer to the window link structure
* for the given window.
*/
int CHtmlDebugHelperVM::srcofs_to_code(CHtmlDebugHelper *helper,
dbgcxdef *ctx, IDebugWin *win,
unsigned long *linenum,
CHtmlDbg_win_link **win_link,
objnum *line_objn, uint *line_ofs)
{
CHtmlDbg_line_link *line_link;
/* find information the current line in the window */
*linenum = helper->find_line_info(win, win_link, &line_link);
/* if we didn't find the window, return failure */
if (*win_link == 0)
return 1;
/* get information on this position */
return srcofs_to_code(ctx, (*win_link)->source_id_, linenum,
line_objn, line_ofs);
}
/*
* Find the line source for a given line source ID
*/
static lindef *find_lindef(dbgcxdef *ctx, int id)
{
lindef *lin;
/* scan the list of line sources */
for (lin = ctx->dbgcxlin ; lin != 0 ; lin = lin->linnxt)
{
/* if this is the one, return it */
if (lin->linid == id)
return lin;
}
/* not found */
return 0;
}
/*
* Find the nearest executable line to a given source location. If TADS
* isn't running, we won't make any adjustment; otherwise, we'll fix up
* the line number to the nearest line with executable code, and we'll
* fill in *line_objn and *line_ofs with the p-code location of the
* code.
*/
int CHtmlDebugHelperVM::srcofs_to_code(dbgcxdef *ctx, int source_id,
unsigned long *linenum,
objnum *line_objn, uint *line_ofs)
{
lindef *lin;
uchar posbuf[4];
/*
* if there's no context, the actual source location is the best we
* can do for now - we have no game file to tell us the location of
* the next executable line
*/
if (ctx == 0)
{
*line_objn = MCMONINV;
*line_ofs = 0;
return 0;
}
/* get the line source */
lin = find_lindef(ctx, source_id);
if (lin == 0)
return 2;
/* find the source line at this location */
oswp4(posbuf, *linenum);
linfind(lin, (char *)posbuf, line_objn, line_ofs);
/*
* adjust the file position to the actual value -- this may be
* different than the text the user was pointing at, since not every
* line contains executable code
*/
*linenum = osrp4(posbuf);
/* make sure we have a valid location */
if (*line_objn == MCMONINV)
return 3;
/* success */
return 0;
}
/* ------------------------------------------------------------------------ */
/*
* Get information on the current source line at the given stack level.
* Returns zero on success, non-zero on failure.
*/
int CHtmlDebugHelper::
vm_get_source_info_at_level(dbgcxdef *ctx, CHtmlDbg_src **src,
unsigned long *linenum, int level,
class CHtmlDebugSysIfc_win *)
{
uchar infobuf[128];
/* get information on the current line */
if (dbglgetlvl(ctx, infobuf, level))
return 1;
/* search for a line source with the given ID */
*src = find_internal_src((int)infobuf[0]);
/* if we didn't find a line source with the current line, give up */
if (*src == 0)
return 2;
/* get the current line number */
*linenum = osrp4(infobuf + 1);
/* success */
return 0;
}
/* ------------------------------------------------------------------------ */
/*
* Perform engine-specific checks on a newly-loaded a game
*/
void CHtmlDebugHelper::vm_check_loaded_program(dbgcxdef *ctx)
{
/*
* check to make sure that the correct debug info is available if we
* have a game loaded (we might only have a config loaded, in which
* case it's too early to determine if the game has the correct
* debug information)
*/
if (ctx != 0 && !(ctx->dbgcxflg & DBGCXFLIN2))
errsig(ctx->dbgcxerr, ERR_NEEDLIN2);
}
/* ------------------------------------------------------------------------ */
/*
* Load line sources from a compiled game program
*/
void CHtmlDebugHelper::vm_load_sources_from_program(dbgcxdef *ctx)
{
lindef *lin;
/* read line sources from the compiled game */
for (lin = ctx->dbgcxlin ; lin != 0 ; lin = lin->linnxt)
{
linfdef *linf;
/* create and add a new source tracker for this line */
linf = (linfdef *)lin;
add_internal_line_source(linf->linfnam,
linf->linfnam + strlen(linf->linfnam)+1,
lin->linid);
/* if this is the highest ID yet, note it */
if (lin->linid > last_compiled_line_source_id_)
last_compiled_line_source_id_ = lin->linid;
}
}
/* ------------------------------------------------------------------------ */
/*
* Set engine execution state to GO
*/
void CHtmlDebugHelper::vm_set_exec_state_go(dbgcxdef *ctx)
{
/* clear the stepping flags */
ctx->dbgcxflg &= ~(DBGCXFSS + DBGCXFSO);
}
/*
* Set the engine execution state to BREAK
*/
void CHtmlDebugHelper::vm_set_exec_state_break(dbgcxdef *ctx)
{
/* set the stepping flag, but clear the step-over-calls flag */
ctx->dbgcxflg |= DBGCXFSS;
ctx->dbgcxflg &= ~DBGCXFSO;
}
/*
* Set engine execution state to STEP OVER
*/
void CHtmlDebugHelper::vm_set_exec_state_step_over(dbgcxdef *ctx)
{
/* set the step and step-over-calls flags */
ctx->dbgcxflg |= (DBGCXFSS + DBGCXFSO);
/* keep stepping until we're back at the current depth again */
ctx->dbgcxsof = ctx->dbgcxdep;
}
/*
* Set engine execution state to STEP OUT
*/
void CHtmlDebugHelper::vm_set_exec_state_step_out(dbgcxdef *ctx)
{
/* set the step and step-over-calls flags */
ctx->dbgcxflg |= (DBGCXFSS + DBGCXFSO);
/* keep stepping until we're back at the *enclosing* depth */
ctx->dbgcxsof = (ctx->dbgcxdep >= 1 ? ctx->dbgcxdep - 1 : 0);
}
/*
* Set engine execution state to STEP INTO
*/
void CHtmlDebugHelper::vm_set_exec_state_step_into(dbgcxdef *ctx)
{
/* set the stepping flag, but clear the step-over-calls flag */
ctx->dbgcxflg |= DBGCXFSS;
ctx->dbgcxflg &= ~DBGCXFSO;
}
/*
* Signal a QUIT condition in the engine
*/
void CHtmlDebugHelper::vm_signal_quit(dbgcxdef *ctx)
{
/* signal the TADS error condition for quitting the game */
errsig(ctx->dbgcxerr, ERR_RUNQUIT);
}
/*
* cancel script recording
*/
void CHtmlDebugHelper::vm_cancel_script_recording(struct dbgcxdef *ctx)
{
qasclose();
}
/*
* Signal a RESTART condition in the engine
*/
void CHtmlDebugHelper::vm_signal_restart(dbgcxdef *ctx)
{
/*
* clear the in-debugger flag - we're leaving the debugger via the
* signal, so we don't need to keep this flag set
*/
ctx->dbgcxflg &= ~DBGCXFIND;
/* clear the debugger stack */
ctx->dbgcxdep = 0;
ctx->dbgcxfcn = 0;
/*
* go restart via the built-in restart() function, which takes care
* of resetting all the run-time context information
*/
bifres((bifcxdef *)ctx->dbgcxrun->runcxbcx, 0);
}
/*
* Signal abort in the engine
*/
void CHtmlDebugHelper::vm_signal_abort(dbgcxdef *ctx)
{
/* signal the TADS error condition for quitting the game */
errsig(ctx->dbgcxerr, ERR_RUNABRT);
}
/* ------------------------------------------------------------------------ */
/*
* Move the execution position in the engine to the current selection in
* the given window. Returns zero on success, non-zero on failure.
*/
int CHtmlDebugHelper::vm_set_next_statement(dbgcxdef *ctx,
void *exec_ofs,
IDebugWin *win,
unsigned long *linenum,
int *need_single_step)
{
CHtmlDbg_win_link *win_link;
objnum line_objn;
uint line_ofs;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, linenum, &win_link,
&line_objn, &line_ofs))
return 2;
/* move the execution point to the new offset */
*(uint *)exec_ofs = line_ofs;
/*
* TADS 2 requires a single step after changing the execution
* position, to set up the new location context in the new line
* (specifically, we need to execute the OPCLINE instruction at the
* start of the new source line)
*/
*need_single_step = TRUE;
/* success */
return 0;
}
/* ------------------------------------------------------------------------ */
/*
* Is the given line executable?
*/
int CHtmlDebugHelper::vm_is_line_executable(struct dbgcxdef *ctx,
IDebugWin *win)
{
CHtmlDbg_line_link *line_link;
CHtmlDbg_win_link *win_link;
unsigned long src_linenum, code_linenum;
objnum line_objn;
uint line_ofs;
/* we can't do anything if the engine isn't running */
if (ctx == 0)
return FALSE;
/* get information on the current source file position */
src_linenum = find_line_info(win, &win_link, &line_link);
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &code_linenum,
&win_link, &line_objn, &line_ofs))
return FALSE;
/*
* it's executable if the line number of the code matches the line
* number in the source
*/
return (src_linenum == code_linenum);
}
/* ------------------------------------------------------------------------ */
/*
* Check if the current selection in the given window is within the same
* function or method as the current execution point. Returns true if
* so, false if not. This is a condition of setting the next statement;
* this function is provided so that the UI code can check to make sure
* that this condition is met when the user attempts to move the
* execution point, and generate an appropriate error message if not.
*/
int CHtmlDebugHelper::vm_is_in_same_fn(dbgcxdef *ctx,
IDebugWin *win)
{
CHtmlDbg_win_link *win_link;
unsigned long fpos;
objnum line_objn;
uint line_ofs;
uint start_ofs, end_ofs;
dbgfdef *fr;
/* if there's no context, there's no way to compare them */
if (ctx == 0)
return FALSE;
/* get the current frame - if there isn't one, return failure */
if (ctx->dbgcxfcn == 0)
return FALSE;
fr = &ctx->dbgcxfrm[ctx->dbgcxfcn - 1];
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &fpos, &win_link,
&line_objn, &line_ofs))
return FALSE;
/*
* if this line is not in the same object as the current target
* object, we can disallow it
*/
if (line_objn == MCMONINV || line_objn != fr->dbgftarg)
return FALSE;
/*
* if there's no property, it's a function, so it's valid as long as
* it's in the current object (which we've just determined that it
* is)
*/
if (fr->dbgfprop == (prpnum)0)
return TRUE;
/* find the limits of the property's data range */
start_ofs = objgetp(ctx->dbgcxmem, line_objn, fr->dbgfprop, 0);
end_ofs = objgetp_end(ctx->dbgcxmem, line_objn, fr->dbgfprop);
/* if it's within the range, it's valid, otherwise it's not */
return (line_ofs >= start_ofs && line_ofs < end_ofs);
}
/* ------------------------------------------------------------------------ */
/*
* Determine if call tracing is active in the engine
*/
int CHtmlDebugHelper::vm_is_call_trace_active(dbgcxdef *ctx) const
{
return ((ctx->dbgcxflg & DBGCXFTRC) != 0);
}
/*
* turn call trace on or off in the engine
*/
void CHtmlDebugHelper::vm_set_call_trace_active(dbgcxdef *ctx, int flag)
{
/* set or clear the trace flag as appropriate */
if (flag)
ctx->dbgcxflg |= DBGCXFTRC;
else
ctx->dbgcxflg &= ~DBGCXFTRC;
}
/*
* Clear the call trace log in the engine
*/
void CHtmlDebugHelper::vm_clear_call_trace_log(dbgcxdef *ctx)
{
/* forget everything in the buffer */
ctx->dbgcxhstf = 0;
}
/*
* Get a pointer to the history log buffer maintained by the engine
*/
const textchar_t *CHtmlDebugHelper::vm_get_call_trace_buf(dbgcxdef *ctx) const
{
return ctx->dbgcxhstp;
}
/*
* get the size of the data accumulated in the history log
*/
unsigned long CHtmlDebugHelper::vm_get_call_trace_len(dbgcxdef *ctx) const
{
return ctx->dbgcxhstf;
}
/* ------------------------------------------------------------------------ */
/*
* Set or clear a breakpoint at a given location. Returns zero on
* success, non-zero on error.
*/
int CHtmlDebugHelperVM::toggle_breakpoint(CHtmlDebugHelper *helper,
dbgcxdef *ctx,
int source_id,
unsigned long linenum,
objnum line_objn, uint line_ofs,
const textchar_t *cond,
int set_only)
{
int bpnum;
int did_set;
char bpname[HTMLDBG_MAXBPNAME];
CHtmlDbg_src *src;
/* find the internal source file tracker */
src = helper->find_internal_src(source_id);
if (src == 0)
return 1;
/*
* Build the name of the breakpoint for display and configuration
* saving purposes. The name consists of the name of the line
* source and the source offset.
*/
sprintf(bpname, "#%lu %s", linenum, src->fname_.get());
/*
* If we can only set a new breakpoint, check to see if there's
* already a breakpoint at this location. If there is, disallow it.
*/
if (set_only && helper->find_internal_bp(source_id, linenum) != 0)
return 2;
/* set the breakpoint in the engine, if we're running */
if (ctx != 0)
{
/* set the breakpoint in TADS */
if (dbgbpat(ctx, line_objn, MCMONINV, line_ofs, &bpnum,
bpname, TRUE, (char *)cond, &did_set))
return 3;
}
/* toggle the internal breakpoint record */
helper->toggle_internal_bp(ctx, source_id, linenum, 0,
bpnum, FALSE, did_set, FALSE);
/* success */
return 0;
}
/*
* Toggle a breakpoint at the current selection in the given window
*/
void CHtmlDebugHelper::vm_toggle_breakpoint(dbgcxdef *ctx,
IDebugWin *win)
{
CHtmlDbg_win_link *win_link;
unsigned long linenum;
objnum line_objn;
uint line_ofs;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win,
&linenum, &win_link,
&line_objn, &line_ofs))
return;
/* toggle the breakpoint at the given location */
CHtmlDebugHelperVM::toggle_breakpoint(this, ctx, win_link->source_id_,
linenum, line_objn, line_ofs,
0, FALSE);
}
/*
* Set a temporary breakpoint
*/
int CHtmlDebugHelper::vm_set_temp_bp(dbgcxdef *ctx, IDebugWin *win)
{
CHtmlDbg_win_link *win_link;
unsigned long fpos;
objnum line_objn;
uint line_ofs;
int did_set;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &fpos, &win_link,
&line_objn, &line_ofs))
return FALSE;
/* if there's already a breakpoint there, there's nothing to do */
if (dbgisbp(ctx, line_objn, MCMONINV, line_ofs, &tmp_bpnum_))
return FALSE;
/* set the breakpoint */
if (dbgbpat(ctx, line_objn, MCMONINV, line_ofs, &tmp_bpnum_,
"Temp BP", FALSE, 0, &did_set) || !did_set)
return FALSE;
/* success */
return TRUE;
}
/*
* Clear a temporary breakpoint
*/
void CHtmlDebugHelper::vm_clear_temp_bp(dbgcxdef *ctx)
{
/* delete the temporary breakpoint in the VM */
dbgbpdel(ctx, tmp_bpnum_);
}
/*
* Set a global breakpoint
*/
int CHtmlDebugHelper::vm_set_global_breakpoint(dbgcxdef *ctx,
const textchar_t *cond,
int change,
int *bpnum,
char *errbuf, size_t errbuflen)
{
/*
* Add the breakpoint in the engine, if we're running. Use the name
* "g" for all global breakpoints; since the breakpoint is based
* entirely on the condition string, we don't need to remember
* anything about it but that it has a condition string.
*/
if (ctx != 0)
{
int err;
/* set it in the engine */
err = dbgbpat(ctx, MCMONINV, MCMONINV, 0, bpnum, "g", TRUE,
(textchar_t *)cond, 0);
/* if an error occurred, get the message and return the error */
if (err != 0)
{
char msg[256];
/* get the message into the caller's error buffer */
errmsg(ctx->dbgcxerr, msg, sizeof(msg), err);
errfmt(errbuf, errbuflen, msg, 0, 0);
/* return failure */
return err;
}
}
else
{
/* the engine isn't running; synthesize a breakpoint ID */
*bpnum = synthesize_bp_num();
}
/* add an entry to our breakpoint tracker list */
toggle_internal_bp(ctx, 0, 0, cond, change, *bpnum, TRUE, TRUE);
/* success */
return 0;
}
/*
* Enable or disable a breakpoint at the current selection in the given
* window
*/
void CHtmlDebugHelper::vm_toggle_bp_disable(dbgcxdef *ctx,
IDebugWin *win)
{
CHtmlDbg_win_link *win_link;
unsigned long linenum;
objnum line_objn;
uint line_ofs;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &linenum,
&win_link, &line_objn, &line_ofs))
return;
/* toggle the status */
CHtmlDebugHelperVM::toggle_bp_disable(this, ctx, win_link->source_id_,
linenum, line_objn, line_ofs);
}
/*
* enable/disable a breakpoint at the given location
*/
void CHtmlDebugHelperVM::toggle_bp_disable(CHtmlDebugHelper *helper,
dbgcxdef *ctx,
int source_id,
unsigned long linenum,
objnum line_objn, int line_ofs)
{
int bpnum;
int disabled;
/*
* if the engine is running, ask it if there's a breakpoint there -
* if not, there's nothing to do
*/
if (ctx != 0)
{
if (!dbgisbp(ctx, line_objn, MCMONINV, line_ofs, &bpnum))
return;
/* toggle the enabled/disabled state of the breakpoint */
disabled = !dbgisbpena(ctx, bpnum);
dbgbpdis(ctx, bpnum, disabled);
}
/* toggle the status of the internal breakpoint record */
helper->toggle_internal_bp_disable(ctx, source_id, linenum);
}
/*
* Enable or disable a breakpoint
*/
int CHtmlDebugHelper::vm_enable_breakpoint(dbgcxdef *ctx, int bpnum,
int enable)
{
/* enable/disable the breakpoint in the debugger */
return dbgbpdis(ctx, bpnum, !enable);
}
/*
* Determine if a breakpoint is enabled
*/
int CHtmlDebugHelper::vm_is_bp_enabled(dbgcxdef *ctx, int bpnum)
{
return dbgisbpena(ctx, bpnum);
}
/*
* Set a breakpoint's condidtion text
*/
int CHtmlDebugHelper::vm_set_bp_condition(dbgcxdef *ctx, int bpnum,
const textchar_t *cond, int change,
char *errbuf, size_t errbuflen)
{
int err;
/* try setting the condition */
err = dbgbpsetcond(ctx, bpnum, (textchar_t *)cond);
/* if that failed, get the error text into the message buffer */
if (err != 0)
{
char msg[256];
errmsg(ctx->dbgcxerr, msg, sizeof(msg), err);
errfmt(errbuf, errbuflen, msg, 0, 0);
}
/* return the result code */
return err;
}
/*
* Delete a breakpoint given a breakpoint number
*/
int CHtmlDebugHelper::vm_delete_breakpoint(dbgcxdef *ctx, int bpnum)
{
int err;
/* if TADS is running, tell TADS to delete the breakpoint */
if (ctx != 0 && (err = dbgbpdel(ctx, bpnum)) != 0)
return err;
/* delete the internal breakpoint and update the display */
delete_internal_bp(ctx, bpnum);
/* success */
return 0;
}
/*
* Set a breakpoint loaded from a saved configuration. Returns zero on
* success, non-zero on failure. We'll fill in *actual_linenum with the
* line number at which we actually set the breakpoint; this might
* differ from the proposed line number because the source might have
* been modified and recompiled since the configuration was saved, hence
* the lines at which breakpoints are valid might have changed.
*/
int CHtmlDebugHelper::vm_set_loaded_bp(dbgcxdef *dbgctx, int source_id,
unsigned long orig_linenum,
unsigned long *actual_linenum,
const char *cond, int change,
int disabled)
{
objnum line_objn;
uint line_ofs;
/* try putting the breakpoint at the requested location */
*actual_linenum = orig_linenum;
/* get the exact location of the breakpoint */
if (CHtmlDebugHelperVM::srcofs_to_code(dbgctx, source_id, actual_linenum,
&line_objn, &line_ofs))
return 1;
/* set the breakpoint */
if (CHtmlDebugHelperVM::toggle_breakpoint(this, dbgctx, source_id,
*actual_linenum,
line_objn, line_ofs,
cond, TRUE))
return 2;
/* if it's disabled, disable it */
if (disabled)
CHtmlDebugHelperVM::toggle_bp_disable(this, dbgctx, source_id,
*actual_linenum,
line_objn, line_ofs);
/* success */