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

hutch--

I am doing a job at the moment that needs to show multiple values at any given point of the procedure so I put this macro together. It suits my purpose at the moment to show signed values but it could be twiddled easily enough to do unsigned.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    mbDebug MACRO txt_title,args:VARARG
      LOCAL buff,bptr,slen,rslt
      pushad
      pushfd
      .data?
        buff db 8192 dup (?)
      .data
        bptr dd buff
      .code
        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
        fn MessageBox,0,rslt,txt_title,MB_OK
      popfd
      popad
    ENDM

    .code

start:

    call main
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL var1  :DWORD
    LOCAL var2  :DWORD
    LOCAL var3  :DWORD

    mov var1, 111
    mov var2, 222
    mov var3, 333

    mbDebug "Debug Test","var1 = ",var1,"var2 = ",var2," var3 = ",var3

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Nice, but the fn MessageBox throws an error on my installation (Masm32 v10 of 26.5.2008).
This one works fine:

              mov bptr, cat$(bptr,sstr$(arg),chr$(13,10))  ; CrLf's look better ;-)
            ENDIF
        ENDM
        invoke MessageBox,0,addr buff, reparg(txt_title),MB_OK
        ; fn MessageBox,0,rslt, txt_title,MB_OK

Errors:
tmp_file.asm(47) : error A2006: undefined symbol : ??001C
fn(5): Macro Called From
  mbDebug(20): Macro Called From
   tmp_file.asm(47): Main Line Code
tmp_file.asm(47) : error A2114: INVOKE argument type mismatch : argument : 2
fn(5): Macro Called From
  mbDebug(20): Macro Called From
   tmp_file.asm(47): Main Line Code

hutch--

jj,

Have you changed anything, the macro should be able to pass a quoted text and the cat$ macro should be able to put it into the list.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

herge

 Hi jj:

I get similiar errors.


C:\masm32\bin>/masm32/bin/ML.exe /c /coff /Zi /Zd /nologo dbgmac.asm
Assembling: dbgmac.asm
dbgmac.asm(49) : error A2006: undefined symbol : ??001C
fn(5): Macro Called From
  mbDebug(19): Macro Called From
   dbgmac.asm(49): Main Line Code
dbgmac.asm(49) : error A2114: INVOKE argument type mismatch : argument : 2
fn(5): Macro Called From
  mbDebug(19): Macro Called From
   dbgmac.asm(49): Main Line Code


This is a very recent install.

Regards herge.
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

hutch--

I may have posted the wrong one.

Try this.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    mbDebug MACRO txt_title,args:VARARG
      LOCAL buff,bptr
      pushad
      pushfd
      .data?
        buff db 8192 dup (?)
      .data
        bptr dd buff
      .code
        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
        fn MessageBox,0,bptr,txt_title,MB_OK
      popfd
      popad
    ENDM

    .code

start:

    call main
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL var1  :DWORD
    LOCAL var2  :DWORD
    LOCAL var3  :DWORD

    mov var1, 111
    mov var2, 222
    mov var3, 333

    mbDebug "Debug Test","var1 = ",var1,"var2 = ",var2,"var3 = ",var3

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jimg

====SNATCH=====

I like that macro, thanks Hutch.   I made a small change to reuse the buffer space for calling from multiple places-
    mbDebug MACRO txt_title,args:VARARG
      pushad
      pushfd
      ifndef mbDebugbuff
          .data?
            mbDebugbuff db 8192 dup (?)
            mbDebugbptr dd ?
          .code
      endif
        mov eax, OFFSET mbDebugbuff
        mov mbDebugbptr,eax
        mov DWORD PTR [eax], 0
        for arg, <args>
          quot SUBSTR <arg>,1,1
            IFIDN quot,<">
              mov mbDebugbptr, cat$(mbDebugbptr,arg," ")
            ELSE
              mov mbDebugbptr, cat$(mbDebugbptr,sstr$(arg),"     ")
            ENDIF
        ENDM
        fn MessageBox,0,mbDebugbptr,txt_title,MB_OK
      popfd
      popad
    ENDM

jj2007

Quote from: hutch-- on June 18, 2008, 02:31:37 PM
I may have posted the wrong one.

Try this.

Yep, that one works, but mine with the CrLf's is more beautiful  :toothy

herge


Hi hutch-:

It works for me!
Good Work.

Regards herge.
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

hutch--

I like both of the suggested mods, I originally wrote it to have different data for each call but Jims mod makes sense as it only ever displays data one at a time.

JJs change of putting a CRLF instead of the spacing is also something I would like as an option as I can see the use of both display formats. MAybe as an optional trailing parameter IFIDN arg, <CRLF> or similar.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

I couldn't resist the temptation to refine it a little bit...

[attachment deleted by admin]

hutch--

jj,

It looks good. I would like to see a version that can do either horizontal display like the original or the vertical list that your version does. It only needs an extra argument, 0 or 1 and it could choose to do either.


macroname 0,"Tite text","arg1 = ",arg1 etc ....
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on June 20, 2008, 08:48:22 AM
It looks good.
Thanks :green

We are quickly approaching perfection:

   mbDebug "Show me five variables:",\
   MyCounter, My2ndVar, MyThirdVar, MyFilePath$, MyGreets$

Full code attached.

[attachment deleted by admin]

Jimg

jj-

Try running two or more mbdebugs in one program.

Also, once you get that fixed, if you set a permanent flag when the user stops a loop, you will not be able to use the macro again.

jj2007

Quote from: Jimg on June 20, 2008, 02:37:03 PM
Try running two or more mbdebugs in one program.
Delete this line:
LOCAL mbDebugbptr
Thanks for the hint...

Quote
Also, once you get that fixed, if you set a permanent flag when the user stops a loop, you will not be able to use the macro again.

That's the whole point: You are stuck in an 1000 iterations loop and want to finish the proggie without killing it. So press Cancel and you are done. I've used that feature many times...

Jimg

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?
I can certainly see both sides of the issue, to each his own.

also, you can certainly save edx if you want to be able to print it-

push edx
mov edx, OFFSET mbDebugbuff
mov mbDebugbptr, edx
mov DWORD PTR [edx], 0
pop edx


or perhaps better don't use it at all-

push OFFSET mbDebugbuff
pop mbDebugbptr
mov byte ptr mbDebugbuff, 0