aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/API/SBDebugger.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-06-23[lldb] Support a buffered logging modeJonas Devlieghere1-1/+1
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-20Add LoadTraceFromFile to SBDebugger and SBTraceJakob Johnson1-0/+8
Add trace load functionality to SBDebugger via the `LoadTraceFromFile` method. Update intelpt test case class to have `testTraceLoad` method so we can take advantage of the testApiAndSB decorator to test both the CLI and SB without duplicating code. Differential Revision: https://reviews.llvm.org/D128107
2022-04-13[lldb] Remove the global platform listPavel Labath1-15/+5
This patch moves the platform creation and selection logic into the per-debugger platform lists. I've tried to keep functional changes to a minimum -- the main (only) observable difference in this change is that APIs, which select a platform by name (e.g., Debugger::SetCurrentPlatform) will not automatically pick up a platform associated with another debugger (or no debugger at all). I've also added several tests for this functionality -- one of the pleasant consequences of the debugger isolation is that it is now possible to test the platform selection and creation logic. This is a product of the discussion at <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>. Differential Revision: https://reviews.llvm.org/D120810
2022-04-07[lldb] Use getMainExecutable in SBDebugger::PrintStackTraceOnErrorJonas Devlieghere1-3/+3
Implement Pavel's suggestion to use llvm::sys::fs::getMainExecutable to find the executable name for llvm::sys::PrintStackTraceOnErrorSignal.
2022-04-07[lldb] Add Python bindings to print stack traces on crashes.Jonas Devlieghere1-0/+11
As noticed in D87637, when LLDB crashes, we only print stack traces if LLDB is directly executed, not when used via Python bindings. Enabling this by default may be undesirable (libraries shouldn't be messing with signal handlers), so make this an explicit opt-in. I "commandeered" this patch from Jordan Rupprecht who put this up for review originally. Differential revision: https://reviews.llvm.org/D91835
2022-03-16[lldb] Expose diagnostic events through the SB APIJonas Devlieghere1-0/+20
Expose diagnostic events through the SB API. Unlike the progress events, I opted to use a SBStructuredData so that we can add fields in the future. Differential revision: https://reviews.llvm.org/D121818
2022-03-14[lldb] Move ProgressEventData out of debugger and into its own file (NFC)Jonas Devlieghere1-2/+3
Move ProgressEventData out of debugger and into its own file. This is in preparation of adding a few new type of event data for diagnostics. Differential revision: https://reviews.llvm.org/D121506
2022-03-09Revert "[lldb] Remove the global platform list"Pavel Labath1-5/+15
It makes module dependencies loopier. This reverts commits 49cffe3c7fab74252d4b6a073303c803dc1659f0 and ffb9429b6f3c29ab4687b96fd85374924c98ad16.
2022-03-09[lldb] Remove the global platform listPavel Labath1-15/+5
This patch moves the platform creation and selection logic into the per-debugger platform lists. I've tried to keep functional changes to a minimum -- the main (only) observable difference in this change is that APIs, which select a platform by name (e.g., Debugger::SetCurrentPlatform) will not automatically pick up a platform associated with another debugger (or no debugger at all). I've also added several tests for this functionality -- one of the pleasant consequences of the debugger isolation is that it is now possible to test the platform selection and creation logic. This is a product of the discussion at <https://discourse.llvm.org/t/multiple-platforms-with-the-same-name/59594>. Differential Revision: https://reviews.llvm.org/D120810
2022-02-25Reland "[lldb/test] Fix TestProgressReporting.py race issue with the event ↵Med Ismail Bennani1-2/+1
listener" This patch relands commit 3e3e79a9e4c378b59f5f393f556e6a84edcd8898, and fixes the memory sanitizer issue described in D120284, by removing the output arguments from the LLDB_INSTRUMENT_VA invocation. Differential Revision: https://reviews.llvm.org/D120599 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-02-18[lldb] Add support for a "global" lldbinit filePavel Labath1-0/+1
This patch adds introduces a new kind of an lldbinit file. Unlike the lldbinit in the home directory (useful for customizing lldb to the needs of a particular user), or the cwd lldbinit file (useful for project-specific settings), this file can be used to customize an entire lldb installation to a particular environment. The feature is enabled at build time, by setting the LLDB_GLOBAL_INIT_DIRECTORY variable to a path to a directory which should contain an "lldbinit" file. Lldb will then load the file at startup, if it exists, and if automatic init loading has not been disabled. Relative paths will be resolved (at runtime) relative to the location of the lldb library (liblldb or LLDB.framework). The system-wide lldbinit file will be loaded first, before any $HOME/.lldbinit and $CWD/.lldbinit files are processed, so that those can override any system-wide settings. More information can be found on the RFC thread at <https://discourse.llvm.org/t/rfc-system-wide-lldbinit/59933>. Differential Revision: https://reviews.llvm.org/D119831
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath1-2/+2
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-02-02[lldb] Convert "LLDB" log channel to the new APIPavel Labath1-12/+12
2022-01-20[lldb] Decouple instrumentation from the reproducersJonas Devlieghere1-229/+139
Remove the last remaining references to the reproducers from the instrumentation. This patch renames the relevant files and macros. Differential revision: https://reviews.llvm.org/D117712
2022-01-19[lldb] Introduce SBPlatform::SetSDKRootPavel Labath1-12/+3
It complements the existing SBDebugger::SetCurrentPlatformSDKRoot and allows one to set the sysroot of a platform without making it current. Differential Revision: https://reviews.llvm.org/D117550
2022-01-10[lldb] Remove LLDB_RECORD_DUMMY_* macrosJonas Devlieghere1-14/+15
2022-01-10[lldb] Remove LLDB_RECORD_CHAR_PTR_* macrosJonas Devlieghere1-3/+2
2022-01-09[lldb] Remove LLDB_RECORD_RESULT macroJonas Devlieghere1-82/+79
2022-01-09[lldb] Remove reproducer instrumentationJonas Devlieghere1-218/+1
This patch removes most of the reproducer instrumentation. It keeps around the LLDB_RECORD_* macros for logging. See [1] for more details. [1] https://lists.llvm.org/pipermail/lldb-dev/2021-September/017045.html Differential revision: https://reviews.llvm.org/D116847
2022-01-05[lldb] Create a property to store the REPL languageJonas Devlieghere1-0/+19
Until the introduction of the C++ REPL, there was always a single REPL language. Several places relied on this assumption through repl_languages.GetSingularLanguage. Now that this is no longer the case, we need a way to specify a selected/preferred REPL language. This patch does that with the help of a debugger property, taking inspiration from how we store the scripting language. Differential revision: https://reviews.llvm.org/D116697
2021-12-14[lldb] Introduce a FreeBSDKernel plugin for vmcoresMichał Górny1-0/+3
Introduce a FreeBSDKernel plugin that provides the ability to read FreeBSD kernel core dumps. The plugin utilizes libfbsdvmcore to provide support for both "full memory dump" and minidump formats across variety of architectures supported by FreeBSD. It provides the ability to read kernel memory, as well as the crashed thread status with registers on arm64, i386 and x86_64. Differential Revision: https://reviews.llvm.org/D114911
2021-12-08[lldb] Make lldbVersion a full fledged libraryJonas Devlieghere1-2/+1
Because of its dependency on clang (and potentially other compilers downstream, such as swift) lldb_private::GetVersion already lives in its own library called lldbBase. Despite that, its implementation was spread across unrelated files. This patch improves things by introducing a Version library with its own directory, header and implementation file. The benefits of this patch include: - We can get rid of the ugly quoting macros. - Other parts of LLDB can read the version number from lldb/Version/Version.inc. - The implementation can be swapped out for tools like lldb-server than don't need to depend on clang at all. Differential revision: https://reviews.llvm.org/D115211
2021-11-24Fixed use of -o and -k in LLDB under Windows when statically compiled with ↵Levon Ter-Grigoryan1-31/+31
vcruntime. Right now if the LLDB is compiled under the windows with static vcruntime library, the -o and -k commands will not work. The problem is that the LLDB create FILE* in lldb.exe and pass it to liblldb.dll which is an object from CRT. Since the CRT is statically linked each of these module has its own copy of the CRT with it's own global state and the LLDB should not share CRT objects between them. In this change I moved the logic of creating FILE* out of commands stream from Driver class to SBDebugger. To do this I added new method: SBError SBDebugger::SetInputStream(SBStream &stream) Command to build the LLDB: cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lldb;libcxx" -DLLVM_USE_CRT_RELEASE="MT" -DLLVM_USE_CRT_MINSIZEREL="MT" -DLLVM_USE_CRT_RELWITHDEBINFO="MT" -DP YTHON_HOME:FILEPATH=C:/Python38 -DCMAKE_C_COMPILER:STRING=cl.exe -DCMAKE_CXX_COMPILER:STRING=cl.exe ../llvm Command which will fail: lldb.exe -o help See discord discussion for more details: https://discord.com/channels/636084430946959380/636732809708306432/854629125398724628 This revision is for the further discussion. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104413
2021-11-10[lldb] make it easier to find LLDB's pythonLawrence D'Anna1-0/+17
It is surprisingly difficult to write a simple python script that can reliably `import lldb` without failing, or crashing. I'm currently resorting to convolutions like this: def find_lldb(may_reexec=False): if prefix := os.environ.get('LLDB_PYTHON_PREFIX'): if os.path.realpath(prefix) != os.path.realpath(sys.prefix): raise Exception("cannot import lldb.\n" f" sys.prefix should be: {prefix}\n" f" but it is: {sys.prefix}") else: line1, line2 = subprocess.run( ['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'], encoding='utf8', stdout=subprocess.PIPE, check=True).stdout.strip().splitlines() assert line1.strip() == '(lldb) script print(sys.prefix)' prefix = line2.strip() os.environ['LLDB_PYTHON_PREFIX'] = prefix if sys.prefix != prefix: if not may_reexec: raise Exception( "cannot import lldb.\n" + f" This python, at {sys.prefix}\n" f" does not math LLDB's python at {prefix}") os.environ['LLDB_PYTHON_PREFIX'] = prefix python_exe = os.path.join(prefix, 'bin', 'python3') os.execl(python_exe, python_exe, *sys.argv) lldb_path = subprocess.run(['lldb', '-P'], check=True, stdout=subprocess.PIPE, encoding='utf8').stdout.strip() sys.path = [lldb_path] + sys.path This patch aims to replace all that with: #!/usr/bin/env lldb-python import lldb ... ... by adding the following features: * new command line option: --print-script-interpreter-info. This prints language-specific information about the script interpreter in JSON format. * new tool (unix only): lldb-python which finds python and exec's it. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D112973
2021-10-26[lldb] Remove ConstString from Platform plugin namesPavel Labath1-7/+4
2021-10-18[lldb] Return StringRef from PluginInterface::GetPluginNamePavel Labath1-2/+1
There is no reason why this function should be returning a ConstString. While modifying these files, I also fixed several instances where GetPluginName and GetPluginNameStatic were returning different strings. I am not changing the return type of GetPluginNameStatic in this patch, as that would necessitate additional changes, and this patch is big enough as it is. Differential Revision: https://reviews.llvm.org/D111877
2021-05-31[lldb][NFC] Remove unused var in SBDebugger::GetInternalVariableValueRaphael Isemann1-1/+0
This variable was originally just the default return value but got unused in 6920b52be6f8731692a9bff4fe6a7b596cda00c5 .
2021-05-31[lldb] Fix typos. NFC.Bruce Mitchener1-1/+1
Differential Revision: https://reviews.llvm.org/D103381
2021-05-18[lldb][NFC] Remove all uses of StringRef::withNullAsEmpty in LLDBRaphael Isemann1-1/+1
A long time ago LLDB wanted to start using StringRef instead of C-Strings/ConstString but was blocked by the fact that the StringRef constructor that takes a C-string was asserting that the C-string isn't a nullptr. To workaround this, D24697 introduced a special function called `withNullAsEmpty` and that's what LLDB (and only LLDB) started to use to build StringRefs from C-strings. A bit later it seems that `withNullAsEmpty` was declared too awkward to use and instead the assert in the StringRef constructor got removed (see D24904). The rest of LLDB was then converted to StringRef by just calling the now perfectly usable implicit constructor. However, all the calls to `withNullAsEmpty` just remained and are now just strange artefacts in the code base that just look out of place. It's also curiously a LLDB-exclusive function and no other project ever called it since it's introduction half a decade ago. This patch removes all uses of `withNullAsEmpty`. The follow up will be to remove the function from StringRef. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D102597
2021-03-24Add a progress class that can track long running operations in LLDB.Greg Clayton1-1/+43
LLDB can often appear deadlocked to users that use IDEs when it is indexing DWARF, or parsing symbol tables. These long running operations can make a debug session appear to be doing nothing even though a lot of work is going on inside LLDB. This patch adds a public API to allow clients to listen to debugger events that report progress and will allow UI to create an activity window or display that can show users what is going on and keep them informed of expensive operations that are going on inside LLDB. Differential Revision: https://reviews.llvm.org/D97739
2021-02-02Revert "[lldb] Use current execution context in SBDebugger"Raphael Isemann1-2/+4
This reverts commit 754ab803b8dc659e3645d369d1b5d6d2f97be29e. As pointed out in https://reviews.llvm.org/D95761, this patch could lead to having the wrong execution context in some situations (thanks Jim!). D92164 is addressing the same issue and will replace this patch, so I'll revert this one.
2021-02-01[lldb] Use current execution context in SBDebuggerAndy Yankovsky1-4/+2
Use `GetSelectedExecutionContext()` instead of `GetCommandInterpreter().GetExecutionContext()` in `SBDebugger::GetInternalVariableValue/SBDebugger::SetInternalVariable`. The execution context in the command interpreter might be empty, if no commands has been executed yet (it is updated only when handling commands or completions -- e.g. https://github.com/llvm/llvm-project/blob/main/lldb/source/Interpreter/CommandInterpreter.cpp#L1855). Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D95761
2021-01-26Make SBDebugger::CreateTargetWithFileAndArch work with lldb::LLDB_DEFAULT_ARCHJim Ingham1-9/+21
Second try, handling both a bogus arch string and the "null file & arch" used to create an empty but valid target. Also check in that case before logging (previously the logging would have crashed.)
2021-01-25Revert "Fix SBDebugger::CreateTargetWithFileAndArch to accept ↵Richard Smith1-11/+7
LLDB_ARCH_DEFAULT." Also revert "Follow on to: f05dc40c31d1883b46b8bb60547087db2f4c03e3" After these changes, multiple lldb tests are failing. Calls to CreateTargetWithFileAndArch(None, None) appear to fail after these changes. This reverts commit f05dc40c31d1883b46b8bb60547087db2f4c03e3 and 1fba21778f84f266f7d32153c88e59e1900fbe5b.
2021-01-25Follow on to: f05dc40c31d1883b46b8bb60547087db2f4c03e3Jim Ingham1-6/+8
When you pass in a bogus ArchSpec, TargetList.CreateTarget makes a target with the arch of the executable. That wasn't the case with a bogus triple, so this change caused one of the bogus input data tests to fail. So check that the ArchSpec is valid before passing it to CreateTarget.
2021-01-25Fix SBDebugger::CreateTargetWithFileAndArch to accept LLDB_ARCH_DEFAULT.Jim Ingham1-4/+6
The API docs in SBDebugger.i claim this should work but it doesn't. This should fix it. Differential Revision: https://reviews.llvm.org/D95164
2020-12-12[lldb] "target create" shouldn't save target if the command failedTatyana Krasnukha1-7/+3
TargetList::CreateTarget automatically adds created target to the list, however, CommandObjectTargetCreate does some additional preparation after creating a target and which can fail. The command should remove created target if it failed. Since the function has many ways to return, scope guard does this work safely. Changes to the TargetList make target adding and selection more transparent. Other changes remove unnecessary SetSelectedTarget after CreateTarget. Differential Revision: https://reviews.llvm.org/D93052
2020-11-09[lldb] Make GetSelectedOrDummyTarget return the target by reference (NFC)Jonas Devlieghere1-1/+1
Return references from GetDummyTarget and GetSelectedOrDummyTarget. This matches how the APIs are already used in practice.
2020-08-20[lldb/interpreter] Add REPL-specific init fileMed Ismail Bennani1-1/+1
This patch adds the infrastructure to have language specific REPL init files. It's the foundation work to a following patch that will introduce Swift REPL init file. When lldb is launched with the `--repl` option, it will look for a REPL init file in the home directory and source it. This overrides the default `~/.lldbinit`, which content might make the REPL behave unexpectedly. If the REPL init file doesn't exists, lldb will fall back to the default init file. rdar://65836048 Differential Revision: https://reviews.llvm.org/D86242 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-08-17[lldb] Don't delete orphaned shared modules in SBDebugger::DeleteTargetRaphael Isemann1-2/+0
In D83876 the consensus seems that LLDB should never deleted orphaned modules implicitly. However, SBDebugger::DeleteTarget is currently doing exactly that. This code was added in 753406221b55b95141c8c1239660dc4db4e35ea5 but I don't see any explanation in the commit, so I think we should delete it. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D83933
2020-07-10[ldb/Reproducers] Add YamlRecorder and MultiProviderJonas Devlieghere1-1/+1
This patch does several things that are all closely related: - It introduces a new YamlRecorder as a counterpart to the existing DataRecorder. As the name suggests the former serializes data as yaml while the latter uses raw texts or bytes. - It introduces a new MultiProvider base class which can be backed by either a DataRecorder or a YamlRecorder. - It reimplements the CommandProvider in terms of the new MultiProvider. Finally, it adds unit testing coverage for the MultiProvider, a naive YamlProvider built on top of the new YamlRecorder and the existing MutliLoader. Differential revision: https://reviews.llvm.org/D83441
2020-05-01[lldb/API] Add SBCommandInterpreterRunResultJonas Devlieghere1-0/+19
This adds an RunCommandInterpreter overload that returns an instance of SBCommandInterpreterRunResults. The goal is to avoid having to add more and more overloads when we need more output arguments. Differential revision: https://reviews.llvm.org/D79120
2020-05-01[lldb/CommandInterpreter] Add CommandInterpreterRunResult (NFC)Jonas Devlieghere1-4/+7
This patch adds a new class CommandInterpreterRunResult which will be backing the SBCommandInterpreterRunResult. It keeps track of the number of errors as well as the result which is an enum, as proposed by Pavel in D79120. The command interpreter now populates the results directly, instead of its own member variables. Differential revision: https://reviews.llvm.org/D79209
2020-04-30[lldb/API] Move SBCommandInterpreterRunOption in its own header. (NFC)Jonas Devlieghere1-0/+1
Currently, `SBCommandInterpreterRunOptions` is defined in `SBCommandInterpreter.h`. Given that the options are always passed by reference, a forward declaration is sufficient. That's not the case for `SBCommandInterpreterRunResults`, which we need for a new overload for `RunCommandInterpreter` and that returns this new class by value. We can't include `SBCommandInterpreter.h` because `SBCommandInterpreter::GetDebugger()` returns SBDebugger by value and therefore needs a full definition. This patch moves the definition of `SBCommandInterpreterRunOptions` into a new header. In a later patch, `SBCommandInterpreterRunResults` will be defined in there as well, solving the aforementioned problem. Differential revision: https://reviews.llvm.org/D79115
2020-04-30[lldb/CommandInterpreter] Move everything into CommandInterpreterRunOptionsJonas Devlieghere1-5/+6
This implements Greg's suggestion from D78825 to include "auto handle events" and "spawn thread" in CommandInterpreterRunOptions. This change is in preparation for adding a new overload for RunCommandInterpreter that takes only SBCommandInterpreterRunOptions and returns SBCommandInterpreterRunResults. Differential revision: https://reviews.llvm.org/D79108
2020-04-20[lldb/Reproducers] Fix passive replay for (char*, size_t) functions.Jonas Devlieghere1-4/+5
Several SB API functions return strings using (char*, size_t) output arguments. During capture, we serialize an empty string for the char* because the memory can be uninitialized. During active replay, we have custom replay redirects that ensure that we don't override the buffer from which we're reading, but rather write to a buffer on the heap with the given length. This is sufficient for the active reproducer use case, where we only care about the side effects of the API calls, not the values actually returned. This approach does not not work for passive replay because here we ignore all the incoming arguments, and re-execute the current function with the arguments deserialized from the reproducer. This means that these function will update the deserialized copy of the arguments, rather than whatever was passed in by the SWIG wrapper. To solve this problem, this patch extends the reproducer instrumentation to handle this special case for passive replay. We nog ignore the replayer in the registry and the incoming char pointer, and instead reinvoke the current method on the deserialized class, and populate the output argument. Differential revision: https://reviews.llvm.org/D77759
2020-04-20[lldb/Reproducers] Support new replay mode: passive replayJonas Devlieghere1-10/+10
Support passive replay as proposed in the RFC [1] on lldb-dev and described in more detail on the lldb website [2]. This patch extends the LLDB_RECORD macros to re-invoke the current function with arguments deserialized from the reproducer. This relies on the function being called in the exact same order as during replay. It uses the same mechanism to toggle the API boundary as during recording, which guarantees that only boundary crossing calls are replayed. Another major change is that before this patch we could ignore the result of an API call, because we only cared about the observable behavior. Now we need to be able to return the replayed result to the SWIG bindings. We reuse a lot of the recording infrastructure, which can be a little confusing. We kept the existing naming to limit the amount of churn, but might revisit that in a future patch. [1] http://lists.llvm.org/pipermail/lldb-dev/2020-April/016100.html [2] https://lldb.llvm.org/resources/reproducers.html Differential revision: https://reviews.llvm.org/D77602
2020-04-20[lldb] Add new LLDB setting: use-source-cacheEmre Kultursay1-0/+12
Summary: LLDB memory-maps large source files, and at the same time, caches all source files in the Source Cache. On Windows, memory-mapped source files are not writeable, causing bad user experience in IDEs (such as errors when saving edited files). IDEs should have the ability to disable the Source Cache at LLDB startup, so that users can edit source files while debugging. Bug: llvm.org/PR45310 Reviewers: labath, JDevlieghere, jingham Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D76804
2020-02-05[lldb/Reproducers] Implement custom replayers for (char *, size_t)Jonas Devlieghere1-11/+3
Some SB API methods returns strings through a char* and a length. This is a problem for the deserializer, which considers a single type at a time, and therefore cannot know how many bytes to allocate for the character buffer. We can solve this problem by implementing a custom replayer, which ignores the passed-in char* and allocates a buffer of the correct size itself, before invoking the original API method or function. This patch adds three new macros to register a custom replayer for methods that take a char* and a size_t. It supports arbitrary return values (some functions return a bool while others return a size_t).
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
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.