News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Multi value debugging macro.

Started by hutch--, June 18, 2008, 11:44:41 AM

Previous topic - Next topic

jj2007

Quote from: Jimg on June 20, 2008, 04:35:12 PM
You may want to kill that particular loop, but further down in the program, you may want to look at different info with a different mbdebug.  Perhaps it should return a flag for the main program to test?
...
also, you can certainly save edx if you want to be able to print it-

You are full of good ideas, young man. Here is the luxury version ;-)

[attachment deleted by admin]

hutch--

Here is a variation that is probably more useful, instead of controling the display, it just creates a string that you can display at the console or in a GUI app in a messagebox, the titlebar or the statusbar. It has had Jim's mod done on it. I would like to see JJs version seperate so it can control the text as a column.



; code
    mov ptxt, mval$("Remainder =",rmnd,"algn =",algn)
    fn MessageBox,0,ptxt,"Results",MB_OK

; macro
     mval$ MACRO args:VARARG
      pushad
      pushfd
      IFNDEF @_buff_@
      .data?
        @_buff_@ db 1024 dup (?)
      .data
        @@_bptr_@@ dd @_buff_@
      .code
      ENDIF
        mov eax, OFFSET @_buff_@
        mov DWORD PTR [eax], 0
        for arg, <args>
          quot SUBSTR <arg>,1,1
            IFIDN quot,<">
              mov @@_bptr_@@, cat$(@@_bptr_@@,arg)
            ELSE
              mov @@_bptr_@@, cat$(@@_bptr_@@,sstr$(arg)," ")
            ENDIF
        ENDM
      popfd
      popad
      mov eax, OFFSET @_buff_@
      EXITM <eax>
    ENDM
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hutch--

Since I have had some time to play with this today, here is a more powerful version that does either horizontal or column list style display with either signed or unsigned values.

Calling code

    mov ptxt, mval$("cPos=",cPos,lf,"tabSize=",tabSize,lf,"Remainder=",rmnd,lf,"algn=",*algn)
    print ptxt,13,10


Source code

    mval$ MACRO args:VARARG
    ;; ------------------------------------------------
    ;; macro accepts 4 classes of input
    ;;   1. quoted text
    ;;   2. unsigned value with a leading "*" EG *myval
    ;;   3. signed value
    ;;   4. a line feed using the notation "lf"
    ;; ------------------------------------------------
      pushad
      pushfd
      IFNDEF @_buff_@
      .data?
        @_buff_@ db 1024 dup (?)
      .data
        @@_bptr_@@ dd @_buff_@
      .code
      ENDIF
        mov eax, OFFSET @_buff_@
        mov DWORD PTR [eax], 0
        for arg, <args>
          char1 SUBSTR <arg>,1,1                                ;; get 1st character
          char2 SUBSTR <arg>,1,2                                ;; get 1st TWO characters
          char3 SUBSTR <arg>,2
            IFIDN char1,<">
              mov @@_bptr_@@, cat$(@@_bptr_@@,arg)              ;; add quoted text
              goto label0
            ENDIF
            IFIDN char2,<lf>
              mov @@_bptr_@@, cat$(@@_bptr_@@,chr$(13,10))      ;; add line feed
              goto label0
            ENDIF
            IFIDN char1,<*>
              item textequ char3
              mov @@_bptr_@@, cat$(@@_bptr_@@,ustr$(item)," ")  ;; add unsigned arg converted to string
              goto label0
            ENDIF
            mov @@_bptr_@@, cat$(@@_bptr_@@,sstr$(arg)," ")     ;; add signed arg converted to string
        :label0
        ENDM
      popfd
      popad
      mov eax, OFFSET @_buff_@
      EXITM <eax>
    ENDM
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on June 22, 2008, 04:25:11 AM
Calling code

    mov ptxt, mval$("cPos=",cPos,lf,"tabSize=",tabSize,lf,"Remainder=",rmnd,lf,"algn=",*algn)
    print ptxt,13,10


For a debugging macro, I would refuse to type the var names twice... will stick to my version  :wink

Jimg

Hutch-

