[Bug 14348] New: Can't run an expression and stop at a breakpoint during its execution

http://llvm.org/bugs/show_bug.cgi?id=14348

             Bug #: 14348
           Summary: Can't run an expression and stop at a breakpoint
                    during its execution
           Product: lldb
           Version: unspecified
          Platform: All
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
        AssignedTo: lldb-dev@cs.uiuc.edu
        ReportedBy: filcab@gmail.com
    Classification: Unclassified

Created attachment 9543
  --> http://llvm.org/bugs/attachment.cgi?id=9543
Test program

lldb is unable to execute an expression if it encounters a breakpoint during
its execution.

Additionally: Some executions will be interrupted, others will silently return
0:

○ ../llvm.org/lldb-fix-and-continue/build/Debug/lldb ./a
Current executable set to './a' (i386).
(lldb) b main
Breakpoint 1: where = a`main + 19 at a.c:7, address = 0x00001f53
(lldb) run
Process 92802 launched: './a' (i386)
Process 92802 stopped
* thread #1: tid = 0x1c03, 0x00001f53 a`main + 19 at a.c:7, stop reason =
breakpoint 1.1
    frame #0: 0x00001f53 a`main + 19 at a.c:7
   4
   5 int main(void)
   6 {
-> 7 printf("%d\n", b());
   8 return 0;
   9 }
   10
(lldb) p b()
(int) $0 = 44
(lldb) b b
Breakpoint 2: where = libb.dylib`b + 8 at b.c:3, address = 0x00004fa8
(lldb) p b()
error: Execution was interrupted, reason: breakpoint 2.1.
The process has been returned to the state before execution.

If you then step through b() and stop at main's return statement, it starts
returning 0:
(lldb) n
Process 92802 stopped
* thread #1: tid = 0x1c03, 0x00004fa8 libb.dylib`b + 8 at b.c:3, stop reason =
breakpoint 2.1
    frame #0: 0x00004fa8 libb.dylib`b + 8 at b.c:3
   1 int b(void)
   2 {
-> 3 return 44;
   4 }
(lldb) p b()
error: Execution was interrupted, reason: breakpoint 2.1.
The process has been returned to the state before execution.
(lldb) fin
Process 92802 stopped
* thread #1: tid = 0x1c03, 0x00001f5b a`main + 27 at a.c:7, stop reason = step
out
Return value: (int) $3 = 44

    frame #0: 0x00001f5b a`main + 27 at a.c:7
   4
   5 int main(void)
   6 {
-> 7 printf("%d\n", b());
   8 return 0;
   9 }
   10
(lldb) p b()
(int) $4 = 0
(lldb) break del 2
1 breakpoints deleted; 0 breakpoint locations disabled.
(lldb) p b()
(int) $5 = 44
(lldb) b b()
Breakpoint 3: where = libb.dylib`b + 8 at b.c:3, address = 0x00004fa8
(lldb) p b()
(int) $6 = 0

... And so on.

This happens on Darwin (Mac OS X 10.8.2), both for x86_64 and i386.
With lldb from trunk.

I suppose the expr command just sees an event going by and cancels everything.
gdb works, although not with a great UX.
We should continue executing, stopping at breakpoints. Then, we would exit our
expression and be back at the prompt in the original place.

I haven't looked at the code yet, but does anyone have a general idea of how we
could make this work?

Ashok Thirumurthi changed bug 14348