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"
|
2010-07-03 02:39:06 +08:00
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
|
|
|
#include "llvm/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"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Core/DataExtractor.h"
|
|
|
|
#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"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/StopInfo.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
|
|
|
|
(
|
|
|
|
const char *target_triple,
|
|
|
|
ClangASTContext *ast_context,
|
|
|
|
void *return_qualtype,
|
|
|
|
const Address& functionAddress,
|
|
|
|
const ValueList &arg_value_list
|
|
|
|
) :
|
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_target_triple (target_triple),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_ptr (NULL),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_function_addr (functionAddress),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_return_qual_type(return_qualtype),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_clang_ast_context (ast_context),
|
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_function_addr (),
|
|
|
|
m_wrapper_args_addrs (),
|
|
|
|
m_arg_values (arg_value_list),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_compiled (false),
|
|
|
|
m_JITted (false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-16 06:48:33 +08:00
|
|
|
ClangFunction::ClangFunction
|
|
|
|
(
|
|
|
|
const char *target_triple,
|
|
|
|
Function &function,
|
|
|
|
ClangASTContext *ast_context,
|
|
|
|
const ValueList &arg_value_list
|
|
|
|
) :
|
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_target_triple (target_triple),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_function_ptr (&function),
|
2010-07-10 04:39:50 +08:00
|
|
|
m_function_addr (),
|
|
|
|
m_function_return_qual_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_function_addr (),
|
|
|
|
m_wrapper_args_addrs (),
|
|
|
|
m_arg_values (arg_value_list),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_compiled (false),
|
|
|
|
m_JITted (false)
|
|
|
|
{
|
|
|
|
m_function_addr = m_function_ptr->GetAddressRange().GetBaseAddress();
|
2010-09-29 09:12:09 +08:00
|
|
|
m_function_return_qual_type = m_function_ptr->GetReturnType().GetClangType();
|
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;
|
|
|
|
|
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 return_type_str = ClangASTContext::GetTypeName(m_function_return_qual_type);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
uint32_t num_args = UINT32_MAX;
|
|
|
|
bool trust_function = false;
|
|
|
|
// GetArgumentCount returns -1 for an unprototyped function.
|
|
|
|
if (m_function_ptr)
|
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
|
|
|
int num_func_args = m_function_ptr->GetArgumentCount();
|
|
|
|
if (num_func_args >= 0)
|
|
|
|
trust_function = true;
|
|
|
|
else
|
|
|
|
num_args = num_func_args;
|
|
|
|
}
|
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++)
|
|
|
|
{
|
|
|
|
const char *type_string;
|
|
|
|
std::string type_stdstr;
|
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)
|
|
|
|
{
|
|
|
|
type_string = m_function_ptr->GetArgumentTypeAtIndex(i).GetName().AsCString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Value *arg_value = m_arg_values.GetValueAtIndex(i);
|
2010-09-29 09:12:09 +08:00
|
|
|
void *clang_qual_type = arg_value->GetClangType ();
|
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 (clang_qual_type != NULL)
|
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
|
|
|
type_stdstr = ClangASTContext::GetTypeName(clang_qual_type);
|
|
|
|
type_string = type_stdstr.c_str();
|
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
|
|
|
{
|
|
|
|
errors.Printf("Could not determine type of input value %d.", i);
|
|
|
|
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
|
|
|
|
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 (type_string);
|
|
|
|
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 (" ");
|
|
|
|
args_buffer.append (type_string);
|
|
|
|
snprintf(arg_buf, 31, "arg_%zd", i);
|
|
|
|
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
|
|
|
|
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
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
|
|
|
|
if (log)
|
|
|
|
log->Printf ("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str());
|
|
|
|
|
|
|
|
// Okay, now compile this expression
|
|
|
|
|
|
|
|
m_parser.reset(new ClangExpressionParser(m_target_triple.c_str(), *this));
|
|
|
|
|
|
|
|
num_errors = m_parser->Parse (errors);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
Process *process = exe_ctx.process;
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-08-28 07:31:21 +08:00
|
|
|
lldb::addr_t wrapper_function_end;
|
|
|
|
|
|
|
|
Error jit_error = m_parser->MakeJIT(m_wrapper_function_addr, wrapper_function_end, exe_ctx);
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
ExecutionResults return_value = eExecutionSetupError;
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
Process *process = exe_ctx.process;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (process == NULL)
|
|
|
|
return return_value;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This is fake, and just assumes that it matches that architecture.
|
|
|
|
// Make a data extractor and put the address into the right byte order & size.
|
|
|
|
|
2010-09-15 07:36:40 +08:00
|
|
|
uint64_t fun_addr = function_address.GetLoadAddress(exe_ctx.target);
|
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
|
|
|
int first_offset = m_member_offsets[0];
|
2010-06-09 00:52:24 +08:00
|
|
|
process->WriteMemory(args_addr_ref + first_offset, &fun_addr, 8, error);
|
|
|
|
|
|
|
|
// 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())
|
|
|
|
{
|
|
|
|
errors.Printf ("Wrong number of arguments - was: %d should be: %d", num_args, m_arg_values.GetSize());
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
int 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 &&
|
|
|
|
arg_value->GetContextType() == Value::eContextTypeOpaqueClangQualType &&
|
2010-09-29 09:12:09 +08:00
|
|
|
ClangASTContext::IsPointerType(arg_value->GetClangType()))
|
2010-06-09 00:52:24 +08:00
|
|
|
continue;
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx, m_clang_ast_context->getASTContext());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
int byte_size = arg_scalar.GetByteSize();
|
|
|
|
std::vector<uint8_t> buffer;
|
|
|
|
buffer.resize(byte_size);
|
|
|
|
DataExtractor value_data;
|
|
|
|
arg_scalar.GetData (value_data);
|
2010-07-21 06:52:08 +08:00
|
|
|
value_data.ExtractBytes(0, byte_size, process->GetByteOrder(), &buffer.front());
|
|
|
|
process->WriteMemory(args_addr_ref + offset, &buffer.front(), byte_size, error);
|
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;
|
|
|
|
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
|
|
|
|
if (log)
|
2010-07-10 04:39:50 +08:00
|
|
|
log->Printf ("Call Address: 0x%llx Struct Address: 0x%llx.\n", m_wrapper_function_addr, args_addr_ref);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlan *
|
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
|
|
|
ClangFunction::GetThreadPlanToCallFunction (ExecutionContext &exe_ctx, lldb::addr_t func_addr, lldb::addr_t &args_addr, Stream &errors, bool stop_others, bool discard_on_error, lldb::addr_t *this_arg)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// FIXME: Use the errors Stream for better error reporting.
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
Process *process = exe_ctx.process;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (process == NULL)
|
|
|
|
{
|
|
|
|
errors.Printf("Can't call a function without a process.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, now run the function:
|
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
Address wrapper_address (NULL, func_addr);
|
2010-07-27 06:14:36 +08:00
|
|
|
ThreadPlan *new_plan = new ThreadPlanCallFunction (*exe_ctx.thread,
|
2010-06-09 00:52:24 +08:00
|
|
|
wrapper_address,
|
|
|
|
args_addr,
|
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
|
|
|
stop_others,
|
|
|
|
discard_on_error,
|
|
|
|
this_arg);
|
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.
|
|
|
|
|
|
|
|
std::vector<uint8_t> data_buffer;
|
|
|
|
data_buffer.resize(m_return_size);
|
2010-07-27 06:14:36 +08:00
|
|
|
Process *process = exe_ctx.process;
|
2010-06-09 00:52:24 +08:00
|
|
|
Error error;
|
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
|
|
|
size_t bytes_read = process->ReadMemory(args_addr + m_return_offset, &data_buffer.front(), m_return_size, error);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (bytes_read == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes_read < m_return_size)
|
|
|
|
return false;
|
|
|
|
|
2010-07-21 06:52:08 +08:00
|
|
|
DataExtractor data(&data_buffer.front(), m_return_size, process->GetByteOrder(), process->GetAddressByteSize());
|
2010-06-09 00:52:24 +08:00
|
|
|
// FIXME: Assuming an integer scalar for now:
|
|
|
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
uint64_t return_integer = data.GetMaxU64(&offset, m_return_size);
|
|
|
|
|
|
|
|
ret_value.SetContext (Value::eContextTypeOpaqueClangQualType, m_function_return_qual_type);
|
|
|
|
ret_value.SetValueType(Value::eValueTypeScalar);
|
|
|
|
ret_value.GetScalar() = return_integer;
|
|
|
|
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);
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
exe_ctx.process->DeallocateMemory(args_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClangFunction::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
|
|
|
}
|
|
|
|
|
|
|
|
ClangFunction::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-07-27 06:14:36 +08:00
|
|
|
return ExecuteFunction (exe_ctx, NULL, errors, stop_others, NULL, false, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClangFunction::ExecutionResults
|
|
|
|
ClangFunction::ExecuteFunction(
|
2010-07-27 06:14:36 +08:00
|
|
|
ExecutionContext &exe_ctx,
|
2010-06-09 00:52:24 +08:00
|
|
|
Stream &errors,
|
|
|
|
uint32_t single_thread_timeout_usec,
|
|
|
|
bool try_all_threads,
|
|
|
|
Value &results)
|
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
return ExecuteFunction (exe_ctx, NULL, errors, true, single_thread_timeout_usec, try_all_threads, results);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
// This is the static function
|
|
|
|
ClangFunction::ExecutionResults
|
|
|
|
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,
|
|
|
|
uint32_t single_thread_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
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
// Save this value for restoration of the execution context after we run
|
2010-09-11 07:07:48 +08:00
|
|
|
uint32_t tid = exe_ctx.thread->GetIndexID();
|
2010-07-27 06:14:36 +08:00
|
|
|
|
2010-09-11 07:07:48 +08:00
|
|
|
// N.B. Running the target may unset the currently selected thread and frame. We don't want to do that either,
|
|
|
|
// so we should arrange to reset them as well.
|
|
|
|
|
|
|
|
lldb::ThreadSP selected_thread_sp = exe_ctx.process->GetThreadList().GetSelectedThread();
|
|
|
|
lldb::StackFrameSP selected_frame_sp;
|
|
|
|
|
|
|
|
uint32_t selected_tid;
|
|
|
|
if (selected_thread_sp != NULL)
|
|
|
|
{
|
|
|
|
selected_tid = selected_thread_sp->GetIndexID();
|
|
|
|
selected_frame_sp = selected_thread_sp->GetSelectedFrame();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selected_tid = LLDB_INVALID_THREAD_ID;
|
|
|
|
}
|
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
ClangFunction::ExecutionResults return_value = eExecutionSetupError;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
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
|
|
|
lldb::ThreadPlanSP call_plan_sp(ClangFunction::GetThreadPlanToCallFunction(exe_ctx, function_address, void_arg, errors, stop_others, false, this_arg));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
ThreadPlanCallFunction *call_plan_ptr = static_cast<ThreadPlanCallFunction *> (call_plan_sp.get());
|
|
|
|
|
|
|
|
if (call_plan_sp == NULL)
|
2010-07-23 08:16:21 +08:00
|
|
|
return eExecutionSetupError;
|
|
|
|
|
2010-09-09 04:04:08 +08:00
|
|
|
//#define SINGLE_STEP_EXPRESSIONS
|
|
|
|
|
|
|
|
#ifdef SINGLE_STEP_EXPRESSIONS
|
|
|
|
return eExecutionInterrupted;
|
|
|
|
#else
|
2010-06-09 00:52:24 +08:00
|
|
|
call_plan_sp->SetPrivate(true);
|
2010-07-27 06:14:36 +08:00
|
|
|
exe_ctx.thread->QueueThreadPlan(call_plan_sp, true);
|
2010-09-09 04:04:08 +08:00
|
|
|
#endif
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// We need to call the function synchronously, so spin waiting for it to return.
|
|
|
|
// If we get interrupted while executing, we're going to lose our context, and
|
|
|
|
// won't be able to gather the result at this point.
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
TimeValue* timeout_ptr = NULL;
|
|
|
|
TimeValue real_timeout;
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (single_thread_timeout_usec != 0)
|
|
|
|
{
|
|
|
|
real_timeout = TimeValue::Now();
|
|
|
|
real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec);
|
|
|
|
timeout_ptr = &real_timeout;
|
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-10-12 07:53:14 +08:00
|
|
|
Listener listener("ClangFunction temporary listener");
|
|
|
|
exe_ctx.process->HijackProcessEvents(&listener);
|
|
|
|
|
2010-08-17 08:35:35 +08:00
|
|
|
Error resume_error = exe_ctx.process->Resume ();
|
|
|
|
if (!resume_error.Success())
|
|
|
|
{
|
|
|
|
errors.Printf("Error resuming inferior: \"%s\".\n", resume_error.AsCString());
|
|
|
|
return eExecutionSetupError;
|
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
lldb::EventSP event_sp;
|
2010-10-12 07:53:14 +08:00
|
|
|
lldb::StateType stop_state = lldb::eStateInvalid;
|
2010-06-09 00:52:24 +08:00
|
|
|
// Now wait for the process to stop again:
|
2010-10-12 07:53:14 +08:00
|
|
|
bool got_event = listener.WaitForEvent (timeout_ptr, event_sp);
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-10-12 07:53:14 +08:00
|
|
|
if (!got_event)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// Right now this is the only way to tell we've timed out...
|
|
|
|
// We should interrupt the process here...
|
|
|
|
// Not really sure what to do if Halt fails here...
|
|
|
|
if (log)
|
2010-09-11 07:07:48 +08:00
|
|
|
if (try_all_threads)
|
2010-10-15 07:45:03 +08:00
|
|
|
log->Printf ("Running function with timeout: %d timed out, trying with all threads enabled.",
|
|
|
|
single_thread_timeout_usec);
|
2010-09-11 07:07:48 +08:00
|
|
|
else
|
2010-10-15 07:45:03 +08:00
|
|
|
log->Printf ("Running function with timeout: %d timed out, abandoning execution.",
|
|
|
|
single_thread_timeout_usec);
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
if (exe_ctx.process->Halt().Success())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
timeout_ptr = NULL;
|
|
|
|
|
2010-10-12 07:53:14 +08:00
|
|
|
got_event = listener.WaitForEvent (timeout_ptr, event_sp);
|
|
|
|
stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (stop_state == lldb::eStateInvalid)
|
|
|
|
{
|
|
|
|
errors.Printf ("Got an invalid stop state after halt.");
|
|
|
|
}
|
|
|
|
else if (stop_state != lldb::eStateStopped)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
event_sp->Dump (&s);
|
|
|
|
|
|
|
|
errors.Printf("Didn't get a stopped event after Halting the target, got: \"%s\"", s.GetData());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (try_all_threads)
|
|
|
|
{
|
|
|
|
// Between the time that we got the timeout and the time we halted, but target
|
|
|
|
// might have actually completed the plan. If so, we're done.
|
2010-07-27 06:14:36 +08:00
|
|
|
if (exe_ctx.thread->IsThreadPlanDone (call_plan_sp.get()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return_value = eExecutionCompleted;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
call_plan_ptr->SetStopOthers (false);
|
2010-07-27 06:14:36 +08:00
|
|
|
exe_ctx.process->Resume();
|
2010-06-09 00:52:24 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
2010-10-12 07:53:14 +08:00
|
|
|
{
|
|
|
|
exe_ctx.process->RestoreProcessEvents ();
|
2010-06-09 00:52:24 +08:00
|
|
|
return eExecutionInterrupted;
|
2010-10-12 07:53:14 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-12 07:53:14 +08:00
|
|
|
|
|
|
|
stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get());
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (stop_state == lldb::eStateRunning || stop_state == lldb::eStateStepping)
|
|
|
|
continue;
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
if (exe_ctx.thread->IsThreadPlanDone (call_plan_sp.get()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return_value = eExecutionCompleted;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-27 06:14:36 +08:00
|
|
|
else if (exe_ctx.thread->WasThreadPlanDiscarded (call_plan_sp.get()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
return_value = eExecutionDiscarded;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-23 08:16:21 +08:00
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
StreamString s;
|
|
|
|
event_sp->Dump (&s);
|
|
|
|
StreamString ts;
|
|
|
|
|
|
|
|
const char *event_explanation;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const Process::ProcessEventData *event_data = Process::ProcessEventData::GetEventDataFromEvent (event_sp.get());
|
|
|
|
|
|
|
|
if (!event_data)
|
|
|
|
{
|
|
|
|
event_explanation = "<no event data>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Process *process = event_data->GetProcessSP().get();
|
|
|
|
|
|
|
|
if (!process)
|
|
|
|
{
|
|
|
|
event_explanation = "<no process>";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadList &thread_list = process->GetThreadList();
|
|
|
|
|
|
|
|
uint32_t num_threads = thread_list.GetSize();
|
|
|
|
uint32_t thread_index;
|
|
|
|
|
|
|
|
ts.Printf("<%u threads> ", num_threads);
|
|
|
|
|
|
|
|
for (thread_index = 0;
|
|
|
|
thread_index < num_threads;
|
|
|
|
++thread_index)
|
|
|
|
{
|
|
|
|
Thread *thread = thread_list.GetThreadAtIndex(thread_index).get();
|
|
|
|
|
|
|
|
if (!thread)
|
|
|
|
{
|
|
|
|
ts.Printf("<?> ");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts.Printf("<");
|
|
|
|
RegisterContext *register_context = thread->GetRegisterContext();
|
|
|
|
|
|
|
|
if (register_context)
|
|
|
|
ts.Printf("[ip 0x%llx] ", register_context->GetPC());
|
|
|
|
else
|
|
|
|
ts.Printf("[ip unknown] ");
|
|
|
|
|
2010-10-20 08:39:53 +08:00
|
|
|
lldb::StopInfoSP stop_info_sp = thread->GetStopInfo();
|
|
|
|
if (stop_info_sp)
|
2010-08-04 09:40:35 +08:00
|
|
|
{
|
2010-10-20 08:39:53 +08:00
|
|
|
const char *stop_desc = stop_info_sp->GetDescription();
|
2010-08-04 09:40:35 +08:00
|
|
|
if (stop_desc)
|
|
|
|
ts.PutCString (stop_desc);
|
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
ts.Printf(">");
|
|
|
|
}
|
|
|
|
|
|
|
|
event_explanation = ts.GetData();
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation);
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return_value = eExecutionInterrupted;
|
|
|
|
break;
|
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
}
|
|
|
|
|
2010-10-12 07:53:14 +08:00
|
|
|
if (exe_ctx.process)
|
|
|
|
exe_ctx.process->RestoreProcessEvents ();
|
|
|
|
|
2010-07-27 06:14:36 +08:00
|
|
|
// Thread we ran the function in may have gone away because we ran the target
|
|
|
|
// Check that it's still there.
|
2010-09-11 07:07:48 +08:00
|
|
|
exe_ctx.thread = exe_ctx.process->GetThreadList().FindThreadByIndexID(tid, true).get();
|
2010-09-30 08:54:27 +08:00
|
|
|
if (exe_ctx.thread)
|
|
|
|
exe_ctx.frame = exe_ctx.thread->GetStackFrameAtIndex(0).get();
|
2010-07-27 06:14:36 +08:00
|
|
|
|
2010-09-11 07:07:48 +08:00
|
|
|
// Also restore the current process'es selected frame & thread, since this function calling may
|
|
|
|
// be done behind the user's back.
|
|
|
|
|
|
|
|
if (selected_tid != LLDB_INVALID_THREAD_ID)
|
|
|
|
{
|
|
|
|
if (exe_ctx.process->GetThreadList().SetSelectedThreadByIndexID (selected_tid))
|
|
|
|
{
|
|
|
|
// We were able to restore the selected thread, now restore the frame:
|
|
|
|
exe_ctx.process->GetThreadList().GetSelectedThread()->SetSelectedFrame(selected_frame_sp.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
return return_value;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-07-23 08:16:21 +08:00
|
|
|
ClangFunction::ExecutionResults
|
|
|
|
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,
|
|
|
|
uint32_t single_thread_timeout_usec,
|
|
|
|
bool try_all_threads,
|
|
|
|
Value &results)
|
|
|
|
{
|
|
|
|
using namespace clang;
|
|
|
|
ExecutionResults return_value = eExecutionSetupError;
|
|
|
|
|
|
|
|
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)
|
|
|
|
return eExecutionSetupError;
|
|
|
|
|
|
|
|
if (args_addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
2010-07-27 06:14:36 +08:00
|
|
|
if (!InsertFunction(exe_ctx, args_addr, errors))
|
2010-07-23 08:16:21 +08:00
|
|
|
return eExecutionSetupError;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-07-23 08:16:21 +08:00
|
|
|
|
2010-09-11 07:07:48 +08:00
|
|
|
return_value = ClangFunction::ExecuteFunction(exe_ctx, m_wrapper_function_addr, args_addr, stop_others,
|
|
|
|
try_all_threads, single_thread_timeout_usec, 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;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (return_value != eExecutionCompleted)
|
|
|
|
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
|
|
|
|
|
|
|
return eExecutionCompleted;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|