Logging C++ Incomplete Types

From OC Systems Wiki!
Revision as of 22:22, 26 April 2022 by Swn (talk | contribs) (Created page with "Logging variables (particularly parameters) whose type is an incomplete C++ struct/union/class type is straightforward on AIX, but not on Linux. Given the declarations in the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Logging variables (particularly parameters) whose type is an incomplete C++ struct/union/class type is straightforward on AIX, but not on Linux.

Given the declarations in the following files:

----------- file: MyClass.h

class MyClass;

----------- file MyClass.cpp

class MyClass
{
   ...
};

the class MyClass is incomplete in all the files that include MyClass.h.

On AIX, when the program is linked the XlC compiler produces debug information which allows the Apc compiler to correctly handle references to objects of that type, that is, use the complete type definition to determine size and layout.

On Linux, the Gcc compiler does not provide a reference to the complete type for objects using the incomplete type in the debug information. This prevents the Apc compiler from knowing how big such an object is or what its layout is. The user can give the Apc compiler some help in determining the complete type for an incomplete type by referencing the complete type in its source file using target expression modifiers.

For example:

// This declaration gets the "hidden" complete type MyClass from the designated file and add it to the symbol
// table where the following target expressions can find it.

typedef typeof($("MyClass", "-file MyClass.cpp")) LocalMyClass;

probe thread
{
   probe "MyClass::myMethod"
   {
      on_entry
      {
         log("Param = ", $myParam);
         log("Param.field = ", $myParam.field);
      }
   }
}

The only real trick is determining in which file the complete definition resides. The tool apcgen has options -T and -U which may help.