[Lldb-commits] [clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

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

Michael137 wrote:

> As I understand it, minimal import is used in LLDB for performance reasons, 
> so we don't waste time parsing and loading AST elements that we don't need. 
> It sounds like a fine idea in general. Implicit imports of external sources 
> in Clang, however, turn import process into a minefield, where you have no 
> idea if a "pure" operation can cause a major change the target AST. 
> "Complete" types are really incomplete, and there is no single point at which 
> they are all guaranteed to be finalized.

Yup, agreed. Our idea is summarized in 
https://discourse.llvm.org/t/rfc-lldb-more-reliable-completion-of-record-types/77442.
 Basically the goal is to guarantee that a call to `getDefinition`, *will* 
fetch the definition. This is something that Clang already does, but we just 
never implement (via `CompleteRedeclChain`). You're right that the "minimal 
import" mode was implemented for perf. reasons. Though we should probably 
revisit this. I think we can make LLDB use non-minimal import for record types 
while keeping the number of transitive imports contained. It would still 
require changes to the importer to be smarter about what we import, but we 
wouldn't have these "complete but incomplete" types floating around.

> Perhaps this approach was taken to minimize impact of external sources on the 
> rest of Clang, to avoid introducing a concept of "not-fully-loaded-AST" 
> everywhere. Understandable, but we have these issues now.

Possibly, I'm not entirely sure of the history here either. But afaiu external 
sources are a thing because of Clang modules, we re-used it for DWARF later on 
(or at least that's my impression). There's quite a lot of difference in the 
way that LLDB makes use of this API, which is where some of the tension comes 
from.

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


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

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


@@ -274,8 +274,9 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 
   builder.setEngineKind(llvm::EngineKind::JIT)
   .setErrorStr(&error_string)
-  .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
-  : llvm::Reloc::Static)
+  .setRelocationModel((triple.isOSBinFormatMachO() || triple.isRISCV64())

Michael137 wrote:

Should we add a comment here for RISCV?

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


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

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


@@ -1441,6 +1443,26 @@ lldb_private::Status 
ClangExpressionParser::DoPrepareForExecution(
 custom_passes.EarlyPasses->run(*llvm_module_up);
   }
 
+  std::unique_ptr arch_passes(nullptr);
+  if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) {
+Architecture *arch = target_sp->GetArchitecturePlugin();
+if (arch) {

Michael137 wrote:

no need for the braces here

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


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

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


@@ -1011,6 +1011,135 @@ void RuntimeDyldELF::resolveBPFRelocation(const 
SectionEntry &Section,
   }
 }
 
+static void applyUTypeImmRISCV(uint8_t *InstrAddr, uint32_t Imm) {

Michael137 wrote:

I'm not sure if this was discussed elsewhere in the thread, but we should 
probably split these out into a separate PR

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


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

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


@@ -0,0 +1,96 @@
+"""
+Test RISC-V expressions evaluation.
+"""

Michael137 wrote:

What happens if you run the test-suite on RISC-V? I do think it's good to 
document what doesn't work, but the successful cases should already be tested 
elsewhere. So should we just leave the unsupported function calls to test the 
Arch Pass failures?

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


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

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


@@ -1441,6 +1443,26 @@ lldb_private::Status 
ClangExpressionParser::DoPrepareForExecution(
 custom_passes.EarlyPasses->run(*llvm_module_up);
   }
 
+  std::unique_ptr arch_passes(nullptr);

Michael137 wrote:

```suggestion
  std::unique_ptr arch_passes;
```

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


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

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,96 @@
+"""
+Test RISC-V expressions evaluation.
+"""

DavidSpickett wrote:

Yeah I'm not sure if this is known failures or known passes.

Adding skipif riscv or xfail to the known failures seems like the better 
option. Tip for that, the lldb tests call xfail "expectedfailure".

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


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

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,217 @@
+//===--- DirectCallReplacementPass.cpp - RISC-V specific pass 
-===//
+//
+// 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 "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#include "Plugins/Architecture/RISCV/DirectCallReplacementPass.h"
+
+#include "lldb/Core/Architecture.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+#include 
+
+using namespace llvm;
+using namespace lldb_private;
+
+namespace {

DavidSpickett wrote:

Prefer `static` functions over anonymous namespaces - 
https://llvm.org/docs/CodingStandards.html#anonymous-namespaces

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


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

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,62 @@
+//===--- DirectCallReplacementPass.h - RISC-V specific pass 
---===//
+//
+// 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_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+#define LLDB_SOURCE_PLUGINS_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+
+#include "lldb/lldb-types.h"
+
+#include "llvm/IR/Instructions.h"
+#include "llvm/Pass.h"
+
+namespace lldb_private {
+
+class ExecutionContext;
+
+// During the lldb expression execution lldb wraps a user expression, jittes
+// fabricated code and then puts it into the stack memory. Thus, if user tried

DavidSpickett wrote:

Are you sure it's using stack memory? This would require the stack to be 
executable.

Generally we find a way to memory map some chunk and use that instead.

Maybe you're referring to jumps from that JIT'd code back to code in the 
binary, that those jumps may be too large?

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


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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

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

2024-09-10 Thread via lldb-commits

dlav-sc wrote:

I've added float, doubles and pointers support in lldb expressions.

Currently, just several python API tests that check expressions with static 
class members (BTW, static methods work) and complex expressions like `expr 
struct Test { int a; int b; }; auto t = Test{3, 4}; t;` fail.

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


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

2024-09-10 Thread via lldb-commits


@@ -0,0 +1,96 @@
+"""
+Test RISC-V expressions evaluation.
+"""

dlav-sc wrote:

If I'm not mistaken, I've supported all types that frontend can generate 
(https://github.com/llvm/llvm-project/pull/99336#issuecomment-2340245433), so 
these tests are no longer relevant and can be removed at all.

However, maybe there are some types I forgot about. Please, let me know if you 
have any suspicious.

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


[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX created 
https://github.com/llvm/llvm-project/pull/108000

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. #101657
The complete changes for porting are present in this draft PR:
#102601

Added Ptrace extensions for AIX. 
- Commit 1: Taken Linux version for reference.
- Commit 2: Modified the extensions for AIX.

Review Request: @DavidSpickett

>From 426874ab276182858b75e9bbf8704dab1742757c Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Tue, 10 Sep 2024 04:38:32 -0500
Subject: [PATCH 1/2] Ptrace code base for AIX

---
 lldb/include/lldb/Host/aix/Ptrace.h | 60 +
 1 file changed, 60 insertions(+)
 create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h

diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
new file mode 100644
index 00..aabd3fd4fc5573
--- /dev/null
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -0,0 +1,60 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_linux_Ptrace_h_
+#define liblldb_Host_linux_Ptrace_h_
+
+#include 
+
+#ifndef __GLIBC__
+typedef int __ptrace_request;
+#endif
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS 12
+#endif
+#ifndef PTRACE_SETREGS
+#define PTRACE_SETREGS 13
+#endif
+#ifndef PTRACE_GETFPREGS
+#define PTRACE_GETFPREGS 14
+#endif
+#ifndef PTRACE_SETFPREGS
+#define PTRACE_SETFPREGS 15
+#endif
+#ifndef PTRACE_GETREGSET
+#define PTRACE_GETREGSET 0x4204
+#endif
+#ifndef PTRACE_SETREGSET
+#define PTRACE_SETREGSET 0x4205
+#endif
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+#ifndef PTRACE_ARCH_PRCTL
+#define PTRACE_ARCH_PRCTL 30
+#endif
+#ifndef ARCH_GET_FS
+#define ARCH_SET_GS 0x1001
+#define ARCH_SET_FS 0x1002
+#define ARCH_GET_FS 0x1003
+#define ARCH_GET_GS 0x1004
+#endif
+#ifndef PTRACE_PEEKMTETAGS
+#define PTRACE_PEEKMTETAGS 33
+#endif
+#ifndef PTRACE_POKEMTETAGS
+#define PTRACE_POKEMTETAGS 34
+#endif
+
+#endif // liblldb_Host_linux_Ptrace_h_

>From 61bdaf75ddbd5940af5f23363311ffcacb0540d7 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Tue, 10 Sep 2024 05:43:37 -0500
Subject: [PATCH 2/2] Modified specific to AIX

---
 lldb/include/lldb/Host/aix/Ptrace.h | 38 +
 1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
index aabd3fd4fc5573..5d5ae82c9dab7d 100644
--- a/lldb/include/lldb/Host/aix/Ptrace.h
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -8,29 +8,25 @@
 
 // This file defines ptrace functions & structures
 
-#ifndef liblldb_Host_linux_Ptrace_h_
-#define liblldb_Host_linux_Ptrace_h_
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
 
 #include 
 
-#ifndef __GLIBC__
-typedef int __ptrace_request;
-#endif
-
 #define DEBUG_PTRACE_MAXBYTES 20
 
 // Support ptrace extensions even when compiled without required kernel support
 #ifndef PTRACE_GETREGS
-#define PTRACE_GETREGS 12
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)
 #endif
 #ifndef PTRACE_SETREGS
-#define PTRACE_SETREGS 13
+#define PTRACE_SETREGS (PT_COMMAND_MAX + 2)
 #endif
 #ifndef PTRACE_GETFPREGS
-#define PTRACE_GETFPREGS 14
+#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3)
 #endif
 #ifndef PTRACE_SETFPREGS
-#define PTRACE_SETFPREGS 15
+#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4)
 #endif
 #ifndef PTRACE_GETREGSET
 #define PTRACE_GETREGSET 0x4204
@@ -38,23 +34,11 @@ typedef int __ptrace_request;
 #ifndef PTRACE_SETREGSET
 #define PTRACE_SETREGSET 0x4205
 #endif
-#ifndef PTRACE_GET_THREAD_AREA
-#define PTRACE_GET_THREAD_AREA 25
-#endif
-#ifndef PTRACE_ARCH_PRCTL
-#define PTRACE_ARCH_PRCTL 30
-#endif
-#ifndef ARCH_GET_FS
-#define ARCH_SET_GS 0x1001
-#define ARCH_SET_FS 0x1002
-#define ARCH_GET_FS 0x1003
-#define ARCH_GET_GS 0x1004
-#endif
-#ifndef PTRACE_PEEKMTETAGS
-#define PTRACE_PEEKMTETAGS 33
+#ifndef PTRACE_GETVRREGS
+#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5)
 #endif
-#ifndef PTRACE_POKEMTETAGS
-#define PTRACE_POKEMTETAGS 34
+#ifndef PTRACE_GETVSRREGS
+#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6)
 #endif
 
-#endif // liblldb_Host_linux_Ptrace_h_
+#endif // liblldb_Host_aix_Ptrace_h_

___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Dhruv Srivastava (DhruvSrivastavaX)


Changes

This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

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

Added Ptrace extensions for AIX. 
- Commit 1: Taken Linux version for reference.
- Commit 2: Modified the extensions for AIX.

Review Request: @DavidSpickett

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


1 Files Affected:

- (added) lldb/include/lldb/Host/aix/Ptrace.h (+44) 


``diff
diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
new file mode 100644
index 00..5d5ae82c9dab7d
--- /dev/null
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)
+#endif
+#ifndef PTRACE_SETREGS
+#define PTRACE_SETREGS (PT_COMMAND_MAX + 2)
+#endif
+#ifndef PTRACE_GETFPREGS
+#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3)
+#endif
+#ifndef PTRACE_SETFPREGS
+#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4)
+#endif
+#ifndef PTRACE_GETREGSET
+#define PTRACE_GETREGSET 0x4204
+#endif
+#ifndef PTRACE_SETREGSET
+#define PTRACE_SETREGSET 0x4205
+#endif
+#ifndef PTRACE_GETVRREGS
+#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5)
+#endif
+#ifndef PTRACE_GETVSRREGS
+#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6)
+#endif
+
+#endif // liblldb_Host_aix_Ptrace_h_

``




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


[Lldb-commits] [lldb] [lldb] Recurse through DW_AT_signature when looking for attributes (PR #107241)

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

labath wrote:

> Wouldn't block the PR on this, but is there a way the `ElaboratingDIIterator` 
> changes can be tested? Maybe a unit-test where we instantiate 
> `elaborating_dies` on something that has `DW_AT_signature` and makes sure we 
> actually iterate over the original DWARF?

We couldn't make a meaningful test in the current form because the class is 
defined in the cpp file, and it's only user uses it in a context where 
DW_AT_signature doesn't make sense. We could move it to the header file, and 
then test it through its public API, but I'm somewhat reluctant to do that, as 
we don't have a use case for it. I guess that could be interpreted as a reason 
to not make this change to it (and that's the thing I'd probably do if you 
insisted on testing), but it's also a very trivial change that's very unlikely 
to go wrong.

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


[Lldb-commits] [lldb] 925b220 - [lldb] Recurse through DW_AT_signature when looking for attributes (#107241)

2024-09-10 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-09-10T12:57:54+02:00
New Revision: 925b220ee424f8489bc8d7b1a247f2c5f3edde5d

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

LOG: [lldb] Recurse through DW_AT_signature when looking for attributes 
(#107241)

This allows e.g. DWARFDIE::GetName() to return the name of the type when
looking at its declaration (which contains only
DW_AT_declaration+DW_AT_signature). This is similar to how we recurse
through DW_AT_specification when looking for a function name. Llvm dwarf
parser has obtained the same functionality through #99495.

This fixes a bug where we would confuse a type like NS::Outer::Struct
with NS::Struct (because NS::Outer (and its name) was in a type unit).

Added: 
lldb/test/Shell/SymbolFile/DWARF/x86/type-unit-same-basename.cpp

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index 0a13c457a307ae..d83740f8e2113b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -25,9 +25,9 @@ using namespace lldb_private::plugin::dwarf;
 namespace {
 
 /// Iterate through all DIEs elaborating (i.e. reachable by a chain of
-/// DW_AT_specification and DW_AT_abstract_origin attributes) a given DIE. For
-/// convenience, the starting die is included in the sequence as the first
-/// item.
+/// DW_AT_specification, DW_AT_abstract_origin and/or DW_AT_signature
+/// attributes) a given DIE. For convenience, the starting die is included in
+/// the sequence as the first item.
 class ElaboratingDIEIterator
 : public llvm::iterator_facade_base<
   ElaboratingDIEIterator, std::input_iterator_tag, DWARFDIE,
@@ -50,7 +50,8 @@ class ElaboratingDIEIterator
 m_worklist.pop_back();
 
 // And add back any items that elaborate it.
-for (dw_attr_t attr : {DW_AT_specification, DW_AT_abstract_origin}) {
+for (dw_attr_t attr :
+ {DW_AT_specification, DW_AT_abstract_origin, DW_AT_signature}) {
   if (DWARFDIE d = die.GetReferencedDIE(attr))
 if (m_seen.insert(die.GetDIE()).second)
   m_worklist.push_back(d);
@@ -129,10 +130,10 @@ DWARFDIE
 DWARFDIE::GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const {
   if (IsValid()) {
 DWARFUnit *cu = GetCU();
-const bool check_specification_or_abstract_origin = true;
+const bool check_elaborating_dies = true;
 DWARFFormValue form_value;
 if (m_die->GetAttributeValue(cu, attr, form_value, nullptr,
- check_specification_or_abstract_origin))
+ check_elaborating_dies))
   return form_value.Reference();
   }
   return DWARFDIE();
@@ -377,11 +378,6 @@ static void GetDeclContextImpl(DWARFDIE die,
   die = spec;
   continue;
 }
-// To find the name of a type in a type unit, we must follow the signature.
-if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
-  die = spec;
-  continue;
-}
 
 // Add this DIE's contribution at the end of the chain.
 auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
@@ -434,12 +430,6 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
  std::vector &context) {
   // Stop if we hit a cycle.
   while (die && seen.insert(die.GetID()).second) {
-// To find the name of a type in a type unit, we must follow the signature.
-if (DWARFDIE spec = die.GetReferencedDIE(DW_AT_signature)) {
-  die = spec;
-  continue;
-}
-
 // Add this DIE's contribution at the end of the chain.
 auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
   context.push_back({kind, ConstString(name)});

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
index e2660735ea7dec..77ef59d605c9c4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -355,8 +355,7 @@ void DWARFDebugInfoEntry::GetAttributes(DWARFUnit *cu,
 // would be a compile unit header).
 dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
 const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &form_value,
-dw_offset_t *end_attr_offset_ptr,
-bool check_specification_or_abstract_origin) const {
+dw_offset_t *end_attr_offset_ptr, bool check_elaborating_dies) const {
   if (const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu)) {
 std::optional attr_i

[Lldb-commits] [lldb] [lldb] Recurse through DW_AT_signature when looking for attributes (PR #107241)

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

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


[Lldb-commits] [lldb] [lldb] Fix some tests that fail with system libstdc++ (PR #106885)

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

Michael137 wrote:

Looks like this broke the macOS bots for one of the tests:
```
runCmd: expr std::reverse(a.begin(), a.end())

Assertion failed: (isa(Decl->TypeForDecl)), function 
getInjectedClassNameType, file ASTContext.cpp, line 5057.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  HandleCommand(command = "expr std::reverse(a.begin(), a.end())")
1.   parser at end of file
2.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:54:1:
 instantiating function definition 'std::reverse>'
3.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:47:58:
 instantiating function definition 'std::__reverse, std::__wrap_iter>'
4.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:40:1:
 instantiating function definition 'std::__reverse_impl>'
```

I'm going to skip it for now.

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


[Lldb-commits] [lldb] [lldb][test] Toolchain detection rewrite in Python (PR #102185)

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

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


[Lldb-commits] [lldb] [lldb][test] Toolchain detection rewrite in Python (PR #102185)

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

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

Looks good now, just remove the dead code.

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


[Lldb-commits] [lldb] [lldb][test] Toolchain detection rewrite in Python (PR #102185)

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


@@ -96,17 +98,105 @@ def getArchSpec(self, architecture):
 """
 return ["ARCH=" + architecture] if architecture else []
 
-def getCCSpec(self, compiler):
+def getToolchainSpec(self, compiler):
 """
-Helper function to return the key-value string to specify the compiler
+Helper function to return the key-value strings to specify the 
toolchain
 used for the make system.
 """
 cc = compiler if compiler else None
 if not cc and configuration.compiler:
 cc = configuration.compiler
-if cc:
-return ['CC="%s"' % cc]
-return []
+
+if not cc:
+return []
+
+exe_ext = ""
+if lldbplatformutil.getHostPlatform() == "windows":
+exe_ext = ".exe"
+

labath wrote:

It looks like this isn't used now.

https://github.com/llvm/llvm-project/pull/102185
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

DavidSpickett wrote:

This PT_COMMAND_MAX is provided by some AIX include file, correct?

If that's correct then using it like this is fine because PTrace.h is only 
included in code built natively.

Do you have public documentation for these ptrace numbers? Perhaps there is a 
man page like https://man7.org/linux/man-pages/man2/ptrace.2.html? It would be 
good to include a link to that in the PR description.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_

DavidSpickett wrote:

These should BE_ALL_UPPER_CASE. I know it's like that in the Linux one, but 
that's a mistake.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett commented:

This is exactly the style of PR I was looking for, thanks.

I don't want this to land without some code that uses it however. So I suggest 
we iterate on this until it's approved, then you put up the next PR and so on. 
We'll find some later point where it makes sense to start landing them.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20

DavidSpickett wrote:

What is the purpose of this and should it be declared like:
```
#ifndef DEBUG_PTRACE_MAXBYTES
#define ...
#endif
```
In case the build machine has a kernel that has changed this?

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


[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

2024-09-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

This started failing on the macOS CI after 
https://github.com/llvm/llvm-project/pull/106885:

```
  lldb-api :: 
commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py

"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 -std=c++11 -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info-nostdlib++ -nostdinc++ -cxx-isystem 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1
  --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 main.o -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info 
-L/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib 
-Wl,-rpath,/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib
 -lc++ --driver-mode=g++ -o "a.out"
ld: warning: ignoring duplicate libraries: '-lc++'
codesign --entitlements 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/entitlements-macos.plist
 -s - "a.out"
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/./bin/dsymutil"
  -o "a.out.dSYM" "a.out"


runCmd: settings set target.import-std-module true

output: 

runCmd: expr std::reverse(a.begin(), a.end())

Assertion failed: (isa(Decl->TypeForDecl)), 
function getInjectedClassNameType, file ASTContext.cpp, line 5057.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  HandleCommand(command = "expr std::reverse(a.begin(), a.end())")
1.   parser at end of file
2.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:54:1:
 instantiating function definition 'std::reverse>'
3.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:47:58:
 instantiating function definition 'std::__reverse, std::__wrap_iter>'
4.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:40:1:
 instantiating function definition 
'std::__reverse_impl>'
```

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


1 Files Affected:

- (modified) 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 (+1) 


``diff
diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 397ac6a14cca88..776700d865a38e 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -13,6 +13,7 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler=no_match("clang"))
 

[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

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

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

This started failing on the macOS CI after 
https://github.com/llvm/llvm-project/pull/106885:

```
  lldb-api :: 
commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py

"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 -std=c++11 -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info-nostdlib++ -nostdinc++ -cxx-isystem 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1
  --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 main.o -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info 
-L/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib 
-Wl,-rpath,/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib
 -lc++ --driver-mode=g++ -o "a.out"
ld: warning: ignoring duplicate libraries: '-lc++'
codesign --entitlements 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/entitlements-macos.plist
 -s - "a.out"
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/./bin/dsymutil"
  -o "a.out.dSYM" "a.out"


runCmd: settings set target.import-std-module true

output: 

runCmd: expr std::reverse(a.begin(), a.end())

Assertion failed: (isa(Decl->TypeForDecl)), function 
getInjectedClassNameType, file ASTContext.cpp, line 5057.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  HandleCommand(command = "expr std::reverse(a.begin(), a.end())")
1.   parser at end of file
2.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:54:1:
 instantiating function definition 'std::reverse>'
3.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:47:58:
 instantiating function definition 'std::__reverse, std::__wrap_iter>'
4.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:40:1:
 instantiating function definition 'std::__reverse_impl>'
```

>From cbc5d1316b5103a109bce905976fb9d5d937b330 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 10 Sep 2024 12:20:22 +0100
Subject: [PATCH] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip
 test on Darwin

---
 .../TestDbgInfoContentVectorFromStdModule.py | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 397ac6a14cca88..776700d865a38e 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -13,6 +13,7 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipI

[Lldb-commits] [lldb] [lldb][test] Toolchain detection rewrite in Python (PR #102185)

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


@@ -96,16 +98,120 @@ def getArchSpec(self, architecture):
 """
 return ["ARCH=" + architecture] if architecture else []
 
-def getCCSpec(self, compiler):
+def getToolchainSpec(self, compiler):
 """
-Helper function to return the key-value string to specify the compiler
+Helper function to return the key-value strings to specify the 
toolchain
 used for the make system.
 """
 cc = compiler if compiler else None
 if not cc and configuration.compiler:
 cc = configuration.compiler
+
 if cc:
-return ['CC="%s"' % cc]
+exe_ext = ""
+if lldbplatformutil.getHostPlatform() == "windows":
+exe_ext = ".exe"
+
+cc = cc.strip()
+cc_path = pathlib.Path(cc)
+cc = cc_path.as_posix()
+
+# We can get CC compiler string in the following formats:
+#  [] - such as 'xrun clang', 'xrun 
/usr/bin/clang' & etc
+#
+# Where  could contain the following parts:
+#   [.]   - sucn as 
'clang', 'clang.exe' ('clamg-cl.exe'?)
+#   -[.]   - such as 
'armv7-linux-gnueabi-gcc'
+#   /[.]- such as 
'/usr/bin/clang', 'c:\path\to\compiler\clang,exe'
+#   /-[.]- such as 
'/usr/bin/clang', 'c:\path\to\compiler\clang,exe'
+
+cc_ext = cc_path.suffix
+# Compiler name without extension
+cc_name = cc_path.stem.split(" ")[-1]
+
+# A kind of compiler (canonical name): clang, gcc, cc & etc.
+cc_type = cc_name
+# A triple prefix of compiler name: gcc
+cc_prefix = ""
+if not "clang-cl" in cc_name and not "llvm-gcc" in cc_name:
+cc_name_parts = cc_name.split("-")
+cc_type = cc_name_parts[-1]
+if len(cc_name_parts) > 1:
+cc_prefix = "-".join(cc_name_parts[:-1]) + "-"
+
+# A kind of C++ compiler.
+cxx_types = {
+"icc": "icpc",
+"llvm-gcc": "llvm-g++",
+"gcc": "g++",
+"cc": "c++",
+"clang": "clang++",
+}
+cxx_type = cxx_types.get(cc_type, cc_type)
+
+cc_dir = cc_path.parent
+
+def getLlvmUtil(util_name):
+llvm_tools_dir = os.getenv("LLVM_TOOLS_DIR", cc_dir.as_posix())
+return llvm_tools_dir + "/" + util_name + exe_ext
+
+def getToolchainUtil(util_name):
+return (cc_dir / (cc_prefix + util_name + cc_ext)).as_posix()
+
+cxx = getToolchainUtil(cxx_type)
+
+util_names = {
+"OBJCOPY": "objcopy",
+"STRIP": "objcopy",
+"ARCHIVER": "ar",
+"DWP": "dwp",
+}
+utils = []
+
+# Note: LLVM_AR is currently required by API TestBSDArchives.py 
tests.
+# Assembly a full path to llvm-ar for given LLVM_TOOLS_DIR;
+# otherwise assume we have llvm-ar at the same place where is CC 
specified.
+if not os.getenv("LLVM_AR"):
+llvm_ar = getLlvmUtil("llvm-ar")
+utils.extend(['LLVM_AR="%s"' % llvm_ar])
+
+if not lldbplatformutil.platformIsDarwin():
+if os.getenv("USE_LLVM_TOOLS"):

labath wrote:

Thanks. Before you go on the next PR, let me just elaborate on what I'm 
thinking.

Basically, the (API) test suite can run in two modes. The first one (the 
default) is where it uses all of the tools from the build tree that it can. 
This includes the compiler and the other tools like llvm-objcopy, etc. This is 
done for two reasons:
- it minimizes the amount of external dependencies
- it maximizes the reproducibility of the build

This mode doesn't (shouldn't?) require any special flags or configuration. The 
second mode is where you can run the tests against a toolchain (mostly: 
compiler) of your choosing, and there it's expected that you may need to pass 
many arguments in order to make it work.

The thing which bothers me about this flag is that it's a flag that forces a 
switch back to the default mode (for some tools), which is makes reasoning 
about it more complicated. I think it would be better to just make the behavior 
you want to be the default, and then (if necessary) have a separate flag to 
force the usage of a specific tool (e.g. objcopy). I think that would be 
similar to how things work with e.g. dsymutil, where by default we pick the 
in-tree version, but we have a cmake/dotest/etc. flag to let the user choose a 
different one.

This would mean that users that run tests against gcc (and which want to 
continue using the gcc's version of objcopy) could no longer rely on the 
compiler-based detection and would have to pass (and

[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

2024-09-10 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 
925b220ee424f8489bc8d7b1a247f2c5f3edde5d...cbc5d1316b5103a109bce905976fb9d5d937b330
 
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
``





View the diff from darker here.


``diff
--- TestDbgInfoContentVectorFromStdModule.py2024-09-10 11:20:22.00 +
+++ TestDbgInfoContentVectorFromStdModule.py2024-09-10 11:26:13.415241 +
@@ -11,11 +11,11 @@
 class TestDbgInfoContentVector(TestBase):
 @add_test_categories(["libc++"])
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
-@skipIfDarwin # https://github.com/llvm/llvm-project/issues/106475
+@skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
 def test(self):
 self.build()
 
 lldbutil.run_to_source_breakpoint(
 self, "// Set break point at this line.", 
lldb.SBFileSpec("main.cpp")

``




https://github.com/llvm/llvm-project/pull/108003
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_

labath wrote:

This is the old include guard style. I guess Jonas only updated the files that 
are built on mac when he was doing the conversion. New files should definitely 
use the new style though..

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

labath wrote:

I'll just add that all of these defines are only required if your system 
headers don't always provide these definitions. This was necessary on linux (in 
the past, maybe not in present), because people built lldb on all kinds of 
kernel versions. If you're only going to support building lldb on AIX version 
>=X (where `X` may even be the most recent version of the OS) then you only 
need to provide the symbols that aren't available on every supported version. 
If all the supported versions of AIX define these symbols, then you don't need 
to define anything here (and maybe you don't even need this file).

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20

labath wrote:

This is a lldb-specific macro that shouldn't be here even on linux (it's just 
used in one place, and might as well be inlined there). Let's delete it from 
here.

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


[Lldb-commits] [clang] [clang-tools-extra] [lldb] [llvm] [SystemZ][z/OS] Propagate IsText parameter to open text files as text (PR #107906)

2024-09-10 Thread Abhina Sree via lldb-commits

https://github.com/abhina-sree updated 
https://github.com/llvm/llvm-project/pull/107906

>From 758745c955471b0ad65cd3a33381f753e2b63797 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Mon, 9 Sep 2024 15:32:09 -0400
Subject: [PATCH 1/2] Propagate IsText parameter to openFileForRead function

---
 clang-tools-extra/clangd/FS.cpp   |  4 +--
 clang-tools-extra/clangd/Preamble.cpp |  4 +--
 .../clangd/support/ThreadsafeFS.cpp   |  2 +-
 .../clangd/unittests/ClangdTests.cpp  |  2 +-
 clang/include/clang/Basic/FileManager.h   |  8 +++---
 .../DependencyScanningFilesystem.h|  2 +-
 clang/lib/Basic/FileManager.cpp   | 12 -
 clang/lib/Basic/SourceManager.cpp | 14 --
 clang/lib/Serialization/ASTReader.cpp |  3 ++-
 .../DependencyScanningFilesystem.cpp  |  5 ++--
 clang/unittests/Driver/DistroTest.cpp |  4 +--
 clang/unittests/Driver/ToolChainTest.cpp  |  2 +-
 clang/unittests/Frontend/PCHPreambleTest.cpp  |  6 ++---
 .../DependencyScannerTest.cpp |  4 +--
 llvm/include/llvm/Support/AutoConvert.h   |  6 +
 llvm/include/llvm/Support/VirtualFileSystem.h | 21 ---
 llvm/lib/Support/AutoConvert.cpp  | 26 +++
 llvm/lib/Support/FileCollector.cpp|  4 +--
 llvm/lib/Support/VirtualFileSystem.cpp| 21 ---
 .../Support/VirtualFileSystemTest.cpp |  6 ++---
 20 files changed, 103 insertions(+), 53 deletions(-)

diff --git a/clang-tools-extra/clangd/FS.cpp b/clang-tools-extra/clangd/FS.cpp
index 5729b9341d9d4b..bd3c6440c24b0f 100644
--- a/clang-tools-extra/clangd/FS.cpp
+++ b/clang-tools-extra/clangd/FS.cpp
@@ -64,8 +64,8 @@ PreambleFileStatusCache::getProducingFS(
 : ProxyFileSystem(std::move(FS)), StatCache(StatCache) {}
 
 llvm::ErrorOr>
-openFileForRead(const llvm::Twine &Path) override {
-  auto File = getUnderlyingFS().openFileForRead(Path);
+openFileForRead(const llvm::Twine &Path, bool IsText = true) override {
+  auto File = getUnderlyingFS().openFileForRead(Path, IsText);
   if (!File || !*File)
 return File;
   // Eagerly stat opened file, as the followup `status` call on the file
diff --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index dd13b1a9e5613d..e970d01f3729f3 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -479,9 +479,9 @@ class TimerFS : public llvm::vfs::ProxyFileSystem {
   : ProxyFileSystem(std::move(FS)) {}
 
   llvm::ErrorOr>
-  openFileForRead(const llvm::Twine &Path) override {
+  openFileForRead(const llvm::Twine &Path, bool IsText = true) override {
 WallTimerRegion T(Timer);
-auto FileOr = getUnderlyingFS().openFileForRead(Path);
+auto FileOr = getUnderlyingFS().openFileForRead(Path, IsText);
 if (!FileOr)
   return FileOr;
 return std::make_unique(Timer, std::move(FileOr.get()));
diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp 
b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index 7398e4258527ba..bc0b984e577cb8 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -29,7 +29,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem {
   : ProxyFileSystem(std::move(FS)) {}
 
   llvm::ErrorOr>
-  openFileForRead(const llvm::Twine &InPath) override {
+  openFileForRead(const llvm::Twine &InPath, bool IsText = true) override {
 llvm::SmallString<128> Path;
 InPath.toVector(Path);
 
diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
index 643b8e9f12d751..e86385c2072b34 100644
--- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1010,7 +1010,7 @@ TEST(ClangdTests, PreambleVFSStatCache) {
 : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {}
 
 llvm::ErrorOr>
-openFileForRead(const Twine &Path) override {
+openFileForRead(const Twine &Path, bool IsText = true) override {
   ++CountStats[llvm::sys::path::filename(Path.str())];
   return ProxyFileSystem::openFileForRead(Path);
 }
diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 527bbef24793ee..67a69fb79ccefe 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -286,21 +286,21 @@ class FileManager : public RefCountedBase {
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
   getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
-   bool RequiresNullTerminator = true,
+   bool RequiresNullTerminator = true, bool IsText = true,
std::optional MaybeLimit = std::nullopt);
   llvm::Error

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

2024-09-10 Thread via lldb-commits


@@ -0,0 +1,62 @@
+//===--- DirectCallReplacementPass.h - RISC-V specific pass 
---===//
+//
+// 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_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+#define LLDB_SOURCE_PLUGINS_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+
+#include "lldb/lldb-types.h"
+
+#include "llvm/IR/Instructions.h"
+#include "llvm/Pass.h"
+
+namespace lldb_private {
+
+class ExecutionContext;
+
+// During the lldb expression execution lldb wraps a user expression, jittes
+// fabricated code and then puts it into the stack memory. Thus, if user tried

dlav-sc wrote:

> Are you sure it's using stack memory? This would require the stack to be 
> executable.
Generally we find a way to memory map some chunk and use that instead.

Well, maybe it's not always true, lldb searches suitable place in memory for 
mapping as you've said, but according to logs, usually stack memory is used 
(please, take a look 
https://github.com/llvm/llvm-project/pull/99336#discussion_r1692134445,  
https://github.com/llvm/llvm-project/pull/99336#issuecomment-2242837459)

> Maybe you're referring to jumps from that JIT'd code back to code in the 
> binary, that those jumps may be too large?

Yep. Even if lldb hasn't used stack memory exactly, we can't guarantee that 
selected region will be close enough to code in the binary to make a jump.

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


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

2024-09-10 Thread David Spickett via lldb-commits


@@ -0,0 +1,62 @@
+//===--- DirectCallReplacementPass.h - RISC-V specific pass 
---===//
+//
+// 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_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+#define LLDB_SOURCE_PLUGINS_ARCHITECTURE_RISCV_DIRECTCALLREPLACEMENTPASS_H
+
+#include "lldb/lldb-types.h"
+
+#include "llvm/IR/Instructions.h"
+#include "llvm/Pass.h"
+
+namespace lldb_private {
+
+class ExecutionContext;
+
+// During the lldb expression execution lldb wraps a user expression, jittes
+// fabricated code and then puts it into the stack memory. Thus, if user tried

DavidSpickett wrote:

Ok then maybe lldb is first looking for anything known to be executable then 
falling back to memory where it's unknown whether it's executable. That would 
include the stack in some scenarios.

I know ideally we find an mmap symbol and call it but clearly this only works 
for hosted systems and requires a a decent feature set first.

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


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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

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

2024-09-10 Thread via lldb-commits


@@ -1441,6 +1443,26 @@ lldb_private::Status 
ClangExpressionParser::DoPrepareForExecution(
 custom_passes.EarlyPasses->run(*llvm_module_up);
   }
 
+  std::unique_ptr arch_passes(nullptr);

dlav-sc wrote:

addressed

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


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

2024-09-10 Thread via lldb-commits


@@ -1441,6 +1443,26 @@ lldb_private::Status 
ClangExpressionParser::DoPrepareForExecution(
 custom_passes.EarlyPasses->run(*llvm_module_up);
   }
 
+  std::unique_ptr arch_passes(nullptr);
+  if (lldb::TargetSP target_sp = exe_ctx.GetTargetSP()) {
+Architecture *arch = target_sp->GetArchitecturePlugin();
+if (arch) {

dlav-sc wrote:

addressed

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


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

2024-09-10 Thread via lldb-commits


@@ -0,0 +1,217 @@
+//===--- DirectCallReplacementPass.cpp - RISC-V specific pass 
-===//
+//
+// 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 "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#include "Plugins/Architecture/RISCV/DirectCallReplacementPass.h"
+
+#include "lldb/Core/Architecture.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+#include 
+
+using namespace llvm;
+using namespace lldb_private;
+
+namespace {

dlav-sc wrote:

addressed

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


[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

DhruvSrivastavaX wrote:

Glad to hear that! 

Sure that should be okay. I can proceed with the files which directly rely on 
this one for the next PRs, so that we can plan accordingly.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_

DhruvSrivastavaX wrote:

Okay, Done!

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20

DhruvSrivastavaX wrote:

To be specific, it is being used in the `NativeProcessLinux.cpp`. For our 
context, it is used similarly for `NativeProcessAIX.cpp`, utilised by 
`DisplayBytes(..)<--PtraceDisplayBytes(..)`.
We can move it to the same file if you suggest so and in the same way as David 
suggested.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20

labath wrote:

Yes, please do that. (Alternatively, we could move this constant to some common 
header, if you think that having a consistent number of logged bytes is useful 
(I don't think that)).

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

DhruvSrivastavaX wrote:

> This PT_COMMAND_MAX is provided by some AIX include file, correct?
> 
> If that's correct then using it like this is fine because PTrace.h is only 
> included in code built natively.
> 
> Do you have public documentation for these ptrace numbers? Perhaps there is a 
> man page like https://man7.org/linux/man-pages/man2/ptrace.2.html? It would 
> be good to include a link to that in the PR description.

Although it is defined in AIX's system header `sys/ptrace.h` , its not been 
mentioned in AIX public documentation. 
For other defines, here is the link though:
https://www.ibm.com/docs/en/aix/7.2?topic=p-ptrace-ptracex-ptrace64-subroutine




> ersions. If you're only going to support building lldb on AIX version >=X 
> (where `X` may even be the most recent version of the OS) then you only need 
> to provide the symbols that aren't available on every supported version. If 
> all the supported versions of AIX define these symbols, then you don't need 
> to define anything here (and maybe you don't even need this file).

We are actually using these defines do some emulation in the NativeProcess 
files, hence the need for them. Please take a look here:
https://github.com/llvm/llvm-project/pull/102601/files#diff-932a7c13bbba2ce92d14f75c525489f726af9e95f955df24b3f840727e9f757a



https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX edited 
https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

labath wrote:

Just to avoid confusion, this comment was actually question: Is it the case 
that the AIX system headers (on all supported versions) do not already define 
these constants?

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX edited 
https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

DhruvSrivastavaX wrote:

Just pasting a small snippet from that here:
line: 1755
```
  if (req == PTRACE_GETREGS) {
GetRegister(pid, GPR0, &(((GPR *)data)->r0));
GetRegister(pid, GPR1, &(((GPR *)data)->r1));
GetRegister(pid, GPR2, &(((GPR *)data)->r2));
GetRegister(pid, GPR3, &(((GPR *)data)->r3));
GetRegister(pid, GPR4, &(((GPR *)data)->r4));
GetRegister(pid, GPR5, &(((GPR *)data)->r5));
GetRegister(pid, GPR6, &(((GPR *)data)->r6));
GetRegister(pid, GPR7, &(((GPR *)data)->r7));
GetRegister(pid, GPR8, &(((GPR *)data)->r8));
GetRegister(pid, GPR9, &(((GPR *)data)->r9));
GetRegister(pid, GPR10, &(((GPR *)data)->r10));
```

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX edited 
https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20

DhruvSrivastavaX wrote:

For now, I can define it with the given value in that file locally and use it, 
and going forward we can update/get it removed if that is a better alternative.

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

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

>From 426874ab276182858b75e9bbf8704dab1742757c Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Tue, 10 Sep 2024 04:38:32 -0500
Subject: [PATCH 1/3] Ptrace code base for AIX

---
 lldb/include/lldb/Host/aix/Ptrace.h | 60 +
 1 file changed, 60 insertions(+)
 create mode 100644 lldb/include/lldb/Host/aix/Ptrace.h

diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
new file mode 100644
index 00..aabd3fd4fc5573
--- /dev/null
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -0,0 +1,60 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_linux_Ptrace_h_
+#define liblldb_Host_linux_Ptrace_h_
+
+#include 
+
+#ifndef __GLIBC__
+typedef int __ptrace_request;
+#endif
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS 12
+#endif
+#ifndef PTRACE_SETREGS
+#define PTRACE_SETREGS 13
+#endif
+#ifndef PTRACE_GETFPREGS
+#define PTRACE_GETFPREGS 14
+#endif
+#ifndef PTRACE_SETFPREGS
+#define PTRACE_SETFPREGS 15
+#endif
+#ifndef PTRACE_GETREGSET
+#define PTRACE_GETREGSET 0x4204
+#endif
+#ifndef PTRACE_SETREGSET
+#define PTRACE_SETREGSET 0x4205
+#endif
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
+#ifndef PTRACE_ARCH_PRCTL
+#define PTRACE_ARCH_PRCTL 30
+#endif
+#ifndef ARCH_GET_FS
+#define ARCH_SET_GS 0x1001
+#define ARCH_SET_FS 0x1002
+#define ARCH_GET_FS 0x1003
+#define ARCH_GET_GS 0x1004
+#endif
+#ifndef PTRACE_PEEKMTETAGS
+#define PTRACE_PEEKMTETAGS 33
+#endif
+#ifndef PTRACE_POKEMTETAGS
+#define PTRACE_POKEMTETAGS 34
+#endif
+
+#endif // liblldb_Host_linux_Ptrace_h_

>From 61bdaf75ddbd5940af5f23363311ffcacb0540d7 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Tue, 10 Sep 2024 05:43:37 -0500
Subject: [PATCH 2/3] Modified specific to AIX

---
 lldb/include/lldb/Host/aix/Ptrace.h | 38 +
 1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
index aabd3fd4fc5573..5d5ae82c9dab7d 100644
--- a/lldb/include/lldb/Host/aix/Ptrace.h
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -8,29 +8,25 @@
 
 // This file defines ptrace functions & structures
 
-#ifndef liblldb_Host_linux_Ptrace_h_
-#define liblldb_Host_linux_Ptrace_h_
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
 
 #include 
 
-#ifndef __GLIBC__
-typedef int __ptrace_request;
-#endif
-
 #define DEBUG_PTRACE_MAXBYTES 20
 
 // Support ptrace extensions even when compiled without required kernel support
 #ifndef PTRACE_GETREGS
-#define PTRACE_GETREGS 12
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)
 #endif
 #ifndef PTRACE_SETREGS
-#define PTRACE_SETREGS 13
+#define PTRACE_SETREGS (PT_COMMAND_MAX + 2)
 #endif
 #ifndef PTRACE_GETFPREGS
-#define PTRACE_GETFPREGS 14
+#define PTRACE_GETFPREGS (PT_COMMAND_MAX + 3)
 #endif
 #ifndef PTRACE_SETFPREGS
-#define PTRACE_SETFPREGS 15
+#define PTRACE_SETFPREGS (PT_COMMAND_MAX + 4)
 #endif
 #ifndef PTRACE_GETREGSET
 #define PTRACE_GETREGSET 0x4204
@@ -38,23 +34,11 @@ typedef int __ptrace_request;
 #ifndef PTRACE_SETREGSET
 #define PTRACE_SETREGSET 0x4205
 #endif
-#ifndef PTRACE_GET_THREAD_AREA
-#define PTRACE_GET_THREAD_AREA 25
-#endif
-#ifndef PTRACE_ARCH_PRCTL
-#define PTRACE_ARCH_PRCTL 30
-#endif
-#ifndef ARCH_GET_FS
-#define ARCH_SET_GS 0x1001
-#define ARCH_SET_FS 0x1002
-#define ARCH_GET_FS 0x1003
-#define ARCH_GET_GS 0x1004
-#endif
-#ifndef PTRACE_PEEKMTETAGS
-#define PTRACE_PEEKMTETAGS 33
+#ifndef PTRACE_GETVRREGS
+#define PTRACE_GETVRREGS (PT_COMMAND_MAX + 5)
 #endif
-#ifndef PTRACE_POKEMTETAGS
-#define PTRACE_POKEMTETAGS 34
+#ifndef PTRACE_GETVSRREGS
+#define PTRACE_GETVSRREGS (PT_COMMAND_MAX + 6)
 #endif
 
-#endif // liblldb_Host_linux_Ptrace_h_
+#endif // liblldb_Host_aix_Ptrace_h_

>From 1134b6fb81cedd75e447f42f788bb6d96351cdf3 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava 
Date: Tue, 10 Sep 2024 08:32:41 -0500
Subject: [PATCH 3/3] Addressed comments

---
 lldb/include/lldb/Host/aix/Ptrace.h | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lldb/include/lldb/Host/aix/Ptrace.h 
b/lldb/include/lldb/Host/aix/Ptrace.h
index 5d5ae82c9dab7d..06678d1e1a2484 100644
--- a/lldb/include/lldb/Host/aix/Ptrace.h
+++ b/lldb/include/lldb/Host/aix/Ptrace.h
@@ -8,13 +8,11 @@
 
 // This file defines ptrace functions & structures
 
-#ifndef liblldb_Host_aix_Ptrace_h_
-#defi

[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

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


[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

2024-09-10 Thread Felipe de Azevedo Piovezan via lldb-commits

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

LGTM!
Not sure why the formatter is complaining about a single line deletion

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


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

2024-09-10 Thread via lldb-commits

dlav-sc wrote:

Also Large Code Model for RISCV targets has been merged 2 days ago 
(https://github.com/llvm/llvm-project/pull/70308), so I'm going to remove 
DirectCallReplacementPass and use large model in MCJIT instead.

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


[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

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

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

>From cbc5d1316b5103a109bce905976fb9d5d937b330 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 10 Sep 2024 12:20:22 +0100
Subject: [PATCH 1/2] [lldb][test] TestDbgInfoContentVectorFromStdModule.py:
 skip test on Darwin

---
 .../TestDbgInfoContentVectorFromStdModule.py | 1 +
 1 file changed, 1 insertion(+)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 397ac6a14cca88..776700d865a38e 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -13,6 +13,7 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
+@skipIfDarwin # https://github.com/llvm/llvm-project/issues/106475
 def test(self):
 self.build()
 

>From c3efc941f76f229792c70db21accfe63b97cbf71 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 10 Sep 2024 16:00:00 +0100
Subject: [PATCH 2/2] fixup! format

---
 .../TestDbgInfoContentVectorFromStdModule.py| 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 776700d865a38e..1c3e64f14c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
@@ -13,7 +13,7 @@ class TestDbgInfoContentVector(TestBase):
 @skipIf(compiler=no_match("clang"))
 @skipIf(compiler="clang", compiler_version=["<", "12.0"])
 @skipIf(macos_version=["<", "14.0"])
-@skipIfDarwin # https://github.com/llvm/llvm-project/issues/106475
+@skipIfDarwin  # https://github.com/llvm/llvm-project/issues/106475
 def test(self):
 self.build()
 

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


[Lldb-commits] [lldb] 2bcab9b - [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (#108003)

2024-09-10 Thread via lldb-commits

Author: Michael Buch
Date: 2024-09-10T16:00:40+01:00
New Revision: 2bcab9ba7139cfa96c85433fa85b29c8a6d7008b

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

LOG: [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin 
(#108003)

This started failing on the macOS CI after
https://github.com/llvm/llvm-project/pull/106885:

```
  lldb-api :: 
commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py

"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 -std=c++11 -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info-nostdlib++ -nostdinc++ -cxx-isystem 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1
  --driver-mode=g++ -MT main.o -MD -MP -MF main.d -c -o main.o 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/main.cpp
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang" 
 main.o -g -O0 -isysroot 
"/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk"
 -arch arm64  
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/include
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content
 
-I/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make
 -include 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h
  -fno-limit-debug-info 
-L/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib 
-Wl,-rpath,/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/lib
 -lc++ --driver-mode=g++ -o "a.out"
ld: warning: ignoring duplicate libraries: '-lc++'
codesign --entitlements 
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/make/entitlements-macos.plist
 -s - "a.out"
"/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/./bin/dsymutil"
  -o "a.out.dSYM" "a.out"


runCmd: settings set target.import-std-module true

output: 

runCmd: expr std::reverse(a.begin(), a.end())

Assertion failed: (isa(Decl->TypeForDecl)), function 
getInjectedClassNameType, file ASTContext.cpp, line 5057.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  HandleCommand(command = "expr std::reverse(a.begin(), a.end())")
1.   parser at end of file
2.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:54:1:
 instantiating function definition 'std::reverse>'
3.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:47:58:
 instantiating function definition 'std::__reverse, std::__wrap_iter>'
4.  
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/include/c++/v1/__algorithm/reverse.h:40:1:
 instantiating function definition 'std::__reverse_impl>'
```

Added: 


Modified: 

lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py

Removed: 




diff  --git 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
index 397ac6a14cca88..1c3e64f14c 100644
--- 
a/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
+++ 
b/lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/Te

[Lldb-commits] [lldb] [lldb][test] TestDbgInfoContentVectorFromStdModule.py: skip test on Darwin (PR #108003)

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

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added readMemory and WriteMemory, var type correction (PR #108036)

2024-09-10 Thread Jennifer Phillips via lldb-commits

jennphilqc wrote:

Please add @clayborg as Reviewer.

https://github.com/llvm/llvm-project/pull/108036
___
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 Ptrace extensions for AIX (PR #108000)

2024-09-10 Thread Dhruv Srivastava via lldb-commits

https://github.com/DhruvSrivastavaX edited 
https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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


@@ -0,0 +1,44 @@
+//===-- Ptrace.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
+//
+//===--===//
+
+// This file defines ptrace functions & structures
+
+#ifndef liblldb_Host_aix_Ptrace_h_
+#define liblldb_Host_aix_Ptrace_h_
+
+#include 
+
+#define DEBUG_PTRACE_MAXBYTES 20
+
+// Support ptrace extensions even when compiled without required kernel support
+#ifndef PTRACE_GETREGS
+#define PTRACE_GETREGS (PT_COMMAND_MAX + 1)

labath wrote:

ok, so if I understand what you're saying, these definitions don't correspond 
to any actual values defined or supported by the system.

In that case, I think these values do not belong here, as this is basically an 
OS compatibility header. In fact, I think there's no reason for these constants 
should exist. You don't have to follow the patterns in NativeProcessLinux, if 
they don't make sense for you. There's nothing forcing you do implement ReadGPR 
like this
```

Status NativeRegisterContextAIX::ReadGPR() {
  return NativeProcessAIX::PtraceWrapper(
  PTRACE_GETREGS, m_thread.GetID(), nullptr, GetGPRBuffer(), GetGPRSize());
}
```
If your host ptrace call does not support reading GPRs in bulk. If you need to 
read registers one by one, the most obvious implementation is to just do that 
directly inside the ReadGPR function -- basically inline the relevant part of 
PtraceWrapper into this function  (and then get rid of the constant).

https://github.com/llvm/llvm-project/pull/108000
___
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 Ptrace extensions for AIX (PR #108000)

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

labath wrote:

Given https://github.com/llvm/llvm-project/pull/108000#discussion_r1752296507, 
my feeling is that this file just should not (need not) exist. For now, I'd 
suggest moving the header into NativeProcessAIX (that's the only place which 
uses it, right?), and then we can figure out what to do with it when we get to 
that.

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


[Lldb-commits] [lldb] [LLDB] Reapply SBSaveCore Add Memory List (PR #107937)

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

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

>From 2bdc8c0bd8b92989420b798d90e47f27d8a06e66 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 9 Sep 2024 13:54:37 -0700
Subject: [PATCH 1/4] Reapply "[LLDB] Reappply SBSaveCore AddMemoryList"
 (#107731)

This reverts commit bb343468ffa8c2190fcdd0f704d370c75d3b5edd.
---
 lldb/include/lldb/API/SBMemoryRegionInfo.h|   2 +-
 lldb/include/lldb/API/SBSaveCoreOptions.h |  11 ++
 lldb/include/lldb/Symbol/SaveCoreOptions.h|  11 +-
 .../lldb/Target/CoreFileMemoryRanges.h|  50 ++
 lldb/include/lldb/Target/Process.h|  25 +--
 lldb/include/lldb/Utility/RangeMap.h  |   2 +
 lldb/include/lldb/lldb-enumerations.h |   1 +
 lldb/include/lldb/lldb-forward.h  |   1 +
 lldb/include/lldb/lldb-private-interfaces.h   |   1 -
 lldb/source/API/SBSaveCoreOptions.cpp |  11 ++
 lldb/source/Commands/CommandObjectProcess.cpp |   1 +
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp |   6 +-
 .../ObjectFile/Mach-O/ObjectFileMachO.h   |   1 +
 .../Minidump/MinidumpFileBuilder.cpp  |  35 ++--
 .../ObjectFile/Minidump/MinidumpFileBuilder.h |   5 +-
 .../ObjectFile/Minidump/ObjectFileMinidump.h  |   1 +
 .../ObjectFile/PECOFF/ObjectFilePECOFF.cpp|   1 +
 .../ObjectFile/PECOFF/ObjectFilePECOFF.h  |   1 +
 lldb/source/Symbol/SaveCoreOptions.cpp|  14 ++
 lldb/source/Target/CMakeLists.txt |   1 +
 lldb/source/Target/CoreFileMemoryRanges.cpp   |  49 ++
 lldb/source/Target/Process.cpp|  75 ++---
 .../TestProcessSaveCoreMinidump.py| 149 ++
 lldb/unittests/Process/Utility/CMakeLists.txt |   1 +
 .../Utility/CoreFileMemoryRangesTest.cpp  | 108 +
 25 files changed, 496 insertions(+), 67 deletions(-)
 create mode 100644 lldb/include/lldb/Target/CoreFileMemoryRanges.h
 create mode 100644 lldb/source/Target/CoreFileMemoryRanges.cpp
 create mode 100644 lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp

diff --git a/lldb/include/lldb/API/SBMemoryRegionInfo.h 
b/lldb/include/lldb/API/SBMemoryRegionInfo.h
index be55de4ead1fa8..f9a5dc993d7cb6 100644
--- a/lldb/include/lldb/API/SBMemoryRegionInfo.h
+++ b/lldb/include/lldb/API/SBMemoryRegionInfo.h
@@ -120,7 +120,7 @@ class LLDB_API SBMemoryRegionInfo {
 private:
   friend class SBProcess;
   friend class SBMemoryRegionInfoList;
-
+  friend class SBSaveCoreOptions;
   friend class lldb_private::ScriptInterpreter;
 
   lldb_private::MemoryRegionInfo &ref();
diff --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index ba48ba5eaea5a0..c076d3ce6f7575 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -80,6 +80,17 @@ class LLDB_API SBSaveCoreOptions {
   /// \return True if the thread was removed, false if it was not in the list.
   bool RemoveThread(lldb::SBThread thread);
 
+  /// Add a memory region to save in the core file.
+  ///
+  /// \param region The memory region to save.
+  /// \returns An empty SBError upon success, or an error if the region is
+  /// invalid.
+  /// \note Ranges that overlapped will be unioned into a single region, this
+  /// also supercedes stack minification. Specifying full regions and a
+  /// non-custom core style will include the specified regions and union them
+  /// with all style specific regions.
+  SBError AddMemoryRegionToSave(const SBMemoryRegionInfo ®ion);
+
   /// Reset all options.
   void Clear();
 
diff --git a/lldb/include/lldb/Symbol/SaveCoreOptions.h 
b/lldb/include/lldb/Symbol/SaveCoreOptions.h
index f4fed4676fa4ae..d90d08026016dc 100644
--- a/lldb/include/lldb/Symbol/SaveCoreOptions.h
+++ b/lldb/include/lldb/Symbol/SaveCoreOptions.h
@@ -10,13 +10,15 @@
 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_SaveCoreOPTIONS_H
 
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/lldb-forward.h"
-#include "lldb/lldb-types.h"
+#include "lldb/Utility/RangeMap.h"
 
 #include 
+#include 
 #include 
 #include 
 
+using MemoryRanges = lldb_private::RangeVector;
+
 namespace lldb_private {
 
 class SaveCoreOptions {
@@ -38,8 +40,12 @@ class SaveCoreOptions {
   Status AddThread(lldb::ThreadSP thread_sp);
   bool RemoveThread(lldb::ThreadSP thread_sp);
   bool ShouldThreadBeSaved(lldb::tid_t tid) const;
+  bool HasSpecifiedThreads() const;
 
   Status EnsureValidConfiguration(lldb::ProcessSP process_sp) const;
+  const MemoryRanges &GetCoreFileMemoryRanges() const;
+
+  void AddMemoryRegionToSave(const lldb_private::MemoryRegionInfo ®ion);
 
   void Clear();
 
@@ -51,6 +57,7 @@ class SaveCoreOptions {
   std::optional m_style;
   lldb::ProcessSP m_process_sp;
   std::unordered_set m_threads_to_save;
+  MemoryRanges m_regions_to_save;
 };
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/Target/CoreFileMemoryRanges.h 
b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
new file mode 100644
index 000

[Lldb-commits] [lldb] [lldb][AIX] Added Ptrace extensions for AIX (PR #108000)

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

labath wrote:

(NativeProcessAIX is one of the classes which I'm certain they will **not** be 
shared with their linux counterpart, so there's really no reason to emulate 
linux implementation if it does not come natural. And "inventing" OS constants 
to make the code layout similar definitely falls in that category.)

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


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

2024-09-10 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb-dap] Improve `stackTrace` and `exceptionInfo` DAP request handlers (PR #105905)

2024-09-10 Thread John Harrison via lldb-commits

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

>From 6612efb0e51d700eeb545a421a34f7a57aafc509 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 23 Aug 2024 16:04:44 -0700
Subject: [PATCH 1/8] [lldb-dap] Improve `stackTrace` and `exceptionInfo` DAP
 request handlers.

Refactoring `stackTrace` to perform frame look ups in a more on-demand fashion 
to improve overall performance.

Additionally adding additional information to the `exceptionInfo` request to 
report exception stacks there instead of merging the exception stack into the 
stack trace. The `exceptionInfo` request is only called if a stop event occurs 
with `reason='exception'`, which should mitigate the performance of 
`SBThread::GetCurrentException` calls.

Adding unit tests for exception handling and stack trace supporting.
---
 .../Python/lldbsuite/test/lldbplatformutil.py |  16 ++
 .../test/tools/lldb-dap/dap_server.py |  11 +
 .../test/tools/lldb-dap/lldbdap_testcase.py   |   9 +-
 .../API/tools/lldb-dap/exception/Makefile |   2 +-
 .../lldb-dap/exception/TestDAP_exception.py   |   8 +-
 .../API/tools/lldb-dap/exception/cpp/Makefile |   3 +
 .../exception/cpp/TestDAP_exception_cpp.py|  26 ++
 .../API/tools/lldb-dap/exception/cpp/main.cpp |   6 +
 .../lldb-dap/exception/{main.cpp => main.c}   |   2 +-
 .../tools/lldb-dap/exception/objc/Makefile|   9 +
 .../exception/objc/TestDAP_exception_objc.py  |  27 ++
 .../API/tools/lldb-dap/exception/objc/main.m  |   8 +
 .../lldb-dap/extendedStackTrace/Makefile  |   5 +
 .../TestDAP_extendedStackTrace.py |  69 +
 .../tools/lldb-dap/extendedStackTrace/main.m  |  28 ++
 .../lldb-dap/stackTrace/TestDAP_stackTrace.py |   4 +-
 .../TestDAP_stackTraceMissingFunctionName.py  |   5 -
 lldb/tools/lldb-dap/DAP.cpp   |   1 -
 lldb/tools/lldb-dap/DAP.h |   2 +-
 lldb/tools/lldb-dap/JSONUtils.cpp |  40 +++
 lldb/tools/lldb-dap/JSONUtils.h   |   3 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 253 +-
 22 files changed, 449 insertions(+), 88 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/cpp/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/exception/cpp/TestDAP_exception_cpp.py
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/cpp/main.cpp
 rename lldb/test/API/tools/lldb-dap/exception/{main.cpp => main.c} (56%)
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/objc/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/exception/objc/TestDAP_exception_objc.py
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/objc/main.m
 create mode 100644 lldb/test/API/tools/lldb-dap/extendedStackTrace/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/extendedStackTrace/TestDAP_extendedStackTrace.py
 create mode 100644 lldb/test/API/tools/lldb-dap/extendedStackTrace/main.m

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 602e15d207e94a..3d8c713562e9bf 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -181,6 +181,22 @@ def findMainThreadCheckerDylib():
 return ""
 
 
+def findBacktraceRecordingDylib():
+if not platformIsDarwin():
+return ""
+
+if getPlatform() in lldbplatform.translate(lldbplatform.darwin_embedded):
+return "/Developer/usr/lib/libBacktraceRecording.dylib"
+
+with os.popen("xcode-select -p") as output:
+xcode_developer_path = output.read().strip()
+mtc_dylib_path = "%s/usr/lib/libBacktraceRecording.dylib" % 
xcode_developer_path
+if os.path.isfile(mtc_dylib_path):
+return mtc_dylib_path
+
+return ""
+
+
 class _PlatformContext(object):
 """Value object class which contains platform-specific options."""
 
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 b095171d8fd1a4..59d0f08bec9a24 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
@@ -707,6 +707,17 @@ def request_evaluate(self, expression, frameIndex=0, 
threadId=None, context=None
 }
 return self.send_recv(command_dict)
 
+def request_exceptionInfo(self, threadId=None):
+if threadId is None:
+threadId = self.get_thread_id()
+args_dict = {"threadId": threadId}
+command_dict = {
+"command": "exceptionInfo",
+"type": "request",
+"arguments": args_dict,
+}
+return self.send_recv(command_dict)
+
 def request_initialize(self, sourceInitFile):
 command_dict = {
 "command": "initialize",
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.

[Lldb-commits] [lldb] [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (PR #102708)

2024-09-10 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] 22144e2 - [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (#102708)

2024-09-10 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2024-09-10T09:58:43-07:00
New Revision: 22144e20cbd237a432fdc4106abe3960555aff42

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

LOG: [LLDB][Data Formatters] Calculate average and total time for summary 
providers within lldb (#102708)

This PR adds a statistics provider cache, which allows an individual
target to keep a rolling tally of it's total time and number of
invocations for a given summary provider. This information is then
available in statistics dump to help slow summary providers, and gleam
more into insight into LLDB's time use.

Added: 
lldb/test/API/commands/statistics/basic/BoxFormatter.py
lldb/test/API/commands/statistics/basic/main.cpp
lldb/unittests/Target/SummaryStatisticsTest.cpp

Modified: 
lldb/include/lldb/DataFormatters/TypeSummary.h
lldb/include/lldb/Target/Statistics.h
lldb/include/lldb/Target/Target.h
lldb/source/Core/ValueObject.cpp
lldb/source/DataFormatters/TypeSummary.cpp
lldb/source/Target/Statistics.cpp
lldb/source/Target/Target.cpp
lldb/test/API/commands/statistics/basic/Makefile
lldb/test/API/commands/statistics/basic/TestStats.py
lldb/unittests/Target/CMakeLists.txt

Removed: 
lldb/test/API/commands/statistics/basic/main.c



diff  --git a/lldb/include/lldb/DataFormatters/TypeSummary.h 
b/lldb/include/lldb/DataFormatters/TypeSummary.h
index a82641021dad36..382824aa2813da 100644
--- a/lldb/include/lldb/DataFormatters/TypeSummary.h
+++ b/lldb/include/lldb/DataFormatters/TypeSummary.h
@@ -258,6 +258,14 @@ class TypeSummaryImpl {
 
   virtual std::string GetDescription() = 0;
 
+  /// Get the name of the Type Summary Provider, either a C++ class, a summary
+  /// string, or a script function name.
+  virtual std::string GetName() = 0;
+
+  /// Get the name of the kind of Summary Provider, either c++, summary string,
+  /// script or python.
+  virtual std::string GetSummaryKindName();
+
   uint32_t &GetRevision() { return m_my_revision; }
 
   typedef std::shared_ptr SharedPointer;
@@ -293,6 +301,8 @@ struct StringSummaryFormat : public TypeSummaryImpl {
 
   std::string GetDescription() override;
 
+  std::string GetName() override;
+
   static bool classof(const TypeSummaryImpl *S) {
 return S->GetKind() == Kind::eSummaryString;
   }
@@ -340,6 +350,8 @@ struct CXXFunctionSummaryFormat : public TypeSummaryImpl {
 return S->GetKind() == Kind::eCallback;
   }
 
+  std::string GetName() override;
+
   typedef std::shared_ptr SharedPointer;
 
 private:
@@ -352,6 +364,7 @@ struct CXXFunctionSummaryFormat : public TypeSummaryImpl {
 struct ScriptSummaryFormat : public TypeSummaryImpl {
   std::string m_function_name;
   std::string m_python_script;
+  std::string m_script_formatter_name;
   StructuredData::ObjectSP m_script_function_sp;
 
   ScriptSummaryFormat(const TypeSummaryImpl::Flags &flags,
@@ -384,6 +397,8 @@ struct ScriptSummaryFormat : public TypeSummaryImpl {
 
   std::string GetDescription() override;
 
+  std::string GetName() override;
+
   static bool classof(const TypeSummaryImpl *S) {
 return S->GetKind() == Kind::eScript;
   }

diff  --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index 5193d099a5494d..f3414ae314f339 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -9,6 +9,7 @@
 #ifndef LLDB_TARGET_STATISTICS_H
 #define LLDB_TARGET_STATISTICS_H
 
+#include "lldb/DataFormatters/TypeSummary.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RealpathPrefixes.h"
 #include "lldb/Utility/Stream.h"
@@ -17,6 +18,7 @@
 #include "llvm/Support/JSON.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +28,9 @@ namespace lldb_private {
 
 using StatsClock = std::chrono::high_resolution_clock;
 using StatsTimepoint = std::chrono::time_point;
+class SummaryStatistics;
+// Declaring here as there is no private forward
+typedef std::shared_ptr SummaryStatisticsSP;
 
 class StatsDuration {
 public:
@@ -175,6 +180,81 @@ struct StatisticsOptions {
   std::optional m_include_transcript;
 };
 
+/// A class that represents statistics about a TypeSummaryProviders invocations
+/// \note All members of this class need to be accessed in a thread safe manner
+class SummaryStatistics {
+public:
+  explicit SummaryStatistics(std::string name, std::string impl_type)
+  : m_total_time(), m_impl_type(std::move(impl_type)),
+m_name(std::move(name)), m_count(0) {}
+
+  std::string GetName() const { return m_name; };
+  double GetTotalTime() const { return m_total_time.get().count(); }
+
+  uint64_t GetSummaryCount() const {
+return m_count.load(std::memory_order_relaxed);
+  }
+
+  StatsDuration &GetDurationReference() { return m_total_time;

[Lldb-commits] [lldb] [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (PR #102708)

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

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


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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

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

2024-09-10 Thread via lldb-commits


@@ -274,8 +274,9 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 
   builder.setEngineKind(llvm::EngineKind::JIT)
   .setErrorStr(&error_string)
-  .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
-  : llvm::Reloc::Static)
+  .setRelocationModel((triple.isOSBinFormatMachO() || triple.isRISCV64())

dlav-sc wrote:

This is not need after large code model has been merged.

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


[Lldb-commits] [lldb] [lldb-dap] Improve `stackTrace` and `exceptionInfo` DAP request handlers (PR #105905)

2024-09-10 Thread John Harrison via lldb-commits

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

>From 6612efb0e51d700eeb545a421a34f7a57aafc509 Mon Sep 17 00:00:00 2001
From: John Harrison 
Date: Fri, 23 Aug 2024 16:04:44 -0700
Subject: [PATCH 1/9] [lldb-dap] Improve `stackTrace` and `exceptionInfo` DAP
 request handlers.

Refactoring `stackTrace` to perform frame look ups in a more on-demand fashion 
to improve overall performance.

Additionally adding additional information to the `exceptionInfo` request to 
report exception stacks there instead of merging the exception stack into the 
stack trace. The `exceptionInfo` request is only called if a stop event occurs 
with `reason='exception'`, which should mitigate the performance of 
`SBThread::GetCurrentException` calls.

Adding unit tests for exception handling and stack trace supporting.
---
 .../Python/lldbsuite/test/lldbplatformutil.py |  16 ++
 .../test/tools/lldb-dap/dap_server.py |  11 +
 .../test/tools/lldb-dap/lldbdap_testcase.py   |   9 +-
 .../API/tools/lldb-dap/exception/Makefile |   2 +-
 .../lldb-dap/exception/TestDAP_exception.py   |   8 +-
 .../API/tools/lldb-dap/exception/cpp/Makefile |   3 +
 .../exception/cpp/TestDAP_exception_cpp.py|  26 ++
 .../API/tools/lldb-dap/exception/cpp/main.cpp |   6 +
 .../lldb-dap/exception/{main.cpp => main.c}   |   2 +-
 .../tools/lldb-dap/exception/objc/Makefile|   9 +
 .../exception/objc/TestDAP_exception_objc.py  |  27 ++
 .../API/tools/lldb-dap/exception/objc/main.m  |   8 +
 .../lldb-dap/extendedStackTrace/Makefile  |   5 +
 .../TestDAP_extendedStackTrace.py |  69 +
 .../tools/lldb-dap/extendedStackTrace/main.m  |  28 ++
 .../lldb-dap/stackTrace/TestDAP_stackTrace.py |   4 +-
 .../TestDAP_stackTraceMissingFunctionName.py  |   5 -
 lldb/tools/lldb-dap/DAP.cpp   |   1 -
 lldb/tools/lldb-dap/DAP.h |   2 +-
 lldb/tools/lldb-dap/JSONUtils.cpp |  40 +++
 lldb/tools/lldb-dap/JSONUtils.h   |   3 +
 lldb/tools/lldb-dap/lldb-dap.cpp  | 253 +-
 22 files changed, 449 insertions(+), 88 deletions(-)
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/cpp/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/exception/cpp/TestDAP_exception_cpp.py
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/cpp/main.cpp
 rename lldb/test/API/tools/lldb-dap/exception/{main.cpp => main.c} (56%)
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/objc/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/exception/objc/TestDAP_exception_objc.py
 create mode 100644 lldb/test/API/tools/lldb-dap/exception/objc/main.m
 create mode 100644 lldb/test/API/tools/lldb-dap/extendedStackTrace/Makefile
 create mode 100644 
lldb/test/API/tools/lldb-dap/extendedStackTrace/TestDAP_extendedStackTrace.py
 create mode 100644 lldb/test/API/tools/lldb-dap/extendedStackTrace/main.m

diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 602e15d207e94a..3d8c713562e9bf 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -181,6 +181,22 @@ def findMainThreadCheckerDylib():
 return ""
 
 
+def findBacktraceRecordingDylib():
+if not platformIsDarwin():
+return ""
+
+if getPlatform() in lldbplatform.translate(lldbplatform.darwin_embedded):
+return "/Developer/usr/lib/libBacktraceRecording.dylib"
+
+with os.popen("xcode-select -p") as output:
+xcode_developer_path = output.read().strip()
+mtc_dylib_path = "%s/usr/lib/libBacktraceRecording.dylib" % 
xcode_developer_path
+if os.path.isfile(mtc_dylib_path):
+return mtc_dylib_path
+
+return ""
+
+
 class _PlatformContext(object):
 """Value object class which contains platform-specific options."""
 
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 b095171d8fd1a4..59d0f08bec9a24 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
@@ -707,6 +707,17 @@ def request_evaluate(self, expression, frameIndex=0, 
threadId=None, context=None
 }
 return self.send_recv(command_dict)
 
+def request_exceptionInfo(self, threadId=None):
+if threadId is None:
+threadId = self.get_thread_id()
+args_dict = {"threadId": threadId}
+command_dict = {
+"command": "exceptionInfo",
+"type": "request",
+"arguments": args_dict,
+}
+return self.send_recv(command_dict)
+
 def request_initialize(self, sourceInitFile):
 command_dict = {
 "command": "initialize",
diff --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.

[Lldb-commits] [lldb] [LLDB] Reapply SBSaveCore Add Memory List (PR #107937)

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


@@ -450,6 +450,8 @@ class RangeDataVector {
 
   void Append(const Entry &entry) { m_entries.emplace_back(entry); }
 
+  void Append(B &&b, S &&s, T &&t) { m_entries.emplace_back(Entry(b, s, t)); }

Jlalond wrote:

Nit to self, add code comments about Base Size And Data

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


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

2024-09-10 Thread via lldb-commits


@@ -0,0 +1,194 @@
+//===--- DirectToIndirectFCR.cpp - RISC-V specific pass 
---===//
+//
+// 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 "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+#include "Plugins/Architecture/RISCV/DirectToIndirectFCR.h"
+
+#include "lldb/Core/Architecture.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Symbol/Symtab.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+
+#include 
+
+using namespace llvm;
+using namespace lldb_private;
+
+namespace {
+std::string GetValueTypeStr(const llvm::Type *value_ty) {
+  assert(value_ty);
+  std::string str_type;
+  llvm::raw_string_ostream rso(str_type);
+  value_ty->print(rso);
+  return rso.str();
+}
+
+template  void LogMessage(const char *msg, Args &&...args) {
+  Log *log = GetLog(LLDBLog::Expressions);
+  LLDB_LOG(log, msg, std::forward(args)...);
+}
+} // namespace
+
+bool DirectToIndirectFCR::canBeReplaced(const llvm::CallInst *ci) {
+  assert(ci);
+  auto *return_value_ty = ci->getType();
+  if (!(return_value_ty->isIntegerTy() || return_value_ty->isVoidTy())) {
+LogMessage("DirectToIndirectFCR: function {0} has unsupported "
+   "return type ({1})\n",
+   ci->getCalledFunction()->getName(),
+   GetValueTypeStr(return_value_ty));
+return false;
+  }
+
+  const auto *arg = llvm::find_if_not(ci->args(), [](const auto &arg) {
+const auto *type = arg->getType();
+return type->isIntegerTy();
+  });
+
+  if (arg != ci->arg_end()) {
+LogMessage("DirectToIndirectFCR: argument {0} of {1} function "
+   "has unsupported type ({2})\n",
+   (*arg)->getName(), ci->getCalledFunction()->getName(),
+   GetValueTypeStr((*arg)->getType()));
+return false;
+  }
+  return true;
+}
+
+std::vector
+DirectToIndirectFCR::getFunctionArgsAsValues(const llvm::CallInst *ci) {
+  assert(ci);
+  std::vector args{};
+  llvm::transform(ci->args(), std::back_inserter(args),
+  [](const auto &arg) { return arg.get(); });
+  return args;
+}
+
+std::optional
+DirectToIndirectFCR::getFunctionAddress(const llvm::CallInst *ci) const {
+  auto *target = m_exe_ctx.GetTargetPtr();

dlav-sc wrote:

Large code model has been merged, so DirectToIndirectFCR pass is deprecated.

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


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

2024-09-10 Thread via lldb-commits

dlav-sc wrote:

> Also Large Code Model for RISCV targets has been merged 2 days ago (#70308), 
> so I'm going to remove DirectCallReplacementPass and use large model in MCJIT 
> instead.

I've removed DirectCallReplacementPass and added large code model instead.

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


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

2024-09-10 Thread via lldb-commits

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

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

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

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

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

[Lldb-commits] [lldb] [LLDB] Fix operators <= and >= returning a wrong result when comparing to a floating point NaN (PR #108060)

2024-09-10 Thread Ilia Kuklin via lldb-commits

https://github.com/kuilpd created 
https://github.com/llvm/llvm-project/pull/108060

Implement operators `<=` and `>=` to explicitly check the comparison results to 
be `cmpLessThan` or `cmpEqual` instead of negating the result of `operators<`.

Fixes #85947 

>From 1e83cdfeb7e3a6fba4b190e95dd794723031370d Mon Sep 17 00:00:00 2001
From: Ilia Kuklin 
Date: Tue, 3 Sep 2024 03:08:48 +0500
Subject: [PATCH] Implement operators <= and >= and add a test

---
 lldb/include/lldb/Utility/Scalar.h|   8 +-
 lldb/source/Utility/Scalar.cpp|  38 ++-
 lldb/test/API/lang/cpp/fpnan/Makefile |   3 +
 lldb/test/API/lang/cpp/fpnan/TestFPNaN.py | 130 ++
 lldb/test/API/lang/cpp/fpnan/main.cpp |   8 ++
 5 files changed, 179 insertions(+), 8 deletions(-)
 create mode 100644 lldb/test/API/lang/cpp/fpnan/Makefile
 create mode 100644 lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
 create mode 100644 lldb/test/API/lang/cpp/fpnan/main.cpp

diff --git a/lldb/include/lldb/Utility/Scalar.h 
b/lldb/include/lldb/Utility/Scalar.h
index 0d8eba3c9726d5..a8fe7fee3a2b9f 100644
--- a/lldb/include/lldb/Utility/Scalar.h
+++ b/lldb/include/lldb/Utility/Scalar.h
@@ -223,9 +223,9 @@ class Scalar {
   friend bool operator==(Scalar lhs, Scalar rhs);
   friend bool operator!=(const Scalar &lhs, const Scalar &rhs);
   friend bool operator<(Scalar lhs, Scalar rhs);
-  friend bool operator<=(const Scalar &lhs, const Scalar &rhs);
+  friend bool operator<=(Scalar lhs, Scalar rhs);
   friend bool operator>(const Scalar &lhs, const Scalar &rhs);
-  friend bool operator>=(const Scalar &lhs, const Scalar &rhs);
+  friend bool operator>=(Scalar lhs, Scalar rhs);
 };
 
 // Split out the operators into a format where the compiler will be able to
@@ -254,9 +254,9 @@ const Scalar operator>>(const Scalar &lhs, const Scalar 
&rhs);
 bool operator==(Scalar lhs, Scalar rhs);
 bool operator!=(const Scalar &lhs, const Scalar &rhs);
 bool operator<(Scalar lhs, Scalar rhs);
-bool operator<=(const Scalar &lhs, const Scalar &rhs);
+bool operator<=(Scalar lhs, Scalar rhs);
 bool operator>(const Scalar &lhs, const Scalar &rhs);
-bool operator>=(const Scalar &lhs, const Scalar &rhs);
+bool operator>=(Scalar lhs, Scalar rhs);
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Scalar &scalar);
 
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 329f5b6e4b9a5b..bdbd79d375a4f7 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -893,16 +893,46 @@ bool lldb_private::operator<(Scalar lhs, Scalar rhs) {
   return false;
 }
 
-bool lldb_private::operator<=(const Scalar &lhs, const Scalar &rhs) {
-  return !(rhs < lhs);
+bool lldb_private::operator<=(Scalar lhs, Scalar rhs) {
+  if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+return false;
+
+  llvm::APFloat::cmpResult result;
+  switch (Scalar::PromoteToMaxType(lhs, rhs)) {
+  case Scalar::e_void:
+break;
+  case Scalar::e_int:
+return lhs.m_integer <= rhs.m_integer;
+  case Scalar::e_float:
+result = lhs.m_float.compare(rhs.m_float);
+if (result == llvm::APFloat::cmpLessThan ||
+result == llvm::APFloat::cmpEqual)
+  return true;
+  }
+  return false;
 }
 
 bool lldb_private::operator>(const Scalar &lhs, const Scalar &rhs) {
   return rhs < lhs;
 }
 
-bool lldb_private::operator>=(const Scalar &lhs, const Scalar &rhs) {
-  return !(lhs < rhs);
+bool lldb_private::operator>=(Scalar lhs, Scalar rhs) {
+  if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+return false;
+
+  llvm::APFloat::cmpResult result;
+  switch (Scalar::PromoteToMaxType(lhs, rhs)) {
+  case Scalar::e_void:
+break;
+  case Scalar::e_int:
+return lhs.m_integer >= rhs.m_integer;
+  case Scalar::e_float:
+result = lhs.m_float.compare(rhs.m_float);
+if (result == llvm::APFloat::cmpGreaterThan ||
+result == llvm::APFloat::cmpEqual)
+  return true;
+  }
+  return false;
 }
 
 bool Scalar::ClearBit(uint32_t bit) {
diff --git a/lldb/test/API/lang/cpp/fpnan/Makefile 
b/lldb/test/API/lang/cpp/fpnan/Makefile
new file mode 100644
index 00..8b20bcb050
--- /dev/null
+++ b/lldb/test/API/lang/cpp/fpnan/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py 
b/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
new file mode 100644
index 00..6093ef91ac1f03
--- /dev/null
+++ b/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
@@ -0,0 +1,130 @@
+"""
+Test floating point expressions with zero, NaN, dernormalized and infinite
+numbers.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class FPNaNTestCase(TestBase):
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to break inside main().
+self.line = line_number("main.cpp", "// Set break point at this line.")
+
+ 

[Lldb-commits] [lldb] [LLDB] Fix operators <= and >= returning a wrong result when comparing to a floating point NaN (PR #108060)

2024-09-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Ilia Kuklin (kuilpd)


Changes

Implement operators `<=` and `>=` to explicitly check the comparison 
results to be `cmpLessThan` or `cmpEqual` instead of negating the result of 
`operators<`.

Fixes #85947 

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


5 Files Affected:

- (modified) lldb/include/lldb/Utility/Scalar.h (+4-4) 
- (modified) lldb/source/Utility/Scalar.cpp (+34-4) 
- (added) lldb/test/API/lang/cpp/fpnan/Makefile (+3) 
- (added) lldb/test/API/lang/cpp/fpnan/TestFPNaN.py (+130) 
- (added) lldb/test/API/lang/cpp/fpnan/main.cpp (+8) 


``diff
diff --git a/lldb/include/lldb/Utility/Scalar.h 
b/lldb/include/lldb/Utility/Scalar.h
index 0d8eba3c9726d5..a8fe7fee3a2b9f 100644
--- a/lldb/include/lldb/Utility/Scalar.h
+++ b/lldb/include/lldb/Utility/Scalar.h
@@ -223,9 +223,9 @@ class Scalar {
   friend bool operator==(Scalar lhs, Scalar rhs);
   friend bool operator!=(const Scalar &lhs, const Scalar &rhs);
   friend bool operator<(Scalar lhs, Scalar rhs);
-  friend bool operator<=(const Scalar &lhs, const Scalar &rhs);
+  friend bool operator<=(Scalar lhs, Scalar rhs);
   friend bool operator>(const Scalar &lhs, const Scalar &rhs);
-  friend bool operator>=(const Scalar &lhs, const Scalar &rhs);
+  friend bool operator>=(Scalar lhs, Scalar rhs);
 };
 
 // Split out the operators into a format where the compiler will be able to
@@ -254,9 +254,9 @@ const Scalar operator>>(const Scalar &lhs, const Scalar 
&rhs);
 bool operator==(Scalar lhs, Scalar rhs);
 bool operator!=(const Scalar &lhs, const Scalar &rhs);
 bool operator<(Scalar lhs, Scalar rhs);
-bool operator<=(const Scalar &lhs, const Scalar &rhs);
+bool operator<=(Scalar lhs, Scalar rhs);
 bool operator>(const Scalar &lhs, const Scalar &rhs);
-bool operator>=(const Scalar &lhs, const Scalar &rhs);
+bool operator>=(Scalar lhs, Scalar rhs);
 
 llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Scalar &scalar);
 
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index 329f5b6e4b9a5b..bdbd79d375a4f7 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -893,16 +893,46 @@ bool lldb_private::operator<(Scalar lhs, Scalar rhs) {
   return false;
 }
 
-bool lldb_private::operator<=(const Scalar &lhs, const Scalar &rhs) {
-  return !(rhs < lhs);
+bool lldb_private::operator<=(Scalar lhs, Scalar rhs) {
+  if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+return false;
+
+  llvm::APFloat::cmpResult result;
+  switch (Scalar::PromoteToMaxType(lhs, rhs)) {
+  case Scalar::e_void:
+break;
+  case Scalar::e_int:
+return lhs.m_integer <= rhs.m_integer;
+  case Scalar::e_float:
+result = lhs.m_float.compare(rhs.m_float);
+if (result == llvm::APFloat::cmpLessThan ||
+result == llvm::APFloat::cmpEqual)
+  return true;
+  }
+  return false;
 }
 
 bool lldb_private::operator>(const Scalar &lhs, const Scalar &rhs) {
   return rhs < lhs;
 }
 
-bool lldb_private::operator>=(const Scalar &lhs, const Scalar &rhs) {
-  return !(lhs < rhs);
+bool lldb_private::operator>=(Scalar lhs, Scalar rhs) {
+  if (lhs.m_type == Scalar::e_void || rhs.m_type == Scalar::e_void)
+return false;
+
+  llvm::APFloat::cmpResult result;
+  switch (Scalar::PromoteToMaxType(lhs, rhs)) {
+  case Scalar::e_void:
+break;
+  case Scalar::e_int:
+return lhs.m_integer >= rhs.m_integer;
+  case Scalar::e_float:
+result = lhs.m_float.compare(rhs.m_float);
+if (result == llvm::APFloat::cmpGreaterThan ||
+result == llvm::APFloat::cmpEqual)
+  return true;
+  }
+  return false;
 }
 
 bool Scalar::ClearBit(uint32_t bit) {
diff --git a/lldb/test/API/lang/cpp/fpnan/Makefile 
b/lldb/test/API/lang/cpp/fpnan/Makefile
new file mode 100644
index 00..8b20bcb050
--- /dev/null
+++ b/lldb/test/API/lang/cpp/fpnan/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py 
b/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
new file mode 100644
index 00..6093ef91ac1f03
--- /dev/null
+++ b/lldb/test/API/lang/cpp/fpnan/TestFPNaN.py
@@ -0,0 +1,130 @@
+"""
+Test floating point expressions with zero, NaN, dernormalized and infinite
+numbers.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class FPNaNTestCase(TestBase):
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Find the line number to break inside main().
+self.line = line_number("main.cpp", "// Set break point at this line.")
+
+def test(self):
+self.build()
+exe = self.getBuildArtifact("a.out")
+self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+# Break inside the main.
+lldbutil.run_break_set_by_file_and_line(
+self, "main.cpp", self.line, num_expected_locations=1
+)
+
+se

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

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


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

Michael137 wrote:

does this need to live in the header?

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


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

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


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

Michael137 wrote:

```suggestion
  for (auto [idx, arg] : enumerate(args)) {
```

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


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

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


@@ -471,6 +498,18 @@ static void SetupTargetOpts(CompilerInstance &compiler,
   // Set the target ABI
   if (std::string abi = GetClangTargetABI(target_arch); !abi.empty())
 compiler.getTargetOpts().ABI = std::move(abi);
+
+  if ((target_machine == llvm::Triple::riscv64 &&
+   compiler.getTargetOpts().ABI == "lp64f") ||
+  (target_machine == llvm::Triple::riscv32 &&
+   compiler.getTargetOpts().ABI == "ilp32f"))
+compiler->getTargetOpts().FeaturesAsWritten.emplace_back("+f");
+
+  if ((target_machine == llvm::Triple::riscv64 &&
+   compiler.getTargetOpts().ABI == "lp64d") ||
+  (target_machine == llvm::Triple::riscv32 &&
+   compiler.getTargetOpts().ABI == "ilp32d"))
+compiler->getTargetOpts().FeaturesAsWritten.emplace_back("+d");

Michael137 wrote:

What happens if we just unconditionally add `+d` and `+f`? I'm not super 
familiar with RISCV but are ilp32d/ilp32f/ilp64f/ilp32f all the supported ABI 
strings? The GCC docs also seem to mention `rv64ifd`, e.g.. So my thinking is 
that we could maybe just enable these features for all targets (like we do with 
x86 sse?)

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


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

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


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

Michael137 wrote:

Could make `log` a reference

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


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

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

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


[Lldb-commits] [lldb] [llvm] [lldb]Implement LLDB Telemetry (PR #98528)

2024-09-10 Thread Vy Nguyen via lldb-commits


@@ -754,6 +760,7 @@ class Debugger : public 
std::enable_shared_from_this,
   uint32_t m_interrupt_requested = 0; ///< Tracks interrupt requests
   std::mutex m_interrupt_mutex;
 
+  std::shared_ptr m_telemeter;

oontvoo wrote:

The use of  "shared_ptr" here is to ensure the object can be "shared" with 
different parts of the code - and not so much about the telemter outliving its 
debugger.

But I suppose we can make it a unique_ptr and just share the raw pointer 
around, if you prefer?

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


[Lldb-commits] [lldb] [LLDB] Reapply SBSaveCore Add Memory List (PR #107937)

2024-09-10 Thread Greg Clayton via lldb-commits

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


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


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

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


@@ -170,12 +215,8 @@ class Status {
   bool Success() const;
 
 protected:
-  Status(llvm::Error error);
-  /// Status code as an integer value.
-  ValueType m_code = 0;
-  /// The type of the above error code.
-  lldb::ErrorType m_type = lldb::eErrorTypeInvalid;
-  /// A string representation of the error code.
+  Status(llvm::Error error) : m_error(std::move(error)) {}
+  mutable llvm::Error m_error;

adrian-prantl wrote:

Done.

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


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

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

https://github.com/adrian-prantl updated 
https://github.com/llvm/llvm-project/pull/106774

>From 31f3217635d937f5c3ff2733eb34905d63714085 Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 4 Sep 2024 12:50:37 -0700
Subject: [PATCH] [lldb] Change the implementation of Status to store an
 llvm::Error (NFC)

Most APIs that currently vend a Status would be better served by
returning llvm::Expected<> instead. Where possible, APIs should be
refactored to avoid Status. The only legitimate long-term uses of
Status are objects that need to store an error for a long time (which
should be questioned as a design decision, too).

This patch makes the transition to llvm::Error easier by making the
places that cannot switch to llvm::Error explicit: They are marked
with a call to Status::clone(). Every other API can and should be
refactored to use llvm::Expected. In the end Status should only be
used in very few places.

Whenever an unchecked Error is dropped by Status it logs this to the
verbose API channel.

Implementation notes:

This patch introduces two new kinds of error_category as well as new
llvm::Error types. Here is the mapping of lldb::ErrorType to
llvm::Errors:

   (eErrorTypeInvalid)
   eErrorTypeGeneric  llvm::StringError
   eErrorTypePOSIXllvm::ECError
   eErrorTypeMachKernel   MachKernelError
   eErrorTypeExpression   llvm::ErrorList
   eErrorTypeWin32Win32Error
---
 lldb/include/lldb/Utility/Status.h |  74 +++--
 lldb/source/Utility/Status.cpp | 252 -
 2 files changed, 238 insertions(+), 88 deletions(-)

diff --git a/lldb/include/lldb/Utility/Status.h 
b/lldb/include/lldb/Utility/Status.h
index 795c830b965173..46b980e36700c7 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -28,6 +28,66 @@ namespace lldb_private {
 
 const char *ExpressionResultAsCString(lldb::ExpressionResults result);
 
+/// Going a bit against the spirit of llvm::Error,
+/// lldb_private::Status need to store errors long-term and sometimes
+/// copy them. This base class defines an interface for this
+/// operation.
+class CloneableError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableError() : ErrorInfo() {}
+  virtual std::unique_ptr Clone() const = 0;
+  static char ID;
+};
+
+/// Common base class for all error-code errors.
+class CloneableECError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableECError(std::error_code ec) : ErrorInfo() {}
+  std::error_code convertToErrorCode() const override { return EC; }
+  void log(llvm::raw_ostream &OS) const override { OS << EC.message(); }
+  static char ID;
+
+protected:
+  std::error_code EC;
+};
+
+/// FIXME: Move these declarations closer to where they're used.
+class MachKernelError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  MachKernelError(std::error_code ec) : ErrorInfo(ec) {}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class Win32Error : public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  Win32Error(std::error_code ec, const llvm::Twine &msg = {}) : ErrorInfo(ec) 
{}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class ExpressionError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  ExpressionError(std::error_code ec, std::string msg = {})
+  : ErrorInfo(ec), m_string(msg) {}
+  std::unique_ptr Clone() const override;
+  static char ID;
+
+protected:
+  std::string m_string;
+};
+
 /// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
 ///
 /// This class is designed to be able to hold any error code that can be
@@ -100,9 +160,7 @@ class Status {
   }
 
   static Status FromExpressionError(lldb::ExpressionResults result,
-std::string msg) {
-return Status(result, lldb::eErrorTypeExpression, msg);
-  }
+std::string msg);
 
   /// Set the current error to errno.
   ///
@@ -115,6 +173,7 @@ class Status {
   const Status &operator=(Status &&);
   /// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
   static Status FromError(llvm::Error error);
+
   /// FIXME: Replace this with a takeError() method.
   llvm::Error ToError() const;
   /// Don't call this function in new code. Instead, redesign the API
@@ -170,12 +229,9 @@ class Status {
   bool Success() const;
 
 protected:
-  Status(llvm::Error error);
-  /// Status code as an integer value.
-  ValueType m_code = 0;
-  /// The type of the above error code.
-  lldb::ErrorType m_type = lldb::eErrorTypeInvalid;
-  /// A string representation of the error code.
+  Status(llvm::Error error) : m_error(std::move(error)) {}
+  llvm::Error m_error;
+  /// TODO: Replace this with just callling toSt

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

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

https://github.com/adrian-prantl updated 
https://github.com/llvm/llvm-project/pull/106774

>From 0091613ba2ab277d469d946fdce605d6afc0596d Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 4 Sep 2024 12:50:37 -0700
Subject: [PATCH] [lldb] Change the implementation of Status to store an
 llvm::Error (NFC)

Most APIs that currently vend a Status would be better served by
returning llvm::Expected<> instead. Where possible, APIs should be
refactored to avoid Status. The only legitimate long-term uses of
Status are objects that need to store an error for a long time (which
should be questioned as a design decision, too).

This patch makes the transition to llvm::Error easier by making the
places that cannot switch to llvm::Error explicit: They are marked
with a call to Status::clone(). Every other API can and should be
refactored to use llvm::Expected. In the end Status should only be
used in very few places.

Whenever an unchecked Error is dropped by Status it logs this to the
verbose API channel.

Implementation notes:

This patch introduces two new kinds of error_category as well as new
llvm::Error types. Here is the mapping of lldb::ErrorType to
llvm::Errors:

   (eErrorTypeInvalid)
   eErrorTypeGeneric  llvm::StringError
   eErrorTypePOSIXllvm::ECError
   eErrorTypeMachKernel   MachKernelError
   eErrorTypeExpression   llvm::ErrorList
   eErrorTypeWin32Win32Error
---
 lldb/include/lldb/Utility/Status.h |  75 +++--
 lldb/source/Utility/Status.cpp | 249 -
 2 files changed, 236 insertions(+), 88 deletions(-)

diff --git a/lldb/include/lldb/Utility/Status.h 
b/lldb/include/lldb/Utility/Status.h
index 795c830b965173..169326eccef450 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -28,6 +28,67 @@ namespace lldb_private {
 
 const char *ExpressionResultAsCString(lldb::ExpressionResults result);
 
+/// Going a bit against the spirit of llvm::Error,
+/// lldb_private::Status need to store errors long-term and sometimes
+/// copy them. This base class defines an interface for this
+/// operation.
+class CloneableError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableError() : ErrorInfo() {}
+  virtual std::unique_ptr Clone() const = 0;
+  static char ID;
+};
+
+/// Common base class for all error-code errors.
+class CloneableECError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableECError(std::error_code ec) : ErrorInfo() {}
+  std::error_code convertToErrorCode() const override { return EC; }
+  void log(llvm::raw_ostream &OS) const override { OS << EC.message(); }
+  static char ID;
+
+protected:
+  std::error_code EC;
+};
+
+/// FIXME: Move these declarations closer to where they're used.
+class MachKernelError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  MachKernelError(std::error_code ec) : ErrorInfo(ec) {}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class Win32Error : public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  Win32Error(std::error_code ec, const llvm::Twine &msg = {}) : ErrorInfo(ec) 
{}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class ExpressionError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  ExpressionError(std::error_code ec, std::string msg = {})
+  : ErrorInfo(ec), m_string(msg) {}
+  std::unique_ptr Clone() const override;
+  std::string message() const override { return m_string; }
+  static char ID;
+
+protected:
+  std::string m_string;
+};
+
 /// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
 ///
 /// This class is designed to be able to hold any error code that can be
@@ -100,9 +161,7 @@ class Status {
   }
 
   static Status FromExpressionError(lldb::ExpressionResults result,
-std::string msg) {
-return Status(result, lldb::eErrorTypeExpression, msg);
-  }
+std::string msg);
 
   /// Set the current error to errno.
   ///
@@ -115,6 +174,7 @@ class Status {
   const Status &operator=(Status &&);
   /// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
   static Status FromError(llvm::Error error);
+
   /// FIXME: Replace this with a takeError() method.
   llvm::Error ToError() const;
   /// Don't call this function in new code. Instead, redesign the API
@@ -170,12 +230,9 @@ class Status {
   bool Success() const;
 
 protected:
-  Status(llvm::Error error);
-  /// Status code as an integer value.
-  ValueType m_code = 0;
-  /// The type of the above error code.
-  lldb::ErrorType m_type = lldb::eErrorTypeInvalid;
-  /// A string representation of the error code.
+  Status(llvm::Error error) : m_error(std::move(error)) {}
+  llvm::Err

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

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


@@ -37,48 +39,75 @@ class raw_ostream;
 using namespace lldb;
 using namespace lldb_private;
 
-Status::Status() {}
+char CloneableError::ID;
+char MachKernelError::ID;
+char Win32Error::ID;
+char ExpressionError::ID;
+
+namespace {
+/// A std::error_code category for eErrorTypeGeneric.
+class GenericCategory : public std::error_category {
+  const char *name() const override { return "LLDBGenericCategory"; }
+  std::string message(int __ev) const override { return "generic LLDB error"; 
};
+};
+GenericCategory &generic_category() {
+  static GenericCategory g_generic_category;
+  return g_generic_category;
+}
+
+/// A std::error_code category for eErrorTypeExpression.
+class ExpressionCategory : public std::error_category {
+  const char *name() const override { return "LLDBExpressionCategory"; }
+  std::string message(int __ev) const override {
+return 
ExecutionResultAsCString(static_cast(__ev));
+  };
+};
+ExpressionCategory &expression_category() {
+  static ExpressionCategory g_expression_category;
+  return g_expression_category;
+}
+} // namespace
+
+Status::Status() : m_error(llvm::Error::success()) {}
+
+static llvm::Error ErrorFromEnums(Status::ValueType err, ErrorType type,
+  std::string msg) {
+  switch (type) {
+  case eErrorTypeMachKernel:
+return llvm::make_error(
+std::error_code(err, std::system_category()), msg);
+  case eErrorTypePOSIX:
+return llvm::errorCodeToError(
+std::error_code(err, std::generic_category()));
+  case eErrorTypeWin32:
+return llvm::make_error(
+std::error_code(err, std::system_category()), msg);
+  default:
+return llvm::createStringError(std::move(msg),
+   std::error_code(err, generic_category()));
+  }
+}
 
 Status::Status(ValueType err, ErrorType type, std::string msg)
-: m_code(err), m_type(type), m_string(std::move(msg)) {}
+: m_error(ErrorFromEnums(err, type, msg)) {}
 
-// This logic is confusing because c++ calls the traditional (posix) errno 
codes
+// This logic is confusing because C++ calls the traditional (posix) errno 
codes
 // "generic errors", while we use the term "generic" to mean completely
 // arbitrary (text-based) errors.
 Status::Status(std::error_code EC)
-: m_code(EC.value()),
-  m_type(EC.category() == std::generic_category() ? eErrorTypePOSIX
-  : eErrorTypeGeneric),
-  m_string(EC.message()) {}
+: m_error(!EC ? llvm::Error::success()
+  : (EC.category() == std::generic_category()
+ ? llvm::errorCodeToError(EC)
+ : llvm::createStringError(EC, "generic error"))) {}

adrian-prantl wrote:

You are right. This is no longer needed.

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


[Lldb-commits] [lldb] [lldb][lldb-dap] Added readMemory and WriteMemory, var type correction (PR #108036)

2024-09-10 Thread Jennifer Phillips via lldb-commits

https://github.com/jennphilqc updated 
https://github.com/llvm/llvm-project/pull/108036

>From b7e59ca0739240796b89b3d114d6c96c3b09c687 Mon Sep 17 00:00:00 2001
From: Jennifer Phillips 
Date: Tue, 27 Aug 2024 10:48:37 -0700
Subject: [PATCH 1/2] Added readMemory and WriteMemory, var type correction

---
 lldb/tools/lldb-dap/lldb-dap.cpp | 237 +++
 1 file changed, 237 insertions(+)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c5c4b09f15622b..8aed6d1a432b84 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -39,6 +40,7 @@
 #include 
 #endif
 
+#include "lldb/lldb-types.h"
 #include 
 #include 
 #include 
@@ -61,6 +63,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Support/Base64.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
@@ -1725,6 +1728,10 @@ void request_initialize(const llvm::json::Object 
&request) {
   body.try_emplace("supportsDataBreakpoints", true);
   // The debug adapter support for instruction breakpoint.
   body.try_emplace("supportsInstructionBreakpoints", true);
+  // The debug adapter support for read.
+  body.try_emplace("supportsReadMemoryRequest", true);
+  // The debug adapter support for write.
+  body.try_emplace("supportsWriteMemoryRequest", true);
 
   // Put in non-DAP specification lldb specific information.
   llvm::json::Object lldb_json;
@@ -4332,6 +4339,232 @@ void request_setInstructionBreakpoints(const 
llvm::json::Object &request) {
   g_dap.SendJSON(llvm::json::Value(std::move(response)));
 }
 
+// "ReadMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Reads bytes from memory at the provided location.\n
+// Clients should only call this request if the corresponding capability
+// `supportsReadMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "readMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/ReadMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "ReadMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `readMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location from which data
+//   should be read."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before reading data. Can be negative."
+// },
+// "count": {
+//   "type": "integer",
+//   "description": "Number of bytes to read at the specified location and
+//   offset."
+// }
+//   },
+//   "required": [ "memoryReference", "count" ]
+// },
+// "ReadMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `readMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "address": {
+// "type": "string",
+// "description": "The address of the first byte of data returned.
+// \nTreated as a hex value if prefixed with `0x`, or as a decimal
+// value otherwise."
+//   },
+//   "unreadableBytes": {
+// "type": "integer",
+// "description": "The number of unreadable bytes encountered after
+// the last successfully read byte.\nThis can be used to determine
+// the number of bytes that should be skipped before a subsequent
+// `readMemory` request succeeds."
+//   },
+//   "data": {
+// "type": "string",
+// "description": "The bytes read from memory, encoded using
+// base64. If the decoded length of `data` is less than the
+// requested `count` in the original `readMemory` request, and
+// `unreadableBytes` is zero or omitted, then the client should
+// assume it's reached the end of readable memory."
+//   }
+// },
+// "required": [ "address" ]
+//   }
+// }
+//   }]
+// },
+void request_readMemory(const llvm::json::Object &request) {
+  llvm::json::Object response;
+  llvm::json::Array response_readMemory;
+  llvm::json::Object body;
+  lldb::SBError error;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference = GetString(arguments, "memoryReference");
+  const size_t count = GetUnsigned(arguments, "count", 0);
+  const a

[Lldb-commits] [lldb] [LLDB] Reapply SBSaveCore Add Memory List (PR #107937)

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

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

>From 2bdc8c0bd8b92989420b798d90e47f27d8a06e66 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde 
Date: Mon, 9 Sep 2024 13:54:37 -0700
Subject: [PATCH 1/5] Reapply "[LLDB] Reappply SBSaveCore AddMemoryList"
 (#107731)

This reverts commit bb343468ffa8c2190fcdd0f704d370c75d3b5edd.
---
 lldb/include/lldb/API/SBMemoryRegionInfo.h|   2 +-
 lldb/include/lldb/API/SBSaveCoreOptions.h |  11 ++
 lldb/include/lldb/Symbol/SaveCoreOptions.h|  11 +-
 .../lldb/Target/CoreFileMemoryRanges.h|  50 ++
 lldb/include/lldb/Target/Process.h|  25 +--
 lldb/include/lldb/Utility/RangeMap.h  |   2 +
 lldb/include/lldb/lldb-enumerations.h |   1 +
 lldb/include/lldb/lldb-forward.h  |   1 +
 lldb/include/lldb/lldb-private-interfaces.h   |   1 -
 lldb/source/API/SBSaveCoreOptions.cpp |  11 ++
 lldb/source/Commands/CommandObjectProcess.cpp |   1 +
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp |   6 +-
 .../ObjectFile/Mach-O/ObjectFileMachO.h   |   1 +
 .../Minidump/MinidumpFileBuilder.cpp  |  35 ++--
 .../ObjectFile/Minidump/MinidumpFileBuilder.h |   5 +-
 .../ObjectFile/Minidump/ObjectFileMinidump.h  |   1 +
 .../ObjectFile/PECOFF/ObjectFilePECOFF.cpp|   1 +
 .../ObjectFile/PECOFF/ObjectFilePECOFF.h  |   1 +
 lldb/source/Symbol/SaveCoreOptions.cpp|  14 ++
 lldb/source/Target/CMakeLists.txt |   1 +
 lldb/source/Target/CoreFileMemoryRanges.cpp   |  49 ++
 lldb/source/Target/Process.cpp|  75 ++---
 .../TestProcessSaveCoreMinidump.py| 149 ++
 lldb/unittests/Process/Utility/CMakeLists.txt |   1 +
 .../Utility/CoreFileMemoryRangesTest.cpp  | 108 +
 25 files changed, 496 insertions(+), 67 deletions(-)
 create mode 100644 lldb/include/lldb/Target/CoreFileMemoryRanges.h
 create mode 100644 lldb/source/Target/CoreFileMemoryRanges.cpp
 create mode 100644 lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp

diff --git a/lldb/include/lldb/API/SBMemoryRegionInfo.h 
b/lldb/include/lldb/API/SBMemoryRegionInfo.h
index be55de4ead1fa8..f9a5dc993d7cb6 100644
--- a/lldb/include/lldb/API/SBMemoryRegionInfo.h
+++ b/lldb/include/lldb/API/SBMemoryRegionInfo.h
@@ -120,7 +120,7 @@ class LLDB_API SBMemoryRegionInfo {
 private:
   friend class SBProcess;
   friend class SBMemoryRegionInfoList;
-
+  friend class SBSaveCoreOptions;
   friend class lldb_private::ScriptInterpreter;
 
   lldb_private::MemoryRegionInfo &ref();
diff --git a/lldb/include/lldb/API/SBSaveCoreOptions.h 
b/lldb/include/lldb/API/SBSaveCoreOptions.h
index ba48ba5eaea5a0..c076d3ce6f7575 100644
--- a/lldb/include/lldb/API/SBSaveCoreOptions.h
+++ b/lldb/include/lldb/API/SBSaveCoreOptions.h
@@ -80,6 +80,17 @@ class LLDB_API SBSaveCoreOptions {
   /// \return True if the thread was removed, false if it was not in the list.
   bool RemoveThread(lldb::SBThread thread);
 
+  /// Add a memory region to save in the core file.
+  ///
+  /// \param region The memory region to save.
+  /// \returns An empty SBError upon success, or an error if the region is
+  /// invalid.
+  /// \note Ranges that overlapped will be unioned into a single region, this
+  /// also supercedes stack minification. Specifying full regions and a
+  /// non-custom core style will include the specified regions and union them
+  /// with all style specific regions.
+  SBError AddMemoryRegionToSave(const SBMemoryRegionInfo ®ion);
+
   /// Reset all options.
   void Clear();
 
diff --git a/lldb/include/lldb/Symbol/SaveCoreOptions.h 
b/lldb/include/lldb/Symbol/SaveCoreOptions.h
index f4fed4676fa4ae..d90d08026016dc 100644
--- a/lldb/include/lldb/Symbol/SaveCoreOptions.h
+++ b/lldb/include/lldb/Symbol/SaveCoreOptions.h
@@ -10,13 +10,15 @@
 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_SaveCoreOPTIONS_H
 
 #include "lldb/Utility/FileSpec.h"
-#include "lldb/lldb-forward.h"
-#include "lldb/lldb-types.h"
+#include "lldb/Utility/RangeMap.h"
 
 #include 
+#include 
 #include 
 #include 
 
+using MemoryRanges = lldb_private::RangeVector;
+
 namespace lldb_private {
 
 class SaveCoreOptions {
@@ -38,8 +40,12 @@ class SaveCoreOptions {
   Status AddThread(lldb::ThreadSP thread_sp);
   bool RemoveThread(lldb::ThreadSP thread_sp);
   bool ShouldThreadBeSaved(lldb::tid_t tid) const;
+  bool HasSpecifiedThreads() const;
 
   Status EnsureValidConfiguration(lldb::ProcessSP process_sp) const;
+  const MemoryRanges &GetCoreFileMemoryRanges() const;
+
+  void AddMemoryRegionToSave(const lldb_private::MemoryRegionInfo ®ion);
 
   void Clear();
 
@@ -51,6 +57,7 @@ class SaveCoreOptions {
   std::optional m_style;
   lldb::ProcessSP m_process_sp;
   std::unordered_set m_threads_to_save;
+  MemoryRanges m_regions_to_save;
 };
 } // namespace lldb_private
 
diff --git a/lldb/include/lldb/Target/CoreFileMemoryRanges.h 
b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
new file mode 100644
index 000

[Lldb-commits] [lldb] [LLDB] Reapply SBSaveCore Add Memory List (PR #107937)

2024-09-10 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 6f8d2781f604cfcf9ea6facecc0bea8e4d682e1e 
f172f08473d9aee702829c46fdb6cb26ec67c331 --extensions cpp,h -- 
lldb/include/lldb/Target/CoreFileMemoryRanges.h 
lldb/source/Target/CoreFileMemoryRanges.cpp 
lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp 
lldb/include/lldb/API/SBMemoryRegionInfo.h 
lldb/include/lldb/API/SBSaveCoreOptions.h 
lldb/include/lldb/Symbol/SaveCoreOptions.h lldb/include/lldb/Target/Process.h 
lldb/include/lldb/Utility/RangeMap.h lldb/include/lldb/lldb-enumerations.h 
lldb/include/lldb/lldb-forward.h lldb/include/lldb/lldb-private-interfaces.h 
lldb/source/API/SBSaveCoreOptions.cpp 
lldb/source/Commands/CommandObjectProcess.cpp 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h 
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h 
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp 
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h 
lldb/source/Symbol/SaveCoreOptions.cpp lldb/source/Target/Process.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Target/CoreFileMemoryRanges.cpp 
b/lldb/source/Target/CoreFileMemoryRanges.cpp
index a6ea268879..6e4ca49959 100644
--- a/lldb/source/Target/CoreFileMemoryRanges.cpp
+++ b/lldb/source/Target/CoreFileMemoryRanges.cpp
@@ -14,7 +14,8 @@ using namespace lldb_private;
 using Entry = CoreFileMemoryRanges::Entry;
 
 static bool Overlaps(const Entry *region_one, const Entry *region_two) {
-  return !(region_one->GetRangeEnd() < region_two->GetRangeBase() || 
region_two->GetRangeEnd() < region_one->GetRangeBase());
+  return !(region_one->GetRangeEnd() < region_two->GetRangeBase() ||
+   region_two->GetRangeEnd() < region_one->GetRangeBase());
 }
 
 static bool IntersectHelper(const Entry *region_one, const Entry *region_two) {

``




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


[Lldb-commits] [lldb] [LLDB][Data Formatters] Calculate average and total time for summary providers within lldb (PR #102708)

2024-09-10 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/2290


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: commands/session/history/TestSessionHistory.py (211 of 2016)
PASS: lldb-api :: commands/session/save/TestSessionSave.py (212 of 2016)
PASS: lldb-api :: commands/settings/TestSettings.py (213 of 2016)
PASS: lldb-api :: commands/settings/quoting/TestQuoting.py (214 of 2016)
PASS: lldb-api :: commands/settings/use_source_cache/TestUseSourceCache.py (215 
of 2016)
PASS: lldb-api :: commands/process/attach/TestProcessAttach.py (216 of 2016)
PASS: lldb-api :: commands/source/info/TestSourceInfo.py (217 of 2016)
UNSUPPORTED: lldb-api :: 
commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py 
(218 of 2016)
PASS: lldb-api :: commands/target/basic/TestTargetCommand.py (219 of 2016)
UNSUPPORTED: lldb-api :: commands/target/create-deps/TestTargetCreateDeps.py 
(220 of 2016)
FAIL: lldb-api :: commands/statistics/basic/TestStats.py (221 of 2016)
 TEST 'lldb-api :: commands/statistics/basic/TestStats.py' 
FAILED 
Script:
--
C:/Users/tcwg/scoop/apps/python/current/python.exe 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/llvm-project/lldb\test\API\dotest.py
 -u CXXFLAGS -u CFLAGS --env 
OBJCOPY=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/llvm-objcopy.exe
 --env LLVM_LIBS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--env 
LLVM_INCLUDE_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/include 
--env LLVM_TOOLS_DIR=C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--arch aarch64 --build-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-lldb\lldb-api
 --clang-module-cache-dir 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/module-cache-clang\lldb-api
 --executable 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/lldb.exe --compiler 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/clang.exe --dsymutil 
C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin/dsymutil.exe 
--llvm-tools-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./bin 
--lldb-obj-root C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/tools/lldb 
--lldb-libs-dir C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/./lib 
--skip-category=watchpoint 
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\commands\statistics\basic
 -p TestStats.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
22144e20cbd237a432fdc4106abe3960555aff42)
  clang revision 22144e20cbd237a432fdc4106abe3960555aff42
  llvm revision 22144e20cbd237a432fdc4106abe3960555aff42
Skipping the following test categories: ['watchpoint', 'libc++', 'libstdcxx', 
'dwo', 'dsym', 'gmodules', 'debugserver', 'objc', 'fork', 'pexpect']


--
Command Output (stderr):
--
PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_breakpoints (TestStats.TestCase.test_breakpoints)

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_commands (TestStats.TestCase.test_commands)

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_default_no_run (TestStats.TestCase.test_default_no_run)

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_default_with_run (TestStats.TestCase.test_default_with_run)

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_dsym_binary_has_symfile_in_stats 
(TestStats.TestCase.test_dsym_binary_has_symfile_in_stats) (requires one of 
macosx, darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, 
appletvsimulator) 

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_enable_disable (TestStats.TestCase.test_enable_disable)

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_expressions_frame_var_counts 
(TestStats.TestCase.test_expressions_frame_var_counts)

UNSUPPORTED: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_had_frame_variable_errors 
(TestStats.TestCase.test_had_frame_variable_errors) (requires one of macosx, 
darwin, ios, tvos, watchos, bridgeos, iphonesimulator, watchsimulator, 
appletvsimulator) 

PASS: LLDB 
(C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\build\bin\clang.exe-aarch64) :: 
test_memo

[Lldb-commits] [lldb] WoA HW Break and Watchpoint support in LLDB (PR #108072)

2024-09-10 Thread Omair Javaid via lldb-commits

https://github.com/omjavaid created 
https://github.com/llvm/llvm-project/pull/108072

This pull request adds support for hardware breakpoints and watchpoints in LLDB 
on Windows on ARM.

### Known Issues:

1. **Number of Supported Hardware Breakpoints/Watchpoints:** Windows does not 
provide the exact number of supported hardware breakpoints or watchpoints. The 
current implementation guesses this number based on testing how many can be 
successfully applied on the platform. winnt.h defines ARM64_MAX_WATCHPOINTS = 2 
and ARM64_MAX_BREAKPOINTS = 8 however actual number differs.

2. **Initial Stop Behavior:** Hardware breakpoints or watchpoints set on the 
initial stop do not trigger, even though they are correctly written to the 
Windows context. They only trigger if set after the main program has started. 
This issue causes the test suite to fail when it attempts to set hardware 
breakpoints on the main function before running, as these do not get triggered.

### Testing:

1. Tested setting 1 hardware watchpoint and 6 hardware breakpoints on 
snapdragon elite x hardware.
2. The LLDB test suite currently fails related tests due to the initial stop 
behavior issue described above.

>From 1c29d30f0b9eb47da63c35f775ad69e1ef40c4de Mon Sep 17 00:00:00 2001
From: Muhammad Omair Javaid 
Date: Tue, 10 Sep 2024 18:03:29 +0500
Subject: [PATCH] WoA hardware breakpoint/watchpoint support

---
 .../Windows/Common/NativeProcessWindows.cpp   | 52 ---
 .../Common/NativeRegisterContextWindows.cpp   |  3 -
 .../Common/NativeRegisterContextWindows.h |  5 +-
 .../NativeRegisterContextWindows_WoW64.cpp|  2 +-
 .../NativeRegisterContextWindows_arm.cpp  |  2 +-
 .../NativeRegisterContextWindows_arm64.cpp| 86 ++-
 .../NativeRegisterContextWindows_arm64.h  | 31 ++-
 .../NativeRegisterContextWindows_i386.cpp |  2 +-
 .../NativeRegisterContextWindows_x86_64.cpp   |  2 +-
 .../Windows/Common/NativeThreadWindows.cpp| 32 +++
 10 files changed, 129 insertions(+), 88 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 24c9aa6b32659d..886df987dc84b6 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -491,24 +491,47 @@ NativeProcessWindows::OnDebugException(bool first_chance,
 return ExceptionResult::MaskException;
   }
   case DWORD(STATUS_BREAKPOINT):
-  case STATUS_WX86_BREAKPOINT:
-if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
-  LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
-   record.GetExceptionAddress());
-
-  StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
-
-  if (NativeThreadWindows *stop_thread =
-  GetThreadByID(record.GetThreadID())) {
-auto ®ister_context = stop_thread->GetRegisterContext();
+  case STATUS_WX86_BREAKPOINT: {
+bool breakpoint_hit = false;
+NativeThreadWindows *stop_thread = GetThreadByID(record.GetThreadID());
+
+if (stop_thread) {
+  uint32_t hw_id = LLDB_INVALID_INDEX32;
+  auto ®_ctx = stop_thread->GetRegisterContext();
+  reg_ctx.GetHardwareBreakHitIndex(hw_id, record.GetExceptionAddress());
+  if (hw_id != LLDB_INVALID_INDEX32) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit hardware breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
+  } else if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
 uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
 // The current PC is AFTER the BP opcode, on all architectures.
-uint64_t pc = register_context.GetPC() - breakpoint_size;
-register_context.SetPC(pc);
+uint64_t pc = reg_ctx.GetPC() - breakpoint_size;
+reg_ctx.SetPC(pc);
   }
 
-  SetState(eStateStopped, true);
-  return ExceptionResult::MaskException;
+  if (breakpoint_hit) {
+StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
+SetState(eStateStopped, true);
+return ExceptionResult::MaskException;
+  } else {
+const std::vector &args = record.GetExceptionArguments();
+if (args.size() >= 2) {
+  reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
+  if (hw_id != LLDB_INVALID_INDEX32) {
+addr_t wp_pc = record.GetExceptionAddress();
+std::string desc =
+formatv("{0} {1} {2}", args[1], hw_id, wp_pc).str();
+StopThread(record.GetThreadID(), StopReason::eStopReasonWatchpoint,
+   desc);
+SetState(eStateStopped, true);
+return ExceptionResult::MaskException;
+   

[Lldb-commits] [lldb] WoA HW Break and Watchpoint support in LLDB (PR #108072)

2024-09-10 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Omair Javaid (omjavaid)


Changes

This pull request adds support for hardware breakpoints and watchpoints in LLDB 
on Windows on ARM.

### Known Issues:

1. **Number of Supported Hardware Breakpoints/Watchpoints:** Windows does not 
provide the exact number of supported hardware breakpoints or watchpoints. The 
current implementation guesses this number based on testing how many can be 
successfully applied on the platform. winnt.h defines ARM64_MAX_WATCHPOINTS = 2 
and ARM64_MAX_BREAKPOINTS = 8 however actual number differs.

2. **Initial Stop Behavior:** Hardware breakpoints or watchpoints set on the 
initial stop do not trigger, even though they are correctly written to the 
Windows context. They only trigger if set after the main program has started. 
This issue causes the test suite to fail when it attempts to set hardware 
breakpoints on the main function before running, as these do not get triggered.

### Testing:

1. Tested setting 1 hardware watchpoint and 6 hardware breakpoints on 
snapdragon elite x hardware.
2. The LLDB test suite currently fails related tests due to the initial stop 
behavior issue described above.

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


10 Files Affected:

- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp (+38-14) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp 
(-3) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h 
(+1-4) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
 (+1-1) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp 
(+1-1) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.cpp
 (+46-40) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.h 
(+8-23) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_i386.cpp
 (+1-1) 
- (modified) 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.cpp
 (+1-1) 
- (modified) lldb/source/Plugins/Process/Windows/Common/NativeThreadWindows.cpp 
(+32) 


``diff
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 24c9aa6b32659d..886df987dc84b6 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -491,24 +491,47 @@ NativeProcessWindows::OnDebugException(bool first_chance,
 return ExceptionResult::MaskException;
   }
   case DWORD(STATUS_BREAKPOINT):
-  case STATUS_WX86_BREAKPOINT:
-if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
-  LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
-   record.GetExceptionAddress());
-
-  StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
-
-  if (NativeThreadWindows *stop_thread =
-  GetThreadByID(record.GetThreadID())) {
-auto ®ister_context = stop_thread->GetRegisterContext();
+  case STATUS_WX86_BREAKPOINT: {
+bool breakpoint_hit = false;
+NativeThreadWindows *stop_thread = GetThreadByID(record.GetThreadID());
+
+if (stop_thread) {
+  uint32_t hw_id = LLDB_INVALID_INDEX32;
+  auto ®_ctx = stop_thread->GetRegisterContext();
+  reg_ctx.GetHardwareBreakHitIndex(hw_id, record.GetExceptionAddress());
+  if (hw_id != LLDB_INVALID_INDEX32) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit hardware breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
+  } else if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
 uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
 // The current PC is AFTER the BP opcode, on all architectures.
-uint64_t pc = register_context.GetPC() - breakpoint_size;
-register_context.SetPC(pc);
+uint64_t pc = reg_ctx.GetPC() - breakpoint_size;
+reg_ctx.SetPC(pc);
   }
 
-  SetState(eStateStopped, true);
-  return ExceptionResult::MaskException;
+  if (breakpoint_hit) {
+StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
+SetState(eStateStopped, true);
+return ExceptionResult::MaskException;
+  } else {
+const std::vector &args = record.GetExceptionArguments();
+if (args.size() >= 2) {
+  reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
+  if (hw_id != LLDB_INVALID_INDEX32) {
+addr_t wp_pc = record.GetExceptionAddress();
+std::string desc =
+

[Lldb-commits] [lldb] WoA HW Break and Watchpoint support in LLDB (PR #108072)

2024-09-10 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 5537ae87b3a87b3abeb4e6983cecd9b103648243 
1c29d30f0b9eb47da63c35f775ad69e1ef40c4de --extensions cpp,h -- 
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.cpp
 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm64.h 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_i386.cpp
 
lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_x86_64.cpp
 lldb/source/Plugins/Process/Windows/Common/NativeThreadWindows.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 886df987dc..87a811123d 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -531,7 +531,7 @@ NativeProcessWindows::OnDebugException(bool first_chance,
 return ExceptionResult::MaskException;
   }
 }
-  } 
+  }
 }
 
 if (!initial_stop) {
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
index 95be1183ab..effe6df36b 100644
--- 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
+++ 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
@@ -18,7 +18,6 @@
 using namespace lldb;
 using namespace lldb_private;
 
-
 lldb::thread_t NativeRegisterContextWindows::GetThreadHandle() const {
   auto wthread = static_cast(&m_thread);
   return wthread->GetHostThread().GetNativeThread().GetSystemHandle();
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h
index 66ced71d27..0f9e37dbd9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.h
@@ -17,9 +17,9 @@ namespace lldb_private {
 
 class NativeThreadWindows;
 
-class NativeRegisterContextWindows : public virtual 
NativeRegisterContextRegisterInfo {
+class NativeRegisterContextWindows
+: public virtual NativeRegisterContextRegisterInfo {
 public:
-
   static std::unique_ptr
   CreateHostNativeRegisterContextWindows(const ArchSpec &target_arch,
  NativeThreadProtocol &native_thread);
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
index 1ba89fbf32..069c327ee2 100644
--- 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
+++ 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_WoW64.cpp
@@ -88,8 +88,8 @@ static Status SetWoW64ThreadContextHelper(lldb::thread_t 
thread_handle,
 
 NativeRegisterContextWindows_WoW64::NativeRegisterContextWindows_WoW64(
 const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
-: NativeRegisterContextRegisterInfo(native_thread,
-   CreateRegisterInfoInterface(target_arch)) {}
+: NativeRegisterContextRegisterInfo(
+  native_thread, CreateRegisterInfoInterface(target_arch)) {}
 
 bool NativeRegisterContextWindows_WoW64::IsGPR(uint32_t reg_index) const {
   return (reg_index >= k_first_gpr_i386 && reg_index < k_first_alias_i386);
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp
 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp
index 470da1afc8..fd8a0c05c1 100644
--- 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp
+++ 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows_arm.cpp
@@ -128,8 +128,8 @@ 
NativeRegisterContextWindows::CreateHostNativeRegisterContextWindows(
 
 NativeRegisterContextWindows_arm::NativeRegisterContextWindows_arm(
 const ArchSpec &target_arch, NativeThreadProtocol &native_thread)
-: NativeRegisterContextRegisterInfo(native_thread,
-   CreateRegisterInfoInterface(target_arch)) {}
+: NativeRegisterContextRegisterInfo(

[Lldb-commits] [lldb] WoA HW Break and Watchpoint support in LLDB (PR #108072)

2024-09-10 Thread Omair Javaid via lldb-commits

https://github.com/omjavaid updated 
https://github.com/llvm/llvm-project/pull/108072

>From ac61e5a75ce59f7834034494a03b43e81bf02d41 Mon Sep 17 00:00:00 2001
From: Muhammad Omair Javaid 
Date: Tue, 10 Sep 2024 18:03:29 +0500
Subject: [PATCH] WoA hardware breakpoint/watchpoint support

---
 .../Windows/Common/NativeProcessWindows.cpp   | 52 ---
 .../Common/NativeRegisterContextWindows.cpp   |  3 -
 .../Common/NativeRegisterContextWindows.h |  6 +-
 .../NativeRegisterContextWindows_WoW64.cpp|  4 +-
 .../NativeRegisterContextWindows_arm.cpp  |  4 +-
 .../NativeRegisterContextWindows_arm64.cpp| 86 ++-
 .../NativeRegisterContextWindows_arm64.h  | 32 ++-
 .../NativeRegisterContextWindows_i386.cpp |  4 +-
 .../NativeRegisterContextWindows_x86_64.cpp   |  4 +-
 .../Windows/Common/NativeThreadWindows.cpp| 32 +++
 10 files changed, 135 insertions(+), 92 deletions(-)

diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 24c9aa6b32659d..87a811123d5de8 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -491,24 +491,47 @@ NativeProcessWindows::OnDebugException(bool first_chance,
 return ExceptionResult::MaskException;
   }
   case DWORD(STATUS_BREAKPOINT):
-  case STATUS_WX86_BREAKPOINT:
-if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
-  LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
-   record.GetExceptionAddress());
-
-  StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
-
-  if (NativeThreadWindows *stop_thread =
-  GetThreadByID(record.GetThreadID())) {
-auto ®ister_context = stop_thread->GetRegisterContext();
+  case STATUS_WX86_BREAKPOINT: {
+bool breakpoint_hit = false;
+NativeThreadWindows *stop_thread = GetThreadByID(record.GetThreadID());
+
+if (stop_thread) {
+  uint32_t hw_id = LLDB_INVALID_INDEX32;
+  auto ®_ctx = stop_thread->GetRegisterContext();
+  reg_ctx.GetHardwareBreakHitIndex(hw_id, record.GetExceptionAddress());
+  if (hw_id != LLDB_INVALID_INDEX32) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit hardware breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
+  } else if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
+breakpoint_hit = true;
+LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
+ record.GetExceptionAddress());
 uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
 // The current PC is AFTER the BP opcode, on all architectures.
-uint64_t pc = register_context.GetPC() - breakpoint_size;
-register_context.SetPC(pc);
+uint64_t pc = reg_ctx.GetPC() - breakpoint_size;
+reg_ctx.SetPC(pc);
   }
 
-  SetState(eStateStopped, true);
-  return ExceptionResult::MaskException;
+  if (breakpoint_hit) {
+StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
+SetState(eStateStopped, true);
+return ExceptionResult::MaskException;
+  } else {
+const std::vector &args = record.GetExceptionArguments();
+if (args.size() >= 2) {
+  reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
+  if (hw_id != LLDB_INVALID_INDEX32) {
+addr_t wp_pc = record.GetExceptionAddress();
+std::string desc =
+formatv("{0} {1} {2}", args[1], hw_id, wp_pc).str();
+StopThread(record.GetThreadID(), StopReason::eStopReasonWatchpoint,
+   desc);
+SetState(eStateStopped, true);
+return ExceptionResult::MaskException;
+  }
+}
+  }
 }
 
 if (!initial_stop) {
@@ -531,6 +554,7 @@ NativeProcessWindows::OnDebugException(bool first_chance,
   // Hit the initial stop. Continue the application.
   return ExceptionResult::BreakInDebugger;
 }
+  }
 
 [[fallthrough]];
   default:
diff --git 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
index 9128363eaa577a..95be1183abb759 100644
--- 
a/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
+++ 
b/lldb/source/Plugins/Process/Windows/Common/NativeRegisterContextWindows.cpp
@@ -18,9 +18,6 @@
 using namespace lldb;
 using namespace lldb_private;
 
-NativeRegisterContextWindows::NativeRegisterContextWindows(
-NativeThreadProtocol &thread, RegisterInfoInterface *reg_info_interface_p)
-: NativeRegisterContextRegisterInfo(thread, reg_info_interface_p) {}
 
 lldb::thread_t NativeRegisterContextWindows::GetThreadHandle() const {
   auto wthread = static_cast(&m_thread);
diff --git 
a/lldb/source/Plugins/Pro

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

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

https://github.com/adrian-prantl updated 
https://github.com/llvm/llvm-project/pull/106774

>From 604d06560549ce7821c5710e566179b7a6faaa42 Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 4 Sep 2024 12:50:37 -0700
Subject: [PATCH] [lldb] Change the implementation of Status to store an
 llvm::Error (NFC)

Most APIs that currently vend a Status would be better served by
returning llvm::Expected<> instead. Where possible, APIs should be
refactored to avoid Status. The only legitimate long-term uses of
Status are objects that need to store an error for a long time (which
should be questioned as a design decision, too).

This patch makes the transition to llvm::Error easier by making the
places that cannot switch to llvm::Error explicit: They are marked
with a call to Status::clone(). Every other API can and should be
refactored to use llvm::Expected. In the end Status should only be
used in very few places.

Whenever an unchecked Error is dropped by Status it logs this to the
verbose API channel.

Implementation notes:

This patch introduces two new kinds of error_category as well as new
llvm::Error types. Here is the mapping of lldb::ErrorType to
llvm::Errors:

   (eErrorTypeInvalid)
   eErrorTypeGeneric  llvm::StringError
   eErrorTypePOSIXllvm::ECError
   eErrorTypeMachKernel   MachKernelError
   eErrorTypeExpression   llvm::ErrorList
   eErrorTypeWin32Win32Error
---
 lldb/include/lldb/Utility/Status.h|  75 +-
 .../Python/PythonDataObjects.cpp  |   5 +-
 lldb/source/Utility/Status.cpp| 237 --
 3 files changed, 228 insertions(+), 89 deletions(-)

diff --git a/lldb/include/lldb/Utility/Status.h 
b/lldb/include/lldb/Utility/Status.h
index 795c830b965173..169326eccef450 100644
--- a/lldb/include/lldb/Utility/Status.h
+++ b/lldb/include/lldb/Utility/Status.h
@@ -28,6 +28,67 @@ namespace lldb_private {
 
 const char *ExpressionResultAsCString(lldb::ExpressionResults result);
 
+/// Going a bit against the spirit of llvm::Error,
+/// lldb_private::Status need to store errors long-term and sometimes
+/// copy them. This base class defines an interface for this
+/// operation.
+class CloneableError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableError() : ErrorInfo() {}
+  virtual std::unique_ptr Clone() const = 0;
+  static char ID;
+};
+
+/// Common base class for all error-code errors.
+class CloneableECError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  CloneableECError(std::error_code ec) : ErrorInfo() {}
+  std::error_code convertToErrorCode() const override { return EC; }
+  void log(llvm::raw_ostream &OS) const override { OS << EC.message(); }
+  static char ID;
+
+protected:
+  std::error_code EC;
+};
+
+/// FIXME: Move these declarations closer to where they're used.
+class MachKernelError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  MachKernelError(std::error_code ec) : ErrorInfo(ec) {}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class Win32Error : public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  Win32Error(std::error_code ec, const llvm::Twine &msg = {}) : ErrorInfo(ec) 
{}
+  std::string message() const override;
+  std::unique_ptr Clone() const override;
+  static char ID;
+};
+
+class ExpressionError
+: public llvm::ErrorInfo {
+public:
+  using llvm::ErrorInfo::ErrorInfo;
+  ExpressionError(std::error_code ec, std::string msg = {})
+  : ErrorInfo(ec), m_string(msg) {}
+  std::unique_ptr Clone() const override;
+  std::string message() const override { return m_string; }
+  static char ID;
+
+protected:
+  std::string m_string;
+};
+
 /// \class Status Status.h "lldb/Utility/Status.h" An error handling class.
 ///
 /// This class is designed to be able to hold any error code that can be
@@ -100,9 +161,7 @@ class Status {
   }
 
   static Status FromExpressionError(lldb::ExpressionResults result,
-std::string msg) {
-return Status(result, lldb::eErrorTypeExpression, msg);
-  }
+std::string msg);
 
   /// Set the current error to errno.
   ///
@@ -115,6 +174,7 @@ class Status {
   const Status &operator=(Status &&);
   /// Avoid using this in new code. Migrate APIs to llvm::Expected instead.
   static Status FromError(llvm::Error error);
+
   /// FIXME: Replace this with a takeError() method.
   llvm::Error ToError() const;
   /// Don't call this function in new code. Instead, redesign the API
@@ -170,12 +230,9 @@ class Status {
   bool Success() const;
 
 protected:
-  Status(llvm::Error error);
-  /// Status code as an integer value.
-  ValueType m_code = 0;
-  /// The type of the above error code.
-  lldb::ErrorType m_type = lldb::eErrorTypeInvalid;
-  /// A string representation of the error code.
+  Statu

  1   2   >