Subversion Repositories Kolibri OS

Rev

Rev 4886 | Rev 4893 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4886 hidnplayr 1
COLOR_THEME fix BLACK_ON_WHITE
4591 hidnplayr 2
 
3
 
4
format binary as ""
542 diamond 5
include '../../macros.inc'
205 heavyiron 6
use32
3675 GerdtR 7
        db      'MENUET01'
8
        dd      1
9
        dd      start
10
        dd      i_end
11
        dd      used_mem
12
        dd      used_mem
13
        dd      i_param
14
        dd      0
205 heavyiron 15
 
3675 GerdtR 16
;-----------------------------------------------------------------------------
17
 
18
REG_MODE_CPU equ 1
19
REG_MODE_MMX equ 2
20
REG_MODE_SSE equ 3
21
REG_MODE_AVX equ 4
22
 
23
;-----------------------------------------------------------------------------
24
 
25
include 'gui.inc' ; GUI routines
26
 
27
;-----------------------------------------------------------------------------
28
;                          Find command in list
29
 
30
find_cmd:
31
; all commands are case-insensitive
32
        push    edi
33
 
34
    .x4:
35
        mov     al, [edi]
36
        cmp     al, 0
37
        jz      .x5
38
        cmp     al, 'A'
39
        jb      @f
40
        cmp     al, 'Z'
41
        ja      @f
42
        or      al, 20h
43
 
44
    @@:
45
        stosb
46
        jmp     .x4
47
 
48
    ; find command
49
    .x5:
50
        pop     edi
51
 
52
    .x6:
53
        cmp     dword [esi], 0
54
        jz      .x7
55
        push    esi
56
        mov     esi, [esi]
57
        lodsb
58
        movzx   ecx, al
59
        push    edi
60
        repz cmpsb
61
        pop     edi
62
        pop     esi
63
        jz      .x8
64
        add     esi, 17
65
        jmp     .x6
66
 
67
    .x7:
68
        stc
69
 
70
    .x8:
71
        ret
72
 
205 heavyiron 73
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3675 GerdtR 74
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEBUGGING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
205 heavyiron 75
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76
 
3675 GerdtR 77
;-----------------------------------------------------------------------------
78
;                                 Help event
205 heavyiron 79
 
3675 GerdtR 80
OnHelp:
81
        mov     esi, help_msg
82
        mov     edi, [curarg]
83
        cmp     byte [edi], 0
84
        jz      .x
85
        mov     esi, help_groups
86
        call    find_cmd
87
        jc      .nocmd
88
        mov     esi, [esi+12]
205 heavyiron 89
 
3675 GerdtR 90
    .x:
91
        jmp     put_message
205 heavyiron 92
 
3675 GerdtR 93
    .nocmd:
94
        mov     esi, aUnknownCommand
95
        jmp     .x
205 heavyiron 96
 
3675 GerdtR 97
;-----------------------------------------------------------------------------
98
;                                Quit event
99
OnQuit:
100
        mcall  -1
205 heavyiron 101
 
3675 GerdtR 102
;-----------------------------------------------------------------------------
103
;                        Working with debug context
205 heavyiron 104
 
3675 GerdtR 105
get_new_context:
106
        mov     esi, context
107
        mov     edi, oldcontext
108
        mov     ecx, 10
109
        rep movsd
205 heavyiron 110
 
3675 GerdtR 111
get_context:
112
        ;push    1
113
        ;pop     ebx
114
        ;push    69
115
        ;pop     eax
116
        ;mov     ecx, [debuggee_pid]
117
        ;mov     esi, context
118
        ;push    28h
119
        ;pop     edx
120
        mcall    69, 1, [debuggee_pid], 28h, context
121
        ret
205 heavyiron 122
 
3675 GerdtR 123
set_context:
124
        ;push    2
125
        ;pop     ebx
126
        ;push    69
127
        ;pop     eax
128
        ;mov     ecx, [debuggee_pid]
129
        ;mov     esi, context
130
        ;push    28h
131
        ;pop     edx
132
        mcall    69, 2, [debuggee_pid], 28h, context
133
        ret
205 heavyiron 134
 
3675 GerdtR 135
get_dump:
136
        mov     edi, dumpdata
137
        mov     esi, [edi-4]
138
        mov     edx, dump_height*10h
139
        mov     ecx, edx
140
        xor     eax, eax
141
        push    edi
142
        rep stosb
143
        pop     edi
144
        ;mov     ecx, [debuggee_pid]
145
        ;mov     al, 69
146
        ;push    6
147
        ;pop     ebx
148
        mcall    69, 6, [debuggee_pid]
149
        cmp     eax, -1
150
        jnz     @f
151
        mov     esi, read_mem_err
152
        call    put_message
153
        xor     eax, eax
205 heavyiron 154
 
3675 GerdtR 155
    @@:
156
        mov     [edi-8], eax
157
;       call    restore_from_breaks
158
;       ret
205 heavyiron 159
 
3675 GerdtR 160
; in: edi=buffer,eax=size,esi=address
161
restore_from_breaks:
162
        mov     ebx, breakpoints
205 heavyiron 163
 
3675 GerdtR 164
    @@:
165
        test    byte [ebx+4], 1
166
        jz      .cont           ; ignore invalid
167
        test    byte [ebx+4], 2 or 8
168
        jnz     .cont           ; ignore disabled and memory breaks
169
        mov     ecx, [ebx]
170
        sub     ecx, esi
171
        cmp     ecx, eax
172
        jae     .cont
173
        mov     dl, [ebx+5]
174
        mov     [edi+ecx], dl
205 heavyiron 175
 
3675 GerdtR 176
    .cont:
177
        add     ebx, 6
178
        cmp     ebx, breakpoints+breakpoints_n*6
179
        jb      @b
180
        ret
205 heavyiron 181
 
3675 GerdtR 182
;-----------------------------------------------------------------------------
183
;                           Load executable event
205 heavyiron 184
 
3675 GerdtR 185
OnLoad:
186
        mov     esi, [curarg]
205 heavyiron 187
 
3675 GerdtR 188
OnLoadInit:
189
        mov     edi, loadname
190
        or      [prgname_len], -1
191
        mov     [prgname_ptr], edi
205 heavyiron 192
 
3675 GerdtR 193
    .copyname:
194
        lodsb
195
        stosb
196
        inc     [prgname_len]
197
        cmp     al, '/'
198
        jnz     @f
199
        or      [prgname_len], -1
200
        mov     [prgname_ptr], edi
205 heavyiron 201
 
3675 GerdtR 202
    @@:
203
        cmp     al, ' '
204
        ja      .copyname
205
        mov     byte [edi-1], 0
206
        and     [load_params], 0
207
        dec     esi
208
        call    get_arg.skip_spaces
209
        cmp     al, 0
210
        jz      @f
211
        mov     [load_params], esi
205 heavyiron 212
 
3675 GerdtR 213
    @@:
214
        and     [dumppos], 0
215
        mov     ecx, [symbols]
216
        jecxz   do_reload
217
        mcall   68, 13
218
        and     [symbols], 0
219
        and     [num_symbols], 0
205 heavyiron 220
 
3675 GerdtR 221
; TODO: make it local
222
do_reload:
223
        ;push    18
224
        ;pop     eax
225
        ;push    7
226
        ;pop     ebx
227
        mcall    18, 7
228
        mov     [dbgwnd], eax
229
        xchg    ecx, eax
230
        ;push    70
231
        ;pop     eax
232
        ;mov     ebx, fn70_load_block
233
        mcall    70, fn70_load_block
234
        test    eax, eax
235
        jns     .load_ok
205 heavyiron 236
 
3675 GerdtR 237
    .load_err:
238
        push    eax
239
        mov     esi, load_err_msg
240
        call    put_message
241
        pop     eax
242
        not     eax
243
        cmp     eax, 0x20
244
        jae     .unk_err
245
        mov     esi, [load_err_msgs+eax*4]
246
        test    esi, esi
247
        jnz     put_message
205 heavyiron 248
 
3675 GerdtR 249
    .unk_err:
250
        mov     esi, unk_err_msg
251
        inc     eax
252
        push    eax
253
        call    put_message_nodraw
254
        jmp     draw_messages
205 heavyiron 255
 
3675 GerdtR 256
    .load_ok:
257
        mov     [debuggee_pid], eax
258
        mov     [bSuspended], 1
259
        push    ecx
260
        call    get_context
261
        mov     edi, oldcontext
262
        mov     ecx, 10
263
        rep movsd
205 heavyiron 264
 
3675 GerdtR 265
    ; activate debugger window
266
        pop     ecx
267
        ;mov     bl, 3
268
        ;push    18
269
        ;pop     eax
270
        mcall    18, 3
271
        call    redraw_title
272
        call    draw_registers.redraw
273
    ; read and draw dump of memory
274
        call    get_dump
275
        call    draw_dump.redraw
276
        call    update_disasm_eip_force
277
        mov     esi, load_succ_msg
278
        push    [debuggee_pid]
279
        call    put_message_nodraw
280
        call    draw_messages
281
    ; try to load symbols
282
        mov     esi, loadname
283
        mov     edi, symbolsfile
284
        push    edi
205 heavyiron 285
 
3675 GerdtR 286
    @@:
287
        lodsb
288
        stosb
289
        test    al, al
290
        jnz     @b
291
        lea     ecx, [edi-1]
205 heavyiron 292
 
3675 GerdtR 293
    @@:
294
        dec     edi
295
        cmp     edi, symbolsfile
296
        jb      @f
297
        cmp     byte [edi], '/'
298
        jz      @f
299
        cmp     byte [edi], '.'
300
        jnz     @b
301
        mov     ecx, edi
205 heavyiron 302
 
3675 GerdtR 303
    @@:
4886 hidnplayr 304
        mov     dword[ecx], '.dbg'
305
        mov     byte[ecx+4], 0
3675 GerdtR 306
        pop     esi
307
        mov     ebp, esi
4886 hidnplayr 308
        push    ecx esi
309
        call    OnLoadSymbols.silent            ; Try to load .dbg file
310
        pop     esi ecx
311
        xor     eax, eax
312
        cmp     [num_symbols], eax
313
        jne     @f
314
        mov     dword[ecx], '.map'              ; If failed, try .map file too
3675 GerdtR 315
        call    OnLoadSymbols.silent
4886 hidnplayr 316
    @@:
317
 
3675 GerdtR 318
    ; now test for packed progs
319
        cmp     [disasm_buf_size], 100h
320
        jz      @f
321
        ret
205 heavyiron 322
 
3675 GerdtR 323
    @@:
324
        mov     esi, mxp_nrv_sig
325
        mov     ebp, disasm_buffer
326
        mov     edi, ebp
327
        push    3
328
        pop     ecx
329
        repz cmpsb
330
        jnz     .not_mxp_nrv
331
        cmpsb
332
        mov     cl, mxp_nrv_sig_size-4
333
        repz cmpsb
334
        mov     esi, mxp_nrv_name
335
        jz      .packed
205 heavyiron 336
 
3675 GerdtR 337
    .not_mxp_nrv:
338
        mov     esi, mxp_sig
339
        mov     edi, ebp
340
        mov     cl, mxp_sig_size
341
        repz cmpsb
342
        mov     esi, mxp_name
343
        jz      .packed
205 heavyiron 344
 
3675 GerdtR 345
    .not_mxp:
