[Lldb-commits] [lldb] r112527 - in /lldb/trunk: include/lldb/Expression/ClangExpressionVariable.h source/Expression/ClangExpressionVariable.cpp
Sean Callanan
scallanan at apple.com
Mon Aug 30 14:15:33 PDT 2010
Author: spyffe
Date: Mon Aug 30 16:15:33 2010
New Revision: 112527
URL: http://llvm.org/viewvc/llvm-project?rev=112527&view=rev
Log:
Fixed a bug where ClangExpressionVariableList was
storing pointers to objects inside a std::vector.
These objects can move around as the std::vector
changes, invalidating the pointers.
Modified:
lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h
lldb/trunk/source/Expression/ClangExpressionVariable.cpp
Modified: lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h?rev=112527&r1=112526&r2=112527&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionVariable.h Mon Aug 30 16:15:33 2010
@@ -28,7 +28,8 @@
}
namespace lldb_private {
-
+
+class ClangExpressionVariableStore;
class DataBufferHeap;
class ExecutionContext;
class Stream;
@@ -83,6 +84,12 @@
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
//----------------------------------------------------------------------
+ /// The following values indicate where the variable originally came from
+ //----------------------------------------------------------------------
+ ClangExpressionVariableStore *m_store; ///< The store containing the variable
+ uint64_t m_index; ///< The index of the variable in the store
+
+ //----------------------------------------------------------------------
/// The following values should not live beyond parsing
//----------------------------------------------------------------------
struct ParserVars {
@@ -273,14 +280,14 @@
return NULL;
}
};
-
+
//----------------------------------------------------------------------
/// @class ClangExpressionVariableListBase ClangExpressionVariable.h "lldb/Expression/ClangExpressionVariable.h"
/// @brief A list of variable references.
///
-/// This class stores references to variables stored elsewhere.
+/// This class stores variables internally, acting as the permanent store.
//----------------------------------------------------------------------
-class ClangExpressionVariableList : public ClangExpressionVariableListBase
+class ClangExpressionVariableStore : public ClangExpressionVariableListBase
{
public:
//----------------------------------------------------------------------
@@ -293,25 +300,39 @@
ClangExpressionVariable &VariableAtIndex(uint64_t index)
{
- return *m_variables[index];
+ return m_variables[index];
}
uint64_t AddVariable(ClangExpressionVariable &var)
{
- m_variables.push_back(&var);
+ m_variables.push_back(var);
return m_variables.size() - 1;
}
+
+ //----------------------------------------------------------------------
+ /// Create a new variable in the list and return its index
+ //----------------------------------------------------------------------
+ uint64_t CreateVariable()
+ {
+ uint64_t index = m_variables.size();
+
+ m_variables.push_back(ClangExpressionVariable());
+ m_variables[index].m_store = this;
+ m_variables[index].m_index = index;
+
+ return index;
+ }
private:
- std::vector <ClangExpressionVariable*> m_variables;
+ std::vector <ClangExpressionVariable> m_variables;
};
//----------------------------------------------------------------------
/// @class ClangExpressionVariableListBase ClangExpressionVariable.h "lldb/Expression/ClangExpressionVariable.h"
/// @brief A list of variable references.
///
-/// This class stores variables internally, acting as the permanent store.
+/// This class stores references to variables stored elsewhere.
//----------------------------------------------------------------------
-class ClangExpressionVariableStore : public ClangExpressionVariableListBase
+class ClangExpressionVariableList : public ClangExpressionVariableListBase
{
public:
//----------------------------------------------------------------------
@@ -319,30 +340,24 @@
//----------------------------------------------------------------------
uint64_t Size()
{
- return m_variables.size();
+ return m_references.size();
}
ClangExpressionVariable &VariableAtIndex(uint64_t index)
{
- return m_variables[index];
+ return m_references[index].first->VariableAtIndex(m_references[index].second);
}
uint64_t AddVariable(ClangExpressionVariable &var)
{
- m_variables.push_back(var);
- return m_variables.size() - 1;
- }
-
- //----------------------------------------------------------------------
- /// Create a new variable in the list and return its index
- //----------------------------------------------------------------------
- uint64_t CreateVariable()
- {
- m_variables.push_back(ClangExpressionVariable());
- return m_variables.size() - 1;
+ m_references.push_back(ClangExpressionVariableRef(var.m_store, var.m_index));
+ return m_references.size() - 1;
}
private:
- std::vector <ClangExpressionVariable> m_variables;
+ typedef std::pair <ClangExpressionVariableStore *, uint64_t>
+ ClangExpressionVariableRef;
+
+ std::vector <ClangExpressionVariableRef> m_references;
};
} // namespace lldb_private
Modified: lldb/trunk/source/Expression/ClangExpressionVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionVariable.cpp?rev=112527&r1=112526&r2=112527&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionVariable.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionVariable.cpp Mon Aug 30 16:15:33 2010
@@ -133,7 +133,9 @@
ClangExpressionVariable::ClangExpressionVariable(const ClangExpressionVariable &cev) :
m_name(cev.m_name),
- m_user_type(cev.m_user_type)
+ m_user_type(cev.m_user_type),
+ m_store(cev.m_store),
+ m_index(cev.m_index)
{
if (cev.m_parser_vars.get())
{
More information about the lldb-commits
mailing list