Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to debug in C++ Builder 5

Status
Not open for further replies.

BorlandDave

Programmer
Jun 13, 2005
86
GB
Could someone please give me some simple steps of hoe to debug in C++ Builder 5? I have previously used VS6 and am unfamiliar with the way Borland does things...

I set a breakpoint on one of the lines of code, and run. This brings up a window entitled "CPU" that contains lots of assembly code which I am not interested in, so I close this window to get back to my C++ code. I press F8 to step through, but instead of stepping, my gui window pops up...

What am I doing wrong?? Thanks for any help.
 
I have used BCB versions 1,3,5. I never see the CPU/Assembler window except when an error occurs in code that I don't have source code for (I.E. library modules). I have never found a bug in library modules. The times when an error occurs in that code it has always been because I had corrupted the stack or the heap or passed an invalid argument. Proceding after such an error usually just crashes some more.

When you are single stepping or stopped at a breakpoint and you want the program to run just press F9. If you have cleared your breakpoints it will then run 'til completion or crash.

If you want to abort a debugging session press Ctrl-F2.
 
Thanks for the help, but I should have given you some more information. The workspace I am trying to debug consists of several projects. There is a main project which, when executed, launches the others and they all communicate through COM interfaces.

How do I debug one of these secondary projects? They all need the main project to be running to function correctly.
 
Anyone?

I really need to be able to do this.

Thanks for any help.
 
set global
bool debug;
Code:
int   function (void)
{
    try
    {      
        sumpin.....

    }
    catch (...)
    {
        if (debug)        
            LogError ("An exception occured on function ()");
        return 1;
    }
}

Code:
#include <time.h>
void LogError (char *error)
{
    if (_LogError)
    {
        FILE *file;
        time_t t;

        char *dir = getcwd(NULL, MAXPATH);

        if (homedir)
            chdir (homedir);

        if ((file = fopen ("error.log", "a+")) != NULL)
        {
            time(&t);
            fprintf (file, "%s ---  %s\n", ctime(&t),error);
            fclose (file);
        }
    
        if (dir)
            chdir (dir); 
    }
}
 
Thanks for the help... but I have infact already done this. The problem is, some of my functions are quite long so it would be very useful to be able to step through line by line. Is this not possible?
 
Also, it's a logical error rather than an exception that I am wanting to debug.
 
I also call "LogError" from inside of many functions.
Code:
// Thr file id is not correct.
if (strncmp (_head2._lead2.a, ID, 4))
{
   LogError ("The file accessed is not a madHatter table.");
   active = true;
   Close ();
   fclose (_tablefile);
   return 1; 
}
I use this quite often in my database engine.
this is not the formal debug but it has helped me
correct many logical errors. infact thats why
I put them there in the first place. Mycode is
sort of home grown and I have not as yet taught
myself how to use a debugger. I sort of got to
rely upon my brain a little more.

TC
 
I have BCB 6, so forgive me if this info doens't apply.

I set a breakpoint in my code, which it sounds like you are doing. When execution stops at that breakpoint, I get a view of the code with the point of execution (my breakpoint) highlighted in red. Then I select View | Debug windows | Local Variables
which pulls up a window that shows me all variables in scope and their values. I also will pull up the call stack window sometimes, depending on what I'm trying to debug. Frequently I'll pull up the watch list window as well. I edit the watch list by right clicking and adding the expression I want to watch. Then, I use the Trace Into (F7) rather than F8, or else I use Trace To Next Source Line (Shift F7). That's how it works in BCB 6, hope that helps.
 
Have you tried this?
1. execute the primary project at full speed.
2. Set your breakpoints in the secondary projects.
3. As the main program is running, "attach" the secondary project you want to step through to the running program.
I have used this to debug some dll's I've developed, and works pretty well for me.
 
Prattaratt, that does sound like it should work. I have infact tried this already, but didn't have any luck. I'll give it another shot today and get back to you.

Cheers for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top