summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
AgeCommit message (Collapse)Author
2025-09-12[lldb] Fixed UB in CPlusPlusLanguage plug-in (#158304)Dmitry Vasilyev
C++11 allows the use of Universal Character Names (UCNs) in identifiers, including function names. According to the spec the behavior of std::isalpha(ch) and std::isalnum(ch) is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char.
2025-08-25[lldb][DataFormatters] Support newer _LIBCPP_COMPRESSED_PAIR layout (#155153)Michael Buch
Starting with https://github.com/llvm/llvm-project/pull/154686 the compressed_pair children are now wrapped in an anonymous structure. This patch adjusts the LLDB data-formatters to support that. Outstanding questions: 1. Should GetChildMemberWithName look through anonymous structures? That will break users most likely. But maybe introducing a new API is worth it? Then we wouldnt have to do this awkward passing around of `anon_struct_index` 2. Do we support the layout without the anonymous structure? It's not too much added complexity. And we did release that version of libc++, so there is code out there compiled against it. But there is no great way of testing it (some of our macOS matrix bots do test it i suppose, but not in a targeted way). We have the layout "simulator" tests for some of the STL types which I will adjust.
2025-07-08[lldb][Formatters] Consistently unwrap pointer element_type in ↵Michael Buch
std::shared_ptr formatters (#147340) Follow-up to https://github.com/llvm/llvm-project/pull/147165#pullrequestreview-2992585513 Currently when we explicitly dereference a std::shared_ptr, both the libstdc++ and libc++ formatters will cast the type of the synthetic pointer child to whatever the `std::shared_ptr::element_type` is aliased to. E.g., ``` (lldb) v p (std::shared_ptr<int>) p = 10 strong=1 weak=0 { pointer = 0x000000010016c6a0 } (lldb) v *p (int) *p = 10 ``` However, when we print (or dereference) `p.pointer`, the type devolves to something less user-friendly: ``` (lldb) v p.pointer (std::shared_ptr<int>::element_type *) p.pointer = 0x000000010016c6a0 (lldb) v *p.pointer (std::shared_ptr<int>::element_type) *p.pointer = 10 ``` This patch changes both formatters to store the casted type. Then `GetChildAtIndex` will consistently use the unwrapped type.
2025-07-07[lldb][Formatter] Consolidate libstdc++ and libc++ unique_ptr formatter ↵Michael Buch
tests into generic test (#147031) The libc++ test was a subset of the tests in libstdc++. This test moves the libc++ test into `generic` and somne additional test-cases from `libstdc++` (specifically the recursive unique_ptr case). It turns out the libstdc++ formatter supports dereferencing using the "object" or "obj" names. We could either drop those from the tests or support the same for libc++. I took the latter approach but don't have strong opinions on this. Split out from https://github.com/llvm/llvm-project/pull/146740
2025-07-07[lldb][Formatters] Make libc++ and libstdc++ std::shared_ptr formatters ↵Michael Buch
consistent with each other (#147165) This patch adjusts the libcxx and libstdcxx std::shared_ptr formatters to look the same. Changes to libcxx: * Now creates a synthetic child called `pointer` (like we already do for `std::unique_ptr`) Changes to libstdcxx: * When asked to dereference the pointer, cast the type of the result ValueObject to the element type (which we get from the template argument to std::shared_ptr). Before: ``` (std::__shared_ptr<int, __gnu_cxx::_S_atomic>::element_type) *foo = 123 ``` After: ``` (int) *foo = 123 ``` Tested in https://github.com/llvm/llvm-project/pull/147141
2025-07-07[lldb][Formatters] Use container summary helper for libstdc++ formatters ↵Michael Buch
(#147140) This re-uses the `LibcxxContainerSummaryProvider` for the libstdc++ formatters. There's a couple of containers that aren't making use of it for libstdc++. This patch will make it easier to review when adding those in the future.
2025-07-04[lldb][Formatters] Fix weak reference count for ↵Michael Buch
std::shared_ptr/std::weak_ptr (#147033) For the `__shared_owners_` we need to add `+1` to the count, but for `__shared_weak_owners_` the value reflects the exact number of weak references.
2025-07-04[lldb][DataFormatter] Format libstdc++ unique_ptr like we do libc++ (#146909)Michael Buch
The only difference is that with libc++ the summary string contains the derefernced pointer value. With libstdc++ we currently display the pointer itself, which seems redundant. E.g., ``` (std::unique_ptr<int>) iup = 0x55555556d2b0 { pointer = 0x000055555556d2b0 } (std::unique_ptr<std::basic_string<char> >) sup = 0x55555556d2d0 { pointer = "foobar" } ``` This patch moves the logic into a common helper that's shared between the libc++ and libstdc++ formatters. After this patch we can combine the libc++ and libstdc++ API tests (see https://github.com/llvm/llvm-project/pull/146740).
2025-06-17[LLDB] Consolidate C++ string buffer summaries (#144258)nerix
As part of https://github.com/llvm/llvm-project/pull/143177, I moved the non-libc++ specific formatting of `std::string`s out to `CxxStringTypes` as MSVC's STL `std::string` can also be thought of a pointer+size pair. I named this kind of string "string buffer". This PR picks that change, so the MSVC PR can be smaller. Unfortunately, libstdc++'s `std::string` does not fit this (it also uses a different string printer function). This resolves two FIXMEs in the libc++ tests, where empty u16 and u32 strings didn't have any prefix (u/U).
2025-04-30[lldb] Upgrade `GetIndexOfChildWithName` to use `llvm::Expected` (#136693)Charles Zablit
This patch replaces the use of `UINT32_MAX` as the error return value of `GetIndexOfChildWithName` with `llvm::Expected`. # Tasks to do in another PR 1. Replace `CalculateNumChildrenIgnoringErrors` with `CalculateNumChildren`. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056319358). 2. Update `lldb_private::formatters::ExtractIndexFromString` to use `llvm::Expected`. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2054217536). 3. Create a new class which carries both user and internal errors. See [this comment](https://github.com/llvm/llvm-project/pull/136693#discussion_r2056439608).
2025-03-05[lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)Adrian Prantl
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-02-17[lldb] Provide default impl for MightHaveChildren (NFC) (#119977)Dave Lee
The vast majority of `SyntheticChildrenFrontEnd` subclasses provide children, and as such implement `MightHaveChildren` with a constant value of `true`. This change makes `true` the default value. With this change, `MightHaveChildren` only needs to be implemented by synthetic providers that can return `false`, which is only 3 subclasses.
2025-02-03[lldb] Show value for libcxx and libstdcxx summary and remove pointer value ↵Zequan Wu
in libcxx container summary (#125294) This has two changes: 1. Set show value for libcxx and libstdcxx summary provider. This will print the pointer value for both pointer type and reference type. 2. Remove pointer value printing in libcxx container summary. Discussion: https://discourse.llvm.org/t/lldb-hides-raw-pointer-value-for-libcxx-and-libstdcxx-pointer-types-in-summary-string/84226
2024-10-24[lldb] Move ValueObject into its own library (NFC) (#113393)Jonas Devlieghere
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-16[lldb] Support new libc++ __compressed_pair layout (#96538)Michael Buch
This patch is in preparation for the `__compressed_pair` refactor in https://github.com/llvm/llvm-project/pull/76756. This is mostly reviewable now. With the new layout we no longer need to unwrap the `__compressed_pair`. Instead, we just need to look for child members. E.g., to get to the underlying pointer of `std::unique_ptr` we no longer do, ``` GetFirstValueOfCXXCompressedPair(GetChildMemberWithName("__ptr_")) ``` but instead do ``` GetChildMemberWithName("__ptr_") ``` We need to be slightly careful because previously the `__compressed_pair` had a member called `__value_`, whereas now `__value_` might be a member of the class that used to hold the `__compressed_pair`. So before unwrapping the pair, we added checks for `isOldCompressedLayout` (not sure yet whether folding this check into `GetFirstValueOfCXXCompressedPair` is better).
2024-07-08[lldb][DataFormatter] Move std::unordered_map::iterator formatter into ↵Michael Buch
LibCxxUnorderedMap.cpp (#97752) Similar to how we moved the `std::map::iterator` formatter in https://github.com/llvm/llvm-project/pull/97687, do the same for `std::unordered_map::iterator`. Again the `unordered_map` and `unordered_map::iterator` formatters try to do very similar things: retrieve data out of the map. The iterator formatter does this in a fragile way (similar to how `std::map` does it, see https://github.com/llvm/llvm-project/pull/97579). Thus we will be refactoring the `std::unordered_map::iterator` in upcoming patches. Having it in `LibCxxUnorderedMap` will allow us to re-use some of the logic (and we won't have to repeat some of the clarification comments).
2024-07-04[lldb][DataFormatter][NFC] Move std::map iterator formatter into ↵Michael Buch
LibCxxMap.cpp (#97687) The two formatters follow very similar techniques to retrieve data out of the map. We're changing this for `std::map` in https://github.com/llvm/llvm-project/pull/97579 and plan to change it in the same way for the iterator formatter. Having them in the same place will allow us to re-use some of the logic (and we won't have to repeat some of the clarification comments).
2024-07-04[lldb][DataFormatter][NFC] Remove duplicate null-check in std::map iterator ↵Michael Buch
formatter The nullness is already checked a few lines before this.
2024-06-25[lldb][LibCxx] Move incorrect nullptr check (#96635)Michael Buch
Found while skimming this code. Don't have a reproducible test case for this but the nullptr check should clearly occur before we try to dereference `location_sp`.
2024-05-20[lldb][Windows] Fixed LibcxxChronoTimePointSecondsSummaryProvider() (#92701)Dmitry Vasilyev
This patch fixes #92574. It is a replacement for #92575.
2024-04-13[lldb][libc++] Adds local_t clock data formatters. (#88178)Mark de Wever
2024-03-26[lldb] Fix warning: comparison of unsigned expression in >= 0 is always trueJonas Devlieghere
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp:1195:15: warning: comparison of unsigned expression in ‘>= 0’ is always true 1195 | if (weekday >= 0 && weekday < 7) | ~~~~~~~~^~~~
2024-03-21[lldb] Reland: Store SupportFile in FileEntry (NFC) (#85892)Jonas Devlieghere
This is another step towards supporting DWARF5 checksums and inline source code in LLDB. This is a reland of #85468 but without the functional change of storing the support file from the line table (yet).
2024-03-19Revert "[lldb] Store SupportFile in FileEntry (NFC)" (#85885)Jonas Devlieghere
Reverts llvm/llvm-project#85468 because @slackito reports this broke stepping in one of their tests [1] and this patch was meant to be NFC. [1] https://github.com/llvm/llvm-project/commit/d5a277d309e92b1d3e493da6036cffdf815105b1#commitcomment-139991120
2024-03-15[lldb] Store SupportFile in FileEntry (NFC) (#85468)Jonas Devlieghere
This is another step towards supporting DWARF5 checksums and inline source code in LLDB.
2024-03-08Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected ↵Adrian Prantl
(#84219) Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected This is an NFC change that does not yet add any error handling or change any code to return any errors. This is the second big change in the patch series started with https://github.com/llvm/llvm-project/pull/83501 A follow-up PR will wire up error handling.
2024-03-08Revert "Change GetNumChildren()/CalculateNumChildren() methods return ↵Florian Mayer
llvm::Expected (#84219)" This reverts commit 99118c809367d518ffe4de60c16da953744b68b9.
2024-03-08Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected ↵Adrian Prantl
(#84219) Change GetNumChildren()/CalculateNumChildren() methods return llvm::Expected This is an NFC change that does not yet add any error handling or change any code to return any errors. This is the second big change in the patch series started with https://github.com/llvm/llvm-project/pull/83501 A follow-up PR will wire up error handling.
2024-03-07Change GetChildAtIndex to take a uint32_tAdrian Prantl
2024-03-07Change the return type of SyntheticFrontend::CalculateNumChildren to int32_tAdrian Prantl
This way it is consistent with ValueObject and TypeSystem.
2024-02-08[lldb] Fix printf formatting of std::time_t seconds (#81078)Jason Molenda
This formatter https://github.com/llvm/llvm-project/pull/78609 was originally passing the signed seconds (which can refer to times in the past) with an unsigned printf formatter, and had tests that expected to see negative values from the printf which always failed on macOS. I'm not clear how they ever passed on any platform. Fix the printf to print seconds as a signed value, and re-enable the tests.
2024-02-08[lldb][TypeSynthetic][NFC] Make SyntheticChildrenFrontend::Update() return ↵Michael Buch
an enum (#80167) This patch changes the return value of `SyntheticChildrenFrontend::Update` to a scoped enum that aims to describe what the return value means.
2024-01-25[lldb] Fix printf format errorsKazu Hirata
This patch fixes: lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp:1108:39: error: format specifies type 'long long' but the argument has type 'std::time_t' (aka 'long') [-Werror,-Wformat] lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp:1116:64: error: format specifies type 'long long' but the argument has type 'std::time_t' (aka 'long') [-Werror,-Wformat]
2024-01-25[lldb] Silence warning when building with Clang ToTAlexandre Ganea
This fixes: ``` [6331/7452] Building CXX object tools\lldb\source\Plugins\Language\CPlusPlus\CMakeFiles\lldbPluginCPlusPlusLanguage.dir\LibCxx.cpp.obj C:\git\llvm-project\lldb\source\Plugins\Language\CPlusPlus\LibCxx.cpp(1108,38): warning: format specifies type 'long' but the argument has type 'std::time_t' (aka 'long long') [-Wformat] 1108 | stream.Printf("timestamp=%ld s", seconds); | ~~~ ^~~~~~~ | %lld C:\git\llvm-project\lldb\source\Plugins\Language\CPlusPlus\LibCxx.cpp(1116,63): warning: format specifies type 'long' but the argument has type 'std::time_t' (aka 'long long') [-Wformat] 1116 | stream.Printf("date/time=%s timestamp=%ld s", str.data(), seconds); | ~~~ ^~~~~~~ | %lld 2 warnings generated. ```
2024-01-22[lldb][libc++] Adds system_clock data formatters. (#78609)Mark de Wever
2024-01-13[lldb][libc++] Adds missing C++20 calendar data formatters. (#77954)Mark de Wever
This is a followup of #76983 and adds the libc++ data formatters for - weekday, - weekday_indexed, - weekday_last, - month_weekday, - month_weekday_last, - year_month, - year_month_day_last - year_month_weekday, and - year_month_weekday_last.
2024-01-09[lldb][libc++] Adds some C++20 calendar data formatters. (#76983)Mark de Wever
This adds a subset of the C++20 calendar data formatters: - day, - month, - year, - month_day, - month_day_last, and - year_month_day. A followup patch will add the missing calendar data formatters: - weekday, - weekday_indexed, - weekday_last, - month_weekday, - month_weekday_last, - year_month, - year_month_day_last - year_month_weekday, and - year_month_weekday_last.
2023-07-20[lldb] Delete unused LibcxxOptionalSummaryProvider (NFC)Dave Lee
No longer needed following refactoring in D115178.
2023-07-03[lldb][NFCI] TypeSystemClang::CreateStructForIdentifier should take a StringRefAlex Langford
This doesn't really use fast comparison or string uniqueness. In fact, all of the current callers pass an empty string for type_name. The only reason I don't remove it is because it looks like it is used downstream for swift. Differential Revision: https://reviews.llvm.org/D153810
2023-06-26Don't allow SBValue::Cast to cast from a smaller type to a larger,Jim Ingham
as we don't in general know where the extra data should come from. Differential Revision: https://reviews.llvm.org/D153657
2023-06-14[lldb][NFCI] Remove ProcessStructReader header where unusedAlex Langford
2023-06-13[lldb] Default can_create to true in GetChildAtIndex (NFC)Dave Lee
Existing callers of `GetChildAtIndex` pass true for can_create. This change makes true the default value, callers don't have to pass an opaque true. See also D151966 for the same change to `GetChildMemberWithName`. Differential Revision: https://reviews.llvm.org/D152031
2023-06-13[lldb] Default can_create to true in GetChildMemberWithName (NFC)Dave Lee
It turns out all existing callers of `GetChildMemberWithName` pass true for `can_create`. This change makes `true` the default value, callers don't have to pass an opaque true. Differential Revision: https://reviews.llvm.org/D151966
2023-06-01[lldb] Take StringRef names in GetChildAtNamePath (NFC)Dave Lee
Following D151810, this changes `GetChildAtNamePath` to take a path of `StringRef` values instead of `ConstString`. Differential Revision: https://reviews.llvm.org/D151813
2023-06-01[lldb] Take StringRef name in GetIndexOfChildWithName (NFC)Dave Lee
As with D151615, which changed `GetIndexOfChildMemberWithName` to take a `StringRef` instead of a `ConstString`, this change does the same for `GetIndexOfChildWithName`. Differential Revision: https://reviews.llvm.org/D151811
2023-05-31[lldb] Take StringRef name in GetChildMemberWithName (NFC)Dave Lee
`GetChildMemberWithName` does not need a `ConstString`. This change makes the function take a `StringRef` instead, which alleviates the need for callers to construct a `ConstString`. I don't expect this change to improve performance, only ergonomics. This is in support of Alex's effort to replace `ConstString` where appropriate. There are related `ValueObject` functions that can also be changed, if this is accepted. Differential Revision: https://reviews.llvm.org/D151615
2023-05-01Re-land "[lldb] Make the libcxx unique_ptr prettyprinter support custom ↵Jorge Gorbe Moya
deleters." This reverts commit 45351120105a7257ccb1e38ec1b1f8a452269da2.
2023-05-01Revert "[lldb] Make the libcxx unique_ptr prettyprinter support custom ↵Jorge Gorbe Moya
deleters." This reverts commit d366da97bd24ddfb91c9f260fa0aaf105d947652.
2023-05-01[lldb] Make the libcxx unique_ptr prettyprinter support custom deleters.Jorge Gorbe Moya
The unique_ptr prettyprinter calls `GetValueOfLibCXXCompressedPair`, which looks for a `__value_` child. However, when the second value in the compressed pair is not an empty class, there are two `__value_` children because `__compressed_pair` derives twice from `__compressed_pair_elem`, one for each member of the pair. And then the lookup fails because it's ambiguous. This patch makes the following changes: - Rename `GetValueOfLibCXXCompressedPair` to `GetFirstValueOfLibCXXCompressedPair`, and add a similar function to get the second value. Put both functions in Plugin/Language/CPlusPlus/LibCxx.cpp because it seems inappropriate to have libcxx-specific helpers separate from all the libcxx-dependent code. - Read the second value of the `__ptr_` pair and display a "deleter" child in the unique_ptr synthetic child provider, when available. - Add a test case for the non-empty deleter case. Differential Revision: https://reviews.llvm.org/D148662
2023-01-09Return a shared_ptr from ScratchTypeSystemClang::GetForTarget()Adrian Prantl
The current interface theoretically could lead to a use-after-free when a client holds on to the returned pointer. Fix this by returning a shared_ptr to the scratch typesystem. rdar://103619233 Differential Revision: https://reviews.llvm.org/D141100