ClangUtilityFunction.h revision 830a903fd7cd4595cf52e1630b6491930ada0400
1//===-- ClangUtilityFunction.h ----------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_ClangUtilityFunction_h_ 11#define liblldb_ClangUtilityFunction_h_ 12 13// C Includes 14// C++ Includes 15#include <string> 16#include <map> 17#include <memory> 18#include <vector> 19 20// Other libraries and framework includes 21// Project includes 22 23#include "lldb/lldb-forward.h" 24#include "lldb/lldb-private.h" 25#include "lldb/Core/ClangForward.h" 26#include "lldb/Expression/ClangExpression.h" 27 28namespace lldb_private 29{ 30 31//---------------------------------------------------------------------- 32/// @class ClangUtilityFunction ClangUtilityFunction.h "lldb/Expression/ClangUtilityFunction.h" 33/// @brief Encapsulates a single expression for use with Clang 34/// 35/// LLDB uses expressions for various purposes, notably to call functions 36/// and as a backend for the expr command. ClangUtilityFunction encapsulates 37/// a self-contained function meant to be used from other code. Utility 38/// functions can perform error-checking for ClangUserExpressions, 39//---------------------------------------------------------------------- 40class ClangUtilityFunction : public ClangExpression 41{ 42public: 43 //------------------------------------------------------------------ 44 /// Constructor 45 /// 46 /// @param[in] text 47 /// The text of the function. Must be a full translation unit. 48 /// 49 /// @param[in] name 50 /// The name of the function, as used in the text. 51 //------------------------------------------------------------------ 52 ClangUtilityFunction (const char *text, 53 const char *name); 54 55 //------------------------------------------------------------------ 56 /// Install the utility function into a process 57 /// 58 /// @param[in] error_stream 59 /// A stream to print parse errors and warnings to. 60 /// 61 /// @param[in] exe_ctx 62 /// The execution context to install the utility function to. 63 /// 64 /// @return 65 /// True on success (no errors); false otherwise. 66 //------------------------------------------------------------------ 67 bool 68 Install (Stream &error_stream, ExecutionContext &exe_ctx); 69 70 //------------------------------------------------------------------ 71 /// Check whether the given PC is inside the function 72 /// 73 /// Especially useful if the function dereferences NULL to indicate a failed 74 /// assert. 75 /// 76 /// @param[in] pc 77 /// The program counter to check. 78 /// 79 /// @return 80 /// True if the program counter falls within the function's bounds; 81 /// false if not (or the function is not JIT compiled) 82 //------------------------------------------------------------------ 83 bool 84 ContainsAddress (lldb::addr_t address) 85 { 86 // nothing is both >= LLDB_INVALID_ADDRESS and < LLDB_INVALID_ADDRESS, 87 // so this always returns false if the function is not JIT compiled yet 88 return (address >= m_jit_begin && address < m_jit_end); 89 } 90 91 //------------------------------------------------------------------ 92 /// Return the address of the function's JIT-compiled code, or 93 /// LLDB_INVALID_ADDRESS if the function is not JIT compiled 94 //------------------------------------------------------------------ 95 lldb::addr_t 96 StartAddress () 97 { 98 return m_jit_begin; 99 } 100 101 //------------------------------------------------------------------ 102 /// Return the string that the parser should parse. Must be a full 103 /// translation unit. 104 //------------------------------------------------------------------ 105 const char * 106 Text () 107 { 108 return m_function_text.c_str(); 109 } 110 111 //------------------------------------------------------------------ 112 /// Return the function name that should be used for executing the 113 /// expression. Text() should contain the definition of this 114 /// function. 115 //------------------------------------------------------------------ 116 const char * 117 FunctionName () 118 { 119 return m_function_name.c_str(); 120 } 121 122 //------------------------------------------------------------------ 123 /// Return the object that the parser should use when resolving external 124 /// values. May be NULL if everything should be self-contained. 125 //------------------------------------------------------------------ 126 ClangExpressionDeclMap * 127 DeclMap () 128 { 129 return NULL; 130 } 131 132 //------------------------------------------------------------------ 133 /// Return the object that the parser should use when registering 134 /// local variables. May be NULL if the Expression doesn't care. 135 //------------------------------------------------------------------ 136 ClangExpressionVariableStore * 137 LocalVariables () 138 { 139 return NULL; 140 } 141 142 //------------------------------------------------------------------ 143 /// Return the object that the parser should allow to access ASTs. 144 /// May be NULL if the ASTs do not need to be transformed. 145 /// 146 /// @param[in] passthrough 147 /// The ASTConsumer that the returned transformer should send 148 /// the ASTs to after transformation. 149 //------------------------------------------------------------------ 150 clang::ASTConsumer * 151 ASTTransformer (clang::ASTConsumer *passthrough) 152 { 153 return NULL; 154 } 155 156 //------------------------------------------------------------------ 157 /// Return the stream that the parser should use to write DWARF 158 /// opcodes. 159 //------------------------------------------------------------------ 160 StreamString & 161 DwarfOpcodeStream () 162 { 163 return *((StreamString*)NULL); 164 } 165 166private: 167 std::string m_function_text; ///< The text of the function. Must be a well-formed translation unit. 168 std::string m_function_name; ///< The name of the function. 169 170 lldb::addr_t m_jit_begin; ///< The address of the JITted code. LLDB_INVALID_ADDRESS if invalid. 171 lldb::addr_t m_jit_end; ///< The end of the JITted code. LLDB_INVALID_ADDRESS if invalid. 172}; 173 174} // namespace lldb_private 175 176#endif // liblldb_ClangUtilityFunction_h_ 177