Page 1 of 2

DEBUGGING a program

Posted: Mon Jan 01, 2007 7:20 am
by Ollie
I have never used debugging, even with just Clipper, but now I feel the need to.

How do I step through the program to see where I am going wrong.

Posted: Mon Jan 01, 2007 7:54 am
by Antonio Linares
Ollie,

The debugger is built into [x]Harbour, and it looks and behaves as the Clipper one. In order to use it you have to compile your PRG using /b. If you are using samples\buildh.bat then do:

buildh.bat myapp /b

In your PRG you have to add these lines:

Code: Select all

function Main()

   AltD( 1 )   // Enables the debugger. Press F5 to go

   MsgInfo( "debugger enabled" )

   AltD()      // Invokes the debugger

   MsgInfo( "debugger invoked" )

return nil

Posted: Mon Jan 01, 2007 9:26 am
by Ollie
Now when I compile I get

Unresolved external 'HB_FUN_ALTD' referenced from ...

How do I resolve this?

Posted: Mon Jan 01, 2007 9:56 am
by Antonio Linares
Ollie,

You have to link Harbour's debug.lib

Posted: Mon Jan 01, 2007 1:23 pm
by Ollie
Ok, did that. But when I add the /b switch it complaints about all kinds of Unresolved Externals (e.g. _HB_FUN_RELEASEWINDOW) from MIDLEX2.LIB (Without the switch it compiles, but of course to debug info)

(I am using XMATE)

And by the way, how would I have found out to link debug.lib without your help - there must be a way I could have found that out. And where does one find out what functions are in the LIB (any LIB for that matter) and how to use them etc.

Posted: Mon Jan 01, 2007 3:08 pm
by Ollie
Ok, ignore last message. I configured XMATE exactly like buildx.bat and now it compiles - /b and all.

I added:
PROCEDURE debugger()
AltD( 1 ) // Enables the debugger. Press F5 to go
MsgInfo( "debugger enabled" )
AltD() // Invokes the debugger
MsgInfo( "debugger invoked" )
RETURN

and I run this PROCEDURE on a button. I see the "debugger enabled" box, but never thee the "debugger invoked" one and the program 'stops responding'

Posted: Mon Jan 01, 2007 7:35 pm
by Antonio Linares
Ollie,

Ops, you need to link GTWIN.lib instead of GTGUI.lib to use the debugger.

The debugger is a [x]Harbour feature, thats why its not explained in FWH docs, and also it may change or get modified in the future (there are plans to rewrite it in pure C without using PRG to improve its speed).

Posted: Mon Jan 01, 2007 8:31 pm
by Ollie
Replaced the GTWIN.LIB with GTGUI.LIB, but then:

Error description: Error BASE/1131 Bound error: array dimension
Args:
[ 1] = N -8

Stack Calls
===========
Called from: => ARRAY(0)
Called from: tbrowse.prg => TDATACACHE:NEW(245)
Called from: tbrowse.prg => TBROWSE:NEW(780)
Called from: tbrowse.prg => TBROWSENEW(3589)
Called from: debugger.prg => TDEBUGGER:BUILDBROWSESTACK(475)
Called from: debugger.prg => TDEBUGGER:NEW(403)
Called from: debugger.prg => __DBGENTRY(156)
Called from: subspro3.prg => MAIN(19)

Line 19 of Main is the first line of code and is simply a LOCAL variable declaration:

LOCAL oIcon, oMain_Toolbar

Something else is wrong.

Posted: Sat Apr 21, 2007 8:43 pm
by PatrickWeisser
Hello Ollie,

Did you ever get the debugger working with Harbour? I'm having the same problem you had -- the example program \FWH\Samples\Altd.prg get's as far as the first message, "Debugger Enabled", but the Altd() call seems to lock it up. Certainly no other windows appear. I took care to compile with the /b option, and I used:

%bcdir%\bin\ilink32 -Tpe -s @b32.bc

in the BuildH.bat file as instructed. I'm linking in Debug.lib.

Thanks!

-Patrick

Posted: Sat Apr 21, 2007 8:58 pm
by Ollie
Hi Patrick,

Alas, I did not.

