• Welcome to Theos PowerBasic Museum 2017.

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.

John Aadnoey

#45
Its not embedded in my code. I let my DLL load it.
To me it looks like zTrace is waiting for VB6 to shutdown, not the DLL. (because shutting down the VB6 IDE kills it)

"However if the source code of zTrace doesn't match your level of expectations"

Its definitely up to my expectations. have no doubt about that, I'm just trying to find out why the DLL ain't closing

Patrice Terrier

Again, i have absolutly no knowledge of VB.

Did you try it without the VB6 IDE, i mean as a real standalone EXE ?
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

John Aadnoey

#47
Yes just three minutes ago. And then when I run the compiled VB6 code, It shut down as expected.

I wouldn't be surprised if its VB not shutting down the DLL beacuse the DLL has an open window. If window is closed before DLL gets shut down, it'll probably work.

Patrice Terrier

Then this means that when you run it within the VB6 IDE, it runs as p-code not native code, that's it.

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

John Aadnoey

#49
Found out some more. When I run it in p-Native/VB6 IDE, if;
DLL opens a DialogWindow, program closes = crash
DLL opens a DialogWindow, DLL close DialogWindow, program closes = OK

Probably a VB6 bug/feature.

Norbert Spoerl

Hi John,

zTrace is only useable with EXE/DLL of pure native Code. Please see my replys 34 and 36. I made the same experiences with another programming language.

Patrice Terrier

zTrace is using GetModuleHandle("") to retrieve the instance handle, but in case of a run-time this is of course the handle of the run-time!
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

John Aadnoey

Ah oki. That explains it. Then I'll just keep on using it on my pure PB hobby projects.

Thanks all

Norm Cook

#53
Patrice, late to the party, just stumbled onto this.  Thanks so much for sharing this
excellent debugging tool.  Here's a little routine I've been using to make coding/debugging
a little easier.  I've thrown just about everything at it and it seems to work OK.

Sub DoTrace(ByVal Msg As Variant)
Local sz As AsciiZ * 1000
Select Case VariantVT(Msg)
  Case %VT_BStr
   sz = Variant$(Msg)
  Case %VT_R4, %VT_R8   'single, double
   sz = "#" & Format$(Round(Variant#(Msg), 4))
  Case Else
   sz = "#" & Format$(Variant#(Msg))
End Select
zTrace sz
End Sub

Patrice Terrier

#54
There is no need to use Variant nor Format$ (both are bloated :) ).

You can just use zTrace like this:

zTrace(STR$(Value))
or
zTrace("Value =" + STR$(Value))
and in case of STRING
zTrace((MyString$))
or
zTrace(A$+ B$ + STR$(12))
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

George Bleck

I absolutely love having zTrace in my toolbox and wanted to give back a slight "helper" that I use with it.

#IF NOT %DEF( %zTrace )
    %zTrace = 0
#ENDIF

#IF %zTrace = 0
    MACRO zTrace = #UTILITY
    MACRO zDebug = #UTILITY
#ELSE
    DECLARE FUNCTION zTraceX LIB "zTrace.DLL" ALIAS "zTrace" ( zMessage AS ASCIIZ ) AS LONG
    DECLARE FUNCTION zDebugX LIB "zTrace.DLL" ALIAS "zDebug" ( zMessage AS ASCIIZ ) AS LONG
    #IF %zTrace > 0
        MACRO zTrace = zTraceX
        MACRO zDebug = zDebugX
    #ELSE
        MACRO zTrace = zDebugX
        MACRO zDebug = zDebugX
    #ENDIF
#ENDIF


This slight mod allows you to leave zTrace code in and never have to remove it.  PLUS it adds some flexibility to the output path.


       
  • If %zTrace is defined as a positive number, zTrace and zDebug work exactly as expected.
  • If %zTrace is defined as a negative number, zTrace and zDebug both act like zDebug and send to zDebug.txt (allows you to easily switch to "silent" debugging).
  • If %zTrace is 0, not defined,  or REM'd out, then all zTrace/zDebug lines are compiled as #UTILITY commands, in other words, they are ignored by the compiler.
This allows you to easily include copious real-time logging in your code as well as switch the output (or remove logging completely) with a single constant change.

Patrice Terrier

#56
George--

Thank you.

The current version of zTrace is able to write to zdebug.txt directly from the contextual popup menu.

PBwin 10, now doesn't compile unused code anymore.
Thus using explicit linking rather than implicit is another solution,
and this is what i am using with the 64-bit version (explicit call is the same for PB) :

long zTrace(IN WCHAR* sPtr) {
    long nRet = 0;
    static HMODULE hDll;
    if (hDll == 0) {
        if (sizeof(LONG_PTR) == 8) {
            hDll = LoadLibrary(L"zTrace64");
        }
        else {
            hDll = LoadLibrary(L"zTrace32");
        }
    }
    if (hDll) {
        long_proc(WCHAR*);
        static zProc hProc;
        if (hProc == 0) { hProc = (zProc)GetProcAddress(hDll, "zTrace"); }
        if (hProc) { nRet = hProc(sPtr); }
    }
    return nRet;
}


The C++ 64-bit DLL version is only 11 Kb in size, it can create ANSI or UNICODE debug file.
In case of ANSI, a UTF-8 BOM header is now being used
this version can be downloaded from www.codeproject.com or from my private forum www.objreader.com
https://www.codeproject.com/Articles/1183063/zTrace-for-bit-only

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

James C. Fuller

Patrice,
  I reverted back to an older version.
The debug.txt output was persistent once set and I often parse the output so I don't want a BOM.

James

Patrice Terrier

No, it is not, you just have to remember to uncheck the menu option, once you are done, if you don't want it for the next session.

Or feel free to customize the source code to match your preference ;)

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

Patrice Terrier

Emil

zTrace is totaly independent from the compiler, it is a standalone DLL.
It has been inspired by the WinDev Trace API.

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