[Lldb-commits] [lldb] [lldb-dap] Support inspecting memory (PR #104317)

2024-09-16 Thread Adrian Vogelsgesang via lldb-commits

https://github.com/vogelsgesang updated 
https://github.com/llvm/llvm-project/pull/104317

>From 88b48a5df0153a44276f14872c48e10639dcb673 Mon Sep 17 00:00:00 2001
From: Adrian Vogelsgesang 
Date: Wed, 14 Aug 2024 11:52:40 +
Subject: [PATCH 01/10] [lldb-dap] Support inspecting memory

Adds support for the `readMemory` request which allows VS-Code to
inspect memory. Also, add `memoryReference` to variablesa and `evaluate`
responses, such that the binary view can be opened from the variables
view and from the "watch" pane.
---
 .../test/tools/lldb-dap/dap_server.py |  13 ++
 lldb/test/API/tools/lldb-dap/memory/Makefile  |   3 +
 .../tools/lldb-dap/memory/TestDAP_memory.py   | 135 +
 lldb/test/API/tools/lldb-dap/memory/main.cpp  |  10 +
 lldb/tools/lldb-dap/JSONUtils.cpp |  29 ++-
 lldb/tools/lldb-dap/JSONUtils.h   |   6 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 177 +-
 7 files changed, 367 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/main.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index c6417760f17a2b..78c0f6233413b6 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -691,6 +691,19 @@ def request_disassemble(
 for inst in instructions:
 self.disassembled_instructions[inst["address"]] = inst
 
+def request_read_memory(self, memoryReference, offset, count):
+args_dict = {
+"memoryReference": memoryReference,
+"offset": offset,
+"count": count,
+}
+command_dict = {
+"command": "readMemory",
+"type": "request",
+"arguments": args_dict,
+}
+return self.send_recv(command_dict)
+
 def request_evaluate(self, expression, frameIndex=0, threadId=None, 
context=None):
 stackFrame = self.get_stackFrame(frameIndex=frameIndex, 
threadId=threadId)
 if stackFrame is None:
diff --git a/lldb/test/API/tools/lldb-dap/memory/Makefile 
b/lldb/test/API/tools/lldb-dap/memory/Makefile
new file mode 100644
index 00..8b20bcb050
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/memory/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py 
b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
new file mode 100644
index 00..f950d5eecda671
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
@@ -0,0 +1,135 @@
+"""
+Test lldb-dap memory support
+"""
+
+from base64 import b64decode
+import dap_server
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbdap_testcase
+import os
+
+
+class TestDAP_memory(lldbdap_testcase.DAPTestCaseBase):
+def test_read_memory(self):
+"""
+Tests the 'read_memory' request
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+source = "main.cpp"
+self.source_path = os.path.join(os.getcwd(), source)
+self.set_source_breakpoints(
+source,
+[line_number(source, "// Breakpoint")],
+)
+self.continue_to_next_stop()
+
+locals = {l["name"]: l for l in self.dap_server.get_local_variables()}
+rawptr_ref = locals["rawptr"]["memoryReference"]
+
+# We can read the complete string
+mem = self.dap_server.request_read_memory(rawptr_ref, 0, 5)["body"]
+self.assertEqual(mem["unreadableBytes"], 0)
+self.assertEqual(b64decode(mem["data"]), b"dead\0")
+
+# Use an offset
+mem = self.dap_server.request_read_memory(rawptr_ref, 2, 3)["body"]
+self.assertEqual(b64decode(mem["data"]), b"ad\0")
+
+# Use a negative offset
+mem = self.dap_server.request_read_memory(rawptr_ref, -1, 6)["body"]
+self.assertEqual(b64decode(mem["data"])[1:], b"dead\0")
+
+# Reads of size 0 are successful
+# VS-Code sends those in order to check if a `memoryReference` can 
actually be dereferenced.
+mem = self.dap_server.request_read_memory(rawptr_ref, 0, 0)
+self.assertEqual(mem["success"], True)
+self.assertEqual(mem["body"]["data"], "")
+
+# Reads at offset 0x0 fail
+mem = self.dap_server.request_read_memory("0x0", 0, 6)
+self.assertEqual(mem["success"], False)
+self.assertTrue(mem["message"].startswith("Unable to read memory: "))
+
+def test_memory_refs_variables(self):
+"""
+Tests memory references for evaluate
+"""
+  

[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/99012
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 765e106 - [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (#99012)

2024-09-16 Thread via lldb-commits

Author: Michael Buch
Date: 2024-09-16T13:46:19+01:00
New Revision: 765e106fb1b0e0aeb1bba18dfd93bd28233bba2f

URL: 
https://github.com/llvm/llvm-project/commit/765e106fb1b0e0aeb1bba18dfd93bd28233bba2f
DIFF: 
https://github.com/llvm/llvm-project/commit/765e106fb1b0e0aeb1bba18dfd93bd28233bba2f.diff

LOG: [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests 
(#99012)

This is a follow-up to https://github.com/llvm/llvm-project/pull/98330
for the upcoming `__compressed_pair` refactor in
https://github.com/llvm/llvm-project/issues/93069

This patch just adds the 2 new copies of `_LIBCPP_COMPRESSED_PAIR`
layouts to the simulator tests.

Added: 


Modified: 

lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/unique_ptr/TestDataFormatterLibcxxUniquePtrSimulator.py

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/unique_ptr/main.cpp

Removed: 




diff  --git 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
index 026e7183ab27a0..89eafcec0ea962 100644
--- 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
+++ 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
@@ -7,7 +7,7 @@
 namespace std {
 namespace __lldb {
 
-// Post-c88580c layout
+#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
 struct __value_init_tag {};
 struct __default_init_tag {};
 
@@ -52,6 +52,53 @@ class __compressed_pair : private 
__compressed_pair_elem<_T1, 0>,
 
   _T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
 };
+#elif COMPRESSED_PAIR_REV == 1
+// From libc++ datasizeof.h
+template  struct _FirstPaddingByte {
+  [[no_unique_address]] _Tp __v_;
+  char __first_padding_byte_;
+};
+
+template 
+inline const size_t __datasizeof_v =
+__builtin_offsetof(_FirstPaddingByte<_Tp>, __first_padding_byte_);
+
+template 
+struct __lldb_is_final : public integral_constant {};
+
+template  class __compressed_pair_padding {
+  char __padding_[((is_empty<_ToPad>::value &&
+!__lldb_is_final<_ToPad>::value) ||
+   is_reference<_ToPad>::value)
+  ? 0
+  : sizeof(_ToPad) - __datasizeof_v<_ToPad>];
+};
+
+#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)  
\
+  [[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; 
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_;
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3,
\
+Initializer3)  
\
+  [[using __gnu__: __aligned__(alignof(T2)),   
\
+__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1;  
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_; 
\
+  [[no_unique_address]] T3 Initializer3;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding3_;
+#elif COMPRESSED_PAIR_REV == 2
+#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2)
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3)   
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2;  
\
+  [[no_unique_address]] T3 Name3
+#endif
 } // namespace __lldb
 } // namespace std
 

diff  --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 98d2c7320003e4..afe6374e55a355 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatt

[Lldb-commits] [lldb] [lldb-dap] Support inspecting memory (PR #104317)

2024-09-16 Thread Adrian Vogelsgesang via lldb-commits

https://github.com/vogelsgesang updated 
https://github.com/llvm/llvm-project/pull/104317

>From 88b48a5df0153a44276f14872c48e10639dcb673 Mon Sep 17 00:00:00 2001
From: Adrian Vogelsgesang 
Date: Wed, 14 Aug 2024 11:52:40 +
Subject: [PATCH 1/9] [lldb-dap] Support inspecting memory

Adds support for the `readMemory` request which allows VS-Code to
inspect memory. Also, add `memoryReference` to variablesa and `evaluate`
responses, such that the binary view can be opened from the variables
view and from the "watch" pane.
---
 .../test/tools/lldb-dap/dap_server.py |  13 ++
 lldb/test/API/tools/lldb-dap/memory/Makefile  |   3 +
 .../tools/lldb-dap/memory/TestDAP_memory.py   | 135 +
 lldb/test/API/tools/lldb-dap/memory/main.cpp  |  10 +
 lldb/tools/lldb-dap/JSONUtils.cpp |  29 ++-
 lldb/tools/lldb-dap/JSONUtils.h   |   6 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 177 +-
 7 files changed, 367 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
 create mode 100644 lldb/test/API/tools/lldb-dap/memory/main.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index c6417760f17a2b..78c0f6233413b6 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -691,6 +691,19 @@ def request_disassemble(
 for inst in instructions:
 self.disassembled_instructions[inst["address"]] = inst
 
+def request_read_memory(self, memoryReference, offset, count):
+args_dict = {
+"memoryReference": memoryReference,
+"offset": offset,
+"count": count,
+}
+command_dict = {
+"command": "readMemory",
+"type": "request",
+"arguments": args_dict,
+}
+return self.send_recv(command_dict)
+
 def request_evaluate(self, expression, frameIndex=0, threadId=None, 
context=None):
 stackFrame = self.get_stackFrame(frameIndex=frameIndex, 
threadId=threadId)
 if stackFrame is None:
diff --git a/lldb/test/API/tools/lldb-dap/memory/Makefile 
b/lldb/test/API/tools/lldb-dap/memory/Makefile
new file mode 100644
index 00..8b20bcb050
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/memory/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py 
b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
new file mode 100644
index 00..f950d5eecda671
--- /dev/null
+++ b/lldb/test/API/tools/lldb-dap/memory/TestDAP_memory.py
@@ -0,0 +1,135 @@
+"""
+Test lldb-dap memory support
+"""
+
+from base64 import b64decode
+import dap_server
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbdap_testcase
+import os
+
+
+class TestDAP_memory(lldbdap_testcase.DAPTestCaseBase):
+def test_read_memory(self):
+"""
+Tests the 'read_memory' request
+"""
+program = self.getBuildArtifact("a.out")
+self.build_and_launch(program)
+source = "main.cpp"
+self.source_path = os.path.join(os.getcwd(), source)
+self.set_source_breakpoints(
+source,
+[line_number(source, "// Breakpoint")],
+)
+self.continue_to_next_stop()
+
+locals = {l["name"]: l for l in self.dap_server.get_local_variables()}
+rawptr_ref = locals["rawptr"]["memoryReference"]
+
+# We can read the complete string
+mem = self.dap_server.request_read_memory(rawptr_ref, 0, 5)["body"]
+self.assertEqual(mem["unreadableBytes"], 0)
+self.assertEqual(b64decode(mem["data"]), b"dead\0")
+
+# Use an offset
+mem = self.dap_server.request_read_memory(rawptr_ref, 2, 3)["body"]
+self.assertEqual(b64decode(mem["data"]), b"ad\0")
+
+# Use a negative offset
+mem = self.dap_server.request_read_memory(rawptr_ref, -1, 6)["body"]
+self.assertEqual(b64decode(mem["data"])[1:], b"dead\0")
+
+# Reads of size 0 are successful
+# VS-Code sends those in order to check if a `memoryReference` can 
actually be dereferenced.
+mem = self.dap_server.request_read_memory(rawptr_ref, 0, 0)
+self.assertEqual(mem["success"], True)
+self.assertEqual(mem["body"]["data"], "")
+
+# Reads at offset 0x0 fail
+mem = self.dap_server.request_read_memory("0x0", 0, 6)
+self.assertEqual(mem["success"], False)
+self.assertTrue(mem["message"].startswith("Unable to read memory: "))
+
+def test_memory_refs_variables(self):
+"""
+Tests memory references for evaluate
+"""
+

[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread via lldb-commits

dlav-sc wrote:

@JDevlieghere @jasonmolenda @labath @tedwoodward could you take another look, 
please.

https://github.com/llvm/llvm-project/pull/99336
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/99012

>From 8d0245dfccc607a4237fc94bbbfea646fa1a6887 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 10 Jul 2024 15:37:45 +0100
Subject: [PATCH 1/5] [WIP][lldb][test] Add a new __compressed_pair layout to
 libcxx simulator tests

---
 .../compressed_pair.h | 34 ++-
 .../TestDataFormatterLibcxxStringSimulator.py | 19 ++-
 .../libcxx-simulators/string/main.cpp | 33 +++---
 ...stDataFormatterLibcxxUniquePtrSimulator.py | 14 ++--
 .../libcxx-simulators/unique_ptr/main.cpp |  5 +++
 5 files changed, 81 insertions(+), 24 deletions(-)

diff --git 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
index 026e7183ab27a0..f2c1b626bd46f7 100644
--- 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
+++ 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
@@ -7,7 +7,7 @@
 namespace std {
 namespace __lldb {
 
-// Post-c88580c layout
+#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
 struct __value_init_tag {};
 struct __default_init_tag {};
 
@@ -52,6 +52,38 @@ class __compressed_pair : private 
__compressed_pair_elem<_T1, 0>,
 
   _T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
 };
+#elif COMPRESSED_PAIR_REV == 1
+template  class __compressed_pair_padding {
+  char __padding_[(is_empty<_ToPad>::value && 
!__libcpp_is_final<_ToPad>::value)
+  ? 0
+  : sizeof(_ToPad) - __datasizeof(_ToPad)];
+};
+
+#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)  
\
+  [[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; 
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_;
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3,
\
+Initializer3)  
\
+  [[using __gnu__: __aligned__(alignof(T2)),   
\
+__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1;  
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_; 
\
+  [[no_unique_address]] T3 Initializer3;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding3_;
+#elif COMPRESSED_PAIR_REV == 2
+#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2)
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3)   
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2;  
\
+  [[no_unique_address]] T3 Name3
+#endif
 } // namespace __lldb
 } // namespace std
 
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 98d2c7320003e4..afe6374e55a355 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
@@ -28,12 +28,13 @@ def _run_test(self, defines):
 
 for v in [None, "ALTERNATE_LAYOUT"]:
 for r in range(5):
-name = "test_r%d" % r
-defines = ["REVISION=%d" % r]
-if v:
-name += "_" + v
-defines += [v]
-f = functools.partialmethod(
-LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
-)
-setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
+for c in range(3):
+name = "test_r%d_c%d" % (r, c)
+defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
+if v:
+name += "_" + v
+defines += [v]
+f = functools.partialmethod(
+LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
+)
+setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/

[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Michael Buch via lldb-commits


@@ -3828,10 +3828,8 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 break;
 
   default:
-GetObjectFile()->GetModule()->ReportError(
-"didn't find appropriate parent DIE for variable list for {0:x8} "
-"{1} ({2}).\n",
-die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
+LLDB_LOG(GetLog(DWARFLog::Lookups),
+ "DIE {0:x8} is not a global variable - ignoring", die.GetID());

Michael137 wrote:

Nit: should we include the name/tag too? I could see it being useful

https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 approved this pull request.


https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Michael Buch via lldb-commits

Michael137 wrote:

Ahh thanks for the clarification. Makes sense.

Sounds like a situation where this would arise is:
```
struct Foo {
  static int bar;
};

int Foo::bar = 5;

int main() {
  static bool bar = false
  __builtin_debugtrap();
}
```

Doing `(lldb) target var bar` would produce this error. Which I agree doesn't 
seem right.

I guess the alternative would be to suppress the error message only if the 
parent is a `DW_TAG_subprogram`. But that wouldn't really be a complete check 
either since local variables wouldn't be distinguishable.

So LGTM.

https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-16 Thread Pavel Labath via lldb-commits


@@ -1364,8 +1364,14 @@ void request_evaluate(const llvm::json::Object &request) 
{
   std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
 
-  if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
-   ExpressionContext::Command) {
+  if (context == "repl" &&
+  (expression.empty() ?
+   g_dap.last_nonempty_var_expression.empty() :
+   g_dap.DetectExpressionContext(frame, expression) ==

labath wrote:

.. but note that the work that DetectExpressionContext does (looking up local 
variables) is relatively expensive, so we probably don't want to do it when 
it's not needed (when `context!="repl"`). 

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Pavel Labath via lldb-commits

labath wrote:

One more clarification :P

I think it would be reasonable for something like `target variable foo()::v` to 
return the static variable `v` in function `foo()`, and to make that work we 
might (depending on how exactly this is implemented) need to insert the 
variable into the manual index as well. However, we don't support such queries 
right now.

https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Pavel Labath via lldb-commits

labath wrote:

Adding these to the manual index is very easy -- there just isn't a point in 
doing it (except maybe for consistency).

In case I wasn't clear: this warning/error appears in the compiler-generated 
indexes, because we find the variable in the name lookup -- and then ignore it.
For the manual index, the variable is simply not found, so there's nothing to 
ignore or warn about.

https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 9548dbe - [lldb][test] Add TestNoUniqueAddress.py

2024-09-16 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2024-09-16T12:05:00+01:00
New Revision: 9548dbedbc1b2bfb130c91df54e8007acb81e1b0

URL: 
https://github.com/llvm/llvm-project/commit/9548dbedbc1b2bfb130c91df54e8007acb81e1b0
DIFF: 
https://github.com/llvm/llvm-project/commit/9548dbedbc1b2bfb130c91df54e8007acb81e1b0.diff

LOG: [lldb][test] Add TestNoUniqueAddress.py

Tests that run expressions on record types with
`[[no_unique_address]]` fields.

Added: 
lldb/test/API/lang/cpp/no_unique_address/Makefile
lldb/test/API/lang/cpp/no_unique_address/TestNoUniqueAddress.py
lldb/test/API/lang/cpp/no_unique_address/main.cpp

Modified: 


Removed: 




diff  --git a/lldb/test/API/lang/cpp/no_unique_address/Makefile 
b/lldb/test/API/lang/cpp/no_unique_address/Makefile
new file mode 100644
index 00..8b20bcb050
--- /dev/null
+++ b/lldb/test/API/lang/cpp/no_unique_address/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git a/lldb/test/API/lang/cpp/no_unique_address/TestNoUniqueAddress.py 
b/lldb/test/API/lang/cpp/no_unique_address/TestNoUniqueAddress.py
new file mode 100644
index 00..d16aaa14153fd7
--- /dev/null
+++ b/lldb/test/API/lang/cpp/no_unique_address/TestNoUniqueAddress.py
@@ -0,0 +1,67 @@
+"""
+Test that LLDB correctly handles fields
+marked with [[no_unique_address]].
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class NoUniqueAddressTestCase(TestBase):
+def test(self):
+self.build()
+lldbutil.run_to_source_breakpoint(
+self, "return 0", lldb.SBFileSpec("main.cpp", False)
+)
+
+# Qualified/unqualified lookup to templates in namespace
+self.expect_expr(
+"b1",
+result_type="basic::Foo",
+result_children=[ValueCheck(name="a", type="Empty")],
+)
+
+self.expect_expr(
+"b2",
+result_type="bases::Foo",
+result_children=[
+ValueCheck(
+type="bases::B", children=[ValueCheck(name="x", 
type="Empty")]
+),
+ValueCheck(
+type="bases::A",
+children=[
+ValueCheck(name="c", type="long", value="1"),
+ValueCheck(name="d", type="long", value="2"),
+],
+),
+ValueCheck(
+type="bases::C", children=[ValueCheck(name="x", 
type="Empty")]
+),
+],
+)
+self.expect_expr(
+"b3",
+result_type="bases::Bar",
+result_children=[
+ValueCheck(
+type="bases::B", children=[ValueCheck(name="x", 
type="Empty")]
+),
+ValueCheck(
+type="bases::C", children=[ValueCheck(name="x", 
type="Empty")]
+),
+ValueCheck(
+type="bases::A",
+children=[
+ValueCheck(name="c", type="long", value="5"),
+ValueCheck(name="d", type="long", value="6"),
+],
+),
+],
+)
+
+self.expect("frame var b1")
+self.expect("frame var b2")
+self.expect("frame var b3")

diff  --git a/lldb/test/API/lang/cpp/no_unique_address/main.cpp 
b/lldb/test/API/lang/cpp/no_unique_address/main.cpp
new file mode 100644
index 00..424fa90859ceaa
--- /dev/null
+++ b/lldb/test/API/lang/cpp/no_unique_address/main.cpp
@@ -0,0 +1,35 @@
+struct Empty {};
+
+namespace basic {
+struct Foo {
+  [[no_unique_address]] Empty a;
+};
+} // namespace basic
+
+namespace bases {
+struct A {
+  long c, d;
+};
+
+struct B {
+  [[no_unique_address]] Empty x;
+};
+
+struct C {
+  [[no_unique_address]] Empty x;
+};
+
+struct Foo : B, A, C {};
+struct Bar : B, C, A {};
+} // namespace bases
+
+int main() {
+  basic::Foo b1;
+  bases::Foo b2;
+  bases::Bar b3;
+  b2.c = 1;
+  b2.d = 2;
+  b3.c = 5;
+  b3.d = 6;
+  return 0;
+}



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/99012

>From 8d0245dfccc607a4237fc94bbbfea646fa1a6887 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 10 Jul 2024 15:37:45 +0100
Subject: [PATCH 1/4] [WIP][lldb][test] Add a new __compressed_pair layout to
 libcxx simulator tests

---
 .../compressed_pair.h | 34 ++-
 .../TestDataFormatterLibcxxStringSimulator.py | 19 ++-
 .../libcxx-simulators/string/main.cpp | 33 +++---
 ...stDataFormatterLibcxxUniquePtrSimulator.py | 14 ++--
 .../libcxx-simulators/unique_ptr/main.cpp |  5 +++
 5 files changed, 81 insertions(+), 24 deletions(-)

diff --git 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
index 026e7183ab27a0..f2c1b626bd46f7 100644
--- 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
+++ 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
@@ -7,7 +7,7 @@
 namespace std {
 namespace __lldb {
 
-// Post-c88580c layout
+#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
 struct __value_init_tag {};
 struct __default_init_tag {};
 
@@ -52,6 +52,38 @@ class __compressed_pair : private 
__compressed_pair_elem<_T1, 0>,
 
   _T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
 };
+#elif COMPRESSED_PAIR_REV == 1
+template  class __compressed_pair_padding {
+  char __padding_[(is_empty<_ToPad>::value && 
!__libcpp_is_final<_ToPad>::value)
+  ? 0
+  : sizeof(_ToPad) - __datasizeof(_ToPad)];
+};
+
+#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)  
\
+  [[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; 
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_;
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3,
\
+Initializer3)  
\
+  [[using __gnu__: __aligned__(alignof(T2)),   
\
+__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1;  
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_; 
\
+  [[no_unique_address]] T3 Initializer3;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding3_;
+#elif COMPRESSED_PAIR_REV == 2
+#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2)
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3)   
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2;  
\
+  [[no_unique_address]] T3 Name3
+#endif
 } // namespace __lldb
 } // namespace std
 
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 98d2c7320003e4..afe6374e55a355 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
@@ -28,12 +28,13 @@ def _run_test(self, defines):
 
 for v in [None, "ALTERNATE_LAYOUT"]:
 for r in range(5):
-name = "test_r%d" % r
-defines = ["REVISION=%d" % r]
-if v:
-name += "_" + v
-defines += [v]
-f = functools.partialmethod(
-LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
-)
-setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
+for c in range(3):
+name = "test_r%d_c%d" % (r, c)
+defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
+if v:
+name += "_" + v
+defines += [v]
+f = functools.partialmethod(
+LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
+)
+setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/

[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 commented:

Seems reasonable to make this less spammy. Though is there a reason why we're 
not adding them to the manual index? Is this just something we didn't implement 
(yet)?

https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread Michael Buch via lldb-commits


@@ -124,6 +124,9 @@ class ABISysV_riscv : public lldb_private::RegInfoBasedABI {
   using lldb_private::RegInfoBasedABI::RegInfoBasedABI; // Call CreateInstance
 // instead.
   bool m_is_rv64; // true if target is riscv64; false if target is riscv32
+  static constexpr size_t s_regs_for_args_count =

Michael137 wrote:

yup i think that would be preferable

https://github.com/llvm/llvm-project/pull/99336
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][intel-pt] Fix build error on conversion from llvm::Error to Status::FromError (PR #108719)

2024-09-16 Thread Sylvestre Ledru via lldb-commits

https://github.com/sylvestre edited 
https://github.com/llvm/llvm-project/pull/108719
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread via lldb-commits


@@ -164,11 +167,82 @@ TotalArgsSizeInWords(bool is_rv64,
   return total_size;
 }
 
+static bool UpdateRegister(RegisterContext *reg_ctx,
+   const lldb::RegisterKind reg_kind,
+   const uint32_t reg_num, const addr_t value) {
+  Log *log = GetLog(LLDBLog::Expressions);
+
+  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(reg_kind, reg_num);
+
+  LLDB_LOG(log, "Writing {0}: 0x{1:x}", reg_info->name,
+   static_cast(value));
+  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, value)) {
+LLDB_LOG(log, "Writing {0}: failed", reg_info->name);
+return false;
+  }
+  return true;
+}
+
+static void LogInitInfo(Log *log, const Thread &thread, addr_t sp,
+addr_t func_addr, addr_t return_addr,
+const llvm::ArrayRef args) {
+  assert(log);
+  std::stringstream ss;
+  ss << "ABISysV_riscv::PrepareTrivialCall"
+ << " (tid = 0x" << std::hex << thread.GetID() << ", sp = 0x" << sp
+ << ", func_addr = 0x" << func_addr << ", return_addr = 0x" << return_addr;
+
+  for (auto &&[idx, arg] : enumerate(args))
+ss << ", arg" << std::dec << idx << " = 0x" << std::hex << arg;
+  ss << ")";
+  log->PutString(ss.str());
+}
+
 bool ABISysV_riscv::PrepareTrivialCall(Thread &thread, addr_t sp,
addr_t func_addr, addr_t return_addr,
llvm::ArrayRef args) const {
-  // TODO: Implement
-  return false;
+  Log *log = GetLog(LLDBLog::Expressions);
+  if (log)
+LogInitInfo(log, thread, sp, func_addr, return_addr, args);
+
+  const auto reg_ctx_sp = thread.GetRegisterContext();
+  if (!reg_ctx_sp) {
+LLDB_LOG(log, "Failed to get RegisterContext");
+return false;
+  }
+
+  if (args.size() > s_regs_for_args_count) {
+LLDB_LOG(log, "Function has {0} arguments, but only {1} are allowed!",
+ args.size(), s_regs_for_args_count);
+return false;
+  }
+
+  // Write arguments to registers
+  for (auto &&[idx, arg] : enumerate(args)) {

dlav-sc wrote:

addressed

https://github.com/llvm/llvm-project/pull/99336
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread via lldb-commits


@@ -164,11 +167,82 @@ TotalArgsSizeInWords(bool is_rv64,
   return total_size;
 }
 
+static bool UpdateRegister(RegisterContext *reg_ctx,
+   const lldb::RegisterKind reg_kind,
+   const uint32_t reg_num, const addr_t value) {
+  Log *log = GetLog(LLDBLog::Expressions);
+
+  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(reg_kind, reg_num);
+
+  LLDB_LOG(log, "Writing {0}: 0x{1:x}", reg_info->name,
+   static_cast(value));
+  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, value)) {
+LLDB_LOG(log, "Writing {0}: failed", reg_info->name);
+return false;
+  }
+  return true;
+}
+
+static void LogInitInfo(Log *log, const Thread &thread, addr_t sp,

dlav-sc wrote:

addressed

https://github.com/llvm/llvm-project/pull/99336
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread via lldb-commits

https://github.com/dlav-sc updated 
https://github.com/llvm/llvm-project/pull/99336

>From 10d7addd0a86789e268189e00a825af27516323e Mon Sep 17 00:00:00 2001
From: Daniil Avdeev 
Date: Thu, 11 Jul 2024 11:21:36 +
Subject: [PATCH 1/5] [lldb][RISCV] add jitted function calls to ABI

Function calls support in LLDB expressions for RISCV: 1 of 5

Augments corresponding functionality to RISCV ABI, which allows to jit
lldb expressions and thus make function calls inside them. Only function
calls with integer and void function arguments and return value are
supported.
---
 .../Plugins/ABI/RISCV/ABISysV_riscv.cpp   | 87 +--
 lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.h |  3 +
 2 files changed, 83 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp 
b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
index de304183f67175..24468838cbb821 100644
--- a/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
+++ b/lldb/source/Plugins/ABI/RISCV/ABISysV_riscv.cpp
@@ -10,7 +10,9 @@
 
 #include 
 #include 
+#include 
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/IR/DerivedTypes.h"
 
 #include "Utility/RISCV_DWARF_Registers.h"
@@ -20,6 +22,7 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Thread.h"
+#include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #define DEFINE_REG_NAME(reg_num) ConstString(#reg_num).GetCString()
@@ -164,11 +167,81 @@ TotalArgsSizeInWords(bool is_rv64,
   return total_size;
 }
 
+static bool UpdateRegister(RegisterContext *reg_ctx,
+   const lldb::RegisterKind reg_kind,
+   const uint32_t reg_num, const addr_t value) {
+  Log *log = GetLog(LLDBLog::Expressions);
+
+  const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo(reg_kind, reg_num);
+
+  LLDB_LOG(log, "Writing {0}: 0x{1:x}", reg_info->name,
+   static_cast(value));
+  if (!reg_ctx->WriteRegisterFromUnsigned(reg_info, value)) {
+LLDB_LOG(log, "Writing {0}: failed", reg_info->name);
+return false;
+  }
+  return true;
+}
+
+static void LogInitInfo(Log &log, const Thread &thread, addr_t sp,
+addr_t func_addr, addr_t return_addr,
+const llvm::ArrayRef args) {
+  std::stringstream ss;
+  ss << "ABISysV_riscv::PrepareTrivialCall"
+ << " (tid = 0x" << std::hex << thread.GetID() << ", sp = 0x" << sp
+ << ", func_addr = 0x" << func_addr << ", return_addr = 0x" << return_addr;
+
+  for (auto [idx, arg] : enumerate(args))
+ss << ", arg" << std::dec << idx << " = 0x" << std::hex << arg;
+  ss << ")";
+  log.PutString(ss.str());
+}
+
 bool ABISysV_riscv::PrepareTrivialCall(Thread &thread, addr_t sp,
addr_t func_addr, addr_t return_addr,
llvm::ArrayRef args) const {
-  // TODO: Implement
-  return false;
+  Log *log = GetLog(LLDBLog::Expressions);
+  if (log)
+LogInitInfo(*log, thread, sp, func_addr, return_addr, args);
+
+  const auto reg_ctx_sp = thread.GetRegisterContext();
+  if (!reg_ctx_sp) {
+LLDB_LOG(log, "Failed to get RegisterContext");
+return false;
+  }
+
+  if (args.size() > s_regs_for_args_count) {
+LLDB_LOG(log, "Function has {0} arguments, but only {1} are allowed!",
+ args.size(), s_regs_for_args_count);
+return false;
+  }
+
+  // Write arguments to registers
+  for (auto [idx, arg] : enumerate(args)) {
+const RegisterInfo *reg_info = reg_ctx_sp->GetRegisterInfo(
+eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + idx);
+LLDB_LOG(log, "About to write arg{0} (0x{1:x}) into {2}", idx, arg,
+ reg_info->name);
+
+if (!reg_ctx_sp->WriteRegisterFromUnsigned(reg_info, arg)) {
+  LLDB_LOG(log, "Failed to write arg{0} (0x{1:x}) into {2}", idx, arg,
+   reg_info->name);
+  return false;
+}
+  }
+
+  if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,
+  LLDB_REGNUM_GENERIC_PC, func_addr))
+return false;
+  if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,
+  LLDB_REGNUM_GENERIC_SP, sp))
+return false;
+  if (!UpdateRegister(reg_ctx_sp.get(), eRegisterKindGeneric,
+  LLDB_REGNUM_GENERIC_RA, return_addr))
+return false;
+
+  LLDB_LOG(log, "ABISysV_riscv::{0}() success", __FUNCTION__);
+  return true;
 }
 
 bool ABISysV_riscv::PrepareTrivialCall(
@@ -222,14 +295,14 @@ bool ABISysV_riscv::PrepareTrivialCall(
   assert(prototype.getFunctionNumParams() == args.size());
 
   const size_t num_args = args.size();
-  const size_t regs_for_args_count = 8U;
   const size_t num_args_in_regs =
-  num_args > regs_for_args_count ?  regs_for_args_count : num_args;
+  num_args > s_regs_for_args_count ? s_regs_for_args_count : num_args;
 
   // Number of arguments passed on stack.
   size_t args_size = TotalArgsSizeInWords(m_is_rv64, args);
-  auto

[Lldb-commits] [lldb] [llvm] [lldb][RISCV] function calls support in lldb expressions (PR #99336)

2024-09-16 Thread via lldb-commits


@@ -124,6 +124,9 @@ class ABISysV_riscv : public lldb_private::RegInfoBasedABI {
   using lldb_private::RegInfoBasedABI::RegInfoBasedABI; // Call CreateInstance
 // instead.
   bool m_is_rv64; // true if target is riscv64; false if target is riscv32
+  static constexpr size_t s_regs_for_args_count =

dlav-sc wrote:

I use `s_regs_for_args_count` in 2 different `ABISysV_riscv` methods, so I've 
decided to place it here. Maybe I can create a static global value in 
`ABISysV_riscv.cpp` instead.

https://github.com/llvm/llvm-project/pull/99336
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Cache negative results of variable parsing (PR #108810)

2024-09-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

Use a `nullptr` map entry to mean "variable parse was attempted and it failed" 
an the absence of an entry to mean "parsing hasn't been attempted yet".

I ran into this because parsing of function-static variables was generating a 
lot of errors (see #108806), but this seems like a good idea in general.

In theory this should be NFC, except for possibly reducing some amount of work.

---
Full diff: https://github.com/llvm/llvm-project/pull/108810.diff


1 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+12-14) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..bacea848988467 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3377,16 +3377,13 @@ VariableSP 
SymbolFileDWARF::ParseVariableDIECached(const SymbolContext &sc,
 
   DIEToVariableSP &die_to_variable = die.GetDWARF()->GetDIEToVariable();
 
-  VariableSP var_sp = die_to_variable[die.GetDIE()];
-  if (var_sp)
-return var_sp;
-
-  var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
-  if (var_sp) {
-die_to_variable[die.GetDIE()] = var_sp;
-if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
-  die_to_variable[spec_die.GetDIE()] = var_sp;
-  }
+  if (auto it = die_to_variable.find(die.GetDIE()); it != 
die_to_variable.end())
+return it->second;
+
+  VariableSP var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
+  die_to_variable.insert_or_assign(die.GetDIE(), var_sp);
+  if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
+die_to_variable.insert_or_assign(spec_die.GetDIE(), var_sp);
   return var_sp;
 }
 
@@ -3799,9 +3796,10 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 return;
 
   // Check to see if we have already parsed this variable or constant?
-  VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
-  if (var_sp) {
-cc_variable_list.AddVariableIfUnique(var_sp);
+  DIEToVariableSP &die_to_variable = GetDIEToVariable();
+  if (auto it = die_to_variable.find(die.GetDIE());
+  it != die_to_variable.end()) {
+cc_variable_list.AddVariableIfUnique(it->second);
 return;
   }
 
@@ -3835,7 +3833,7 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 return;
   }
 
-  var_sp = ParseVariableDIECached(sc, die);
+  VariableSP var_sp = ParseVariableDIECached(sc, die);
   if (!var_sp)
 return;
 

``




https://github.com/llvm/llvm-project/pull/108810
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Cache negative results of variable parsing (PR #108810)

2024-09-16 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/108810

Use a `nullptr` map entry to mean "variable parse was attempted and it failed" 
an the absence of an entry to mean "parsing hasn't been attempted yet".

I ran into this because parsing of function-static variables was generating a 
lot of errors (see #108806), but this seems like a good idea in general.

In theory this should be NFC, except for possibly reducing some amount of work.

>From fddb89e718e3bc96ce5e051ce9a8e63f37ce5a25 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 16 Sep 2024 11:46:05 +0200
Subject: [PATCH] [lldb/DWARF] Cache negative results of variable parsing

Use a `nullptr` map entry to mean "variable parse was attempted and it
failed" an the absence of an entry to mean "parsing hasn't been
attempted yet".

I ran into this because parsing of function-static variables was
generating a lot of errors (see #108806), but this seems like a good
idea in general.

In theory this should be NFC, except for possibly reducing some amount
of work.
---
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 26 +--
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..bacea848988467 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3377,16 +3377,13 @@ VariableSP 
SymbolFileDWARF::ParseVariableDIECached(const SymbolContext &sc,
 
   DIEToVariableSP &die_to_variable = die.GetDWARF()->GetDIEToVariable();
 
-  VariableSP var_sp = die_to_variable[die.GetDIE()];
-  if (var_sp)
-return var_sp;
-
-  var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
-  if (var_sp) {
-die_to_variable[die.GetDIE()] = var_sp;
-if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
-  die_to_variable[spec_die.GetDIE()] = var_sp;
-  }
+  if (auto it = die_to_variable.find(die.GetDIE()); it != 
die_to_variable.end())
+return it->second;
+
+  VariableSP var_sp = ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS);
+  die_to_variable.insert_or_assign(die.GetDIE(), var_sp);
+  if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification))
+die_to_variable.insert_or_assign(spec_die.GetDIE(), var_sp);
   return var_sp;
 }
 
@@ -3799,9 +3796,10 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 return;
 
   // Check to see if we have already parsed this variable or constant?
-  VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
-  if (var_sp) {
-cc_variable_list.AddVariableIfUnique(var_sp);
+  DIEToVariableSP &die_to_variable = GetDIEToVariable();
+  if (auto it = die_to_variable.find(die.GetDIE());
+  it != die_to_variable.end()) {
+cc_variable_list.AddVariableIfUnique(it->second);
 return;
   }
 
@@ -3835,7 +3833,7 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 return;
   }
 
-  var_sp = ParseVariableDIECached(sc, die);
+  VariableSP var_sp = ParseVariableDIECached(sc, die);
   if (!var_sp)
 return;
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

This can legitimately happen for static function-local variables with a 
non-manual dwarf index. According to the DWARF spec, these variables should be 
(and are) included in the compiler generated indexes, but they are ignored by 
our manual index. Encountering them does not indicate any sort of error.

The error message is particularly annoying due to a combination of the fact 
that we don't cache negative hits (so we print it every time we encounter it), 
VSCode's aggresive tab completion (which attempts a lookup after every 
keypress) and the fact that some low-level libraries (e.g. tcmalloc) have 
several local variables called "v". The result is a console full of error 
messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that these 
variables are not included in the result (and by extension, that their presence 
does not crash lldb). It would be possible to extend it to make sure it does 
*not* print this error message, but it doesn't seem like it would be 
particularly useful.

---
Full diff: https://github.com/llvm/llvm-project/pull/108806.diff


1 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+2-4) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..082c437321e38b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3828,10 +3828,8 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 break;
 
   default:
-GetObjectFile()->GetModule()->ReportError(
-"didn't find appropriate parent DIE for variable list for {0:x8} "
-"{1} ({2}).\n",
-die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
+LLDB_LOG(GetLog(DWARFLog::Lookups),
+ "DIE {0:x8} is not a global variable - ignoring", die.GetID());
 return;
   }
 

``




https://github.com/llvm/llvm-project/pull/108806
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb/DWARF] Downgrade the "parent of variable is not CU" error (PR #108806)

2024-09-16 Thread Pavel Labath via lldb-commits

https://github.com/labath created 
https://github.com/llvm/llvm-project/pull/108806

This can legitimately happen for static function-local variables with a 
non-manual dwarf index. According to the DWARF spec, these variables should be 
(and are) included in the compiler generated indexes, but they are ignored by 
our manual index. Encountering them does not indicate any sort of error.

The error message is particularly annoying due to a combination of the fact 
that we don't cache negative hits (so we print it every time we encounter it), 
VSCode's aggresive tab completion (which attempts a lookup after every 
keypress) and the fact that some low-level libraries (e.g. tcmalloc) have 
several local variables called "v". The result is a console full of error 
messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that these 
variables are not included in the result (and by extension, that their presence 
does not crash lldb). It would be possible to extend it to make sure it does 
*not* print this error message, but it doesn't seem like it would be 
particularly useful.

>From baea580cd620065bbe0f4e653bfbd5316e7f63ee Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 16 Sep 2024 10:52:00 +0200
Subject: [PATCH] [lldb/DWARF] Downgrade the "parent of variable is not CU"
 error

This can legitimately happen for static function-local variables with a
non-manual dwarf index. According to the DWARF spec, these variables
should be (and are) included in the compiler generated indexes, but they
are ignored by our manual index. Encountering them does not indicate any
sort of error.

The error message is particularly annoying due to a combination of the
fact that we don't cache negative hits (so we print it every time we
encounter it), VSCode's aggresive tab completion (which attempts a
lookup after every keypress) and the fact that some low-level libraries
(e.g. tcmalloc) have several local variables called "v". The result is a
console full of error messages everytime you type "v ".

