LLDB mainline
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::ASTStructExtractor Class Reference

"lldb/Expression/ASTStructExtractor.h" Extracts and describes the argument structure for a wrapped function. More...

#include <ASTStructExtractor.h>

Inheritance diagram for lldb_private::ASTStructExtractor:
Inheritance graph
[legend]

Public Member Functions

 ASTStructExtractor (clang::ASTConsumer *passthrough, const char *struct_name, ClangFunctionCaller &function)
 Constructor.
 
 ~ASTStructExtractor () override
 Destructor.
 
void Initialize (clang::ASTContext &Context) override
 Link this consumer with a particular AST context.
 
bool HandleTopLevelDecl (clang::DeclGroupRef D) override
 Examine a list of Decls to find the function $__lldb_expr and transform its code.
 
void HandleTranslationUnit (clang::ASTContext &Ctx) override
 Passthrough stub.
 
void HandleTagDeclDefinition (clang::TagDecl *D) override
 Passthrough stub.
 
void CompleteTentativeDefinition (clang::VarDecl *D) override
 Passthrough stub.
 
void HandleVTable (clang::CXXRecordDecl *RD) override
 Passthrough stub.
 
void PrintStats () override
 Passthrough stub.
 
void InitializeSema (clang::Sema &S) override
 Set the Sema object to use when performing transforms, and pass it on.
 
void ForgetSema () override
 Reset the Sema to NULL now that transformations are done.
 

Private Member Functions

void ExtractFromFunctionDecl (clang::FunctionDecl *F)
 Hunt the given FunctionDecl for the argument struct and place information about it into m_function.
 
void ExtractFromTopLevelDecl (clang::Decl *D)
 Hunt the given Decl for FunctionDecls named the same as the wrapper function name, recursing as necessary through LinkageSpecDecls, and calling ExtractFromFunctionDecl on anything that was found.
 

Private Attributes

clang::ASTContext * m_ast_context
 The AST context to use for identifiers and types.
 
clang::ASTConsumer * m_passthrough
 The ASTConsumer down the chain, for passthrough.
 
clang::SemaConsumer * m_passthrough_sema
 The SemaConsumer down the chain, for passthrough.
 
clang::Sema * m_sema
 The Sema to use.
 
ClangFunctionCallerm_function
 The function to populate with information about the argument structure.
 
std::string m_struct_name
 The name of the structure to extract.
 

Detailed Description

"lldb/Expression/ASTStructExtractor.h" Extracts and describes the argument structure for a wrapped function.

This pass integrates with ClangFunctionCaller, which calls functions with custom sets of arguments. To avoid having to implement the full calling convention for the target's architecture, ClangFunctionCaller writes a simple wrapper function that takes a pointer to an argument structure that contains room for the address of the function to be called, the values of all its arguments, and room for the function's return value.

The definition of this struct is itself in the body of the wrapper function, so Clang does the structure layout itself. ASTStructExtractor reads through the AST for the wrapper function and finds the struct.

Definition at line 33 of file ASTStructExtractor.h.

Constructor & Destructor Documentation

◆ ASTStructExtractor()

ASTStructExtractor::ASTStructExtractor ( clang::ASTConsumer *  passthrough,
const char *  struct_name,
ClangFunctionCaller function 
)

Constructor.

Parameters
[in]passthroughSince the ASTs must typically go through to the Clang code generator in order to produce LLVM IR, this SemaConsumer must allow them to pass to the next step in the chain after processing. Passthrough is the next ASTConsumer, or NULL if none is required.
[in]struct_nameThe name of the structure to extract from the wrapper function.
[in]functionThe caller object whose members should be populated with information about the argument struct. ClangFunctionCaller friends ASTStructExtractor for this purpose.

Definition at line 29 of file ASTStructExtractor.cpp.

References m_passthrough, and m_passthrough_sema.

◆ ~ASTStructExtractor()

ASTStructExtractor::~ASTStructExtractor ( )
overridedefault

Destructor.

Member Function Documentation

◆ CompleteTentativeDefinition()

void ASTStructExtractor::CompleteTentativeDefinition ( clang::VarDecl *  D)
override

Passthrough stub.

Definition at line 156 of file ASTStructExtractor.cpp.

References m_passthrough.

◆ ExtractFromFunctionDecl()

void ASTStructExtractor::ExtractFromFunctionDecl ( clang::FunctionDecl *  F)
private

Hunt the given FunctionDecl for the argument struct and place information about it into m_function.

Parameters
[in]FThe FunctionDecl to hunt.

Definition at line 50 of file ASTStructExtractor.cpp.

References m_ast_context, m_function, lldb_private::FunctionCaller::m_member_offsets, lldb_private::FunctionCaller::m_return_offset, lldb_private::FunctionCaller::m_return_size, m_struct_name, lldb_private::FunctionCaller::m_struct_size, and lldb_private::FunctionCaller::m_struct_valid.

Referenced by ExtractFromTopLevelDecl().

◆ ExtractFromTopLevelDecl()

