This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix crash when tab-completing in multi-line expr
ClosedPublic

Authored by teemperor on Jul 19 2019, 7:37 AM.

Details

Summary

Tab completing inside the multiline expression command can cause LLDB to crash. The easiest way
to do this is to go inside a frame with at least one local variable and then try to complete:

(lldb) expr
1. a[tab]

Reason for this was some mixup when we calculate the cursor position. Obviously we should calculate
the offset inside the string by doing 'end - start', but we are doing 'start - end' (which causes the offset to
become -1 which will lead to some out-of-bounds reading).

Fixes rdar://51754005

I don't see any way to test this as the *multiline* expression completion is completely untested at the moment
and I don't think we have any existing code for testing infrastructure for it.

Diff Detail

Repository
rL LLVM

Event Timeline

teemperor created this revision.Jul 19 2019, 7:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2019, 7:37 AM

I don't see any way to test this as the *multiline* expression completion is completely untested at the moment and I don't think we have any existing code for testing infrastructure for it.

Correct me if I'm wrong with this. I know we never test this functionality (as the whole IOHandler business is tricky to test), but I'm not sure if we maybe have some funky way around it.

Otherwise I would say we merge this as-is, as I don't want to have an obvious bug around until we find a method to test the interactive IO code.

This looks like a good opportunity to unleash pexpect.

davide requested changes to this revision.Jul 19 2019, 3:49 PM

See if you can write a pexpect test, as Pavel suggested.

This revision now requires changes to proceed.Jul 19 2019, 3:49 PM

Also once we get one test going then it should be easy to add coverage for all sorts of scenarios. Who knows maybe we will find more bugs.

teemperor updated this revision to Diff 212163.Jul 29 2019, 6:41 AM
  • Added test.
labath accepted this revision.Jul 29 2019, 8:15 AM

Thanks. The test looks good to me. You might want to consider marking it as NO_DEBUG_INFO_TESTCASE.

This revision was not accepted when it landed; it landed in state Needs Review.Jul 30 2019, 5:32 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2019, 5:32 AM