Because it couldn't handle a single character variable name and I wanted to pass the name or address of a string, I was playing around-

    mvalx$ MACRO args:VARARG
    ;; ------------------------------------------------
    ;; macro accepts 6 classes of input
    ;;   1. quoted text
    ;;   2. unsigned value with a leading "*" EG *myval
    ;;   3. signed value
    ;;   4. a line feed using the notation "lf"
    ;;   5. name of a string variable if leading /  eg. /MyStr
    ;;   6. address of a string if leading //  eg. //MyStrAddr
    ;; ------------------------------------------------
      pushad
      pushfd
      IFNDEF @_buff_@
      .data?
        @_buff_@ db 1024 dup (?)
      .data
        @@_bptr_@@ dd @_buff_@
      .code
      ENDIF
        mov eax, OFFSET @_buff_@
        mov DWORD PTR [eax], 0
        for arg, <args>
          char1 SUBSTR <arg>,1,1                                ;; get 1st character
          if @SizeStr(<arg>) GT 1
            char2 SUBSTR <arg>,1,2                              ;; get 1st TWO characters
            char3 SUBSTR <arg>,2
            if @SizeStr(<arg>) GT 2
              char4 substr <arg>,3
            endif
          endif
            IFIDN char1,<">
              mov @@_bptr_@@, cat$(@@_bptr_@@,arg)              ;; add quoted text
              goto label0
            ENDIF
            IFIDN <arg>,<lf>
              mov @@_bptr_@@, cat$(@@_bptr_@@,chr$(13,10))      ;; add line feed
              goto label0
            ENDIF
            IFIDN char1,<*>
              item textequ char3
              mov @@_bptr_@@, cat$(@@_bptr_@@,ustr$(item)," ")  ;; add unsigned arg converted to string
              goto label0
            ENDIF
            if @SizeStr(<arg>) GT 2
                IFIDN char2,<//>
                  item textequ char4
                  mov @@_bptr_@@, cat$(@@_bptr_@@,<item>," ")  ;; was address of a string
                  goto label0
                ENDIF
            endif
            if @SizeStr(<arg>) GT 1
                IFIDN char1,</>
                  item textequ char3
                  mov @@_bptr_@@, cat$(@@_bptr_@@,addr(item)," ")  ;; was name of a string
                  goto label0
                ENDIF
            endif
            mov @@_bptr_@@, cat$(@@_bptr_@@,sstr$(arg)," ")     ;; add signed arg converted to string
        :label0
        ENDM
      popfd
      popad
      mov eax, OFFSET @_buff_@
      EXITM <eax>
    ENDM
.data
q     dd 99
cPos  dd 20
ptxt  dd 0
tSize dd 6
algn  dd 8
lfont dd 10
qtd db 'This is "quoted".',0
MyPath  db "MulDbgMacro.asm", 0
aMyPath dd txMyPath
.code
    mov ptxt, mvalx$("cPos=",cPos,lf,"tSize=",tSize,lf,"lfont=",lfont,lf ,"q = ",q,lf,"algn=",*algn,lf,"quoted=","This is ""quoted"".",lf,"quoted2=",/qtd,lf,"/path = ",/txMyPath,lf,"//path = ",//MyFilePath$)
    print ptxt,13,10

A big kludge at the moment, but might be worth a look.  There's probably a better way to distinguish strings but I couldn't think of one.

jj2007

Quote from: Jimg on June 22, 2008, 05:16:54 PM
There's probably a better way to distinguish strings but I couldn't think of one.
It depends on whether you are willing to commit the sacrilege of using $ as string suffix ;-)

I have tried to put my previous "luxury" and your version together, see attachment. You might ruthlessly steal some of my code to get register display and multi-slots working - at present eax, ecx and edx don't work. I discovered that my code can handle extra quotes, see the MsgBox, last line.

EolMode equ 13, 10
; EolMode equ 32,32,32,32 ; for horizontal display


I added this equate to allow horizontal display, although, frankly speaking, I can hardly imagine a situation where this would be advantageous.

EDIT: Is there a good explanation why...

   mov ptxt, mvalx$("cPos=",cPos,lf,"tSize=",tSize,lf,"lfont=",lfont,lf ,"q = ",q,lf,"algn=",*algn,lf,"quoted=",\
   "This is ""quoted"".",lf,"quoted2=",/qtd,lf,"/path = ",/txMyPath,lf,"//path = ",//MyFilePath$)

... the line continuation character is not being interpreted correctly?

[attachment deleted by admin]