346
        mov     esi, mxp_lzo_sig1
347
        mov     edi, ebp
348
        mov     cl, mxp_lzo_sig1_size
349
        repz cmpsb
350
        mov     esi, mxp_lzo_name
351
        jz      .packed
352
        mov     esi, mxp_lzo_sig2
353
        mov     edi, ebp
354
        mov     cl, 8
355
        repz cmpsb
356
        jnz     .not_mxp_lzo
357
        cmpsb
358
        mov     cl, mxp_lzo_sig2_size - 9
359
        repz cmpsb
360
        mov     esi, mxp_lzo_name
361
        jz      .packed
205 heavyiron 362
 
3675 GerdtR 363
    .not_mxp_lzo:
364
        mov     esi, mtappack_name
365
        cmp     dword [ebp], 0xBF5E246A
366
        jnz     .not_mtappack
367
        cmp     dword [ebp+8], 0xEC4E8B57
368
        jnz     .not_mtappack1
369
        cmp     dword [ebp+12], 0x8D5EA4F3
370
        jnz     .not_mtappack1
371
        cmp     byte [ebp+12h], 0xE9
372
        jz      .packed
373
 
374
    .not_mtappack1:
375
        cmp     word [ebp+8], 0xB957
376
        jnz     .not_mtappack
377
        cmp     dword [ebp+14], 0x575EA4F3
378
        jnz     .not_mtappack2
379
        cmp     byte [ebp+17h], 0xE9
380
        jz      .packed
381
 
382
    .not_mtappack2:
383
        cmp     dword [ebp+14], 0x5F8DA4F3
384
        jnz     .not_mtappack3
385
        cmp     word [ebp+18], 0xE9FC
386
        jz      .packed
387
 
388
    .not_mtappack3:
389
        cmp     word [ebp+14], 0xA4F3
390
        jnz     .not_mtappack
391
        cmp     byte [ebp+15h], 0xE9
392
        jz      .packed
393
 
394
    .not_mtappack:
395
        ret
396
 
397
    .packed:
398
        push    esi
399
        mov     esi, aPacked1
400
        call    put_message_nodraw
401
        pop     esi
402
        call    put_message_nodraw
403
        mov     esi, aPacked2
404
        call    put_message
405
        call    hide_cursor
406
        ;push    40
407
        ;pop     eax
408
        ;push    7
409
        ;pop     ebx
410
        mcall    40, 7
411
 
412
    .wait:
413
        ;push    10
414
        ;pop     eax
415
        mcall    10
416
        dec     eax
417
        jz      .redraw
418
        dec     eax
419
        jz      .key
420
        or      eax, -1
421
        mcall
422
 
423
    .redraw:
424
        call    draw_window
425
        call    hide_cursor
426
        jmp     .wait
427
 
428
    .key:
429
        mov     al, 2
430
        mcall
431
        cmp     ah, 'y'
432
        jz      .yes
433
        cmp     ah, 'Y'
434
        jz      .yes
435
        cmp     ah, 0xD
436
        jz      .yes
437
        cmp     ah, 'n'
438
        jz      .no
439
        cmp     ah, 'N'
440
        jnz     .wait
441
 
442
    .no:
443
        ;push    40
444
        ;pop     eax
445
        ;mov     ebx, 0x107
446
        mcall    40, 0x107
447
        call    draw_cursor
448
        mov     esi, aN_str
449
        jmp     put_message
450
 
451
    .yes:
452
        ;push    40
453
        ;pop     eax
454
        ;mov     ebx, 0x107
455
        mcall    40, 0x107
456
        call    draw_cursor
457
        mov     esi, aY_str
458
        call    put_message
459
        call    OnUnpack
460
        ret
461
 
462
;-----------------------------------------------------------------------------
463
;                       Searching signatures
464
 
205 heavyiron 465
mxp_nrv_sig:
3675 GerdtR 466
        xor     eax, eax
467
        mov     ecx, 0x95       ; 0xA1 for programs with parameters
468
        mov     [eax], ecx
469
        add     ecx, [eax+24h]
470
        push    40h
471
        pop     esi
472
        mov     edi, [eax+20h]
473
        push    edi
474
        rep movsb
475
        jmp     dword [esp]
476
        pop     esi
477
        add     esi, [eax]
478
        xor     edi, edi
479
 
205 heavyiron 480
mxp_nrv_sig_size = $ - mxp_nrv_sig
481
 
482
mxp_sig:
3675 GerdtR 483
        mov     ecx, 1CBh
484
        push    46h
485
        pop     esi
486
        mov     edi, [20h]
487
        rep movsb
488
        mov     ecx, [24h]
489
        rep movsb
490
        jmp     dword [20h]
491
        mov     eax, [20h]
492
        add     eax, 1CBh
493
        push    eax
494
        push    dword [24h]
495
        push    0
496
        push    8
497
        call    $+0x25
498
 
205 heavyiron 499
mxp_sig_size = $ - mxp_sig
500
 
501
mxp_lzo_sig1:
3675 GerdtR 502
        xor     eax, eax
503
        mov     ebp, 0FFh
504
        mov     ecx, 175h
505
        mov     [eax], ecx
506
        add     ecx, [eax+24h]
507
        push    45h
508
        pop     esi
509
        mov     edi, [eax+20h]
510
        push    edi
511
        rep movsb
512
        jmp     dword [esp]
513
        pop     ebx
514
        add     ebx, [eax]
515
        xor     edi, edi
516
        cmp     byte [ebx], 11h
517
        jbe     $+0x1A
518
 
205 heavyiron 519
mxp_lzo_sig1_size = $ - mxp_lzo_sig1
3675 GerdtR 520
 
205 heavyiron 521
mxp_lzo_sig2:
3675 GerdtR 522
        xor     eax, eax
523
        mov     ebp, 0FFh
524
        mov     ecx, 188h       ; or 177h
525
        mov     [eax], ecx
526
        add     ecx, [eax+24h]
527
        push    44h
528
        pop     esi
529
        mov     edi, [eax+20h]
530
        rep movsb
531
        jmp     dword [eax+20h]
532
        mov     ebx, [eax+20h]
533
        add     ebx, [eax]
534
 
205 heavyiron 535
mxp_lzo_sig2_size = $ - mxp_lzo_sig2
536
 
3675 GerdtR 537
;-----------------------------------------------------------------------------
538
;                         Reload executable event
539
 
205 heavyiron 540
OnReload:
3675 GerdtR 541
        cmp     [debuggee_pid], 0
542
        jnz     terminate_reload
543
        mov     esi, need_debuggee
544
        cmp     byte [loadname], 0
545
        jnz     do_reload
546
        jz      put_message
547
 
548
; TODO: make it local
205 heavyiron 549
terminate_reload:
3675 GerdtR 550
        mov     [bReload], 1
551
 
552
;-----------------------------------------------------------------------------
553
;                        Terminate process event
554
 
205 heavyiron 555
OnTerminate:
3675 GerdtR 556
        ;mov     ecx, [debuggee_pid]
557
        ;push    8
558
        ;pop     ebx
559
        ;push    69
560
        ;pop     eax
561
        mcall    69, 8, [debuggee_pid]
562
        ret
563
;-----------------------------------------------------------------------------
564
;                         Suspend process event
205 heavyiron 565
 
566
AfterSuspend:
3675 GerdtR 567
        mov     [bSuspended], 1
568
        call    get_new_context
569
        call    get_dump
570
        call    redraw_title
571
        call    draw_registers.redraw
572
        call    draw_dump.redraw
573
        call    update_disasm_eip
574
        ret
205 heavyiron 575
 
576
OnSuspend:
3675 GerdtR 577
        ;mov     ecx, [debuggee_pid]
578
        ;push    4
579
        ;pop     ebx
580
        ;push    69
581
        ;pop     eax
582
        mcall    69, 4, [debuggee_pid]
583
        call    AfterSuspend
584
        mov     esi, aSuspended
585
        jmp     put_message
586
 
587
;-----------------------------------------------------------------------------
588
;                        Resume process event
589
 
205 heavyiron 590
DoResume:
3675 GerdtR 591
        ;mov     ecx, [debuggee_pid]
592
        ;push    5
593
        ;pop     ebx
594
        ;push    69
595
        ;pop     eax
596
        mcall    69, 5, [debuggee_pid]
597
        mov     [bSuspended], 0
598
        ret
599
 
205 heavyiron 600
OnResume:
3675 GerdtR 601
        mov     esi, [curarg]
602
        cmp     byte [esi], 0
603
        jz      GoOn
604
        call    calc_expression
605
        jc      .ret
606
        mov     eax, ebp
607
        push    eax
608
        call    find_enabled_breakpoint
609
        pop     eax
610
        jz      GoOn
611
        mov     bl, 5   ; valid enabled one-shot
612
        call    add_breakpoint
613
        jnc     GoOn
614
        mov     esi, aBreakpointLimitExceeded
615
        call    put_message
616
 
617
    .ret:
618
        ret
619
 
205 heavyiron 620
GoOn:
3675 GerdtR 621
    ; test for enabled breakpoint at eip
622
        mov     eax, [_eip]
623
        call    find_enabled_breakpoint
624
        jnz     .nobreak
625
    ; temporarily disable breakpoint, make step, enable breakpoint, continue
626
        inc     eax
627
        mov     [temp_break], eax
628
        mov     [bAfterGo], 1
629
        dec     eax
630
        call    disable_breakpoint
631
        call    get_context
632
        or      byte [_eflags+1], 1             ; set TF
633
        call    set_context
634
        and     byte [_eflags+1], not 1
635
        call    DoResume
636
        ret
637
 
638
    .nobreak:
639
        call    DoResume
640
        call    redraw_title
641
        call    draw_registers.redraw
642
        call    draw_dump.redraw
643
        ret
644
 
645
;-----------------------------------------------------------------------------
646
;                        Detach process event
647
 
205 heavyiron 648
OnDetach:
3675 GerdtR 649
        ;mov     ecx, [debuggee_pid]
650
        ;push    3
651
        ;pop     ebx
652
        ;push    69
653
        ;pop     eax
654
        mcall    69, 3, [debuggee_pid]
655
        and     [debuggee_pid], 0
656
        call    redraw_title
657
        call    draw_registers.redraw
658
        call    draw_dump.redraw
659
        call    free_symbols
660
        mov     esi, aContinued
661
        jmp     put_message
205 heavyiron 662
 
663
after_go_exception:
3675 GerdtR 664
        push    eax
665
        mov     eax, [temp_break]
666
        dec     eax
667
        push    esi
668
        call    enable_breakpoint
669
    ; in any case, clear TF and RF
670
        call    get_new_context
671
        and     [_eflags], not 10100h           ; clear TF,RF
672
        call    set_context
673
        xor     edx, edx
674
        mov     [temp_break], edx
675
        xchg    dl, [bAfterGo]
676
        pop     esi
677
        pop     eax
678
        cmp     dl, 2
679
        jnz     @f
680
        lodsd
681
        push    esi
682
        call    get_dump
683
        jmp     exception.done
205 heavyiron 684
 
3675 GerdtR 685
    @@:
686
        test    eax, eax
687
        jz      .notint1
688
    ; if exception is result of single step, simply ignore it and continue
689
        test    dword [esi], 0xF
690
        jnz     dbgmsgstart.5
691
        lodsd
692
        push    esi