void ASTStructExtractor::ExtractFromTopLevelDecl ( clang::Decl *  D)
private

Hunt the given Decl for FunctionDecls named the same as the wrapper function name, recursing as necessary through LinkageSpecDecls, and calling ExtractFromFunctionDecl on anything that was found.

Parameters
[in]DThe Decl to hunt.

Definition at line 111 of file ASTStructExtractor.cpp.

References ExtractFromFunctionDecl(), ExtractFromTopLevelDecl(), m_ast_context, m_function, and lldb_private::FunctionCaller::m_wrapper_function_name.

Referenced by ExtractFromTopLevelDecl(), and HandleTopLevelDecl().

◆ ForgetSema()

void ASTStructExtractor::ForgetSema ( )
override

Reset the Sema to NULL now that transformations are done.

Definition at line 178 of file ASTStructExtractor.cpp.

References m_passthrough_sema, and m_sema.

◆ HandleTagDeclDefinition()

void ASTStructExtractor::HandleTagDeclDefinition ( clang::TagDecl *  D)
override

Passthrough stub.

Definition at line 151 of file ASTStructExtractor.cpp.

References m_passthrough.

◆ HandleTopLevelDecl()

bool ASTStructExtractor::HandleTopLevelDecl ( clang::DeclGroupRef  D)
override

Examine a list of Decls to find the function $__lldb_expr and transform its code.

Parameters
[in]DThe list of Decls to search. These may contain LinkageSpecDecls, which need to be searched recursively. That job falls to TransformTopLevelDecl.

Definition at line 132 of file ASTStructExtractor.cpp.

References ExtractFromTopLevelDecl(), and m_passthrough.

◆ HandleTranslationUnit()

void ASTStructExtractor::HandleTranslationUnit ( clang::ASTContext &  Ctx)
override

Passthrough stub.

Definition at line 146 of file ASTStructExtractor.cpp.

References m_passthrough.

◆ HandleVTable()

void ASTStructExtractor::HandleVTable ( clang::CXXRecordDecl *  RD)
override

Passthrough stub.

Definition at line 161 of file ASTStructExtractor.cpp.

References m_passthrough.

◆ Initialize()

void ASTStructExtractor::Initialize ( clang::ASTContext &  Context)
override

Link this consumer with a particular AST context.

Parameters
[in]ContextThis AST context will be used for types and identifiers, and also forwarded to the passthrough consumer, if one exists.

Definition at line 43 of file ASTStructExtractor.cpp.

References m_ast_context, and m_passthrough.

◆ InitializeSema()

void ASTStructExtractor::InitializeSema ( clang::Sema &  S)
override

Set the Sema object to use when performing transforms, and pass it on.

Parameters
[in]SThe Sema to use. Because Sema isn't externally visible, this class casts it to an Action for actual use.

Definition at line 171 of file ASTStructExtractor.cpp.

References m_passthrough_sema, and m_sema.

◆ PrintStats()

void ASTStructExtractor::PrintStats ( )
override

Passthrough stub.

Definition at line 166 of file ASTStructExtractor.cpp.

References m_passthrough.

Member Data Documentation

◆ m_ast_context

clang::ASTContext* lldb_private::ASTStructExtractor::m_ast_context
private

The AST context to use for identifiers and types.

Definition at line 115 of file ASTStructExtractor.h.

Referenced by ExtractFromFunctionDecl(), ExtractFromTopLevelDecl(), and Initialize().

◆ m_function

ClangFunctionCaller& lldb_private::ASTStructExtractor::m_function
private

The function to populate with information about the argument structure.

Definition at line 124 of file ASTStructExtractor.h.

Referenced by ExtractFromFunctionDecl(), and ExtractFromTopLevelDecl().

◆ m_passthrough

clang::ASTConsumer* lldb_private::ASTStructExtractor::m_passthrough
private

The ASTConsumer down the chain, for passthrough.

NULL if it's a SemaConsumer.

Definition at line 116 of file ASTStructExtractor.h.

Referenced by ASTStructExtractor(), CompleteTentativeDefinition(), HandleTagDeclDefinition(), HandleTopLevelDecl(), HandleTranslationUnit(), HandleVTable(), Initialize(), and PrintStats().

◆ m_passthrough_sema

clang::SemaConsumer* lldb_private::ASTStructExtractor::m_passthrough_sema
private

The SemaConsumer down the chain, for passthrough.

NULL if it's an ASTConsumer.

Definition at line 119 of file ASTStructExtractor.h.

Referenced by ASTStructExtractor(), ForgetSema(), and InitializeSema().

◆ m_sema

clang::Sema* lldb_private::ASTStructExtractor::m_sema
private

The Sema to use.

Definition at line 122 of file ASTStructExtractor.h.

Referenced by ForgetSema(), and InitializeSema().

◆ m_struct_name

std::string lldb_private::ASTStructExtractor::m_struct_name
private

The name of the structure to extract.

Definition at line 126 of file ASTStructExtractor.h.

Referenced by ExtractFromFunctionDecl().


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