[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

2025-03-10 Thread Julius Alexandre via lldb-commits

https://github.com/wizardengineer updated 
https://github.com/llvm/llvm-project/pull/130516

>From 161bdb32b284d2370b138e72a8a1ad560b258ba9 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalgh...@users.noreply.github.com>
Date: Sun, 9 Mar 2025 16:20:47 -0400
Subject: [PATCH 1/6] Change ValueObject::GetData to return llvm::Expected

---
 lldb/include/lldb/ValueObject/ValueObject.h   |  2 +-
 .../AppleObjCRuntime/AppleObjCRuntime.cpp |  5 ++--
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 12 
 lldb/source/ValueObject/ValueObject.cpp   | 28 +--
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/lldb/include/lldb/ValueObject/ValueObject.h 
b/lldb/include/lldb/ValueObject/ValueObject.h
index 06d2589002ed0..2ee7f99718416 100644
--- a/lldb/include/lldb/ValueObject/ValueObject.h
+++ b/lldb/include/lldb/ValueObject/ValueObject.h
@@ -757,7 +757,7 @@ class ValueObject {
   virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
 uint32_t item_count = 1);
 
-  virtual uint64_t GetData(DataExtractor &data, Status &error);
+  virtual llvm::Expected GetData();
 
   virtual bool SetData(DataExtractor &data, Status &error);
 
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index ad60290382c02..69856d4592843 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -551,9 +551,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
 
 DataExtractor data;
 data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
-Status error;
-dict_entry->GetData(data, error);
-if (error.Fail()) return ThreadSP();
+auto data_or_err = dict_entry->GetData();
+if (!data_or_err) return ThreadSP();
 
 lldb::offset_t data_offset = 0;
 auto dict_entry_key = data.GetAddress(&data_offset);
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 4ca4752310868..763a80faa914a 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -247,13 +247,15 @@ static lldb::addr_t GetVTableAddress(Process &process,
   // We have an object already read from process memory,
   // so just extract VTable pointer from it
 
-  DataExtractor data;
-  Status err;
-  auto size = valobj.GetData(data, err);
-  if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size)
+  auto data_or_err = valobj.GetData();
+  if (!data_or_err)
+return LLDB_INVALID_ADDRESS;
+
+  auto size = data_or_err->GetByteSize();
+  if (vbtable_ptr_offset + data_or_err->GetAddressByteSize() > size)
 return LLDB_INVALID_ADDRESS;
 
-  return data.GetAddress(&vbtable_ptr_offset);
+  return data_or_err->GetAddress(&vbtable_ptr_offset);
 }
 
 static int64_t ReadVBaseOffsetFromVTable(Process &process,
diff --git a/lldb/source/ValueObject/ValueObject.cpp 
b/lldb/source/ValueObject/ValueObject.cpp
index eac24353de90b..05cbc5489d25e 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -691,13 +691,20 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, 
uint32_t item_idx,
   ValueObjectSP pointee_sp = Dereference(error);
   if (error.Fail() || pointee_sp.get() == nullptr)
 return 0;
-  return pointee_sp->GetData(data, error);
+  auto data_or_err = pointee_sp->GetData();
+  if (!data_or_err)
+return 0;
+  data = *data_or_err;
+  return data.GetByteSize();
 } else {
   ValueObjectSP child_sp = GetChildAtIndex(0);
   if (child_sp.get() == nullptr)
 return 0;
-  Status error;
-  return child_sp->GetData(data, error);
+  auto data_or_err = child_sp->GetData();
+  if (!data_or_err)
+return 0;
+  data = *data_or_err;
+  return data.GetByteSize();
 }
 return true;
   } else /* (items > 1) */
@@ -764,22 +771,27 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, 
uint32_t item_idx,
   return 0;
 }
 