693
        mov     esi, oldcontext
694
        mov     edi, context
695
        mov     ecx, 28h/4
696
        rep movsd
697
        call    DoResume
698
        jmp     dbgmsgend
699
 
700
    .notint1:
701
    ; in other case, work as without temp_break
702
        lodsd
703
        push    esi
704
        push    eax
705
        jmp     exception.4
706
 
707
    .notour:
708
 
709
; TODO: split it out
205 heavyiron 710
debugmsg:
3675 GerdtR 711
        neg     [dbgbufsize]
712
        mov     esi, dbgbuf
713
 
714
; TODO: make it local
205 heavyiron 715
dbgmsgstart:
3675 GerdtR 716
        lodsd
717
;       push    eax esi
718
;       push    dword [esi]
719
;       mov     esi, dbgmsg_str
720
;       call    put_message_nodraw
721
;       pop     esi eax
722
        add     esi, 4
723
        dec     eax
724
        jz      exception
725
        dec     eax
726
        jz      terminated
727
        mov     [bSuspended], 1
728
        cmp     [bAfterGo], 0
729
        jnz     after_go_exception
730
        push    esi
731
        call    get_new_context
732
        and     [_eflags], not 10100h           ; clear TF,RF
733
        call    set_context
734
        pop     esi
735
 
736
    ; TODO: WTF? Need for meaning label names
737
    .5:
738
        push    esi
739
        call    get_dump
740
        pop     esi
741
        lodsd
742
        xor     ecx, ecx
743
 
744
    .6:
745
        bt      eax, ecx
746
        jnc     .7
747
        mov     ebx, [drx_break+ecx*4]
748
        test    ebx, ebx
749
        jz      .7
750
        pushad
751
        dec     ebx
752
        push    ebx
753
        mov     esi, aBreakStop
754
        call    put_message_nodraw
755
        popad
756
 
757
    .7:
758
        inc     ecx
759
        cmp     cl, 4
760
        jb      .6
761
        push    esi
762
        jmp     exception.done_draw
763
 
764
; TODO: make it local
205 heavyiron 765
terminated:
3675 GerdtR 766
        push    esi
767
        mov     esi, terminated_msg
768
        call    put_message
769
        and     [debuggee_pid], 0
770
        and     [temp_break], 0
771
        mov     [bAfterGo], 0
772
        xor     eax, eax
773
        mov     ecx, breakpoints_n*6/4+4
774
        mov     edi, breakpoints
775
        rep stosd
776
        cmp     [bReload], 1
777
        sbb     [bReload], -1
778
        jnz     exception.done
779
        call    free_symbols
780
        jmp     exception.done
781
 
205 heavyiron 782
exception:
3675 GerdtR 783
        mov     [bSuspended], 1
784
        cmp     [bAfterGo], 0
785
        jnz     after_go_exception
786
        lodsd
787
        push    esi
788
        push    eax
789
        call    get_new_context
790
        and     [_eflags], not 10100h           ; clear TF,RF
791
        call    set_context
792
 
793
    ; TODO: fix for useful name
794
    .4:
795
        call    get_dump
796
        pop     eax
797
    ; int3 command generates exception 0D, #GP
798
        push    eax
799
        cmp     al, 0Dh
800
        jnz     .notdbg
801
    ; check for 0xCC byte at eip
802
        push    0
803
        ;push    69
804
        ;pop     eax
805
        ;push    6
806
        ;pop     ebx
807
        ;mov     ecx, [debuggee_pid]
808
        ;mov     edi, esp
809
        ;mov     esi, [_eip]
810
        ;push    1
811
        ;pop     edx
812
        mcall    69, 6, [debuggee_pid], 1, [_eip], esp
813
        pop     eax
814
        cmp     al, 0xCC
815
        jnz     .notdbg
816
    ; this is either dbg breakpoint or int3 cmd in debuggee
817
        mov     eax, [_eip]
818
        call    find_enabled_breakpoint
819
        jnz     .user_int3
820
    ; dbg breakpoint; clear if one-shot
821
        pop     ecx
822
        push    eax
823
        mov     esi, aBreakStop
824
        test    byte [edi+4], 4
825
        jz      .put_msg_eax
826
        pop     ecx
827
        call    clear_breakpoint
828
        jmp     .done
829
 
830
    .user_int3:
831
        mov     eax, [_eip]
832
        inc     [_eip]
833
        pop     ecx
834
        push    eax
835
        call    set_context
836
        mov     esi, aUserBreak
837
        jmp     .put_msg_eax
838
 
839
    .notdbg:
840
        mov     esi, aException
841
 
842
    .put_msg_eax:
843
        call    put_message_nodraw
844
 
845
    .done_draw:
846
        call    draw_messages
847
 
848
    .done:
849
        ;push    18
850
        ;pop     eax
851
        ;push    3
852
        ;pop     ebx
853
        ;mov     ecx, [dbgwnd]
854
        mcall    18, 3, [dbgwnd]    ; activate dbg window
855
        call    redraw_title
856
        call    draw_registers.redraw
857
        call    draw_dump.redraw
858
        call    update_disasm_eip
859
 
205 heavyiron 860
dbgmsgend:
3675 GerdtR 861
        pop     esi
862
        mov     ecx, [dbgbuflen]
863
        add     ecx, dbgbuf
864
        cmp     esi, ecx
865
        jnz     dbgmsgstart
866
        and     [dbgbuflen], 0
867
        neg     [dbgbufsize]
868
        cmp     [bReload], 2
869
        jnz     @f
870
        mov     [bReload], 0
871
        call    do_reload
205 heavyiron 872
 
3675 GerdtR 873
    @@:
874
        jmp     waitevent
875
 
876
; TODO: make it local
4590 clevermous 877
F7:
3675 GerdtR 878
        cmp     [debuggee_pid], 0
879
        jz      .no
880
        call    OnStep
881
 
882
    .no:
883
        jmp     waitevent
884
 
885
; TODO: make it local
4590 clevermous 886
F8:
3675 GerdtR 887
        cmp     [debuggee_pid], 0
4590 clevermous 888
        jz      F7.no
3675 GerdtR 889
        call    OnProceed
4590 clevermous 890
        jmp     F7.no
205 heavyiron 891
 
3675 GerdtR 892
;-----------------------------------------------------------------------------
893
;                       Step execution event
894
 
895
;Here we get [] argument at do step  times
4443 clevermous 896
OnStepMultiple:
3675 GerdtR 897
        cmp     [bSuspended], 0
4443 clevermous 898
        jz      OnStep.running
899
        mov     [step_num], 1
3675 GerdtR 900
        mov     esi, [curarg]
4443 clevermous 901
        test    esi, esi
902
        jz      .do
3675 GerdtR 903
        cmp     byte [esi], 0
4443 clevermous 904
        jz      .do
3675 GerdtR 905
        call    get_hex_number
906
        jc      .ret
907
        cmp     eax, 0 ; check if lesser or equal than 0
908
        jle     .ret
909
        mov     [step_num], eax
4443 clevermous 910
.do:
911
        call    OnStep
912
        dec     [step_num]
913
        jnz     .do
914
.ret:
915
        ret
205 heavyiron 916
 
4443 clevermous 917
OnStep:
918
        cmp     [bSuspended], 0
919
        jz      .running
3675 GerdtR 920
        call    get_context
921
        or      byte [_eflags+1], 1             ; set TF
922
        call    set_context
923
        and     byte [_eflags+1], not 1
924
    ; if instruction at eip is "int xx", set one-shot breakpoint immediately after
925
        mov     eax, [_eip]
926
        call    find_enabled_breakpoint
927
        jnz     @f
928
        cmp     byte [edi+5], 0xCD
929
        jz      .int
930
 
931
     @@:
932
        push    0
933
        ;push    69
934
        ;pop     eax
935
        ;push    6
936
        ;pop     ebx
937
        ;mov     ecx, [debuggee_pid]
938
        ;push    3
939
        ;pop     edx
940
        ;mov     edi, esp
941
        ;mov     esi, [_eip]
942
        mcall    69, 6, [debuggee_pid], 3, [_eip], esp
943
        cmp     eax, edx
944
        pop     eax
945
        jnz     .doit
946
        cmp     al, 0xCD
947
        jz      .int
948
        cmp     ax, 0x050F
949
        jz      .syscall
950
        cmp     ax, 0x340F
951
        jz      .sysenter
952
 
953
    ; resume process
954
    .doit:
955
        call    GoOn
956
        cmp     [bAfterGo], 0
957
        jz      @f
958
        mov     [bAfterGo], 2
959
 
960
    @@:
961
        ret
962
 
963
    ; return address is [ebp-4]
964
    .sysenter:
965
        push    0
966
        ;push    69
967
        ;pop     eax
968
        inc     edx     ; read 4 bytes
969
        mov     esi, [_ebp]
970
        sub     esi, 4
971
        mcall    69
972
        cmp     eax, edx
973
        pop     eax
974
        jnz     .syscall
975
        push    eax
976
        and     byte [_eflags+1], not 1
977
        call    set_context
978
        pop     eax
979
        jmp     @f
980
 
981
    .syscall:
982
        and     byte [_eflags+1], not 1 ; clear TF - avoid system halt (!)
983
        call    set_context
984
 
985
    .int:
986
        mov     eax, [_eip]
987
        inc     eax
988
        inc     eax
989
 
990
    @@:
991
        push    eax
992
        call    find_enabled_breakpoint
993
        pop     eax
994
        jz      .doit
995
    ; there is no enabled breakpoint yet; set temporary breakpoint
996
        mov     bl, 5
997
        call    add_breakpoint
998
        jmp     .doit
999
 
1000
    .running:
1001
        mov     esi, aRunningErr
1002
        jmp     put_message
1003
 
1004
;-----------------------------------------------------------------------------
1005
;                       Proceed process event
1006
 
205 heavyiron 1007
OnProceed:
3675 GerdtR 1008
        cmp     [bSuspended], 0
1009
        jz      OnStep.running
1010
        cmp     [proc_num], 0
1011
        jg      .procone
1012
        mov     esi, [curarg]
4285 tserj 1013
        cmp     esi, 0
1014
        jz      .procone
3675 GerdtR 1015
        cmp     byte [esi], 0
1016
        jz      .procone
1017
        call    get_hex_number
1018
        jc      .ret
1019
        cmp     eax, 0 ; check if lesser than 0
1020
        jle     .ret
1021
        mov     [proc_num], eax
1022
        mov     [curarg], 0
205 heavyiron 1023
 
3675 GerdtR 1024
    .procone:
1025
        mov     esi, [_eip]
205 heavyiron 1026
 
3675 GerdtR 1027
    @@:
1028
        call    get_byte_nobreak
4443 clevermous 1029
        jc      OnStep
3675 GerdtR 1030
        inc     esi
1031
    ; skip prefixes
1032
        call    is_prefix
1033
        jz      @b
1034
        cmp     al, 0xE8        ; call
1035
        jnz     @f
1036
        add     esi, 4
1037
        jmp     .doit
205 heavyiron 1038
 
3675 GerdtR 1039
    ; A4,A5 = movs; A6,A7 = cmps
1040
    @@:
1041
        cmp     al, 0xA4
1042
        jb      @f
1043
        cmp     al, 0xA8
1044
        jb      .doit
205 heavyiron 1045
 
