[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
kpdev wrote: @jimingham Please take a look: https://github.com/llvm/llvm-project/pull/67782#issuecomment-2047369473 https://github.com/llvm/llvm-project/pull/67782 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 83695d4 - [lldb][gui] Update TreeItem children's m_parent on move
Author: Pavel Kosov Date: 2023-08-16T11:10:00+03:00 New Revision: 83695d45d62121ab306d0dc108b549d9056a2f28 URL: https://github.com/llvm/llvm-project/commit/83695d45d62121ab306d0dc108b549d9056a2f28 DIFF: https://github.com/llvm/llvm-project/commit/83695d45d62121ab306d0dc108b549d9056a2f28.diff LOG: [lldb][gui] Update TreeItem children's m_parent on move Before this patch, any time TreeItem is copied in Resize method, its parent is not updated, which can cause crashes when, for example, thread window with multiple hierarchy levels is updated. Makes TreeItem move-only, removes TreeItem's m_delegate extra self-assignment by making it a pointer, adds code to fix up children's parent on move constructor and operator= Patch prepared by NH5pml30 ~~~ Huawei RRI, OS Lab Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D157960 Added: lldb/test/API/commands/gui/spawn-threads/Makefile lldb/test/API/commands/gui/spawn-threads/TestGuiSpawnThreads.py lldb/test/API/commands/gui/spawn-threads/main.cpp Modified: lldb/source/Core/IOHandlerCursesGUI.cpp Removed: diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp index 92f62b725ce385..22b8cc3582eae7 100644 --- a/lldb/source/Core/IOHandlerCursesGUI.cpp +++ b/lldb/source/Core/IOHandlerCursesGUI.cpp @@ -4614,30 +4614,48 @@ class TreeDelegate { typedef std::shared_ptr TreeDelegateSP; -class TreeItem { +struct TreeItemData { + TreeItemData(TreeItem *parent, TreeDelegate &delegate, + bool might_have_children, bool is_expanded) + : m_parent(parent), m_delegate(&delegate), +m_might_have_children(might_have_children), m_is_expanded(is_expanded) { + } + +protected: + TreeItem *m_parent; + TreeDelegate *m_delegate; + void *m_user_data = nullptr; + uint64_t m_identifier = 0; + std::string m_text; + int m_row_idx = -1; // Zero based visible row index, -1 if not visible or for + // the root item + bool m_might_have_children; + bool m_is_expanded = false; +}; + +class TreeItem : public TreeItemData { public: TreeItem(TreeItem *parent, TreeDelegate &delegate, bool might_have_children) - : m_parent(parent), m_delegate(delegate), m_children(), -m_might_have_children(might_have_children) { -if (m_parent == nullptr) - m_is_expanded = m_delegate.TreeDelegateExpandRootByDefault(); - } + : TreeItemData(parent, delegate, might_have_children, + parent == nullptr + ? delegate.TreeDelegateExpandRootByDefault() + : false), +m_children() {} + + TreeItem(const TreeItem &) = delete; + TreeItem &operator=(const TreeItem &rhs) = delete; - TreeItem &operator=(const TreeItem &rhs) { + TreeItem &operator=(TreeItem &&rhs) { if (this != &rhs) { - m_parent = rhs.m_parent; - m_delegate = rhs.m_delegate; - m_user_data = rhs.m_user_data; - m_identifier = rhs.m_identifier; - m_row_idx = rhs.m_row_idx; - m_children = rhs.m_children; - m_might_have_children = rhs.m_might_have_children; - m_is_expanded = rhs.m_is_expanded; + TreeItemData::operator=(std::move(rhs)); + AdoptChildren(rhs.m_children); } return *this; } - TreeItem(const TreeItem &) = default; + TreeItem(TreeItem &&rhs) : TreeItemData(std::move(rhs)) { +AdoptChildren(rhs.m_children); + } size_t GetDepth() const { if (m_parent) @@ -4649,18 +4667,28 @@ class TreeItem { void ClearChildren() { m_children.clear(); } - void Resize(size_t n, const TreeItem &t) { m_children.resize(n, t); } + void Resize(size_t n, TreeDelegate &delegate, bool might_have_children) { +if (m_children.size() >= n) { + m_children.erase(m_children.begin() + n, m_children.end()); + return; +} +m_children.reserve(n); +std::generate_n(std::back_inserter(m_children), n - m_children.size(), +[&, parent = this]() { + return TreeItem(parent, delegate, might_have_children); +}); + } TreeItem &operator[](size_t i) { return m_children[i]; } void SetRowIndex(int row_idx) { m_row_idx = row_idx; } size_t GetNumChildren() { -m_delegate.TreeDelegateGenerateChildren(*this); +m_delegate->TreeDelegateGenerateChildren(*this); return m_children.size(); } - void ItemWasSelected() { m_delegate.TreeDelegateItemSelected(*this); } + void ItemWasSelected() { m_delegate->TreeDelegateItemSelected(*this); } void CalculateRowIndexes(int &row_idx) { SetRowIndex(row_idx); @@ -4727,7 +4755,7 @@ class TreeItem { if (highlight) window.AttributeOn(A_REVERSE); - m_delegate.TreeDelegateDrawTreeItem(*this, window); + m_delegate->TreeDelegateDrawTreeItem(*this, window); if (highlight) window.AttributeOff(A
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
https://github.com/kpdev created https://github.com/llvm/llvm-project/pull/67309 It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. This patch adds to the synthetic child interface a “change value” method which goes back to the synthetic child provider and ask it if it knows how to change the underlying value that the synthetic child represents Overall context is avaliable in the following question: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3: ~~ Huawei RRI, OS Lab >From 07f943e3c243a41f1e7395379ca09a1ee79f2a93 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Mon, 25 Sep 2023 13:41:03 +0300 Subject: [PATCH] [lldb] Add SetValueFromCString API to SyntheticFronend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. This patch adds to the synthetic child interface a “change value” method which goes back to the synthetic child provider and ask it if it knows how to change the underlying value that the synthetic child represents Overall context is avaliable in the following question: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3: ~~ Huawei RRI, OS Lab --- lldb/include/lldb/Core/ValueObject.h | 11 +++ lldb/include/lldb/DataFormatters/TypeSynthetic.h | 8 +++- lldb/source/Core/ValueObject.cpp | 7 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 3af94f0a86e2fcc..892f5d0dea4f650 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -589,6 +589,14 @@ class ValueObject { virtual bool IsSynthetic() { return false; } + void SetSyntheticFrontend(SyntheticChildrenFrontEnd *synth_front) { +m_synthetic_frontend = synth_front; + } + + SyntheticChildrenFrontEnd *GetSyntheticFrontend() const { +return m_synthetic_frontend; + } + lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue); @@ -898,6 +906,9 @@ class ValueObject { /// Unique identifier for every value object. UserID m_id; + // If frontend exist - we may try to update our value through it + SyntheticChildrenFrontEnd *m_synthetic_frontend = nullptr; + // Utility class for initializing all bitfields in ValueObject's constructors. // FIXME: This could be done via default initializers once we have C++20. struct Bitflags { diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 41be9b7efda8fdb..3a19804b22c196c 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -34,7 +34,9 @@ class SyntheticChildrenFrontEnd { public: SyntheticChildrenFrontEnd(ValueObject &backend) - : m_backend(backend), m_valid(true) {} + : m_backend(backend), m_valid(true) { +backend.SetSyntheticFrontend(this); + } virtual ~SyntheticChildrenFrontEnd() = default; @@ -75,6 +77,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + typedef std::shared_ptr SharedPointer; typedef std::unique_ptr AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index ebfc1cf4d6fe9e1..cea3ea523020443 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1535,7 +1535,12 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { } } else { // We don't support setting things bigger than a scalar at present. -error.SetErrorString("unable to write aggregate data type"); +// But maybe our frontend knows how to update the value. +if (auto *frontend = GetSyntheticFrontend()) { + return frontend->SetValueFromCString(value_str, error); +} else { + error.SetErrorString("unable to write aggregate data type"); +} return false; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
@@ -75,6 +77,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + kpdev wrote: It will be used in the following patches (it is the first, two more to come). But maybe it is better to use one big patch with all changes? https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
https://github.com/kpdev edited https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
kpdev wrote: > This part of the change seems straightforward, if the synthetic child > provider can set a value it will have to have this API... But yes, if there > are a bunch of patches that build on one another, if they aren't too big one > patch that shows the functionality is easier to understand, or put a few > substantial patches up but mark them as depending on the previous ones, so we > can get the big picture. Jim Ok, will prepare them https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
kpdev wrote: > Getting the SyntheticFrontEnd to try updating the synthetic value is a good > addition. But I'm not sure that ValueObject should be the one that should > provide access directly to the FrontEnd? Why isn't it enough to have the > ValueObjectSynthetic's SetValueFromCString do this? If you have decided to > pull the Non-synthetic value (and so are accessing the ValueObjectVariable > directly, would you expect to have the synthetic value do an update? When > would something that is a ValueObject but not a ValueObjectSynthetic really > want to update the value using the SyntheticFrontEnd? @jimingham In my understanding, the situation is looks like this: When somebody wants to update a value from lldb API, then SBValue's `SetValueFromCString` method should be used, which in turn calls ValueObjectVariable / ValueObjectRegister / etc.'s method `SetValueFromCString` - all of them currently working only with `Scalar`s, which represent addresses for structured values (e.g., std::string in our case) in the process that we debug. I do not see a common way to update aggregate types in ValueObject* since it can represent any type of data, but if we have defined synthetic children for the concrete structure we want to update, then we can explicitly define there how to update it. So, in case of std::string we can't simply copy a new c-string value to a location of an old c-string value; we have to destroy the old string (free memory) and create a new one. It can be done in expression evaluation for example. I might misunderstand something in this problem, if so - please point me the right way. https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
https://github.com/kpdev created https://github.com/llvm/llvm-project/pull/67782 Before this update strings has only DataFormatters, and therefore the way they were printed was slightly different (see comment here: https://github.com/llvm/llvm-project/blob/main/lldb/source/DataFormatters/FormatManager.cpp#L498), so tests which rely on this formatting also changed. std::string/std::wstring/std::u16(32)string synthetic frontend implemented Also tests for the frontend added. ~~ Huawei RRI, OS Lab >From 433d3973716cc46e1ffd7044898189f845e536f6 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Fri, 29 Sep 2023 13:09:00 +0300 Subject: [PATCH] [lldb] Add support for updating string during debug process Before this update strings has only DataFormatters, and therefore the way they were printed was slightly different (see comment here: https://github.com/llvm/llvm-project/blob/main/lldb/source/DataFormatters/FormatManager.cpp#L498), so tests which rely on this formatting also changed. std::string/std::wstring/std::u16(32)string synthetic frontend implemented Also tests for the frontend added. ~~ Huawei RRI, OS Lab --- lldb/include/lldb/Core/ValueObject.h | 11 ++ .../lldb/DataFormatters/TypeSynthetic.h | 8 +- lldb/source/Core/ValueObject.cpp | 8 +- .../Plugins/Language/CPlusPlus/CMakeLists.txt | 1 + .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 87 + .../Plugins/Language/CPlusPlus/LibCxx.cpp | 96 +- .../Plugins/Language/CPlusPlus/LibCxx.h | 15 ++ .../Language/CPlusPlus/LibCxxString.cpp | 171 ++ .../CPlusPlus/LibCxxStringInfoExtractor.h | 119 lldb/source/Utility/Scalar.cpp| 11 +- .../TestDataFormatterGenericMultiMap.py | 105 +++ .../libcxx/map/TestDataFormatterLibccMap.py | 112 .../TestDataFormatterLibcxxSharedPtr.py | 2 +- .../TestDataFormatterLibcxxUniquePtr.py | 2 +- .../change_values/libcxx/string/Makefile | 6 + .../libcxx/string/TestChangeStringValue.py| 71 .../change_values/libcxx/string/main.cpp | 21 +++ 17 files changed, 648 insertions(+), 198 deletions(-) create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxString.cpp create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxStringInfoExtractor.h create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/Makefile create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/TestChangeStringValue.py create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/main.cpp diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 3af94f0a86e2fcc..892f5d0dea4f650 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -589,6 +589,14 @@ class ValueObject { virtual bool IsSynthetic() { return false; } + void SetSyntheticFrontend(SyntheticChildrenFrontEnd *synth_front) { +m_synthetic_frontend = synth_front; + } + + SyntheticChildrenFrontEnd *GetSyntheticFrontend() const { +return m_synthetic_frontend; + } + lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue); @@ -898,6 +906,9 @@ class ValueObject { /// Unique identifier for every value object. UserID m_id; + // If frontend exist - we may try to update our value through it + SyntheticChildrenFrontEnd *m_synthetic_frontend = nullptr; + // Utility class for initializing all bitfields in ValueObject's constructors. // FIXME: This could be done via default initializers once we have C++20. struct Bitflags { diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 41be9b7efda8fdb..3a19804b22c196c 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -34,7 +34,9 @@ class SyntheticChildrenFrontEnd { public: SyntheticChildrenFrontEnd(ValueObject &backend) - : m_backend(backend), m_valid(true) {} + : m_backend(backend), m_valid(true) { +backend.SetSyntheticFrontend(this); + } virtual ~SyntheticChildrenFrontEnd() = default; @@ -75,6 +77,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + typedef std::shared_ptr SharedPointer; typedef std::unique_ptr AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index ebfc1cf4d6fe9e1..ba88f848c0fb191 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1479,7 +1479,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { if (v
[Lldb-commits] [lldb] [lldb] Add support for changing char in Scalar::SetValueFromCString (PR #67784)
https://github.com/kpdev created https://github.com/llvm/llvm-project/pull/67784 When we trying to change not the whole string, but single character in it - lldb's ValueObject fits in Scalar and therefore lldb trying to update it as a Scalar value which is currently only support numbers, so characters support added. ~~ Huawei RRI, OS Lab >From 55dbf63ab7a052859fc7b297f699f0957484d3bf Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Fri, 29 Sep 2023 12:04:16 +0300 Subject: [PATCH] [lldb] Add support for changing char in Scalar::SetValueFromCString When we trying to change not the whole string, but single character in it - lldb's ValueObject fits in Scalar and therefore lldb trying to update it as a Scalar value which is currently only support numbers, so characters support added. ~~ Huawei RRI, OS Lab --- lldb/source/Utility/Scalar.cpp | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp index 791c0fb74352913..33d0b832bfd9be6 100644 --- a/lldb/source/Utility/Scalar.cpp +++ b/lldb/source/Utility/Scalar.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include // for std::isalpha #include #include @@ -646,7 +647,15 @@ Status Scalar::SetValueFromCString(const char *value_str, Encoding encoding, bool is_signed = encoding == eEncodingSint; bool is_negative = is_signed && str.consume_front("-"); APInt integer; -if (str.getAsInteger(0, integer)) { +if (str.size() == 1 && std::isalpha(static_cast(str[0]))) { + // We can represent single character as Scalar - + // this is useful when working with symbols in string + // NOTE: it is okay to consider char size as 8-bit since we only have + // `SetValueFrom C String` api, not the `C Wstring` or something like + // that. If we can ever get wide characters here - we have to modify this + // behaviour somehow. + integer = APInt(8, static_cast(str[0])); +} else if (str.getAsInteger(0, integer)) { error.SetErrorStringWithFormatv( "'{0}' is not a valid integer string value", value_str); break; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
kpdev wrote: Patch 2: https://github.com/llvm/llvm-project/pull/67782 Patch 3: https://github.com/llvm/llvm-project/pull/67784 https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
kpdev wrote: Depends on: https://github.com/llvm/llvm-project/pull/67309#issuecomment-1740657973 https://github.com/llvm/llvm-project/pull/67782 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for changing char in Scalar::SetValueFromCString (PR #67784)
kpdev wrote: Depends on: https://github.com/llvm/llvm-project/pull/67309#issuecomment-1740657973 https://github.com/llvm/llvm-project/pull/67784 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
kpdev wrote: @jimingham @bulbazord Please check patch with all supposed changes (without breaking into different patches) https://github.com/llvm/llvm-project/pull/67784 https://github.com/llvm/llvm-project/pull/67309 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/67782 >From ccc9fb6be2f390cd894e0632cfded98f329f3059 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Wed, 10 Apr 2024 14:45:49 +0300 Subject: [PATCH] [LLDB] Add ability to update string during debugging This is the last patch needed for adding an ability to update std::string/wstring/etc during debug process. std::string/std::wstring/std::u16(32)string synthetic frontend implemented Also tests for the frontend added. ~~ Huawei RRI, OS Lab --- .../lldb/DataFormatters/TypeSynthetic.h | 4 + lldb/source/Core/ValueObject.cpp | 2 +- .../Core/ValueObjectSyntheticFilter.cpp | 2 + lldb/source/DataFormatters/FormatManager.cpp | 10 +- .../Plugins/Language/CPlusPlus/CMakeLists.txt | 1 + .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 88 + .../Plugins/Language/CPlusPlus/LibCxx.cpp | 96 +- .../Plugins/Language/CPlusPlus/LibCxx.h | 15 ++ .../Language/CPlusPlus/LibCxxString.cpp | 171 ++ .../CPlusPlus/LibCxxStringInfoExtractor.h | 119 .../change_values/libcxx/string/Makefile | 6 + .../libcxx/string/TestChangeStringValue.py| 56 ++ .../change_values/libcxx/string/main.cpp | 21 +++ 13 files changed, 461 insertions(+), 130 deletions(-) create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxString.cpp create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxStringInfoExtractor.h create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/Makefile create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/TestChangeStringValue.py create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/main.cpp diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index ede7442a02bf6af..6de32eed79942b3 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -80,6 +80,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + typedef std::shared_ptr SharedPointer; typedef std::unique_ptr AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index f39bd07a255366a..dca15e4d427b26d 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1461,7 +1461,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { if (value_type == Value::ValueType::Scalar) { // If the value is already a scalar, then let the scalar change itself: m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); - } else if (byte_size <= 16) { + } else if (byte_size <= 16 && encoding != eEncodingInvalid) { // If the value fits in a scalar, then make a new scalar and again let the // scalar code do the conversion, then figure out where to put the new // value. diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp index adac1b400705e20..f2d7e240200693f 100644 --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -379,6 +379,8 @@ bool ValueObjectSynthetic::CanProvideValue() { bool ValueObjectSynthetic::SetValueFromCString(const char *value_str, Status &error) { + if (m_synth_filter_up->SetValueFromCString(value_str, error)) +return true; return m_parent->SetValueFromCString(value_str, error); } diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index d7ba5b4b70c949c..8b2be03694ede56 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -504,9 +504,13 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) { // wait.. wat? just get out of here.. if (!synth_sp) return false; - // but if we only have them to provide a value, keep going - if (!synth_sp->MightHaveChildren() && - synth_sp->DoesProvideSyntheticValue()) + // but if they can fit in one line or ... + if (auto format = synth_sp->GetSummaryFormat()) { +is_synth_val = format->IsOneLiner(); + } + // ... if we only have them to provide a value, keep going + else if (!synth_sp->MightHaveChildren() && + synth_sp->DoesProvideSyntheticValue()) is_synth_val = true; else return false; diff --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt index 0c6fdb2b9573152..6987838b758ebde 100644 --- a/lldb/source/Plugins/Languag
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
kpdev wrote: Hello, @jimingham , first of all - sorry for the long delay in reply. I carefully read through all your messages once again and found, that I totally misunderstood some places, i.e. "Why isn't it enough to have the ValueObjectSynthetic's SetValueFromCString do this" - I think it should be enough, I'll fix it. > Secondly, lldb only supports changing scalars because it's hard to give > meaning to "changing an aggregate object". You have to change it in situ - > which really means changing the values of its contents, i.e. its children - > or you will end up invalidating code that relies on the location of the > aggregate I agree with this, but I think there is not so much aggregates for which it makes sense to change their length as for strings (at least in libcxx) - I mean it is natural to update whole string to completely different value, but it is not natural to do so for e.g. vector. In case of strings, one might want to set string longer, than the one he has now for the debug purposes, so this will indeed invalidate code, that relies on the pointers that was obtained through `.data` or `.c_str` methods, but it is the programmer responsibility to care about this. This it the same behaviour as if you change your string in the program - you should update your pointers. > However, I think it's confusing here to start with the model that > ValueObjects with SCPs have "underlying strings". Sorry, I think that I didn't express my thoughts carefully, by the underlying string I didn't mean, that we have some string in the SCP or ValueObjects, I meant the strings in the code that is under debug. > By the way, as a side note, watching the part of your example where you > change the raw string guts, it looks like we don't update summaries of a > ValueObject if one of its children gets changed. Be good to file bug on that > one so we don't forget. I'm not sure that this bug might be reproduced without the string example, I don't know which type have the summary which represent all its children. Is it ok, to file a bug with current strings example or how to do it better? > In the case of std::strings, which seems to be your primary motivator here, I > think considering the string value to be the summary makes the most sense And in the end, may I kindly ask you to clarify your position about these changes please? Do you suggest to return to the `SetSummaryFromCString` API? https://github.com/llvm/llvm-project/pull/67782 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] f63e2cf - [LLDB] Add basic floating point ops to IR interpreter
Author: Pavel Kosov Date: 2022-08-10T16:34:52+03:00 New Revision: f63e2cfb7f5235d4d5148988e8a0ef86004da66e URL: https://github.com/llvm/llvm-project/commit/f63e2cfb7f5235d4d5148988e8a0ef86004da66e DIFF: https://github.com/llvm/llvm-project/commit/f63e2cfb7f5235d4d5148988e8a0ef86004da66e.diff LOG: [LLDB] Add basic floating point ops to IR interpreter Patch adds support for fadd, fsub, fdiv, fmul and fcmp to IR interpreter. ~~~ OS Laboratory. Huawei RRI. Saint-Petersburg Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D126359 Added: lldb/test/API/lang/c/fpeval/Makefile lldb/test/API/lang/c/fpeval/TestFPEval.py lldb/test/API/lang/c/fpeval/main.c Modified: lldb/source/Expression/IRInterpreter.cpp Removed: diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index a6efeb3f960f7..d03fea6ffce3c 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -167,6 +167,18 @@ class InterpreterStackFrame { const Constant *constant = dyn_cast(value); if (constant) { + if (constant->getValueID() == Value::ConstantFPVal) { +if (auto *cfp = dyn_cast(constant)) { + if (cfp->getType()->isDoubleTy()) +scalar = cfp->getValueAPF().convertToDouble(); + else if (cfp->getType()->isFloatTy()) +scalar = cfp->getValueAPF().convertToFloat(); + else +return false; + return true; +} +return false; + } APInt value_apint; if (!ResolveConstantValue(value_apint, constant)) @@ -189,9 +201,18 @@ class InterpreterStackFrame { lldb::offset_t offset = 0; if (value_size <= 8) { - uint64_t u64value = value_extractor.GetMaxU64(&offset, value_size); - return AssignToMatchType(scalar, llvm::APInt(64, u64value), - value->getType()); + Type *ty = value->getType(); + if (ty->isDoubleTy()) { +scalar = value_extractor.GetDouble(&offset); +return true; + } else if (ty->isFloatTy()) { +scalar = value_extractor.GetFloat(&offset); +return true; + } else { +uint64_t u64value = value_extractor.GetMaxU64(&offset, value_size); +return AssignToMatchType(scalar, llvm::APInt(64, u64value), + value->getType()); + } } return false; @@ -205,11 +226,15 @@ class InterpreterStackFrame { return false; lldb_private::Scalar cast_scalar; - -scalar.MakeUnsigned(); -if (!AssignToMatchType(cast_scalar, scalar.UInt128(llvm::APInt()), - value->getType())) - return false; +Type *vty = value->getType(); +if (vty->isFloatTy() || vty->isDoubleTy()) { + cast_scalar = scalar; +} else { + scalar.MakeUnsigned(); + if (!AssignToMatchType(cast_scalar, scalar.UInt128(llvm::APInt()), + value->getType())) +return false; +} size_t value_byte_size = m_target_data.getTypeStoreSize(value->getType()); @@ -543,16 +568,17 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, } break; case Instruction::GetElementPtr: break; + case Instruction::FCmp: case Instruction::ICmp: { -ICmpInst *icmp_inst = dyn_cast(&ii); +CmpInst *cmp_inst = dyn_cast(&ii); -if (!icmp_inst) { +if (!cmp_inst) { error.SetErrorToGenericError(); error.SetErrorString(interpreter_internal_error); return false; } -switch (icmp_inst->getPredicate()) { +switch (cmp_inst->getPredicate()) { default: { LLDB_LOGF(log, "Unsupported ICmp predicate: %s", PrintValue(&ii).c_str()); @@ -561,11 +587,17 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, error.SetErrorString(unsupported_opcode_error); return false; } +case CmpInst::FCMP_OEQ: case CmpInst::ICMP_EQ: +case CmpInst::FCMP_UNE: case CmpInst::ICMP_NE: +case CmpInst::FCMP_OGT: case CmpInst::ICMP_UGT: +case CmpInst::FCMP_OGE: case CmpInst::ICMP_UGE: +case CmpInst::FCMP_OLT: case CmpInst::ICMP_ULT: +case CmpInst::FCMP_OLE: case CmpInst::ICMP_ULE: case CmpInst::ICMP_SGT: case CmpInst::ICMP_SGE: @@ -595,6 +627,11 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, case Instruction::Xor: case Instruction::ZExt: break; + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: +break; } for (unsigned oi = 0, oe = ii.getNumOp
[Lldb-commits] [lldb] ff9efe2 - [LLDB][JIT] Set processor for ARM architecture
Author: Pavel Kosov Date: 2022-08-17T09:10:21+03:00 New Revision: ff9efe240c4711572d2892f9058fd94a8bd5336e URL: https://github.com/llvm/llvm-project/commit/ff9efe240c4711572d2892f9058fd94a8bd5336e DIFF: https://github.com/llvm/llvm-project/commit/ff9efe240c4711572d2892f9058fd94a8bd5336e.diff LOG: [LLDB][JIT] Set processor for ARM architecture Patch sets ARM cpu, before compiling JIT code. This enables FastISel for armv6 and higher CPUs and allows using hardware FPU ~~~ OS Laboratory. Huawei RRI. Saint-Petersburg Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D131783 Added: Modified: lldb/source/Utility/ArchSpec.cpp lldb/test/API/lang/c/fpeval/TestFPEval.py Removed: diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp index b61d180bca1e9..348a62dd0df42 100644 --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -583,7 +583,6 @@ void ArchSpec::SetFlags(const std::string &elf_abi) { std::string ArchSpec::GetClangTargetCPU() const { std::string cpu; - if (IsMIPS()) { switch (m_core) { case ArchSpec::eCore_mips32: @@ -630,6 +629,9 @@ std::string ArchSpec::GetClangTargetCPU() const { break; } } + + if (GetTriple().isARM()) +cpu = GetTriple().getARMCPUForArch("").str(); return cpu; } diff --git a/lldb/test/API/lang/c/fpeval/TestFPEval.py b/lldb/test/API/lang/c/fpeval/TestFPEval.py index 6a3dc955ebf66..694d1ed7aa99d 100644 --- a/lldb/test/API/lang/c/fpeval/TestFPEval.py +++ b/lldb/test/API/lang/c/fpeval/TestFPEval.py @@ -19,7 +19,6 @@ def setUp(self): # Find the line number to break inside main(). self.line = line_number('main.c', '// Set break point at this line.') -@skipIf(archs=no_match(['amd64', 'x86_64', 'arm64'])) # lldb jitter incorrectly evals function with FP args on 32 bit arm def test(self): """Test floating point expressions while jitter is disabled.""" self.build() ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/67309 >From a0aae1f59fcdc9f0266bdc6248544f674b298e85 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Mon, 25 Sep 2023 13:41:03 +0300 Subject: [PATCH] [lldb] Add SetValueFromCString API to SyntheticFronend It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. Add SetValueFromCString API to SyntheticFronend Overall context is avaliable in the following discussion: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3: ~~ Huawei RRI, OS Lab --- lldb/include/lldb/Core/ValueObject.h | 11 +++ lldb/include/lldb/DataFormatters/TypeSynthetic.h | 12 ++-- lldb/source/Core/ValueObject.cpp | 9 +++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 3af94f0a86e2fcc..892f5d0dea4f650 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -589,6 +589,14 @@ class ValueObject { virtual bool IsSynthetic() { return false; } + void SetSyntheticFrontend(SyntheticChildrenFrontEnd *synth_front) { +m_synthetic_frontend = synth_front; + } + + SyntheticChildrenFrontEnd *GetSyntheticFrontend() const { +return m_synthetic_frontend; + } + lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue); @@ -898,6 +906,9 @@ class ValueObject { /// Unique identifier for every value object. UserID m_id; + // If frontend exist - we may try to update our value through it + SyntheticChildrenFrontEnd *m_synthetic_frontend = nullptr; + // Utility class for initializing all bitfields in ValueObject's constructors. // FIXME: This could be done via default initializers once we have C++20. struct Bitflags { diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 41be9b7efda8fdb..8e9bf9da77211ba 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -34,9 +34,13 @@ class SyntheticChildrenFrontEnd { public: SyntheticChildrenFrontEnd(ValueObject &backend) - : m_backend(backend), m_valid(true) {} + : m_backend(backend), m_valid(true) { +m_backend.SetSyntheticFrontend(this); + } - virtual ~SyntheticChildrenFrontEnd() = default; + virtual ~SyntheticChildrenFrontEnd() { +m_backend.SetSyntheticFrontend(nullptr); + } virtual size_t CalculateNumChildren() = 0; @@ -75,6 +79,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + typedef std::shared_ptr SharedPointer; typedef std::unique_ptr AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index ebfc1cf4d6fe9e1..e6ae56045d5f3ba 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1479,7 +1479,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { if (value_type == Value::ValueType::Scalar) { // If the value is already a scalar, then let the scalar change itself: m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); - } else if (byte_size <= 16) { + } else if (byte_size <= 16 && encoding != eEncodingInvalid) { // If the value fits in a scalar, then make a new scalar and again let the // scalar code do the conversion, then figure out where to put the new // value. @@ -1535,7 +1535,12 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { } } else { // We don't support setting things bigger than a scalar at present. -error.SetErrorString("unable to write aggregate data type"); +// But maybe our frontend knows how to update the value. +if (auto *frontend = GetSyntheticFrontend()) { + return frontend->SetValueFromCString(value_str, error); +} else { + error.SetErrorString("unable to write aggregate data type"); +} return false; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add SetValueFromCString API to SyntheticFronend (PR #67309)
https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/67309 >From 94d31eabaea7edd2cb139a45fdc8b85d2768f29d Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Mon, 25 Sep 2023 13:41:03 +0300 Subject: [PATCH] [lldb] Add SetValueFromCString API to SyntheticFronend It is a first of three patches neded for adding an ability to update std::string/wstring/etc during debug process. Add SetValueFromCString API to SyntheticFronend Overall context is avaliable in the following discussion: https://discourse.llvm.org/t/clarify-hostaddress-loadaddress-logic/72175/3: ~~ Huawei RRI, OS Lab --- lldb/include/lldb/Core/ValueObject.h | 11 +++ lldb/include/lldb/DataFormatters/TypeSynthetic.h | 12 ++-- lldb/source/Core/ValueObject.cpp | 5 - 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 3af94f0a86e2fcc..892f5d0dea4f650 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -589,6 +589,14 @@ class ValueObject { virtual bool IsSynthetic() { return false; } + void SetSyntheticFrontend(SyntheticChildrenFrontEnd *synth_front) { +m_synthetic_frontend = synth_front; + } + + SyntheticChildrenFrontEnd *GetSyntheticFrontend() const { +return m_synthetic_frontend; + } + lldb::ValueObjectSP GetQualifiedRepresentationIfAvailable(lldb::DynamicValueType dynValue, bool synthValue); @@ -898,6 +906,9 @@ class ValueObject { /// Unique identifier for every value object. UserID m_id; + // If frontend exist - we may try to update our value through it + SyntheticChildrenFrontEnd *m_synthetic_frontend = nullptr; + // Utility class for initializing all bitfields in ValueObject's constructors. // FIXME: This could be done via default initializers once we have C++20. struct Bitflags { diff --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h b/lldb/include/lldb/DataFormatters/TypeSynthetic.h index 41be9b7efda8fdb..8e9bf9da77211ba 100644 --- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h +++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h @@ -34,9 +34,13 @@ class SyntheticChildrenFrontEnd { public: SyntheticChildrenFrontEnd(ValueObject &backend) - : m_backend(backend), m_valid(true) {} + : m_backend(backend), m_valid(true) { +m_backend.SetSyntheticFrontend(this); + } - virtual ~SyntheticChildrenFrontEnd() = default; + virtual ~SyntheticChildrenFrontEnd() { +m_backend.SetSyntheticFrontend(nullptr); + } virtual size_t CalculateNumChildren() = 0; @@ -75,6 +79,10 @@ class SyntheticChildrenFrontEnd { // display purposes virtual ConstString GetSyntheticTypeName() { return ConstString(); } + virtual bool SetValueFromCString(const char *value_str, Status &error) { +return false; + } + typedef std::shared_ptr SharedPointer; typedef std::unique_ptr AutoPointer; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index ebfc1cf4d6fe9e1..c93c7dd32e0c7f2 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1479,7 +1479,7 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { if (value_type == Value::ValueType::Scalar) { // If the value is already a scalar, then let the scalar change itself: m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); - } else if (byte_size <= 16) { + } else if (byte_size <= 16 && encoding != eEncodingInvalid) { // If the value fits in a scalar, then make a new scalar and again let the // scalar code do the conversion, then figure out where to put the new // value. @@ -1535,6 +1535,9 @@ bool ValueObject::SetValueFromCString(const char *value_str, Status &error) { } } else { // We don't support setting things bigger than a scalar at present. +// But maybe our frontend knows how to update the value. +if (auto *frontend = GetSyntheticFrontend()) + return frontend->SetValueFromCString(value_str, error); error.SetErrorString("unable to write aggregate data type"); return false; } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
https://github.com/kpdev updated https://github.com/llvm/llvm-project/pull/67782 >From 374784cbaaffe9ca2bac716c996485783b959364 Mon Sep 17 00:00:00 2001 From: Pavel Kosov Date: Tue, 23 Jan 2024 09:37:54 +0300 Subject: [PATCH] [LLDB] Add ability to update string during debugging This is the last patch needed for adding an ability to update std::string/wstring/etc during debug process. std::string/std::wstring/std::u16(32)string synthetic frontend implemented Also tests for the frontend added. ~~ Huawei RRI, OS Lab --- lldb/source/DataFormatters/FormatManager.cpp | 8 +- .../Plugins/Language/CPlusPlus/CMakeLists.txt | 1 + .../Language/CPlusPlus/CPlusPlusLanguage.cpp | 88 + .../Plugins/Language/CPlusPlus/LibCxx.cpp | 96 +- .../Plugins/Language/CPlusPlus/LibCxx.h | 15 ++ .../Language/CPlusPlus/LibCxxString.cpp | 171 ++ .../CPlusPlus/LibCxxStringInfoExtractor.h | 119 .../change_values/libcxx/string/Makefile | 6 + .../libcxx/string/TestChangeStringValue.py| 56 ++ .../change_values/libcxx/string/main.cpp | 21 +++ 10 files changed, 453 insertions(+), 128 deletions(-) create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxString.cpp create mode 100644 lldb/source/Plugins/Language/CPlusPlus/LibCxxStringInfoExtractor.h create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/Makefile create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/TestChangeStringValue.py create mode 100644 lldb/test/API/python_api/value/change_values/libcxx/string/main.cpp diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index f1f135de32ca874..b57b9b864ac5819 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -502,8 +502,12 @@ bool FormatManager::ShouldPrintAsOneLiner(ValueObject &valobj) { // wait.. wat? just get out of here.. if (!synth_sp) return false; - // but if we only have them to provide a value, keep going - if (!synth_sp->MightHaveChildren() && + // but if they can fit in one line or ... + if (auto format = synth_sp->GetSummaryFormat()) { +is_synth_val = format->IsOneLiner(); + } + // ... if we only have them to provide a value, keep going + else if (!synth_sp->MightHaveChildren() && synth_sp->DoesProvideSyntheticValue()) is_synth_val = true; else diff --git a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt index 21108b27896a1a9..224f6bd205d7d2e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt +++ b/lldb/source/Plugins/Language/CPlusPlus/CMakeLists.txt @@ -14,6 +14,7 @@ add_lldb_library(lldbPluginCPlusPlusLanguage PLUGIN LibCxxQueue.cpp LibCxxRangesRefView.cpp LibCxxSpan.cpp + LibCxxString.cpp LibCxxTuple.cpp LibCxxUnorderedMap.cpp LibCxxVariant.cpp diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp index 586cc08a6f1233b..e5afab44d5dc90e 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp @@ -645,51 +645,52 @@ static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) { .SetShowMembersOneLiner(false) .SetHideItemNames(false); + static ConstString std_string_regex{ + "^std::__[[:alnum:]]+::string$" + "|" + "^std::__[[:alnum:]]+::basic_string, " + "std::__[[:alnum:]]+::allocator >$" + "|" + "^std::__[[:alnum:]]+::basic_string, " + "std::__[[:alnum:]]+::allocator >$"}; + + static ConstString std_u16string_regex{ + "^std::__[[:alnum:]]+::basic_string, " + "std::__[[:alnum:]]+::allocator >$"}; + + static ConstString std_u32string_regex{ + "^std::__[[:alnum:]]+::basic_string, " + "std::__[[:alnum:]]+::allocator >$"}; + + static ConstString std_wstring_regex{ + "^std::__[[:alnum:]]+::wstring$" + "|" + "^std::__[[:alnum:]]+::basic_string, " + "std::__[[:alnum:]]+::allocator >$"}; + AddCXXSummary(cpp_category_sp, lldb_private::formatters::LibcxxStringSummaryProviderASCII, -"std::string summary provider", "^std::__[[:alnum:]]+::string$", -stl_summary_flags, true); - AddCXXSummary(cpp_category_sp, -lldb_private::formatters::LibcxxStringSummaryProviderASCII, -"std::string summary provider", -"^std::__[[:alnum:]]+::basic_string, " -"std::__[[:alnum:]]+::allocator >$", -stl_summary_flags, true); - AddCXXSummary(cpp_category_sp, -lldb_private::formatters::LibcxxStringSummaryProviderASCII, -"std::string summary provider",
[Lldb-commits] [lldb] ff9c31b - [LLDB] Fix for libc++ atomic allowing modification of contained value
Author: Pavel Kosov Date: 2023-01-25T10:39:50+03:00 New Revision: ff9c31b23b7635f2c97c5f9c33fd4e032b717ad0 URL: https://github.com/llvm/llvm-project/commit/ff9c31b23b7635f2c97c5f9c33fd4e032b717ad0 DIFF: https://github.com/llvm/llvm-project/commit/ff9c31b23b7635f2c97c5f9c33fd4e032b717ad0.diff LOG: [LLDB] Fix for libc++ atomic allowing modification of contained value Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D140623 Added: lldb/test/API/python_api/value/change_values/libcxx/atomic/Makefile lldb/test/API/python_api/value/change_values/libcxx/atomic/TestChangeValue.py lldb/test/API/python_api/value/change_values/libcxx/atomic/main.cpp Modified: lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp Removed: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp index 4eec79a278402..8b30e3fb27d95 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp @@ -139,7 +139,7 @@ lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::GetChildAtIndex( size_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd:: GetIndexOfChildWithName(ConstString name) { - return formatters::ExtractIndexFromString(name.GetCString()); + return name == "Value" ? 0 : UINT32_MAX; } SyntheticChildrenFrontEnd * diff --git a/lldb/test/API/python_api/value/change_values/libcxx/atomic/Makefile b/lldb/test/API/python_api/value/change_values/libcxx/atomic/Makefile new file mode 100644 index 0..564cbada74e08 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/atomic/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/lldb/test/API/python_api/value/change_values/libcxx/atomic/TestChangeValue.py b/lldb/test/API/python_api/value/change_values/libcxx/atomic/TestChangeValue.py new file mode 100644 index 0..d2bb27d8c7df2 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/atomic/TestChangeValue.py @@ -0,0 +1,48 @@ +""" +Test change libc++ std::atomic values. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LibcxxChangeValueTestCase(TestBase): + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) + +@add_test_categories(["libc++"]) +@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772") +def test(self): +"""Test that we can change values of libc++ std::atomic.""" +self.build() +self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + +bkpt = self.target().FindBreakpointByID( +lldbutil.run_break_set_by_source_regexp( +self, "Set break point at this line.")) + +self.runCmd("run", RUN_SUCCEEDED) + +# Get Frame #0. +target = self.dbg.GetSelectedTarget() +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped) +thread = lldbutil.get_stopped_thread( +process, lldb.eStopReasonBreakpoint) +self.assertTrue( +thread.IsValid(), +"There should be a thread stopped due to breakpoint condition") +frame0 = thread.GetFrameAtIndex(0) +self.assertTrue(frame0.IsValid(), "Got a valid frame.") + +q_value = frame0.FindVariable("Q") +self.assertTrue(q_value.IsValid(), "Got the SBValue for val") +inner_val = q_value.GetChildAtIndex(0) +self.assertTrue(inner_val.IsValid(), "Got the SBValue for inner atomic val") +result = inner_val.SetValueFromCString("42") +self.assertTrue(result, "Setting val returned True.") +result = inner_val.GetValueAsUnsigned() +self.assertTrue(result == 42, "Got correct value (42)") diff --git a/lldb/test/API/python_api/value/change_values/libcxx/atomic/main.cpp b/lldb/test/API/python_api/value/change_values/libcxx/atomic/main.cpp new file mode 100644 index 0..60dc085d7d1f6 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/atomic/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ +std::atomic Q(1); +return Q; // Set break point at this line. +} ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 92f0e4c - [LLDB] Fixes summary formatter for libc++ map allowing modification of contained value
Author: Pavel Kosov Date: 2023-01-25T10:48:04+03:00 New Revision: 92f0e4ccafacb61f7de93e7ef5bd4beb02047086 URL: https://github.com/llvm/llvm-project/commit/92f0e4ccafacb61f7de93e7ef5bd4beb02047086 DIFF: https://github.com/llvm/llvm-project/commit/92f0e4ccafacb61f7de93e7ef5bd4beb02047086.diff LOG: [LLDB] Fixes summary formatter for libc++ map allowing modification of contained value Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D140624 Added: lldb/test/API/python_api/value/change_values/libcxx/map/Makefile lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py lldb/test/API/python_api/value/change_values/libcxx/map/main.cpp Modified: lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp Removed: diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp index bf6c65c8d9c2..21dbd64feac5 100644 --- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp +++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp @@ -397,18 +397,9 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex( // at this point we have a valid // we need to copy current_sp into a new object otherwise we will end up with // all items named __value_ - DataExtractor data; - Status error; - iterated_sp->GetData(data, error); - if (error.Fail()) { -m_tree = nullptr; -return lldb::ValueObjectSP(); - } StreamString name; name.Printf("[%" PRIu64 "]", (uint64_t)idx); - auto potential_child_sp = CreateValueObjectFromData( - name.GetString(), data, m_backend.GetExecutionContextRef(), - m_element_type); + auto potential_child_sp = iterated_sp->Clone(ConstString(name.GetString())); if (potential_child_sp) { switch (potential_child_sp->GetNumChildren()) { case 1: { diff --git a/lldb/test/API/python_api/value/change_values/libcxx/map/Makefile b/lldb/test/API/python_api/value/change_values/libcxx/map/Makefile new file mode 100644 index ..564cbada74e0 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/map/Makefile @@ -0,0 +1,6 @@ +CXX_SOURCES := main.cpp + +USE_LIBCPP := 1 + +CXXFLAGS_EXTRAS := -O0 +include Makefile.rules diff --git a/lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py b/lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py new file mode 100644 index ..087e4c8446f8 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py @@ -0,0 +1,51 @@ +""" +Test change libc++ map values. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class LibcxxChangeValueTestCase(TestBase): + +def setUp(self): +# Call super's setUp(). +TestBase.setUp(self) + +@add_test_categories(["libc++"]) +@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772") +def test(self): +"""Test that we can change values of libc++ map.""" +self.build() +self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + +bkpt = self.target().FindBreakpointByID( +lldbutil.run_break_set_by_source_regexp( +self, "Set break point at this line.")) + +self.runCmd("run", RUN_SUCCEEDED) + +# Get Frame #0. +target = self.dbg.GetSelectedTarget() +process = target.GetProcess() +self.assertState(process.GetState(), lldb.eStateStopped) +thread = lldbutil.get_stopped_thread( +process, lldb.eStopReasonBreakpoint) +self.assertTrue( +thread.IsValid(), +"There should be a thread stopped due to breakpoint condition") +frame0 = thread.GetFrameAtIndex(0) +self.assertTrue(frame0.IsValid(), "Got a valid frame.") + +val_value = frame0.FindVariable("M") +self.assertTrue(val_value.IsValid(), "Got the SBValue for val") +pair0 = val_value.GetChildMemberWithName("[0]") +self.assertTrue(pair0.IsValid(), "Got the SBValue for [0]") +self.assertTrue(pair0.GetNumChildren() == 2, "Got 2 children") +pair0_second = pair0.GetChildMemberWithName("second") +self.assertTrue(pair0_second.IsValid(), "Got the SBValue for [0].second") +result = pair0_second.SetValueFromCString("12345") +self.assertTrue(result, "Setting val returned True.") +result = pair0_second.GetValueAsUnsigned() +self.assertTrue(result == 12345, "Got correct value (12345)") diff --git a/lldb/test/API/python_api/value/change_values/libcxx/map/main.cpp b/lldb/test/API/python_api/value/change_values/libcxx/map/main.cpp new file mode 100644 index ..4e1ee213e0f3 --- /dev/null +++ b/lldb/test/API/python_api/value/change_values
[Lldb-commits] [lldb] 2af0a47 - [lldb] Consider all breakpoints in breakpoint detection
Author: Pavel Kosov Date: 2023-01-25T11:06:07+03:00 New Revision: 2af0a478eaee5e6236e7e9fd9b1e3207228ce2ff URL: https://github.com/llvm/llvm-project/commit/2af0a478eaee5e6236e7e9fd9b1e3207228ce2ff DIFF: https://github.com/llvm/llvm-project/commit/2af0a478eaee5e6236e7e9fd9b1e3207228ce2ff.diff LOG: [lldb] Consider all breakpoints in breakpoint detection Currently in some cases lldb reports stop reason as "step out" or "step over" (from thread plan completion) instead of "breakpoint", if the user breakpoint happens to be set on the same address. The part of https://github.com/llvm/llvm-project/commit/f08f5c99262ff9eaa08956334accbb2614b0f7a2 seems to overwrite internal breakpoint detection logic, so that only the last breakpoint for the current stop address is considered. Together with step-out plans not clearing its breakpoint until they are destrouyed, this creates a situation when there is a user breakpoint set for address, but internal breakpoint makes lldb report a plan completion stop reason instead of breakpoint. This patch reverts that internal breakpoint detection logic to consider all breakpoints Reviewed By: jingham Differential Revision: https://reviews.llvm.org/D140368 Added: lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/TestThreadPlanUserBreakpoint.py lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/main.cpp Modified: lldb/source/Target/StopInfo.cpp Removed: diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp index 225234c0ffbad..2c61216ee53d5 100644 --- a/lldb/source/Target/StopInfo.cpp +++ b/lldb/source/Target/StopInfo.cpp @@ -256,7 +256,7 @@ class StopInfoBreakpoint : public StopInfo { if (!m_should_perform_action) return; m_should_perform_action = false; -bool internal_breakpoint = true; +bool all_stopping_locs_internal = true; ThreadSP thread_sp(m_thread_wp.lock()); @@ -421,8 +421,6 @@ class StopInfoBreakpoint : public StopInfo { continue; } -internal_breakpoint = bp_loc_sp->GetBreakpoint().IsInternal(); - // First run the precondition, but since the precondition is per // breakpoint, only run it once per breakpoint. std::pair::iterator, bool> result = @@ -509,7 +507,7 @@ class StopInfoBreakpoint : public StopInfo { loc_desc.GetData()); // We want this stop reported, so you will know we auto-continued // but only for external breakpoints: - if (!internal_breakpoint) + if (!bp_loc_sp->GetBreakpoint().IsInternal()) thread_sp->SetShouldReportStop(eVoteYes); auto_continue_says_stop = false; } @@ -539,6 +537,9 @@ class StopInfoBreakpoint : public StopInfo { actually_said_continue = true; } +if (m_should_stop && !bp_loc_sp->GetBreakpoint().IsInternal()) + all_stopping_locs_internal = false; + // If we are going to stop for this breakpoint, then remove the // breakpoint. if (callback_says_stop && bp_loc_sp && @@ -576,7 +577,7 @@ class StopInfoBreakpoint : public StopInfo { __FUNCTION__, m_value); } - if ((!m_should_stop || internal_breakpoint) && + if ((!m_should_stop || all_stopping_locs_internal) && thread_sp->CompletedPlanOverridesBreakpoint()) { // Override should_stop decision when we have completed step plan diff --git a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile new file mode 100644 index 0..2c00681fa2280 --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile @@ -0,0 +1,8 @@ +CXX_SOURCES := main.cpp + +ifneq (,$(findstring icc,$(CC))) +CXXFLAGS_EXTRAS := -debug inline-debug-info +endif + + +include Makefile.rules diff --git a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/TestThreadPlanUserBreakpoint.py b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/TestThreadPlanUserBreakpoint.py new file mode 100644 index 0..aaecdff0069f6 --- /dev/null +++ b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/TestThreadPlanUserBreakpoint.py @@ -0,0 +1,121 @@ +""" +Test that breakpoints (reason = breakpoint) have more priority than +plan completion (reason = step in/out/over) when reporting stop reason after step, +in particular 'step out' and 'step over', and in addition 'step in'. +Check for correct StopReason when stepping to the line with breakpoint, +which should be eStopReasonBreakp
[Lldb-commits] [lldb] 4ae221f - [NFC][LLDB] Rename test file
Author: Pavel Kosov Date: 2023-01-25T12:03:11+03:00 New Revision: 4ae221f5a4d1977f316b7d5f033763f876b471e7 URL: https://github.com/llvm/llvm-project/commit/4ae221f5a4d1977f316b7d5f033763f876b471e7 DIFF: https://github.com/llvm/llvm-project/commit/4ae221f5a4d1977f316b7d5f033763f876b471e7.diff LOG: [NFC][LLDB] Rename test file Commit 92f0e4cca introduced test file with name TestChangeValue.py, which leads to test failure because there already is a test files with the same name In this commit a newly added file is renamed to fix this failure Added: lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeMapValue.py Modified: Removed: lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py diff --git a/lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py b/lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeMapValue.py similarity index 100% rename from lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeValue.py rename to lldb/test/API/python_api/value/change_values/libcxx/map/TestChangeMapValue.py ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 1aab5e6 - [LLDB] Provide target specific directories to libclang
Author: Pavel Kosov Date: 2021-11-25T21:27:02+03:00 New Revision: 1aab5e653d2cf8b147748d014c5fb513a4670418 URL: https://github.com/llvm/llvm-project/commit/1aab5e653d2cf8b147748d014c5fb513a4670418 DIFF: https://github.com/llvm/llvm-project/commit/1aab5e653d2cf8b147748d014c5fb513a4670418.diff LOG: [LLDB] Provide target specific directories to libclang On Linux some C++ and C include files reside in target specific directories, like /usr/include/x86_64-linux-gnu. Patch adds them to libclang, so LLDB jitter has more chances to compile expression. OS Laboratory. Huawei Russian Research Institute. Saint-Petersburg Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D110827 Added: Modified: lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.h lldb/unittests/Expression/CppModuleConfigurationTest.cpp Removed: diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index 50e9f78278388..1437d7b58293a 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -516,7 +516,7 @@ CppModuleConfiguration GetModuleConfig(lldb::LanguageType language, // Try to create a configuration from the files. If there is no valid // configuration possible with the files, this just returns an invalid // configuration. - return CppModuleConfiguration(files); + return CppModuleConfiguration(files, target->GetArchitecture().GetTriple()); } bool ClangUserExpression::PrepareForParsing( diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp index ffab16b1682be..befb1f1254060 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp @@ -10,6 +10,7 @@ #include "ClangHost.h" #include "lldb/Host/FileSystem.h" +#include "llvm/ADT/Triple.h" using namespace lldb_private; @@ -30,7 +31,35 @@ bool CppModuleConfiguration::SetOncePath::TrySet(llvm::StringRef path) { return false; } -bool CppModuleConfiguration::analyzeFile(const FileSpec &f) { +static llvm::SmallVector +getTargetIncludePaths(const llvm::Triple &triple) { + llvm::SmallVector paths; + if (!triple.str().empty()) { +paths.push_back("/usr/include/" + triple.str()); +if (!triple.getArchName().empty() || +triple.getOSAndEnvironmentName().empty()) + paths.push_back(("/usr/include/" + triple.getArchName() + "-" + + triple.getOSAndEnvironmentName()) + .str()); + } + return paths; +} + +/// Returns the include path matching the given pattern for the given file +/// path (or None if the path doesn't match the pattern). +static llvm::Optional +guessIncludePath(llvm::StringRef path_to_file, llvm::StringRef pattern) { + if (pattern.empty()) +return llvm::NoneType(); + size_t pos = path_to_file.find(pattern); + if (pos == llvm::StringRef::npos) +return llvm::NoneType(); + + return path_to_file.substr(0, pos + pattern.size()); +} + +bool CppModuleConfiguration::analyzeFile(const FileSpec &f, + const llvm::Triple &triple) { using namespace llvm::sys::path; // Convert to slashes to make following operations simpler. std::string dir_buffer = convert_to_slash(f.GetDirectory().GetStringRef()); @@ -43,15 +72,25 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f) { // need to be specified in the header search. if (libcpp_regex.match(f.GetPath()) && parent_path(posix_dir, Style::posix).endswith("c++")) { -return m_std_inc.TrySet(posix_dir); +if (!m_std_inc.TrySet(posix_dir)) + return false; +if (triple.str().empty()) + return true; + +posix_dir.consume_back("c++/v1"); +// Check if this is a target-specific libc++ include directory. +return m_std_target_inc.TrySet( +(posix_dir + triple.str() + "/c++/v1").str()); } - // Check for /usr/include. On Linux this might be /usr/include/bits, so - // we should remove that '/bits' suffix to get the actual include directory. - if (posix_dir.endswith("/usr/include/bits")) -posix_dir.consume_back("/bits"); - if (posix_dir.endswith("/usr/include")) -return m_c_inc.TrySet(posix_dir); + llvm::Optional inc_path; + // Target specific paths contains /usr/include, so we check them first + for (auto &path : getTargetIncludePaths(triple)) { +if ((inc_path = guessIncludePath(posix_dir, path))) + return m_c_target_inc.TrySet(*inc_path); + } + if (
[Lldb-commits] [lldb] [lldb] Add support for changing char in Scalar::SetValueFromCString (PR #67784)
kpdev wrote: > This seems like a somewhat limited way to poke a character into the value if > the string has more than one character already in it. > > If you are trying to do more fancy setting of the contents of an SBValue, > then it would be more straightforward to get the SBData for the value with > GetData, then you have access to the actual bytes in the data, and you can > poke in values wherever you want. I think that might be a better approach > than trying to get SetValueFromCString to handle changing single character > ValueObjects. The main purpose of all these patches is to be able to update string value during debug process in IDE (vscode for example). LLDB communication with IDE is not straight, it uses some external tools for this, e.g.: When we want to change value in the vscode, firstly vscode send request to lldb-mi through `Debug Adapter Protocol`, then lldb-mi asks lldb to change received value through `SetValueFromCString` api, so if we would like to avoid using this api - we need to add such support on the lldb-mi side. But it is not necessary, that IDE will communicate to the lldb-mi, it can send requests to any tool which supports DAP, and this tool will probably use `SetValueFromCString` api https://github.com/llvm/llvm-project/pull/67784 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
kpdev wrote: > What is it about this change that is defeating the ValueObject printer from > compressing this output onto one line? It looks like the contents that get > printed are the same, so there's something about switching from a Summary > provider to a child provider that's causing problems. We should fix that as > people are really picky about variable printing being as space efficient as > possible. > To clear up terminology... Strings had data formatters before AND after this > change. The difference is that you've switched from a "Summary Provider" data > formatter to a "Synthetic Child Provider" data formatter. > > It looks like you've made the printing of std::strings less space efficient. > That shouldn't be necessary, and isn't desirable. We should figure out why > that's happening and fix that before this change is going to not cause > complaints. As there is mentioned in a comment for `FormatManager::ShouldPrintAsOneLiner` ( https://github.com/llvm/llvm-project/blob/main/lldb/source/DataFormatters/FormatManager.cpp#L498 ): ``` // if we decided to define synthetic children for a type, we probably care // enough to show them, but avoid nesting children in children ``` So, there is a condition for that: ``` // but if we only have them to provide a value, keep going if (!synth_sp->MightHaveChildren() && synth_sp->DoesProvideSyntheticValue()) is_synth_val = true; else return false; ``` This patch adds StringSynthetic and this synthetic `MightHaveChildren()` is `true`, therefore `ShouldPrintAsOneLiner` returns `false`. And the printer will use `"()"` or `"{\n ... \n}"` according to whether we return `true` or `false` from this function. If we would like to avoid unnecessary output we probably may ask SyntheticFrontend directly if it would like to print expanded info or not, what do you think about it? https://github.com/llvm/llvm-project/pull/67782 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add support for updating string during debug process (PR #67782)
kpdev wrote: > BTW, I have no problem with the general direction of this change. It makes a > lot more sense to ask a synthetic child provider to change a value - since it > does represent the value of the ValueObject - rather than the summary which > is just some free-form text. And being able to change characters in a string > seems a reasonable thing to do, so switching the std::string comprehension > from a Summary provider to a Synthetic Child Provider is the way to do that. > So that part if fine. > > But std::strings abound in code, and so if we're going to make this change I > don't think we can make that printing less space efficient, which this change > seems to have done. We should figure out why that's the case and fix for this > to be a really good change. So, is it Ok to use current `SetValueFromCString` api from ValueObject to ask synthetic provider to update the underlying string? You mentioned previously that we may add `SetSummaryFromCString` api - in fact currently this is what I am doing - changing the whole string through its summary (please check attached gif for example). But the problem with the new API is the same as for the changing characters through `SBValue::GetData` - IDE doesn't support it https://github.com/llvm/llvm-project/pull/67782 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] a0fb69d - [lldb][DWARF5] Enable macro evaluation
Author: Pavel Kosov Date: 2022-09-14T11:32:07+03:00 New Revision: a0fb69d17b4d7501a85554010727837340e7b52f URL: https://github.com/llvm/llvm-project/commit/a0fb69d17b4d7501a85554010727837340e7b52f DIFF: https://github.com/llvm/llvm-project/commit/a0fb69d17b4d7501a85554010727837340e7b52f.diff LOG: [lldb][DWARF5] Enable macro evaluation Patch enables handing of DWARFv5 DW_MACRO_define_strx and DW_MACRO_undef_strx ~~~ OS Laboratory. Huawei RRI. Saint-Petersburg Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D130062 Added: lldb/test/API/lang/c/macro/Makefile lldb/test/API/lang/c/macro/TestMacro.py lldb/test/API/lang/c/macro/main.c Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/test/API/commands/expression/macros/Makefile lldb/test/API/commands/expression/macros/TestMacros.py Removed: diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp index 37e28a09f3c45..c357033aa91d7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFContext.cpp @@ -92,8 +92,8 @@ const DWARFDataExtractor &DWARFContext::getOrLoadLocListsData() { } const DWARFDataExtractor &DWARFContext::getOrLoadMacroData() { - return LoadOrGetSection(eSectionTypeDWARFDebugMacro, llvm::None, - m_data_debug_macro); + return LoadOrGetSection(eSectionTypeDWARFDebugMacro, + eSectionTypeDWARFDebugMacro, m_data_debug_macro); } const DWARFDataExtractor &DWARFContext::getOrLoadRangesData() { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp index 19c6448c4e74a..d7a43a3f9c68b 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp @@ -16,6 +16,11 @@ using namespace lldb_private; using namespace lldb_private::dwarf; +uint64_t DWARFStrOffsetsInfo::GetOffset(uint64_t index) const { + uint64_t offset = cu_str_offset + data.GetDWARFSizeOfOffset() * index; + return data.GetU32(&offset); +} + DWARFDebugMacroHeader DWARFDebugMacroHeader::ParseHeader(const DWARFDataExtractor &debug_macro_data, lldb::offset_t *offset) { @@ -59,7 +64,8 @@ void DWARFDebugMacroHeader::SkipOperandTable( void DWARFDebugMacroEntry::ReadMacroEntries( const DWARFDataExtractor &debug_macro_data, -const DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit, +const DWARFDataExtractor &debug_str_data, +const DWARFStrOffsetsInfo *str_offsets_info, const bool offset_is_64_bit, lldb::offset_t *offset, SymbolFileDWARF *sym_file_dwarf, DebugMacrosSP &debug_macros_sp) { llvm::dwarf::MacroEntryType type = @@ -97,6 +103,22 @@ void DWARFDebugMacroEntry::ReadMacroEntries( debug_macros_sp->AddMacroEntry( DebugMacroEntry::CreateUndefEntry(line, macro_str)); break; +case DW_MACRO_define_strx: +case DW_MACRO_undef_strx: + line = debug_macro_data.GetULEB128(offset); + str_offset = debug_macro_data.GetULEB128(offset); + if (!str_offsets_info) +// Can't do much in this case, skip all such entries +continue; + str_offset = str_offsets_info->GetOffset(str_offset); + macro_str = debug_str_data.GetCStr(&str_offset); + if (type == DW_MACRO_define_strx) +debug_macros_sp->AddMacroEntry( +DebugMacroEntry::CreateDefineEntry(line, macro_str)); + else +debug_macros_sp->AddMacroEntry( +DebugMacroEntry::CreateUndefEntry(line, macro_str)); + break; case DW_MACRO_start_file: line = debug_macro_data.GetULEB128(offset); debug_line_file_idx = debug_macro_data.GetULEB128(offset); @@ -113,7 +135,7 @@ void DWARFDebugMacroEntry::ReadMacroEntries( else new_offset = debug_macro_data.GetU32(offset); debug_macros_sp->AddMacroEntry(DebugMacroEntry::CreateIndirectEntry( - sym_file_dwarf->ParseDebugMacros(&new_offset))); + sym_file_dwarf->ParseDebugMacros(&new_offset, str_offsets_info))); break; default: // TODO: Add support for other standard operations. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h index cbf762458331b..27be105b5949a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.h @@ -24,6 +24,17 @@ class DWARFDataExtractor; class SymbolFi