Posted: Sat Apr 21, 2007 9:31 pm
by PatrickWeisser
Okay thanks for letting me know. I wrote an email to Antonio about this, so hopefully we should at least be able to get the sample program Altd.prg working, and we can go from there.

-Patrick

Posted: Sun Apr 22, 2007 4:48 am
by Ollie
Great. Good luck, please copy me.

Thanks

Posted: Sun Apr 22, 2007 5:26 am
by Antonio Linares
Patrick, Ollie,

If you use samples\buildh.bat to test it then you have to modify it to use GTWIN.lib instead of GTGUI.lib, add debug.lib and remove -aa when linking. And invoke buildh.bat this way:

c:\fwh\samples\buildh.bat altd /b

Here it is working fine:
Image

Here you have gtwin.lib and debug.lib just in case yours are not the right ones:
http://rapidshare.com/files/27268617/libs.zip.html

Posted: Sun Apr 22, 2007 6:20 pm
by PatrickWeisser
Antonio,

Still no luck I'm afraid. When I try and build altd.prg I get these errors:

Code: Select all

┌────────────────────────────────────────────────────────────────────────────┐
│ FiveWin for Harbour 7.01 - January 2007         Harbour development power  │▄
│ (c) FiveTech, 1993-2006      for Microsoft Windows 95/98/NT/2000/ME and XP │█
└────────────────────────────────────────────────────────────────────────────┘█
  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Compiling...
Harbour Alpha build 1.0 Intl.
Copyright 1999-2007, http://www.harbour-project.org/
Compiling 'altd.prg' and generating preprocessed output to 'altd.ppo'...
Lines 28, Functions/Procedures 1
Generating C source output to 'altd.c'... Done.
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
altd.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_FUN_HB_DBG_SETENTRY' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETGO' referenced from C:\HARBOUR\LIB
\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETCBTRACE' referenced from C:\HARBOU
R\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_HEVAL' referenced from C:\HARBOUR\LIB\DEB
UG.LIB|dbgthsh
Error: Unresolved external '_HB_FUN_HB_HVALUEAT' referenced from C:\HARBOUR\LIB\
DEBUG.LIB|dbgthsh
Error: Unresolved external '_HB_FUN_HB_HKEYAT' referenced from C:\HARBOUR\LIB\DE
BUG.LIB|dbgthsh
Error: Unresolved external '_HB_FUN_HB_CSTR' referenced from C:\HARBOUR\LIB\DEBU
G.LIB|dbgthsh
Error: Unresolved external '_HB_FUN_HB_DBG_GETEXPRVALUE' referenced from C:\HARB
OUR\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_GETSOURCEFILES' referenced from C:\HA
RBOUR\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_ISVALIDSTOPLINE' referenced from C:\H
ARBOUR\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETNEXTROUTINE' referenced from C:\HA
RBOUR\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETQUIT' referenced from C:\HARBOUR\L
IB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETTOCURSOR' referenced from C:\HARBO
UR\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_ADDBREAK' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_DELBREAK' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETTRACE' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_ADDWATCH' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_VMVARGGET' referenced from C:\HARBOUR
\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_VMVARGSET' referenced from C:\HARBOUR
\LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_DELWATCH' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
Error: Unresolved external '_HB_FUN_HB_DBG_SETWATCH' referenced from C:\HARBOUR\
LIB\DEBUG.LIB|debugger
* There are errors

C:\FWH\SAMPLES>buildh altd /b

Here is what my BuildH.bat file contains:

Code: Select all

@ECHO OFF
CLS
ECHO 
if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST

ECHO Compiling...

set hdir=c:\harbour
set fwh=c:\FWH
set bcdir=c:\borland\bcc55

%hdir%\bin\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > clip.log
@type clip.log
IF ERRORLEVEL 1 PAUSE
IF ERRORLEVEL 1 GOTO EXIT

echo -O2 -e%1.exe -I%hdir%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c @b32.bc
:ENDCOMPILE

IF EXIST %1.rc %bcdir%\bin\brc32 -r %1