3675 GerdtR 1046
    ; AA,AB = stos; AC,AD = lods; AE,AF = scas
1047
    @@:
1048
        cmp     al, 0xAA
1049
        jb      @f
1050
        cmp     al, 0xB0
1051
        jb      .doit
205 heavyiron 1052
 
3675 GerdtR 1053
    ; E0 = loopnz; E1 = loopz; E2 = loop
1054
    @@:
1055
        cmp     al, 0xE0
1056
        jb      .noloop
1057
        cmp     al, 0xE2
1058
        ja      .noloop
1059
        inc     esi
1060
        jmp     .doit
205 heavyiron 1061
 
3675 GerdtR 1062
    ; FF /2 = call
1063
    .noloop:
1064
        cmp     al, 0xFF
4443 clevermous 1065
        jnz     OnStep
3675 GerdtR 1066
        call    get_byte_nobreak
4443 clevermous 1067
        jc      OnStep
3675 GerdtR 1068
        inc     esi
1069
        mov     cl, al
1070
        and     al, 00111000b
1071
        cmp     al, 00010000b
4443 clevermous 1072
        jnz     OnStep
3675 GerdtR 1073
    ; skip instruction
1074
        mov     al, cl
1075
        and     eax, 7
1076
        shr     cl, 6
1077
        jz      .mod0
1078
        jp      .doit
1079
        cmp     al, 4
1080
        jnz     @f
1081
        inc     esi
205 heavyiron 1082
 
3675 GerdtR 1083
    @@:
1084
        inc     esi
1085
        dec     cl
1086
        jz      @f
1087
        add     esi, 3
205 heavyiron 1088
 
3675 GerdtR 1089
    @@:
1090
        jmp     .doit
205 heavyiron 1091
 
3675 GerdtR 1092
    .mod0:
1093
        cmp     al, 4
1094
        jnz     @f
1095
        call    get_byte_nobreak
4443 clevermous 1096
        jc      OnStep
3675 GerdtR 1097
        inc     esi
1098
        and     al, 7
205 heavyiron 1099
 
3675 GerdtR 1100
    @@:
1101
        cmp     al, 5
1102
        jnz     .doit
1103
        add     esi, 4
205 heavyiron 1104
 
3675 GerdtR 1105
    .doit:
1106
    ; insert one-shot breakpoint at esi and resume
1107
        call    get_byte_nobreak
4443 clevermous 1108
        jc      OnStep
3675 GerdtR 1109
        mov     eax, esi
1110
        call    find_enabled_breakpoint
1111
        jz      @f
1112
        mov     eax, esi
1113
        mov     bl, 5
1114
        call    add_breakpoint
1115
        jmp     OnStep.doit
1116
 
1117
    @@:
1118
        mov     eax, [proc_num]
1119
        dec     eax
1120
        cmp     eax, 0
1121
        jle     .ret
1122
        mov     [proc_num], eax
1123
        jmp     .procone
1124
 
1125
    .ret:
1126
        mov     [proc_num], 0
1127
        ret
1128
 
1129
;-----------------------------------------------------------------------------
1130
;                        Read next byte of machine code
1131
 
1132
get_byte_nobreak:
1133
        mov     eax, esi
1134
        call    find_enabled_breakpoint
1135
        jnz     .nobreak
1136
        mov     al, [edi+5]
1137
        clc
1138
        ret
1139
 
1140
    .nobreak:
1141
        ;push    69
1142
        ;pop     eax
1143
        ;push    6
1144
        ;pop     ebx
1145
        ;mov     ecx, [debuggee_pid]
1146
        xor     edx, edx
1147
        push    edx
1148
        inc     edx
1149
        mov     edi, esp
1150
        mcall    69, 6, [debuggee_pid]
1151
        dec     eax
1152
        clc
1153
        jz      @f
1154
        stc
1155
 
1156
    @@:
1157
        pop     eax
1158
        ret
1159
 
1160
include 'parser.inc'
1161
 
1162
;-----------------------------------------------------------------------------
1163
;                        Calculate expression event
1164
 
205 heavyiron 1165
OnCalc:
3675 GerdtR 1166
        mov     esi, [curarg]
1167
        call    calc_expression
1168
        jc      .ret
1169
        push    ebp
1170
        mov     esi, calc_string
1171
        call    put_message_nodraw
1172
        jmp     draw_messages
1173
 
1174
    .ret:
1175
        ret
205 heavyiron 1176
 
3675 GerdtR 1177
;-----------------------------------------------------------------------------
1178
;                            Dump memory event
1179
 
205 heavyiron 1180
OnDump:
3675 GerdtR 1181
        mov     esi, [curarg]
1182
        cmp     byte [esi], 0
1183
        jnz     .param
1184
        add     [dumppos], dump_height*10h
1185
        jmp     .doit
1186
 
1187
    .param:
1188
        call    calc_expression
1189
        jc      .ret
1190
        mov     [dumppos], ebp
205 heavyiron 1191
 
3675 GerdtR 1192
    .doit:
1193
        call    get_dump
1194
        call    draw_dump.redraw
1195
 
1196
    .ret:
1197
        ret
1198
 
1199
;-----------------------------------------------------------------------------
1200
;                   Dissassemble block of executable event
1201
 
205 heavyiron 1202
OnUnassemble:
3675 GerdtR 1203
        mov     esi, [curarg]
1204
        cmp     byte [esi], 0
1205
        jnz     .param
1206
        mov     eax, [disasm_start_pos]
1207
        mov     ecx, disasm_height
1208
        mov     [disasm_cur_pos], eax
205 heavyiron 1209
 
3675 GerdtR 1210
    .l:
1211
        mov     eax, [disasm_cur_pos]
1212
        call    find_symbol
1213
        jc      @f
1214
        dec     ecx
1215
        jz      .m
1216
 
1217
    @@:
1218
        push    ecx
1219
        call    disasm_instr
1220
        pop     ecx
1221
        jc      .err
1222
        loop    .l
1223
 
1224
    .m:
1225
        mov     eax, [disasm_cur_pos]
1226
        jmp     .doit
1227
 
1228
    .param:
1229
        call    calc_expression
1230
        jc      .ret
1231
        mov     eax, ebp
1232
 
1233
    .doit:
1234
        push    eax
1235
        push    [disasm_start_pos]
1236
        mov     [disasm_start_pos], eax
1237
        call    update_disasm
1238
        pop     [disasm_start_pos]
1239
        pop     eax
1240
        cmp     [disasm_cur_str], 0
1241
        jz      @f
1242
        mov     [disasm_start_pos], eax
1243
 
1244
    .ret:
1245
        ret
1246
 
1247
    @@:
1248
        call    update_disasm
1249
 
1250
    .err:
1251
        mov     esi, aInvAddr
1252
        jmp     put_message
1253
 
1254
;-----------------------------------------------------------------------------
1255
;                       Access to register value event
1256
 
205 heavyiron 1257
OnReg:
3675 GerdtR 1258
        mov     esi, [curarg]
1259
        call    get_arg.skip_spaces
1260
        call    find_reg
1261
        jnc     @f
205 heavyiron 1262
 
3675 GerdtR 1263
    .err:
1264
        mov     esi, RSyntax
1265
        jmp     put_message
1266
 
1267
    @@:
1268
        call    get_arg.skip_spaces
1269
        test    al, al
1270
        jz      .err
1271
        cmp     al, '='
1272
        jnz     @f
1273
        inc     esi
1274
        call    get_arg.skip_spaces
1275
        test    al, al
1276
        jz      .err
1277
 
1278
    @@:
1279
        push    edi
1280
        call    calc_expression
1281
        pop     edi
1282
        jc      .ret
1283
    ; now edi=register id, ebp=value
1284
        cmp     [bSuspended], 0
1285
        mov     esi, aRunningErr
1286
        jz      put_message
1287
        xchg    eax, ebp
1288
        cmp     edi, 24
1289
        jz      .eip
1290
        sub     edi, 4
1291
        jb      .8lo
1292
        sub     edi, 4
1293
        jb      .8hi
1294
        sub     edi, 8
1295
        jb      .16
1296
        mov     [_eax+edi*4], eax
1297
        jmp     .ret
1298
 
1299
    .16:
1300
        mov     word [_eax+(edi+8)*4], ax
1301
        jmp     .ret
1302
 
1303
    .8lo:
1304
        mov     byte [_eax+(edi+4)*4], al
1305
        jmp     .ret
1306
 
1307
    .8hi:
1308
        mov     byte [_eax+(edi+4)*4+1], al
1309
        jmp     .ret
1310
 
1311
    .eip:
1312
        mov     [_eip], eax
1313
        call    update_disasm_eip
1314
 
1315
    .ret:
1316
        call    set_context
1317
        jmp     draw_registers.redraw
1318
 
1319
;-----------------------------------------------------------------------------
1320
;                        Breakpoints manipulation
205 heavyiron 1321
OnBp:
3675 GerdtR 1322
        mov     esi, [curarg]
1323
        call    calc_expression
1324
        jc      .ret
1325
        xchg    eax, ebp
1326
        push    eax
1327
        call    find_breakpoint
1328
        inc     eax
1329
        pop     eax
1330
        jz      .notfound
1331
        mov     esi, aDuplicateBreakpoint
1332
        jmp     .sayerr
205 heavyiron 1333
 
3675 GerdtR 1334
    .notfound:
1335
        mov     bl, 1
1336
        call    add_breakpoint
1337
        jnc     .ret
1338
        mov     esi, aBreakpointLimitExceeded
1339
 
1340
    .sayerr:
1341
        call    put_message
1342
 
1343
    .ret:
4890 hidnplayr 1344
        jmp     draw_disasm
3675 GerdtR 1345
 
205 heavyiron 1346
OnBpmb:
3675 GerdtR 1347
        mov     dh, 0011b
1348
        jmp     DoBpm
1349
 
205 heavyiron 1350
OnBpmw:
3675 GerdtR 1351
        mov     dh, 0111b
1352
        jmp     DoBpm
1353
 
205 heavyiron 1354
OnBpmd:
3675 GerdtR 1355
        mov     dh, 1111b
1356
 
205 heavyiron 1357
DoBpm:
3675 GerdtR 1358
        mov     esi, [curarg]
1359
        cmp     byte [esi], 'w'
1360
        jnz     @f
1361
        and     dh, not 2
1362
        inc     esi
205 heavyiron 1363
 
3675 GerdtR 1364
    @@:
1365
        push    edx
1366
        call    calc_expression
1367
        pop     edx
1368
        jnc     @f
1369
        ret
1370
 
1371
    ; ebp = expression, dh = flags
1372
    @@:
1373
        movzx   eax, dh
1374
        shr     eax, 2
1375
        test    ebp, eax
1376
        jz      @f
1377
        mov     esi, aUnaligned
1378
        jmp     put_message
1379
 
1380
    @@:
1381
        mov     eax, ebp
1382
        mov     bl, 0Bh
1383
        call    add_breakpoint
1384
        jnc     @f
1385
        mov     esi, aBreakpointLimitExceeded
1386
        jmp     put_message
1387
 
1388
    ; now find index
1389
    @@:
1390
        push    eax
1391
        xor     ecx, ecx
1392
 
1393
    .l1:
1394
        cmp     [drx_break+ecx*4], 0
1395
        jnz     .l2
1396
        ;push    69
1397
        ;pop     eax
1398
        push    ecx
1399
        mov     dl, cl
1400
        ;mov     ecx, [debuggee_pid]
1401
        mov     esi, ebp
1402
        ;push    9
1403
        ;pop     ebx
1404
        mcall    69, 9, [debuggee_pid]
1405
        test    eax, eax
1406
        jz      .ok
1407
        pop     ecx
1408
 
1409
    .l2:
1410
        inc     ecx
1411
        cmp     ecx, 4
1412
        jb      .l1
1413
        pop     eax
1414
        call    clear_breakpoint
1415
        mov     esi, aBreakpointLimitExceeded
1416
        jmp     put_message
1417
 
1418
    .ok:
1419
        pop     ecx
1420
        pop     eax
1421
        and     byte [edi], not 2       ; breakpoint is enabled
1422
        shl     dl, 6
1423
        or      dl, dh
1424
        mov     byte [edi+1], dl
1425
        inc     eax
1426
        mov     [drx_break+ecx*4], eax
1427
        ret
1428
 
205 heavyiron 1429
OnBc:
3675 GerdtR 1430
        mov     esi, [curarg]
205 heavyiron 1431
 
3675 GerdtR 1432
    @@:
1433
        call    get_hex_number
1434
        jc      OnBp.ret
1435
        call    clear_breakpoint
1436
        jmp     @b
1437
 
205 heavyiron 1438
OnBd:
3675 GerdtR 1439
        mov     esi, [curarg]
205 heavyiron 1440
 
3675 GerdtR 1441
    @@:
1442
        call    get_hex_number
1443
        jc      OnBp.ret
1444
        call    disable_breakpoint
1445
        jmp     @b
1446
 
205 heavyiron 1447
OnBe:
3675 GerdtR 1448
        mov     esi, [curarg]
205 heavyiron 1449
 
3675 GerdtR 1450
    @@:
1451
        call    get_hex_number
1452
        jc      OnBp.ret
1453
        push    eax
1454
        call    find_enabled_breakpoint
1455
        pop     eax
1456
        jz      .err
1457
        call    enable_breakpoint
1458
        jmp     @b
1459
 
1460
    .err:
1461
        mov     esi, OnBeErrMsg
1462
        jmp     put_message
1463
 
1464
; TODO: split it out in parser.inc
205 heavyiron 1465
get_hex_number:
3675 GerdtR 1466
        call    get_arg.skip_spaces
1467
        xor     ecx, ecx
1468
        xor     edx, edx
205 heavyiron 1469
 
3675 GerdtR 1470
    @@:
1471
        lodsb
1472
        call    is_hex_digit
1473
        jc      .ret
1474
        shl     edx, 4
1475
        or      dl, al
1476
        inc     ecx
1477
        jmp     @b
1478
 
1479
    .ret:
1480
        dec     esi
1481
        cmp     ecx, 1
1482
        xchg    eax, edx
1483
        ret
1484
 
1485
;-----------------------------------------------------------------------------
1486
;                       Breakpoints list event
1487
 
205 heavyiron 1488
OnBl:
3675 GerdtR 1489
        mov     esi, [curarg]
1490
        cmp     byte [esi], 0
1491
        jz      .listall
1492
        call    get_hex_number
1493
        jc      .ret
1494
        cmp     eax, breakpoints_n
1495
        jae     .err
1496
        push    eax
1497
        add     eax, eax
1498
        lea     edi, [breakpoints + eax + eax*2]
1499
        pop     eax
1500
        test    byte [edi+4], 1
1501
        jz      .err
1502
        call    show_break_info
205 heavyiron 1503
 
3675 GerdtR 1504
    .ret:
1505
        ret
1506
 
1507
    .err:
1508
        mov     esi, aInvalidBreak
1509
        jmp     put_message
1510
 
1511
    .listall:
1512
        mov     edi, breakpoints
1513
        xor     eax, eax
1514
 
1515
    @@:
1516
        test    byte [edi+4], 1
1517
        jz      .cont
1518
        push    edi eax
1519
        call    show_break_info
1520
        pop     eax edi
1521
 
1522
    .cont:
1523
        add     edi, 6
1524
        inc     eax
1525
        cmp     eax, breakpoints_n
1526
        jb      @b
1527
        ret
1528
 
1529
;-----------------------------------------------------------------------------
1530
 
205 heavyiron 1531
show_break_info:
3675 GerdtR 1532
        push    edi
1533
        test    byte [edi+4], 8
1534
        jnz     .dr
1535
        push    dword [edi]
1536
        push    eax
1537
        mov     esi, aBreakNum
1538
        call    put_message_nodraw
1539
        jmp     .cmn
205 heavyiron 1540
 
3675 GerdtR 1541
    .dr:
1542
        push    eax
1543
        mov     esi, aMemBreak1
1544
        call    put_message_nodraw
1545
        pop     edi
1546
        push    edi
1547
        mov     esi, aMemBreak2
1548
        test    byte [edi+5], 2
1549
        jz      @f
1550
        mov     esi, aMemBreak3
1551
 
1552
    @@:
1553
        call    put_message_nodraw
1554
        pop     edi
1555
        push    edi
1556
        mov     esi, aMemBreak6
1557
        test    byte [edi+5], 8
1558
        jnz     @f
1559
        mov     esi, aMemBreak5
1560
        test    byte [edi+5], 4
1561
        jnz     @f
1562
        mov     esi, aMemBreak4
1563
 
1564
    @@:
1565
        call    put_message_nodraw
1566
        pop     edi
1567
        push    edi
1568
        push    dword [edi]
1569
        mov     esi, aMemBreak7
1570
        call    put_message_nodraw
1571
 
1572
    .cmn:
1573
        pop     edi
1574
        test    byte [edi+4], 2
1575
        jz      @f
1576
        push    edi
1577
        mov     esi, aDisabled
1578
        call    put_message_nodraw
1579
        pop     edi
1580
 
1581
    @@:
1582
        test    byte [edi+4], 4
1583
        jz      @f
1584
        mov     esi, aOneShot
1585
        call    put_message_nodraw
1586
 
1587
    @@:
1588
        mov     esi, newline
1589
        jmp     put_message
1590
 
1591
;-----------------------------------------------------------------------------
1592
;                        Add breakpoint
1593
; in: EAX = address; BL = flags
1594
; out: CF = 1 => error
1595
;      CF = 0 and EAX = breakpoint number
1596
 
205 heavyiron 1597
add_breakpoint:
3675 GerdtR 1598
        xor     ecx, ecx
1599
        mov     edi, breakpoints
205 heavyiron 1600
 
3675 GerdtR 1601
    @@:
1602
        test    byte [edi+4], 1
1603
        jz      .found
1604
        add     edi, 6
1605
        inc     ecx
1606
        cmp     ecx, breakpoints_n
1607
        jb      @b
1608
        stc
1609
        ret
1610
 
1611
    .found:
1612
        stosd
1613
        xchg    eax, ecx
1614
        mov     [edi], bl
1615
        test    bl, 2
1616
        jnz     @f
1617
        or      byte [edi], 2
1618
        push    eax
1619
        call    enable_breakpoint
1620
        pop     eax
1621
 
1622
    @@:
1623
        clc
1624
        ret
1625
 
1626
;-----------------------------------------------------------------------------
1627
;                         Remove breakpoint
1628
 
205 heavyiron 1629
clear_breakpoint:
3675 GerdtR 1630
        cmp     eax, breakpoints_n
1631
        jae     .ret
1632
        mov     ecx, 4
1633
        inc     eax
205 heavyiron 1634
 
3675 GerdtR 1635
    .1:
1636
        cmp     [drx_break-4+ecx*4], eax
1637
        jnz     @f
1638
        and     [drx_break-4+ecx*4], 0
1639
 
1640
    @@:
1641
        loop    .1
1642
        dec     eax
1643
        push    eax
1644
        add     eax, eax
1645
        lea     edi, [breakpoints + eax + eax*2 + 4]
1646
        test    byte [edi], 1
1647
        pop     eax
1648
        jz      .ret
1649
        push    edi
1650
        call    disable_breakpoint
1651
        pop     edi
1652
        mov     byte [edi], 0
1653
 
1654
    .ret:
1655
        ret
1656
 
1657
;-----------------------------------------------------------------------------
1658
;                          Disable breakpoint
1659
 
205 heavyiron 1660
disable_breakpoint:
3675 GerdtR 1661
        cmp     eax, breakpoints_n
1662
        jae     .ret
1663
        add     eax, eax
1664
        lea     edi, [breakpoints + eax + eax*2 + 5]
1665
        test    byte [edi-1], 1
1666
        jz      .ret
1667
        test    byte [edi-1], 2
1668
        jnz     .ret
1669
        or      byte [edi-1], 2
1670
        test    byte [edi-1], 8
1671
        jnz     .dr
1672
        push    esi
1673
        ;push    7
1674
        ;pop     ebx
1675
        ;push    69
1676
        ;pop     eax
1677
        ;mov     ecx, [debuggee_pid]
1678
        ;xor     edx, edx
1679
        ;inc     edx
1680
        ;mov     esi, [edi-5]
1681
        mcall    69, 7, [debuggee_pid], 1, [edi-5]
1682
        pop     esi
205 heavyiron 1683
 
3675 GerdtR 1684
    .ret:
1685
        ret
1686
 
1687
    .dr:
1688
        mov     dl, [edi]
1689
        shr     dl, 6
1690
        mov     dh, 80h
1691
        ;push    69
1692
        ;pop     eax
1693
        ;push    9
1694
        ;pop     ebx
1695
        ;mov     ecx, [debuggee_pid]
1696
        mcall    69, 9, [debuggee_pid]
1697
        ret
1698
 
1699
;-----------------------------------------------------------------------------
1700
;                           Enable breakpoint
1701
 
205 heavyiron 1702
enable_breakpoint:
3675 GerdtR 1703
        push    esi
1704
        cmp     eax, breakpoints_n
1705
        jae     .ret
1706
        add     eax, eax
1707
        lea     edi, [breakpoints + eax + eax*2 + 5]
1708
        test    byte [edi-1], 1
1709
        jz      .ret
1710
        test    byte [edi-1], 2
1711
        jz      .ret
1712
        and     byte [edi-1], not 2
1713
        test    byte [edi-1], 8
1714
        jnz     .dr
1715
        ;push    6
1716
        ;pop     ebx
1717
        ;push    69
1718
        ;pop     eax
1719
        ;mov     esi, [edi-5]
1720
        ;mov     ecx, [debuggee_pid]
1721
        ;xor     edx, edx
1722
        ;inc     edx
1723
        mcall    69, 6, [debuggee_pid], 1, [edi-5]
1724
        dec     eax
1725
        jnz     .err
1726
        ;mov     al, 69
1727
        push    0xCC
1728
        mov     edi, esp
1729
        inc     ebx
1730
        mcall    69
1731
        pop     eax
205 heavyiron 1732
 
3675 GerdtR 1733
    .ret:
1734
        pop     esi
1735
        ret
205 heavyiron 1736
 
3675 GerdtR 1737
    .err:
1738
        or      byte [edi-1], 2
1739
        mov     esi, aBreakErr
1740
        call    put_message
1741
        pop     esi
1742
        ret
205 heavyiron 1743
 
3675 GerdtR 1744
    .dr:
1745
        ;push    9
1746
        ;pop     ebx
