[Lldb-commits] [lldb] [lldb][test] Disable PIE for some API tests (PR #93808)

2024-06-13 Thread Pavel Labath via lldb-commits

labath wrote:

Thanks.

https://github.com/llvm/llvm-project/pull/93808
___
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] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread Jay Foad via lldb-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/95373

None

>From 6d326a96d2651f8836b29ff1e3edef022f41549e Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Thu, 13 Jun 2024 09:46:48 +0100
Subject: [PATCH] [llvm-project] Fix typo "seperate"

---
 clang-tools-extra/clangd/TidyProvider.cpp | 10 
 .../include/clang/Frontend/FrontendOptions.h  |  2 +-
 .../include/clang/InstallAPI/DylibVerifier.h  |  2 +-
 clang/lib/InstallAPI/Visitor.cpp  |  2 +-
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 +-
 compiler-rt/test/dfsan/custom.cpp |  2 +-
 .../Linux/ppc64/trivial-tls-pwr10.test|  2 +-
 .../FlangOmpReport/yaml_summarizer.py |  2 +-
 flang/lib/Semantics/check-omp-structure.cpp   | 10 
 flang/test/Driver/mllvm_vs_mmlir.f90  |  2 +-
 libc/src/__support/FPUtil/x86_64/FEnvImpl.h   |  2 +-
 .../stdio/printf_core/float_hex_converter.h   | 10 
 .../str_to_float_comparison_test.cpp  |  2 +-
 lld/test/wasm/data-segments.ll|  2 +-
 .../lldb/Expression/DWARFExpressionList.h |  2 +-
 lldb/include/lldb/Target/MemoryTagManager.h   |  2 +-
 .../NativeRegisterContextLinux_arm64.cpp  |  2 +-
 lldb/test/API/CMakeLists.txt  |  2 +-
 .../TestGdbRemoteMemoryTagging.py |  2 +-
 .../DW_AT_data_bit_offset-DW_OP_stack_value.s |  2 +-
 llvm/include/llvm/CodeGen/LiveRegUnits.h  |  2 +-
 llvm/include/llvm/CodeGen/MIRFormatter.h  |  2 +-
 llvm/include/llvm/MC/MCAsmInfo.h  |  2 +-
 llvm/include/llvm/Support/raw_socket_stream.h |  2 +-
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h   |  2 +-
 .../CodeGen/AssignmentTrackingAnalysis.cpp|  6 ++---
 .../SelectionDAG/SelectionDAGBuilder.cpp  |  4 ++--
 llvm/lib/FileCheck/FileCheck.cpp  |  2 +-
 llvm/lib/IR/DebugInfo.cpp |  2 +-
 llvm/lib/MC/MCPseudoProbe.cpp |  2 +-
 llvm/lib/Support/VirtualFileSystem.cpp|  2 +-
 llvm/lib/Support/raw_socket_stream.cpp|  2 +-
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  2 +-
 .../Target/RISCV/RISCVMachineFunctionInfo.h   |  2 +-
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  2 +-
 llvm/lib/TextAPI/Utils.cpp|  2 +-
 llvm/lib/Transforms/IPO/Attributor.cpp|  4 ++--
 .../lib/Transforms/IPO/SampleProfileProbe.cpp |  2 +-
 .../Scalar/RewriteStatepointsForGC.cpp|  2 +-
 .../Transforms/Utils/LoopUnrollRuntime.cpp|  2 +-
 llvm/test/CodeGen/X86/AMX/amx-greedy-ra.ll|  2 +-
 llvm/test/CodeGen/X86/apx/shift-eflags.ll | 24 +--
 .../X86/merge-consecutive-stores-nt.ll|  4 ++--
 llvm/test/CodeGen/X86/shift-eflags.ll | 24 +--
 .../InstSimplify/constant-fold-fp-denormal.ll |  2 +-
 .../LoopVectorize/LoongArch/defaults.ll   |  2 +-
 .../LoopVectorize/RISCV/defaults.ll   |  2 +-
 .../split-gep-or-as-add.ll|  2 +-
 llvm/test/Verifier/alloc-size-failedparse.ll  |  2 +-
 llvm/test/tools/llvm-ar/windows-path.test |  2 +-
 .../ELF/mirror-permissions-win.test   |  2 +-
 llvm/tools/llvm-cov/CodeCoverage.cpp  |  2 +-
 llvm/tools/llvm-profgen/PerfReader.cpp|  2 +-
 llvm/unittests/Support/Path.cpp   |  4 ++--
 .../Analysis/Presburger/IntegerRelation.h |  2 +-
 .../Analysis/Presburger/PresburgerSpace.h |  2 +-
 .../mlir/Dialect/OpenMP/OpenMPInterfaces.h|  2 +-
 .../Analysis/Presburger/PresburgerSpace.cpp   |  2 +-
 .../lib/Conversion/GPUCommon/GPUOpsLowering.h |  2 +-
 .../LLVMIR/IR/BasicPtxBuilderInterface.cpp|  2 +-
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  |  6 ++---
 .../CPU/sparse_reduce_custom_prod.mlir|  2 +-
 .../omptarget-constant-alloca-raise.mlir  |  2 +-
 openmp/tools/Modules/FindOpenMPTarget.cmake   |  2 +-
 64 files changed, 106 insertions(+), 106 deletions(-)

diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index a4121df30d3df..a87238e0c0938 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -195,10 +195,10 @@ TidyProvider addTidyChecks(llvm::StringRef Checks,
 }
 
 TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) 
{
-  constexpr llvm::StringLiteral Seperator(",");
+  constexpr llvm::StringLiteral Separator(",");
   static const std::string BadChecks = llvm::join_items(
-  Seperator,
-  // We want this list to start with a seperator to
+  Separator,
+  // We want this list to start with a separator to
   // simplify appending in the lambda. So including an
   // empty string here will force that.
   "",
@@ -227,7 +227,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   for (const std::string &Str : ExtraBadChecks) {
 if (Str.empty())
   continue;
-Size += Seperator.size();
+Size += Separator.size();
 if (LLVM_LIKELY(Str.front() 

[Lldb-commits] [clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread Matt Arsenault via lldb-commits

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


https://github.com/llvm/llvm-project/pull/95373
___
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] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread via lldb-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra
@llvm/pr-subscribers-lldb

@llvm/pr-subscribers-lld

Author: Jay Foad (jayfoad)


Changes



---

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


64 Files Affected:

- (modified) clang-tools-extra/clangd/TidyProvider.cpp (+5-5) 
- (modified) clang/include/clang/Frontend/FrontendOptions.h (+1-1) 
- (modified) clang/include/clang/InstallAPI/DylibVerifier.h (+1-1) 
- (modified) clang/lib/InstallAPI/Visitor.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+1-1) 
- (modified) compiler-rt/test/dfsan/custom.cpp (+1-1) 
- (modified) compiler-rt/test/orc/TestCases/Linux/ppc64/trivial-tls-pwr10.test 
(+1-1) 
- (modified) flang/examples/FlangOmpReport/yaml_summarizer.py (+1-1) 
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+5-5) 
- (modified) flang/test/Driver/mllvm_vs_mmlir.f90 (+1-1) 
- (modified) libc/src/__support/FPUtil/x86_64/FEnvImpl.h (+1-1) 
- (modified) libc/src/stdio/printf_core/float_hex_converter.h (+5-5) 
- (modified) libc/test/src/__support/str_to_float_comparison_test.cpp (+1-1) 
- (modified) lld/test/wasm/data-segments.ll (+1-1) 
- (modified) lldb/include/lldb/Expression/DWARFExpressionList.h (+1-1) 
- (modified) lldb/include/lldb/Target/MemoryTagManager.h (+1-1) 
- (modified) 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp (+1-1) 
- (modified) lldb/test/API/CMakeLists.txt (+1-1) 
- (modified) 
lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py 
(+1-1) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_data_bit_offset-DW_OP_stack_value.s 
(+1-1) 
- (modified) llvm/include/llvm/CodeGen/LiveRegUnits.h (+1-1) 
- (modified) llvm/include/llvm/CodeGen/MIRFormatter.h (+1-1) 
- (modified) llvm/include/llvm/MC/MCAsmInfo.h (+1-1) 
- (modified) llvm/include/llvm/Support/raw_socket_stream.h (+1-1) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h (+1-1) 
- (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+2-2) 
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+1-1) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+1-1) 
- (modified) llvm/lib/MC/MCPseudoProbe.cpp (+1-1) 
- (modified) llvm/lib/Support/VirtualFileSystem.cpp (+1-1) 
- (modified) llvm/lib/Support/raw_socket_stream.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h (+1-1) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+1-1) 
- (modified) llvm/lib/TextAPI/Utils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/Attributor.cpp (+2-2) 
- (modified) llvm/lib/Transforms/IPO/SampleProfileProbe.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp (+1-1) 
- (modified) llvm/test/CodeGen/X86/AMX/amx-greedy-ra.ll (+1-1) 
- (modified) llvm/test/CodeGen/X86/apx/shift-eflags.ll (+12-12) 
- (modified) llvm/test/CodeGen/X86/merge-consecutive-stores-nt.ll (+2-2) 
- (modified) llvm/test/CodeGen/X86/shift-eflags.ll (+12-12) 
- (modified) llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll 
(+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/LoongArch/defaults.ll (+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/RISCV/defaults.ll (+1-1) 
- (modified) 
llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll (+1-1) 
- (modified) llvm/test/Verifier/alloc-size-failedparse.ll (+1-1) 
- (modified) llvm/test/tools/llvm-ar/windows-path.test (+1-1) 
- (modified) llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-win.test 
(+1-1) 
- (modified) llvm/tools/llvm-cov/CodeCoverage.cpp (+1-1) 
- (modified) llvm/tools/llvm-profgen/PerfReader.cpp (+1-1) 
- (modified) llvm/unittests/Support/Path.cpp (+2-2) 
- (modified) mlir/include/mlir/Analysis/Presburger/IntegerRelation.h (+1-1) 
- (modified) mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h (+1-1) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h (+1-1) 
- (modified) mlir/lib/Analysis/Presburger/PresburgerSpace.cpp (+1-1) 
- (modified) mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h (+1-1) 
- (modified) mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp (+1-1) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+3-3) 
- (modified) 
mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reduce_custom_prod.mlir 
(+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-constant-alloca-raise.mlir 
(+1-1) 
- (modified) openmp/tools/Modules/FindOpenMPTarget.cmake (+1-1) 


``diff
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index a4121df30d3df..a87238e0c0938 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -195,10 +195,10 @@ TidyProvider addTidyChecks(llvm

[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFC] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

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

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

This patch factors out the completion logic for individual clang::Type's into 
their own helper functions.

During the process I cleaned up a few assumptions (e.g., unnecessary if-guards 
that could be asserts because these conditions are guaranteed by the 
`clang::Type::TypeClass` switch in `GetCompleteQualType`).

This is mainly motivated by the type-completion rework proposed in 
https://github.com/llvm/llvm-project/pull/95100.

>From e3ecb1e686e16d90f860126c3ede758196df8f31 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 13:22:04 +0100
Subject: [PATCH] [lldb][TypeSystemClang][NFC] Factor completion logic for
 individual types in GetCompleteQualType

This patch factors out the completion logic for individual
clang::Type's into their own helper functions.

During the process I cleaned up a few assumptions (e.g.,
unnecessary if-guards that could be asserts because these
conditions are guaranteed by the `clang::Type::TypeClass`
switch in `GetCompleteQualType`).

This is mainly motivated by the type-completion rework
proposed in https://github.com/llvm/llvm-project/pull/95100.
---
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 210 +++---
 1 file changed, 133 insertions(+), 77 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 369ae46cf264a..bef9263eaeafc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,
+  clang::QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isEnumeralType());
+  assert(ast);
+
+  const clang::EnumType *enum_type =
+  llvm::cast(qual_type.getTypePtr());
+
+  auto *tag_decl = enum_type->getAsTagDecl();
+  assert(tag_decl);
+
+  // Already completed, nothing to be done.
+  if (tag_decl->getDefinition())
+return enum_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // No definition but can't complete it, error out.
+  if (!tag_decl->hasExternalLexicalStorage())
+return nullptr;
+
+  // We can't complete the type without an external source.
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (!external_ast_source)
+return nullptr;
+
+  external_ast_source->CompleteType(tag_decl);
+  return enum_type;
+}
+
+/// Returns the clang::ObjCObjectType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static cl

[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

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

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

2024-06-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

This patch factors out the completion logic for individual clang::Type's into 
their own helper functions.

During the process I cleaned up a few assumptions (e.g., unnecessary if-guards 
that could be asserts because these conditions are guaranteed by the 
`clang::Type::TypeClass` switch in `GetCompleteQualType`).

This is mainly motivated by the type-completion rework proposed in 
https://github.com/llvm/llvm-project/pull/95100.

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


1 Files Affected:

- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+133-77) 


``diff
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 369ae46cf264a..bef9263eaeafc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,
+  clang::QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isEnumeralType());
+  assert(ast);
+
+  const clang::EnumType *enum_type =
+  llvm::cast(qual_type.getTypePtr());
+
+  auto *tag_decl = enum_type->getAsTagDecl();
+  assert(tag_decl);
+
+  // Already completed, nothing to be done.
+  if (tag_decl->getDefinition())
+return enum_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // No definition but can't complete it, error out.
+  if (!tag_decl->hasExternalLexicalStorage())
+return nullptr;
+
+  // We can't complete the type without an external source.
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (!external_ast_source)
+return nullptr;
+
+  external_ast_source->CompleteType(tag_decl);
+  return enum_type;
+}
+
+/// Returns the clang::ObjCObjectType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::ObjCObjectType const *
+GetCompleteObjCObjectType(clang::ASTContext *ast, QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isObjCObjectType());
+  assert(ast);
+
+  const clang::ObjCObjectType *objc_class_type =
+  llvm::cast(qual_type);
+
+  clang::ObjCInterfaceDecl *class_interface_decl =
+  objc_class_type->getInterface();
+  // We currently can't complete objective C types through the newly added
+  // ASTContext because it only supports TagDecl objects right now...
+  if (!class_interface_decl)
+return objc_class_type;
+
+  // Already complete,

