include \masm32\MasmBasic\MasmBasic.inc
StackWalk ; click menu Help/Profiling to see results
SetWatch lastMenu ; find out who changes this variable
... more ...
With these two lines, all procedures check, when returning, whether the variable "lastMenu" was changed. If lastMenu was changed (in this case by clicking into one of the file menu entries), a console opens and displays this kind of text:
## lastMenu changed by ShowMenu to 104
## lastMenu changed by WndProc to 104
## lastMenu changed by ShowMenu to 101
## lastMenu changed by WndProc to 101
This works for local and global dwords and strings, and even for DWORD arrays (e.g. as SetWatch MyInt(ecx)).
In addition, the StackWalk macro allows to profile an application, i.e. to check which procs cost how much time. Example (when clicking on menu Help/Profile):
#count proc ...called by args
1 WinMain _Kernel32
343 WndProc _User32 002E1D92 00000111 00000069 00000000
344 ShowMenu WndProc 00000069
577 WndProc _User32 002E1D92 00000111 00000068 00000000
578 ShowMenu WndProc 00000068
697 WndProc _User32 002E1D92 00000111 00000067 00000000
698 ShowMenu WndProc 00000067
810 WndProc _User32 002E1D92 00000111 00000065 00000000
811 ShowMenu WndProc 00000065
1579 WndProc _User32 002E1D92 0000000F 00000000 00000000
1580 MbSwShow _Kernel32 002E1D92
1598 WndProc _User32 002E1D92 00000200 00000000 00090056
Name #called total time per call
WndProc 1592 76 ms 48 us
## Hit any key. Ctrl C may cause data loss. Press 'h' to hide the console, 'r' to reset ##
The upper half shows a stack walk, the lower half shows how much time was passed in the WndProc callback.
This is a pretty simple example with only one relevant function (source & exe are attached). In contrast, see below what the RichMasm editor displays (to see this, press F9, hold Ctrl and click "No"):
#count proc ...called by args
24256 SubRE _User32 00650AA0 000000BA 00000000 00000000
24586 gtbP SetLcBufferP
26279 WndProc _User32 006D0444 0000000F 00000000 00000000
26280 GdiInitP WndProc
26290 WndProcMenu _User32 007C13CE 0000000F 00000000 00000000
26295 TextOutPlus WndProcMenu 00000040 0059DAAC 0000017C 00000003 0059DAAC 00000006
26303 WndProc _User32 006D0444 00000111 04000004 00650AA0
26304 DrawPics SubRE
26307 SubRE _User32 00650AA0 000000D7 00000000 0018F978
26308 DelRegions DrawPics
26309 SetLcBufferP DrawPics
26310 gtbP SetLcBufferP
26312 SubRE _User32 00650AA0 000000BA 00000000 00000000
26313 gtbP SetLcBufferP
26341 CbTimer _User32 006D0444 00000113 FFFFFF81 2402D564
26342 DispMenu CbTimer
26355 WndProcMenu _User32 007C13CE 0000000F 00000000 00000000
26360 TextOutPlus WndProcMenu 00000040 0059DB2C 0000017C 00000003 0059DB2C 00000006
26414 CbTimer _User32 006D0444 00000113 FFFFFF81 2402D620
26415 DrawBookmark CbTimer
26502 CbTimer _User32 006D0444 00000113 FFFFFF81 2402DA64
26503 BubbleHelp CbTimer
26506 WndProc _User32 006D0444 00000111 0001007F 00000000
26507 MyTest WndProc
26510 WndProc _User32 006D0444 00000006 00000000 008103FA
26511 SetTTP WndProc
26512 ClosePopup WndProc
26513 DispMenu ClosePopup
26514 SetTTP ClosePopup
26579 WndProcMenu _User32 007C13CE 0000000F 00000000 00000000
26584 TextOutPlus WndProcMenu 00000040 0059DF44 0000017C 00000003 0059DF44 00000006
26585 MbSwShow _Kernel32 006D0444
26601 WndProcMenu _User32 007C13CE 0000000F 00000000 00000000
26606 TextOutPlus WndProcMenu 00000040 0059DFC4 0000017C 00000003 0059DFC4 00000006
26627 WndProc _User32 006D0444 00000006 00000000 00000000
26628 SetTTP WndProc
26629 ClosePopup WndProc
26630 DispMenu ClosePopup
26631 SetTTP ClosePopup
26644 WndProc _User32 006D0444 0000000F 00000000 00000000
26645 GdiInitP WndProc
26651 SubRE _User32 00650AA0 0000000F 00000000 00000000
26652 DrawPics SubRE
26655 SubRE _User32 00650AA0 000000D7 00000000 0018F978
26656 DelRegions DrawPics
26657 SetLcBufferP DrawPics
26658 gtbP SetLcBufferP
26660 SubRE _User32 00650AA0 000000BA 00000000 00000000
26661 gtbP SetLcBufferP
26688 CbTimer _User32 006D0444 00000113 FFFFFF81 2402E27E
Name #called total time per call
HelpOrAuto 1 14 s 14969 ms
MyTest 1 1957 ms 1957 ms
SubRE 8592 1937 ms 225 us
BigPopUp 2 1775 ms 887 ms
WndProc 5558 1593 ms 287 us
CbTimer 6649 1105 ms 166 us
AssRun 4 748 ms 186 ms
ReSaveFile 10 623 ms 62 ms
DrawPics 141 562 ms 3986 us
AssRunThread 3 388 ms 129 ms
SubList 2089 339 ms 162 us
BubbleHelp 43 219 ms 5084 us
SetTTP 138 120 ms 872 us
FindBookmark 9 109 ms 12 ms
FindTextP 238 78 ms 328 us
CrtRichEdit 1 74 ms 73 ms
## Hit any key. Ctrl C may cause data loss. Press 'h' to hide the console, 'r' to reset ##
To build the example, MasmBasic version 3 April is required (http://masm32.com/board/index.php?topic=94.0).
P.S.: By changing line 1 to useMB=0, the whole program becomes standard Masm32 SDK code and does no longer require MasmBasic :tongue: