Skip to content

[lldb] Restore upstream implementation of ClangPersistentVariables::RemovePersistentVariable #7514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,26 @@ void ClangPersistentVariables::RemovePersistentVariable(

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++;

bool is_error = false;

if (variable->GetCompilerType().GetTypeSystem()->SupportsLanguage(
lldb::eLanguageTypeSwift)) {
switch (*name) {
case 'R':
break;
case 'E':
is_error = true;
break;
default:
return;
}
name++;
}

uint32_t value = strtoul(name, nullptr, 0);
if (is_error) {
if (value == m_next_persistent_error_id - 1)
m_next_persistent_error_id--;
} else {
if (value == m_next_persistent_variable_id - 1)
m_next_persistent_variable_id--;
}
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--;
}

std::optional<CompilerType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class ClangPersistentVariables
uint32_t m_next_user_file_id = 0;
// The counter used by GetNextPersistentVariableName
uint32_t m_next_persistent_variable_id = 0;
/// The counter used by GetNextResultName when is_error is true.
uint32_t m_next_persistent_error_id;

typedef llvm::DenseMap<const char *, clang::TypeDecl *>
ClangPersistentTypeMap;
Expand Down