Debugging



Table of Contents      

Introduction

Getting Up and Running

 

Debugging

New C++ Features

 

External Interface   

Tutorials

Man Page

FAQ   


This chapter describes how to apply debuggers to code generated with KAI C++. The best debugger to use with KAI C++ depends upon the platform, as shown in the table below.
Platform Recommended Debugger
SGI-Irix5

KCC aware gdb
SGI-Irix6

64-bit dbx
DEC

KCC aware gdb
HP
Linux
Sparc

 

8.1 Compiling for Debugging

When debugging your code, use the +K0 option. This option implicitly sets the -g option, and turns off inlining and other optimizations. The intent is to make the code easy to understand by debuggers.

Debugging at +K1 is practical too. The -g option is not implicitly set, so you should use set -g for debugging at the +K1 level. The principle transformation at the +K1 level is inlining. Thus at this level, the only surprise should be that you cannot step into a call of an inlined function.

Some debugging can be done at +K2 and +K3, but you should be aware that the optimizations can be quite radical and can confuse debuggers. In particular, entire objects defined in the source may not exist in the object code, and the order of evaluation may be rearranged. As with +K1, you will need to set -g explicitly when debugging at +K2 and +K3.


8.1.1 Example

The following trivial example will be used frequently in the following discussions of debuggers.

1   class Fraction {
2   public:
3       Fraction( int n, int d ) :
4           numerator(n),
5           denominator(d)
6       {}
7
8       Fraction& operator+=( int i ) {
9           numerator += i*denominator;
10           return *this;
11       }
12
13   private:
14       int numerator;
15       int denominator;
16   };
17
18   int main() {
19       Fraction a(2,5);
20       a += 6;
21   }

 

8.2 For GDB Users

This section presumes that you are familiar with using GDB for debugging executables produced by other compilers. If not, you should first read the manual titled Debugging with GDB that comes with GDB.


8.2.1 Starting GDB

In order to debug executables compiled with KAI C++ with GDB, first run the command:

    set demangle-style edg

If you always want to run this command when you start gdb, put it in a .gdbinit file in your home directory.

 

8.2.2 Accessing Qualified Names

GDB seems to have some difficulty with qualified names. Use the tab and single-quote (') to help GDB find qualified and overloaded names. For example, to set a breakpoint in method Fraction::operator+= of Figure 8.1, you can type in:

    break 'Fraction::operator+=<TAB>

where <TAB> denotes the "tab" key, and GDB will fill in the line to read:

    break 'Fraction::operator+=(int)'

Single-quotes must be used around names that are not simple identifiers.

 

8.2.3 Base Classes

A non-virtual base class Foo for a derived class Bar shows up in the debugger as a member __b_Foo of class Bar. A virtual base class Foo shows up as a member __p_Foo that is a pointer to the virtual base. The virtual base is stored in a member __v_Foo of the complete object. If you are inspecting a subobject, sometimes __v_Foo does not appear because it is in another subobject.


8.3 For SGI Irix 5.3 DBX Users

For the most part, you can debug code generated with the +K0 option with SGI's odbx (old dbx) the same way you would debug code generated by SGI's C++ compilers. This section presumes that you are familiar with using SGI's dbx, and summarizes a few non-obvious points peculiar to KAI C++.

 

8.3.1 Printing Data Members

When inside a method, you must use the this pointer explicitly to reference members. For example, if while stopped inside method Fraction::operator+= of Figure 8.1, you want to print the value of numerator, you must prefix it with this->. For example:

(dbx) print numerator
"numerator" not defined or not active..

 

(dbx) print this->numerator 
2 

 

8.3.2 Base Classes

SGI's Irix 5.3 DBX prints base classes in the same way that GDB does.


Next Section         Copyright © 1996-1998. All rights reserved.

E-Mail KAI Technical Support   E-Mail KAI   Contact KAI   

This file last updated on 10 April 1998..