[Lldb-commits] [lldb] r110415 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h source/Commands/CommandObjectExpression.cpp source/Commands/CommandObjectExpression.h source/Expression/ClangExpressionDeclMap.cpp
Sean Callanan
scallanan at apple.com
Thu Aug 5 17:35:32 PDT 2010
Author: spyffe
Date: Thu Aug 5 19:35:32 2010
New Revision: 110415
URL: http://llvm.org/viewvc/llvm-project?rev=110415&view=rev
Log:
Removed the -i option from the expr command, and
made IR-based expression evaluation the default.
Also added a new class to hold persistent variables.
The class is empty as yet while I write up a design
document for what it will do. Also the place where
it is currently created (by the Expression command)
is certainly wrong.
Modified:
lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
lldb/trunk/source/Commands/CommandObjectExpression.cpp
lldb/trunk/source/Commands/CommandObjectExpression.h
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=110415&r1=110414&r2=110415&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Thu Aug 5 19:35:32 2010
@@ -30,6 +30,7 @@
namespace lldb_private {
+class ClangPersistentVariables;
class Error;
class Function;
class NameSearchContext;
@@ -38,7 +39,8 @@
class ClangExpressionDeclMap
{
public:
- ClangExpressionDeclMap(ExecutionContext *exe_ctx);
+ ClangExpressionDeclMap(ExecutionContext *exe_ctx,
+ ClangPersistentVariables &persistent_vars);
~ClangExpressionDeclMap();
// Interface for ClangStmtVisitor
@@ -88,10 +90,10 @@
// Interface for ClangASTSource
void GetDecls (NameSearchContext &context,
const char *name);
-private:
+
typedef TaggedASTType<0> TypeFromParser;
typedef TaggedASTType<1> TypeFromUser;
-
+private:
struct Tuple
{
const clang::NamedDecl *m_decl;
@@ -118,15 +120,16 @@
typedef std::vector<StructMember> StructMemberVector;
typedef StructMemberVector::iterator StructMemberIterator;
- TupleVector m_tuples;
- StructMemberVector m_members;
- ExecutionContext *m_exe_ctx;
- SymbolContext *m_sym_ctx; /* owned by ClangExpressionDeclMap */
- off_t m_struct_alignment;
- size_t m_struct_size;
- bool m_struct_laid_out;
- lldb::addr_t m_allocated_area;
- lldb::addr_t m_materialized_location;
+ TupleVector m_tuples;
+ StructMemberVector m_members;
+ ExecutionContext *m_exe_ctx;
+ SymbolContext *m_sym_ctx; /* owned by ClangExpressionDeclMap */
+ ClangPersistentVariables &m_persistent_vars;
+ off_t m_struct_alignment;
+ size_t m_struct_size;
+ bool m_struct_laid_out;
+ lldb::addr_t m_allocated_area;
+ lldb::addr_t m_materialized_location;
Variable *FindVariableInScope(const SymbolContext &sym_ctx,
const char *name,
@@ -156,6 +159,11 @@
Error &err);
};
+class ClangPersistentVariables
+{
+
+};
+
} // namespace lldb_private
#endif // liblldb_ClangExpressionDeclMap_h_
Modified: lldb/trunk/source/Commands/CommandObjectExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.cpp?rev=110415&r1=110414&r2=110415&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.cpp Thu Aug 5 19:35:32 2010
@@ -70,10 +70,6 @@
case 'f':
error = Args::StringToFormat(option_arg, format);
break;
-
- case 'i':
- use_ir = true;
- break;
default:
error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
@@ -92,7 +88,6 @@
format = eFormatDefault;
show_types = true;
show_summary = true;
- use_ir = false;
}
const lldb::OptionDefinition*
@@ -222,7 +217,8 @@
return false;
}
- ClangExpressionDeclMap expr_decl_map (&m_exe_ctx);
+ ClangPersistentVariables persistent_vars; /* TODO store this somewhere sensible */
+ ClangExpressionDeclMap expr_decl_map (&m_exe_ctx, persistent_vars);
ClangExpression clang_expr (target_triple.AsCString (), &expr_decl_map);
//////////////////////////
@@ -234,7 +230,7 @@
if (bare)
num_errors = clang_expr.ParseBareExpression (llvm::StringRef (expr), error_stream);
else
- num_errors = clang_expr.ParseExpression (expr, error_stream, m_options.use_ir);
+ num_errors = clang_expr.ParseExpression (expr, error_stream, true);
if (num_errors)
{
@@ -259,174 +255,129 @@
Value expr_result;
Error expr_error;
- if (m_options.use_ir)
+ canInterpret = clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes);
+
+ if (canInterpret)
{
- canInterpret = clang_expr.ConvertIRToDWARF (expr_local_vars, dwarf_opcodes);
-
- if (canInterpret)
+ if (log)
+ log->Printf("Code can be interpreted.");
+ success = true;
+ }
+ else
+ {
+ if (log)
+ log->Printf("Code cannot be interpreted and must be run in the target.");
+ success = clang_expr.PrepareIRForTarget (expr_local_vars);
+ }
+
+ if (!success)
+ {
+ error_stream.PutCString ("error: expression couldn't be converted to IR\n");
+ return false;
+ }
+
+ if (canInterpret)
+ {
+ // TODO interpret IR
+ return false;
+ }
+ else
+ {
+ if (!clang_expr.JITFunction (m_exe_ctx, "___clang_expr"))
{
- if (log)
- log->Printf("Code can be interpreted.");
- success = true;
+ error_stream.PutCString ("error: IR could not be JIT compiled\n");
+ return false;
}
- else
+
+ if (!clang_expr.WriteJITCode (m_exe_ctx))
{
- if (log)
- log->Printf("Code cannot be interpreted and must be run in the target.");
- success = clang_expr.PrepareIRForTarget (expr_local_vars);
+ error_stream.PutCString ("error: JIT code could not be written to the target\n");
+ return false;
}
- if (!success)
+ lldb::addr_t function_address(clang_expr.GetFunctionAddress ("___clang_expr"));
+
+ if (function_address == LLDB_INVALID_ADDRESS)
{
- error_stream.PutCString ("error: expression couldn't be converted to IR\n");
+ error_stream.PutCString ("JIT compiled code's address couldn't be found\n");
return false;
}
- if (canInterpret)
+ lldb::addr_t struct_address;
+
+ if (!expr_decl_map.Materialize(&m_exe_ctx, struct_address, expr_error))
{
- // TODO interpret IR
+ error_stream.Printf ("Couldn't materialize struct: %s\n", expr_error.AsCString("unknown error"));
return false;
}
- else
+
+ if (log)
{
- if (!clang_expr.JITFunction (m_exe_ctx, "___clang_expr"))
- {
- error_stream.PutCString ("error: IR could not be JIT compiled\n");
- return false;
- }
-
- if (!clang_expr.WriteJITCode (m_exe_ctx))
- {
- error_stream.PutCString ("error: JIT code could not be written to the target\n");
- return false;
- }
+ log->Printf("Function address : 0x%llx", (uint64_t)function_address);
+ log->Printf("Structure address : 0x%llx", (uint64_t)struct_address);
- lldb::addr_t function_address(clang_expr.GetFunctionAddress ("___clang_expr"));
+ StreamString insns;
+
+ Error err = clang_expr.DisassembleFunction(insns, m_exe_ctx, "___clang_expr");
- if (function_address == LLDB_INVALID_ADDRESS)
+ if (!err.Success())
{
- error_stream.PutCString ("JIT compiled code's address couldn't be found\n");
- return false;
+ log->Printf("Couldn't disassemble function : %s", err.AsCString("unknown error"));
}
-
- lldb::addr_t struct_address;
-
- if (!expr_decl_map.Materialize(&m_exe_ctx, struct_address, expr_error))
+ else
{
- error_stream.Printf ("Couldn't materialize struct: %s\n", expr_error.AsCString("unknown error"));
- return false;
+ log->Printf("Function disassembly:\n%s", insns.GetData());
}
- if (log)
- {
- log->Printf("Function address : 0x%llx", (uint64_t)function_address);
- log->Printf("Structure address : 0x%llx", (uint64_t)struct_address);
-
- StreamString insns;
-
- Error err = clang_expr.DisassembleFunction(insns, m_exe_ctx, "___clang_expr");
-
- if (!err.Success())
- {
- log->Printf("Couldn't disassemble function : %s", err.AsCString("unknown error"));
- }
- else
- {
- log->Printf("Function disassembly:\n%s", insns.GetData());
- }
-
- StreamString args;
-
- if (!expr_decl_map.DumpMaterializedStruct(&m_exe_ctx, args, err))
- {
- log->Printf("Couldn't extract variable values : %s", err.AsCString("unknown error"));
- }
- else
- {
- log->Printf("Structure contents:\n%s", args.GetData());
- }
- }
-
- ClangFunction::ExecutionResults execution_result =
- ClangFunction::ExecuteFunction (m_exe_ctx, function_address, struct_address, true, true, 10000, error_stream);
+ StreamString args;
- if (execution_result != ClangFunction::eExecutionCompleted)
+ if (!expr_decl_map.DumpMaterializedStruct(&m_exe_ctx, args, err))
{
- const char *result_name;
-
- switch (execution_result)
- {
- case ClangFunction::eExecutionCompleted:
- result_name = "eExecutionCompleted";
- break;
- case ClangFunction::eExecutionDiscarded:
- result_name = "eExecutionDiscarded";
- break;
- case ClangFunction::eExecutionInterrupted:
- result_name = "eExecutionInterrupted";
- break;
- case ClangFunction::eExecutionSetupError:
- result_name = "eExecutionSetupError";
- break;
- case ClangFunction::eExecutionTimedOut:
- result_name = "eExecutionTimedOut";
- break;
- }
-
- error_stream.Printf ("Couldn't execute function; result was %s\n", result_name);
- return false;
+ log->Printf("Couldn't extract variable values : %s", err.AsCString("unknown error"));
}
-
- if (!expr_decl_map.Dematerialize(&m_exe_ctx, expr_result, expr_error))
+ else
{
- error_stream.Printf ("Couldn't dematerialize struct: %s\n", expr_error.AsCString("unknown error"));
- return false;
+ log->Printf("Structure contents:\n%s", args.GetData());
}
}
- }
- else
- {
- success = (clang_expr.ConvertExpressionToDWARF (expr_local_vars, dwarf_opcodes) == 0);
-
- if (!success)
- {
- error_stream.PutCString ("error: expression couldn't be translated to DWARF\n");
- return false;
- }
-
- //////////////////////////////////////////
- // Evaluate the generated DWARF opcodes
- //
-
- DataExtractor dwarf_opcodes_data (dwarf_opcodes.GetData (), dwarf_opcodes.GetSize (), eByteOrderHost, 8);
- DWARFExpression dwarf_expr (dwarf_opcodes_data, 0, dwarf_opcodes_data.GetByteSize (), NULL);
+
+ ClangFunction::ExecutionResults execution_result =
+ ClangFunction::ExecuteFunction (m_exe_ctx, function_address, struct_address, true, true, 10000, error_stream);
- dwarf_expr.SetExpressionLocalVariableList(&expr_local_vars);
-
- if (log)
+ if (execution_result != ClangFunction::eExecutionCompleted)
{
- StreamString stream_string;
-
- log->PutCString ("Expression parsed ok, dwarf opcodes:");
+ const char *result_name;
- stream_string.PutCString ("\n");
- stream_string.IndentMore ();
- dwarf_expr.GetDescription (&stream_string, lldb::eDescriptionLevelVerbose);
- stream_string.IndentLess ();
- stream_string.EOL ();
+ switch (execution_result)
+ {
+ case ClangFunction::eExecutionCompleted:
+ result_name = "eExecutionCompleted";
+ break;
+ case ClangFunction::eExecutionDiscarded:
+ result_name = "eExecutionDiscarded";
+ break;
+ case ClangFunction::eExecutionInterrupted:
+ result_name = "eExecutionInterrupted";
+ break;
+ case ClangFunction::eExecutionSetupError:
+ result_name = "eExecutionSetupError";
+ break;
+ case ClangFunction::eExecutionTimedOut:
+ result_name = "eExecutionTimedOut";
+ break;
+ }
- log->PutCString (stream_string.GetString ().c_str ());
+ error_stream.Printf ("Couldn't execute function; result was %s\n", result_name);
+ return false;
}
-
- success = dwarf_expr.Evaluate (&m_exe_ctx, ast_context, NULL, expr_result, &expr_error);
-
- if (!success)
+
+ if (!expr_decl_map.Dematerialize(&m_exe_ctx, expr_result, expr_error))
{
- error_stream.Printf ("error: couldn't evaluate DWARF expression: %s\n", expr_error.AsCString ());
+ error_stream.Printf ("Couldn't dematerialize struct: %s\n", expr_error.AsCString("unknown error"));
return false;
}
}
-
+
///////////////////////////////////////
// Interpret the result and print it
//
Modified: lldb/trunk/source/Commands/CommandObjectExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectExpression.h?rev=110415&r1=110414&r2=110415&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectExpression.h (original)
+++ lldb/trunk/source/Commands/CommandObjectExpression.h Thu Aug 5 19:35:32 2010
@@ -52,7 +52,6 @@
bool debug;
bool show_types;
bool show_summary;
- bool use_ir;
};
CommandObjectExpression ();
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=110415&r1=110414&r2=110415&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Thu Aug 5 19:35:32 2010
@@ -36,8 +36,10 @@
using namespace lldb_private;
using namespace clang;
-ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx) :
+ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx,
+ ClangPersistentVariables &persistent_vars) :
m_exe_ctx(exe_ctx),
+ m_persistent_vars(persistent_vars),
m_struct_laid_out(false),
m_materialized_location(0)
{
More information about the lldb-commits
mailing list