[Lldb-commits] [PATCH] D117383: [lldb] Expose std::pair children for unordered_map
kastiglione updated this revision to Diff 456123. kastiglione added a comment. Add @jdevlieghere helper Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117383/new/ https://reviews.llvm.org/D117383 Files: lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py === --- lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py +++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/unordered/TestDataFormatterGenericUnordered.py @@ -47,12 +47,17 @@ "corrupt_map", ['%s::unordered_map' % ns, 'size=0 {}']) -self.look_for_content_and_continue( -"map", ['%s::unordered_map' % -ns, 'size=5 {', 'hello', 'world', 'this', 'is', 'me']) +must_not_contain__cc = r'(?s)^(?!.*\b__cc = )' self.look_for_content_and_continue( -"mmap", ['%s::unordered_multimap' % ns, 'size=6 {', 'first = 3', 'second = "this"', +"map", ['%s::unordered_map' % ns, +must_not_contain__cc, +'size=5 {', 'hello', 'world', 'this', 'is', 'me']) + +self.look_for_content_and_continue( +"mmap", ['%s::unordered_multimap' % ns, + must_not_contain__cc, + 'size=6 {', 'first = 3', 'second = "this"', 'first = 2', 'second = "hello"']) self.look_for_content_and_continue( Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp === --- lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp +++ lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp @@ -13,10 +13,12 @@ #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/DataFormatters/FormattersHelpers.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/ConstString.h" #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/Endian.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" +#include "llvm/ADT/StringRef.h" using namespace lldb; using namespace lldb_private; @@ -65,6 +67,19 @@ return m_num_elements; } +static bool isStdTemplate(ConstString type_name, llvm::StringRef type) { + llvm::StringRef name = type_name.GetStringRef(); + // The type name may or may not be prefixed with `std::` or `std::__1::`. + if (name.consume_front("std::")) +name.consume_front("__1::"); + return name.consume_front(type) && name.startswith("<"); +} + +static bool isUnorderedMap(ConstString type_name) { + return isStdTemplate(type_name, "unordered_map") || + isStdTemplate(type_name, "unordered_multimap"); +} + lldb::ValueObjectSP lldb_private::formatters:: LibcxxStdUnorderedMapSyntheticFrontEnd::GetChildAtIndex(size_t idx) { if (idx >= CalculateNumChildren()) @@ -118,10 +133,20 @@ m_element_type = m_element_type.GetPointeeType(); m_node_type = m_element_type; m_element_type = m_element_type.GetTypeTemplateArgument(0); -std::string name; -m_element_type = -m_element_type.GetFieldAtIndex(0, name, nullptr, nullptr, nullptr); -m_element_type = m_element_type.GetTypedefedType(); +// This synthetic provider is used for both unordered_(multi)map and +// unordered_(multi)set. For unordered_map, the element type has an +// additional type layer, an internal struct (`__hash_value_type`) +// that wraps a std::pair. Peel away the internal wrapper type - whose +// structure is of no value to users, to expose the std::pair. This +// matches the structure returned by the std::map synthetic provider. +if (isUnorderedMap(m_backend.GetTypeName())) { + std::string name; + CompilerType field_type = m_element_type.GetFieldAtIndex( + 0, name, nullptr, nullptr, nullptr); + CompilerType actual_type = field_type.GetTypedefedType(); + if (isStdTemplate(actual_type.GetTypeName(), "pair")) +m_element_type = actual_type; +} } if (!m_node_type) return nullptr; @@ -153,7 +178,7 @@ ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock( thread_and_frame_only_if_stopped); return CreateValueObjectFromData(stream.GetString(), data, exe_ctx, - val_hash.first->GetCompilerType()); + m_element_type); } bool lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd:: Index: lldb/test/API/functiona
[Lldb-commits] [PATCH] D117383: [lldb] Expose std::pair children for unordered_map
kastiglione added inline comments. Comment at: lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp:75-76 + name.startswith("unordered_multimap<") || + name.startswith("std::__1::unordered_map<") || + name.startswith("std::__1::unordered_multimap<"); +} JDevlieghere wrote: > Maybe a little helper could avoid some duplication here and below. Something > like: > > ``` > static bool isStdType(llvm::StringRef name, llvm::StringRef type) { > return name.startswith(type) || > name.startswith(llvm::Twine("std::__1::") + type); > } > ``` good idea. Since `startswith` doesn't accept a Twine I went with a slightly different approach, to the same effect. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117383/new/ https://reviews.llvm.org/D117383 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D117383: [lldb] Expose std::pair children for unordered_map
JDevlieghere accepted this revision. JDevlieghere added a comment. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D117383/new/ https://reviews.llvm.org/D117383 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132735: [LLDB] Recognize `std::noop_coroutine()` in `std::coroutine_handle` pretty printer
avogelsgesang updated this revision to Diff 456155. avogelsgesang added a comment. fix test case Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132735/new/ https://reviews.llvm.org/D132735 Files: lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp === --- lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp +++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/main.cpp @@ -45,6 +45,7 @@ std::coroutine_handle<> type_erased_hdl = gen.hdl; std::coroutine_handle incorrectly_typed_hdl = std::coroutine_handle::from_address(gen.hdl.address()); + std::coroutine_handle<> noop_hdl = std::noop_coroutine(); gen.hdl.resume();// Break at initial_suspend gen.hdl.resume();// Break after co_yield empty_function_so_we_can_set_a_breakpoint(); // Break at final_suspend Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py === --- lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py +++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/coroutine_handle/TestCoroutineHandle.py @@ -38,6 +38,13 @@ ValueCheck(name="current_value", value = "-1"), ]) ]) +# We recognize and pretty-print `std::noop_coroutine`. We don't display +# any children as those are irrelevant for the noop coroutine. +# clang version < 16 did not yet write debug info for the noop coroutines. +if not (is_clang and self.expectedCompilerVersion(["<", "16"])): +self.expect_expr("noop_hdl", +result_summary="noop_coroutine", +result_children=[]) if is_clang: # For a type-erased `coroutine_handle<>`, we can still devirtualize # the promise call and display the correctly typed promise. Index: lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp === --- lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp +++ lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp @@ -34,7 +34,7 @@ return ptr_sp; } -static Function *ExtractDestroyFunction(ValueObjectSP &frame_ptr_sp) { +static Function *ExtractFunction(ValueObjectSP &frame_ptr_sp, int offset) { lldb::TargetSP target_sp = frame_ptr_sp->GetTargetSP(); lldb::ProcessSP process_sp = frame_ptr_sp->GetProcessSP(); auto ptr_size = process_sp->GetAddressByteSize(); @@ -46,24 +46,64 @@ lldbassert(addr_type == AddressType::eAddressTypeLoad); Status error; - // The destroy pointer is the 2nd pointer inside the compiler-generated - // `pair`. - auto destroy_func_ptr_addr = frame_ptr_addr + ptr_size; - lldb::addr_t destroy_func_addr = - process_sp->ReadPointerFromMemory(destroy_func_ptr_addr, error); + auto func_ptr_addr = frame_ptr_addr + offset * ptr_size; + lldb::addr_t func_addr = + process_sp->ReadPointerFromMemory(func_ptr_addr, error); if (error.Fail()) return nullptr; - Address destroy_func_address; - if (!target_sp->ResolveLoadAddress(destroy_func_addr, destroy_func_address)) + Address func_address; + if (!target_sp->ResolveLoadAddress(func_addr, func_address)) return nullptr; - Function *destroy_func = - destroy_func_address.CalculateSymbolContextFunction(); - if (!destroy_func) -return nullptr; + return func_address.CalculateSymbolContextFunction(); +} - return destroy_func; +static Function *ExtractResumeFunction(ValueObjectSP &frame_ptr_sp) { + return ExtractFunction(frame_ptr_sp, 0); +} + +static Function *ExtractDestroyFunction(ValueObjectSP &frame_ptr_sp) { + return ExtractFunction(frame_ptr_sp, 1); +} + +static bool IsNoopResumeDestroy(Function *f) { + if (!f) +return false; + + // clang's `__builtin_coro_noop` gets lowered to + // `_NoopCoro_ResumeDestroy`. This is used by libc++ + // on clang. + auto mangledName = f->GetMangled().GetMangledName(); + if (mangledName == "__NoopCoro_ResumeDestroy") +return true; + + // libc++ uses the following name as a fallback on + // compilers without `__builtin_coro_noop`. + auto name = f->GetNameNoArguments(); + static RegularExpression libcxxRegex( + "^std::coroutine_handle::" + "__noop_coroutine_frame_ty_::__dummy_resume_destroy_func$"); + lldbassert(libc
[Lldb-commits] [PATCH] D132803: [lldb][test] Speed up lldb arch determination (NFC)
kastiglione created this revision. kastiglione added reviewers: JDevlieghere, mib. Herald added a project: All. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits. While investigation slow tests, I looked into why `TestMultithreaded.py`. One of the reasons is that it determines the architecture of lldb by running: lldb -o 'file path/to/lldb' -o 'quit' On my fairly fast machine, this takes 24 seconds, and `TestMultithreaded.py` calls this function 4 times. With this change, this command now takes less than 0.2s on the same machine. The reason it's slow is symbol table and debug info loading, as indicated by the new progress events printed to the console. One setting reduced the time in half: settings set target.preload-symbols false Further investigation, by profiling with Instruments on macOS, showed that loading time was also caused by looking for scripts. The setting that eliminates this time is: settings set target.load-script-from-symbol-file false Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D132803 Files: lldb/packages/Python/lldbsuite/test/lldbtest.py Index: lldb/packages/Python/lldbsuite/test/lldbtest.py === --- lldb/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -1255,21 +1255,23 @@ """Returns the architecture of the lldb binary.""" if not hasattr(self, 'lldbArchitecture'): -# spawn local process +# These two target settings prevent lldb from doing setup that does +# nothing but slow down the end goal of printing the architecture. command = [ lldbtest_config.lldbExec, -"-o", -"file " + lldbtest_config.lldbExec, -"-o", -"quit" +"-x", +"-b", +"-o", "settings set target.preload-symbols false", +"-o", "settings set target.load-script-from-symbol-file false", +"-o", "file " + lldbtest_config.lldbExec, ] output = check_output(command) -str = output.decode("utf-8") +str = output.decode() for line in str.splitlines(): m = re.search( -"Current executable set to '.*' \\((.*)\\)\\.", line) +r"Current executable set to '.*' \((.*)\)\.", line) if m: self.lldbArchitecture = m.group(1) break Index: lldb/packages/Python/lldbsuite/test/lldbtest.py === --- lldb/packages/Python/lldbsuite/test/lldbtest.py +++ lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -1255,21 +1255,23 @@ """Returns the architecture of the lldb binary.""" if not hasattr(self, 'lldbArchitecture'): -# spawn local process +# These two target settings prevent lldb from doing setup that does +# nothing but slow down the end goal of printing the architecture. command = [ lldbtest_config.lldbExec, -"-o", -"file " + lldbtest_config.lldbExec, -"-o", -"quit" +"-x", +"-b", +"-o", "settings set target.preload-symbols false", +"-o", "settings set target.load-script-from-symbol-file false", +"-o", "file " + lldbtest_config.lldbExec, ] output = check_output(command) -str = output.decode("utf-8") +str = output.decode() for line in str.splitlines(): m = re.search( -"Current executable set to '.*' \\((.*)\\)\\.", line) +r"Current executable set to '.*' \((.*)\)\.", line) if m: self.lldbArchitecture = m.group(1) break ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132803: [lldb][test] Speed up lldb arch determination (NFC)
kastiglione added a comment. I did a little cleanup while here. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132803/new/ https://reviews.llvm.org/D132803 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132803: [lldb][test] Speed up lldb arch determination (NFC)
kastiglione added a comment. I wonder if it's worth disabling `target.load-script-from-symbol-file` for all tests as well. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132803/new/ https://reviews.llvm.org/D132803 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 0660249 - [lldb] Remove a redundaunt return statement (NFC)
Author: Kazu Hirata Date: 2022-08-27T21:21:05-07:00 New Revision: 0660249cca89208f042b13913bf0bb5485527ec1 URL: https://github.com/llvm/llvm-project/commit/0660249cca89208f042b13913bf0bb5485527ec1 DIFF: https://github.com/llvm/llvm-project/commit/0660249cca89208f042b13913bf0bb5485527ec1.diff LOG: [lldb] Remove a redundaunt return statement (NFC) Identified with readability-redundant-control-flow. Added: Modified: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Removed: diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 2178db8e9b7c5..7717f22f97885 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -1259,8 +1259,6 @@ void ScriptInterpreterPythonImpl::SetWatchpointCommandCallback( wp_options->SetCallback( ScriptInterpreterPythonImpl::WatchpointCallbackFunction, baton_sp); } - - return; } Status ScriptInterpreterPythonImpl::ExportFunctionDefinitionToInterpreter( ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 920ffab - [lldb] Use nullptr instead of NULL (NFC)
Author: Kazu Hirata Date: 2022-08-27T21:21:07-07:00 New Revision: 920ffab9cccfe1a5dde0368d252ed50e5dbcd6a5 URL: https://github.com/llvm/llvm-project/commit/920ffab9cccfe1a5dde0368d252ed50e5dbcd6a5 DIFF: https://github.com/llvm/llvm-project/commit/920ffab9cccfe1a5dde0368d252ed50e5dbcd6a5.diff LOG: [lldb] Use nullptr instead of NULL (NFC) Identified with modernize-use-nullptr. Added: Modified: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp Removed: diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index ae61736fbbb3..f0f5debcab8f 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -923,7 +923,7 @@ const char *PythonException::toCString() const { PythonException::PythonException(const char *caller) { assert(PyErr_Occurred()); - m_exception_type = m_exception = m_traceback = m_repr_bytes = NULL; + m_exception_type = m_exception = m_traceback = m_repr_bytes = nullptr; PyErr_Fetch(&m_exception_type, &m_exception, &m_traceback); PyErr_NormalizeException(&m_exception_type, &m_exception, &m_traceback); PyErr_Clear(); @@ -951,7 +951,7 @@ void PythonException::Restore() { } else { PyErr_SetString(PyExc_Exception, toCString()); } - m_exception_type = m_exception = m_traceback = NULL; + m_exception_type = m_exception = m_traceback = nullptr; } PythonException::~PythonException() { diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp index 2753847f39f8..3cbd3b5efecc 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp @@ -40,7 +40,7 @@ static char *simple_readline(FILE *stdin, FILE *stdout, const char *prompt) { char *line = readline(prompt); if (!line) { char *ret = (char *)PyMem_RawMalloc(1); -if (ret != NULL) +if (ret != nullptr) *ret = '\0'; return ret; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 7717f22f9788..d530936484b9 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -96,7 +96,7 @@ struct InitializePythonRAII { // Python's readline is incompatible with libedit being linked into lldb. // Provide a patched version local to the embedded interpreter. bool ReadlinePatched = false; -for (auto *p = PyImport_Inittab; p->name != NULL; p++) { +for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { if (strcmp(p->name, "readline") == 0) { p->initfunc = initlldb_readline; break; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits