HB_TRACE little help

142 views
Skip to first unread message

Luigi Ferraris

unread,
Sep 28, 2026, 8:24:50 AM (6 days ago) Sep 28
to Harbour Users
Hi everyone, I wrote a C-wrapper and, for verification purposes, I inserted: 
HB_TRACE( HB_TR_DEBUG, ( "wkStart(%d)", wkStart ) );
 
I compiled the program without any debug-related flags.
 

Then I created the .bat file: 
@ECHO OFF
SET HB_TR_LEVEL=DEBUG
oop001.exe > dubg.log 2>&1
SET HB_TR_LEVEL=

Result: the file is created, but it is empty.

If I use: 
HB_TRACE( HB_TR_ALWAYS, ( "wkStart(%d)", wkStart ) );

 ...and run the program from the prompt, 
obviously it writes to the screen; 
if I run the .bat file, it writes log to the file. 

My goal is to use: 
HB_TRACE( HB_TR_DEBUG, ( "wkStart(%d)", wkStart ) );
 
...but enable tracing at runtime for this level.
 
Is this possible or not?

Many thanks in advance for any info.
Regards, Luigi

Alex Strickland

unread,
Sep 29, 2026, 1:20:23 AM (5 days ago) Sep 29
to harbou...@googlegroups.com

Hi Luigi

Off the top of my head, doesn't Harbour have to be compiled first to do this?

-- 

Regards

Alex

it writes to the screen; 
Regards, Luigi --
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/caa68ebd-4a38-4161-80c7-ac3f59b8b9dan%40googlegroups.com.

Luigi Ferraris

unread,
Sep 29, 2026, 4:56:53 AM (5 days ago) Sep 29
to harbou...@googlegroups.com
Hi Alex,
I'm sorry, but I don't understand what you mean with ".....doesn't Harbour have to be compiled first to do this?"

I wrote a C-wrapper; for example: 
HB_FUNC( MYTEST )
 

I wanted to insert a debug statement like this: 

HB_TRACE( HB_TR_DEBUG, ( "wkStart(%d)", wkStart ) );
 

set tracing level and enable debugging at runtime using: 

SET HB_TR_LEVEL=DEBUG
oop001.exe > dubg.log 2>&1
 
This sequence doesn't work; it creates an empty file.

Of course, if I use: 

HB_TRACE( HB_TR_ALWAYS, ( "wkStart(%d)", wkStart ) );
There is no need to set the level, because this command always writes to either the screen or a file.

As far as I know, it isn't necessary to compile the program with a specific flag, let alone recompile Harbour itself.


Any help would be appreciated.
Regards
Luigi

You received this message because you are subscribed to a topic in the Google Groups "Harbour Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-users/2oIBLBqq7fU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/a8d50d6d-5317-4213-afb5-26bac882989c%40mweb.co.za.


--
Luigi Ferraris
www.l3w.it

Francesco Perillo

unread,
Sep 29, 2026, 5:48:02 AM (5 days ago) Sep 29
to harbou...@googlegroups.com
Luigi,
please have a look at the file doc\tracing.txt in harbour source.

The HB_TRACE "command" is compiled (so at compile time) only when the HB_TR_LEVEL variable is set to a value higher

There is everything in the doc, test it and came back if you need more support (or PM me)

Ciao
Francesco

Luigi Ferraris

unread,
Sep 29, 2026, 8:59:09 AM (5 days ago) Sep 29
to Harbour Users
Hi Francesco,
many thanks for your quickly answer.

1) I compiled my "program" (not Harbour) using
SET HB_USER_CFLAGS=-DHB_TR_LEVEL_DEBUG
and my C-wrapper contains
HB_TRACE( HB_TR_DEBUG, ( "KK_ADDWEEKS(%ld, %d)", lDate, delta ) );

1.a) when I run program from prompt, it writes stderr on the screen
1.b) when I run program from .bat (*), it writes stderr on the file
(*) whitout any SET HB_TR_LEVEL=HB_TR_XXXXXXXX

So, to enable tracing it seems that
SET HB_USER_CFLAGS=
is mandatory


