[cfe-dev] Debugging Information

Cédric Venet cedric.venet at student.ecp.fr
Sat Nov 10 12:04:28 PST 2007


> >> I am investigating adding debugging information to clang. Do you
> >> think it to
> >> soon? (I would like to add a -g flag to the drivers and add
> >> conditional llvm
> >> debug intrinsic emission in CodeGen).
> >> Do you have already some idea on the question? (I studied llvm-gcc
> >> debug
> >> generation and would add something similar)
> 
> I'm not currently involved with the efforts on the CodeGen module.
> Chris, Devang?

I started coding and have a few functionalities working but I hesitate
between two possible implementations.

What I started doing is:

- Add members and accessor functions to CodeGenModule and CodeGenFuntion.
- Insert code directly in the code generating function of these class,
conditionnaly activated on a flag:

======================================================================

class CodeGenModule {
[...]

  // debug information
  bool DebugInfoEnabled;
  llvm::CompileUnitDesc* CompileUnit;
  llvm::AnchorDesc* SubprogramAnchor;
public:
[...]
  
  // acces to debug information:
  bool isDebugInfoEnabled() { return DebugInfoEnabled; }
  llvm::AnchorDesc* getSubprogramAnchor() { return SubprogramAnchor; }
  void setSubprogramAnchor(llvm::AnchorDesc* p) { SubprogramAnchor = p; }
  llvm::CompileUnitDesc* getCompileUnit() { return CompileUnit; }

};

======================================================================

void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
[...]
  
// debug information
  if( CGM.isDebugInfoEnabled() ) {
    // Create subprogram descriptor.
    llvm::SubprogramDesc* Subprogram = new llvm::SubprogramDesc();
    [...]
  }
//

  // Emit the function body.
  EmitStmt(FD->getBody());

[...]  
}

======================================================================

But perhaps It would have been better to encapsulate the functionalities in
one new class, like this:

======================================================================

Class CodeGenDebugInfo {
  llvm::CompileUnitDesc* CompileUnit;
  llvm::AnchorDesc* SubprogramAnchor;
public:
  void EmitFunctionDecl();
  void EmitStatementDecl();
//...
}

======================================================================

class CodeGenModule {
[...]

  // debug information
  CodeGenDebugInfo* CGdebuginfo;
public:
[...]
  
  // acces to debug information:
//  bool isDebugInfoEnabled() { return CGdebuginfo!=NULL; }
  CGdebuginfo* getCGDebugInfo() { return CGdebuginfo; }

};

======================================================================

void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
[...]
  
  if(CodeGenDebugInfo* CGdebuginfo  = CGM.getCGDebugInfo() ) {
    CGdebuginfo-> EmitFunctionDecl();
  }

  // Emit the function body.
  EmitStmt(FD->getBody());

[...]  
}

======================================================================


Sorry for the long long mail...

Cédric

Ps: I didn't post my code because I need study the needed lifetime of the
llvm objects and add the cleanup code

Ps2: Should the first letter of method be a upper or a lower case:
setA(); or SetA();
getA();
isA();

and for DoIt() or doIt? This doesn't seems to be consistant in the code (Not
very important with code completion but else pretty annoying)

ps3: If my English is too bad, says it and I will try to do better. The
thing is I lake practice and I have never be good in grammar (even In my
natural language)





More information about the cfe-dev mailing list