aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Expression/Materializer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-13[lldb] Convert registers values into target endian for expressions (#148836)David Spickett1-14/+11
Relates to https://github.com/llvm/llvm-project/issues/135707 Where it was reported that reading the PC using "register read" had different results to an expression "$pc". This was happening because registers are treated in lldb as pure "values" that don't really have an endian. We have to store them somewhere on the host of course, so the endian becomes host endian. When you want to use a register as a value in an expression you're pretending that it's a variable in memory. In target memory. Therefore we must convert the register value to that endian before use. The test I have added is based on the one used for XML register flags. Where I fake an AArch64 little endian and an s390x big endian target. I set up the data in such a way the pc value should print the same for both, either with register read or an expression. I considered just adding a live process test that checks the two are the same but with on one doing cross endian testing, I doubt it would have ever caught this bug. Simulating this means most of the time, little endian hosts will test little to little and little to big. In the minority of cases with a big endian host, they'll check the reverse. Covering all the combinations.
2025-07-30[lldb] Fix updating persistent variables without JIT (#149642)Igor Kudrin1-10/+11
This patch fixes updating persistent variables when memory cannot be allocated in an inferior process: ``` > lldb -c test.core (lldb) expr int $i = 5 (lldb) expr $i = 55 (int) $0 = 55 (lldb) expr $i (int) $i = 5 ``` With this patch, the last command prints: ``` (int) $i = 55 ``` The issue was introduced in #145599.
2025-06-27[lldb] Fix evaluating expressions without JIT in an object context (#145599)Igor Kudrin1-27/+25
If a server does not support allocating memory in an inferior process or when debugging a core file, evaluating an expression in the context of a value object results in an error: ``` error: <lldb wrapper prefix>:43:1: use of undeclared identifier '$__lldb_class' 43 | $__lldb_class::$__lldb_expr(void *$__lldb_arg) | ^ ``` Such expressions require a live address to be stored in the value object. However, `EntityResultVariable::Dematerialize()` only sets `ret->m_live_sp` if JIT is available, even if the address points to the process memory and no custom allocations were made. Similarly, `EntityPersistentVariable::Dematerialize()` tries to deallocate memory based on the same check, resulting in an error if the memory was not previously allocated in `EntityPersistentVariable::Materialize()`. As an unintended bonus, the patch also fixes a FIXME case in `TestCxxChar8_t.py`.
2025-06-27[lldb][NFC] Switch IRMemoryMap::Malloc to return llvm::Expected (#146016)Igor Kudrin1-30/+26
This will make changes in #145599 a bit nicer.
2025-06-02[lldb] Refactor away UB in SBValue::GetLoadAddress (#141799)Pavel Labath1-3/+1
The problem was in calling GetLoadAddress on a value in the error state, where `ValueObject::GetLoadAddress` could end up accessing the uninitialized "address type" by-ref return value from `GetAddressOf`. This probably happened because each function expected the other to initialize it. We can guarantee initialization by turning this into a proper return value. I've added a test, but it only (reliably) crashes if lldb is built with ubsan.
2025-03-05[lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)Adrian Prantl1-30/+46
This patch pushes the error handling boundary for the GetBitSize() methods from Runtime into the Type and CompilerType APIs. This makes it easier to diagnose problems thanks to more meaningful error messages being available. GetBitSize() is often the first thing LLDB asks about a type, so this method is particularly important for a better user experience. rdar://145667239
2025-01-30[NFC][lldb] Document a few ivars on the value object system. (#124971)Augusto Noronha1-0/+3
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2024-10-24[lldb] Move ValueObject into its own library (NFC) (#113393)Jonas Devlieghere1-2/+2
ValueObject is part of lldbCore for historical reasons, but conceptually it deserves to be its own library. This does introduce a (link-time) circular dependency between lldbCore and lldbValueObject, which is unfortunate but probably unavoidable because so many things in LLDB rely on ValueObject. We already have cycles and these libraries are never built as dylibs so while this doesn't improve the situation, it also doesn't make things worse. The header includes were updated with the following command: ``` find . -type f -exec sed -i.bak "s%include \"lldb/Core/ValueObject%include \"lldb/ValueObject/ValueObject%" '{}' \; ```
2024-09-05[lldb] Make deep copies of Status explicit (NFC) (#107170)Adrian Prantl1-1/+1
2024-08-27[lldb] Turn lldb_private::Status into a value type. (#106163)Adrian Prantl1-90/+100
This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected<ResultTy> DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup.
2023-03-30[lldb][NFC] Move various constructor definitions from .h to .cppRiver Riddle1-0/+2
I ran into issues with linking downstream language plugin to liblldb in debug builds, hitting link time errors of form: ``` undefined reference to `vtable for lldb_private::<Insert LLDB class here>' ``` Anchoring the vtable to the .cpp files resolved those issues. Differential Revision: https://reviews.llvm.org/D147252
2023-01-07[lldb] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-9/+9
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to clean up the "using" declarations, #include "llvm/ADT/Optional.h", etc. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[lldb] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04[lldb] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-2/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-16Make CompilerType safeAdrian Prantl1-1/+8
When a process gets restarted TypeSystem objects associated with it may get deleted, and any CompilerType objects holding on to a reference to that type system are a use-after-free in waiting. Because of the SBAPI, we don't have tight control over where CompilerTypes go and when they are used. This is particularly a problem in the Swift plugin, where the scratch TypeSystem can be restarted while the process is still running. The Swift plugin has a lock to prevent abuse, but where there's a lock there can be bugs. This patch changes CompilerType to store a std::weak_ptr<TypeSystem>. Most of the std::weak_ptr<TypeSystem>* uglyness is hidden by introducing a wrapper class CompilerType::WrappedTypeSystem that has a dyn_cast_or_null() method. The only sites that need to know about the weak pointer implementation detail are the ones that deal with creating TypeSystems. rdar://101505232 Differential Revision: https://reviews.llvm.org/D136650
2022-07-22[LLDB][Expression] Allow instantiation of IR Entity from ValueObjectMichael Buch1-37/+172
This is required in preparation for the follow-up patch which adds support for evaluating expressions from within C++ lambdas. In such cases we need to materialize variables which are not part of the current frame but instead are ivars on a 'this' pointer of the current frame.
2022-07-22[LLDB][NFC] Create variable for hardcoded alignment/size constants in ↵Michael Buch1-8/+16
materializer
2022-07-12Reland "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Zequan Wu1-1/+1
This reland 227dffd0b6d78154516ace45f6ed28259c7baa48 and 562c3467a6738aa89203f72fc1d1343e5baadf3c with failed api tests fixed by keeping function base file addres in DWARFExpressionList.
2022-07-07Revert "[LLDB][NFC] Decouple dwarf location table from DWARFExpression."Jonas Devlieghere1-1/+1
This reverts commit 227dffd0b6d78154516ace45f6ed28259c7baa48 and its follow up 562c3467a6738aa89203f72fc1d1343e5baadf3c because it breaks a bunch of tests on GreenDragon: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45155/
2022-07-07[LLDB][NFC] Decouple dwarf location table from DWARFExpression.Zequan Wu1-1/+1
Differential Revision: https://reviews.llvm.org/D125509
2022-06-19[lldb] Use value_or instead of getValueOr (NFC)Kazu Hirata1-11/+13
2022-03-14[LLDB] Applying clang-tidy modernize-use-default-member-init over LLDBShafik Yaghmour1-11/+7
Applied modernize-use-default-member-init clang-tidy check over LLDB. It appears in many files we had already switched to in class member init but never updated the constructors to reflect that. This check is already present in the lldb/.clang-tidy config. Differential Revision: https://reviews.llvm.org/D121481
2022-02-03[lldb] Rename Logging.h to LLDBLog.h and clean up includesPavel Labath1-0/+1
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-13/+11
2022-01-26[lldb] Fix a couple of use-of-uninit-var errors in Materializer.cppPavel Labath1-2/+2
These were probably not picked up before because they only run when logging is enabled.
2021-06-11Improve materializer error messages to include type names.Adrian Prantl1-2/+4
rdar://79201552
2020-11-03[lldb/Utility] Add unit tests for RegisterValue::GetScalarValuePavel Labath1-3/+2
Buggy cases are commented out. Also sneak in a modernization of a RegisterValue constructor.
2020-07-27Unify the return value of GetByteSize to an llvm::Optional<uint64_t> (NFC-ish)Adrian Prantl1-10/+13
This cleanup patch unifies all methods called GetByteSize() in the ValueObject hierarchy to return an optional, like the methods in CompilerType do. This means fewer magic 0 values, which could fix bugs down the road in languages where types can have a size of zero, such as Swift and C (but not C++). Differential Revision: https://reviews.llvm.org/D84285 This re-lands the patch with bogus :m_byte_size(0) initalizations removed.
2020-07-25Temporarily Revert "Unify the return value of GetByteSize to an ↵Eric Christopher1-13/+10
llvm::Optional<uint64_t> (NFC-ish)" as it's causing numerous (176) test failures on linux. This reverts commit 1d9b860fb6a85df33fd52fcacc6a5efb421621bd.
2020-07-25Unify the return value of GetByteSize to an llvm::Optional<uint64_t> (NFC-ish)Adrian Prantl1-10/+13
This cleanup patch unifies all methods called GetByteSize() in the ValueObject hierarchy to return an optional, like the methods in CompilerType do. This means fewer magic 0 values, which could fix bugs down the road in languages where types can have a size of zero, such as Swift and C (but not C++). Differential Revision: https://reviews.llvm.org/D84285
2020-07-22Thread ExecutionContextScope through GetByteSize where possible (NFC-ish)Adrian Prantl1-2/+2
This patch has no effect for C and C++. In more dynamic languages, such as Objective-C and Swift GetByteSize() needs to call into the language runtime, so it's important to pass one in where possible. My primary motivation for this is some work I'm doing on the Swift branch, however, it looks like we are also seeing warnings in Objective-C that this may resolve. Everything in the SymbolFile hierarchy still passes in nullptrs, because we don't have an execution context in SymbolFile, since SymbolFile transcends processes. Differential Revision: https://reviews.llvm.org/D84267
2020-07-20[lldb] Remove redundant WithFormat suffixes (NFC)Jonas Devlieghere1-1/+1
Replace calls to FooWithFormat() with calls to Foo() when only one argument is provided and the given string doesn't need to be formatted.
2020-07-08Unify the ExecutionContextScope computation in Materializer.Adrian Prantl1-5/+12
This is an NFC cleanup for Clang, and a bugfix for the Swift branch. In swift-lldb one target may have multiple scratch TypeSystems, so it is important to pick the one that belongs to the current frame, rather than the one for the current target. <rdar://problem/65001402>
2020-06-24[lldb] Use std::make_unique<> (NFC)Jonas Devlieghere1-6/+7
Update the rest of lldb to use std::make_unique<>. I used clang-tidy to automate this, which probably missed cases that are wrapped in ifdefs.
2020-03-23Internal expressions shouldn't increment the result variable numbering.Jim Ingham1-5/+3
There an option: EvaluateExpressionOptions::SetResultIsInternal to indicate whether the result number should be returned to the pool or not. It got broken when the PersistentExpressionState was refactored. This fixes the issue and provides a test of the behavior. Differential Revision: https://reviews.llvm.org/D76532
2020-02-18[lldb] Remove DataExtractor::GetPointerPavel Labath1-2/+2
This function is equivalent to GetAddress, but getAddress is also present on the llvm version of the data extractor.
2020-01-28[lldb][NFC] Simplify Materializer/Dematerializer constructorsRaphael Isemann1-3/+0
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann1-1/+1
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-08-12[CompilerType] Pass an ExecutionContextScope to GetTypeBitAlign.Davide Italiano1-2/+2
llvm-svn: 368620
2019-08-12[Symbol] GetTypeBitAlign() should return None in case of failure.Davide Italiano1-8/+14
Summary: And not `zero`. This is the last API needed to be converted to an Optional<T>. Reviewers: xiaobai, compnerd Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D66093 llvm-svn: 368614
2019-08-08[Materializer] Remove wrong SetSizeAndAlignmentFromType().Davide Italiano1-14/+0
This function is unused. It's also wrong, because it computes the size and the alignment of the type without asking the runtime, so it doesn't work for any language that has one (e.g. swift). One could consider re-implementing this passing an execution scope context, and modifying GetTypeBitAlign() to do the right thing, but given there are no uses, it's not really useful. llvm-svn: 368249
2019-07-30[Symbol] Use llvm::Expected when getting TypeSystemsAlex Langford1-7/+5
Summary: This commit achieves the following: - Functions used to return a `TypeSystem *` return an `llvm::Expected<TypeSystem *>` now. This means that the result of a call is always checked, forcing clients to move more carefully. - `TypeSystemMap::GetTypeSystemForLanguage` will either return an Error or a non-null pointer to a TypeSystem. Reviewers: JDevlieghere, davide, compnerd Subscribers: jdoerfert, lldb-commits Differential Revision: https://reviews.llvm.org/D65122 llvm-svn: 367360
2019-07-24[Logging] Replace Log::Printf with LLDB_LOG macro (NFC)Jonas Devlieghere1-41/+48
This patch replaces explicit calls to log::Printf with the new LLDB_LOGF macro. The macro is similar to LLDB_LOG but supports printf-style format strings, instead of formatv-style format strings. So instead of writing: if (log) log->Printf("%s\n", str); You'd write: LLDB_LOG(log, "%s\n", str); This change was done mechanically with the command below. I replaced the spurious if-checks with vim, since I know how to do multi-line replacements with it. find . -type f -name '*.cpp' -exec \ sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" + Differential revision: https://reviews.llvm.org/D65128 llvm-svn: 366936
2019-07-19[NFC] Remove instances of unused ClangASTContext headerAlex Langford1-1/+0
llvm-svn: 366519
2019-02-11Use std::make_shared in LLDB (NFC)Jonas Devlieghere1-4/+6
Unlike std::make_unique, which is only available since C++14, std::make_shared is available since C++11. Not only is std::make_shared a lot more readable compared to ::reset(new), it also performs a single heap allocation for the object and control block. Differential revision: https://reviews.llvm.org/D57990 llvm-svn: 353764
2019-01-29Make Type::GetByteSize optional (NFC)Adrian Prantl1-1/+2
This is a continuation of my quest to make the size 0 a supported value. This reapplies r352394 with additional PDB parser fixes prepared by Pavel Labath! Differential Revision: https://reviews.llvm.org/D57273 llvm-svn: 352521
2019-01-28Revert "Make Type::GetByteSize optional (NFC)"Adrian Prantl1-2/+1
This reverts commit r352394 because it broke three windows-specific tests. llvm-svn: 352434
2019-01-28Make Type::GetByteSize optional (NFC)Adrian Prantl1-1/+2
This is a continuation of my quest to make the size 0 a supported value. Differential Revision: https://reviews.llvm.org/D57273 llvm-svn: 352394
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
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
2019-01-15Replace auto -> llvm::Optional<uint64_t>Adrian Prantl1-2/+2
This addresses post-commit feedback for https://reviews.llvm.org/D56688 llvm-svn: 351237