• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

zTrace 1.52 (debugging utility)

Started by Patrice Terrier, April 05, 2009, 12:43:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

zTrace 1.52

Is a small Win32 SDK DLL to display debugging information into a popup window tool, and/or a text file.
zTrace uses a distinct thread to work in parallel of the current application you want to debug.

zTrace is very useful at development time to check whether a program operates properly, it has been modeled onto the WinDev's Trace API.

Declaration:
DECLARE FUNCTION zTrace LIB "zTrace.DLL" ALIAS "zTrace" (zMessage AS ASCIIZ) AS LONG
DECLARE FUNCTION zDebug LIB "zTrace.DLL" ALIAS "zDebug" (zMessage AS ASCIIZ) AS LONG

Syntax to use:
zTrace("StringInformation")
zDebug("StringInformation")

Parameter detail:
QuoteStringInformation, holds the information that will be displayed in the Trace window.

Trace Window:

  • The information passed as parameter is displayed on the next line of the zTrace window.
  • The trace window is automatically opened when zTrace is called, by default, this window is opened at the top left corner of the screen.
  • The zTrace window shuts down automatically when you close the application being debugged.

QuoteStringInformation, holds the information that will be stored in the zDebug.txt file.

zDebug.txt report:

  • Works exactly like the zTrace window, except that the information is written to a text file.
  • The report is automatically created when zDebug is called, it is saved into the same folder than the debugged application.
  • zDebug can be used alone or combined with zTrace (when the option is checked in the popup menu).
  • zDebug is very handy when the debugged application shuts down unexpectedly or when the application as a short life duration, that won't give you enough time to read what is written in the zTrace window.
  • A new fresh zDebug.txt is created each time you start a new zDebug session.


Contextual popup menu (right mouse click on the trace window):

  • Use horizontal scrollbar, show or hide the horizontal scrollbar.
  • Send selection to printer, print the selected lines (or the whole list when none).
  • Copy selection to clipboard, copy the selected lines (or the whole list when none) to clipboard.
  • Clear content, clear the content of the Trace window.
  • Trace window TopMost, open the Trace window on top of all the other windows (including the windows from the other applications).
  • Create zDebug.txt report, the zDebug.txt report is created into the debugged application's folder.
  • Save window coordinates, store the size and position of the zTrace window into the registry when closed. Next time the window will be shown using the previous size and location.

Screen shot:


This utility is freeware, not public domain. This means that you can use it for your own purposes, even in commercial applications, without paying a fee, but not to make derivative works from, sell or redistribute without permission. Also you must assume the entire risk of using it. Downloading the software indicates that you accept these terms.

PS: zTrace is another example of what could be done only with the plain low level Win32 SDK flat API.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

#1
zTrace.zip is attached to the first post of this thread.

Thank you to report any problem you may encounter with it.

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Here are a few insights about zTrace.

1 - The message pump:

WHILE GetMessage(Msg, %NULL, 0, 0)
   '// Easier to detect the right mouse button click on the listBox from the message pump
   IF Msg.hWnd = hCtrl AND Msg.Message = %WM_RBUTTONDOWN THEN
      CALL ToolProc(hWnd, %WM_RBUTTONDOWN, 0, 0)
   ELSE
      IF IsDialogMessage(hWnd, Msg) = %FALSE THEN
         CALL TranslateMessage(Msg)
         CALL DispatchMessage(Msg)
      END IF
   END IF
WEND

And the masterpiece is this
QuoteIF Msg.hWnd = hCtrl AND Msg.Message = %WM_RBUTTONDOWN THEN
   CALL ToolProc(hWnd, %WM_RBUTTONDOWN, 0, 0)
ELSE
It is the easiest way to detect the right mouse button click onto the listBox to popup the contextual menu.


2 - The CASE %WM_DESTROY:
While %WM_DESTROY is being called when you click on the close button of the tool window.
It is never called when zTrace shuts down after the closing of the main debugged application,
the solution is to clear and save the zTrace parameters from DllMain:

    IF Reason = %DLL_PROCESS_DETACH THEN
       IF gnBackBrush THEN
          CALL DeleteObject(gnBackBrush): gnBackBrush = 0
          CALL zLoadSaveCoordinates (gnX, gnY, gnW, gnH, 1)
       END IF
    END IF



3 - Save settings:
This code is responsible to save/restore the settings from the registry

SUB zLoadSaveCoordinates (BYREF x AS LONG, BYREF y AS LONG, BYREF w AS LONG, BYREF h AS LONG, BYVAL RW AS LONG)
    STATIC WasCoordinates AS STRING
    IF RW THEN '// Save settings
       WasCoordinates = LTRIM$(STR$(x)) + "," + LTRIM$(STR$(y)) + "," + LTRIM$(STR$(w)) + "," + LTRIM$(STR$(h)) + "," + LTRIM$(STR$(gbUseTopMost)) + "," + LTRIM$(STR$(gbSaveCoordinates))
       IF LEN(WasCoordinates) THEN CALL zSetReg(%HKEY_LOCAL_MACHINE, $RegistryKey, $RegistryCoordinates, (WasCoordinates))
    ELSE '// Restore settings
       IF LEN(WasCoordinates) = 0 THEN
          WasCoordinates = zGetReg(%HKEY_LOCAL_MACHINE, $RegistryKey, $RegistryCoordinates)
          x = VAL(PARSE$(WasCoordinates, 1))
          y = VAL(PARSE$(WasCoordinates, 2))
          w = VAL(PARSE$(WasCoordinates, 3))
          h = VAL(PARSE$(WasCoordinates, 4))
          gbUseTopMost       = VAL(PARSE$(WasCoordinates, 5))
          gbSaveCoordinates  = VAL(PARSE$(WasCoordinates, 6)): IF gbSaveCoordinates = 0 THEN w = 0
       END IF
       IF w = 0 OR h = 0 THEN w = %MIN_WIDTH: h = %MIN_HEIGHT: x = 0: y = 0
    END IF
