[Bug 28621] New: lldb-mi can't get variables of a frame (-stack-list-* MI-commands) if the thread didn't cause the stop event

Bug ID 28621
Summary lldb-mi can’t get variables of a frame (-stack-list-* MI-commands) if the thread didn’t cause the stop event
Product lldb
Version 3.9
Hardware Macintosh
OS MacOS X
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter edmunoz@microsoft.com
CC llvm-bugs@lists.llvm.org
Classification Unclassified

Created attachment 16771 [details]
Simple repro

lldb-mi provides a set of commands to list variables from a stack frame,
namely: stack-list-variables -stack-list-arguments and -stack-list-locals.

In a multithreaded process, these commands return a empty list if queried for a
thread that didn't cause the stopped event.

The root cause for this bug is https://llvm.org/bugs/show_bug.cgi?id=15824

lldb-mi checks the stopped reason for the thread being queried through those
commands and returns an empty list if the stopped reason in none or invalid.

This doesn't affect the normal command line interface for lldb (through the
similar command "frame variable") since lldb doesn't have such a strict check
(it just checks that the process is paused and that the frame exists).

In order to fix this bug, lldb-mi should perform the same checks as lldb.

Repro steps:

1. Compile the attached file a.cpp: clang++ -g a.cpp -lpthread
2. Start lldb-mi and execute the following

-file-exec-and-symbols "<path to a.out>"
-break-insert -f on a.cpp:5
-exec-run

After hitting the breakpoint
-stack-list-variables 0 --thread 1 --frame 5
^done,variables=[]

However, going through the non-MI command:

-interpreter-exec console "thread select 1"
-interpreter-exec console "frame select 5"
-interpreter-exec console "frame variable"
(int) argc = 1
(char **) argv = 0x00007fff5fbffee0
(int) x = 3
(int) y = 0
(pthread_t) id = 0x00000001000b6000

The expected result is:
-stack-list-variables 0 --thread 1 --frame 5
^done,variables=[{arg="1",name="argc"},{arg="1",name="argv"},{name="x"},{name="y"},{name="id"}]