llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.41k stars 12.15k forks source link

lldb can swallow some of the output when doing `p SM.dump(SourceLoc)`, or similar #44356

Open vedantk opened 4 years ago

vedantk commented 4 years ago
Bugzilla Link 45011
Version unspecified
OS All
CC @JDevlieghere,@Teemperor

Extended Description

While debugging clang or llvm and calling 'dump' on various objects, lldb sometimes swallows part of the output. E.g.:

(lldb) p BV.dump()
(lldb)1]}

or

(lldb) p SM.dump(SourceLoc)
(lldb)ile.cpp:30:10

Why does that happen? These dump methods are writing to dbgs(), which should just be stderr.

llvmbot commented 4 years ago

We could add a check to see if we have gotten any input from our process and when the ProcessIOHandler is about to deactivate itself, it could print an extra newline if needed. The "(lldb) " prompt comes from editline and has ansi terminal codes that are used to get the start of the line and if the process prints stuff without a newline this will happen. The ProcessIOHandler gets pushed and popped each time the process starts and stops and it takes over the input and output in case you need to type anything into STDIN or print stuff from STDOUT/ERR. So it would be easy to maintain some state in the ProcessIOHandler and print an extra newline if needed. I believe the ProcessIOHandler gets pushed and popped during expression evaluation. Also editline has a bug where it doesn't colorize the prompt correctly, so it lets editline paint the normal prompt, and then there is LLDB code that will repaint the prompt with color, that is why we see two prompts in Raphael's example.

vedantk commented 4 years ago

Sandwiching the 'dump' output between two newline characters totally solves the problem, it was just not intuitive to me that that's necessary.

But I suppose it makes sense. As the printf occurs during expression evaluation, lldb cannot know that it should print a newline. This might be ntbf / behaves correctly, then.

Teemperor commented 4 years ago

The other option is that Editline is maybe somehow rendering the prompt while the stderr output is being rendered, but I'm not sure how exactly that actually works under the hood.

Teemperor commented 4 years ago

This usually happens when there is a missing trailing newline in the output:

(lldb) p (void)fprintf(stderr, "fooddasdfasdf")
(lldb) dfasdf(lldb) 

Did you check that this is not stripped by accident?