Debugging hbQt

I decided to spend some time trying to understand what is happening inside hbQt in certain situations.
I started with a fresh Harbour and hbQt build, compiled according to my previous post.

Harbour includes a way to trace code execution. You to enable it before compilation and before running a program setting some environment variables.

As usual, I created a new batch script in c:\cvs directory taking infos from readme.md

set HB_TR_LEVEL=always
set HB_TR_SYSOUT=yes

When we compile a source code inside Harbour and HB_TR_LEVEL is set, some #defines are read and code is compiled. When is not set, the code is simply ignored. We will see later some examples.

There are several levels of trace severity.

To look at the logs you need to run this software:
Download DebugView (http://technet.microsoft.com/it-it/sysinternals/bb896647.aspx).

We built a version of Harbour and hbQt without setting that env variables. When compiling hbQt the build process creates lots of intermediate c++ files in a parallel directory tree starting at addons\hbqt\.hbmk\win\mingw.
If we enter the hbqtgui subfolder you will see the generated files. They are named after the equivalent Qt classes.

If we run another build of qtcontribs, the files are not generated but hbmk2 checks if they are newer than the compiled file and, if yes, it compiles them.
So we can edit any .cpp file of hbqt and run hbmk2 qtcontribs.hbp to generate a new lib file with the updated function.
To shorten compilation time it is also possible to disable in qtcontribs.hbp all the libraries and utilities I’m not going to change.

I’m a command-line guy, and use vim as my editor. So I end having 3 command prompt windows:
– path set to the dir of the program used to test
– path set to the subdir of hbqt that I need to change (hbqt\qtcore for modifying internal hbQt files, hbqt\.hbmk\win\mingw\hbqtgui for testing the objects)
– path set to addons dir, to be able to issue hbmk2 qtcontribs.hbp
All three command prompt windows have se trace variables set
A fourth window is DebugView.

How to enable traceing in source code?

It is possible to enable tracing level by level, but to be honest I always find some problems to do so.
hbQt has a lot of trace messages at HB_TR_LEVEL=debug and enabling that level will bring a lot of logs that I’m not interested in.
So I use another method: I change the level in the lines I’m interested to trace from HB_TR_DEBUG to HB_TR_ALWAYS, so that I can have the logs of the lines I want to look for.

In cpp code the syntax is:

HB_TRACE( HB_TR_ALWAYS, ( "............QT_DESTROY_ENDS...............%p %p", qtObject, qObject ) );

It follows printf syntax to replace %p (pointers) %i (integers) %s (strings). Note that the strings and the values are enclosed in a parenthesis.

In Harbour the syntax is:

#include
...
HB_TRACE( HB_TR_ALWAYS, "value to trace "+str( value,5) )

Remember to set the environemnt variables in the command prompt windows to enable tracing, compile what you need, run DebugView and then run the test program.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>