summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
AgeCommit message (Collapse)Author
2025-07-02[LLDB] Simplify libstdc++ string summaries (#146562)nerix
From #143177. This combines the summaries for the pre- and post C++ 11 `std::string` as well as `std::wstring`. In all cases, the data pointer is reachable through `_M_dataplus._M_p`. It has the correct type (i.e. `char*`/`wchar_t*`) and it's null terminated, so LLDB knows how to format it as expected when using `GetSummaryAsCString`.
2025-06-23[lldb] upgrade HandleFrameFormatVariable callees to llvm::Expected (#144731)Charles Zablit
Upgrade the callees of `HandleFrameFormatVariable` (`GetDemangledTemplateArguments`, etc), to return a `llvm::Expected` instead of an `std::optional`. This patch also bundles the logic of validating the demangled name and information into a single reusable function to reduce code duplication.
2025-06-03[lldb] Fix data race in statusline format handling (#142489)Jonas Devlieghere
This fixes a data race between the main thread and the default event handler thread. The statusline format option value was protected by a mutex, but it was returned as a pointer, allowing one thread to access it while another was modifying it. Avoid the data race by returning format values by value instead of by pointer.
2025-05-28[Demangling] Refactor Demangler range tracking (#140762)Charles Zablit
This PR is a subset of the commits made in https://github.com/swiftlang/llvm-project/pull/10710. The most notable change is the addition of `PrefixRange` and `SuffixRange` which are a catch-all to track anything after or before a function's demangled name. In the case of Swift, this allows to add support for name highlighting without having to track the range of the scope and specifiers of a function (this will come in another PR).
2025-05-27[lldb] optionally match the `__debug` namespace for libstdc++ containers. ↵Ebuka Ezike
(#140727) If libstdc++ is compiled with `_GLIBCXX_DEBUG` flag it puts the containers in the namespace `std::__debug`. this causes the summary and synthetic formatters not to match the types. The formatters is updated to optionally match the `__debug::`. The formatters now clashed with the libc++ containers namespace regex which uses `std::__1` namespace The libc++ formatter is loaded first, then the libstdc++ since the priority of the formatters in lldb is the last one added. Fixes #60841
2025-04-29Reland "[lldb][Format] Make function name frame-format variables work ↵Michael Buch
without debug-info" (#137757) This reverts commit da7099290cea7d11b83da01adda8afeb3bcd5362. Same as the original PR. The failing test-case was resolved in https://github.com/llvm/llvm-project/pull/137763
2025-04-29[lldb][Format] Add function.suffix frame-format variable (#137763)Michael Buch
This patch adds another frame-format variable (currently only implemented in the CPlusPlus language plugin) that represents the "suffix" of a function. The name is derived from the `DotSuffix` node of LLVM's Itanium demangler. For a function name such as `int foo() (.cold)`, the suffix would be `(.cold)`.
2025-04-29Revert "[lldb][Format] Make function name frame-format variables work ↵Michael Buch
without debug-info" (#137757) Reverts llvm/llvm-project#137408 This change broke `lldb/test/Shell/Unwind/split-machine-functions.test`. The test binary has a symbol named `_Z3foov.cold` and the test expects the backtrace to print the name of the cold part of the function like this: ``` # SPLIT: frame #1: {{.*}}`foo() (.cold) + ``` but now it gets ``` frame #1: 0x000055555555514f split-machine-functions.test.tmp`foo() + 12 ```
2025-04-28[lldb][Format] Make function name frame-format variables work without ↵Michael Buch
debug-info (#137408) This patch makes the frame-format variables introduced in https://github.com/llvm/llvm-project/pull/131836 also work when no debug-info is available. Previously, we assumed `sc.function` was available, but without debug-info we might only have `sc.symbol`. We don't really need the `sc.function` apart from when formatting arguments. For the function arguments case I added a fallback that will just print the arguments we get from the demangler (which is what LLDB does for stacktraces with no debug-info anyway). Ideally we'd have a separate `FormatEntity::Entry::Type::FunctionArguments` that will just print the arguments from the demangler and have something like the following in the `plugin.cplusplus.display.function-name-format`: ``` { ${function.formatted-arguments} || ${function.arguments} } ``` I.e., when we can't format the arguments, print the ones from the demangler. But we currently don't have the `||` operator in the frame-format language yet.
2025-04-25[lldb][NFC] Add missing newline between function definitionsMichael Buch
2025-04-25[lldb][CPlusPlus] Add plugin.cplusplus.display.function-name-format setting ↵Michael Buch
(#131836) Adds the new `plugin.cplusplus.display.function-name-format` setting and makes the `${function.name-with-args}` query it for formatting the function name. One caveat is that the setting can't itself be set to `${function.name-with-args}` because that would cause infinite recursion and blow the stack. I added an XFAILed test-case for it and will address it in a follow-up patch. https://github.com/llvm/llvm-project/pull/131836
2025-04-25[lldb][Format] Introduce new frame-format variables for function parts (#131836)Michael Buch
Adds new frame-format variables and implements them in the CPlusPlusLanguage plugin. We use the `DemangledNameInfo` type to retrieve the necessary part of the demangled name. https://github.com/llvm/llvm-project/pull/131836
2025-04-14[LLDB] Reapply refactored CPlusPlusLanguage::MethodName to break lldb-server ↵Dmitry Vasilyev
dependencies (#135033) The original PR is #132274. Co-authored-by: @bulbazord Alex Langford
2025-04-13[lldb][Format] Display only the inlined frame name in backtraces if ↵Michael Buch
available (#135343) When a frame is inlined, LLDB will display its name in backtraces as follows: ``` * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3 * frame #0: 0x0000000100000398 a.out`func() [inlined] baz(x=10) at inline.cpp:1:42 frame #1: 0x0000000100000398 a.out`func() [inlined] bar() at inline.cpp:2:37 frame #2: 0x0000000100000398 a.out`func() at inline.cpp:4:15 frame #3: 0x00000001000003c0 a.out`main at inline.cpp:7:5 frame #4: 0x000000026eb29ab8 dyld`start + 6812 ``` The longer the names get the more confusing this gets because the first function name that appears is the parent frame. My assumption (which may need some more surveying) is that for the majority of cases we only care about the actual frame name (not the parent). So this patch removes all the special logic that prints the parent frame. Another quirk of the current format is that the inlined frame name does not abide by the `${function.name-XXX}` format variables. We always just print the raw demangled name. With this patch, we would format the inlined frame name according to the `frame-format` setting (see the test-cases). If we really want to have the `parentFrame [inlined] inlinedFrame` format, we could expose it through a new `frame-format` variable (e..g., `${function.inlined-at-name}` and let the user decide where to place things.
2025-04-13[lldb][Language] Change GetFunctionDisplayName to take SymbolContext by ↵Michael Buch
reference (#135536) Both the `CPlusPlusLanguage` plugins and the Swift language plugin already assume the `sc != nullptr`. And all `FormatEntity` callsites of `GetFunctionDisplayName` already check for nullptr before passing `sc`. This patch makes this pre-condition explicit by changing the parameter to `const SymbolContext &`. This will help with some upcoming changes in this area.
2025-04-11[lldb][Format][NFCI] Refactor CPlusPlusLanguage::GetFunctionDisplayName into ↵Michael Buch
helpers and use LLVM style (#135331) Same cleanup as in https://github.com/llvm/llvm-project/pull/135031. It pretty much is the same code that we had to duplicate in the language plugin. Maybe eventually we'll find a way of getting rid of the duplication.
2025-04-09Revert "[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server ↵David Spickett
dependencies" (#134995) Reverts llvm/llvm-project#132274 Broke a test on LLDB Widows on Arm: https://lab.llvm.org/buildbot/#/builders/141/builds/7726 ``` FAIL: test_dwarf (lldbsuite.test.lldbtest.TestExternCSymbols.test_dwarf) <...> self.assertTrue(self.res.Succeeded(), msg + output) AssertionError: False is not true : Command 'expression -- foo()' did not return successfully Error output: error: Couldn't look up symbols: int foo(void) Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler. ```
2025-04-09[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server ↵Dmitry Vasilyev
dependencies (#132274) This patch addresses the issue #129543. After this patch the size of lldb-server is reduced by 9MB. Co-authored-by: @bulbazord Alex Langford
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-06-01Use StringRef::starts_with (NFC) (#94112)Kazu Hirata
2024-04-15[LLDB][libc++] Adds valarray proxy data formatters. (#88613)Mark de Wever
These proxies are returned by operator[](...). These proxies all "behave" the same. They store a pointer to the data of the valarray they are a proxy for and they have an internal array of indices. This internal array is considered its contents.
2024-04-13[lldb][libc++] Adds local_t clock data formatters. (#88178)Mark de Wever
2024-03-17[lldb][libc++] Adds slice_array data formatters. (#85544)Mark de Wever
Co-authored-by: Michael Buch <michaelbuch12@gmail.com>
2024-02-10[lldb][libc++] Adds valarray data formatters. (#80609)Mark de Wever
The code is heavily based on the vector data formatter.
2024-02-05[lldb] Cleanup regex in libcxx formatters (NFC) (#80618)Dave Lee
I noticed a number of regex for libcxx formatters use an unnecessary regex grouping. This change removes those parentheses.
2024-01-26[lldb] Remove unnecessary suffix from libc++ type name patterns (NFC) (#79644)Dave Lee
The `(( )?&)?` appears to match types which are references. However lldb can load the correct data formatters without having to pattern match against a `&` suffix. The suffix may have been needed at one point, but it's no longer needed.
2024-01-22[lldb][libc++] Adds system_clock data formatters. (#78609)Mark de Wever
2024-01-18[lldb][Format] Fix missing inlined function names in frame formatting. (#78494)Zequan Wu
This fixes missing inlined function names when formatting frame and the `Block` in `SymbolContext` is a lexical block (e.g. `DW_TAG_lexical_block` in Dwarf).
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-12-16[lldb] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-10-30Add the ability to get a C++ vtable ValueObject from another ValueObj… ↵Greg Clayton
(#67599) Add the ability to get a C++ vtable ValueObject from another ValueObject. This patch adds the ability to ask a ValueObject for a ValueObject that represents the virtual function table for a C++ class. If the ValueObject is not a C++ class with a vtable, a valid ValueObject value will be returned that contains an appropriate error. If it is successful a valid ValueObject that represents vtable will be returned. The ValueObject that is returned will have a name that matches the demangled value for a C++ vtable mangled name like "vtable for <class-name>". It will have N children, one for each virtual function pointer. Each child's value is the function pointer itself, the summary is the symbolication of this function pointer, and the type will be a valid function pointer from the debug info if there is debug information corresponding to the virtual function pointer. The vtable SBValue will have the following: - SBValue::GetName() returns "vtable for <class>" - SBValue::GetValue() returns a string representation of the vtable address - SBValue::GetSummary() returns NULL - SBValue::GetType() returns a type appropriate for a uintptr_t type for the current process - SBValue::GetLoadAddress() returns the address of the vtable adderess - SBValue::GetValueAsUnsigned(...) returns the vtable address - SBValue::GetNumChildren() returns the number of virtual function pointers in the vtable - SBValue::GetChildAtIndex(...) returns a SBValue that represents a virtual function pointer The child SBValue objects that represent a virtual function pointer has the following values: - SBValue::GetName() returns "[%u]" where %u is the vtable function pointer index - SBValue::GetValue() returns a string representation of the virtual function pointer - SBValue::GetSummary() returns a symbolicated respresentation of the virtual function pointer - SBValue::GetType() returns the function prototype type if there is debug info, or a generic funtion prototype if there is no debug info - SBValue::GetLoadAddress() returns the address of the virtual function pointer - SBValue::GetValueAsUnsigned(...) returns the virtual function pointer - SBValue::GetNumChildren() returns 0 - SBValue::GetChildAtIndex(...) returns invalid SBValue for any index Examples of using this API via python: ``` (lldb) script vtable = lldb.frame.FindVariable("shape_ptr").GetVTable() (lldb) script vtable vtable for Shape = 0x0000000100004088 { [0] = 0x0000000100003d20 a.out`Shape::~Shape() at main.cpp:3 [1] = 0x0000000100003e4c a.out`Shape::~Shape() at main.cpp:3 [2] = 0x0000000100003e7c a.out`Shape::area() at main.cpp:4 [3] = 0x0000000100003e3c a.out`Shape::optional() at main.cpp:7 } (lldb) script c = vtable.GetChildAtIndex(0) (lldb) script c (void ()) [0] = 0x0000000100003d20 a.out`Shape::~Shape() at main.cpp:3 ```
2023-10-25[lldb][libc++] Adds chrono data formatters.Mark de Wever
This adds the data formatters for chrono duration typedefs. Reviewed By: Michael137 Differential Revision: https://reviews.llvm.org/D159127
2023-10-02Implement data formatters for LibStdC++ std::variant (#68012)jeffreytan81
This patch implements the data formatters for LibStdC++ `std::variant`. --------- Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-09-20[lldb] Fix stdcpp type summary mistakenly marked as regex (NFC) (#66949)Dave Lee
`std::basic_string<char>` is not a regex, and treating it as such could unintentionally cause a formatter to substring match a template type parameter, for example: `std::vector<std::basic_string<char>>`. Differential Revision: https://reviews.llvm.org/D158663
2023-06-05Replace deprecated startswith_insensitive with starts_with_insensitiveFangrui Song
2023-04-12[lldb] Change formatter helper function parameter list to remove ConstStringAlex Langford
All of these functions take a ConstString for the type_name, but this isn't really needed for two reasons: 1.) This parameter is always constructed from a static c-string constant. 2.) They are passed along to to `AddTypeSummary` as a StringRef anyway. Differential Revision: https://reviews.llvm.org/D148050
2023-03-07Reland "[lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider ↵Michael Buch
for member-function pointers" With this patch member-function pointers are formatted using `CXXFunctionPointerSummaryProvider`. This turns, ``` (lldb) v pointer_to_member_func (void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 ``` into ``` (lldb) v pointer_to_member_func (void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 (a.out`Foo::member_func() at main.cpp:3) ``` Differential Revision: https://reviews.llvm.org/D145242
2023-03-07Revert "[lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider ↵Michael Buch
for member-function pointers" Reverted because Windows buildbot started failing This reverts commit 6bd46e713c6d8deda7bdae8b1efadb99c88b4443.
2023-03-03[lldb][TypeSystemClang] Use the CXXFunctionPointerSummaryProvider for ↵Michael Buch
member-function pointers With this patch member-function pointers are formatted using `CXXFunctionPointerSummaryProvider`. This turns, ``` (lldb) v pointer_to_member_func (void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 ``` into ``` (lldb) v pointer_to_member_func (void (Foo::*)()) ::pointer_to_member_func = 0x00000000000000000000000100003f94 (a.out`Foo::member_func() at main.cpp:3) ``` Differential Revision: https://reviews.llvm.org/D145242
2022-12-17[lldb] llvm::Optional::value => operator*/operator->Fangrui Song
std::optional::value() has undesired exception checking semantics and is unavailable in some older Xcode. The call sites block std::optional migration.
2022-11-30[lldb][DataFormatter] Add std::ranges::ref_view formatterMichael Buch
This patch adds a formatter for `std::ranges::ref_view<T>`. It simply holds a `T*`, so all this formatter does is dereference this pointer and format it as `T` would be. **Testing** * Added API tests Differential Revision: https://reviews.llvm.org/D138558
2022-10-31[lldb][CPlusPlus] Implement CPlusPlusLanguage::GetFunctionDisplayNameMichael Buch
This patch implements the `GetFunctionDisplayName` API which gets used by the frame-formatting code to decide how to print a function name. Currently this API trivially returns `false`, so we try to parse the demangled function base-name by hand. We try find the closing parenthesis by doing a forward scan through the demangled name. However, for arguments that contain parenthesis (e.g., function pointers) this would leave garbage in the frame function name. By re-using the `CPlusPlusLanguage` parser for this we offload the need to parse function names to a component that knows how to do this already. We leave the existing parsing code in `FormatEntity` since it's used in cases where a language-plugin is not available (and is not necessarily C++ specific). **Example** For following function: ``` int foo(std::function<int(void)> const& func) { return 1; } ``` Before patch: ``` frame #0: 0x000000010000151c a.out`foo(func= Function = bar() )> const&) at sample.cpp:11:49 ``` After patch: ``` frame #0: 0x000000010000151c a.out`foo(func= Function = bar() ) at sample.cpp:11:49 ``` **Testing** * Added shell test
2022-10-31[lldb][CPlusPlus] Introduce CPlusPlusLanguage::MethodName::GetReturnTypeMichael Buch
This patch adds a way to extract the return type out of the `CPlusPlusNameParser`. This will be useful for cases where we want a function's basename *and* the return type but not the function arguments; this is currently not possible (the parser either gives us the full name or just the basename). Since the parser knows how to handle return types already we should just expose this to users that need it. **Testing** * Added unit-tests Differential Revision: https://reviews.llvm.org/D136935
2022-10-14[lldb][Breakpoint] Fix setting breakpoints on templates by basenameMichael Buch
This patch fixes a regression with setting breakpoints on template functions by name. E.g.,: ``` $ cat main.cpp template<typename T> struct Foo { template<typename U> void func() {} }; int main() { Foo<int> f; f.func<double>(); } (lldb) br se -n func ``` This has regressed since `3339000e0bda696c2e29173d15958c0a4978a143` where we started using the `CPlusPlusNameParser` for getting the basename of the function symbol and match it exactly against the name in the breakpoint command. The parser will include template parameters in the basename, so the exact match will always fail **Testing** * Added API tests * Added unit-tests Differential Revision: https://reviews.llvm.org/D135921
2022-10-10[NFCI] More TypeCategoryImpl refactoring.Jorge Gorbe Moya
The main aim of this patch is to delete the remaining instances of code reaching into the internals of `TypeCategoryImpl`. I made the following changes: - Add some more methods to `TieredFormatterContainer` and `TypeCategoryImpl` to expose functionality that is implemented in `FormattersContainer`. - Add new overloads of `TypeCategoryImpl::AddTypeXXX` to make it easier to add formatters to categories without reaching into the internal `FormattersContainer` objects. - Remove the `GetTypeXXXContainer` and `GetRegexTypeXXXContainer` accessors from `TypeCategoryImpl` and update all call sites to use the new methods instead. Differential Revision: https://reviews.llvm.org/D135399
2022-08-24[LLDB] Add data formatter for std::coroutine_handleAdrian Vogelsgesang
This patch adds a formatter for `std::coroutine_handle`, both for libc++ and libstdc++. For the type-erased `coroutine_handle<>`, it shows the `resume` and `destroy` function pointers. For a non-type-erased `coroutine_handle<promise_type>` it also shows the `promise` value. With this change, executing the `v t` command on the example from https://clang.llvm.org/docs/DebuggingCoroutines.html now outputs ``` (task) t = { handle = coro frame = 0x55555555b2a0 { resume = 0x0000555555555a10 (a.out`coro_task(int, int) at llvm-example.cpp:36) destroy = 0x0000555555556090 (a.out`coro_task(int, int) at llvm-example.cpp:36) } } ``` instead of just ``` (task) t = { handle = { __handle_ = 0x55555555b2a0 } } ``` Note, how the symbols for the `resume` and `destroy` function pointer reveal which coroutine is stored inside the `std::coroutine_handle`. A follow-up commit will use this fact to infer the coroutine's promise type and the representation of its internal coroutine state based on the `resume` and `destroy` pointers. The same formatter is used for both libc++ and libstdc++. It would also work for MSVC's standard library, however it is not registered for MSVC, given that lldb does not provide pretty printers for other MSVC types, either. The formatter is in a newly added `Coroutines.{h,cpp}` file because there does not seem to be an already existing place where we could share formatters across libc++ and libstdc++. Also, I expect this code to grow as we improve debugging experience for coroutines further. **Testing** * Added API test Differential Revision: https://reviews.llvm.org/D132415
2022-07-21[LLDB][DataFormatter] Add support for std::__map_const_iteratorMichael Buch
This patch adds support for formatting `std::map::const_iterator`. It's just a matter of adding `const_` to the existing regex. **Testing** * Added test case to existing API tests Differential Revision: https://reviews.llvm.org/D129962
2022-07-20[LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scanSlava Gurevich
Improve LLDB reliability by fixing the following "uninitialized variables" static code inspection warnings from scan.coverity.com: 1094796 1095721 1095728 1095737 1095741 1095756 1095779 1095789 1095805 1214552 1229457 1232475 1274006 1274010 1293427 1364800 1364802 1364804 1364812 1364816 1374902 1374909 1384975 1399312 1420451 1431704 1454230 1454554 1454615 1454579 1454594 1454832 1457759 1458696 1461909 1467658 1487814 1487830 1487845 Differential Revision: https://reviews.llvm.org/D130098