[Lldb-commits] [lldb] r116634 - in /lldb/trunk: include/lldb/Core/ include/lldb/Expression/ source/Core/ source/Expression/
Greg Clayton
gclayton at apple.com
Fri Oct 15 15:48:33 PDT 2010
Author: gclayton
Date: Fri Oct 15 17:48:33 2010
New Revision: 116634
URL: http://llvm.org/viewvc/llvm-project?rev=116634&view=rev
Log:
Made many ConstString functions inlined in the header file.
Changed all of our synthesized "___clang" functions, types and variables
that get used in expressions over to have a prefix of "$_lldb". Now when we
do name lookups we can easily switch off of the first '$' character to know
if we should look through only our internal (when first char is '$') stuff,
or when we should look through program variables, functions and types.
Converted all of the clang expression code over to using "const ConstString&"
values for names instead of "const char *" since there were many places that
were converting the "const char *" names into ConstString names and them
throwing them away. We now avoid making a lot of ConstString conversions and
benefit from the quick comparisons in a few extra spots.
Converted a lot of code from LLVM coding conventions into LLDB coding
conventions.
Modified:
lldb/trunk/include/lldb/Core/ConstString.h
lldb/trunk/include/lldb/Expression/ASTResultSynthesizer.h
lldb/trunk/include/lldb/Expression/ASTStructExtractor.h
lldb/trunk/include/lldb/Expression/ClangASTSource.h
lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h
lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h
lldb/trunk/include/lldb/Expression/ClangUserExpression.h
lldb/trunk/include/lldb/Expression/IRDynamicChecks.h
lldb/trunk/include/lldb/Expression/IRForTarget.h
lldb/trunk/include/lldb/Expression/IRToDWARF.h
lldb/trunk/source/Core/ConstString.cpp
lldb/trunk/source/Expression/ASTResultSynthesizer.cpp
lldb/trunk/source/Expression/ClangASTSource.cpp
lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
lldb/trunk/source/Expression/ClangExpressionParser.cpp
lldb/trunk/source/Expression/ClangExpressionVariable.cpp
lldb/trunk/source/Expression/ClangFunction.cpp
lldb/trunk/source/Expression/ClangPersistentVariables.cpp
lldb/trunk/source/Expression/ClangUserExpression.cpp
lldb/trunk/source/Expression/IRDynamicChecks.cpp
lldb/trunk/source/Expression/IRForTarget.cpp
Modified: lldb/trunk/include/lldb/Core/ConstString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ConstString.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ConstString.h (original)
+++ lldb/trunk/include/lldb/Core/ConstString.h Fri Oct 15 17:48:33 2010
@@ -122,7 +122,7 @@
};
//------------------------------------------------------------------
- /// Convert to pointer operator.
+ /// Convert to bool operator.
///
/// This allows code to check a ConstString object to see if it
/// contains a valid string using code such as:
@@ -137,8 +137,10 @@
/// A pointer to this object if the string isn't empty, NULL
/// otherwise.
//------------------------------------------------------------------
- operator void*() const;
-
+ operator bool() const
+ {
+ return m_string && m_string[0];
+ }
//------------------------------------------------------------------
/// Assignment operator
@@ -157,7 +159,11 @@
/// A const reference to this object.
//------------------------------------------------------------------
const ConstString&
- operator = (const ConstString& rhs);
+ operator = (const ConstString& rhs)
+ {
+ m_string = rhs.m_string;
+ return *this;
+ }
//------------------------------------------------------------------
/// Equal to operator
@@ -175,7 +181,12 @@
/// @li \b false if this object is not equal to \a rhs.
//------------------------------------------------------------------
bool
- operator == (const ConstString& rhs) const;
+ operator == (const ConstString& rhs) const
+ {
+ // We can do a pointer compare to compare these strings since they
+ // must come from the same pool in order to be equal.
+ return m_string == rhs.m_string;
+ }
//------------------------------------------------------------------
/// Not equal to operator
@@ -193,7 +204,10 @@
/// @li \b false if this object is equal to \a rhs.
//------------------------------------------------------------------
bool
- operator != (const ConstString& rhs) const;
+ operator != (const ConstString& rhs) const
+ {
+ return m_string != rhs.m_string;
+ }
bool
operator < (const ConstString& rhs) const;
@@ -211,11 +225,19 @@
/// the C string value contained in this object.
//------------------------------------------------------------------
const char *
- AsCString(const char *value_if_empty = NULL) const;
-
+ AsCString(const char *value_if_empty = NULL) const
+ {
+ if (m_string == NULL)
+ return value_if_empty;
+ return m_string;
+ }
const char *
- GetCString () const;
+ GetCString () const
+ {
+ return m_string;
+ }
+
size_t
GetLength () const;
@@ -230,7 +252,10 @@
/// count reaches zero.
//------------------------------------------------------------------
void
- Clear ();
+ Clear ()
+ {
+ m_string = NULL;
+ }
//------------------------------------------------------------------
/// Compare two string objects.
Modified: lldb/trunk/include/lldb/Expression/ASTResultSynthesizer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ASTResultSynthesizer.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ASTResultSynthesizer.h (original)
+++ lldb/trunk/include/lldb/Expression/ASTResultSynthesizer.h Fri Oct 15 17:48:33 2010
@@ -22,7 +22,7 @@
/// Users expect the expression "i + 3" to return a result, even if a result
/// variable wasn't specifically declared. To fulfil this requirement, LLDB adds
/// a result variable to the expression, transforming it to
-/// "int ___clang_expr_result = i + 3." The IR transformers ensure that the
+/// "int $__lldb_expr_result = i + 3." The IR transformers ensure that the
/// resulting variable is mapped to the right piece of memory.
/// ASTResultSynthesizer's job is to add the variable and its initialization to
/// the ASTs for the expression, and it does so by acting as a SemaConsumer for
@@ -57,7 +57,7 @@
void Initialize(clang::ASTContext &Context);
//----------------------------------------------------------------------
- /// Examine a list of Decls to find the function ___clang_expr and
+ /// Examine a list of Decls to find the function $__lldb_expr and
/// transform its code
///
/// @param[in] D
@@ -107,7 +107,7 @@
void ForgetSema();
private:
//----------------------------------------------------------------------
- /// Hunt the given Decl for FunctionDecls named ___clang_expr, recursing
+ /// Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing
/// as necessary through LinkageSpecDecls, and calling SynthesizeResult on
/// anything that was found
///
Modified: lldb/trunk/include/lldb/Expression/ASTStructExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ASTStructExtractor.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ASTStructExtractor.h (original)
+++ lldb/trunk/include/lldb/Expression/ASTStructExtractor.h Fri Oct 15 17:48:33 2010
@@ -71,7 +71,7 @@
void Initialize(clang::ASTContext &Context);
//----------------------------------------------------------------------
- /// Examine a list of Decls to find the function ___clang_expr and
+ /// Examine a list of Decls to find the function $__lldb_expr and
/// transform its code
///
/// @param[in] D
Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Fri Oct 15 17:48:33 2010
@@ -29,8 +29,8 @@
/// the actual lookups.
//----------------------------------------------------------------------
class ClangASTSource : public clang::ExternalSemaSource {
- clang::ASTContext &Context; ///< The parser's AST context, for copying types into
- ClangExpressionDeclMap &DeclMap; ///< The object that looks up named entities in LLDB
+ clang::ASTContext &m_ast_context; ///< The parser's AST context, for copying types into
+ ClangExpressionDeclMap &m_decl_map; ///< The object that looks up named entities in LLDB
public:
friend struct NameSearchContext;
@@ -46,9 +46,11 @@
/// A reference to the LLDB object that handles entity lookup.
//------------------------------------------------------------------
ClangASTSource(clang::ASTContext &context,
- ClangExpressionDeclMap &declMap) :
- Context(context),
- DeclMap(declMap) {}
+ ClangExpressionDeclMap &decl_map) :
+ m_ast_context(context),
+ m_decl_map(decl_map)
+ {
+ }
//------------------------------------------------------------------
/// Destructor
@@ -123,10 +125,10 @@
/// Decls given appropriate type information.
//----------------------------------------------------------------------
struct NameSearchContext {
- ClangASTSource &ASTSource; ///< The AST source making the request
- llvm::SmallVectorImpl<clang::NamedDecl*> &Decls; ///< The list of declarations already constructed
- clang::DeclarationName &Name; ///< The name being looked for
- const clang::DeclContext *DC; ///< The DeclContext to put declarations into
+ ClangASTSource &m_ast_source; ///< The AST source making the request
+ llvm::SmallVectorImpl<clang::NamedDecl*> &m_decls; ///< The list of declarations already constructed
+ const clang::DeclarationName &m_decl_name; ///< The name being looked for
+ const clang::DeclContext *m_decl_context; ///< The DeclContext to put declarations into
//------------------------------------------------------------------
/// Constructor
@@ -150,10 +152,10 @@
llvm::SmallVectorImpl<clang::NamedDecl*> &decls,
clang::DeclarationName &name,
const clang::DeclContext *dc) :
- ASTSource(astSource),
- Decls(decls),
- Name(name),
- DC(dc) {}
+ m_ast_source(astSource),
+ m_decls(decls),
+ m_decl_name(name),
+ m_decl_context(dc) {}
//------------------------------------------------------------------
/// Return the AST context for the current search. Useful when copying
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Fri Oct 15 17:48:33 2010
@@ -24,6 +24,8 @@
#include "lldb/Core/Value.h"
#include "lldb/Expression/ClangExpressionVariable.h"
#include "lldb/Symbol/TaggedASTType.h"
+#include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Target/ExecutionContext.h"
namespace llvm {
class Type;
@@ -88,7 +90,8 @@
/// @param[in] name
/// The std::string to place the name into.
//------------------------------------------------------------------
- void GetPersistentResultName (std::string &name);
+ const ConstString &
+ GetPersistentResultName ();
//------------------------------------------------------------------
/// [Used by IRForTarget] Add a variable to the list of persistent
@@ -108,7 +111,7 @@
/// True on success; false otherwise.
//------------------------------------------------------------------
bool AddPersistentVariable (const clang::NamedDecl *decl,
- const char *name,
+ const ConstString &name,
TypeFromParser type);
//------------------------------------------------------------------
@@ -134,7 +137,7 @@
/// True on success; false otherwise.
//------------------------------------------------------------------
bool AddValueToStruct (const clang::NamedDecl *decl,
- const char *name,
+ const ConstString &name,
llvm::Value *value,
size_t size,
off_t alignment);
@@ -175,7 +178,7 @@
/// @param[out] decl
/// The parsed Decl for the field, as generated by ClangASTSource
/// on ClangExpressionDeclMap's behalf. In the case of the result
- /// value, this will have the name ___clang_result even if the
+ /// value, this will have the name $__lldb_result even if the
/// result value ends up having the name $1. This is an
/// implementation detail of IRForTarget.
///
@@ -202,7 +205,7 @@
bool GetStructElement (const clang::NamedDecl *&decl,
llvm::Value *&value,
off_t &offset,
- const char *&name,
+ ConstString &name,
uint32_t index);
//------------------------------------------------------------------
@@ -242,7 +245,7 @@
/// @return
/// True if the address could be retrieved; false otherwise.
//------------------------------------------------------------------
- bool GetFunctionAddress (const char *name,
+ bool GetFunctionAddress (const ConstString &name,
uint64_t &ptr);
//------------------------------------------------------------------
@@ -348,20 +351,34 @@
/// True on success; false otherwise.
//------------------------------------------------------------------
void GetDecls (NameSearchContext &context,
- const char *name);
+ const ConstString &name);
+
+ bool
+ GetLookupsEnabled ()
+ {
+ return m_enable_lookups;
+ }
+
+ void
+ SetLookupsEnabled (bool b)
+ {
+ m_enable_lookups = b;
+ }
+
private:
ClangExpressionVariableStore m_found_entities; ///< All entities that were looked up for the parser.
ClangExpressionVariableList m_struct_members; ///< All entities that need to be placed in the struct.
- ExecutionContext *m_exe_ctx; ///< The execution context where this expression was first defined. It determines types for all the external variables, even if the expression is re-used.
- SymbolContext *m_sym_ctx; ///< [owned by ClangExpressionDeclMap] The symbol context where this expression was first defined.
+ ExecutionContext m_exe_ctx; ///< The execution context where this expression was first defined. It determines types for all the external variables, even if the expression is re-used.
+ SymbolContext m_sym_ctx; ///< [owned by ClangExpressionDeclMap] The symbol context where this expression was first defined.
ClangPersistentVariables *m_persistent_vars; ///< The list of persistent variables to use when resolving symbols in the expression and when creating new ones (like the result).
off_t m_struct_alignment; ///< The alignment of the struct in bytes.
size_t m_struct_size; ///< The size of the struct in bytes.
bool m_struct_laid_out; ///< True if the struct has been laid out and the layout is valid (that is, no new fields have been added since).
+ bool m_enable_lookups; ///< Set to true during expression evaluation if we have found the first "$__lldb" name.
lldb::addr_t m_allocated_area; ///< The base of the memory allocated for the struct. Starts on a potentially unaligned address and may therefore be larger than the struct.
lldb::addr_t m_materialized_location; ///< The address at which the struct is placed. Falls inside the allocated area.
- std::string m_result_name; ///< The name of the result variable ($1, for example)
+ ConstString m_result_name; ///< The name of the result variable ($1, for example)
TypeFromUser m_object_pointer_type; ///< The type of the "this" variable, if one exists.
llvm::DenseMap <const char*, bool> m_lookedup_types; ///< Contains each type that has been looked up in the current type lookup stack.
@@ -395,7 +412,7 @@
/// The LLDB Variable found, or NULL if none was found.
//------------------------------------------------------------------
Variable *FindVariableInScope(StackFrame &frame,
- const char *name,
+ const ConstString &name,
TypeFromUser *type = NULL);
//------------------------------------------------------------------
@@ -487,7 +504,7 @@
/// The type that needs to be created.
///
/// @param[in] add_method
- /// True if a method with signature void ___clang_expr(void*)
+ /// True if a method with signature void $__lldb_expr(void*)
/// should be added to the C++ class type passed in
//------------------------------------------------------------------
void AddOneType(NameSearchContext &context,
@@ -549,7 +566,7 @@
//------------------------------------------------------------------
bool DoMaterializeOnePersistentVariable(bool dematerialize,
ExecutionContext &exe_ctx,
- const char *name,
+ const ConstString &name,
lldb::addr_t addr,
Error &err);
@@ -586,7 +603,7 @@
bool DoMaterializeOneVariable(bool dematerialize,
ExecutionContext &exe_ctx,
const SymbolContext &sym_ctx,
- const char *name,
+ const ConstString &name,
TypeFromUser type,
lldb::addr_t addr,
Error &err);
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h Fri Oct 15 17:48:33 2010
@@ -21,6 +21,7 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ClangForward.h"
+#include "lldb/Core/ConstString.h"
#include "lldb/Symbol/TaggedASTType.h"
namespace llvm {
@@ -88,7 +89,7 @@
//----------------------------------------------------------------------
/// The following values should stay valid for the life of the variable
//----------------------------------------------------------------------
- std::string m_name; ///< The name of the variable
+ ConstString m_name; ///< The name of the variable
TypeFromUser m_user_type; ///< The type of the variable according to some LLDB context;
///< NULL if the type hasn't yet been migrated to one
@@ -231,12 +232,12 @@
/// @return
/// The variable requested, or NULL if that variable is not in the list.
//----------------------------------------------------------------------
- ClangExpressionVariable *GetVariable (const char *name)
+ ClangExpressionVariable *GetVariable (const ConstString &name)
{
for (uint64_t index = 0, size = Size(); index < size; ++index)
{
ClangExpressionVariable &candidate (VariableAtIndex(index));
- if (!candidate.m_name.compare(name))
+ if (candidate.m_name == name)
return &candidate;
}
return NULL;
Modified: lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangPersistentVariables.h Fri Oct 15 17:48:33 2010
@@ -33,17 +33,19 @@
/// @param[in] name
/// A string to place the variable name in.
//----------------------------------------------------------------------
- void GetNextResultName (std::string &name);
+ void
+ GetNextResultName (ConstString &name);
//----------------------------------------------------------------------
/// Constructor
//----------------------------------------------------------------------
ClangPersistentVariables ();
- bool CreatePersistentVariable(const char *name,
- TypeFromUser user_type);
+ bool
+ CreatePersistentVariable (const ConstString &name,
+ TypeFromUser user_type);
private:
- uint64_t m_result_counter; ///< The counter used by GetNextResultName().
+ uint64_t m_result_counter; ///< The counter used by GetNextResultName().
};
}
Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Fri Oct 15 17:48:33 2010
@@ -128,7 +128,7 @@
const char *
FunctionName ()
{
- return "___clang_expr";
+ return "$__lldb_expr";
}
//------------------------------------------------------------------
Modified: lldb/trunk/include/lldb/Expression/IRDynamicChecks.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRDynamicChecks.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRDynamicChecks.h (original)
+++ lldb/trunk/include/lldb/Expression/IRDynamicChecks.h Fri Oct 15 17:48:33 2010
@@ -105,8 +105,8 @@
/// The mapping used to look up entities in the target process. In
/// this case, used to find objc_msgSend
//------------------------------------------------------------------
- IRDynamicChecks(DynamicCheckerFunctions &checker_functions,
- const char* func_name = "___clang_expr");
+ IRDynamicChecks (DynamicCheckerFunctions &checker_functions,
+ const char* func_name = "$__lldb_expr");
//------------------------------------------------------------------
/// Destructor
@@ -118,7 +118,7 @@
///
/// @param[in] M
/// The module to run on. This module is searched for the function
- /// ___clang_expr, and that function is passed to the passes one by
+ /// $__lldb_expr, and that function is passed to the passes one by
/// one.
///
/// @return
Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRForTarget.h (original)
+++ lldb/trunk/include/lldb/Expression/IRForTarget.h Fri Oct 15 17:48:33 2010
@@ -61,7 +61,7 @@
//------------------------------------------------------------------
IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map,
bool resolve_vars,
- const char* func_name = "___clang_expr");
+ const char* func_name = "$__lldb_expr");
//------------------------------------------------------------------
/// Destructor
@@ -73,7 +73,7 @@
///
/// @param[in] M
/// The module to run on. This module is searched for the function
- /// ___clang_expr, and that function is passed to the passes one by
+ /// $__lldb_expr, and that function is passed to the passes one by
/// one.
///
/// @return
@@ -94,7 +94,7 @@
private:
//------------------------------------------------------------------
/// A function-level pass to take the generated global value
- /// ___clang_expr_result and make it into a persistent variable.
+ /// $__lldb_expr_result and make it into a persistent variable.
/// Also see ASTResultSynthesizer.
//------------------------------------------------------------------
Modified: lldb/trunk/include/lldb/Expression/IRToDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRToDWARF.h?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRToDWARF.h (original)
+++ lldb/trunk/include/lldb/Expression/IRToDWARF.h Fri Oct 15 17:48:33 2010
@@ -67,7 +67,7 @@
IRToDWARF(lldb_private::ClangExpressionVariableStore &local_vars,
lldb_private::ClangExpressionDeclMap *decl_map,
lldb_private::StreamString &strm,
- const char* func_name = "___clang_expr");
+ const char* func_name = "$__lldb_expr");
//------------------------------------------------------------------
/// Destructor
@@ -79,7 +79,7 @@
///
/// @param[in] M
/// The module to run on. This module is searched for the function
- /// ___clang_expr, and that function is converted to a location
+ /// $__lldb_expr, and that function is converted to a location
/// expression.
///
/// @return
Modified: lldb/trunk/source/Core/ConstString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConstString.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Core/ConstString.cpp (original)
+++ lldb/trunk/source/Core/ConstString.cpp Fri Oct 15 17:48:33 2010
@@ -213,58 +213,6 @@
{
}
-//----------------------------------------------------------------------
-// Convert to pointer operator. This allows code to check any
-// ConstString objects to see if they contain anything (not empty)
-// valid using code such as:
-//
-// ConstString str(...);
-// if (str)
-// { ...
-//----------------------------------------------------------------------
-ConstString::operator void*() const
-{
- return IsEmpty() ? NULL : const_cast<ConstString*>(this);
-}
-
-//----------------------------------------------------------------------
-// Assignment operator
-//
-// Assigns the string in this object with the value from "rhs"
-// and increments the reference count of that string.
-//
-// The previously contained string will be get its reference count
-// decremented and removed from the string pool if its reference
-// count reaches zero.
-//----------------------------------------------------------------------
-const ConstString&
-ConstString::operator=(const ConstString& rhs)
-{
- m_string = rhs.m_string;
- return *this;
-}
-
-//----------------------------------------------------------------------
-// Equal to operator
-//
-// Returns true if this string is equal to that in "rhs". This is
-// very fast as it results in a pointer comparison since all strings
-// are in a uniqued and reference counted string pool.
-//------------------------------------------------------------------
-bool
-ConstString::operator == (const ConstString& rhs) const
-{
- // We can do a pointer compare to compare these strings since they
- // must come from the same pool in order to be equal.
- return m_string == rhs.m_string;
-}
-
-bool
-ConstString::operator != (const ConstString& rhs) const
-{
- return m_string != rhs.m_string;
-}
-
bool
ConstString::operator < (const ConstString& rhs) const
{
@@ -295,45 +243,12 @@
return s;
}
-//----------------------------------------------------------------------
-// Get the value of the contained string as a NULL terminated C
-// string value. Return "fail_value" if the string is empty.
-//----------------------------------------------------------------------
-const char *
-ConstString::AsCString(const char *fail_value) const
-{
- if (m_string == NULL)
- return fail_value;
- return m_string;
-}
-
-const char *
-ConstString::GetCString () const
-{
- return m_string;
-}
-
size_t
ConstString::GetLength () const
{
return StringPool().GetConstCStringLength (m_string);
}
-
-//----------------------------------------------------------------------
-// Clear any contained string and reset the value to the an empty
-// string value.
-//
-// The previously contained string will be get its reference count
-// decremented and removed from the string pool if its reference
-// count reaches zero.
-//----------------------------------------------------------------------
-void
-ConstString::Clear ()
-{
- m_string = NULL;
-}
-
//----------------------------------------------------------------------
// Compare two string objects.
//
Modified: lldb/trunk/source/Expression/ASTResultSynthesizer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ASTResultSynthesizer.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ASTResultSynthesizer.cpp (original)
+++ lldb/trunk/source/Expression/ASTResultSynthesizer.cpp Fri Oct 15 17:48:33 2010
@@ -70,7 +70,7 @@
if (m_ast_context &&
function_decl &&
- !function_decl->getNameInfo().getAsString().compare("___clang_expr"))
+ !function_decl->getNameInfo().getAsString().compare("$__lldb_expr"))
{
SynthesizeResult(function_decl);
}
@@ -164,7 +164,7 @@
log->Printf("Last statement's type: %s", s.c_str());
}
- IdentifierInfo &result_id = Ctx.Idents.get("___clang_expr_result");
+ IdentifierInfo &result_id = Ctx.Idents.get("$__lldb_expr_result");
clang::VarDecl *result_decl = VarDecl::Create(Ctx,
function_decl,
Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Fri Oct 15 17:48:33 2010
@@ -21,8 +21,8 @@
void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) {
// Tell Sema to ask us when looking into the translation unit's decl.
- Context.getTranslationUnitDecl()->setHasExternalVisibleStorage();
- Context.getTranslationUnitDecl()->setHasExternalLexicalStorage();
+ m_ast_context.getTranslationUnitDecl()->setHasExternalVisibleStorage();
+ m_ast_context.getTranslationUnitDecl()->setHasExternalLexicalStorage();
}
// These are only required for AST source that want to lazily load
@@ -41,13 +41,15 @@
DeclContext::lookup_result ClangASTSource::FindExternalVisibleDeclsByName
(
const DeclContext *decl_ctx,
- DeclarationName decl_name
+ DeclarationName clang_decl_name
)
{
- switch (decl_name.getNameKind()) {
+ switch (clang_decl_name.getNameKind()) {
// Normal identifiers.
case DeclarationName::Identifier:
- break;
+ if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0)
+ return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+ break;
// Operator names. Not important for now.
case DeclarationName::CXXOperatorName:
@@ -57,7 +59,7 @@
// Using directives found in this context.
// Tell Sema we didn't find any or we'll end up getting asked a *lot*.
case DeclarationName::CXXUsingDirective:
- return SetNoExternalVisibleDeclsForName(decl_ctx, decl_name);
+ return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
// These aren't looked up like this.
case DeclarationName::ObjCZeroArgSelector:
@@ -72,33 +74,28 @@
return DeclContext::lookup_result();
}
-
- std::string name (decl_name.getAsString());
- if (0 == name.compare ("__va_list_tag") ||
- 0 == name.compare ("__int128_t") ||
- 0 == name.compare ("__uint128_t") ||
- 0 == name.compare ("SEL") ||
- 0 == name.compare ("id") ||
- 0 == name.compare ("Class") ||
- 0 == name.compare ("nil") ||
- 0 == name.compare ("gp_offset") ||
- 0 == name.compare ("fp_offset") ||
- 0 == name.compare ("overflow_arg_area") ||
- 0 == name.compare ("reg_save_area") ||
- 0 == name.find ("__builtin") )
- {
- Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- if (log)
- log->Printf("Ignoring built-in in find external declarations for name: '%s'", name.c_str());
+ std::string decl_name (clang_decl_name.getAsString());
- return SetNoExternalVisibleDeclsForName(decl_ctx, decl_name);
+ if (!m_decl_map.GetLookupsEnabled())
+ {
+ // Wait until we see a '$' at the start of a name before we start doing
+ // any lookups so we can avoid lookup up all of the builtin types.
+ if (!decl_name.empty() && decl_name[0] == '$')
+ {
+ m_decl_map.SetLookupsEnabled (true);
+ }
+ else
+ {
+ return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
+ }
}
+
+ llvm::SmallVector<NamedDecl*, 4> name_decls;
- llvm::SmallVector<NamedDecl*, 4> Decls;
-
- NameSearchContext NSC(*this, Decls, decl_name, decl_ctx);
- DeclMap.GetDecls(NSC, name.c_str());
- return SetExternalVisibleDeclsForName(decl_ctx, decl_name, Decls);
+ NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
+ ConstString const_decl_name(decl_name.c_str());
+ m_decl_map.GetDecls(name_search_context, const_decl_name);
+ return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls);
}
void ClangASTSource::MaterializeVisibleDecls(const DeclContext *DC)
@@ -114,103 +111,101 @@
}
clang::ASTContext *NameSearchContext::GetASTContext() {
- return &ASTSource.Context;
+ return &m_ast_source.m_ast_context;
}
clang::NamedDecl *NameSearchContext::AddVarDecl(void *type) {
- IdentifierInfo *ii = Name.getAsIdentifierInfo();
+ IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
- clang::NamedDecl *Decl = VarDecl::Create(ASTSource.Context,
- const_cast<DeclContext*>(DC),
+ clang::NamedDecl *Decl = VarDecl::Create(m_ast_source.m_ast_context,
+ const_cast<DeclContext*>(m_decl_context),
SourceLocation(),
ii,
QualType::getFromOpaquePtr(type),
0,
SC_Static,
SC_Static);
- Decls.push_back(Decl);
+ m_decls.push_back(Decl);
return Decl;
}
-clang::NamedDecl *NameSearchContext::AddFunDecl(void *type) {
- clang::FunctionDecl *Decl = FunctionDecl::Create(ASTSource.Context,
- const_cast<DeclContext*>(DC),
- SourceLocation(),
- Name.getAsIdentifierInfo(),
- QualType::getFromOpaquePtr(type),
- NULL,
- SC_Static,
- SC_Static,
- false,
- true);
+clang::NamedDecl *NameSearchContext::AddFunDecl (void *type) {
+ clang::FunctionDecl *func_decl = FunctionDecl::Create (m_ast_source.m_ast_context,
+ const_cast<DeclContext*>(m_decl_context),
+ SourceLocation(),
+ m_decl_name.getAsIdentifierInfo(),
+ QualType::getFromOpaquePtr(type),
+ NULL,
+ SC_Static,
+ SC_Static,
+ false,
+ true);
// We have to do more than just synthesize the FunctionDecl. We have to
// synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
// this, we raid the function's FunctionProtoType for types.
- QualType QT = QualType::getFromOpaquePtr(type);
- clang::Type *T = QT.getTypePtr();
- const FunctionProtoType *FPT = T->getAs<FunctionProtoType>();
+ QualType qual_type (QualType::getFromOpaquePtr(type));
+ const FunctionProtoType *func_proto_type = qual_type->getAs<FunctionProtoType>();
- if (FPT)
+ if (func_proto_type)
{
- unsigned NumArgs = FPT->getNumArgs();
+ unsigned NumArgs = func_proto_type->getNumArgs();
unsigned ArgIndex;
- ParmVarDecl **ParmVarDecls = new ParmVarDecl*[NumArgs];
+ ParmVarDecl **param_var_decls = new ParmVarDecl*[NumArgs];
for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
{
- QualType ArgQT = FPT->getArgType(ArgIndex);
+ QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
- ParmVarDecls[ArgIndex] = ParmVarDecl::Create(ASTSource.Context,
- const_cast<DeclContext*>(DC),
- SourceLocation(),
- NULL,
- ArgQT,
- NULL,
- SC_Static,
- SC_Static,
- NULL);
+ param_var_decls[ArgIndex] = ParmVarDecl::Create (m_ast_source.m_ast_context,
+ const_cast<DeclContext*>(m_decl_context),
+ SourceLocation(),
+ NULL,
+ arg_qual_type,
+ NULL,
+ SC_Static,
+ SC_Static,
+ NULL);
}
- Decl->setParams(ParmVarDecls, NumArgs);
+ func_decl->setParams(param_var_decls, NumArgs);
- delete [] ParmVarDecls;
+ delete [] param_var_decls;
}
- Decls.push_back(Decl);
+ m_decls.push_back(func_decl);
- return Decl;
+ return func_decl;
}
clang::NamedDecl *NameSearchContext::AddGenericFunDecl()
{
- QualType generic_function_type(ASTSource.Context.getFunctionType(ASTSource.Context.getSizeType(), // result
- NULL, // argument types
- 0, // number of arguments
- true, // variadic?
- 0, // type qualifiers
- false, // has exception specification?
- false, // has any exception specification?
- 0, // number of exceptions
- NULL, // exceptions
- FunctionType::ExtInfo())); // defaults for noreturn, regparm, calling convention
-
+ QualType generic_function_type(m_ast_source.m_ast_context.getFunctionType (m_ast_source.m_ast_context.getSizeType(), // result
+ NULL, // argument types
+ 0, // number of arguments
+ true, // variadic?
+ 0, // type qualifiers
+ false, // has exception specification?
+ false, // has any exception specification?
+ 0, // number of exceptions
+ NULL, // exceptions
+ FunctionType::ExtInfo())); // defaults for noreturn, regparm, calling convention
+
return AddFunDecl(generic_function_type.getAsOpaquePtr());
}
clang::NamedDecl *NameSearchContext::AddTypeDecl(void *type)
{
- QualType QT = QualType::getFromOpaquePtr(type);
- clang::Type *T = QT.getTypePtr();
+ QualType qual_type = QualType::getFromOpaquePtr(type);
- if (TagType *tag_type = dyn_cast<clang::TagType>(T))
+ if (TagType *tag_type = dyn_cast<clang::TagType>(qual_type))
{
TagDecl *tag_decl = tag_type->getDecl();
- Decls.push_back(tag_decl);
+ m_decls.push_back(tag_decl);
return tag_decl;
}
Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Oct 15 17:48:33 2010
@@ -39,17 +39,30 @@
using namespace lldb_private;
using namespace clang;
-ClangExpressionDeclMap::ClangExpressionDeclMap(ExecutionContext *exe_ctx) :
- m_exe_ctx(exe_ctx), m_struct_laid_out(false),
- m_materialized_location(0)
-{
- if (exe_ctx && exe_ctx->frame)
- m_sym_ctx = new SymbolContext(exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything));
- else
- m_sym_ctx = NULL;
-
- if (exe_ctx && exe_ctx->process)
- m_persistent_vars = &exe_ctx->process->GetPersistentVariables();
+ClangExpressionDeclMap::ClangExpressionDeclMap (ExecutionContext *exe_ctx) :
+ m_found_entities (),
+ m_struct_members (),
+ m_exe_ctx (),
+ m_sym_ctx (),
+ m_persistent_vars (NULL),
+ m_struct_alignment (0),
+ m_struct_size (0),
+ m_struct_laid_out (false),
+ m_enable_lookups (false),
+ m_allocated_area (0),
+ m_materialized_location (0),
+ m_result_name (),
+ m_object_pointer_type (),
+ m_lookedup_types ()
+{
+ if (exe_ctx)
+ {
+ m_exe_ctx = *exe_ctx;
+ if (exe_ctx->frame)
+ m_sym_ctx = exe_ctx->frame->GetSymbolContext(lldb::eSymbolContextEverything);
+ if (exe_ctx->process)
+ m_persistent_vars = &exe_ctx->process->GetPersistentVariables();
+ }
}
ClangExpressionDeclMap::~ClangExpressionDeclMap()
@@ -76,30 +89,30 @@
if (m_materialized_location)
{
- m_exe_ctx->process->DeallocateMemory(m_materialized_location);
+ m_exe_ctx.process->DeallocateMemory(m_materialized_location);
m_materialized_location = 0;
}
-
- if (m_sym_ctx)
- delete m_sym_ctx;
}
// Interface for IRForTarget
-void
-ClangExpressionDeclMap::GetPersistentResultName (std::string &name)
+const ConstString &
+ClangExpressionDeclMap::GetPersistentResultName ()
{
- m_persistent_vars->GetNextResultName(m_result_name);
-
- name = m_result_name;
+ if (!m_result_name)
+ m_persistent_vars->GetNextResultName(m_result_name);
+ return m_result_name;
}
bool
-ClangExpressionDeclMap::AddPersistentVariable (const clang::NamedDecl *decl,
- const char *name,
- TypeFromParser parser_type)
+ClangExpressionDeclMap::AddPersistentVariable
+(
+ const clang::NamedDecl *decl,
+ const ConstString &name,
+ TypeFromParser parser_type
+)
{
- clang::ASTContext *context(m_exe_ctx->target->GetScratchClangASTContext()->getASTContext());
+ clang::ASTContext *context(m_exe_ctx.target->GetScratchClangASTContext()->getASTContext());
TypeFromUser user_type(ClangASTContext::CopyType(context,
parser_type.GetASTContext(),
@@ -123,11 +136,14 @@
}
bool
-ClangExpressionDeclMap::AddValueToStruct (const clang::NamedDecl *decl,
- const char *name,
- llvm::Value *value,
- size_t size,
- off_t alignment)
+ClangExpressionDeclMap::AddValueToStruct
+(
+ const clang::NamedDecl *decl,
+ const ConstString &name,
+ llvm::Value *value,
+ size_t size,
+ off_t alignment
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -147,8 +163,8 @@
if (log)
log->Printf("Adding value for decl %p [%s - %s] to the structure",
decl,
- name,
- var->m_name.c_str());
+ name.GetCString(),
+ var->m_name.GetCString());
// We know entity->m_parser_vars is valid because we used a parser variable
// to find it
@@ -199,9 +215,12 @@
return true;
}
-bool ClangExpressionDeclMap::GetStructInfo (uint32_t &num_elements,
- size_t &size,
- off_t &alignment)
+bool ClangExpressionDeclMap::GetStructInfo
+(
+ uint32_t &num_elements,
+ size_t &size,
+ off_t &alignment
+)
{
if (!m_struct_laid_out)
return false;
@@ -214,11 +233,14 @@
}
bool
-ClangExpressionDeclMap::GetStructElement (const clang::NamedDecl *&decl,
- llvm::Value *&value,
- off_t &offset,
- const char *&name,
- uint32_t index)
+ClangExpressionDeclMap::GetStructElement
+(
+ const clang::NamedDecl *&decl,
+ llvm::Value *&value,
+ off_t &offset,
+ ConstString &name,
+ uint32_t index
+)
{
if (!m_struct_laid_out)
return false;
@@ -235,15 +257,18 @@
decl = member.m_parser_vars->m_named_decl;
value = member.m_parser_vars->m_llvm_value;
offset = member.m_jit_vars->m_offset;
- name = member.m_name.c_str();
+ name = member.m_name;
return true;
}
bool
-ClangExpressionDeclMap::GetFunctionInfo (const clang::NamedDecl *decl,
- llvm::Value**& value,
- uint64_t &ptr)
+ClangExpressionDeclMap::GetFunctionInfo
+(
+ const clang::NamedDecl *decl,
+ llvm::Value**& value,
+ uint64_t &ptr
+)
{
ClangExpressionVariable *entity = m_found_entities.GetVariable(decl);
@@ -260,17 +285,19 @@
}
bool
-ClangExpressionDeclMap::GetFunctionAddress (const char *name,
- uint64_t &ptr)
+ClangExpressionDeclMap::GetFunctionAddress
+(
+ const ConstString &name,
+ uint64_t &ptr
+)
{
// Back out in all cases where we're not fully initialized
- if (!m_exe_ctx || !m_exe_ctx->frame || !m_sym_ctx)
+ if (m_exe_ctx.frame == NULL)
return false;
- ConstString name_cs(name);
SymbolContextList sym_ctxs;
- m_sym_ctx->FindFunctionsByName(name_cs, false, sym_ctxs);
+ m_sym_ctx.FindFunctionsByName(name, false, sym_ctxs);
if (!sym_ctxs.GetSize())
return false;
@@ -287,7 +314,7 @@
else
return false;
- ptr = fun_address->GetLoadAddress(m_exe_ctx->target);
+ ptr = fun_address->GetLoadAddress (m_exe_ctx.target);
return true;
}
@@ -295,9 +322,12 @@
// Interface for CommandObjectExpression
bool
-ClangExpressionDeclMap::Materialize (ExecutionContext *exe_ctx,
- lldb::addr_t &struct_address,
- Error &err)
+ClangExpressionDeclMap::Materialize
+(
+ ExecutionContext *exe_ctx,
+ lldb::addr_t &struct_address,
+ Error &err
+)
{
bool result = DoMaterialize(false, exe_ctx, NULL, err);
@@ -308,9 +338,12 @@
}
bool
-ClangExpressionDeclMap::GetObjectPointer(lldb::addr_t &object_ptr,
- ExecutionContext *exe_ctx,
- Error &err)
+ClangExpressionDeclMap::GetObjectPointer
+(
+ lldb::addr_t &object_ptr,
+ ExecutionContext *exe_ctx,
+ Error &err
+)
{
if (!exe_ctx || !exe_ctx->frame || !exe_ctx->target || !exe_ctx->process)
{
@@ -324,7 +357,8 @@
return false;
}
- Variable *object_ptr_var = FindVariableInScope(*exe_ctx->frame, "this", &m_object_pointer_type);
+ static ConstString g_this_cs ("this");
+ Variable *object_ptr_var = FindVariableInScope(*exe_ctx->frame, g_this_cs, &m_object_pointer_type);
if (!object_ptr_var)
{
@@ -380,17 +414,23 @@
}
bool
-ClangExpressionDeclMap::Dematerialize (ExecutionContext *exe_ctx,
- ClangExpressionVariable *&result,
- Error &err)
+ClangExpressionDeclMap::Dematerialize
+(
+ ExecutionContext *exe_ctx,
+ ClangExpressionVariable *&result,
+ Error &err
+)
{
return DoMaterialize(true, exe_ctx, &result, err);
}
bool
-ClangExpressionDeclMap::DumpMaterializedStruct(ExecutionContext *exe_ctx,
- Stream &s,
- Error &err)
+ClangExpressionDeclMap::DumpMaterializedStruct
+(
+ ExecutionContext *exe_ctx,
+ Stream &s,
+ Error &err
+)
{
if (!m_struct_laid_out)
{
@@ -434,7 +474,7 @@
{
ClangExpressionVariable &member (m_struct_members.VariableAtIndex(member_index));
- s.Printf("[%s]\n", member.m_name.c_str());
+ s.Printf("[%s]\n", member.m_name.GetCString());
if (!member.m_jit_vars.get())
return false;
@@ -456,10 +496,13 @@
}
bool
-ClangExpressionDeclMap::DoMaterialize (bool dematerialize,
- ExecutionContext *exe_ctx,
- ClangExpressionVariable **result,
- Error &err)
+ClangExpressionDeclMap::DoMaterialize
+(
+ bool dematerialize,
+ ExecutionContext *exe_ctx,
+ ClangExpressionVariable **result,
+ Error &err
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -529,19 +572,19 @@
return false;
ClangExpressionVariable *entity = m_found_entities.GetVariable(member.m_parser_vars->m_named_decl);
- ClangExpressionVariable *persistent_variable = m_persistent_vars->GetVariable(member.m_name.c_str());
+ ClangExpressionVariable *persistent_variable = m_persistent_vars->GetVariable(member.m_name);
if (entity)
{
if (!member.m_jit_vars.get())
return false;
- if (!DoMaterializeOneVariable(dematerialize, *exe_ctx, sym_ctx, member.m_name.c_str(), member.m_user_type, m_materialized_location + member.m_jit_vars->m_offset, err))
+ if (!DoMaterializeOneVariable(dematerialize, *exe_ctx, sym_ctx, member.m_name, member.m_user_type, m_materialized_location + member.m_jit_vars->m_offset, err))
return false;
}
else if (persistent_variable)
{
- if (!member.m_name.compare(m_result_name))
+ if (member.m_name == m_result_name)
{
if (!dematerialize)
continue;
@@ -553,14 +596,14 @@
}
if (log)
- log->Printf("Searched for persistent variable %s and found %s", member.m_name.c_str(), persistent_variable->m_name.c_str());
+ log->Printf("Searched for persistent variable %s and found %s", member.m_name.GetCString(), persistent_variable->m_name.GetCString());
- if (!DoMaterializeOnePersistentVariable(dematerialize, *exe_ctx, persistent_variable->m_name.c_str(), m_materialized_location + member.m_jit_vars->m_offset, err))
+ if (!DoMaterializeOnePersistentVariable(dematerialize, *exe_ctx, persistent_variable->m_name, m_materialized_location + member.m_jit_vars->m_offset, err))
return false;
}
else
{
- err.SetErrorStringWithFormat("Unexpected variable %s", member.m_name.c_str());
+ err.SetErrorStringWithFormat("Unexpected variable %s", member.m_name.GetCString());
return false;
}
}
@@ -569,17 +612,20 @@
}
bool
-ClangExpressionDeclMap::DoMaterializeOnePersistentVariable(bool dematerialize,
- ExecutionContext &exe_ctx,
- const char *name,
- lldb::addr_t addr,
- Error &err)
+ClangExpressionDeclMap::DoMaterializeOnePersistentVariable
+(
+ bool dematerialize,
+ ExecutionContext &exe_ctx,
+ const ConstString &name,
+ lldb::addr_t addr,
+ Error &err
+)
{
ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name));
if (!pvar)
{
- err.SetErrorStringWithFormat("Undefined persistent variable %s", name);
+ err.SetErrorStringWithFormat("Undefined persistent variable %s", name.GetCString());
return LLDB_INVALID_ADDRESS;
}
@@ -612,13 +658,16 @@
}
bool
-ClangExpressionDeclMap::DoMaterializeOneVariable(bool dematerialize,
- ExecutionContext &exe_ctx,
- const SymbolContext &sym_ctx,
- const char *name,
- TypeFromUser type,
- lldb::addr_t addr,
- Error &err)
+ClangExpressionDeclMap::DoMaterializeOneVariable
+(
+ bool dematerialize,
+ ExecutionContext &exe_ctx,
+ const SymbolContext &sym_ctx,
+ const ConstString &name,
+ TypeFromUser type,
+ lldb::addr_t addr,
+ Error &err
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -629,12 +678,12 @@
if (!var)
{
- err.SetErrorStringWithFormat("Couldn't find %s with appropriate type", name);
+ err.SetErrorStringWithFormat("Couldn't find %s with appropriate type", name.GetCString());
return false;
}
if (log)
- log->Printf("%s %s with type %p", (dematerialize ? "Dematerializing" : "Materializing"), name, type.GetOpaqueQualType());
+ log->Printf("%s %s with type %p", (dematerialize ? "Dematerializing" : "Materializing"), name.GetCString(), type.GetOpaqueQualType());
std::auto_ptr<lldb_private::Value> location_value(GetVariableValue(exe_ctx,
var,
@@ -642,7 +691,7 @@
if (!location_value.get())
{
- err.SetErrorStringWithFormat("Couldn't get value for %s", name);
+ err.SetErrorStringWithFormat("Couldn't get value for %s", name.GetCString());
return false;
}
@@ -661,7 +710,7 @@
location_value->Dump(&ss);
- err.SetErrorStringWithFormat("%s has a value of unhandled type: %s", name, ss.GetString().c_str());
+ err.SetErrorStringWithFormat("%s has a value of unhandled type: %s", name.GetCString(), ss.GetString().c_str());
return false;
}
break;
@@ -689,13 +738,13 @@
Error error;
if (exe_ctx.process->ReadMemory (src_addr, data.GetBytes(), addr_byte_size, error) != addr_byte_size)
{
- err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name, error.AsCString());
+ err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name.GetCString(), error.AsCString());
return false;
}
if (exe_ctx.process->WriteMemory (dest_addr, data.GetBytes(), addr_byte_size, error) != addr_byte_size)
{
- err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", name, error.AsCString());
+ err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", name.GetCString(), error.AsCString());
return false;
}
@@ -711,7 +760,7 @@
location_value->Dump(&ss);
- err.SetErrorStringWithFormat("%s is a scalar of unhandled type: %s", name, ss.GetString().c_str());
+ err.SetErrorStringWithFormat("%s is a scalar of unhandled type: %s", name.GetCString(), ss.GetString().c_str());
return false;
}
@@ -719,7 +768,7 @@
if (!register_info)
{
- err.SetErrorStringWithFormat("Couldn't get the register information for %s", name);
+ err.SetErrorStringWithFormat("Couldn't get the register information for %s", name.GetCString());
return false;
}
@@ -727,7 +776,7 @@
if (!register_context)
{
- err.SetErrorStringWithFormat("Couldn't read register context to read %s from %s", name, register_info->name);
+ err.SetErrorStringWithFormat("Couldn't read register context to read %s from %s", name.GetCString(), register_info->name);
return false;
}
@@ -755,7 +804,7 @@
if (addr_byte_size > register_byte_size)
{
- err.SetErrorStringWithFormat("%s is too big to store in %s", name, register_info->name);
+ err.SetErrorStringWithFormat("%s is too big to store in %s", name.GetCString(), register_info->name);
return false;
}
@@ -764,7 +813,7 @@
switch (exe_ctx.process->GetByteOrder())
{
default:
- err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name);
+ err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name.GetCString());
return false;
case lldb::eByteOrderLittle:
register_offset = 0;
@@ -779,7 +828,7 @@
Error error;
if (exe_ctx.process->ReadMemory (addr, register_data.GetBytes() + register_offset, addr_byte_size, error) != addr_byte_size)
{
- err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name, error.AsCString());
+ err.SetErrorStringWithFormat ("Couldn't read %s from the target: %s", name.GetCString(), error.AsCString());
return false;
}
@@ -787,7 +836,7 @@
if (!register_context->WriteRegisterBytes(register_number, register_extractor, 0))
{
- err.SetErrorStringWithFormat("Couldn't read %s from %s", name, register_info->name);
+ err.SetErrorStringWithFormat("Couldn't read %s from %s", name.GetCString(), register_info->name);
return false;
}
}
@@ -812,7 +861,7 @@
if (addr_byte_size > register_byte_size)
{
- err.SetErrorStringWithFormat("%s is too big to store in %s", name, register_info->name);
+ err.SetErrorStringWithFormat("%s is too big to store in %s", name.GetCString(), register_info->name);
return false;
}
@@ -821,7 +870,7 @@
switch (exe_ctx.process->GetByteOrder())
{
default:
- err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name);
+ err.SetErrorStringWithFormat("%s is stored with an unhandled byte order", name.GetCString());
return false;
case lldb::eByteOrderLittle:
register_offset = 0;
@@ -835,7 +884,7 @@
if (!register_context->ReadRegisterBytes(register_number, register_extractor))
{
- err.SetErrorStringWithFormat("Couldn't read %s from %s", name, register_info->name);
+ err.SetErrorStringWithFormat("Couldn't read %s from %s", name.GetCString(), register_info->name);
return false;
}
@@ -843,7 +892,7 @@
if (!register_data)
{
- err.SetErrorStringWithFormat("Read but couldn't extract data for %s from %s", name, register_info->name);
+ err.SetErrorStringWithFormat("Read but couldn't extract data for %s from %s", name.GetCString(), register_info->name);
return false;
}
@@ -861,20 +910,21 @@
}
Variable *
-ClangExpressionDeclMap::FindVariableInScope(StackFrame &frame,
- const char *name,
- TypeFromUser *type)
+ClangExpressionDeclMap::FindVariableInScope
+(
+ StackFrame &frame,
+ const ConstString &name,
+ TypeFromUser *type
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- ConstString name_cs(name);
-
VariableList *var_list = frame.GetVariableList(true);
if (!var_list)
return NULL;
- lldb::VariableSP var = var_list->FindVariable(name_cs);
+ lldb::VariableSP var = var_list->FindVariable(name);
if (!var)
return NULL;
@@ -901,25 +951,27 @@
// Interface for ClangASTSource
void
-ClangExpressionDeclMap::GetDecls(NameSearchContext &context,
- const char *name)
+ClangExpressionDeclMap::GetDecls
+(
+ NameSearchContext &context,
+ const ConstString &name
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
if (log)
- log->Printf("Hunting for a definition for '%s'", name);
+ log->Printf("Hunting for a definition for '%s'", name.GetCString());
// Back out in all cases where we're not fully initialized
- if (!m_exe_ctx || !m_exe_ctx->frame || !m_sym_ctx)
+ if (m_exe_ctx.frame == NULL)
return;
- ConstString name_cs(name);
-
- if (!strcmp(name, "___clang_class"))
+ static ConstString g_lldb_class_name ("$__lldb_class");
+ if (name == g_lldb_class_name)
{
// Clang is looking for the type of "this"
- VariableList *vars = m_exe_ctx->frame->GetVariableList(false);
+ VariableList *vars = m_exe_ctx.frame->GetVariableList(false);
if (!vars)
return;
@@ -955,59 +1007,72 @@
SymbolContextList sym_ctxs;
- m_sym_ctx->FindFunctionsByName(name_cs, false, sym_ctxs);
-
- bool found_specific = false;
- Symbol *generic_symbol = NULL;
- Symbol *non_extern_symbol = NULL;
-
- for (uint32_t index = 0, num_indices = sym_ctxs.GetSize();
- index < num_indices;
- ++index)
+ // Only look for functions by name out in our symbols if the function
+ // doesn't start with our phony prefix of '$'
+ if (name.GetCString()[0] != '$')
{
- SymbolContext sym_ctx;
- sym_ctxs.GetContextAtIndex(index, sym_ctx);
-
- if (sym_ctx.function)
+
+ Variable *var = FindVariableInScope(*m_exe_ctx.frame, name);
+
+ // If we found a variable in scope, no need to pull up function names
+ if (var != NULL)
{
- // TODO only do this if it's a C function; C++ functions may be
- // overloaded
- if (!found_specific)
- AddOneFunction(context, sym_ctx.function, NULL);
- found_specific = true;
+ AddOneVariable(context, var);
}
- else if (sym_ctx.symbol)
+ else
{
- if (sym_ctx.symbol->IsExternal())
- generic_symbol = sym_ctx.symbol;
- else
- non_extern_symbol = sym_ctx.symbol;
+ m_sym_ctx.FindFunctionsByName (name, false, sym_ctxs);
+
+ bool found_specific = false;
+ Symbol *generic_symbol = NULL;
+ Symbol *non_extern_symbol = NULL;
+
+ for (uint32_t index = 0, num_indices = sym_ctxs.GetSize();
+ index < num_indices;
+ ++index)
+ {
+ SymbolContext sym_ctx;
+ sym_ctxs.GetContextAtIndex(index, sym_ctx);
+
+ if (sym_ctx.function)
+ {
+ // TODO only do this if it's a C function; C++ functions may be
+ // overloaded
+ if (!found_specific)
+ AddOneFunction(context, sym_ctx.function, NULL);
+ found_specific = true;
+ }
+ else if (sym_ctx.symbol)
+ {
+ if (sym_ctx.symbol->IsExternal())
+ generic_symbol = sym_ctx.symbol;
+ else
+ non_extern_symbol = sym_ctx.symbol;
+ }
+ }
+
+ if (!found_specific)
+ {
+ if (generic_symbol)
+ AddOneFunction(context, NULL, generic_symbol);
+ else if (non_extern_symbol)
+ AddOneFunction(context, NULL, non_extern_symbol);
+ }
}
}
-
- if (!found_specific)
+ else
{
- if (generic_symbol)
- AddOneFunction(context, NULL, generic_symbol);
- else if (non_extern_symbol)
- AddOneFunction(context, NULL, non_extern_symbol);
- }
+ ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name));
- Variable *var = FindVariableInScope(*m_exe_ctx->frame, name);
-
- if (var)
- AddOneVariable(context, var);
-
- ClangExpressionVariable *pvar(m_persistent_vars->GetVariable(name));
-
- if (pvar)
- AddOneVariable(context, pvar);
+ if (pvar)
+ AddOneVariable(context, pvar);
+ }
// See information on gating of this operation next to the definition for
// m_lookedup_types.
- const char *name_uniq = name_cs.GetCString();
+ const char *name_uniq = name.GetCString();
if (m_lookedup_types.find(name_uniq) == m_lookedup_types.end())
{
@@ -1015,7 +1080,7 @@
m_lookedup_types.insert(std::pair<const char*, bool>(name_uniq, true));
// 2 The type is looked up and added, potentially causing more type loookups.
- lldb::TypeSP type = m_sym_ctx->FindTypeByName(name_cs);
+ lldb::TypeSP type = m_sym_ctx.FindTypeByName (name);
if (type.get())
{
@@ -1028,15 +1093,17 @@
// 3 The name is removed from m_lookedup_types.
m_lookedup_types.erase(name_uniq);
}
-
}
Value *
-ClangExpressionDeclMap::GetVariableValue(ExecutionContext &exe_ctx,
- Variable *var,
- clang::ASTContext *parser_ast_context,
- TypeFromUser *user_type,
- TypeFromParser *parser_type)
+ClangExpressionDeclMap::GetVariableValue
+(
+ ExecutionContext &exe_ctx,
+ Variable *var,
+ clang::ASTContext *parser_ast_context,
+ TypeFromUser *user_type,
+ TypeFromParser *parser_type
+)
{
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -1129,7 +1196,7 @@
Address so_addr(var_location->GetScalar().ULongLong(), object_file->GetSectionList());
- lldb::addr_t load_addr = so_addr.GetLoadAddress(m_exe_ctx->target);
+ lldb::addr_t load_addr = so_addr.GetLoadAddress(m_exe_ctx.target);
var_location->GetScalar() = load_addr;
var_location->SetValueType(Value::eValueTypeLoadAddress);
@@ -1150,17 +1217,18 @@
TypeFromUser ut;
TypeFromParser pt;
- Value *var_location = GetVariableValue(*m_exe_ctx,
- var,
- context.GetASTContext(),
- &ut,
- &pt);
+ Value *var_location = GetVariableValue (m_exe_ctx,
+ var,
+ context.GetASTContext(),
+ &ut,
+ &pt);
NamedDecl *var_decl = context.AddVarDecl(pt.GetOpaqueQualType());
ClangExpressionVariable &entity(m_found_entities.VariableAtIndex(m_found_entities.CreateVariable()));
- entity.m_name = context.Name.getAsString();
- entity.m_user_type = ut;
+ std::string decl_name(context.m_decl_name.getAsString());
+ entity.m_name.SetCString (decl_name.c_str());
+ entity.m_user_type = ut;
entity.EnableParserVars();
entity.m_parser_vars->m_parser_type = pt;
@@ -1169,7 +1237,9 @@
entity.m_parser_vars->m_lldb_value = var_location;
if (log)
- log->Printf("Found variable %s, returned (NamedDecl)%p", context.Name.getAsString().c_str(), var_decl);
+ {
+ log->Printf("Found variable %s, returned (NamedDecl)%p", decl_name.c_str(), var_decl);
+ }
}
void
@@ -1194,7 +1264,7 @@
pvar->m_parser_vars->m_lldb_value = NULL;
if (log)
- log->Printf("Added pvar %s, returned (NamedDecl)%p", pvar->m_name.c_str(), var_decl);
+ log->Printf("Added pvar %s, returned (NamedDecl)%p", pvar->m_name.GetCString(), var_decl);
}
void
@@ -1261,12 +1331,13 @@
return;
}
- lldb::addr_t load_addr = fun_address->GetLoadAddress(m_exe_ctx->target);
+ lldb::addr_t load_addr = fun_address->GetLoadAddress(m_exe_ctx.target);
fun_location->SetValueType(Value::eValueTypeLoadAddress);
fun_location->GetScalar() = load_addr;
ClangExpressionVariable &entity(m_found_entities.VariableAtIndex(m_found_entities.CreateVariable()));
- entity.m_name = context.Name.getAsString();
+ std::string decl_name(context.m_decl_name.getAsString());
+ entity.m_name.SetCString(decl_name.c_str());
entity.m_user_type = TypeFromUser(fun_opaque_type, fun_ast_context);;
entity.EnableParserVars();
@@ -1275,7 +1346,9 @@
entity.m_parser_vars->m_lldb_value = fun_location.release();
if (log)
- log->Printf("Found %s function %s, returned (NamedDecl)%p", (fun ? "specific" : "generic"), context.Name.getAsString().c_str(), fun_decl);
+ {
+ log->Printf("Found %s function %s, returned (NamedDecl)%p", (fun ? "specific" : "generic"), decl_name.c_str(), fun_decl);
+ }
}
void
@@ -1310,7 +1383,7 @@
ClangASTContext::AddMethodToCXXRecordType (parser_ast_context,
copied_type,
- "___clang_expr",
+ "$__lldb_expr",
method_type,
lldb::eAccessPublic,
is_virtual,
Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Fri Oct 15 17:48:33 2010
@@ -272,7 +272,7 @@
m_compiler->setASTContext(ast_context.release());
- std::string module_name("___clang_module");
+ std::string module_name("$__lldb_module");
m_code_generator.reset(CreateLLVMCodeGen(m_compiler->getDiagnostics(),
module_name,
Modified: lldb/trunk/source/Expression/ClangExpressionVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionVariable.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionVariable.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionVariable.cpp Fri Oct 15 17:48:33 2010
@@ -127,7 +127,7 @@
}
result_sp.reset (new ValueObjectConstResult (m_user_type.GetASTContext(),
m_user_type.GetOpaqueQualType(),
- ConstString (m_name.c_str()),
+ m_name,
m_data_sp,// TODO: sean can you get this to be valid?
byte_order,
addr_byte_size));
Modified: lldb/trunk/source/Expression/ClangFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangFunction.cpp Fri Oct 15 17:48:33 2010
@@ -45,11 +45,14 @@
//----------------------------------------------------------------------
// ClangFunction constructor
//----------------------------------------------------------------------
-ClangFunction::ClangFunction(const char *target_triple,
- ClangASTContext *ast_context,
- void *return_qualtype,
- const Address& functionAddress,
- const ValueList &arg_value_list) :
+ClangFunction::ClangFunction
+(
+ const char *target_triple,
+ ClangASTContext *ast_context,
+ void *return_qualtype,
+ const Address& functionAddress,
+ const ValueList &arg_value_list
+) :
m_target_triple (target_triple),
m_function_ptr (NULL),
m_function_addr (functionAddress),
@@ -65,10 +68,13 @@
{
}
-ClangFunction::ClangFunction(const char *target_triple,
- Function &function,
- ClangASTContext *ast_context,
- const ValueList &arg_value_list) :
+ClangFunction::ClangFunction
+(
+ const char *target_triple,
+ Function &function,
+ ClangASTContext *ast_context,
+ const ValueList &arg_value_list
+) :
m_target_triple (target_triple),
m_function_ptr (&function),
m_function_addr (),
Modified: lldb/trunk/source/Expression/ClangPersistentVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangPersistentVariables.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangPersistentVariables.cpp (original)
+++ lldb/trunk/source/Expression/ClangPersistentVariables.cpp Fri Oct 15 17:48:33 2010
@@ -22,19 +22,16 @@
}
void
-ClangPersistentVariables::GetNextResultName (std::string &name)
+ClangPersistentVariables::GetNextResultName (ConstString &name)
{
- StreamString s;
- s.Printf("$%llu", m_result_counter);
-
- m_result_counter++;
-
- name = s.GetString();
+ char result_name[256];
+ ::snprintf (result_name, sizeof(result_name), "$%llu", m_result_counter++);
+ name.SetCString(result_name);
}
bool
-ClangPersistentVariables::CreatePersistentVariable(const char *name,
- TypeFromUser user_type)
+ClangPersistentVariables::CreatePersistentVariable (const ConstString &name,
+ TypeFromUser user_type)
{
if (GetVariable(name))
return false;
Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Fri Oct 15 17:48:33 2010
@@ -88,7 +88,7 @@
if (m_cplusplus)
{
m_transformed_stream.Printf("void \n"
- "___clang_class::%s(void *___clang_arg) \n"
+ "$__lldb_class::%s(void *$__lldb_arg) \n"
"{ \n"
" %s; \n"
"} \n",
@@ -100,7 +100,7 @@
else
{
m_transformed_stream.Printf("void \n"
- "%s(void *___clang_arg) \n"
+ "%s(void *$__lldb_arg) \n"
"{ \n"
" %s; \n"
"} \n",
Modified: lldb/trunk/source/Expression/IRDynamicChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRDynamicChecks.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRDynamicChecks.cpp (original)
+++ lldb/trunk/source/Expression/IRDynamicChecks.cpp Fri Oct 15 17:48:33 2010
@@ -26,18 +26,15 @@
static char ID;
-static const char valid_pointer_check_name[] =
-"___clang_valid_pointer_check";
+#define VALID_POINTER_CHECK_NAME "$__lldb_valid_pointer_check"
+#define VALID_OBJC_OBJECT_CHECK_NAME "$__lldb_objc_object_check"
-static const char valid_pointer_check_text[] =
- "extern \"C\" void "
- "___clang_valid_pointer_check (unsigned char *ptr)"
- "{"
- "unsigned char val = *ptr;"
- "}";
-
-static const char objc_object_check_name[] =
- "___clang_objc_object_check";
+static const char g_valid_pointer_check_text[] =
+"extern \"C\" void\n"
+VALID_POINTER_CHECK_NAME " (unsigned char *ptr)\n"
+"{\n"
+" unsigned char val = *ptr;\n"
+"}";
static bool FunctionExists(const SymbolContext &sym_ctx, const char *name)
{
@@ -55,14 +52,14 @@
std::string ret;
if (!exe_ctx.frame)
- return "extern \"C\" void ___clang_objc_object_check (unsigned char *obj) { }";
+ return "extern \"C\" void $__lldb_objc_object_check (unsigned char *obj) { }";
const SymbolContext &sym_ctx(exe_ctx.frame->GetSymbolContext(lldb::eSymbolContextEverything));
if (FunctionExists(sym_ctx, "gdb_object_getClass"))
{
return "extern \"C\" void "
- "___clang_objc_object_check(uint8_t *obj)"
+ "$__lldb_objc_object_check(uint8_t *obj)"
"{"
""
"}";
@@ -70,7 +67,7 @@
else if (FunctionExists(sym_ctx, "gdb_class_getClass"))
{
return "extern \"C\" void "
- "___clang_objc_object_check(uint8_t *obj)"
+ "$__lldb_objc_object_check(uint8_t *obj)"
"{"
""
"}";
@@ -78,7 +75,7 @@
else
{
return "extern \"C\" void "
- "___clang_objc_object_check(uint8_t *obj)"
+ "$__lldb_objc_object_check(uint8_t *obj)"
"{"
""
"}";
@@ -97,8 +94,8 @@
DynamicCheckerFunctions::Install(Stream &error_stream,
ExecutionContext &exe_ctx)
{
- m_valid_pointer_check.reset(new ClangUtilityFunction(valid_pointer_check_text,
- valid_pointer_check_name));
+ m_valid_pointer_check.reset(new ClangUtilityFunction(g_valid_pointer_check_text,
+ VALID_POINTER_CHECK_NAME));
if (!m_valid_pointer_check->Install(error_stream, exe_ctx))
return false;
Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=116634&r1=116633&r2=116634&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Oct 15 17:48:33 2010
@@ -19,6 +19,7 @@
#include "clang/AST/ASTContext.h"
+#include "lldb/Core/ConstString.h"
#include "lldb/Core/dwarf.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/Scalar.h"
@@ -73,8 +74,7 @@
}
bool
-IRForTarget::createResultVariable(llvm::Module &M,
- llvm::Function &F)
+IRForTarget::createResultVariable (llvm::Module &llvm_module, llvm::Function &llvm_function)
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -83,7 +83,7 @@
// Find the result variable. If it doesn't exist, we can give up right here.
- ValueSymbolTable& value_symbol_table = M.getValueSymbolTable();
+ ValueSymbolTable& value_symbol_table = llvm_module.getValueSymbolTable();
const char *result_name = NULL;
@@ -91,7 +91,7 @@
vi != ve;
++vi)
{
- if (strstr(vi->first(), "___clang_expr_result") &&
+ if (strstr(vi->first(), "$__lldb_expr_result") &&
!strstr(vi->first(), "GV"))
{
result_name = vi->first();
@@ -110,7 +110,7 @@
if (log)
log->Printf("Result name: %s", result_name);
- Value *result_value = M.getNamedValue(result_name);
+ Value *result_value = llvm_module.getNamedValue(result_name);
if (!result_value)
{
@@ -134,7 +134,7 @@
// Find the metadata and follow it to the VarDecl
- NamedMDNode *named_metadata = M.getNamedMetadata("clang.global.decl.ptrs");
+ NamedMDNode *named_metadata = llvm_module.getNamedMetadata("clang.global.decl.ptrs");
if (!named_metadata)
{
@@ -180,27 +180,26 @@
lldb_private::TypeFromParser result_decl_type (result_decl->getType().getAsOpaquePtr(),
&result_decl->getASTContext());
- std::string new_result_name;
-
- m_decl_map->GetPersistentResultName(new_result_name);
- m_decl_map->AddPersistentVariable(result_decl, new_result_name.c_str(), result_decl_type);
+
+ lldb_private::ConstString new_result_name (m_decl_map->GetPersistentResultName());
+ m_decl_map->AddPersistentVariable(result_decl, new_result_name, result_decl_type);
if (log)
- log->Printf("Creating a new result global: %s", new_result_name.c_str());
+ log->Printf("Creating a new result global: %s", new_result_name.GetCString());
// Construct a new result global and set up its metadata
- GlobalVariable *new_result_global = new GlobalVariable(M,
+ GlobalVariable *new_result_global = new GlobalVariable(llvm_module,
result_global->getType()->getElementType(),
false, /* not constant */
GlobalValue::ExternalLinkage,
NULL, /* no initializer */
- new_result_name.c_str());
+ new_result_name.GetCString ());
// It's too late in compilation to create a new VarDecl for this, but we don't
// need to. We point the metadata at the old VarDecl. This creates an odd
// anomaly: a variable with a Value whose name is something like $0 and a
- // Decl whose name is ___clang_expr_result. This condition is handled in
+ // Decl whose name is $__lldb_expr_result. This condition is handled in
// ClangExpressionDeclMap::DoMaterialize, and the name of the variable is
// fixed up.
@@ -212,7 +211,7 @@
values[0] = new_result_global;
values[1] = new_constant_int;
- MDNode *persistent_global_md = MDNode::get(M.getContext(), values, 2);
+ MDNode *persistent_global_md = MDNode::get(llvm_module.getContext(), values, 2);
named_metadata->addOperand(persistent_global_md);
if (log)
@@ -225,7 +224,7 @@
// We need to synthesize a store for this variable, because otherwise
// there's nothing to put into its equivalent persistent variable.
- BasicBlock &entry_block(F.getEntryBlock());
+ BasicBlock &entry_block(llvm_function.getEntryBlock());
Instruction *first_entry_instruction(entry_block.getFirstNonPHIOrDbg());
if (!first_entry_instruction)
@@ -332,7 +331,8 @@
{
uint64_t srN_addr;
- if (!m_decl_map->GetFunctionAddress("sel_registerName", srN_addr))
+ static lldb_private::ConstString g_sel_registerName_str ("sel_registerName");
+ if (!m_decl_map->GetFunctionAddress (g_sel_registerName_str, srN_addr))
return false;
// Build the function type: struct objc_selector *sel_registerName(uint8_t*)
@@ -418,7 +418,7 @@
bool
IRForTarget::RewritePersistentAlloc(llvm::Instruction *persistent_alloc,
- llvm::Module &M)
+ llvm::Module &llvm_module)
{
AllocaInst *alloc = dyn_cast<AllocaInst>(persistent_alloc);
@@ -441,10 +441,12 @@
lldb_private::TypeFromParser result_decl_type (decl->getType().getAsOpaquePtr(),
&decl->getASTContext());
- if (!m_decl_map->AddPersistentVariable(decl, decl->getName().str().c_str(), result_decl_type))
+ StringRef decl_name (decl->getName());
+ lldb_private::ConstString persistent_variable_name (decl_name.data(), decl_name.size());
+ if (!m_decl_map->AddPersistentVariable(decl, persistent_variable_name, result_decl_type))
return false;
- GlobalVariable *persistent_global = new GlobalVariable(M,
+ GlobalVariable *persistent_global = new GlobalVariable(llvm_module,
alloc->getType()->getElementType(),
false, /* not constant */
GlobalValue::ExternalLinkage,
@@ -454,13 +456,13 @@
// What we're going to do here is make believe this was a regular old external
// variable. That means we need to make the metadata valid.
- NamedMDNode *named_metadata = M.getNamedMetadata("clang.global.decl.ptrs");
+ NamedMDNode *named_metadata = llvm_module.getNamedMetadata("clang.global.decl.ptrs");
llvm::Value* values[2];
values[0] = persistent_global;
values[1] = constant_int;
- MDNode *persistent_global_md = MDNode::get(M.getContext(), values, 2);
+ MDNode *persistent_global_md = MDNode::get(llvm_module.getContext(), values, 2);
named_metadata->addOperand(persistent_global_md);
alloc->replaceAllUsesWith(persistent_global);
@@ -554,13 +556,16 @@
}
bool
-IRForTarget::MaybeHandleVariable(Module &M,
- Value *V,
- bool Store)
+IRForTarget::MaybeHandleVariable
+(
+ Module &llvm_module,
+ Value *llvm_value_ptr,
+ bool Store
+)
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- if (ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(V))
+ if (ConstantExpr *constant_expr = dyn_cast<ConstantExpr>(llvm_value_ptr))
{
switch (constant_expr->getOpcode())
{
@@ -569,16 +574,16 @@
case Instruction::GetElementPtr:
case Instruction::BitCast:
Value *s = constant_expr->getOperand(0);
- MaybeHandleVariable(M, s, Store);
+ MaybeHandleVariable(llvm_module, s, Store);
}
}
- if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(V))
+ if (GlobalVariable *global_variable = dyn_cast<GlobalVariable>(llvm_value_ptr))
{
- clang::NamedDecl *named_decl = DeclForGlobalValue(M, global_variable);
+ clang::NamedDecl *named_decl = DeclForGlobalValue(llvm_module, global_variable);
if (!named_decl)
{
- if (isObjCSelectorRef(V))
+ if (isObjCSelectorRef(llvm_value_ptr))
return true;
if (log)
@@ -586,7 +591,7 @@
return false;
}
- std::string name = named_decl->getName().str();
+ std::string name (named_decl->getName().str());
void *opaque_type = NULL;
clang::ASTContext *ast_context = NULL;
@@ -618,8 +623,8 @@
if (named_decl && !m_decl_map->AddValueToStruct(named_decl,
- name.c_str(),
- V,
+ lldb_private::ConstString (name.c_str()),
+ llvm_value_ptr,
value_size,
value_alignment))
return false;
@@ -644,16 +649,16 @@
}
bool
-IRForTarget::MaybeHandleCall(Module &M,
- CallInst *C)
+IRForTarget::MaybeHandleCall(Module &llvm_module,
+ CallInst *llvm_call_inst)
{
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
- Function *fun = C->getCalledFunction();
+ Function *fun = llvm_call_inst->getCalledFunction();
if (fun == NULL)
{
- Value *val = C->getCalledValue();
+ Value *val = llvm_call_inst->getCalledValue();
ConstantExpr *const_expr = dyn_cast<ConstantExpr>(val);
@@ -670,7 +675,7 @@
}
}
- std::string str;
+ lldb_private::ConstString str;
if (fun->isIntrinsic())
{
@@ -683,32 +688,35 @@
log->Printf("Unresolved intrinsic %s", Intrinsic::getName(intrinsic_id).c_str());
return false;
case Intrinsic::memcpy:
- str = "memcpy";
+ {
+ static lldb_private::ConstString g_memcpy_str ("memcpy");
+ str = g_memcpy_str;
+ }
break;
}
- if (log)
- log->Printf("Resolved intrinsic name %s", str.c_str());
+ if (log && str)
+ log->Printf("Resolved intrinsic name %s", str.GetCString());
}
else
{
- str = fun->getName().str();
+ str.SetCStringWithLength (fun->getName().data(), fun->getName().size());
}
- clang::NamedDecl *fun_decl = DeclForGlobalValue(M, fun);
+ clang::NamedDecl *fun_decl = DeclForGlobalValue (llvm_module, fun);
uint64_t fun_addr;
Value **fun_value_ptr = NULL;
if (fun_decl)
{
- if (!m_decl_map->GetFunctionInfo(fun_decl, fun_value_ptr, fun_addr))
+ if (!m_decl_map->GetFunctionInfo (fun_decl, fun_value_ptr, fun_addr))
{
fun_value_ptr = NULL;
- if (!m_decl_map->GetFunctionAddress(str.c_str(), fun_addr))
+ if (!m_decl_map->GetFunctionAddress (str, fun_addr))
{
if (log)
- log->Printf("Function %s had no address", str.c_str());
+ log->Printf("Function %s had no address", str.GetCString());
return false;
}
@@ -716,22 +724,22 @@
}
else
{
- if (!m_decl_map->GetFunctionAddress(str.c_str(), fun_addr))
+ if (!m_decl_map->GetFunctionAddress (str, fun_addr))
{
if (log)
- log->Printf("Metadataless function %s had no address", str.c_str());
+ log->Printf ("Metadataless function %s had no address", str.GetCString());
}
}
if (log)
- log->Printf("Found %s at %llx", str.c_str(), fun_addr);
+ log->Printf("Found %s at %llx", str.GetCString(), fun_addr);
Value *fun_addr_ptr;
if (!fun_value_ptr || !*fun_value_ptr)
{
- const IntegerType *intptr_ty = Type::getIntNTy(M.getContext(),
- (M.getPointerSize() == Module::Pointer64) ? 64 : 32);
+ const IntegerType *intptr_ty = Type::getIntNTy(llvm_module.getContext(),
+ (llvm_module.getPointerSize() == Module::Pointer64) ? 64 : 32);
const FunctionType *fun_ty = fun->getFunctionType();
PointerType *fun_ptr_ty = PointerType::getUnqual(fun_ty);
Constant *fun_addr_int = ConstantInt::get(intptr_ty, fun_addr, false);
@@ -744,18 +752,18 @@
if (fun_value_ptr)
fun_addr_ptr = *fun_value_ptr;
- C->setCalledFunction(fun_addr_ptr);
+ llvm_call_inst->setCalledFunction(fun_addr_ptr);
- ConstantArray *func_name = (ConstantArray*)ConstantArray::get(M.getContext(), str);
+ ConstantArray *func_name = (ConstantArray*)ConstantArray::get(llvm_module.getContext(), str.GetCString());
Value *values[1];
values[0] = func_name;
- MDNode *func_metadata = MDNode::get(M.getContext(), values, 1);
+ MDNode *func_metadata = MDNode::get(llvm_module.getContext(), values, 1);
- C->setMetadata("lldb.call.realName", func_metadata);
+ llvm_call_inst->setMetadata("lldb.call.realName", func_metadata);
if (log)
- log->Printf("Set metadata for %p [%d, %s]", C, func_name->isString(), func_name->getAsString().c_str());
+ log->Printf("Set metadata for %p [%d, %s]", llvm_call_inst, func_name->isString(), func_name->getAsString().c_str());
return true;
}
@@ -1048,7 +1056,7 @@
argument = iter;
}
- if (!argument->getName().equals("___clang_arg"))
+ if (!argument->getName().equals("$__lldb_arg"))
return false;
if (log)
@@ -1071,7 +1079,7 @@
const clang::NamedDecl *decl;
Value *value;
off_t offset;
- const char *name;
+ lldb_private::ConstString name;
if (!m_decl_map->GetStructElement (decl, value, offset, name, element_index))
return false;
@@ -1079,7 +1087,7 @@
if (log)
log->Printf(" %s [%s] (%s) placed at %d",
value->getName().str().c_str(),
- name,
+ name.GetCString(),
PrintValue(value, true).c_str(),
offset);
@@ -1117,7 +1125,7 @@
Function::iterator bbi;
////////////////////////////////////////////////////////////
- // Replace __clang_expr_result with a persistent variable
+ // Replace $__lldb_expr_result with a persistent variable
//
if (!createResultVariable(M, *function))
More information about the lldb-commits
mailing list