2010-06-09 00:52:24 +08:00
|
|
|
//===-- ClangFunction.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/RecordLayout.h"
|
2010-07-03 02:39:06 +08:00
|
|
|
#include "clang/CodeGen/CodeGenAction.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "clang/CodeGen/ModuleBuilder.h"
|
2010-07-03 02:39:06 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2011-02-16 05:59:32 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2010-07-03 02:39:06 +08:00
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
2013-01-02 20:20:07 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Project includes
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
#include "lldb/Expression/ASTStructExtractor.h"
|
|
|
|
#include "lldb/Expression/ClangExpressionParser.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Expression/ClangFunction.h"
|
2013-04-19 02:10:51 +08:00
|
|
|
#include "lldb/Expression/IRExecutionUnit.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
2010-11-17 10:32:00 +08:00
|
|
|
#include "lldb/Core/State.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
|
|
|
#include "lldb/Core/ValueObjectList.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
#include "lldb/Symbol/ClangASTContext.h"
|
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2010-07-23 08:16:21 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2011-02-16 05:59:32 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
#include "lldb/Target/ThreadPlanCallFunction.h"
|
|
|
|
#include "lldb/Core/Log.h"
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ClangFunction constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-10-16 06:48:33 +08:00
|
|
|
ClangFunction::ClangFunction
|
|
|
|
(
|
2011-03-18 04:02:56 +08:00
|
|
|
ExecutionContextScope &exe_scope,
|
2013-07-12 06:46:58 +08:00
|
|
|
const ClangASTType &return_type,
|
2010-10-16 06:48:33 +08:00
|
|
|
const Address& functionAddress,
|
|
|
|
const ValueList &arg_value_list
|
|
|
|
) :
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_ptr (NULL),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_function_addr (functionAddress),
|
2013-07-12 06:46:58 +08:00
|
|
|
m_function_return_type(return_type),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_wrapper_function_name ("__lldb_caller_function"),
|
|
|
|
m_wrapper_struct_name ("__lldb_caller_struct"),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_wrapper_args_addrs (),
|
|
|
|
m_arg_values (arg_value_list),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_compiled (false),
|
|
|
|
m_JITted (false)
|
|
|
|
{
|
2012-09-18 08:08:47 +08:00
|
|
|
m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
|
2011-03-18 04:02:56 +08:00
|
|
|
// Can't make a ClangFunction without a process.
|
2012-09-18 08:08:47 +08:00
|
|
|
assert (m_jit_process_wp.lock());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
ClangFunction::ClangFunction
|
|
|
|
(
|
2011-03-18 04:02:56 +08:00
|
|
|
ExecutionContextScope &exe_scope,
|
2010-10-16 06:48:33 +08:00
|
|
|
Function &function,
|
|
|
|
ClangASTContext *ast_context,
|
|
|
|
const ValueList &arg_value_list
|
|
|
|
) :
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_ptr (&function),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_function_addr (),
|
2013-07-12 06:46:58 +08:00
|
|
|
m_function_return_type (),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_clang_ast_context (ast_context),
|
|
|
|
m_wrapper_function_name ("__lldb_function_caller"),
|
|
|
|
m_wrapper_struct_name ("__lldb_caller_struct"),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_wrapper_args_addrs (),
|
|
|
|
m_arg_values (arg_value_list),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_compiled (false),
|
|
|
|
m_JITted (false)
|
|
|
|
{
|
2012-09-18 08:08:47 +08:00
|
|
|
m_jit_process_wp = lldb::ProcessWP(exe_scope.CalculateProcess());
|
2011-03-18 04:02:56 +08:00
|
|
|
// Can't make a ClangFunction without a process.
|
2012-09-18 08:08:47 +08:00
|
|
|
assert (m_jit_process_wp.lock());
|
2011-02-16 05:59:32 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_addr = m_function_ptr->GetAddressRange().GetBaseAddress();
|
2013-07-12 06:46:58 +08:00
|
|
|
m_function_return_type = m_function_ptr->GetClangType().GetFunctionReturnType();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ClangFunction::~ClangFunction()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
ClangFunction::CompileFunction (Stream &errors)
|
|
|
|
{
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (m_compiled)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// FIXME: How does clang tell us there's no return value? We need to handle that case.
|
|
|
|
unsigned num_errors = 0;
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
std::string return_type_str (m_function_return_type.GetTypeName());
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
|
|
|
// Cons up the function we're going to wrap our call in, then compile it...
|
|
|
|
// We declare the function "extern "C"" because the compiler might be in C++
|
|
|
|
// mode which would mangle the name and then we couldn't find it again...
|
|
|
|
m_wrapper_function_text.clear();
|
|
|
|
m_wrapper_function_text.append ("extern \"C\" void ");
|
|
|
|
m_wrapper_function_text.append (m_wrapper_function_name);
|
|
|
|
m_wrapper_function_text.append (" (void *input)\n{\n struct ");
|
|
|
|
m_wrapper_function_text.append (m_wrapper_struct_name);
|
|
|
|
m_wrapper_function_text.append (" \n {\n");
|
|
|
|
m_wrapper_function_text.append (" ");
|
|
|
|
m_wrapper_function_text.append (return_type_str);
|
|
|
|
m_wrapper_function_text.append (" (*fn_ptr) (");
|
|
|
|
|
|
|
|
// Get the number of arguments. If we have a function type and it is prototyped,
|
|
|
|
// trust that, otherwise use the values we were given.
|
|
|
|
|
|
|
|
// FIXME: This will need to be extended to handle Variadic functions. We'll need
|
|
|
|
// to pull the defined arguments out of the function, then add the types from the
|
|
|
|
// arguments list for the variable arguments.
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
uint32_t num_args = UINT32_MAX;
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
bool trust_function = false;
|
|
|
|
// GetArgumentCount returns -1 for an unprototyped function.
|
2013-07-12 06:46:58 +08:00
|
|
|
ClangASTType function_clang_type;
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (m_function_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-12 06:46:58 +08:00
|
|
|
function_clang_type = m_function_ptr->GetClangType();
|
|
|
|
if (function_clang_type)
|
|
|
|
{
|
|
|
|
int num_func_args = function_clang_type.GetFunctionArgumentCount();
|
|
|
|
if (num_func_args >= 0)
|
|
|
|
{
|
|
|
|
trust_function = true;
|
|
|
|
num_args = num_func_args;
|
|
|
|
}
|
|
|
|
}
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (num_args == UINT32_MAX)
|
|
|
|
num_args = m_arg_values.GetSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
std::string args_buffer; // This one stores the definition of all the args in "struct caller".
|
|
|
|
std::string args_list_buffer; // This one stores the argument list called from the structure.
|
|
|
|
for (size_t i = 0; i < num_args; i++)
|
|
|
|
{
|
2011-02-17 07:00:21 +08:00
|
|
|
std::string type_name;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (trust_function)
|
|
|
|
{
|
2013-07-12 06:46:58 +08:00
|
|
|
type_name = function_clang_type.GetFunctionArgumentTypeAtIndex(i).GetTypeName();
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-12 06:46:58 +08:00
|
|
|
ClangASTType clang_qual_type = m_arg_values.GetValueAtIndex(i)->GetClangType ();
|
|
|
|
if (clang_qual_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-07-12 06:46:58 +08:00
|
|
|
type_name = clang_qual_type.GetTypeName();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
{
|
2011-09-21 05:44:10 +08:00
|
|
|
errors.Printf("Could not determine type of input value %lu.", i);
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
return 1;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-17 07:00:21 +08:00
|
|
|
m_wrapper_function_text.append (type_name);
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (i < num_args - 1)
|
|
|
|
m_wrapper_function_text.append (", ");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
char arg_buf[32];
|
|
|
|
args_buffer.append (" ");
|
2011-02-17 07:00:21 +08:00
|
|
|
args_buffer.append (type_name);
|
2012-11-30 05:49:15 +08:00
|
|
|
snprintf(arg_buf, 31, "arg_%" PRIu64, (uint64_t)i);
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
args_buffer.push_back (' ');
|
|
|
|
args_buffer.append (arg_buf);
|
|
|
|
args_buffer.append (";\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
args_list_buffer.append ("__lldb_fn_data->");
|
|
|
|
args_list_buffer.append (arg_buf);
|
|
|
|
if (i < num_args - 1)
|
|
|
|
args_list_buffer.append (", ");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
}
|
|
|
|
m_wrapper_function_text.append (");\n"); // Close off the function calling prototype.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
m_wrapper_function_text.append (args_buffer);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
m_wrapper_function_text.append (" ");
|
|
|
|
m_wrapper_function_text.append (return_type_str);
|
|
|
|
m_wrapper_function_text.append (" return_value;");
|
|
|
|
m_wrapper_function_text.append ("\n };\n struct ");
|
|
|
|
m_wrapper_function_text.append (m_wrapper_struct_name);
|
|
|
|
m_wrapper_function_text.append ("* __lldb_fn_data = (struct ");
|
|
|
|
m_wrapper_function_text.append (m_wrapper_struct_name);
|
|
|
|
m_wrapper_function_text.append (" *) input;\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
m_wrapper_function_text.append (" __lldb_fn_data->return_value = __lldb_fn_data->fn_ptr (");
|
|
|
|
m_wrapper_function_text.append (args_list_buffer);
|
|
|
|
m_wrapper_function_text.append (");\n}\n");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf ("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str());
|
|
|
|
|
|
|
|
// Okay, now compile this expression
|
|
|
|
|
2012-09-18 08:08:47 +08:00
|
|
|
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
|
|
|
|
if (jit_process_sp)
|
|
|
|
{
|
|
|
|
m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this));
|
|
|
|
|
|
|
|
num_errors = m_parser->Parse (errors);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
errors.Printf("no process - unable to inject function");
|
|
|
|
num_errors = 1;
|
|
|
|
}
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
|
|
|
m_compiled = (num_errors == 0);
|
|
|
|
|
|
|
|
if (!m_compiled)
|
|
|
|
return num_errors;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return num_errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::WriteFunctionWrapper (ExecutionContext &exe_ctx, Stream &errors)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (!process)
|
|
|
|
return false;
|
2012-09-18 08:08:47 +08:00
|
|
|
|
|
|
|
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
|
|
|
|
|
|
|
|
if (process != jit_process_sp.get())
|
2011-03-18 04:02:56 +08:00
|
|
|
return false;
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
|
|
|
if (!m_compiled)
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
if (m_JITted)
|
|
|
|
return true;
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
|
|
|
|
bool can_interpret = false; // should stay that way
|
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
|
|
|
|
2013-03-19 08:10:07 +08:00
|
|
|
Error jit_error (m_parser->PrepareForExecution (m_jit_start_addr,
|
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
|
|
|
m_jit_end_addr,
|
2013-04-05 10:22:57 +08:00
|
|
|
m_execution_unit_ap,
|
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
|
|
|
exe_ctx,
|
This commit changes the way LLDB executes user
expressions.
Previously, ClangUserExpression assumed that if
there was a constant result for an expression
then it could be determined during parsing. In
particular, the IRInterpreter ran while parser
state (in particular, ClangExpressionDeclMap)
was present. This approach is flawed, because
the IRInterpreter actually is capable of using
external variables, and hence the result might
be different each run. Until now, we papered
over this flaw by re-parsing the expression each
time we ran it.
I have rewritten the IRInterpreter to be
completely independent of the ClangExpressionDeclMap.
Instead of special-casing external variable lookup,
which ties the IRInterpreter closely to LLDB,
we now interpret the exact same IR that the JIT
would see. This IR assumes that materialization
has occurred; hence the recent implementation of the
Materializer, which does not require parser state
(in the form of ClangExpressionDeclMap) to be
present.
Materialization, interpretation, and dematerialization
are now all independent of parsing. This means that
in theory we can parse expressions once and run them
many times. I have three outstanding tasks before
shutting this down:
- First, I will ensure that all of this works with
core files. Core files have a Process but do not
allow allocating memory, which currently confuses
materialization.
- Second, I will make expression breakpoint
conditions remember their ClangUserExpression and
re-use it.
- Third, I will tear out all the redundant code
(for example, materialization logic in
ClangExpressionDeclMap) that is no longer used.
While implementing this fix, I also found a bug in
IRForTarget's handling of floating-point constants.
This should be fixed.
llvm-svn: 179801
2013-04-19 06:06:33 +08:00
|
|
|
can_interpret,
|
This patch modifies the expression parser to allow it
to execute expressions even in the absence of a process.
This allows expressions to run in situations where the
target cannot run -- e.g., to perform calculations based
on type information, or to inspect a binary's static
data.
This modification touches the following files:
lldb-private-enumerations.h
Introduce a new enum specifying the policy for
processing an expression. Some expressions should
always be JITted, for example if they are functions
that will be used over and over again. Some
expressions should always be interpreted, for
example if the target is unsafe to run. For most,
it is acceptable to JIT them, but interpretation
is preferable when possible.
Target.[h,cpp]
Have EvaluateExpression now accept the new enum.
ClangExpressionDeclMap.[cpp,h]
Add support for the IR interpreter and also make
the ClangExpressionDeclMap more robust in the
absence of a process.
ClangFunction.[cpp,h]
Add support for the new enum.
IRInterpreter.[cpp,h]
New implementation.
ClangUserExpression.[cpp,h]
Add support for the new enum, and for running
expressions in the absence of a process.
ClangExpression.h
Remove references to the old DWARF-based method
of evaluating expressions, because it has been
superseded for now.
ClangUtilityFunction.[cpp,h]
Add support for the new enum.
ClangExpressionParser.[cpp,h]
Add support for the new enum, remove references
to DWARF, and add support for checking whether
the expression could be evaluated statically.
IRForTarget.[h,cpp]
Add support for the new enum, and add utility
functions to support the interpreter.
IRToDWARF.cpp
Removed
CommandObjectExpression.cpp
Remove references to the obsolete -i option.
Process.cpp
Modify calls to ClangUserExpression::Evaluate
to pass the correct enum (for dlopen/dlclose)
SBValue.cpp
Add support for the new enum.
SBFrame.cpp
Add support for he new enum.
BreakpointOptions.cpp
Add support for the new enum.
llvm-svn: 139772
2011-09-15 10:13:07 +08:00
|
|
|
eExecutionPolicyAlways));
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
|
|
|
if (!jit_error.Success())
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2013-03-19 08:10:07 +08:00
|
|
|
|
|
|
|
if (process && m_jit_start_addr)
|
2012-09-18 08:08:47 +08:00
|
|
|
m_jit_process_wp = lldb::ProcessWP(process->shared_from_this());
|
2013-01-15 05:45:38 +08:00
|
|
|
|
|
|
|
m_JITted = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::WriteFunctionArguments (ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, Stream &errors)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
return WriteFunctionArguments(exe_ctx, args_addr_ref, m_function_addr, m_arg_values, errors);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Assure that the ValueList we were passed in is consistent with the one that defined this function.
|
|
|
|
|
|
|
|
bool
|
2010-09-11 07:07:48 +08:00
|
|
|
ClangFunction::WriteFunctionArguments (ExecutionContext &exe_ctx,
|
|
|
|
lldb::addr_t &args_addr_ref,
|
|
|
|
Address function_address,
|
|
|
|
ValueList &arg_values,
|
|
|
|
Stream &errors)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
// All the information to reconstruct the struct is provided by the
|
|
|
|
// StructExtractor.
|
|
|
|
if (!m_struct_valid)
|
|
|
|
{
|
|
|
|
errors.Printf("Argument information was not correctly parsed, so the function cannot be called.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Error error;
|
|
|
|
using namespace clang;
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults return_value = eExecutionSetupError;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (process == NULL)
|
|
|
|
return return_value;
|
2011-03-18 04:02:56 +08:00
|
|
|
|
2012-09-18 08:08:47 +08:00
|
|
|
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
|
|
|
|
|
|
|
|
if (process != jit_process_sp.get())
|
2011-03-18 04:02:56 +08:00
|
|
|
return false;
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (args_addr_ref == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
args_addr_ref = process->AllocateMemory(m_struct_size, lldb::ePermissionsReadable|lldb::ePermissionsWritable, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (args_addr_ref == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
m_wrapper_args_addrs.push_back (args_addr_ref);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Make sure this is an address that we've already handed out.
|
|
|
|
if (find (m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), args_addr_ref) == m_wrapper_args_addrs.end())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
// TODO: verify fun_addr needs to be a callable address
|
2011-09-22 12:58:26 +08:00
|
|
|
Scalar fun_addr (function_address.GetCallableLoadAddress(exe_ctx.GetTargetPtr()));
|
2013-01-26 02:06:21 +08:00
|
|
|
uint64_t first_offset = m_member_offsets[0];
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr, process->GetAddressByteSize(), error);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// FIXME: We will need to extend this for Variadic functions.
|
|
|
|
|
|
|
|
Error value_error;
|
|
|
|
|
|
|
|
size_t num_args = arg_values.GetSize();
|
|
|
|
if (num_args != m_arg_values.GetSize())
|
|
|
|
{
|
2011-09-21 05:44:10 +08:00
|
|
|
errors.Printf ("Wrong number of arguments - was: %lu should be: %lu", num_args, m_arg_values.GetSize());
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
for (size_t i = 0; i < num_args; i++)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// FIXME: We should sanity check sizes.
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
uint64_t offset = m_member_offsets[i+1]; // Clang sizes are in bytes.
|
2010-06-09 00:52:24 +08:00
|
|
|
Value *arg_value = arg_values.GetValueAtIndex(i);
|
|
|
|
|
|
|
|
// FIXME: For now just do scalars:
|
|
|
|
|
|
|
|
// Special case: if it's a pointer, don't do anything (the ABI supports passing cstrings)
|
|
|
|
|
|
|
|
if (arg_value->GetValueType() == Value::eValueTypeHostAddress &&
|
2013-07-12 06:46:58 +08:00
|
|
|
arg_value->GetContextType() == Value::eContextTypeInvalid &&
|
|
|
|
arg_value->GetClangType().IsPointerType())
|
2010-06-09 00:52:24 +08:00
|
|
|
continue;
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar, arg_scalar.GetByteSize(), error))
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::InsertFunction (ExecutionContext &exe_ctx, lldb::addr_t &args_addr_ref, Stream &errors)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
if (CompileFunction(errors) != 0)
|
|
|
|
return false;
|
2010-07-27 06:14:36 +08:00
|
|
|
if (!WriteFunctionWrapper(exe_ctx, errors))
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
2010-07-27 06:14:36 +08:00
|
|
|
if (!WriteFunctionArguments(exe_ctx, args_addr_ref, errors))
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", m_jit_start_addr, args_addr_ref);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlan *
|
2010-11-06 03:25:48 +08:00
|
|
|
ClangFunction::GetThreadPlanToCallFunction (ExecutionContext &exe_ctx,
|
|
|
|
lldb::addr_t func_addr,
|
|
|
|
lldb::addr_t &args_addr,
|
|
|
|
Stream &errors,
|
|
|
|
bool stop_others,
|
2013-01-15 10:47:48 +08:00
|
|
|
bool unwind_on_error,
|
|
|
|
bool ignore_breakpoints,
|
2010-12-14 06:46:15 +08:00
|
|
|
lldb::addr_t *this_arg,
|
|
|
|
lldb::addr_t *cmd_arg)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
|
2013-03-07 03:57:25 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("-- [ClangFunction::GetThreadPlanToCallFunction] Creating thread plan to call function --");
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// FIXME: Use the errors Stream for better error reporting.
|
2011-09-22 12:58:26 +08:00
|
|
|
Thread *thread = exe_ctx.GetThreadPtr();
|
|
|
|
if (thread == NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-08-13 05:40:01 +08:00
|
|
|
errors.Printf("Can't call a function without a valid thread.");
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, now run the function:
|
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
Address wrapper_address (func_addr);
|
2011-09-22 12:58:26 +08:00
|
|
|
ThreadPlan *new_plan = new ThreadPlanCallFunction (*thread,
|
2010-12-14 06:46:15 +08:00
|
|
|
wrapper_address,
|
2011-12-23 03:12:40 +08:00
|
|
|
ClangASTType(),
|
2010-12-14 06:46:15 +08:00
|
|
|
args_addr,
|
|
|
|
stop_others,
|
2013-01-15 10:47:48 +08:00
|
|
|
unwind_on_error,
|
|
|
|
ignore_breakpoints,
|
2010-12-14 06:46:15 +08:00
|
|
|
this_arg,
|
|
|
|
cmd_arg);
|
2012-05-12 02:43:38 +08:00
|
|
|
new_plan->SetIsMasterPlan(true);
|
|
|
|
new_plan->SetOkayToDiscard (false);
|
2010-06-09 00:52:24 +08:00
|
|
|
return new_plan;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::FetchFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr, Value &ret_value)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// Read the return value - it is the last field in the struct:
|
|
|
|
// FIXME: How does clang tell us there's no return value? We need to handle that case.
|
2011-12-23 03:12:40 +08:00
|
|
|
// FIXME: Create our ThreadPlanCallFunction with the return ClangASTType, and then use GetReturnValueObject
|
|
|
|
// to fetch the value. That way we can fetch any values we need.
|
2013-03-07 03:57:25 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
|
2013-03-07 03:57:25 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("-- [ClangFunction::FetchFunctionResults] Fetching function results --");
|
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2011-03-18 04:02:56 +08:00
|
|
|
|
|
|
|
if (process == NULL)
|
|
|
|
return false;
|
2012-09-18 08:08:47 +08:00
|
|
|
|
|
|
|
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
|
|
|
|
|
|
|
|
if (process != jit_process_sp.get())
|
2011-03-18 04:02:56 +08:00
|
|
|
return false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Error error;
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory (args_addr + m_return_offset, m_return_size, 0, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:
lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);
bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);
size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);
size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);
in lldb_private::Process the following functions were renamed:
From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr,
size_t byte_size,
Error &error);
To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr,
size_t byte_size,
uint64_t fail_value,
Error &error);
Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.
Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):
uint32_t
Scalar::GetAsMemoryData (void *dst,
uint32_t dst_len,
lldb::ByteOrder dst_byte_order,
Error &error) const;
The "dst_len" can be smaller that the size of the scalar and the least
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes.
Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:
lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;
All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.
Fixed up a lot of places that were calling :
addr_t
Address::GetLoadAddress(Target*);
to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.
llvm-svn: 131878
2011-05-23 06:46:53 +08:00
|
|
|
if (error.Fail())
|
2010-06-09 00:52:24 +08:00
|
|
|
return false;
|
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
ret_value.SetClangType(m_function_return_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
ret_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::DeallocateFunctionResults (ExecutionContext &exe_ctx, lldb::addr_t args_addr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
std::list<lldb::addr_t>::iterator pos;
|
|
|
|
pos = std::find(m_wrapper_args_addrs.begin(), m_wrapper_args_addrs.end(), args_addr);
|
|
|
|
if (pos != m_wrapper_args_addrs.end())
|
|
|
|
m_wrapper_args_addrs.erase(pos);
|
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
exe_ctx.GetProcessRef().DeallocateMemory(args_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::ExecuteFunction(ExecutionContext &exe_ctx, Stream &errors, Value &results)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
return ExecuteFunction (exe_ctx, errors, 1000, true, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults
|
2010-07-27 06:14:36 +08:00
|
|
|
ClangFunction::ExecuteFunction(ExecutionContext &exe_ctx, Stream &errors, bool stop_others, Value &results)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-06 03:25:48 +08:00
|
|
|
const bool try_all_threads = false;
|
2013-01-15 10:47:48 +08:00
|
|
|
const bool unwind_on_error = true;
|
|
|
|
const bool ignore_breakpoints = true;
|
|
|
|
return ExecuteFunction (exe_ctx, NULL, errors, stop_others, 0UL, try_all_threads,
|
|
|
|
unwind_on_error, ignore_breakpoints, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults
|
2010-06-09 00:52:24 +08:00
|
|
|
ClangFunction::ExecuteFunction(
|
2010-07-27 06:14:36 +08:00
|
|
|
ExecutionContext &exe_ctx,
|
2010-06-09 00:52:24 +08:00
|
|
|
Stream &errors,
|
2012-10-17 05:41:58 +08:00
|
|
|
uint32_t timeout_usec,
|
2010-06-09 00:52:24 +08:00
|
|
|
bool try_all_threads,
|
|
|
|
Value &results)
|
|
|
|
{
|
2010-11-06 03:25:48 +08:00
|
|
|
const bool stop_others = true;
|
2013-01-15 10:47:48 +08:00
|
|
|
const bool unwind_on_error = true;
|
|
|
|
const bool ignore_breakpoints = true;
|
2012-10-17 05:41:58 +08:00
|
|
|
return ExecuteFunction (exe_ctx, NULL, errors, stop_others, timeout_usec,
|
2013-01-15 10:47:48 +08:00
|
|
|
try_all_threads, unwind_on_error, ignore_breakpoints, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
// This is the static function
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults
|
2010-07-23 08:16:21 +08:00
|
|
|
ClangFunction::ExecuteFunction (
|
2010-07-27 06:14:36 +08:00
|
|
|
ExecutionContext &exe_ctx,
|
2010-07-23 08:16:21 +08:00
|
|
|
lldb::addr_t function_address,
|
|
|
|
lldb::addr_t &void_arg,
|
|
|
|
bool stop_others,
|
|
|
|
bool try_all_threads,
|
2013-01-15 10:47:48 +08:00
|
|
|
bool unwind_on_error,
|
|
|
|
bool ignore_breakpoints,
|
2012-10-17 05:41:58 +08:00
|
|
|
uint32_t timeout_usec,
|
Removed the hacky "#define this ___clang_this" handler
for C++ classes. Replaced it with a less hacky approach:
- If an expression is defined in the context of a
method of class A, then that expression is wrapped as
___clang_class::___clang_expr(void*) { ... }
instead of ___clang_expr(void*) { ... }.
- ___clang_class is resolved as the type of the target
of the "this" pointer in the method the expression
is defined in.
- When reporting the type of ___clang_class, a method
with the signature ___clang_expr(void*) is added to
that class, so that Clang doesn't complain about a
method being defined without a corresponding
declaration.
- Whenever the expression gets called, "this" gets
looked up, type-checked, and then passed in as the
first argument.
This required the following changes:
- The ABIs were changed to support passing of the "this"
pointer as part of trivial calls.
- ThreadPlanCallFunction and ClangFunction were changed
to support passing of an optional "this" pointer.
- ClangUserExpression was extended to perform the
wrapping described above.
- ClangASTSource was changed to revert the changes
required by the hack.
- ClangExpressionParser, IRForTarget, and
ClangExpressionDeclMap were changed to handle
different manglings of ___clang_expr flexibly. This
meant no longer searching for a function called
___clang_expr, but rather looking for a function whose
name *contains* ___clang_expr.
- ClangExpressionParser and ClangExpressionDeclMap now
remember whether "this" is required, and know how to
look it up as necessary.
A few inheritance bugs remain, and I'm trying to resolve
these. But it is now possible to use "this" as well as
refer implicitly to member variables, when in the proper
context.
llvm-svn: 114384
2010-09-21 08:44:12 +08:00
|
|
|
Stream &errors,
|
|
|
|
lldb::addr_t *this_arg)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP));
|
2013-03-07 03:57:25 +08:00
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf("== [ClangFunction::ExecuteFunction] Executing function ==");
|
|
|
|
|
|
|
|
lldb::ThreadPlanSP call_plan_sp (ClangFunction::GetThreadPlanToCallFunction (exe_ctx,
|
2011-09-22 12:58:26 +08:00
|
|
|
function_address,
|
|
|
|
void_arg,
|
|
|
|
errors,
|
|
|
|
stop_others,
|
2013-01-15 10:47:48 +08:00
|
|
|
unwind_on_error,
|
|
|
|
ignore_breakpoints,
|
2011-09-22 12:58:26 +08:00
|
|
|
this_arg));
|
2012-08-09 08:50:26 +08:00
|
|
|
if (!call_plan_sp)
|
2011-03-25 05:19:54 +08:00
|
|
|
return eExecutionSetupError;
|
2012-12-08 03:04:31 +08:00
|
|
|
|
2012-08-04 06:24:48 +08:00
|
|
|
// <rdar://problem/12027563> we need to make sure we record the fact that we are running an expression here
|
|
|
|
// otherwise this fact will fail to be recorded when fetching an Objective-C object description
|
|
|
|
if (exe_ctx.GetProcessPtr())
|
|
|
|
exe_ctx.GetProcessPtr()->SetRunningUserExpression(true);
|
|
|
|
|
|
|
|
ExecutionResults results = exe_ctx.GetProcessRef().RunThreadPlan (exe_ctx, call_plan_sp,
|
|
|
|
stop_others,
|
|
|
|
try_all_threads,
|
2013-01-15 10:47:48 +08:00
|
|
|
unwind_on_error,
|
|
|
|
ignore_breakpoints,
|
2012-10-17 05:41:58 +08:00
|
|
|
timeout_usec,
|
2012-08-04 06:24:48 +08:00
|
|
|
errors);
|
|
|
|
|
2013-03-07 03:57:25 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
if (results != eExecutionCompleted)
|
|
|
|
{
|
|
|
|
log->Printf("== [ClangFunction::ExecuteFunction] Execution completed abnormally ==");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log->Printf("== [ClangFunction::ExecuteFunction] Execution completed normally ==");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-04 06:24:48 +08:00
|
|
|
if (exe_ctx.GetProcessPtr())
|
|
|
|
exe_ctx.GetProcessPtr()->SetRunningUserExpression(false);
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults
|
2010-07-23 08:16:21 +08:00
|
|
|
ClangFunction::ExecuteFunction(
|
2010-07-27 06:14:36 +08:00
|
|
|
ExecutionContext &exe_ctx,
|
2010-07-23 08:16:21 +08:00
|
|
|
lldb::addr_t *args_addr_ptr,
|
|
|
|
Stream &errors,
|
|
|
|
bool stop_others,
|
2012-10-17 05:41:58 +08:00
|
|
|
uint32_t timeout_usec,
|
2010-11-06 03:25:48 +08:00
|
|
|
bool try_all_threads,
|
2013-01-15 10:47:48 +08:00
|
|
|
bool unwind_on_error,
|
|
|
|
bool ignore_breakpoints,
|
2010-07-23 08:16:21 +08:00
|
|
|
Value &results)
|
|
|
|
{
|
|
|
|
using namespace clang;
|
2011-03-25 05:19:54 +08:00
|
|
|
ExecutionResults return_value = eExecutionSetupError;
|
2010-07-23 08:16:21 +08:00
|
|
|
|
|
|
|
lldb::addr_t args_addr;
|
|
|
|
|
|
|
|
if (args_addr_ptr != NULL)
|
|
|
|
args_addr = *args_addr_ptr;
|
|
|
|
else
|
|
|
|
args_addr = LLDB_INVALID_ADDRESS;
|
|
|
|
|
|
|
|
if (CompileFunction(errors) != 0)
|
2011-03-25 05:19:54 +08:00
|
|
|
return eExecutionSetupError;
|
2010-07-23 08:16:21 +08:00
|
|
|
|
|
|
|
if (args_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
if (!InsertFunction(exe_ctx, args_addr, errors))
|
2011-03-25 05:19:54 +08:00
|
|
|
return eExecutionSetupError;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2011-01-20 07:00:49 +08:00
|
|
|
return_value = ClangFunction::ExecuteFunction (exe_ctx,
|
|
|
|
m_jit_start_addr,
|
|
|
|
args_addr,
|
|
|
|
stop_others,
|
|
|
|
try_all_threads,
|
2013-01-15 10:47:48 +08:00
|
|
|
unwind_on_error,
|
|
|
|
ignore_breakpoints,
|
2012-10-17 05:41:58 +08:00
|
|
|
timeout_usec,
|
2011-01-20 07:00:49 +08:00
|
|
|
errors);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
if (args_addr_ptr != NULL)
|
|
|
|
*args_addr_ptr = args_addr;
|
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
if (return_value != eExecutionCompleted)
|
2010-06-09 00:52:24 +08:00
|
|
|
return return_value;
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
FetchFunctionResults(exe_ctx, args_addr, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (args_addr_ptr == NULL)
|
2010-07-27 06:14:36 +08:00
|
|
|
DeallocateFunctionResults(exe_ctx, args_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-25 05:19:54 +08:00
|
|
|
return eExecutionCompleted;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
clang::ASTConsumer *
|
|
|
|
ClangFunction::ASTTransformer (clang::ASTConsumer *passthrough)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
This is a major refactoring of the expression parser.
The goal is to separate the parser's data from the data
belonging to the parser's clients. This allows clients
to use the parser to obtain (for example) a JIT compiled
function or some DWARF code, and then discard the parser
state.
Previously, parser state was held in ClangExpression and
used liberally by ClangFunction, which inherited from
ClangExpression. The main effects of this refactoring
are:
- reducing ClangExpression to an abstract class that
declares methods that any client must expose to the
expression parser,
- moving the code specific to implementing the "expr"
command from ClangExpression and
CommandObjectExpression into ClangUserExpression,
a new class,
- moving the common parser interaction code from
ClangExpression into ClangExpressionParser, a new
class, and
- making ClangFunction rely only on
ClangExpressionParser and not depend on the
internal implementation of ClangExpression.
Side effects include:
- the compiler interaction code has been factored
out of ClangFunction and is now in an AST pass
(ASTStructExtractor),
- the header file for ClangFunction is now fully
documented,
- several bugs that only popped up when Clang was
deallocated (which never happened, since the
lifetime of the compiler was essentially infinite)
are now fixed, and
- the developer-only "call" command has been
disabled.
I have tested the expr command and the Objective-C
step-into code, which use ClangUserExpression and
ClangFunction, respectively, and verified that they
work. Please let me know if you encounter bugs or
poor documentation.
llvm-svn: 112249
2010-08-27 09:01:44 +08:00
|
|
|
return new ASTStructExtractor(passthrough, m_wrapper_struct_name.c_str(), *this);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|