1747
        ;push    69
1748
        ;pop     eax
1749
        mov     esi, [edi-5]
1750
        ;mov     ecx, [debuggee_pid]
1751
        mov     dl, [edi]
1752
        shr     dl, 6
1753
        mov     dh, [edi]
1754
        and     dh, 0xF
1755
        mcall    69, 9, [debuggee_pid]
1756
        test    eax, eax
1757
        jnz     .err
1758
        pop     esi
1759
        ret
205 heavyiron 1760
 
3675 GerdtR 1761
;-----------------------------------------------------------------------------
1762
;                             Find breakpoint
542 diamond 1763
 
3675 GerdtR 1764
find_breakpoint:
1765
        xor     ecx, ecx
1766
        xchg    eax, ecx
1767
        mov     edi, breakpoints
542 diamond 1768
 
3675 GerdtR 1769
    @@:
1770
        test    byte [edi+4], 1
1771
        jz      .cont
1772
        test    byte [edi+4], 8
1773
        jnz     .cont
1774
        cmp     [edi], ecx
1775
        jz      .found
542 diamond 1776
 
3675 GerdtR 1777
    .cont:
1778
        add     edi, 6
1779
        inc     eax
1780
        cmp     eax, breakpoints_n
1781
        jb      @b
1782
        or      eax, -1
542 diamond 1783
 
3675 GerdtR 1784
    .found:
1785
        ret
542 diamond 1786
 
3675 GerdtR 1787
;-----------------------------------------------------------------------------
1788
;
542 diamond 1789
 
3675 GerdtR 1790
find_enabled_breakpoint:
1791
        xor     ecx, ecx
1792
        xchg    eax, ecx
1793
        mov     edi, breakpoints
542 diamond 1794
 
3675 GerdtR 1795
    @@:
1796
        test    byte [edi+4], 1
1797
        jz      .cont
1798
        test    byte [edi+4], 2 or 8
1799
        jnz     .cont
1800
        cmp     [edi], ecx
1801
        jz      .found
542 diamond 1802
 
3675 GerdtR 1803
    .cont:
1804
        add     edi, 6
1805
        inc     eax
1806
        cmp     eax, breakpoints_n
1807
        jb      @b
1808
        or      eax, -1
205 heavyiron 1809
 
3675 GerdtR 1810
    .found:
1811
        ret
205 heavyiron 1812
 
3675 GerdtR 1813
; TODO: add find_disabled_breakpoint
205 heavyiron 1814
 
3675 GerdtR 1815
;-----------------------------------------------------------------------------
1816
;                       Unpack executable event
205 heavyiron 1817
 
3675 GerdtR 1818
OnUnpack:
1819
    ; program must be loaded - checked when command was parsed
1820
    ; program must be stopped
1821
        mov     esi, aRunningErr
1822
        cmp     [bSuspended], 0
1823
        jz      put_message
1824
   ; all breakpoints must be disabled
1825
        mov     edi, breakpoints
205 heavyiron 1826
 
3675 GerdtR 1827
    @@:
1828
        test    byte [edi+4], 1
1829
        jz      .cont
1830
        test    byte [edi+4], 2
1831
        jnz     .cont
1832
        mov     esi, aEnabledBreakErr
1833
        jmp     put_message
205 heavyiron 1834
 
3675 GerdtR 1835
    .cont:
1836
        add     edi, 6
1837
        cmp     edi, breakpoints+breakpoints_n*6
1838
        jb      @b
1839
    ; ok, now do it
1840
    ; set breakpoint on 0xC dword access
1841
        push    9
1842
        pop     ebx
1843
        mov     ecx, [debuggee_pid]
1844
        mov     dx, 1111b*256
1845
        push    0xC
1846
        pop     esi
205 heavyiron 1847
 
3675 GerdtR 1848
    @@:
1849
        ;push    69
1850
        ;pop     eax
1851
        mcall    69
1852
        test    eax, eax
1853
        jz      .breakok
1854
        inc     edx
1855
        cmp     dl, 4
1856
        jb      @b
809 diamond 1857
 
3675 GerdtR 1858
    .breakok:
1859
        call    GoOn
809 diamond 1860
 
3675 GerdtR 1861
    ; now wait for event
1862
    .wait:
1863
        ;push    10
1864
        ;pop     eax
1865
        mcall    10
1866
        dec     eax
1867
        jz      .redraw
1868
        dec     eax
1869
        jz      .key
1870
        dec     eax
1871
        jnz     .debug
1872
    ; button; we have only one button, close
1873
        or      eax, -1
1874
        mcall
205 heavyiron 1875
 
3675 GerdtR 1876
    .redraw:
1877
        call    draw_window
1878
        jmp     .wait
205 heavyiron 1879
 
3675 GerdtR 1880
    .key:
1881
        mov     al, 2
1882
        mcall
1883
        cmp     ah, 3   ; Ctrl+C
1884
        jnz     .wait
205 heavyiron 1885
 
3675 GerdtR 1886
    .userbreak:
1887
        mov     esi, aInterrupted
205 heavyiron 1888
 
3675 GerdtR 1889
    .x1:
1890
        push    edx esi
1891
        call    put_message
1892
        pop     esi edx
1893
        or      dh, 80h
1894
        ;push    69
1895
        ;pop     eax
1896
        ;push    9
1897
        ;pop     ebx
1898
        ;mov     ecx, [debuggee_pid]
1899
        mcall    69, 9, [debuggee_pid]
1900
        cmp     esi, aUnpacked
1901
        jnz     OnSuspend
1902
        jmp     AfterSuspend
205 heavyiron 1903
 
3675 GerdtR 1904
    .debug:
1905
        cmp     [dbgbuflen], 4*3
1906
        jnz     .notour
1907
        cmp     dword [dbgbuf], 3
1908
        jnz     .notour
1909
        test    byte [dbgbuf+8], 1
1910
        jnz     .our
205 heavyiron 1911
 
3675 GerdtR 1912
    .notour:
1913
        mov     esi, aInterrupted
1914
        push    edx
1915
        call    put_message
1916
        pop     edx
1917
        or      dh, 80h
1918
        ;push    69
1919
        ;pop     eax
1920
        ;push    9
1921
        ;pop     ebx
1922
        ;mov     ecx, [debuggee_pid]
1923
        mcall    69, 9, [debuggee_pid]
1924
        jmp     debugmsg
205 heavyiron 1925
 
3675 GerdtR 1926
    .our:
1927
        and     [dbgbuflen], 0
1928
        push    edx
1929
        call    get_context
1930
        push    eax
1931
        ;mov     al, 69
1932
        ;mov     bl, 6
1933
        ;mov     ecx, [debuggee_pid]
1934
        ;mov     edi, esp
1935
        ;push    4
1936
        ;pop     edx
1937
        ;push    0xC
1938
        ;pop     esi
1939
        mcall    69, 6, [debuggee_pid], 4, 0xC, esp
1940
        pop     eax
1941
        pop     edx
1942
        cmp     eax, [_eip]
1943
        jz      .done
1944
        call    DoResume
1945
        jmp     .wait
205 heavyiron 1946
 
3675 GerdtR 1947
    .done:
1948
        mov     esi, aUnpacked
1949
        jmp     .x1
809 diamond 1950
 
3675 GerdtR 1951
;-----------------------------------------------------------------------------
4886 hidnplayr 1952
;                            Include Symbol parser
205 heavyiron 1953
 
4886 hidnplayr 1954
include 'symbols.inc'
205 heavyiron 1955
 
3675 GerdtR 1956
;-----------------------------------------------------------------------------
1957
;                        Include disassembler engine
1958
 
1959
include 'disasm.inc'
1960
 
205 heavyiron 1961
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1962
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1963
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1964
 
4886 hidnplayr 1965
caption_str db  'Kolibri Debugger',0
205 heavyiron 1966
 
4886 hidnplayr 1967
begin_str db    'Kolibri Debugger, version 0.34',10
4591 hidnplayr 1968
        db      'Hint: type "help" for help, "quit" to quit'
3675 GerdtR 1969
newline db      10,0
1970
prompt  db      '> ',0
1971
 
205 heavyiron 1972
help_groups:
3675 GerdtR 1973
        dd      aControl, 0, 0, help_control_msg
1974
        db      0
1975
        dd      aData, 0, 0, help_data_msg
1976
        db      0
1977
        dd      aBreakpoints, 0, 0, help_breaks_msg
1978
        db      0
1979
 
1980
;-----------------------------------------------------------------------------
1981
;                   Commands format definitions
1982
 
1983
; TODO: make it with macros
1984
 
205 heavyiron 1985
; flags field:
1986
; &1: command may be called without parameters
1987
; &2: command may be called with parameters
1988
; &4: command may be called without loaded program
1989
; &8: command may be called with loaded program
1990
commands:
3675 GerdtR 1991
        dd      _aH, OnHelp, HelpSyntax, HelpHelp
1992
        db      0Fh
1993
        dd      aHelp, OnHelp, HelpSyntax, HelpHelp
1994
        db      0Fh
1995
        dd      aQuit, OnQuit, QuitSyntax, QuitHelp
1996
        db      0Dh
1997
        dd      aLoad, OnLoad, LoadSyntax, LoadHelp
1998
        db      6
1999
        dd      aReload, OnReload, ReloadSyntax, ReloadHelp
2000
        db      0Dh
2001
        dd      aTerminate, OnTerminate, TerminateSyntax, TerminateHelp
2002
        db      9
2003
        dd      aDetach, OnDetach, DetachSyntax, DetachHelp
2004
        db      9
2005
        dd      aSuspend, OnSuspend, SuspendSyntax, SuspendHelp
2006
        db      9
2007
        dd      aResume, OnResume, ResumeSyntax, ResumeHelp
2008
        db      0Bh
4443 clevermous 2009
        dd      aStep, OnStepMultiple, StepSyntax, StepHelp
3675 GerdtR 2010
        db      0Bh
2011
        dd      aProceed, OnProceed, ProceedSyntax, ProceedHelp
2012
        db      0Bh
2013
        dd      aCalc, OnCalc, CalcSyntax, CalcHelp
2014
        db      0Eh
2015
        dd      aDump, OnDump, DumpSyntax, DumpHelp
2016
        db      0Bh
2017
        dd      aUnassemble, OnUnassemble, UnassembleSyntax, UnassembleHelp
2018
        db      0Bh
2019
        dd      aBp, OnBp, BpSyntax, BpHelp
2020
        db      0Ah
2021
        dd      aBpm, OnBpmb, BpmSyntax, BpmHelp
2022
        db      0Ah
2023
        dd      aBpmb, OnBpmb, BpmSyntax, BpmHelp
2024
        db      0Ah
2025
        dd      aBpmw, OnBpmw, BpmSyntax, BpmHelp
2026
        db      0Ah
2027
        dd      aBpmd, OnBpmd, BpmSyntax, BpmHelp
2028
        db      0Ah
2029
        dd      aBl, OnBl, BlSyntax, BlHelp
2030
        db      0Bh
2031
        dd      aBc, OnBc, BcSyntax, BcHelp
2032
        db      0Ah
2033
        dd      aBd, OnBd, BdSyntax, BdHelp
2034
        db      0Ah
2035
        dd      aBe, OnBe, BeSyntax, BeHelp
2036
        db      0Ah
2037
        dd      aReg, OnReg, RSyntax, RHelp
