[lldb-dev] strange behaviour at lldb cmd line
Greg Clayton
gclayton at apple.com
Thu Jun 19 11:31:07 PDT 2014
Shawn,
All of this code is in:
Debugger::HandleProcessEvent (const EventSP &event_sp);
A little background:
LLDB has IOHandlers to handle the stdin/out/err given to the debugger. There is a stack of IOHandler objects that allows us to redirect the stdin/out/err to the appropriate place. The command line interpreter is the top most IOHandler when the process isn't running. So when you launch LLDB but haven't launched your process yet, you get a IOHandler stack like:
1 - LLDB Command Interpreter
When your process is launched, it hooks a pseudo terminal (pty) up the the stdin/out/err of the program you are debugging. When we resume the process and if we launched the process, and stdio was enabled for the process, then we push a ProcessIOHandler by calling:
process->PushProcessIOHandler ()
While your process is running you have:
1 - LLDB Command Interpreter
2 - Process IOHandler
The top item on the IOHandler stack is the "active" IOHandler. As soon as your process stops the Process IOHandler should pop itself off of the stack. When this happens it causes the "LLDB command interpreter" to become active again. As soon as that happens, the "(lldb)" prompt comes out again. Again, all of this is managed in Debugger::HandleProcessEvent().
Now if you attach to a process, then we don't have anything hooked up to the debugged process' in/out/err, so we don't have an IOHandler to push/pop (even though the process->PushProcessIOHandler() and process->PopProcessIOHandler() function might be called, they will actually not push/pop anything).
So now we launch the process and stop, resume the process and it prints "hello" to stdout, we might get this IO asynchronously through a GDB remote packet and the flow is:
1 - get the process stopped event
2 - check if there is any stdout or stderr to display, and if so tell the current IOHandler to hide itself (which will cause the "(lldb) " prompt to disappear, then display the stdout ("hello") followed by a refresh to the top IOHandler (causes "(lldb) " to redisplay itself.
The Debugger::HandleProcessEvent() tries to carefully do all of this to avoid any overlaps or any cases where the prompt comes out in the wrong place. The first thing is set a breakpoint in "Debugger::HandleProcessEvent()" and slowly follow the code and see where things come out incorrectly. No other code should be pushing or popping the ProcessIOHandler. So if you find the ProcessLinux plug-in or some other code trying to pop the process IOHandler (process->PopProcessIOHandler()), the you should remove that and let the Debugger::HandleProcessEvent() handle it.
Let me know what you find and I hope the above info gives you enough to go on.
Greg
> On Jun 19, 2014, at 10:29 AM, Shawn Best <sbest at blueshiftinc.com> wrote:
>
> Hi All,
>
> I would like to start contributing to lldb project and help improve it on linux. I am seeing some strange behaviour that makes lldb appear a little flakey. Some details of my system:
>
> - Ubuntu 14.04, 64 bit running inside a VM on windows
> - built from top of top of tree with gcc 4.8.2. Issue happens either configure/make or cmake/ninja
> - stock lldb-3.4 version shipped with Ubuntu does not exhibit this behaviour
>
> There are two intermittent issues: 1. When I run a program, I see messages that do not belong (indicating the process was stopped) 2. There appears to be a race condition sending text to the console where (lldb) prompt will come out of order making it appear there is no command prompt.
>
> shawn at shawn-VirtualBox:~/Projects$ ./lldb.sh
> (lldb) file a.out
> Current executable set to 'a.out' (x86_64).
> (lldb) br se -l 7
> Breakpoint 1: where = a.out`main + 35 at hello2.cpp:7, address = 0x0000000000400553
> (lldb) run
> Process 2509 launching
> Process 2509 launched: '/home/shawn/Projects/a.out' (x86_64)
> Process 2509 stopped
> * thread #1: tid = 2509, 0x00007f50bd2af2d0, name = 'a.out', stop reason = trace
> frame #0: 0x00007f50bd2af2d0
> -> 0x7f50bd2af2d0: movq %rsp, %rdi
> 0x7f50bd2af2d3: callq 0x7f50bd2b2a70
> 0x7f50bd2af2d8: movq %rax, %r12
> 0x7f50bd2af2db: movl 0x221b17(%rip), %eax
> Hello world!
> Process 2509 stopped
> * thread #1: tid = 2509, 0x0000000000400553 a.out`main + 35 at hello2.cpp:7, name = 'a.out', stop reason = breakpoint 1.1
> frame #0: 0x0000000000400553 a.out`main + 35 at hello2.cpp:7
> 4 {
> 5 printf("Hello world!\n");
> 6
> -> 7 return 0;
> 8 }
> (lldb) cont
> Process 2509 resuming
> (lldb) Process 2509 exited with status = 0 (0x00000000)
>
> My process was:
>
> Build simple hello world program. gcc -g hello.cpp
> Run lldb:
> file a.out
> br se -l 7
> run
> cont
>
> Notice all the unexpected stuff before it prints "Hello world!", also notice the (lldb) prompt that shows up before the "Process 2509 exited" message.
>
> Any suggestions where I can look in the code and start tracking this down?
>
> Thanks,
> Shawn Best.
> Blueshift Inc.
>
>
>
>
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
More information about the lldb-dev
mailing list