Skip to content
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

LLDB crash when hitting up arrow in expression evaluator #49189

Closed
rupprecht opened this issue Apr 5, 2021 · 3 comments
Closed

LLDB crash when hitting up arrow in expression evaluator #49189

rupprecht opened this issue Apr 5, 2021 · 3 comments
Labels
bugzilla Issues migrated from bugzilla lldb

Comments

@rupprecht
Copy link
Collaborator

Bugzilla Link 49845
Resolution FIXED
Resolved on Apr 15, 2021 12:26
Version unspecified
OS Linux
CC @JDevlieghere
Fixed by commit(s) f49a444

Extended Description

This is at trunk. When you are prompted to enter expressions:

$ lldb
(lldb) e
Enter expressions, then terminate with an empty line to evaluate:
1:

... and then you hit the up arrow, it crashes (usually*):

$ lldb
(lldb) e
Enter expressions, then terminate with an empty line to evaluate:
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: lldb
#​0 0x00000000003b337a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/rupprecht/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:11
#​1 0x00000000003b354b PrintStackTraceSignalHandler(void*) /home/rupprecht/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
#​2 0x00000000003b1b5b llvm::sys::RunSignalHandlers() /home/rupprecht/src/llvm-project/llvm/lib/Support/Signals.cpp:70:5
#​3 0x00000000003b3ca1 SignalHandler(int) /home/rupprecht/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
#​4 0x00007fba26d9d140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
#​5 0x00007fba178fd6f0 std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::length() const (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x1496f0)
#​6 0x00007fba1e3dc9ff lldb_private::Editline::CountRowsForLine(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:434:53
#​7 0x00007fba1e3dc90c lldb_private::Editline::GetLineIndexForLocation(lldb_private::line_editor::CursorLocation, int) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:370:12
#​8 0x00007fba1e3dcab7 lldb_private::Editline::MoveCursor(lldb_private::line_editor::CursorLocation, lldb_private::line_editor::CursorLocation) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:392:7
#​9 0x00007fba1e3dd3ac lldb_private::Editline::RecallHistory(lldb_private::line_editor::HistoryOperation) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:528:3
#​10 0x00007fba1e3de5fe lldb_private::Editline::PreviousLineCommand(int) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:779:5
#​11 0x00007fba1e3e2237 lldb_private::Editline::ConfigureEditor(bool)::$_7::operator()(editline*, int) const /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:1162:13
#​12 0x00007fba1e3e21fb lldb_private::Editline::ConfigureEditor(bool)::$_7::__invoke(editline*, int) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:1161:41
#​13 0x00007fba16e47fc4 el_wgets (/usr/lib/x86_64-linux-gnu/libedit.so.2+0x10fc4)
#​14 0x00007fba1e3e1a78 lldb_private::Editline::GetLines(int, lldb_private::StringList&, bool&) /home/rupprecht/src/llvm-project/lldb/source/Host/common/Editline.cpp:1514:3
#​15 0x00007fba1e2e05a9 lldb_private::IOHandlerEditline::GetLines(lldb_private::StringList&, bool&) /home/rupprecht/src/llvm-project/lldb/source/Core/IOHandler.cpp:520:5
#​16 0x00007fba1e2e07dd lldb_private::IOHandlerEditline::Run() /home/rupprecht/src/llvm-project/lldb/source/Core/IOHandler.cpp:562:11
#​17 0x00007fba1e2a071d lldb_private::Debugger::RunIOHandlers() /home/rupprecht/src/llvm-project/lldb/source/Core/Debugger.cpp:868:16
#​18 0x00007fba1e424985 lldb_private::CommandInterpreter::RunCommandInterpreter(lldb_private::CommandInterpreterRunOptions&) /home/rupprecht/src/llvm-project/lldb/source/Interpreter/CommandInterpreter.cpp:3089:9
#​19 0x00007fba1dbf629d lldb::SBDebugger::RunCommandInterpreter(bool, bool) /home/rupprecht/src/llvm-project/lldb/source/API/SBDebugger.cpp:1214:42
#​20 0x0000000000295ada Driver::MainLoop() /home/rupprecht/src/llvm-project/lldb/tools/driver/Driver.cpp:677:3
#​21 0x0000000000296d1e main /home/rupprecht/src/llvm-project/lldb/tools/driver/Driver.cpp:940:17

(note the "1:" prompt line got eaten)

  • The first time I tried to run it, it didn't crash, but it gave me bogus history results. I guess it happened to venture into junk memory without triggering a segfault.
@JDevlieghere
Copy link
Member

I can reproduce this by adding an empty line to the lldb-expr-widehistory:

_HiStOrY_V2_
foo\012

bar\012

The issue appears to be that Editline::RecallHistory assumes that m_current_line_index is not empty:

    m_current_line_index = (int)m_input_lines.size() - 1;

We can either return an error when that happens:

  if (new_input_lines.empty())
    return CC_ERROR;

Or we can modify SplitLines to return a vector with an empty entry when passed the empty string.

std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) {
  std::vector<EditLineStringType> result;
  if (input.empty()) {
    result.emplace_back();
    return result;
  }
  ...

@rupprecht
Copy link
Collaborator Author

The CC_ERROR suggestion seems to cause really funky behavior (and causes crashes in other scenarios), but making SplitLines never return an empty vector seems to work nicely. Patch in http://go/phab/D100048 does this.

I was able to get an empty entry in the history file organically (i.e. without directly twiddling it) by entering the expression evaluator and hitting enter.

@rupprecht
Copy link
Collaborator Author

Forgot to close this. And thanks for suggesting the fix!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lldb
Projects
None yet
Development

No branches or pull requests

2 participants