aboutsummaryrefslogtreecommitdiffstats
path: root/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp')
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp b/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
index 742a14992dc9..24dd705e37b1 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
+++ b/source/Plugins/ExpressionParser/Clang/ClangPersistentVariables.cpp
@@ -23,8 +23,7 @@ using namespace lldb;
using namespace lldb_private;
ClangPersistentVariables::ClangPersistentVariables()
- : lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang),
- m_next_persistent_variable_id(0) {}
+ : lldb_private::PersistentExpressionState(LLVMCastKind::eKindClang) {}
ExpressionVariableSP ClangPersistentVariables::CreatePersistentVariable(
const lldb::ValueObjectSP &valobj_sp) {
@@ -43,13 +42,25 @@ void ClangPersistentVariables::RemovePersistentVariable(
lldb::ExpressionVariableSP variable) {
RemoveVariable(variable);
- const char *name = variable->GetName().AsCString();
+ // Check if the removed variable was the last one that was created. If yes,
+ // reuse the variable id for the next variable.
- if (*name != '$')
+ // Nothing to do if we have not assigned a variable id so far.
+ if (m_next_persistent_variable_id == 0)
return;
- name++;
- if (strtoul(name, nullptr, 0) == m_next_persistent_variable_id - 1)
+ llvm::StringRef name = variable->GetName().GetStringRef();
+ // Remove the prefix from the variable that only the indes is left.
+ if (!name.consume_front(GetPersistentVariablePrefix(false)))
+ return;
+
+ // Check if the variable contained a variable id.
+ uint32_t variable_id;
+ if (name.getAsInteger(10, variable_id))
+ return;
+ // If it's the most recent variable id that was assigned, make sure that this
+ // variable id will be used for the next persistent variable.
+ if (variable_id == m_next_persistent_variable_id - 1)
m_next_persistent_variable_id--;
}