This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Reject redefinitions of persistent variables
ClosedPublic

Authored by teemperor on Oct 13 2020, 5:29 AM.

Details

Summary

Currently one can redefine a persistent variable and LLDB will just silently ignore the second definition:

(lldb) expr int $i = 1
(lldb) expr int $i = 2
(lldb) expr $i
(int) $i = 1

This patch makes this an error and rejects the expression with the second definition.

A nice follow up would be to refactor LLDB's persistent variables to not just be a pair of type and name,
but also contain some way to obtain the original declaration and source code that declared the variable.
That way we could actually make a full diagnostic as we would get from redefining a variable twice
in the same expression.

Diff Detail

Event Timeline

teemperor created this revision.Oct 13 2020, 5:29 AM
teemperor requested review of this revision.Oct 13 2020, 5:29 AM
labath accepted this revision.Oct 13 2020, 5:41 AM

Looks straight-forward enough.

This revision is now accepted and ready to land.Oct 13 2020, 5:41 AM
shafik accepted this revision.Oct 13 2020, 10:17 AM

makes sense, LGTM.

JDevlieghere accepted this revision.Oct 13 2020, 11:37 AM
JDevlieghere added inline comments.
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
212

As a totally unnecessary micro-optimization, it seems like Diagnostic is taking a StringRef in it's ctor only to store it as a std::string. We should make that a std::string and then move that string into place instead of making two unnecessary copies. Of course that doesn't have to be part of this patch.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2020, 1:25 AM