END SUB


...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Dominique Bodin

Thank's Patrice.

could you add to the zTrace tool the ability to print the windows content ?
It would be better than to have to copy the content and paste in an editor
to finaly print it . . .

Thank's

Dominique

Patrice Terrier

Dominique

You can do the same than the code below that copy to clipboard


        CASE %IDM_CopyToClipboard
             hCtrl = GetDlgItem(hWnd, %ID_LISTBOX)
             nCount = SendMessage(hCtrl, %LB_GETCOUNT, 0, 0)
             IF nCount > 0 THEN
                sBuffer = ""
                FOR K = 0 TO nCount - 1
                    sBuffer = sBuffer + zGetTextListbox(hCtrl, K) + $CRLF
                NEXT

'               CLIPBOARD SET TEXT sBuffer '// requires PB 9.0+
                LOCAL hClipData, hGlob AS DWORD
                hClipData = GlobalAlloc(%GMEM_MOVEABLE OR %GMEM_DDESHARE, LEN(sBuffer) + 1)
                hGlob = GlobalLock(hClipData)
                POKE$ hGlob, sBuffer + CHR$(0)
                CALL GlobalUnlock(hClipData)
                IF OpenClipboard(0) THEN
                   CALL EmptyClipboard()
                   CALL SetClipboardData(%CF_TEXT, hClipData)
                   CALL CloseClipboard()
                ELSE
                   CALL GlobalFree(hClipData)
                END IF

            END IF


and instead of sending to clipboard then send it to printer using XPRINT.

I shall update the zip file with the clipboard feature for the next version.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Under request of Dominique Bodin,

i have added two new options:

  • Send selection to printer
  • Copy selection to clipboard

The new zip file is attached to the first post of this thread.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Eddy Van Esch

Patrice,

Nice tool, thanks !
I sometimes have to show (very) large strings while debugging, so I took the liberty of adding a horizontal scrollbar to zTraces listbox.
Modifications shown in bold:
Quote
          hCtrl = CreateWindowEx(0, "ListBox", BYVAL %NULL, _
                                 %WS_CHILD OR %WS_VISIBLE OR %WS_VSCROLL OR %WS_HSCROLL OR %LBS_MULTIPLESEL OR _
                                 %LBS_HASSTRINGS OR %LBS_NOINTEGRALHEIGHT OR %LBS_EXTENDEDSEL OR _
                                 %LBS_DISABLENOSCROLL, _
                                 0, 0, UseW, UseH, _
                                 hWnd, %ID_LISTBOX, zInstance(), BYVAL %NULL)
          CALL SENDMESSAGE(hCtrl, %LB_SETHORIZONTALEXTENT, 6000, 0)  '<-- change scrollwidth here if necessary

Kind regards
Eddy
www.devotechs.com -- HIME Huge Integer Math and Encryption library--

Patrice Terrier

Eddy,

Thank you for the feedback, i think showing the horizontal srollbar could become another option of the popup menu.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Under request of Eddy Van Esch,

i have added a new option:

  • Use horizontal scrollbar

It can be turned On/Off on the fly.

The new zip file is attached to the first post of this thread.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

Because no problem was reported, i shall consider that zTrace is working well 8)

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Paul Squires

I have been using it since the day that you posted it.

I love it.   :)

No problems to report from me. I will post if something comes up.

Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

Patrice Terrier

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Eddy Van Esch

Patrice,

You know, the danger in publishing a tool like zTrace is that everyone keeps asking for more and more features ... ;D
Speaking about new features ... ;)

Before you published zTrace, I was using a console window (from PBWin) to print text to.
I used that console window often to test algorithms in a small test program without any GUI at all. The console window was the 'GUI'.
At the end of the test code, I place a SLEEP xxx statement to halt the program and to enable me to study the programs output in the console window.

The nice thing of using a console window as output, is that, by closing the console window (clicking the "X") the entire program is terminated. So no need to foresee any code in the test program to properly shut it down. Just clicking the X closes down the program.
The difference with zTrace is that, when I close the zTrace window, the main calling program continues to run.
In some cases, this might be the desired situation, but usually in my case, I prefer that the calling program is terminated along with the debug window.

This is probably asking much, but any chance of implementing this in zTrace ....?   :-\

Kind regards
www.devotechs.com -- HIME Huge Integer Math and Encryption library--

Patrice Terrier

In such a case, DestroyWindow(hParent), should do it.

However zTrace is not of much interrest for a console window, because you can use "?" already ...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Eddy Van Esch

Hi Patrice,

Is it too late to make another feature request ?   :)

When printing a lot of data to the zTrace window, the text disappears on the bottom of the zTrace window.
To view the text that is added when the window is 'full', you have to use the vertical scrollbar to scroll downward to see the text.

Would it be possible to make zTrace scroll the text automatically upwards so that the text that was printed last is always visible ?
This feature would be most helpful to me.

Kind regards
Eddy