Subversion Repositories Kolibri OS

Rev

Rev 7677 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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