2038
        db      0Ah
2039
        dd      aUnpack, OnUnpack, UnpackSyntax, UnpackHelp
2040
        db      9
2041
        dd      aLoadSymbols, OnLoadSymbols, LoadSymbolsSyntax, LoadSymbolsHelp
2042
        db      0Ah
2043
        dd      0
205 heavyiron 2044
 
3675 GerdtR 2045
;-----------------------------------------------------------------------------
2046
;                   Help messages for commands groups
2047
 
2048
aHelp   db      5,'help',0
2049
_aH     db      2,'h',0
2050
HelpHelp db     'Help on specified function',10
2051
HelpSyntax db   'Usage: h or help [group | command]',10,0
2052
 
2053
help_msg db     'List of known command groups:',10
2054
        db      '"help control"     - display list of control commands',10
2055
        db      '"help data"        - display list of commands concerning data',10
2056
        db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
2057
 
2058
;               Control commands group
2059
 
2060
aControl db     8,'control',0
2061
help_control_msg db     'List of control commands:',10
2062
        db      'h = help             - help',10
2063
        db      'quit                 - exit from debugger',10
2064
        db      'load  [params] - load program for debugging',10
2065
        db      'reload               - reload debugging program',10
2066
        db      'load-symbols   - load information on symbols for program',10
2067
        db      'terminate            - terminate loaded program',10
2068
        db      'detach               - detach from debugging program',10
2069
        db      'stop                 - suspend execution of debugging program',10
2070
        db      'g []     - go on (resume execution of debugging program)',10
4590 clevermous 2071
        db      's []            - program step, also ',10
2072
        db      'p []            - program wide step, also ',10
3675 GerdtR 2073
        db      'unpack               - try to bypass unpacker code (heuristic)',10,0
2074
 
2075
;               Data commands group
2076
 
2077
aData   db      5,'data',0
2078
help_data_msg db        'List of data commands:',10
2079
        db      '?        - calculate value of expression',10
2080
        db      'd []     - dump data at given address',10
2081
        db      'u []     - unassemble instructions at given address',10
2082
        db      'r   or',10
2083
        db      'r = - set register value',10,0
2084
 
2085
;               Breakpoints commands group
2086
 
205 heavyiron 2087
aBreakpoints db 12,'breakpoints',0
3675 GerdtR 2088
help_breaks_msg db      'List of breakpoints commands:',10
2089
        db      'bp       - set breakpoint on execution',10
2090
        db      'bpm[b|w|d]   - set breakpoint on memory access',10
2091
        db      'bl []        - breakpoint(s) info',10
2092
        db      'bc ...       - clear breakpoint',10
2093
        db      'bd ...       - disable breakpoint',10
2094
        db      'be ...       - enable breakpoint',10,0
205 heavyiron 2095
 
3675 GerdtR 2096
;-----------------------------------------------------------------------------
2097
;                    Individual command help messages
205 heavyiron 2098
 
3675 GerdtR 2099
aQuit   db      5,'quit',0
2100
QuitHelp db     'Quit from debugger',10
2101
QuitSyntax db   'Usage: quit',10,0
205 heavyiron 2102
 
3675 GerdtR 2103
aLoad   db      5,'load',0
2104
LoadHelp db     'Load program for debugging',10
2105
LoadSyntax db   'Usage: load  [parameters]',10,0
205 heavyiron 2106
 
3675 GerdtR 2107
aReload db      7,'reload',0
2108
ReloadHelp db   'Reload debugging program (restart debug session)',10
2109
ReloadSyntax db 'Usage: reload',10,0
2110
 
2111
aTerminate db   10,'terminate',0
205 heavyiron 2112
TerminateHelp db 'Terminate debugged program',10
2113
TerminateSyntax db 'Usage: terminate',10,0
2114
 
3675 GerdtR 2115
aDetach db      7,'detach',0
2116
DetachHelp db   'Detach from debugged program',10
2117
DetachSyntax db 'Usage: detach',10,0
205 heavyiron 2118
 
3675 GerdtR 2119
aSuspend db     5,'stop',0
2120
SuspendHelp db  'Suspend execution of debugged program',10
205 heavyiron 2121
SuspendSyntax db 'Usage: stop',10,0
2122
 
3675 GerdtR 2123
aResume db      2,'g',0
2124
ResumeHelp db   'Go (resume execution of debugged program)',10
2125
ResumeSyntax db 'Usage: g',10
2126
        db      '   or: g  - wait until specified address is reached',10,0
205 heavyiron 2127
 
3675 GerdtR 2128
aStep   db      2,'s',0
2129
StepHelp db     'Make step in debugged program',10
2130
StepSyntax db   'Usage: s []',10,0
205 heavyiron 2131
 
3675 GerdtR 2132
aProceed db     2,'p',0
2133
ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
2134
ProceedSyntax db 'Usage: p []',10,0
205 heavyiron 2135
 
3675 GerdtR 2136
aDump   db      2,'d',0
2137
DumpHelp db     'Dump data of debugged program',10
2138
DumpSyntax db   'Usage: d  - dump data at specified address',10
2139
        db      '   or: d              - continue current dump',10,0
205 heavyiron 2140
 
3675 GerdtR 2141
aCalc   db      2,'?',0
2142
CalcHelp db     'Calculate value of expression',10
2143
CalcSyntax db   'Usage: ? ',10,0
205 heavyiron 2144
 
3675 GerdtR 2145
aUnassemble db  2,'u',0
205 heavyiron 2146
UnassembleHelp db 'Unassemble',10
3675 GerdtR 2147
UnassembleSyntax db      'Usage: u  - unassemble instructions at specified address',10
2148
                 db      '   or: u              - continue current unassemble screen',10,0
205 heavyiron 2149
 
3675 GerdtR 2150
aReg    db      2,'r',0
2151
RHelp   db      'Set register value',10
2152
RSyntax db      'Usage: r  ',10
2153
        db      '   or: r = - set value of  to ',10,0
205 heavyiron 2154
 
3675 GerdtR 2155
aBp     db      3,'bp',0
2156
BpHelp  db      'set BreakPoint on execution',10
2157
BpSyntax db     'Usage: bp ',10,0
205 heavyiron 2158
 
3675 GerdtR 2159
aBpm    db      4,'bpm',0
2160
aBpmb   db      5,'bpmb',0
2161
aBpmw   db      5,'bpmw',0
2162
aBpmd   db      5,'bpmd',0
2163
BpmHelp db      'set BreakPoint on Memory access',10
2164
        db      'Maximum 4 breakpoints of this type are allowed',10
2165
        db      'Note that for this breaks debugger is activated after access',10
2166
BpmSyntax db    'Usage: bpmb [w] ',10
2167
        db      '       bpmw [w] ',10
2168
        db      '       bpmd [w] ',10
2169
        db      '       bpm is synonym for bpmd',10
2170
        db      '"w" means break only on writes (default is on read/write)',10,0
205 heavyiron 2171
 
3675 GerdtR 2172
aBl     db      3,'bl',0
2173
BlHelp  db      'Breakpoint List',10
2174
BlSyntax db     'Usage: bl          - list all breakpoints',10
2175
        db      '       bl  - display info on particular breakpoint',10,0
205 heavyiron 2176
 
3675 GerdtR 2177
aBc     db      3,'bc',0
2178
BcHelp  db      'Breakpoint Clear',10
2179
BcSyntax db     'Usage: bc ',10
2180
        db      'Examples: bc 2',10
2181
        db      '          bc 1 3 4 A',10,0
205 heavyiron 2182
 
3675 GerdtR 2183
aBd     db      3,'bd',0
2184
BdHelp  db      'Breakpoint Disable',10
2185
BdSyntax db     'Usage: bd ',10
2186
        db      'Examples: bd 2',10
2187
        db      '          bd 1 3 4 A',10,0
205 heavyiron 2188
 
3675 GerdtR 2189
aBe     db      3,'be',0
2190
BeHelp  db      'Breakpoint Enable',10
2191
BeSyntax db     'Usage: be ',10
2192
        db      'Examples: be 2',10
2193
        db      '          be 1 3 4 A',10,0
205 heavyiron 2194
 
3675 GerdtR 2195
aUnpack db      7,'unpack',0
2196
UnpackHelp db   'Try to bypass unpacker code',10
2197
UnpackSyntax db 'Usage: unpack',10,0
205 heavyiron 2198
 
3675 GerdtR 2199
aLoadSymbols db 13,'load-symbols',0
542 diamond 2200
LoadSymbolsHelp db 'Load symbolic information for executable',10
2201
LoadSymbolsSyntax db 'Usage: load-symbols ',10,0
2202
 
205 heavyiron 2203
aUnknownCommand db 'Unknown command',10,0
2204
 
3675 GerdtR 2205
;-----------------------------------------------------------------------------
2206
;                             Error messages
2207
 
2208
load_err_msg    db      'Cannot load program. ',0
2209
unk_err_msg     db      'Unknown error code -%4X',10,0
2210
aCannotLoadFile db      'Cannot load file. ',0
2211
unk_err_msg2    db      'Unknown error code %4X.',10,0
205 heavyiron 2212
load_err_msgs:
3675 GerdtR 2213
        dd      .1, 0, .3, 0, .5, .6, 0, 0, .9, .A, 0, 0, 0, 0, 0, 0
2214
        dd      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .1E, .1F, .20
