Page MenuHomePhabricator

Internal expressions should not increment the next result variable numbering
ClosedPublic

Authored by jingham on Mar 20 2020, 3:21 PM.

Details

Summary

For instance, breakpoints run an expression when evaluating a condition. If each of these expression evaluations incremented the result numbering, you could end up running an expression, and getting:

(lldb) expression foo
$1 = ...

Then do a continue, and then:

(lldb) expression foo
$14532 =

That would be disconcerting...

There was code (but no test, alas) to make this work, but when we refactored the PersistentExpression class, this got broken.

This patch goes back to using the original method of computing the number. But I also changed the API's a bit. When you went to get a result variable name in the current method you had to do:

auto prefix = persistent_expression_state->GetPersistentVariablePrefix();
 ConstString persistent_variable_name =
    persistent_expression_state->GetNextPersistentVariableName(target,
                                                               prefix);

The persistent variable prefix is only ever used to make the persistent variable name, so having this be done in two steps is unnecessary. It was also odd that you needed the target - that was only because we the "next result variable index" had been errantly moved into the target. So I made GetNextPersistentVariableName the public interface, and passed in only the is_error bool. I left the GetPersistentVariablePrefix in as a protected method - it doesn't do anything for C, but it is used for swift.

I also added a test.

Diff Detail

Event Timeline

jingham created this revision.Mar 20 2020, 3:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2020, 3:21 PM
davide accepted this revision.Mar 23 2020, 12:00 PM
This revision is now accepted and ready to land.Mar 23 2020, 12:00 PM
This revision was automatically updated to reflect the committed changes.