[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)

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


@@ -0,0 +1,193 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Use defined constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+#if defined(_AIX)
+#include 
+#else // For remotely cross debugging aix
+#define MAP_VARIABLE 0x0
+#define MAP_PRIVATE 0x2
+#define MAP_ANONYMOUS 0x10
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::AIX:
+  create = true;
+  break;
+
+default:
+  break;
+}
+  }
+
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#ifdef _AIX
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0) {
+if (--g_initialize_count == 0) {
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+}
+  }
+
+  PlatformPOSIX::Terminate();
+}
+
+/// Default Constructor
+PlatformAIX::PlatformAIX(bool is_host)
+: PlatformPOSIX(is_host) // This is the local host platform
+{
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+if (hostArch.GetTriple().isArch64Bit()) {
+  m_supported_architectures.push_back(
+  HostInfo::GetArchitecture(HostInfo::eArchKind32));

labath wrote:

This isn't a typo. What is says is that a 64-bit linux host can debug 32-bit 
linux application running on that host. That is true for linux, but not for aix 
(yet?), so I think we should remove this from here.

https://github.com/llvm/llvm-project/pull/121273
___
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 PlatformAIX plugin (PR #121273)

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


@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")

labath wrote:

Remind me please, what symbol is this needed for?

https://github.com/llvm/llvm-project/pull/121273
___
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 PlatformAIX plugin (PR #121273)

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


@@ -0,0 +1,72 @@
+//===-- PlatformAIX.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 LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+#define LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+
+#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+
+namespace lldb_private {
+namespace platform_aix {
+
+class PlatformAIX : public PlatformPOSIX {
+public:
+  PlatformAIX(bool is_host);
+
+  static void Initialize();
+
+  static void Terminate();
+
+  // lldb_private::PluginInterface functions
+  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+  static llvm::StringRef GetPluginNameStatic(bool is_host) {
+return is_host ? Platform::GetHostPlatformName() : "remote-AIX";
+  }
+
+  static llvm::StringRef GetPluginDescriptionStatic(bool is_host);
+
+  llvm::StringRef GetPluginName() override {
+return GetPluginNameStatic(IsHost());
+  }
+
+  // lldb_private::Platform functions
+  llvm::StringRef GetDescription() override {
+return GetPluginDescriptionStatic(IsHost());
+  }
+
+  void GetStatus(Stream &strm) override;
+
+  std::vector
+  GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
+
+  bool CanDebugProcess() override;

labath wrote:

I doubt the exact implementation matters much because this function is only 
used for choosing between the old and new ways of initiating the debug session 
(in the new way, the session is initiated by the Platform, typically by 
spawning lldb-server; in the old way everything is handled by the Process 
class, usually by debugging in-process). Since you're not going to be using the 
old method I think the default `Platform` implementation returning true will 
work just fine.

https://github.com/llvm/llvm-project/pull/121273
___
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 PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,193 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Use defined constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+#if defined(_AIX)
+#include 
+#else // For remotely cross debugging aix
+#define MAP_VARIABLE 0x0
+#define MAP_PRIVATE 0x2
+#define MAP_ANONYMOUS 0x10
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::AIX:
+  create = true;
+  break;
+
+default:
+  break;
+}
+  }
+
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#ifdef _AIX
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0) {
+if (--g_initialize_count == 0) {
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+}
+  }
+
+  PlatformPOSIX::Terminate();
+}
+
+/// Default Constructor
+PlatformAIX::PlatformAIX(bool is_host)
+: PlatformPOSIX(is_host) // This is the local host platform
+{
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+if (hostArch.GetTriple().isArch64Bit()) {
+  m_supported_architectures.push_back(
+  HostInfo::GetArchitecture(HostInfo::eArchKind32));

DhruvSrivastavaX wrote:

Oh! Got it. Thanks for the clarity.

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


[Lldb-commits] [lldb] [WIP] [lldb][TypeSystemClang] Create clang::SourceLocation from DWARF and attach to AST (PR #127829)

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

labath wrote:

Sounds like a nice feature to have. I'm not really familiar with these APIs, so 
I don't have much to say in the way of specifics. One high level question I 
have (I can't tell from the patch) is how are these files actually handled. Do 
we need to (preemptively) read them into some clang-owned buffer, or can we say 
something like "there is a file here, come back to me if you need it". I have 
two reasons for asking this: I'm wondering if this will have any impact on our 
memory footprint; and I'm wondering how will this behave if the file is changed 
(or deleted) during the course of the debug session.

https://github.com/llvm/llvm-project/pull/127829
___
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 PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")

DhruvSrivastavaX wrote:

For this plugin, it is there for `MAP_ANONYMOUS`

https://github.com/llvm/llvm-project/pull/121273
___
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 PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,72 @@
+//===-- PlatformAIX.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 LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+#define LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+
+#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+
+namespace lldb_private {
+namespace platform_aix {
+
+class PlatformAIX : public PlatformPOSIX {
+public:
+  PlatformAIX(bool is_host);
+
+  static void Initialize();
+
+  static void Terminate();
+
+  // lldb_private::PluginInterface functions
+  static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+  static llvm::StringRef GetPluginNameStatic(bool is_host) {
+return is_host ? Platform::GetHostPlatformName() : "remote-AIX";
+  }
+
+  static llvm::StringRef GetPluginDescriptionStatic(bool is_host);
+
+  llvm::StringRef GetPluginName() override {
+return GetPluginNameStatic(IsHost());
+  }
+
+  // lldb_private::Platform functions
+  llvm::StringRef GetDescription() override {
+return GetPluginDescriptionStatic(IsHost());
+  }
+
+  void GetStatus(Stream &strm) override;
+
+  std::vector
+  GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
+
+  bool CanDebugProcess() override;

DhruvSrivastavaX wrote:

Okay, Removed

https://github.com/llvm/llvm-project/pull/121273
___
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 PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX updated 
https://github.com/llvm/llvm-project/pull/121273

>From 16107a423e30cc339b7529db35a75c3c26924146 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Sat, 28 Dec 2024 13:19:21 -0600
Subject: [PATCH 1/6] Introducing PlatformAIX from PlatformLinux

---
 .../Plugins/Platform/AIX/CMakeLists.txt   |  13 +
 .../Plugins/Platform/AIX/PlatformAIX.cpp  | 471 ++
 .../source/Plugins/Platform/AIX/PlatformAIX.h |  74 +++
 lldb/source/Plugins/Platform/CMakeLists.txt   |   1 +
 4 files changed, 559 insertions(+)
 create mode 100644 lldb/source/Plugins/Platform/AIX/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
 create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.h

diff --git a/lldb/source/Plugins/Platform/AIX/CMakeLists.txt 
b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
new file mode 100644
index 0..85ff0a315eabd
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")
+
+add_lldb_library(lldbPluginPlatformAIX PLUGIN
+  PlatformAIX.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginPlatformPOSIX
+  )
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp 
b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
new file mode 100644
index 0..5c94477002978
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -0,0 +1,471 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Define these constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+#if defined(_AIX)
+#include 
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::AIX:
+  create = true;
+  break;
+
+default:
+  break;
+}
+  }
+
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#if defined(_AIX)
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0) {
+if (--g_initialize_count == 0) {
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+}
+  }
+
+  PlatformPOSIX::Terminate();
+}
+
+/// Default Constructor
+PlatformAIX::PlatformAIX(bool is_host)
+: PlatformPOSIX(is_host) // This is the local host platform
+{
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+if (hostArch.GetTriple().isArch64Bit()) {
+  m_supported_architectures.push_back(
+  HostInfo::GetArchitecture(HostInfo::eArchKind32));
+}
+  } else {
+m_supported_architectures = CreateArchList(
+{llvm::Triple::x86_64, llvm::Triple

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

2025-02-21 Thread Hu Jialun via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();

SuibianP wrote:

Yes, it is the NUL. It would be encoded into JSON if not popped.

I think it might have always been buggy and just happened to work, as NUL 
termination from `StringRef::data` is explicitly not guaranteed.

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-02-21 Thread Hu Jialun via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);
+constexpr size_t buffer_size = 2048;

SuibianP wrote:

The two sizes are not related. The one passed to `CreateNamedPipe` is the 
kernel buffer, while this one is for the receiving user buffer. I do need to 
rethink how long the buffer needs to be, though.

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] Don't hand out UnwindPlan::Row shared_ptrs (PR #128181)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

The whole unwind plan is already stored in a shared pointer, and there's no 
need to persist Rows individually. If there's ever a need to do that, there are 
at least two options:
- copy the row (they're not that big, and they're being copied left and right 
during construction already)
- use the shared_ptr subobject constructor to create a shared_ptr which points 
to a Row but holds the entire unwind plan alive

This also changes all of the getter functions to return const Row pointers, 
which is important for safety because all of these objects are cached and 
potentially accessed from multiple threads. (Technically one could hand out 
`shared_ptr`s, but we don't have a habit of doing that.)

As a next step, I'd like to remove the internal UnwindPlan usages of the shared 
pointer, but I'm doing this separately to gauge feedback, and also because the 
patch got rather big.

---

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


10 Files Affected:

- (modified) lldb/include/lldb/Symbol/UnwindPlan.h (+9-7) 
- (modified) lldb/include/lldb/Target/RegisterContextUnwind.h (+2-1) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp
 (+3-5) 
- (modified) lldb/source/Plugins/UnwindAssembly/x86/UnwindAssembly-x86.cpp 
(+2-2) 
- (modified) 
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp (+3-3) 
- (modified) lldb/source/Symbol/FuncUnwinders.cpp (+4-4) 
- (modified) lldb/source/Symbol/UnwindPlan.cpp (+24-28) 
- (modified) lldb/source/Target/RegisterContextUnwind.cpp (+16-16) 
- (modified) lldb/unittests/UnwindAssembly/ARM64/TestArm64InstEmulation.cpp 
(+201-201) 
- (modified) 
lldb/unittests/UnwindAssembly/x86/Testx86AssemblyInspectionEngine.cpp 
(+670-673) 


``diff
diff --git a/lldb/include/lldb/Symbol/UnwindPlan.h 
b/lldb/include/lldb/Symbol/UnwindPlan.h
index 48c9bef76857c..de120c4a734db 100644
--- a/lldb/include/lldb/Symbol/UnwindPlan.h
+++ b/lldb/include/lldb/Symbol/UnwindPlan.h
@@ -175,13 +175,13 @@ class UnwindPlan {
 
   void SetIsDWARFExpression(const uint8_t *opcodes, uint32_t len);
 
-  const uint8_t *GetDWARFExpressionBytes() {
+  const uint8_t *GetDWARFExpressionBytes() const {
 if (m_type == atDWARFExpression || m_type == isDWARFExpression)
   return m_location.expr.opcodes;
 return nullptr;
   }
 
-  int GetDWARFExpressionLength() {
+  int GetDWARFExpressionLength() const {
 if (m_type == atDWARFExpression || m_type == isDWARFExpression)
   return m_location.expr.length;
 return 0;
@@ -308,13 +308,13 @@ class UnwindPlan {
 }
   }
 
-  const uint8_t *GetDWARFExpressionBytes() {
+  const uint8_t *GetDWARFExpressionBytes() const {
 if (m_type == isDWARFExpression)
   return m_value.expr.opcodes;
 return nullptr;
   }
 
-  int GetDWARFExpressionLength() {
+  int GetDWARFExpressionLength() const {
 if (m_type == isDWARFExpression)
   return m_value.expr.length;
 return 0;
@@ -362,8 +362,10 @@ class UnwindPlan {
 
 void SlideOffset(lldb::addr_t offset) { m_offset += offset; }
 
+const FAValue &GetCFAValue() const { return m_cfa_value; }
 FAValue &GetCFAValue() { return m_cfa_value; }
 
+const FAValue &GetAFAValue() const { return m_afa_value; }
 FAValue &GetAFAValue() { return m_afa_value; }
 
 bool SetRegisterLocationToAtCFAPlusOffset(uint32_t reg_num, int32_t offset,
@@ -464,7 +466,7 @@ class UnwindPlan {
   // unknown - the final row in the UnwindPlan is returned. In practice, the
   // UnwindPlan for a function with no known start address will be the
   // architectural default UnwindPlan which will only have one row.
-  UnwindPlan::RowSP GetRowForFunctionOffset(int offset) const;
+  const UnwindPlan::Row *GetRowForFunctionOffset(int offset) const;
 
   lldb::RegisterKind GetRegisterKind() const { return m_register_kind; }
 
@@ -495,9 +497,9 @@ class UnwindPlan {
 
   bool IsValidRowIndex(uint32_t idx) const;
 
-  const UnwindPlan::RowSP GetRowAtIndex(uint32_t idx) const;
+  const UnwindPlan::Row *GetRowAtIndex(uint32_t idx) const;
 
-  const UnwindPlan::RowSP GetLastRow() const;
+  const UnwindPlan::Row *GetLastRow() const;
 
   lldb_private::ConstString GetSourceName() const;
 
diff --git a/lldb/include/lldb/Target/RegisterContextUnwind.h 
b/lldb/include/lldb/Target/RegisterContextUnwind.h
index 3be9eb5c5c70f..6cd918fedc003 100644
--- a/lldb/include/lldb/Target/RegisterContextUnwind.h
+++ b/lldb/include/lldb/Target/RegisterContextUnwind.h
@@ -191,7 +191,8 @@ class RegisterContextUnwind : public 
lldb_private::RegisterContext {
 
   // Get the Frame Address register for a given frame.
   bool ReadFrameAddress(lldb::RegisterKind register_kind,
-  UnwindPlan::Row::FAV

[Lldb-commits] [lldb] [lldb] Don't hand out UnwindPlan::Row shared_ptrs (PR #128181)

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

https://github.com/labath edited 
https://github.com/llvm/llvm-project/pull/128181
___
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-02-21 Thread Hu Jialun via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
-
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  std::error_code EC;
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_path.clear();
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createUniqueNamedPipe(const Twine &prefix, StringRef suffix,
+  int &result_fd,
+  SmallVectorImpl &result_path) {
+  const char *middle = suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + prefix + middle + suffix,
+  result_path);
+  if (EC)
+return EC;
+  result_path.push_back(0);
+  const char *path = result_path.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return llvm::mapLastWindowsError();
+  result_fd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (result_fd == -1)
+return llvm::mapLastWindowsError();
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(result_path, result_fd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  result_path.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);
+constexpr size_t buffer_size = 2048;
+char buffer[buffer_size];
+char *ptr = fgets(buffer, buffer_size, m_fifo_file.m_file);
+if (ptr == nullptr || *ptr == 0)
+  return;
+size_t len = strlen(buffer);
+if (len <= 1)
+  return;
+buffer[len - 1] = '\0'; // remove newline
+line = buffer;

SuibianP wrote:

We can reinvent POSIX `getline`, but it is probably not worth the effort. Any 
JSON schema change that overruns the buffer will absolutely get truncated, 
break the test visibly and get caught during review.

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] d2b3912 - [lldb] Remove commented out declaration in DWARFExpressionList

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

Author: David Spickett
Date: 2025-02-21T14:56:30Z
New Revision: d2b3912002693008141ed8a15c0f2fdb6e861f84

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

LOG: [lldb] Remove commented out declaration in DWARFExpressionList

Added: 


Modified: 
lldb/include/lldb/Expression/DWARFExpressionList.h

Removed: 




diff  --git a/lldb/include/lldb/Expression/DWARFExpressionList.h 
b/lldb/include/lldb/Expression/DWARFExpressionList.h
index 664c2603770f6..519bbb354fa6f 100644
--- a/lldb/include/lldb/Expression/DWARFExpressionList.h
+++ b/lldb/include/lldb/Expression/DWARFExpressionList.h
@@ -106,10 +106,6 @@ class DWARFExpressionList {
   /// \return
   /// True if IsLocationList() is true and the address was found;
   /// false otherwise.
-  //bool
-  //LocationListContainsLoadAddress (Process* process, const Address &addr)
-  //const;
-  //
   bool ContainsAddress(lldb::addr_t func_load_addr, lldb::addr_t addr) const;
 
   void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }



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


[Lldb-commits] [lldb] [WIP] [lldb][TypeSystemClang] Create clang::SourceLocation from DWARF and attach to AST (PR #127829)

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

Michael137 wrote:

> Sounds like a nice feature to have. I'm not really familiar with these APIs, 
> so I don't have much to say in the way of specifics. One high level question 
> I have (I can't tell from the patch) is how are these files actually handled. 
> Do we need to (preemptively) read them into some clang-owned buffer, or can 
> we say something like "there is a file here, come back to me if you need it". 
> I have two reasons for asking this: I'm wondering if this will have any 
> impact on our memory footprint; and I'm wondering how will this behave if the 
> file is changed (or deleted) during the course of the debug session.

Yea I wasn't sure what the best answer to this is yet. Currently we create a 
`SourceLocation` (which is just a compact <`FileID`, `offset`> pair, where 
`offset` is the position into the file) using `translateLineCol`, which will 
mmap the file if we haven't done so yet, and then calculate the offset based on 
the line/column info.

> "there is a file here, come back to me if you need it"

>From my limited understanding of these APIs, I don't think there's currently 
>such a customization point. LLDB would have to somehow store that column/line 
>info somewhere until Clang asks for it. We could maybe stuff 
>`FileID`+`column`+`line` into the `SourceLocation`, and steal bit as an 
>indicator that this is a "lazy source location"? I'd have to investigate this 
>a bit more.

But I guess we'd have to decide whether opening the source files is an 
unacceptable increase in the memory footprint for the common debugging 
use-case. I can collect some memory usage numbers when debugging clang/lldb as 
one data-point

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


[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

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

JDevlieghere wrote:

> @JDevlieghere, I've updated messages :)

Lightning fast! Thanks! 

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


[Lldb-commits] [lldb] [lldb] Fix GCC's `-Wreturn-type` warnings (PR #127974)

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

JDevlieghere wrote:

> @JDevlieghere, it is still not merged. Are there any extra checks?

Nope, I just wasn't sure if you had commit access. I'll go ahead and merge it 
for you. 

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


[Lldb-commits] [lldb] [lldb] Don't hand out UnwindPlan::Row shared_ptrs (PR #128181)

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

labath wrote:

That, or even actual values. I'm looking over the construction code, and it 
looks like most of the time it's making a (deep) copy of the value before/after 
storing it in the unwind plan.

https://github.com/llvm/llvm-project/pull/128181
___
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-02-21 Thread Hu Jialun via lldb-commits

https://github.com/SuibianP 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] Implement a statusline in LLDB (PR #121860)

2025-02-21 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] [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::recu

[Lldb-commits] [lldb] [lldb] Fix GCC's `-Wreturn-type` warnings (PR #127974)

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

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


[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

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

https://github.com/JDevlieghere closed 
https://github.com/llvm/llvm-project/pull/128196
___
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-02-21 Thread Hu Jialun via lldb-commits


@@ -158,13 +156,25 @@ std::string 
RunInTerminalDebugAdapterCommChannel::GetLauncherError() {
 }
 
 Expected> CreateRunInTerminalCommFile() {
+  int comm_fd;
   SmallString<256> comm_file;
-  if (std::error_code EC = sys::fs::getPotentiallyUniqueTempFileName(
-  "lldb-dap-run-in-terminal-comm", "", comm_file))
+  if (std::error_code EC = createUniqueNamedPipe(
+  "lldb-dap-run-in-terminal-comm", "", comm_fd, comm_file))
 return createStringError(EC, "Error making unique file name for "
  "runInTerminal communication files");
-
-  return CreateFifoFile(comm_file.str());
+  FILE *cf = fdopen(comm_fd, "r+");
+  if (setvbuf(cf, NULL, _IONBF, 0))
+return createStringError(std::error_code(errno, std::generic_category()),
+ "Error setting unbuffered mode on C FILE");
+  // There is no portable way to conjure an ofstream from HANDLE, so use FILE *
+  // llvm::raw_fd_stream does not support getline() and there is no
+  // llvm::buffer_istream

SuibianP wrote:

On the client (launcher) side it should be possible, but on the server end I 
suppose not. Windows has the distinction of "server" (from `CreateNamedPipe`) 
and "client" (from `CreateFile`) ends of FIFOs and unlike on POSIX where FIFOs 
can read from any previous write, clients can only communicate with server but 
not fellow clients.

Opening a `std::ofstream` (which underlyingly is `CreateFile`) would open a 
client of the pipe in the same process that connects to the server. The server 
side must use `CreateNamedPipe` which gives out a `HANDLE`, thus the issue of 
turning that into some platform independent file object.

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-02-21 Thread Hu Jialun via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
+std::error_code EC;
 
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createNamedPipe(const Twine &Prefix, StringRef Suffix,
+int &ResultFd,
+SmallVectorImpl &ResultPath) {
+  const char *Middle = Suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"

SuibianP wrote:

Hmm.. maybe `llvm::sys::path::system_temp_directory` then?

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-02-21 Thread Hu Jialun via lldb-commits


@@ -24,41 +30,95 @@ using namespace llvm;
 
 namespace lldb_dap {
 
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
+std::error_code EC;
 
+FifoFile::FifoFile(StringRef path)
+: m_path(path), m_file(fopen(path.data(), "r+")) {
+  if (m_file == nullptr) {
+EC = std::error_code(errno, std::generic_category());
+llvm::errs() << "Failed to open fifo file " << path << ": " << EC.message()
+ << "\n";
+std::terminate();
+  }
+  if (setvbuf(m_file, NULL, _IONBF, 0))
+llvm::errs() << "Error setting unbuffered mode on C FILE\n";
+}
+FifoFile::FifoFile(StringRef path, FILE *f) : m_path(path), m_file(f) {}
+FifoFile::FifoFile(FifoFile &&other)
+: m_path(other.m_path), m_file(other.m_file) {
+  other.m_file = nullptr;
+}
 FifoFile::~FifoFile() {
+  if (m_file)
+fclose(m_file);
 #if !defined(_WIN32)
+  // Unreferenced named pipes are deleted automatically on Win32
   unlink(m_path.c_str());
 #endif
 }
 
-Expected> CreateFifoFile(StringRef path) {
-#if defined(_WIN32)
-  return createStringError(inconvertibleErrorCode(), "Unimplemented");
+// This probably belongs to llvm::sys::fs as another FSEntity type
+std::error_code createNamedPipe(const Twine &Prefix, StringRef Suffix,
+int &ResultFd,
+SmallVectorImpl &ResultPath) {
+  const char *Middle = Suffix.empty() ? "-%%" : "-%%.";
+  auto EC = sys::fs::getPotentiallyUniqueFileName(
+#ifdef _WIN32
+  ".\\pipe\\LOCAL\\"
+#else
+  "/tmp/"
+#endif
+  + Prefix + Middle + Suffix,
+  ResultPath);
+  if (EC)
+return EC;
+  ResultPath.push_back(0);
+  const char *path = ResultPath.data();
+#ifdef _WIN32
+  HANDLE h = ::CreateNamedPipeA(
+  path, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE,
+  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, 0, NULL);
+  if (h == INVALID_HANDLE_VALUE)
+return std::error_code(::GetLastError(), std::system_category());
+  ResultFd = _open_osfhandle((intptr_t)h, _O_TEXT | _O_RDWR);
+  if (ResultFd == -1)
+return std::error_code(::GetLastError(), std::system_category());
 #else
-  if (int err = mkfifo(path.data(), 0600))
-return createStringError(std::error_code(err, std::generic_category()),
- "Couldn't create fifo file: %s", path.data());
-  return std::make_shared(path);
+  if (mkfifo(path, 0600) == -1)
+return std::error_code(errno, std::generic_category());
+  EC = openFileForWrite(ResultPath, ResultFd, sys::fs::CD_OpenExisting,
+sys::fs::OF_None, 0600);
+  if (EC)
+return EC;
 #endif
+  ResultPath.pop_back();
+  return std::error_code();
 }
 
-FifoFileIO::FifoFileIO(StringRef fifo_file, StringRef other_endpoint_name)
-: m_fifo_file(fifo_file), m_other_endpoint_name(other_endpoint_name) {}
+FifoFileIO::FifoFileIO(FifoFile &&fifo_file, StringRef other_endpoint_name)
+: m_fifo_file(std::move(fifo_file)),
+  m_other_endpoint_name(other_endpoint_name) {}
 
 Expected FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
   // We use a pointer for this future, because otherwise its normal destructor
   // would wait for the getline to end, rendering the timeout useless.
   std::optional line;
   std::future *future =
   new std::future(std::async(std::launch::async, [&]() {
-std::ifstream reader(m_fifo_file, std::ifstream::in);
-std::string buffer;
-std::getline(reader, buffer);
-if (!buffer.empty())
-  line = buffer;
+rewind(m_fifo_file.m_file);

SuibianP wrote:

The DA side first sends a `RunInTerminalMessageDidAttach` message in 
`RunInTerminalDebugAdapterCommChannel::NotifyDidAttach` when it attaches to the 
launcher. This is also why the FIFO must be `PIPE_ACCESS_DUPLEX`.

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-02-21 Thread Hu Jialun via lldb-commits

https://github.com/SuibianP 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-02-21 Thread Hu Jialun via lldb-commits

https://github.com/SuibianP 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-02-21 Thread Hu Jialun via lldb-commits

https://github.com/SuibianP 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][AIX] Added PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

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

This reverts commit 
https://github.com/llvm/llvm-project/commit/87b7f63a117c340a6d9ca47959335fd7ef6c7ad2,
 reapplying
https://github.com/llvm/llvm-project/commit/7e66cf74fb4e6a103f923e34700a7b6f20ac2a9b
 with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot issues.

>From b213b08c0a6527ec4732ef977ad43e3261dd73ad Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Fri, 21 Feb 2025 10:36:20 +0100
Subject: [PATCH 1/2] Reapply "[lldb] Implement basic support for
 reverse-continue (#125242)" (again)

This reverts commit 87b7f63a117c340a6d9ca47959335fd7ef6c7ad2, reapplying
7e66cf74fb4e6a103f923e34700a7b6f20ac2a9b with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot issues.
---
 lldb/include/lldb/API/SBProcess.h |   1 +
 lldb/include/lldb/Target/Process.h|  28 +-
 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  | 541 ++
 .../Python/lldbsuite/test/lldbtest.py |   2 +
 .../tools/lldb-server/lldbgdbserverutils.py   |  14 +-
 lldb/source/API/SBProcess.cpp |  12 +
 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   |  98 +++-
 .../Process/gdb-remote/ProcessGDBRemote.h |   4 +-
 .../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 | 159 +
 .../TestReverseContinueNotSupported.py|  35 ++
 .../TestReverseContinueWatchpoints.py | 136 +
 .../functionalities/reverse-execution/main.c  |  25 +
 lldb/tools/lldb-dap/JSONUtils.cpp |   3 +
 lldb/tools/lldb-dap/LLDBUtils.cpp |   1 +
 40 files changed, 1402 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/TestReverseContinueWatchpoints.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 1624e02070b1b..882b8bd837131 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 c3622a29bc772..2e827d4c5cb74 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1089,6 +1089,13 @@ class Process : public 
std::enable_shared_from_this,
   /// Returns an error object.
   virtual Status WillResume() { return Status(); }
 
+  /// Reports whether this process supports reverse execution.
+  ///
+  /// \return
+  /// Returns true if the process supports reverse execution (at least
+  /// under some circumstances).
+  virtual bool SupportsReverseDirection() { return false; }
+
   /// Resumes all of a process's threads as configured using the Thread run
   /// control functions.
   ///
@@ -1104,9 +,13 @@ class Process : public 
std::enable_sha

[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,155 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Use defined constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+// For remotely cross debugging aix
+constexpr int MapVariable = 0x0;
+constexpr int MapPrivate = 0x2;
+constexpr int MapAnonymous = 0x10;
+#if defined(_AIX)
+#include 
+static_assert(MapVariable == MAP_VARIABLE);
+static_assert(MapPrivate == MAP_PRIVATE);
+static_assert(MapAnonymous = MAP_ANONYMOUS);
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force || (arch && arch->IsValid() &&
+  arch->GetTriple().getOS() == llvm::Triple::AIX);
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#ifdef _AIX
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0)
+if (--g_initialize_count == 0)
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+
+  PlatformPOSIX::Terminate();
+}
+
+PlatformAIX::PlatformAIX(bool is_host) : PlatformPOSIX(is_host) {
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+  } else {
+m_supported_architectures =
+CreateArchList({llvm::Triple::ppc64}, llvm::Triple::AIX);
+  }
+}
+
+std::vector
+PlatformAIX::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
+  if (m_remote_platform_sp)
+return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
+  return m_supported_architectures;
+}
+
+void PlatformAIX::GetStatus(Stream &strm) {
+  Platform::GetStatus(strm);
+
+#if LLDB_ENABLE_POSIX
+  // Display local kernel information only when we are running in host mode.
+  // Otherwise, we would end up printing non-AIX information (when running on
+  // Mac OS for example).
+  if (IsHost()) {
+struct utsname un;
+
+if (uname(&un))
+  return;
+
+strm.Printf("Kernel: %s\n", un.sysname);
+strm.Printf("   Release: %s\n", un.release);
+strm.Printf("   Version: %s\n", un.version);
+  }
+#endif
+}
+
+void PlatformAIX::CalculateTrapHandlerSymbolNames() {}
+
+lldb::UnwindPlanSP
+PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
+  ConstString name) {
+  return {};
+}
+
+MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
+ addr_t length, unsigned prot,
+ unsigned flags, addr_t fd,
+ addr_t offset) {
+  unsigned flags_platform = 0;
+#if defined(_AIX)
+  flags_platform = MapPrivate | MapVariable | MapAnon;
+#endif

DhruvSrivastavaX wrote:

Hope I have covered everything and its okay now?

https://github.com/llvm/llvm-project/pull/121273
__

[Lldb-commits] [lldb] [lldb] Don't hand out UnwindPlan::Row shared_ptrs (PR #128181)

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

JDevlieghere wrote:

Does this open the door towards storing these rows as unique pointers? 

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


[Lldb-commits] [lldb] 917ed99 - [lldb] Fix "in function" detection in "thread until" (#123622)

2025-02-21 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-02-21T13:17:36+01:00
New Revision: 917ed99d815a4cc6bde249d292376f75dbe3700c

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

LOG: [lldb] Fix "in function" detection in "thread until" (#123622)

The implementation has an optimization which detects the range of line
table entries covered by the function and then only searches for a
matching line between them.

This optimization was interfering with the logic for detecting whether a
line belongs to the function because the first call to FindLineEntry was
made with exact=false, which meant that if the function did not contain
any exact matches, we would just pick the closest line number in that
range, even if it was very far away.

This patch fixes that by first attempting an inexact search across the
entire line table, and then use the (potentially inexact) result of that
for searching within the function. This makes the optimization a less
effective, but I don't think we can differentiate between a line that
belongs to the function (but doesn't have any code) and a line outside
the function without that.

The patch also avoids the use of (deprecated) Function::GetAddressRange
by iterating over the GetAddressRanges result to find the full range of
line entries for the function.

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp
lldb/test/API/functionalities/thread/step_until/TestStepUntil.py

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 4e2c4c1126bc3..cd3d2d89333f1 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -959,7 +959,6 @@ class CommandObjectThreadUntil : public CommandObjectParsed 
{
 }
 
 LineEntry function_start;
-uint32_t index_ptr = 0, end_ptr = UINT32_MAX;
 std::vector address_list;
 
 // Find the beginning & end index of the function, but first make
@@ -970,19 +969,14 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
   return;
 }
 
-AddressRange fun_addr_range = sc.function->GetAddressRange();
-Address fun_start_addr = fun_addr_range.GetBaseAddress();
-line_table->FindLineEntryByAddress(fun_start_addr, function_start,
-   &index_ptr);
-
-Address fun_end_addr(fun_start_addr.GetSection(),
- fun_start_addr.GetOffset() +
- fun_addr_range.GetByteSize());
-
-bool all_in_function = true;
+RangeVector line_idx_ranges;
+for (const AddressRange &range : sc.function->GetAddressRanges()) {
+  auto [begin, end] = line_table->GetLineEntryIndexRange(range);
+  line_idx_ranges.Append(begin, end - begin);
+}
+line_idx_ranges.Sort();
 
-line_table->FindLineEntryByAddress(fun_end_addr, function_start,
-   &end_ptr);
+bool found_something = false;
 
 // Since not all source lines will contribute code, check if we are
 // setting the breakpoint on the exact line number or the nearest
@@ -991,45 +985,43 @@ class CommandObjectThreadUntil : public 
CommandObjectParsed {
 for (uint32_t line_number : line_numbers) {
   LineEntry line_entry;
   bool exact = false;
-  uint32_t start_idx_ptr = index_ptr;
-  start_idx_ptr = sc.comp_unit->FindLineEntry(
-  index_ptr, line_number, nullptr, exact, &line_entry);
-  if (start_idx_ptr != UINT32_MAX)
-line_number = line_entry.line;
+  if (sc.comp_unit->FindLineEntry(0, line_number, nullptr, exact,
+  &line_entry) == UINT32_MAX)
+continue;
+
+  found_something = true;
+  line_number = line_entry.line;
   exact = true;
-  start_idx_ptr = index_ptr;
-  while (start_idx_ptr <= end_ptr) {
-start_idx_ptr = sc.comp_unit->FindLineEntry(
-start_idx_ptr, line_number, nullptr, exact, &line_entry);
-if (start_idx_ptr == UINT32_MAX)
-  break;
-
-addr_t address =
-line_entry.range.GetBaseAddress().GetLoadAddress(target);
-if (address != LLDB_INVALID_ADDRESS) {
-  if (fun_addr_range.ContainsLoadAddress(address, target))
+  uint32_t end_func_idx = line_idx_ranges.GetMaxRangeEnd(0);
+  uint32_t idx = sc.comp_unit->FindLineEntry(
+  line_idx_ranges.GetMinRangeBase(UINT32_MAX), line_number, 
nullptr,
+  exact, &line_entry);
+  while (idx < end_func_idx) {
+if (line_idx_ra

[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

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

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

LGTM. Would you mind making the `MESSAGE` lowercase in this file? I think this 
is the only place where we use `MESSAGE` instead of `message` and it just looks 
weird. Can be the same or a different PR. 

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


[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

2025-02-21 Thread via lldb-commits

foxtran wrote:

@JDevlieghere, I've updated messages :)

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


[Lldb-commits] [lldb] [lldb] Fix GCC's `-Wreturn-type` warnings (PR #127974)

2025-02-21 Thread via lldb-commits

foxtran wrote:

@JDevlieghere, it is still not merged. Are there any extra checks?

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


[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

2025-02-21 Thread via lldb-commits

https://github.com/foxtran updated 
https://github.com/llvm/llvm-project/pull/128196

>From 4683735bef8f43a5e39be6aedffd76c47e43beb2 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" 
Date: Fri, 21 Feb 2025 17:33:25 +0100
Subject: [PATCH 1/2] Use STATUS instead of explicit '--' in MESSAGE

---
 lldb/source/API/CMakeLists.txt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 147b30f3b0026..47b60ef0895a3 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -206,23 +206,23 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
 # If we're not exporting all symbols, we'll want to explicitly set
 # the exported symbols here.  This prevents 'log enable --stack ...'
 # from working on some systems but limits the liblldb size.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb 
namespace")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
 # Don't use an explicit export. Instead, tell the linker to export all 
symbols.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
   else ()
-MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the 
exports "
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
 " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
   endif()
 elseif (LLDB_EXPORT_ALL_SYMBOLS)
-  MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+  MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 
   # Pull out the various lldb libraries linked into liblldb, these will be used
   # when looking for symbols to extract. We ignore most plugin libraries here,

>From c8405f65bd8a4eeaad1002e5f7feeef41b85f25b Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" 
Date: Fri, 21 Feb 2025 17:47:21 +0100
Subject: [PATCH 2/2] Use message in lower case

---
 lldb/source/API/CMakeLists.txt | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 47b60ef0895a3..9d6a7d8850286 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -206,23 +206,23 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
 # If we're not exporting all symbols, we'll want to explicitly set
 # the exported symbols here.  This prevents 'log enable --stack ...'
 # from working on some systems but limits the liblldb size.
-MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
+message(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
 # Don't use an explicit export. Instead, tell the linker to export all 
symbols.
-MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
-MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
+message(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+message(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
   else ()
-MESSAGE(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
+message(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
 " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
-MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
+message(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
   endif()
 elseif (L

[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

2025-02-21 Thread via lldb-commits

https://github.com/foxtran created 
https://github.com/llvm/llvm-project/pull/128196

Currently, configuring lldb with cmake with separated stdout and stderr gives 
some unnecessary output in stderr which happens since message statement is used 
without `[mode]` (See https://cmake.org/cmake/help/v3.31/command/message.html). 
This patch adds mode `STATUS` instead of explicit `--` at the beginning of 
messages. 

>From 4683735bef8f43a5e39be6aedffd76c47e43beb2 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" 
Date: Fri, 21 Feb 2025 17:33:25 +0100
Subject: [PATCH] Use STATUS instead of explicit '--' in MESSAGE

---
 lldb/source/API/CMakeLists.txt | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 147b30f3b0026..47b60ef0895a3 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -206,23 +206,23 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
 # If we're not exporting all symbols, we'll want to explicitly set
 # the exported symbols here.  This prevents 'log enable --stack ...'
 # from working on some systems but limits the liblldb size.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb 
namespace")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
 # Don't use an explicit export. Instead, tell the linker to export all 
symbols.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
   else ()
-MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the 
exports "
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
 " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
   endif()
 elseif (LLDB_EXPORT_ALL_SYMBOLS)
-  MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+  MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 
   # Pull out the various lldb libraries linked into liblldb, these will be used
   # when looking for symbols to extract. We ignore most plugin libraries here,

___
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-02-21 Thread Hu Jialun via lldb-commits

https://github.com/SuibianP 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] Refactoring lldb-dap port listening mode to allow multiple connections. (PR #116392)

2025-02-21 Thread John Harrison via lldb-commits


@@ -58,12 +58,13 @@ const char DEV_NULL[] = "/dev/null";
 
 namespace lldb_dap {
 
-DAP::DAP(llvm::StringRef path, std::ofstream *log, ReplMode repl_mode,
- StreamDescriptor input, StreamDescriptor output)
-: debug_adaptor_path(path), log(log), input(std::move(input)),
+DAP::DAP(std::string name, llvm::StringRef path, std::ofstream *log,
+ StreamDescriptor input, StreamDescriptor output, ReplMode repl_mode,
+ std::vector pre_init_commands)
+: name(name), debug_adaptor_path(path), log(log), input(std::move(input)),

ashgti wrote:

Done.

https://github.com/llvm/llvm-project/pull/116392
___
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 lldb-dap port listening mode to allow multiple connections. (PR #116392)

2025-02-21 Thread John Harrison via lldb-commits


@@ -4952,6 +4895,29 @@ static int DuplicateFileDescriptor(int fd) {
 #endif
 }
 
+static llvm::Expected>
+validateConnection(llvm::StringRef conn) {
+  auto uri = lldb_private::URI::Parse(conn);
+
+  if (uri && (uri->scheme == "tcp" || uri->scheme == "connect" ||
+  !uri->hostname.empty() || uri->port)) {
+return std::make_pair(
+Socket::ProtocolTcp,
+formatv("[{0}]:{1}", uri->hostname.empty() ? "0.0.0.0" : uri->hostname,
+uri->port.value_or(0)));
+  }
+
+  if (uri && (uri->scheme == "unix" || uri->scheme == "unix-connect" ||
+  uri->path != "/")) {
+return std::make_pair(Socket::ProtocolUnixDomain, uri->path.str());
+  }
+
+  return llvm::createStringError(
+  "Unsupported connection specifier, expected 'unix-connect:///path' or "
+  "'connect://[host]:port', got '%s'.",
+  conn.str().c_str());
+}
+
 int main(int argc, char *argv[]) {

ashgti wrote:

I moved the main connection handling loop to its own function, we can break 
things up further as well if you'd like

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


[Lldb-commits] [lldb] 506deb0 - [lldb] Fix GCC's `-Wreturn-type` warnings (#127974)

2025-02-21 Thread via lldb-commits

Author: foxtran
Date: 2025-02-21T11:02:19-06:00
New Revision: 506deb0cce3fe503f61ef1a1a08a40770ef4b978

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

LOG: [lldb] Fix GCC's `-Wreturn-type` warnings (#127974)

This patch fixes `-Wreturn-type` warnings which happens if LLVM is built
with GCC compiler (14.1 is used for detecting)

Warnings:
```
llvm-project/lldb/source/ValueObject/DILLexer.cpp: In static member function 
‘static llvm::StringRef lldb_private::dil::Token::GetTokenName(Kind)’:
llvm-project/lldb/source/ValueObject/DILLexer.cpp:33:1: warning: control 
reaches end of non-void function [-Wreturn-type]
   33 | }
  | ^
```
and:
```
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp: In member function 
‘virtual std::string lldb_private::TypeSummaryImpl::GetSummaryKindName()’:
llvm-project/lldb/source/DataFormatters/TypeSummary.cpp:62:1: warning: control 
reaches end of non-void function [-Wreturn-type]
   62 | }
  | ^
```

Technically, it is a bug in Clang (see #115345), however, UBSan with
Clang should detect these places, therefore it would be nice to provide
a return statement for all possible inputs (even invalid).

Added: 


Modified: 
lldb/source/DataFormatters/TypeSummary.cpp
lldb/source/ValueObject/DILLexer.cpp

Removed: 




diff  --git a/lldb/source/DataFormatters/TypeSummary.cpp 
b/lldb/source/DataFormatters/TypeSummary.cpp
index 2c863b364538f..18bf81aedf2cb 100644
--- a/lldb/source/DataFormatters/TypeSummary.cpp
+++ b/lldb/source/DataFormatters/TypeSummary.cpp
@@ -59,6 +59,7 @@ std::string TypeSummaryImpl::GetSummaryKindName() {
   case Kind::eBytecode:
 return "bytecode";
   }
+  llvm_unreachable("Unknown type kind name");
 }
 
 StringSummaryFormat::StringSummaryFormat(const TypeSummaryImpl::Flags &flags,

diff  --git a/lldb/source/ValueObject/DILLexer.cpp 
b/lldb/source/ValueObject/DILLexer.cpp
index c7acfec347af4..1f013288c839b 100644
--- a/lldb/source/ValueObject/DILLexer.cpp
+++ b/lldb/source/ValueObject/DILLexer.cpp
@@ -30,6 +30,7 @@ llvm::StringRef Token::GetTokenName(Kind kind) {
   case Kind::r_paren:
 return "r_paren";
   }
+  llvm_unreachable("Unknown token name");
 }
 
 static bool IsLetter(char c) {



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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

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


@@ -56,13 +60,83 @@ struct LLDBBaseTelemetryInfo : public 
llvm::telemetry::TelemetryInfo {
   void serialize(llvm::telemetry::Serializer &serializer) const override;
 };
 
+/// Describes the exit status of a debugger.
+struct ExitDescription {
+  int exit_code;
+  std::string description;
+};
+
+struct DebuggerTelemetryInfo : public LLDBBaseTelemetryInfo {

labath wrote:

Okay, but the fields are still there. I know why you did this, but I think it's 
strange to have a field that is never set anywhere, and I definitely wouldn't 
want to define a field for every piece of information that anybody wants to 
collect. If we go in this direction (data collected downstream), then I think 
the fields should be defined downstream as well. One way to do that would be to 
wrap the upstream member in a vendor-specific event struct which includes the 
upstream struct as a member (or just a copy of its members). Another would be 
to attach them directly in the Destination class (that way the custom event 
struct doesn't even have to exist).

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

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


@@ -43,29 +77,79 @@ void LLDBBaseTelemetryInfo::serialize(Serializer 
&serializer) const {
 serializer.write("end_time", ToNanosec(end_time.value()));
 }
 
-[[maybe_unused]] static std::string MakeUUID(Debugger *debugger) {
-  uint8_t random_bytes[16];
-  if (auto ec = llvm::getRandomBytes(random_bytes, 16)) {
-LLDB_LOG(GetLog(LLDBLog::Object),
- "Failed to generate random bytes for UUID: {0}", ec.message());
-// Fallback to using timestamp + debugger ID.
-return llvm::formatv(
-"{0}_{1}", std::chrono::steady_clock::now().time_since_epoch().count(),
-debugger->GetID());
+void DebuggerInfo::serialize(Serializer &serializer) const {
+  LLDBBaseTelemetryInfo::serialize(serializer);
+
+  serializer.write("username", username);
+  serializer.write("lldb_git_sha", lldb_git_sha);
+  serializer.write("lldb_path", lldb_path);
+  serializer.write("cwd", cwd);
+  if (exit_desc.has_value()) {
+serializer.write("exit_code", exit_desc->exit_code);
+serializer.write("exit_desc", exit_desc->description);
   }
-  return UUID(random_bytes).GetAsString();
+}
+
+void MiscTelemetryInfo::serialize(Serializer &serializer) const {
+  LLDBBaseTelemetryInfo::serialize(serializer);
+  serializer.write("target_uuid", target_uuid);
+  serializer.beginObject("meta_data");
+  for (const auto &kv : meta_data)
+serializer.write(kv.first, kv.second);
+  serializer.endObject();
 }
 
 TelemetryManager::TelemetryManager(std::unique_ptr config)
-: m_config(std::move(config)) {}
+: m_config(std::move(config)), m_id(MakeUUID) {}
 
 llvm::Error TelemetryManager::preDispatch(TelemetryInfo *entry) {
-  // Do nothing for now.
-  // In up-coming patch, this would be where the manager
-  // attach the session_uuid to the entry.
+  // Look up the session_id to assign to this entry or make one
+  // if none had been computed for this debugger.
+  LLDBBaseTelemetryInfo *lldb_entry =
+  llvm::dyn_cast(entry);
+  std::string session_id = m_id;
+  if (Debugger *debugger = lldb_entry->debugger) {
+auto session_id_pos = session_ids.find(debugger->getID());

labath wrote:

Can we drop the map? I doubt copying the string is noticably faster than 
constructing it each time (particularly if you use lower level constructs like 
`raw_string_ostream(lldb_entry->SessionId) << m_id << "_" << debugger->getID()`

Or even better, use two fields like I originally suggested? Then there's no 
copying and it has the advantage that you can choose how to do the analysis: I 
can imagine that in some situations you may want to see all events from a 
particular Debugger object, but in others you may want to see "everything that 
happens within a single process". I think that would be easier to do if the 
fields are separate.

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

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


@@ -41,17 +41,32 @@ static uint64_t ToNanosec(const SteadyTimePoint Point) {
   return std::chrono::nanoseconds(Point.time_since_epoch()).count();
 }
 
-static std::string MakeUUID(Debugger *debugger) {
+// Generate a unique string. This should be unique across different runs.
+// We build such string by combining three parts:
+// <16 random bytes>__
+// This reduces the chances of getting the same UUID, even when the same

labath wrote:

Can we drop the user name part? I would hope 16 bytes of random data is enough 
to guarantee uniqueness, and I suspect the MD5 hash on the user name is easily 
reversible (so it's basically leaking the user name).

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


[Lldb-commits] [lldb] [LLDB][Telemetry]Define DebuggerTelemetryInfo and related methods (PR #127696)

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

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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

https://github.com/labath updated 
https://github.com/llvm/llvm-project/pull/128156

>From b213b08c0a6527ec4732ef977ad43e3261dd73ad Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Fri, 21 Feb 2025 10:36:20 +0100
Subject: [PATCH 1/3] Reapply "[lldb] Implement basic support for
 reverse-continue (#125242)" (again)

This reverts commit 87b7f63a117c340a6d9ca47959335fd7ef6c7ad2, reapplying
7e66cf74fb4e6a103f923e34700a7b6f20ac2a9b with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot issues.
---
 lldb/include/lldb/API/SBProcess.h |   1 +
 lldb/include/lldb/Target/Process.h|  28 +-
 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  | 541 ++
 .../Python/lldbsuite/test/lldbtest.py |   2 +
 .../tools/lldb-server/lldbgdbserverutils.py   |  14 +-
 lldb/source/API/SBProcess.cpp |  12 +
 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   |  98 +++-
 .../Process/gdb-remote/ProcessGDBRemote.h |   4 +-
 .../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 | 159 +
 .../TestReverseContinueNotSupported.py|  35 ++
 .../TestReverseContinueWatchpoints.py | 136 +
 .../functionalities/reverse-execution/main.c  |  25 +
 lldb/tools/lldb-dap/JSONUtils.cpp |   3 +
 lldb/tools/lldb-dap/LLDBUtils.cpp |   1 +
 40 files changed, 1402 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/TestReverseContinueWatchpoints.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 1624e02070b1b..882b8bd837131 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 c3622a29bc772..2e827d4c5cb74 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1089,6 +1089,13 @@ class Process : public 
std::enable_shared_from_this,
   /// Returns an error object.
   virtual Status WillResume() { return Status(); }
 
+  /// Reports whether this process supports reverse execution.
+  ///
+  /// \return
+  /// Returns true if the process supports reverse execution (at least
+  /// under some circumstances).
+  virtual bool SupportsReverseDirection() { return false; }
+
   /// Resumes all of a process's threads as configured using the Thread run
   /// control functions.
   ///
@@ -1104,9 +,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

[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

This reverts commit 
https://github.com/llvm/llvm-project/commit/87b7f63a117c340a6d9ca47959335fd7ef6c7ad2,
 reapplying
https://github.com/llvm/llvm-project/commit/7e66cf74fb4e6a103f923e34700a7b6f20ac2a9b
 with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot issues.

---

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


40 Files Affected:

- (modified) lldb/include/lldb/API/SBProcess.h (+1) 
- (modified) lldb/include/lldb/Target/Process.h (+26-2) 
- (modified) lldb/include/lldb/Target/StopInfo.h (+7) 
- (modified) lldb/include/lldb/Target/Thread.h (+4-5) 
- (modified) lldb/include/lldb/Target/ThreadList.h (+5-1) 
- (modified) lldb/include/lldb/Target/ThreadPlan.h (+13) 
- (modified) lldb/include/lldb/Target/ThreadPlanBase.h (+2) 
- (modified) lldb/include/lldb/lldb-enumerations.h (+6) 
- (modified) lldb/packages/Python/lldbsuite/test/gdbclientutils.py (+3-2) 
- (added) lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py (+177) 
- (added) lldb/packages/Python/lldbsuite/test/lldbreverse.py (+541) 
- (modified) lldb/packages/Python/lldbsuite/test/lldbtest.py (+2) 
- (modified) 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py 
(+9-5) 
- (modified) lldb/source/API/SBProcess.cpp (+12) 
- (modified) lldb/source/API/SBThread.cpp (+2) 
- (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+2-1) 
- (modified) lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp (+3) 
- (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (+7-1) 
- (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h (+1-1) 
- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
(+8-1) 
- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h (+1-1) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (+20) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (+6) 
- (modified) 
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp 
(+1) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
(+85-13) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (+3-1) 
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp (+7-2) 
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.h (+1-1) 
- (modified) lldb/source/Target/Process.cpp (+20-4) 
- (modified) lldb/source/Target/StopInfo.cpp (+28) 
- (modified) lldb/source/Target/Thread.cpp (+6-3) 
- (modified) lldb/source/Target/ThreadList.cpp (+29-3) 
- (modified) lldb/source/Target/ThreadPlanBase.cpp (+4) 
- (added) lldb/test/API/functionalities/reverse-execution/Makefile (+3) 
- (added) 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
 (+159) 
- (added) 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py
 (+35) 
- (added) 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
 (+136) 
- (added) lldb/test/API/functionalities/reverse-execution/main.c (+25) 
- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+3) 
- (modified) lldb/tools/lldb-dap/LLDBUtils.cpp (+1) 


``diff
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index 1624e02070b1b..882b8bd837131 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 c3622a29bc772..2e827d4c5cb74 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1089,6 +1089,13 @@ class Process : public 
std::enable_shared_from_this,
   /// Returns an error object.
   virtual Status WillResume() { return Status(); }
 
+  /// Reports whether this process supports reverse execution.
+  ///
+  /// \return
+  /// Returns true if the process supports reverse execution (at least
+  /// under some circumstances).
+  virtual bool SupportsReverseDirection() { return false; }
+
   /// Resumes all of a process's threads as configured using the Thread run
   /// control functions.
   ///
@@ -1104,9 +,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::F

[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

2025-02-21 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
41cece8c86399dd1ffcb6b7a8b50c10083fe5a40...2dc2ff7a51f5173073a1b9aa57a49b1800657972
 lldb/packages/Python/lldbsuite/test/lldbgdbproxy.py 
lldb/packages/Python/lldbsuite/test/lldbreverse.py 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueBreakpoints.py
 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueNotSupported.py
 
lldb/test/API/functionalities/reverse-execution/TestReverseContinueWatchpoints.py
 lldb/packages/Python/lldbsuite/test/gdbclientutils.py 
lldb/packages/Python/lldbsuite/test/lldbtest.py 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py
``





View the diff from darker here.


``diff
--- packages/Python/lldbsuite/test/lldbgdbproxy.py  2025-02-21 
09:49:05.00 +
+++ packages/Python/lldbsuite/test/lldbgdbproxy.py  2025-02-21 
09:57:12.340560 +
@@ -38,11 +38,13 @@
 self.logger.propagate = False
 self.logger.setLevel(logging.DEBUG)
 
 # log all warnings to stderr
 self._stderr_log_handler = logging.StreamHandler()
-self._stderr_log_handler.setLevel(logging.DEBUG if self.TraceOn() else 
logging.WARNING)
+self._stderr_log_handler.setLevel(
+logging.DEBUG if self.TraceOn() else logging.WARNING
+)
 self._stderr_log_handler.setFormatter(self._log_formatter)
 self.logger.addHandler(self._stderr_log_handler)
 
 def setUp(self):
 TestBase.setUp(self)

``




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


[Lldb-commits] [lldb] Reland "[lldb] Implement basic support for reverse-continue" (#123906)" (PR #123945)

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

labath wrote:

Okay, I've created a new version of the patch 
[here](https://github.com/llvm/llvm-project/pull/128156). Would you like to 
merge it at your convenience? There was a small merge conflict with Jason's 
breakpoint detection patch, but I think I've was able to resolve that 
correctly.  I've added some debugging output to print the packet log in the 
"TraceOn" mode. If your bot doesn't run in this mode, you may want to change 
that to dumping the logs unconditionally.

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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


@@ -0,0 +1,177 @@
+import logging
+import os
+import os.path
+import random
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.gdbclientutils import *
+import lldbgdbserverutils
+from lldbsuite.support import seven
+
+
+class GDBProxyTestBase(TestBase):
+"""
+Base class for gdbserver proxy tests.
+
+This class will setup and start a mock GDB server for the test to use.
+It pases through requests to a regular lldb-server/debugserver and
+forwards replies back to the LLDB under test.
+"""
+
+"""The gdbserver that we implement."""
+server = None
+"""The inner lldb-server/debugserver process that we proxy requests 
into."""
+monitor_server = None
+monitor_sock = None
+
+server_socket_class = TCPServerSocket
+
+DEFAULT_TIMEOUT = 20 * (10 if ("ASAN_OPTIONS" in os.environ) else 1)
+
+_verbose_log_handler = None
+_log_formatter = logging.Formatter(fmt="%(asctime)-15s %(levelname)-8s 
%(message)s")
+
+def setUpBaseLogging(self):
+self.logger = logging.getLogger(__name__)
+
+self.logger.propagate = False
+self.logger.setLevel(logging.DEBUG)
+
+# log all warnings to stderr
+self._stderr_log_handler = logging.StreamHandler()
+self._stderr_log_handler.setLevel(logging.DEBUG if self.TraceOn() else 
logging.WARNING)

labath wrote:

Apply this if you want to dump traces unconditionally.

```suggestion
self._stderr_log_handler.setLevel(logging.DEBUG)
```

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


[Lldb-commits] [lldb] Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (PR #128156)

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


@@ -635,10 +635,11 @@ bool Thread::SetupForResume() {
 // what the current plan is.
 
 lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
-if (reg_ctx_sp) {
+ProcessSP process_sp(GetProcess());
+if (reg_ctx_sp && process_sp && direction == eRunForward) {

labath wrote:

merge conflict around here

https://github.com/llvm/llvm-project/pull/128156
___
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 PlatformAIX plugin (PR #121273)

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


@@ -0,0 +1,155 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Use defined constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+// For remotely cross debugging aix
+constexpr int MapVariable = 0x0;
+constexpr int MapPrivate = 0x2;
+constexpr int MapAnonymous = 0x10;
+#if defined(_AIX)
+#include 
+static_assert(MapVariable == MAP_VARIABLE);
+static_assert(MapPrivate == MAP_PRIVATE);
+static_assert(MapAnonymous = MAP_ANONYMOUS);
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force || (arch && arch->IsValid() &&
+  arch->GetTriple().getOS() == llvm::Triple::AIX);
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#ifdef _AIX
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0)
+if (--g_initialize_count == 0)
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+
+  PlatformPOSIX::Terminate();
+}
+
+PlatformAIX::PlatformAIX(bool is_host) : PlatformPOSIX(is_host) {
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+  } else {
+m_supported_architectures =
+CreateArchList({llvm::Triple::ppc64}, llvm::Triple::AIX);
+  }
+}
+
+std::vector
+PlatformAIX::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
+  if (m_remote_platform_sp)
+return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
+  return m_supported_architectures;
+}
+
+void PlatformAIX::GetStatus(Stream &strm) {
+  Platform::GetStatus(strm);
+
+#if LLDB_ENABLE_POSIX
+  // Display local kernel information only when we are running in host mode.
+  // Otherwise, we would end up printing non-AIX information (when running on
+  // Mac OS for example).
+  if (IsHost()) {
+struct utsname un;
+
+if (uname(&un))
+  return;
+
+strm.Printf("Kernel: %s\n", un.sysname);
+strm.Printf("   Release: %s\n", un.release);
+strm.Printf("   Version: %s\n", un.version);
+  }
+#endif
+}
+
+void PlatformAIX::CalculateTrapHandlerSymbolNames() {}
+
+lldb::UnwindPlanSP
+PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
+  ConstString name) {
+  return {};
+}
+
+MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
+ addr_t length, unsigned prot,
+ unsigned flags, addr_t fd,
+ addr_t offset) {
+  unsigned flags_platform = 0;
+#if defined(_AIX)
+  flags_platform = MapPrivate | MapVariable | MapAnon;
+#endif

labath wrote:

No, drop the ifdef. Thanks.

https://github.com/llvm/llvm-project/pull/121273
___
lldb-commits mailing 

[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)

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

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

Looks good. Thanks.

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


[Lldb-commits] [lldb] a5f759e - [lldb][AIX] Added PlatformAIX plugin (#121273)

2025-02-21 Thread via lldb-commits

Author: Dhruv Srivastava
Date: 2025-02-21T17:11:06+05:30
New Revision: a5f759ed9d119f4bf28f6f4c32487917fb93ec5e

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

LOG: [lldb][AIX] Added PlatformAIX plugin (#121273)

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

Details:
--
Adding PlatformAIX plugin for a basic lldb build support. The 1st commit
is the original version as in the draft PR which is a PlatformLinux
copy. I have removed some of the code in the next commits.
Please let me know all the other changes required to push the
PlatformAIX changes and avoid any duplication.

Added: 
lldb/source/Plugins/Platform/AIX/CMakeLists.txt
lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
lldb/source/Plugins/Platform/AIX/PlatformAIX.h

Modified: 
lldb/source/Plugins/Platform/CMakeLists.txt

Removed: 




diff  --git a/lldb/source/Plugins/Platform/AIX/CMakeLists.txt 
b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
new file mode 100644
index 0..70f6681204438
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_lldb_library(lldbPluginPlatformAIX PLUGIN
+  PlatformAIX.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginPlatformPOSIX
+  )
+
+target_compile_definitions(lldbPluginPlatformAIX PRIVATE "-D_ALL_SOURCE")

diff  --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp 
b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
new file mode 100644
index 0..21724d83133e9
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -0,0 +1,158 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Use defined constants from AIX mman.h for use when targeting remote aix
+// systems even when host has 
diff erent values.
+
+// For remotely cross debugging aix
+constexpr int MapVariable = 0x0;
+constexpr int MapPrivate = 0x2;
+constexpr int MapAnonymous = 0x10;
+#if defined(_AIX)
+#include 
+static_assert(MapVariable == MAP_VARIABLE);
+static_assert(MapPrivate == MAP_PRIVATE);
+static_assert(MapAnonymous == MAP_ANONYMOUS);
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force || (arch && arch->IsValid() &&
+  arch->GetTriple().getOS() == llvm::Triple::AIX);
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#ifdef _AIX
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+ 

[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX updated 
https://github.com/llvm/llvm-project/pull/121273

>From 16107a423e30cc339b7529db35a75c3c26924146 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Sat, 28 Dec 2024 13:19:21 -0600
Subject: [PATCH 1/7] Introducing PlatformAIX from PlatformLinux

---
 .../Plugins/Platform/AIX/CMakeLists.txt   |  13 +
 .../Plugins/Platform/AIX/PlatformAIX.cpp  | 471 ++
 .../source/Plugins/Platform/AIX/PlatformAIX.h |  74 +++
 lldb/source/Plugins/Platform/CMakeLists.txt   |   1 +
 4 files changed, 559 insertions(+)
 create mode 100644 lldb/source/Plugins/Platform/AIX/CMakeLists.txt
 create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
 create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.h

diff --git a/lldb/source/Plugins/Platform/AIX/CMakeLists.txt 
b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
new file mode 100644
index 0..85ff0a315eabd
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")
+
+add_lldb_library(lldbPluginPlatformAIX PLUGIN
+  PlatformAIX.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+lldbHost
+lldbInterpreter
+lldbTarget
+lldbPluginPlatformPOSIX
+  )
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp 
b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
new file mode 100644
index 0..5c94477002978
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -0,0 +1,471 @@
+//===-- PlatformAIX.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 "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+
+#include 
+#if LLDB_ENABLE_POSIX
+#include 
+#endif
+
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Define these constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+#if defined(_AIX)
+#include 
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+  Log *log = GetLog(LLDBLog::Platform);
+  LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+   arch ? arch->GetArchitectureName() : "",
+   arch ? arch->GetTriple().getTriple() : "");
+
+  bool create = force;
+  if (!create && arch && arch->IsValid()) {
+const llvm::Triple &triple = arch->GetTriple();
+switch (triple.getOS()) {
+case llvm::Triple::AIX:
+  create = true;
+  break;
+
+default:
+  break;
+}
+  }
+
+  LLDB_LOG(log, "create = {0}", create);
+  if (create) {
+return PlatformSP(new PlatformAIX(false));
+  }
+  return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+  if (is_host)
+return "Local AIX user platform plug-in.";
+  return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+  PlatformPOSIX::Initialize();
+
+  if (g_initialize_count++ == 0) {
+#if defined(_AIX)
+PlatformSP default_platform_sp(new PlatformAIX(true));
+default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+Platform::SetHostPlatform(default_platform_sp);
+#endif
+PluginManager::RegisterPlugin(
+PlatformAIX::GetPluginNameStatic(false),
+PlatformAIX::GetPluginDescriptionStatic(false),
+PlatformAIX::CreateInstance, nullptr);
+  }
+}
+
+void PlatformAIX::Terminate() {
+  if (g_initialize_count > 0) {
+if (--g_initialize_count == 0) {
+  PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+}
+  }
+
+  PlatformPOSIX::Terminate();
+}
+
+/// Default Constructor
+PlatformAIX::PlatformAIX(bool is_host)
+: PlatformPOSIX(is_host) // This is the local host platform
+{
+  if (is_host) {
+ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+m_supported_architectures.push_back(hostArch);
+if (hostArch.GetTriple().isArch64Bit()) {
+  m_supported_architectures.push_back(
+  HostInfo::GetArchitecture(HostInfo::eArchKind32));
+}
+  } else {
+m_supported_architectures = CreateArchList(
+{llvm::Triple::x86_64, llvm::Triple

[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)

2025-02-21 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")

DhruvSrivastavaX wrote:

Done, Thanks!

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


[Lldb-commits] [lldb] [WIP] [lldb][TypeSystemClang] Create clang::SourceLocation from DWARF and attach to AST (PR #127829)

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

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

>From 1aabc8a93ffac06755cbaf5e6c1fa8913cd63729 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 19 Feb 2025 12:47:30 +
Subject: [PATCH 1/3] [lldb][TypeSystemClang] Create MainFileID for
 TypeSystemClang ASTContexts

---
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 1e0c7f0514941..563961b9a4971 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -13,6 +13,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/SmallVectorMemoryBuffer.h"
 
 #include 
 #include 
@@ -361,6 +362,39 @@ static void SetMemberOwningModule(clang::Decl *member,
 }
 }
 
+/// Creates a dummy main file for the given SourceManager.
+/// This file only serves as a container for include locations to other
+/// FileIDs that are put into this type system (either by the ASTImporter
+/// or when TypeSystemClang generates source locations for declarations).
+/// This file is not reflected to disk.
+static clang::FileID CreateDummyMainFile(clang::SourceManager &sm,
+ clang::FileManager &fm) {
+  llvm::StringRef main_file_path = "";
+  // The file contents are empty and should never be seen by the user. The new
+  // line is just there to not throw off any line counting logic that might
+  // expect files to end with a newline.
+  llvm::StringRef main_file_contents = "\n";
+  const time_t mod_time = 0;
+  const off_t file_size = static_cast(main_file_contents.size());
+
+  // Create a virtual FileEntry for our dummy file.
+  auto fe = fm.getVirtualFileRef(main_file_path, file_size, mod_time);
+
+  // Overwrite the file buffer with our empty file contents.
+  llvm::SmallVector buffer;
+  buffer.append(main_file_contents.begin(), main_file_contents.end());
+  auto file_contents = std::make_unique(
+  std::move(buffer), main_file_path);
+  sm.overrideFileContents(fe, std::move(file_contents));
+
+  // Create the actual file id for the FileEntry and set it as the main file.
+  clang::FileID fid =
+  sm.createFileID(fe, SourceLocation(), clang::SrcMgr::C_User);
+  sm.setMainFileID(fid);
+
+  return fid;
+}
+
 char TypeSystemClang::ID;
 
 bool TypeSystemClang::IsOperator(llvm::StringRef name,
@@ -692,6 +726,11 @@ void TypeSystemClang::CreateASTContext() {
   m_diagnostic_consumer_up = std::make_unique();
   m_ast_up->getDiagnostics().setClient(m_diagnostic_consumer_up.get(), false);
 
+  // Set up the MainFileID of this ASTContext. All other FileIDs created
+  // by this TypeSystem will act as-if included into this dummy main file.
+  auto fid = CreateDummyMainFile(*m_source_manager_up, *m_file_manager_up);
+  assert(m_ast_up->getSourceManager().getMainFileID() == fid);
+
   // This can be NULL if we don't know anything about the architecture or if
   // the target for an architecture isn't enabled in the llvm/clang that we
   // built

>From 5d4cbd3e306f02eee80b4fd614b9e155f75d3d1d Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Wed, 19 Feb 2025 13:37:01 +
Subject: [PATCH 2/3] [lldb][TypeSystemClang] Set location on functions,
 parameters, enums and structures

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 10 ++--
 .../SymbolFile/NativePDB/PdbAstBuilder.cpp|  2 +-
 .../Plugins/SymbolFile/PDB/PDBASTParser.cpp   |  3 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 48 ++-
 .../TypeSystem/Clang/TypeSystemClang.h| 46 +++---
 lldb/unittests/Symbol/TestTypeSystemClang.cpp |  7 +--
 6 files changed, 78 insertions(+), 38 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 2d4d22559963f..abf3b22b0ae15 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1372,7 +1372,7 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
 ignore_containing_context ? m_ast.GetTranslationUnitDecl()
   : containing_decl_ctx,
 GetOwningClangModule(die), name, clang_type, attrs.storage,
-attrs.is_inline);
+attrs.is_inline, attrs.decl);
 std::free(name_buf);
 
 if (has_template_params) {
@@ -1382,11 +1382,11 @@ DWARFASTParserClang::ParseSubroutine(const DWARFDIE 
&die,
   ignore_containing_context ? m_ast.GetTranslationUnitDecl()
 : containing_decl_ctx,
   GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
-  attrs.storage

[Lldb-commits] [lldb] [lldb] Fixing edge cases in "source list" (PR #126526)

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

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


[Lldb-commits] [lldb] [lldb] Fix "in function" detection in "thread until" (PR #123622)

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

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


[Lldb-commits] [lldb] 71af48f - [lldb] Fixing edge cases in "source list" (#126526)

2025-02-21 Thread via lldb-commits

Author: Pavel Labath
Date: 2025-02-21T13:13:34+01:00
New Revision: 71af48fafdb6319da38ee7e5f04e16ff548fe57e

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

LOG: [lldb] Fixing edge cases in "source list" (#126526)

While looking at how to make Function::GetEndLineSourceInfo (which is
only used in "command source") work with discontinuous functions, I
realized there are other corner cases that this function doesn't handle.

The code assumed that the last line entry in the function will also
correspond to the last source line. This is probably true for
unoptimized code, but I don't think we can rely on the optimizer to
preserve this property. What's worse, the code didn't check that the
last line entry belonged to the same file as the first one, so if this
line entry was the result of inlining, we could end up using a line from
a completely different file.

To fix this, I change the algorithm to iterate over all line entries in
the function (which belong to the same file) and find the max line
number out of those. This way we can naturally handle the discontinuous
case as well.

This implementation is going to be slower than the previous one, but I
don't think that matters, because:
- this command is only used rarely, and interactively
- we have plenty of other code which iterates through the line table

I added some basic tests for the function operation. I don't claim the
tests to be comprehensive, or that the function handles all edge cases,
but test framework created here could be used for testing other
fixes/edge cases as well.

Added: 
lldb/test/Shell/Commands/command-source-list.s

Modified: 
lldb/include/lldb/Symbol/Function.h
lldb/source/Commands/CommandObjectSource.cpp
lldb/source/Symbol/Function.cpp

Removed: 




diff  --git a/lldb/include/lldb/Symbol/Function.h 
b/lldb/include/lldb/Symbol/Function.h
index f3b956139f3c5..ee3a8304fc5b3 100644
--- a/lldb/include/lldb/Symbol/Function.h
+++ b/lldb/include/lldb/Symbol/Function.h
@@ -15,6 +15,7 @@
 #include "lldb/Expression/DWARFExpressionList.h"
 #include "lldb/Symbol/Block.h"
 #include "lldb/Utility/UserID.h"
+#include "lldb/lldb-forward.h"
 #include "llvm/ADT/ArrayRef.h"
 
 #include 
@@ -460,6 +461,7 @@ class Function : public UserID, public SymbolContextScope {
   }
 
   lldb::LanguageType GetLanguage() const;
+
   /// Find the file and line number of the source location of the start of the
   /// function.  This will use the declaration if present and fall back on the
   /// line table if that fails.  So there may NOT be a line table entry for
@@ -473,16 +475,9 @@ class Function : public UserID, public SymbolContextScope {
   void GetStartLineSourceInfo(lldb::SupportFileSP &source_file_sp,
   uint32_t &line_no);
 
-  /// Find the file and line number of the source location of the end of the
-  /// function.
-  ///
-  ///
-  /// \param[out] source_file
-  /// The source file.
-  ///
-  /// \param[out] line_no
-  /// The line number.
-  void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no);
+  using SourceRange = Range;
+  /// Find the file and line number range of the function.
+  llvm::Expected> GetSourceInfo();
 
   /// Get the outgoing call edges from this function, sorted by their return
   /// PC addresses (in increasing order).

diff  --git a/lldb/source/Commands/CommandObjectSource.cpp 
b/lldb/source/Commands/CommandObjectSource.cpp
index 936783216f6ff..c205813565d52 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -784,14 +784,14 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
 
   if (sc.block == nullptr) {
 // Not an inlined function
-sc.function->GetStartLineSourceInfo(start_file, start_line);
-if (start_line == 0) {
-  result.AppendErrorWithFormat("Could not find line information for "
-   "start of function: \"%s\".\n",
-   source_info.function.GetCString());
+auto expected_info = sc.function->GetSourceInfo();
+if (!expected_info) {
+  result.AppendError(llvm::toString(expected_info.takeError()));
   return 0;
 }
-sc.function->GetEndLineSourceInfo(end_file, end_line);
+start_file = expected_info->first;
+start_line = expected_info->second.GetRangeBase();
+end_line = expected_info->second.GetRangeEnd();
   } else {
 // We have an inlined function
 start_file = source_info.line_entry.file_sp;

diff  --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp
index 11a43a9172ea6..c80f37ae68d9d 100644
--- a/lldb/source/Symbol/Function.cpp
+++ b/lldb/source/Symbol/F

[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Daniel Thornburgh via lldb-commits


@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)

mysterymath wrote:

This should still be "curses.h", since this is how curses will be referenced in 
the LLVM code that uses it. Instead, this should set `CMAKE_REQUIRED_INCLUDES` 
to the `CURSES_INCLUDE_DIRS` list.

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google edited 
https://github.com/llvm/llvm-project/pull/128245
___
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-02-21 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Rebased on the recent debugger stream changes & improved the test based on code 
review feedback. 

https://github.com/llvm/llvm-project/pull/121860
___
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 lldb-dap port listening mode to allow multiple connections. (PR #116392)

2025-02-21 Thread John Harrison via lldb-commits

https://github.com/ashgti updated 
https://github.com/llvm/llvm-project/pull/116392

>From 420153ffa051951332d1fca92af2a2bff7e9c52a Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Tue, 28 Jan 2025 12:39:38 -0800
Subject: [PATCH 1/6] [lldb-dap] Refactoring lldb-dap port listening mode to
 allow multiple connections.

This adjusts the lldb-dap listening mode to accept multiple clients.
Each client initializes a new instance of DAP and an associated 
`lldb::SBDebugger` instance.

The listening mode is configured with the `--connection` option and supports 
listening on a port or a unix socket on supported platforms.
---
 .../test/tools/lldb-dap/dap_server.py |  74 -
 .../test/tools/lldb-dap/lldbdap_testcase.py   |   6 +-
 lldb/test/API/tools/lldb-dap/server/Makefile  |   3 +
 .../tools/lldb-dap/server/TestDAP_server.py   |  77 +
 lldb/test/API/tools/lldb-dap/server/main.c|  10 +
 lldb/test/Shell/DAP/TestOptions.test  |   4 +-
 lldb/tools/lldb-dap/DAP.cpp   |  18 +-
 lldb/tools/lldb-dap/DAP.h |   6 +-
 lldb/tools/lldb-dap/DAPForward.h  |   2 +
 lldb/tools/lldb-dap/Options.td|  22 +-
 lldb/tools/lldb-dap/lldb-dap.cpp  | 283 +++---
 11 files changed, 358 insertions(+), 147 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/server/Makefile
 create mode 100644 lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
 create mode 100644 lldb/test/API/tools/lldb-dap/server/main.c

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 043d82e2e2c7d..eb247f6ae53c1 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -927,7 +927,7 @@ def request_setBreakpoints(self, file_path, line_array, 
data=None):
 "sourceModified": False,
 }
 if line_array is not None:
-args_dict["lines"] = "%s" % line_array
+args_dict["lines"] = line_array
 breakpoints = []
 for i, line in enumerate(line_array):
 breakpoint_data = None
@@ -1170,11 +1170,12 @@ def request_setInstructionBreakpoints(self, 
memory_reference=[]):
 }
 return self.send_recv(command_dict)
 
+
 class DebugAdaptorServer(DebugCommunication):
 def __init__(
 self,
 executable=None,
-port=None,
+connection=None,
 init_commands=[],
 log_file=None,
 env=None,
@@ -1187,21 +1188,62 @@ def __init__(
 
 if log_file:
 adaptor_env["LLDBDAP_LOG"] = log_file
+args = [executable]
+
+if connection is not None:
+args.append("--connection")
+args.append(connection)
+
 self.process = subprocess.Popen(
-[executable],
+args,
 stdin=subprocess.PIPE,
 stdout=subprocess.PIPE,
 stderr=subprocess.PIPE,
 env=adaptor_env,
 )
+
+if connection is not None:
+# If the process was also launched, parse the connection from the
+# resolved connection. For example, if the connection
+# `connection://localhost:0` was specified then the OS would pick a
+# random port for listening and lldb-dap would print the listening
+# port to stdout.
+if self.process is not None:
+# lldb-dap will print the listening address once the listener 
is
+# made to stdout. The listener is formatted like
+# `connection://host:port` or `unix-connection:///path`.
+expected_prefix = "Listening for: "
+out = self.process.stdout.readline().decode()
+if not out.startswith(expected_prefix):
+self.process.kill()
+raise ValueError(
+"lldb-dap failed to print listening address, expected 
'{}', got '{}'".format(
+expected_prefix, out
+)
+)
+
+# If the listener expanded into multiple addresses, use the 
first.
+connection = (
+
out.removeprefix(expected_prefix).rstrip("\r\n").split(",", 1)[0]
+)
+
+scheme, address = connection.split("://")
+if scheme == "unix-connect":  # unix-connect:///path
+s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+s.connect(address)
+elif scheme == "connection":  # connection://[host]:port
+host, port = address.rsplit(":", 1)
+# create_connection with try both ipv4 and ipv6.
+s = socket.create_connection((host.strip("[]"), int(port)))
+

[Lldb-commits] [lldb] [lldb] Document behavior in process launch help (PR #128215)

2025-02-21 Thread via lldb-commits

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

That's correct & useful.

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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)


Changes

This adds 'source' references to all stack frames. When opening a stack frame 
users will see the disassembly of the frame if the source is not available.

This works around the odd behavior of navigating frames without the VSCode 
disassembly view open, which causes 'step' to step in the first frame with a 
source instead of the active frame.

This fixes #128260

Old behavior:
https://github.com/user-attachments/assets/3f40582d-ac96-451a-a5ae-498a323bf30e

New behavior:
https://github.com/user-attachments/assets/3a3f9ac6-3e6c-4795-9bb2-1132b3916b6f



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


2 Files Affected:

- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+23-15) 
- (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+25-3) 


``diff
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 6ca4dfb4711a1..ee8fcef6f2503 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -45,7 +45,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -698,14 +697,22 @@ llvm::json::Value CreateSource(llvm::StringRef 
source_path) {
   return llvm::json::Value(std::move(source));
 }
 
-static std::optional CreateSource(lldb::SBFrame &frame) {
+static llvm::json::Value CreateSource(lldb::SBFrame &frame,
+  llvm::StringRef frame_name) {
   auto line_entry = frame.GetLineEntry();
   // A line entry of 0 indicates the line is compiler generated i.e. no source
   // file is associated with the frame.
   if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
-  return {};
+  llvm::json::Object source;
+  EmplaceSafeString(source, "name", frame_name);
+  source.try_emplace("sourceReference", MakeDAPFrameID(frame));
+  // If we don't have a filespec then we don't have the original source. Mark
+  // the source as deemphasized since users will only be able to view assembly
+  // for these frames.
+  EmplaceSafeString(source, "presentationHint", "deemphasize");
+  return std::move(source);
 }
 
 // "StackFrame": {
@@ -799,21 +806,22 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
 
   EmplaceSafeString(object, "name", frame_name);
 
-  auto source = CreateSource(frame);
-
-  if (source) {
-object.try_emplace("source", *source);
-auto line_entry = frame.GetLineEntry();
-auto line = line_entry.GetLine();
-if (line && line != LLDB_INVALID_LINE_NUMBER)
-  object.try_emplace("line", line);
-else
-  object.try_emplace("line", 0);
+  object.try_emplace("source", CreateSource(frame, frame_name));
+  auto line_entry = frame.GetLineEntry();
+  if (line_entry.IsValid() &&
+  (line_entry.GetLine() != 0 ||
+   line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) {
+object.try_emplace("line", line_entry.GetLine());
 auto column = line_entry.GetColumn();
 object.try_emplace("column", column);
   } else {
-object.try_emplace("line", 0);
-object.try_emplace("column", 0);
+lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() -
+   frame.GetSymbol().GetStartAddress().GetOffset();
+lldb::addr_t inst_line =
+inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 
2);
+// lines are base-1 indexed
+object.try_emplace("line", inst_line + 1);
+object.try_emplace("column", 1);
   }
 
   const auto pc = frame.GetPC();
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..1da8358eb5224 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -13,7 +13,9 @@
 #include "RunInTerminal.h"
 #include "Watchpoint.h"
 #include "lldb/API/SBDeclaration.h"
+#include "lldb/API/SBDefines.h"
 #include "lldb/API/SBEvent.h"
+#include "lldb/API/SBFile.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBMemoryRegionInfo.h"
@@ -38,9 +40,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -3488,6 +3487,29 @@ void request_source(DAP &dap, const llvm::json::Object 
&request) {
   llvm::json::Object response;
   FillResponse(request, response);
   llvm::json::Object body{{"content", ""}};
+
+  const auto *arguments = request.getObject("arguments");
+  const auto *source = arguments->getObject("source");
+  int64_t source_ref = GetUnsigned(
+  source, "sourceReference", GetUnsigned(arguments, "sourceReference", 0));
+
+  lldb::SBProcess process = dap.target.GetProcess();
+  // Upper 32 bits is the thread index ID
+  lldb::SBThread thread =
+  process.GetThreadByIndexID(GetLLDBThreadIndexID(source_ref));
+  // Lower 32 bits is the frame index
+  lldb::SBFrame frame = thread

[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

2025-02-21 Thread John Harrison via lldb-commits

https://github.com/ashgti commented:

I think this is a good idea to help simplify the lldb-dap.cpp file and improve 
code organization


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


[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

2025-02-21 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

2025-02-21 Thread John Harrison via lldb-commits


@@ -0,0 +1,45 @@
+//===-- Request.h 
-===//
+//
+// 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 LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+#define LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+
+namespace lldb_dap {
+struct DAP;
+
+class Request {
+public:
+  Request(DAP &dap) : dap(dap) {}
+  virtual ~Request() = default;
+
+  virtual void operator()(const llvm::json::Object &request) = 0;
+
+  static llvm::StringLiteral getName() { return "invalid"; };
+
+  enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
+
+  void SendProcessEvent(LaunchMethod launch_method);
+  void SetSourceMapFromArguments(const llvm::json::Object &arguments);
+
+protected:
+  DAP &dap;

ashgti wrote:

I've been thinking about the naming convention of the DAP object and I wonder 
if we should refer to this DAP as a session?

e.g. `DAP &session;`

That kind of represents what this is actually managing in the context of 
lldb-dap. The `DAP` object is the debug session and is coordinating the 
`dap.debugger` / `dap.target` with the various requests from the client.

I'm open to other ideas, but its something I've noticed while working on 
lldb-dap code. 

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


[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

2025-02-21 Thread John Harrison via lldb-commits


@@ -0,0 +1,45 @@
+//===-- Request.h 
-===//
+//
+// 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 LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+#define LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+
+namespace lldb_dap {
+struct DAP;
+
+class Request {
+public:
+  Request(DAP &dap) : dap(dap) {}
+  virtual ~Request() = default;
+
+  virtual void operator()(const llvm::json::Object &request) = 0;
+
+  static llvm::StringLiteral getName() { return "invalid"; };

ashgti wrote:

Should this be named `getCommand`? In the protocol, the requests are keyed by 
the command field, so it aligns more with the spec.

Should this assert to help ensure we catch missing?

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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-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 79261d4aab4f7a0f56f5ea32a5ac06241c5cd94a 
2f7885cfac5d5049c317de56109eed3bd2579acc --extensions cpp -- 
lldb/tools/lldb-dap/JSONUtils.cpp lldb/tools/lldb-dap/lldb-dap.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index 1da8358eb5..a6db74cd3f 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -3503,7 +3503,8 @@ void request_source(DAP &dap, const llvm::json::Object 
&request) {
 response["success"] = false;
 response["message"] = "source not found";
   } else {
-lldb::SBInstructionList insts = 
frame.GetSymbol().GetInstructions(dap.target);
+lldb::SBInstructionList insts =
+frame.GetSymbol().GetInstructions(dap.target);
 lldb::SBStream stream;
 insts.GetDescription(stream);
 body["content"] = stream.GetData();

``




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


[Lldb-commits] [lldb] [lldb-dap] Add 'source' references to stack frames without source files. (PR #128268)

2025-02-21 Thread John Harrison via lldb-commits

https://github.com/ashgti created 
https://github.com/llvm/llvm-project/pull/128268

This adds 'source' references to all stack frames. When opening a stack frame 
users will see the disassembly of the frame if the source is not available.

This works around the odd behavior of navigating frames without the VSCode 
disassembly view open, which causes 'step' to step in the first frame with a 
source instead of the active frame.

This fixes #128260

Old behavior:
https://github.com/user-attachments/assets/3f40582d-ac96-451a-a5ae-498a323bf30e

New behavior:
https://github.com/user-attachments/assets/3a3f9ac6-3e6c-4795-9bb2-1132b3916b6f



>From 2f7885cfac5d5049c317de56109eed3bd2579acc Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 21 Feb 2025 17:45:17 -0800
Subject: [PATCH] [lldb-dap] Add 'source' references to stack frames without
 source files.

This adds 'source' references to all stack frames. When opening a stack frame 
users will see the disassembly of the frame if the source is not available.

This works around the odd behavior of navigating frames without the VSCode 
disassembly view open, which causes 'step' to step in the first frame with a 
source instead of the active frame.
---
 lldb/tools/lldb-dap/JSONUtils.cpp | 38 +++
 lldb/tools/lldb-dap/lldb-dap.cpp  | 28 ---
 2 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 6ca4dfb4711a1..ee8fcef6f2503 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -45,7 +45,6 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -698,14 +697,22 @@ llvm::json::Value CreateSource(llvm::StringRef 
source_path) {
   return llvm::json::Value(std::move(source));
 }
 
-static std::optional CreateSource(lldb::SBFrame &frame) {
+static llvm::json::Value CreateSource(lldb::SBFrame &frame,
+  llvm::StringRef frame_name) {
   auto line_entry = frame.GetLineEntry();
   // A line entry of 0 indicates the line is compiler generated i.e. no source
   // file is associated with the frame.
   if (line_entry.GetFileSpec().IsValid() && line_entry.GetLine() != 0)
 return CreateSource(line_entry);
 
-  return {};
+  llvm::json::Object source;
+  EmplaceSafeString(source, "name", frame_name);
+  source.try_emplace("sourceReference", MakeDAPFrameID(frame));
+  // If we don't have a filespec then we don't have the original source. Mark
+  // the source as deemphasized since users will only be able to view assembly
+  // for these frames.
+  EmplaceSafeString(source, "presentationHint", "deemphasize");
+  return std::move(source);
 }
 
 // "StackFrame": {
@@ -799,21 +806,22 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame,
 
   EmplaceSafeString(object, "name", frame_name);
 
-  auto source = CreateSource(frame);
-
-  if (source) {
-object.try_emplace("source", *source);
-auto line_entry = frame.GetLineEntry();
-auto line = line_entry.GetLine();
-if (line && line != LLDB_INVALID_LINE_NUMBER)
-  object.try_emplace("line", line);
-else
-  object.try_emplace("line", 0);
+  object.try_emplace("source", CreateSource(frame, frame_name));
+  auto line_entry = frame.GetLineEntry();
+  if (line_entry.IsValid() &&
+  (line_entry.GetLine() != 0 ||
+   line_entry.GetLine() != LLDB_INVALID_LINE_NUMBER)) {
+object.try_emplace("line", line_entry.GetLine());
 auto column = line_entry.GetColumn();
 object.try_emplace("column", column);
   } else {
-object.try_emplace("line", 0);
-object.try_emplace("column", 0);
+lldb::addr_t inst_offset = frame.GetPCAddress().GetOffset() -
+   frame.GetSymbol().GetStartAddress().GetOffset();
+lldb::addr_t inst_line =
+inst_offset / (frame.GetThread().GetProcess().GetAddressByteSize() / 
2);
+// lines are base-1 indexed
+object.try_emplace("line", inst_line + 1);
+object.try_emplace("column", 1);
   }
 
   const auto pc = frame.GetPC();
diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index e323990d8b6ed..1da8358eb5224 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -13,7 +13,9 @@
 #include "RunInTerminal.h"
 #include "Watchpoint.h"
 #include "lldb/API/SBDeclaration.h"
+#include "lldb/API/SBDefines.h"
 #include "lldb/API/SBEvent.h"
+#include "lldb/API/SBFile.h"
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBListener.h"
 #include "lldb/API/SBMemoryRegionInfo.h"
@@ -38,9 +40,6 @@
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -3488,6 +3487,29 @@ void request_source(DAP &dap, const llvm::json::Object 
&request) {
   llvm::json::Object response;
   FillResponse(request, response);
   ll

[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

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


@@ -0,0 +1,45 @@
+//===-- Request.h 
-===//
+//
+// 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 LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+#define LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+
+namespace lldb_dap {
+struct DAP;
+
+class Request {
+public:
+  Request(DAP &dap) : dap(dap) {}
+  virtual ~Request() = default;
+
+  virtual void operator()(const llvm::json::Object &request) = 0;
+
+  static llvm::StringLiteral getName() { return "invalid"; };
+
+  enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
+
+  void SendProcessEvent(LaunchMethod launch_method);
+  void SetSourceMapFromArguments(const llvm::json::Object &arguments);

JDevlieghere wrote:

They are indeed shared, but not by many request handlers. I don't think this is 
a good place for them, but I'm trtying to minimize the changes. 

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


[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

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


@@ -0,0 +1,45 @@
+//===-- Request.h 
-===//
+//
+// 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 LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+#define LLDB_TOOLS_LLDB_DAP_REQUEST_REQUEST_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+
+namespace lldb_dap {
+struct DAP;
+
+class Request {
+public:
+  Request(DAP &dap) : dap(dap) {}
+  virtual ~Request() = default;
+
+  virtual void operator()(const llvm::json::Object &request) = 0;
+
+  static llvm::StringLiteral getName() { return "invalid"; };
+
+  enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
+
+  void SendProcessEvent(LaunchMethod launch_method);
+  void SetSourceMapFromArguments(const llvm::json::Object &arguments);
+
+protected:
+  DAP &dap;

JDevlieghere wrote:

Session sounds good. `Context` would probably be another good option?

https://github.com/llvm/llvm-project/pull/128262
___
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 lldb-dap port listening mode to allow multiple connections. (PR #116392)

2025-02-21 Thread LLVM Continuous Integration via lldb-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-windows` 
running on `linaro-armv8-windows-msvc-05` while building `lldb` at step 6 
"test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/141/builds/6506


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)

```



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


[Lldb-commits] [lldb] [lldb-da] skip TestDAP_server on windows to unblock CI. (PR #128278)

2025-02-21 Thread John Harrison via lldb-commits

https://github.com/ashgti created 
https://github.com/llvm/llvm-project/pull/128278

This should fix the tests running on windows.

https://lab.llvm.org/buildbot/#/builders/141/builds/6506 is the failure, the 
error message does not clearly indicate why the connection failed.

>From 0598331ccb52807020c2c1fc2f1ada1f02fe0952 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 21 Feb 2025 19:42:10 -0800
Subject: [PATCH] [lldb-da] skip TestDAP_server on windows to unblock CI.

---
 lldb/test/API/tools/lldb-dap/server/TestDAP_server.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py 
b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
index e78fdceed1bbd..1f562e989533a 100644
--- a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
+++ b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
@@ -48,6 +48,7 @@ def run_debug_session(self, connection, name):
 self.assertEqual(output, f"Hello {name}!\r\n")
 self.dap_server.request_disconnect()
 
+@skipIfWindows
 def test_server_port(self):
 """
 Test launching a binary with a lldb-dap in server mode on a specific 
port.

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


[Lldb-commits] [lldb] [lldb-da] skip TestDAP_server on windows to unblock CI. (PR #128278)

2025-02-21 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-da] skip TestDAP_server on windows to unblock CI. (PR #128278)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)


Changes

This should fix the tests running on windows.

https://lab.llvm.org/buildbot/#/builders/141/builds/6506 is the failure, the 
error message does not clearly indicate why the connection failed.

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


1 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/server/TestDAP_server.py (+1) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py 
b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
index e78fdceed1bbd..1f562e989533a 100644
--- a/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
+++ b/lldb/test/API/tools/lldb-dap/server/TestDAP_server.py
@@ -48,6 +48,7 @@ def run_debug_session(self, connection, name):
 self.assertEqual(output, f"Hello {name}!\r\n")
 self.dap_server.request_disconnect()
 
+@skipIfWindows
 def test_server_port(self):
 """
 Test launching a binary with a lldb-dap in server mode on a specific 
port.

``




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


[Lldb-commits] [lldb] [lldb-da] skip TestDAP_server on windows to unblock CI. (PR #128278)

2025-02-21 Thread John Harrison via lldb-commits

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


[Lldb-commits] [lldb] [lldb-dap] skip TestDAP_server on windows to unblock CI. (PR #128278)

2025-02-21 Thread John Harrison via lldb-commits

https://github.com/ashgti edited 
https://github.com/llvm/llvm-project/pull/128278
___
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 lldb-dap port listening mode to allow multiple connections. (PR #116392)

2025-02-21 Thread John Harrison via lldb-commits

ashgti wrote:

https://github.com/llvm/llvm-project/pull/128278 Should mark the test as 
skipped on windows to unblock the CI.

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


[Lldb-commits] [lldb] [lldb] Document behavior in process launch help (PR #128215)

2025-02-21 Thread Med Ismail Bennani via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google created 
https://github.com/llvm/llvm-project/pull/128245

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES after 
it is found through `find_package`. However, by introducing a check for 
TINFO_LIBRARIES, we break systems which pass all of CURSES_INCLUDE_DIRS, 
CURSES_LIBRARIES, and PANEL_LIBRARIES individually without passing 
TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES at all.

This commit preemptively attempts to fix issues encountered on systems that 
manually pass CURSES_LIBRARIES which already contain the necessary terminfo 
symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd to begin 
with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368

>From ff5884d252b8359bcec41024f9dc9e3c7bbe3fc2 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..315810c87b67b 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if (NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,7 +34,9 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jordan R AW (ajordanr-google)


Changes

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES after 
it is found through `find_package`. However, by introducing a check for 
TINFO_LIBRARIES, we break systems which pass all of CURSES_INCLUDE_DIRS, 
CURSES_LIBRARIES, and PANEL_LIBRARIES individually without passing 
TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES at all.

This commit preemptively attempts to fix issues encountered on systems that 
manually pass CURSES_LIBRARIES which already contain the necessary terminfo 
symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd to begin 
with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368

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


1 Files Affected:

- (modified) lldb/cmake/modules/FindCursesAndPanel.cmake (+15-4) 


``diff
diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..315810c87b67b 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if (NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,7 +34,9 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)

``




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


[Lldb-commits] [lldb] [lldb][cmake] Use STATUS instead of explicit '--' in message logging (PR #128196)

2025-02-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (foxtran)


Changes

Currently, configuring lldb with cmake with separated stdout and stderr gives 
some unnecessary output in stderr which happens since message statement is used 
without `[mode]` (See https://cmake.org/cmake/help/v3.31/command/message.html). 
This patch adds mode `STATUS` instead of explicit `--` at the beginning of 
messages. 

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


1 Files Affected:

- (modified) lldb/source/API/CMakeLists.txt (+4-4) 


``diff
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 147b30f3b0026..47b60ef0895a3 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -206,23 +206,23 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
 # If we're not exporting all symbols, we'll want to explicitly set
 # the exported symbols here.  This prevents 'log enable --stack ...'
 # from working on some systems but limits the liblldb size.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb 
namespace")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
 # Don't use an explicit export. Instead, tell the linker to export all 
symbols.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
   else ()
-MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the 
exports "
+MESSAGE(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
 " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
 MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
   endif()
 elseif (LLDB_EXPORT_ALL_SYMBOLS)
-  MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+  MESSAGE(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 
   # Pull out the various lldb libraries linked into liblldb, these will be used
   # when looking for symbols to extract. We ignore most plugin libraries here,

``




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


[Lldb-commits] [lldb] [lldb] Add terminfo dependency for ncurses support (PR #126810)

2025-02-21 Thread Jordan R AW via lldb-commits

ajordanr-google wrote:

Turns out `set(CURSES_LIBRARIES "${CURSES_LIBRARIES } ${TINFO_LIBRARIES}")` 
definitely does NOT work. I think there's some string quoting which gives:

```
ninja -v -j96 -l999 distribution libclang.so


   
ninja: error: '/usr/lib/libform.so /usr/lib/libtinfo.so', needed by 
'lib64/liblldb.so.20.0.0git', missing and no known rule to make it
 * ERROR: sys-devel/llvm-::chromiumos failed (compile phase):
 ```
Both `libform.so` and `libtinfo.so` exist at those locations, but obviously the 
joint path with a space does not.

Using `list(APPEND *_LIBRARIES ${...})` is pretty common elsewhere throughout 
llvm-project, so I think this is normal. (e.g. 
mlir/cmake/modules/FindLevelZero.cmake, 
libunwind/cmake/Modules/HandleLibunwindFlags.cmake, etc.). Also `LINK_LIBS` in 
`add_lldb_library` is a list, so it should work out.

Everything else I think have working in a new patch. Will upload now.

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits


@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)

ajordanr-google wrote:

Both options work, but indeed, I chose `check_symbol_exists` as the cmake 
documentation prefers it.

I'm fine with using `CMAKE_REQUIRED_INCLUDES` instead; I think that makes sense.

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From ff5884d252b8359bcec41024f9dc9e3c7bbe3fc2 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH 1/4] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..315810c87b67b 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if (NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,7 +34,9 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)

>From b25240267657f4d5c66125eac6fe74856b73b15a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Fri, 21 Feb 2025 23:39:01 +
Subject: [PATCH 2/4] fixup! [lldb] Fix manual CURSES_LIBRARIES tinfo finding

---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 315810c87b67b..9033813009977 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,12 +6,13 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
 if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
@@ -34,7 +35,7 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
 "${CURSES_LIBRARIES}"
 CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)

>From 0f16f66afc4e822824e0bf19d889ff3415701df1 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Wh

[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From ff5884d252b8359bcec41024f9dc9e3c7bbe3fc2 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH 1/3] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..315810c87b67b 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if (NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,7 +34,9 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)

>From b25240267657f4d5c66125eac6fe74856b73b15a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Fri, 21 Feb 2025 23:39:01 +
Subject: [PATCH 2/3] fixup! [lldb] Fix manual CURSES_LIBRARIES tinfo finding

---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 315810c87b67b..9033813009977 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,12 +6,13 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
 if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
@@ -34,7 +35,7 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
 "${CURSES_LIBRARIES}"
 CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)

>From 0f16f66afc4e822824e0bf19d889ff3415701df1 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Wh

[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

ajordanr-google wrote:

Rebasing to fix merge conflict...

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From f0d81ca9124f0e4b0a60f2752c56c4166052813a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..8628059f91ba1 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,25 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
   check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,8 +35,10 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
-if (NOT CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)
   list(APPEND CURSES_LIBRARIES "${TINFO_LIBRARIES}")

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From f0d81ca9124f0e4b0a60f2752c56c4166052813a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..8628059f91ba1 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,25 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
   check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,8 +35,10 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
-if (NOT CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)
   list(APPEND CURSES_LIBRARIES "${TINFO_LIBRARIES}")

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From f0d81ca9124f0e4b0a60f2752c56c4166052813a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..8628059f91ba1 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,25 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
   check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,8 +35,10 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
-if (NOT CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if(NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)
   list(APPEND CURSES_LIBRARIES "${TINFO_LIBRARIES}")

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


[Lldb-commits] [lldb] 7c1f679 - [lldb][cmake] Use STATUS instead of explicit '--' in message logging (#128196)

2025-02-21 Thread via lldb-commits

Author: foxtran
Date: 2025-02-21T12:12:06-06:00
New Revision: 7c1f679c387a68defbc2b240cb58eb9152252c25

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

LOG: [lldb][cmake] Use STATUS instead of explicit '--' in message logging 
(#128196)

Currently, configuring lldb with cmake with separated stdout and stderr
gives some unnecessary output in stderr which happens since message
statement is used without `[mode]` (See
https://cmake.org/cmake/help/v3.31/command/message.html). This patch
adds mode `STATUS` instead of explicit `--` at the beginning of
messages.

Added: 


Modified: 
lldb/source/API/CMakeLists.txt

Removed: 




diff  --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index 147b30f3b0026..9d6a7d8850286 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -206,23 +206,23 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
 # If we're not exporting all symbols, we'll want to explicitly set
 # the exported symbols here.  This prevents 'log enable --stack ...'
 # from working on some systems but limits the liblldb size.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb 
namespace")
+message(STATUS "Symbols (liblldb): exporting all symbols from the lldb 
namespace")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
   elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
 # Don't use an explicit export. Instead, tell the linker to export all 
symbols.
-MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
-MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
+message(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+message(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb 
${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
   else ()
-MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the 
exports "
+message(STATUS "Symbols (liblldb): exporting all symbols specified in the 
exports "
 " file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
-MESSAGE(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
+message(WARNING "Private LLDB symbols frequently change and no API 
stability is guaranteed. "
 "Only the SB API is guaranteed to be stable.")
 add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
   endif()
 elseif (LLDB_EXPORT_ALL_SYMBOLS)
-  MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
+  message(STATUS "Symbols (liblldb): exporting all symbols from the lldb and 
lldb_private namespaces")
 
   # Pull out the various lldb libraries linked into liblldb, these will be used
   # when looking for symbols to extract. We ignore most plugin libraries here,



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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

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


@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)

JDevlieghere wrote:

Can we avoid the curses header altogether by using 
`check_library_exists(curses, tinfo_get, ${CURSES_LIBRARIES} 
HAVE_LIBRARY_TINFO)`? As a counter-argument, [the 
documentation](https://cmake.org/cmake/help/latest/module/CheckLibraryExists.html)
 encourages preferring `check_symbol_exists`. 

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


[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits

https://github.com/ajordanr-google updated 
https://github.com/llvm/llvm-project/pull/128245

>From ff5884d252b8359bcec41024f9dc9e3c7bbe3fc2 Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Wed, 19 Feb 2025 19:24:40 +
Subject: [PATCH 1/2] [lldb] Fix manual CURSES_LIBRARIES tinfo finding

At present, we automatically detect terminfo symbols in CURSES_LIBRARIES
after it is found through `find_package`. However, by introducing a
check for TINFO_LIBRARIES, we break systems which pass all of
CURSES_INCLUDE_DIRS, CURSES_LIBRARIES, and PANEL_LIBRARIES individually
without passing TINFO_LIBRARIES. We'd rather not expose TINFO_LIBRARIES
at all.

This commit preemptively attempts to fix issues encountered
on systems that manually pass CURSES_LIBRARIES which already
contain the necessary terminfo symbols (e.g. 'acs_map').

Additionally, let's not make CURSES_LIBRARIES a list. That was odd
to begin with.

See this breakage in Google Fuchsia:
https://issues.fuchsia.dev/397455029

References Issue #101368
---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 75ebaa35d7ea1..315810c87b67b 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
 endfunction()
 
-if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND TINFO_LIBRARIES AND 
PANEL_LIBRARIES)
+if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
+  if(NOT HAS_TERMINFO_SYMBOLS)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
+if (NOT CURSES_HAS_TINFO)
+  message(WARNING "CURSES_LIBRARIES was provided manually but is missing 
terminfo symbols")
+endif()
+mark_as_advanced(CURSES_HAS_TINFO)
+  endif()
   set(CURSESANDPANEL_FOUND TRUE)
 else()
   find_package(Curses QUIET)
@@ -25,7 +34,9 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_LIBRARIES}" CURSES_HAS_TINFO)
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+"${CURSES_LIBRARIES}"
+CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)
   message(STATUS "curses library missing terminfo symbols, looking for 
tinfo separately")
   find_library(TINFO_LIBRARIES NAMES tinfo DOC "The curses tinfo library" 
QUIET)

>From b25240267657f4d5c66125eac6fe74856b73b15a Mon Sep 17 00:00:00 2001
From: Jordan R Abrahams-Whitehead 
Date: Fri, 21 Feb 2025 23:39:01 +
Subject: [PATCH 2/2] fixup! [lldb] Fix manual CURSES_LIBRARIES tinfo finding

---
 lldb/cmake/modules/FindCursesAndPanel.cmake | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/cmake/modules/FindCursesAndPanel.cmake 
b/lldb/cmake/modules/FindCursesAndPanel.cmake
index 315810c87b67b..9033813009977 100644
--- a/lldb/cmake/modules/FindCursesAndPanel.cmake
+++ b/lldb/cmake/modules/FindCursesAndPanel.cmake
@@ -6,12 +6,13 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_INCLUDE_DIRS CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
+  set(CMAKE_REQUIRED_INCLUDES "${CURSES_INCLUDE_DIRS}")
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
 endfunction()
 
 if(CURSES_INCLUDE_DIRS AND CURSES_LIBRARIES AND PANEL_LIBRARIES)
@@ -34,7 +35,7 @@ else()
 # Sometimes the curses libraries define their own terminfo symbols,
 # other times they're extern and are defined by a separate terminfo 
library.
 # Auto-detect which.
-lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}/curses.h"
+lldb_check_curses_tinfo("${CURSES_INCLUDE_DIRS}"
 "${CURSES_LIBRARIES}"
 CURSES_HAS_TINFO)
 if (NOT CURSES_HAS_TINFO)

___
lldb-commits mailing list
lldb-commits@lists.llvm.

[Lldb-commits] [lldb] [lldb] Fix manual CURSES_LIBRARIES tinfo finding (PR #128245)

2025-02-21 Thread Jordan R AW via lldb-commits


@@ -6,15 +6,24 @@
 
 include(CMakePushCheckState)
 
-function(lldb_check_curses_tinfo CURSES_LIBRARIES CURSES_HAS_TINFO)
+function(lldb_check_curses_tinfo CURSES_HEADER CURSES_LIBRARIES 
CURSES_HAS_TINFO)
   cmake_reset_check_state()
   set(CMAKE_REQUIRED_LIBRARIES "${CURSES_LIBRARIES}")
   # acs_map is one of many symbols that are part of tinfo but could
   # be bundled in curses.
-  check_symbol_exists(acs_map "curses.h" CURSES_HAS_TINFO)
+  check_symbol_exists(acs_map "${CURSES_HEADER}" CURSES_HAS_TINFO)

ajordanr-google wrote:

Patched using @mystermath's suggestion, tested in 3 different configurations:

1. With acs_map defined in libcurses.so
1. with acs_map defined in libtinfo.so
1. With -DCURSES_LIBRARIES specified, and acs_map defined in libcurses.so

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


[Lldb-commits] [lldb] [lldb-dap] Move requests into their own object/file (PR #128262)

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

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

None

>From 03bf2fafb0b8b7e1dc08f6510802b73b5fe4dde7 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Fri, 21 Feb 2025 19:20:36 -0600
Subject: [PATCH] [lldb-dap] Move requests into their own object/file

---
 lldb/tools/lldb-dap/CMakeLists.txt|   5 +
 lldb/tools/lldb-dap/DAP.h |   8 +
 lldb/tools/lldb-dap/Request/AttachRequest.cpp | 211 ++
 lldb/tools/lldb-dap/Request/Request.cpp   |  92 
 lldb/tools/lldb-dap/Request/Request.h |  45 
 lldb/tools/lldb-dap/lldb-dap.cpp  |   4 +
 6 files changed, 365 insertions(+)
 create mode 100644 lldb/tools/lldb-dap/Request/AttachRequest.cpp
 create mode 100644 lldb/tools/lldb-dap/Request/Request.cpp
 create mode 100644 lldb/tools/lldb-dap/Request/Request.h

diff --git a/lldb/tools/lldb-dap/CMakeLists.txt 
b/lldb/tools/lldb-dap/CMakeLists.txt
index 43fc18873feb3..e97f7ecdbd31b 100644
--- a/lldb/tools/lldb-dap/CMakeLists.txt
+++ b/lldb/tools/lldb-dap/CMakeLists.txt
@@ -36,6 +36,9 @@ add_lldb_tool(lldb-dap
   SourceBreakpoint.cpp
   Watchpoint.cpp
 
+  Request/Request.cpp
+  Request/AttachRequest.cpp
+
   LINK_LIBS
 liblldb
 lldbHost
@@ -46,6 +49,8 @@ add_lldb_tool(lldb-dap
 Support
   )
 
+target_include_directories(lldb-dap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+
 if(LLDB_DAP_WELCOME_MESSAGE)
   target_compile_definitions(lldb-dap
 PRIVATE
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index b23be68ea002f..33507061e0750 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -16,6 +16,7 @@
 #include "InstructionBreakpoint.h"
 #include "OutputRedirector.h"
 #include "ProgressEvent.h"
+#include "Request/Request.h"
 #include "SourceBreakpoint.h"
 #include "lldb/API/SBBroadcaster.h"
 #include "lldb/API/SBCommandInterpreter.h"
@@ -37,6 +38,7 @@
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Threading.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -184,6 +186,7 @@ struct DAP {
   lldb::pid_t restarting_process_id;
   bool configuration_done_sent;
   std::map> request_handlers;
+  llvm::StringMap> new_request_handlers;
   bool waiting_for_run_in_terminal;
   ProgressEventReporter progress_event_reporter;
   // Keep track of the last stop thread index IDs as threads won't go away
@@ -330,6 +333,11 @@ struct DAP {
   /// IDE.
   void RegisterRequestCallback(std::string request, RequestCallback callback);
 
+  /// Registers a request handler.
+  template  void RegisterRequest() {
+new_request_handlers[Request::getName()] = 
std::make_unique(*this);
+  }
+
   /// Debuggee will continue from stopped state.
   void WillContinue() { variables.Clear(); }
 
diff --git a/lldb/tools/lldb-dap/Request/AttachRequest.cpp 
b/lldb/tools/lldb-dap/Request/AttachRequest.cpp
new file mode 100644
index 0..f1b3bfc878427
--- /dev/null
+++ b/lldb/tools/lldb-dap/Request/AttachRequest.cpp
@@ -0,0 +1,211 @@
+//===-- AttachRequest.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 "DAP.h"
+#include "JSONUtils.h"
+#include "Request.h"
+#include "lldb/API/SBListener.h"
+#include "llvm/Support/FileSystem.h"
+
+namespace lldb_dap {
+/// Prints a welcome message on the editor if the preprocessor variable
+/// LLDB_DAP_WELCOME_MESSAGE is defined.
+static void PrintWelcomeMessage(DAP &dap) {
+#ifdef LLDB_DAP_WELCOME_MESSAGE
+  dap.SendOutput(OutputType::Console, LLDB_DAP_WELCOME_MESSAGE);
+#endif
+}
+
+// "AttachRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Attach request; value of command field is 'attach'.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "attach" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/AttachRequestArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "AttachRequestArguments": {
+//   "type": "object",
+//   "description": "Arguments for 'attach' request.\nThe attach request has no
+//   standardized attributes."
+// },
+// "AttachResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to 'attach' request. This is just an
+// acknowledgement, so no body field is required."
+//   }]
+// }
+
+void AttachRequest::operator()(const llvm::json::Object &request) {
+  dap.is_attach = true;
+  dap.last_launch_or_attach_request = request;
+  llvm::json::Object response;
+  lldb::SBError error;
+  FillResponse(request, response);
+  lldb::SBAtta