-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmldb3.cpp
1233 lines (1041 loc) · 34.4 KB
/
htmldb3.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
htmldb3.cpp - debugger helper class - T3 interface
Function
This module contains the helper class interfaces to the T3 VM 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
11/24/99 MJRoberts - Creation
*/
#include <string.h>
/* include the necessary T3 interfaces */
#include "t3std.h"
#include "os.h"
#include "vmglob.h"
#include "vmtype.h"
#include "vmdbg.h"
#include "vmrun.h"
#include "vmconsol.h"
#include "vmerr.h"
#include "vmerrnum.h"
#include "vmsrcf.h"
#include "vmerr.h"
#include "tcerr.h"
/* include some HTML TADS headers */
#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
/* ------------------------------------------------------------------------ */
/*
* dbgcxdef structure. We define this structure for interface
* compatibility with debugger UI's designed for TADS 2. This is NOT
* the same structure as used in the TADS 2 debugger engine, so the
* underlying UI code must not attempt to access the interior of this
* structure.
*/
struct dbgcxdef
{
/* pointer to VM global variables */
vm_globals *vmg;
/* underlying user interface context pointer */
void *ui_ctx;
};
/* ------------------------------------------------------------------------ */
/*
* T3 API to the UI. This is the implementation for the HTML TADS
* Debugger for Windows.
*/
/*
* Initialize
*/
void CVmDebugUI::init(VMG_ const char *image_filename)
{
dbgcxdef *ctx;
/* create our private context */
ctx = new dbgcxdef;
/*
* stash the global variable structure pointer in our context
* structure for later use
*/
ctx->vmg = VMGLOB_ADDR;
/*
* tell the UI to initialize, and save the UI context object it
* returns
*/
ctx->ui_ctx = html_dbgui_ini(ctx, image_filename);
/* save our context in the VM debugger object */
G_debugger->set_ui_ctx(ctx);
/* clear the HALT flag in the VM, since we're just starting */
G_interpreter->set_halt_vm(FALSE);
}
/*
* Initialize, phase 2 - after image file loading
*/
void CVmDebugUI::init_after_load(VMG0_)
{
dbgcxdef *ctx;
/* get my private context */
ctx = (dbgcxdef *)G_debugger->get_ui_ctx();
/* tell the UI to finish initialization */
html_dbgui_ini2(ctx, ctx->ui_ctx);
}
/*
* terminate
*/
void CVmDebugUI::terminate(VMG0_)
{
dbgcxdef *ctx;
/* get my private context */
ctx = (dbgcxdef *)G_debugger->get_ui_ctx();
/* if there's a valid context, notify the UI */
if (ctx != 0)
{
/* notify the UI that we're shutting down */
html_dbgui_term(ctx, ctx->ui_ctx);
/* delete my context */
delete ctx;
}
/* clear the debugger object's memory of our context */
G_debugger->set_ui_ctx(0);
}
/*
* main command loop entrypoint
*/
void CVmDebugUI::cmd_loop(VMG_ int bpnum, int err,
const uchar **pc)
{
dbgcxdef *ctx;
/* get my private context */
ctx = (dbgcxdef *)G_debugger->get_ui_ctx();
/* invoke the command loop in the UI */
html_dbgui_cmd(ctx, ctx->ui_ctx, bpnum, err, pc);
}
/* ------------------------------------------------------------------------ */
/*
* 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:
/* find the code address of the current source window's selection */
static int srcofs_to_code(CHtmlDebugHelper *helper, dbgcxdef *ctx,
IDebugWin *win, ulong *linenum,
CHtmlDbg_win_link **win_link,
void *code_addr);
/* find the code address of a given source file location */
static int srcofs_to_code(dbgcxdef *ctx,
int source_id, ulong *linenum,
void *code_addr);
/* toggle a breakpoint */
static int toggle_breakpoint(CHtmlDebugHelper *helper, dbgcxdef *ctx,
int source_id, unsigned long linenum,
void *code_addr,
const char *cond, int change,
int set_only, int set_internal_bp,
int *bpnum, int *did_set);
/* toggle a breakpoint's disabled status */
static void toggle_bp_disable(CHtmlDebugHelper *helper,
dbgcxdef *ctx,
int source_id, unsigned long linenum,
void *code_addr);
};
/*
* Find the code address of the current source window's selection
*/
int CHtmlDebugHelperVM::
srcofs_to_code(CHtmlDebugHelper *helper, dbgcxdef *ctx,
IDebugWin *win, ulong *linenum,
CHtmlDbg_win_link **win_link, void *code_addr)
{
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, code_addr);
}
/*
* Find the code address of a given source file location
*/
int CHtmlDebugHelperVM::srcofs_to_code(dbgcxdef *ctx,
int source_id, ulong *linenum,
void *code_addr)
{
CVmSrcfEntry *entry;
/* if there's no context, we can't do anything */
if (ctx == 0)
{
*(const uchar **)code_addr = 0;
return 0;
}
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* get the source file entry for the given source ID */
entry = G_srcf_table->get_entry(source_id);
/* if we didn't get an entry, return failure */
if (entry == 0)
return 1;
/* find the line record, and get the code pool offset */
ulong ofs = entry->find_src_addr(linenum, FALSE);
/* if we didn't find the line, return failure */
if (ofs == 0)
return 1;
/* translate the offset to a code pool address */
*(const uchar **)code_addr = (const uchar *)G_code_pool->get_ptr(ofs);
/* success */
return 0;
}
/*
* 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,
void *code_addr,
const char *cond, int change,
int set_only,
int set_internal_bp,
int *bpnum, int *did_set)
{
/*
* 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 up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the breakpoint in the VM */
if (G_debugger->toggle_breakpoint(vmg_ (const uchar *)code_addr,
cond, change,
bpnum, did_set, 0, 0))
return 3;
}
else
{
/* the engine isn't running; synthesize a breakpoint ID */
*bpnum = helper->synthesize_bp_num();
*did_set = TRUE;
}
/*
* If the caller wants us to, toggle the internal breakpoint record
* so we show the breakpoint visually
*/
if (set_internal_bp)
helper->toggle_internal_bp(ctx, source_id, linenum, cond, change,
*bpnum, *did_set, FALSE);
/* success */
return 0;
}
/*
* enable/disable a breakpoint at the given location
*/
void CHtmlDebugHelperVM::toggle_bp_disable(CHtmlDebugHelper *helper,
dbgcxdef *ctx,
int source_id,
unsigned long linenum,
void *code_addr)
{
/*
* if the engine is running, ask it if there's a breakpoint there -
* if not, there's nothing to do
*/
if (ctx != 0)
{
CHtmlDbg_bp *bp;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* find the breakpoint */
bp = helper->find_internal_bp(source_id, linenum);
/* if we found it, toggle the VM breakpoint status */
if (bp != 0)
G_debugger->toggle_breakpoint_disable(vmg_ bp->bpnum_);
}
/* toggle the status of the internal breakpoint record */
helper->toggle_internal_bp_disable(ctx, source_id, linenum);
}
/* ------------------------------------------------------------------------ */
/*
* Flush output to the main game text window
*/
void CHtmlDebugHelper::vm_flush_main_output(dbgcxdef *ctx)
{
/* ignore this if we get called without a context */
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* flush output on the main console */
G_console->flush(vmg_ VM_NL_NONE);
}
}
/* ------------------------------------------------------------------------ */
/*
* Perform engine-specific checks on a newly-loaded a game
*/
void CHtmlDebugHelper::vm_check_loaded_program(dbgcxdef *ctx)
{
/* ignore this if we get called without a context */
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* make sure the program was compiled for debugging */
if (!G_debugger->image_has_debug_info(vmg0_))
err_throw(VMERR_NO_IMAGE_DBG_INFO);
}
}
/* ------------------------------------------------------------------------ */
/*
* 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,
CHtmlDebugSysIfc_win *syswinifc)
{
const char *fname;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* get the file information for the source level */
if (G_debugger->get_source_info(vmg_ &fname, linenum, level))
return 1;
/* get the line source for this filename */
*src = find_internal_src(syswinifc, fname, 0, TRUE);
/* if we didn't find the source file, return failure */
if (*src == 0)
return 2;
/* success */
return 0;
}
/* ------------------------------------------------------------------------ */
/*
* Load line sources from a compiled game program
*/
void CHtmlDebugHelper::vm_load_sources_from_program(dbgcxdef *ctx)
{
size_t i;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* add each line source */
for (i = 0 ; i < G_srcf_table->get_count() ; ++i)
{
CVmSrcfEntry *entry;
/* get this entry */
entry = G_srcf_table->get_entry(i);
/*
* If the entry is a master record, add it to the UI's file
* list. We don't add non-master entries, since we want to show
* each unique source file in the UI only once.
*/
if (entry->is_master())
{
/* add the entry */
add_internal_line_source(entry->get_name(), entry->get_name(), i);
}
}
/* note the highest ID */
last_compiled_line_source_id_ = i;
}
/* ------------------------------------------------------------------------ */
/*
* Set engine execution state to GO
*/
void CHtmlDebugHelper::vm_set_exec_state_go(dbgcxdef *ctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the execution state in the debugger object */
G_debugger->set_go();
}
/*
* Set the engine execution state to BREAK
*/
void CHtmlDebugHelper::vm_set_exec_state_break(dbgcxdef *ctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the execution state in the debugger object */
G_debugger->set_break_stop();
}
/*
* Set engine execution state to STEP OVER
*/
void CHtmlDebugHelper::vm_set_exec_state_step_over(dbgcxdef *ctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the execution state in the debugger object */
G_debugger->set_step_over(vmg0_);
}
/*
* Set engine execution state to STEP OUT
*/
void CHtmlDebugHelper::vm_set_exec_state_step_out(dbgcxdef *ctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the execution state in the debugger object */
G_debugger->set_step_out(vmg0_);
}
/*
* Set engine execution state to STEP INTO
*/
void CHtmlDebugHelper::vm_set_exec_state_step_into(dbgcxdef *ctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the execution state in the debugger object */
G_debugger->set_step_in();
}
/* ------------------------------------------------------------------------ */
/*
* Build a stack listing
*/
void CHtmlDebugHelper::vm_build_stack_listing(dbgcxdef *ctx, void *cbctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* have the debugger object build the stack listing */
G_debugger->build_stack_listing(vmg_ &update_stack_disp_cb, cbctx, FALSE);
}
/* ------------------------------------------------------------------------ */
/*
* Evaluate an expression
*/
int CHtmlDebugHelper::
vm_eval_expr(struct dbgcxdef *ctx, textchar_t *buf, size_t buflen,
const textchar_t *expr, int level,
int *is_lval, int *is_openable,
void (*aggcb)(void *, const char *, int,
const char *), void *aggctx, int speculative)
{
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* go evalute it */
return G_debugger->eval_expr(vmg_ buf, buflen, expr, level, is_lval,
is_openable, aggcb, aggctx, speculative);
}
else
{
/* engine not running - can't evaluate the expression */
buf[0] = '\0';
return 1;
}
}
/*
* Execute an assignment
*/
int CHtmlDebugHelper::vm_eval_asi_expr(dbgcxdef *ctx, int level,
const textchar_t *lvalue,
const textchar_t *rvalue)
{
textchar_t asi_expr[2048];
textchar_t result[10];
/* build the assignment expression */
sprintf(asi_expr, "(%s)=%s", lvalue, rvalue);
/* evaluate the expression */
return vm_eval_expr(ctx, result, sizeof(result), asi_expr, level,
0, 0, 0, 0, FALSE);
}
/*
* Enumerate local variables in the current stack context.
*/
void CHtmlDebugHelper::
vm_enum_locals(dbgcxdef *ctx, int level,
void (*cbfunc)(void *, const textchar_t *, size_t),
void *cbctx)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* have the VM debug object enumerate the locals */
G_debugger->enum_locals(vmg_ cbfunc, cbctx, level);
}
/* ------------------------------------------------------------------------ */
/*
* Toggle a breakpoint at the current selection in the given window
*/
void CHtmlDebugHelper::vm_toggle_breakpoint(dbgcxdef *ctx, IDebugWin *win)
{
ulong linenum;
CHtmlDbg_win_link *win_link;
void *code_addr;
int bpnum;
int did_set;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win,
&linenum, &win_link, &code_addr))
return;
/* toggle a breakpoint at the location we found */
CHtmlDebugHelperVM::toggle_breakpoint(this, ctx, win_link->source_id_,
linenum, code_addr, 0, FALSE,
FALSE, TRUE, &bpnum, &did_set);
}
/*
* Set a temporary breakpoint at the current selection in the given
* window. Returns true if successful, false if we didn't set the
* breakpoint.
*/
int CHtmlDebugHelper::vm_set_temp_bp(dbgcxdef *ctx, IDebugWin *win)
{
ulong linenum;
CHtmlDbg_win_link *win_link;
void *code_addr;
int did_set;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win,
&linenum, &win_link, &code_addr))
return FALSE;
/*
* if there's already a breakpoint there, we don't need to set
* another one
*/
if (find_internal_bp(win_link->source_id_, linenum) != 0)
return FALSE;
/* toggle a breakpoint at the location we found */
if (CHtmlDebugHelperVM::toggle_breakpoint(this, ctx, win_link->source_id_,
linenum, code_addr, 0, FALSE,
FALSE, FALSE,
&tmp_bpnum_, &did_set))
return FALSE;
/* success */
return TRUE;
}
/*
* Clear a temporary breakpoint
*/
void CHtmlDebugHelper::vm_clear_temp_bp(dbgcxdef *ctx)
{
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* toggle the temporary breakpoint */
G_debugger->delete_breakpoint(vmg_ tmp_bpnum_);
/* forget the temporary breakpoint */
tmp_bpnum_ = 0;
}
}
/*
* 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)
{
if (ctx != 0)
{
int did_set;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* set the breakpoint in the VM */
if (G_debugger->toggle_breakpoint(vmg_ 0, cond, change, bpnum,
&did_set, errbuf, errbuflen))
return 3;
}
else
{
/* the engine isn't running; synthesize a breakpoint ID */
*bpnum = synthesize_bp_num();
}
/* set the internal breakpoint record */
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;
void *code_addr;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &linenum,
&win_link, &code_addr))
return;
/* toggle the status */
CHtmlDebugHelperVM::toggle_bp_disable(this, ctx, win_link->source_id_,
linenum, code_addr);
}
/*
* Enable or disable a breakpoint
*/
int CHtmlDebugHelper::vm_enable_breakpoint(dbgcxdef *ctx, int bpnum,
int enable)
{
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* ask the VM to the do work */
G_debugger->set_breakpoint_disable(vmg_ bpnum, !enable);
/* success */
return 0;
}
else
{
/* engine not active - return failure */
return 1;
}
}
/*
* Determine if a breakpoint is enabled
*/
int CHtmlDebugHelper::vm_is_bp_enabled(dbgcxdef *ctx, int bpnum)
{
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* ask the VM about the breakpoint */
return !G_debugger->is_breakpoint_disabled(vmg_ bpnum);
}
else
{
/* engine not active - return enabled by default */
return TRUE;
}
}
/*
* Set a breakpoint's condition text
*/
int CHtmlDebugHelper::vm_set_bp_condition(dbgcxdef *ctx, int bpnum,
const textchar_t *cond,
int change,
char *errbuf, size_t errbuflen)
{
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* ask the VM to the do work */
return G_debugger
->set_breakpoint_condition(vmg_ bpnum, cond, change,
errbuf, errbuflen);
}
else
{
/* engine isn't running - fail */
strncpy(errbuf, "The program is not running.", errbuflen - 1);
errbuf[errbuflen - 1] = '\0';
return 1;
}
}
/*
* Delete a breakpoint given a breakpoint number
*/
int CHtmlDebugHelper::vm_delete_breakpoint(dbgcxdef *ctx, int bpnum)
{
/* delete the VM breakpoint if the engine is running */
if (ctx != 0)
{
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* ask the VM to delete the breakpoint */
G_debugger->delete_breakpoint(vmg_ bpnum);
}
/* delete the internal breakpoint tracker 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)
{
void *code_addr;
int bpnum;
int did_set;
/* 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,
&code_addr))
return 1;
/* set the breakpoint */
if (CHtmlDebugHelperVM::toggle_breakpoint(this, dbgctx, source_id,
*actual_linenum, code_addr,
cond, change, TRUE, TRUE,
&bpnum, &did_set))
return 2;
/* if it's disabled, disable it */
if (disabled)
CHtmlDebugHelperVM::toggle_bp_disable(this, dbgctx, source_id,
*actual_linenum, code_addr);
/* success */
return 0;
}
/* ------------------------------------------------------------------------ */
/*
* Move the execution position in the engine to the current selection in
* the given window. Returns zero on success, non-zero on failure.
* This only works for setting the line location within the currently
* executing function.
*/
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;
const uchar *code_addr;
/* we can't do anything if the engine isn't running */
if (ctx == 0)
return 1;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, linenum,
&win_link, &code_addr))
return 2;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* ask the VM to make the change */
if (G_debugger->set_exec_ofs((const uchar **)exec_ofs, code_addr))
return 3;
/* T3 doesn't require any stepping after a location change */
*need_single_step = FALSE;
/* success */
return 0;
}
/*
* Is the given line executable?
*/
int CHtmlDebugHelper::vm_is_line_executable(struct dbgcxdef *ctx,
IDebugWin *win)
{
CHtmlDbg_win_link *win_link;
unsigned long src_linenum, code_linenum;
CHtmlDbg_line_link *line_link;
unsigned long code_addr;
/* 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, &code_addr))
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 linenum;
const uchar *code_addr;
/* we can't do anything if the engine isn't running */
if (ctx == 0)
return FALSE;
/* find information on the current line in the window */
if (CHtmlDebugHelperVM::srcofs_to_code(this, ctx, win, &linenum,
&win_link, &code_addr))
return FALSE;
/* set up for VM global access */
VMGLOB_PTR(ctx->vmg);
/* let the engine make the determination */
return G_debugger->is_in_current_method(vmg_ code_addr);
}
/* ------------------------------------------------------------------------ */
/*
* Get the text of an error message
*/
void CHtmlDebugHelper::vm_get_error_text(struct dbgcxdef *ctx, int err,
textchar_t *buf, size_t buflen)
{
const char *txt;
char dflt[50];
/* look up the message in the run-time messages */
txt = err_get_msg(vm_messages, vm_message_count, err, FALSE);
/* try the compiler messages if we didn't find anything */
if (txt == 0)
txt = err_get_msg(tc_messages, tc_message_count, err, FALSE);
/* if we didn't find the message, provide a generic default */
if (txt == 0)
{
/* build the generic message based on the error number */
sprintf(dflt, "VM Error %d", err);