[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
2389    /build/llvm-toolchain-8-8.0.1/tools/lldb/source/Target/Target.cpp: No
such file or directory.
(gdb) bt
#0  EvaluateExpression () at
#1  0x00007ffff2bcc196 in EvaluateExpression () at
#2  0x00007ffff2bcd0e8 in DoExecute () at
#3  0x00007ffff277692f in Execute () at
#4  0x00007ffff276ddf2 in HandleCommand () at
#5  0x00007ffff2771531 in IOHandlerInputComplete () at
#6  0x00007ffff26c63e1 in Run () at
#7  0x00007ffff26abb86 in ExecuteIOHandlers () at
#8  0x00007ffff2772376 in RunCommandInterpreter () at
#9  0x00007ffff2561121 in RunCommandInterpreter () at
#10 0x0000000000407131 in MainLoop () at
#11 0x0000000000407d51 in main () at

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
Assignee teemperor@gmail.com lldb-dev@lists.llvm.org

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?