2215
.1              db      'HD undefined.',10,0
2216
.3              db      'Unknown FS.',10,0
2217
.5              db      'File not found.',10,0
2218
.6              db      'Unexpected EOF.',10,0
2219
.9              db      'FAT table corrupted.',10,0
2220
.A              db      'Access denied.',10,0
2221
.1E             db      'No memory.',10,0
2222
.1F             db      'Not Menuet/Kolibri executable.',10,0
2223
.20             db      'Too many processes.',10,0
2224
load_succ_msg   db      'Program loaded successfully! PID=%4X. Use "g" to run.',10,0
2225
need_debuggee   db      'No program loaded. Use "load" command.',10,0
2226
aAlreadyLoaded  db      'Program is already loaded. Use "terminate" or "detach" commands',10,0
2227
terminated_msg  db      'Program terminated.',10,0
2228
aException      db      'Debugged program caused an exception %2X. '
2229
aSuspended      db      'Suspended',10,0
2230
aContinued      db      'Continuing',10,0
2231
aRunningErr     db      'Program is running',10,0
2232
read_mem_err    db      'ERROR: cannot read process memory!!!',10,0
205 heavyiron 2233
aBreakpointLimitExceeded db 'Breakpoint limit exceeded',10,0
3675 GerdtR 2234
aBreakErr       db      'Cannot activate breakpoint, it will be disabled',10,0
2235
aDuplicateBreakpoint db 'Duplicate breakpoint',10,0
2236
aInvalidBreak   db      'Invalid breakpoint number',10,0
2237
OnBeErrMsg      db      'There is already enabled breakpoint on this address',10,0
2238
aBreakNum       db      '%2X: at %8X',0
2239
aMemBreak1      db      '%2X: on ',0
2240
aMemBreak2      db      'read from ',0
2241
aMemBreak3      db      'access of ',0
2242
aMemBreak4      db      'byte',0
2243
aMemBreak5      db      'word',0
2244
aMemBreak6      db      'dword',0
2245
aMemBreak7      db      ' at %8X',0
2246
aOneShot        db      ', one-shot',0
2247
aDisabled       db      ', disabled',0
2248
aBreakStop      db      'Breakpoint #%2X',10,0
2249
aUserBreak      db      'int3 command at %8X',10,0
2250
;dbgmsg_str     db      'Debug message for process %4X.',10,0
2251
aInvAddr        db      'Invalid address',10,0
2252
NoPrgLoaded_str db      'No program loaded'
205 heavyiron 2253
NoPrgLoaded_len = $ - NoPrgLoaded_str
3675 GerdtR 2254
aRunning        db      'Running'
2255
aPaused         db      'Paused'
4591 hidnplayr 2256
aMain           db      '[ CPU ]'
2257
aSSE            db      '[ SSE ]'
2258
aAVX            db      '[ AVX ]'
2259
aMSR            db      '[ MSR ]'
3675 GerdtR 2260
aPoint          db      0x1C
2261
aMinus          db      '-'
2262
aColon          db      ':'
2263
aSpace          db      ' '
2264
aQuests         db      '??'
2265
aDots           db      '...'
2266
aParseError     db      'Parse error',10,0
2267
aDivByZero      db      'Division by 0',10,0
2268
calc_string     db      '%8X',10,0
2269
aNoMemory       db      'No memory',10,0
2270
aSymbolsLoaded  db      'Symbols loaded',10,0
2271
aUnaligned      db      'Unaligned address',10,0
2272
aEnabledBreakErr db     'Enabled breakpoints are not allowed',10,0
2273
aInterrupted    db      'Interrupted',10,0
2274
aUnpacked       db      'Unpacked successful!',10,0
2275
aPacked1        db      'Program is probably packed with ',0
2276
aPacked2        db      '.',10,'Try to unpack automatically? [y/n]: ',0
2277
aY_str          db      'y',10,0
2278
aN_str          db      'n',10,0
2279
mxp_nrv_name    db      'mxp_nrv',0
2280
mxp_name        db      'mxp',0
2281
mxp_lzo_name    db      'mxp_lzo',0
2282
mtappack_name   db      'mtappack',0
2283
flags           db      'CPAZSDO'
2284
flags_bits      db      0,2,4,6,7,10,11
2285
 
2286
;-----------------------------------------------------------------------------
2287
;                         Registers strings
2288
 
205 heavyiron 2289
regs_strs:
4886 hidnplayr 2290
        db 'EAX='
2291
        db 'EBX='
2292
        db 'ECX='
2293
        db 'EDX='
2294
        db 'ESI='
2295
        db 'EDI='
2296
        db 'EBP='
2297
        db 'ESP='
2298
        db 'EIP='
2299
        db 'EFLAGS='
2300
 
3675 GerdtR 2301
fpu_strs:
4886 hidnplayr 2302
        db 'ST0='
2303
        db 'ST1='
2304
        db 'ST2='
2305
        db 'ST3='
2306
        db 'ST4='
2307
        db 'ST5='
2308
        db 'ST6='
2309
        db 'ST7='
2310
 
3675 GerdtR 2311
mmx_strs:
4886 hidnplayr 2312
        db 'MM0='
2313
        db 'MM1='
2314
        db 'MM2='
2315
        db 'MM3='
2316
        db 'MM4='
2317
        db 'MM5='
2318
        db 'MM6='
2319
        db 'MM7='
3675 GerdtR 2320
sse_strs:
4886 hidnplayr 2321
        db '-XMM0-'
2322
        db '-XMM1-'
2323
        db '-XMM2-'
2324
        db '-XMM3-'
2325
        db '-XMM4-'
2326
        db '-XMM5-'
2327
        db '-XMM6-'
2328
        db '-XMM7-'
3675 GerdtR 2329
avx_strs:
4886 hidnplayr 2330
        db '-YMM0-'
2331
        db '-YMM1-'
2332
        db '-YMM2-'
2333
        db '-YMM3-'
2334
        db '-YMM4-'
2335
        db '-YMM5-'
2336
        db '-YMM6-'
2337
        db '-YMM7-'
205 heavyiron 2338
 
4886 hidnplayr 2339
debuggee_pid    dd 0
2340
bSuspended      db 0
2341
bAfterGo        db 0
2342
temp_break      dd 0
2343
reg_mode        db 1
205 heavyiron 2344
 
3675 GerdtR 2345
include 'disasm_tbl.inc'
205 heavyiron 2346
 
2347
reg_table:
4886 hidnplayr 2348
        db 2,'al',0
2349
        db 2,'cl',1
2350
        db 2,'dl',2
2351
        db 2,'bl',3
2352
        db 2,'ah',4
2353
        db 2,'ch',5
2354
        db 2,'dh',6
2355
        db 2,'bh',7
2356
        db 2,'ax',8
2357
        db 2,'cx',9
2358
        db 2,'dx',10
2359
        db 2,'bx',11
2360
        db 2,'sp',12
2361
        db 2,'bp',13
2362
        db 2,'si',14
2363
        db 2,'di',15
2364
        db 3,'eax',16
2365
        db 3,'ecx',17
2366
        db 3,'edx',18
2367
        db 3,'ebx',19
2368
        db 3,'esp',20
2369
        db 3,'ebp',21
2370
        db 3,'esi',22
2371
        db 3,'edi',23
2372
        db 3,'eip',24
2373
        db 0
205 heavyiron 2374
 
542 diamond 2375
IncludeIGlobals
2376
 
2377
fn70_read_block:
4886 hidnplayr 2378
        dd 0
2379
        dq 0
2380
        dd ?
2381
        dd ?
2382
        db 0
2383
        dd ?
542 diamond 2384
 
2385
fn70_attr_block:
4886 hidnplayr 2386
        dd 5
2387
        dd 0,0,0
2388
        dd fileattr
2389
        db 0
2390
        dd ?
542 diamond 2391
 
205 heavyiron 2392
fn70_load_block:
4886 hidnplayr 2393
        dd 7
2394
        dd 1
2395
load_params dd 0
2396
        dd 0
2397
        dd 0
205 heavyiron 2398
i_end:
2399
loadname:
4886 hidnplayr 2400
        db 0
2401
        rb 255
205 heavyiron 2402
 
4886 hidnplayr 2403
symbolsfile     rb 260
542 diamond 2404
 
205 heavyiron 2405
prgname_ptr dd ?
2406
prgname_len dd ?
2407
 
542 diamond 2408
IncludeUGlobals
2409
 
4886 hidnplayr 2410
dbgwnd          dd ?
205 heavyiron 2411
 
4886 hidnplayr 2412
messages        rb messages_height*messages_width
2413
messages_pos    dd ?
205 heavyiron 2414
 
4886 hidnplayr 2415
cmdline         rb cmdline_width+1
2416
cmdline_len     dd ?
2417
cmdline_pos     dd ?
2418
curarg          dd ?
205 heavyiron 2419
 
4886 hidnplayr 2420
cmdline_prev    rb cmdline_width+1
205 heavyiron 2421
 
4886 hidnplayr 2422
was_temp_break  db ?
2423
symbol_section  db ?
205 heavyiron 2424
 
4886 hidnplayr 2425
dbgbufsize      dd ?
2426
dbgbuflen       dd ?
2427
dbgbuf          rb 256
542 diamond 2428
 
4886 hidnplayr 2429
fileattr        rb 40
3675 GerdtR 2430
 
205 heavyiron 2431
needzerostart:
2432
 
2433
context:
2434
 
4886 hidnplayr 2435
_eip    dd ?
2436
_eflags dd ?
2437
_eax    dd ?
2438
_ecx    dd ?
2439
_edx    dd ?
2440
_ebx    dd ?
2441
_esp    dd ?
2442
_ebp    dd ?
2443
_esi    dd ?
2444
_edi    dd ?
205 heavyiron 2445
oldcontext rb $-context
2446
 
3675 GerdtR 2447
mmx_context:
4886 hidnplayr 2448
_mm0    dq ?
2449
_mm1    dq ?
2450
_mm2    dq ?
2451
_mm3    dq ?
2452
_mm4    dq ?
2453
_mm5    dq ?
2454
_mm6    dq ?
2455
_mm7    dq ?
3675 GerdtR 2456
oldmmxcontext rb $-mmx_context
205 heavyiron 2457
 
3675 GerdtR 2458
fpu_context:
4886 hidnplayr 2459
_st0    dq ?
2460
_st1    dq ?
2461
_st2    dq ?
2462
_st3    dq ?
2463
_st4    dq ?
2464
_st5    dq ?
2465
_st6    dq ?
2466
_st7    dq ?
3675 GerdtR 2467
oldfpucontext rb $-fpu_context
2468
 
2469
sse_context:
4886 hidnplayr 2470
_xmm0   dq 2 dup ?
2471
_xmm1   dq 2 dup ?
2472
_xmm2   dq 2 dup ?
2473
_xmm3   dq 2 dup ?
2474
_xmm4   dq 2 dup ?
2475
_xmm5   dq 2 dup ?
2476
_xmm6   dq 2 dup ?
2477
_xmm7   dq 2 dup ?
3675 GerdtR 2478
oldssecontext rb $-sse_context
2479
 
2480
avx_context:
4886 hidnplayr 2481
_ymm0   dq 4 dup ?
2482
_ymm1   dq 4 dup ?
2483
_ymm2   dq 4 dup ?
2484
_ymm3   dq 4 dup ?
2485
_ymm4   dq 4 dup ?
2486
_ymm5   dq 4 dup ?
2487
_ymm6   dq 4 dup ?
2488
_ymm7   dq 4 dup ?
3675 GerdtR 2489
oldavxcontext rb $-avx_context
2490
 
2491
step_num dd 0
2492
proc_num dd 0
4886 hidnplayr 2493
dumpread dd ?
2494
dumppos  dd ?
2495
dumpdata rb dump_height*10h
3675 GerdtR 2496
 
205 heavyiron 2497
; breakpoint structure:
2498
; dword +0: address
2499
; byte +4: flags
2500
; bit 0: 1 <=> breakpoint valid
2501
; bit 1: 1 <=> breakpoint disabled
2502
; bit 2: 1 <=> one-shot breakpoint
2503
; bit 3: 1 <=> DRx breakpoint
2504
; byte +5: overwritten byte
2505
;          for DRx breaks: flags + (index shl 6)
2506
breakpoints_n = 256
4886 hidnplayr 2507
breakpoints     rb breakpoints_n*6
2508
drx_break       rd 4
205 heavyiron 2509
 
4886 hidnplayr 2510
disasm_buf_size dd ?
205 heavyiron 2511
 
4886 hidnplayr 2512
symbols         dd ?
2513
num_symbols     dd ?
542 diamond 2514
 
4886 hidnplayr 2515
bReload         db ?
205 heavyiron 2516
 
2517
needzeroend:
2518
 
4886 hidnplayr 2519
disasm_buffer           rb 256
2520
disasm_start_pos        dd ?
2521
disasm_cur_pos          dd ?
2522
disasm_cur_str          dd ?
2523
disasm_string           rb 256
205 heavyiron 2524
 
4886 hidnplayr 2525
i_param         rb 256
205 heavyiron 2526
 
2527
; stack
3675 GerdtR 2528
        align   400h
2529
        rb      400h
205 heavyiron 2530
used_mem:
3675 GerdtR 2531
 
2532
; vim: ft=fasm tabstop=4
2533