Poplar and PopLibs
poplar::DebugContext Class Reference

DebugContext gathers the common external parameters of the context of an operation. More...

#include <DebugContext.hpp>

Public Member Functions

std::string getPathName () const
 Gets the pathname of this object as the concatenation of the parent name received in the constructor via DebugInfo or DebugNameAndId and the name explicitly set for this object.
 

Detailed Description

DebugContext gathers the common external parameters of the context of an operation.

As an extension to DebugNameAndId, DebugContext bundles a name and a DebugId as well as the file and line in the source code where it is invoked.

Note that to reflect the specific line where an invocation took place, the DebugContext object must be constructed in the same line of the invocation. For instance, if a function foo wants to capture the DebugContext of its invocation, it should be called like this:

foo(DebugContext{});

Rather than:

DebugContext debugContext;
foo(debugContext);

Although typically foo would accept a default argument:

void foo(const DebugContext &debugContext = {});

so that the DebugContext can be automatically captured:

foo();

The ultimate target of DebugContext is to be passed to the constructor of a DebugInfo object. The DebugContext carries the DebugId of the parent DebugInfo to keep a hierarchical relationship. A typical flow would be:

The initial DebugContext is (implicitly) created in foo default argument and used to create the initial DebugInfo. Then foo2 is called:

void foo(const DebugContext &debugContext = {}) {
DebugInfo debugInfo{debugContext};
foo2(debugInfo);
}

foo2 captures the DebugContext that contains the parent DebugId:

void foo2(const DebugContext &debugContext) {
DebugInfo debugInfo{debugContext};
}

In this way, low-level operations and resources can be related to the high-level operation that triggered them.


The documentation for this class was generated from the following file: