Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9353 leency 1
InitCmdHistBuffer:
2
;-------------------------------------------------------------------------------
3
        push    eax ebx ecx
4
 
5
        mcall   68,12,4096      ;allocate 4KB block
6
        mov     [CmdHistBuffer.Ptr],eax
7
        mov     [CmdHistBuffer.Size],ecx
8
 
9
        mov     edi,eax
10
        xor     eax,eax
11
        stosd
12
        stosd
13
        mov     [CmdHistBuffer.NewNodeOffset],eax
14
        mov     [CmdHistBuffer.LastNodeOffset],eax
15
        mov     [CmdHistBuffer.CurNodeOffset],eax
16
        mov     [CmdHistBuffer.TmpLineFlag],al
17
        mov     [CmdHistBuffer.NFlag],al
18
 
19
        pop     ecx ebx eax
20
        ret
21
;-------------------------------------------------------------------------------
22
 
23
EnlargeCmdHistBuffer:
24
;-------------------------------------------------------------------------------
25
        pusha
26
 
27
        mov     ecx,[CmdHistBuffer.Size]
28
        add     ecx,4096
29
        mov     edx,[CmdHistBuffer.Ptr]
30
        mcall   68,20           ;reallocate the buffer (prev. size + 4KB)
31
        test    eax,eax
32
        jz      .Err
33
        mov     [CmdHistBuffer.Ptr],eax
34
        mov     [CmdHistBuffer.Size],ecx
35
.OK:
36
        clc
37
        popa
38
        ret
39
.Err:
40
        stc
41
        popa
42
        ret
43
;-------------------------------------------------------------------------------
44
 
45
AddCmdHistLine:
46
;-------------------------------------------------------------------------------
47
;in:
48
;eax = ptr to ASCIIZ string of line
49
;-------------------------------------------------------------------------------
50
        pusha
51
 
52
        mov     esi,eax
53
        mov     edx,eax
54
        xor     ecx,ecx
55
@@:
56
        inc     ecx
57
        lodsb
58
        test    al,al
59
        jz      @F
60
        jmp     @B
61
@@:
62
        dec     ecx
63
        jz      .OK
64
 
65
        inc     ecx
66
 
67
        mov     eax,[CmdHistBuffer.NewNodeOffset]
68
        lea     eax,[eax+ecx+2*4]
69
        cmp     [CmdHistBuffer.Size],eax
70
        jae     @F
71
        call    EnlargeCmdHistBuffer
72
        jc      .Err
73
@@:
74
        mov     edi,[CmdHistBuffer.NewNodeOffset]
75
        mov     eax,[CmdHistBuffer.Ptr]
76
        add     edi,eax
77
        cmp     eax,edi                 ;if eax = edi, then it's the first node
78
        jne     @F
79
        xor     eax,eax
80
        dec     eax
81
        stosd                           ;save previous node link = -1 for the first node
82
        stosd                           ;save next node link = -1 for the first node
83
        jmp     .CPStr
84
@@:
85
        mov     ebx,[CmdHistBuffer.LastNodeOffset]
86
        mov     [edi],ebx               ;save previous node link for a new node
87
        add     ebx,eax
88
        mov     eax,[CmdHistBuffer.NewNodeOffset]
89
        mov     [ebx+4],eax             ;update next node link for a last node
90
        mov     [CmdHistBuffer.LastNodeOffset],eax
91
        mov     [CmdHistBuffer.CurNodeOffset],eax
92
        add     edi,4
93
        xor     eax,eax
94
        dec     eax
95
        stosd
96
.CPStr:
97
        mov     esi,edx
98
 
99
        push    ecx
100
        rep     movsb
101
        pop     ecx
102
 
103
        add     ecx,2*4
104
        add     [CmdHistBuffer.NewNodeOffset],ecx
105
.OK:
106
        clc
107
.Err:
108
        mov     [CmdHistBuffer.TmpLineFlag],0
109
        popa
110
        ret
111
;-------------------------------------------------------------------------------
112
 
113
AddCmdHistTmpLine:
114
;-------------------------------------------------------------------------------
115
;in:
116
;eax = ptr to ASCIIZ string of line
117
;-------------------------------------------------------------------------------
118
        pusha
119
 
120
        mov     esi,eax
121
        mov     edx,eax
122
        xor     ecx,ecx
123
@@:
124
        inc     ecx
125
        lodsb
126
        test    al,al
127
        jz      @F
128
        jmp     @b
129
@@:
130
        mov     eax,[CmdHistBuffer.NewNodeOffset]
131
        lea     eax,[eax+ecx+2*4]
132
        cmp     [CmdHistBuffer.Size],eax
133
        jae     @F
134
        call    EnlargeCmdHistBuffer
135
        jc      .Err
136
@@:
137
        mov     edi,[CmdHistBuffer.NewNodeOffset]
138
        mov     [CmdHistBuffer.TmpLineFlag],1
139
        mov     eax,[CmdHistBuffer.Ptr]
140
        add     edi,eax
141
        xor     eax,eax
142
        stosd
143
        stosd   ;two zeroes - marker (prefix) of tmp line
144
.CPStr:
145
        mov     esi,edx
146
        rep     movsb
147
.OK:
148
        clc
149
.Err:
150
        popa
151
        ret
152
;-------------------------------------------------------------------------------
153
 
154
GetCmdHistLine:
155
;-------------------------------------------------------------------------------
156
;out:
157
;eax = ptr to ASCIIZ string of current line
158
;-------------------------------------------------------------------------------
159
        push    ebx
160
 
161
        mov     eax,[CmdHistBuffer.Ptr]
162
        mov     ebx,[CmdHistBuffer.CurNodeOffset]
163
 
164
        lea     eax,[eax+ebx+2*4]
165
 
166
        pop     ebx
167
        ret
168
;-------------------------------------------------------------------------------
169
 
170
GetCmdHistTmpLine:
171
;-------------------------------------------------------------------------------
172
;out:
173
;eax = ptr to ASCIIZ string of current line or 0 (no tmp line)
174
;-------------------------------------------------------------------------------
175
        cmp     [CmdHistBuffer.TmpLineFlag],0
176
        je      @F
177
 
178
        mov     eax,[CmdHistBuffer.NewNodeOffset]
179
        add     eax,[CmdHistBuffer.Ptr]
180
        add     eax,2*4
181
@@:
182
        ret
183
;-------------------------------------------------------------------------------
184
 
185
PrevCmdHistLine:
186
;-------------------------------------------------------------------------------
187
;out:
188
;CF = 0 - OK, CF = 1 (no previous lines)
189
;-------------------------------------------------------------------------------
190
        push    eax ebx
191
 
192
        mov     eax,[CmdHistBuffer.Ptr]
193
        mov     ebx,[CmdHistBuffer.CurNodeOffset]
194
 
195
        lea     eax,[eax+ebx]
196
        mov     eax,[eax]
197
        inc     eax
198
        jz      .RetCF
199
        dec     eax
200
        mov     [CmdHistBuffer.CurNodeOffset],eax
201
 
202
        clc
203
        pop     ebx eax
204
        ret
205
.RetCF:
206
        stc
207
        pop     ebx eax
208
        ret
209
;-------------------------------------------------------------------------------
210
 
211
NextCmdHistLine:
212
;-------------------------------------------------------------------------------
213
;out:
214
;CF = 0 - OK, CF = 1 (no next lines)
215
;-------------------------------------------------------------------------------
216
        push    eax ebx
217
 
218
        mov     eax,[CmdHistBuffer.Ptr]
219
        mov     ebx,[CmdHistBuffer.CurNodeOffset]
220
 
221
        lea     eax,[eax+ebx]
222
        mov     eax,[eax+4]
223
        inc     eax
224
        jz      .RetCF
225
        dec     eax
226
        mov     [CmdHistBuffer.CurNodeOffset],eax
227
 
228
        clc
229
        pop     ebx eax
230
        ret
231
.RetCF:
232
        stc
233
        pop     ebx eax
234
ClearCmdLineEnd:
235
        ret
236
;-------------------------------------------------------------------------------
237
 
238
DrawCmdLine:
239
        pushad
240
        xor     ebx,ebx
241
        jmp     @F
242
 
243
DrawCmdLineEnd:
244
        pushad
245
        mov     ebx,[CmdLinePos]
246
    @@:
247
        call    ClearCmdLine
248
 
249
        mov     [XPos],1
250
        mov     [YPos],MinHeight-1
251
        mov     [Color],15
252
        mov     al,'>'
253
        call    PrintC
254
        mov     ecx,[CmdLineLen]
