demo.cpp
/* Print function location in source code.
 */
Print function location in source code.
Print function location in source code .
void Support::printFunLocation(Function * Fun)
{
	for (Function::iterator BB = Fun->begin(); BB != Fun->end(); BB++) {
		for (BasicBlock::iterator II = BB->begin(); II != BB->end(); II++) {
			Instruction *I = &*II;
			const DILocation * DIL = I->getDebugLoc();
			if(!DIL){
				continue;
			}else{
				char pPath[200];
				string sFileName;
				if(DIL->getFilename().str().substr(0,5) == "/home"){
					sFileName = DIL->getFilename().str();
				}else{
					sFileName = DIL->getDirectory().str() + "/" + DIL->getFilename().str();
				}
				realpath(sFileName.c_str(), pPath);
				sFileName = string(sFileName);
				unsigned int numLine = DIL->getLine();
				errs() << "//---" << sFileName << ": " << numLine << "\n";
				return;
			}
		}
	}
	return;
}
void Support :: printFunLocation ( Function * Fun ) { for ( Function :: iterator BB = Fun -> begin ( ) ; BB != Fun -> end ( ) ; BB ++ ) { for ( BasicBlock :: iterator II = BB -> begin ( ) ; II != BB -> end ( ) ; II ++ ) { Instruction * I = & * II ; const DILocation * DIL = I -> getDebugLoc ( ) ; if ( ! DIL ) { continue ; } else { char pPath [ 200 ] ; string sFileName ; if ( DIL -> getFilename ( ) . str ( ) . substr ( 0 , 5 ) == " " ) { sFileName = DIL -> getFilename ( ) . str ( ) ; } else { sFileName = DIL -> getDirectory ( ) . str ( ) + " " + DIL -> getFilename ( ) . str ( ) ; } realpath ( sFileName . c_str ( ) , pPath ) ; sFileName = string ( sFileName ) ; unsigned int numLine = DIL -> getLine ( ) ; errs ( ) << " " << sFileName << " " << numLine << " \n " ; return ; } } } return ; }
Print function location in source code.
Print function location in source code .