echo c0w32.obj + > b32.bc
echo %1.obj, + >> b32.bc
echo %1.exe, + >> b32.bc
echo %1.map, + >> b32.bc
echo %fwh%\lib\FiveH.lib %fwh%\lib\FiveHC.lib + >> b32.bc
echo %hdir%\lib\rtl.lib + >> b32.bc
echo %hdir%\lib\vm.lib + >> b32.bc
rem echo %hdir%\lib\gtgui.lib + >> b32.bc  // Use gtwin.lib instead for debugger.
echo %hdir%\lib\gtwin.lib + >> b32.bc
echo %hdir%\lib\lang.lib + >> b32.bc
echo %hdir%\lib\macro.lib + >> b32.bc
echo %hdir%\lib\rdd.lib + >> b32.bc
echo %hdir%\lib\dbfntx.lib + >> b32.bc
echo %hdir%\lib\dbfcdx.lib + >> b32.bc
echo %hdir%\lib\dbffpt.lib + >> b32.bc
echo %hdir%\lib\hbsix.lib + >> b32.bc
echo %hdir%\lib\debug.lib + >> b32.bc
echo %hdir%\lib\common.lib + >> b32.bc
echo %hdir%\lib\pp.lib + >> b32.bc
echo %hdir%\lib\codepage.lib + >> b32.bc

rem Uncomment these two lines to use Advantage RDD
rem echo %hdir%\lib\rddads.lib + >> b32.bc
rem echo %hdir%\lib\Ace32.lib + >> b32.bc

echo %bcdir%\lib\cw32.lib + >> b32.bc
echo %bcdir%\lib\import32.lib + >> b32.bc
echo %bcdir%\lib\psdk\odbc32.lib + >> b32.bc
echo %bcdir%\lib\psdk\nddeapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\iphlpapi.lib + >> b32.bc
echo %bcdir%\lib\psdk\rasapi32.lib, >> b32.bc

IF EXIST %1.res echo %1.res >> b32.bc
rem uncomment this line to use the debugger and comment the next one
%bcdir%\bin\ilink32 -Tpe -s @b32.bc
rem %bcdir%\bin\ilink32 -Gn -aa -Tpe -s @b32.bc

IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * Application successfully built
%1
GOTO EXIT
ECHO

rem delete temporary files
@del %1.c

:LINKERROR
ECHO * There are errors
GOTO EXIT

:SINTAX
ECHO    SYNTAX: Build [Program]     {-- No especifiques la extensi¢n PRG
ECHO                                {-- Don't specify .PRG extension
GOTO EXIT

:NOEXIST
ECHO The specified PRG %1 does not exist

:EXIT
Here is my \Harbour\Lib\ folder:

Code: Select all


04/22/2007  10:58 AM    <DIR>          .
04/22/2007  10:58 AM    <DIR>          ..
01/13/2007  08:41 AM            99,840 codepage.lib
01/13/2007  08:41 AM            71,168 common.lib
01/13/2007  08:41 AM           126,976 dbfcdx.lib
01/13/2007  08:41 AM            34,304 dbffpt.lib
01/13/2007  08:41 AM            51,712 dbfntx.lib
04/17/2007  09:42 PM           183,808 debug.lib
01/13/2007  08:41 AM             5,120 gtgui.lib
04/17/2007  09:42 PM            15,872 gtwin.lib
01/13/2007  08:41 AM            10,752 hbsix.lib
01/13/2007  08:41 AM            17,408 hsx.lib
01/13/2007  08:41 AM           213,504 lang.lib
01/13/2007  08:41 AM            61,952 macro.lib
04/22/2007  10:58 AM            54,436 OLD.ZIP
01/13/2007  08:41 AM           216,064 pp.lib
01/13/2007  08:41 AM           157,184 rdd.lib
01/13/2007  08:53 AM            62,976 rddads.lib
01/13/2007  08:41 AM           672,256 rtl.lib
01/13/2007  08:41 AM           250,368 vm.lib
              18 File(s)      2,305,700 bytes
               2 Dir(s)   4,571,369,472 bytes free

C:\harbour\lib>


Posted: Sun Apr 22, 2007 7:10 pm
by Antonio Linares
Patrick,

Are you using Harbour, the one provided by FiveTech, or have you download it from the Harbour CVS ?