255
        sub     ecx,ebx
256
        jbe     .Skip
257
        lea     esi,[CmdLine+ebx]
258
    .Loop:
259
        lodsb
260
        call    PrintC
261
        loop    .Loop
262
    .Skip:
263
        popad
264
        ret
265
 
266
DrawCursor:
267
        pushad
268
        mov     eax,[CmdLinePos]
269
times 2 inc     eax
270
        mov     [CursorX],eax
271
        mov     [CursorY],MinHeight-1
272
        mov     [AfterKey],1
273
        call    ShowImage
274
        popad
275
        ret
276
 
277
HideCursor:
278
        pushad
279
        or      [CursorX],-1
280
        or      [CursorY],-1
281
        mov     [AfterKey],1
282
        call    ShowImage
283
        popad
284
        ret
285
 
286
;-----------------------------------------------------------------------------
287
;                          Find command in list
288
FindCmd:
289
; all commands are case-insensitive
290
        push    edi
291
    .X4:
292
        mov     al,[edi]
293
        cmp     al,0
294
        jz      .X5
295
        cmp     al,'A'
296
        jb      @F
297
        cmp     al,'Z'
298
        ja      @F
299
        or      al,20h
300
    @@:
301
        stosb
302
        jmp     .X4
303
 
304
    ; find command
305
    .X5:
306
        pop     edi
307
    .X6:
308
        cmp     dword [esi],0
309
        jz      .X7
310
        push    esi
311
        mov     esi,[esi]
312
        lodsb
313
        movzx   ecx,al
314
        push    edi
315
        repz    cmpsb
316
        pop     edi
317
        pop     esi
318
        jz      .X8
319
        add     esi,17
320
        jmp     .X6
321
    .X7:
322
        stc
323
    .X8:
324
        ret
325
 
326
HelpGroups:
327
        dd      aControl,0,0,HelpControlMsg
328
        db      0
329
        dd      aData,0,0,HelpDataMsg
330
        db      0
331
        dd      aBreakpoints,0,0,HelpBreaksMsg
332
        db      0
333
; flags field:
334
; &1: command may be called without parameters
335
; &2: command may be called with parameters
336
; &4: command may be called without loaded program
337
; &8: command may be called with loaded program
338
Commands:
339
        dd      aHlp,OnHelp,HelpSyntax,HelpHelp
340
        db      0Fh
341
        dd      aHelp,OnHelp,HelpSyntax,HelpHelp
342
        db      0Fh
343
        dd      aQuit,OnQuit,QuitSyntax,QuitHelp
344
        db      0Dh
345
        dd      aExit,OnQuit,ExitSyntax,ExitHelp
346
        db      0Dh
347
        dd      aLoad,OnLoad,LoadSyntax,LoadHelp
348
        db      6
349
        dd      aReload,OnReLoad,ReloadSyntax,ReloadHelp
350
        db      0Dh
351
        dd      aTerminate,OnTerminate,TerminateSyntax,TerminateHelp
352
        db      9
353
        dd      aDetach,OnDetach,DetachSyntax,DetachHelp
354
        db      9
355
        dd      aSuspend,OnSuspend,SuspendSyntax,SuspendHelp
356
        db      9
357
        dd      aResume,OnResume,ResumeSyntax,ResumeHelp
358
        db      0Bh
359
        dd      aStep,OnStepMultiple,StepSyntax,StepHelp
360
        db      0Bh
361
        dd      aProceed,OnProceedMultiple,ProceedSyntax,ProceedHelp
362
        db      0Bh
363
        dd      aCalc,OnCalc,CalcSyntax,CalcHelp
364
        db      0Eh
365
        dd      aDump,OnDump,DumpSyntax,DumpHelp
366
        db      0Bh
367
       ;dd      aUnassemble,OnUnassemble,UnassembleSyntax,UnassembleHelp
368
       ;db      0Bh
369
        dd      aBp,OnBp,BpSyntax,BpHelp
370
        db      0Ah
371
        dd      aBpm,OnBpmb,BpmSyntax,BpmHelp
372
        db      0Ah
373
        dd      aBpmb,OnBpmb,BpmSyntax,BpmHelp
374
        db      0Ah
375
        dd      aBpmw,OnBpmw,BpmSyntax,BpmHelp
376
        db      0Ah
377
        dd      aBpmd,OnBpmd,BpmSyntax,BpmHelp