2) but reading harbour/src/common/hbtrace.c and following "int hb_tr_level( void )" funcion
it seems that tracing level can be set iow enabling tracing WITHOUT compiler flag

On line 202 I see
      if( hb_getenv_buffer( "HB_TR_LEVEL", env, sizeof( env ) ) &&
          env[ 0 ] != '\0' )
      {
         int i;

         for( i = 0; i < HB_TR_LAST; ++i )
         {
            if( hb_stricmp( env, s_slevel[ i ] ) == 0 ||
                hb_stricmp( env, s_slevel[ i ] + 6 ) == 0 )
            {
               s_level = i;
               break;
            }
         }
      }


About s_slevel I read
static const char * s_slevel[ HB_TR_LAST ] =
{
   "HB_TR_ALWAYS",
   "HB_TR_FATAL",
   "HB_TR_ERROR",
   "HB_TR_WARNING",
   "HB_TR_INFO",
   "HB_TR_DEBUG"
};


So, the answer to my question: No, it's impossibile without setting HB_USER_CFLAGS

But it seems to me a very strange behaviour about tracing.
I was think this usage:
a) insert
   HB_TRACE( HB_TR_DEBUG, ( "KK_MYFUNC(%ld, %d)", lDate, delta ) );
   in the code C-wrapper
b) change trace level using
   SET HB_TR_LEVEL=HB_TR_DEBUG
   because current level is
   static int s_level   = -1;
   iow enable trace only for required level

Anyway, many thanks to guide me in the right direction :-)
Ciao, Luigi

Francesco Perillo

unread,
Sep 29, 2026, 9:14:16 AM (5 days ago) Sep 29
to harbou...@googlegroups.com
If you don't set the c flags when you compile your code, HB_TRACE is transformed to an empty statement (sort of...) 

So, imagine a 2 step process:

When compiling you define while HB_TRACE you want to be compiled in the code, less important levels are not even included in the executable.

Then, at run time, you specify which level you want in the trace logs but if the code is not in the exe, it can't be run, whatever is the log level you ask at runtime.



Luigi Ferraris

unread,
Sep 29, 2026, 10:17:24 AM (5 days ago) Sep 29
to harbou...@googlegroups.com
Ciao Francesco



Il 29/09/2026 15:14, Francesco Perillo ha scritto:
If you don't set the c flags when you compile your code, HB_TRACE is transformed to an empty statement (sort of...) 
So, imagine a 2 step process:
When compiling you define while HB_TRACE you want to be compiled in the code, less important levels are not even included in the executable.

Yes, I understand that without usage of -cflag=-DHB_TR_LEVEL_DEBUG the macro is not created: OK



Then, at run time, you specify which level you want in the trace logs but if the code is not in the exe, it can't be run, whatever is the log level you ask at runtime.

I'm sorry, but this is not quite true, at least with my compiled Harbour. Follow these steps

1.a) This is my snippet C code
HB_FUNC( KK_ADDWEEKS )
{
...............

HB_TRACE( HB_TR_DEBUG, ( "KK_ADDWEEKS(%ld, %d)", lDate, delta ) );
...............
}

1.b) This is my snippet build cmd
# enable HB_TRACE level
-cflag=-DHB_TR_LEVEL_DEBUG

1.c) This is my runner.bat
@ECHO OFF
SET HB_TR_LEVEL=HB_TR_DEBUG
oop001.exe 2> lwdubg.log
SET HB_TR_LEVEL=

1.d) This is lwdebug.log content iow empty

So, I do these changes
1.a) This is my snippet C code
HB_FUNC( KK_ADDWEEKS )
{
hb_tracelevel( HB_TR_DEBUG );
...............

HB_TRACE( HB_TR_DEBUG, ( "KK_ADDWEEKS(%ld, %d)", lDate, delta ) );
...............
}

1.c) This is my runner.bat
@ECHO OFF
oop001.exe 2> lwdubg.log

1.d) This is lwdebug.log content
kklib/kkdtwrap.c:175: HB_TR_DEBUG KK_ADDWEEKS(2458909, 364)

As you can see it writes something!
From my point of view, because now the trace level is set (forced) correctly.

Luigi


Reply all
Reply to author
Forward
0 new messages