PDT HOME PREVIOUS NEXT

PDT Application:
Static Analysis and Documentation Generation
with DUCTAPE

Source code from DUCTAPE's pdbtree utility that displays the static call graph:

  • Functions instantiated from templates are automatically included in the vector of called functions (at (1))
  • The for loop iterates over functions called by the current function (at (2))
  • Functions called by the current function are reported (at (3))
  • The routine printFuncTree() recurses to display the entire tree of called functions (at (4))


Sample Source Code from pdbtree
static void printFuncTree(const pdbRoutine *r, int level) {
	r->flag(ACTIVE);
	pdbRoutine::callvec c = r->callees( );					(1)
	for (pdbRoutine::callvec::iterator it=c.begin( ); it!=c.end( ); ++it) {	(2)
		const pdbRoutine *rr = (*it)->call( );
		if ( level != 0 || rr->callees( ).size( ) ) {		
			cout << setw((level-1)*5) << "";
			if ( level ) cout << "`--> ";
			cout << rr->fullName( );				(3)
			if ( (*it)->isVirtual( ) ) cout << " (VIRTUAL)";
			if ( rr->flag() == ACTIVE ) {
				cout << " ..." << endl;
			} else {
				cout << endl;
				printFuncTree(rr, level+1);			(4)
			}
		}
	}
	r->flag(INACTIVE);
}