[Lldb-commits] [lldb] r179842 - Removed 2800+ lines of code that no longer do anything
Sean Callanan
scallanan at apple.com
Fri Apr 19 01:14:33 PDT 2013
Author: spyffe
Date: Fri Apr 19 03:14:32 2013
New Revision: 179842
URL: http://llvm.org/viewvc/llvm-project?rev=179842&view=rev
Log:
Removed 2800+ lines of code that no longer do anything
now that the IR interpreter and the JIT share the same
materialization codepaths.
Modified:
lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
lldb/trunk/include/lldb/Expression/IRInterpreter.h
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
lldb/trunk/source/Expression/IRInterpreter.cpp
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=179842&r1=179841&r2=179842&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Fri Apr 19 03:14:32 2013
@@ -117,60 +117,6 @@ public:
DidParse ();
//------------------------------------------------------------------
- /// [Used by IRForTarget] Get a new result variable name of the form
- /// $n, where n is a natural number starting with 0.
- ///
- /// @param[in] name
- /// The std::string to place the name into.
- //------------------------------------------------------------------
- const ConstString &
- GetPersistentResultName ();
-
- //------------------------------------------------------------------
- /// [Used by IRForTarget] Get a constant variable given a name,
- /// a type, and an llvm::APInt.
- ///
- /// @param[in] name
- /// The name of the variable
- ///
- /// @param[in] type
- /// The type of the variable, which will be imported into the
- /// target's AST context
- ///
- /// @param[in] value
- /// The value of the variable
- ///
- /// @return
- /// The created variable
- //------------------------------------------------------------------
- lldb::ClangExpressionVariableSP
- BuildIntegerVariable (const ConstString &name,
- lldb_private::TypeFromParser type,
- const llvm::APInt& value);
-
- //------------------------------------------------------------------
- /// [Used by IRForTarget] Cast an existing variable given a Decl and
- /// a type.
- ///
- /// @param[in] name
- /// The name of the new variable
- ///
- /// @param[in] decl
- /// The Clang variable declaration for the original variable,
- /// which must be looked up in the map
- ///
- /// @param[in] type
- /// The desired type of the variable after casting
- ///
- /// @return
- /// The created variable
- //------------------------------------------------------------------
- lldb::ClangExpressionVariableSP
- BuildCastVariable (const ConstString &name,
- clang::VarDecl *decl,
- lldb_private::TypeFromParser type);
-
- //------------------------------------------------------------------
/// [Used by IRForTarget] Add a variable to the list of persistent
/// variables for the process.
///
@@ -391,244 +337,6 @@ public:
TargetInfo GetTargetInfo();
//------------------------------------------------------------------
- /// [Used by IRInterpreter] Promote an unknown address to a
- /// LoadAddress or FileAddress depending on the presence of a
- /// process.
- ///
- /// @param[in] addr
- /// The address to promote.
- ///
- /// @return
- /// The wrapped entity.
- //------------------------------------------------------------------
- lldb_private::Value WrapBareAddress (lldb::addr_t addr);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Write to the target.
- ///
- /// @param[in] value
- /// The address to write to.
- ///
- /// @param[in] addr
- /// The address of the data buffer to read from.
- ///
- /// @param[in] length
- /// The amount of data to write, in bytes.
- ///
- /// @return
- /// True if the write could be performed; false otherwise.
- //------------------------------------------------------------------
- bool
- WriteTarget (lldb_private::IRMemoryMap &map,
- lldb_private::Value &value,
- const uint8_t *data,
- size_t length);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Read from the target.
- ///
- /// @param[in] data
- /// The address of the data buffer to write to.
- ///
- /// @param[in] value
- /// The address to read from.
- ///
- /// @param[in] length
- /// The amount of data to read, in bytes.
- ///
- /// @return
- /// True if the read could be performed; false otherwise.
- //------------------------------------------------------------------
- bool
- ReadTarget (lldb_private::IRMemoryMap &map,
- uint8_t *data,
- lldb_private::Value &value,
- size_t length);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Get the Value for a NamedDecl.
- ///
- /// @param[in] decl
- /// The Decl whose value is to be found.
- ///
- /// @param[out] flags
- /// The flags for the found variable.
- ///
- /// @return
- /// The value, or NULL.
- //------------------------------------------------------------------
- lldb_private::Value
- LookupDecl (clang::NamedDecl *decl,
- ClangExpressionVariable::FlagType &flags);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Get the Value for "this", "self", or
- /// "_cmd".
- ///
- /// @param[in] name
- /// The name of the entity to be found.
- ///
- /// @return
- /// The value, or NULL.
- //------------------------------------------------------------------
- lldb_private::Value
- GetSpecialValue (const ConstString &name);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Returns true if the result is a
- /// reference to data in the target, meaning it must be
- /// dereferenced once more to get its data.
- ///
- /// @param[in] name
- /// The name of the result.
- ///
- /// @return
- /// True if the result is a reference; false otherwise (or on
- /// error).
- //------------------------------------------------------------------
- bool
- ResultIsReference (const ConstString &name);
-
- //------------------------------------------------------------------
- /// [Used by IRInterpreter] Find the result persistent variable,
- /// propagate the given value to it, and return it.
- ///
- /// @param[out] valobj
- /// Set to the complete object.
- ///
- /// @param[in] value
- /// A value indicating the location of the value's contents.
- ///
- /// @param[in] name
- /// The name of the result.
- ///
- /// @param[in] type
- /// The type of the data.
- ///
- /// @param[in] transient
- /// True if the data should be treated as disappearing after the
- /// expression completes. In that case, it gets no live data.
- ///
- /// @param[in] maybe_make_load
- /// True if the value is a file address but should be potentially
- /// upgraded to a load address if a target is presence.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj,
- lldb_private::IRMemoryMap &map,
- lldb_private::Value &value,
- const ConstString &name,
- lldb_private::TypeFromParser type,
- bool transient,
- bool maybe_make_load);
-
-
- void
- RemoveResultVariable (const ConstString &name);
-
- //------------------------------------------------------------------
- /// [Used by CommandObjectExpression] Materialize the entire struct
- /// at a given address, which should be aligned as specified by
- /// GetStructInfo().
- ///
- /// @param[in] struct_address
- /// The address at which the struct should be written.
- ///
- /// @param[in] error
- /// An Error to populate with any messages related to
- /// materializing the struct.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- Materialize (IRMemoryMap &map,
- lldb::addr_t &struct_address,
- Error &error);
-
- //------------------------------------------------------------------
- /// [Used by CommandObjectExpression] Get the "this" pointer
- /// from a given execution context.
- ///
- /// @param[out] object_ptr
- /// The this pointer.
- ///
- /// @param[in] object_name
- /// The name of the object pointer -- "this," "self," or similar
- /// depending on language
- ///
- /// @param[in] error
- /// An Error to populate with any messages related to
- /// finding the "this" pointer.
- ///
- /// @param[in] suppress_type_check
- /// True if the type is not needed.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- GetObjectPointer (lldb::addr_t &object_ptr,
- ConstString &object_name,
- Error &error,
- bool suppress_type_check = false);
-
- //------------------------------------------------------------------
- /// [Used by CommandObjectExpression] Pretty-print a materialized
- /// struct, which must have been materialized by Materialize(),
- /// byte for byte on a given stream.
- ///
- /// @param[in] exe_ctx
- /// The execution context from which to read the struct.
- ///
- /// @param[in] s
- /// The stream on which to write the pretty-printed output.
- ///
- /// @param[in] error
- /// An Error to populate with any messages related to
- /// pretty-printing the struct.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- DumpMaterializedStruct (Stream &s,
- Error &error);
-
- //------------------------------------------------------------------
- /// [Used by CommandObjectExpression] Deaterialize the entire struct.
- ///
- /// @param[in] exe_ctx
- /// The execution context from which to read the struct.
- ///
- /// @param[out] result
- /// A ClangExpressionVariable containing the result of the
- /// expression, for potential re-use.
- ///
- /// @param[in] stack_frame_top, stack_frame_bottom
- /// If not LLDB_INVALID_ADDRESS, the bounds for the stack frame
- /// in which the expression ran. A result whose address falls
- /// inside this stack frame is dematerialized as a value
- /// requiring rematerialization.
- ///
- /// @param[in] error
- /// An Error to populate with any messages related to
- /// dematerializing the struct.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- Dematerialize (lldb::ClangExpressionVariableSP &result_sp,
- IRMemoryMap &map,
- lldb::addr_t stack_frame_top,
- lldb::addr_t stack_frame_bottom,
- Error &error);
-
- //------------------------------------------------------------------
/// [Used by ClangASTSource] Find all entities matching a given name,
/// using a NameSearchContext to make Decls for them.
///
@@ -778,45 +486,6 @@ private:
}
//----------------------------------------------------------------------
- /// The following values refer to a specific materialization of the
- /// structure in a process
- //----------------------------------------------------------------------
- struct MaterialVars {
- MaterialVars() :
- m_allocated_area(0),
- m_materialized_location(0)
- {
- }
-
- Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer to use.
-
- Process *m_process; ///< The process that the struct is materialized into.
- lldb::addr_t m_allocated_area; ///< The base of the memory allocated for the struct. Starts on a potentially unaligned address and may therefore be larger than the struct.
- lldb::addr_t m_materialized_location; ///< The address at which the struct is placed. Falls inside the allocated area.
- };
-
- std::unique_ptr<MaterialVars> m_material_vars;
-
- //----------------------------------------------------------------------
- /// Activate materialization-specific variables
- //----------------------------------------------------------------------
- void
- EnableMaterialVars()
- {
- if (!m_material_vars.get())
- m_material_vars.reset(new struct MaterialVars);
- }
-
- //----------------------------------------------------------------------
- /// Deallocate materialization-specific variables
- //----------------------------------------------------------------------
- void
- DisableMaterialVars()
- {
- m_material_vars.reset();
- }
-
- //----------------------------------------------------------------------
/// Get this parser's ID for use in extracting parser- and JIT-specific
/// data from persistent variables.
//----------------------------------------------------------------------
@@ -827,36 +496,6 @@ private:
}
//------------------------------------------------------------------
- /// Given a stack frame, find a variable that matches the given name and
- /// type. We need this for expression re-use; we may not always get the
- /// same lldb::Variable back, and we want the expression to work wherever
- /// it can. Returns the variable defined in the tightest scope.
- ///
- /// @param[in] frame
- /// The stack frame to use as a basis for finding the variable.
- ///
- /// @param[in] name
- /// The name as a plain C string.
- ///
- /// @param[in] type
- /// The required type for the variable. This function may be called
- /// during parsing, in which case we don't know its type; hence the
- /// default.
- ///
- /// @param[in] object_pointer
- /// The type expected is an object type. This means we will ignore
- /// constness of the pointer target.
- ///
- /// @return
- /// The LLDB Variable found, or NULL if none was found.
- //------------------------------------------------------------------
- lldb::VariableSP
- FindVariableInScope (StackFrame &frame,
- const ConstString &name,
- TypeFromUser *type = NULL,
- bool object_pointer = false);
-
- //------------------------------------------------------------------
/// Given a target, find a data symbol that has the given name.
///
/// @param[in] target
@@ -1052,47 +691,6 @@ private:
TypeFromParser
CopyClassType(TypeFromUser &type,
unsigned int current_id);
-
- //------------------------------------------------------------------
- /// Actually do the task of materializing or dematerializing the struct.
- /// Since both tasks are very similar, although ClangExpressionDeclMap
- /// exposes two functions to the outside, both call DoMaterialize.
- ///
- /// @param[in] dematerialize
- /// True if the struct is to be dematerialized; false if it is to
- /// be materialized.
- ///
- /// @param[in] stack_frame_top, stack_frame_bottom
- /// If not LLDB_INVALID_ADDRESS, the bounds for the stack frame
- /// in which the expression ran. A result whose address falls
- /// inside this stack frame is dematerialized as a value
- /// requiring rematerialization.
- ///
- /// @param[out] result
- /// If the struct is being dematerialized, a pointer into which the
- /// location of the result persistent variable is placed. If not,
- /// NULL.
- ///
- /// @param[in] err
- /// An Error to populate with any messages related to
- /// (de)materializing the struct.
- ///
- /// @return
- /// True on success; false otherwise.
- //------------------------------------------------------------------
- bool
- DoMaterialize (bool dematerialize,
- IRMemoryMap &map,
- lldb::addr_t stack_frame_top,
- lldb::addr_t stack_frame_bottom,
- lldb::ClangExpressionVariableSP *result_sp_ptr,
- Error &err);
-
- //------------------------------------------------------------------
- /// Clean up the state required to dematerialize the variable.
- //------------------------------------------------------------------
- void
- DidDematerialize ();
};
} // namespace lldb_private
Modified: lldb/trunk/include/lldb/Expression/IRInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRInterpreter.h?rev=179842&r1=179841&r2=179842&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRInterpreter.h (original)
+++ lldb/trunk/include/lldb/Expression/IRInterpreter.h Fri Apr 19 03:14:32 2013
@@ -41,46 +41,6 @@ class IRMemoryMap;
class IRInterpreter
{
public:
- //------------------------------------------------------------------
- /// Run the IR interpreter on a single function
- ///
- /// @param[in] result
- /// This variable is populated with the return value of the
- /// function, if it could be interpreted completely.
- ///
- /// @param[in] result_name
- /// The name of the result in the IR. If this name got a
- /// value written to it as part of execution, then that value
- /// will be used to create the result variable.
- ///
- /// @param[in] result_type
- /// The type of the result.
- ///
- /// @param[in] llvm_function
- /// The function to interpret.
- ///
- /// @param[in] llvm_module
- /// The module containing the function.
- ///
- /// @param[in] error
- /// If the expression fails to interpret, a reason why.
- ///
- /// @return
- /// True on success; false otherwise
- //------------------------------------------------------------------
- static bool
- maybeRunOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
- lldb_private::IRMemoryMap &memory_map,
- lldb_private::Stream *error_stream,
- lldb::ClangExpressionVariableSP &result,
- const lldb_private::ConstString &result_name,
- lldb_private::TypeFromParser result_type,
- llvm::Function &llvm_function,
- llvm::Module &llvm_module,
- lldb_private::Error &err);
-
- // new api
-
static bool
CanInterpret (llvm::Module &module,
llvm::Function &function,
@@ -97,17 +57,6 @@ private:
static bool
supportsFunction (llvm::Function &llvm_function,
lldb_private::Error &err);
-
- static bool
- runOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
- lldb_private::IRMemoryMap &memory_map,
- lldb_private::Stream *error_stream,
- lldb::ClangExpressionVariableSP &result,
- const lldb_private::ConstString &result_name,
- lldb_private::TypeFromParser result_type,
- llvm::Function &llvm_function,
- llvm::Module &llvm_module,
- lldb_private::Error &err);
};
#endif
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=179842&r1=179841&r2=179842&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Apr 19 03:14:32 2013
@@ -70,7 +70,6 @@ ClangExpressionDeclMap::~ClangExpression
// that valuable lookup data (like namespaces) doesn't vanish, but
DidParse();
- DidDematerialize();
DisableStructVars();
}
@@ -182,271 +181,6 @@ ClangExpressionDeclMap::GetTargetInfo()
return ret;
}
-const ConstString &
-ClangExpressionDeclMap::GetPersistentResultName ()
-{
- assert (m_struct_vars.get());
- assert (m_parser_vars.get());
- if (!m_struct_vars->m_result_name)
- {
- Target *target = m_parser_vars->GetTarget();
- assert (target);
- m_struct_vars->m_result_name = target->GetPersistentVariables().GetNextPersistentVariableName();
- }
- return m_struct_vars->m_result_name;
-}
-
-lldb::ClangExpressionVariableSP
-ClangExpressionDeclMap::BuildIntegerVariable (const ConstString &name,
- lldb_private::TypeFromParser type,
- const llvm::APInt& value)
-{
- assert (m_parser_vars.get());
-
- ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
-
- Target *target = exe_ctx.GetTargetPtr();
-
- if (!target)
- return ClangExpressionVariableSP();
-
- ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
-
- TypeFromUser user_type(m_ast_importer->CopyType(context,
- type.GetASTContext(),
- type.GetOpaqueQualType()),
- context);
-
- if (!user_type.GetOpaqueQualType())
- {
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (log)
- log->Printf("ClangExpressionDeclMap::BuildIntegerVariable - Couldn't export the type for a constant integer result");
-
- return lldb::ClangExpressionVariableSP();
- }
-
- if (!m_parser_vars->m_persistent_vars->CreatePersistentVariable (exe_ctx.GetBestExecutionContextScope (),
- name,
- user_type,
- m_parser_vars->m_target_info.byte_order,
- m_parser_vars->m_target_info.address_byte_size))
- return lldb::ClangExpressionVariableSP();
-
- ClangExpressionVariableSP pvar_sp (m_parser_vars->m_persistent_vars->GetVariable(name));
-
- if (!pvar_sp)
- return lldb::ClangExpressionVariableSP();
-
- uint8_t *pvar_data = pvar_sp->GetValueBytes();
- if (pvar_data == NULL)
- return lldb::ClangExpressionVariableSP();
-
- uint64_t value64 = value.getLimitedValue();
-
- size_t num_val_bytes = sizeof(value64);
- size_t num_data_bytes = pvar_sp->GetByteSize();
-
- size_t num_bytes = num_val_bytes;
- if (num_bytes > num_data_bytes)
- num_bytes = num_data_bytes;
-
- for (size_t byte_idx = 0;
- byte_idx < num_bytes;
- ++byte_idx)
- {
- uint64_t shift = byte_idx * 8;
- uint64_t mask = 0xffll << shift;
- uint8_t cur_byte = (uint8_t)((value64 & mask) >> shift);
-
- switch (m_parser_vars->m_target_info.byte_order)
- {
- case eByteOrderBig:
- // High Low
- // Original: |AABBCCDDEEFFGGHH|
- // Target: |EEFFGGHH|
-
- pvar_data[num_data_bytes - (1 + byte_idx)] = cur_byte;
- break;
- case eByteOrderLittle:
- // Target: |HHGGFFEE|
- pvar_data[byte_idx] = cur_byte;
- break;
- default:
- return lldb::ClangExpressionVariableSP();
- }
- }
-
- pvar_sp->m_flags |= ClangExpressionVariable::EVIsFreezeDried;
- pvar_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
- pvar_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
-
- return pvar_sp;
-}
-
-lldb::ClangExpressionVariableSP
-ClangExpressionDeclMap::BuildCastVariable (const ConstString &name,
- VarDecl *decl,
- lldb_private::TypeFromParser type)
-{
- assert (m_parser_vars.get());
-
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
- Target *target = exe_ctx.GetTargetPtr();
- if (target == NULL)
- return lldb::ClangExpressionVariableSP();
-
- ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
-
- ClangExpressionVariableSP var_sp (m_found_entities.GetVariable(decl, GetParserID()));
-
- if (!var_sp)
- var_sp = m_parser_vars->m_persistent_vars->GetVariable(decl, GetParserID());
-
- if (!var_sp)
- return ClangExpressionVariableSP();
-
- TypeFromUser user_type(m_ast_importer->CopyType(context,
- type.GetASTContext(),
- type.GetOpaqueQualType()),
- context);
-
- if (!user_type.GetOpaqueQualType())
- {
- if (log)
- log->Printf("ClangExpressionDeclMap::BuildCastVariable - Couldn't export the type for a constant cast result");
-
- return lldb::ClangExpressionVariableSP();
- }
-
- TypeFromUser var_type = var_sp->GetTypeFromUser();
-
- StackFrame *frame = exe_ctx.GetFramePtr();
- if (frame == NULL)
- return lldb::ClangExpressionVariableSP();
-
- VariableSP var = FindVariableInScope (*frame, var_sp->GetName(), &var_type);
-
- if (!var)
- return lldb::ClangExpressionVariableSP(); // but we should handle this; it may be a persistent variable
-
- ValueObjectSP var_valobj = frame->GetValueObjectForFrameVariable(var, lldb::eNoDynamicValues);
-
- if (!var_valobj)
- return lldb::ClangExpressionVariableSP();
-
- ValueObjectSP var_casted_valobj = var_valobj->CastPointerType(name.GetCString(), user_type);
-
- if (!var_casted_valobj)
- return lldb::ClangExpressionVariableSP();
-
- if (log)
- {
- StreamString my_stream_string;
-
- ClangASTType::DumpTypeDescription (var_type.GetASTContext(),
- var_type.GetOpaqueQualType(),
- &my_stream_string);
-
-
- log->Printf("Building cast variable to type: %s", my_stream_string.GetString().c_str());
- }
-
- ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->CreatePersistentVariable (var_casted_valobj);
-
- if (!pvar_sp)
- return lldb::ClangExpressionVariableSP();
-
- if (pvar_sp != m_parser_vars->m_persistent_vars->GetVariable(name))
- return lldb::ClangExpressionVariableSP();
-
- pvar_sp->m_flags |= ClangExpressionVariable::EVIsFreezeDried;
- pvar_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
- pvar_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
-
- return pvar_sp;
-}
-
-bool
-ClangExpressionDeclMap::ResultIsReference (const ConstString &name)
-{
- ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name);
-
- return (pvar_sp->m_flags & ClangExpressionVariable::EVIsProgramReference);
-}
-
-bool
-ClangExpressionDeclMap::CompleteResultVariable (lldb::ClangExpressionVariableSP &valobj,
- IRMemoryMap &map,
- lldb_private::Value &value,
- const ConstString &name,
- lldb_private::TypeFromParser type,
- bool transient,
- bool maybe_make_load)
-{
- assert (m_parser_vars.get());
-
- ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name);
-
- if (!pvar_sp)
- return false;
-
- if (maybe_make_load &&
- value.GetValueType() == Value::eValueTypeFileAddress &&
- m_parser_vars->m_exe_ctx.GetProcessPtr())
- {
- value.SetValueType(Value::eValueTypeLoadAddress);
- }
-
- if (pvar_sp->m_flags & ClangExpressionVariable::EVIsProgramReference &&
- !pvar_sp->m_live_sp &&
- !transient)
- {
- // The reference comes from the program. We need to set up a live SP for it.
-
- unsigned long long address = value.GetScalar().ULongLong();
- AddressType address_type = value.GetValueAddressType();
-
- pvar_sp->m_live_sp = ValueObjectConstResult::Create(m_parser_vars->m_exe_ctx.GetBestExecutionContextScope(),
- pvar_sp->GetTypeFromUser().GetASTContext(),
- pvar_sp->GetTypeFromUser().GetOpaqueQualType(),
- pvar_sp->GetName(),
- address,
- address_type,
- pvar_sp->GetByteSize());
- }
-
- if (pvar_sp->m_flags & ClangExpressionVariable::EVNeedsFreezeDry)
- {
- pvar_sp->ValueUpdated();
-
- const size_t pvar_byte_size = pvar_sp->GetByteSize();
- uint8_t *pvar_data = pvar_sp->GetValueBytes();
-
- if (!ReadTarget(map, pvar_data, value, pvar_byte_size))
- return false;
-
- pvar_sp->m_flags &= ~(ClangExpressionVariable::EVNeedsFreezeDry);
- }
-
- valobj = pvar_sp;
-
- return true;
-}
-
-void
-ClangExpressionDeclMap::RemoveResultVariable
-(
- const ConstString &name
-)
-{
- ClangExpressionVariableSP pvar_sp = m_parser_vars->m_persistent_vars->GetVariable(name);
- m_parser_vars->m_persistent_vars->RemovePersistentVariable(pvar_sp);
-}
-
bool
ClangExpressionDeclMap::AddPersistentVariable
(
@@ -956,866 +690,6 @@ ClangExpressionDeclMap::GetSymbolAddress
return GetSymbolAddress(m_parser_vars->m_exe_ctx.GetTargetRef(), m_parser_vars->m_exe_ctx.GetProcessPtr(), name, symbol_type);
}
-// Interface for IRInterpreter
-
-Value
-ClangExpressionDeclMap::WrapBareAddress (lldb::addr_t addr)
-{
- Value ret;
-
- ret.SetContext(Value::eContextTypeInvalid, NULL);
-
- if (m_parser_vars->m_exe_ctx.GetProcessPtr())
- ret.SetValueType(Value::eValueTypeLoadAddress);
- else
- ret.SetValueType(Value::eValueTypeFileAddress);
-
- ret.GetScalar() = (unsigned long long)addr;
-
- return ret;
-}
-
-bool
-ClangExpressionDeclMap::WriteTarget (lldb_private::IRMemoryMap &map,
- lldb_private::Value &value,
- const uint8_t *data,
- size_t length)
-{
- assert (m_parser_vars.get());
-
- ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
-
- Process *process = exe_ctx.GetProcessPtr();
- if (value.GetContextType() == Value::eContextTypeRegisterInfo)
- {
- if (!process)
- return false;
-
- RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
- RegisterInfo *reg_info = value.GetRegisterInfo();
-
- if (!reg_ctx)
- return false;
-
- lldb_private::RegisterValue reg_value;
- Error err;
-
- if (!reg_value.SetFromMemoryData (reg_info, data, length, process->GetByteOrder(), err))
- return false;
-
- return reg_ctx->WriteRegister(reg_info, reg_value);
- }
- else
- {
- switch (value.GetValueType())
- {
- default:
- return false;
- case Value::eValueTypeFileAddress:
- {
- if (!process)
- return false;
-
- Target *target = exe_ctx.GetTargetPtr();
- Address file_addr;
-
- if (!target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
- return false;
-
- lldb::addr_t load_addr = file_addr.GetLoadAddress(target);
-
- Error err;
- map.WriteMemory(load_addr, data, length, err);
-
- return err.Success();
- }
- case Value::eValueTypeLoadAddress:
- {
- if (!process)
- return false;
-
- Error err;
- map.WriteMemory((lldb::addr_t)value.GetScalar().ULongLong(), data, length, err);
-
- return err.Success();
- }
- case Value::eValueTypeHostAddress:
- {
- if (value.GetScalar().ULongLong() == 0 || data == NULL)
- return false;
- memcpy ((void *)value.GetScalar().ULongLong(), data, length);
- return true;
- }
- case Value::eValueTypeScalar:
- return false;
- }
- }
-}
-
-bool
-ClangExpressionDeclMap::ReadTarget (IRMemoryMap &map,
- uint8_t *data,
- lldb_private::Value &value,
- size_t length)
-{
- assert (m_parser_vars.get());
-
- ExecutionContext &exe_ctx = m_parser_vars->m_exe_ctx;
-
- Process *process = exe_ctx.GetProcessPtr();
-
- if (value.GetContextType() == Value::eContextTypeRegisterInfo)
- {
- if (!process)
- return false;
-
- RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
- RegisterInfo *reg_info = value.GetRegisterInfo();
-
- if (!reg_ctx)
- return false;
-
- lldb_private::RegisterValue reg_value;
- Error err;
-
- if (!reg_ctx->ReadRegister(reg_info, reg_value))
- return false;
-
- return reg_value.GetAsMemoryData(reg_info, data, length, process->GetByteOrder(), err);
- }
- else
- {
- switch (value.GetValueType())
- {
- default:
- return false;
- case Value::eValueTypeFileAddress:
- {
- Target *target = exe_ctx.GetTargetPtr();
- if (target == NULL)
- return false;
-
- Address file_addr;
-
- if (!target->GetImages().ResolveFileAddress((lldb::addr_t)value.GetScalar().ULongLong(), file_addr))
- return false;
-
- Error err;
- target->ReadMemory(file_addr, false, data, length, err);
-
- return err.Success();
- }
- case Value::eValueTypeLoadAddress:
- {
- Error err;
- map.ReadMemory(data, (lldb::addr_t)value.GetScalar().ULongLong(), length, err);
-
- return err.Success();
- }
- case Value::eValueTypeHostAddress:
- {
- void *host_addr = (void*)value.GetScalar().ULongLong();
-
- if (!host_addr)
- return false;
-
- memcpy (data, host_addr, length);
- return true;
- }
- case Value::eValueTypeScalar:
- return false;
- }
- }
-}
-
-lldb_private::Value
-ClangExpressionDeclMap::LookupDecl (clang::NamedDecl *decl, ClangExpressionVariable::FlagType &flags)
-{
- assert (m_parser_vars.get());
-
- ClangExpressionVariableSP expr_var_sp (m_found_entities.GetVariable(decl, GetParserID()));
- ClangExpressionVariableSP persistent_var_sp (m_parser_vars->m_persistent_vars->GetVariable(decl, GetParserID()));
-
- if (isa<FunctionDecl>(decl))
- {
- ClangExpressionVariableSP entity_sp(m_found_entities.GetVariable(decl, GetParserID()));
-
- if (!entity_sp)
- return Value();
-
- // We know m_parser_vars is valid since we searched for the variable by
- // its NamedDecl
-
- ClangExpressionVariable::ParserVars *parser_vars = entity_sp->GetParserVars(GetParserID());
-
- return *parser_vars->m_lldb_value;
- }
-
- if (expr_var_sp)
- {
- flags = expr_var_sp->m_flags;
-
- ClangExpressionVariable::ParserVars *parser_vars = expr_var_sp->GetParserVars(GetParserID());
-
- if (!parser_vars)
- return Value();
-
- bool is_reference = expr_var_sp->m_flags & ClangExpressionVariable::EVTypeIsReference;
-
- if (parser_vars->m_lldb_var)
- {
- std::unique_ptr<Value> value(GetVariableValue(parser_vars->m_lldb_var, NULL));
-
- if (is_reference && value.get() && value->GetValueType() == Value::eValueTypeLoadAddress)
- {
- Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
-
- if (!process)
- return Value();
-
- lldb::addr_t value_addr = value->GetScalar().ULongLong();
- Error read_error;
- addr_t ref_value = process->ReadPointerFromMemory (value_addr, read_error);
-
- if (!read_error.Success())
- return Value();
-
- value->GetScalar() = (unsigned long long)ref_value;
- }
-
- if (value.get())
- return *value;
- else
- return Value();
- }
- else if (parser_vars->m_lldb_sym)
- {
- const Address sym_address = parser_vars->m_lldb_sym->GetAddress();
-
- if (!sym_address.IsValid())
- return Value();
-
- Value ret;
-
- ProcessSP process_sp (m_parser_vars->m_exe_ctx.GetProcessSP());
-
- if (process_sp)
- {
- uint64_t symbol_load_addr = sym_address.GetLoadAddress(&process_sp->GetTarget());
-
- ret.GetScalar() = symbol_load_addr;
- ret.SetValueType(Value::eValueTypeLoadAddress);
- }
- else
- {
- uint64_t symbol_file_addr = sym_address.GetFileAddress();
-
- ret.GetScalar() = symbol_file_addr;
- ret.SetValueType(Value::eValueTypeFileAddress);
- }
-
- return ret;
- }
- else if (RegisterInfo *reg_info = expr_var_sp->GetRegisterInfo())
- {
- StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-
- if (!frame)
- return Value();
-
- RegisterContextSP reg_context_sp(frame->GetRegisterContextSP());
-
- RegisterValue reg_value;
-
- if (!reg_context_sp->ReadRegister(reg_info, reg_value))
- return Value();
-
- Value ret;
-
- ret.SetContext(Value::eContextTypeRegisterInfo, reg_info);
- if (reg_info->encoding == eEncodingVector)
- {
- if (ret.SetVectorBytes((uint8_t *)reg_value.GetBytes(), reg_value.GetByteSize(), reg_value.GetByteOrder()))
- ret.SetScalarFromVector();
- }
- else if (!reg_value.GetScalarValue(ret.GetScalar()))
- return Value();
-
- return ret;
- }
- else
- {
- return Value();
- }
- }
- else if (persistent_var_sp)
- {
- flags = persistent_var_sp->m_flags;
-
- if ((persistent_var_sp->m_flags & ClangExpressionVariable::EVIsProgramReference ||
- persistent_var_sp->m_flags & ClangExpressionVariable::EVIsLLDBAllocated) &&
- persistent_var_sp->m_live_sp &&
- ((persistent_var_sp->m_live_sp->GetValue().GetValueType() == Value::eValueTypeLoadAddress &&
- m_parser_vars->m_exe_ctx.GetProcessSP() &&
- m_parser_vars->m_exe_ctx.GetProcessSP()->IsAlive()) ||
- (persistent_var_sp->m_live_sp->GetValue().GetValueType() == Value::eValueTypeFileAddress)))
- {
- return persistent_var_sp->m_live_sp->GetValue();
- }
- else
- {
- lldb_private::Value ret;
- ret.SetValueType(Value::eValueTypeHostAddress);
- ret.SetContext(Value::eContextTypeInvalid, NULL);
- ret.GetScalar() = (lldb::addr_t)persistent_var_sp->GetValueBytes();
- return ret;
- }
- }
- else
- {
- return Value();
- }
-}
-
-Value
-ClangExpressionDeclMap::GetSpecialValue (const ConstString &name)
-{
- assert(m_parser_vars.get());
-
- StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-
- if (!frame)
- return Value();
-
- VariableList *vars = frame->GetVariableList(false);
-
- if (!vars)
- return Value();
-
- lldb::VariableSP var = vars->FindVariable(name);
-
- if (!var ||
- !var->IsInScope(frame) ||
- !var->LocationIsValidForFrame (frame))
- return Value();
-
- std::unique_ptr<Value> value(GetVariableValue(var, NULL));
-
- if (value.get() && value->GetValueType() == Value::eValueTypeLoadAddress)
- {
- Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
-
- if (!process)
- return Value();
-
- lldb::addr_t value_addr = value->GetScalar().ULongLong();
- Error read_error;
- addr_t ptr_value = process->ReadPointerFromMemory (value_addr, read_error);
-
- if (!read_error.Success())
- return Value();
-
- value->GetScalar() = (unsigned long long)ptr_value;
- }
-
- if (value.get())
- return *value;
- else
- return Value();
-}
-
-// Interface for CommandObjectExpression
-
-bool
-ClangExpressionDeclMap::Materialize
-(
- IRMemoryMap &map,
- lldb::addr_t &struct_address,
- Error &err
-)
-{
- if (!m_parser_vars.get())
- return false;
-
- EnableMaterialVars();
-
- m_material_vars->m_process = m_parser_vars->m_exe_ctx.GetProcessPtr();
-
- bool result = DoMaterialize(false /* dematerialize */,
- map,
- LLDB_INVALID_ADDRESS /* top of stack frame */,
- LLDB_INVALID_ADDRESS /* bottom of stack frame */,
- NULL, /* result SP */
- err);
-
- if (result)
- struct_address = m_material_vars->m_materialized_location;
-
- return result;
-}
-
-bool
-ClangExpressionDeclMap::GetObjectPointer
-(
- lldb::addr_t &object_ptr,
- ConstString &object_name,
- Error &err,
- bool suppress_type_check
-)
-{
- assert (m_struct_vars.get());
-
- Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
- Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
- StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
-
- if (frame == NULL || process == NULL || target == NULL)
- {
- err.SetErrorStringWithFormat("Couldn't load '%s' because the context is incomplete", object_name.AsCString());
- return false;
- }
-
- if (!m_struct_vars->m_object_pointer_type.GetOpaqueQualType())
- {
- err.SetErrorStringWithFormat("Couldn't load '%s' because its type is unknown", object_name.AsCString());
- return false;
- }
-
- const bool object_pointer = true;
-
- VariableSP object_ptr_var = FindVariableInScope (*frame,
- object_name,
- (suppress_type_check ? NULL : &m_struct_vars->m_object_pointer_type),
- object_pointer);
-
- if (!object_ptr_var)
- {
- err.SetErrorStringWithFormat("Couldn't find '%s' with appropriate type in scope", object_name.AsCString());
- return false;
- }
-
- std::unique_ptr<lldb_private::Value> location_value(GetVariableValue(object_ptr_var,
- NULL));
-
- if (!location_value.get())
- {
- err.SetErrorStringWithFormat("Couldn't get the location for '%s'", object_name.GetCString());
- return false;
- }
-
- switch (location_value->GetValueType())
- {
- default:
- err.SetErrorStringWithFormat("'%s' is not in memory; LLDB must be extended to handle registers", object_name.GetCString());
- return false;
- case Value::eValueTypeLoadAddress:
- {
- lldb::addr_t value_addr = location_value->GetScalar().ULongLong();
- uint32_t address_byte_size = target->GetArchitecture().GetAddressByteSize();
-
- if (ClangASTType::GetClangTypeBitWidth(m_struct_vars->m_object_pointer_type.GetASTContext(),
- m_struct_vars->m_object_pointer_type.GetOpaqueQualType()) != address_byte_size * 8)
- {
- err.SetErrorStringWithFormat("'%s' is not of an expected pointer size", object_name.GetCString());
- return false;
- }
-
- Error read_error;
- object_ptr = process->ReadPointerFromMemory (value_addr, read_error);
- if (read_error.Fail() || object_ptr == LLDB_INVALID_ADDRESS)
- {
- err.SetErrorStringWithFormat("Coldn't read '%s' from the target: %s", object_name.GetCString(), read_error.AsCString());
- return false;
- }
- return true;
- }
- case Value::eValueTypeScalar:
- {
- if (location_value->GetContextType() != Value::eContextTypeRegisterInfo)
- {
- StreamString ss;
- location_value->Dump(&ss);
-
- err.SetErrorStringWithFormat("%s is a scalar of unhandled type: %s", object_name.GetCString(), ss.GetString().c_str());
- return false;
- }
-
- RegisterInfo *reg_info = location_value->GetRegisterInfo();
-
- if (!reg_info)
- {
- err.SetErrorStringWithFormat("Couldn't get the register information for %s", object_name.GetCString());
- return false;
- }
-
- RegisterContext *reg_ctx = m_parser_vars->m_exe_ctx.GetRegisterContext();
-
- if (!reg_ctx)
- {
- err.SetErrorStringWithFormat("Couldn't read register context to read %s from %s", object_name.GetCString(), reg_info->name);
- return false;
- }
-
- uint32_t register_number = reg_info->kinds[lldb::eRegisterKindLLDB];
-
- object_ptr = reg_ctx->ReadRegisterAsUnsigned(register_number, 0x0);
-
- return true;
- }
- }
-}
-
-bool
-ClangExpressionDeclMap::Dematerialize
-(
- ClangExpressionVariableSP &result_sp,
- IRMemoryMap &map,
- lldb::addr_t stack_frame_top,
- lldb::addr_t stack_frame_bottom,
- Error &err
-)
-{
- return DoMaterialize(true, map, stack_frame_top, stack_frame_bottom, &result_sp, err);
-
- DidDematerialize();
-}
-
-void
-ClangExpressionDeclMap::DidDematerialize()
-{
- if (m_material_vars.get())
- {
- if (m_material_vars->m_materialized_location)
- {
- //#define SINGLE_STEP_EXPRESSIONS
-
-#ifndef SINGLE_STEP_EXPRESSIONS
- m_material_vars->m_process->DeallocateMemory(m_material_vars->m_materialized_location);
-#endif
- m_material_vars->m_materialized_location = 0;
- }
-
- DisableMaterialVars();
- }
-}
-
-bool
-ClangExpressionDeclMap::DumpMaterializedStruct
-(
- Stream &s,
- Error &err
-)
-{
- assert (m_struct_vars.get());
- assert (m_material_vars.get());
-
- if (!m_struct_vars->m_struct_laid_out)
- {
- err.SetErrorString("Structure hasn't been laid out yet");
- return false;
- }
- Process *process = m_parser_vars->m_exe_ctx.GetProcessPtr();
-
- if (!process)
- {
- err.SetErrorString("Couldn't find the process");
- return false;
- }
-
- Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
- if (!target)
- {
- err.SetErrorString("Couldn't find the target");
- return false;
- }
-
- if (!m_material_vars->m_materialized_location)
- {
- err.SetErrorString("No materialized location");
- return false;
- }
-
- lldb::DataBufferSP data_sp(new DataBufferHeap(m_struct_vars->m_struct_size, 0));
-
- Error error;
- if (process->ReadMemory (m_material_vars->m_materialized_location,
- data_sp->GetBytes(),
- data_sp->GetByteSize(), error) != data_sp->GetByteSize())
- {
- err.SetErrorStringWithFormat ("Couldn't read struct from the target: %s", error.AsCString());
- return false;
- }
-
- DataExtractor extractor(data_sp, process->GetByteOrder(), target->GetArchitecture().GetAddressByteSize());
-
- for (size_t member_idx = 0, num_members = m_struct_members.GetSize();
- member_idx < num_members;
- ++member_idx)
- {
- ClangExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(member_idx));
-
- if (!member_sp)
- return false;
-
- s.Printf("[%s]\n", member_sp->GetName().GetCString());
-
- ClangExpressionVariable::JITVars *jit_vars = member_sp->GetJITVars(GetParserID());
-
- if (!jit_vars)
- return false;
-
- extractor.Dump (&s, // stream
- jit_vars->m_offset, // offset
- lldb::eFormatBytesWithASCII, // format
- 1, // byte size of individual entries
- jit_vars->m_size, // number of entries
- 16, // entries per line
- m_material_vars->m_materialized_location + jit_vars->m_offset, // address to print
- 0, // bit size (bitfields only; 0 means ignore)
- 0); // bit alignment (bitfields only; 0 means ignore)
-
- s.PutChar('\n');
- }
-
- return true;
-}
-
-bool
-ClangExpressionDeclMap::DoMaterialize
-(
- bool dematerialize,
- IRMemoryMap &map,
- lldb::addr_t stack_frame_top,
- lldb::addr_t stack_frame_bottom,
- lldb::ClangExpressionVariableSP *result_sp_ptr,
- Error &err
-)
-{
- if (result_sp_ptr)
- result_sp_ptr->reset();
-
- assert (m_struct_vars.get());
-
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- if (!m_struct_vars->m_struct_laid_out)
- {
- err.SetErrorString("Structure hasn't been laid out yet");
- return false;
- }
-
- StackFrame *frame = m_parser_vars->m_exe_ctx.GetFramePtr();
- if (!frame)
- {
- err.SetErrorString("Received null execution frame");
- return false;
- }
- Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
-
- ClangPersistentVariables &persistent_vars = target->GetPersistentVariables();
-
- if (!m_struct_vars->m_struct_size)
- {
- if (log)
- log->PutCString("Not bothering to allocate a struct because no arguments are needed");
-
- m_material_vars->m_allocated_area = 0UL;
-
- return true;
- }
-
- if (!m_parser_vars->m_materializer)
- {
- err.SetErrorString("No materializer");
-
- return false;
- }
-
- lldb::StackFrameSP frame_sp = frame->shared_from_this();
- ClangExpressionVariableSP result_sp;
-
- if (dematerialize)
- {
- Error dematerialize_error;
-
- bool ret = true;
-
- ClangExpressionVariableSP result;
-
- m_material_vars->m_dematerializer_sp->Dematerialize(dematerialize_error, result, stack_frame_top, stack_frame_bottom);
- m_material_vars->m_dematerializer_sp.reset();
-
- if (!dematerialize_error.Success())
- {
- err.SetErrorStringWithFormat("Couldn't dematerialize: %s", dematerialize_error.AsCString());
- ret = false;
- }
- else
- {
- Error free_error;
- map.Free(m_material_vars->m_materialized_location, free_error);
- if (!free_error.Success())
- {
- err.SetErrorStringWithFormat("Couldn't free struct from materialization: %s", free_error.AsCString());
- ret = false;
- }
- }
-
- if (ret)
- {
- for (uint64_t member_index = 0, num_members = m_struct_members.GetSize();
- member_index < num_members;
- ++member_index)
- {
- ClangExpressionVariableSP member_sp(m_struct_members.GetVariableAtIndex(member_index));
-
- if (!m_found_entities.ContainsVariable (member_sp))
- {
- // No need to look for presistent variables if the name doesn't start
- // with with a '$' character...
- if (member_sp->GetName().AsCString ("!")[0] == '$' && persistent_vars.ContainsVariable(member_sp))
- {
- if (member_sp->GetName() == m_struct_vars->m_result_name)
- {
- if (log)
- log->PutCString("Found result member in the struct");
-
- if (result_sp_ptr)
- *result_sp_ptr = member_sp;
-
- break;
- }
- }
- }
- }
- }
-
- return ret;
- }
- else
- {
- Error malloc_error;
-
- m_material_vars->m_allocated_area = LLDB_INVALID_ADDRESS;
- m_material_vars->m_materialized_location = map.Malloc(m_parser_vars->m_materializer->GetStructByteSize(),
- m_parser_vars->m_materializer->GetStructAlignment(),
- lldb::ePermissionsReadable | lldb::ePermissionsWritable,
- IRMemoryMap::eAllocationPolicyMirror,
- malloc_error);
-
- if (!malloc_error.Success())
- {
- err.SetErrorStringWithFormat("Couldn't malloc struct for materialization: %s", malloc_error.AsCString());
-
- return false;
- }
-
- Error materialize_error;
-
- m_material_vars->m_dematerializer_sp = m_parser_vars->m_materializer->Materialize(frame_sp, map, m_material_vars->m_materialized_location, materialize_error);
-
- if (!materialize_error.Success())
- {
- err.SetErrorStringWithFormat("Couldn't materialize: %s", materialize_error.AsCString());
-
- return false;
- }
-
- return true;
- }
-}
-
-lldb::VariableSP
-ClangExpressionDeclMap::FindVariableInScope
-(
- StackFrame &frame,
- const ConstString &name,
- TypeFromUser *type,
- bool object_pointer
-)
-{
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- ValueObjectSP valobj;
- VariableSP var_sp;
- Error err;
-
- valobj = frame.GetValueForVariableExpressionPath(name.GetCString(),
- eNoDynamicValues,
- StackFrame::eExpressionPathOptionCheckPtrVsMember ||
- StackFrame::eExpressionPathOptionsAllowDirectIVarAccess ||
- StackFrame::eExpressionPathOptionsNoFragileObjcIvar ||
- StackFrame::eExpressionPathOptionsNoSyntheticChildren ||
- StackFrame::eExpressionPathOptionsNoSyntheticArrayRange,
- var_sp,
- err);
-
- if (!err.Success() ||
- !var_sp ||
- !var_sp->IsInScope(&frame) ||
- !var_sp->LocationIsValidForFrame (&frame))
- return lldb::VariableSP();
-
- if (var_sp)
- {
- if (!type)
- return var_sp;
-
- TypeFromUser candidate_type(var_sp->GetType()->GetClangFullType(),
- var_sp->GetType()->GetClangAST());
-
- if (candidate_type.GetASTContext() != type->GetASTContext())
- {
- if (log)
- log->PutCString("Skipping a candidate variable because of different AST contexts");
- return lldb::VariableSP();
- }
-
- if (object_pointer)
- {
- clang::QualType desired_qual_type = clang::QualType::getFromOpaquePtr(type->GetOpaqueQualType());
- clang::QualType candidate_qual_type = clang::QualType::getFromOpaquePtr(candidate_type.GetOpaqueQualType());
-
- const clang::ObjCObjectPointerType *desired_objc_ptr_type = desired_qual_type->getAs<clang::ObjCObjectPointerType>();
- const clang::ObjCObjectPointerType *candidate_objc_ptr_type = desired_qual_type->getAs<clang::ObjCObjectPointerType>();
-
- if (desired_objc_ptr_type && candidate_objc_ptr_type) {
- clang::QualType desired_target_type = desired_objc_ptr_type->getPointeeType().getUnqualifiedType();
- clang::QualType candidate_target_type = candidate_objc_ptr_type->getPointeeType().getUnqualifiedType();
-
- if (ClangASTContext::AreTypesSame(type->GetASTContext(),
- desired_target_type.getAsOpaquePtr(),
- candidate_target_type.getAsOpaquePtr()))
- return var_sp;
- }
-
- const clang::PointerType *desired_ptr_type = desired_qual_type->getAs<clang::PointerType>();
- const clang::PointerType *candidate_ptr_type = candidate_qual_type->getAs<clang::PointerType>();
-
- if (desired_ptr_type && candidate_ptr_type) {
- clang::QualType desired_target_type = desired_ptr_type->getPointeeType().getUnqualifiedType();
- clang::QualType candidate_target_type = candidate_ptr_type->getPointeeType().getUnqualifiedType();
-
- if (ClangASTContext::AreTypesSame(type->GetASTContext(),
- desired_target_type.getAsOpaquePtr(),
- candidate_target_type.getAsOpaquePtr()))
- return var_sp;
- }
-
- return lldb::VariableSP();
- }
- else
- {
- if (ClangASTContext::AreTypesSame(type->GetASTContext(),
- type->GetOpaqueQualType(),
- var_sp->GetType()->GetClangFullType()))
- return var_sp;
- }
- }
-
- return lldb::VariableSP();
-}
-
const Symbol *
ClangExpressionDeclMap::FindGlobalDataSymbol (Target &target,
const ConstString &name)
Modified: lldb/trunk/source/Expression/IRInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRInterpreter.cpp?rev=179842&r1=179841&r2=179842&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRInterpreter.cpp (original)
+++ lldb/trunk/source/Expression/IRInterpreter.cpp Fri Apr 19 03:14:32 2013
@@ -83,7 +83,6 @@ public:
ValueMap m_values;
PlacedValueVector m_placed_values;
DataLayout &m_target_data;
- lldb_private::ClangExpressionDeclMap *m_decl_map;
lldb_private::IRMemoryMap &m_memory_map;
const BasicBlock *m_bb;
BasicBlock::const_iterator m_ii;
@@ -97,10 +96,8 @@ public:
size_t m_addr_byte_size;
InterpreterStackFrame (DataLayout &target_data,
- lldb_private::ClangExpressionDeclMap *decl_map,
lldb_private::IRMemoryMap &memory_map) :
m_target_data (target_data),
- m_decl_map (decl_map),
m_memory_map (memory_map)
{
m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig);
@@ -396,68 +393,6 @@ public:
return Malloc(m_target_data.getTypeAllocSize(type), m_target_data.getPrefTypeAlignment(type));
}
- lldb::addr_t PlaceLLDBValue (const llvm::Value *value, lldb_private::Value lldb_value)
- {
- if (!m_decl_map)
- return false;
-
- lldb_private::Error alloc_error;
- lldb_private::RegisterInfo *reg_info = lldb_value.GetRegisterInfo();
-
- lldb::addr_t ret;
-
- size_t value_size = m_target_data.getTypeStoreSize(value->getType());
- size_t value_align = m_target_data.getPrefTypeAlignment(value->getType());
-
- if (reg_info && (reg_info->encoding == lldb::eEncodingVector))
- value_size = reg_info->byte_size;
-
- if (!reg_info && (lldb_value.GetValueType() == lldb_private::Value::eValueTypeLoadAddress))
- return lldb_value.GetScalar().ULongLong();
-
- ret = Malloc(value_size, value_align);
-
- if (ret == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- lldb_private::DataBufferHeap buf(value_size, 0);
-
- m_decl_map->ReadTarget(m_memory_map, buf.GetBytes(), lldb_value, value_size);
-
- lldb_private::Error write_error;
-
- m_memory_map.WriteMemory(ret, buf.GetBytes(), buf.GetByteSize(), write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(ret, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- m_placed_values.push_back(PlacedValue(lldb_value, ret, value_size));
-
- return ret;
- }
-
- void RestoreLLDBValues ()
- {
- if (!m_decl_map)
- return;
-
- for (PlacedValue &placed_value : m_placed_values)
- {
- lldb_private::DataBufferHeap buf(placed_value.size, 0);
-
- lldb_private::Error read_error;
-
- m_memory_map.ReadMemory(buf.GetBytes(), placed_value.process_address, buf.GetByteSize(), read_error);
-
- if (read_error.Success())
- m_decl_map->WriteTarget(m_memory_map, placed_value.lldb_value, buf.GetBytes(), buf.GetByteSize());
- }
- }
-
std::string PrintData (lldb::addr_t addr, llvm::Type *type)
{
size_t length = m_target_data.getTypeStoreSize(type);
@@ -507,395 +442,9 @@ public:
m_values[value] = data_address;
return data_address;
-
- const GlobalValue *global_value = dyn_cast<GlobalValue>(value);
-
- // If the variable is indirected through the argument
- // array then we need to build an extra level of indirection
- // for it. This is the default; only magic arguments like
- // "this", "self", and "_cmd" are direct.
- bool variable_is_this = false;
-
- // If the variable is a function pointer, we do not need to
- // build an extra layer of indirection for it because it is
- // accessed directly.
- bool variable_is_function_address = false;
-
- // Attempt to resolve the value using the program's data.
- // If it is, the values to be created are:
- //
- // data_region - a region of memory in which the variable's data resides.
- // ref_region - a region of memory in which its address (i.e., &var) resides.
- // In the JIT case, this region would be a member of the struct passed in.
- // pointer_region - a region of memory in which the address of the pointer
- // resides. This is an IR-level variable.
- do
- {
- lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- lldb_private::Value resolved_value;
- lldb_private::ClangExpressionVariable::FlagType flags = 0;
-
- if (global_value)
- {
- clang::NamedDecl *decl = IRForTarget::DeclForGlobal(global_value, &module);
-
- if (!decl)
- break;
-
- if (isa<clang::FunctionDecl>(decl))
- variable_is_function_address = true;
-
- resolved_value = m_decl_map->LookupDecl(decl, flags);
- }
- else
- {
- // Special-case "this", "self", and "_cmd"
-
- std::string name_str = value->getName().str();
-
- if (name_str == "this" ||
- name_str == "self" ||
- name_str == "_cmd")
- {
- resolved_value = m_decl_map->GetSpecialValue(lldb_private::ConstString(name_str.c_str()));
- variable_is_this = true;
- }
- }
-
- if (resolved_value.GetScalar().GetType() != lldb_private::Scalar::e_void)
- {
- if (resolved_value.GetContextType() == lldb_private::Value::eContextTypeRegisterInfo)
- {
- if (variable_is_this)
- {
- lldb_private::Error alloc_error;
- lldb::addr_t ref_addr = Malloc(value->getType());
-
- if (ref_addr == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- lldb_private::Error write_error;
- m_memory_map.WritePointerToMemory(ref_addr, resolved_value.GetScalar().ULongLong(), write_error);
-
- if (!write_error.Success())
- return LLDB_INVALID_ADDRESS;
-
- if (log)
- {
- log->Printf("Made an allocation for \"this\" register variable %s", PrintValue(value).c_str());
- log->Printf(" Data region : %llx", (unsigned long long)resolved_value.GetScalar().ULongLong());
- log->Printf(" Ref region : %llx", (unsigned long long)ref_addr);
- }
-
- m_values[value] = ref_addr;
- return ref_addr;
- }
- else if (flags & lldb_private::ClangExpressionVariable::EVBareRegister)
- {
- lldb::addr_t data_address = PlaceLLDBValue(value, resolved_value);
-
- if (!data_address)
- return LLDB_INVALID_ADDRESS;
-
- lldb::addr_t ref_address = MallocPointer();
-
- if (ref_address == LLDB_INVALID_ADDRESS)
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- lldb_private::Error write_error;
-
- m_memory_map.WritePointerToMemory(ref_address, data_address, write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- if (log)
- {
- log->Printf("Made an allocation for bare register variable %s", PrintValue(value).c_str());
- log->Printf(" Data contents : %s", PrintData(data_address, value->getType()).c_str());
- log->Printf(" Data region : 0x%llx", (unsigned long long)data_address);
- log->Printf(" Ref region : 0x%llx", (unsigned long long)ref_address);
- }
-
- m_values[value] = ref_address;
- return ref_address;
- }
- else
- {
- lldb::addr_t data_address = PlaceLLDBValue(value, resolved_value);
-
- if (data_address == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- lldb::addr_t ref_address = MallocPointer();
-
- if (ref_address == LLDB_INVALID_ADDRESS)
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- lldb::addr_t pointer_address = MallocPointer();
-
- if (pointer_address == LLDB_INVALID_ADDRESS)
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- lldb_private::Error write_error;
-
- m_memory_map.WritePointerToMemory(ref_address, data_address, write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- m_memory_map.Free(pointer_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- write_error.Clear();
-
- m_memory_map.WritePointerToMemory(pointer_address, ref_address, write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- m_memory_map.Free(pointer_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- if (log)
- {
- log->Printf("Made an allocation for ordinary register variable %s", PrintValue(value).c_str());
- log->Printf(" Data contents : %s", PrintData(data_address, value->getType()).c_str());
- log->Printf(" Data region : 0x%llx", (unsigned long long)data_address);
- log->Printf(" Ref region : 0x%llx", (unsigned long long)ref_address);
- log->Printf(" Pointer region : 0x%llx", (unsigned long long)pointer_address);
- }
-
- m_values[value] = pointer_address;
- return pointer_address;
- }
- }
- else
- {
- bool no_extra_redirect = (variable_is_this || variable_is_function_address);
-
- lldb::addr_t data_address = PlaceLLDBValue(value, resolved_value);
-
- if (data_address == LLDB_INVALID_ADDRESS)
- return LLDB_INVALID_ADDRESS;
-
- lldb::addr_t ref_address = MallocPointer();
-
- if (ref_address == LLDB_INVALID_ADDRESS)
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- lldb::addr_t pointer_address = LLDB_INVALID_ADDRESS;
-
- if (!no_extra_redirect)
- {
- pointer_address = MallocPointer();
-
- if (pointer_address == LLDB_INVALID_ADDRESS)
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
- }
-
- lldb_private::Error write_error;
-
- m_memory_map.WritePointerToMemory(ref_address, data_address, write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- if (pointer_address != LLDB_INVALID_ADDRESS)
- m_memory_map.Free(pointer_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
-
- if (!no_extra_redirect)
- {
- write_error.Clear();
-
- m_memory_map.WritePointerToMemory(pointer_address, ref_address, write_error);
-
- if (!write_error.Success())
- {
- lldb_private::Error free_error;
- m_memory_map.Free(data_address, free_error);
- m_memory_map.Free(ref_address, free_error);
- if (pointer_address != LLDB_INVALID_ADDRESS)
- m_memory_map.Free(pointer_address, free_error);
- return LLDB_INVALID_ADDRESS;
- }
- }
-
- if (log)
- {
- log->Printf("Made an allocation for %s", PrintValue(value).c_str());
- log->Printf(" Data contents : %s", PrintData(data_address, value->getType()).c_str());
- log->Printf(" Data region : %llx", (unsigned long long)data_address);
- log->Printf(" Ref region : %llx", (unsigned long long)ref_address);
- if (!variable_is_this)
- log->Printf(" Pointer region : %llx", (unsigned long long)pointer_address);
- }
-
- if (no_extra_redirect)
- {
- m_values[value] = ref_address;
- return ref_address;
- }
- else
- {
- m_values[value] = pointer_address;
- return pointer_address;
- }
- }
- }
- }
- while(0);
- }
-
- bool ConstructResult (lldb::ClangExpressionVariableSP &result,
- const GlobalValue *result_value,
- const lldb_private::ConstString &result_name,
- lldb_private::TypeFromParser result_type,
- Module &module)
- {
- if (!m_decl_map)
- return false;
-
- // The result_value resolves to P, a pointer to a region R containing the result data.
- // If the result variable is a reference, the region R contains a pointer to the result R_final in the original process.
-
- if (!result_value)
- return true; // There was no slot for a result â the expression doesn't return one.
-
- ValueMap::iterator i = m_values.find(result_value);
-
- if (i == m_values.end())
- return false; // There was a slot for the result, but we didn't write into it.
-
- lldb::addr_t P = i->second;
-
- Type *pointer_ty = result_value->getType();
- PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty);
- if (!pointer_ptr_ty)
- return false;
- Type *R_ty = pointer_ptr_ty->getElementType();
-
- lldb_private::Error read_error;
- lldb::addr_t R;
- m_memory_map.ReadPointerFromMemory(&R, P, read_error);
- if (!read_error.Success())
- return false;
-
- lldb_private::Value base;
-
- bool transient = false;
- bool maybe_make_load = false;
-
- if (m_decl_map->ResultIsReference(result_name))
- {
- PointerType *R_ptr_ty = dyn_cast<PointerType>(R_ty);
- if (!R_ptr_ty)
- return false;
-
- read_error.Clear();
- lldb::addr_t R_pointer;
- m_memory_map.ReadPointerFromMemory(&R_pointer, R, read_error);
- if (!read_error.Success())
- return false;
-
- // We got a bare pointer. We are going to treat it as a load address
- // or a file address, letting decl_map make the choice based on whether
- // or not a process exists.
-
- bool was_placed = false;
-
- for (PlacedValue &value : m_placed_values)
- {
- if (value.process_address == R_pointer)
- {
- base = value.lldb_value;
- was_placed = true;
- break;
- }
- }
-
- if (!was_placed)
- {
- base.SetContext(lldb_private::Value::eContextTypeInvalid, NULL);
- base.SetValueType(lldb_private::Value::eValueTypeFileAddress);
- base.GetScalar() = (unsigned long long)R_pointer;
- maybe_make_load = true;
- }
- }
- else
- {
- base.SetContext(lldb_private::Value::eContextTypeInvalid, NULL);
- base.SetValueType(lldb_private::Value::eValueTypeLoadAddress);
- base.GetScalar() = (unsigned long long)R;
- }
-
- return m_decl_map->CompleteResultVariable (result, m_memory_map, base, result_name, result_type, transient, maybe_make_load);
}
};
-bool
-IRInterpreter::maybeRunOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
- lldb_private::IRMemoryMap &memory_map,
- lldb_private::Stream *error_stream,
- lldb::ClangExpressionVariableSP &result,
- const lldb_private::ConstString &result_name,
- lldb_private::TypeFromParser result_type,
- Function &llvm_function,
- Module &llvm_module,
- lldb_private::Error &err)
-{
- if (supportsFunction (llvm_function, err))
- return runOnFunction(decl_map,
- memory_map,
- error_stream,
- result,
- result_name,
- result_type,
- llvm_function,
- llvm_module,
- err);
- else
- return false;
-}
-
static const char *unsupported_opcode_error = "Interpreter doesn't handle one of the expression's opcodes";
//static const char *interpreter_initialization_error = "Interpreter couldn't be initialized";
static const char *interpreter_internal_error = "Interpreter encountered an internal error";
@@ -904,15 +453,16 @@ static const char *memory_allocation_err
static const char *memory_write_error = "Interpreter couldn't write to memory";
static const char *memory_read_error = "Interpreter couldn't read from memory";
static const char *infinite_loop_error = "Interpreter ran for too many cycles";
-static const char *bad_result_error = "Result of expression is in bad memory";
+//static const char *bad_result_error = "Result of expression is in bad memory";
bool
-IRInterpreter::supportsFunction (Function &llvm_function,
- lldb_private::Error &err)
+IRInterpreter::CanInterpret (llvm::Module &module,
+ llvm::Function &function,
+ lldb_private::Error &error)
{
lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- for (Function::iterator bbi = llvm_function.begin(), bbe = llvm_function.end();
+ for (Function::iterator bbi = function.begin(), bbe = function.end();
bbi != bbe;
++bbi)
{
@@ -926,8 +476,8 @@ IRInterpreter::supportsFunction (Functio
{
if (log)
log->Printf("Unsupported instruction: %s", PrintValue(ii).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(unsupported_opcode_error);
+ error.SetErrorToGenericError();
+ error.SetErrorString(unsupported_opcode_error);
return false;
}
case Instruction::Add:
@@ -942,22 +492,22 @@ IRInterpreter::supportsFunction (Functio
if (!icmp_inst)
{
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
+ error.SetErrorToGenericError();
+ error.SetErrorString(interpreter_internal_error);
return false;
}
switch (icmp_inst->getPredicate())
{
default:
- {
- if (log)
- log->Printf("Unsupported ICmp predicate: %s", PrintValue(ii).c_str());
-
- err.SetErrorToGenericError();
- err.SetErrorString(unsupported_opcode_error);
- return false;
- }
+ {
+ if (log)
+ log->Printf("Unsupported ICmp predicate: %s", PrintValue(ii).c_str());
+
+ error.SetErrorToGenericError();
+ error.SetErrorString(unsupported_opcode_error);
+ return false;
+ }
case CmpInst::ICMP_EQ:
case CmpInst::ICMP_NE:
case CmpInst::ICMP_UGT:
@@ -995,785 +545,7 @@ IRInterpreter::supportsFunction (Functio
}
}
- return true;
-}
-
-bool
-IRInterpreter::runOnFunction (lldb_private::ClangExpressionDeclMap *decl_map,
- lldb_private::IRMemoryMap &memory_map,
- lldb_private::Stream *error_stream,
- lldb::ClangExpressionVariableSP &result,
- const lldb_private::ConstString &result_name,
- lldb_private::TypeFromParser result_type,
- Function &llvm_function,
- Module &llvm_module,
- lldb_private::Error &err)
-{
- lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-
- DataLayout target_data(&llvm_module);
-
- InterpreterStackFrame frame(target_data, decl_map, memory_map);
-
- uint32_t num_insts = 0;
-
- frame.Jump(llvm_function.begin());
-
- while (frame.m_ii != frame.m_ie && (++num_insts < 4096))
- {
- const Instruction *inst = frame.m_ii;
-
- if (log)
- log->Printf("Interpreting %s", PrintValue(inst).c_str());
-
- switch (inst->getOpcode())
- {
- default:
- break;
- case Instruction::Add:
- case Instruction::Sub:
- case Instruction::Mul:
- case Instruction::SDiv:
- case Instruction::UDiv:
- case Instruction::SRem:
- case Instruction::URem:
- case Instruction::Shl:
- case Instruction::LShr:
- case Instruction::AShr:
- case Instruction::And:
- case Instruction::Or:
- case Instruction::Xor:
- {
- const BinaryOperator *bin_op = dyn_cast<BinaryOperator>(inst);
-
- if (!bin_op)
- {
- if (log)
- log->Printf("getOpcode() returns %s, but instruction is not a BinaryOperator", inst->getOpcodeName());
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- Value *lhs = inst->getOperand(0);
- Value *rhs = inst->getOperand(1);
-
- lldb_private::Scalar L;
- lldb_private::Scalar R;
-
- if (!frame.EvaluateValue(L, lhs, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (!frame.EvaluateValue(R, rhs, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- lldb_private::Scalar result;
-
- switch (inst->getOpcode())
- {
- default:
- break;
- case Instruction::Add:
- result = L + R;
- break;
- case Instruction::Mul:
- result = L * R;
- break;
- case Instruction::Sub:
- result = L - R;
- break;
- case Instruction::SDiv:
- result = L / R;
- break;
- case Instruction::UDiv:
- result = L.GetRawBits64(0) / R.GetRawBits64(1);
- break;
- case Instruction::SRem:
- result = L % R;
- break;
- case Instruction::URem:
- result = L.GetRawBits64(0) % R.GetRawBits64(1);
- break;
- case Instruction::Shl:
- result = L << R;
- break;
- case Instruction::AShr:
- result = L >> R;
- break;
- case Instruction::LShr:
- result = L;
- result.ShiftRightLogical(R);
- break;
- case Instruction::And:
- result = L & R;
- break;
- case Instruction::Or:
- result = L | R;
- break;
- case Instruction::Xor:
- result = L ^ R;
- break;
- }
-
- frame.AssignValue(inst, result, llvm_module);
-
- if (log)
- {
- log->Printf("Interpreted a %s", inst->getOpcodeName());
- log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str());
- log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str());
- log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
- }
- }
- break;
- case Instruction::Alloca:
- {
- const AllocaInst *alloca_inst = dyn_cast<AllocaInst>(inst);
-
- if (!alloca_inst)
- {
- if (log)
- log->Printf("getOpcode() returns Alloca, but instruction is not an AllocaInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- if (alloca_inst->isArrayAllocation())
- {
- if (log)
- log->Printf("AllocaInsts are not handled if isArrayAllocation() is true");
- err.SetErrorToGenericError();
- err.SetErrorString(unsupported_opcode_error);
- return false;
- }
-
- // The semantics of Alloca are:
- // Create a region R of virtual memory of type T, backed by a data buffer
- // Create a region P of virtual memory of type T*, backed by a data buffer
- // Write the virtual address of R into P
-
- Type *T = alloca_inst->getAllocatedType();
- Type *Tptr = alloca_inst->getType();
-
- lldb::addr_t R = frame.Malloc(T);
-
- if (R == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("Couldn't allocate memory for an AllocaInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_allocation_error);
- return false;
- }
-
- lldb::addr_t P = frame.Malloc(Tptr);
-
- if (P == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("Couldn't allocate the result pointer for an AllocaInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_allocation_error);
- return false;
- }
-
- lldb_private::Error write_error;
-
- memory_map.WritePointerToMemory(P, R, write_error);
-
- if (!write_error.Success())
- {
- if (log)
- log->Printf("Couldn't write the result pointer for an AllocaInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_write_error);
- lldb_private::Error free_error;
- memory_map.Free(P, free_error);
- memory_map.Free(R, free_error);
- return false;
- }
-
- frame.m_values[alloca_inst] = P;
-
- if (log)
- {
- log->Printf("Interpreted an AllocaInst");
- log->Printf(" R : 0x%llx", R);
- log->Printf(" P : 0x%llx", P);
- }
- }
- break;
- case Instruction::BitCast:
- case Instruction::ZExt:
- {
- const CastInst *cast_inst = dyn_cast<CastInst>(inst);
-
- if (!cast_inst)
- {
- if (log)
- log->Printf("getOpcode() returns %s, but instruction is not a BitCastInst", cast_inst->getOpcodeName());
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- Value *source = cast_inst->getOperand(0);
-
- lldb_private::Scalar S;
-
- if (!frame.EvaluateValue(S, source, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(source).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- frame.AssignValue(inst, S, llvm_module);
- }
- break;
- case Instruction::Br:
- {
- const BranchInst *br_inst = dyn_cast<BranchInst>(inst);
-
- if (!br_inst)
- {
- if (log)
- log->Printf("getOpcode() returns Br, but instruction is not a BranchInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- if (br_inst->isConditional())
- {
- Value *condition = br_inst->getCondition();
-
- lldb_private::Scalar C;
-
- if (!frame.EvaluateValue(C, condition, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(condition).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (C.GetRawBits64(0))
- frame.Jump(br_inst->getSuccessor(0));
- else
- frame.Jump(br_inst->getSuccessor(1));
-
- if (log)
- {
- log->Printf("Interpreted a BrInst with a condition");
- log->Printf(" cond : %s", frame.SummarizeValue(condition).c_str());
- }
- }
- else
- {
- frame.Jump(br_inst->getSuccessor(0));
-
- if (log)
- {
- log->Printf("Interpreted a BrInst with no condition");
- }
- }
- }
- continue;
- case Instruction::GetElementPtr:
- {
- const GetElementPtrInst *gep_inst = dyn_cast<GetElementPtrInst>(inst);
-
- if (!gep_inst)
- {
- if (log)
- log->Printf("getOpcode() returns GetElementPtr, but instruction is not a GetElementPtrInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- const Value *pointer_operand = gep_inst->getPointerOperand();
- Type *pointer_type = pointer_operand->getType();
-
- lldb_private::Scalar P;
-
- if (!frame.EvaluateValue(P, pointer_operand, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(pointer_operand).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- typedef SmallVector <Value *, 8> IndexVector;
- typedef IndexVector::iterator IndexIterator;
-
- SmallVector <Value *, 8> indices (gep_inst->idx_begin(),
- gep_inst->idx_end());
-
- SmallVector <Value *, 8> const_indices;
-
- for (IndexIterator ii = indices.begin(), ie = indices.end();
- ii != ie;
- ++ii)
- {
- ConstantInt *constant_index = dyn_cast<ConstantInt>(*ii);
-
- if (!constant_index)
- {
- lldb_private::Scalar I;
-
- if (!frame.EvaluateValue(I, *ii, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(*ii).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (log)
- log->Printf("Evaluated constant index %s as %llu", PrintValue(*ii).c_str(), I.ULongLong(LLDB_INVALID_ADDRESS));
-
- constant_index = cast<ConstantInt>(ConstantInt::get((*ii)->getType(), I.ULongLong(LLDB_INVALID_ADDRESS)));
- }
-
- const_indices.push_back(constant_index);
- }
-
- uint64_t offset = target_data.getIndexedOffset(pointer_type, const_indices);
-
- lldb_private::Scalar Poffset = P + offset;
-
- frame.AssignValue(inst, Poffset, llvm_module);
-
- if (log)
- {
- log->Printf("Interpreted a GetElementPtrInst");
- log->Printf(" P : %s", frame.SummarizeValue(pointer_operand).c_str());
- log->Printf(" Poffset : %s", frame.SummarizeValue(inst).c_str());
- }
- }
- break;
- case Instruction::ICmp:
- {
- const ICmpInst *icmp_inst = dyn_cast<ICmpInst>(inst);
-
- if (!icmp_inst)
- {
- if (log)
- log->Printf("getOpcode() returns ICmp, but instruction is not an ICmpInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- CmpInst::Predicate predicate = icmp_inst->getPredicate();
-
- Value *lhs = inst->getOperand(0);
- Value *rhs = inst->getOperand(1);
-
- lldb_private::Scalar L;
- lldb_private::Scalar R;
-
- if (!frame.EvaluateValue(L, lhs, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(lhs).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (!frame.EvaluateValue(R, rhs, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(rhs).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- lldb_private::Scalar result;
-
- switch (predicate)
- {
- default:
- return false;
- case CmpInst::ICMP_EQ:
- result = (L == R);
- break;
- case CmpInst::ICMP_NE:
- result = (L != R);
- break;
- case CmpInst::ICMP_UGT:
- result = (L.GetRawBits64(0) > R.GetRawBits64(0));
- break;
- case CmpInst::ICMP_UGE:
- result = (L.GetRawBits64(0) >= R.GetRawBits64(0));
- break;
- case CmpInst::ICMP_ULT:
- result = (L.GetRawBits64(0) < R.GetRawBits64(0));
- break;
- case CmpInst::ICMP_ULE:
- result = (L.GetRawBits64(0) <= R.GetRawBits64(0));
- break;
- case CmpInst::ICMP_SGT:
- result = (L > R);
- break;
- case CmpInst::ICMP_SGE:
- result = (L >= R);
- break;
- case CmpInst::ICMP_SLT:
- result = (L < R);
- break;
- case CmpInst::ICMP_SLE:
- result = (L <= R);
- break;
- }
-
- frame.AssignValue(inst, result, llvm_module);
-
- if (log)
- {
- log->Printf("Interpreted an ICmpInst");
- log->Printf(" L : %s", frame.SummarizeValue(lhs).c_str());
- log->Printf(" R : %s", frame.SummarizeValue(rhs).c_str());
- log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
- }
- }
- break;
- case Instruction::IntToPtr:
- {
- const IntToPtrInst *int_to_ptr_inst = dyn_cast<IntToPtrInst>(inst);
-
- if (!int_to_ptr_inst)
- {
- if (log)
- log->Printf("getOpcode() returns IntToPtr, but instruction is not an IntToPtrInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- Value *src_operand = int_to_ptr_inst->getOperand(0);
-
- lldb_private::Scalar I;
-
- if (!frame.EvaluateValue(I, src_operand, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- frame.AssignValue(inst, I, llvm_module);
-
- if (log)
- {
- log->Printf("Interpreted an IntToPtr");
- log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str());
- log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
- }
- }
- break;
- case Instruction::PtrToInt:
- {
- const PtrToIntInst *ptr_to_int_inst = dyn_cast<PtrToIntInst>(inst);
-
- if (!ptr_to_int_inst)
- {
- if (log)
- log->Printf("getOpcode() returns PtrToInt, but instruction is not an PtrToIntInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- Value *src_operand = ptr_to_int_inst->getOperand(0);
-
- lldb_private::Scalar I;
-
- if (!frame.EvaluateValue(I, src_operand, llvm_module))
- {
- if (log)
- log->Printf("Couldn't evaluate %s", PrintValue(src_operand).c_str());
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- frame.AssignValue(inst, I, llvm_module);
-
- if (log)
- {
- log->Printf("Interpreted a PtrToInt");
- log->Printf(" Src : %s", frame.SummarizeValue(src_operand).c_str());
- log->Printf(" = : %s", frame.SummarizeValue(inst).c_str());
- }
- }
- break;
- case Instruction::Load:
- {
- const LoadInst *load_inst = dyn_cast<LoadInst>(inst);
-
- if (!load_inst)
- {
- if (log)
- log->Printf("getOpcode() returns Load, but instruction is not a LoadInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- // The semantics of Load are:
- // Create a region D that will contain the loaded data
- // Resolve the region P containing a pointer
- // Dereference P to get the region R that the data should be loaded from
- // Transfer a unit of type type(D) from R to D
-
- const Value *pointer_operand = load_inst->getPointerOperand();
-
- Type *pointer_ty = pointer_operand->getType();
- PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty);
- if (!pointer_ptr_ty)
- {
- if (log)
- log->Printf("getPointerOperand()->getType() is not a PointerType");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
- Type *target_ty = pointer_ptr_ty->getElementType();
-
- lldb::addr_t D = frame.ResolveValue(load_inst, llvm_module);
- lldb::addr_t P = frame.ResolveValue(pointer_operand, llvm_module);
-
- if (D == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("LoadInst's value doesn't resolve to anything");
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (P == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("LoadInst's pointer doesn't resolve to anything");
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- lldb::addr_t R;
- lldb_private::Error read_error;
- memory_map.ReadPointerFromMemory(&R, P, read_error);
-
- if (!read_error.Success())
- {
- if (log)
- log->Printf("Couldn't read the address to be loaded for a LoadInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- size_t target_size = target_data.getTypeStoreSize(target_ty);
- lldb_private::DataBufferHeap buffer(target_size, 0);
-
- read_error.Clear();
- memory_map.ReadMemory(buffer.GetBytes(), R, buffer.GetByteSize(), read_error);
- if (!read_error.Success())
- {
- if (log)
- log->Printf("Couldn't read from a region on behalf of a LoadInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- lldb_private::Error write_error;
- memory_map.WriteMemory(D, buffer.GetBytes(), buffer.GetByteSize(), write_error);
- if (!write_error.Success())
- {
- if (log)
- log->Printf("Couldn't write to a region on behalf of a LoadInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- if (log)
- {
- log->Printf("Interpreted a LoadInst");
- log->Printf(" P : 0x%llx", P);
- log->Printf(" R : 0x%llx", R);
- log->Printf(" D : 0x%llx", D);
- }
- }
- break;
- case Instruction::Ret:
- {
- frame.RestoreLLDBValues();
-
- if (result_name.IsEmpty())
- return true;
-
- GlobalValue *result_value = llvm_module.getNamedValue(result_name.GetCString());
-
- if (!frame.ConstructResult(result, result_value, result_name, result_type, llvm_module))
- {
- if (log)
- log->Printf("Couldn't construct the expression's result");
- err.SetErrorToGenericError();
- err.SetErrorString(bad_result_error);
- return false;
- }
-
- return true;
- }
- case Instruction::Store:
- {
- const StoreInst *store_inst = dyn_cast<StoreInst>(inst);
-
- if (!store_inst)
- {
- if (log)
- log->Printf("getOpcode() returns Store, but instruction is not a StoreInst");
- err.SetErrorToGenericError();
- err.SetErrorString(interpreter_internal_error);
- return false;
- }
-
- // The semantics of Store are:
- // Resolve the region D containing the data to be stored
- // Resolve the region P containing a pointer
- // Dereference P to get the region R that the data should be stored in
- // Transfer a unit of type type(D) from D to R
-
- const Value *value_operand = store_inst->getValueOperand();
- const Value *pointer_operand = store_inst->getPointerOperand();
-
- Type *pointer_ty = pointer_operand->getType();
- PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty);
- if (!pointer_ptr_ty)
- return false;
- Type *target_ty = pointer_ptr_ty->getElementType();
-
- lldb::addr_t D = frame.ResolveValue(value_operand, llvm_module);
- lldb::addr_t P = frame.ResolveValue(pointer_operand, llvm_module);
-
- if (D == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("StoreInst's value doesn't resolve to anything");
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- if (P == LLDB_INVALID_ADDRESS)
- {
- if (log)
- log->Printf("StoreInst's pointer doesn't resolve to anything");
- err.SetErrorToGenericError();
- err.SetErrorString(bad_value_error);
- return false;
- }
-
- lldb::addr_t R;
- lldb_private::Error read_error;
- memory_map.ReadPointerFromMemory(&R, P, read_error);
-
- if (!read_error.Success())
- {
- if (log)
- log->Printf("Couldn't read the address to be loaded for a LoadInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- size_t target_size = target_data.getTypeStoreSize(target_ty);
- lldb_private::DataBufferHeap buffer(target_size, 0);
-
- read_error.Clear();
- memory_map.ReadMemory(buffer.GetBytes(), D, buffer.GetByteSize(), read_error);
- if (!read_error.Success())
- {
- if (log)
- log->Printf("Couldn't read from a region on behalf of a StoreInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- lldb_private::Error write_error;
- memory_map.WriteMemory(R, buffer.GetBytes(), buffer.GetByteSize(), write_error);
- if (!write_error.Success())
- {
- if (log)
- log->Printf("Couldn't write to a region on behalf of a StoreInst");
- err.SetErrorToGenericError();
- err.SetErrorString(memory_read_error);
- return false;
- }
-
- if (log)
- {
- log->Printf("Interpreted a StoreInst");
- log->Printf(" D : 0x%llx", D);
- log->Printf(" P : 0x%llx", P);
- log->Printf(" R : 0x%llx", R);
- }
- }
- break;
- }
-
- ++frame.m_ii;
- }
-
- if (num_insts >= 4096)
- {
- err.SetErrorToGenericError();
- err.SetErrorString(infinite_loop_error);
- return false;
- }
-
- return false;
-}
-
-// new api
-
-bool
-IRInterpreter::CanInterpret (llvm::Module &module,
- llvm::Function &function,
- lldb_private::Error &error)
-{
- return supportsFunction(function, error);
-}
+ return true;}
bool
IRInterpreter::Interpret (llvm::Module &module,
@@ -1798,7 +570,7 @@ IRInterpreter::Interpret (llvm::Module &
DataLayout data_layout(&module);
- InterpreterStackFrame frame(data_layout, NULL, memory_map);
+ InterpreterStackFrame frame(data_layout, memory_map);
if (frame.m_frame_process_address == LLDB_INVALID_ADDRESS)
{
More information about the lldb-commits
mailing list