Debug

Re: Debug

Postby dutch » Mon Oct 31, 2011 3: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: Select all  Expand view

#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: Select all  Expand view

******************************************************************
* 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 19.01 / 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)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Debug

Postby hua » Mon Oct 31, 2011 4: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Debug

Postby dutch » Tue Nov 01, 2011 3:25 am

Dear Hua,

Thanks, I got it now.

Regards,
Dutch
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Debug

Postby nageswaragunupudi » 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: Select all  Expand view
#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: Select all  Expand view
        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: Select all  Expand view
#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:

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Debug

Postby Antonio Linares » Sun Nov 27, 2011 8:09 pm

Dear Rao,

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

Thanks!
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42087
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Debug

Postby Rick Lipkin » Mon Nov 28, 2011 1:32 pm

Rao

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

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Debug

Postby nageswaragunupudi » Mon Nov 28, 2011 1: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
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Debug

Postby hua » Tue Nov 29, 2011 2: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Debug

Postby nageswaragunupudi » Tue Nov 29, 2011 5: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: Select all  Expand view
< ||

//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
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Debug

Postby hua » Tue Nov 29, 2011 6: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Debug

Postby Perry Nichols » Mon Feb 20, 2012 5: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.
Perry Nichols
 
Posts: 17
Joined: Thu Feb 28, 2008 6:56 pm

Re: Debug

Postby dutch » Wed Feb 29, 2012 5: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. :wink:

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

There is a new version?

Is possible to compile WinDebug?
Regards,
Dutch

FWH 19.01 / 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)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests