summaryrefslogtreecommitdiff
path: root/lldb/source/Utility/Log.cpp
AgeCommit message (Collapse)Author
2024-10-22[lldb] Log errors to the system log if they would otherwise get dropped ↵Jonas Devlieghere
(#111911) Log errors to the (always-on) system log if they would otherwise get dropped by LLDB_LOG_ERROR.
2024-10-10[lldb] Introduce an always-on system log category/channel (#108495)Jonas Devlieghere
Add an "always on" log category and channel. Unlike other, existing log channels, it is not exposed to users. The channel is meant to be used sparsely and deliberately for logging high-value information to the system log. We have a similar concept in the downstream Swift fork and this has proven to be extremely valuable. This is especially true on macOS where system log messages are automatically captured as part of a sysdiagnose.
2024-09-16[lldb] Nits on uses of llvm::raw_string_ostream (NFC) (#108745)Youngsuk Kim
As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b13610a5226b84889b923bae884ba395ad084d for further reference ) * Don't call raw_string_ostream::flush(), which is essentially a no-op. * Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
2024-05-03[lldb] Add TeeLogHandler to log to 2 handlers (#90984)Jonas Devlieghere
Add a T-style log handler that multiplexes messages to two log handlers. The goal is to use this in combination with the SystemLogHandler to log messages both to the user requested file as well as the system log. The latter is part of a sysdiagnose on Darwin which is commonly attached to bug reports.
2023-11-03[lldb][NFC] Use UNUSED_IF_ASSERT_DISABLED instead of (void) castDavid Spickett
Uses of (void) remain where they are for purposes other than an assert variable.
2023-06-06[lldb] Support file and function names in LLDB_LOGF macroJonas Devlieghere
LLDB's logging machinery supports prepending log messages with the name of the file and function that generates the log. However, currently this functionality is limited to the LLDB_LOG macro. I meant to do this as a follow up to D65128 but never got around to it. Differential revision: https://reviews.llvm.org/D151764
2023-05-09[lldb] Simplify Log::PutString (NFC)Dave Lee
* As no format string is involved, avoid unecessary call into `Printf` * Eliminate creation of a `std::string` to print a `StringRef` Differential Revision: https://reviews.llvm.org/D150160
2023-04-19[lldb][NFCI] Stop creating additional temporary string in Log::VAPrintfAlex Langford
Instead of creating a std::string from the `SmallString`, let's just use a std::string from the start. I initially tried to make `SmallString` work but getting it right proved complicated because `LogHandler::Emit` will take its `StringRef` parameter and touch the raw `const char *` from it directly, which isn't guaranteed to be null-terminated with a `SmallString`. I changed `WriteMessage` to take a `StringRef` instead of a `const std::string &` for flexibility. Differential Revision: https://reviews.llvm.org/D148676
2022-09-19[lldb] Actually support more than 32 logging categoriesJonas Devlieghere
In January, Greg put up a patch (D117382) to support, among other things, more than 32 log categories. That led to a bunch of nice cleanups, but categories remained constrained because different parts of the code were still using uint32_t. This patch fixes the remaining issues and makes it possible to add a 32nd log category. Differential revision: https://reviews.llvm.org/D134245
2022-06-27[lldb] Add a log dump commandJonas Devlieghere
Add a log dump command to dump logs to a file. This only works for channels that have a log handler associated that supports dumping. For now that's limited to the circular log handler, but more could be added in the future. Differential revision: https://reviews.llvm.org/D128557
2022-06-23[lldb] Make thread safety the responsibility of the log handlersJonas Devlieghere
Drop the thread-safe flag and make the locking strategy the responsibility of the individual log handler. Previously we got away with a non-thread safe mode because we were using unbuffered streams that rely on the underlying syscalls/OS for synchronization. With the introduction of log handlers, we can have arbitrary logic involved in writing out the logs. With this patch the log handlers can pick the most appropriate locking strategy for their particular implementation. Differential revision: https://reviews.llvm.org/D127922
2022-06-23[lldb] Support a buffered logging modeJonas Devlieghere
This patch adds a buffered logging mode to lldb. A buffer size can be passed to `log enable` with the -b flag. If no buffer size is specified, logging is unbuffered. Differential revision: https://reviews.llvm.org/D127986
2022-06-16[lldb] Remove LogHandler::Create functions (NFC)Jonas Devlieghere
Remove the LogHandler::Create functions. Except for the StreamHandler they were just forwarding their arguments to std::make_shared.
2022-06-16[lldb] Add RotatingLogHandlerJonas Devlieghere
Add a log handler that maintains a circular buffer with a fixed size. Differential revision: https://reviews.llvm.org/D127937
2022-06-16[lldb] Introduce the concept of a log handler (NFC)Jonas Devlieghere
This patch introduces the concept of a log handlers. Log handlers allow customizing the way log output is emitted. The StreamCallback class tried to do something conceptually similar. The benefit of the log handler interface is that you don't need to conform to llvm's raw_ostream interface. Differential revision: https://reviews.llvm.org/D127922
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath
Most of our code was including Log.h even though that is not where the "lldb" log channel is defined (Log.h defines the generic logging infrastructure). This worked because Log.h included Logging.h, even though it should. After the recent refactor, it became impossible the two files include each other in this direction (the opposite inclusion is needed), so this patch removes the workaround that was put in place and cleans up all files to include the right thing. It also renames the file to LLDBLog to better reflect its purpose.
2022-01-25[lldb] Make logging machinery type-safePavel Labath
This patch makes use of c++ type checking and scoped enums to make logging statements shorter and harder to misuse. Defines like LIBLLDB_LOG_PROCESS are replaces with LLDBLog::Process. Because it now carries type information we do not need to worry about matching a specific enum value with the right getter function -- the compiler will now do that for us. The main entry point for the logging machinery becomes the GetLog (template) function, which will obtain the correct Log object based on the enum type. It achieves this through another template function (LogChannelFor<T>), which must be specialized for each type, and should return the appropriate channel object. This patch also removes the ability to log a message if multiple categories are enabled simultaneously as it was unused and confusing. This patch does not actually remove any of the existing interfaces. The defines and log retrieval functions are left around as wrappers around the new interfaces. They will be removed in follow-up patch. Differential Revision: https://reviews.llvm.org/D117490
2021-12-29[lldb] Make ProcessLauncherPosixFork (mostly) async-signal-safePavel Labath
Multithreaded applications using fork(2) need to be extra careful about what they do in the fork child. Without any special precautions (which only really work if you can fully control all threads) they can only safely call async-signal-safe functions. This is because the forked child will contain snapshot of the parents memory at a random moment in the execution of all of the non-forking threads (this is where the similarity with signals comes in). For example, the other threads could have been holding locks that can now never be released in the child process and any attempt to obtain them would block. This is what sometimes happen when using tcmalloc -- our fork child ends up hanging in the memory allocation routine. It is also what happened with our logging code, which is why we added a pthread_atfork hackaround. This patch implements a proper fix to the problem, by which is to make the child code async-signal-safe. The ProcessLaunchInfo structure is transformed into a simpler ForkLaunchInfo representation, one which can be read without allocating memory and invoking complex library functions. Strictly speaking this implementation is not async-signal-safe, as it still invokes library functions outside of the posix-blessed set of entry points. Strictly adhering to the spec would mean reimplementing a lot of the functionality in pure C, so instead I rely on the fact that any reasonable implementation of some functions (e.g., basic_string::c_str()) will not start allocating memory or doing other unsafe things. The new child code does not call into our logging infrastructure, which enables us to remove the pthread_atfork call from there. Differential Revision: https://reviews.llvm.org/D116165
2021-06-25[lldb] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2019-09-24[lldb] Fix log output and UtilityTests/LogChannelTest.ListRaphael Isemann
I refactored this code in 372691 and it seems I didn't fully replicate the original log output, so that test was failing. llvm-svn: 372696
2019-09-24[lldb] Add completion support for log enable/disable/listRaphael Isemann
Reviewers: #lldb, JDevlieghere Reviewed By: JDevlieghere Subscribers: JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67903 llvm-svn: 372691
2019-04-10[NFC] Remove ASCII lines from commentsJonas Devlieghere
A lot of comments in LLDB are surrounded by an ASCII line to delimit the begging and end of the comment. Its use is not really consistent across the code base, sometimes the lines are longer, sometimes they are shorter and sometimes they are omitted. Furthermore, it looks kind of weird with the 80 column limit, where the comment actually extends past the line, but not by much. Furthermore, when /// is used for Doxygen comments, it looks particularly odd. And when // is used, it incorrectly gives the impression that it's actually a Doxygen comment. I assume these lines were added to improve distinguishing between comments and code. However, given that todays editors and IDEs do a great job at highlighting comments, I think it's worth to drop this for the sake of consistency. The alternative is fixing all the inconsistencies, which would create a lot more churn. Differential revision: https://reviews.llvm.org/D60508 llvm-svn: 358135
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-11Remove comments after header includes.Jonas Devlieghere
This patch removes the comments following the header includes. They were added after running IWYU over the LLDB codebase. However they add little value, are often outdates and burdensome to maintain. Differential revision: https://reviews.llvm.org/D54385 llvm-svn: 346625
2018-07-13Adjust thread name column width depending on real name length.Tatyana Krasnukha
Make 16-byte aligned field instead of truncating a name to 16 byte. llvm-svn: 336993
2018-04-30Reflow paragraphs in comments.Adrian Prantl
This is intended as a clean up after the big clang-format commit (r280751), which unfortunately resulted in many of the comment paragraphs in LLDB being very hard to read. FYI, the script I used was: import textwrap import commands import os import sys import re tmp = "%s.tmp"%sys.argv[1] out = open(tmp, "w+") with open(sys.argv[1], "r") as f: header = "" text = "" comment = re.compile(r'^( *//) ([^ ].*)$') special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$') for line in f: match = comment.match(line) if match and not special.match(match.group(2)): # skip intentionally short comments. if not text and len(match.group(2)) < 40: out.write(line) continue if text: text += " " + match.group(2) else: header = match.group(1) text = match.group(2) continue if text: filled = textwrap.wrap(text, width=(78-len(header)), break_long_words=False) for l in filled: out.write(header+" "+l+'\n') text = "" out.write(line) os.rename(tmp, sys.argv[1]) Differential Revision: https://reviews.llvm.org/D46144 llvm-svn: 331197
2018-04-10s/LLVM_ON_WIN32/_WIN32/, lldbNico Weber
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the default macro instead of a reinvented one. See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev. No intended behavior change. llvm-svn: 329697
2017-11-08Log: delimit thread name in log messagePavel Labath
The thread name was not followed by a space, which meant it was glued to the log message. I also align the name as we do that with other log fields. I align it to 16 chars instead of llvm::max_thread_name(), as that can be 64 on darwin, which is rather long. If anybody feels differently about that, we can change it. llvm-svn: 317679
2017-10-23Logging: Disable logging after fork()Pavel Labath
Summary: We had a bug where if we had forked (in the ProcessLauncherPosixFork) while another thread was writing a log message, we would deadlock. This happened because the fork child inherited the locked log rwmutex, which would never get unlocked. This meant the child got stuck trying to disable all log channels. The bug existed for a while but only started being apparent after D37930, which started using ThreadLauncher (which uses logging) instead of std::thread (which does not) for launching TaskPool threads. The fix is to use pthread_atfork to disable logging in the forked child. Reviewers: zturner, eugene, clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D38938 llvm-svn: 316368
2017-10-20Revert "Logging: Make sure logging machinery is in a consistent state after ↵Pavel Labath
forking" The pthread_atfork trick breaks on android, because pthread_rwlock_unlock detects that it is not the same thread which locked the lock. This means that the subsequent lock attempt will still deadlock (only this time it happens deterministically instead of at random). Reverting to find a better solution. This reverts commit r316173. llvm-svn: 316231
2017-10-19Logging: Make sure logging machinery is in a consistent state after forkingPavel Labath
Summary: We had a bug where if we had forked (in the ProcessLauncherPosixFork) while another thread was writing a log message, we would deadlock. This happened because the fork child inherited the locked log rwmutex, which would never get unlocked. This meant the child got stuck trying to disable all log channels. The bug existed for a while but only started being apparent after D37930, which started using ThreadLauncher (which uses logging) instead of std::thread (which does not) for launching TaskPool threads. The fix is to use pthread_atfork to make sure noone is writing a log message while we are forking. Reviewers: zturner, eugene, clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D38938 llvm-svn: 316173
2017-04-06iwyu fixes on lldbUtility.Zachary Turner
This patch makes adjustments to header file includes in lldbUtility based on recommendations by the iwyu tool (include-what-you-use). The goal here is to make sure that all files include the exact set of headers which are needed for that file only, to eliminate cases of dead includes (e.g. someone deleted some code but forgot to delete the header includes that that code necessitated), and to eliminate the case where header includes are picked up transitively. llvm-svn: 299676
2017-03-15Remove lldb streams from the Log class completelyPavel Labath
Summary: previously we switched to llvm streams for log output, this completes the switch for the error streams. I also clean up the includes and remove the unused argument from DisableAllLogChannels(). This required adding a bit of boiler plate to convert the output in the command interpreter, but that should go away when we switch command results to use llvm streams as well. Reviewers: zturner, eugene Subscribers: lldb-commits, emaste Differential Revision: https://reviews.llvm.org/D30894 llvm-svn: 297812
2017-03-09Fix remaining threading issues in Log.hPavel Labath
Summary: This fixes two threading issues in the logging code. The access to the mask and options flags had data races when we were trying to enable/disable logging while another thread was writing to the log. Since we can log from almost any context, and we want it to be fast, so I avoided locking primitives and used atomic variables instead. I have also removed the (unused) setters for the mask and flags to make sure that the only way to set them is through the enable/disable channel functions. I also add tests, which when run under tsan, verify that the use cases like "doing an LLDB_LOGV while another thread disables logging" are data-race-free. Reviewers: zturner, clayborg Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D30702 llvm-svn: 297368
2017-03-06Update log_options unit testPavel Labath
it was accessing the details of the Log class directly. Let it go through the channel class instead. This also discovered a bug when we were setting but not clearing the log options when enabling a channel. llvm-svn: 297053
2017-03-03Move Log from Core -> Utility.Zachary Turner
All references to Host and Core have been removed, so this class can now safely be lowered into Utility. Differential Revision: https://reviews.llvm.org/D30559 llvm-svn: 296909