-uint64_t ValueObject::GetData(DataExtractor &data, Status &error) {
+llvm::Expected ValueObject::GetData() {
   UpdateValueIfNeeded(false);
   ExecutionContext exe_ctx(GetExecutionContextRef());
-  error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
+  DataExtractor data;
+  Status error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
   if (error.Fail()) {
 if (m_data.GetByteSize()) {
   data = m_data;
   error.Clear();
-  return data.GetByteSize();
+  data.SetAddressByteSize(m_data.GetAddressByteSize());
+  data.SetByteOrder(m_data.GetByteOrder());
+  return data;
 } else {
-  return 0;
+  retu

[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

2025-03-10 Thread Julius Alexandre via lldb-commits

https://github.com/wizardengineer updated 
https://github.com/llvm/llvm-project/pull/130516

>From 161bdb32b284d2370b138e72a8a1ad560b258ba9 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalgh...@users.noreply.github.com>
Date: Sun, 9 Mar 2025 16:20:47 -0400
Subject: [PATCH 1/5] Change ValueObject::GetData to return llvm::Expected

---
 lldb/include/lldb/ValueObject/ValueObject.h   |  2 +-
 .../AppleObjCRuntime/AppleObjCRuntime.cpp |  5 ++--
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 12 
 lldb/source/ValueObject/ValueObject.cpp   | 28 +--
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/lldb/include/lldb/ValueObject/ValueObject.h 
b/lldb/include/lldb/ValueObject/ValueObject.h
index 06d2589002ed0..2ee7f99718416 100644
--- a/lldb/include/lldb/ValueObject/ValueObject.h
+++ b/lldb/include/lldb/ValueObject/ValueObject.h
@@ -757,7 +757,7 @@ class ValueObject {
   virtual size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
 uint32_t item_count = 1);
 
-  virtual uint64_t GetData(DataExtractor &data, Status &error);
+  virtual llvm::Expected GetData();
 
   virtual bool SetData(DataExtractor &data, Status &error);
 
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
index ad60290382c02..69856d4592843 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
@@ -551,9 +551,8 @@ ThreadSP AppleObjCRuntime::GetBacktraceThreadFromException(
 
 DataExtractor data;
 data.SetAddressByteSize(dict_entry->GetProcessSP()->GetAddressByteSize());
-Status error;
-dict_entry->GetData(data, error);
-if (error.Fail()) return ThreadSP();
+auto data_or_err = dict_entry->GetData();
+if (!data_or_err) return ThreadSP();
 
 lldb::offset_t data_offset = 0;
 auto dict_entry_key = data.GetAddress(&data_offset);
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 4ca4752310868..763a80faa914a 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -247,13 +247,15 @@ static lldb::addr_t GetVTableAddress(Process &process,
   // We have an object already read from process memory,
   // so just extract VTable pointer from it
 
-  DataExtractor data;
-  Status err;
-  auto size = valobj.GetData(data, err);
-  if (err.Fail() || vbtable_ptr_offset + data.GetAddressByteSize() > size)
+  auto data_or_err = valobj.GetData();
+  if (!data_or_err)
+return LLDB_INVALID_ADDRESS;
+
+  auto size = data_or_err->GetByteSize();
+  if (vbtable_ptr_offset + data_or_err->GetAddressByteSize() > size)
 return LLDB_INVALID_ADDRESS;
 
-  return data.GetAddress(&vbtable_ptr_offset);
+  return data_or_err->GetAddress(&vbtable_ptr_offset);
 }
 
 static int64_t ReadVBaseOffsetFromVTable(Process &process,
diff --git a/lldb/source/ValueObject/ValueObject.cpp 
b/lldb/source/ValueObject/ValueObject.cpp
index eac24353de90b..05cbc5489d25e 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -691,13 +691,20 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, 
uint32_t item_idx,
   ValueObjectSP pointee_sp = Dereference(error);
   if (error.Fail() || pointee_sp.get() == nullptr)
 return 0;
-  return pointee_sp->GetData(data, error);
+  auto data_or_err = pointee_sp->GetData();
+  if (!data_or_err)
+return 0;
+  data = *data_or_err;
+  return data.GetByteSize();
 } else {
   ValueObjectSP child_sp = GetChildAtIndex(0);
   if (child_sp.get() == nullptr)
 return 0;
-  Status error;
-  return child_sp->GetData(data, error);
+  auto data_or_err = child_sp->GetData();
+  if (!data_or_err)
+return 0;
+  data = *data_or_err;
+  return data.GetByteSize();
 }
 return true;
   } else /* (items > 1) */
@@ -764,22 +771,27 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, 
uint32_t item_idx,
   return 0;
 }
 
-uint64_t ValueObject::GetData(DataExtractor &data, Status &error) {
+llvm::Expected ValueObject::GetData() {
   UpdateValueIfNeeded(false);
   ExecutionContext exe_ctx(GetExecutionContextRef());
-  error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
+  DataExtractor data;
+  Status error = m_value.GetValueAsData(&exe_ctx, data, GetModule().get());
   if (error.Fail()) {
 if (m_data.GetByteSize()) {
   data = m_data;
   error.Clear();
-  return data.GetByteSize();
+  data.SetAddressByteSize(m_data.GetAddressByteSize());
+  data.SetByteOrder(m_data.GetByteOrder());
+  return data;
 } else {
-  return 0;
+  retu

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,290 @@
+//===-- NativeProcessAIX.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "NativeProcessAIX.h"
+#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Host/posix/ProcessLauncherPosixFork.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static Status EnsureFDFlags(int fd, int flags) {
+  Status error;
+
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1) {
+error = Status::FromErrno();
+return error;
+  }
+
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+error = Status::FromErrno();
+return error;
+  }
+
+  return error;
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+lldb::addr_t NativeProcessAIX::GetSharedLibraryInfoAddress() {
+  return LLDB_INVALID_ADDRESS;
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

> I started reviewing this, but I got a feeling that you did not actually push 
> the changes that you made.
> 
> Does the PR accurately reflect the latest version of the patch?

Hi @labath , I am in the process of making the changes. will push them together 
and post a comment once I am done

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


[Lldb-commits] [lldb] [lldb][Mangled] Use early-return style in GetDemangledName (PR #130622)

2025-03-10 Thread Pavel Labath via lldb-commits

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

This looks good, although the "re-demangling" part sounds scary :)

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


[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

2025-03-10 Thread Julius Alexandre via lldb-commits

wizardengineer wrote:

I added another wave of refactors, I'll add more changes, once this current 
wave(commit) is approved. And I'll continue to incrementally add changes to 
make it easier to manage.

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


[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

2025-03-10 Thread Julius Alexandre via lldb-commits


@@ -46,19 +46,27 @@ bool TypeFormatImpl_Format::FormatObject(ValueObject 
*valobj,
 Value &value(valobj->GetValue());
 const Value::ContextType context_type = value.GetContextType();
 ExecutionContext exe_ctx(valobj->GetExecutionContextRef());
-DataExtractor data;
 
+auto data_or_err = valobj->GetData();

wizardengineer wrote:

I think this is a practical approach?

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


[Lldb-commits] [lldb] [lldb][Mach-O] Don't read symbol table of specially marked binary (PR #129967)

2025-03-10 Thread Pavel Labath via lldb-commits

labath wrote:

>  I create the specially named section by compiling an assembly file that puts 
> a byte in the section which makes for a bit of a messy Makefile

You probably don't need an asm file for that. There are at least [two 
ways](https://godbolt.org/z/4sTrdrT49) to generate a random section from C:
```
asm(R"(.section ".text.foo"; .byte 0)");

void  __attribute__((section(".text.bar"))) f(){}
```

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


[Lldb-commits] [lldb] [lldb] Split TestGdbRemoteFork test to avoid timeout (PR #129614)

2025-03-10 Thread David Spickett via lldb-commits

DavidSpickett wrote:

You could make the test binary a cmake dependency, see 
`lldb/test/CMakeLists.txt`. Perhaps in:
```
if(TARGET lldb-server)
  add_lldb_test_dependency(lldb-server)
endif()
```
This means if you ran the test directly without `ninja check-lldb`, it would 
fail, but this would apply to any test using `lldb-server` as well so it's no 
worse.

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


[Lldb-commits] [lldb] 502385c - [lldb] Remove an extraneous `printf` statement. (#130453)

2025-03-10 Thread via lldb-commits

Author: John Harrison
Date: 2025-03-10T11:38:03Z
New Revision: 502385c2412aa04867dc7386296a2f9bc4745d36

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

LOG: [lldb] Remove an extraneous `printf` statement. (#130453)

This was missed in review but is showing up in lldb-dap output.

Added: 


Modified: 
lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm

Removed: 




diff  --git a/lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm 
b/lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm
index cb6c2457df1e3..c3a430bda7fa5 100644
--- a/lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/MemoryMonitorMacOSX.mm
@@ -32,7 +32,6 @@ void Start() override {
   }
 });
 dispatch_activate(m_memory_pressure_source);
-printf("Started\n");
   }
 
   void Stop() override {



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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,265 @@
+//===-- NativeProcessAIX.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "NativeProcessAIX.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  Error error;
+
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1) {
+error = errorCodeToError(errnoAsErrorCode());
+return error;
+  }
+
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+error = errorCodeToError(errnoAsErrorCode());
+return error;
+  }
+
+  return error;
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtocol(pid, terminal_fd, delegate), m_manager(manager),
+  m_arch(arch) {
+  manager.AddProcess(*this);
+  if (m_terminal_fd != -1) {
+Status status =

[Lldb-commits] [lldb] [lldb] Clean up UnwindAssemblyInstEmulation (PR #129030)

2025-03-10 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AIX] Host.cpp for AIX (PR #130582)

2025-03-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dhruv Srivastava (DhruvSrivastavaX)


Changes

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

Added base file - aix/Host.cpp for Process info

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


2 Files Affected:

- (modified) lldb/source/Host/CMakeLists.txt (+1) 
- (added) lldb/source/Host/aix/Host.cpp (+109) 


``diff
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 9be0c06a516ba..52ef67feeb6ab 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -135,6 +135,7 @@ else()
 
   elseif (CMAKE_SYSTEM_NAME MATCHES "AIX")
 add_host_subdirectory(aix
+  aix/Host.cpp
   aix/HostInfoAIX.cpp
   )
   endif()
diff --git a/lldb/source/Host/aix/Host.cpp b/lldb/source/Host/aix/Host.cpp
new file mode 100644
index 0..38c77b4959ead
--- /dev/null
+++ b/lldb/source/Host/aix/Host.cpp
@@ -0,0 +1,109 @@
+//===-- source/Host/aix/Host.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Host/Host.h"
+#include "lldb/Utility/ProcessInfo.h"
+#include "lldb/Utility/Status.h"
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+enum class ProcessState {
+  Unknown,
+  Dead,
+  DiskSleep,
+  Idle,
+  Paging,
+  Parked,
+  Running,
+  Sleeping,
+  TracedOrStopped,
+  Zombie,
+};
+}
+
+namespace lldb_private {
+class ProcessLaunchInfo;
+}
+
+static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
+  ProcessState &State, ::pid_t &TracerPid,
+  ::pid_t &Tgid) {
+  return false;
+}
+
+static void GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+  ProcessInstanceInfo &process_info,
+  ProcessState &State, ::pid_t &tracerpid) {
+  return false;
+}
+
+uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
+ ProcessInstanceInfoList &process_infos) {
+  static const char procdir[] = "/proc/";
+
+  DIR *dirproc = opendir(procdir);
+  if (dirproc) {
+struct dirent *direntry = nullptr;
+const uid_t our_uid = getuid();
+const lldb::pid_t our_pid = getpid();
+bool all_users = match_info.GetMatchAllUsers();
+
+while ((direntry = readdir(dirproc)) != nullptr) {
+
+  lldb::pid_t pid = atoi(direntry->d_name);
+
+  // Skip this process.
+  if (pid == our_pid)
+continue;
+
+  ::pid_t tracerpid;
+  ProcessState State;
+  ProcessInstanceInfo process_info;
+
+  if (!GetProcessAndStatInfo(pid, process_info, State, tracerpid))
+continue;
+
+  // Skip if process is being debugged.
+  if (tracerpid != 0)
+continue;
+
+  if (State == ProcessState::Zombie)
+continue;
+
+  // Check for user match if we're not matching all users and not running
+  // as root.
+  if (!all_users && (our_uid != 0) && (process_info.GetUserID() != 
our_uid))
+continue;
+
+  if (match_info.Matches(process_info))
+process_infos.push_back(process_info);
+}
+
+closedir(dirproc);
+  }
+
+  return process_infos.size();
+}
+
+bool Host::GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &process_info) {
+  ::pid_t tracerpid;
+  ProcessState State;
+  return GetProcessAndStatInfo(pid, process_info, State, tracerpid);
+}
+
+Environment Host::GetEnvironment() { return Environment(environ); }
+
+Status Host::ShellExpandArguments(ProcessLaunchInfo &launch_info) {
+  return Status("unimplemented");
+}

``




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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");
+
+  return data.substr(0, length);
+}
+
+static Expected ReadUntil(IOObjectSP &descriptor,
+   StringRef delimiter) {
+  std::string buffer;
+  buffer.reserve(delimiter.size() + 1);
+  while (!llvm::StringRef(buffer).ends_with(delimiter)) {
+auto next = ReadFull(descriptor, 1);
+if (auto Err = next.takeError())
+  return std::move(Err);
+buffer += *next;
+  }
+  return buffer.substr(0, buffer.size() - delimiter.size());
+}
+
+static Error ReadExpected(IOObjectSP &descriptor, StringRef want) {
+  auto got = ReadFull(descriptor, want.size());
+  if (auto Err = got.takeError())
+return Err;
+  if (*got != want) {
+return createStringError("want %s, got %s", want.str().c_str(),
+ got->c_str());
+  }
+  return Error::success();
+}
+
+namespace lldb_dap {
+
+const std::error_code Transport::kEOF =
+std::error_code(0x1001, std::generic_category());

labath wrote:

Let's not add new members to scopes we don't control. The most llvm-y way to do 
this kind of thing would be to define a new ErrorInfo type (EOFError?).

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");
+
+  return data.substr(0, length);
+}
+
+static Expected ReadUntil(IOObjectSP &descriptor,
+   StringRef delimiter) {
+  std::string buffer;
+  buffer.reserve(delimiter.size() + 1);
+  while (!llvm::StringRef(buffer).ends_with(delimiter)) {
+auto next = ReadFull(descriptor, 1);
+if (auto Err = next.takeError())
+  return std::move(Err);
+buffer += *next;
+  }
+  return buffer.substr(0, buffer.size() - delimiter.size());
+}
+
+static Error ReadExpected(IOObjectSP &descriptor, StringRef want) {
+  auto got = ReadFull(descriptor, want.size());
+  if (auto Err = got.takeError())
+return Err;
+  if (*got != want) {
+return createStringError("want %s, got %s", want.str().c_str(),
+ got->c_str());
+  }
+  return Error::success();
+}
+
+namespace lldb_dap {
+
+const std::error_code Transport::kEOF =
+std::error_code(0x1001, std::generic_category());
+
+Transport::Transport(StringRef client_name, IOObjectSP input, IOObjectSP 
output)
+: m_client_name(client_name), m_input(std::move(input)),
+  m_output(std::move(output)) {}
+
+Expected Transport::Read(std::ofstream *log) {
+  // If we don't find the expected header we have reached EOF.
+  if (auto Err = ReadExpected(m_input, "Content-Length: "))
+return std::move(Err);
+
+  auto rawLength = ReadUntil(m_input, "\r\n\r\n");
+  if (auto Err = rawLength.takeError())
+return std::move(Err);
+
+  size_t length;
+  if (!to_integer(*rawLength, length))
+return createStringError("invalid content length %s", rawLength->c_str());
+
+  auto rawJSON = ReadFull(m_input, length);
+  if (auto Err = rawJSON.takeError())
+return std::move(Err);
+  if (rawJSON->length() != length)
+return createStringError(
+"malformed request, expected %ld bytes, got %ld bytes", length,

labath wrote:

Also, `%ld` is not a correct way to print a variable of type `size_t`. It's 
`%zd`, but I think it'd be even better to avoid this question and format these 
strings with `llvm::formatv`, even though the result is a bit longer.

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");
+
+  return data.substr(0, length);
+}
+
+static Expected ReadUntil(IOObjectSP &descriptor,
+   StringRef delimiter) {
+  std::string buffer;
+  buffer.reserve(delimiter.size() + 1);
+  while (!llvm::StringRef(buffer).ends_with(delimiter)) {
+auto next = ReadFull(descriptor, 1);
+if (auto Err = next.takeError())
+  return std::move(Err);
+buffer += *next;
+  }
+  return buffer.substr(0, buffer.size() - delimiter.size());
+}
+
+static Error ReadExpected(IOObjectSP &descriptor, StringRef want) {
+  auto got = ReadFull(descriptor, want.size());
+  if (auto Err = got.takeError())
+return Err;
+  if (*got != want) {
+return createStringError("want %s, got %s", want.str().c_str(),
+ got->c_str());
+  }
+  return Error::success();
+}
+
+namespace lldb_dap {
+
+const std::error_code Transport::kEOF =
+std::error_code(0x1001, std::generic_category());
+
+Transport::Transport(StringRef client_name, IOObjectSP input, IOObjectSP 
output)
+: m_client_name(client_name), m_input(std::move(input)),
+  m_output(std::move(output)) {}
+
+Expected Transport::Read(std::ofstream *log) {
+  // If we don't find the expected header we have reached EOF.
+  if (auto Err = ReadExpected(m_input, "Content-Length: "))
+return std::move(Err);
+
+  auto rawLength = ReadUntil(m_input, "\r\n\r\n");

labath wrote:

Is there any risk in this appearing in the middle of a single block returned by 
the read call (e.g. if the transport layer merges the `\n` terminating one 
request with the subsequent request)?

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");

labath wrote:

```suggestion
return makeError();
```

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -838,19 +775,16 @@ llvm::Error DAP::Loop() {
 StopEventHandlers();
   });
   while (!disconnecting) {
-llvm::json::Object object;
-lldb_dap::PacketStatus status = GetNextObject(object);
-
-if (status == lldb_dap::PacketStatus::EndOfFile) {
-  break;
-}
-
-if (status != lldb_dap::PacketStatus::Success) {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "failed to send packet");
+auto next = transport.Read(log);
+if (auto Err = next.takeError()) {
+  // On EOF, simply break out of the loop.
+  std::error_code ec = llvm::errorToErrorCode(std::move(Err));
+  if (ec == Transport::kEOF)
+break;
+  return llvm::errorCodeToError(ec);
 }

labath wrote:

Then this would be something like:
```suggestion
if (auto Err = next.takeError()) {
  // On EOF, simply break out of the loop.
  return handleErrors(std::move(Err), [](const EOFError &) {});
}
```

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


[Lldb-commits] [lldb] [lldb] Remove an extraneous `printf` statement. (PR #130453)

2025-03-10 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,130 @@
+//===-- NativeProcessAIX.h -- -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef liblldb_NativeProcessAIX_H_
+#define liblldb_NativeProcessAIX_H_
+
+#include 
+#include 
+
+#include "lldb/Host/Debug.h"
+#include "lldb/Host/HostThread.h"
+#include "lldb/Target/MemoryRegionInfo.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/lldb-types.h"
+#include "llvm/ADT/SmallPtrSet.h"
+
+#include "NativeThreadAIX.h"
+#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
+#include "lldb/Host/common/NativeProcessProtocol.h"
+
+namespace lldb_private {
+class Status;
+class Scalar;
+
+namespace process_aix {
+/// \class NativeProcessAIX
+/// Manages communication with the inferior (debugee) process.
+///
+/// Upon construction, this class prepares and launches an inferior process
+/// for debugging.
+///
+/// Changes in the inferior process state are broadcasted.
+class NativeProcessAIX : public NativeProcessProtocol,
+ private NativeProcessSoftwareSingleStep {
+public:
+  class Manager : public NativeProcessProtocol::Manager {
+  public:
+Manager(MainLoop &mainloop);
+
+llvm::Expected>
+Launch(ProcessLaunchInfo &launch_info,
+   NativeDelegate &native_delegate) override;
+
+llvm::Expected>
+Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override;
+
+Extension GetSupportedExtensions() const override;
+
+void AddProcess(NativeProcessAIX &process) { m_processes.insert(&process); 
}
+
+void RemoveProcess(NativeProcessAIX &process) {
+  m_processes.erase(&process);
+}
+
+// Collect an event for the given tid, waiting for it if necessary.
+void CollectThread(::pid_t tid);
+
+  private:
+MainLoop::SignalHandleUP m_sigchld_handle;
+
+llvm::SmallPtrSet m_processes;
+
+void SigchldHandler();
+  };
+
+  // NativeProcessProtocol Interface
+
+  ~NativeProcessAIX() override { m_manager.RemoveProcess(*this); }
+
+  Status Resume(const ResumeActionList &resume_actions) override;
+
+  Status Halt() override;
+
+  Status Detach() override;
+
+  Status Signal(int signo) override;
+
+  Status Interrupt() override;
+
+  Status Kill() override;
+
+  const ArchSpec &GetArchitecture() const override { return m_arch; }
+
+  Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
+   bool hardware) override;
+
+  Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false) override;
+
+  Status GetFileLoadAddress(const llvm::StringRef &file_name,
+lldb::addr_t &load_addr) override;
+
+  static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
+  void *data = nullptr, size_t data_size = 0,
+  long *result = nullptr);

DhruvSrivastavaX wrote:

For now I've made sure that things compile, and I am pushing more changes. 
Please let me know what works better for you after this.

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Dhruv Srivastava via lldb-commits

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


[Lldb-commits] [lldb] fe544d4 - [lldb] Add more ARM checks in TestLldbGdbServer.py (#130277)

2025-03-10 Thread via lldb-commits

Author: David Spickett
Date: 2025-03-10T10:10:19Z
New Revision: fe544d404d841ef44aebf4fc36948fd1e1d89685

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

LOG: [lldb] Add more ARM checks in TestLldbGdbServer.py (#130277)

When https://github.com/llvm/llvm-project/pull/130034 enabled RISC-V
here I noticed that these should run for ARM as well.

ARM only has 4 argument registers, which matches Arm's ABI for it:
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#core-registers

The ABI defines a link register LR, and I assume that's what becomes
'ra' in LLDB.

Tested on ARM and AArch64 Linux.

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 7d0e6e9a970eb..590024ef77119 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1344,6 +1344,13 @@ def isAArch64(self):
 arch = self.getArchitecture().lower()
 return arch in ["aarch64", "arm64", "arm64e"]
 
+def isARM(self):
+"""Returns true if the architecture is ARM, meaning 32-bit ARM. Which 
could
+be M profile, A profile Armv7-a, or the AArch32 mode of Armv8-a."""
+return not self.isAArch64() and (
+self.getArchitecture().lower().startswith("arm")
+)
+
 def isAArch64SVE(self):
 return self.isAArch64() and "sve" in self.getCPUInfo()
 

diff  --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py 
b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
index ce75e3e89e0a6..12c97bc62dcef 100644
--- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -199,12 +199,12 @@ def 
test_qRegisterInfo_contains_required_generics_debugserver(self):
 if not self.isRISCV():
 self.assertIn("flags", generic_regs)
 
-if self.isRISCV():
-# Special RISC-V register for a return address
+if self.isRISCV() or self.isAArch64() or self.isARM():
+# Specific register for a return address
 self.assertIn("ra", generic_regs)
 
-# RISC-V's function arguments registers
-for i in range(1, 9):
+# Function arguments registers
+for i in range(1, 5 if self.isARM() else 9):
 self.assertIn(f"arg{i}", generic_regs)
 
 def test_qRegisterInfo_contains_at_least_one_register_set(self):



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


[Lldb-commits] [lldb] [lldb][AIX] Host.cpp for AIX (PR #130582)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,109 @@
+//===-- source/Host/aix/Host.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Host/Host.h"
+#include "lldb/Utility/ProcessInfo.h"
+#include "lldb/Utility/Status.h"
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+
+namespace {
+enum class ProcessState {
+  Unknown,
+  Dead,
+  DiskSleep,
+  Idle,
+  Paging,
+  Parked,
+  Running,
+  Sleeping,
+  TracedOrStopped,
+  Zombie,
+};
+}
+
+namespace lldb_private {
+class ProcessLaunchInfo;
+}
+
+static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
+  ProcessState &State, ::pid_t &TracerPid,
+  ::pid_t &Tgid) {
+  return false;
+}
+
+static void GetProcessArgs(::pid_t pid, ProcessInstanceInfo &process_info) {}
+
+static bool GetProcessAndStatInfo(::pid_t pid,
+  ProcessInstanceInfo &process_info,
+  ProcessState &State, ::pid_t &tracerpid) {
+  return false;
+}
+
+uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
+ ProcessInstanceInfoList &process_infos) {

labath wrote:

IIUC, this whole function is right now equivalent to `return 0` (because the 
static functions above are stubbed out. If the goal is to provide an empty 
implementation (so that the rest of code can build), can you do just that?

If you want to actually implement this function, then I'd like to see the 
static functions implemented as well (so that I can e.g. see whether it makes 
sense to share the code with the linux implementation).

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


[Lldb-commits] [lldb] [lldb] Avoid force loading symbol files in statistics collection (PR #129593)

2025-03-10 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread John Harrison via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");
+
+  return data.substr(0, length);
+}
+
+static Expected ReadUntil(IOObjectSP &descriptor,
+   StringRef delimiter) {
+  std::string buffer;
+  buffer.reserve(delimiter.size() + 1);
+  while (!llvm::StringRef(buffer).ends_with(delimiter)) {
+auto next = ReadFull(descriptor, 1);
+if (auto Err = next.takeError())
+  return std::move(Err);
+buffer += *next;
+  }
+  return buffer.substr(0, buffer.size() - delimiter.size());
+}
+
+static Error ReadExpected(IOObjectSP &descriptor, StringRef want) {
+  auto got = ReadFull(descriptor, want.size());
+  if (auto Err = got.takeError())
+return Err;
+  if (*got != want) {
+return createStringError("want %s, got %s", want.str().c_str(),
+ got->c_str());
+  }
+  return Error::success();
+}
+
+namespace lldb_dap {
+
+const std::error_code Transport::kEOF =
+std::error_code(0x1001, std::generic_category());
+
+Transport::Transport(StringRef client_name, IOObjectSP input, IOObjectSP 
output)
+: m_client_name(client_name), m_input(std::move(input)),
+  m_output(std::move(output)) {}
+
+Expected Transport::Read(std::ofstream *log) {
+  // If we don't find the expected header we have reached EOF.
+  if (auto Err = ReadExpected(m_input, "Content-Length: "))
+return std::move(Err);
+
+  auto rawLength = ReadUntil(m_input, "\r\n\r\n");

ashgti wrote:

Shouldn't break the output, even though it will produce something that looks 
like a message in the middle of a message.

We're not searching for the `Content-Length: ` header, we expect it to be those 
exact bytes, per the spec.  The messages should always be formatted like:

```
Content-Length: (\d+)\r\n\r\n(.{\1})
```

Or more generally:

```


   = "Content-Length: "
   = \d+
   = "\r\n\r\n"
   = length bytes
```

Otherwise the message is malformed.

Once we have a message header, if the `Content-Length: ` string appears in the 
body of the message, that should be okay. 
e.g.

```
int main() {
  printf("Content-Length: 51\r\n\r\n{\"command\":\"disconnect\",\"seq\": 
1,\"type\": \"request\"}");
  return 0;
}
```

Works fine with VSCode and doesn't have any problems with lldb-dap.

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread John Harrison via lldb-commits


@@ -0,0 +1,146 @@
+//===-- Transport.cpp 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Transport.h"
+#include "Protocol.h"
+#include "c++/v1/__system_error/error_code.h"
+#include "lldb/Utility/IOObject.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/lldb-forward.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+static Expected ReadFull(IOObjectSP &descriptor, size_t length) {
+  if (!descriptor || !descriptor->IsValid())
+return createStringError("transport input is closed");
+
+  std::string data;
+  data.resize(length);
+
+  auto status = descriptor->Read(data.data(), length);
+  if (status.Fail())
+return status.takeError();
+
+  // If we got back zero then we have reached EOF.
+  if (length == 0)
+return createStringError(Transport::kEOF, "end-of-file");

ashgti wrote:

I tweaked the `Transport` class to log any errors it encounters and return 
`std::nullopt` whenever there is a problem, including EOF.

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


[Lldb-commits] [lldb] [lldb-dap] Refactoring IOStream into Transport handler. (PR #130026)

2025-03-10 Thread John Harrison via lldb-commits


@@ -838,19 +775,16 @@ llvm::Error DAP::Loop() {
 StopEventHandlers();
   });
   while (!disconnecting) {
-llvm::json::Object object;
-lldb_dap::PacketStatus status = GetNextObject(object);
-
-if (status == lldb_dap::PacketStatus::EndOfFile) {
-  break;
-}
-
-if (status != lldb_dap::PacketStatus::Success) {
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "failed to send packet");
+auto next = transport.Read(log);
+if (auto Err = next.takeError()) {
+  // On EOF, simply break out of the loop.
+  std::error_code ec = llvm::errorToErrorCode(std::move(Err));
+  if (ec == Transport::kEOF)
+break;
+  return llvm::errorCodeToError(ec);
 }

ashgti wrote:

I tweaked the `Transport` class to log any errors it encounters and return 
`std::nullopt` whenever there is a problem, including EOF.

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


[Lldb-commits] [lldb] [lldb][AIX] Host.cpp for AIX (PR #130582)

2025-03-10 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -0,0 +1,265 @@
+//===-- NativeProcessAIX.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "NativeProcessAIX.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostProcess.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_aix;
+using namespace llvm;
+
+static constexpr unsigned k_ptrace_word_size = sizeof(void *);
+static_assert(sizeof(long) >= k_ptrace_word_size,
+  "Size of long must be larger than ptrace word size");
+
+// Simple helper function to ensure flags are enabled on the given file
+// descriptor.
+static llvm::Error EnsureFDFlags(int fd, int flags) {
+  Error error;
+
+  int status = fcntl(fd, F_GETFL);
+  if (status == -1) {
+error = errorCodeToError(errnoAsErrorCode());
+return error;
+  }
+
+  if (fcntl(fd, F_SETFL, status | flags) == -1) {
+error = errorCodeToError(errnoAsErrorCode());
+return error;
+  }
+
+  return error;
+}
+
+NativeProcessAIX::Manager::Manager(MainLoop &mainloop)
+: NativeProcessProtocol::Manager(mainloop) {
+  Status status;
+  m_sigchld_handle = mainloop.RegisterSignal(
+  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
+  assert(m_sigchld_handle && status.Success());
+}
+
+// Public Static Methods
+
+llvm::Expected>
+NativeProcessAIX::Manager::Launch(ProcessLaunchInfo &launch_info,
+  NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+
+  Status status;
+  ::pid_t pid = ProcessLauncherPosixFork()
+.LaunchProcess(launch_info, status)
+.GetProcessId();
+  LLDB_LOG(log, "pid = {0:x}", pid);
+  if (status.Fail()) {
+LLDB_LOG(log, "failed to launch process: {0}", status);
+return status.ToError();
+  }
+
+  // Wait for the child process to trap on its call to execve.
+  int wstatus = 0;
+  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
+  assert(wpid == pid);
+  UNUSED_IF_ASSERT_DISABLED(wpid);
+  if (!WIFSTOPPED(wstatus)) {
+LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
+ WaitStatus::Decode(wstatus));
+return llvm::make_error("Could not sync with inferior 
process",
+ llvm::inconvertibleErrorCode());
+  }
+  LLDB_LOG(log, "inferior started, now in stopped state");
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+
+  // Set the architecture to the exe architecture.
+  LLDB_LOG(log, "pid = {0}, detected architecture {1}", pid,
+   Info.GetArchitecture().GetArchitectureName());
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), 
native_delegate,
+  Info.GetArchitecture(), *this, {pid}));
+}
+
+llvm::Expected>
+NativeProcessAIX::Manager::Attach(
+lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate) {
+  Log *log = GetLog(POSIXLog::Process);
+  LLDB_LOG(log, "pid = {0:x}", pid);
+
+  ProcessInstanceInfo Info;
+  if (!Host::GetProcessInfo(pid, Info)) {
+return llvm::make_error("Cannot get process architectrue",
+ llvm::inconvertibleErrorCode());
+  }
+  auto tids_or = NativeProcessAIX::Attach(pid);
+  if (!tids_or)
+return tids_or.takeError();
+
+  return std::unique_ptr(new NativeProcessAIX(
+  pid, -1, native_delegate, Info.GetArchitecture(), *this, *tids_or));
+}
+
+NativeProcessAIX::Extension
+NativeProcessAIX::Manager::GetSupportedExtensions() const {
+  NativeProcessAIX::Extension supported = {};
+
+  return supported;
+}
+
+void NativeProcessAIX::Manager::SigchldHandler() {}
+
+void NativeProcessAIX::Manager::CollectThread(::pid_t tid) {}
+
+// Public Instance Methods
+
+NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
+   NativeDelegate &delegate,
+   const ArchSpec &arch, Manager &manager,
+   llvm::ArrayRef<::pid_t> tids)
+: NativeProcessProtocol(pid, terminal_fd, delegate), m_manager(manager),
+  m_arch(arch) {
+  manager.AddProcess(*this);
+  if (m_terminal_fd != -1) {
+Status status =

[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Pavel Labath via lldb-commits

https://github.com/labath commented:

I started reviewing this, but I got a feeling that you did not actually push 
the changes that you made.

Does the PR accurately reflect the latest version of the patch?

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


[Lldb-commits] [lldb] [lldb][AIX] Added base files for NativeProcess Support for AIX (PR #118160)

2025-03-10 Thread Pavel Labath via lldb-commits


@@ -292,7 +292,7 @@ endif()
 
 # Figure out if lldb could use lldb-server.  If so, then we'll
 # ensure we build lldb-server when an lldb target is being built.
-if (CMAKE_SYSTEM_NAME MATCHES 
"Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
+if (CMAKE_SYSTEM_NAME MATCHES 
"Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows|AIX")

labath wrote:

```suggestion
if (CMAKE_SYSTEM_NAME MATCHES 
"AIX|Android|Darwin|FreeBSD|Linux|NetBSD|OpenBSD|Windows")
```

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


[Lldb-commits] [lldb] draft: [lldb] Upgrade ValueObject::GetData to return llvm::Expected (PR #130516)

2025-03-10 Thread Julius Alexandre via lldb-commits


@@ -68,11 +68,9 @@ static bool CharStringSummaryProvider(ValueObject &valobj, 
Stream &stream) {
 
 template 
 static bool CharSummaryProvider(ValueObject &valobj, Stream &stream) {
-  DataExtractor data;
-  Status error;
-  valobj.GetData(data, error);
+  auto data_or_err = valobj.GetData();
 
-  if (error.Fail())
+  if (!data_or_err)

wizardengineer wrote:

Okay that makes sense, I was aware of the assertion of `llvm::Error`. I'll make 
sure to fix that and resort to handling the Errors if needed so. Otherwise, 
I'll use `llvm::expectedToOptional()`. Just to be sure, in what case would I 
know if a error doesn't really matter? 

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


[Lldb-commits] [lldb] [lldb] Split TestGdbRemoteFork test to avoid timeout (PR #129614)

2025-03-10 Thread David Peixotto via lldb-commits

dmpots wrote:

> You could make the test binary a cmake dependency, see 
> `lldb/test/CMakeLists.txt`. Perhaps in:
> 
> ```
> if(TARGET lldb-server)
>   add_lldb_test_dependency(lldb-server)
> endif()
> ```

Just so it's clear, it is not lldb-server itself that is the slow dependency, 
but the cpp file in the test directory. I think you mean we could create a new 
binary from the test file.

Pulling out the [cpp 
file](https://github.com/llvm/llvm-project/blob/main/lldb/test/API/tools/lldb-server/main.cpp)
 into a separate tool might work. I don't know if there are any issues trying 
that. It's now building with the just-built clang binaries hooks into the 
dotest build system which seems to allow more flexibility in building it in 
different ways at test runtime (although I'm not sure we actually rely on that 
flexibility).



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


[Lldb-commits] [lldb] [lldb] Implement a statusline in LLDB (PR #121860)

2025-03-10 Thread Jonas Devlieghere via lldb-commits

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

>From 13524447f9af1c8d1923e9ef8cc3693a1c53253a Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Fri, 17 Jan 2025 17:10:36 -0800
Subject: [PATCH 1/5] [lldb] Implement a statusline in LLDB
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add a statusline to command-line LLDB to display progress events and
other information related to the current state of the debugger. The
statusline is a dedicated area displayed the bottom of the screen. The
contents of the status line are configurable through a setting
consisting of LLDB’s format strings.

The statusline is configurable through the `statusline-format` setting.
The default configuration shows the target name, the current file, the
stop reason and the current progress event.

```
(lldb) settings show statusline-format
statusline-format (format-string) = 
"${ansi.bg.cyan}${ansi.fg.black}{${target.file.basename}}{ | 
${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ 
| {${progress.count} }${progress.message}}"
```

The statusline is enabled by default, but can be disabled with the
following setting:

```
(lldb) settings set show-statusline false
```

The statusline supersedes the current progress reporting implementation.
Consequently, the following settings no longer have any effect (but
continue to exist):

```
show-progress -- Whether to show progress or not if the debugger's 
output is an interactive color-enabled terminal.
show-progress-ansi-prefix -- When displaying progress in a color-enabled 
terminal, use the ANSI terminal code specified in this format immediately 
before the progress message.
show-progress-ansi-suffix -- When displaying progress in a color-enabled 
terminal, use the ANSI terminal code specified in this format immediately after 
the progress message.
```

RFC: https://discourse.llvm.org/t/rfc-lldb-statusline/83948
---
 lldb/include/lldb/Core/Debugger.h |  24 ++-
 lldb/include/lldb/Core/FormatEntity.h |   4 +-
 lldb/include/lldb/Core/Statusline.h   |  58 ++
 .../Python/lldbsuite/test/lldbtest.py |   2 +
 lldb/source/Core/CMakeLists.txt   |   1 +
 lldb/source/Core/CoreProperties.td|   8 +
 lldb/source/Core/Debugger.cpp | 159 
 lldb/source/Core/FormatEntity.cpp |  44 -
 lldb/source/Core/Statusline.cpp   | 171 ++
 .../TestTrimmedProgressReporting.py   |  51 --
 .../API/functionalities/statusline/Makefile   |   3 +
 .../statusline/TestStatusline.py  |  57 ++
 .../API/functionalities/statusline/main.c |  11 ++
 13 files changed, 458 insertions(+), 135 deletions(-)
 create mode 100644 lldb/include/lldb/Core/Statusline.h
 create mode 100644 lldb/source/Core/Statusline.cpp
 delete mode 100644 
lldb/test/API/functionalities/progress_reporting/TestTrimmedProgressReporting.py
 create mode 100644 lldb/test/API/functionalities/statusline/Makefile
 create mode 100644 lldb/test/API/functionalities/statusline/TestStatusline.py
 create mode 100644 lldb/test/API/functionalities/statusline/main.c

diff --git a/lldb/include/lldb/Core/Debugger.h 
b/lldb/include/lldb/Core/Debugger.h
index 6ebc6147800e1..9e2100662c6de 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -19,6 +19,7 @@
 #include "lldb/Core/FormatEntity.h"
 #include "lldb/Core/IOHandler.h"
 #include "lldb/Core/SourceManager.h"
+#include "lldb/Core/Statusline.h"
 #include "lldb/Core/UserSettingsController.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/StreamFile.h"
@@ -303,6 +304,10 @@ class Debugger : public 
std::enable_shared_from_this,
 
   bool SetShowProgress(bool show_progress);
 
+  bool GetShowStatusline() const;
+
+  const FormatEntity::Entry *GetStatuslineFormat() const;
+
   llvm::StringRef GetShowProgressAnsiPrefix() const;
 
   llvm::StringRef GetShowProgressAnsiSuffix() const;
@@ -599,11 +604,20 @@ class Debugger : public 
std::enable_shared_from_this,
 return m_source_file_cache;
   }
 
+  struct ProgressReport {
+uint64_t id;
+uint64_t completed;
+uint64_t total;
+std::string message;
+  };
+  std::optional GetCurrentProgressReport() const;
+
 protected:
   friend class CommandInterpreter;
   friend class REPL;
   friend class Progress;
   friend class ProgressManager;
+  friend class Statusline;
 
   /// Report progress events.
   ///
@@ -656,6 +670,8 @@ class Debugger : public 
std::enable_shared_from_this,
   lldb::LockableStreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
   /// @}
 
+  bool StatuslineSupported();
+
   void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
  bool cancel_top_handler = true);
 
@@ -732,7 +748,7 @@ class Debugger : public 
std::enable_shared_from_this,
   IOHandlerStack m_io_handler_stack;
   std::

[Lldb-commits] [lldb] [lldb] Split TestGdbRemoteFork test to avoid timeout (PR #129614)

2025-03-10 Thread David Peixotto via lldb-commits

dmpots wrote:

> The test really is big and splitting it up is a good idea, but instead of an 
> arbitrary 1/2/3 split, I think it be better to do it by functionality. 
> Looking at the part of the code you moved, I can see several "themes" that we 
> could use to split this up. One of them is "memory operations" 
> (TestGdbRemoteMemory?) where we could put all of the memory and 
> qMemoryRegionInfo tests. Another might be "qSupported" tests. And a third 
> test for the register operations (`p`/`P` packets).
> 
> If that doesn't reduce the file sufficiently, I'm sure we can find some more.

Thanks for the suggestion. I wasn't familiar enough to do a proper split, but I 
can take a look based on your suggestion. It seems we already have some memory 
tests split out:

https://github.com/llvm/llvm-project/blob/main/lldb/test/API/tools/lldb-server/memory-allocation/TestGdbRemoteMemoryAllocation.py

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