We already have tests (e.g. find-basic-variable.cpp), which check that
these variables are not included in the result (and by extension, that
their presence does not crash lldb). It would be possible to extend it
to make sure it does *not* print this error message, but it doesn't seem
like it would be particularly useful.
---
 lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index f721ca00fd3559..082c437321e38b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3828,10 +3828,8 @@ void SymbolFileDWARF::ParseAndAppendGlobalVariable(
 break;
 
   default:
-GetObjectFile()->GetModule()->ReportError(
-"didn't find appropriate parent DIE for variable list for {0:x8} "
-"{1} ({2}).\n",
-die.GetID(), DW_TAG_value_to_name(die.Tag()), die.Tag());
+LLDB_LOG(GetLog(DWARFLog::Lookups),
+ "DIE {0:x8} is not a global variable - ignoring", die.GetID());
 return;
   }
 

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/108629
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 7e5fe3e - [lldb][test] Remove benchmark API tests (#108629)

2024-09-16 Thread via lldb-commits

Author: Michael Buch
Date: 2024-09-16T10:15:52+01:00
New Revision: 7e5fe3ec5aed001c3b8f0bf59167b6472b91b9cc

URL: 
https://github.com/llvm/llvm-project/commit/7e5fe3ec5aed001c3b8f0bf59167b6472b91b9cc
DIFF: 
https://github.com/llvm/llvm-project/commit/7e5fe3ec5aed001c3b8f0bf59167b6472b91b9cc.diff

LOG: [lldb][test] Remove benchmark API tests (#108629)

These benchmarks don't get run as part of the regular API test-suite.
And I'm not aware of any CI running this. Also, I haven't quite managed
to actually run them locally using the `bench.py` script. It looks like
these are obsolete, so I'm proposing to remove the infrastructure around
it entirely.

If anyone does know of a use for these do let me know.

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/decorators.py

Removed: 
lldb/packages/Python/lldbsuite/test/bench.py
lldb/test/API/benchmarks/continue/Makefile
lldb/test/API/benchmarks/continue/TestBenchmarkContinue.py
lldb/test/API/benchmarks/continue/main.cpp
lldb/test/API/benchmarks/expression/Makefile
lldb/test/API/benchmarks/expression/TestExpressionCmd.py
lldb/test/API/benchmarks/expression/TestRepeatedExprs.py
lldb/test/API/benchmarks/expression/main.cpp
lldb/test/API/benchmarks/frame_variable/TestFrameVariableResponse.py
lldb/test/API/benchmarks/libcxxlist/Makefile
lldb/test/API/benchmarks/libcxxlist/TestBenchmarkLibcxxList.py
lldb/test/API/benchmarks/libcxxlist/main.cpp
lldb/test/API/benchmarks/libcxxmap/Makefile
lldb/test/API/benchmarks/libcxxmap/TestBenchmarkLibcxxMap.py
lldb/test/API/benchmarks/libcxxmap/main.cpp
lldb/test/API/benchmarks/startup/TestStartupDelays.py
lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
lldb/test/API/benchmarks/turnaround/TestCompileRunToBreakpointTurnaround.py



diff  --git a/lldb/packages/Python/lldbsuite/test/bench.py 
b/lldb/packages/Python/lldbsuite/test/bench.py
deleted file mode 100644
index 1a11b3ef4f0e64..00
--- a/lldb/packages/Python/lldbsuite/test/bench.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-
-"""
-A simple bench runner which delegates to the ./dotest.py test driver to run the
-benchmarks defined in the list named 'benches'.
-
-You need to hand edit 'benches' to modify/change the command lines passed to 
the
-test driver.
-
-Use the following to get only the benchmark results in your terminal output:
-
-./bench.py -e /Volumes/data/lldb/svn/regression/build/Debug/lldb -x '-F 
Driver::MainLoop()' 2>&1 | grep -P '^lldb.*benchmark:'
-"""
-
-import os
-from optparse import OptionParser
-
-# dotest.py invocation with no '-e exe-path' uses lldb as the inferior program,
-# unless there is a mentioning of custom executable program.
-benches = [
-# Measure startup delays creating a target, setting a breakpoint, and run
-# to breakpoint stop.
-"./dotest.py -v +b %E %X -n -p TestStartupDelays.py",
-# Measure 'frame variable' response after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestFrameVariableResponse.py",
-# Measure stepping speed after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestSteppingSpeed.py",
-# Measure expression cmd response with a simple custom executable program.
-"./dotest.py +b -n -p TestExpressionCmd.py",
-# Attach to a spawned process then run disassembly benchmarks.
-"./dotest.py -v +b -n %E -p TestDoAttachThenDisassembly.py",
-]
-
-
-def main():
-"""Read the items from 'benches' and run the command line one by one."""
-parser = OptionParser(
-usage="""\
-%prog [options]
-Run the standard benchmarks defined in the list named 'benches'.\
-"""
-)
-parser.add_option(
-"-e",
-"--executable",
-type="string",
-action="store",
-dest="exe",
-help="The target program launched by lldb.",
-)
-parser.add_option(
-"-x",
-"--breakpoint-spec",
-type="string",
-action="store",
-dest="break_spec",
-help="The lldb breakpoint spec for the target program.",
-)
-
-# Parses the options, if any.
-opts, args = parser.parse_args()
-
-print("Starting bench runner")
-
-for item in benches:
-command = item.replace("%E", '-e "%s"' % opts.exe if opts.exe else "")
-command = command.replace(
-"%X", '-x "%s"' % opts.break_spec if opts.break_spec else ""
-)
-print("Running %s" % (command))
-os.system(command)
-
-print("Bench runner done.")
-
-
-if __name__ == "__main__":
-main()

diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py 
b/lldb/packages/Python/lldbsuite/test/decorators.py
index 834f01aaa61e6b..34319e203a3177 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -426,18 +426,6 @@ def impl(func):
 

[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/96538
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 9e9b117 - [lldb] Support new libc++ __compressed_pair layout (#96538)

2024-09-16 Thread via lldb-commits

Author: Michael Buch
Date: 2024-09-16T10:11:49+01:00
New Revision: 9e9b1178ca435f690381ffe8241e4bf1bb7e60fb

URL: 
https://github.com/llvm/llvm-project/commit/9e9b1178ca435f690381ffe8241e4bf1bb7e60fb
DIFF: 
https://github.com/llvm/llvm-project/commit/9e9b1178ca435f690381ffe8241e4bf1bb7e60fb.diff

LOG: [lldb] Support new libc++ __compressed_pair layout (#96538)

This patch is in preparation for the `__compressed_pair` refactor in
https://github.com/llvm/llvm-project/pull/76756.

This is mostly reviewable now. With the new layout we no longer need to
unwrap the `__compressed_pair`. Instead, we just need to look for child
members. E.g., to get to the underlying pointer of `std::unique_ptr` we
no longer do,
```
GetFirstValueOfCXXCompressedPair(GetChildMemberWithName("__ptr_"))

```
but instead do
```
GetChildMemberWithName("__ptr_")
```

We need to be slightly careful because previously the
`__compressed_pair` had a member called `__value_`, whereas now
`__value_` might be a member of the class that used to hold the
`__compressed_pair`. So before unwrapping the pair, we added checks for
`isOldCompressedLayout` (not sure yet whether folding this check into
`GetFirstValueOfCXXCompressedPair` is better).

Added: 


Modified: 
lldb/examples/synthetic/libcxx.py
lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxx.h
lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxVector.cpp

lldb/test/API/functionalities/data-formatter/data-formatter-stl/generic/list/TestDataFormatterGenericList.py

Removed: 




diff  --git a/lldb/examples/synthetic/libcxx.py 
b/lldb/examples/synthetic/libcxx.py
index 474aaa428fa23a..b078a4eb2f6394 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair):
 def update(self):
 logger = lldb.formatters.Logger.Logger()
 try:
+has_compressed_pair_layout = True
+alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_")
+size_valobj = self.valobj.GetChildMemberWithName("__size_")
+if alloc_valobj.IsValid() and size_valobj.IsValid():
+has_compressed_pair_layout = False
+
 # A deque is effectively a two-dim array, with fixed width.
 # 'map' contains pointers to the rows of this array. The
 # full memory area allocated by the deque is delimited
@@ -734,9 +740,13 @@ def update(self):
 # variable tells which element in this NxM array is the 0th
 # one, and the 'size' element gives the number of elements
 # in the deque.
-count = self._get_value_of_compressed_pair(
-self.valobj.GetChildMemberWithName("__size_")
-)
+if has_compressed_pair_layout:
+count = self._get_value_of_compressed_pair(
+self.valobj.GetChildMemberWithName("__size_")
+)
+else:
+count = size_valobj.GetValueAsUnsigned(0)
+
 # give up now if we cant access memory reliably
 if self.block_size < 0:
 logger.write("block_size < 0")
@@ -748,9 +758,15 @@ def update(self):
 self.map_begin = map_.GetChildMemberWithName("__begin_")
 map_begin = self.map_begin.GetValueAsUnsigned(0)
 map_end = 
map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0)
-map_endcap = self._get_value_of_compressed_pair(
-map_.GetChildMemberWithName("__end_cap_")
-)
+
+if has_compressed_pair_layout:
+map_endcap = self._get_value_of_compressed_pair(
+map_.GetChildMemberWithName("__end_cap_")
+)
+else:
+map_endcap = map_.GetChildMemberWithName(
+"__end_cap_"
+).GetValueAsUnsigned(0)
 
 # check consistency
 if not map_first <= map_begin <= map_end <= map_endcap:

diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index feaa51a96843ab..7d3b2410a7296e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -27,6 +27,7 @@
 #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
 #include 
 #include 
 
@@ -34,6 +35,32 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+static void consumeInlineNamespace(

[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)

2024-09-16 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/96538

>From 16ae2c3c04d908807d78224a8fee34f772a337fa Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 29 Jan 2024 16:23:16 +
Subject: [PATCH 1/4] [lldb] Support new libc++ __compressed_pair layout

---
 lldb/examples/synthetic/libcxx.py |  26 ++-
 .../Plugins/Language/CPlusPlus/LibCxx.cpp |  85 ++---
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   3 +-
 .../Plugins/Language/CPlusPlus/LibCxxList.cpp |  72 +---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  |  41 +++--
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++---
 .../Language/CPlusPlus/LibCxxVector.cpp   |  38 ++--
 .../list/TestDataFormatterGenericList.py  |   2 +-
 8 files changed, 282 insertions(+), 151 deletions(-)

diff --git a/lldb/examples/synthetic/libcxx.py 
b/lldb/examples/synthetic/libcxx.py
index 474aaa428fa23a..060ff901008497 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair):
 def update(self):
 logger = lldb.formatters.Logger.Logger()
 try:
+has_compressed_pair_layout = True
+alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_")
+size_valobj = self.valobj.GetChildMemberWithName("__size_")
+if alloc_valobj.IsValid() and size_valobj.IsValid():
+has_compressed_pair_layout = False
+
 # A deque is effectively a two-dim array, with fixed width.
 # 'map' contains pointers to the rows of this array. The
 # full memory area allocated by the deque is delimited
@@ -734,9 +740,13 @@ def update(self):
 # variable tells which element in this NxM array is the 0th
 # one, and the 'size' element gives the number of elements
 # in the deque.
-count = self._get_value_of_compressed_pair(
-self.valobj.GetChildMemberWithName("__size_")
-)
+if has_compressed_pair_layout:
+count = self._get_value_of_compressed_pair(
+self.valobj.GetChildMemberWithName("__size_")
+)
+else:
+count = size_valobj.GetValueAsUnsigned(0)
+
 # give up now if we cant access memory reliably
 if self.block_size < 0:
 logger.write("block_size < 0")
@@ -748,9 +758,13 @@ def update(self):
 self.map_begin = map_.GetChildMemberWithName("__begin_")
 map_begin = self.map_begin.GetValueAsUnsigned(0)
 map_end = 
map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0)
-map_endcap = self._get_value_of_compressed_pair(
-map_.GetChildMemberWithName("__end_cap_")
-)
+
+if has_compressed_pair_layout:
+map_endcap = self._get_value_of_compressed_pair(
+map_.GetChildMemberWithName("__end_cap_")
+)
+else:
+map_endcap = 
map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0)
 
 # check consistency
 if not map_first <= map_begin <= map_end <= map_endcap:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index feaa51a96843ab..7d3b2410a7296e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -27,6 +27,7 @@
 #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
 #include 
 #include 
 
@@ -34,6 +35,32 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+static void consumeInlineNamespace(llvm::StringRef &name) {
+  // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
+  auto scratch = name;
+  if (scratch.consume_front("__") && std::isalnum(scratch[0])) {
+scratch = scratch.drop_while([](char c) { return std::isalnum(c); });
+if (scratch.consume_front("::")) {
+  // Successfully consumed a namespace.
+  name = scratch;
+}
+  }
+}
+
+bool lldb_private::formatters::isOldCompressedPairLayout(
+ValueObject &pair_obj) {
+  return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair");
+}
+
+bool lldb_private::formatters::isStdTemplate(ConstString type_name,
+ llvm::StringRef type) {
+  llvm::StringRef name = type_name.GetStringRef();
+  // The type name may be prefixed with `std::__::`.
+  if (name.consume_front("std::"))
+consumeInlineNamespace(name);
+  return name.consume_front(type) && name.starts_with("<");
+}
+
 lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
 ValueObject &obj, llvm::ArrayRef alternative_nam

[Lldb-commits] [lldb] [lldb] Introduce an always-on system log category/channel (PR #108495)

2024-09-16 Thread Pavel Labath via lldb-commits

labath wrote:

> * Everyone (else) I talked to liked the idea of reusing the logging system 
> because that's what we already use and are familiar with. Promoting a log 
> message to be part of this log becomes as easy as adding a `GetLog` and using 
> the same macro.

I'm all for code reuse, and reusing some part of the logging machinery for this 
makes sense to me. The thing I'm not sure about is whether this is plugging 
into the machinery at the right level. The most irritating part is the 
`internal` flag -- like, we do all the motions to place the channel into the 
global log channel map (which is the source of truth for all user-facing log 
commands), but then set this flag which basically says "pretend this channel 
isn't here". 

I think this would look better if the flag wasn't there. Like, what if we had a 
separate way to create/register one of these "system" channels -- one which 
does not involve putting it in a list with all the other channels. Maybe the 
`Initialize` function could be something like:
```
Log g_system(g_system_channel);
g_system->Enable(...);
```
(The `Enable` function is currently private, but I think it would make sense to 
make it public, especially since it's possible (like you're effectively doing 
now) to bypass this restriction by calling the static string-based 
EnableLogChannel function. Alternatively, we could make the existence of this 
channel a feature of the generic log machinery (I expect we'll never want to 
have more than one of these), and then we can do this work from within 
`Log::Initialize`)

https://github.com/llvm/llvm-project/pull/108495
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-09-16 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

Actually, the CI failure appears to be relevant. The error path in the test is 
`errno->std::error_code->Status->Expected` and the code in `CheckIPSupport` 
expects to get a `llvm::ECError`.
It looks like it gets a different type now, and I think that's probably fine, 
but we should also relax the expectation there.

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-09-16 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.


https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-16 Thread Pavel Labath via lldb-commits

https://github.com/labath approved this pull request.

I believe these weren't functional for a very long time now.

https://github.com/llvm/llvm-project/pull/108629
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2024-09-15 Thread Vitaly Buka via lldb-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/106505
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2024-09-15 Thread Vitaly Buka via lldb-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/106505
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2024-09-15 Thread Vitaly Buka via lldb-commits

https://github.com/vitalybuka requested changes to this pull request.

I think it change the meaning completly.
I read "Coverage Sanitizer" as a tool which finds bugs in Coverage.
When "Sanitizer Coverage" as a coverage used by sanitizers.

https://github.com/llvm/llvm-project/pull/106505
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Youngsuk Kim via lldb-commits

https://github.com/JOE1994 closed 
https://github.com/llvm/llvm-project/pull/108745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] d779685 - [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (#108745)

2024-09-15 Thread via lldb-commits

Author: Youngsuk Kim
Date: 2024-09-16T00:26:51-04:00
New Revision: d7796855b87911b8ae6c726ab5df4949f173dbd2

URL: 
https://github.com/llvm/llvm-project/commit/d7796855b87911b8ae6c726ab5df4949f173dbd2
DIFF: 
https://github.com/llvm/llvm-project/commit/d7796855b87911b8ae6c726ab5df4949f173dbd2.diff

LOG: [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (#108745)

As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly

( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess
indirection.

Added: 


Modified: 
lldb/include/lldb/Utility/Instrumentation.h
lldb/source/Breakpoint/Breakpoint.cpp
lldb/source/Commands/CommandObjectLog.cpp
lldb/source/Commands/CommandObjectRegexCommand.cpp
lldb/source/Core/Module.cpp
lldb/source/Expression/IRExecutionUnit.cpp
lldb/source/Expression/IRInterpreter.cpp
lldb/source/Host/windows/PipeWindows.cpp
lldb/source/Interpreter/Options.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp
lldb/source/Symbol/Symtab.cpp
lldb/source/Target/Statistics.cpp
lldb/source/Target/Target.cpp
lldb/source/Utility/LLDBAssert.cpp
lldb/source/Utility/Log.cpp
lldb/tools/lldb-dap/DAP.cpp
lldb/tools/lldb-dap/JSONUtils.cpp
lldb/tools/lldb-dap/LLDBUtils.cpp
lldb/tools/lldb-dap/lldb-dap.cpp
lldb/tools/lldb-instr/Instrument.cpp
lldb/tools/lldb-server/LLDBServerUtilities.cpp
lldb/tools/lldb-test/lldb-test.cpp
lldb/unittests/Symbol/PostfixExpressionTest.cpp
lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/Instrumentation.h 
b/lldb/include/lldb/Utility/Instrumentation.h
index 4a9ac810eb05e9..1a86bfb38654b5 100644
--- a/lldb/include/lldb/Utility/Instrumentation.h
+++ b/lldb/include/lldb/Utility/Instrumentation.h
@@ -70,7 +70,7 @@ template  inline std::string 
stringify_args(const Ts &...ts) {
   std::string buffer;
   llvm::raw_string_ostream ss(buffer);
   stringify_helper(ss, ts...);
-  return ss.str();
+  return buffer;
 }
 
 /// RAII object for instrumenting LLDB API functions.

diff  --git a/lldb/source/Breakpoint/Breakpoint.cpp 
b/lldb/source/Breakpoint/Breakpoint.cpp
index 3268ce0b6857da..54ebafc3f65b5c 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -1127,7 +1127,7 @@ json::Value Breakpoint::GetStatistics() {
 llvm::raw_string_ostream ss(buffer);
 json::OStream json_os(ss);
 bp_data_sp->Serialize(json_os);
-if (auto expected_value = llvm::json::parse(ss.str())) {
+if (auto expected_value = llvm::json::parse(buffer)) {
   bp.try_emplace("details", std::move(*expected_value));
 } else {
   std::string details_error = toString(expected_value.takeError());

diff  --git a/lldb/source/Commands/CommandObjectLog.cpp 
b/lldb/source/Commands/CommandObjectLog.cpp
index 9eb68ddb73b6e9..5fb2dfaab8de03 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -204,7 +204,7 @@ class CommandObjectLogEnable : public CommandObjectParsed {
 channel, args.GetArgumentArrayRef(), log_file, m_options.log_options,
 m_options.buffer_size.GetCurrentValue(), m_options.handler,
 error_stream);
-result.GetErrorStream() << error_stream.str();
+result.GetErrorStream() << error;
 
 if (success)
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -273,7 +273,7 @@ class CommandObjectLogDisable : public CommandObjectParsed {
   if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(),
  error_stream))
 result.SetStatus(eReturnStatusSuccessFinishNoResult);
-  result.GetErrorStream() << error_stream.str();
+  result.GetErrorStream() << e

[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Youngsuk Kim via lldb-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/108745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Youngsuk Kim via lldb-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/108745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Youngsuk Kim via lldb-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/108745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.

Okay this is safe because after 65b13610a5226b84889b923bae884ba395ad084d, 
`raw_string_ostream` is always unbuffered so you (1) don't need to flush and 
(2) can use the underlying buffer directly. That makes sense. Please include 
that in your commit message. 

I would have split this up into two PRs/commits as the changes are related but 
can stand on their own, but it's not important enough to make you do more work. 
LGTM. 

https://github.com/llvm/llvm-project/pull/108745
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Conditionalize context_switch attribute based on kernel version (PR #105715)

2024-09-15 Thread via lldb-commits

root-kidik wrote:

Ping

https://github.com/llvm/llvm-project/pull/105715
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Youngsuk Kim (JOE1994)


Changes

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess 
indirection.

---

Patch is 26.83 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108745.diff


37 Files Affected:

- (modified) lldb/include/lldb/Utility/Instrumentation.h (+1-1) 
- (modified) lldb/source/Breakpoint/Breakpoint.cpp (+1-1) 
- (modified) lldb/source/Commands/CommandObjectLog.cpp (+4-4) 
- (modified) lldb/source/Commands/CommandObjectRegexCommand.cpp (+1-1) 
- (modified) lldb/source/Core/Module.cpp (+2-2) 
- (modified) lldb/source/Expression/IRExecutionUnit.cpp (-2) 
- (modified) lldb/source/Expression/IRInterpreter.cpp (-4) 
- (modified) lldb/source/Host/windows/PipeWindows.cpp (-1) 
- (modified) lldb/source/Interpreter/Options.cpp (+1-1) 
- (modified) lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp (-2) 
- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (-2) 
- (modified) 
lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (-1) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp 
(-3) 
- (modified) lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp (-9) 
- (modified) 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 (+1-1) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp (+1-1) 
- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
(+3-3) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+1-4) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+1-1) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+2-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp 
(+1-1) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp (+1-1) 
- (modified) lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp 
(+1-1) 
- (modified) lldb/source/Symbol/Symtab.cpp (+1-1) 
- (modified) lldb/source/Target/Statistics.cpp (+1-1) 
- (modified) lldb/source/Target/Target.cpp (+1-1) 
- (modified) lldb/source/Utility/LLDBAssert.cpp (+1-1) 
- (modified) lldb/source/Utility/Log.cpp (+1-1) 
- (modified) lldb/tools/lldb-dap/DAP.cpp (+2-4) 
- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (-1) 
- (modified) lldb/tools/lldb-dap/LLDBUtils.cpp (-1) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (-3) 
- (modified) lldb/tools/lldb-instr/Instrument.cpp (+2-2) 
- (modified) lldb/tools/lldb-server/LLDBServerUtilities.cpp (+1-1) 
- (modified) lldb/tools/lldb-test/lldb-test.cpp (+1-1) 
- (modified) lldb/unittests/Symbol/PostfixExpressionTest.cpp (+1-1) 
- (modified) 
lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp 
(+1-1) 


``diff
diff --git a/lldb/include/lldb/Utility/Instrumentation.h 
b/lldb/include/lldb/Utility/Instrumentation.h
index 4a9ac810eb05e9..1a86bfb38654b5 100644
--- a/lldb/include/lldb/Utility/Instrumentation.h
+++ b/lldb/include/lldb/Utility/Instrumentation.h
@@ -70,7 +70,7 @@ template  inline std::string 
stringify_args(const Ts &...ts) {
   std::string buffer;
   llvm::raw_string_ostream ss(buffer);
   stringify_helper(ss, ts...);
-  return ss.str();
+  return buffer;
 }
 
 /// RAII object for instrumenting LLDB API functions.
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp 
b/lldb/source/Breakpoint/Breakpoint.cpp
index 3268ce0b6857da..54ebafc3f65b5c 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -1127,7 +1127,7 @@ json::Value Breakpoint::GetStatistics() {
 llvm::raw_string_ostream ss(buffer);
 json::OStream json_os(ss);
 bp_data_sp->Serialize(json_os);
-if (auto expected_value = llvm::json::parse(ss.str())) {
+if (auto expected_value = llvm::json::parse(buffer)) {
   bp.try_emplace("details", std::move(*expected_value));
 } else {
   std::string details_error = toString(expected_value.takeError());
diff --git a/lldb/source/Commands/CommandObjectLog.cpp 
b/lldb/source/Commands/CommandObjectLog.cpp
index 9eb68ddb73b6e9..5fb2dfaab8de03 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -204,7 +204,7 @@ class CommandObjectLogEnable : public CommandObjectParsed {
 channel, args.GetArgumentArrayRef(), log_file, m_options.log_options,
 m_options.buffer_size.GetCurrentValue(), m_options.handler,
 error_stream);
-result.GetErrorStream() << error_stream.str();
+result.GetErrorStream() << error;
 
 if (success)
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -273,7 +273,7 @@ class CommandObjectLogDisable : public CommandObjectParsed {
   if (Log::DisableLogChannel(channel, args.GetArgumentArrayRef(),

[Lldb-commits] [lldb] [lldb] Nits on uses of llvm::raw_string_ostream (NFC) (PR #108745)

2024-09-15 Thread Youngsuk Kim via lldb-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/108745

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess 
indirection.

>From 35f463d394ec57a38a4e940a61af5cd1f527a00d Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 15 Sep 2024 05:16:25 -0400
Subject: [PATCH] [lldb] Nits on uses of llvm::raw_string_ostream (NFC)

* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess 
indirection.
---
 lldb/include/lldb/Utility/Instrumentation.h  | 2 +-
 lldb/source/Breakpoint/Breakpoint.cpp| 2 +-
 lldb/source/Commands/CommandObjectLog.cpp| 8 
 lldb/source/Commands/CommandObjectRegexCommand.cpp   | 2 +-
 lldb/source/Core/Module.cpp  | 4 ++--
 lldb/source/Expression/IRExecutionUnit.cpp   | 2 --
 lldb/source/Expression/IRInterpreter.cpp | 4 
 lldb/source/Host/windows/PipeWindows.cpp | 1 -
 lldb/source/Interpreter/Options.cpp  | 2 +-
 .../Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp | 2 --
 .../ExpressionParser/Clang/ClangExpressionParser.cpp | 2 --
 .../ExpressionParser/Clang/ClangModulesDeclVendor.cpp| 1 -
 .../Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp   | 3 ---
 .../Plugins/ExpressionParser/Clang/IRForTarget.cpp   | 9 -
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp | 2 +-
 .../Process/Windows/Common/NativeProcessWindows.cpp  | 2 +-
 .../Plugins/Process/Windows/Common/ProcessWindows.cpp| 6 +++---
 .../Process/gdb-remote/GDBRemoteCommunicationClient.cpp  | 5 +
 .../Plugins/Process/gdb-remote/ProcessGDBRemote.cpp  | 2 +-
 lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp | 4 ++--
 .../Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp| 2 +-
 .../source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp | 2 +-
 .../Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp  | 2 +-
 lldb/source/Symbol/Symtab.cpp| 2 +-
 lldb/source/Target/Statistics.cpp| 2 +-
 lldb/source/Target/Target.cpp| 2 +-
 lldb/source/Utility/LLDBAssert.cpp   | 2 +-
 lldb/source/Utility/Log.cpp  | 2 +-
 lldb/tools/lldb-dap/DAP.cpp  | 6 ++
 lldb/tools/lldb-dap/JSONUtils.cpp| 1 -
 lldb/tools/lldb-dap/LLDBUtils.cpp| 1 -
 lldb/tools/lldb-dap/lldb-dap.cpp | 3 ---
 lldb/tools/lldb-instr/Instrument.cpp | 4 ++--
 lldb/tools/lldb-server/LLDBServerUtilities.cpp   | 2 +-
 lldb/tools/lldb-test/lldb-test.cpp   | 2 +-
 lldb/unittests/Symbol/PostfixExpressionTest.cpp  | 2 +-
 .../NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp| 2 +-
 37 files changed, 35 insertions(+), 69 deletions(-)

diff --git a/lldb/include/lldb/Utility/Instrumentation.h 
b/lldb/include/lldb/Utility/Instrumentation.h
index 4a9ac810eb05e9..1a86bfb38654b5 100644
--- a/lldb/include/lldb/Utility/Instrumentation.h
+++ b/lldb/include/lldb/Utility/Instrumentation.h
@@ -70,7 +70,7 @@ template  inline std::string 
stringify_args(const Ts &...ts) {
   std::string buffer;
   llvm::raw_string_ostream ss(buffer);
   stringify_helper(ss, ts...);
-  return ss.str();
+  return buffer;
 }
 
 /// RAII object for instrumenting LLDB API functions.
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp 
b/lldb/source/Breakpoint/Breakpoint.cpp
index 3268ce0b6857da..54ebafc3f65b5c 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -1127,7 +1127,7 @@ json::Value Breakpoint::GetStatistics() {
 llvm::raw_string_ostream ss(buffer);
 json::OStream json_os(ss);
 bp_data_sp->Serialize(json_os);
-if (auto expected_value = llvm::json::parse(ss.str())) {
+if (auto expected_value = llvm::json::parse(buffer)) {
   bp.try_emplace("details", std::move(*expected_value));
 } else {
   std::string details_error = toString(expected_value.takeError());
diff --git a/lldb/source/Commands/CommandObjectLog.cpp 
b/lldb/source/Commands/CommandObjectLog.cpp
index 9eb68ddb73b6e9..5fb2dfaab8de03 100644
--- a/lldb/source/Commands/CommandObjectLog.cpp
+++ b/lldb/source/Commands/CommandObjectLog.cpp
@@ -204,7 +204,7 @@ class CommandObjectLogEnable : public CommandObjectParsed {
 channel, args.GetArgumentArrayRef(), log_file, m_options.log_options,
 m_options.buffer_size.GetCurrentValue(), m_options.handler,
 error_stream);
-result.GetErrorStream() << error_stream.str();
+result.GetErrorStream() << error;
 
 if (success)
   result.SetStatus(eReturnStatusSuccessFinishNoResult);
@@ -273,7 +273,7 @@ class CommandObjectLogDisable : pu

[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-15 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

This is a follow-up to https://github.com/llvm/llvm-project/pull/98330 for the 
upcoming `__compressed_pair` refactor in 
https://github.com/llvm/llvm-project/issues/93069

This patch just adds the 2 new copies of `_LIBCPP_COMPRESSED_PAIR` layouts to 
the simulator tests.

---
Full diff: https://github.com/llvm/llvm-project/pull/99012.diff


5 Files Affected:

- (modified) 
lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 (+33-1) 
- (modified) 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 (+10-9) 
- (modified) 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/main.cpp
 (+31-12) 
- (modified) 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/unique_ptr/TestDataFormatterLibcxxUniquePtrSimulator.py
 (+13-2) 
- (modified) 
lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/unique_ptr/main.cpp
 (+5) 


``diff
diff --git 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
index 026e7183ab27a0..f2c1b626bd46f7 100644
--- 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
+++ 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
@@ -7,7 +7,7 @@
 namespace std {
 namespace __lldb {
 
-// Post-c88580c layout
+#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
 struct __value_init_tag {};
 struct __default_init_tag {};
 
@@ -52,6 +52,38 @@ class __compressed_pair : private 
__compressed_pair_elem<_T1, 0>,
 
   _T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
 };
+#elif COMPRESSED_PAIR_REV == 1
+template  class __compressed_pair_padding {
+  char __padding_[(is_empty<_ToPad>::value && 
!__libcpp_is_final<_ToPad>::value)
+  ? 0
+  : sizeof(_ToPad) - __datasizeof(_ToPad)];
+};
+
+#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)  
\
+  [[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; 
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_;
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3,
\
+Initializer3)  
\
+  [[using __gnu__: __aligned__(alignof(T2)),   
\
+__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1;  
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_; 
\
+  [[no_unique_address]] T3 Initializer3;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding3_;
+#elif COMPRESSED_PAIR_REV == 2
+#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2)
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3)   
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2;  
\
+  [[no_unique_address]] T3 Name3
+#endif
 } // namespace __lldb
 } // namespace std
 
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 98d2c7320003e4..afe6374e55a355 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
@@ -28,12 +28,13 @@ def _run_test(self, defines):
 
 for v in [None, "ALTERNATE_LAYOUT"]:
 for r in range(5):
-name = "test_r%d" % r
-defines = ["REVISION=%d" % r]
-if v:
-name += "_" + v
-defines += [v]
-f = functools.partialmethod(
-LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
-)
-setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
+for c in range(3):
+name = "test_r%d_c%d" % (r, c)
+defines = ["REVI

[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-15 Thread Michael Buch via lldb-commits

https://github.com/Michael137 ready_for_review 
https://github.com/llvm/llvm-project/pull/99012
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-15 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/99012

>From e3ec030cb404c407ead39b10d5ea0baa4a0683ff Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 10 Jul 2024 15:37:45 +0100
Subject: [PATCH 1/4] [WIP][lldb][test] Add a new __compressed_pair layout to
 libcxx simulator tests

---
 .../compressed_pair.h | 34 ++-
 .../TestDataFormatterLibcxxStringSimulator.py | 19 ++-
 .../libcxx-simulators/string/main.cpp | 33 +++---
 ...stDataFormatterLibcxxUniquePtrSimulator.py | 14 ++--
 .../libcxx-simulators/unique_ptr/main.cpp |  5 +++
 5 files changed, 81 insertions(+), 24 deletions(-)

diff --git 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
index 026e7183ab27a0..f2c1b626bd46f7 100644
--- 
a/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
+++ 
b/lldb/packages/Python/lldbsuite/test/make/libcxx-simulators-common/compressed_pair.h
@@ -7,7 +7,7 @@
 namespace std {
 namespace __lldb {
 
-// Post-c88580c layout
+#if COMPRESSED_PAIR_REV == 0 // Post-c88580c layout
 struct __value_init_tag {};
 struct __default_init_tag {};
 
@@ -52,6 +52,38 @@ class __compressed_pair : private 
__compressed_pair_elem<_T1, 0>,
 
   _T1 &first() { return static_cast<_Base1 &>(*this).__get(); }
 };
+#elif COMPRESSED_PAIR_REV == 1
+template  class __compressed_pair_padding {
+  char __padding_[(is_empty<_ToPad>::value && 
!__libcpp_is_final<_ToPad>::value)
+  ? 0
+  : sizeof(_ToPad) - __datasizeof(_ToPad)];
+};
+
+#define _LLDB_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2)  
\
+  [[__gnu__::__aligned__(alignof(T2))]] [[no_unique_address]] T1 Initializer1; 
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_;
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3,
\
+Initializer3)  
\
+  [[using __gnu__: __aligned__(alignof(T2)),   
\
+__aligned__(alignof(T3))]] [[no_unique_address]] T1 Initializer1;  
\
+  [[no_unique_address]] __compressed_pair_padding __padding1_; 
\
+  [[no_unique_address]] T2 Initializer2;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding2_; 
\
+  [[no_unique_address]] T3 Initializer3;   
\
+  [[no_unique_address]] __compressed_pair_padding __padding3_;
+#elif COMPRESSED_PAIR_REV == 2
+#define _LLDB_COMPRESSED_PAIR(T1, Name1, T2, Name2)
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2
+
+#define _LLDB_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3)   
\
+  [[no_unique_address]] T1 Name1;  
\
+  [[no_unique_address]] T2 Name2;  
\
+  [[no_unique_address]] T3 Name3
+#endif
 } // namespace __lldb
 } // namespace std
 
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
index 3e5c493692c4f0..0d4270ef58568a 100644
--- 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
+++ 
b/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/TestDataFormatterLibcxxStringSimulator.py
@@ -25,12 +25,13 @@ def _run_test(self, defines):
 
 for v in [None, "ALTERNATE_LAYOUT"]:
 for r in range(5):
-name = "test_r%d" % r
-defines = ["REVISION=%d" % r]
-if v:
-name += "_" + v
-defines += [v]
-f = functools.partialmethod(
-LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
-)
-setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
+for c in range(3):
+name = "test_r%d_c%d" % (r, c)
+defines = ["REVISION=%d" % r, "COMPRESSED_PAIR_REV=%d" % c]
+if v:
+name += "_" + v
+defines += [v]
+f = functools.partialmethod(
+LibcxxStringDataFormatterSimulatorTestCase._run_test, defines
+)
+setattr(LibcxxStringDataFormatterSimulatorTestCase, name, f)
diff --git 
a/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/string/

[Lldb-commits] [lldb] [lldb][test] Add a new __compressed_pair layout to libcxx simulator tests (PR #99012)

2024-09-15 Thread Michael Buch via lldb-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/99012
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Support new libc++ __compressed_pair layout (PR #96538)

2024-09-15 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/96538

>From 16ae2c3c04d908807d78224a8fee34f772a337fa Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 29 Jan 2024 16:23:16 +
Subject: [PATCH 1/4] [lldb] Support new libc++ __compressed_pair layout

---
 lldb/examples/synthetic/libcxx.py |  26 ++-
 .../Plugins/Language/CPlusPlus/LibCxx.cpp |  85 ++---
 .../Plugins/Language/CPlusPlus/LibCxx.h   |   3 +-
 .../Plugins/Language/CPlusPlus/LibCxxList.cpp |  72 +---
 .../Plugins/Language/CPlusPlus/LibCxxMap.cpp  |  41 +++--
 .../Language/CPlusPlus/LibCxxUnorderedMap.cpp | 166 +++---
 .../Language/CPlusPlus/LibCxxVector.cpp   |  38 ++--
 .../list/TestDataFormatterGenericList.py  |   2 +-
 8 files changed, 282 insertions(+), 151 deletions(-)

diff --git a/lldb/examples/synthetic/libcxx.py 
b/lldb/examples/synthetic/libcxx.py
index 474aaa428fa23a..060ff901008497 100644
--- a/lldb/examples/synthetic/libcxx.py
+++ b/lldb/examples/synthetic/libcxx.py
@@ -721,6 +721,12 @@ def _get_value_of_compressed_pair(self, pair):
 def update(self):
 logger = lldb.formatters.Logger.Logger()
 try:
+has_compressed_pair_layout = True
+alloc_valobj = self.valobj.GetChildMemberWithName("__alloc_")
+size_valobj = self.valobj.GetChildMemberWithName("__size_")
+if alloc_valobj.IsValid() and size_valobj.IsValid():
+has_compressed_pair_layout = False
+
 # A deque is effectively a two-dim array, with fixed width.
 # 'map' contains pointers to the rows of this array. The
 # full memory area allocated by the deque is delimited
@@ -734,9 +740,13 @@ def update(self):
 # variable tells which element in this NxM array is the 0th
 # one, and the 'size' element gives the number of elements
 # in the deque.
-count = self._get_value_of_compressed_pair(
-self.valobj.GetChildMemberWithName("__size_")
-)
+if has_compressed_pair_layout:
+count = self._get_value_of_compressed_pair(
+self.valobj.GetChildMemberWithName("__size_")
+)
+else:
+count = size_valobj.GetValueAsUnsigned(0)
+
 # give up now if we cant access memory reliably
 if self.block_size < 0:
 logger.write("block_size < 0")
@@ -748,9 +758,13 @@ def update(self):
 self.map_begin = map_.GetChildMemberWithName("__begin_")
 map_begin = self.map_begin.GetValueAsUnsigned(0)
 map_end = 
map_.GetChildMemberWithName("__end_").GetValueAsUnsigned(0)
-map_endcap = self._get_value_of_compressed_pair(
-map_.GetChildMemberWithName("__end_cap_")
-)
+
+if has_compressed_pair_layout:
+map_endcap = self._get_value_of_compressed_pair(
+map_.GetChildMemberWithName("__end_cap_")
+)
+else:
+map_endcap = 
map_.GetChildMemberWithName("__end_cap_").GetValueAsUnsigned(0)
 
 # check consistency
 if not map_first <= map_begin <= map_end <= map_endcap:
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp 
b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
index feaa51a96843ab..7d3b2410a7296e 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxx.cpp
@@ -27,6 +27,7 @@
 #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
 #include 
 #include 
 
@@ -34,6 +35,32 @@ using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
 
+static void consumeInlineNamespace(llvm::StringRef &name) {
+  // Delete past an inline namespace, if any: __[a-zA-Z0-9_]+::
+  auto scratch = name;
+  if (scratch.consume_front("__") && std::isalnum(scratch[0])) {
+scratch = scratch.drop_while([](char c) { return std::isalnum(c); });
+if (scratch.consume_front("::")) {
+  // Successfully consumed a namespace.
+  name = scratch;
+}
+  }
+}
+
+bool lldb_private::formatters::isOldCompressedPairLayout(
+ValueObject &pair_obj) {
+  return isStdTemplate(pair_obj.GetTypeName(), "__compressed_pair");
+}
+
+bool lldb_private::formatters::isStdTemplate(ConstString type_name,
+ llvm::StringRef type) {
+  llvm::StringRef name = type_name.GetStringRef();
+  // The type name may be prefixed with `std::__::`.
+  if (name.consume_front("std::"))
+consumeInlineNamespace(name);
+  return name.consume_front(type) && name.starts_with("<");
+}
+
 lldb::ValueObjectSP lldb_private::formatters::GetChildMemberWithName(
 ValueObject &obj, llvm::ArrayRef alternative_nam

[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-14 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

(I hadn't noticed the kernel added this new flavor for intel machines, I've had 
people ask for access to these before.)

https://github.com/llvm/llvm-project/pull/108663
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-14 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

Nice improvement.  Let me apply it and experiment a tiny bit next week, but a 
quick read looks good.

https://github.com/llvm/llvm-project/pull/108663
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][intel-pt] Fix build error on conversion from llvm::Error to Status::FromError (PR #108719)

2024-09-14 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

Hey @kusmour. I actually looked into this on Thursday, see #108248. If we are 
going to merge this I think we should just call `std::move` and not 
`Status::FromError(std::move(err))` as the API takes an err r-value.

https://github.com/llvm/llvm-project/pull/108719
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][intel-pt] Fix build error on conversion from llvm::Error to Status::FromError (PR #108719)

2024-09-14 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Wanyi (kusmour)


Changes

Summary: This introduced from upstream [#107163](https://github.com/llvm/llvm-project/pull/107163)

Test Plan: I can build

---
Full diff: https://github.com/llvm/llvm-project/pull/108719.diff


1 Files Affected:

- (modified) 
lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp (+2-2) 


``diff
diff --git 
a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index 81f7c228561a6d..40035e4480495f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -78,7 +78,7 @@ bool CommandObjectThreadTraceStartIntelPT::DoExecuteOnThreads(
 llvm::ArrayRef tids) {
   if (Error err = m_trace.Start(tids, m_options.m_ipt_trace_size,
 m_options.m_enable_tsc, 
m_options.m_psb_period))
-result.SetError(Status(std::move(err)));
+result.SetError(Status::FromError(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
 
@@ -164,7 +164,7 @@ void CommandObjectProcessTraceStartIntelPT::DoExecute(
   m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
   m_options.m_enable_tsc, m_options.m_psb_period,
   m_options.m_per_cpu_tracing, m_options.m_disable_cgroup_filtering))
-result.SetError(Status(std::move(err)));
+result.SetError(Status::FromError(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
 }

``




https://github.com/llvm/llvm-project/pull/108719
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][intel-pt] Fix build error on conversion from llvm::Error to Status::FromError (PR #108719)

2024-09-14 Thread via lldb-commits

https://github.com/kusmour created 
https://github.com/llvm/llvm-project/pull/108719

Summary: This introduced from upstream 
[#107163](https://github.com/llvm/llvm-project/pull/107163)

Test Plan: I can build

>From ff2f26081b5535587e5ccb28522b728a596b6e12 Mon Sep 17 00:00:00 2001
From: Wanyi Ye 
Date: Sat, 14 Sep 2024 14:23:01 -0700
Subject: [PATCH] [lldb][intel-pt] Fix build error on conversion from
 llvm::Error to Status::FromError

Summary: This introduced from upstream #107163

Test Plan: I can build
---
 .../Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index 81f7c228561a6d..40035e4480495f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -78,7 +78,7 @@ bool CommandObjectThreadTraceStartIntelPT::DoExecuteOnThreads(
 llvm::ArrayRef tids) {
   if (Error err = m_trace.Start(tids, m_options.m_ipt_trace_size,
 m_options.m_enable_tsc, 
m_options.m_psb_period))
-result.SetError(Status(std::move(err)));
+result.SetError(Status::FromError(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
 
@@ -164,7 +164,7 @@ void CommandObjectProcessTraceStartIntelPT::DoExecute(
   m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
   m_options.m_enable_tsc, m_options.m_psb_period,
   m_options.m_per_cpu_tracing, m_options.m_disable_cgroup_filtering))
-result.SetError(Status(std::move(err)));
+result.SetError(Status::FromError(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
 }

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (PR #108715)

2024-09-14 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere closed 
https://github.com/llvm/llvm-project/pull/108715
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (PR #108715)

2024-09-14 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Reverts llvm/llvm-project#106791 because it breaks 
`trap_frame_sym_ctx.test ` on x86_64.

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/5745/


---
Full diff: https://github.com/llvm/llvm-project/pull/108715.diff


1 Files Affected:

- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+63) 


``diff
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c36748963db37b..06da83e26a26a5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,6 +3768,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
+  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4353,6 +4354,47 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
+if (symbol_byte_size == 0 && function_starts_count > 0) {
+  addr_t symbol_lookup_file_addr = nlist.n_value;
+  // Do an exact address match for non-ARM addresses, else get the
+  // closest since the symbol might be a thumb symbol which has an
+  // address with bit zero set.
+  FunctionStarts::Entry *func_start_entry =
+  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
+  if (is_arm && func_start_entry) {
+// Verify that the function start address is the symbol address
+// (ARM) or the symbol address + 1 (thumb).
+if (func_start_entry->addr != symbol_lookup_file_addr &&
+func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
+  // Not the right entry, NULL it out...
+  func_start_entry = nullptr;
+}
+  }
+  if (func_start_entry) {
+func_start_entry->data = true;
+
+addr_t symbol_file_addr = func_start_entry->addr;
+if (is_arm)
+  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+
+const FunctionStarts::Entry *next_func_start_entry =
+function_starts.FindNextEntry(func_start_entry);
+const addr_t section_end_file_addr =
+section_file_addr + symbol_section->GetByteSize();
+if (next_func_start_entry) {
+  addr_t next_symbol_file_addr = next_func_start_entry->addr;
+  // Be sure the clear the Thumb address bit when we calculate the
+  // size from the current and next address
+  if (is_arm)
+next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+  symbol_byte_size = std::min(
+  next_symbol_file_addr - symbol_file_addr,
+  section_end_file_addr - symbol_file_addr);
+} else {
+  symbol_byte_size = section_end_file_addr - symbol_file_addr;
+}
+  }
+}
 symbol_value -= section_file_addr;
   }
 
@@ -4459,6 +4501,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   if (nlist.n_desc & N_WEAK_REF)
 sym[sym_idx].SetIsWeak(true);
 
+  if (symbol_byte_size > 0)
+sym[sym_idx].SetByteSize(symbol_byte_size);
+
   if (demangled_is_synthesized)
 sym[sym_idx].SetDemangledNameIsSynthesized(true);
 
@@ -4577,7 +4622,23 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   Address symbol_addr;
   if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
 SectionSP symbol_section(symbol_addr.GetSection());
+uint32_t symbol_byte_size = 0;
 if (symbol_section) {
+  const addr_t section_file_addr = 
symbol_section->GetFileAddress();
+  const FunctionStarts::Entry *next_func_start_entry =
+  function_starts.FindNextEntry(func_start_entry);
+  const addr_t section_end_file_addr =
+  section_file_addr + symbol_section->GetByteSize();
+  if (next_func_start_entry) {
+addr_t next_symbol_file_addr = next_func_start_entry->addr;
+if (is_arm)
+  next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+symbol_byte_size = std::min(
+next_symbol_file_addr - symbol_file_addr,
+section_end_file_addr - symbol_file_addr);
+  } else {
+symbol_byte_size = section_end_file_addr - symbol_file_addr;
+  }
   sym[sym_idx].SetID(synthetic_sym_id++);
   // Don't set the name for any synthetic symbols, the Symbol
   // object will 

[Lldb-commits] [lldb] fa478bd - Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (#108715)

2024-09-14 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-09-14T10:50:44-07:00
New Revision: fa478bd275f473861f6d4df4896244a730d4853f

URL: 
https://github.com/llvm/llvm-project/commit/fa478bd275f473861f6d4df4896244a730d4853f
DIFF: 
https://github.com/llvm/llvm-project/commit/fa478bd275f473861f6d4df4896244a730d4853f.diff

LOG: Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size 
as symbols are created" (#108715)

Reverts llvm/llvm-project#106791 because it breaks
`trap_frame_sym_ctx.test ` on x86_64.

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/5745/

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c36748963db37b..06da83e26a26a5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,6 +3768,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
+  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4353,6 +4354,47 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
+if (symbol_byte_size == 0 && function_starts_count > 0) {
+  addr_t symbol_lookup_file_addr = nlist.n_value;
+  // Do an exact address match for non-ARM addresses, else get the
+  // closest since the symbol might be a thumb symbol which has an
+  // address with bit zero set.
+  FunctionStarts::Entry *func_start_entry =
+  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
+  if (is_arm && func_start_entry) {
+// Verify that the function start address is the symbol address
+// (ARM) or the symbol address + 1 (thumb).
+if (func_start_entry->addr != symbol_lookup_file_addr &&
+func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
+  // Not the right entry, NULL it out...
+  func_start_entry = nullptr;
+}
+  }
+  if (func_start_entry) {
+func_start_entry->data = true;
+
+addr_t symbol_file_addr = func_start_entry->addr;
+if (is_arm)
+  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+
+const FunctionStarts::Entry *next_func_start_entry =
+function_starts.FindNextEntry(func_start_entry);
+const addr_t section_end_file_addr =
+section_file_addr + symbol_section->GetByteSize();
+if (next_func_start_entry) {
+  addr_t next_symbol_file_addr = next_func_start_entry->addr;
+  // Be sure the clear the Thumb address bit when we calculate the
+  // size from the current and next address
+  if (is_arm)
+next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+  symbol_byte_size = std::min(
+  next_symbol_file_addr - symbol_file_addr,
+  section_end_file_addr - symbol_file_addr);
+} else {
+  symbol_byte_size = section_end_file_addr - symbol_file_addr;
+}
+  }
+}
 symbol_value -= section_file_addr;
   }
 
@@ -4459,6 +4501,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   if (nlist.n_desc & N_WEAK_REF)
 sym[sym_idx].SetIsWeak(true);
 
+  if (symbol_byte_size > 0)
+sym[sym_idx].SetByteSize(symbol_byte_size);
+
   if (demangled_is_synthesized)
 sym[sym_idx].SetDemangledNameIsSynthesized(true);
 
@@ -4577,7 +4622,23 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   Address symbol_addr;
   if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
 SectionSP symbol_section(symbol_addr.GetSection());
+uint32_t symbol_byte_size = 0;
 if (symbol_section) {
+  const addr_t section_file_addr = 
symbol_section->GetFileAddress();
+  const FunctionStarts::Entry *next_func_start_entry =
+  function_starts.FindNextEntry(func_start_entry);
+  const addr_t section_end_file_addr =
+  section_file_addr + symbol_section->GetByteSize();
+  if (next_func_start_entry) {
+addr_t next_symbol_file_addr = next_func_start_entry->addr;
+if (is_arm)
+  next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+symbol_byte_size = std::min(
+next_symbol_file_addr - symbol_file_addr,
+s

[Lldb-commits] [lldb] Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (PR #108715)

2024-09-14 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/108715
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Revert "[lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created" (PR #108715)

2024-09-14 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere created 
https://github.com/llvm/llvm-project/pull/108715

Reverts llvm/llvm-project#106791 because it breaks `trap_frame_sym_ctx.test ` 
on x86_64.

https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/lldb-cmake/5745/


>From ba6e663299e1d7b54a3ac4a7c647d44f66d8699d Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Sat, 14 Sep 2024 10:49:27 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[lldb]=20Do=20not=20use=20LC=5FFUNCTI?=
 =?UTF-8?q?ON=5FSTARTS=20data=20to=20determine=20symbol=20size=20as?=
 =?UTF-8?q?=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 0351dc522a25df0473a63b414a5bfde5814d3dc3.
---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 63 +++
 1 file changed, 63 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c36748963db37b..06da83e26a26a5 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,6 +3768,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
+  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4353,6 +4354,47 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
+if (symbol_byte_size == 0 && function_starts_count > 0) {
+  addr_t symbol_lookup_file_addr = nlist.n_value;
+  // Do an exact address match for non-ARM addresses, else get the
+  // closest since the symbol might be a thumb symbol which has an
+  // address with bit zero set.
+  FunctionStarts::Entry *func_start_entry =
+  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
+  if (is_arm && func_start_entry) {
+// Verify that the function start address is the symbol address
+// (ARM) or the symbol address + 1 (thumb).
+if (func_start_entry->addr != symbol_lookup_file_addr &&
+func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
+  // Not the right entry, NULL it out...
+  func_start_entry = nullptr;
+}
+  }
+  if (func_start_entry) {
+func_start_entry->data = true;
+
+addr_t symbol_file_addr = func_start_entry->addr;
+if (is_arm)
+  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+
+const FunctionStarts::Entry *next_func_start_entry =
+function_starts.FindNextEntry(func_start_entry);
+const addr_t section_end_file_addr =
+section_file_addr + symbol_section->GetByteSize();
+if (next_func_start_entry) {
+  addr_t next_symbol_file_addr = next_func_start_entry->addr;
+  // Be sure the clear the Thumb address bit when we calculate the
+  // size from the current and next address
+  if (is_arm)
+next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+  symbol_byte_size = std::min(
+  next_symbol_file_addr - symbol_file_addr,
+  section_end_file_addr - symbol_file_addr);
+} else {
+  symbol_byte_size = section_end_file_addr - symbol_file_addr;
+}
+  }
+}
 symbol_value -= section_file_addr;
   }
 
@@ -4459,6 +4501,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   if (nlist.n_desc & N_WEAK_REF)
 sym[sym_idx].SetIsWeak(true);
 
+  if (symbol_byte_size > 0)
+sym[sym_idx].SetByteSize(symbol_byte_size);
+
   if (demangled_is_synthesized)
 sym[sym_idx].SetDemangledNameIsSynthesized(true);
 
@@ -4577,7 +4622,23 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
   Address symbol_addr;
   if (module_sp->ResolveFileAddress(symbol_file_addr, symbol_addr)) {
 SectionSP symbol_section(symbol_addr.GetSection());
+uint32_t symbol_byte_size = 0;
 if (symbol_section) {
+  const addr_t section_file_addr = 
symbol_section->GetFileAddress();
+  const FunctionStarts::Entry *next_func_start_entry =
+  function_starts.FindNextEntry(func_start_entry);
+  const addr_t section_end_file_addr =
+  section_file_addr + symbol_section->GetByteSize();
+  if (next_func_start_entry) {
+addr_t next_symbol_file_addr = next_func_start_entry->addr;
+if (is_arm)
+  next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
+symbol_byte_size = std::min(
+next

[Lldb-commits] [lldb] [lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created (PR #106791)

2024-09-14 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

It looks like this breaks `Unwind.trap_frame_sym_ctx` on x86_64: 
https://ci.swift.org/view/all/job/llvm.org/view/LLDB/job/lldb-cmake/5745/testReport/junit/lldb-shell/Unwind/trap_frame_sym_ctx_test/

I'm going to revert this to get the bots green over the weekend. 

https://github.com/llvm/llvm-project/pull/106791
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-14 Thread Walter Erquinigo via lldb-commits


@@ -1364,8 +1364,14 @@ void request_evaluate(const llvm::json::Object &request) 
{
   std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
 
-  if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
-   ExpressionContext::Command) {
+  if (context == "repl" &&
+  (expression.empty() ?
+   g_dap.last_nonempty_var_expression.empty() :
+   g_dap.DetectExpressionContext(frame, expression) ==

walter-erquinigo wrote:

it's hard to read this. Please move this ternary check into another variable 
with a good name.

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-14 Thread Walter Erquinigo via lldb-commits


@@ -1376,6 +1382,16 @@ void request_evaluate(const llvm::json::Object &request) 
{
 EmplaceSafeString(body, "result", result);
 body.try_emplace("variablesReference", (int64_t)0);
   } else {
+if (context == "repl") {
+  // If the expression is empty and the last expression was for a
+  // variable, set the expression to the previous expression (repeat the
+  // evaluation); otherwise save the current non-empty expression for the
+  // next (possibly empty) variable expression.
+  if (expression.empty())
+expression = g_dap.last_nonempty_var_expression;

walter-erquinigo wrote:

IIUC, this has the following flow in the debug console:

- You send a command (non-var expression) FOO
- You send a var expression VAR
- You send empty text -> then FOO repeats

If that understanding is correct, that would lead to a confusing behavior. I 
think it's better to repeat only if the previous input was exactly a command.

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-13 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b74e7792194d9a8a9ef32c7dc1ffcd205b299336 
4453801c7d8abf7a6adfb7fae57ad9fa9d52a0c4 --extensions cpp,h -- 
lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp 
lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h 
lldb/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp 
b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
index 286fd72267..6bc1055278 100644
--- a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -184,10 +184,10 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
 #else
 mach_msg_type_number_t count = e_regSetWordSizeGPRFull;
 int flavor = __x86_64_THREAD_FULL_STATE;
-m_state.SetError(
-e_regSetGPR, Read,
-::thread_get_state(m_thread->MachPortNumber(), flavor,
-   (thread_state_t)&m_state.context.gpr, &count));
+m_state.SetError(e_regSetGPR, Read,
+ ::thread_get_state(m_thread->MachPortNumber(), flavor,
+(thread_state_t)&m_state.context.gpr,
+&count));
 
 if (!m_state.GetError(e_regSetGPR, Read)) {
   m_state.hasFullGPRState = true;
@@ -195,10 +195,10 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
   m_state.hasFullGPRState = false;
   count = e_regSetWordSizeGPR;
   flavor = __x86_64_THREAD_STATE;
-  m_state.SetError(
-  e_regSetGPR, Read,
-  ::thread_get_state(m_thread->MachPortNumber(), flavor,
- (thread_state_t)&m_state.context.gpr, &count));
+  m_state.SetError(e_regSetGPR, Read,
+   ::thread_get_state(m_thread->MachPortNumber(), flavor,
+  (thread_state_t)&m_state.context.gpr,
+  &count));
 }
 DNBLogThreadedIf(
 LOG_THREAD,
@@ -214,20 +214,19 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
 m_state.hasFullGPRState ? "full" : "non-full",
 m_state.hasFullGPRState ? __x86_64_THREAD_FULL_STATE
 : __x86_64_THREAD_STATE,
-m_state.GetError(e_regSetGPR, Read),
-m_state.context.gpr.__rax, m_state.context.gpr.__rbx,
-m_state.context.gpr.__rcx, m_state.context.gpr.__rdx,
-m_state.context.gpr.__rdi, m_state.context.gpr.__rsi,
-m_state.context.gpr.__rbp, m_state.context.gpr.__rsp,
-m_state.context.gpr.__r8, m_state.context.gpr.__r9,
-m_state.context.gpr.__r10, m_state.context.gpr.__r11,
-m_state.context.gpr.__r12, m_state.context.gpr.__r13,
-m_state.context.gpr.__r14, m_state.context.gpr.__r15,
-m_state.context.gpr.__rip, m_state.context.gpr.__rflags,
-m_state.context.gpr.__cs, m_state.context.gpr.__fs,
-m_state.context.gpr.__gs, m_state.context.gpr.__ds,
-m_state.context.gpr.__es, m_state.context.gpr.__ss,
-m_state.context.gpr.__gsbase );
+m_state.GetError(e_regSetGPR, Read), m_state.context.gpr.__rax,
+m_state.context.gpr.__rbx, m_state.context.gpr.__rcx,
+m_state.context.gpr.__rdx, m_state.context.gpr.__rdi,
+m_state.context.gpr.__rsi, m_state.context.gpr.__rbp,
+m_state.context.gpr.__rsp, m_state.context.gpr.__r8,
+m_state.context.gpr.__r9, m_state.context.gpr.__r10,
+m_state.context.gpr.__r11, m_state.context.gpr.__r12,
+m_state.context.gpr.__r13, m_state.context.gpr.__r14,
+m_state.context.gpr.__r15, m_state.context.gpr.__rip,
+m_state.context.gpr.__rflags, m_state.context.gpr.__cs,
+m_state.context.gpr.__fs, m_state.context.gpr.__gs,
+m_state.context.gpr.__ds, m_state.context.gpr.__es,
+m_state.context.gpr.__ss, m_state.context.gpr.__gsbase);
 
 //  DNBLogThreadedIf (LOG_THREAD, "thread_get_state(0x%4.4x, %u, &gpr, %u)
 //  => 0x%8.8x"
@@ -478,13 +477,14 @@ kern_return_t DNBArchImplX86_64::SetGPRState() {
   "(SetGPRState() for stop_count = %u)",
   m_thread->MachPortNumber(), kret, m_thread->Process()->StopCount());
 
-  m_state.SetError(e_regSetGPR, Write,
-   ::thread_set_state(m_thread->MachPortNumber(),
-  m_state.hasFullGPRState ? 
__x86_64_THREAD_FULL_STATE
-  : 
__x86_64_THREAD_STATE,
-  (thread_state_t)&m_state.context.gpr,
-  m_state.hasFul

[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-13 Thread via lldb-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/108663
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Brendan Shanks (mrpippy)


Changes

macOS 10.15 added a "full" x86_64 GPR thread state flavor, equivalent to the 
normal one but with DS, ES, SS, and GSbase added. This flavor can only be used 
with processes that install a custom LDT (functionality that was also added in 
10.15 and is used by apps like Wine to execute 32-bit code).

Along with allowing DS, ES, SS, and GSbase to be viewed/modified, using the 
full flavor is necessary when debugging a thread executing 32-bit code.
If thread_set_state() is used with the regular thread state flavor, the kernel 
resets CS to the 64-bit code segment (see 
[set_thread_state64()](https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/i386/pcb.c#L723),
 which makes debugging impossible.

There's no way to detect whether the full flavor is available, try to use it 
and fall back to the regular one if it's not available.

A downside is that this patch exposes the DS, ES, SS, and GSbase registers for 
all x86_64 processes, even though they are not populated unless the full thread 
state is available.
I'm not sure if there's a way to tell LLDB that a register is unavailable. The 
classic GDB `g` command [allows returning 
`x`](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets)
 to denote unavailable registers, but it seems like the debug server uses newer 
commands like `jThreadsInfo` and I'm not sure if those have the same support.

Fixes #57591
(also filed as Apple FB11464104)

@jasonmolenda 

---
Full diff: https://github.com/llvm/llvm-project/pull/108663.diff


3 Files Affected:

- (modified) lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp 
(+43-9) 
- (modified) lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h 
(+3-1) 
- (modified) 
lldb/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h (+5) 


``diff
diff --git a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp 
b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
index 5a62e2a8d12e2c..286fd72267b349 100644
--- a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -182,22 +182,39 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
 m_state.context.gpr.__gs = ('g' << 8) + 's';
 m_state.SetError(e_regSetGPR, Read, 0);
 #else
-mach_msg_type_number_t count = e_regSetWordSizeGPR;
+mach_msg_type_number_t count = e_regSetWordSizeGPRFull;
+int flavor = __x86_64_THREAD_FULL_STATE;
 m_state.SetError(
 e_regSetGPR, Read,
-::thread_get_state(m_thread->MachPortNumber(), __x86_64_THREAD_STATE,
+::thread_get_state(m_thread->MachPortNumber(), flavor,
(thread_state_t)&m_state.context.gpr, &count));
+
+if (!m_state.GetError(e_regSetGPR, Read)) {
+  m_state.hasFullGPRState = true;
+} else {
+  m_state.hasFullGPRState = false;
+  count = e_regSetWordSizeGPR;
+  flavor = __x86_64_THREAD_STATE;
+  m_state.SetError(
+  e_regSetGPR, Read,
+  ::thread_get_state(m_thread->MachPortNumber(), flavor,
+ (thread_state_t)&m_state.context.gpr, &count));
+}
 DNBLogThreadedIf(
 LOG_THREAD,
-"::thread_get_state (0x%4.4x, %u, &gpr, %u) => 0x%8.8x"
+"::thread_get_state (0x%4.4x, %u (%s), &gpr, %u) => 0x%8.8x"
 "\n\trax = %16.16llx rbx = %16.16llx rcx = %16.16llx rdx = %16.16llx"
 "\n\trdi = %16.16llx rsi = %16.16llx rbp = %16.16llx rsp = %16.16llx"
 "\n\t r8 = %16.16llx  r9 = %16.16llx r10 = %16.16llx r11 = %16.16llx"
 "\n\tr12 = %16.16llx r13 = %16.16llx r14 = %16.16llx r15 = %16.16llx"
 "\n\trip = %16.16llx"
-"\n\tflg = %16.16llx  cs = %16.16llx  fs = %16.16llx  gs = %16.16llx",
-m_thread->MachPortNumber(), x86_THREAD_STATE64,
-x86_THREAD_STATE64_COUNT, m_state.GetError(e_regSetGPR, Read),
+"\n\tflg = %16.16llx  cs = %16.16llx  fs = %16.16llx  gs = %16.16llx"
+"\n\t ds = %16.16llx  es = %16.16llx  ss = %16.16llx gsB = %16.16llx",
+m_thread->MachPortNumber(), flavor,
+m_state.hasFullGPRState ? "full" : "non-full",
+m_state.hasFullGPRState ? __x86_64_THREAD_FULL_STATE
+: __x86_64_THREAD_STATE,
+m_state.GetError(e_regSetGPR, Read),
 m_state.context.gpr.__rax, m_state.context.gpr.__rbx,
 m_state.context.gpr.__rcx, m_state.context.gpr.__rdx,
 m_state.context.gpr.__rdi, m_state.context.gpr.__rsi,
@@ -208,7 +225,9 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
 m_state.context.gpr.__r14, m_state.context.gpr.__r15,
 m_state.context.gpr.__rip, m_state.context.gpr.__rflags,
 m_state.context.gpr.__cs, m_state.context.gpr.__fs,
-m_state.context.gpr.__gs);
+m

[Lldb-commits] [lldb] [lldb] [debugserver] Use "full" x86_64 GPR state when available. (PR #108663)

2024-09-13 Thread Brendan Shanks via lldb-commits

https://github.com/mrpippy created 
https://github.com/llvm/llvm-project/pull/108663

macOS 10.15 added a "full" x86_64 GPR thread state flavor, equivalent to the 
normal one but with DS, ES, SS, and GSbase added. This flavor can only be used 
with processes that install a custom LDT (functionality that was also added in 
10.15 and is used by apps like Wine to execute 32-bit code).

Along with allowing DS, ES, SS, and GSbase to be viewed/modified, using the 
full flavor is necessary when debugging a thread executing 32-bit code.
If thread_set_state() is used with the regular thread state flavor, the kernel 
resets CS to the 64-bit code segment (see 
[set_thread_state64()](https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/i386/pcb.c#L723),
 which makes debugging impossible.

There's no way to detect whether the full flavor is available, try to use it 
and fall back to the regular one if it's not available.

A downside is that this patch exposes the DS, ES, SS, and GSbase registers for 
all x86_64 processes, even though they are not populated unless the full thread 
state is available.
I'm not sure if there's a way to tell LLDB that a register is unavailable. The 
classic GDB `g` command [allows returning 
`x`](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#Packets)
 to denote unavailable registers, but it seems like the debug server uses newer 
commands like `jThreadsInfo` and I'm not sure if those have the same support.

Fixes #57591
(also filed as Apple FB11464104)

@jasonmolenda 

>From 4453801c7d8abf7a6adfb7fae57ad9fa9d52a0c4 Mon Sep 17 00:00:00 2001
From: Brendan Shanks 
Date: Thu, 12 Sep 2024 16:01:30 -0700
Subject: [PATCH] [lldb] [debugserver] Use "full" x86_64 GPR state when
 available.

macOS 10.15 added a "full" x86_64 GPR thread state flavor, equivalent to
the normal one but with DS, ES, SS, and GSbase added.
This flavor can only be used with processes that install a custom LDT
(functionality that was also added in 10.15 and is used by apps like
Wine to execute 32-bit code).

Along with allowing DS, ES, SS, and GSbase to be viewed/modified, using
the full flavor is necessary when debugging a thread executing 32-bit
code.
If thread_set_state() is used with the regular thread state flavor, the
kernel resets CS to the 64-bit code segment, which makes debugging
impossible.

There's no way to detect whether the full flavor is available, try to
use it and fall back to the regular one if it's not available.

A downside is that this patch exposes the DS, ES, SS, and GSbase
registers for all x86_64 processes, even though they are not populated
unless the full thread state is available.

Fixes #57591
---
 .../MacOSX/x86_64/DNBArchImplX86_64.cpp   | 52 +++
 .../source/MacOSX/x86_64/DNBArchImplX86_64.h  |  4 +-
 .../MacOSX/x86_64/MachRegisterStatesX86_64.h  |  5 ++
 3 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp 
b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
index 5a62e2a8d12e2c..286fd72267b349 100644
--- a/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -182,22 +182,39 @@ kern_return_t DNBArchImplX86_64::GetGPRState(bool force) {
 m_state.context.gpr.__gs = ('g' << 8) + 's';
 m_state.SetError(e_regSetGPR, Read, 0);
 #else
-mach_msg_type_number_t count = e_regSetWordSizeGPR;
+mach_msg_type_number_t count = e_regSetWordSizeGPRFull;
+int flavor = __x86_64_THREAD_FULL_STATE;
 m_state.SetError(
 e_regSetGPR, Read,
-::thread_get_state(m_thread->MachPortNumber(), __x86_64_THREAD_STATE,
+::thread_get_state(m_thread->MachPortNumber(), flavor,
(thread_state_t)&m_state.context.gpr, &count));
+
+if (!m_state.GetError(e_regSetGPR, Read)) {
+  m_state.hasFullGPRState = true;
+} else {
+  m_state.hasFullGPRState = false;
+  count = e_regSetWordSizeGPR;
+  flavor = __x86_64_THREAD_STATE;
+  m_state.SetError(
+  e_regSetGPR, Read,
+  ::thread_get_state(m_thread->MachPortNumber(), flavor,
+ (thread_state_t)&m_state.context.gpr, &count));
+}
 DNBLogThreadedIf(
 LOG_THREAD,
-"::thread_get_state (0x%4.4x, %u, &gpr, %u) => 0x%8.8x"
+"::thread_get_state (0x%4.4x, %u (%s), &gpr, %u) => 0x%8.8x"
 "\n\trax = %16.16llx rbx = %16.16llx rcx = %16.16llx rdx = %16.16llx"
 "\n\trdi = %16.16llx rsi = %16.16llx rbp = %16.16llx rsp = %16.16llx"
 "\n\t r8 = %16.16llx  r9 = %16.16llx r10 = %16.16llx r11 = %16.16llx"
 "\n\tr12 = %16.16llx r13 = %16.16llx r14 = %16.16llx r15 = %16.16llx"
 "\n\trip = %16.16llx"
-"\n\tflg = %16.16llx  cs = %16.16llx  fs = %16.16llx  gs = %16.16llx",
-m_thread->MachPortNumber(), x86_THREAD_STATE64,

[Lldb-commits] [lldb] [llvm] [lldb] Change lldb's breakpoint detection behavior [WIP] (PR #105594)

2024-09-13 Thread Jason Molenda via lldb-commits

jasonmolenda wrote:

(1) the armv7/aarch32 step-by-breakpoint fix for lldb-server is merged on 
github main.  
(2) the change to ProcessGDBRemote to recognize "swbreak" and "hwbreak" as a 
breakpoint is merged on github main.
(3) lldb with this patch works fine with the existing debugserver on armv7k 
where we get the breakpoint hit mach exception when we instruction step 
(StopInfoMachException handles it)
(4) dexter has been updated on github main to work with this patch or with old 
lldb stepping

which leaves

(5) Martin's mingw finish bug report
(6) Review Omair's Windows aarch64 hardware breakpoint/watchpoint PR for any 
changes necessary to work with this PR.

https://github.com/llvm/llvm-project/pull/105594
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Removed gdbserver ports map from lldb-server (PR #104238)

2024-09-13 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman updated 
https://github.com/llvm/llvm-project/pull/104238

>From 792cb17f05ded47b152408ac7f4d1de6c986013f Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Fri, 6 Sep 2024 16:12:50 +0400
Subject: [PATCH 1/2] [lldb] Removed gdbserver ports map from lldb-server

Listen to gdbserver-port, accept the connection and run lldb-server gdbserver 
--fd on all platforms.
Parameters --min-gdbserver-port and --max-gdbserver-port are deprecated now.

This is the part 2 of #101283.

Fixes #97537, fixes #101475.
---
 lldb/docs/man/lldb-server.rst |  11 +-
 lldb/docs/resources/qemu-testing.rst  |  19 +-
 .../GDBRemoteCommunicationServerPlatform.cpp  | 287 +
 .../GDBRemoteCommunicationServerPlatform.h|  82 +---
 .../TestPlatformLaunchGDBServer.py|  12 +-
 .../Shell/lldb-server/TestGdbserverPort.test  |   4 -
 lldb/tools/lldb-server/Acceptor.cpp   |  98 -
 lldb/tools/lldb-server/Acceptor.h |  60 ---
 lldb/tools/lldb-server/CMakeLists.txt |   1 -
 lldb/tools/lldb-server/lldb-gdbserver.cpp |  17 +-
 lldb/tools/lldb-server/lldb-platform.cpp  | 391 --
 .../Process/gdb-remote/CMakeLists.txt |   1 -
 .../Process/gdb-remote/PortMapTest.cpp| 115 --
 13 files changed, 391 insertions(+), 707 deletions(-)
 delete mode 100644 lldb/test/Shell/lldb-server/TestGdbserverPort.test
 delete mode 100644 lldb/tools/lldb-server/Acceptor.cpp
 delete mode 100644 lldb/tools/lldb-server/Acceptor.h
 delete mode 100644 lldb/unittests/Process/gdb-remote/PortMapTest.cpp

diff --git a/lldb/docs/man/lldb-server.rst b/lldb/docs/man/lldb-server.rst
index a67c00b305f6d2..31f5360df5e23e 100644
--- a/lldb/docs/man/lldb-server.rst
+++ b/lldb/docs/man/lldb-server.rst
@@ -147,15 +147,8 @@ GDB-SERVER CONNECTIONS
 
 .. option:: --gdbserver-port 
 
- Define a port to be used for gdb-server connections. Can be specified multiple
- times to allow multiple ports. Has no effect if --min-gdbserver-port
- and --max-gdbserver-port are specified.
-
-.. option:: --min-gdbserver-port 
-.. option:: --max-gdbserver-port 
-
- Specify the range of ports that can be used for gdb-server connections. Both
- options need to be specified simultaneously. Overrides --gdbserver-port.
+ Define a port to be used for gdb-server connections. This port is used for
+ multiple connections.
 
 .. option:: --port-offset 
 
diff --git a/lldb/docs/resources/qemu-testing.rst 
b/lldb/docs/resources/qemu-testing.rst
index 51a30b11717a87..e102f84a1d31f4 100644
--- a/lldb/docs/resources/qemu-testing.rst
+++ b/lldb/docs/resources/qemu-testing.rst
@@ -149,7 +149,6 @@ to the host (refer to QEMU's manuals for the specific 
options).
 * At least one to connect to the intial ``lldb-server``.
 * One more if you want to use ``lldb-server`` in ``platform mode``, and have it
   start a ``gdbserver`` instance for you.
-* A bunch more if you want to run tests against the ``lldb-server`` platform.
 
 If you are doing either of the latter 2 you should also restrict what ports
 ``lldb-server tries`` to use, otherwise it will randomly pick one that is 
almost
@@ -157,22 +156,14 @@ certainly not forwarded. An example of this is shown 
below.
 
 ::
 
-  $ lldb-server plaform --server --listen 0.0.0.0:54321 \
---min-gdbserver-port 49140 --max-gdbserver-port 49150
+  $ lldb-server plaform --server --listen 0.0.0.0:54321 --gdbserver-port 49140
 
 The result of this is that:
 
 * ``lldb-server`` platform mode listens externally on port ``54321``.
 
-* When it is asked to start a new gdbserver mode instance, it will use a port
-  in the range ``49140`` to ``49150``.
+* When it is asked to start a new gdbserver mode instance, it will use the port
+  ``49140``.
 
-Your VM configuration should have ports ``54321``, and ``49140`` to ``49150``
-forwarded for this to work.
-
-.. note::
-  These options are used to create a "port map" within ``lldb-server``.
-  Unfortunately this map is not cleaned up on Windows on connection close,
-  and across a few uses you may run out of valid ports. To work around this,
-  restart the platform every so often, especially after running a set of tests.
-  This is tracked here: https://github.com/llvm/llvm-project/issues/90923
+Your VM configuration should have ports ``54321`` and ``49140`` forwarded for
+this to work.
diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index c60a83d351ba09..647130b2984aac 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -44,79 +44,14 @@ using namespace lldb;
 using namespace lldb_private::process_gdb_remote;
 using namespace lldb_private;
 
-GDBRemoteCommunicationServerPlatform::PortMap::PortMap(uint16_t min_port,
-   

[Lldb-commits] [lldb] [lldb] Introduce an always-on system log category/channel (PR #108495)

2024-09-13 Thread Adrian Prantl via lldb-commits


@@ -31,6 +31,22 @@ class ProcessInstanceInfo;
 class ProcessInstanceInfoMatch;
 typedef std::vector ProcessInstanceInfoList;
 
+// Always on system log category and channel.

adrian-prantl wrote:

I think we should have a comment that explains what this channel is supposed to 
be used for?

https://github.com/llvm/llvm-project/pull/108495
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-13 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere approved this pull request.

Unless someone steps up to maintain these tests I'm fine with removing them.

https://github.com/llvm/llvm-project/pull/108629
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-13 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl approved this pull request.

Looks like a nice thing to have conceptually, but if it's not maintained and 
not functional ...

https://github.com/llvm/llvm-project/pull/108629
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

These benchmarks don't get run as part of the regular API test-suite. And I'm 
not aware of any CI running this. Also, I haven't quite managed to actually run 
them locally using the `bench.py` script. It looks like these are obsolete, so 
I'm proposing to remove the infrastructure around it entirely.

If anyone does know of a use for these do let me know.

---

Patch is 33.82 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/108629.diff


19 Files Affected:

- (removed) lldb/packages/Python/lldbsuite/test/bench.py (-77) 
- (modified) lldb/packages/Python/lldbsuite/test/decorators.py (-12) 
- (removed) lldb/test/API/benchmarks/continue/Makefile (-3) 
- (removed) lldb/test/API/benchmarks/continue/TestBenchmarkContinue.py (-65) 
- (removed) lldb/test/API/benchmarks/continue/main.cpp (-36) 
- (removed) lldb/test/API/benchmarks/expression/Makefile (-3) 
- (removed) lldb/test/API/benchmarks/expression/TestExpressionCmd.py (-74) 
- (removed) lldb/test/API/benchmarks/expression/TestRepeatedExprs.py (-131) 
- (removed) lldb/test/API/benchmarks/expression/main.cpp (-43) 
- (removed) 
lldb/test/API/benchmarks/frame_variable/TestFrameVariableResponse.py (-68) 
- (removed) lldb/test/API/benchmarks/libcxxlist/Makefile (-3) 
- (removed) lldb/test/API/benchmarks/libcxxlist/TestBenchmarkLibcxxList.py 
(-58) 
- (removed) lldb/test/API/benchmarks/libcxxlist/main.cpp (-11) 
- (removed) lldb/test/API/benchmarks/libcxxmap/Makefile (-3) 
- (removed) lldb/test/API/benchmarks/libcxxmap/TestBenchmarkLibcxxMap.py (-58) 
- (removed) lldb/test/API/benchmarks/libcxxmap/main.cpp (-11) 
- (removed) lldb/test/API/benchmarks/startup/TestStartupDelays.py (-78) 
- (removed) lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py (-69) 
- (removed) 
lldb/test/API/benchmarks/turnaround/TestCompileRunToBreakpointTurnaround.py 
(-122) 


``diff
diff --git a/lldb/packages/Python/lldbsuite/test/bench.py 
b/lldb/packages/Python/lldbsuite/test/bench.py
deleted file mode 100644
index 1a11b3ef4f0e64..00
--- a/lldb/packages/Python/lldbsuite/test/bench.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-
-"""
-A simple bench runner which delegates to the ./dotest.py test driver to run the
-benchmarks defined in the list named 'benches'.
-
-You need to hand edit 'benches' to modify/change the command lines passed to 
the
-test driver.
-
-Use the following to get only the benchmark results in your terminal output:
-
-./bench.py -e /Volumes/data/lldb/svn/regression/build/Debug/lldb -x '-F 
Driver::MainLoop()' 2>&1 | grep -P '^lldb.*benchmark:'
-"""
-
-import os
-from optparse import OptionParser
-
-# dotest.py invocation with no '-e exe-path' uses lldb as the inferior program,
-# unless there is a mentioning of custom executable program.
-benches = [
-# Measure startup delays creating a target, setting a breakpoint, and run
-# to breakpoint stop.
-"./dotest.py -v +b %E %X -n -p TestStartupDelays.py",
-# Measure 'frame variable' response after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestFrameVariableResponse.py",
-# Measure stepping speed after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestSteppingSpeed.py",
-# Measure expression cmd response with a simple custom executable program.
-"./dotest.py +b -n -p TestExpressionCmd.py",
-# Attach to a spawned process then run disassembly benchmarks.
-"./dotest.py -v +b -n %E -p TestDoAttachThenDisassembly.py",
-]
-
-
-def main():
-"""Read the items from 'benches' and run the command line one by one."""
-parser = OptionParser(
-usage="""\
-%prog [options]
-Run the standard benchmarks defined in the list named 'benches'.\
-"""
-)
-parser.add_option(
-"-e",
-"--executable",
-type="string",
-action="store",
-dest="exe",
-help="The target program launched by lldb.",
-)
-parser.add_option(
-"-x",
-"--breakpoint-spec",
-type="string",
-action="store",
-dest="break_spec",
-help="The lldb breakpoint spec for the target program.",
-)
-
-# Parses the options, if any.
-opts, args = parser.parse_args()
-
-print("Starting bench runner")
-
-for item in benches:
-command = item.replace("%E", '-e "%s"' % opts.exe if opts.exe else "")
-command = command.replace(
-"%X", '-x "%s"' % opts.break_spec if opts.break_spec else ""
-)
-print("Running %s" % (command))
-os.system(command)
-
-print("Bench runner done.")
-
-
-if __name__ == "__main__":
-main()
diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py 
b/lldb/packages/Python/lldbsuite/test/decorators.py
index 834f01aaa61e6b..34319e203a3177 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/ll

[Lldb-commits] [lldb] [lldb][test] Remove benchmark API tests (PR #108629)

2024-09-13 Thread Michael Buch via lldb-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/108629

These benchmarks don't get run as part of the regular API test-suite. And I'm 
not aware of any CI running this. Also, I haven't quite managed to actually run 
them locally using the `bench.py` script. It looks like these are obsolete, so 
I'm proposing to remove the infrastructure around it entirely.

If anyone does know of a use for these do let me know.

>From c58fd8c9a3e7f568cc9fb451297a840b52ccb2b4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 13 Sep 2024 20:07:16 +0100
Subject: [PATCH] [lldb][test] Remove benchmark API tests

These benchmarks don't get run as part of the regular
API test-suite. And I'm not aware of any CI running this.
Also, I haven't quite managed to actually run them locally
using the `bench.py` script. It looks like these are obsolete,
so I'm proposing to remove the infrastructure around it entirely.

If anyone does know of a use for these do let me know.
---
 lldb/packages/Python/lldbsuite/test/bench.py  |  77 --
 .../Python/lldbsuite/test/decorators.py   |  12 --
 lldb/test/API/benchmarks/continue/Makefile|   3 -
 .../continue/TestBenchmarkContinue.py |  65 -
 lldb/test/API/benchmarks/continue/main.cpp|  36 -
 lldb/test/API/benchmarks/expression/Makefile  |   3 -
 .../expression/TestExpressionCmd.py   |  74 --
 .../expression/TestRepeatedExprs.py   | 131 --
 lldb/test/API/benchmarks/expression/main.cpp  |  43 --
 .../TestFrameVariableResponse.py  |  68 -
 lldb/test/API/benchmarks/libcxxlist/Makefile  |   3 -
 .../libcxxlist/TestBenchmarkLibcxxList.py |  58 
 lldb/test/API/benchmarks/libcxxlist/main.cpp  |  11 --
 lldb/test/API/benchmarks/libcxxmap/Makefile   |   3 -
 .../libcxxmap/TestBenchmarkLibcxxMap.py   |  58 
 lldb/test/API/benchmarks/libcxxmap/main.cpp   |  11 --
 .../benchmarks/startup/TestStartupDelays.py   |  78 ---
 .../benchmarks/stepping/TestSteppingSpeed.py  |  69 -
 .../TestCompileRunToBreakpointTurnaround.py   | 122 
 19 files changed, 925 deletions(-)
 delete mode 100644 lldb/packages/Python/lldbsuite/test/bench.py
 delete mode 100644 lldb/test/API/benchmarks/continue/Makefile
 delete mode 100644 lldb/test/API/benchmarks/continue/TestBenchmarkContinue.py
 delete mode 100644 lldb/test/API/benchmarks/continue/main.cpp
 delete mode 100644 lldb/test/API/benchmarks/expression/Makefile
 delete mode 100644 lldb/test/API/benchmarks/expression/TestExpressionCmd.py
 delete mode 100644 lldb/test/API/benchmarks/expression/TestRepeatedExprs.py
 delete mode 100644 lldb/test/API/benchmarks/expression/main.cpp
 delete mode 100644 
lldb/test/API/benchmarks/frame_variable/TestFrameVariableResponse.py
 delete mode 100644 lldb/test/API/benchmarks/libcxxlist/Makefile
 delete mode 100644 
lldb/test/API/benchmarks/libcxxlist/TestBenchmarkLibcxxList.py
 delete mode 100644 lldb/test/API/benchmarks/libcxxlist/main.cpp
 delete mode 100644 lldb/test/API/benchmarks/libcxxmap/Makefile
 delete mode 100644 lldb/test/API/benchmarks/libcxxmap/TestBenchmarkLibcxxMap.py
 delete mode 100644 lldb/test/API/benchmarks/libcxxmap/main.cpp
 delete mode 100644 lldb/test/API/benchmarks/startup/TestStartupDelays.py
 delete mode 100644 lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
 delete mode 100644 
lldb/test/API/benchmarks/turnaround/TestCompileRunToBreakpointTurnaround.py

diff --git a/lldb/packages/Python/lldbsuite/test/bench.py 
b/lldb/packages/Python/lldbsuite/test/bench.py
deleted file mode 100644
index 1a11b3ef4f0e64..00
--- a/lldb/packages/Python/lldbsuite/test/bench.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/env python
-
-"""
-A simple bench runner which delegates to the ./dotest.py test driver to run the
-benchmarks defined in the list named 'benches'.
-
-You need to hand edit 'benches' to modify/change the command lines passed to 
the
-test driver.
-
-Use the following to get only the benchmark results in your terminal output:
-
-./bench.py -e /Volumes/data/lldb/svn/regression/build/Debug/lldb -x '-F 
Driver::MainLoop()' 2>&1 | grep -P '^lldb.*benchmark:'
-"""
-
-import os
-from optparse import OptionParser
-
-# dotest.py invocation with no '-e exe-path' uses lldb as the inferior program,
-# unless there is a mentioning of custom executable program.
-benches = [
-# Measure startup delays creating a target, setting a breakpoint, and run
-# to breakpoint stop.
-"./dotest.py -v +b %E %X -n -p TestStartupDelays.py",
-# Measure 'frame variable' response after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestFrameVariableResponse.py",
-# Measure stepping speed after stopping at a breakpoint.
-"./dotest.py -v +b %E %X -n -p TestSteppingSpeed.py",
-# Measure expression cmd response with a simple custom executable program.
-"./dotest.py +b -n -p TestExpressionCmd.py",
-

[Lldb-commits] [lldb] [lldb] Emit signpost intervals for progress events (NFC) (PR #108498)

2024-09-13 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere edited 
https://github.com/llvm/llvm-project/pull/108498
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Make env and source map dictionaries #95137 (PR #106919)

2024-09-13 Thread via lldb-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/106919

>From d2bddca1753b4c960895f51d7eb80b6efa7dc986 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 1 Sep 2024 17:26:11 +0100
Subject: [PATCH 1/9] [lldb-dap] Make environment option an object

---
 .../tools/lldb-dap/launch/TestDAP_launch.py   |  4 +-
 lldb/tools/lldb-dap/JSONUtils.cpp | 40 ---
 lldb/tools/lldb-dap/JSONUtils.h   | 22 ++
 lldb/tools/lldb-dap/README.md |  5 ++-
 lldb/tools/lldb-dap/lldb-dap.cpp  |  8 +++-
 lldb/tools/lldb-dap/package.json  | 11 +++--
 6 files changed, 77 insertions(+), 13 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py 
b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
index a16f2da3c4df71..6b9993a2548b8d 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
@@ -229,7 +229,7 @@ def test_environment(self):
 Tests launch of a simple program with environment variables
 """
 program = self.getBuildArtifact("a.out")
-env = ["NO_VALUE", "WITH_VALUE=BAR", "EMPTY_VALUE=", "SPACE=Hello 
World"]
+env = {"NO_VALUE": "", "WITH_VALUE":"BAR", "EMPTY_VALUE": "", "SPACE": 
"Hello World"}
 self.build_and_launch(program, env=env)
 self.continue_to_exit()
 
@@ -242,7 +242,7 @@ def test_environment(self):
 lines.pop(0)
 # Make sure each environment variable in "env" is actually set in the
 # program environment that was printed to STDOUT
-for var in env:
+for var in env.keys():
 found = False
 for program_var in lines:
 if var in program_var:
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 7338e7cf41eb03..29b3ad490af0b6 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -136,6 +136,31 @@ std::vector GetStrings(const 
llvm::json::Object *obj,
   return strs;
 }
 
+std::unordered_map
+GetStringMap(const llvm::json::Object &obj, llvm::StringRef key) {
+  std::unordered_map strs;
+  const auto *const json_object = obj.getObject(key);
+  if (!json_object)
+return strs;
+
+  for (const auto &[key, value] : *json_object) {
+switch (value.kind()) {
+case llvm::json::Value::String:
+  strs.emplace(key.str(), value.getAsString()->str());
+  break;
+case llvm::json::Value::Number:
+case llvm::json::Value::Boolean:
+  strs.emplace(key.str(), llvm::to_string(value));
+  break;
+case llvm::json::Value::Null:
+case llvm::json::Value::Object:
+case llvm::json::Value::Array:
+  break;
+}
+  }
+  return strs;
+}
+
 static bool IsClassStructOrUnionType(lldb::SBType t) {
   return (t.GetTypeClass() & (lldb::eTypeClassUnion | lldb::eTypeClassStruct |
   lldb::eTypeClassArray)) != 0;
@@ -1370,13 +1395,16 @@ CreateRunInTerminalReverseRequest(const 
llvm::json::Object &launch_request,
   if (!cwd.empty())
 run_in_terminal_args.try_emplace("cwd", cwd);
 
-  // We need to convert the input list of environments variables into a
-  // dictionary
-  std::vector envs = GetStrings(launch_request_arguments, "env");
+  std::unordered_map envMap =
+  GetStringMap(*launch_request_arguments, "env");
   llvm::json::Object environment;
-  for (const std::string &env : envs) {
-size_t index = env.find('=');
-environment.try_emplace(env.substr(0, index), env.substr(index + 1));
+  for (const auto &[key, value] : envMap) {
+if (key.empty())
+  g_dap.SendOutput(OutputType::Stderr,
+   "empty environment variable for value: \"" + value +
+   '\"');
+else
+  environment.try_emplace(key, value);
   }
   run_in_terminal_args.try_emplace("env",
llvm::json::Value(std::move(environment)));
diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h
index b6356630b72682..60d5db06560657 100644
--- a/lldb/tools/lldb-dap/JSONUtils.h
+++ b/lldb/tools/lldb-dap/JSONUtils.h
@@ -16,6 +16,7 @@
 #include "llvm/Support/JSON.h"
 #include 
 #include 
+#include 
 
 namespace lldb_dap {
 
@@ -152,6 +153,27 @@ bool ObjectContainsKey(const llvm::json::Object &obj, 
llvm::StringRef key);
 std::vector GetStrings(const llvm::json::Object *obj,
 llvm::StringRef key);
 
+/// Extract an object of key value strings for the specified key from an 
object.
+///
+/// String values in the object will be extracted without any quotes
+/// around them. Numbers and Booleans will be converted into
+/// strings. Any NULL, array or objects values in the array will be
+/// ignored.
+///
+/// \param[in] obj
+/// A JSON object that we will attempt to extract the array from
+///
+/// \param[in] key
+/// The key to use when extr

[Lldb-commits] [lldb] [lldb] Removed gdbserver ports map from lldb-server (PR #104238)

2024-09-13 Thread Dmitry Vasilyev via lldb-commits

https://github.com/slydiman updated 
https://github.com/llvm/llvm-project/pull/104238

>From 792cb17f05ded47b152408ac7f4d1de6c986013f Mon Sep 17 00:00:00 2001
From: Dmitry Vasilyev 
Date: Fri, 6 Sep 2024 16:12:50 +0400
Subject: [PATCH] [lldb] Removed gdbserver ports map from lldb-server

Listen to gdbserver-port, accept the connection and run lldb-server gdbserver 
--fd on all platforms.
Parameters --min-gdbserver-port and --max-gdbserver-port are deprecated now.

This is the part 2 of #101283.

Fixes #97537, fixes #101475.
---
 lldb/docs/man/lldb-server.rst |  11 +-
 lldb/docs/resources/qemu-testing.rst  |  19 +-
 .../GDBRemoteCommunicationServerPlatform.cpp  | 287 +
 .../GDBRemoteCommunicationServerPlatform.h|  82 +---
 .../TestPlatformLaunchGDBServer.py|  12 +-
 .../Shell/lldb-server/TestGdbserverPort.test  |   4 -
 lldb/tools/lldb-server/Acceptor.cpp   |  98 -
 lldb/tools/lldb-server/Acceptor.h |  60 ---
 lldb/tools/lldb-server/CMakeLists.txt |   1 -
 lldb/tools/lldb-server/lldb-gdbserver.cpp |  17 +-
 lldb/tools/lldb-server/lldb-platform.cpp  | 391 --
 .../Process/gdb-remote/CMakeLists.txt |   1 -
 .../Process/gdb-remote/PortMapTest.cpp| 115 --
 13 files changed, 391 insertions(+), 707 deletions(-)
 delete mode 100644 lldb/test/Shell/lldb-server/TestGdbserverPort.test
 delete mode 100644 lldb/tools/lldb-server/Acceptor.cpp
 delete mode 100644 lldb/tools/lldb-server/Acceptor.h
 delete mode 100644 lldb/unittests/Process/gdb-remote/PortMapTest.cpp

diff --git a/lldb/docs/man/lldb-server.rst b/lldb/docs/man/lldb-server.rst
index a67c00b305f6d2..31f5360df5e23e 100644
--- a/lldb/docs/man/lldb-server.rst
+++ b/lldb/docs/man/lldb-server.rst
@@ -147,15 +147,8 @@ GDB-SERVER CONNECTIONS
 
 .. option:: --gdbserver-port 
 
- Define a port to be used for gdb-server connections. Can be specified multiple
- times to allow multiple ports. Has no effect if --min-gdbserver-port
- and --max-gdbserver-port are specified.
-
-.. option:: --min-gdbserver-port 
-.. option:: --max-gdbserver-port 
-
- Specify the range of ports that can be used for gdb-server connections. Both
- options need to be specified simultaneously. Overrides --gdbserver-port.
+ Define a port to be used for gdb-server connections. This port is used for
+ multiple connections.
 
 .. option:: --port-offset 
 
diff --git a/lldb/docs/resources/qemu-testing.rst 
b/lldb/docs/resources/qemu-testing.rst
index 51a30b11717a87..e102f84a1d31f4 100644
--- a/lldb/docs/resources/qemu-testing.rst
+++ b/lldb/docs/resources/qemu-testing.rst
@@ -149,7 +149,6 @@ to the host (refer to QEMU's manuals for the specific 
options).
 * At least one to connect to the intial ``lldb-server``.
 * One more if you want to use ``lldb-server`` in ``platform mode``, and have it
   start a ``gdbserver`` instance for you.
-* A bunch more if you want to run tests against the ``lldb-server`` platform.
 
 If you are doing either of the latter 2 you should also restrict what ports
 ``lldb-server tries`` to use, otherwise it will randomly pick one that is 
almost
@@ -157,22 +156,14 @@ certainly not forwarded. An example of this is shown 
below.
 
 ::
 
-  $ lldb-server plaform --server --listen 0.0.0.0:54321 \
---min-gdbserver-port 49140 --max-gdbserver-port 49150
+  $ lldb-server plaform --server --listen 0.0.0.0:54321 --gdbserver-port 49140
 
 The result of this is that:
 
 * ``lldb-server`` platform mode listens externally on port ``54321``.
 
-* When it is asked to start a new gdbserver mode instance, it will use a port
-  in the range ``49140`` to ``49150``.
+* When it is asked to start a new gdbserver mode instance, it will use the port
+  ``49140``.
 
-Your VM configuration should have ports ``54321``, and ``49140`` to ``49150``
-forwarded for this to work.
-
-.. note::
-  These options are used to create a "port map" within ``lldb-server``.
-  Unfortunately this map is not cleaned up on Windows on connection close,
-  and across a few uses you may run out of valid ports. To work around this,
-  restart the platform every so often, especially after running a set of tests.
-  This is tracked here: https://github.com/llvm/llvm-project/issues/90923
+Your VM configuration should have ports ``54321`` and ``49140`` forwarded for
+this to work.
diff --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index c60a83d351ba09..647130b2984aac 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -44,79 +44,14 @@ using namespace lldb;
 using namespace lldb_private::process_gdb_remote;
 using namespace lldb_private;
 
-GDBRemoteCommunicationServerPlatform::PortMap::PortMap(uint16_t min_port,
-   

[Lldb-commits] [lldb] [lldb] Removed gdbserver ports map from lldb-server (PR #104238)

2024-09-13 Thread Dmitry Vasilyev via lldb-commits

slydiman wrote:

> I do want it. I don't think it's necessary to transfer the type of the 
> socket, as that can be determined by inspecting the socket FD 
> (getsockopt(SO_DOMAIN/SO_PROTOCOL)).

Oh, I expected this. We can determine non-tcp by missing or 0 gdb port. But it 
is impossible to separare ProtocolUnixDomain and ProtocolUnixAbstract. The 
difference is only the implementation of Socket::GetNameOffset().
getsockopt(SO_DOMAIN/SO_PROTOCOL) will not help.
We can provide `--listen same_host_port ` to the child process additionally to 
`--child-platform-fd X`  and move the parsing of the listen parameter to the 
beginning to get the correct protocol.
I will make the second commit with the version where I will mux functions 
platform_tcp() and platform_named() back together, complicated and hard as 
possible.

https://github.com/llvm/llvm-project/pull/104238
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created (PR #106791)

2024-09-13 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/106791
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0351dc5 - [lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as symbols are created (#106791)

2024-09-13 Thread via lldb-commits

Author: Alex Langford
Date: 2024-09-13T10:33:43-07:00
New Revision: 0351dc522a25df0473a63b414a5bfde5814d3dc3

URL: 
https://github.com/llvm/llvm-project/commit/0351dc522a25df0473a63b414a5bfde5814d3dc3
DIFF: 
https://github.com/llvm/llvm-project/commit/0351dc522a25df0473a63b414a5bfde5814d3dc3.diff

LOG: [lldb] Do not use LC_FUNCTION_STARTS data to determine symbol size as 
symbols are created (#106791)

Summary:
This improves the performance of ObjectFileMacho::ParseSymtab by
removing eager and expensive work in favor of doing it later in a
less-expensive fashion.

Experiment:
My goal was to understand LLDB's startup time.
First, I produced a Debug build of LLDB (no dSYM) and a
Release+NoAsserts build of LLDB. The Release build debugged the Debug
build as it debugged a small C++ program. I found that
ObjectFileMachO::ParseSymtab accounted for somewhere between 1.2 and 1.3
seconds consistently. After applying this change, I consistently
measured a reduction of approximately 100ms, putting the time closer to
1.1s and 1.2s on average.

Background:
ObjectFileMachO::ParseSymtab will incrementally create symbols by
parsing nlist entries from the symtab section of a MachO binary. As it
does this, it eagerly tries to determine the size of symbols (e.g. how
long a function is) using LC_FUNCTION_STARTS data (or eh_frame if
LC_FUNCTION_STARTS is unavailable). Concretely, this is done by
performing a binary search on the function starts array and calculating
the distance to the next function or the end of the section (whichever
is smaller).

However, this work is unnecessary for 2 reasons:
1. If you have debug symbol entries (i.e. STABs), the size of a function
is usually stored right after the function's entry. Performing this work
right before parsing the next entry is unnecessary work.
2. Calculating symbol sizes for symbols of size 0 is already performed
in `Symtab::InitAddressIndexes` after all the symbols are added to the
Symtab. It also does this more efficiently by walking over a list of
symbols sorted by address, so the work to calculate the size per symbol
is constant instead of O(log n).

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 06da83e26a26a5..c36748963db37b 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,7 +3768,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
-  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4354,47 +4353,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
-if (symbol_byte_size == 0 && function_starts_count > 0) {
-  addr_t symbol_lookup_file_addr = nlist.n_value;
-  // Do an exact address match for non-ARM addresses, else get the
-  // closest since the symbol might be a thumb symbol which has an
-  // address with bit zero set.
-  FunctionStarts::Entry *func_start_entry =
-  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
-  if (is_arm && func_start_entry) {
-// Verify that the function start address is the symbol address
-// (ARM) or the symbol address + 1 (thumb).
-if (func_start_entry->addr != symbol_lookup_file_addr &&
-func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
-  // Not the right entry, NULL it out...
-  func_start_entry = nullptr;
-}
-  }
-  if (func_start_entry) {
-func_start_entry->data = true;
-
-addr_t symbol_file_addr = func_start_entry->addr;
-if (is_arm)
-  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-
-const FunctionStarts::Entry *next_func_start_entry =
-function_starts.FindNextEntry(func_start_entry);
-const addr_t section_end_file_addr =
-section_file_addr + symbol_section->GetByteSize();
-if (next_func_start_entry) {
-  addr_t next_symbol_file_addr = next_func_start_entry->addr;
-  // Be sure the clear the Thumb address bit when we calculate the
-  // size from the current and next address
-  if (is_arm)
-next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-  symbol_byte_size = std::min(
-  next_symbol_file_addr - symbol_file_addr,
-  section_end_file_addr - symbol_file_addr);
-   

[Lldb-commits] [lldb] Avoid expression evaluation in libStdC++ std::vector synthetic children provider (PR #108414)

2024-09-13 Thread via lldb-commits

https://github.com/jeffreytan81 closed 
https://github.com/llvm/llvm-project/pull/108414
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] b6bf27e - Avoid expression evaluation in libStdC++ std::vector synthetic children provider (#108414)

2024-09-13 Thread via lldb-commits

Author: jeffreytan81
Date: 2024-09-13T10:26:01-07:00
New Revision: b6bf27ef3c179eefd805f39aa681705fc980ceed

URL: 
https://github.com/llvm/llvm-project/commit/b6bf27ef3c179eefd805f39aa681705fc980ceed
DIFF: 
https://github.com/llvm/llvm-project/commit/b6bf27ef3c179eefd805f39aa681705fc980ceed.diff

LOG: Avoid expression evaluation in libStdC++ std::vector synthetic 
children provider  (#108414)

Our customers is reporting a serious performance issue (expanding a this
pointer takes 70 seconds in VSCode) in a specific execution context.

Profiling shows the hot path is triggered by an expression evaluation
from libStdC++ synthetic children provider for `std::vector` since
it uses `CreateValueFromExpression()`.

This PR added a new `SBValue::CreateBoolValue()` API and switch
`std::vector` synthetic children provider to use the new API
without performing expression evaluation.

Note: there might be other cases of `CreateValueFromExpression()` in our
summary/synthetic children providers which I will sweep through in later
PRs.

With this PR, the customer's scenario reduces from 70 seconds => 50
seconds. I will add other PRs to further optimize the remaining 50
seconds (mostly from type/namespace lookup).

Testing:

`test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/TestDataFormatterStdVBool.py`
passes with the PR

-

Co-authored-by: jeffreytan81 

Added: 


Modified: 
lldb/examples/synthetic/gnu_libstdcpp.py
lldb/include/lldb/API/SBValue.h
lldb/source/API/SBValue.cpp

Removed: 




diff  --git a/lldb/examples/synthetic/gnu_libstdcpp.py 
b/lldb/examples/synthetic/gnu_libstdcpp.py
index d98495b8a9df38..a6605a7a7eb5b3 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -473,11 +473,7 @@ def get_child_at_index(self, index):
 "[" + str(index) + "]", element_offset, element_type
 )
 bit = element.GetValueAsUnsigned(0) & (1 << bit_offset)
-if bit != 0:
-value_expr = "(bool)true"
-else:
-value_expr = "(bool)false"
-return self.valobj.CreateValueFromExpression("[%d]" % index, 
value_expr)
+return self.valobj.CreateBoolValue("[%d]" % index, bool(bit))
 
 def update(self):
 try:

diff  --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index bec816fb451844..9090cece80f7ce 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -145,6 +145,8 @@ class LLDB_API SBValue {
   // AddressOf() on the return of this call all return invalid
   lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data,
 lldb::SBType type);
+  // Returned value has no address.
+  lldb::SBValue CreateBoolValue(const char *name, bool value);
 
   /// Get a child value by index from a value.
   ///

diff  --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 273aac5ad47989..e1a31708d46ffb 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -645,6 +645,22 @@ lldb::SBValue SBValue::CreateValueFromData(const char 
*name, SBData data,
   return sb_value;
 }
 
+lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) {
+  LLDB_INSTRUMENT_VA(this, name);
+
+  lldb::SBValue sb_value;
+  lldb::ValueObjectSP new_value_sp;
+  ValueLocker locker;
+  lldb::ValueObjectSP value_sp(GetSP(locker));
+  lldb::TargetSP target_sp = m_opaque_sp->GetTargetSP();
+  if (value_sp && target_sp) {
+new_value_sp =
+ValueObject::CreateValueObjectFromBool(target_sp, value, name);
+  }
+  sb_value.SetSP(new_value_sp);
+  return sb_value;
+}
+
 SBValue SBValue::GetChildAtIndex(uint32_t idx) {
   LLDB_INSTRUMENT_VA(this, idx);
 



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Emit signpost intervals for progress events (NFC) (PR #108498)

2024-09-13 Thread Alex Langford via lldb-commits

https://github.com/bulbazord approved this pull request.


https://github.com/llvm/llvm-project/pull/108498
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Add a comment in the SB API doc about keeping the SB API's lightweight. (PR #108462)

2024-09-13 Thread via lldb-commits

https://github.com/jimingham closed 
https://github.com/llvm/llvm-project/pull/108462
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 02d8813 - Add a comment in the SB API doc about keeping the SB API's lightweight. (#108462)

2024-09-13 Thread via lldb-commits

Author: jimingham
Date: 2024-09-13T10:18:03-07:00
New Revision: 02d8813820b1ebf3fae6993e677db269f0077272

URL: 
https://github.com/llvm/llvm-project/commit/02d8813820b1ebf3fae6993e677db269f0077272
DIFF: 
https://github.com/llvm/llvm-project/commit/02d8813820b1ebf3fae6993e677db269f0077272.diff

LOG: Add a comment in the SB API doc about keeping the SB API's lightweight. 
(#108462)

Added: 


Modified: 
lldb/docs/resources/sbapi.rst

Removed: 




diff  --git a/lldb/docs/resources/sbapi.rst b/lldb/docs/resources/sbapi.rst
index cf32cc6c815581..4ca3909e0f2919 100644
--- a/lldb/docs/resources/sbapi.rst
+++ b/lldb/docs/resources/sbapi.rst
@@ -72,6 +72,17 @@ building the LLDB framework for macOS, the headers are 
processed with
 ``unifdef`` prior to being copied into the framework bundle to remove macros
 involving SWIG.
 
+Another good principle when adding SB API methods is: if you find yourself
+implementing a significant algorithm in the SB API method, you should not do
+that, but instead look for and then add it - if not found - as a method in the
+underlying lldb_private class, and then call that from your SB API method.
+If it was a useful algorithm, it's very likely it already exists
+because the lldb_private code also needed to do it.  And if it doesn't at
+present, if it was a useful thing to do, it's likely someone will later need
+it in lldb_private and then we end up with two implementations of the same
+algorithm.  If we keep the SB API code to just what's needed to manage the SB
+objects and requests, we won't get into this situation.
+
 Lifetime
 
 Many SB API methods will return strings in the form of ``const char *`` values.



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Avoid expression evaluation in libStdC++ std::vector synthetic children provider (PR #108414)

2024-09-13 Thread via lldb-commits


@@ -645,6 +645,23 @@ lldb::SBValue SBValue::CreateValueFromData(const char 
*name, SBData data,
   return sb_value;
 }
 
+lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) {
+  LLDB_INSTRUMENT_VA(this, name);
+
+  lldb::SBValue sb_value;
+  lldb::ValueObjectSP new_value_sp;
+  ValueLocker locker;
+  lldb::ValueObjectSP value_sp(GetSP(locker));
+  lldb::TargetSP target_sp = m_opaque_sp->GetTargetSP();
+  if (value_sp && target_sp) {
+new_value_sp =
+ValueObject::CreateValueObjectFromBool(target_sp, value, name);
+new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);

jimingham wrote:

The problem comes with ValueObjects that live in lldb host memory for instance 
ValueObjectConstResult "history" entities or ValueObject made from 
DataExtractors.  If you have such a result value that includes pointers that 
you copied up from the target memory, even though the ValueObject itself lives 
in lldb host memory, the pointer children still point into the target (are load 
addresses).  This API states that that is true for this ValueObject.

It's not relevant for ValueObjects that can't have pointer children.

https://github.com/llvm/llvm-project/pull/108414
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] Avoid expression evaluation in libStdC++ std::vector synthetic children provider (PR #108414)

2024-09-13 Thread via lldb-commits

https://github.com/jimingham approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/108414
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][Minidump] Add Multiplatform test to ensure determinism (PR #108602)

2024-09-13 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond updated 
https://github.com/llvm/llvm-project/pull/108602

>From 41bb7f8a13483e55f677d51e049e3d79d763088b Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 13 Sep 2024 09:29:46 -0700
Subject: [PATCH 1/2] Add multiplatform minidump determinism test

---
 .../TestProcessSaveCoreMinidump.py| 39 +++
 1 file changed, 39 insertions(+)

diff --git 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index ccdb6653cf16f8..d4eaa40b13f7ee 100644
--- 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -522,3 +522,42 @@ def minidump_deleted_on_save_failure(self):
 
 finally:
 self.assertTrue(self.dbg.DeleteTarget(target))
+
+def minidump_deterministic_difference(self):
+"""Test that verifies that two minidumps produced are identical."""
+
+self.build()
+exe = self.getBuildArtifact("a.out")
+try:
+target = self.dbg.CreateTarget(exe)
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory()
+)
+self.assertState(process.GetState(), lldb.eStateStopped)
+
+core_styles = [lldb.eSaveCoreStackOnly, lldb.eSaveCoreDirtyOnly, 
lldb.eSaveCoreFull]
+for style in core_styles:
+spec_one = 
lldb.SBFileSpec(self.getBuildArtifact("core.one.dmp"))
+spec_two = 
lldb.SBFileSpec(self.getBuildArtifact("core.two.dmp"))
+options = lldb.SBSaveCoreOptions()
+options.SetOutputFile(spec_one)
+options.SetPluginName("minidump")
+options.SetStyle(style)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+options.SetOutputFile(spec_two)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+
+file_one = None
+file_two = None
+with open(spec_one.GetFileName(), mode='rb') as file: # b is 
important -> binary
+file_one = file.read()
+with open(spec_two.GetFileName(), mode='rb') as file:
+file_two = file.read()
+self.assertEqual(file_one, file_two)
+self.assertTrue(os.unlink(spec_one.GetFileName()))
+self.assertTrue(os.unlink(spec_two.GetFileName()))
+
+finally:
+self.assertTrue(self.dbg.DeleteTarget(target))

>From b52d9e4b80a35c3f1e58d53b7134b01e5b44bf30 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 13 Sep 2024 10:08:51 -0700
Subject: [PATCH 2/2] Comment cleanup

---
 .../TestProcessSaveCoreMinidump.py   | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index d4eaa40b13f7ee..e994dd75645400 100644
--- 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -535,7 +535,11 @@ def minidump_deterministic_difference(self):
 )
 self.assertState(process.GetState(), lldb.eStateStopped)
 
-core_styles = [lldb.eSaveCoreStackOnly, lldb.eSaveCoreDirtyOnly, 
lldb.eSaveCoreFull]
+core_styles = [
+lldb.eSaveCoreStackOnly,
+lldb.eSaveCoreDirtyOnly,
+lldb.eSaveCoreFull,
+]
 for style in core_styles:
 spec_one = 
lldb.SBFileSpec(self.getBuildArtifact("core.one.dmp"))
 spec_two = 
lldb.SBFileSpec(self.getBuildArtifact("core.two.dmp"))
@@ -551,9 +555,11 @@ def minidump_deterministic_difference(self):
 
 file_one = None
 file_two = None
-with open(spec_one.GetFileName(), mode='rb') as file: # b is 
important -> binary
+with open(
+spec_one.GetFileName(), mode="rb"
+) as file:
 file_one = file.read()
-with open(spec_two.GetFileName(), mode='rb') as file:
+with open(spec_two.GetFileName(), mode="rb") as file:
 file_two = file.read()
 self.assertEqual(file_one, file_two)
 self.assertTrue(os.unlink(spec_one.GetFileName()))

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-09-13 Thread Adrian Prantl via lldb-commits


@@ -94,25 +126,36 @@ Status Status::FromErrorStringWithFormat(const char 
*format, ...) {
   return Status(string);
 }
 
-Status Status::FromError(llvm::Error error) { return Status(std::move(error)); 
}
+Status Status::FromExpressionError(lldb::ExpressionResults result,
+   std::string msg) {
+  return Status(llvm::make_error(
+  std::error_code(result, expression_category()), msg));
+}
 
-llvm::Error Status::ToError() const {
-  if (Success())
+/// Creates a deep copy of all known errors and converts all other
+/// errors to a new llvm::StringError.
+static llvm::Error CloneError(const llvm::Error &error) {
+  std::vector> info;
+  llvm::visitErrors(error, [&](const llvm::ErrorInfoBase &error) {
+if (error.isA())
+  info.push_back(static_cast(&error)->Clone());

adrian-prantl wrote:

Ah, I didn't realize that `joinErrors(success(), e) == e`

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Change the implementation of Status to store an llvm::Error (NFC) (PR #106774)

2024-09-13 Thread Adrian Prantl via lldb-commits


@@ -94,25 +126,36 @@ Status Status::FromErrorStringWithFormat(const char 
*format, ...) {
   return Status(string);
 }
 
-Status Status::FromError(llvm::Error error) { return Status(std::move(error)); 
}
+Status Status::FromExpressionError(lldb::ExpressionResults result,
+   std::string msg) {
+  return Status(llvm::make_error(
+  std::error_code(result, expression_category()), msg));
+}
 
-llvm::Error Status::ToError() const {
-  if (Success())
+/// Creates a deep copy of all known errors and converts all other
+/// errors to a new llvm::StringError.
+static llvm::Error CloneError(const llvm::Error &error) {
+  std::vector> info;
+  llvm::visitErrors(error, [&](const llvm::ErrorInfoBase &error) {
+if (error.isA())
+  info.push_back(static_cast(&error)->Clone());

adrian-prantl wrote:

Oh nice. I actually hadn't realized this before.

https://github.com/llvm/llvm-project/pull/106774
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Emit signpost intervals for progress events (NFC) (PR #108498)

2024-09-13 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/108498
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][Minidump] Add Multiplatform test to ensure determinism (PR #108602)

2024-09-13 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
661382f2c07ba464caa0ad0fb8c64c1c3b20e9a4...60b48f98ffa70dbf633f1b9bf935479dbfce59d4
 
lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
``





View the diff from darker here.


``diff
--- TestProcessSaveCoreMinidump.py  2024-09-13 16:29:46.00 +
+++ TestProcessSaveCoreMinidump.py  2024-09-13 16:37:56.432599 +
@@ -533,11 +533,15 @@
 process = target.LaunchSimple(
 None, None, self.get_process_working_directory()
 )
 self.assertState(process.GetState(), lldb.eStateStopped)
 
-core_styles = [lldb.eSaveCoreStackOnly, lldb.eSaveCoreDirtyOnly, 
lldb.eSaveCoreFull]
+core_styles = [
+lldb.eSaveCoreStackOnly,
+lldb.eSaveCoreDirtyOnly,
+lldb.eSaveCoreFull,
+]
 for style in core_styles:
 spec_one = 
lldb.SBFileSpec(self.getBuildArtifact("core.one.dmp"))
 spec_two = 
lldb.SBFileSpec(self.getBuildArtifact("core.two.dmp"))
 options = lldb.SBSaveCoreOptions()
 options.SetOutputFile(spec_one)
@@ -549,13 +553,15 @@
 error = process.SaveCore(options)
 self.assertTrue(error.Success())
 
 file_one = None
 file_two = None
-with open(spec_one.GetFileName(), mode='rb') as file: # b is 
important -> binary
+with open(
+spec_one.GetFileName(), mode="rb"
+) as file:  # b is important -> binary
 file_one = file.read()
-with open(spec_two.GetFileName(), mode='rb') as file:
+with open(spec_two.GetFileName(), mode="rb") as file:
 file_two = file.read()
 self.assertEqual(file_one, file_two)
 self.assertTrue(os.unlink(spec_one.GetFileName()))
 self.assertTrue(os.unlink(spec_two.GetFileName()))
 

``




https://github.com/llvm/llvm-project/pull/108602
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][Minidump] Add Multiplatform test to ensure determinism (PR #108602)

2024-09-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)


Changes

Adds a test that ensures two minidumps produced from the same target are the 
same bytes. Covers the three primary core flavors.

---
Full diff: https://github.com/llvm/llvm-project/pull/108602.diff


1 Files Affected:

- (modified) 
lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 (+39) 


``diff
diff --git 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index ccdb6653cf16f8..d4eaa40b13f7ee 100644
--- 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -522,3 +522,42 @@ def minidump_deleted_on_save_failure(self):
 
 finally:
 self.assertTrue(self.dbg.DeleteTarget(target))
+
+def minidump_deterministic_difference(self):
+"""Test that verifies that two minidumps produced are identical."""
+
+self.build()
+exe = self.getBuildArtifact("a.out")
+try:
+target = self.dbg.CreateTarget(exe)
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory()
+)
+self.assertState(process.GetState(), lldb.eStateStopped)
+
+core_styles = [lldb.eSaveCoreStackOnly, lldb.eSaveCoreDirtyOnly, 
lldb.eSaveCoreFull]
+for style in core_styles:
+spec_one = 
lldb.SBFileSpec(self.getBuildArtifact("core.one.dmp"))
+spec_two = 
lldb.SBFileSpec(self.getBuildArtifact("core.two.dmp"))
+options = lldb.SBSaveCoreOptions()
+options.SetOutputFile(spec_one)
+options.SetPluginName("minidump")
+options.SetStyle(style)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+options.SetOutputFile(spec_two)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+
+file_one = None
+file_two = None
+with open(spec_one.GetFileName(), mode='rb') as file: # b is 
important -> binary
+file_one = file.read()
+with open(spec_two.GetFileName(), mode='rb') as file:
+file_two = file.read()
+self.assertEqual(file_one, file_two)
+self.assertTrue(os.unlink(spec_one.GetFileName()))
+self.assertTrue(os.unlink(spec_two.GetFileName()))
+
+finally:
+self.assertTrue(self.dbg.DeleteTarget(target))

``




https://github.com/llvm/llvm-project/pull/108602
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB][Minidump] Add Multiplatform test to ensure determinism (PR #108602)

2024-09-13 Thread Jacob Lalonde via lldb-commits

https://github.com/Jlalond created 
https://github.com/llvm/llvm-project/pull/108602

Adds a test that ensures two minidumps produced from the same target are the 
same bytes. Covers the three primary core flavors.

>From 60b48f98ffa70dbf633f1b9bf935479dbfce59d4 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Fri, 13 Sep 2024 09:29:46 -0700
Subject: [PATCH] Add Add multiplatform minidump determinism test

---
 .../TestProcessSaveCoreMinidump.py| 39 +++
 1 file changed, 39 insertions(+)

diff --git 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
index ccdb6653cf16f8..d4eaa40b13f7ee 100644
--- 
a/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
+++ 
b/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py
@@ -522,3 +522,42 @@ def minidump_deleted_on_save_failure(self):
 
 finally:
 self.assertTrue(self.dbg.DeleteTarget(target))
+
+def minidump_deterministic_difference(self):
+"""Test that verifies that two minidumps produced are identical."""
+
+self.build()
+exe = self.getBuildArtifact("a.out")
+try:
+target = self.dbg.CreateTarget(exe)
+process = target.LaunchSimple(
+None, None, self.get_process_working_directory()
+)
+self.assertState(process.GetState(), lldb.eStateStopped)
+
+core_styles = [lldb.eSaveCoreStackOnly, lldb.eSaveCoreDirtyOnly, 
lldb.eSaveCoreFull]
+for style in core_styles:
+spec_one = 
lldb.SBFileSpec(self.getBuildArtifact("core.one.dmp"))
+spec_two = 
lldb.SBFileSpec(self.getBuildArtifact("core.two.dmp"))
+options = lldb.SBSaveCoreOptions()
+options.SetOutputFile(spec_one)
+options.SetPluginName("minidump")
+options.SetStyle(style)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+options.SetOutputFile(spec_two)
+error = process.SaveCore(options)
+self.assertTrue(error.Success())
+
+file_one = None
+file_two = None
+with open(spec_one.GetFileName(), mode='rb') as file: # b is 
important -> binary
+file_one = file.read()
+with open(spec_two.GetFileName(), mode='rb') as file:
+file_two = file.read()
+self.assertEqual(file_one, file_two)
+self.assertTrue(os.unlink(spec_one.GetFileName()))
+self.assertTrue(os.unlink(spec_two.GetFileName()))
+
+finally:
+self.assertTrue(self.dbg.DeleteTarget(target))

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-13 Thread via lldb-commits

cmtice wrote:

All reviewer comments have been addressed. Please take another look. Thank you!

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-13 Thread via lldb-commits


@@ -1376,6 +1382,16 @@ void request_evaluate(const llvm::json::Object &request) 
{
 EmplaceSafeString(body, "result", result);
 body.try_emplace("variablesReference", (int64_t)0);
   } else {
+if (context != "hover") {

cmtice wrote:

Done.

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-13 Thread via lldb-commits


@@ -1364,8 +1364,14 @@ void request_evaluate(const llvm::json::Object &request) 
{
   std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
 
-  if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
-   ExpressionContext::Command) {
+  if (context == "repl" &&
+  ((!expression.empty() &&
+   g_dap.DetectExpressionContext(frame, expression) ==
+   ExpressionContext::Command) ||
+   (expression.empty() && g_dap.last_nonempty_var_expression.empty( {

cmtice wrote:

Thank you for the suggestion! Done.

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-13 Thread via lldb-commits


@@ -45,7 +45,8 @@ bool RunLLDBCommands(llvm::StringRef prefix,
   // RunTerminateCommands.
   static std::mutex handle_command_mutex;
   std::lock_guard locker(handle_command_mutex);
-  interp.HandleCommand(command.str().c_str(), result);
+  interp.HandleCommand(command.str().c_str(), result,
+   /* add_to_history */ true);

cmtice wrote:

Done.

https://github.com/llvm/llvm-project/pull/107485
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb-dap] Add feature to remember last non-empty expression. (PR #107485)

2024-09-13 Thread via lldb-commits

https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/107485

>From 15541f354decf80586d590db9f9cb353be04b122 Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 5 Sep 2024 15:51:35 -0700
Subject: [PATCH 1/6] [lldb-dap] Add feature to remember last non-empty
 expression.

Update lldb-dap so if the user just presses return, which sends an
empty expression, it re-evaluates the most recent non-empty
expression/command. Also udpated test to test this case.
---
 lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py | 3 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  | 8 
 2 files changed, 11 insertions(+)

diff --git a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py 
b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
index 29548a835c6919..9ed0fc564268a7 100644
--- a/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
+++ b/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py
@@ -60,7 +60,10 @@ def run_test_evaluate_expressions(
 
 # Expressions at breakpoint 1, which is in main
 self.assertEvaluate("var1", "20")
+# Empty expression should equate to the previous expression.
+self.assertEvaluate("", "20")
 self.assertEvaluate("var2", "21")
+self.assertEvaluate("", "21")
 self.assertEvaluate("static_int", "42")
 self.assertEvaluate("non_static_int", "43")
 self.assertEvaluate("struct1.foo", "15")
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c5c4b09f15622b..a6a701dc2219fa 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1363,6 +1363,14 @@ void request_evaluate(const llvm::json::Object &request) 
{
   lldb::SBFrame frame = g_dap.GetLLDBFrame(*arguments);
   std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
+  static std::string last_nonempty_expression;
+
+  // Remember the last non-empty expression from the user, and use that if
+  // the current expression is empty (i.e. the user hit plain 'return').
+  if (!expression.empty())
+last_nonempty_expression = expression;
+  else
+expression = last_nonempty_expression;
 
   if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
ExpressionContext::Command) {

>From e35928e08f792163dd4886e797bc6de3d16ea6e6 Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Fri, 6 Sep 2024 10:02:18 -0700
Subject: [PATCH 2/6] [lldb] Add feature to remember last non-empty expression

Make last_nonempty_spression part of DAP struct rather than a
static variable.
---
 lldb/tools/lldb-dap/DAP.h| 1 +
 lldb/tools/lldb-dap/lldb-dap.cpp | 5 ++---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index f4fdec6e895ad1..4220c15d3ae70d 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -205,6 +205,7 @@ struct DAP {
   std::string command_escape_prefix = "`";
   lldb::SBFormat frame_format;
   lldb::SBFormat thread_format;
+  std::string last_nonempty_expression;
 
   DAP();
   ~DAP();
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index a6a701dc2219fa..d3728df9183aa1 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -1363,14 +1363,13 @@ void request_evaluate(const llvm::json::Object 
&request) {
   lldb::SBFrame frame = g_dap.GetLLDBFrame(*arguments);
   std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
-  static std::string last_nonempty_expression;
 
   // Remember the last non-empty expression from the user, and use that if
   // the current expression is empty (i.e. the user hit plain 'return').
   if (!expression.empty())
-last_nonempty_expression = expression;
+g_dap.last_nonempty_expression = expression;
   else
-expression = last_nonempty_expression;
+expression = g_dap.last_nonempty_expression;
 
   if (context == "repl" && g_dap.DetectExpressionContext(frame, expression) ==
ExpressionContext::Command) {

>From 616017152f3f0611462e9863273754036b52f7eb Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 12 Sep 2024 10:52:32 -0700
Subject: [PATCH 3/6] [lldb-dap] Add feature to remember last non-empty
 expression

Update to handle commands & variables separately: empty command
expressions are passed to the CommandIntepreter to handle as it
normally does; empty variable expressions are updated to use the last
non-empty variable expression, if the last expression was a variable (not
a command).  Also updated the test case to test these cases properly, and
added a 'memory read' followed by an empty expression, to make sure it
handles that sequence correctly.
---
 .../lldb-dap/evaluate/TestDAP_evaluate.py | 16 +++--
 ...

<    5   6   7   8   9   10   11   12   13   14   >