378
        db      0Ah
379
        dd      aBl,OnBl,BlSyntax,BlHelp
380
        db      0Bh
381
        dd      aBc,OnBc,BcSyntax,BcHelp
382
        db      0Ah
383
        dd      aBd,OnBd,BdSyntax,BdHelp
384
        db      0Ah
385
        dd      aBe,OnBe,BeSyntax,BeHelp
386
        db      0Ah
387
        dd      aReg,OnReg,RSyntax,RHelp
388
        db      0Ah
389
        dd      aUnpack,OnUnpack,UnpackSyntax,UnpackHelp
390
        db      9
391
        dd      aLoadSymbols,OnLoadSymbols,LoadSymbolsSyntax,LoadSymbolsHelp
392
        db      0Ah
393
        ;
394
        dd      aAsm,OnAsm,AsmSyntax,AsmHelp
395
        db      2+8
396
        dd      aJump,OnJump,JumpSyntax,JumpHelp
397
        db      2+8
398
        dd      aDoLoad,DoLoad,DoLoadSyntax,DoLoadHelp
399
        db      1+4
400
        ;
401
        dd      0
402
 
403
aHelp   db      5,'help',0
404
aHlp    db      2,'h',0
405
HelpHelp db     'Help on specified function',10
406
HelpSyntax db   'Usage: h or help [group | command]',10,0
407
 
408
HelpMsg db     'List of known command groups:',10
409
        db      '"help control"     - display list of control commands',10
410
        db      '"help data"        - display list of commands concerning data',10
411
        db      '"help breakpoints" - display list of commands concerning breakpoints',10,0
412
 
413
aAsm    db      2,'a',0
414
AsmHelp db      'Assemble instruction at current position',10
415
AsmSyntax db    'Usage: a instruction (',8,8Ah,'mov al,[ebx+12h]',8,8Fh,')',10,0
416
 
417
aJump   db      2,'j',0
418
JumpHelp db     'Sets current window or current register new address',10
419
JumpSyntax db   'Usage: Jump ',10,0
420
 
421
aDetach db      7,'detach',0
422
DetachHelp db   'Detach from debugged program',10
423
DetachSyntax db 'Usage: detach',10,0
424
 
425
aSuspend db     5,'stop',0
426
SuspendHelp db  'Suspend execution of debugged program',10
427
SuspendSyntax db 'Usage: stop',10,0
428
 
429
aQuit   db      5,'quit',0
430
QuitHelp db     'Quit from debugger',10
431
QuitSyntax db   'Usage: quit',10,0
432
 
433
aExit   db      5,'exit',0
434
ExitHelp db     'Exit from debugger',10
435
ExitSyntax db   'Usage: exit',10,0
436
 
437
aLoad   db      5,'load',0
438
LoadHelp db     'Load program for debugging',10
439
LoadSyntax db   'Usage: load  [parameters]',10,0
440
 
441
aDoLoad  db     7,'doload',0
442
DoLoadHelp db   'Load test program for debugging',10
443
DoLoadSyntax db 'Usage: doload',10,0
444
 
445
aReload db      7,'reload',0
446
ReloadHelp db   'Reload debugging program (restart debug session)',10
447
ReloadSyntax db 'Usage: reload',10,0
448
 
449
aTerminate db   10,'terminate',0
450
TerminateHelp db 'Terminate debugged program',10
451
TerminateSyntax db 'Usage: terminate',10,0
452
 
453
aResume db      2,'g',0
454
ResumeHelp db   'Go (resume execution of debugged program)',10
455
ResumeSyntax db 'Usage: g',10
456
        db      '   or: g  - wait until specified address is reached',10,0
457
 
458
aStep   db      2,'s',0
459
StepHelp db     'Make step in debugged program',10
460
StepSyntax db   'Usage: s []',10,0
461
 
462
aProceed db     2,'p',0
463
ProceedHelp db  'Make wide step in debugged program (step over CALL, REPxx, LOOP)',10
464
ProceedSyntax db 'Usage: p []',10,0
465
 
466
aDump   db      2,'d',0
467
DumpHelp db     'Dump data of debugged program',10
468
DumpSyntax db   'Usage: d  - dump data at specified address',10
469
        db      '   or: d              - continue current dump',10,0
470
 
