News:

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

How do you debug a macro?

Started by gwapo, September 12, 2006, 07:04:18 AM

Previous topic - Next topic

gwapo

Hi,

Right now, lame as it is, I am debugging macros by tracing it line by line, and making notes to ensure that it produces the result that I want. Maybe you guys can suggest me a better way, or the prefered way of debugging a macro, especially long and complicated ones.

Thanks,

-chris

MazeGen

As for important or public macros, I write a set of testing calls and if possible, I use ECHO to output some results. When some call doesn't seem to be working, I look at the listing (/Fl command line parameter) and I try to find the bug (.LISTMACROALL directive has to be used).

hutch--

Chris,

When I bother I use the /EP option then load the output file to see what has been done with the macro. I tend to make a very short file without the major includes where possible so that the expanded macro is easier to find.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

gwapo

Thanks MazeGen and Hutch, I think echoing and /EP is the one I am looking :dance:

-chris

Sergiu FUNIERU

Quote from: hutch-- on September 12, 2006, 10:08:51 AMWhen I bother I use the /EP option then load the output file to see what has been done with the macro. I tend to make a very short file without the major includes where possible so that the expanded macro is easier to find.
I want to try that.


I used this code, from which I removed the major include files (that is, I removed the include \masm32\include\masm32rt.inc line)
Quote from: jj2007 on February 28, 2010, 06:30:04 PM

.data
MySrcVar dd 123
MyDestVar dd 0

.code
start: m2m MyDestVar, MySrcVar
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
exit
end start


  ; memory to memory assignment
    ; ----------------------------
      m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM



This is the listing I got:
.data
.data
Error A2113: Model is not declared
MySrcVar dd 123
Error A2094: Must be in segment block
MyDestVar dd 0
Error A2094: Must be in segment block
.code
.code
Error A2113: Model is not declared
start: m2m MyDestVar, MySrcVar
Error A2094: Must be in segment block
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
Error A2233: Syntax error: MsgBox
exit
Error A2233: Syntax error: exit
end start
Error A2105: Invalid start address


I expected to see the expanded macro, yet I see the original one.

What I'm doing wrong?
Quote

dedndave

i think Jochen uses a few ECHO directives to help debug macros   :U

Sergiu FUNIERU

Quote from: dedndave on February 28, 2010, 10:02:07 PMi think Jochen uses a few ECHO directives to help debug macros   :U
Could you give me a short example, please?

dedndave

ECHO is very similar to the batch file ECHO
it just lets you display text at assembly time
so, if you want to test a condition, place something like

        ECHO    Condition True

in the assembler file at the appropriate place and it will echo "Condition True" at assembly
it is quite often used to display programmer-created warning and error messages

qWord

QuoteWhat I'm doing wrong?
include masm32rt.inc is missing.
IMO it is better to generate a listing using commandline switch /FlList.txt /Sn (->file=list.txt). Then place .nolist at top of source file. To see the expansion of macro, wrap the macro call with .listall and .nolist.
.nolist
include masm32rt.inc
...
.listall
;call here the macro
.nolist
FPU in a trice: SmplMath
It's that simple!

Sergiu FUNIERU

Quote from: qWord on February 28, 2010, 10:09:34 PM
QuoteWhat I'm doing wrong?
include masm32rt.inc is missing.
Quote
That one I disabled on purpose, to avoid listing all. I didn't know how to do it until I saw your example.

Well, it seems that I'm still doing something wrong, because when I try this:
.nolist
include \masm32\include\masm32rt.inc
.data
MySrcVar dd 123
MyDestVar dd 0
.code
start:
.listall
m2m MyDestVar, MySrcVar
.nolist
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
exit
end start


with the parameters you've told me, I receive this:
index.asm
                           .listall
00000000  FF3500000000     1 push MySrcVar
00000006  8F0504000000     index.asm: 13 lines, 2 passes, 156 ms, 0 warnings, 0 errors


I see there the push, but I don't see the pop from the macro.

Anyway, thank you for your answer. That is very close to what I want to do, except for that pop mention.

Sergiu FUNIERU

Quote from: Sergiu Funieru on February 28, 2010, 10:20:15 PM
Quote from: qWord on February 28, 2010, 10:09:34 PM
What I'm doing wrong?
include masm32rt.inc is missing.

That one I disabled on purpose, to avoid listing all. I didn't know how to do it until I saw your example.

Well, it seems that I'm still doing something wrong, because when I try this:
.nolist
include \masm32\include\masm32rt.inc
.data
MySrcVar dd 123
MyDestVar dd 0
.code
start:

.listall
m2m MyDestVar, MySrcVar

.nolist
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
exit
end start


with the parameters you've told me, I receive this:
index.asm
                           .listall
00000000  FF3500000000     1 push MySrcVar
00000006  8F0504000000     index.asm: 13 lines, 2 passes, 156 ms, 0 warnings, 0 errors


I see there the push, but I don't see the pop from the macro.

Anyway, thank you for your answer. That is very close to what I want to do, except for that pop mention.

jj2007

Quote from: Sergiu Funieru on February 28, 2010, 10:20:15 PM
What I'm doing wrong?

You are doing nothing wrong. JWasm has its little quirks...

JWasm v2.02pre, Dec 18 2009
Tmp_File.asm
                           .listall
00000000  FF3500000000     1 push MySrcVar
00000006  8F0500000000     Tmp_File.asm: 15 lines, 2 passes, 203 ms, 0 warnings, 0 errors


Microsoft (R) Macro Assembler Version 6.14.8444     03/01/10 00:06:06
tmp_file.asm      Page 1 - 1
start:

.listall
00000000  FF 35 00000000 R  1         push MySrcVar
00000006  8F 05 00000004 R  1         pop  MyDestVar
m2m MyDestVar, MySrcVar


Same code:
.nolist
include \masm32\include\masm32rt.inc

.data
MySrcVar dd 123
MyDestVar dd 0

.code
start:

.listall
m2m MyDestVar, MySrcVar
.nolist
MsgBox 0, str$(MyDestVar), "Masm mem to mem:", MB_OK
exit
end start

jj2007

Here is a simple example on using echo:
m2m MACRO M1, M2
LOCAL tmp$
tmp$ CATSTR <So you want me to move >, <M2>, < into >, <M1>, <, huh?>
echo
% echo tmp$
echo
; .err ;; if you remove the comment, the code will not assemble but you
;; still see what the macro does
push M2
pop M1
ENDM


Output window:

So you want me to move MySrcVar into MyDestVar, huh?