[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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

This is a minimal reproducer for a crash reported internally where we would try 
to call `DumpTypeDescription` on an incomplete type. This crash surfaced as 
part of an NFC refactor of some of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122

>From 2e84cf46b9378307d9059aa1ce2a97046b0866b4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:00:07 +0100
Subject: [PATCH] [lldb][test] Add test for completing ObjCObjectType

This is a minimal reproducer for a crash reported internally
where we would try to call `DumpTypeDescription` on an incomplete
type. This crash surfaced as part of an NFC refactor of some
of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122
---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

2024-06-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

This is a minimal reproducer for a crash reported internally where we would try 
to call `DumpTypeDescription` on an incomplete type. This crash surfaced as 
part of an NFC refactor of some of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122

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


1 Files Affected:

- (added) lldb/test/Shell/Expr/TestObjCIDCast.cpp (+10) 


``diff
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

``




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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

2024-06-13 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

2024-06-13 Thread Pavel Labath via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

2024-06-13 Thread Pavel Labath via lldb-commits


@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,

labath wrote:

const before object type (is this some swift style or something?)

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

2024-06-13 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff cece0a105b29dcbb9d88d0aa264c4745c07a8456 
2e84cf46b9378307d9059aa1ce2a97046b0866b4 -- 
lldb/test/Shell/Expr/TestObjCIDCast.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
index 011bd943b5..919f35ce60 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -6,5 +6,5 @@
 
 int main() { return 0; }
 
-// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: (lldb) expression --language objc -- *(id)0x1234
 // CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

``




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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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

>From 2e84cf46b9378307d9059aa1ce2a97046b0866b4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:00:07 +0100
Subject: [PATCH 1/2] [lldb][test] Add test for completing ObjCObjectType

This is a minimal reproducer for a crash reported internally
where we would try to call `DumpTypeDescription` on an incomplete
type. This crash surfaced as part of an NFC refactor of some
of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122
---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

>From 6081327e68d1df1594f17bda97e0f12506681772 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:07:19 +0100
Subject: [PATCH 2/2] fixup! clang-format

---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
index 011bd943b5967..919f35ce6060e 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -6,5 +6,5 @@
 
 int main() { return 0; }
 
-// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: (lldb) expression --language objc -- *(id)0x1234
 // CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

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


@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,

Michael137 wrote:

Hehe just a habit of mine. I'll change it

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

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


@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,

Michael137 wrote:

done

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types out of GetCompleteQualType (PR #95402)

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

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


[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types in GetCompleteQualType (PR #95402)

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

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

>From e3ecb1e686e16d90f860126c3ede758196df8f31 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 13:22:04 +0100
Subject: [PATCH 1/2] [lldb][TypeSystemClang][NFC] Factor completion logic for
 individual types in GetCompleteQualType

This patch factors out the completion logic for individual
clang::Type's into their own helper functions.

During the process I cleaned up a few assumptions (e.g.,
unnecessary if-guards that could be asserts because these
conditions are guaranteed by the `clang::Type::TypeClass`
switch in `GetCompleteQualType`).

This is mainly motivated by the type-completion rework
proposed in https://github.com/llvm/llvm-project/pull/95100.
---
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 210 +++---
 1 file changed, 133 insertions(+), 77 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 369ae46cf264a..bef9263eaeafc 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::RecordType const *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  auto const *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::EnumType const *GetCompleteEnumType(clang::ASTContext *ast,
+  clang::QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isEnumeralType());
+  assert(ast);
+
+  const clang::EnumType *enum_type =
+  llvm::cast(qual_type.getTypePtr());
+
+  auto *tag_decl = enum_type->getAsTagDecl();
+  assert(tag_decl);
+
+  // Already completed, nothing to be done.
+  if (tag_decl->getDefinition())
+return enum_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // No definition but can't complete it, error out.
+  if (!tag_decl->hasExternalLexicalStorage())
+return nullptr;
+
+  // We can't complete the type without an external source.
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (!external_ast_source)
+return nullptr;
+
+  external_ast_source->CompleteType(tag_decl);
+  return enum_type;
+}
+
+/// Returns the clang::ObjCObjectType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static clang::ObjCObjectType const *
+GetCompleteObjCObjectType(clang::ASTContext *ast, QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isObjCObjectType());
+  assert(ast);
+
+  const clang::ObjCObjectType *objc_class_type =
+  llvm::cast(qual_type);
+
+  clang::ObjCInterfaceDecl *class_interface_decl =
+  objc_class_type->getInterface();
+  // We currently can't complete objective C t

[Lldb-commits] [clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Support case-insensitive regex matches (PR #95350)

2024-06-13 Thread Felipe de Azevedo Piovezan via lldb-commits

felipepiovezan wrote:

> LGTM, may be we could also support this for the command line

Just keep in mind that those are very different queries w.r.t. speed: one goes 
through a fast path in the accelerator table, the other one doesn't.

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


[Lldb-commits] [lldb] [lldb] Adds additional fields to ProcessInfo (PR #91544)

2024-06-13 Thread Fred Grim via lldb-commits

feg208 wrote:

@JDevlieghere could I talk you into merging this? Somehow I got shifted from 
the committers group to the triagers group but it's taking time to resolve.

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


[Lldb-commits] [lldb] [LLDB] Add more helper functions to ValueObject class. (PR #87197)

2024-06-13 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Support case-insensitive regex matches (PR #95350)

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

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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


@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s

adrian-prantl wrote:

Does this test work on Linux?
Is there another constant that is even less likely to ever be a real pointer?
Would 0x0001 work?

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


[Lldb-commits] [lldb] 9f70cd8 - [LLDB] Add more helper functions to ValueObject class. (#87197)

2024-06-13 Thread via lldb-commits

Author: cmtice
Date: 2024-06-13T09:14:17-07:00
New Revision: 9f70cd83897b36e5628057dfef2855a0b9045766

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

LOG: [LLDB] Add more helper functions to ValueObject class. (#87197)

Create additional helper functions for the ValueObject class, for:
  - returning the value as an APSInt or APFloat
  - additional type casting options
  - additional ways to create ValueObjects from various types of data
  - dereferencing a ValueObject

These helper functions are needed for implementing the Data Inspection
Language, described in
https://discourse.llvm.org/t/rfc-data-inspection-language/69893

Added: 


Modified: 
lldb/include/lldb/Core/ValueObject.h
lldb/include/lldb/Utility/Scalar.h
lldb/source/API/SBValue.cpp
lldb/source/Core/ValueObject.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index 1e8c7c9c00536..db1fdae170ed0 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -441,6 +441,30 @@ class ValueObject {
 
   virtual int64_t GetValueAsSigned(int64_t fail_value, bool *success = 
nullptr);
 
+  /// If the current ValueObject is of an appropriate type, convert the
+  /// value to an APSInt and return that. Otherwise return an error.
+  llvm::Expected GetValueAsAPSInt();
+
+  /// If the current ValueObject is of an appropriate type, convert the
+  /// value to an APFloat and return that. Otherwise return an error.
+  llvm::Expected GetValueAsAPFloat();
+
+  /// If the current ValueObject is of an appropriate type, convert the
+  /// value to a boolean and return that. Otherwise return an error.
+  llvm::Expected GetValueAsBool();
+
+  /// Update an existing integer ValueObject with a new integer value. This
+  /// is only intended to be used with 'temporary' ValueObjects, i.e. ones that
+  /// are not associated with program variables. It does not update program
+  /// memory, registers, stack, etc.
+  void SetValueFromInteger(const llvm::APInt &value, Status &error);
+
+  /// Update an existing integer ValueObject with an integer value created
+  /// frome 'new_val_sp'.  This is only intended to be used with 'temporary'
+  /// ValueObjects, i.e. ones that are not associated with program variables.
+  /// It does not update program  memory, registers, stack, etc.
+  void SetValueFromInteger(lldb::ValueObjectSP new_val_sp, Status &error);
+
   virtual bool SetValueFromCString(const char *value_str, Status &error);
 
   /// Return the module associated with this value object in case the value is
@@ -618,6 +642,32 @@ class ValueObject {
   virtual lldb::ValueObjectSP CastPointerType(const char *name,
   lldb::TypeSP &type_sp);
 
+  /// Return the target load address associated with this value object.
+  lldb::addr_t GetLoadAddress();
+
+  /// Take a ValueObject whose type is an inherited class, and cast it to
+  /// 'type', which should be one of its base classes. 'base_type_indices'
+  /// contains the indices of direct base classes on the path from the
+  /// ValueObject's current type to 'type'
+  llvm::Expected
+  CastDerivedToBaseType(CompilerType type,
+const llvm::ArrayRef &base_type_indices);
+
+  /// Take a ValueObject whose type is a base class, and cast it to 'type',
+  /// which should be one of its derived classes. 'base_type_indices'
+  /// contains the indices of direct base classes on the path from the
+  /// ValueObject's current type to 'type'
+  llvm::Expected CastBaseToDerivedType(CompilerType type,
+uint64_t offset);
+
+  // Take a ValueObject that contains a scalar, enum or pointer type, and
+  // cast it to a "basic" type (integer, float or boolean).
+  lldb::ValueObjectSP CastToBasicType(CompilerType type);
+
+  // Take a ValueObject that contain an integer, float or enum, and cast it
+  // to an enum.
+  lldb::ValueObjectSP CastToEnumType(CompilerType type);
+
   /// If this object represents a C++ class with a vtable, return an object
   /// that represents the virtual function table. If the object isn't a class
   /// with a vtable, return a valid ValueObject with the error set correctly.
@@ -659,15 +709,41 @@ class ValueObject {
   const ExecutionContext &exe_ctx,
   const EvaluateExpressionOptions &options);
 
+  /// Given an address either create a value object containing the value at
+  /// that address, or create a value object containing the address itself
+  /// (pointer value), depending on whether the parameter 'do_deref' is true or
+  /// false.
   static lldb::ValueObjectSP
   CreateValueObjectFromAddres

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -40,7 +46,7 @@ lldb_private::Status WriteString(const std::string &to_write,
 /// the data on heap.
 class MinidumpFileBuilder {
 public:
-  MinidumpFileBuilder() = default;
+  MinidumpFileBuilder(lldb::FileUP&& core_file): 
m_core_file(std::move(core_file)) {};

Jlalond wrote:

I agree with this. I also think it reduces the split responsibility with 
`ObjectfileMinidump`

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


[Lldb-commits] [lldb] 8f2a4e8 - [lldb] Support case-insensitive regex matches (#95350)

2024-06-13 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-06-13T09:37:02-07:00
New Revision: 8f2a4e83554abb2fb67f11d95428c3ff3147e88b

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

LOG: [lldb] Support case-insensitive regex matches (#95350)

Support case-insensitive regex matches for
`SBTarget::FindGlobalFunctions` and `SBTarget::FindGlobalVariables`.

Added: 


Modified: 
lldb/include/lldb/Utility/RegularExpression.h
lldb/include/lldb/lldb-enumerations.h
lldb/source/API/SBTarget.cpp
lldb/source/Utility/RegularExpression.cpp
lldb/test/API/lang/cpp/class_static/TestStaticVariables.py

Removed: 




diff  --git a/lldb/include/lldb/Utility/RegularExpression.h 
b/lldb/include/lldb/Utility/RegularExpression.h
index 415f1b58b1110..e8bd47bb53c29 100644
--- a/lldb/include/lldb/Utility/RegularExpression.h
+++ b/lldb/include/lldb/Utility/RegularExpression.h
@@ -31,7 +31,13 @@ class RegularExpression {
   /// \param[in] string
   /// An llvm::StringRef that represents the regular expression to compile.
   //  String is not referenced anymore after the object is constructed.
-  explicit RegularExpression(llvm::StringRef string);
+  //
+  /// \param[in] flags
+  /// An llvm::Regex::RegexFlags that modifies the matching behavior. The
+  /// default is NoFlags.
+  explicit RegularExpression(
+  llvm::StringRef string,
+  llvm::Regex::RegexFlags flags = llvm::Regex::NoFlags);
 
   ~RegularExpression() = default;
 

diff  --git a/lldb/include/lldb/lldb-enumerations.h 
b/lldb/include/lldb/lldb-enumerations.h
index 8e05f6ba9c876..74ff458bf87de 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -1107,7 +1107,12 @@ enum MemberFunctionKind {
 };
 
 /// String matching algorithm used by SBTarget.
-enum MatchType { eMatchTypeNormal, eMatchTypeRegex, eMatchTypeStartsWith };
+enum MatchType {
+  eMatchTypeNormal,
+  eMatchTypeRegex,
+  eMatchTypeStartsWith,
+  eMatchTypeRegexInsensitive
+};
 
 /// Bitmask that describes details about a type.
 FLAGS_ENUM(TypeFlags){

diff  --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index adb9e645610ba..2c336296f0b8d 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1789,6 +1789,11 @@ lldb::SBSymbolContextList 
SBTarget::FindGlobalFunctions(const char *name,
 target_sp->GetImages().FindFunctions(RegularExpression(name_ref),
  function_options, *sb_sc_list);
 break;
+  case eMatchTypeRegexInsensitive:
+target_sp->GetImages().FindFunctions(
+RegularExpression(name_ref, llvm::Regex::RegexFlags::IgnoreCase),
+function_options, *sb_sc_list);
+break;
   case eMatchTypeStartsWith:
 regexstr = llvm::Regex::escape(name) + ".*";
 target_sp->GetImages().FindFunctions(RegularExpression(regexstr),
@@ -1936,6 +1941,11 @@ SBValueList SBTarget::FindGlobalVariables(const char 
*name,
   target_sp->GetImages().FindGlobalVariables(RegularExpression(name_ref),
  max_matches, variable_list);
   break;
+case eMatchTypeRegexInsensitive:
+  target_sp->GetImages().FindGlobalVariables(
+  RegularExpression(name_ref, llvm::Regex::IgnoreCase), max_matches,
+  variable_list);
+  break;
 case eMatchTypeStartsWith:
   regexstr = "^" + llvm::Regex::escape(name) + ".*";
   target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr),

diff  --git a/lldb/source/Utility/RegularExpression.cpp 
b/lldb/source/Utility/RegularExpression.cpp
index 20bebbfe15f27..026793462221c 100644
--- a/lldb/source/Utility/RegularExpression.cpp
+++ b/lldb/source/Utility/RegularExpression.cpp
@@ -12,10 +12,11 @@
 
 using namespace lldb_private;
 
-RegularExpression::RegularExpression(llvm::StringRef str)
+RegularExpression::RegularExpression(llvm::StringRef str,
+ llvm::Regex::RegexFlags flags)
 : m_regex_text(std::string(str)),
   // m_regex does not reference str anymore after it is constructed.
-  m_regex(llvm::Regex(str)) {}
+  m_regex(llvm::Regex(str, flags)) {}
 
 RegularExpression::RegularExpression(const RegularExpression &rhs)
 : RegularExpression(rhs.GetText()) {}

diff  --git a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py 
b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
index 8211d532b2638..04678ec018bdf 100644
--- a/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
+++ b/lldb/test/API/lang/cpp/class_static/TestStaticVariables.py
@@ -2,7 +2,6 @@
 Test display and Python APIs on file and class static variables.
 """
 
-
 import lldb
 from lldbsuite.test.decorators import *
 from 

[Lldb-commits] [lldb] [WIP][lldb] Use forward decls with redeclared definitions instead of minimal import for records (PR #95100)

2024-06-13 Thread David Blaikie via lldb-commits

dwblaikie wrote:

Yeah, putting this behind a very-explicitly-temporary flag seems reasonable to 
me, FWIW.

& yeah, the analogy to modules re: member function expansion seems relevant as 
far as I understand things too.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -797,20 +822,75 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(const ProcessSP &process_sp,
+  SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_for_memory_list;
+  error = process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_for_memory_list);
+  if (error.Fail()) {
+return error;
+  }
+
+  std::set stack_ranges;
+  for (const auto &core_range : ranges_for_memory_list) {
+stack_ranges.insert(core_range.range.start());
+  }
+  // We leave a little padding for dictionary and any other metadata we would
+  // want. Also so that we can put the header of the memory list 64 in 32b 
land,
+  // because the directory requires a 32b RVA.
+  Process::CoreFileMemoryRanges ranges;
+  error = process_sp->CalculateCoreFileSaveRanges(core_style, ranges);
+  if (error.Fail()) {
+return error;
+  }
+
+  uint64_t total_size =
+  256 + (ranges.size() * sizeof(llvm::minidump::MemoryDescriptor_64));
+  // Take all the memory that will fit in the 32b range.
+  for (int i = ranges.size() - 1; i >= 0; i--) {

Jlalond wrote:

The reverse is so that I can remove them in place, this was so that I could use 
two lists. The reason being is I already get the stacks in my first call to 
process, and then I call process again with the user specific style. This is so 
stacks are the first items in the memory list for the thread RVA's. 

So I remove anything from the second call to process and instead move it to the 
list of ranges I pass to memorylist, and the remaining go to memorylist64.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -797,20 +822,75 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(const ProcessSP &process_sp,
+  SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_for_memory_list;

Jlalond wrote:

I responded above on this, I tried to minimize allocating vectors and reduce 
iterations by just removing what will fit in 32b. 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status
+  AddMemoryList_32(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status FixThreads();
+  lldb_private::Status FlushToDisk();
+
+  lldb_private::Status DumpHeader() const;
+  lldb_private::Status DumpDirectories() const;
+  bool CheckIf_64Bit(const size_t size);
   // Add directory of StreamType pointing to the current end of the prepared
   // file with the specified size.
-  void AddDirectory(llvm::minidump::StreamType type, size_t stream_size);
-  size_t GetCurrentDataEndOffset() const;
-
-  // Stores directories to later put them at the end of minidump file
+  void AddDirectory(llvm::minidump::StreamType type, uint64_t stream_size);
+  lldb::addr_t GetCurrentDataEndOffset() const;
+  // Stores directories to fill in later
   std::vector m_directories;
+  // When we write off the threads for the first time, we need to clean them up
+  // and give them the correct RVA once we write the stack memory list.
+  std::map m_thread_by_range_start;

Jlalond wrote:

In this case, the map is the start of the memory range, and the corresponding 
thread. So I think addr_t is more clear. If it is not, I'll take map name 
recommendations.

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread Aleksandr Korepanov via lldb-commits

https://github.com/AlexK0 created 
https://github.com/llvm/llvm-project/pull/95446

Hello!

Currently, watchpoints don't work on Windows (this can be reproduced with the 
existing tests). This patch fixes the related issues so that the tests and 
watchpoints start working.

Here is the list of tests that are fixed by this patch (on Windows, checked in 
**release/18.x** branch):
- commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py
- commands/watchpoints/multiple_hits/TestMultipleHits.py
- commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
- commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
- commands/watchpoints/unaligned-watchpoint/TestUnalignedWatchpoint.py
- commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py
- commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py
- 
commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py
- 
commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
- commands/watchpoints/watchpoint_count/TestWatchpointCount.py
- commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
- commands/watchpoints/watchpoint_size/TestWatchpointSizes.py
- python_api/watchpoint/TestSetWatchpoint.py
- python_api/watchpoint/TestWatchpointIgnoreCount.py
- python_api/watchpoint/TestWatchpointIter.py
- python_api/watchpoint/condition/TestWatchpointConditionAPI.py
- python_api/watchpoint/watchlocation/TestTargetWatchAddress.py


>From 0053a9cfdd4637be0d52901b5d871ed1c43e06a1 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Thu, 13 Jun 2024 15:56:08 +0200
Subject: [PATCH] [LLDB][Windows] Fix watchpoints for Windows

The patch fixes not working watchpoints on windows.
---
 lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index eb0834b1159f6..780147fc607e9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -406,7 +406,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
   stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  *stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;
@@ -857,7 +857,7 @@ Status ProcessWindows::EnableWatchpoint(WatchpointSP wp_sp, 
bool notify) {
   info.address = wp_sp->GetLoadAddress();
   info.size = wp_sp->GetByteSize();
   info.read = wp_sp->WatchpointRead();
-  info.write = wp_sp->WatchpointWrite();
+  info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
 
   for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff ffab938f50fa999f2218976f7de78cf8e4f70d4e 
0053a9cfdd4637be0d52901b5d871ed1c43e06a1 -- 
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 780147fc60..f383b3d40a 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -405,8 +405,7 @@ void ProcessWindows::RefreshStateAfterStop() {
"{1:x} with watchpoint {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
-  stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id);
+  stop_info = StopInfo::CreateStopReasonWithWatchpointID(*stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;

``




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


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits


@@ -810,6 +809,65 @@ const char *SBProcess::GetBroadcasterClass() {
   return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
 }
 
+lldb::SBAddressRangeList
+SBProcess::FindRangesInMemory(const void *buf, uint64_t size,
+  SBAddressRangeList &ranges, uint32_t alignment,
+  uint32_t max_matches, SBError &error) {
+  LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
+
+  Log *log = GetLog(LLDBLog::Process);
+  lldb::SBAddressRangeList matches;
+
+  ProcessSP process_sp(GetSP());
+  if (!process_sp) {
+LLDB_LOGF(log, "SBProcess::%s SBProcess is invalid.", __FUNCTION__);
+return matches;
+  }
+  Process::StopLocker stop_locker;
+  if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
+LLDB_LOGF(
+log,
+"SBProcess::%s Cannot find process in memory while process is 
running.",
+__FUNCTION__);
+return matches;
+  }
+  std::lock_guard guard(
+  process_sp->GetTarget().GetAPIMutex());
+  matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
+  reinterpret_cast(buf), size, ranges.m_opaque_up->ref(),
+  alignment, max_matches, error.ref());
+  return matches;
+}
+
+lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
+ SBAddressRange &range, uint32_t alignment,
+ SBError &error) {
+  LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
+
+  if (!range.IsValid()) {
+error.SetErrorStringWithFormat("range is invalid");
+return LLDB_INVALID_ADDRESS;
+  }
+

mbucko wrote:

We are dereferencing the pointer though. If I don't do this check and someone 
passes in an invalid range, it will segfault.

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


[Lldb-commits] [lldb] [lldb][test] Force dwarf4 usage in test requiring it (PR #95449)

2024-06-13 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/95449

This test is explicitly checking for dwarf 4 behavior on Apple platforms, so we 
should explicitly use the dwarf4 flag.

Related to https://github.com/llvm/llvm-project/pull/95164

>From d4915d55cfbef6f9d4183db648725b3edf5e8024 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Thu, 13 Jun 2024 11:16:45 -0700
Subject: [PATCH] [lldb][test] Force dwarf4 usage in test requiring it

This test is explicitly checking for dwarf 4 behavior on Apple platforms, so we
should explicitly use the dwarf4 flag.
---
 lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
index 00440531e99f7..5bcb2cbcbbe29 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
@@ -1,5 +1,5 @@
 // Test that we use the apple indexes.
-// RUN: %clang %s -g -c -o %t --target=x86_64-apple-macosx
+// RUN: %clang %s -g -c -o %t --target=x86_64-apple-macosx -gdwarf-4
 // RUN: lldb-test symbols %t | FileCheck %s
 
 // CHECK: .apple_names index present

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


[Lldb-commits] [lldb] [lldb][test] Force dwarf4 usage in test requiring it (PR #95449)

2024-06-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

This test is explicitly checking for dwarf 4 behavior on Apple platforms, so we 
should explicitly use the dwarf4 flag.

Related to https://github.com/llvm/llvm-project/pull/95164

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


1 Files Affected:

- (modified) lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp 
(+1-1) 


``diff
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
index 00440531e99f7..5bcb2cbcbbe29 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/apple-index-is-used.cpp
@@ -1,5 +1,5 @@
 // Test that we use the apple indexes.
-// RUN: %clang %s -g -c -o %t --target=x86_64-apple-macosx
+// RUN: %clang %s -g -c -o %t --target=x86_64-apple-macosx -gdwarf-4
 // RUN: lldb-test symbols %t | FileCheck %s
 
 // CHECK: .apple_names index present

``




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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread Aleksandr Korepanov via lldb-commits

https://github.com/AlexK0 updated 
https://github.com/llvm/llvm-project/pull/95446

>From 0053a9cfdd4637be0d52901b5d871ed1c43e06a1 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Thu, 13 Jun 2024 15:56:08 +0200
Subject: [PATCH 1/2] [LLDB][Windows] Fix watchpoints for Windows

The patch fixes not working watchpoints on windows.
---
 lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index eb0834b1159f6..780147fc607e9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -406,7 +406,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
   stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  *stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;
@@ -857,7 +857,7 @@ Status ProcessWindows::EnableWatchpoint(WatchpointSP wp_sp, 
bool notify) {
   info.address = wp_sp->GetLoadAddress();
   info.size = wp_sp->GetByteSize();
   info.read = wp_sp->WatchpointRead();
-  info.write = wp_sp->WatchpointWrite();
+  info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
 
   for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();

>From 19bd5b051b69677682b4923b8cee7054607ff480 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Thu, 13 Jun 2024 20:24:24 +0200
Subject: [PATCH 2/2] fixup! [LLDB][Windows] Fix watchpoints for Windows

Style fix
---
 lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 780147fc607e9..f383b3d40a4f3 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -405,8 +405,7 @@ void ProcessWindows::RefreshStateAfterStop() {
"{1:x} with watchpoint {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
-  stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id);
+  stop_info = StopInfo::CreateStopReasonWithWatchpointID(*stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;

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


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From a5335c87ed7e04b8b6d74cf5f166bfcdd9f723e6 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  64 +-
 lldb/source/Target/Process.cpp| 118 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 591 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
&ranges,
+ uint32_t alignment, uint32_t max_matches, SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges &ref();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges &ranges,
+   size_t alignment, size_t max_matches,
+   Status &error);
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange &range, size_t alignment,
+Status &error);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status &error) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges &matches,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has

[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 02345eaea4eab488234d0dccd437676279b065e6 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  64 +-
 lldb/source/Target/Process.cpp| 117 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 590 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
&ranges,
+ uint32_t alignment, uint32_t max_matches, SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges &ref();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges &ranges,
+   size_t alignment, size_t max_matches,
+   Status &error);
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange &range, size_t alignment,
+Status &error);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status &error) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges &matches,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -797,20 +822,75 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(const ProcessSP &process_sp,
+  SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_for_memory_list;
+  error = process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_for_memory_list);
+  if (error.Fail()) {
+return error;
+  }
+
+  std::set stack_ranges;
+  for (const auto &core_range : ranges_for_memory_list) {
+stack_ranges.insert(core_range.range.start());
+  }
+  // We leave a little padding for dictionary and any other metadata we would
+  // want. Also so that we can put the header of the memory list 64 in 32b 
land,
+  // because the directory requires a 32b RVA.
+  Process::CoreFileMemoryRanges ranges;
+  error = process_sp->CalculateCoreFileSaveRanges(core_style, ranges);
+  if (error.Fail()) {
+return error;
+  }
+
+  uint64_t total_size =
+  256 + (ranges.size() * sizeof(llvm::minidump::MemoryDescriptor_64));

Jlalond wrote:

It's actually arbitrary. I wanted to make sure we had some byte aligned padding 
before the end of the file, so that all the MemoryDescriptors64 could be 32b 
addressable with the data after them.

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

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

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

Thanks for the fixes, these are correct and they look like they're caused by me 
when I was doing my work on watchpoints earlier this year.  Do you have 
permissions to merge the PR?

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread via lldb-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status
+  AddMemoryList_32(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status FixThreads();
+  lldb_private::Status FlushToDisk();
+
+  lldb_private::Status DumpHeader() const;
+  lldb_private::Status DumpDirectories() const;
+  bool CheckIf_64Bit(const size_t size);
   // Add directory of StreamType pointing to the current end of the prepared
   // file with the specified size.
-  void AddDirectory(llvm::minidump::StreamType type, size_t stream_size);
-  size_t GetCurrentDataEndOffset() const;
-
-  // Stores directories to later put them at the end of minidump file
+  void AddDirectory(llvm::minidump::StreamType type, uint64_t stream_size);
+  lldb::addr_t GetCurrentDataEndOffset() const;
+  // Stores directories to fill in later
   std::vector m_directories;
+  // When we write off the threads for the first time, we need to clean them up
+  // and give them the correct RVA once we write the stack memory list.
+  std::map m_thread_by_range_start;
   // Main data buffer consisting of data without the minidump header and
   // directories
   lldb_private::DataBufferHeap m_data;
+  uint m_expected_directories = 0;
+  uint64_t m_saved_data_size = 0;
+  size_t m_thread_list_start = 0;
+  // We set the max write amount to 128 mb
+  // Linux has a signed 32b - some buffer on writes
+  // and we have guarauntee a user memory region / 'object' could be over 2gb
+  // now that we support 64b memory dumps.
+  static constexpr size_t m_write_chunk_max = (1024 * 1024 * 128);

Jlalond wrote:

Avoiding OS limitations was the goal. Originally when I was testing large 
minidumps, I created a large array, that was 5.2gb in size. Linux has a max 
write byte size that is slightly less than `SSIZE_T` max. However that also 
ends up being platform specific, and we should probably make the write size the 
architecture byte width max value for `SSIZE_T`.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();

Jlalond wrote:

To start, this is not a good name, but we need at least two methods: 
 - One method to just write data from the buffer to the current end of the file
 - One method to finalize and run header/directory cleanup.

When trying to get this done I couldn't come up with a good name, so I am 
soliciting ideas. I think going forward some better version could be 
`CompleteFile()` `FinalizeFile()` `WriteAndFinish()` but I don't like any of 
them

https://github.com/llvm/llvm-project/pull/95312
___
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] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread Jay Foad via lldb-commits

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


[Lldb-commits] [lldb] d4a0154 - [llvm-project] Fix typo "seperate" (#95373)

2024-06-13 Thread via lldb-commits

Author: Jay Foad
Date: 2024-06-13T20:20:27+01:00
New Revision: d4a0154902fb9b0611ed857134b26a64a1d5ad1e

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

LOG: [llvm-project] Fix typo "seperate" (#95373)

Added: 


Modified: 
clang-tools-extra/clangd/TidyProvider.cpp
clang/include/clang/Frontend/FrontendOptions.h
clang/include/clang/InstallAPI/DylibVerifier.h
clang/lib/InstallAPI/Visitor.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
compiler-rt/test/dfsan/custom.cpp
compiler-rt/test/orc/TestCases/Linux/ppc64/trivial-tls-pwr10.test
flang/examples/FlangOmpReport/yaml_summarizer.py
flang/lib/Semantics/check-omp-structure.cpp
flang/test/Driver/mllvm_vs_mmlir.f90
libc/src/__support/FPUtil/x86_64/FEnvImpl.h
libc/src/stdio/printf_core/float_hex_converter.h
libc/test/src/__support/str_to_float_comparison_test.cpp
lld/test/wasm/data-segments.ll
lldb/include/lldb/Expression/DWARFExpressionList.h
lldb/include/lldb/Target/MemoryTagManager.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
lldb/test/API/CMakeLists.txt
lldb/test/API/tools/lldb-server/memory-tagging/TestGdbRemoteMemoryTagging.py

lldb/test/Shell/SymbolFile/DWARF/x86/DW_AT_data_bit_offset-DW_OP_stack_value.s
llvm/include/llvm/CodeGen/LiveRegUnits.h
llvm/include/llvm/CodeGen/MIRFormatter.h
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/Support/raw_socket_stream.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/FileCheck/FileCheck.cpp
llvm/lib/IR/DebugInfo.cpp
llvm/lib/MC/MCPseudoProbe.cpp
llvm/lib/Support/VirtualFileSystem.cpp
llvm/lib/Support/raw_socket_stream.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/lib/TextAPI/Utils.cpp
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
llvm/test/CodeGen/X86/AMX/amx-greedy-ra.ll
llvm/test/CodeGen/X86/apx/shift-eflags.ll
llvm/test/CodeGen/X86/merge-consecutive-stores-nt.ll
llvm/test/CodeGen/X86/shift-eflags.ll
llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
llvm/test/Transforms/LoopVectorize/LoongArch/defaults.ll
llvm/test/Transforms/LoopVectorize/RISCV/defaults.ll
llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll
llvm/test/Verifier/alloc-size-failedparse.ll
llvm/test/tools/llvm-ar/windows-path.test
llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-win.test
llvm/tools/llvm-cov/CodeCoverage.cpp
llvm/tools/llvm-profgen/PerfReader.cpp
llvm/unittests/Support/Path.cpp
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
mlir/include/mlir/Analysis/Presburger/PresburgerSpace.h
mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h
mlir/lib/Analysis/Presburger/PresburgerSpace.cpp
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.h
mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_reduce_custom_prod.mlir
mlir/test/Target/LLVMIR/omptarget-constant-alloca-raise.mlir
openmp/tools/Modules/FindOpenMPTarget.cmake

Removed: 




diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index a4121df30d3df..a87238e0c0938 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -195,10 +195,10 @@ TidyProvider addTidyChecks(llvm::StringRef Checks,
 }
 
 TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) 
{
-  constexpr llvm::StringLiteral Seperator(",");
+  constexpr llvm::StringLiteral Separator(",");
   static const std::string BadChecks = llvm::join_items(
-  Seperator,
-  // We want this list to start with a seperator to
+  Separator,
+  // We want this list to start with a separator to
   // simplify appending in the lambda. So including an
   // empty string here will force that.
   "",
@@ -227,7 +227,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   for (const std::string &Str : ExtraBadChecks) {
 if (Str.empty())
   continue;
-Size += Seperator.size();
+Size += Separator.size();
 if (LLVM_LIKELY(Str.front() != '-'))
   ++Size;
 Size += Str.size();
@@ -238,7 +238,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
   for (const std

[Lldb-commits] [clang] [clang-tools-extra] [compiler-rt] [flang] [libc] [lld] [lldb] [llvm] [mlir] [openmp] [llvm-project] Fix typo "seperate" (PR #95373)

2024-06-13 Thread Arjun P via lldb-commits

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


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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


@@ -797,20 +822,75 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(const ProcessSP &process_sp,
+  SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_for_memory_list;
+  error = process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_for_memory_list);
+  if (error.Fail()) {
+return error;
+  }
+
+  std::set stack_ranges;
+  for (const auto &core_range : ranges_for_memory_list) {
+stack_ranges.insert(core_range.range.start());
+  }

Jlalond wrote:

I would say we should error, especially with the reduced stacks since !92002 if 
the stacks did exceed 4gb this would be a case where we wouldn't fully be able 
to support the user.

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Aleksandr Korepanov (AlexK0)


Changes

Hello!

Currently, watchpoints don't work on Windows (this can be reproduced with the 
existing tests). This patch fixes the related issues so that the tests and 
watchpoints start working.

Here is the list of tests that are fixed by this patch (on Windows, checked in 
**release/18.x** branch):
- commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py
- commands/watchpoints/multiple_hits/TestMultipleHits.py
- commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
- commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
- commands/watchpoints/unaligned-watchpoint/TestUnalignedWatchpoint.py
- commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py
- commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py
- 
commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py
- 
commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
- commands/watchpoints/watchpoint_count/TestWatchpointCount.py
- commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
- commands/watchpoints/watchpoint_size/TestWatchpointSizes.py
- python_api/watchpoint/TestSetWatchpoint.py
- python_api/watchpoint/TestWatchpointIgnoreCount.py
- python_api/watchpoint/TestWatchpointIter.py
- python_api/watchpoint/condition/TestWatchpointConditionAPI.py
- python_api/watchpoint/watchlocation/TestTargetWatchAddress.py


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


1 Files Affected:

- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
(+2-2) 


``diff
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index eb0834b1159f6..780147fc607e9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -406,7 +406,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
   stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  *stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;
@@ -857,7 +857,7 @@ Status ProcessWindows::EnableWatchpoint(WatchpointSP wp_sp, 
bool notify) {
   info.address = wp_sp->GetLoadAddress();
   info.size = wp_sp->GetByteSize();
   info.read = wp_sp->WatchpointRead();
-  info.write = wp_sp->WatchpointWrite();
+  info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
 
   for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();

``




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


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 42ec0dd50ea037c832e38541204d3a911577cfab Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  68 ++-
 lldb/source/Target/Process.cpp| 116 
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 172 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +++
 .../API/python_api/find_in_memory/main.cpp|  11 ++
 11 files changed, 555 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
&ranges,
+ uint32_t alignment, uint32_t max_matches, SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges &ref();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..3ac19a74b8b99 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges &ranges,
+   size_t alignment, size_t max_count,
+   Status &error);
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange &range, size_t alignment,
+Status &error);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status &error) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges &matches,
+  size_t alignment, size_t max_count);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

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

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

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


@@ -406,7 +406,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
   stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  *stop_thread, id);

jasonmolenda wrote:

Ah yikes, I believe I broke this in https://reviews.llvm.org/D147816 and that 
`addr_t` is being treated like a boolean now :( 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);

clayborg wrote:

yeah, always good to minimize code changes to make reviewing easier

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -858,10 +937,225 @@ Status MinidumpFileBuilder::Dump(lldb::FileUP 
&core_file) const {
   return error;
 }
 
-size_t MinidumpFileBuilder::GetDirectoriesNum() const {
-  return m_directories.size();
+Status MinidumpFileBuilder::AddMemoryList_32(
+const ProcessSP &process_sp, const Process::CoreFileMemoryRanges &ranges) {
+  std::vector descriptors;
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+// Take the offset before we write.
+const size_t offset_for_data = GetCurrentDataEndOffset();
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);
+
+LLDB_LOGF(
+log,
+"AddMemoryList %zu/%zu reading memory for region (%zu bytes) [%zx, 
%zx)",
+region_index, ranges.size(), size, addr, addr + size);
+++region_index;
+
+const size_t bytes_read =
+process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
+if (error.Fail() || bytes_read == 0) {
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  // Just skip sections with errors or zero bytes in 32b mode
+  continue;
+} else if (bytes_read != size) {
+  LLDB_LOGF(log, "Memory region at: %zu failed to read %zu bytes", addr,
+size);
+}
+
+MemoryDescriptor descriptor;
+descriptor.StartOfMemoryRange =
+static_cast(addr);
+descriptor.Memory.DataSize =
+static_cast(bytes_read);
+descriptor.Memory.RVA =
+static_cast(offset_for_data);
+descriptors.push_back(descriptor);
+if (m_thread_by_range_start.count(addr) > 0) {
+  m_thread_by_range_start[addr].Stack = descriptor;
+}
+
+// Add the data to the buffer, flush as needed.
+error = AddData(data_up->GetBytes(), bytes_read);
+if (error.Fail())
+  return error;
+  }
+
+  // Add a directory that references this list
+  // With a size of the number of ranges as a 32 bit num
+  // And then the size of all the ranges
+  AddDirectory(StreamType::MemoryList,
+   sizeof(llvm::support::ulittle32_t) +
+   descriptors.size() *
+   sizeof(llvm::minidump::MemoryDescriptor));
+
+  llvm::support::ulittle32_t memory_ranges_num =
+  static_cast(descriptors.size());
+  m_data.AppendData(&memory_ranges_num, sizeof(llvm::support::ulittle32_t));
+  // For 32b we can get away with writing off the descriptors after the data.
+  // This means no cleanup loop needed.
+  m_data.AppendData(descriptors.data(),
+descriptors.size() * sizeof(MemoryDescriptor));
+
+  return error;
 }
 
-size_t MinidumpFileBuilder::GetCurrentDataEndOffset() const {
-  return sizeof(llvm::minidump::Header) + m_data.GetByteSize();
+Status MinidumpFileBuilder::AddMemoryList_64(
+const ProcessSP &process_sp, const Process::CoreFileMemoryRanges &ranges) {
+  AddDirectory(StreamType::Memory64List,
+   (sizeof(llvm::support::ulittle64_t) * 2) +
+   ranges.size() * 
sizeof(llvm::minidump::MemoryDescriptor_64));
+
+  llvm::support::ulittle64_t memory_ranges_num =
+  static_cast(ranges.size());
+  m_data.AppendData(&memory_ranges_num, sizeof(llvm::support::ulittle64_t));
+  llvm::support::ulittle64_t memory_ranges_base_rva =
+  static_cast(GetCurrentDataEndOffset());
+  m_data.AppendData(&memory_ranges_base_rva,
+sizeof(llvm::support::ulittle64_t));
+  // Capture the starting offset, so we can do cleanup later if needed.
+  uint64_t starting_offset = GetCurrentDataEndOffset();
+
+  bool cleanup_required = false;
+  std::vector descriptors;
+  // Enumerate the ranges and create the memory descriptors so we can append
+  // them first
+  for (const auto core_range : ranges) {
+// Add the space required to store the memory descriptor
+MemoryDescriptor_64 memory_desc;
+memory_desc.StartOfMemoryRange =
+static_cast(core_range.range.start());
+memory_desc.DataSize =
+static_cast(core_range.range.size());
+descriptors.push_back(memory_desc);
+// Now write this memory descriptor to the buffer.
+m_data.AppendData(&memory_desc, sizeof(MemoryDescriptor_64));
+  }
+
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);
+
+LLDB_LOGF(log,
+  "AddMemoryList_64 %zu/%zu reading memory for region (%zu bytes) "
+  "[%zx, %zx)",
+  region_index, ranges.size(), size, addr, addr + size);
+++region_index;
+
+const size_t bytes_read =
+process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
+if (error.Fail()) {
+

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();

clayborg wrote:

It would be nice to just have a `Finalize()` that does what `CompleteFile` and 
`FinalizeFile` and `WriteAndFinish` would do?

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -797,20 +794,89 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_32;
+  Process::CoreFileMemoryRanges ranges_64;
+  error = m_process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_32);
+  if (error.Fail())
+return error;
 
+  std::set stack_start_addresses;
+  for (const auto &core_range : ranges_32)
+stack_start_addresses.insert(core_range.range.start());
+
+  uint64_t total_size =
+  ranges_32.size() * sizeof(llvm::minidump::MemoryDescriptor);
+  for (const auto &core_range : ranges_32)
+total_size += core_range.range.size();
+
+  if (total_size >= UINT32_MAX) {
+error.SetErrorStringWithFormat("Unable to write minidump. Stack memory "
+   "exceeds 32b limit. (Num Stacks %zu)",
+   ranges_32.size());
+return error;
+  }
+
+  Process::CoreFileMemoryRanges all_core_memory_ranges;
+  if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {
+error = m_process_sp->CalculateCoreFileSaveRanges(core_style,
+  all_core_memory_ranges);
+if (error.Fail())
+  return error;
+  }
+
+  // We need to calculate the MemoryDescriptor size in the worst case
+  // Where all memory descriptors are 64b. We also leave some additional 
padding
+  // So that we convert over to 64b with space to spare. This does not waste
+  // space in the dump But instead converts some memory from being in the
+  // memorylist_32 to the memorylist_64.
+  total_size += 256 + (ranges_64.size() - stack_start_addresses.size()) *
+  sizeof(llvm::minidump::MemoryDescriptor_64);
+
+  for (const auto &core_range : all_core_memory_ranges) {
+addr_t size_to_add =
+core_range.range.size() + sizeof(llvm::minidump::MemoryDescriptor);
+if (stack_start_addresses.count(core_range.range.start()) > 0) {
+  // Don't double save stacks.
+  continue;
+} else if (total_size + size_to_add < UINT32_MAX) {

clayborg wrote:

No need for `else if` if we continue:
```
if (stack_start_addresses.count(core_range.range.start()) > 0)
  continue;  // Stacks are already in ranges_32

if (total_size + size_to_add < UINT32_MAX)
```

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -858,10 +923,224 @@ Status MinidumpFileBuilder::Dump(lldb::FileUP 
&core_file) const {
   return error;
 }
 
-size_t MinidumpFileBuilder::GetDirectoriesNum() const {
-  return m_directories.size();
+Status MinidumpFileBuilder::AddMemoryList_32(
+const Process::CoreFileMemoryRanges &ranges) {
+  std::vector descriptors;
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;

clayborg wrote:

Make on DataBufferHeap outside of this loop and re-use it:
```
lldb::offset_t max_size = 0;
for (const auto &core_range : ranges) {
  if (core_range.renge.size() > max_size)
max_size = core_range.renge.size();
}
auto data_up = std::make_unique(max_size, 0);
```

auto data_up = std::make_unique(size, 0);

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -797,20 +794,89 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_32;
+  Process::CoreFileMemoryRanges ranges_64;
+  error = m_process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_32);
+  if (error.Fail())
+return error;
 
+  std::set stack_start_addresses;
+  for (const auto &core_range : ranges_32)
+stack_start_addresses.insert(core_range.range.start());
+
+  uint64_t total_size =
+  ranges_32.size() * sizeof(llvm::minidump::MemoryDescriptor);
+  for (const auto &core_range : ranges_32)
+total_size += core_range.range.size();
+
+  if (total_size >= UINT32_MAX) {
+error.SetErrorStringWithFormat("Unable to write minidump. Stack memory "
+   "exceeds 32b limit. (Num Stacks %zu)",
+   ranges_32.size());
+return error;
+  }
+
+  Process::CoreFileMemoryRanges all_core_memory_ranges;
+  if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {
+error = m_process_sp->CalculateCoreFileSaveRanges(core_style,
+  all_core_memory_ranges);
+if (error.Fail())
+  return error;
+  }
+
+  // We need to calculate the MemoryDescriptor size in the worst case
+  // Where all memory descriptors are 64b. We also leave some additional 
padding
+  // So that we convert over to 64b with space to spare. This does not waste
+  // space in the dump But instead converts some memory from being in the
+  // memorylist_32 to the memorylist_64.
+  total_size += 256 + (ranges_64.size() - stack_start_addresses.size()) *
+  sizeof(llvm::minidump::MemoryDescriptor_64);
+
+  for (const auto &core_range : all_core_memory_ranges) {
+addr_t size_to_add =
+core_range.range.size() + sizeof(llvm::minidump::MemoryDescriptor);
+if (stack_start_addresses.count(core_range.range.start()) > 0) {
+  // Don't double save stacks.
+  continue;
+} else if (total_size + size_to_add < UINT32_MAX) {
+  ranges_32.push_back(core_range);
+  total_size += core_range.range.size();
+  total_size += sizeof(llvm::minidump::MemoryDescriptor);

clayborg wrote:

Change these two lines to:
```
total_size += size_to_add;
```


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -50,48 +60,75 @@ class MinidumpFileBuilder {
 
   ~MinidumpFileBuilder() = default;
 
+  lldb_private::Status AddHeaderAndCalculateDirectories();
   // Add SystemInfo stream, used for storing the most basic information
   // about the system, platform etc...
-  lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple);
+  lldb_private::Status AddSystemInfo();
   // Add ModuleList stream, containing information about all loaded modules
   // at the time of saving minidump.
-  lldb_private::Status AddModuleList(lldb_private::Target &target);
+  lldb_private::Status AddModuleList();
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+  lldb_private::Status AddThreadList();
   // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
+  void AddExceptions();
   // Add MiscInfo stream, mainly providing ProcessId
-  void AddMiscInfo(const lldb::ProcessSP &process_sp);
+  void AddMiscInfo();
   // Add informative files about a Linux process
-  void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
-  // Dump the prepared data into file. In case of the failure data are
-  // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  void AddLinuxFileStreams();
+
+  lldb_private::Status AddMemory(lldb::SaveCoreStyle core_style);

clayborg wrote:

I would leave this named the same as it was before as `AddMemoryList` and move 
it back up to where it used to be in this source file

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -858,10 +937,225 @@ Status MinidumpFileBuilder::Dump(lldb::FileUP 
&core_file) const {
   return error;
 }
 
-size_t MinidumpFileBuilder::GetDirectoriesNum() const {
-  return m_directories.size();
+Status MinidumpFileBuilder::AddMemoryList_32(
+const ProcessSP &process_sp, const Process::CoreFileMemoryRanges &ranges) {
+  std::vector descriptors;
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+// Take the offset before we write.
+const size_t offset_for_data = GetCurrentDataEndOffset();
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);
+
+LLDB_LOGF(
+log,
+"AddMemoryList %zu/%zu reading memory for region (%zu bytes) [%zx, 
%zx)",
+region_index, ranges.size(), size, addr, addr + size);
+++region_index;
+
+const size_t bytes_read =
+process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
+if (error.Fail() || bytes_read == 0) {
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  // Just skip sections with errors or zero bytes in 32b mode
+  continue;
+} else if (bytes_read != size) {
+  LLDB_LOGF(log, "Memory region at: %zu failed to read %zu bytes", addr,
+size);
+}
+
+MemoryDescriptor descriptor;
+descriptor.StartOfMemoryRange =
+static_cast(addr);
+descriptor.Memory.DataSize =
+static_cast(bytes_read);
+descriptor.Memory.RVA =
+static_cast(offset_for_data);
+descriptors.push_back(descriptor);
+if (m_thread_by_range_start.count(addr) > 0) {
+  m_thread_by_range_start[addr].Stack = descriptor;
+}

clayborg wrote:

Still need to remove these braces from this if

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -858,10 +937,225 @@ Status MinidumpFileBuilder::Dump(lldb::FileUP 
&core_file) const {
   return error;
 }
 
-size_t MinidumpFileBuilder::GetDirectoriesNum() const {
-  return m_directories.size();
+Status MinidumpFileBuilder::AddMemoryList_32(
+const ProcessSP &process_sp, const Process::CoreFileMemoryRanges &ranges) {
+  std::vector descriptors;
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+// Take the offset before we write.
+const size_t offset_for_data = GetCurrentDataEndOffset();
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);

clayborg wrote:

re-use the one copy of `data_up` from above, just remove this line.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -28,17 +29,90 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Minidump.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
+#include "llvm/TargetParser/Triple.h"
 
 #include "Plugins/Process/minidump/MinidumpTypes.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-types.h"
 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm::minidump;
 
-void MinidumpFileBuilder::AddDirectory(StreamType type, size_t stream_size) {
+Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
+  // First set the offset on the file, and on the bytes saved
+  m_saved_data_size += header_size;
+  // We know we will have at least Misc, SystemInfo, Modules, and ThreadList
+  // (corresponding memory list for stacks) And an additional memory list for
+  // non-stacks.
+
+  lldb_private::Target &target = m_process_sp->GetTarget();
+  m_expected_directories = 6;
+  // Check if OS is linux

clayborg wrote:

```
// Check if OS is linux and reserve directory space for all linux specific 
breakpad extension directories.
```

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -28,17 +29,90 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Minidump.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
+#include "llvm/TargetParser/Triple.h"
 
 #include "Plugins/Process/minidump/MinidumpTypes.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-types.h"
 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm::minidump;
 
-void MinidumpFileBuilder::AddDirectory(StreamType type, size_t stream_size) {
+Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
+  // First set the offset on the file, and on the bytes saved
+  m_saved_data_size += header_size;

clayborg wrote:

Can we have data already in the file here? If not we should assign 
`m_saved_data_size` here:
```
m_saved_data_size = header_size;
```

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -858,10 +923,224 @@ Status MinidumpFileBuilder::Dump(lldb::FileUP 
&core_file) const {
   return error;
 }
 
-size_t MinidumpFileBuilder::GetDirectoriesNum() const {
-  return m_directories.size();
+Status MinidumpFileBuilder::AddMemoryList_32(
+const Process::CoreFileMemoryRanges &ranges) {
+  std::vector descriptors;
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+// Take the offset before we write.
+const size_t offset_for_data = GetCurrentDataEndOffset();
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);
+
+LLDB_LOGF(log,
+  "/AddMemoryList/AddMemory/ %zu/%zu reading memory for region "
+  "(%zu bytes) [%zx, %zx)",
+  region_index, ranges.size(), size, addr, addr + size);
+++region_index;
+
+const size_t bytes_read =
+m_process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
+if (error.Fail() || bytes_read == 0) {
+  LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: 
%s",
+bytes_read, error.AsCString());
+  // Just skip sections with errors or zero bytes in 32b mode
+  continue;
+} else if (bytes_read != size) {
+  LLDB_LOGF(log, "Memory region at: %zu failed to read %zu bytes", addr,
+size);
+}
+
+MemoryDescriptor descriptor;
+descriptor.StartOfMemoryRange =
+static_cast(addr);
+descriptor.Memory.DataSize =
+static_cast(bytes_read);
+descriptor.Memory.RVA =
+static_cast(offset_for_data);
+descriptors.push_back(descriptor);
+if (m_thread_by_range_start.count(addr) > 0) {
+  m_thread_by_range_start[addr].Stack = descriptor;
+}
+
+// Add the data to the buffer, flush as needed.
+error = AddData(data_up->GetBytes(), bytes_read);
+if (error.Fail())
+  return error;
+  }
+
+  // Add a directory that references this list
+  // With a size of the number of ranges as a 32 bit num
+  // And then the size of all the ranges
+  AddDirectory(StreamType::MemoryList,
+   sizeof(llvm::support::ulittle32_t) +
+   descriptors.size() *
+   sizeof(llvm::minidump::MemoryDescriptor));
+
+  llvm::support::ulittle32_t memory_ranges_num =
+  static_cast(descriptors.size());
+  m_data.AppendData(&memory_ranges_num, sizeof(llvm::support::ulittle32_t));
+  // For 32b we can get away with writing off the descriptors after the data.
+  // This means no cleanup loop needed.
+  m_data.AppendData(descriptors.data(),
+descriptors.size() * sizeof(MemoryDescriptor));
+
+  return error;
 }
 
-size_t MinidumpFileBuilder::GetCurrentDataEndOffset() const {
-  return sizeof(llvm::minidump::Header) + m_data.GetByteSize();
+Status MinidumpFileBuilder::AddMemoryList_64(
+const Process::CoreFileMemoryRanges &ranges) {
+  AddDirectory(StreamType::Memory64List,
+   (sizeof(llvm::support::ulittle64_t) * 2) +
+   ranges.size() * 
sizeof(llvm::minidump::MemoryDescriptor_64));
+
+  llvm::support::ulittle64_t memory_ranges_num =
+  static_cast(ranges.size());
+  m_data.AppendData(&memory_ranges_num, sizeof(llvm::support::ulittle64_t));
+  llvm::support::ulittle64_t memory_ranges_base_rva =
+  static_cast(GetCurrentDataEndOffset());
+  m_data.AppendData(&memory_ranges_base_rva,
+sizeof(llvm::support::ulittle64_t));
+  // Capture the starting offset, so we can do cleanup later if needed.
+  uint64_t starting_offset = GetCurrentDataEndOffset();
+
+  bool cleanup_required = false;
+  std::vector descriptors;
+  // Enumerate the ranges and create the memory descriptors so we can append
+  // them first
+  for (const auto core_range : ranges) {
+// Add the space required to store the memory descriptor
+MemoryDescriptor_64 memory_desc;
+memory_desc.StartOfMemoryRange =
+static_cast(core_range.range.start());
+memory_desc.DataSize =
+static_cast(core_range.range.size());
+descriptors.push_back(memory_desc);
+// Now write this memory descriptor to the buffer.
+m_data.AppendData(&memory_desc, sizeof(MemoryDescriptor_64));
+  }
+
+  Status error;
+  Log *log = GetLog(LLDBLog::Object);
+  size_t region_index = 0;
+  for (const auto &core_range : ranges) {
+const addr_t addr = core_range.range.start();
+const addr_t size = core_range.range.size();
+auto data_up = std::make_unique(size, 0);

clayborg wrote:

move this out of the for loop and have it contain `max_size` bytes just like in 
the 32 bit variant of this function.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread Greg Clayton via lldb-commits


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status
+  AddMemoryList_32(const lldb::ProcessSP &process_sp,
+   const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status FixThreads();
+  lldb_private::Status FlushToDisk();
+
+  lldb_private::Status DumpHeader() const;
+  lldb_private::Status DumpDirectories() const;
+  bool CheckIf_64Bit(const size_t size);
   // Add directory of StreamType pointing to the current end of the prepared
   // file with the specified size.
-  void AddDirectory(llvm::minidump::StreamType type, size_t stream_size);
-  size_t GetCurrentDataEndOffset() const;
-
-  // Stores directories to later put them at the end of minidump file
+  void AddDirectory(llvm::minidump::StreamType type, uint64_t stream_size);
+  lldb::addr_t GetCurrentDataEndOffset() const;
+  // Stores directories to fill in later
   std::vector m_directories;
+  // When we write off the threads for the first time, we need to clean them up
+  // and give them the correct RVA once we write the stack memory list.
+  std::map m_thread_by_range_start;

clayborg wrote:

If it is an address then `lldb::addr_t` is the right choice. I must have 
confused this with another location that needed to use `lldb::offset_t` for an 
offset that was being stored as a `lldb::addr_t`

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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

>From 2e84cf46b9378307d9059aa1ce2a97046b0866b4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:00:07 +0100
Subject: [PATCH 1/3] [lldb][test] Add test for completing ObjCObjectType

This is a minimal reproducer for a crash reported internally
where we would try to call `DumpTypeDescription` on an incomplete
type. This crash surfaced as part of an NFC refactor of some
of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122
---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

>From 6081327e68d1df1594f17bda97e0f12506681772 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:07:19 +0100
Subject: [PATCH 2/3] fixup! clang-format

---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
index 011bd943b5967..919f35ce6060e 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -6,5 +6,5 @@
 
 int main() { return 0; }
 
-// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: (lldb) expression --language objc -- *(id)0x1234
 // CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

>From 2e3f16035167472fa82502cc8c05e68fee325d95 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 22:18:50 +0100
Subject: [PATCH 3/3] fixup! skip on linux and windows, change pointer value,
 move source into separate file

---
 lldb/test/Shell/Expr/Inputs/objc-cast.cpp |  1 +
 lldb/test/Shell/Expr/TestObjCIDCast.cpp   | 10 --
 lldb/test/Shell/Expr/TestObjCIDCast.test  |  9 +
 3 files changed, 10 insertions(+), 10 deletions(-)
 create mode 100644 lldb/test/Shell/Expr/Inputs/objc-cast.cpp
 delete mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.test

diff --git a/lldb/test/Shell/Expr/Inputs/objc-cast.cpp 
b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
new file mode 100644
index 0..76e8197013aab
--- /dev/null
+++ b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
deleted file mode 100644
index 919f35ce6060e..0
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clangxx_host %s -g -o %t
-//
-// RUN: %lldb -f %t \
-// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
-// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
-
-int main() { return 0; }
-
-// CHECK: (lldb) expression --language objc -- *(id)0x1234
-// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.test 
b/lldb/test/Shell/Expr/TestObjCIDCast.test

[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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


@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s

Michael137 wrote:

done

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread Aleksandr Korepanov via lldb-commits

AlexK0 wrote:

> Do you have permissions to merge the PR?

I don't have the necessary permissions. Could you please merge the PR when it 
becomes possible?

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


[Lldb-commits] [lldb] [lldb][API] Add Find(Ranges)InMemory() to Process SB API (PR #95007)

2024-06-13 Thread Miro Bucko via lldb-commits

https://github.com/mbucko updated 
https://github.com/llvm/llvm-project/pull/95007

>From 3a580b40d41575eb35c6fc3f465a628196299373 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 4 Jun 2024 12:01:48 -0700
Subject: [PATCH] [lldb][API] Add Find(Ranges)InMemory() to Process SB API

Test Plan:
llvm-lit 
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |   8 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   2 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBProcess.cpp |  68 +-
 lldb/source/Target/Process.cpp| 118 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 11 files changed, 595 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..dc8cd116fd420 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,14 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList
+  FindRangesInMemory(const void *buf, uint64_t size, SBAddressRangeList 
&ranges,
+ uint32_t alignment, uint32_t max_matches, SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..777cf81e2b1c3 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -14,6 +14,7 @@
 
 namespace lldb {
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -40,6 +41,7 @@ class AddressRangeListImpl {
 
 private:
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges &ref();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..a9840d889db89 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges &ranges,
+   size_t alignment, size_t max_matches,
+   Status &error);
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange &range, size_t alignment,
+Status &error);
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,10 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status &error) = 0;
 
+  void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size, AddressRanges &matches,
+  size_t alignment, size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has

[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

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

https://github.com/jasonmolenda updated 
https://github.com/llvm/llvm-project/pull/95446

>From 0053a9cfdd4637be0d52901b5d871ed1c43e06a1 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Thu, 13 Jun 2024 15:56:08 +0200
Subject: [PATCH 1/2] [LLDB][Windows] Fix watchpoints for Windows

The patch fixes not working watchpoints on windows.
---
 lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index eb0834b1159f6..780147fc607e9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -406,7 +406,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
   stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  *stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;
@@ -857,7 +857,7 @@ Status ProcessWindows::EnableWatchpoint(WatchpointSP wp_sp, 
bool notify) {
   info.address = wp_sp->GetLoadAddress();
   info.size = wp_sp->GetByteSize();
   info.read = wp_sp->WatchpointRead();
-  info.write = wp_sp->WatchpointWrite();
+  info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
 
   for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();

>From 19bd5b051b69677682b4923b8cee7054607ff480 Mon Sep 17 00:00:00 2001
From: Aleksandr Korepanov 
Date: Thu, 13 Jun 2024 20:24:24 +0200
Subject: [PATCH 2/2] fixup! [LLDB][Windows] Fix watchpoints for Windows

Style fix
---
 lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 780147fc607e9..f383b3d40a4f3 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -405,8 +405,7 @@ void ProcessWindows::RefreshStateAfterStop() {
"{1:x} with watchpoint {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
-  stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id);
+  stop_info = StopInfo::CreateStopReasonWithWatchpointID(*stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;

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


[Lldb-commits] [lldb] 00ed887 - [LLDB][Windows] Fix watchpoints for Windows (#95446)

2024-06-13 Thread via lldb-commits

Author: Aleksandr Korepanov
Date: 2024-06-13T14:50:31-07:00
New Revision: 00ed887454f7d7522f3eac8549661e51f864a9a7

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

LOG: [LLDB][Windows] Fix watchpoints for Windows (#95446)

Hello!

Currently, watchpoints don't work on Windows (this can be reproduced
with the existing tests). This patch fixes the related issues so that
the tests and watchpoints start working.

Here is the list of tests that are fixed by this patch (on Windows,
checked in **release/18.x** branch):
- commands/watchpoints/hello_watchpoint/TestMyFirstWatchpoint.py
- commands/watchpoints/multiple_hits/TestMultipleHits.py
- commands/watchpoints/multiple_threads/TestWatchpointMultipleThreads.py
- commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py
- commands/watchpoints/unaligned-watchpoint/TestUnalignedWatchpoint.py
- commands/watchpoints/watchpoint_commands/TestWatchpointCommands.py
-
commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandLLDB.py
-
commands/watchpoints/watchpoint_commands/command/TestWatchpointCommandPython.py
-
commands/watchpoints/watchpoint_commands/condition/TestWatchpointConditionCmd.py
- commands/watchpoints/watchpoint_count/TestWatchpointCount.py
- commands/watchpoints/watchpoint_disable/TestWatchpointDisable.py
- commands/watchpoints/watchpoint_size/TestWatchpointSizes.py
- python_api/watchpoint/TestSetWatchpoint.py
- python_api/watchpoint/TestWatchpointIgnoreCount.py
- python_api/watchpoint/TestWatchpointIter.py
- python_api/watchpoint/condition/TestWatchpointConditionAPI.py
- python_api/watchpoint/watchlocation/TestTargetWatchAddress.py

-

Co-authored-by: Jason Molenda 

Added: 


Modified: 
lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index eb0834b1159f6..f383b3d40a4f3 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -405,8 +405,7 @@ void ProcessWindows::RefreshStateAfterStop() {
"{1:x} with watchpoint {2}",
m_session_data->m_debugger->GetProcess().GetProcessId(), pc, 
id);
 
-  stop_info = StopInfo::CreateStopReasonWithWatchpointID(
-  *stop_thread, id, m_watchpoints[id].address);
+  stop_info = StopInfo::CreateStopReasonWithWatchpointID(*stop_thread, id);
   stop_thread->SetStopInfo(stop_info);
 
   return;
@@ -857,7 +856,7 @@ Status ProcessWindows::EnableWatchpoint(WatchpointSP wp_sp, 
bool notify) {
   info.address = wp_sp->GetLoadAddress();
   info.size = wp_sp->GetByteSize();
   info.read = wp_sp->WatchpointRead();
-  info.write = wp_sp->WatchpointWrite();
+  info.write = wp_sp->WatchpointWrite() || wp_sp->WatchpointModify();
 
   for (unsigned i = 0U; i < m_thread_list.GetSize(); i++) {
 Thread *thread = m_thread_list.GetThreadAtIndex(i).get();



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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

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

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


[Lldb-commits] [lldb] [LLDB][Windows] Fix watchpoints for Windows (PR #95446)

2024-06-13 Thread via lldb-commits

github-actions[bot] wrote:



@AlexK0 Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[Lldb-commits] [lldb] [llvm] Add support for using foreign type units in .debug_names. (PR #87740)

2024-06-13 Thread Greg Clayton via lldb-commits

clayborg wrote:

I think I have addressed all issues. Does anyone have time to review?

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


[Lldb-commits] [lldb] [lldb][test] Force dwarf4 usage in test requiring it (PR #95449)

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

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


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


[Lldb-commits] [lldb] 22ea97d - [lldb] Use packaging module instead of pkg_resources (#93712)

2024-06-13 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2024-06-13T16:00:12-07:00
New Revision: 22ea97d7bfd65abf68a68b13bf96ad69be23df54

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

LOG: [lldb] Use packaging module instead of pkg_resources (#93712)

Use the packaging [1] module for parsing version numbers, instead of
pkg_resources which is distributed with setuptools. I recently switched
over to using the latter, knowing it was deprecated (in favor of the
packaging module) because it comes with Python out of the box. Newer
versions of setuptools have removed `pkg_resources` so we have to use
packaging.

[1] https://pypi.org/project/packaging/

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/decorators.py
lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
lldb/test/Shell/helper/build.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/decorators.py 
b/lldb/packages/Python/lldbsuite/test/decorators.py
index 79cc0a2aeacbe..ecc7b81035f11 100644
--- a/lldb/packages/Python/lldbsuite/test/decorators.py
+++ b/lldb/packages/Python/lldbsuite/test/decorators.py
@@ -1,6 +1,6 @@
 # System modules
 from functools import wraps
-from pkg_resources import packaging
+from packaging import version
 import ctypes
 import locale
 import os
@@ -66,9 +66,7 @@ def fn_neq(x, y):
 "<=": fn_leq,
 }
 
-return op_lookup[comparison](
-packaging.version.parse(actual), packaging.version.parse(expected)
-)
+return op_lookup[comparison](version.parse(actual), 
version.parse(expected))
 
 
 def _match_decorator_property(expected, actual):

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 187d16aa1baa6..21f2095db90f8 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -8,8 +8,7 @@
 import subprocess
 import sys
 import os
-from urllib.parse import urlparse
-from pkg_resources import packaging
+from packaging import version
 
 # LLDB modules
 import lldb
@@ -309,17 +308,17 @@ def expectedCompilerVersion(compiler_version):
 # Assume the compiler version is at or near the top of trunk.
 return operator in [">", ">=", "!", "!=", "not"]
 
-version = packaging.version.parse(version_str)
-test_compiler_version = packaging.version.parse(test_compiler_version_str)
+actual_version = version.parse(version_str)
+test_compiler_version = version.parse(test_compiler_version_str)
 
 if operator == ">":
-return test_compiler_version > version
+return test_compiler_version > actual_version
 if operator == ">=" or operator == "=>":
-return test_compiler_version >= version
+return test_compiler_version >= actual_version
 if operator == "<":
-return test_compiler_version < version
+return test_compiler_version < actual_version
 if operator == "<=" or operator == "=<":
-return test_compiler_version <= version
+return test_compiler_version <= actual_version
 if operator == "!=" or operator == "!" or operator == "not":
 return version_str not in test_compiler_version_str
 return version_str in test_compiler_version_str

diff  --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py 
b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
index d770447f0771c..754579a59c11e 100644
--- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -61,9 +61,9 @@ def check_simulator_ostype(self, sdk, platform_name, 
arch=platform.machine()):
 
 # Older versions of watchOS (<7.0) only support i386
 if platform_name == "watchos":
-from pkg_resources import packaging
+from packaging import version
 
-if packaging.version.parse(vers) < packaging.version.parse("7.0"):
+if version.parse(vers) < version.parse("7.0"):
 arch = "i386"
 
 triple = "-".join([arch, "apple", platform_name + vers, "simulator"])

diff  --git a/lldb/test/Shell/helper/build.py b/lldb/test/Shell/helper/build.py
index d3c25bd944e98..b2b8146e88c75 100755
--- a/lldb/test/Shell/helper/build.py
+++ b/lldb/test/Shell/helper/build.py
@@ -441,9 +441,9 @@ def _get_vctools_version(self):
 if not subdirs:
 return None
 
-from distutils.version import StrictVersion
+from packaging import version
 
-subdirs.sort(key=lambda x: StrictVersion(x))
+subdirs.sort(key=lambda x: version.parse(x))
 
 if self.verbose:
 full_path = os.path.join(vcinstalldi

[Lldb-commits] [lldb] [lldb] Use packaging module instead of pkg_resources (PR #93712)

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

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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


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


[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/95075

>From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Mon, 10 Jun 2024 17:04:11 -0700
Subject: [PATCH 1/6] Add --targets and --modules option to statistics dump

---
 lldb/include/lldb/Target/Statistics.h   |  2 ++
 lldb/source/Commands/CommandObjectStats.cpp |  6 ++
 lldb/source/Commands/Options.td | 16 +---
 lldb/source/Target/Statistics.cpp   | 21 ++---
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'f':
 m_stats_options.load_all_debug_info = true;
 break;
+  case 'r':
+m_stats_options.include_targets = true;
+break;
+  case 'm':
+m_stats_options.include_modules = true;
+break;
   case 't':
 m_stats_options.include_transcript = true;
 break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
 Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
 Desc<"Dump only high-level summary statistics. "
  "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 
2>,
 Desc<"Dump the total possible debug info statistics. "
 "Force loading all the debug information if not yet loaded, and collect "
 "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+Desc<"Dump statistics for the targets, including breakpoints, expression "
+"evaluations, frame variables, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+Desc<"Dump statistics for the modules, including time and size of various "
+"aspects of the module and debug information, type system, path, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
 Desc<"If the setting interpreter.save-transcript is enabled and this "
 "option is specified, include a JSON array with all commands the user and/"
 "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..13c430d73990e 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
 
   json::Array json_targets;
@@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-for (const auto &target : debugger.GetTargetList().Targets())
+  if (!summary_only || include_targets) {
+if (target) {
   json_targets.emplace_back(target->ReportStatistics(options));
+} else {
+  for (const auto &target : debugger.GetTargetList().Targets())
+json_targets.emplace_back(target->ReportStatistics(options));
+ 

[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/95075

>From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Mon, 10 Jun 2024 17:04:11 -0700
Subject: [PATCH 1/7] Add --targets and --modules option to statistics dump

---
 lldb/include/lldb/Target/Statistics.h   |  2 ++
 lldb/source/Commands/CommandObjectStats.cpp |  6 ++
 lldb/source/Commands/Options.td | 16 +---
 lldb/source/Target/Statistics.cpp   | 21 ++---
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'f':
 m_stats_options.load_all_debug_info = true;
 break;
+  case 'r':
+m_stats_options.include_targets = true;
+break;
+  case 'm':
+m_stats_options.include_modules = true;
+break;
   case 't':
 m_stats_options.include_transcript = true;
 break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
 Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
 Desc<"Dump only high-level summary statistics. "
  "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 
2>,
 Desc<"Dump the total possible debug info statistics. "
 "Force loading all the debug information if not yet loaded, and collect "
 "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+Desc<"Dump statistics for the targets, including breakpoints, expression "
+"evaluations, frame variables, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+Desc<"Dump statistics for the modules, including time and size of various "
+"aspects of the module and debug information, type system, path, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
 Desc<"If the setting interpreter.save-transcript is enabled and this "
 "option is specified, include a JSON array with all commands the user and/"
 "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..13c430d73990e 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
 
   json::Array json_targets;
@@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-for (const auto &target : debugger.GetTargetList().Targets())
+  if (!summary_only || include_targets) {
+if (target) {
   json_targets.emplace_back(target->ReportStatistics(options));
+} else {
+  for (const auto &target : debugger.GetTargetList().Targets())
+json_targets.emplace_back(target->ReportStatistics(options));
+ 

[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/95075

>From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Mon, 10 Jun 2024 17:04:11 -0700
Subject: [PATCH 1/9] Add --targets and --modules option to statistics dump

---
 lldb/include/lldb/Target/Statistics.h   |  2 ++
 lldb/source/Commands/CommandObjectStats.cpp |  6 ++
 lldb/source/Commands/Options.td | 16 +---
 lldb/source/Target/Statistics.cpp   | 21 ++---
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'f':
 m_stats_options.load_all_debug_info = true;
 break;
+  case 'r':
+m_stats_options.include_targets = true;
+break;
+  case 'm':
+m_stats_options.include_modules = true;
+break;
   case 't':
 m_stats_options.include_transcript = true;
 break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
 Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
 Desc<"Dump only high-level summary statistics. "
  "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 
2>,
 Desc<"Dump the total possible debug info statistics. "
 "Force loading all the debug information if not yet loaded, and collect "
 "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+Desc<"Dump statistics for the targets, including breakpoints, expression "
+"evaluations, frame variables, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+Desc<"Dump statistics for the modules, including time and size of various "
+"aspects of the module and debug information, type system, path, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
 Desc<"If the setting interpreter.save-transcript is enabled and this "
 "option is specified, include a JSON array with all commands the user and/"
 "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..13c430d73990e 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
 
   json::Array json_targets;
@@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-for (const auto &target : debugger.GetTargetList().Targets())
+  if (!summary_only || include_targets) {
+if (target) {
   json_targets.emplace_back(target->ReportStatistics(options));
+} else {
+  for (const auto &target : debugger.GetTargetList().Targets())
+json_targets.emplace_back(target->ReportStatistics(options));
+ 

[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

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


[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/95075

>From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Mon, 10 Jun 2024 17:04:11 -0700
Subject: [PATCH 01/10] Add --targets and --modules option to statistics dump

---
 lldb/include/lldb/Target/Statistics.h   |  2 ++
 lldb/source/Commands/CommandObjectStats.cpp |  6 ++
 lldb/source/Commands/Options.td | 16 +---
 lldb/source/Target/Statistics.cpp   | 21 ++---
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'f':
 m_stats_options.load_all_debug_info = true;
 break;
+  case 'r':
+m_stats_options.include_targets = true;
+break;
+  case 'm':
+m_stats_options.include_modules = true;
+break;
   case 't':
 m_stats_options.include_transcript = true;
 break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
 Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
 Desc<"Dump only high-level summary statistics. "
  "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 
2>,
 Desc<"Dump the total possible debug info statistics. "
 "Force loading all the debug information if not yet loaded, and collect "
 "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+Desc<"Dump statistics for the targets, including breakpoints, expression "
+"evaluations, frame variables, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+Desc<"Dump statistics for the modules, including time and size of various "
+"aspects of the module and debug information, type system, path, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
 Desc<"If the setting interpreter.save-transcript is enabled and this "
 "option is specified, include a JSON array with all commands the user and/"
 "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..13c430d73990e 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
 
   json::Array json_targets;
@@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-for (const auto &target : debugger.GetTargetList().Targets())
+  if (!summary_only || include_targets) {
+if (target) {
   json_targets.emplace_back(target->ReportStatistics(options));
+} else {
+  for (const auto &target : debugger.GetTargetList().Targets())
+json_targets.emplace_back(target->ReportStatistics(options));

[Lldb-commits] [lldb] Add options to "statistics dump" to control what sections are dumped (PR #95075)

2024-06-13 Thread via lldb-commits

https://github.com/royitaqi updated 
https://github.com/llvm/llvm-project/pull/95075

>From f57f98f22425d3c869621b43b65da705d50b5934 Mon Sep 17 00:00:00 2001
From: Roy Shi 
Date: Mon, 10 Jun 2024 17:04:11 -0700
Subject: [PATCH 01/11] Add --targets and --modules option to statistics dump

---
 lldb/include/lldb/Target/Statistics.h   |  2 ++
 lldb/source/Commands/CommandObjectStats.cpp |  6 ++
 lldb/source/Commands/Options.td | 16 +---
 lldb/source/Target/Statistics.cpp   | 21 ++---
 4 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index c04d529290fff..b24520b72a95d 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -133,6 +133,8 @@ struct ConstStringStats {
 struct StatisticsOptions {
   bool summary_only = false;
   bool load_all_debug_info = false;
+  bool include_targets = false;
+  bool include_modules = false;
   bool include_transcript = false;
 };
 
diff --git a/lldb/source/Commands/CommandObjectStats.cpp 
b/lldb/source/Commands/CommandObjectStats.cpp
index 1935b0fdfadfb..1347b1ba25b1d 100644
--- a/lldb/source/Commands/CommandObjectStats.cpp
+++ b/lldb/source/Commands/CommandObjectStats.cpp
@@ -81,6 +81,12 @@ class CommandObjectStatsDump : public CommandObjectParsed {
   case 'f':
 m_stats_options.load_all_debug_info = true;
 break;
+  case 'r':
+m_stats_options.include_targets = true;
+break;
+  case 'm':
+m_stats_options.include_modules = true;
+break;
   case 't':
 m_stats_options.include_transcript = true;
 break;
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index cee5a81d3796b..45f46334d5c73 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1416,16 +1416,26 @@ let Command = "trace schema" in {
 }
 
 let Command = "statistics dump" in {
-  def statistics_dump_all: Option<"all-targets", "a">, Group<1>,
+  def statistics_dump_all: Option<"all-targets", "a">, GroupRange<1, 2>,
 Desc<"Include statistics for all targets.">;
   def statistics_dump_summary: Option<"summary", "s">, Group<1>,
 Desc<"Dump only high-level summary statistics. "
  "Exclude targets, modules, breakpoints etc... details.">;
-  def statistics_dump_force: Option<"load-all-debug-info", "f">, Group<1>,
+  def statistics_dump_force: Option<"load-all-debug-info", "f">, GroupRange<1, 
2>,
 Desc<"Dump the total possible debug info statistics. "
 "Force loading all the debug information if not yet loaded, and collect "
 "statistics with those.">;
-  def statistics_dump_transcript: Option<"transcript", "t">, Group<1>,
+  def statistics_dump_targets: Option<"targets", "r">, Group<2>,
+Desc<"Dump statistics for the targets, including breakpoints, expression "
+"evaluations, frame variables, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_modules: Option<"modules", "m">, Group<2>,
+Desc<"Dump statistics for the modules, including time and size of various "
+"aspects of the module and debug information, type system, path, etc. "
+"If both the '--targets' and the '--modules' options are specified, a "
+"list of module identifiers will be added to the 'targets' section.">;
+  def statistics_dump_transcript: Option<"transcript", "t">, Group<2>,
 Desc<"If the setting interpreter.save-transcript is enabled and this "
 "option is specified, include a JSON array with all commands the user and/"
 "or scripts executed during a debug session.">;
diff --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 2a5300012511a..13c430d73990e 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -226,6 +226,8 @@ llvm::json::Value DebuggerStats::ReportStatistics(
 
   const bool summary_only = options.summary_only;
   const bool load_all_debug_info = options.load_all_debug_info;
+  const bool include_targets = options.include_targets;
+  const bool include_modules = options.include_modules;
   const bool include_transcript = options.include_transcript;
 
   json::Array json_targets;
@@ -347,13 +349,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(
   {"totalSymbolTableStripped", num_stripped_modules},
   };
 
-  if (target) {
-json_targets.emplace_back(target->ReportStatistics(options));
-  } else {
-for (const auto &target : debugger.GetTargetList().Targets())
+  if (!summary_only || include_targets) {
+if (target) {
   json_targets.emplace_back(target->ReportStatistics(options));
+} else {
+  for (const auto &target : debugger.GetTargetList().Targets())
+json_targets.emplace_back(target->ReportStatistics(options));

[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -50,48 +60,75 @@ class MinidumpFileBuilder {
 
   ~MinidumpFileBuilder() = default;
 
+  lldb_private::Status AddHeaderAndCalculateDirectories();
   // Add SystemInfo stream, used for storing the most basic information
   // about the system, platform etc...
-  lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple);
+  lldb_private::Status AddSystemInfo();
   // Add ModuleList stream, containing information about all loaded modules
   // at the time of saving minidump.
-  lldb_private::Status AddModuleList(lldb_private::Target &target);
+  lldb_private::Status AddModuleList();
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+  lldb_private::Status AddThreadList();
   // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
+  void AddExceptions();
   // Add MiscInfo stream, mainly providing ProcessId
-  void AddMiscInfo(const lldb::ProcessSP &process_sp);
+  void AddMiscInfo();
   // Add informative files about a Linux process
-  void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
-  // Dump the prepared data into file. In case of the failure data are
-  // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  void AddLinuxFileStreams();
+
+  lldb_private::Status AddMemory(lldb::SaveCoreStyle core_style);
+
+  // Run cleanup and write all remaining bytes to file
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb_private::Process::CoreFileMemoryRanges &ranges);

jeffreytan81 wrote:

I would simply call `AddMemoryList64`, `AddMemoryList32` and `Is64Bit`.
Let's be consistent about the member function naming convention. 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -50,48 +60,75 @@ class MinidumpFileBuilder {
 
   ~MinidumpFileBuilder() = default;
 
+  lldb_private::Status AddHeaderAndCalculateDirectories();
   // Add SystemInfo stream, used for storing the most basic information
   // about the system, platform etc...
-  lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple);
+  lldb_private::Status AddSystemInfo();
   // Add ModuleList stream, containing information about all loaded modules
   // at the time of saving minidump.
-  lldb_private::Status AddModuleList(lldb_private::Target &target);
+  lldb_private::Status AddModuleList();
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+  lldb_private::Status AddThreadList();
   // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
+  void AddExceptions();
   // Add MiscInfo stream, mainly providing ProcessId
-  void AddMiscInfo(const lldb::ProcessSP &process_sp);
+  void AddMiscInfo();
   // Add informative files about a Linux process
-  void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
-  // Dump the prepared data into file. In case of the failure data are
-  // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  void AddLinuxFileStreams();
+
+  lldb_private::Status AddMemory(lldb::SaveCoreStyle core_style);
+
+  // Run cleanup and write all remaining bytes to file
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status
+  AddMemoryList_32(const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status FixThreads();
+  lldb_private::Status FlushToDisk();
+
+  lldb_private::Status DumpHeader() const;
+  lldb_private::Status DumpDirectories() const;
+  bool CheckIf_64Bit(const size_t size);
   // Add directory of StreamType pointing to the current end of the prepared
   // file with the specified size.
-  void AddDirectory(llvm::minidump::StreamType type, size_t stream_size);
-  size_t GetCurrentDataEndOffset() const;
-
-  // Stores directories to later put them at the end of minidump file
+  void AddDirectory(llvm::minidump::StreamType type, uint64_t stream_size);
+  lldb::offset_t GetCurrentDataEndOffset() const;
+  // Stores directories to fill in later
   std::vector m_directories;
+  // When we write off the threads for the first time, we need to clean them up
+  // and give them the correct RVA once we write the stack memory list.
+  std::map m_thread_by_range_start;
   // Main data buffer consisting of data without the minidump header and
   // directories
   lldb_private::DataBufferHeap m_data;
+  lldb::ProcessSP m_process_sp;
+
+  uint m_expected_directories = 0;
+  uint64_t m_saved_data_size = 0;
+  lldb::offset_t m_thread_list_start = 0;
+  // We set the max write amount to 128 mb, this is arbitrary
+  // but we want to try to keep the size of m_data small
+  // and we will only exceed a 128 mb buffer if we get a memory region
+  // that is larger than 128 mb.
+  static constexpr size_t m_write_chunk_max = (1024 * 1024 * 128);
+
+  static constexpr size_t header_size = sizeof(llvm::minidump::Header);
+  static constexpr size_t directory_size = sizeof(llvm::minidump::Directory);

jeffreytan81 wrote:

The naming convention is not consistent. For constexpr, either 
`MAX_WRITE_CHUNK` or `MaxChunkSize` for readability. 
Similar for `HEADER_SIZE` and `DIRECTORY_SIZE`. 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -59,39 +68,67 @@ class MinidumpFileBuilder {
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
-  // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
   // Add MiscInfo stream, mainly providing ProcessId
   void AddMiscInfo(const lldb::ProcessSP &process_sp);
   // Add informative files about a Linux process
   void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
+  // Add Exception streams for any threads that stopped with exceptions.
+  void AddExceptions(const lldb::ProcessSP &process_sp);
   // Dump the prepared data into file. In case of the failure data are
   // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+
+  lldb_private::Status AddMemory(const lldb::ProcessSP &process_sp,
+ lldb::SaveCoreStyle core_style);
+
+  lldb_private::Status DumpToFile();

jeffreytan81 wrote:

As you are describing it, you can see this method is doing two things. I do not 
see the benefit of grouping them into one confusing named function. Let's split 
it into two functions:
1. FixupHeaderDirectory()
2. FlushToFile()


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -480,42 +557,32 @@ class ArchThreadContexts {
   }
 };
 
-// Function returns start and size of the memory region that contains
-// memory location pointed to by the current stack pointer.
-llvm::Expected>
-findStackHelper(const lldb::ProcessSP &process_sp, uint64_t rsp) {
-  MemoryRegionInfo range_info;
-  Status error = process_sp->GetMemoryRegionInfo(rsp, range_info);
-  // Skip failed memory region requests or any regions with no permissions.
-  if (error.Fail() || range_info.GetLLDBPermissions() == 0)
-return llvm::createStringError(
-std::errc::not_supported,
-"unable to load stack segment of the process");
-
-  // This is a duplicate of the logic in
-  // Process::SaveOffRegionsWithStackPointers but ultimately, we need to only
-  // save up from the start of the stack down to the stack pointer
-  const addr_t range_end = range_info.GetRange().GetRangeEnd();
-  const addr_t red_zone = process_sp->GetABI()->GetRedZoneSize();
-  const addr_t stack_head = rsp - red_zone;
-  if (stack_head > range_info.GetRange().GetRangeEnd()) {
-range_info.GetRange().SetRangeBase(stack_head);
-range_info.GetRange().SetByteSize(range_end - stack_head);
-  }
-
-  const addr_t addr = range_info.GetRange().GetRangeBase();
-  const addr_t size = range_info.GetRange().GetByteSize();
-
-  if (size == 0)
-return llvm::createStringError(std::errc::not_supported,
-   "stack segment of the process is empty");
-
-  return std::make_pair(addr, size);
+Status MinidumpFileBuilder::FixThreads() {
+  Status error;
+  // If we have anything in the heap flush it.
+  FlushToDisk();
+  m_core_file->SeekFromStart(m_thread_list_start);
+  for (auto &pair : m_thread_by_range_start) {
+// The thread objects will get a new memory descriptor added
+// When we are emitting the memory list and then we write it here
+llvm::minidump::Thread thread = pair.second;

jeffreytan81 wrote:

I do not think you need to copy:
```
const llvm::minidump::Thread& thread
```

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -797,20 +794,89 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   }
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemory(SaveCoreStyle core_style) {
+  Status error;
+
+  Process::CoreFileMemoryRanges ranges_32;
+  Process::CoreFileMemoryRanges ranges_64;
+  error = m_process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_32);
+  if (error.Fail())
+return error;
 
+  std::set stack_start_addresses;

jeffreytan81 wrote:

If you do not need ordering of the elements in the set, use 
`std::unordered_set`.

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -50,48 +60,75 @@ class MinidumpFileBuilder {
 
   ~MinidumpFileBuilder() = default;
 
+  lldb_private::Status AddHeaderAndCalculateDirectories();
   // Add SystemInfo stream, used for storing the most basic information
   // about the system, platform etc...
-  lldb_private::Status AddSystemInfo(const llvm::Triple &target_triple);
+  lldb_private::Status AddSystemInfo();
   // Add ModuleList stream, containing information about all loaded modules
   // at the time of saving minidump.
-  lldb_private::Status AddModuleList(lldb_private::Target &target);
+  lldb_private::Status AddModuleList();
   // Add ThreadList stream, containing information about all threads running
   // at the moment of core saving. Contains information about thread
   // contexts.
-  lldb_private::Status AddThreadList(const lldb::ProcessSP &process_sp);
+  lldb_private::Status AddThreadList();
   // Add Exception streams for any threads that stopped with exceptions.
-  void AddExceptions(const lldb::ProcessSP &process_sp);
-  // Add MemoryList stream, containing dumps of important memory segments
-  lldb_private::Status AddMemoryList(const lldb::ProcessSP &process_sp,
- lldb::SaveCoreStyle core_style);
+  void AddExceptions();
   // Add MiscInfo stream, mainly providing ProcessId
-  void AddMiscInfo(const lldb::ProcessSP &process_sp);
+  void AddMiscInfo();
   // Add informative files about a Linux process
-  void AddLinuxFileStreams(const lldb::ProcessSP &process_sp);
-  // Dump the prepared data into file. In case of the failure data are
-  // intact.
-  lldb_private::Status Dump(lldb::FileUP &core_file) const;
-  // Returns the current number of directories(streams) that have been so far
-  // created. This number of directories will be dumped when calling Dump()
-  size_t GetDirectoriesNum() const;
+  void AddLinuxFileStreams();
+
+  lldb_private::Status AddMemory(lldb::SaveCoreStyle core_style);
+
+  // Run cleanup and write all remaining bytes to file
+  lldb_private::Status DumpToFile();
 
 private:
+  // Add data to the end of the buffer, if the buffer exceeds the flush level,
+  // trigger a flush.
+  lldb_private::Status AddData(const void *data, size_t size);
+  // Add MemoryList stream, containing dumps of important memory segments
+  lldb_private::Status
+  AddMemoryList_64(const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status
+  AddMemoryList_32(const lldb_private::Process::CoreFileMemoryRanges &ranges);
+  lldb_private::Status FixThreads();

jeffreytan81 wrote:

1. You should add comment explaining what is "FixThreads()" doing and why we 
need it. 
2. `FixThreads` is a very generic name, but you are really fixing up the stack 
field only. So rename to "FixupThreadStack()" to be more specific.


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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -65,56 +66,52 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   if (!process_sp)
 return false;
 
-  MinidumpFileBuilder builder;
-
-  Target &target = process_sp->GetTarget();
-
-  Log *log = GetLog(LLDBLog::Object);
-  error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
-  if (error.Fail()) {
-LLDB_LOG(log, "AddSystemInfo failed: %s", error.AsCString());
+  llvm::Expected maybe_core_file = FileSystem::Instance().Open(

jeffreytan81 wrote:

Let's add a block of comment explaining the high level of the serialization 
logic. Most importantly:
1. Physical layout (header first, directories next, memory list has to be the 
last and why)
2. Later fixup needs to be done to header/directories after everything to the 
important fields
3. Later fixup needs to be done to thread.stack field after dumping memory list 
so that we can avoid duplication

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -65,56 +66,52 @@ bool ObjectFileMinidump::SaveCore(const lldb::ProcessSP 
&process_sp,
   if (!process_sp)
 return false;
 
-  MinidumpFileBuilder builder;
-
-  Target &target = process_sp->GetTarget();
-
-  Log *log = GetLog(LLDBLog::Object);
-  error = builder.AddSystemInfo(target.GetArchitecture().GetTriple());
-  if (error.Fail()) {
-LLDB_LOG(log, "AddSystemInfo failed: %s", error.AsCString());
+  llvm::Expected maybe_core_file = FileSystem::Instance().Open(
+  outfile, File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate);
+  if (!maybe_core_file) {
+error = maybe_core_file.takeError();
 return false;
   }
+  MinidumpFileBuilder builder(std::move(maybe_core_file.get()), process_sp);
 
-  error = builder.AddModuleList(target);
+  Target &target = process_sp->GetTarget();
+  builder.AddHeaderAndCalculateDirectories();
+  Log *log = GetLog(LLDBLog::Object);
+  error = builder.AddSystemInfo();
   if (error.Fail()) {
-LLDB_LOG(log, "AddModuleList failed: %s", error.AsCString());
+LLDB_LOGF(log, "AddSystemInfo failed: %s", error.AsCString());
 return false;
   }
 
-  builder.AddMiscInfo(process_sp);
+  builder.AddModuleList();

jeffreytan81 wrote:

Let's handle the failure from `AddModuleList()`. I am pretty sure I have seen a 
failure once. 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits


@@ -50,48 +60,75 @@ class MinidumpFileBuilder {
 
   ~MinidumpFileBuilder() = default;
 
+  lldb_private::Status AddHeaderAndCalculateDirectories();

jeffreytan81 wrote:

I would add comment to clarify that this is partially done and which fields 
require later fixup. 

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


[Lldb-commits] [lldb] [llvm] [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (PR #95312)

2024-06-13 Thread via lldb-commits

jeffreytan81 wrote:

Can this be landed safely? Do we need to update consumer side to support memory 
list 64? For example, if this diff is landed, and a user tries to save a 
minidump with memory list 64, if there is no consumer side support, will lldb 
crash?

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


[Lldb-commits] [lldb] f2d215f - [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types out of GetCompleteQualType (#95402)

2024-06-13 Thread via lldb-commits

Author: Michael Buch
Date: 2024-06-14T07:20:50+01:00
New Revision: f2d215f572affc9ad73da07763ce1831de7f2d4d

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

LOG: [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types 
out of GetCompleteQualType (#95402)

This patch factors out the completion logic for individual clang::Type's
into their own helper functions.

During the process I cleaned up a few assumptions (e.g., unnecessary
if-guards that could be asserts because these conditions are guaranteed
by the `clang::Type::TypeClass` switch in `GetCompleteQualType`).

This is mainly motivated by the type-completion rework proposed in
https://github.com/llvm/llvm-project/pull/95100.

Added: 


Modified: 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 369ae46cf264a..dbe6238d4fe5a 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -2574,6 +2574,128 @@ TypeSystemClang::GetDeclContextForType(clang::QualType 
type) {
   return nullptr;
 }
 
+/// Returns the clang::RecordType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static const clang::RecordType *GetCompleteRecordType(clang::ASTContext *ast,
+  clang::QualType 
qual_type,
+  bool allow_completion) {
+  assert(qual_type->isRecordType());
+
+  const auto *tag_type = llvm::cast(qual_type.getTypePtr());
+
+  clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl();
+
+  // RecordType with no way of completing it, return the plain
+  // TagType.
+  if (!cxx_record_decl || !cxx_record_decl->hasExternalLexicalStorage())
+return tag_type;
+
+  const bool is_complete = cxx_record_decl->isCompleteDefinition();
+  const bool fields_loaded =
+  cxx_record_decl->hasLoadedFieldsFromExternalStorage();
+
+  // Already completed this type, nothing to be done.
+  if (is_complete && fields_loaded)
+return tag_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // Call the field_begin() accessor to for it to use the external source
+  // to load the fields...
+  //
+  // TODO: if we need to complete the type but have no external source,
+  // shouldn't we error out instead?
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (external_ast_source) {
+external_ast_source->CompleteType(cxx_record_decl);
+if (cxx_record_decl->isCompleteDefinition()) {
+  cxx_record_decl->field_begin();
+  cxx_record_decl->setHasLoadedFieldsFromExternalStorage(true);
+}
+  }
+
+  return tag_type;
+}
+
+/// Returns the clang::EnumType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static const clang::EnumType *GetCompleteEnumType(clang::ASTContext *ast,
+  clang::QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isEnumeralType());
+  assert(ast);
+
+  const clang::EnumType *enum_type =
+  llvm::cast(qual_type.getTypePtr());
+
+  auto *tag_decl = enum_type->getAsTagDecl();
+  assert(tag_decl);
+
+  // Already completed, nothing to be done.
+  if (tag_decl->getDefinition())
+return enum_type;
+
+  if (!allow_completion)
+return nullptr;
+
+  // No definition but can't complete it, error out.
+  if (!tag_decl->hasExternalLexicalStorage())
+return nullptr;
+
+  // We can't complete the type without an external source.
+  clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+  if (!external_ast_source)
+return nullptr;
+
+  external_ast_source->CompleteType(tag_decl);
+  return enum_type;
+}
+
+/// Returns the clang::ObjCObjectType of the specified \ref qual_type. This
+/// function will try to complete the type if necessary (and allowed
+/// by the specified \ref allow_completion). If we fail to return a *complete*
+/// type, returns nullptr.
+static const clang::ObjCObjectType *
+GetCompleteObjCObjectType(clang::ASTContext *ast, QualType qual_type,
+  bool allow_completion) {
+  assert(qual_type->isObjCObjectType());
+  assert(ast);
+
+  const clang::ObjCObjectType *objc_class_type =
+  llvm::cast(qual_type);
+
+  

[Lldb-commits] [lldb] [lldb][TypeSystemClang][NFCI] Factor completion logic for individual types out of GetCompleteQualType (PR #95402)

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

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


[Lldb-commits] [lldb] [lldb][test] Add test for completing ObjCObjectType (PR #95405)

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

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

>From 2e84cf46b9378307d9059aa1ce2a97046b0866b4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:00:07 +0100
Subject: [PATCH 1/4] [lldb][test] Add test for completing ObjCObjectType

This is a minimal reproducer for a crash reported internally
where we would try to call `DumpTypeDescription` on an incomplete
type. This crash surfaced as part of an NFC refactor of some
of the logic in `GetCompleteQualType`:
```
(lldb) expr -l objc -- *(id)0x1234
Stack dump:
0.  Program arguments: ./bin/lldb a.out -o "b main" -o run -o "expr -l objc 
-- *(id)0x1234"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
0  lldb 0x000102ec768c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  lldb 0x000102ec6010 llvm::sys::RunSignalHandlers() + 
112
2  lldb 0x000102ec7fa8 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00018c7a8c44 _sigtramp + 56
4  LLDB 0x000116b2030c 
lldb_private::TypeSystemClang::DumpTypeDescription(void*, 
lldb_private::Stream&, lldb::DescriptionLevel, 
lldb_private::ExecutionContextScope*) + 588
5  LLDB 0x0001166b5124 
lldb_private::CompilerType::DumpTypeDescription(lldb_private::Stream*, 
lldb::DescriptionLevel, lldb_private::ExecutionContextScope*) const + 228
6  LLDB 0x000116d4f08c 
IRForTarget::CreateResultVariable(llvm::Function&) + 2076
```

rdar://129633122
---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 10 ++
 1 file changed, 10 insertions(+)
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
new file mode 100644
index 0..011bd943b5967
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -0,0 +1,10 @@
+// RUN: %clangxx_host %s -g -o %t
+//
+// RUN: %lldb -f %t \
+// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
+// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
+
+int main() { return 0; }
+
+// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

>From 6081327e68d1df1594f17bda97e0f12506681772 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 14:07:19 +0100
Subject: [PATCH 2/4] fixup! clang-format

---
 lldb/test/Shell/Expr/TestObjCIDCast.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
index 011bd943b5967..919f35ce6060e 100644
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
@@ -6,5 +6,5 @@
 
 int main() { return 0; }
 
-// CHECK: (lldb) expression --language objc -- *(id)0x1234 
+// CHECK: (lldb) expression --language objc -- *(id)0x1234
 // CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory

>From 2e3f16035167472fa82502cc8c05e68fee325d95 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 13 Jun 2024 22:18:50 +0100
Subject: [PATCH 3/4] fixup! skip on linux and windows, change pointer value,
 move source into separate file

---
 lldb/test/Shell/Expr/Inputs/objc-cast.cpp |  1 +
 lldb/test/Shell/Expr/TestObjCIDCast.cpp   | 10 --
 lldb/test/Shell/Expr/TestObjCIDCast.test  |  9 +
 3 files changed, 10 insertions(+), 10 deletions(-)
 create mode 100644 lldb/test/Shell/Expr/Inputs/objc-cast.cpp
 delete mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.cpp
 create mode 100644 lldb/test/Shell/Expr/TestObjCIDCast.test

diff --git a/lldb/test/Shell/Expr/Inputs/objc-cast.cpp 
b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
new file mode 100644
index 0..76e8197013aab
--- /dev/null
+++ b/lldb/test/Shell/Expr/Inputs/objc-cast.cpp
@@ -0,0 +1 @@
+int main() { return 0; }
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.cpp 
b/lldb/test/Shell/Expr/TestObjCIDCast.cpp
deleted file mode 100644
index 919f35ce6060e..0
--- a/lldb/test/Shell/Expr/TestObjCIDCast.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clangxx_host %s -g -o %t
-//
-// RUN: %lldb -f %t \
-// RUN:  -o "settings set interpreter.stop-command-source-on-error false" \
-// RUN:  -o "b main" -o run -o "expression --language objc -- *(id)0x1234" -o 
exit 2>&1 | FileCheck %s
-
-int main() { return 0; }
-
-// CHECK: (lldb) expression --language objc -- *(id)0x1234
-// CHECK: error: Couldn't apply expression side effects : Couldn't 
dematerialize a result variable: couldn't read its memory
diff --git a/lldb/test/Shell/Expr/TestObjCIDCast.test 
b/lldb/test/Shell/Expr/TestObjCIDCast.test

  1   2   >