471
aCalc   db      2,'?',0
472
CalcHelp db     'Calculate value of expression',10
473
CalcSyntax db   'Usage: ? ',10,0
474
 
475
aReg    db      2,'r',0
476
RHelp   db      'Set register value',10
477
RSyntax db      'Usage: r  ',10
478
        db      '   or: r = - set value of  to ',10,0
479
 
480
aBp     db      3,'bp',0
481
BpHelp  db      'set BreakPoint on execution',10
482
BpSyntax db     'Usage: bp ',10,0
483
 
484
aBpm    db      4,'bpm',0
485
aBpmb   db      5,'bpmb',0
486
aBpmw   db      5,'bpmw',0
487
aBpmd   db      5,'bpmd',0
488
BpmHelp db      'set BreakPoint on Memory access',10
489
        db      'Maximum 4 breakpoints of this type are allowed',10
490
        db      'Note that for this breaks debugger is activated after access',10
491
BpmSyntax db    'Usage: bpmb [w] ',10
492
        db      '       bpmw [w] ',10
493
        db      '       bpmd [w] ',10
494
        db      '       bpm is synonym for bpmd',10
495
        db      '"w" means break only on writes (default is on read/write)',10,0
496
 
497
aBl     db      3,'bl',0
498
BlHelp  db      'Breakpoint List',10
499
BlSyntax db     'Usage: bl          - list all breakpoints',10
500
        db      '       bl  - display info on particular breakpoint',10,0
501
 
502
aBc     db      3,'bc',0
503
BcHelp  db      'Breakpoint Clear',10
504
BcSyntax db     'Usage: bc ',10
505
        db      'Examples: bc 2',10
506
        db      '          bc 1 3 4 A',10,0
507
 
508
aBd     db      3,'bd',0
509
BdHelp  db      'Breakpoint Disable',10
510
BdSyntax db     'Usage: bd ',10
511
        db      'Examples: bd 2',10
512
        db      '          bd 1 3 4 A',10,0
513
 
514
aBe     db      3,'be',0
515
BeHelp  db      'Breakpoint Enable',10
516
BeSyntax db     'Usage: be ',10
517
        db      'Examples: be 2',10
518
        db      '          be 1 3 4 A',10,0
519
 
520
aUnpack db      7,'unpack',0
521
UnpackHelp db   'Try to bypass unpacker code',10
522
UnpackSyntax db 'Usage: unpack',10,0
523
 
524
aLoadSymbols db 13,'load-symbols',0
525
LoadSymbolsHelp db 'Load symbolic information for executable',10
526
LoadSymbolsSyntax db 'Usage: load-symbols ',10,0
527
 
528
;               Control commands group
529
aControl db     8,'control',0
530
HelpControlMsg db     'List of control commands:',10
531
        db      'h = help             - help',10
532
        db      'exit/quit            - exit from debugger',10
533
        db      'load  [params] - load program for debugging',10
534
        db      'reload               - reload debugging program',10
535
        db      'load-symbols   - load information on symbols for program',10
536
        db      'terminate            - terminate loaded program',10
537
        db      'detach               - detach from debugging program',10
538
        db      'stop                 - suspend execution of debugging program',10
539
        db      'a       - assemble instruction at current position',10
540
        db      'g []     - go on (resume execution of debugging program)',10
541
        db      's []            - program step, also ',10
542
        db      'p []            - program wide step, also ',10
543
        db      'unpack               - try to bypass unpacker code (heuristic)',10,0
544
 
545
;               Data commands group
546
aData   db      5,'data',0
547
HelpDataMsg db        'List of data commands:',10
548
        db      '?        - calculate value of expression',10
549
        db      'd []     - dump data at given address',10
550
        db      'j        - jump, current window or current register new address',10
551
       ;db      'u []     - unassemble instructions at given address',10
552
        db      'r   or',10
553
        db      'r = - set register value',10,0
554
 
555
;               Breakpoints commands group
556
aBreakpoints db 12,'breakpoints',0
557
HelpBreaksMsg db      'List of breakpoints commands:',10
558
        db      'bp       - set breakpoint on execution',10
559
        db      'bpm[b|w|d]   - set breakpoint on memory access',10
560
        db      'bl []        - breakpoint(s) info',10
561
        db      'bc ...       - clear breakpoint',10
562
        db      'bd ...       - disable breakpoint',10
563
        db      'be ...       - enable breakpoint',10,0
564
;