[Lldb-commits] [lldb] 5658bc4 - [lldb][Linux] Add Control Protection Fault signal (#122917)

2025-01-21 Thread via lldb-commits

Author: David Spickett
Date: 2025-01-21T09:24:41Z
New Revision: 5658bc4ae75497edc5ec7c934931c8681d33fac8

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

LOG: [lldb][Linux] Add Control Protection Fault signal (#122917)

This will be sent by Arm's Guarded Control Stack extension when an
invalid return is executed.

The signal does have an address we could show, but it's the PC at which
the fault occured. The debugger has plenty of ways to show you that
already, so I've left it out.

```
(lldb) c
Process 460 resuming
Process 460 stopped
* thread #1, name = 'test', stop reason = signal SIGSEGV: control protection 
fault
frame #0: 0x00400784 test`main at main.c:57:1
   54 afunc();
   55 printf("return from main\n");
   56 return 0;
-> 57   }
(lldb) dis
<...>
->  0x400784 <+100>: ret
```

The new test case generates the signal by corrupting the link register
then attempting to return. This will work whether we manually enable GCS
or the C library does it for us.

(in the former case you could just return from main and it would fault)

Added: 


Modified: 
lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
lldb/test/API/linux/aarch64/gcs/main.c

Removed: 




diff  --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp 
b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 3f25dbc6abbbe3..eaecc84df15d4c 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -20,6 +20,9 @@
 #ifndef SEGV_MTESERR
 #define SEGV_MTESERR 9
 #endif
+#ifndef SEGV_CPERR
+#define SEGV_CPERR 10
+#endif
 
 #define ADD_SIGCODE(signal_name, signal_value, code_name, code_value, ...) 
\
   static_assert(signal_name == signal_value,   
\
@@ -82,6 +85,7 @@ void LinuxSignals::Reset() {
   ADD_SIGCODE(SIGSEGV, 11, SEGV_BNDERR,  3, "failed address bounds checks", 
SignalCodePrintOption::Bounds);
   ADD_SIGCODE(SIGSEGV, 11, SEGV_MTEAERR, 8, "async tag check fault");
   ADD_SIGCODE(SIGSEGV, 11, SEGV_MTESERR, 9, "sync tag check fault", 
SignalCodePrintOption::Address);
+  ADD_SIGCODE(SIGSEGV, 11, SEGV_CPERR,  10, "control protection fault");
   // Some platforms will occasionally send nonstandard spurious SI_KERNEL
   // codes. One way to get this is via unaligned SIMD loads. Treat it as 
invalid address.
   ADD_SIGCODE(SIGSEGV, 11, SI_KERNEL, 0x80, "invalid address", 
SignalCodePrintOption::Address);

diff  --git a/lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py 
b/lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
index b425c9e548ee51..0928ff8e14e000 100644
--- a/lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
+++ b/lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py
@@ -61,3 +61,25 @@ def test_gcs_region(self):
 
 # Note that we must let the debugee get killed here as it cannot exit
 # cleanly if GCS was manually enabled.
+
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_gcs_fault(self):
+if not self.isAArch64GCS():
+self.skipTest("Target must support GCS.")
+
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
+self.runCmd("run", RUN_SUCCEEDED)
+
+if self.process().GetState() == lldb.eStateExited:
+self.fail("Test program failed to run.")
+
+self.expect(
+"thread list",
+"Expected stopped by SIGSEGV.",
+substrs=[
+"stopped",
+"stop reason = signal SIGSEGV: control protection fault",
+],
+)

diff  --git a/lldb/test/API/linux/aarch64/gcs/main.c 
b/lldb/test/API/linux/aarch64/gcs/main.c
index 9633ed2838f9e8..32a9b07c207436 100644
--- a/lldb/test/API/linux/aarch64/gcs/main.c
+++ b/lldb/test/API/linux/aarch64/gcs/main.c
@@ -36,6 +36,19 @@ unsigned long get_gcs_status() {
   return mode;
 }
 
+void gcs_signal() {
+  // If we enabled GCS manually, then we could just return from main to 
generate
+  // a signal. However, if the C library enabled it, then we'd just exit
+  // normally. Assume the latter, and try to return to some bogus address to
+  // generate the signal.
+  __asm__ __volatile__(
+  // Corrupt the link register. This could be many numbers but 16 is a
+  // nicely aligned value that is unlikely to result in a fault because the
+  // PC is misaligned, which would hide the GCS fault.
+  "add x30, x30, #10\n"
+  "ret\n");
+}
+
 int main() {
   if (!(getauxval(AT_HWCAP2) & HWCAP2_GCS))
 return 1;
@@ -50,5 +63,7 @@ int main() {
   }
 
   // By now we should have one memory region where the GCS is stored.
-  return 0; 

[Lldb-commits] [lldb] [lldb][Linux] Add Control Protection Fault signal (PR #122917)

2025-01-21 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread Pavel Labath via lldb-commits

labath wrote:

Hmm.. could you update the patch description with the text you want the final 
commit to contain. I see that at least the API names have changed during the 
review, but maybe there are other things (?)

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


[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

https://github.com/patryk4815 created 
https://github.com/llvm/llvm-project/pull/123735

When the environment variables `_PYTHON_HOST_PLATFORM` and 
`_PYTHON_SYSCONFIGDATA_NAME` are set, the script 
`bindings/python/get-python-config.py` provides accurate data because the 
`sysconfig` module uses these variables internally. 

It is not well-documented in Python's official documentation and is only 
provided on a best-effort basis.
Some info here: [PEP 720 - Upstream 
Support](https://peps.python.org/pep-0720/#upstream-support).

Adding support for this environment variable in LLDB simplifies 
cross-compilation with Python, even though this functionality is not officially 
documented. Maintainers of various Linux distributions already use these 
environment variables, making it easier to build LLDB with Python support 
across different package distributions (eg: 
https://github.com/NixOS/nixpkgs/pull/375484 ).


>From 1883c703f335d44f5a4cfff8148c8d557ab6af1e Mon Sep 17 00:00:00 2001
From: Patryk Sondej 
Date: Tue, 21 Jan 2025 12:44:44 +0100
Subject: [PATCH] Added support for `_PYTHON_HOST_PLATFORM` and
 `_PYTHON_SYSCONFIGDATA_NAME` environment variables when cross-compiling LLDB
 with Python, https://peps.python.org/pep-0720/#upstream-support

---
 lldb/CMakeLists.txt | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 85ba4fde17418a..d11c68dd5b96af 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -59,8 +59,23 @@ if (LLDB_ENABLE_PYTHON)
   set(cachestring_LLDB_PYTHON_EXT_SUFFIX
 "Filename extension for native code python modules")
 
+  set(LLDB_USE_HOST_PYTHON FALSE)
+  if(NOT CMAKE_CROSSCOMPILING)
+set(LLDB_USE_HOST_PYTHON TRUE)
+  else()
+# Used when cross-compiling LLDB with Python:
+# - `_PYTHON_HOST_PLATFORM`: Specifies the host platform, e.g., 
'linux-x86_64'.
+# - `_PYTHON_SYSCONFIGDATA_NAME`: The name of the Python configuration 
module containing
+#   platform, build, and configuration details (e.g., 
`_sysconfigdata__linux_x86_64-linux-gnu`).
+# See: https://peps.python.org/pep-0720/#upstream-support
+# If both environment variables are defined, we assume host Python can be 
used.
+if(DEFINED ENV{_PYTHON_HOST_PLATFORM} AND DEFINED 
ENV{_PYTHON_SYSCONFIGDATA_NAME})
+  set(LLDB_USE_HOST_PYTHON TRUE)
+endif()
+  endif()
+
   foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH 
LLDB_PYTHON_EXT_SUFFIX)
-if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
+if(NOT DEFINED ${var} AND LLDB_USE_HOST_PYTHON)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}
   ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py

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


[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 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/123735
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (patryk4815)


Changes

When the environment variables `_PYTHON_HOST_PLATFORM` and 
`_PYTHON_SYSCONFIGDATA_NAME` are set, the script 
`bindings/python/get-python-config.py` provides accurate data because the 
`sysconfig` module uses these variables internally. 

It is not well-documented in Python's official documentation and is only 
provided on a best-effort basis.
Some info here: [PEP 720 - Upstream 
Support](https://peps.python.org/pep-0720/#upstream-support).

Adding support for this environment variable in LLDB simplifies 
cross-compilation with Python, even though this functionality is not officially 
documented. Maintainers of various Linux distributions already use these 
environment variables, making it easier to build LLDB with Python support 
across different package distributions (eg: 
https://github.com/NixOS/nixpkgs/pull/375484 ).


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


1 Files Affected:

- (modified) lldb/CMakeLists.txt (+16-1) 


``diff
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 85ba4fde17418a..d11c68dd5b96af 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -59,8 +59,23 @@ if (LLDB_ENABLE_PYTHON)
   set(cachestring_LLDB_PYTHON_EXT_SUFFIX
 "Filename extension for native code python modules")
 
+  set(LLDB_USE_HOST_PYTHON FALSE)
+  if(NOT CMAKE_CROSSCOMPILING)
+set(LLDB_USE_HOST_PYTHON TRUE)
+  else()
+# Used when cross-compiling LLDB with Python:
+# - `_PYTHON_HOST_PLATFORM`: Specifies the host platform, e.g., 
'linux-x86_64'.
+# - `_PYTHON_SYSCONFIGDATA_NAME`: The name of the Python configuration 
module containing
+#   platform, build, and configuration details (e.g., 
`_sysconfigdata__linux_x86_64-linux-gnu`).
+# See: https://peps.python.org/pep-0720/#upstream-support
+# If both environment variables are defined, we assume host Python can be 
used.
+if(DEFINED ENV{_PYTHON_HOST_PLATFORM} AND DEFINED 
ENV{_PYTHON_SYSCONFIGDATA_NAME})
+  set(LLDB_USE_HOST_PYTHON TRUE)
+endif()
+  endif()
+
   foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH 
LLDB_PYTHON_EXT_SUFFIX)
-if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
+if(NOT DEFINED ${var} AND LLDB_USE_HOST_PYTHON)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}
   ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py

``




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


[Lldb-commits] [lldb] aeffc01 - [lldb][DWARFASTParserClang][NFC] Remove redundant local variable

2025-01-21 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2025-01-21T14:33:37Z
New Revision: aeffc01a7247cd95560b0c35b7a2c8d5a434b1f0

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

LOG: [lldb][DWARFASTParserClang][NFC] Remove redundant local variable

Tiny improvement to reviewability of an upcoming refactor.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index fb3af44abfa8d4..68fa1d13943a16 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3127,7 +3127,6 @@ size_t DWARFASTParserClang::ParseChildParameters(
 }
   }
 
-  bool skip = false;
   if (is_artificial) {
 // In order to determine if a C++ member function is "const" we
 // have to look at the const-ness of "this"...
@@ -3150,10 +3149,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
 }
   }
 }
-skip = true;
-  }
-
-  if (!skip) {
+  } else {
 Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
 if (type) {
   function_param_types.push_back(type->GetForwardCompilerType());



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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

CC @youngdfb

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


[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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

>From ae32d8b691c658f3fc945576d5d6ac2c4d24213b Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 21 Jan 2025 13:40:23 -0800
Subject: [PATCH] Wire up DAP to listen to external progress events, and list
 the enumeration in SBDebugger

---
 lldb/include/lldb/API/SBDebugger.h | 16 ++--
 lldb/tools/lldb-dap/lldb-dap.cpp   |  3 ++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index eb371e33c4951c..42e9edafcb53ab 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -42,12 +42,16 @@ class LLDB_API SBInputReader {
 
 class LLDB_API SBDebugger {
 public:
-  FLAGS_ANONYMOUS_ENUM(){
-  eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
-  eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
-  eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitProgressCategory =
-  lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+  FLAGS_ANONYMOUS_ENUM() {
+eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
+eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
+eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
+eBroadcastBitExternalProgressCategory =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgressCategory,
+eBroadcastBitExternalProgress =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
+eBroadcastBitExternalProgressCategory =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgressCategory,
   };
   SBDebugger();
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7e8f7b5f6df679..6b12569d90a831 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -414,7 +414,8 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
 void ProgressEventThreadFunction(DAP &dap) {
   lldb::SBListener listener("lldb-dap.progress.listener");
   dap.debugger.GetBroadcaster().AddListener(
-  listener, lldb::SBDebugger::eBroadcastBitProgress);
+  listener, lldb::SBDebugger::eBroadcastBitProgress |
+lldb::SBDebugger::eBroadcastBitExternalProgress);
   dap.broadcaster.AddListener(listener, eBroadcastBitStopProgressThread);
   lldb::SBEvent event;
   bool done = false;

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 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 1888a5f02fc53703c70abca2b12048e896d8c136 
f16aab0a3b715cd294d61a4bb7278ff24610598a --extensions h,cpp -- 
lldb/include/lldb/API/SBDebugger.h lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index 7f56bf34c3..212e817e3c 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -42,12 +42,12 @@ public:
 
 class LLDB_API SBDebugger {
 public:
-  FLAGS_ANONYMOUS_ENUM(){
-  eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
-  eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
-  eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitExternalProgress =
-  lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
+  FLAGS_ANONYMOUS_ENUM() {
+eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
+eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
+eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
+eBroadcastBitExternalProgress =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
   };
   SBDebugger();
 

``




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


[Lldb-commits] [lldb] [LLDB-DAP] Send Progress update message over DAP (PR #123837)

2025-01-21 Thread Jonas Devlieghere via lldb-commits


@@ -164,10 +168,11 @@ const ProgressEvent 
&ProgressEventManager::GetMostRecentEvent() const {
   return m_last_update_event ? *m_last_update_event : m_start_event;
 }
 
-void ProgressEventManager::Update(uint64_t progress_id, uint64_t completed,
-  uint64_t total) {
-  if (std::optional event = ProgressEvent::Create(
-  progress_id, std::nullopt, completed, total, &GetMostRecentEvent())) 
{
+void ProgressEventManager::Update(uint64_t progress_id, const char *message,

JDevlieghere wrote:

```suggestion
void ProgressEventManager::Update(uint64_t progress_id, llvm::StringRef message,
```

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


[Lldb-commits] [lldb] [LLDB-DAP] Send Progress update message over DAP (PR #123837)

2025-01-21 Thread Jonas Devlieghere via lldb-commits


@@ -117,6 +117,10 @@ json::Value ProgressEvent::ToJSON() const {
 body.try_emplace("cancellable", false);
   }
 
+  if (m_event_type == progressUpdate) {
+EmplaceSafeString(body, "message", m_message);
+  }

JDevlieghere wrote:

Nit: no braces around single-line if.

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


[Lldb-commits] [lldb] [LLDB-DAP] Send Progress update message over DAP (PR #123837)

2025-01-21 Thread Jonas Devlieghere via lldb-commits


@@ -164,10 +168,11 @@ const ProgressEvent 
&ProgressEventManager::GetMostRecentEvent() const {
   return m_last_update_event ? *m_last_update_event : m_start_event;
 }
 
-void ProgressEventManager::Update(uint64_t progress_id, uint64_t completed,
-  uint64_t total) {
-  if (std::optional event = ProgressEvent::Create(
-  progress_id, std::nullopt, completed, total, &GetMostRecentEvent())) 
{
+void ProgressEventManager::Update(uint64_t progress_id, const char *message,
+  uint64_t completed, uint64_t total) {
+  if (std::optional event =
+  ProgressEvent::Create(progress_id, StringRef(message), completed,

JDevlieghere wrote:

```suggestion
  ProgressEvent::Create(progress_id, message, completed,
```

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


[Lldb-commits] [lldb] [LLDB-DAP] Send Progress update message over DAP (PR #123837)

2025-01-21 Thread Jonas Devlieghere via lldb-commits


@@ -99,7 +99,8 @@ class ProgressEventManager {
 
   /// Receive a new progress event for the start event and try to report it if
   /// appropriate.
-  void Update(uint64_t progress_id, uint64_t completed, uint64_t total);
+  void Update(uint64_t progress_id, const char *message, uint64_t completed,

JDevlieghere wrote:

```suggestion
  void Update(uint64_t progress_id, llvm::StringRef message, uint64_t completed,
```

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread David Spickett via lldb-commits

DavidSpickett wrote:

This is a point of confusion, the LLVM project is set up to take the PR 
description, https://github.com/llvm/llvm-project/pull/112079#issue-2582537001 
(the one you see on the page where this comment is also) as the commit message 
for the squashed commits.

As opposed to using the combination of the commits in the PR, or picking the 
last one, or whatever else GitHub allows.

The merits of this - out of scope, but the point is that there is a chance to 
edit this description before it's used, but only the one merging gets that 
chance. So if you had the ability to merge you could do that and that's fine.

But you don't so we need to know what it should be and the easiest way to do 
that is update the PR's description and all we have to do is click the button 
and accept what GitHub chooses.

If you have a really good reason to keep the PR description as is (perhaps it 
includes a bunch of context for reviewers that might be useful for 
archaeology), then you can just write a new comment and we'll copy that.

If this seems like I'm being overly verbose and maybe a bit insulting, that's 
not my intent, it's just a very tricky distinction to convey and I spent this 
morning also writing about it elsewhere :) . It's not perfect but it is what it 
is for the time being.

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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread David Spickett via lldb-commits

DavidSpickett wrote:

If the final message is in fact just the several commit messages, and that 
describes the changes well, then great! Doesn't have to be a new, unique thing.

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread Michael Buch via lldb-commits

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

>From 505eb69920a291604378bc3ce0adb14ce8843138 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 21 Jan 2025 17:30:44 +
Subject: [PATCH 1/3] [lldb][DWARFASTParserClang][NFCI] Simplify
 ParseChildParameters

This patch refactors `ParseChildParameters` in a way which makes it (in my 
opinion) more readable, removing some redundant local variables in the process 
and reduces the scope of some variables.

Since `DW_AT_object_pointer`s are now attached to declarations, we can make 
test for their existence to check whether a C++ method is static or not 
(whereas currently we're deducing this from `ParseChildParameters` based on 
some heuristics we know are true for most compilers). So my plan is to move the 
code for determining `type_quals` and `is_static` out of 
`ParseChildParameters`. The refactoring in this PR will make this follow-up 
patch hopefully easier to review.

**Testing**

* This should be NFC. The main changes is that we now no longer iterate over 
`GetAttributes()` but instead retrieve the name, type and is_artificial 
attributes of the parameters individually.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 58 +++
 1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 68fa1d13943a16..4df95513f8dfa2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3084,50 +3084,11 @@ size_t DWARFASTParserClang::ParseChildParameters(
 const dw_tag_t tag = die.Tag();
 switch (tag) {
 case DW_TAG_formal_parameter: {
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0) {
-arg_idx++;
-break;
-  }
-
-  const char *name = nullptr;
-  DWARFFormValue param_type_die_form;
-  bool is_artificial = false;
-  // one of None, Auto, Register, Extern, Static, PrivateExtern
-
-  clang::StorageClass storage = clang::SC_None;
-  uint32_t i;
-  for (i = 0; i < attributes.Size(); ++i) {
-const dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-  switch (attr) {
-  case DW_AT_name:
-name = form_value.AsCString();
-break;
-  case DW_AT_type:
-param_type_die_form = form_value;
-break;
-  case DW_AT_artificial:
-is_artificial = form_value.Boolean();
-break;
-  case DW_AT_location:
-  case DW_AT_const_value:
-  case DW_AT_default_value:
-  case DW_AT_description:
-  case DW_AT_endianity:
-  case DW_AT_is_optional:
-  case DW_AT_segment:
-  case DW_AT_variable_parameter:
-  default:
-  case DW_AT_abstract_origin:
-  case DW_AT_sibling:
-break;
-  }
-}
-  }
+  arg_idx++;
+  const char *name = die.GetName();
+  DWARFDIE param_type_die = 
die.GetAttributeValueAsReferenceDIE(DW_AT_type);
 
-  if (is_artificial) {
+  if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) {
 // In order to determine if a C++ member function is "const" we
 // have to look at the const-ness of "this"...
 if (arg_idx == 0 &&
@@ -3136,8 +3097,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
 // specification DIEs, so we can't rely upon the name being in
 // the formal parameter DIE...
 (name == nullptr || ::strcmp(name, "this") == 0)) {
-  Type *this_type = 
die.ResolveTypeUID(param_type_die_form.Reference());
-  if (this_type) {
+  if (Type *this_type = die.ResolveTypeUID(param_type_die)) {
 uint32_t encoding_mask = this_type->GetEncodingMask();
 if (encoding_mask & Type::eEncodingIsPointerUID) {
   is_static = false;
@@ -3149,21 +3109,17 @@ size_t DWARFASTParserClang::ParseChildParameters(
 }
   }
 }
-  } else {
-Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
-if (type) {
+  } else if (Type *type = die.ResolveTypeUID(param_type_die)) {
   function_param_types.push_back(type->GetForwardCompilerType());
 
   clang::ParmVarDecl *param_var_decl = 
m_ast.CreateParameterDeclaration(
   containing_decl_ctx, GetOwningClangModule(die), name,
-  type->GetForwardCompilerType(), storage);
+  type->GetForwardCompilerType(), clang::StorageClass::SC_None);
   assert(param_var_decl);
   function_param_decls.push_back(param_var_decl);
 
   m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
-}
   }
-

[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread Robert O'Callahan via lldb-commits

rocallahan wrote:

> Hmm.. could you update the patch description with the text you want the final 
> commit to contain. I see that at least the API names have changed during the 
> review, but maybe there are other things (?)

The API names in the commit messages are correct.

But I noticed that the commit message for the main commit was somehow 
corrupted. I've fixed that now.

Or by "patch description" do you mean some other metadata?
Do you need me to provide a summary commit message for the squashed commits?

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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread Robert O'Callahan via lldb-commits

https://github.com/rocallahan updated 
https://github.com/llvm/llvm-project/pull/112079

>From 1d587f12fccc8baebb3d502389c6e7e479fab9f7 Mon Sep 17 00:00:00 2001
From: Robert O'Callahan 
Date: Fri, 19 Jul 2024 22:46:42 +1200
Subject: [PATCH 1/3] [lldb] Implement basic support for reverse-continue

This commit only adds support for the
`SBProcess::ContinueInDirection()` API. A user-accessible command
for this will follow in a later commit.

This feature depends on a gdbserver implementation (e.g. `rr`)
providing support for the `bc` and `bs` packets. `lldb-server`
does not support those packets, and there is no plan to change that.
For testing purposes, this commit adds a Python implementation of
*very limited* record-and-reverse-execute functionality, implemented
as a proxy between lldb and lldb-server in `lldbreverse.py`. This
should not (and in practice cannot) be used for anything except
testing.
---
 lldb/include/lldb/API/SBProcess.h |   1 +
 lldb/include/lldb/Target/Process.h|  21 +-
 lldb/include/lldb/Target/StopInfo.h   |   7 +
 lldb/include/lldb/Target/Thread.h |   9 +-
 lldb/include/lldb/Target/ThreadList.h |   6 +-
 lldb/include/lldb/Target/ThreadPlan.h |  13 +
 lldb/include/lldb/Target/ThreadPlanBase.h |   2 +
 lldb/include/lldb/lldb-enumerations.h |   6 +
 .../Python/lldbsuite/test/gdbclientutils.py   |   5 +-
 .../Python/lldbsuite/test/lldbgdbproxy.py | 175 +++
 .../Python/lldbsuite/test/lldbreverse.py  | 492 ++
 .../Python/lldbsuite/test/lldbtest.py |   2 +
 .../tools/lldb-server/lldbgdbserverutils.py   |  14 +-
 lldb/source/API/SBProcess.cpp |   6 +
 lldb/source/API/SBThread.cpp  |   2 +
 .../source/Interpreter/CommandInterpreter.cpp |   3 +-
 .../Process/Linux/NativeThreadLinux.cpp   |   3 +
 .../Process/MacOSX-Kernel/ProcessKDP.cpp  |   8 +-
 .../Process/MacOSX-Kernel/ProcessKDP.h|   2 +-
 .../Process/Windows/Common/ProcessWindows.cpp |   9 +-
 .../Process/Windows/Common/ProcessWindows.h   |   2 +-
 .../GDBRemoteCommunicationClient.cpp  |  20 +
 .../gdb-remote/GDBRemoteCommunicationClient.h |   6 +
 .../GDBRemoteCommunicationServerLLGS.cpp  |   1 +
 .../Process/gdb-remote/ProcessGDBRemote.cpp   |  93 +++-
 .../Process/gdb-remote/ProcessGDBRemote.h |   2 +-
 .../Process/scripted/ScriptedProcess.cpp  |   9 +-
 .../Process/scripted/ScriptedProcess.h|   2 +-
 lldb/source/Target/Process.cpp|  24 +-
 lldb/source/Target/StopInfo.cpp   |  28 +
 lldb/source/Target/Thread.cpp |   9 +-
 lldb/source/Target/ThreadList.cpp |  32 +-
 lldb/source/Target/ThreadPlanBase.cpp |   4 +
 .../reverse-execution/Makefile|   3 +
 .../TestReverseContinueBreakpoints.py | 149 ++
 .../TestReverseContinueNotSupported.py|  30 ++
 .../functionalities/reverse-execution/main.c  |  14 +
 lldb/tools/lldb-dap/JSONUtils.cpp |   3 +
 lldb/tools/lldb-dap/LLDBUtils.cpp |   1 +
 39 files changed, 1171 insertions(+), 47 deletions(-)
 create mode 100644 lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py
 create mode 100644 lldb/packages/Python/lldbsuite/test/lldbreverse.py
 create mode 100644 lldb/test/API/functionalities/reverse-execution/Makefile
 create mode 100644 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
 create mode 100644 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py
 create mode 100644 lldb/test/API/functionalities/reverse-execution/main.c

diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 1624e02070b1b2..882b8bd837131d 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -159,6 +159,7 @@ class LLDB_API SBProcess {
   lldb::SBError Destroy();
 
   lldb::SBError Continue();
+  lldb::SBError ContinueInDirection(lldb::RunDirection direction);
 
   lldb::SBError Stop();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a184e6dd891aff..3d76413da0fce2 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1104,9 +1104,13 @@ class Process : public 
std::enable_shared_from_this,
   /// \see Thread:Resume()
   /// \see Thread:Step()
   /// \see Thread:Suspend()
-  virtual Status DoResume() {
+  virtual Status DoResume(lldb::RunDirection direction) {
+if (direction == lldb::RunDirection::eRunForward)
+  return Status::FromErrorStringWithFormatv(
+  "error: {0} does not support resuming processes", GetPluginName());
 return Status::FromErrorStringWithFormatv(
-"error: {0} does not support resuming processes", GetPluginName());
+"error: {0} does not support reverse execution of processes",
+GetPluginName());
   }
 
   /// Called after resuming a process.
@@ -

[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Support format string in the prompt (PR #123430)

2025-01-21 Thread via lldb-commits


@@ -171,7 +171,45 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef 
format,
   }
   return fmt;
 }
+
+inline std::string StripAnsiTerminalCodes(llvm::StringRef str) {
+  std::string stripped;
+  while (!str.empty()) {
+llvm::StringRef left, right;
+
+std::tie(left, right) = str.split(ANSI_ESC_START);
+stripped += left;
+
+// ANSI_ESC_START not found.
+if (left == str && right.empty())
+  break;
+
+auto end = llvm::StringRef::npos;
+for (size_t i = 0; i < right.size(); i++) {
+  char c = right[i];
+  if (c == 'm' || c == 'G') {
+end = i;
+break;
+  }
+  if (isdigit(c) || c == ';')
+continue;
+
+  break;
+}
+
+// ANSI_ESC_END not found.
+if (end != llvm::StringRef::npos) {
+  str = right.substr(end + 1);
+  continue;
+}
+
+stripped += ANSI_ESC_START;
+str = right;

jimingham wrote:

Because your code sleeps all night and works all day?

https://github.com/llvm/llvm-project/pull/123430
___
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 compiler version check and use regex (PR #123393)

2025-01-21 Thread Michael Buch via lldb-commits

Michael137 wrote:

This is failing on the macOS matrix bots: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake-matrix which 
test with older compiler versions

Looks like the regex might be incorrect.

Mind fixing this? Or revert if it isn't an easy fix?

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

This patch refactors `ParseChildParameters` in a way which makes it (in my 
opinion) more readable, removing some redundant local variables in the process 
and reduces the scope of some variables.

**Motivation**

Since `DW_AT_object_pointer`s are now attached to declarations, we can make 
test for their existence to check whether a C++ method is static or not 
(whereas currently we're deducing this from `ParseChildParameters` based on 
some heuristics we know are true for most compilers). So my plan is to move the 
code for determining `type_quals` and `is_static` out of 
`ParseChildParameters`. The refactoring in this PR will make this follow-up 
patch hopefully easier to review.

**Testing**

* This should be NFC. The main change is that we now no longer iterate over 
`GetAttributes()` but instead retrieve the name, type and is_artificial 
attributes of the parameters individually.

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


1 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+7-51) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 68fa1d13943a16..4df95513f8dfa2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3084,50 +3084,11 @@ size_t DWARFASTParserClang::ParseChildParameters(
 const dw_tag_t tag = die.Tag();
 switch (tag) {
 case DW_TAG_formal_parameter: {
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0) {
-arg_idx++;
-break;
-  }
-
-  const char *name = nullptr;
-  DWARFFormValue param_type_die_form;
-  bool is_artificial = false;
-  // one of None, Auto, Register, Extern, Static, PrivateExtern
-
-  clang::StorageClass storage = clang::SC_None;
-  uint32_t i;
-  for (i = 0; i < attributes.Size(); ++i) {
-const dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-  switch (attr) {
-  case DW_AT_name:
-name = form_value.AsCString();
-break;
-  case DW_AT_type:
-param_type_die_form = form_value;
-break;
-  case DW_AT_artificial:
-is_artificial = form_value.Boolean();
-break;
-  case DW_AT_location:
-  case DW_AT_const_value:
-  case DW_AT_default_value:
-  case DW_AT_description:
-  case DW_AT_endianity:
-  case DW_AT_is_optional:
-  case DW_AT_segment:
-  case DW_AT_variable_parameter:
-  default:
-  case DW_AT_abstract_origin:
-  case DW_AT_sibling:
-break;
-  }
-}
-  }
+  arg_idx++;
+  const char *name = die.GetName();
+  DWARFDIE param_type_die = 
die.GetAttributeValueAsReferenceDIE(DW_AT_type);
 
-  if (is_artificial) {
+  if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) {
 // In order to determine if a C++ member function is "const" we
 // have to look at the const-ness of "this"...
 if (arg_idx == 0 &&
@@ -3136,8 +3097,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
 // specification DIEs, so we can't rely upon the name being in
 // the formal parameter DIE...
 (name == nullptr || ::strcmp(name, "this") == 0)) {
-  Type *this_type = 
die.ResolveTypeUID(param_type_die_form.Reference());
-  if (this_type) {
+  if (Type *this_type = die.ResolveTypeUID(param_type_die)) {
 uint32_t encoding_mask = this_type->GetEncodingMask();
 if (encoding_mask & Type::eEncodingIsPointerUID) {
   is_static = false;
@@ -3149,21 +3109,17 @@ size_t DWARFASTParserClang::ParseChildParameters(
 }
   }
 }
-  } else {
-Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
-if (type) {
+  } else if (Type *type = die.ResolveTypeUID(param_type_die)) {
   function_param_types.push_back(type->GetForwardCompilerType());
 
   clang::ParmVarDecl *param_var_decl = 
m_ast.CreateParameterDeclaration(
   containing_decl_ctx, GetOwningClangModule(die), name,
-  type->GetForwardCompilerType(), storage);
+  type->GetForwardCompilerType(), clang::StorageClass::SC_None);
   assert(param_var_decl);
   function_param_decls.push_back(param_var_decl);
 
   m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
-}
   }
-  arg_idx++;
 } break;
 
 case DW_TAG_unspecified_parameters:

``




https://github.com/llvm/llvm-project/pull/123

[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread Michael Buch via lldb-commits

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

>From 505eb69920a291604378bc3ce0adb14ce8843138 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 21 Jan 2025 17:30:44 +
Subject: [PATCH 1/2] [lldb][DWARFASTParserClang][NFCI] Simplify
 ParseChildParameters

This patch refactors `ParseChildParameters` in a way which makes it (in my 
opinion) more readable, removing some redundant local variables in the process 
and reduces the scope of some variables.

Since `DW_AT_object_pointer`s are now attached to declarations, we can make 
test for their existence to check whether a C++ method is static or not 
(whereas currently we're deducing this from `ParseChildParameters` based on 
some heuristics we know are true for most compilers). So my plan is to move the 
code for determining `type_quals` and `is_static` out of 
`ParseChildParameters`. The refactoring in this PR will make this follow-up 
patch hopefully easier to review.

**Testing**

* This should be NFC. The main changes is that we now no longer iterate over 
`GetAttributes()` but instead retrieve the name, type and is_artificial 
attributes of the parameters individually.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 58 +++
 1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 68fa1d13943a16..4df95513f8dfa2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3084,50 +3084,11 @@ size_t DWARFASTParserClang::ParseChildParameters(
 const dw_tag_t tag = die.Tag();
 switch (tag) {
 case DW_TAG_formal_parameter: {
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0) {
-arg_idx++;
-break;
-  }
-
-  const char *name = nullptr;
-  DWARFFormValue param_type_die_form;
-  bool is_artificial = false;
-  // one of None, Auto, Register, Extern, Static, PrivateExtern
-
-  clang::StorageClass storage = clang::SC_None;
-  uint32_t i;
-  for (i = 0; i < attributes.Size(); ++i) {
-const dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-  switch (attr) {
-  case DW_AT_name:
-name = form_value.AsCString();
-break;
-  case DW_AT_type:
-param_type_die_form = form_value;
-break;
-  case DW_AT_artificial:
-is_artificial = form_value.Boolean();
-break;
-  case DW_AT_location:
-  case DW_AT_const_value:
-  case DW_AT_default_value:
-  case DW_AT_description:
-  case DW_AT_endianity:
-  case DW_AT_is_optional:
-  case DW_AT_segment:
-  case DW_AT_variable_parameter:
-  default:
-  case DW_AT_abstract_origin:
-  case DW_AT_sibling:
-break;
-  }
-}
-  }
+  arg_idx++;
+  const char *name = die.GetName();
+  DWARFDIE param_type_die = 
die.GetAttributeValueAsReferenceDIE(DW_AT_type);
 
-  if (is_artificial) {
+  if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) {
 // In order to determine if a C++ member function is "const" we
 // have to look at the const-ness of "this"...
 if (arg_idx == 0 &&
@@ -3136,8 +3097,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
 // specification DIEs, so we can't rely upon the name being in
 // the formal parameter DIE...
 (name == nullptr || ::strcmp(name, "this") == 0)) {
-  Type *this_type = 
die.ResolveTypeUID(param_type_die_form.Reference());
-  if (this_type) {
+  if (Type *this_type = die.ResolveTypeUID(param_type_die)) {
 uint32_t encoding_mask = this_type->GetEncodingMask();
 if (encoding_mask & Type::eEncodingIsPointerUID) {
   is_static = false;
@@ -3149,21 +3109,17 @@ size_t DWARFASTParserClang::ParseChildParameters(
 }
   }
 }
-  } else {
-Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
-if (type) {
+  } else if (Type *type = die.ResolveTypeUID(param_type_die)) {
   function_param_types.push_back(type->GetForwardCompilerType());
 
   clang::ParmVarDecl *param_var_decl = 
m_ast.CreateParameterDeclaration(
   containing_decl_ctx, GetOwningClangModule(die), name,
-  type->GetForwardCompilerType(), storage);
+  type->GetForwardCompilerType(), clang::StorageClass::SC_None);
   assert(param_var_decl);
   function_param_decls.push_back(param_var_decl);
 
   m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
-}
   }
-

[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 Thread Michael Buch via lldb-commits

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

This patch refactors `ParseChildParameters` in a way which makes it (in my 
opinion) more readable, removing some redundant local variables in the process 
and reduces the scope of some variables.

**Motivation**

Since `DW_AT_object_pointer`s are now attached to declarations, we can make 
test for their existence to check whether a C++ method is static or not 
(whereas currently we're deducing this from `ParseChildParameters` based on 
some heuristics we know are true for most compilers). So my plan is to move the 
code for determining `type_quals` and `is_static` out of 
`ParseChildParameters`. The refactoring in this PR will make this follow-up 
patch hopefully easier to review.

**Testing**

* This should be NFC. The main changes is that we now no longer iterate over 
`GetAttributes()` but instead retrieve the name, type and is_artificial 
attributes of the parameters individually.

>From 505eb69920a291604378bc3ce0adb14ce8843138 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 21 Jan 2025 17:30:44 +
Subject: [PATCH] [lldb][DWARFASTParserClang][NFCI] Simplify
 ParseChildParameters

This patch refactors `ParseChildParameters` in a way which makes it (in my 
opinion) more readable, removing some redundant local variables in the process 
and reduces the scope of some variables.

Since `DW_AT_object_pointer`s are now attached to declarations, we can make 
test for their existence to check whether a C++ method is static or not 
(whereas currently we're deducing this from `ParseChildParameters` based on 
some heuristics we know are true for most compilers). So my plan is to move the 
code for determining `type_quals` and `is_static` out of 
`ParseChildParameters`. The refactoring in this PR will make this follow-up 
patch hopefully easier to review.

**Testing**

* This should be NFC. The main changes is that we now no longer iterate over 
`GetAttributes()` but instead retrieve the name, type and is_artificial 
attributes of the parameters individually.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 58 +++
 1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 68fa1d13943a16..4df95513f8dfa2 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3084,50 +3084,11 @@ size_t DWARFASTParserClang::ParseChildParameters(
 const dw_tag_t tag = die.Tag();
 switch (tag) {
 case DW_TAG_formal_parameter: {
-  DWARFAttributes attributes = die.GetAttributes();
-  if (attributes.Size() == 0) {
-arg_idx++;
-break;
-  }
-
-  const char *name = nullptr;
-  DWARFFormValue param_type_die_form;
-  bool is_artificial = false;
-  // one of None, Auto, Register, Extern, Static, PrivateExtern
-
-  clang::StorageClass storage = clang::SC_None;
-  uint32_t i;
-  for (i = 0; i < attributes.Size(); ++i) {
-const dw_attr_t attr = attributes.AttributeAtIndex(i);
-DWARFFormValue form_value;
-if (attributes.ExtractFormValueAtIndex(i, form_value)) {
-  switch (attr) {
-  case DW_AT_name:
-name = form_value.AsCString();
-break;
-  case DW_AT_type:
-param_type_die_form = form_value;
-break;
-  case DW_AT_artificial:
-is_artificial = form_value.Boolean();
-break;
-  case DW_AT_location:
-  case DW_AT_const_value:
-  case DW_AT_default_value:
-  case DW_AT_description:
-  case DW_AT_endianity:
-  case DW_AT_is_optional:
-  case DW_AT_segment:
-  case DW_AT_variable_parameter:
-  default:
-  case DW_AT_abstract_origin:
-  case DW_AT_sibling:
-break;
-  }
-}
-  }
+  arg_idx++;
+  const char *name = die.GetName();
+  DWARFDIE param_type_die = 
die.GetAttributeValueAsReferenceDIE(DW_AT_type);
 
-  if (is_artificial) {
+  if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) {
 // In order to determine if a C++ member function is "const" we
 // have to look at the const-ness of "this"...
 if (arg_idx == 0 &&
@@ -3136,8 +3097,7 @@ size_t DWARFASTParserClang::ParseChildParameters(
 // specification DIEs, so we can't rely upon the name being in
 // the formal parameter DIE...
 (name == nullptr || ::strcmp(name, "this") == 0)) {
-  Type *this_type = 
die.ResolveTypeUID(param_type_die_form.Reference());
-  if (this_type) {
+  if (Type *this_type = die.ResolveTypeUID(param_type_die)) {
 uint32_t encoding_mask = this_type->GetEncodingMask();
 if (encoding_mask & Type::eEnco

[Lldb-commits] [lldb] [lldb][DWARFASTParserClang][NFCI] Simplify ParseChildParameters (PR #123790)

2025-01-21 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 aeffc01a7247cd95560b0c35b7a2c8d5a434b1f0 
505eb69920a291604378bc3ce0adb14ce8843138 --extensions cpp -- 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 4df95513f8..677b8884c7 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3110,15 +3110,15 @@ size_t DWARFASTParserClang::ParseChildParameters(
   }
 }
   } else if (Type *type = die.ResolveTypeUID(param_type_die)) {
-  function_param_types.push_back(type->GetForwardCompilerType());
+function_param_types.push_back(type->GetForwardCompilerType());
 
-  clang::ParmVarDecl *param_var_decl = 
m_ast.CreateParameterDeclaration(
-  containing_decl_ctx, GetOwningClangModule(die), name,
-  type->GetForwardCompilerType(), clang::StorageClass::SC_None);
-  assert(param_var_decl);
-  function_param_decls.push_back(param_var_decl);
+clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration(
+containing_decl_ctx, GetOwningClangModule(die), name,
+type->GetForwardCompilerType(), clang::StorageClass::SC_None);
+assert(param_var_decl);
+function_param_decls.push_back(param_var_decl);
 
-  m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
+m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
   }
 } break;
 

``




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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread Robert O'Callahan via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add SymbolContext::GetAddress (PR #123340)

2025-01-21 Thread via lldb-commits


@@ -370,6 +370,31 @@ bool SymbolContext::GetAddressRange(uint32_t scope, 
uint32_t range_idx,
   return false;
 }
 
+Address SymbolContext::GetAddress(uint32_t scope,
+  bool use_inline_block_range) const {
+  if ((scope & eSymbolContextLineEntry) && line_entry.IsValid())
+return line_entry.range.GetBaseAddress();
+
+  if (scope & eSymbolContextBlock) {
+Block *block_to_use = (block && use_inline_block_range)
+  ? block->GetContainingInlinedBlock()
+  : block;
+if (block_to_use) {
+  Address addr;
+  block_to_use->GetStartAddress(addr);
+  return addr;
+}
+  }

jimingham wrote:

Giving a single address to a block considered as a logical entity is 
problematic, but the address of the start of the block referenced by a 
SymbolContext doesn't have that problem.  I think the confusing part is the 
fact that we call what is in the symbol context "Block" rather than 
"BlockElement" or something.  We don't make a distinction between logical 
blocks and the address ranges that constitute them the way a Function is the 
logical entity that organizes the block(s) that constitute it.

But for instance, when the "step through range targeting function" wants to 
limit the stepping range to the extent of the block we're currently sitting in, 
getting the SymbolContext from the current address and using that block element 
is what you need to do.  Note, in that case we use the end address rather than 
the start but the idea is still the same.

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


[Lldb-commits] [lldb] [lldb] Implement basic support for reverse-continue (PR #112079)

2025-01-21 Thread Robert O'Callahan via lldb-commits

rocallahan wrote:

> this seems like I'm being overly verbose and maybe a bit insulting, that's 
> not my intent

No, this is pretty clear and helpful, thanks! I've updated the PR description.

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


[Lldb-commits] [lldb] [lldb] Add SymbolContext::GetAddress (PR #123340)

2025-01-21 Thread via lldb-commits


@@ -192,6 +192,33 @@ class SymbolContext {
   bool GetAddressRange(uint32_t scope, uint32_t range_idx,
bool use_inline_block_range, AddressRange &range) const;
 
+  /// Get the address represented by this symbol context.
+  ///
+  /// The exact meaning of the address depends on object being queried and the
+  /// flags. Priority is as follows:
+  /// - The beginning (lowest address) of the line_entry if line_entry is
+  /// valid and eSymbolContextLineEntry is set in \a scope
+  /// - The beginning of the block if block is not nullptr and
+  /// eSymbolContextBlock is set in \a scope
+  /// - function address (entry point) if function is not nullptr and
+  /// eSymbolContextFunction is set in \a scope
+  /// - symbol address if symbol is not nullptr and eSymbolContextSymbol is
+  /// set in \a scope
+  ///
+  /// \param[in] scope
+  /// A mask of symbol context bits telling this function which

jimingham wrote:

If you know lldb a bit at the public layer, you would know that 
eSymbolContextWhatever is an enum, and if you wanted to find the whole enum and 
where it is documented you go to include/lldb/include/, etc.  But if you said 
"these flag is composed of bits from the enum SymbolContextItem", that would 
lead directly there.

https://github.com/llvm/llvm-project/pull/123340
___
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 compiler version check and use regex (PR #123393)

2025-01-21 Thread Adrian Prantl via lldb-commits

adrian-prantl wrote:

```
Got output:
(std::vector, std::allocator > >) $0 = size=2 
{
  [0] = size=3 {
[0] = 1
[1] = 2
[2] = 3
  }
  [1] = size=3 {
[0] = 3
[1] = 2
[2] = 1
  }
}

Expecting regex pattern: "\(std::vector(, 
std::allocator )* >\) \$0 = size=2 \{
  \[0\] = size=3 \{
\[0\] = 1
\[1\] = 2
\[2\] = 3
  \}
  \[1\] = size=3 \{
\[0\] = 3
\[1\] = 2
\[2\] = 1
  \}
\}" (was not found)
```

https://github.com/llvm/llvm-project/pull/123393
___
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 compiler version check and use regex (PR #123393)

2025-01-21 Thread Adrian Prantl via lldb-commits

adrian-prantl wrote:

Generally speaking, it would be a lot more robust to not try and write a regex 
for the output, but individually check the summary/type for main node and 
children.

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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

Recently I added SBProgress (#119052), and during that original commit I tested 
if the progress event was sent over LLDB-DAP, and it was. However upon the 
suggestion of @JDevlieghere and @labath we added an external category 
(#120171), which I did not test.

This small patch wires up DAP to listen for external events by default, and 
adds the external category to the SBDebugger enumeration.

>From f16aab0a3b715cd294d61a4bb7278ff24610598a Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 21 Jan 2025 13:40:23 -0800
Subject: [PATCH] Wire up DAP to listen to external progress events, and list
 the enumeration in SBDebugger

---
 lldb/include/lldb/API/SBDebugger.h | 4 ++--
 lldb/tools/lldb-dap/lldb-dap.cpp   | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index eb371e33c4951c..7f56bf34c37388 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -46,8 +46,8 @@ class LLDB_API SBDebugger {
   eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
   eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
   eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitProgressCategory =
-  lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+  eBroadcastBitExternalProgress =
+  lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
   };
   SBDebugger();
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7e8f7b5f6df679..6b12569d90a831 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -414,7 +414,8 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
 void ProgressEventThreadFunction(DAP &dap) {
   lldb::SBListener listener("lldb-dap.progress.listener");
   dap.debugger.GetBroadcaster().AddListener(
-  listener, lldb::SBDebugger::eBroadcastBitProgress);
+  listener, lldb::SBDebugger::eBroadcastBitProgress |
+lldb::SBDebugger::eBroadcastBitExternalProgress);
   dap.broadcaster.AddListener(listener, eBroadcastBitStopProgressThread);
   lldb::SBEvent event;
   bool done = false;

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-01-21 Thread Omair Javaid via lldb-commits


@@ -71,12 +74,14 @@ class FifoFileIO {
   /// \return
   /// An \a llvm::Error object indicating whether the data was consumed by
   /// a reader or not.
-  llvm::Error SendJSON(
-  const llvm::json::Value &json,
-  std::chrono::milliseconds timeout = std::chrono::milliseconds(2));
+  llvm::Error
+  SendJSON(const llvm::json::Value &json,
+   std::chrono::milliseconds timeout = 
std::chrono::milliseconds(2000));

omjavaid wrote:

Is it ok to change to timeout here 2 --> 2000?

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-01-21 Thread Omair Javaid via lldb-commits


@@ -71,12 +74,14 @@ class FifoFileIO {
   /// \return
   /// An \a llvm::Error object indicating whether the data was consumed by
   /// a reader or not.
-  llvm::Error SendJSON(
-  const llvm::json::Value &json,
-  std::chrono::milliseconds timeout = std::chrono::milliseconds(2));
+  llvm::Error
+  SendJSON(const llvm::json::Value &json,
+   std::chrono::milliseconds timeout = 
std::chrono::milliseconds(2000));
+
+  llvm::Error WaitForPeer();
 
-private:
-  std::string m_fifo_file;
+  // private:

omjavaid wrote:

Why commenting out private?

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-01-21 Thread Omair Javaid via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Implement `runInTerminal` for Windows (PR #121269)

2025-01-21 Thread Omair Javaid via lldb-commits

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

This should be able make 
lldb\test\API\tools\lldb-dap\runInTerminal\TestDAP_runInTerminal.py pass all 
tests. Please tests and remove the skipping decorators.

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


[Lldb-commits] [lldb] [lldb][AArch64] Add Guarded Control Stack registers (PR #123720)

2025-01-21 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/123720

The Guarded Control Stack extension implements a shadow stack and the Linux 
kernel provides access to 3 registers for it via ptrace.

struct user_gcs {
__u64 features_enabled;
__u64 features_locked;
__u64 gcspr_el0;
};

This commit adds support for reading those from a live process.

The first 2 are pseudo registers based on the real control register and the 3rd 
is a real register. This is the stack pointer for the guarded stack.

I have added a "gcs_" prefix to the "features" registers so that they have a 
clear name when shown individually. Also this means they will tab complete from 
"gcs", and be next to gcspr_el0 in any sorted lists of registers.

Guarded Control Stack Registers:
  gcs_features_enabled = 0x
  gcs_features_locked = 0x
  gcspr_el0 = 0x

Testing is more of the usual, where possible I'm writing a register then doing 
something in the program to confirm the value was actually sent to ptrace.

>From 951a38910e49f3e93dc6c9a084e955ab01ad4c49 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Fri, 9 Aug 2024 11:56:29 +0100
Subject: [PATCH] [lldb][AArch64] Add Guarded Control Stack registers

The Guarded Control Stack extension implements a shadow stack and
the Linux kernel provides access to 3 registers for it via ptrace.

struct user_gcs {
__u64 features_enabled;
__u64 features_locked;
__u64 gcspr_el0;
};

This commit adds support for reading those from a live process.

The first 2 are pseudo registers based on the real control register
and the 3rd is a real register. This is the stack pointer for the
guarded stack.

I have added a "gcs_" prefix to the "features" registers so that
they have a clear name when shown individually. Also this means
they will tab complete from "gcs", and be next to gcspr_el0 in
any sorted lists of registers.

Guarded Control Stack Registers:
  gcs_features_enabled = 0x
  gcs_features_locked = 0x
  gcspr_el0 = 0x

Testing is more of the usual, where possible I'm writing a register
then doing something in the program to confirm the value was actually
sent to ptrace.
---
 .../NativeRegisterContextLinux_arm64.cpp  |  86 +++
 .../Linux/NativeRegisterContextLinux_arm64.h  |  16 +++
 .../Utility/RegisterContextPOSIX_arm64.cpp|   4 +
 .../Utility/RegisterContextPOSIX_arm64.h  |   1 +
 .../Utility/RegisterInfoPOSIX_arm64.cpp   |  39 -
 .../Process/Utility/RegisterInfoPOSIX_arm64.h |   7 +
 .../linux/aarch64/gcs/TestAArch64LinuxGCS.py  | 134 ++
 lldb/test/API/linux/aarch64/gcs/main.c|  23 ++-
 8 files changed, 305 insertions(+), 5 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 6056f3001fed6e..efd3385c46e92f 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -64,8 +64,14 @@
 #define NT_ARM_FPMR 0x40e /* Floating point mode register */
 #endif
 
+#ifndef NT_ARM_GCS
+#define NT_ARM_GCS 0x410 /* Guarded Control Stack control registers */
+#endif
+
 #define HWCAP_PACA (1 << 30)
 
+#define HWCAP_GCS (1UL << 32)
+
 #define HWCAP2_MTE (1 << 18)
 
 #define HWCAP2_FPMR (1UL << 48)
@@ -150,6 +156,8 @@ 
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskMTE);
   if (*auxv_at_hwcap2 & HWCAP2_FPMR)
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskFPMR);
+  if (*auxv_at_hwcap & HWCAP_GCS)
+opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskGCS);
 }
 
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskTLS);
@@ -193,6 +201,7 @@ 
NativeRegisterContextLinux_arm64::NativeRegisterContextLinux_arm64(
   ::memset(&m_pac_mask, 0, sizeof(m_pac_mask));
   ::memset(&m_tls_regs, 0, sizeof(m_tls_regs));
   ::memset(&m_sme_pseudo_regs, 0, sizeof(m_sme_pseudo_regs));
+  ::memset(&m_gcs_regs, 0, sizeof(m_gcs_regs));
   std::fill(m_zt_reg.begin(), m_zt_reg.end(), 0);
 
   m_mte_ctrl_reg = 0;
@@ -213,6 +222,7 @@ 
NativeRegisterContextLinux_arm64::NativeRegisterContextLinux_arm64(
   m_tls_is_valid = false;
   m_zt_buffer_is_valid = false;
   m_fpmr_is_valid = false;
+  m_gcs_is_valid = false;
 
   // SME adds the tpidr2 register
   m_tls_size = GetRegisterInfo().IsSSVEPresent() ? sizeof(m_tls_regs)
@@ -433,6 +443,14 @@ NativeRegisterContextLinux_arm64::ReadRegister(const 
RegisterInfo *reg_info,
 offset = reg_info->byte_offset - GetRegisterInfo().GetFPMROffset();
 assert(offset < GetFPMRBufferSize());
 src = (uint8_t *)GetFPMRBuffer() + offset;
+  } else if (IsGCS(reg)) {
+error = ReadGCS();
+if (error.Fail())
+  return error;
+
+offset = r

[Lldb-commits] [lldb] [lldb][AArch64] Add Guarded Control Stack registers (PR #123720)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

The Guarded Control Stack extension implements a shadow stack and the Linux 
kernel provides access to 3 registers for it via ptrace.

struct user_gcs {
__u64 features_enabled;
__u64 features_locked;
__u64 gcspr_el0;
};

This commit adds support for reading those from a live process.

The first 2 are pseudo registers based on the real control register and the 3rd 
is a real register. This is the stack pointer for the guarded stack.

I have added a "gcs_" prefix to the "features" registers so that they have a 
clear name when shown individually. Also this means they will tab complete from 
"gcs", and be next to gcspr_el0 in any sorted lists of registers.

Guarded Control Stack Registers:
  gcs_features_enabled = 0x
  gcs_features_locked = 0x
  gcspr_el0 = 0x

Testing is more of the usual, where possible I'm writing a register then doing 
something in the program to confirm the value was actually sent to ptrace.

---

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


8 Files Affected:

- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (+86) 
- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h (+16) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp 
(+4) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h 
(+1) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp 
(+38-1) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h (+7) 
- (modified) lldb/test/API/linux/aarch64/gcs/TestAArch64LinuxGCS.py (+134) 
- (modified) lldb/test/API/linux/aarch64/gcs/main.c (+19-4) 


``diff
diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 6056f3001fed6e..efd3385c46e92f 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -64,8 +64,14 @@
 #define NT_ARM_FPMR 0x40e /* Floating point mode register */
 #endif
 
+#ifndef NT_ARM_GCS
+#define NT_ARM_GCS 0x410 /* Guarded Control Stack control registers */
+#endif
+
 #define HWCAP_PACA (1 << 30)
 
+#define HWCAP_GCS (1UL << 32)
+
 #define HWCAP2_MTE (1 << 18)
 
 #define HWCAP2_FPMR (1UL << 48)
@@ -150,6 +156,8 @@ 
NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskMTE);
   if (*auxv_at_hwcap2 & HWCAP2_FPMR)
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskFPMR);
+  if (*auxv_at_hwcap & HWCAP_GCS)
+opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskGCS);
 }
 
 opt_regsets.Set(RegisterInfoPOSIX_arm64::eRegsetMaskTLS);
@@ -193,6 +201,7 @@ 
NativeRegisterContextLinux_arm64::NativeRegisterContextLinux_arm64(
   ::memset(&m_pac_mask, 0, sizeof(m_pac_mask));
   ::memset(&m_tls_regs, 0, sizeof(m_tls_regs));
   ::memset(&m_sme_pseudo_regs, 0, sizeof(m_sme_pseudo_regs));
+  ::memset(&m_gcs_regs, 0, sizeof(m_gcs_regs));
   std::fill(m_zt_reg.begin(), m_zt_reg.end(), 0);
 
   m_mte_ctrl_reg = 0;
@@ -213,6 +222,7 @@ 
NativeRegisterContextLinux_arm64::NativeRegisterContextLinux_arm64(
   m_tls_is_valid = false;
   m_zt_buffer_is_valid = false;
   m_fpmr_is_valid = false;
+  m_gcs_is_valid = false;
 
   // SME adds the tpidr2 register
   m_tls_size = GetRegisterInfo().IsSSVEPresent() ? sizeof(m_tls_regs)
@@ -433,6 +443,14 @@ NativeRegisterContextLinux_arm64::ReadRegister(const 
RegisterInfo *reg_info,
 offset = reg_info->byte_offset - GetRegisterInfo().GetFPMROffset();
 assert(offset < GetFPMRBufferSize());
 src = (uint8_t *)GetFPMRBuffer() + offset;
+  } else if (IsGCS(reg)) {
+error = ReadGCS();
+if (error.Fail())
+  return error;
+
+offset = reg_info->byte_offset - GetRegisterInfo().GetGCSOffset();
+assert(offset < GetGCSBufferSize());
+src = (uint8_t *)GetGCSBuffer() + offset;
   } else
 return Status::FromErrorString(
 "failed - register wasn't recognized to be a GPR or an FPR, "
@@ -657,6 +675,17 @@ Status NativeRegisterContextLinux_arm64::WriteRegister(
 ::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
 
 return WriteFPMR();
+  } else if (IsGCS(reg)) {
+error = ReadGCS();
+if (error.Fail())
+  return error;
+
+offset = reg_info->byte_offset - GetRegisterInfo().GetGCSOffset();
+assert(offset < GetGCSBufferSize());
+dst = (uint8_t *)GetGCSBuffer() + offset;
+::memcpy(dst, reg_value.GetBytes(), reg_info->byte_size);
+
+return WriteGCS();
   }
 
   return Status::FromErrorString("Failed to write register value");
@@ -672,6 +701,7 @@ enum RegisterSetType : u

[Lldb-commits] [lldb] [lldb] Preparation for DWARF indexing speedup (PR #123732)

2025-01-21 Thread Pavel Labath via lldb-commits

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

This is part of the work proposed in
. One 
of the change is that the there will be a different structure for holding the 
partial indexes and the final (consolidated) index. To prepare for this, I'm 
making the IndexSet structure a template. The index cache encoding/decoding 
methods are changed into free functions, as they only need to know how to work 
with the final index.

I've moved this functionality to a separate file as all this doesn't really 
depend on the rest of the ManualDWARFIndex and it needs to be public due to its 
use in the unit test (both of which indicate that it could be a component of 
its own).

>From 7f9367f45a46fd56844dc7ade5e3591910a8c057 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Tue, 21 Jan 2025 11:50:31 +0100
Subject: [PATCH] [lldb] Preparation for DWARF indexing speedup

This is part of the work proposed in
.
One of the change is that the there will be a different structure for
holding the partial indexes and the final (consolidated) index. To
prepare for this, I'm making the IndexSet structure a template. The
index cache encoding/decoding methods are changed into free functions,
as they only need to know how to work with the final index.

I've moved this functionality to a separate file as all this doesn't
really depend on the rest of the ManualDWARFIndex and it needs to be
public due to its use in the unit test (both of which indicate that it
could be a component of its own).
---
 .../Plugins/SymbolFile/DWARF/CMakeLists.txt   |   1 +
 .../SymbolFile/DWARF/ManualDWARFIndex.cpp | 181 ++
 .../SymbolFile/DWARF/ManualDWARFIndex.h   |  31 +--
 .../SymbolFile/DWARF/ManualDWARFIndexSet.cpp  | 154 +++
 .../SymbolFile/DWARF/ManualDWARFIndexSet.h|  54 ++
 .../DWARF/DWARFIndexCachingTest.cpp   |  14 +-
 6 files changed, 240 insertions(+), 195 deletions(-)
 create mode 100644 lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.cpp
 create mode 100644 lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.h

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt 
b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
index e87194dfe74cb3..2d2eb73f4513bf 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
+++ b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
@@ -30,6 +30,7 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN
   DWARFUnit.cpp
   LogChannelDWARF.cpp
   ManualDWARFIndex.cpp
+  ManualDWARFIndexSet.cpp
   NameToDIE.cpp
   SymbolFileDWARF.cpp
   SymbolFileDWARFDwo.cpp
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index 6f2c45e74132c1..9e78b17b8f3a51 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -77,8 +77,10 @@ void ManualDWARFIndex::Index() {
   lldb::eDescriptionLevelBrief);
 
   // Include 2 passes per unit to index for extracting DIEs from the unit and
-  // indexing the unit, and then 8 extra entries for finalizing each index set.
-  const uint64_t total_progress = units_to_index.size() * 2 + 8;
+  // indexing the unit, and then extra entries for finalizing each index in the
+  // set.
+  const auto indices = IndexSet::Indices();
+  const uint64_t total_progress = units_to_index.size() * 2 + indices.size();
   Progress progress("Manually indexing DWARF", module_desc.GetData(),
 total_progress, /*debugger=*/nullptr,
 /*minimum_report_time=*/std::chrono::milliseconds(20));
@@ -122,7 +124,7 @@ void ManualDWARFIndex::Index() {
   });
 
   // Now index all DWARF unit in parallel.
-  std::vector sets(num_threads);
+  std::vector> sets(num_threads);
   for_each_unit(
   [this, dwp_dwarf, &sets](size_t worker_id, size_t, DWARFUnit *unit) {
 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
@@ -130,29 +132,22 @@ void ManualDWARFIndex::Index() {
 
   // Merge partial indexes into a single index. Process each index in a set in
   // parallel.
-  auto finalize_fn = [this, &sets, &progress](NameToDIE(IndexSet::*index)) {
-NameToDIE &result = m_set.*index;
-for (auto &set : sets)
-  result.Append(set.*index);
-result.Finalize();
-progress.Increment();
-  };
-
-  task_group.async(finalize_fn, &IndexSet::function_basenames);
-  task_group.async(finalize_fn, &IndexSet::function_fullnames);
-  task_group.async(finalize_fn, &IndexSet::function_methods);
-  task_group.async(finalize_fn, &IndexSet::function_selectors);
-  task_group.async(finalize_fn, &IndexSet::objc_class_selectors);
-  task_group.async(finalize_fn, &IndexSet::globals);
-  task_group.async(finalize_fn, &IndexSet::types);
-  task_group.async(f

[Lldb-commits] [lldb] [lldb] Preparation for DWARF indexing speedup (PR #123732)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

This is part of the work proposed in
;.
 One of the change is that the there will be a different structure for holding 
the partial indexes and the final (consolidated) index. To prepare for this, 
I'm making the IndexSet structure a template. The index cache encoding/decoding 
methods are changed into free functions, as they only need to know how to work 
with the final index.

I've moved this functionality to a separate file as all this doesn't really 
depend on the rest of the ManualDWARFIndex and it needs to be public due to its 
use in the unit test (both of which indicate that it could be a component of 
its own).

---

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


6 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt (+1) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp 
(+20-161) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h (+5-26) 
- (added) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.cpp (+154) 
- (added) lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.h (+54) 
- (modified) lldb/unittests/SymbolFile/DWARF/DWARFIndexCachingTest.cpp (+6-8) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt 
b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
index e87194dfe74cb3..2d2eb73f4513bf 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
+++ b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
@@ -30,6 +30,7 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN
   DWARFUnit.cpp
   LogChannelDWARF.cpp
   ManualDWARFIndex.cpp
+  ManualDWARFIndexSet.cpp
   NameToDIE.cpp
   SymbolFileDWARF.cpp
   SymbolFileDWARFDwo.cpp
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
index 6f2c45e74132c1..9e78b17b8f3a51 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
@@ -77,8 +77,10 @@ void ManualDWARFIndex::Index() {
   lldb::eDescriptionLevelBrief);
 
   // Include 2 passes per unit to index for extracting DIEs from the unit and
-  // indexing the unit, and then 8 extra entries for finalizing each index set.
-  const uint64_t total_progress = units_to_index.size() * 2 + 8;
+  // indexing the unit, and then extra entries for finalizing each index in the
+  // set.
+  const auto indices = IndexSet::Indices();
+  const uint64_t total_progress = units_to_index.size() * 2 + indices.size();
   Progress progress("Manually indexing DWARF", module_desc.GetData(),
 total_progress, /*debugger=*/nullptr,
 /*minimum_report_time=*/std::chrono::milliseconds(20));
@@ -122,7 +124,7 @@ void ManualDWARFIndex::Index() {
   });
 
   // Now index all DWARF unit in parallel.
-  std::vector sets(num_threads);
+  std::vector> sets(num_threads);
   for_each_unit(
   [this, dwp_dwarf, &sets](size_t worker_id, size_t, DWARFUnit *unit) {
 IndexUnit(*unit, dwp_dwarf, sets[worker_id]);
@@ -130,29 +132,22 @@ void ManualDWARFIndex::Index() {
 
   // Merge partial indexes into a single index. Process each index in a set in
   // parallel.
-  auto finalize_fn = [this, &sets, &progress](NameToDIE(IndexSet::*index)) {
-NameToDIE &result = m_set.*index;
-for (auto &set : sets)
-  result.Append(set.*index);
-result.Finalize();
-progress.Increment();
-  };
-
-  task_group.async(finalize_fn, &IndexSet::function_basenames);
-  task_group.async(finalize_fn, &IndexSet::function_fullnames);
-  task_group.async(finalize_fn, &IndexSet::function_methods);
-  task_group.async(finalize_fn, &IndexSet::function_selectors);
-  task_group.async(finalize_fn, &IndexSet::objc_class_selectors);
-  task_group.async(finalize_fn, &IndexSet::globals);
-  task_group.async(finalize_fn, &IndexSet::types);
-  task_group.async(finalize_fn, &IndexSet::namespaces);
+  for (NameToDIE IndexSet::*index : indices) {
+task_group.async([this, &sets, index, &progress]() {
+  NameToDIE &result = m_set.*index;
+  for (auto &set : sets)
+result.Append(set.*index);
+  result.Finalize();
+  progress.Increment();
+});
+  }
   task_group.wait();
 
   SaveToCache();
 }
 
 void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
- IndexSet &set) {
+ IndexSet &set) {
   Log *log = GetLog(DWARFLog::Lookups);
 
   if (log) {
@@ -210,7 +205,7 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, 
SymbolFileDWARFDwo *dwp,
 
 void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit,
  const LanguageType cu_language,
-   

[Lldb-commits] [lldb] [LLDB] Add draft docstrings for SBSaveCoreOptions (PR #123132)

2025-01-21 Thread via lldb-commits

dyung wrote:

@Jlalond This seems to be breaking the LLDB build on multiple bots, can you 
take a look and revert if you need time to investigate?

- https://lab.llvm.org/buildbot/#/builders/181/builds/12112
- https://lab.llvm.org/buildbot/#/builders/59/builds/11453
- https://lab.llvm.org/buildbot/#/builders/141/builds/5631
- https://lab.llvm.org/buildbot/#/builders/18/builds/10190
- https://lab.llvm.org/buildbot/#/builders/195/builds/3803
- https://lab.llvm.org/buildbot/#/builders/197/builds/955
- https://lab.llvm.org/buildbot/#/builders/162/builds/14562

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


[Lldb-commits] [lldb] [LLDB] Add draft docstrings for SBSaveCoreOptions (PR #123132)

2025-01-21 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

@dyung Yeah, I'll revert and I'll figure it out tomorrow

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


[Lldb-commits] [lldb] Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions" (PR #123873)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)


Changes

Reverts llvm/llvm-project#123132

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


1 Files Affected:

- (modified) lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i (-71) 


``diff
diff --git a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i 
b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
index 3e99101203ee9c..e69de29bb2d1d6 100644
--- a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
+++ b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
@@ -1,71 +0,0 @@
-%feature("docstring",
-"A container to specify how to save a core file.
-
-SBSaveCoreOptions includes API's to specify the memory regions and threads to 
include
-when generating a core file. It extends the existing SaveCoreStyle option.
-
-* eSaveCoreFull will save off all thread and memory regions, ignoring the 
memory regions and threads in
-the options object.
-
-* eSaveCoreDirtyOnly pages will capture all threads and all rw- memory 
regions, in addition to the regions specified
-in the options object if they are not already captured.
-
-* eSaveCoreStackOnly will capture all threads, but no memory regions unless 
specified.
-
-* eSaveCoreCustomOnly Custom defers entirely to the SBSaveCoreOptions object 
and will only save what is specified. 
-  Picking custom and specifying nothing will result in an error being returned.
-
-Note that currently ELF Core files are not supported.
-")
-
-%feature("docstring", "
-Set the plugin name to save a Core file with. Only plugins registered with 
Plugin manager will be accepted
-Examples are Minidump and Mach-O."
-) lldb::SBSaveCoreOptions::SetPluginName
-
-%feature("docstring", "
-Get the specified plugin name, or None if the name is not set."
-) lldb::SBSaveCoreOptions::GetPluginName
-
-%feature("docstring", "
-Set the lldb.SaveCoreStyle."
-) lldb::SBSaveCoreOptions::SetStyle
-
-%feature("docstring", "
-Get the specified lldb.SaveCoreStyle, or eSaveCoreUnspecified if not set."
-) lldb::SBSaveCoreOptions::GetStyle
-
-%feature("docstring", "
-Set the file path to save the Core file at."
-) lldb::SBSaveCoreOptions::SetOutputFile
-
-%feature("docstring", "
-Get an SBFileSpec corresponding to the specified output path, or none if 
not set."
-) lldb::SBSaveCoreOptions::GetOutputFile
-
-%feature("docstring", "
-Set the process to save, or unset a process by providing a default 
SBProcess. 
-Resetting will result in the reset of all process specific options, such 
as Threads to save."
-) lldb::SBSaveCoreOptions::SetProcess
-
-%feature("docstring", "
-Add an SBThread to be saved, an error will be returned if an SBThread from 
a different process is specified. 
-The process is set either by the first SBThread added to the options 
container, or explicitly by the SetProcess call."
-) lldb::SBSaveCoreOptions::AddThread
-
-%feature("docstring", "
-Remove an SBthread if present in the container, returns true if a matching 
thread was found and removed."
-) lldb::SBSaveCoreOptions::RemoveThread
-
-%feature("docstring", "
-Add a memory region to save, an error will be returned in the region is 
invalid. 
-Ranges that overlap will be unioned into a single region."
-) lldb::SBSaveCoreOptions::AddMemoryRegionToSave
-
-%feature("docstring", "
-Get an SBThreadCollection of all threads marked to be saved. This 
collection is not sorted according to insertion order."
-) lldb::SBSaveCoreOptions::GetThreadsToSave
-
-%feature("docstring", "
-Unset all options."
-) lldb::SBSaveCoreOptions::Clear

``




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


[Lldb-commits] [lldb] 18ee7e1 - Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions" (#123873)

2025-01-21 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2025-01-21T19:55:17-08:00
New Revision: 18ee7e1792cf4cc9b287ae10063a7c2b7792da8f

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

LOG: Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions" (#123873)

Reverts llvm/llvm-project#123132

Added: 


Modified: 
lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i

Removed: 




diff  --git a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i 
b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
index 3e99101203ee9c..e69de29bb2d1d6 100644
--- a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
+++ b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
@@ -1,71 +0,0 @@
-%feature("docstring",
-"A container to specify how to save a core file.
-
-SBSaveCoreOptions includes API's to specify the memory regions and threads to 
include
-when generating a core file. It extends the existing SaveCoreStyle option.
-
-* eSaveCoreFull will save off all thread and memory regions, ignoring the 
memory regions and threads in
-the options object.
-
-* eSaveCoreDirtyOnly pages will capture all threads and all rw- memory 
regions, in addition to the regions specified
-in the options object if they are not already captured.
-
-* eSaveCoreStackOnly will capture all threads, but no memory regions unless 
specified.
-
-* eSaveCoreCustomOnly Custom defers entirely to the SBSaveCoreOptions object 
and will only save what is specified. 
-  Picking custom and specifying nothing will result in an error being returned.
-
-Note that currently ELF Core files are not supported.
-")
-
-%feature("docstring", "
-Set the plugin name to save a Core file with. Only plugins registered with 
Plugin manager will be accepted
-Examples are Minidump and Mach-O."
-) lldb::SBSaveCoreOptions::SetPluginName
-
-%feature("docstring", "
-Get the specified plugin name, or None if the name is not set."
-) lldb::SBSaveCoreOptions::GetPluginName
-
-%feature("docstring", "
-Set the lldb.SaveCoreStyle."
-) lldb::SBSaveCoreOptions::SetStyle
-
-%feature("docstring", "
-Get the specified lldb.SaveCoreStyle, or eSaveCoreUnspecified if not set."
-) lldb::SBSaveCoreOptions::GetStyle
-
-%feature("docstring", "
-Set the file path to save the Core file at."
-) lldb::SBSaveCoreOptions::SetOutputFile
-
-%feature("docstring", "
-Get an SBFileSpec corresponding to the specified output path, or none if 
not set."
-) lldb::SBSaveCoreOptions::GetOutputFile
-
-%feature("docstring", "
-Set the process to save, or unset a process by providing a default 
SBProcess. 
-Resetting will result in the reset of all process specific options, such 
as Threads to save."
-) lldb::SBSaveCoreOptions::SetProcess
-
-%feature("docstring", "
-Add an SBThread to be saved, an error will be returned if an SBThread from 
a 
diff erent process is specified. 
-The process is set either by the first SBThread added to the options 
container, or explicitly by the SetProcess call."
-) lldb::SBSaveCoreOptions::AddThread
-
-%feature("docstring", "
-Remove an SBthread if present in the container, returns true if a matching 
thread was found and removed."
-) lldb::SBSaveCoreOptions::RemoveThread
-
-%feature("docstring", "
-Add a memory region to save, an error will be returned in the region is 
invalid. 
-Ranges that overlap will be unioned into a single region."
-) lldb::SBSaveCoreOptions::AddMemoryRegionToSave
-
-%feature("docstring", "
-Get an SBThreadCollection of all threads marked to be saved. This 
collection is not sorted according to insertion order."
-) lldb::SBSaveCoreOptions::GetThreadsToSave
-
-%feature("docstring", "
-Unset all options."
-) lldb::SBSaveCoreOptions::Clear



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


[Lldb-commits] [lldb] Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions" (PR #123873)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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


[Lldb-commits] [lldb] Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions" (PR #123873)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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

Reverts llvm/llvm-project#123132

>From 7aac81a4e30f9e46907a60009ec051473089319e Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 21 Jan 2025 19:54:42 -0800
Subject: [PATCH] Revert "[LLDB] Add draft docstrings for SBSaveCoreOptions
 (#123132)"

This reverts commit d33e33fde770214e134ed58f992a5a95a522f7ff.
---
 .../interface/SBSaveCoreOptionsDocstrings.i   | 71 ---
 1 file changed, 71 deletions(-)

diff --git a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i 
b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
index 3e99101203ee9c..e69de29bb2d1d6 100644
--- a/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
+++ b/lldb/bindings/interface/SBSaveCoreOptionsDocstrings.i
@@ -1,71 +0,0 @@
-%feature("docstring",
-"A container to specify how to save a core file.
-
-SBSaveCoreOptions includes API's to specify the memory regions and threads to 
include
-when generating a core file. It extends the existing SaveCoreStyle option.
-
-* eSaveCoreFull will save off all thread and memory regions, ignoring the 
memory regions and threads in
-the options object.
-
-* eSaveCoreDirtyOnly pages will capture all threads and all rw- memory 
regions, in addition to the regions specified
-in the options object if they are not already captured.
-
-* eSaveCoreStackOnly will capture all threads, but no memory regions unless 
specified.
-
-* eSaveCoreCustomOnly Custom defers entirely to the SBSaveCoreOptions object 
and will only save what is specified. 
-  Picking custom and specifying nothing will result in an error being returned.
-
-Note that currently ELF Core files are not supported.
-")
-
-%feature("docstring", "
-Set the plugin name to save a Core file with. Only plugins registered with 
Plugin manager will be accepted
-Examples are Minidump and Mach-O."
-) lldb::SBSaveCoreOptions::SetPluginName
-
-%feature("docstring", "
-Get the specified plugin name, or None if the name is not set."
-) lldb::SBSaveCoreOptions::GetPluginName
-
-%feature("docstring", "
-Set the lldb.SaveCoreStyle."
-) lldb::SBSaveCoreOptions::SetStyle
-
-%feature("docstring", "
-Get the specified lldb.SaveCoreStyle, or eSaveCoreUnspecified if not set."
-) lldb::SBSaveCoreOptions::GetStyle
-
-%feature("docstring", "
-Set the file path to save the Core file at."
-) lldb::SBSaveCoreOptions::SetOutputFile
-
-%feature("docstring", "
-Get an SBFileSpec corresponding to the specified output path, or none if 
not set."
-) lldb::SBSaveCoreOptions::GetOutputFile
-
-%feature("docstring", "
-Set the process to save, or unset a process by providing a default 
SBProcess. 
-Resetting will result in the reset of all process specific options, such 
as Threads to save."
-) lldb::SBSaveCoreOptions::SetProcess
-
-%feature("docstring", "
-Add an SBThread to be saved, an error will be returned if an SBThread from 
a different process is specified. 
-The process is set either by the first SBThread added to the options 
container, or explicitly by the SetProcess call."
-) lldb::SBSaveCoreOptions::AddThread
-
-%feature("docstring", "
-Remove an SBthread if present in the container, returns true if a matching 
thread was found and removed."
-) lldb::SBSaveCoreOptions::RemoveThread
-
-%feature("docstring", "
-Add a memory region to save, an error will be returned in the region is 
invalid. 
-Ranges that overlap will be unioned into a single region."
-) lldb::SBSaveCoreOptions::AddMemoryRegionToSave
-
-%feature("docstring", "
-Get an SBThreadCollection of all threads marked to be saved. This 
collection is not sorted according to insertion order."
-) lldb::SBSaveCoreOptions::GetThreadsToSave
-
-%feature("docstring", "
-Unset all options."
-) lldb::SBSaveCoreOptions::Clear

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


[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

https://github.com/patryk4815 updated 
https://github.com/llvm/llvm-project/pull/123735

>From 1883c703f335d44f5a4cfff8148c8d557ab6af1e Mon Sep 17 00:00:00 2001
From: Patryk Sondej 
Date: Tue, 21 Jan 2025 12:44:44 +0100
Subject: [PATCH 1/2] Added support for `_PYTHON_HOST_PLATFORM` and
 `_PYTHON_SYSCONFIGDATA_NAME` environment variables when cross-compiling LLDB
 with Python, https://peps.python.org/pep-0720/#upstream-support

---
 lldb/CMakeLists.txt | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 85ba4fde17418a..d11c68dd5b96af 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -59,8 +59,23 @@ if (LLDB_ENABLE_PYTHON)
   set(cachestring_LLDB_PYTHON_EXT_SUFFIX
 "Filename extension for native code python modules")
 
+  set(LLDB_USE_HOST_PYTHON FALSE)
+  if(NOT CMAKE_CROSSCOMPILING)
+set(LLDB_USE_HOST_PYTHON TRUE)
+  else()
+# Used when cross-compiling LLDB with Python:
+# - `_PYTHON_HOST_PLATFORM`: Specifies the host platform, e.g., 
'linux-x86_64'.
+# - `_PYTHON_SYSCONFIGDATA_NAME`: The name of the Python configuration 
module containing
+#   platform, build, and configuration details (e.g., 
`_sysconfigdata__linux_x86_64-linux-gnu`).
+# See: https://peps.python.org/pep-0720/#upstream-support
+# If both environment variables are defined, we assume host Python can be 
used.
+if(DEFINED ENV{_PYTHON_HOST_PLATFORM} AND DEFINED 
ENV{_PYTHON_SYSCONFIGDATA_NAME})
+  set(LLDB_USE_HOST_PYTHON TRUE)
+endif()
+  endif()
+
   foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH 
LLDB_PYTHON_EXT_SUFFIX)
-if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
+if(NOT DEFINED ${var} AND LLDB_USE_HOST_PYTHON)
   execute_process(
 COMMAND ${Python3_EXECUTABLE}
   ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py

>From 2bcb3ca530cc77a975542a36027d986ff05efea5 Mon Sep 17 00:00:00 2001
From: Patryk Sondej 
Date: Wed, 22 Jan 2025 05:06:31 +0100
Subject: [PATCH 2/2] get-python-config.py: Replace all sys.* references with
 sysconfig.get_config_var calls

---
 lldb/bindings/python/get-python-config.py | 28 +--
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/lldb/bindings/python/get-python-config.py 
b/lldb/bindings/python/get-python-config.py
index ae84cbb1215a9e..82fc11dd3997ed 100755
--- a/lldb/bindings/python/get-python-config.py
+++ b/lldb/bindings/python/get-python-config.py
@@ -1,5 +1,14 @@
 #!/usr/bin/env python3
 
+# In this script, we should only use the following to retrieve configuration 
values:
+# - `sysconfig.get_config_var`
+# - `sysconfig.get_platform`
+# - `sysconfig.get_path`
+# This is because certain variables may return invalid data during 
cross-compilation, for example:
+# - sys.prefix -> Use sysconfig.get_config_var("prefix") instead.
+# - sys.executable -> Use sysconfig.get_config_var("EXENAME") instead.
+# - os.name -> Use sysconfig.get_platform() for platform detection.
+
 import os
 import sys
 import argparse
@@ -32,20 +41,25 @@ def main():
 # If not, you'll have to use lldb -P or lldb 
-print-script-interpreter-info
 # to figure out where it is.
 try:
-print(relpath_nodots(sysconfig.get_path("platlib"), sys.prefix))
+print(relpath_nodots(sysconfig.get_path("platlib"), 
sysconfig.get_config_var("prefix")))
 except ValueError:
 # Try to fall back to something reasonable if sysconfig's platlib
 # is outside of sys.prefix
 if os.name == "posix":
-print("lib/python%d.%d/site-packages" % sys.version_info[:2])
+print("lib/python%s/site-packages" % 
sysconfig.get_config_var("VERSION"))
 elif os.name == "nt":
 print("Lib\\site-packages")
 else:
 raise
 elif args.variable_name == "LLDB_PYTHON_EXE_RELATIVE_PATH":
 tried = list()
-exe = sys.executable
-prefix = os.path.realpath(sys.prefix)
+exe = sysconfig.get_config_var("EXENAME")
+if not exe:
+# Fallback: 'EXENAME' is not available on Windows
+exe_name = "python" + sysconfig.get_config_var("VERSION") + 
sysconfig.get_config_var("EXE")
+exe = os.path.join(sysconfig.get_config_var("BINDIR"), exe_name)
+
+prefix = os.path.realpath(sysconfig.get_config_var("prefix"))
 while True:
 try:
 print(relpath_nodots(exe, prefix))
@@ -59,13 +73,13 @@ def main():
 continue
 else:
 print(
-"Could not find a relative path to sys.executable 
under sys.prefix",
+"Could not find a relative path to 
sysconfig.get_config_var(\"EXENAME\") under 
sysconfig.get_config_var(\"prefix\")",
 file=sys.stderr,
 )
  

[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)

2025-01-21 Thread via lldb-commits

patryk4815 wrote:

@DavidSpickett I found that `get-python-config.py` wasn't fully correct for 
cross-compilation. 
I've added a comment there specifying which functions should be used.

Guide how to cross compile, eg. for riscv64:
```
export _PYTHON_HOST_PLATFORM="linux-riscv64"
export _PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__linux_riscv64-linux-gnu"
export 
PYTHONPATH="/lib/python3.12/site-packages:/lib/python3.12/site-packages"
```
^ just replace with proper paths in `PYTHONPATH`


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


[Lldb-commits] [lldb] [lldb] Support format string in the prompt (PR #123430)

2025-01-21 Thread Jonas Devlieghere via lldb-commits

https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/123430

>From 10e89226a485d73acfb07ad6d72f3004d270a2f5 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Fri, 17 Jan 2025 16:51:21 -0800
Subject: [PATCH 1/4] [lldb] Support format string in the prompt

Implement ansi::StripAnsiTerminalCodes and fix a long standing bug where
using format strings in lldb's prompt resulted in an incorrect prompt
column width.
---
 lldb/include/lldb/Utility/AnsiTerminal.h| 38 +
 lldb/source/Host/common/Editline.cpp|  4 ++-
 lldb/test/API/terminal/TestEditline.py  | 16 +
 lldb/unittests/Utility/AnsiTerminalTest.cpp | 15 
 4 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Utility/AnsiTerminal.h 
b/lldb/include/lldb/Utility/AnsiTerminal.h
index 67795971d2ca89..22601e873dfe9e 100644
--- a/lldb/include/lldb/Utility/AnsiTerminal.h
+++ b/lldb/include/lldb/Utility/AnsiTerminal.h
@@ -171,7 +171,45 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef 
format,
   }
   return fmt;
 }
+
+inline std::string StripAnsiTerminalCodes(llvm::StringRef str) {
+  std::string stripped;
+  while (!str.empty()) {
+llvm::StringRef left, right;
+
+std::tie(left, right) = str.split(ANSI_ESC_START);
+stripped += left;
+
+// ANSI_ESC_START not found.
+if (left == str && right.empty())
+  break;
+
+auto end = llvm::StringRef::npos;
+for (size_t i = 0; i < right.size(); i++) {
+  char c = right[i];
+  if (c == 'm' || c == 'G') {
+end = i;
+break;
+  }
+  if (isdigit(c) || c == ';')
+continue;
+
+  break;
+}
+
+// ANSI_ESC_END not found.
+if (end != llvm::StringRef::npos) {
+  str = right.substr(end + 1);
+  continue;
+}
+
+stripped += ANSI_ESC_START;
+str = right;
+  }
+  return stripped;
 }
+
+} // namespace ansi
 } // namespace lldb_private
 
 #endif
diff --git a/lldb/source/Host/common/Editline.cpp 
b/lldb/source/Host/common/Editline.cpp
index 6e35b15d69651d..d31fe3af946b37 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -14,6 +14,7 @@
 #include "lldb/Host/Editline.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
+#include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/LLDBAssert.h"
@@ -85,7 +86,8 @@ bool IsOnlySpaces(const EditLineStringType &content) {
 }
 
 static size_t ColumnWidth(llvm::StringRef str) {
-  return llvm::sys::locale::columnWidth(str);
+  std::string stripped = ansi::StripAnsiTerminalCodes(str);
+  return llvm::sys::locale::columnWidth(stripped);
 }
 
 static int GetOperation(HistoryOperation op) {
diff --git a/lldb/test/API/terminal/TestEditline.py 
b/lldb/test/API/terminal/TestEditline.py
index aa7d827e599441..40f8a50e06bf6d 100644
--- a/lldb/test/API/terminal/TestEditline.py
+++ b/lldb/test/API/terminal/TestEditline.py
@@ -69,6 +69,22 @@ def test_prompt_color(self):
 # Column: 16.8
 self.child.expect(re.escape("\x1b[31m(lldb) \x1b[0m\x1b[8G"))
 
+@skipIfAsan
+@skipIfEditlineSupportMissing
+def test_prompt_format_color(self):
+"""Test that we can change the prompt color with a format string."""
+self.launch(use_colors=True)
+# Clear the prefix and suffix setting to simplify the output.
+self.child.send('settings set prompt-ansi-prefix ""\n')
+self.child.send('settings set prompt-ansi-suffix ""\n')
+self.child.send('settings set prompt 
"${ansi.fg.red}(lldb)${ansi.normal} "\n')
+self.child.send("foo")
+# Make sure this change is reflected immediately. Check that the color
+# is set (31) and the cursor position (8) is correct.
+# Prompt: (lldb) _
+# Column: 16.8
+self.child.expect(re.escape("\x1b[31m(lldb)\x1b[0m foo"))
+
 @skipIfAsan
 @skipIfEditlineSupportMissing
 def test_prompt_no_color(self):
diff --git a/lldb/unittests/Utility/AnsiTerminalTest.cpp 
b/lldb/unittests/Utility/AnsiTerminalTest.cpp
index a6dbfd61061420..1ba9565c3f6af3 100644
--- a/lldb/unittests/Utility/AnsiTerminalTest.cpp
+++ b/lldb/unittests/Utility/AnsiTerminalTest.cpp
@@ -16,16 +16,21 @@ TEST(AnsiTerminal, Empty) { EXPECT_EQ("", 
ansi::FormatAnsiTerminalCodes("")); }
 
 TEST(AnsiTerminal, WhiteSpace) {
   EXPECT_EQ(" ", ansi::FormatAnsiTerminalCodes(" "));
+  EXPECT_EQ(" ", ansi::StripAnsiTerminalCodes(" "));
 }
 
 TEST(AnsiTerminal, AtEnd) {
   EXPECT_EQ("abc\x1B[30m",
 ansi::FormatAnsiTerminalCodes("abc${ansi.fg.black}"));
+
+  EXPECT_EQ("abc", ansi::StripAnsiTerminalCodes("abc\x1B[30m"));
 }
 
 TEST(AnsiTerminal, AtStart) {
   EXPECT_EQ("\x1B[30mabc",
 ansi::FormatAnsiTerminalCodes("${ansi.fg.black}abc"));
+
+  EXPECT_EQ("abc", ansi::StripAnsiTerminalCodes("\x1B[30mabc"));
 }
 
 TEST(AnsiTerminal, KnownPrefix) 

[Lldb-commits] [lldb] b9813ce - [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (#123826)

2025-01-21 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2025-01-21T16:54:53-08:00
New Revision: b9813ceb95a81506b0bdedfae5e7b4b9f4d9c6bc

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

LOG: [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events 
(#123826)

Recently I added SBProgress (#119052), and during that original commit I
tested if the progress event was sent over LLDB-DAP, and it was. However
upon the suggestion of @JDevlieghere and @labath we added an external
category (#120171), which I did not test.

This small patch wires up DAP to listen for external events by default,
and adds the external category to the SBDebugger enumeration.

Added: 


Modified: 
lldb/include/lldb/API/SBDebugger.h
lldb/tools/lldb-dap/lldb-dap.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index eb371e33c4951c..e0819f1684f8b8 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -42,12 +42,16 @@ class LLDB_API SBInputReader {
 
 class LLDB_API SBDebugger {
 public:
-  FLAGS_ANONYMOUS_ENUM(){
-  eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
-  eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
-  eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitProgressCategory =
-  lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+  FLAGS_ANONYMOUS_ENUM() {
+eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
+eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
+eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
+eBroadcastBitProgressCategory =
+lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+eBroadcastBitExternalProgress =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
+eBroadcastBitExternalProgressCategory =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgressCategory,
   };
   SBDebugger();
 

diff  --git a/lldb/tools/lldb-dap/lldb-dap.cpp 
b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7e8f7b5f6df679..6b12569d90a831 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -414,7 +414,8 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
 void ProgressEventThreadFunction(DAP &dap) {
   lldb::SBListener listener("lldb-dap.progress.listener");
   dap.debugger.GetBroadcaster().AddListener(
-  listener, lldb::SBDebugger::eBroadcastBitProgress);
+  listener, lldb::SBDebugger::eBroadcastBitProgress |
+lldb::SBDebugger::eBroadcastBitExternalProgress);
   dap.broadcaster.AddListener(listener, eBroadcastBitStopProgressThread);
   lldb::SBEvent event;
   bool done = false;



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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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


[Lldb-commits] [lldb] 2841cdb - [lldb] Support format string in the prompt (#123430)

2025-01-21 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2025-01-21T21:01:02-08:00
New Revision: 2841cdbfda92b3fb5fbec726f3376b198106d496

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

LOG: [lldb] Support format string in the prompt (#123430)

Implement ansi::StripAnsiTerminalCodes and fix a long standing bug where
using format strings in lldb's prompt resulted in an incorrect prompt
column width.

Added: 


Modified: 
lldb/include/lldb/Host/Editline.h
lldb/include/lldb/Utility/AnsiTerminal.h
lldb/source/Core/IOHandler.cpp
lldb/source/Host/common/Editline.cpp
lldb/test/API/terminal/TestEditline.py
lldb/unittests/Editline/EditlineTest.cpp
lldb/unittests/Utility/AnsiTerminalTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/Editline.h 
b/lldb/include/lldb/Host/Editline.h
index 26deba38f8471c..27b863870090cb 100644
--- a/lldb/include/lldb/Host/Editline.h
+++ b/lldb/include/lldb/Host/Editline.h
@@ -152,7 +152,7 @@ using namespace line_editor;
 class Editline {
 public:
   Editline(const char *editor_name, FILE *input_file, FILE *output_file,
-   FILE *error_file, std::recursive_mutex &output_mutex);
+   FILE *error_file, bool color, std::recursive_mutex &output_mutex);
 
   ~Editline();
 
@@ -212,19 +212,23 @@ class Editline {
   }
 
   void SetPromptAnsiPrefix(std::string prefix) {
-m_prompt_ansi_prefix = std::move(prefix);
+if (m_color)
+  m_prompt_ansi_prefix = std::move(prefix);
   }
 
   void SetPromptAnsiSuffix(std::string suffix) {
-m_prompt_ansi_suffix = std::move(suffix);
+if (m_color)
+  m_prompt_ansi_suffix = std::move(suffix);
   }
 
   void SetSuggestionAnsiPrefix(std::string prefix) {
-m_suggestion_ansi_prefix = std::move(prefix);
+if (m_color)
+  m_suggestion_ansi_prefix = std::move(prefix);
   }
 
   void SetSuggestionAnsiSuffix(std::string suffix) {
-m_suggestion_ansi_suffix = std::move(suffix);
+if (m_color)
+  m_suggestion_ansi_suffix = std::move(suffix);
   }
 
   /// Prompts for and reads a single line of user input.
@@ -400,6 +404,7 @@ class Editline {
   CompleteCallbackType m_completion_callback;
   SuggestionCallbackType m_suggestion_callback;
 
+  bool m_color;
   std::string m_prompt_ansi_prefix;
   std::string m_prompt_ansi_suffix;
   std::string m_suggestion_ansi_prefix;

diff  --git a/lldb/include/lldb/Utility/AnsiTerminal.h 
b/lldb/include/lldb/Utility/AnsiTerminal.h
index 67795971d2ca89..1939c49c7b859c 100644
--- a/lldb/include/lldb/Utility/AnsiTerminal.h
+++ b/lldb/include/lldb/Utility/AnsiTerminal.h
@@ -171,7 +171,32 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef 
format,
   }
   return fmt;
 }
+
+inline std::string StripAnsiTerminalCodes(llvm::StringRef str) {
+  std::string stripped;
+  while (!str.empty()) {
+llvm::StringRef left, right;
+
+std::tie(left, right) = str.split(ANSI_ESC_START);
+stripped += left;
+
+// ANSI_ESC_START not found.
+if (left == str && right.empty())
+  break;
+
+size_t end = right.find_first_not_of("0123456789;");
+if (end < right.size() && (right[end] == 'm' || right[end] == 'G')) {
+  str = right.substr(end + 1);
+} else {
+  // ANSI_ESC_END not found.
+  stripped += ANSI_ESC_START;
+  str = right;
+}
+  }
+  return stripped;
 }
+
+} // namespace ansi
 } // namespace lldb_private
 
 #endif

diff  --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp
index 695c2481e353db..ca06b52b874db6 100644
--- a/lldb/source/Core/IOHandler.cpp
+++ b/lldb/source/Core/IOHandler.cpp
@@ -264,7 +264,7 @@ IOHandlerEditline::IOHandlerEditline(
   if (use_editline) {
 m_editline_up = std::make_unique(editline_name, GetInputFILE(),
GetOutputFILE(), GetErrorFILE(),
-   GetOutputMutex());
+   m_color, GetOutputMutex());
 m_editline_up->SetIsInputCompleteCallback(
 [this](Editline *editline, StringList &lines) {
   return this->IsInputCompleteCallback(editline, lines);
@@ -278,12 +278,10 @@ IOHandlerEditline::IOHandlerEditline(
   m_editline_up->SetSuggestionCallback([this](llvm::StringRef line) {
 return this->SuggestionCallback(line);
   });
-  if (m_color) {
-m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes(
-debugger.GetAutosuggestionAnsiPrefix()));
-m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes(
-debugger.GetAutosuggestionAnsiSuffix()));
-  }
+  m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes(
+  debugger.GetAutosuggestionAnsiPrefix()));
+  m_editline_up->SetSuggestionAnsiSuffix(

[Lldb-commits] [lldb] [lldb] Support format string in the prompt (PR #123430)

2025-01-21 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Avoid repeated map lookups (NFC) (PR #123892)

2025-01-21 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Avoid repeated map lookups (NFC) (PR #123892)

2025-01-21 Thread Kazu Hirata via lldb-commits

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Jacob Lalonde via lldb-commits

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

>From 1e14270bbbce2531d51c7153e26d49c2bb868684 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Tue, 21 Jan 2025 13:40:23 -0800
Subject: [PATCH] Wire up DAP to listen to external progress events, and list
 the enumeration in SBDebugger

---
 lldb/include/lldb/API/SBDebugger.h | 12 ++--
 lldb/tools/lldb-dap/lldb-dap.cpp   |  3 ++-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index eb371e33c4951c..212e817e3cba5b 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -42,12 +42,12 @@ class LLDB_API SBInputReader {
 
 class LLDB_API SBDebugger {
 public:
-  FLAGS_ANONYMOUS_ENUM(){
-  eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
-  eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
-  eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitProgressCategory =
-  lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+  FLAGS_ANONYMOUS_ENUM() {
+eBroadcastBitProgress = lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
+eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
+eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
+eBroadcastBitExternalProgress =
+lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
   };
   SBDebugger();
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7e8f7b5f6df679..6b12569d90a831 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -414,7 +414,8 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
 void ProgressEventThreadFunction(DAP &dap) {
   lldb::SBListener listener("lldb-dap.progress.listener");
   dap.debugger.GetBroadcaster().AddListener(
-  listener, lldb::SBDebugger::eBroadcastBitProgress);
+  listener, lldb::SBDebugger::eBroadcastBitProgress |
+lldb::SBDebugger::eBroadcastBitExternalProgress);
   dap.broadcaster.AddListener(listener, eBroadcastBitStopProgressThread);
   lldb::SBEvent event;
   bool done = false;

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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)


Changes

Recently I added SBProgress (#119052), and during that original commit 
I tested if the progress event was sent over LLDB-DAP, and it was. However upon 
the suggestion of @JDevlieghere and @labath we added an 
external category (#120171), which I did not test.

This small patch wires up DAP to listen for external events by default, and 
adds the external category to the SBDebugger enumeration.

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


2 Files Affected:

- (modified) lldb/include/lldb/API/SBDebugger.h (+2-2) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+2-1) 


``diff
diff --git a/lldb/include/lldb/API/SBDebugger.h 
b/lldb/include/lldb/API/SBDebugger.h
index eb371e33c4951c..7f56bf34c37388 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -46,8 +46,8 @@ class LLDB_API SBDebugger {
   eBroadcastBitProgress = 
lldb::DebuggerBroadcastBit::eBroadcastBitProgress,
   eBroadcastBitWarning = lldb::DebuggerBroadcastBit::eBroadcastBitWarning,
   eBroadcastBitError = lldb::DebuggerBroadcastBit::eBroadcastBitError,
-  eBroadcastBitProgressCategory =
-  lldb::DebuggerBroadcastBit::eBroadcastBitProgressCategory,
+  eBroadcastBitExternalProgress =
+  lldb::DebuggerBroadcastBit::eBroadcastBitExternalProgress,
   };
   SBDebugger();
 
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 7e8f7b5f6df679..6b12569d90a831 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -414,7 +414,8 @@ void SendStdOutStdErr(DAP &dap, lldb::SBProcess &process) {
 void ProgressEventThreadFunction(DAP &dap) {
   lldb::SBListener listener("lldb-dap.progress.listener");
   dap.debugger.GetBroadcaster().AddListener(
-  listener, lldb::SBDebugger::eBroadcastBitProgress);
+  listener, lldb::SBDebugger::eBroadcastBitProgress |
+lldb::SBDebugger::eBroadcastBitExternalProgress);
   dap.broadcaster.AddListener(listener, eBroadcastBitStopProgressThread);
   lldb::SBEvent event;
   bool done = false;

``




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


[Lldb-commits] [lldb] [LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (PR #123826)

2025-01-21 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo approved this pull request.


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


[Lldb-commits] [lldb] [LLDB] Add draft docstrings for SBSaveCoreOptions (PR #123132)

2025-01-21 Thread Jacob Lalonde via lldb-commits

Jlalond wrote:

Hey @JDevlieghere, bump for this patch but also a follow up question. Do I need 
to manually add docstrings for the constructors for SBProgress, [the 
webpage](https://lldb.llvm.org/python_api/lldb.SBProgress.html) reflects the 
method but no the constructor(s).

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


[Lldb-commits] [lldb] [LLDB] Add draft docstrings for SBSaveCoreOptions (PR #123132)

2025-01-21 Thread Jonas Devlieghere via lldb-commits

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

🚢

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