FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Debug
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Debug
Posted: Mon Oct 31, 2011 03:41 PM
angelo.c wrote:Thanks Carlos for that neat piece of code. I use the OutputDebugString(...) command a lot in my code for debugging.

I modified yours slightly to make it more useful for me so that array values can be displayed on the output debug window.

Here is the modified code:


Code (fw): Select all Collapse
#ifdef __RELEASE__
#xcommand DEBUG <cString1>[, <cStringN>] => 
#else
#translate ASSTRING( <x> ) => If( <x> == NIL, 'NIL', Transform( <x> , NIL ) ) + CRLF

#xcommand DEBUG <cString1>[, <cStringN>] ;
         => ;
          OutputDebugString( ProcName() +"("+LTrim(Str(ProcLine())) +") - " ) ; OutputDebugString( <"cString1">+" ("+ValType( <cString1> )+"): " ) ; OutputDebugString( FormatAsString( <cString1> ) )  ;
          [ ; OutputDebugString( ProcName() +"("+LTrim(Str(ProcLine())) +") - " ) ; OutputDebugString( <"cStringN">+" ("+ValType( <cStringN> )+"): " ) ; OutputDebugString( FormatAsString( <cStringN> ) )  ]

#endif




Then add these two routines somewhere in your code:


Code (fw): Select all Collapse
******************************************************************
* Procedure: FormatAsString( xVal )
* Notes...: Writes information stored in xVal as a string suitable to be
*       output to any standard character output device.
*           Function returns the formatted string representing the value "xVal"
*****************************************************************
Function FormatAsString( xVal )
local cString, cValtype, cBuffer,i, j
local nFirstDimLen,nSecondDimLen,  nSecondDimType
local cTabSeparator := chr(VK_TAB)

  cValtype := VALTYPE(xVal)
  DO CASE
     CASE cValtype == "A"   //Check if an Array
         nFirstDimLen := len(xVal)  //First Dimension length
         //Init to a show array length and then output a new line
         cString := "Array Length is: " + alltrim(str(nFirstDimLen)) + "  ...  Array values follow:" + CRLF   
         if nFirstDimLen > 0
           FOR i := 1 TO nFirstDimLen       //Loop through the number of First dimension elements
             nSecondDimType := if (xVal[i] == NIL, "U", ValType(xVal[i]))  //Type of Second dimension element
             if nSecondDimType == 'A'
               nSecondDimLen := len(xVal[i])       //Number of Second dimension elements
               if nSecondDimLen != 0
                 // Must be non-zero length array
                 cBuffer :=  ""                         //Init to empty string
                 FOR j := 1 TO nSecondDimLen        //Loop through the number of Second dimension elements
                   cBuffer :=  cBuffer + ElementToString(xVal[i][j]) + cTabSeparator
                 NEXT  // j
               else  //if nSecondDimLen != 0
                 cBuffer := "Nil Array {}"
               endif  //if nSecondDimLen != 0
             else   //  if cValType == 'A'
                cBuffer :=  ElementToString(xVal[i])    //Convert element that is NOT an Array to a string value
             endif  //  if cValType == 'A'
             cString += cBuffer + CRLF          //Build resultant string
           NEXT  // i
         else
           cBuffer := "Nil Array {}"  + CRLF
         endif

     OTHERWISE
        // xVal is NOT an array at this point.
        cString := ElementToString(xVal) + CRLF
  ENDCASE

return cString


******************************************************************
* Procedure: ElementToString( xVal )
* Notes...: Function returns a string representing the value "xVal"
*****************************************************************
Function ElementToString(xVal)
local cBuffer, cValtype := VALTYPE(xVal)

 DO CASE
   CASE cValtype == "A" //Check if an Array
        cBuffer :=  "Recursive Array. Not Implemented"

   CASE cValtype == "L" //Logical value ... I prefer the displayed .T. or .F. notation
        cBuffer :=  if(xVal, ".T.", ".F.")

   CASE cValtype == "C" .OR. cValtype == "M"   //ASCII String or Memo value
        cBuffer :=  xVal

   CASE cValtype == "N" //Numeric
        cBuffer := Alltrim(str(xVal))

   CASE cValtype == "D" //Date
        cBuffer := DToC(xVal)

   OTHERWISE
     cBuffer := "Not Processed" // All other cases, then return "Not Processed"
 ENDCASE

return cBuffer






When you execute this:
local cText := "Array n := {2, 4, 6}"
local n := {2, 4, 6}
DEBUG cText, n, Date(), .T., 5, Nil

n := {1, "Test String",{3,4,5}, .t.}
DEBUG n

n := {}
DEBUG n




you get on the output debug window the following:
PACKIT(197) - cText (C): Array n := {2, 4, 6}
PACKIT(197) - n (A): Array Length is: 3 ... Array values follow:
2
4
6
PACKIT(197) - Date() (D): 18/03/2009
PACKIT(197) - .T. (L): .T.
PACKIT(197) - 5 (N): 5
PACKIT(197) - Nil (U): Not Processed
PACKIT(200) - n (A): Array Length is: 4 ... Array values follow:
1
Test String
3 4 5
.T.
PACKIT(203) - n (A): Array Length is: 0 ... Array values follow:


Ofcourse, the code can be tailored to suit yourselves; perhaps even displaying instantiated Object variables in a tabular form.

Best regards,
Angelo.c

Dear Angelo,

What is output debug window? I try your modified code but it doesn't show anywhere?

Regards,
Dutch
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Debug
Posted: Mon Oct 31, 2011 04:13 PM
hua wrote:
I'm using the same method as you do, only instead of msginfo I use outputDebugString(). I monitor stuffs using DebugView


Dutch, use my link above to download the program that'll capture and display the debug messages. Run it before you run your code.
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Debug
Posted: Tue Nov 01, 2011 03:25 AM

Dear Hua,

Thanks, I got it now.

Regards,
Dutch

Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Debug
Posted: Sun Nov 27, 2011 12:30 PM
Here is another simpler approach, which does not require any separate functions to display the values.

Command:
Code (fw): Select all Collapse
#ifdef __RELEASE__
#xcommand DBG <vars,...> =>
#else
#xcommand DBG <vars,...> => ;
            XBrowse( ArrTranspose( \{ \{ <"vars"> \}, Eval( \{ || \{ <vars> \} \} ) \} ), ;
            ProcName(0) + " : Line : " + LTrim( Str( ProcLine(0) ) ),, ;
            { |o| o:cHeaders := { "Variable", "Value" } } )

#endif


Usage:
Code (fw): Select all Collapse
         DBG nVar, cVar, aData, oWnd, oBrush, oFont, oFont:nHeight


In my view, probably less robust, but the advantages are:

1) Good enough for lazy programmers like me who can not write and maintain long and complex lines of code.

2) I don't have to link my library code for debug. It is just enough to include the command translate alone. I keep this in my personal ch file which I include in every program.

3) I can also view the values of Arrays, Nested Arrays, Objects, etc.

and finally,
4) KISS: Keep it simple and stupid

Sample code:
Code (fw): Select all Collapse
#include "fivewin.ch"

#ifdef __RELEASE__
#xcommand DBG <vars,...> =>
#else

#xcommand DBG <vars,...> => ;
            XBrowse( ArrTranspose( \{ \{ <"vars"> \}, Eval( \{ || \{ <vars> \} \} ) \} ), ;
            ProcName(0) + " : Line : " + LTrim( Str( ProcLine(0) ) ),, ;
            { |o| o:cHeaders := { "Variable", "Value" } } )

#endif

function Main()

   local oWnd, oBrush, oFont
   local aData := { 1, 2, 3, 'Something' }
   local nVar := 99, cVar := 'Hello'

   DEFINE BRUSH oBrush GRADIENT {{ .5, CLR_BLUE, CLR_GREEN },{.5, CLR_GREEN,CLR_BLUE}}
   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-15
   DEFINE WINDOW oWnd BRUSH oBrush
   oWnd:SetFont( oFont )

   oWnd:bRClicked := ;
      < ||
         DBG nVar, cVar, aData, oWnd, oBrush, oFont, oFont:nHeight
      >

   ACTIVATE WINDOW oWnd

   RELEASE BRUSH oBrush
   RELEASE FONT  oFont

return nil


Sample Output:

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Debug
Posted: Sun Nov 27, 2011 08:09 PM

Dear Rao,

It would be great to include it in FiveWin.ch :-)

Thanks!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Debug
Posted: Mon Nov 28, 2011 01:32 PM

Rao

Where does the function ArrTranspose() come from .. I am using xHarbout 1.21 and fwh 910 ?

Thanks
Rick Lipkin

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Debug
Posted: Mon Nov 28, 2011 01:36 PM
Rick Lipkin wrote:Rao

Where does the function ArrTranspose() come from .. I am using xHarbout 1.21 and fwh 910 ?

Thanks
Rick Lipkin

In xbrowse.prg. But in later versions.
It works like Transpose feature of Excel.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Debug
Posted: Tue Nov 29, 2011 02:21 AM
Rao,
"< || ...  >" seems to be a codeblock notation but this is the first time I've seen it. Could you elaborate about it further?

TIA
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Debug
Posted: Tue Nov 29, 2011 05:31 AM
hua wrote:Rao,
"< || ...  >" seems to be a codeblock notation but this is the first time I've seen it. Could you elaborate about it further?

TIA

This is an alternative way of coding codeblocks.

Code (fw): Select all Collapse
< ||

//here write any code using commands / functions
// we can have if / endif; do while / enddo. etc

>

This works both in Harbour and xHarbour.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Debug
Posted: Tue Nov 29, 2011 06:31 AM

Thank you for the explanation Rao. This will simplify things a lot.

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 17
Joined: Thu Feb 28, 2008 06:56 PM
Re: Debug
Posted: Mon Feb 20, 2012 05:30 PM

Antonio,

I am attempting to use the console mode debugger per your instructions.

I am using the fwh1107 sample altd.prg and compiling with harbour v3.0 using bcc582.
I am using /b for compile and linking without -aa and with gtwin.lib (per sample instructions)

Upon execution I get the FiveWin debugger NOT the console window?
Please advise.

Posts: 1598
Joined: Fri Oct 07, 2005 05:56 PM
Re: Debug
Posted: Wed Feb 29, 2012 05:02 PM
Dear All,

Is the Windebug of xHarbour still alive?

Regards,
Dutch
Ugo wrote:
anserkk wrote:WinDebug
http://rapidshare.com/files/209798998/windebug.zip

Things to be taken care for winDebug to work properly

1. Compile your PRG's with /b (Debug parameter)
2. Instead of the xHarbour lib DEBUG.LIB, WDEBUG.LIB (Which comes along with WinDebug) should be linked to the exe
3. The CT.LIB also should be linked to the Exe. This lib is available in \xHarbour\lib
4. Run WinDebug.Exe before you run your application exe. It will be displayed in your taskbar near the clock/time
5. To close WinDebug, right click on it and choose the menu

Dear Anser,

I see this with a productive solution. :-)

I use the PCode 10 and the downloaded version is for PCode 9! :-)

There is a new version?

Is possible to compile WinDebug?
Regards,

Dutch



FWH 2304 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio

FWPPC 10.02 / Harbour for PPC (FTDN)

ADS V.9 / MySql / MariaDB

R&R 12 Infinity / Crystal Report XI R2

(Thailand)

Continue the discussion