[Bug 42895] New: Segfault on `p $0`

Bug ID 42895
Summary Segfault on p $0
Product lldb
Version 8.0
Hardware PC
OS Linux
Status NEW
Severity enhancement
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter whitequark@whitequark.org
CC jdevlieghere@apple.com, llvm-bugs@lists.llvm.org

Created attachment 22342 [details]
Communication with GDB stub

I am using LLDB 8 from Debian. To reproduce:

(lldb) gdb-remote 1234
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0xffffffffffffffff
(lldb) p $0
(lldb) p $0

Thread 1 "lldb-8" received signal SIGSEGV, Segmentation fault.
EvaluateExpression () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Target/Target.cpp:2389
2389    /build/llvm-toolchain-8-8.0.1/tools/lldb/source/Target/Target.cpp: No
such file or directory.
(gdb) bt
#0  EvaluateExpression () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Target/Target.cpp:2389
#1  0x00007ffff2bcc196 in EvaluateExpression () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Commands/CommandObjectExpression.cpp:441
#2  0x00007ffff2bcd0e8 in DoExecute () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Commands/CommandObjectExpression.cpp:658
#3  0x00007ffff277692f in Execute () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Interpreter/CommandObject.cpp:997
#4  0x00007ffff276ddf2 in HandleCommand () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Interpreter/CommandInterpreter.cpp:1761
#5  0x00007ffff2771531 in IOHandlerInputComplete () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Interpreter/CommandInterpreter.cpp:2801
#6  0x00007ffff26c63e1 in Run () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Core/IOHandler.cpp:558
#7  0x00007ffff26abb86 in ExecuteIOHandlers () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Core/Debugger.cpp:988
#8  0x00007ffff2772376 in RunCommandInterpreter () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/Interpreter/CommandInterpreter.cpp:3003
#9  0x00007ffff2561121 in RunCommandInterpreter () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/source/API/SBDebugger.cpp:934
#10 0x0000000000407131 in MainLoop () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/tools/driver/Driver.cpp:756
#11 0x0000000000407d51 in main () at
/build/llvm-toolchain-8-8.0.1/tools/lldb/tools/driver/Driver.cpp:936

Communication with GDB stub is attached.

This is a MIPS target and I was trying to get the value of register $0.

Davide Italiano changed bug 42895

Davide Italiano changed bug 42895

What | Removed | Added |

Comment # 3 on bug 42895 from Davide Italiano

(In reply to Jim Ingham from comment #1)
> $<NUM> is the space reserved in the expression parser for result variables. 
> I don't think it is a good idea to name your registers $0...  If you are
> going to do that, then you probably need to teach the
> ClangPersistentVariables to start above the numbers you've taken over for
> registers.  But I think it would be less confusing if you chose a prefix for
> registers ($r0 or whatever).

LLDB shouldn't segfault regardless. Raphael fixed a similar bug recently, as
newer C/C++ standards allow identifiers to start with dollar sign, e.g. $0.
So, this happens to be an incarnation of a larger problem.

Raphael, do you have ideas on how to fix this?