[Lldb-commits] [lldb] d3fb05b - [lldb][AArch64][Linux] Add SME2 release notes and usage docs (#70935)

2023-11-08 Thread via lldb-commits

Author: David Spickett
Date: 2023-11-08T09:23:02Z
New Revision: d3fb05ba10ca4b46b5bb1b9d90bfcbb019fea1ca

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

LOG: [lldb][AArch64][Linux] Add SME2 release notes and usage docs (#70935)

ZT0 is much like ZA apart from not being scalable, so there's not much
new to cover.

Added: 


Modified: 
lldb/docs/use/aarch64-linux.rst
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/lldb/docs/use/aarch64-linux.rst b/lldb/docs/use/aarch64-linux.rst
index fcd0d1b805bf7df..c790d9d369a4805 100644
--- a/lldb/docs/use/aarch64-linux.rst
+++ b/lldb/docs/use/aarch64-linux.rst
@@ -194,9 +194,48 @@ instrucion could interpret its contents as many kinds and 
sizes of data.
 So LLDB will default to showing  ``za`` as one large vector of individual 
bytes.
 You can override this with a format option (see the SVE example above).
 
-Expression evaluation
+Expression Evaluation
 .
 
 The mode (streaming or non-streaming), streaming vector length and ZA state 
will
 be restored after expression evaluation. On top of all the things saved for SVE
 in general.
+
+Scalable Matrix Extension (SME2)
+
+
+The Scalable Matrix Extension 2 is documented in the same architecture
+specification as SME, and covered by the same kernel documentation page as SME.
+
+SME2 adds 1 new register, ``zt0``. This register is a fixed size 512 bit
+register that is used by new instructions added in SME2. It is shown in LLDB in
+the existing SME register set.
+
+``zt0`` can be active or inactive, as ``za`` can. The same ``SVCR.ZA`` bit
+controls this. An inactive ``zt0`` is shown as 0s, like ``za`` is. Though in
+``zt0``'s case, LLDB does not need to fake the value. Ptrace already returns a
+block of 0s for an inactive ``zt0``.
+
+Like ``za``, writing to an inactive ``zt0`` will enable it and ``za``. This can
+be done from within LLDB. If the write is instead to ``za``, ``zt0`` becomes
+active but with a value of all 0s.
+
+Since ``svcr`` is read only, there is no way at this time to deactivate the
+registers from within LLDB (though of course a running process can still do
+this).
+
+To check whether ``zt0`` is active, refer to ``SVCR.ZA`` and not to the value 
of
+``zt0``.
+
+ZT0 Register Presentation
+.
+
+As for ``za``, the meaning of ``zt0`` depends on the instructions used with it,
+so LLDB does not attempt to guess this and defaults to showing it as a vector 
of
+bytes.
+
+Expression Evaluation
+.
+
+``zt0``'s value and whether it is active or not will be saved prior to
+expression evaluation and restored afterwards.
\ No newline at end of file

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 2544aebaf2a22ef..f221025c06d7907 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -236,9 +236,9 @@ Changes to LLDB
   instructions have been updated to reflect this. The underlying functionality
   remains unchanged.
 * The ``mte_ctrl`` register can now be read from AArch64 Linux core files.
-
-* LLDB now supports debugging the Scalable Matrix Extension (SME) on AArch64
-  Linux for both running processes and core files. For details refer to the
+* LLDB on AArch64 Linux now supports debugging the Scalable Matrix Extension
+  (SME) and Scalable Matrix Extension 2 (SME2) for both live processes and core
+  files. For details refer to the
   `AArch64 Linux documentation 
`_.
 
 Changes to Sanitizers



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


[Lldb-commits] [llvm] [lldb] [lldb][AArch64][Linux] Add SME2 release notes and usage docs (PR #70935)

2023-11-08 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)

2023-11-08 Thread David Spickett via lldb-commits


@@ -62,7 +62,10 @@ struct RegisterInfo {
   /// rax ax, ah, and al.
   uint32_t *invalidate_regs;
   /// If not nullptr, a type defined by XML descriptions.
-  const RegisterFlags *flags_type;
+  /// This is mutable so that it may be updated after the register info tables
+  /// have been constructed. For example a specific target OS may have a
+  /// different layout.
+  mutable const RegisterFlags *flags_type;

DavidSpickett wrote:

My intent is that the `RegisterFlags` pointed to is const, but that you can 
change which `RegisterFlags` is pointed to. Or in other words, you can change 
the information but only if you change all the fields at once.

Whether what I have written does that, I will double check, and expand the 
comment to clarify.

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


[Lldb-commits] [lldb] [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsString (PR #71613)

2023-11-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

LGTM, happy to see more bool + parameter -> optional conversions.

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


[Lldb-commits] [lldb] [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsString (PR #71613)

2023-11-08 Thread David Spickett via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)

2023-11-08 Thread David Spickett via lldb-commits


@@ -62,7 +62,10 @@ struct RegisterInfo {
   /// rax ax, ah, and al.
   uint32_t *invalidate_regs;
   /// If not nullptr, a type defined by XML descriptions.
-  const RegisterFlags *flags_type;
+  /// This is mutable so that it may be updated after the register info tables
+  /// have been constructed. For example a specific target OS may have a
+  /// different layout.
+  mutable const RegisterFlags *flags_type;

DavidSpickett wrote:

Actually it's not that, it's that `RegsterInfo's are const elsewhere in lldb. 
So mutable allows us to update `flags_type` even in that scenario.

Which is a code smell but I don't want to unpick all the const-ness elsewhere. 
Just trust that we will not mutate this while someone else is trying to use it.

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)

2023-11-08 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)

2023-11-08 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett updated 
https://github.com/llvm/llvm-project/pull/70300

>From 45a9d131ce6c9fb31355519cd810ceff32c05ee7 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 11 Oct 2023 14:54:07 +0100
Subject: [PATCH 1/9] [lldb][AArch64][Linux] Add field information for the CPSR
 register

The contents of which are mostly SPSR_EL1 as shown in the Arm manual,
with a few adjustments for things Linux says userspace shouldn't concern
itself with.

```
(lldb) register read cpsr
cpsr = 0x80001000
 = (N = 1, Z = 0, C = 0, V = 0, SS = 0, IL = 0, ...
```

Some fields are always present, some depend on extensions. I've checked
for those extensions using HWCAP and HWCAP2.

To provide this for core files and live processes I've added a new class
LinuxArm64RegisterFlags. This is a container for all the registers we'll want
to have fields and handles detecting fields and updating register info.

This is used by the native process as follows:
* There is a global LinuxArm64RegisterFlags object.
* The first thread takes a mutex on it, and updates the fields.
* Subsequent threads see that detection is already done, and skip it.
* All threads then update their own copy of the register information
  with pointers to the field information contained in the global object.

This means that even though every thread will have the same fields,
we only detect them once and have one copy of the information.

Core files instead have a LinuxArm64RegisterFlags as a member, because
each core file could have different saved capabilities. The logic from
there is the same but we get HWACP values from the corefile note.

This handler class is Linux specific right now, but it can easily be made
more generic if needed. For example by using LLVM's FeatureBitset
instead of HWCAPs.

Updating register info is done with string comparison, which isn't ideal.
For CPSR, we do know the register number ahead of time but we do not for
other registers in dynamic register sets. So in the interest of
consistency, I'm going to use string comparison for all registers including 
cpsr.

I've added tests with a core file and live process. Only checking for
fields that are always present to account for CPU variance.
---
 lldb/include/lldb/Target/RegisterFlags.h  |   5 +
 lldb/include/lldb/lldb-private-types.h|   5 +-
 .../NativeRegisterContextLinux_arm64.cpp  |  18 
 .../Plugins/Process/Utility/CMakeLists.txt|   1 +
 .../Utility/RegisterFlagsLinux_arm64.cpp  | 100 ++
 .../Utility/RegisterFlagsLinux_arm64.h|  75 +
 .../RegisterContextPOSIXCore_arm64.cpp|  17 +++
 .../elf-core/RegisterContextPOSIXCore_arm64.h |   3 +
 lldb/source/Target/RegisterFlags.cpp  |  14 ++-
 .../register_command/TestRegisters.py |  12 +++
 .../postmortem/elf-core/TestLinuxCore.py  |   4 +
 11 files changed, 249 insertions(+), 5 deletions(-)
 create mode 100644 
lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
 create mode 100644 
lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h

diff --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 7c5b97c2265fda3..1d8c8e943813e77 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -83,6 +83,11 @@ class RegisterFlags {
   RegisterFlags(std::string id, unsigned size,
 const std::vector &fields);
 
+  /// Replace all the fields with the new set of fields. All the assumptions
+  /// and checks apply as when you use the constructor. Intended to only be 
used
+  /// when runtime field detection is needed.
+  void SetFields(const std::vector &fields);
+
   // Reverse the order of the fields, keeping their values the same.
   // For example a field from bit 31 to 30 with value 0b10 will become bits
   // 1 to 0, with the same 0b10 value.
diff --git a/lldb/include/lldb/lldb-private-types.h 
b/lldb/include/lldb/lldb-private-types.h
index e6717836331f590..f2ced61b7cc315b 100644
--- a/lldb/include/lldb/lldb-private-types.h
+++ b/lldb/include/lldb/lldb-private-types.h
@@ -62,7 +62,10 @@ struct RegisterInfo {
   /// rax ax, ah, and al.
   uint32_t *invalidate_regs;
   /// If not nullptr, a type defined by XML descriptions.
-  const RegisterFlags *flags_type;
+  /// This is mutable so that it may be updated after the register info tables
+  /// have been constructed. For example a specific target OS may have a
+  /// different layout.
+  mutable const RegisterFlags *flags_type;
 
   llvm::ArrayRef data(const uint8_t *context_base) const {
 return llvm::ArrayRef(context_base + byte_offset, byte_size);
diff --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index b5210c368144206..b55d60f3d9bbd13 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/lldb/source/Plu

[Lldb-commits] [lldb] e28157e - [lldb][AArch64][Linux] Add field information for the CPSR register (#70300)

2023-11-08 Thread via lldb-commits

Author: David Spickett
Date: 2023-11-08T10:17:38Z
New Revision: e28157e778423fd9d39c9065ef06e841fc320f09

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

LOG: [lldb][AArch64][Linux] Add field information for the CPSR register (#70300)

The contents of which are mostly SPSR_EL1 as shown in the Arm manual,
with a few adjustments for things Linux says userspace shouldn't concern
itself with.

```
(lldb) register read cpsr
cpsr = 0x80001000
 = (N = 1, Z = 0, C = 0, V = 0, SS = 0, IL = 0, ...
```

Some fields are always present, some depend on extensions. I've checked
for those extensions using HWCAP and HWCAP2.

To provide this for core files and live processes I've added a new class
LinuxArm64RegisterFlags. This is a container for all the registers we'll
want to have fields and handles detecting fields and updating register
info.

This is used by the native process as follows:
* There is a global LinuxArm64RegisterFlags object.
* The first thread takes a mutex on it, and updates the fields.
* Subsequent threads see that detection is already done, and skip it.
* All threads then update their own copy of the register information
with pointers to the field information contained in the global object.

This means that even though every thread will have the same fields, we
only detect them once and have one copy of the information.

Core files instead have a LinuxArm64RegisterFlags as a member, because
each core file could have different saved capabilities. The logic from
there is the same but we get HWACP values from the corefile note.

This handler class is Linux specific right now, but it can easily be
made more generic if needed. For example by using LLVM's FeatureBitset
instead of HWCAPs.

Updating register info is done with string comparison, which isn't
ideal. For CPSR, we do know the register number ahead of time but we do
not for other registers in dynamic register sets. So in the interest of
consistency, I'm going to use string comparison for all registers
including cpsr.

I've added tests with a core file and live process. Only checking for
fields that are always present to account for CPU variance.

Added: 
lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h

Modified: 
lldb/include/lldb/Target/RegisterFlags.h
lldb/include/lldb/lldb-private-types.h
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
lldb/source/Plugins/Process/Utility/CMakeLists.txt
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
lldb/source/Target/RegisterFlags.cpp
lldb/test/API/commands/register/register/register_command/TestRegisters.py
lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py

Removed: 




diff  --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index a088981918cb349..9b343e445678ab3 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -84,6 +84,11 @@ class RegisterFlags {
   RegisterFlags(std::string id, unsigned size,
 const std::vector &fields);
 
+  /// Replace all the fields with the new set of fields. All the assumptions
+  /// and checks apply as when you use the constructor. Intended to only be 
used
+  /// when runtime field detection is needed.
+  void SetFields(const std::vector &fields);
+
   // Reverse the order of the fields, keeping their values the same.
   // For example a field from bit 31 to 30 with value 0b10 will become bits
   // 1 to 0, with the same 0b10 value.

diff  --git a/lldb/include/lldb/lldb-private-types.h 
b/lldb/include/lldb/lldb-private-types.h
index e6717836331f590..7d301666df1a174 100644
--- a/lldb/include/lldb/lldb-private-types.h
+++ b/lldb/include/lldb/lldb-private-types.h
@@ -62,7 +62,11 @@ struct RegisterInfo {
   /// rax ax, ah, and al.
   uint32_t *invalidate_regs;
   /// If not nullptr, a type defined by XML descriptions.
-  const RegisterFlags *flags_type;
+  /// Register info tables are constructed as const, but this field may need to
+  /// be updated if a specific target OS has a 
diff erent layout. To enable that,
+  /// this is mutable. The data pointed to is still const, so you must swap a
+  /// whole set of flags for another.
+  mutable const RegisterFlags *flags_type;
 
   llvm::ArrayRef data(const uint8_t *context_base) const {
 return llvm::ArrayRef(context_base + byte_offset, byte_size);

diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index e23165933c221cf..9b5f7aef

[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the CPSR register (PR #70300)

2023-11-08 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the fpsr register (PR #71651)

2023-11-08 Thread David Spickett via lldb-commits

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

This one is easy because none of the fields depend on extensions. Only thing to 
note is that I've ignored some AArch32 only fields.

```
(lldb) register read fpsr
fpsr = 0x
 = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
```

>From 2a4f47985d8575842034446c4f18fd7c092dd7b7 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 8 Nov 2023 10:32:31 +
Subject: [PATCH] [lldb][AArch64][Linux] Add field information for the fpsr
 register

This one is easy because none of the fields depend on extensions.
Only thing to note is that I've ignored some AArch32 only fields.

```
(lldb) register read fpsr
fpsr = 0x
 = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
```
---
 .../Utility/RegisterFlagsLinux_arm64.cpp  | 20 +++
 .../Utility/RegisterFlagsLinux_arm64.h|  4 +++-
 .../register_command/TestRegisters.py |  5 +++--
 .../postmortem/elf-core/TestLinuxCore.py  |  1 +
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
index 043789bd6d21e47..f2f8b3b3211663d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
@@ -20,6 +20,26 @@
 
 using namespace lldb_private;
 
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2) {
+  // fpsr's contents are constant.
+  (void)hwcap;
+  (void)hwcap2;
+
+  return {
+  // Bits 31-28 are N/Z/C/V, only used by AArch32.
+  {"QC", 27},
+  // Bits 26-8 reserved.
+  {"IDC", 7},
+  // Bits 6-5 reserved.
+  {"IXC", 4},
+  {"UFC", 3},
+  {"OFC", 2},
+  {"DZC", 1},
+  {"IOC", 0},
+  };
+}
+
 LinuxArm64RegisterFlags::Fields
 LinuxArm64RegisterFlags::DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2) {
   // The fields here are a combination of the Arm manual's SPSR_EL1,
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
index 6c7a3b61a1425ee..1058ac2c70bdc5d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
@@ -56,6 +56,7 @@ class LinuxArm64RegisterFlags {
   using DetectorFn = std::function;
 
   static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
+  static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
 
   struct RegisterEntry {
 RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -65,8 +66,9 @@ class LinuxArm64RegisterFlags {
 llvm::StringRef m_name;
 RegisterFlags m_flags;
 DetectorFn m_detector;
-  } m_registers[1] = {
+  } m_registers[2] = {
   RegisterEntry("cpsr", 4, DetectCPSRFields),
+  RegisterEntry("fpsr", 4, DetectFPSRFields),
   };
 
   // Becomes true once field detection has been run for all registers.
diff --git 
a/lldb/test/API/commands/register/register/register_command/TestRegisters.py 
b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index f29b2ab5d8f259d..2bd1d6f08f08478 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -622,13 +622,14 @@ def test_info_register(self):
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["aarch64"]))
 def test_register_read_fields(self):
-"""Test that when debugging a live process, we see the fields of the
-CPSR register."""
+"""Test that when debugging a live process, we see the fields of 
certain
+registers."""
 self.build()
 self.common_setup()
 
 # N/Z/C/V bits will always be present, so check only for those.
 self.expect("register read cpsr", substrs=["= (N = 0, Z = 1, C = 1, V 
= 0"])
+self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 
0"])
 
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["x86_64"]))
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index a083fab18eabcbc..1a913c2c0843cbc 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -577,6 +577,7 @@ def test_aarch64_sve_regs_full(self):
 # Register field information should work with core files as it does a 
live process.
 # The N/Z/C/V bits are always present so just check for those.
 self.expect("register read cpsr", substrs=["= (N = 0, Z = 0, C = 0, V 
= 0"])
+self.expect("register rea

[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the fpsr register (PR #71651)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

This one is easy because none of the fields depend on extensions. Only thing to 
note is that I've ignored some AArch32 only fields.

```
(lldb) register read fpsr
fpsr = 0x
 = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
```

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


4 Files Affected:

- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
(+20) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
(+3-1) 
- (modified) 
lldb/test/API/commands/register/register/register_command/TestRegisters.py 
(+3-2) 
- (modified) lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
(+1) 


``diff
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
index 043789bd6d21e47..f2f8b3b3211663d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
@@ -20,6 +20,26 @@
 
 using namespace lldb_private;
 
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2) {
+  // fpsr's contents are constant.
+  (void)hwcap;
+  (void)hwcap2;
+
+  return {
+  // Bits 31-28 are N/Z/C/V, only used by AArch32.
+  {"QC", 27},
+  // Bits 26-8 reserved.
+  {"IDC", 7},
+  // Bits 6-5 reserved.
+  {"IXC", 4},
+  {"UFC", 3},
+  {"OFC", 2},
+  {"DZC", 1},
+  {"IOC", 0},
+  };
+}
+
 LinuxArm64RegisterFlags::Fields
 LinuxArm64RegisterFlags::DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2) {
   // The fields here are a combination of the Arm manual's SPSR_EL1,
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
index 6c7a3b61a1425ee..1058ac2c70bdc5d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
@@ -56,6 +56,7 @@ class LinuxArm64RegisterFlags {
   using DetectorFn = std::function;
 
   static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
+  static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
 
   struct RegisterEntry {
 RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -65,8 +66,9 @@ class LinuxArm64RegisterFlags {
 llvm::StringRef m_name;
 RegisterFlags m_flags;
 DetectorFn m_detector;
-  } m_registers[1] = {
+  } m_registers[2] = {
   RegisterEntry("cpsr", 4, DetectCPSRFields),
+  RegisterEntry("fpsr", 4, DetectFPSRFields),
   };
 
   // Becomes true once field detection has been run for all registers.
diff --git 
a/lldb/test/API/commands/register/register/register_command/TestRegisters.py 
b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index f29b2ab5d8f259d..2bd1d6f08f08478 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -622,13 +622,14 @@ def test_info_register(self):
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["aarch64"]))
 def test_register_read_fields(self):
-"""Test that when debugging a live process, we see the fields of the
-CPSR register."""
+"""Test that when debugging a live process, we see the fields of 
certain
+registers."""
 self.build()
 self.common_setup()
 
 # N/Z/C/V bits will always be present, so check only for those.
 self.expect("register read cpsr", substrs=["= (N = 0, Z = 1, C = 1, V 
= 0"])
+self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 
0"])
 
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["x86_64"]))
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index a083fab18eabcbc..1a913c2c0843cbc 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -577,6 +577,7 @@ def test_aarch64_sve_regs_full(self):
 # Register field information should work with core files as it does a 
live process.
 # The N/Z/C/V bits are always present so just check for those.
 self.expect("register read cpsr", substrs=["= (N = 0, Z = 0, C = 0, V 
= 0"])
+self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 
0"])
 
 @skipIfLLVMTargetMissing("AArch64")
 def test_aarch64_pac_regs(self):

``




https://github.com/llvm/llvm-project/pull/71651
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://list

[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the fpsr register (PR #71651)

2023-11-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

It may be worth adding a fast path for "constant" information, but I would like 
to look into that after the initial set of 5 registers is in.

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


[Lldb-commits] [clang-tools-extra] [clang] [llvm] [lldb] [flang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-08 Thread Markos Horro via lldb-commits

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


[Lldb-commits] [llvm] [flang] [clang] [libc] [libunwind] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] Test pr (PR #71086)

2023-11-08 Thread Zahira Ammarguellat via lldb-commits

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


[Lldb-commits] [flang] [libc] [llvm] [clang-tools-extra] [clang] [lldb] [libcxx] [compiler-rt] [InstCombine] Fold converted urem to 0 if there's no overlapping bits (PR #71528)

2023-11-08 Thread Graham Hunter via lldb-commits

https://github.com/huntergr-arm updated 
https://github.com/llvm/llvm-project/pull/71528

>From 754519ad9b37343c827504e7d6bfcfa590f69483 Mon Sep 17 00:00:00 2001
From: Graham Hunter 
Date: Fri, 3 Nov 2023 14:22:57 +
Subject: [PATCH] [InstCombine] Fold converted urem to 0 if there's no
 overlapping bits

When folding urem instructions we can end up not recognizing that
the output will always be 0 due to Value*s being different, despite
generating the same data (in this case, 2 different calls to vscale).

This patch recognizes the (x << N) & (add (x << M), -1) pattern that
instcombine replaces urem with after the two vscale calls have been
reduced to one via CSE, then replaces with 0 when x is a non-zero
power of 2 and N >= M.
---
 .../InstCombine/InstCombineAndOrXor.cpp   | 10 
 .../InstCombine/po2-shift-add-and-to-zero.ll  | 52 +++
 2 files changed, 62 insertions(+)
 create mode 100644 
llvm/test/Transforms/InstCombine/po2-shift-add-and-to-zero.ll

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 46af9bf5eed003a..da38f8039dbc3ca 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2662,6 +2662,16 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator 
&I) {
   if (sinkNotIntoOtherHandOfLogicalOp(I))
 return &I;
 
+  // (x << N) & (add (x << M), -1) --> 0, where x is known to be a non-zero
+  // power of 2 and M <= N.
+  const APInt *Shift1, *Shift2;
+  if (match(&I, m_c_And(m_OneUse(m_Shl(m_Value(X), m_APInt(Shift1))),
+m_OneUse(m_Add(m_Shl(m_Value(Y), m_APInt(Shift2)),
+   m_AllOnes() &&
+  X == Y && isKnownToBeAPowerOfTwo(X, /*OrZero*/ false, 0, &I) &&
+  Shift1->uge(*Shift2))
+return replaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+
   // An and recurrence w/loop invariant step is equivelent to (and start, step)
   PHINode *PN = nullptr;
   Value *Start = nullptr, *Step = nullptr;
diff --git a/llvm/test/Transforms/InstCombine/po2-shift-add-and-to-zero.ll 
b/llvm/test/Transforms/InstCombine/po2-shift-add-and-to-zero.ll
new file mode 100644
index 000..4979e7a01972299
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/po2-shift-add-and-to-zero.ll
@@ -0,0 +1,52 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt -mtriple unknown -passes=instcombine -S < %s | FileCheck %s
+
+;; The and X, (add Y, -1) pattern is from an earlier instcombine pass which
+;; converted
+
+;; define dso_local i64 @f1() local_unnamed_addr #0 {
+;; entry:
+;;   %0 = call i64 @llvm.aarch64.sve.cntb(i32 31)
+;;   %1 = call i64 @llvm.aarch64.sve.cnth(i32 31)
+;;   %rem = urem i64 %0, %1
+;;   ret i64 %rem
+;; }
+
+;; into
+
+;; define dso_local i64 @f1() local_unnamed_addr #0 {
+;; entry:
+;;   %0 = call i64 @llvm.vscale.i64()
+;;   %1 = shl nuw nsw i64 %0, 4
+;;   %2 = call i64 @llvm.vscale.i64()
+;;   %3 = shl nuw nsw i64 %2, 3
+;;   %4 = add nsw i64 %3, -1
+;;   %rem = and i64 %1, %4
+;;   ret i64 %rem
+;; }
+
+;; InstCombine would have folded the original to returning 0 if the vscale
+;; calls were the same Value*, but since there's two of them it doesn't
+;; work and we convert the urem to add/and. CSE then gets rid of the extra
+;; vscale, leaving us with a new pattern to match. This only works because
+;; vscale is known to be a nonzero power of 2 (assuming there's a defined
+;; range for it).
+
+define dso_local i64 @f1() local_unnamed_addr #0 {
+; CHECK-LABEL: define dso_local i64 @f1
+; CHECK-SAME: () local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:ret i64 0
+;
+entry:
+  %0 = call i64 @llvm.vscale.i64()
+  %1 = shl nuw nsw i64 %0, 4
+  %2 = shl nuw nsw i64 %0, 3
+  %3 = add nsw i64 %2, -1
+  %rem = and i64 %1, %3
+  ret i64 %rem
+}
+
+declare i64 @llvm.vscale.i64()
+
+attributes #0 = { vscale_range(1,16) }

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


[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)

2023-11-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

New test is failing on Windows on Arm: 
https://lab.llvm.org/buildbot/#/builders/219/builds/6799/steps/6/logs/stdio

The build in general was red when this initially went in, so no notification 
went out.

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


[Lldb-commits] [lldb] ea82853 - [lldb][test] Skip ScriptedProcess missing methods test on Windows

2023-11-08 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-11-08T15:23:03Z
New Revision: ea82853499cc8780cfc86a6913d851f05d527188

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

LOG: [lldb][test] Skip ScriptedProcess missing methods test on Windows

No dylib on Windows, so the test fails to build.

Added: 


Modified: 
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py 
b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index 8c6b9c74bde4703..837ceea22ad1647 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -60,6 +60,8 @@ def move_blueprint_to_dsym(self, blueprint_name):
 )
 shutil.copy(blueprint_origin_path, blueprint_destination_path)
 
+# No dylib on Windows.
+@skipIfWindows
 def test_missing_methods_scripted_register_context(self):
 """Test that we only instanciate scripted processes if they implement
 all the required abstract methods."""



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


[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)

2023-11-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Skipped: 
https://github.com/llvm/llvm-project/commit/ea82853499cc8780cfc86a6913d851f05d527188

I'm not 100% on what the difference between an so and a dylib is but it works 
on Linux as well, so I assume that a Windows test would need to build a dll to 
do the same thing.

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add fields for FPCR register (PR #71694)

2023-11-08 Thread David Spickett via lldb-commits

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

Follows the format laid out in the Arm manual, AArch32 only fields are ignored.

```
(lldb) register read fpcr
fpcr = 0x
 = (AHP = 0, DN = 0, FZ = 0, RMMode = 0, FZ16 = 0, IDE = 0, IXE = 0, 
UFE = 0, OFE = 0, DZE = 0, IOE = 0)
```

Tests use the first 4 fields that we know are always present.

Converted all the HCWAP defines to `UL` because I'm bound to
forget one if I don't do it now.

>From 2a4f47985d8575842034446c4f18fd7c092dd7b7 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 8 Nov 2023 10:32:31 +
Subject: [PATCH 1/2] [lldb][AArch64][Linux] Add field information for the fpsr
 register

This one is easy because none of the fields depend on extensions.
Only thing to note is that I've ignored some AArch32 only fields.

```
(lldb) register read fpsr
fpsr = 0x
 = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
```
---
 .../Utility/RegisterFlagsLinux_arm64.cpp  | 20 +++
 .../Utility/RegisterFlagsLinux_arm64.h|  4 +++-
 .../register_command/TestRegisters.py |  5 +++--
 .../postmortem/elf-core/TestLinuxCore.py  |  1 +
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
index 043789bd6d21e47..f2f8b3b3211663d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
@@ -20,6 +20,26 @@
 
 using namespace lldb_private;
 
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2) {
+  // fpsr's contents are constant.
+  (void)hwcap;
+  (void)hwcap2;
+
+  return {
+  // Bits 31-28 are N/Z/C/V, only used by AArch32.
+  {"QC", 27},
+  // Bits 26-8 reserved.
+  {"IDC", 7},
+  // Bits 6-5 reserved.
+  {"IXC", 4},
+  {"UFC", 3},
+  {"OFC", 2},
+  {"DZC", 1},
+  {"IOC", 0},
+  };
+}
+
 LinuxArm64RegisterFlags::Fields
 LinuxArm64RegisterFlags::DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2) {
   // The fields here are a combination of the Arm manual's SPSR_EL1,
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
index 6c7a3b61a1425ee..1058ac2c70bdc5d 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
@@ -56,6 +56,7 @@ class LinuxArm64RegisterFlags {
   using DetectorFn = std::function;
 
   static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
+  static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
 
   struct RegisterEntry {
 RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -65,8 +66,9 @@ class LinuxArm64RegisterFlags {
 llvm::StringRef m_name;
 RegisterFlags m_flags;
 DetectorFn m_detector;
-  } m_registers[1] = {
+  } m_registers[2] = {
   RegisterEntry("cpsr", 4, DetectCPSRFields),
+  RegisterEntry("fpsr", 4, DetectFPSRFields),
   };
 
   // Becomes true once field detection has been run for all registers.
diff --git 
a/lldb/test/API/commands/register/register/register_command/TestRegisters.py 
b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index f29b2ab5d8f259d..2bd1d6f08f08478 100644
--- a/lldb/test/API/commands/register/register/register_command/TestRegisters.py
+++ b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
@@ -622,13 +622,14 @@ def test_info_register(self):
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["aarch64"]))
 def test_register_read_fields(self):
-"""Test that when debugging a live process, we see the fields of the
-CPSR register."""
+"""Test that when debugging a live process, we see the fields of 
certain
+registers."""
 self.build()
 self.common_setup()
 
 # N/Z/C/V bits will always be present, so check only for those.
 self.expect("register read cpsr", substrs=["= (N = 0, Z = 1, C = 1, V 
= 0"])
+self.expect("register read fpsr", substrs=["= (QC = 0, IDC = 0, IXC = 
0"])
 
 @skipUnlessPlatform(["linux"])
 @skipIf(archs=no_match(["x86_64"]))
diff --git a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
index a083fab18eabcbc..1a913c2c0843cbc 100644
--- a/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ b/lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -577,6 +577,7 @@ def test_aarch64_sve_regs_full(self):
 # Register field information should work with core files as it does a 
live process.
 # The N/Z/C/V bits are always prese

[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add fields for FPCR register (PR #71694)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)


Changes

Follows the format laid out in the Arm manual, AArch32 only fields are ignored.

```
(lldb) register read fpcr
fpcr = 0x
 = (AHP = 0, DN = 0, FZ = 0, RMMode = 0, FZ16 = 0, IDE = 0, IXE = 0, 
UFE = 0, OFE = 0, DZE = 0, IOE = 0)
```

Tests use the first 4 fields that we know are always present.

Converted all the HCWAP defines to `UL` because I'm bound to
forget one if I don't do it now.

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


4 Files Affected:

- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
(+64-4) 
- (modified) lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
(+5-1) 
- (modified) 
lldb/test/API/commands/register/register/register_command/TestRegisters.py 
(+7-2) 
- (modified) lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
(+5) 


``diff
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
index 043789bd6d21e47..ba1a0d5599e7703 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.cpp
@@ -12,14 +12,74 @@
 // This file is built on all systems because it is used by native processes and
 // core files, so we manually define the needed HWCAP values here.
 
-#define HWCAP_DIT (1 << 24)
-#define HWCAP_SSBS (1 << 28)
+#define HWCAP_FPHP (1UL << 9)
+#define HWCAP_ASIMDHP (1UL << 10)
+#define HWCAP_DIT (1UL << 24)
+#define HWCAP_SSBS (1UL << 28)
 
-#define HWCAP2_BTI (1 << 17)
-#define HWCAP2_MTE (1 << 18)
+#define HWCAP2_BTI (1UL << 17)
+#define HWCAP2_MTE (1UL << 18)
+#define HWCAP2_AFP (1UL << 20)
+#define HWCAP2_EBF16 (1UL << 32)
 
 using namespace lldb_private;
 
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2) {
+  std::vector fpcr_fields{
+  {"AHP", 26}, {"DN", 25}, {"FZ", 24}, {"RMMode", 22, 23},
+  // Bits 21-20 are "Stride" which is unused in AArch64 state.
+  };
+
+  // FEAT_FP16 is indicated by the presence of FPHP (floating point half
+  // precision) and ASIMDHP (Advanced SIMD half precision) features.
+  if ((hwcap & HWCAP_FPHP) && (hwcap & HWCAP_ASIMDHP))
+fpcr_fields.push_back({"FZ16", 19});
+
+  // Bits 18-16 are "Len" which is unused in AArch64 state.
+
+  fpcr_fields.push_back({"IDE", 15});
+
+  // Bit 14 is unused.
+  if (hwcap2 & HWCAP2_EBF16)
+fpcr_fields.push_back({"EBF", 13});
+
+  fpcr_fields.push_back({"IXE", 12});
+  fpcr_fields.push_back({"UFE", 11});
+  fpcr_fields.push_back({"OFE", 10});
+  fpcr_fields.push_back({"DZE", 9});
+  fpcr_fields.push_back({"IOE", 8});
+  // Bits 7-3 reserved.
+
+  if (hwcap2 & HWCAP2_AFP) {
+fpcr_fields.push_back({"NEP", 2});
+fpcr_fields.push_back({"AH", 1});
+fpcr_fields.push_back({"FIZ", 0});
+  }
+
+  return fpcr_fields;
+}
+
+LinuxArm64RegisterFlags::Fields
+LinuxArm64RegisterFlags::DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2) {
+  // fpsr's contents are constant.
+  (void)hwcap;
+  (void)hwcap2;
+
+  return {
+  // Bits 31-28 are N/Z/C/V, only used by AArch32.
+  {"QC", 27},
+  // Bits 26-8 reserved.
+  {"IDC", 7},
+  // Bits 6-5 reserved.
+  {"IXC", 4},
+  {"UFC", 3},
+  {"OFC", 2},
+  {"DZC", 1},
+  {"IOC", 0},
+  };
+}
+
 LinuxArm64RegisterFlags::Fields
 LinuxArm64RegisterFlags::DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2) {
   // The fields here are a combination of the Arm manual's SPSR_EL1,
diff --git a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h 
b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
index 6c7a3b61a1425ee..651a8c86f7c86a9 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
+++ b/lldb/source/Plugins/Process/Utility/RegisterFlagsLinux_arm64.h
@@ -56,6 +56,8 @@ class LinuxArm64RegisterFlags {
   using DetectorFn = std::function;
 
   static Fields DetectCPSRFields(uint64_t hwcap, uint64_t hwcap2);
+  static Fields DetectFPSRFields(uint64_t hwcap, uint64_t hwcap2);
+  static Fields DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2);
 
   struct RegisterEntry {
 RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
@@ -65,8 +67,10 @@ class LinuxArm64RegisterFlags {
 llvm::StringRef m_name;
 RegisterFlags m_flags;
 DetectorFn m_detector;
-  } m_registers[1] = {
+  } m_registers[3] = {
   RegisterEntry("cpsr", 4, DetectCPSRFields),
+  RegisterEntry("fpsr", 4, DetectFPSRFields),
+  RegisterEntry("fpcr", 4, DetectFPCRFields),
   };
 
   // Becomes true once field detection has been run for all registers.
diff --git 
a/lldb/test/API/commands/register/register/register_command/TestRegisters.py 
b/lldb/test/API/commands/register/register/register_command/TestRegisters.py
index f29b2ab5d8f259d..386991c18db7c8c

[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add fields for FPCR register (PR #71694)

2023-11-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

First commit is actually https://github.com/llvm/llvm-project/pull/71651, so 
look at the second one only.

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


[Lldb-commits] [lld] [compiler-rt] [libunwind] [lldb] [libc] [libcxx] [flang] [clang-tools-extra] [llvm] [clang] Test branch (PR #70505)

2023-11-08 Thread Timm Baeder via lldb-commits

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the fpsr register (PR #71651)

2023-11-08 Thread Alex Langford via lldb-commits

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

Looks straightforward to me.

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add fields for FPCR register (PR #71694)

2023-11-08 Thread Alex Langford via lldb-commits

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

This also looks pretty straightforward after you implemented the initial 
support. :)

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


[Lldb-commits] [lldb] [lldb/Interpreter] Make Scripted*Interface base class abstract (PR #71465)

2023-11-08 Thread Leandro Lupori via lldb-commits

luporl wrote:

It seems this broke the lldb-aarch64-windows buildbot:
https://lab.llvm.org/buildbot/#/builders/219/builds/6801

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


[Lldb-commits] [lldb] [lldb/Interpreter] Make Scripted*Interface base class abstract (PR #71465)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> It seems this broke the lldb-aarch64-windows buildbot: 
> https://lab.llvm.org/buildbot/#/builders/219/builds/6801

No, this didn't break that bot, `Expr/TestIRMemoryMapWindows.test` was already 
failing in https://lab.llvm.org/buildbot/#/builders/219/builds/6786

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


[Lldb-commits] [lldb] 767ce07 - Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). (#71559)

2023-11-08 Thread via lldb-commits

Author: Adrian Prantl
Date: 2023-11-08T09:54:41-08:00
New Revision: 767ce07c2d4c312188623441979d620b9708ee99

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

LOG: Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). (#71559)

I received a couple of nullptr-deref crash reports with no line numbers
in this function. The way the function was written it was a bit
diffucult to keep track of when result_sp could be null, so this patch
simplifies the function to make it more obvious when a nullptr can be
contained in the variable.

Added: 


Modified: 
lldb/source/Core/ValueObject.cpp

Removed: 




diff  --git a/lldb/source/Core/ValueObject.cpp 
b/lldb/source/Core/ValueObject.cpp
index bdb1bef633d8fb1..a7f7ee64282d891 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -2594,34 +2594,30 @@ ValueObjectSP 
ValueObject::CreateConstantValue(ConstString name) {
 
 ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable(
 lldb::DynamicValueType dynValue, bool synthValue) {
-  ValueObjectSP result_sp(GetSP());
-
+  ValueObjectSP result_sp;
   switch (dynValue) {
   case lldb::eDynamicCanRunTarget:
   case lldb::eDynamicDontRunTarget: {
-if (!result_sp->IsDynamic()) {
-  if (result_sp->GetDynamicValue(dynValue))
-result_sp = result_sp->GetDynamicValue(dynValue);
-}
+if (!IsDynamic())
+  result_sp = GetDynamicValue(dynValue);
   } break;
   case lldb::eNoDynamicValues: {
-if (result_sp->IsDynamic()) {
-  if (result_sp->GetStaticValue())
-result_sp = result_sp->GetStaticValue();
-}
+if (IsDynamic())
+  result_sp = GetStaticValue();
   } break;
   }
+  if (!result_sp)
+result_sp = GetSP();
+  assert(result_sp);
 
-  if (synthValue) {
-if (!result_sp->IsSynthetic()) {
-  if (result_sp->GetSyntheticValue())
-result_sp = result_sp->GetSyntheticValue();
-}
-  } else {
-if (result_sp->IsSynthetic()) {
-  if (result_sp->GetNonSyntheticValue())
-result_sp = result_sp->GetNonSyntheticValue();
-}
+  bool is_synthetic = result_sp->IsSynthetic();
+  if (synthValue && !is_synthetic) {
+if (auto synth_sp = result_sp->GetSyntheticValue())
+  return synth_sp;
+  }
+  if (!synthValue && is_synthetic) {
+if (auto non_synth_sp = result_sp->GetNonSyntheticValue())
+  return non_synth_sp;
   }
 
   return result_sp;



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


[Lldb-commits] [lldb] Simplify ValueObject::GetQualifiedRepresentationIfAvailable(). (PR #71559)

2023-11-08 Thread Adrian Prantl via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

@DavidSpickett Thanks for fixing the windows bot :) 

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


[Lldb-commits] [lldb] [lldb] Add Checksum class to lldbUtility (PR #71456)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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

>From 5693686d3570784fbcadb9921532faf354e5b74f Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Mon, 6 Nov 2023 14:39:26 -0800
Subject: [PATCH] [lldb] Add Checksum class to lldbUtility

This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose
is to store the MD5 hash added to the DWARF 5 line table.
---
 lldb/include/lldb/Utility/Checksum.h| 36 
 lldb/source/Utility/CMakeLists.txt  |  1 +
 lldb/source/Utility/Checksum.cpp| 44 +++
 lldb/unittests/Utility/CMakeLists.txt   |  1 +
 lldb/unittests/Utility/ChecksumTest.cpp | 57 +
 5 files changed, 139 insertions(+)
 create mode 100644 lldb/include/lldb/Utility/Checksum.h
 create mode 100644 lldb/source/Utility/Checksum.cpp
 create mode 100644 lldb/unittests/Utility/ChecksumTest.cpp

diff --git a/lldb/include/lldb/Utility/Checksum.h 
b/lldb/include/lldb/Utility/Checksum.h
new file mode 100644
index 000..4b788b8eef17182
--- /dev/null
+++ b/lldb/include/lldb/Utility/Checksum.h
@@ -0,0 +1,36 @@
+//===-- Checksum.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_UTILITY_CHECKSUM_H
+#define LLDB_UTILITY_CHECKSUM_H
+
+#include "llvm/Support/MD5.h"
+
+namespace lldb_private {
+class Checksum {
+public:
+  static llvm::MD5::MD5Result g_sentinel;
+
+  Checksum(llvm::MD5::MD5Result md5 = g_sentinel);
+  Checksum(const Checksum &checksum);
+  Checksum &operator=(const Checksum &checksum);
+
+  explicit operator bool() const;
+  bool operator==(const Checksum &checksum) const;
+  bool operator!=(const Checksum &checksum) const;
+
+  std::string digest() const;
+
+private:
+  void SetMD5(llvm::MD5::MD5Result);
+
+  llvm::MD5::MD5Result m_checksum;
+};
+} // namespace lldb_private
+
+#endif // LLDB_UTILITY_CHECKSUM_H
diff --git a/lldb/source/Utility/CMakeLists.txt 
b/lldb/source/Utility/CMakeLists.txt
index 16afab1113a970c..a3b0a405b4133f6 100644
--- a/lldb/source/Utility/CMakeLists.txt
+++ b/lldb/source/Utility/CMakeLists.txt
@@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
   Args.cpp
   Baton.cpp
   Broadcaster.cpp
+  Checksum.cpp
   CompletionRequest.cpp
   Connection.cpp
   ConstString.cpp
diff --git a/lldb/source/Utility/Checksum.cpp b/lldb/source/Utility/Checksum.cpp
new file mode 100644
index 000..a7ad4759f1be809
--- /dev/null
+++ b/lldb/source/Utility/Checksum.cpp
@@ -0,0 +1,44 @@
+//===-- Checksum.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Utility/Checksum.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace lldb_private;
+
+Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); }
+
+Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); }
+
+Checksum &Checksum::operator=(const Checksum &checksum) {
+  SetMD5(checksum.m_checksum);
+  return *this;
+}
+
+void Checksum::SetMD5(llvm::MD5::MD5Result md5) {
+  const constexpr size_t md5_length = 16;
+  std::uninitialized_copy_n(md5.begin(), md5_length, m_checksum.begin());
+}
+
+Checksum::operator bool() const { return !llvm::equal(m_checksum, g_sentinel); 
}
+
+bool Checksum::operator==(const Checksum &checksum) const {
+  return llvm::equal(m_checksum, checksum.m_checksum);
+}
+
+bool Checksum::operator!=(const Checksum &checksum) const {
+  return !(*this == checksum);
+}
+
+std::string Checksum::digest() const {
+  return std::string(m_checksum.digest());
+}
+
+llvm::MD5::MD5Result Checksum::g_sentinel = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
diff --git a/lldb/unittests/Utility/CMakeLists.txt 
b/lldb/unittests/Utility/CMakeLists.txt
index 5c7003a156813dc..097dae860b15911 100644
--- a/lldb/unittests/Utility/CMakeLists.txt
+++ b/lldb/unittests/Utility/CMakeLists.txt
@@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests
   OptionsWithRawTest.cpp
   ArchSpecTest.cpp
   BroadcasterTest.cpp
+  ChecksumTest.cpp
   ConstStringTest.cpp
   CompletionRequestTest.cpp
   DataBufferTest.cpp
diff --git a/lldb/unittests/Utility/ChecksumTest.cpp 
b/lldb/unittests/Utility/ChecksumTest.cpp
new file mode 100644
index 000..7537d30b5ff5b84
--- /dev/null
+++ b/lldb/unittests/Utility/ChecksumTest.cpp
@@ -0,0 +1,57 @@
+//===-- ChecksumTest.cpp

[Lldb-commits] [lldb] [lldb] Add Checksum class to lldbUtility (PR #71456)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -0,0 +1,46 @@
+//===-- Checksum.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Utility/Checksum.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace lldb_private;
+
+Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); }
+
+Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); }
+
+Checksum &Checksum::operator=(const Checksum &checksum) {
+  SetMD5(checksum.m_checksum);
+  return *this;
+}
+
+void Checksum::SetMD5(llvm::MD5::MD5Result md5) {
+  std::uninitialized_copy_n(md5.begin(), 16, m_checksum.begin());

JDevlieghere wrote:

`llvm::MD5::MD5Result` is just a wrapper around a `std::Array` so 
since the contents can't be moved, that wouldn't make a difference. 

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


[Lldb-commits] [lldb] 7ef7a92 - [lldb] Add Checksum class to lldbUtility (#71456)

2023-11-08 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2023-11-08T10:11:58-08:00
New Revision: 7ef7a92ead3dd4c3b5cd10b6cf5775a603654945

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

LOG: [lldb] Add Checksum class to lldbUtility (#71456)

This commit adds an MD5 checksum (`Checksum`) class to LLDB. Its purpose
is to store the MD5 hash added to the DWARF 5 line table.

Added: 
lldb/include/lldb/Utility/Checksum.h
lldb/source/Utility/Checksum.cpp
lldb/unittests/Utility/ChecksumTest.cpp

Modified: 
lldb/source/Utility/CMakeLists.txt
lldb/unittests/Utility/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/Utility/Checksum.h 
b/lldb/include/lldb/Utility/Checksum.h
new file mode 100644
index 000..4b788b8eef17182
--- /dev/null
+++ b/lldb/include/lldb/Utility/Checksum.h
@@ -0,0 +1,36 @@
+//===-- Checksum.h --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_UTILITY_CHECKSUM_H
+#define LLDB_UTILITY_CHECKSUM_H
+
+#include "llvm/Support/MD5.h"
+
+namespace lldb_private {
+class Checksum {
+public:
+  static llvm::MD5::MD5Result g_sentinel;
+
+  Checksum(llvm::MD5::MD5Result md5 = g_sentinel);
+  Checksum(const Checksum &checksum);
+  Checksum &operator=(const Checksum &checksum);
+
+  explicit operator bool() const;
+  bool operator==(const Checksum &checksum) const;
+  bool operator!=(const Checksum &checksum) const;
+
+  std::string digest() const;
+
+private:
+  void SetMD5(llvm::MD5::MD5Result);
+
+  llvm::MD5::MD5Result m_checksum;
+};
+} // namespace lldb_private
+
+#endif // LLDB_UTILITY_CHECKSUM_H

diff  --git a/lldb/source/Utility/CMakeLists.txt 
b/lldb/source/Utility/CMakeLists.txt
index 16afab1113a970c..a3b0a405b4133f6 100644
--- a/lldb/source/Utility/CMakeLists.txt
+++ b/lldb/source/Utility/CMakeLists.txt
@@ -29,6 +29,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
   Args.cpp
   Baton.cpp
   Broadcaster.cpp
+  Checksum.cpp
   CompletionRequest.cpp
   Connection.cpp
   ConstString.cpp

diff  --git a/lldb/source/Utility/Checksum.cpp 
b/lldb/source/Utility/Checksum.cpp
new file mode 100644
index 000..a7ad4759f1be809
--- /dev/null
+++ b/lldb/source/Utility/Checksum.cpp
@@ -0,0 +1,44 @@
+//===-- Checksum.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "lldb/Utility/Checksum.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace lldb_private;
+
+Checksum::Checksum(llvm::MD5::MD5Result md5) { SetMD5(md5); }
+
+Checksum::Checksum(const Checksum &checksum) { SetMD5(checksum.m_checksum); }
+
+Checksum &Checksum::operator=(const Checksum &checksum) {
+  SetMD5(checksum.m_checksum);
+  return *this;
+}
+
+void Checksum::SetMD5(llvm::MD5::MD5Result md5) {
+  const constexpr size_t md5_length = 16;
+  std::uninitialized_copy_n(md5.begin(), md5_length, m_checksum.begin());
+}
+
+Checksum::operator bool() const { return !llvm::equal(m_checksum, g_sentinel); 
}
+
+bool Checksum::operator==(const Checksum &checksum) const {
+  return llvm::equal(m_checksum, checksum.m_checksum);
+}
+
+bool Checksum::operator!=(const Checksum &checksum) const {
+  return !(*this == checksum);
+}
+
+std::string Checksum::digest() const {
+  return std::string(m_checksum.digest());
+}
+
+llvm::MD5::MD5Result Checksum::g_sentinel = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};

diff  --git a/lldb/unittests/Utility/CMakeLists.txt 
b/lldb/unittests/Utility/CMakeLists.txt
index 5c7003a156813dc..097dae860b15911 100644
--- a/lldb/unittests/Utility/CMakeLists.txt
+++ b/lldb/unittests/Utility/CMakeLists.txt
@@ -4,6 +4,7 @@ add_lldb_unittest(UtilityTests
   OptionsWithRawTest.cpp
   ArchSpecTest.cpp
   BroadcasterTest.cpp
+  ChecksumTest.cpp
   ConstStringTest.cpp
   CompletionRequestTest.cpp
   DataBufferTest.cpp

diff  --git a/lldb/unittests/Utility/ChecksumTest.cpp 
b/lldb/unittests/Utility/ChecksumTest.cpp
new file mode 100644
index 000..7537d30b5ff5b84
--- /dev/null
+++ b/lldb/unittests/Utility/ChecksumTest.cpp
@@ -0,0 +1,57 @@
+//===-- ChecksumTest.cpp 
--===//
+//
+// Part of the LLVM Project, under t

[Lldb-commits] [lldb] [lldb] Add Checksum class to lldbUtility (PR #71456)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] [lldb/Interpreter] Make Scripted*Interface base class abstract (PR #71465)

2023-11-08 Thread Leandro Lupori via lldb-commits

luporl wrote:

@medismailben Yes, it did break that bot.
https://lab.llvm.org/buildbot/#/builders/219/builds/6786 is the first build 
that includes your commit and when `Expr/TestIRMemoryMapWindows.test` started 
failing.
https://lab.llvm.org/buildbot/#/builders/219/builds/6785 is a build failure 
that was fixed by 
https://github.com/llvm/llvm-project/commit/3267cd3fa10651b46e9d1ce66940301e784c0533.

To confirm it, I've forced builds of particular revisions. 
https://lab.llvm.org/buildbot/#/builders/219/builds/6800 is right before your 
commit and passes and https://lab.llvm.org/buildbot/#/builders/219/builds/6801 
adds only your commit and fails.

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


[Lldb-commits] [lldb] [lldb/Interpreter] Make Scripted*Interface base class abstract (PR #71465)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

> @medismailben Yes, it did break that bot. 
> https://lab.llvm.org/buildbot/#/builders/219/builds/6786 is the first build 
> that includes your commit and when `Expr/TestIRMemoryMapWindows.test` started 
> failing. https://lab.llvm.org/buildbot/#/builders/219/builds/6785 is a build 
> failure that was fixed by 
> [3267cd3](https://github.com/llvm/llvm-project/commit/3267cd3fa10651b46e9d1ce66940301e784c0533).
> 
> To confirm it, I've forced builds of particular revisions. 
> https://lab.llvm.org/buildbot/#/builders/219/builds/6800 is right before your 
> commit and passes and 
> https://lab.llvm.org/buildbot/#/builders/219/builds/6801 adds only your 
> commit and fails.

Ok, I'll take a look ?

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

https://github.com/jeffreytan81 created 
https://github.com/llvm/llvm-project/pull/71723

Currently VSCode logpoint uses `SBValue::GetValue` to get the value for 
printing. This is not providing an intuitive result for std::string or char * 
-- it shows the pointer value instead of the string content.

This patch improves by prefers `SBValue::GetSummary()` before using 
`SBValue::GetValue()`. 

>From e92d7125be6b6677d0553967bb3f8e821de3ea18 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 7 Nov 2023 16:57:23 -0800
Subject: [PATCH] Improve DAP logpoint value summary

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py| 5 +++--
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp  | 2 ++
 lldb/tools/lldb-dap/BreakpointBase.cpp| 8 +---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..44858c888a96940 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,8 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -75,7 +76,7 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+self.assertEqual(logMessage_line, f"{logMessage_prefix}{result}, 
{message}")
 
 @skipIfWindows
 @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..84560dad92c286e 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char * message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..d5253431053cc25 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();
 } else {
   output += messagePart.text;
 }

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 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 5aa934e2af8727852dec0ec1cfa0cba05d858f70 
e92d7125be6b6677d0553967bb3f8e821de3ea18 -- 
lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
lldb/tools/lldb-dap/BreakpointBase.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 84560dad92c2..a84546a95af1 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,7 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
-  const char * message = "Hello from main!";
+  const char *message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());

``




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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Greg Clayton via lldb-commits


@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();

clayborg wrote:

I think we should do what we do for variables: show the value + summary. If you 
have pointer, but it has a summary, we should still show the poiinter and tthe 
summary

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits


@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();

jeffreytan81 wrote:

Sure, I can do that.

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add fields for FPCR register (PR #71694)

2023-11-08 Thread Jason Molenda via lldb-commits

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

lgtm

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


[Lldb-commits] [lldb] [lldb][AArch64][Linux] Add field information for the fpsr register (PR #71651)

2023-11-08 Thread Jason Molenda via lldb-commits

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

Looks good.

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/71723

>From e92d7125be6b6677d0553967bb3f8e821de3ea18 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 7 Nov 2023 16:57:23 -0800
Subject: [PATCH 1/2] Improve DAP logpoint value summary

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py| 5 +++--
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp  | 2 ++
 lldb/tools/lldb-dap/BreakpointBase.cpp| 8 +---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..44858c888a96940 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,8 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -75,7 +76,7 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+self.assertEqual(logMessage_line, f"{logMessage_prefix}{result}, 
{message}")
 
 @skipIfWindows
 @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..84560dad92c286e 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char * message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..d5253431053cc25 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();
 } else {
   output += messagePart.text;
 }

>From 9664c6f13accbab2616e891ac031701566fd58b4 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Wed, 8 Nov 2023 14:54:45 -0800
Subject: [PATCH 2/2] Use the same format as variables view

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py   | 4 +++-
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp | 2 +-
 lldb/tools/lldb-dap/BreakpointBase.cpp   | 7 ++-
 lldb/tools/lldb-dap/JSONUtils.cpp| 9 +++--
 lldb/tools/lldb-dap/JSONUtils.h  | 3 +++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 44858c888a96940..8614b3e19be6962 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,6 +48,7 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
+message_addr_pattern = r'\b0x[0-9A-Fa-f]+\b'
 message = '"Hello from main!"'
 logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
@@ -76,7 +77,8 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, f"{log

[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (jeffreytan81)


Changes

Currently VSCode logpoint uses `SBValue::GetValue` to get the value for 
printing. This is not providing an intuitive result for std::string or char * 
-- it shows the pointer value instead of the string content.

This patch improves by prefers `SBValue::GetSummary()` before using 
`SBValue::GetValue()`. 

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


5 Files Affected:

- (modified) lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
(+5-2) 
- (modified) lldb/test/API/tools/lldb-dap/breakpoint/main.cpp (+2) 
- (modified) lldb/tools/lldb-dap/BreakpointBase.cpp (+2-3) 
- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+7-2) 
- (modified) lldb/tools/lldb-dap/JSONUtils.h (+3) 


``diff
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..8614b3e19be6962 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,9 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message_addr_pattern = r'\b0x[0-9A-Fa-f]+\b'
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -75,7 +77,8 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+reg_str = f"{logMessage_prefix}{result}, {message_addr_pattern} 
{message}"
+self.assertRegex(logMessage_line, reg_str)
 
 @skipIfWindows
 @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..a84546a95af1533 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char *message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..b0946f0103c2a34 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -8,6 +8,7 @@
 
 #include "BreakpointBase.h"
 #include "DAP.h"
+#include "JSONUtils.h"
 #include "llvm/ADT/StringExtras.h"
 
 using namespace lldb_dap;
@@ -295,9 +296,7 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  output += ValeuToString(value);
 } else {
   output += messagePart.text;
 }
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 46528a2a28d4d6f..84c8037108cdcd4 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -210,8 +210,7 @@ static std::optional 
TryCreateAutoSummary(lldb::SBValue value) {
   return TryCreateAutoSummaryForContainer(value);
 }
 
-void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
-llvm::StringRef key) {
+std::string ValeuToString(lldb::SBValue v) {
   std::string result;
   llvm::raw_string_ostream strm(result);
 
@@ -242,6 +241,12 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object 
&object,
   }
 }
   }
+  return result;
+}
+
+void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
+llvm::StringRef key) {
+  std::string result = ValeuToString(v);
   EmplaceSafeString(object, key, result);
 }
 
diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h
index d829e650b8f31c4..39f2be6a2dde301 100644
--- a/lldb/tools/lldb-dap/JSONUtils.h
+++ b/lldb/tools/lldb-dap/JSONUtils.h
@@ -167,6 +167,9 @@ std::vector GetStrings(const 
llvm::json::Object *obj,
 void FillResponse(const 

[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
5aa934e2af8727852dec0ec1cfa0cba05d858f70..9664c6f13accbab2616e891ac031701566fd58b4
 lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
``





View the diff from darker here.


``diff
--- TestDAP_logpoints.py2023-11-08 22:54:45.00 +
+++ TestDAP_logpoints.py2023-11-08 23:08:31.300707 +
@@ -46,11 +46,11 @@
 
 # Set two breakpoints:
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-message_addr_pattern = r'\b0x[0-9A-Fa-f]+\b'
+message_addr_pattern = r"\b0x[0-9A-Fa-f]+\b"
 message = '"Hello from main!"'
 logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],

``




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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/71723

>From e92d7125be6b6677d0553967bb3f8e821de3ea18 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 7 Nov 2023 16:57:23 -0800
Subject: [PATCH 1/3] Improve DAP logpoint value summary

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py| 5 +++--
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp  | 2 ++
 lldb/tools/lldb-dap/BreakpointBase.cpp| 8 +---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..44858c888a96940 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,8 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -75,7 +76,7 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+self.assertEqual(logMessage_line, f"{logMessage_prefix}{result}, 
{message}")
 
 @skipIfWindows
 @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..84560dad92c286e 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char * message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..d5253431053cc25 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();
 } else {
   output += messagePart.text;
 }

>From 9664c6f13accbab2616e891ac031701566fd58b4 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Wed, 8 Nov 2023 14:54:45 -0800
Subject: [PATCH 2/3] Use the same format as variables view

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py   | 4 +++-
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp | 2 +-
 lldb/tools/lldb-dap/BreakpointBase.cpp   | 7 ++-
 lldb/tools/lldb-dap/JSONUtils.cpp| 9 +++--
 lldb/tools/lldb-dap/JSONUtils.h  | 3 +++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 44858c888a96940..8614b3e19be6962 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,6 +48,7 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
+message_addr_pattern = r'\b0x[0-9A-Fa-f]+\b'
 message = '"Hello from main!"'
 logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
@@ -76,7 +77,8 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, f"{log

[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits


@@ -48,7 +48,9 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message_addr_pattern = r"\b0x[0-9A-Fa-f]+\b"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"

bulbazord wrote:

Does the string literal here need to be an f-string so `message` is properly 
interpolated?

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits


@@ -210,8 +210,7 @@ static std::optional 
TryCreateAutoSummary(lldb::SBValue value) {
   return TryCreateAutoSummaryForContainer(value);
 }
 
-void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
-llvm::StringRef key) {
+std::string ValeuToString(lldb::SBValue v) {

bulbazord wrote:

Same Typo

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits


@@ -295,9 +296,7 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  output += ValeuToString(value);

bulbazord wrote:

Typo here -- `ValueToString`

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits

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

Looks fine, but the method you added has a typo in its name.

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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben created 
https://github.com/llvm/llvm-project/pull/71744

This patch should fix a test failure in `Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the 
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr` when using 
the base `ScriptInterpreter` instance, instead of `ScriptInterpreterPython` for 
instance.

This nullptr is actually well handled in the various places where we create a 
Scripted Interface, however, because of the way to instanciate a process, the 
process plugin manager have to iterate over every process plugin and call the 
`CreateInstance` static function that should instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when trying 
to create a `ScriptedProcessInterface`, we try to discard the process object, 
which calls the Process destructor, which in turns calls the `ScriptedProcess` 
plugin `IsAlive` method. That method will fire an assertion if the scripted 
interface pointer is not allocated.

This patch address that issue by setting a flag when destroying the 
ScriptedProcess object, and checks that flag when calling `IsAlive`.

>From 066032b6840130897e42c9a196b72fecfc9fb44f Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Wed, 8 Nov 2023 15:01:43 -0800
Subject: [PATCH] [lldb] Fix assert in ScriptedProcess destructor

This patch should fix a test failure in `Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr`
when using the base `ScriptInterpreter` instance, instead of
`ScriptInterpreterPython` for instance.

This nullptr is actually well handled in the various places where we
create a Scripted Interface, however, because of the way to instanciate
a process, the process plugin manager have to iterate over every process
plugin and call the `CreateInstance` static function that should
instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when
trying to create a `ScriptedProcessInterface`, we try to discard the
process object, which calls the Process destructor, which in turns
calls the `ScriptedProcess` plugin `IsAlive` method. That method will
fire an assertion if the scripted interface pointer is not allocated.

This patch address that issue by setting a flag when destroying the
ScriptedProcess object, and checks that flag when calling `IsAlive`.

Signed-off-by: Med Ismail Bennani 
---
 lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | 5 -
 lldb/source/Plugins/Process/scripted/ScriptedProcess.h   | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f2a647c1b0bea4c..11c681b957e7af8 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -129,6 +129,7 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
 }
 
 ScriptedProcess::~ScriptedProcess() {
+  m_is_finalizing = true;
   Clear();
   // We need to call finalize on the process before destroying ourselves to
   // make sure all of the broadcaster cleanup goes as planned. If we destruct
@@ -212,7 +213,9 @@ void ScriptedProcess::DidAttach(ArchSpec &process_arch) {
 
 Status ScriptedProcess::DoDestroy() { return Status(); }
 
-bool ScriptedProcess::IsAlive() { return GetInterface().IsAlive(); }
+bool ScriptedProcess::IsAlive() {
+  return !m_is_finalizing && GetInterface().IsAlive();
+}
 
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 0335364b4010b22..c4b4633a14c7abb 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -129,6 +129,7 @@ class ScriptedProcess : public Process {
   // Member variables.
   const ScriptedMetadata m_scripted_metadata;
   lldb::ScriptedProcessInterfaceUP m_interface_up;
+  bool m_is_finalizing = false;
 };
 
 } // namespace lldb_private

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


[Lldb-commits] [lldb] [lldb/Interpreter] Make Scripted*Interface base class abstract (PR #71465)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

@luporl I found the issue. #71744 should fix it.

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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)


Changes

This patch should fix a test failure in `Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the 
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr` when using 
the base `ScriptInterpreter` instance, instead of `ScriptInterpreterPython` for 
instance.

This nullptr is actually well handled in the various places where we create a 
Scripted Interface, however, because of the way to instanciate a process, the 
process plugin manager have to iterate over every process plugin and call the 
`CreateInstance` static function that should instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when trying 
to create a `ScriptedProcessInterface`, we try to discard the process object, 
which calls the Process destructor, which in turns calls the `ScriptedProcess` 
plugin `IsAlive` method. That method will fire an assertion if the scripted 
interface pointer is not allocated.

This patch address that issue by setting a flag when destroying the 
ScriptedProcess object, and checks that flag when calling `IsAlive`.

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


2 Files Affected:

- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp (+4-1) 
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.h (+1) 


``diff
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f2a647c1b0bea4c..11c681b957e7af8 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -129,6 +129,7 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
 }
 
 ScriptedProcess::~ScriptedProcess() {
+  m_is_finalizing = true;
   Clear();
   // We need to call finalize on the process before destroying ourselves to
   // make sure all of the broadcaster cleanup goes as planned. If we destruct
@@ -212,7 +213,9 @@ void ScriptedProcess::DidAttach(ArchSpec &process_arch) {
 
 Status ScriptedProcess::DoDestroy() { return Status(); }
 
-bool ScriptedProcess::IsAlive() { return GetInterface().IsAlive(); }
+bool ScriptedProcess::IsAlive() {
+  return !m_is_finalizing && GetInterface().IsAlive();
+}
 
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 0335364b4010b22..c4b4633a14c7abb 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -129,6 +129,7 @@ class ScriptedProcess : public Process {
   // Member variables.
   const ScriptedMetadata m_scripted_metadata;
   lldb::ScriptedProcessInterfaceUP m_interface_up;
+  bool m_is_finalizing = false;
 };
 
 } // namespace lldb_private

``




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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

https://github.com/jeffreytan81 updated 
https://github.com/llvm/llvm-project/pull/71723

>From e92d7125be6b6677d0553967bb3f8e821de3ea18 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Tue, 7 Nov 2023 16:57:23 -0800
Subject: [PATCH 1/4] Improve DAP logpoint value summary

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py| 5 +++--
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp  | 2 ++
 lldb/tools/lldb-dap/BreakpointBase.cpp| 8 +---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..44858c888a96940 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,8 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -75,7 +76,7 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+self.assertEqual(logMessage_line, f"{logMessage_prefix}{result}, 
{message}")
 
 @skipIfWindows
 @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..84560dad92c286e 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char * message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..d5253431053cc25 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  llvm::StringRef summary_str = value.GetSummary();
+  if (!summary_str.empty())
+output += summary_str.str();
+  else
+output += value.GetValue();
 } else {
   output += messagePart.text;
 }

>From 9664c6f13accbab2616e891ac031701566fd58b4 Mon Sep 17 00:00:00 2001
From: jeffreytan81 
Date: Wed, 8 Nov 2023 14:54:45 -0800
Subject: [PATCH 2/4] Use the same format as variables view

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py   | 4 +++-
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp | 2 +-
 lldb/tools/lldb-dap/BreakpointBase.cpp   | 7 ++-
 lldb/tools/lldb-dap/JSONUtils.cpp| 9 +++--
 lldb/tools/lldb-dap/JSONUtils.h  | 3 +++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 44858c888a96940..8614b3e19be6962 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,6 +48,7 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
+message_addr_pattern = r'\b0x[0-9A-Fa-f]+\b'
 message = '"Hello from main!"'
 logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
@@ -76,7 +77,8 @@ def test_logmessage_basic(self):
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, f"{log

[Lldb-commits] [lldb] [clang] [clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (PR #70639)

2023-11-08 Thread Michael Buch via lldb-commits

Michael137 wrote:

> This causes Clang to assert:
> 
> ```
>   llvm/lib/IR/Metadata.cpp:689:
>   void llvm::MDNode::resolve(): Assertion `isUniqued() && "Expected this 
> to be uniqued"' failed.
> ```
> 
> See https://bugs.chromium.org/p/chromium/issues/detail?id=1500262#c1 for a 
> reproducer.
> 
> I'll revert to green.

Thanks for the repro. Reduced it to:
```
struct Foo; 
template  using Int = int;  
class Bar { 
  template  static const bool Constant = false; 
  Int> Val;   
  Bar();
};  
Bar::Bar() {}   
```
when compiling with `-debug-info-kind=limited`.

The issue was that `EmitGlobalVariable` can cause creation of `DINodes`, which, 
if using limited debug-info, will be temporary. But the emission of the global 
variables is done *after* we've uniqued the temporaries. So the fix is really 
to just do the `EmitGlobalVariable` at the beginning of 
`CGDebugInfo::finalize`. Will submit a new PR with that change and a new 
test-case for this

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread Alex Langford via lldb-commits

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

Thanks!

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits


@@ -48,7 +48,9 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+message_addr_pattern = r"\b0x[0-9A-Fa-f]+\b"
+message = '"Hello from main!"'
+logMessage = logMessage_prefix + "{i + 3}, {message}"

jeffreytan81 wrote:

`{message}` is DAP's log message format not python f-string. Changed the test 
order and variable name to less confusing.

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


[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -420,13 +428,17 @@ class FileSpec {
   ///   The lifetime of the StringRefs is tied to the lifetime of the FileSpec.
   std::vector GetComponents() const;
 
+  /// Return the checksum for this FileSpec or all zeros if there is none.
+  const Checksum &GetChecksum() const { return m_checksum; };
+
 protected:
   // Convenience method for setting the file without changing the style.
   void SetFile(llvm::StringRef path);
 
   /// Called anytime m_directory or m_filename is changed to clear any cached
   /// state in this object.
   void PathWasModified() {
+m_checksum = Checksum();

JDevlieghere wrote:

Given that the FileSpec is a system independent path description (i.e. the file 
doesn't need to exist on the host) there's no way to recompute it 
automatically, although the user can specify a new checksum if the path 
changes.  

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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/71744

>From a26236eec419adc99c188f9fe3d0440f81aff0da Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Wed, 8 Nov 2023 16:24:57 -0800
Subject: [PATCH] [lldb] Fix assert in ScriptedProcess destructor

This patch should fix a test failure in `Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr`
when using the base `ScriptInterpreter` instance, instead of
`ScriptInterpreterPython` for instance.

This nullptr is actually well handled in the various places where we
create a Scripted Interface, however, because of the way to instanciate
a process, the process plugin manager have to iterate over every process
plugin and call the `CreateInstance` static function that should
instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when
trying to create a `ScriptedProcessInterface`, we try to discard the
process object, which calls the Process destructor, which in turns
calls the `ScriptedProcess` plugin `IsAlive` method. That method will
fire an assertion if the scripted interface pointer is not allocated.

This patch address that issue by setting a flag when destroying the
ScriptedProcess object, and checks that flag when calling `IsAlive`.

Signed-off-by: Med Ismail Bennani 
---
 lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | 6 +-
 lldb/source/Plugins/Process/scripted/ScriptedProcess.h   | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f2a647c1b0bea4c..7e48ea0fd2d935d 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -129,6 +129,8 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
 }
 
 ScriptedProcess::~ScriptedProcess() {
+  std::lock_guard g(m_finalizing_mutex);
+  m_is_finalizing = true;
   Clear();
   // We need to call finalize on the process before destroying ourselves to
   // make sure all of the broadcaster cleanup goes as planned. If we destruct
@@ -212,7 +214,9 @@ void ScriptedProcess::DidAttach(ArchSpec &process_arch) {
 
 Status ScriptedProcess::DoDestroy() { return Status(); }
 
-bool ScriptedProcess::IsAlive() { return GetInterface().IsAlive(); }
+bool ScriptedProcess::IsAlive() {
+  return !m_is_finalizing && GetInterface().IsAlive();
+}
 
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 0335364b4010b22..42e1d67740b7483 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -129,6 +129,8 @@ class ScriptedProcess : public Process {
   // Member variables.
   const ScriptedMetadata m_scripted_metadata;
   lldb::ScriptedProcessInterfaceUP m_interface_up;
+  std::mutex m_finalizing_mutex;
+  bool m_is_finalizing = false;
 };
 
 } // namespace lldb_private

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


[Lldb-commits] [lldb] f175b96 - Improve VSCode DAP logpoint value summary (#71723)

2023-11-08 Thread via lldb-commits

Author: jeffreytan81
Date: 2023-11-08T16:48:55-08:00
New Revision: f175b9647ccdfd67300264b2d3bd76e6f9a3fb93

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

LOG: Improve VSCode DAP logpoint value summary (#71723)

Currently VSCode logpoint uses `SBValue::GetValue` to get the value for
printing. This is not providing an intuitive result for std::string or
char * -- it shows the pointer value instead of the string content.

This patch improves by prefers `SBValue::GetSummary()` before using
`SBValue::GetValue()`.

-

Co-authored-by: jeffreytan81 

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
lldb/tools/lldb-dap/BreakpointBase.cpp
lldb/tools/lldb-dap/JSONUtils.cpp
lldb/tools/lldb-dap/JSONUtils.h

Removed: 




diff  --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py 
b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..2367313b095ea26 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,7 @@ def test_logmessage_basic(self):
 # 1. First at the loop line with logMessage
 # 2. Second guard breakpoint at a line after loop
 logMessage_prefix = "This is log message for { -- "
-logMessage = logMessage_prefix + "{i + 3}"
+logMessage = logMessage_prefix + "{i + 3}, {message}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(
 self.main_path,
 [loop_line, after_loop_line],
@@ -72,10 +72,13 @@ def test_logmessage_basic(self):
 loop_count = 10
 self.assertEqual(len(logMessage_output), loop_count)
 
+message_addr_pattern = r"\b0x[0-9A-Fa-f]+\b"
+message_content = '"Hello from main!"'
 # Verify log message match
 for idx, logMessage_line in enumerate(logMessage_output):
 result = idx + 3
-self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+reg_str = f"{logMessage_prefix}{result}, {message_addr_pattern} 
{message_content}"
+self.assertRegex(logMessage_line, reg_str)
 
 @skipIfWindows
 @skipIfRemote

diff  --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp 
b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..a84546a95af1533 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
 exit(1);
   }
 
+  const char *message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
 fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
 throw std::invalid_argument("throwing exception for testing");
   } catch (...) {

diff  --git a/lldb/tools/lldb-dap/BreakpointBase.cpp 
b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..bc9bde97678adbd 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -8,6 +8,7 @@
 
 #include "BreakpointBase.h"
 #include "DAP.h"
+#include "JSONUtils.h"
 #include "llvm/ADT/StringExtras.h"
 
 using namespace lldb_dap;
@@ -295,9 +296,7 @@ bool BreakpointBase::BreakpointHitCallback(
   frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
   if (value.GetError().Fail())
 value = frame.EvaluateExpression(expr);
-  const char *expr_val = value.GetValue();
-  if (expr_val)
-output += expr_val;
+  output += ValueToString(value);
 } else {
   output += messagePart.text;
 }

diff  --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index 46528a2a28d4d6f..2ff17616c2e9986 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -210,8 +210,7 @@ static std::optional 
TryCreateAutoSummary(lldb::SBValue value) {
   return TryCreateAutoSummaryForContainer(value);
 }
 
-void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
-llvm::StringRef key) {
+std::string ValueToString(lldb::SBValue v) {
   std::string result;
   llvm::raw_string_ostream strm(result);
 
@@ -242,6 +241,12 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object 
&object,
   }
 }
   }
+  return result;
+}
+
+void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
+llvm::StringRef key) {
+  std::string result = ValueToSt

[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

2023-11-08 Thread via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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

>From 0a4b349d6299db6b2a0a6709c40d15b1a4a0f62a Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 8 Nov 2023 16:51:53 -0800
Subject: [PATCH] [lldb] Add Checksum to FileSpec

Store a Checksum in FileSpec. Its purpose is to store the MD5 hash that
was added to the DWARF 5 line table.

This increases the size of a FileSpec from 24 to 40 bytes. The
alternative is to introduce a new SupportFile abstraction for a FileSpec
+ Checksum but that would require a corresponding SupportFileList class.
During review we decided that wasn't worth it, but that's something we
can revisit in the future.
---
 lldb/include/lldb/Utility/FileSpec.h| 20 ++--
 lldb/source/Utility/FileSpec.cpp|  9 ++---
 lldb/unittests/Utility/FileSpecTest.cpp | 12 
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/lldb/include/lldb/Utility/FileSpec.h 
b/lldb/include/lldb/Utility/FileSpec.h
index f06a8543a056e87..ccd25a81c11f368 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 
+#include "lldb/Utility/Checksum.h"
 #include "lldb/Utility/ConstString.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -71,8 +72,12 @@ class FileSpec {
   /// \param[in] style
   /// The style of the path
   ///
+  /// \param[in] checksum
+  /// The MD5 checksum of the path.
+  ///
   /// \see FileSpec::SetFile (const char *path)
-  explicit FileSpec(llvm::StringRef path, Style style = Style::native);
+  explicit FileSpec(llvm::StringRef path, Style style = Style::native,
+const Checksum &checksum = {});
 
   explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple);
 
@@ -362,7 +367,11 @@ class FileSpec {
   ///
   /// \param[in] style
   /// The style for the given path.
-  void SetFile(llvm::StringRef path, Style style);
+  ///
+  /// \param[in] checksum
+  /// The checksum for the given path.
+  void SetFile(llvm::StringRef path, Style style,
+   const Checksum &checksum = {});
 
   /// Change the file specified with a new path.
   ///
@@ -420,6 +429,9 @@ class FileSpec {
   ///   The lifetime of the StringRefs is tied to the lifetime of the FileSpec.
   std::vector GetComponents() const;
 
+  /// Return the checksum for this FileSpec or all zeros if there is none.
+  const Checksum &GetChecksum() const { return m_checksum; };
+
 protected:
   // Convenience method for setting the file without changing the style.
   void SetFile(llvm::StringRef path);
@@ -427,6 +439,7 @@ class FileSpec {
   /// Called anytime m_directory or m_filename is changed to clear any cached
   /// state in this object.
   void PathWasModified() {
+m_checksum = Checksum();
 m_is_resolved = false;
 m_absolute = Absolute::Calculate;
   }
@@ -443,6 +456,9 @@ class FileSpec {
   /// The unique'd filename path.
   ConstString m_filename;
 
+  /// The optional MD5 checksum of the file.
+  Checksum m_checksum;
+
   /// True if this path has been resolved.
   mutable bool m_is_resolved = false;
 
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index eb34ef97cea0b2f..4bbfbb7c1fab5e6 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -68,8 +68,9 @@ void Denormalize(llvm::SmallVectorImpl &path, 
FileSpec::Style style) {
 FileSpec::FileSpec() : m_style(GetNativeStyle()) {}
 
 // Default constructor that can take an optional full path to a file on disk.
-FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
-  SetFile(path, style);
+FileSpec::FileSpec(llvm::StringRef path, Style style, const Checksum &checksum)
+: m_checksum(checksum), m_style(style) {
+  SetFile(path, style, checksum);
 }
 
 FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
@@ -171,9 +172,11 @@ void FileSpec::SetFile(llvm::StringRef pathname) { 
SetFile(pathname, m_style); }
 // Update the contents of this object with a new path. The path will be split
 // up into a directory and filename and stored as uniqued string values for
 // quick comparison and efficient memory usage.
-void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
+void FileSpec::SetFile(llvm::StringRef pathname, Style style,
+   const Checksum &checksum) {
   Clear();
   m_style = (style == Style::native) ? GetNativeStyle() : style;
+  m_checksum = checksum;
 
   if (pathname.empty())
 return;
diff --git a/lldb/unittests/Utility/FileSpecTest.cpp 
b/lldb/unittests/Utility/FileSpecTest.cpp
index 2a62f6b1e76120f..565395a495be60e 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -534,3 +534,15 @@ TEST(FileSpecTest, TestGetComponents) {
 EXPECT_EQ(file_spec.GetComponents(), pair.second);
   }
 }
+
+TEST(FileSpecTest, TestChecksum) {
+  Checksum checksum({0, 1, 2, 3, 4, 5, 6, 7, 8,

[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

https://github.com/medismailben updated 
https://github.com/llvm/llvm-project/pull/71744

>From a0617d18d1cbcf0ca21ca01b350a22930414991f Mon Sep 17 00:00:00 2001
From: Med Ismail Bennani 
Date: Wed, 8 Nov 2023 17:01:07 -0800
Subject: [PATCH] [lldb] Fix assert in ScriptedProcess destructor

This patch should fix a test failure in `Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr`
when using the base `ScriptInterpreter` instance, instead of
`ScriptInterpreterPython` for instance.

This nullptr is actually well handled in the various places where we
create a Scripted Interface, however, because of the way to instanciate
a process, the process plugin manager have to iterate over every process
plugin and call the `CreateInstance` static function that should
instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when
trying to create a `ScriptedProcessInterface`, we try to discard the
process object, which calls the Process destructor, which in turns
calls the `ScriptedProcess` plugin `IsAlive` method. That method will
fire an assertion if the scripted interface pointer is not allocated.

This patch address that issue by returning early in the Scripted Process
destructor, and not call `Finalize`, if the interface pointer is not valid.

Signed-off-by: Med Ismail Bennani 
---
 lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f2a647c1b0bea4c..54b367727913ca7 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -130,6 +130,12 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
 
 ScriptedProcess::~ScriptedProcess() {
   Clear();
+  // If the interface is not valid, we can't call Finalize(). When that happens
+  // it means that the Scripted Process instanciation failed and the
+  // CreateProcess function returns a nullptr, so no one besides this class
+  // should have access to that bogus process object.
+  if (!m_interface_up)
+return;
   // We need to call finalize on the process before destroying ourselves to
   // make sure all of the broadcaster cleanup goes as planned. If we destruct
   // this class, then Process::~Process() might have problems trying to fully

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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Alex Langford via lldb-commits

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

🚢 

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


[Lldb-commits] [lldb] 0adbde6 - [lldb] Fix assert in ScriptedProcess destructor (#71744)

2023-11-08 Thread via lldb-commits

Author: Med Ismail Bennani
Date: 2023-11-08T17:18:40-08:00
New Revision: 0adbde65414af263175fcce6f9aaf51bc8849a9f

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

LOG: [lldb] Fix assert in ScriptedProcess destructor (#71744)

This patch should fix a test failure in
`Expr/TestIRMemoryMapWindows.test`:

https://lab.llvm.org/buildbot/#/builders/219/builds/6786

The problem here is that since 7991412 landed, all the
`ScriptInterpreter::CreateScripted*Interface` now return a `nullptr`
when using the base `ScriptInterpreter` instance, instead of
`ScriptInterpreterPython` for instance.

This nullptr is actually well handled in the various places where we
create a Scripted Interface, however, because of the way to instanciate
a process, the process plugin manager have to iterate over every process
plugin and call the `CreateInstance` static function that should
instanciate the right object.

So in the ScriptedProcess case, because we are getting a `nullptr` when
trying to create a `ScriptedProcessInterface`, we try to discard the
process object, which calls the Process destructor, which in turns calls
the `ScriptedProcess` plugin `IsAlive` method. That method will fire an
assertion if the scripted interface pointer is not allocated.

This patch address that issue by setting a flag when destroying the
ScriptedProcess object, and checks that flag when calling `IsAlive`.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f2a647c1b0bea4c..54b367727913ca7 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -130,6 +130,12 @@ ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
 
 ScriptedProcess::~ScriptedProcess() {
   Clear();
+  // If the interface is not valid, we can't call Finalize(). When that happens
+  // it means that the Scripted Process instanciation failed and the
+  // CreateProcess function returns a nullptr, so no one besides this class
+  // should have access to that bogus process object.
+  if (!m_interface_up)
+return;
   // We need to call finalize on the process before destroying ourselves to
   // make sure all of the broadcaster cleanup goes as planned. If we destruct
   // this class, then Process::~Process() might have problems trying to fully



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


[Lldb-commits] [lldb] [lldb] Fix assert in ScriptedProcess destructor (PR #71744)

2023-11-08 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] 919f5ef - [lldb] Add Checksum to FileSpec (#71457)

2023-11-08 Thread via lldb-commits

Author: Jonas Devlieghere
Date: 2023-11-08T20:11:48-08:00
New Revision: 919f5ef4621edcfd9e9793e1363df53eef3e89d5

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

LOG: [lldb] Add Checksum to FileSpec (#71457)

Store a Checksum in FileSpec. Its purpose is to store the MD5 hash that
was added to the DWARF 5 line table.

This increases the size of a FileSpec from 24 to 40 bytes. The
alternative is to introduce a new SupportFile abstraction for a FileSpec
+ Checksum but that would require a corresponding SupportFileList class.
During review we decided that wasn't worth it, but that's something we
can revisit in the future.

Added: 


Modified: 
lldb/include/lldb/Utility/FileSpec.h
lldb/source/Utility/FileSpec.cpp
lldb/unittests/Utility/FileSpecTest.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/FileSpec.h 
b/lldb/include/lldb/Utility/FileSpec.h
index f06a8543a056e87..ccd25a81c11f368 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 
+#include "lldb/Utility/Checksum.h"
 #include "lldb/Utility/ConstString.h"
 
 #include "llvm/ADT/StringRef.h"
@@ -71,8 +72,12 @@ class FileSpec {
   /// \param[in] style
   /// The style of the path
   ///
+  /// \param[in] checksum
+  /// The MD5 checksum of the path.
+  ///
   /// \see FileSpec::SetFile (const char *path)
-  explicit FileSpec(llvm::StringRef path, Style style = Style::native);
+  explicit FileSpec(llvm::StringRef path, Style style = Style::native,
+const Checksum &checksum = {});
 
   explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple);
 
@@ -362,7 +367,11 @@ class FileSpec {
   ///
   /// \param[in] style
   /// The style for the given path.
-  void SetFile(llvm::StringRef path, Style style);
+  ///
+  /// \param[in] checksum
+  /// The checksum for the given path.
+  void SetFile(llvm::StringRef path, Style style,
+   const Checksum &checksum = {});
 
   /// Change the file specified with a new path.
   ///
@@ -420,6 +429,9 @@ class FileSpec {
   ///   The lifetime of the StringRefs is tied to the lifetime of the FileSpec.
   std::vector GetComponents() const;
 
+  /// Return the checksum for this FileSpec or all zeros if there is none.
+  const Checksum &GetChecksum() const { return m_checksum; };
+
 protected:
   // Convenience method for setting the file without changing the style.
   void SetFile(llvm::StringRef path);
@@ -427,6 +439,7 @@ class FileSpec {
   /// Called anytime m_directory or m_filename is changed to clear any cached
   /// state in this object.
   void PathWasModified() {
+m_checksum = Checksum();
 m_is_resolved = false;
 m_absolute = Absolute::Calculate;
   }
@@ -443,6 +456,9 @@ class FileSpec {
   /// The unique'd filename path.
   ConstString m_filename;
 
+  /// The optional MD5 checksum of the file.
+  Checksum m_checksum;
+
   /// True if this path has been resolved.
   mutable bool m_is_resolved = false;
 

diff  --git a/lldb/source/Utility/FileSpec.cpp 
b/lldb/source/Utility/FileSpec.cpp
index eb34ef97cea0b2f..4bbfbb7c1fab5e6 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -68,8 +68,9 @@ void Denormalize(llvm::SmallVectorImpl &path, 
FileSpec::Style style) {
 FileSpec::FileSpec() : m_style(GetNativeStyle()) {}
 
 // Default constructor that can take an optional full path to a file on disk.
-FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) {
-  SetFile(path, style);
+FileSpec::FileSpec(llvm::StringRef path, Style style, const Checksum &checksum)
+: m_checksum(checksum), m_style(style) {
+  SetFile(path, style, checksum);
 }
 
 FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple)
@@ -171,9 +172,11 @@ void FileSpec::SetFile(llvm::StringRef pathname) { 
SetFile(pathname, m_style); }
 // Update the contents of this object with a new path. The path will be split
 // up into a directory and filename and stored as uniqued string values for
 // quick comparison and efficient memory usage.
-void FileSpec::SetFile(llvm::StringRef pathname, Style style) {
+void FileSpec::SetFile(llvm::StringRef pathname, Style style,
+   const Checksum &checksum) {
   Clear();
   m_style = (style == Style::native) ? GetNativeStyle() : style;
+  m_checksum = checksum;
 
   if (pathname.empty())
 return;

diff  --git a/lldb/unittests/Utility/FileSpecTest.cpp 
b/lldb/unittests/Utility/FileSpecTest.cpp
index 2a62f6b1e76120f..565395a495be60e 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -534,3 +534,15 @@ TEST(FileSpecTest, TestGetComponents) {
 EXPECT_EQ(file_spec.GetComponents(), pair.second);
   

[Lldb-commits] [lldb] [lldb] Add Checksum to FileSpec (PR #71457)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread via lldb-commits

https://github.com/GeorgeHuyubo created 
https://github.com/llvm/llvm-project/pull/71769

Add a new API in SBTarget to Load Core from a SBFile.
This will enable a target to load core from a file descriptor.
So that in coredumper, we don't need to write core file to disk, instead we can 
pass the input file descriptor to lldb directly.


Test:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> file_object = open("/home/hyubo/210hda79ms32sr0h", "r")
>>> fd=file_object.fileno()
>>> file = lldb.SBFile(fd,'r', True)
>>> error = lldb.SBError()
>>> target = lldb.debugger.CreateTarget(None)
>>> target.LoadCore(file,error)
SBProcess: pid = 56415, state = stopped, threads = 1
```


>From e7fb5814d7ef7ad28543978567db9f8305630f90 Mon Sep 17 00:00:00 2001
From: George Hu 
Date: Wed, 8 Nov 2023 16:25:34 -0800
Subject: [PATCH] Add new API in SBTarget for loading core from SBFile

---
 lldb/include/lldb/API/SBTarget.h  |  2 +
 lldb/include/lldb/Target/PostMortemProcess.h  | 15 ++
 lldb/include/lldb/Target/Process.h| 37 +--
 lldb/include/lldb/Target/ProcessTrace.h   |  4 +-
 lldb/include/lldb/Target/Target.h |  3 +-
 lldb/include/lldb/lldb-private-interfaces.h   |  3 +-
 lldb/source/API/SBTarget.cpp  | 41 +++-
 lldb/source/Commands/CommandObjectTarget.cpp  | 47 ---
 lldb/source/Core/IOHandlerCursesGUI.cpp   | 13 -
 .../FreeBSDKernel/ProcessFreeBSDKernel.cpp| 27 ++-
 .../FreeBSDKernel/ProcessFreeBSDKernel.h  |  2 +-
 .../Process/MacOSX-Kernel/ProcessKDP.cpp  |  4 +-
 .../Process/MacOSX-Kernel/ProcessKDP.h|  5 +-
 .../Process/elf-core/ProcessElfCore.cpp   | 28 ++-
 .../Plugins/Process/elf-core/ProcessElfCore.h |  8 ++--
 .../Process/gdb-remote/ProcessGDBRemote.cpp   |  5 +-
 .../Process/gdb-remote/ProcessGDBRemote.h |  5 +-
 .../Process/mach-core/ProcessMachCore.cpp | 25 +-
 .../Process/mach-core/ProcessMachCore.h   |  7 ++-
 .../Process/minidump/ProcessMinidump.cpp  | 16 ---
 .../Process/minidump/ProcessMinidump.h|  6 +--
 .../Process/scripted/ScriptedProcess.cpp  |  4 +-
 .../Process/scripted/ScriptedProcess.h|  2 +-
 lldb/source/Target/Process.cpp| 11 ++---
 lldb/source/Target/ProcessTrace.cpp   |  9 ++--
 lldb/source/Target/Target.cpp |  2 +-
 .../postmortem/elf-core/TestLinuxCore.py  | 16 +++
 .../Target/LocateModuleCallbackTest.cpp   |  3 +-
 28 files changed, 232 insertions(+), 118 deletions(-)

diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b4..e49c32d0548501a 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -184,6 +184,8 @@ class LLDB_API SBTarget {
 
   SBProcess LoadCore(const char *core_file);
   SBProcess LoadCore(const char *core_file, lldb::SBError &error);
+  SBProcess LoadCore(SBFile &file);
+  SBProcess LoadCore(SBFile &file, lldb::SBError &error);
 
   /// Launch a new process with sensible defaults.
   ///
diff --git a/lldb/include/lldb/Target/PostMortemProcess.h 
b/lldb/include/lldb/Target/PostMortemProcess.h
index 7207fc99ef29a41..1f563e5f1ff6b88 100644
--- a/lldb/include/lldb/Target/PostMortemProcess.h
+++ b/lldb/include/lldb/Target/PostMortemProcess.h
@@ -10,6 +10,8 @@
 #define LLDB_TARGET_POSTMORTEMPROCESS_H
 
 #include "lldb/Target/Process.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/lldb-forward.h"
 
 namespace lldb_private {
 
@@ -24,7 +26,20 @@ class PostMortemProcess : public Process {
   using Process::Process;
 
 public:
+  PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+lldb::FileSP file_sp)
+  : Process(target_sp, listener_sp), m_core_file(file_sp) {}
+
   bool IsLiveDebugSession() const override { return false; }
+
+  FileSpec GetCoreFile() const override {
+const FileSpec file_spec;
+m_core_file->GetFileSpec(const_cast(file_spec));
+return file_spec;
+  }
+
+protected:
+  lldb::FileSP m_core_file;
 };
 
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a6d3e6c2d16926e..62284b29886a4ac 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -52,6 +52,7 @@
 #include "lldb/Utility/TraceGDBRemotePackets.h"
 #include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UserIDResolver.h"
+#include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
 
 #include "llvm/ADT/ArrayRef.h"
@@ -354,12 +355,10 @@ class Process : public 
std::enable_shared_from_this,
   };
   // This is all the event bits the public process broadcaster broadcasts.
   // The process shadow listener signs up for all these bits...
-  static constexpr int g_all_event_bits = eBroadcastBitStateChanged 
-| eBroadcastBitInter

[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (GeorgeHuyubo)


Changes

Add a new API in SBTarget to Load Core from a SBFile.
This will enable a target to load core from a file descriptor.
So that in coredumper, we don't need to write core file to disk, instead we can 
pass the input file descriptor to lldb directly.


Test:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> file_object = open("/home/hyubo/210hda79ms32sr0h", "r")
>>> fd=file_object.fileno()
>>> file = lldb.SBFile(fd,'r', True)
>>> error = lldb.SBError()
>>> target = lldb.debugger.CreateTarget(None)
>>> target.LoadCore(file,error)
SBProcess: pid = 56415, state = stopped, threads = 1
```


---

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


28 Files Affected:

- (modified) lldb/include/lldb/API/SBTarget.h (+2) 
- (modified) lldb/include/lldb/Target/PostMortemProcess.h (+15) 
- (modified) lldb/include/lldb/Target/Process.h (+22-15) 
- (modified) lldb/include/lldb/Target/ProcessTrace.h (+2-2) 
- (modified) lldb/include/lldb/Target/Target.h (+2-1) 
- (modified) lldb/include/lldb/lldb-private-interfaces.h (+2-1) 
- (modified) lldb/source/API/SBTarget.cpp (+39-2) 
- (modified) lldb/source/Commands/CommandObjectTarget.cpp (+30-17) 
- (modified) lldb/source/Core/IOHandlerCursesGUI.cpp (+11-2) 
- (modified) lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp 
(+16-11) 
- (modified) lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.h 
(+1-1) 
- (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp (+2-2) 
- (modified) lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h (+3-2) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+15-13) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.h (+4-4) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+3-2) 
- (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (+3-2) 
- (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp (+14-11) 
- (modified) lldb/source/Plugins/Process/mach-core/ProcessMachCore.h (+3-4) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp (+9-7) 
- (modified) lldb/source/Plugins/Process/minidump/ProcessMinidump.h (+3-3) 
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp (+2-2) 
- (modified) lldb/source/Plugins/Process/scripted/ScriptedProcess.h (+1-1) 
- (modified) lldb/source/Target/Process.cpp (+5-6) 
- (modified) lldb/source/Target/ProcessTrace.cpp (+5-4) 
- (modified) lldb/source/Target/Target.cpp (+1-1) 
- (modified) lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py 
(+16) 
- (modified) lldb/unittests/Target/LocateModuleCallbackTest.cpp (+1-2) 


``diff
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 83087623088c5b4..e49c32d0548501a 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -184,6 +184,8 @@ class LLDB_API SBTarget {
 
   SBProcess LoadCore(const char *core_file);
   SBProcess LoadCore(const char *core_file, lldb::SBError &error);
+  SBProcess LoadCore(SBFile &file);
+  SBProcess LoadCore(SBFile &file, lldb::SBError &error);
 
   /// Launch a new process with sensible defaults.
   ///
diff --git a/lldb/include/lldb/Target/PostMortemProcess.h 
b/lldb/include/lldb/Target/PostMortemProcess.h
index 7207fc99ef29a41..1f563e5f1ff6b88 100644
--- a/lldb/include/lldb/Target/PostMortemProcess.h
+++ b/lldb/include/lldb/Target/PostMortemProcess.h
@@ -10,6 +10,8 @@
 #define LLDB_TARGET_POSTMORTEMPROCESS_H
 
 #include "lldb/Target/Process.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/lldb-forward.h"
 
 namespace lldb_private {
 
@@ -24,7 +26,20 @@ class PostMortemProcess : public Process {
   using Process::Process;
 
 public:
+  PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+lldb::FileSP file_sp)
+  : Process(target_sp, listener_sp), m_core_file(file_sp) {}
+
   bool IsLiveDebugSession() const override { return false; }
+
+  FileSpec GetCoreFile() const override {
+const FileSpec file_spec;
+m_core_file->GetFileSpec(const_cast(file_spec));
+return file_spec;
+  }
+
+protected:
+  lldb::FileSP m_core_file;
 };
 
 } // namespace lldb_private
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a6d3e6c2d16926e..62284b29886a4ac 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -52,6 +52,7 @@
 #include "lldb/Utility/TraceGDBRemotePackets.h"
 #include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UserIDResolver.h"
+#include "lldb/lldb-forward.h"
 #include "lldb/lldb-private.h"
 
 #include "llvm/ADT/ArrayRef.h"
@@ -354,12 +355,10 @@ class Process : public 
std::enable_shared_from_this,
   };
   // This is all the event bits the p

[Lldb-commits] [lldb] [lldb] Read Checksum from DWARF line tables (PR #71458)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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

>From 5673248f1f19145cbbb0435177b6a5ed425fa1c0 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 24 Oct 2023 16:14:27 -0700
Subject: [PATCH] [lldb] Read Checksum from DWARF line tables

Read the MD5 checksum from DWARF line tables and store it in the
corresponding support files.
---
 lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index aabd83a194932ff..79d44bce3d663b6 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -229,8 +229,15 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
 remapped_file = std::move(*file_path);
 }
 
+Checksum checksum;
+if (prologue.ContentTypes.HasMD5) {
+  const llvm::DWARFDebugLine::FileNameEntry &file_name_entry =
+  prologue.getFileNameEntry(idx);
+  checksum = file_name_entry.Checksum;
+}
+
 // Unconditionally add an entry, so the indices match up.
-support_files.EmplaceBack(remapped_file, style);
+support_files.EmplaceBack(remapped_file, style, checksum);
   }
 
   return support_files;

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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -184,6 +184,8 @@ class LLDB_API SBTarget {
 
   SBProcess LoadCore(const char *core_file);
   SBProcess LoadCore(const char *core_file, lldb::SBError &error);
+  SBProcess LoadCore(SBFile &file);

JDevlieghere wrote:

Did you add this for consistency? I don't think we should be adding an overload 
without error handling.

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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -24,7 +26,20 @@ class PostMortemProcess : public Process {
   using Process::Process;
 
 public:
+  PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+lldb::FileSP file_sp)
+  : Process(target_sp, listener_sp), m_core_file(file_sp) {}
+
   bool IsLiveDebugSession() const override { return false; }
+
+  FileSpec GetCoreFile() const override {
+const FileSpec file_spec;
+m_core_file->GetFileSpec(const_cast(file_spec));
+return file_spec;

JDevlieghere wrote:

I'm not sure I understand what's going on here. You're marking the local 
variable as `const` only to immediately `const_cast` it away in the line below? 
Can't you avoid all this like so:

```
FileSpec file_spec;
m_core_file->GetFileSpec(file_spec);
```

or even better, why doesn't `GetFileSpec` return a `FileSpec` instead of an out 
parameter?
```

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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -354,12 +355,10 @@ class Process : public 
std::enable_shared_from_this,
   };
   // This is all the event bits the public process broadcaster broadcasts.
   // The process shadow listener signs up for all these bits...
-  static constexpr int g_all_event_bits = eBroadcastBitStateChanged 
-| eBroadcastBitInterrupt
-| eBroadcastBitSTDOUT 
-| eBroadcastBitSTDERR
-| eBroadcastBitProfileData 
-| eBroadcastBitStructuredData;
+  static constexpr int g_all_event_bits =
+  eBroadcastBitStateChanged | eBroadcastBitInterrupt | eBroadcastBitSTDOUT 
|
+  eBroadcastBitSTDERR | eBroadcastBitProfileData |
+  eBroadcastBitStructuredData;

JDevlieghere wrote:

Unrelated formatting change? 

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


[Lldb-commits] [lldb] Centralize the code that figures out which memory ranges to save into core files (PR #71772)

2023-11-08 Thread Greg Clayton via lldb-commits

https://github.com/clayborg created 
https://github.com/llvm/llvm-project/pull/71772

Prior to this patch, each core file plugin (ObjectFileMachO.cpp and 
ObjectFileMinindump.cpp) would calculate the address ranges to save in 
different ways. This patch adds a new function to Process.h/.cpp:

```
Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style, 
CoreFileMemoryRanges &ranges);
```

The patch updates the ObjectFileMachO::SaveCore(...) and 
ObjectFileMinindump::SaveCore(...) to use same code. This will allow core files 
to be consistent with the lldb::SaveCoreStyle across different core file 
creators and will allow us to add new core file saving features that do more 
complex things in future patches.

>From 9ff1e92175f90613de6f07dfb4821b8fc0226939 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Wed, 8 Nov 2023 21:14:49 -0800
Subject: [PATCH] Centralize the code that figures out which memory ranges to
 save into core files.

Prior to this patch, each core file plugin (ObjectFileMachO.cpp and 
ObjectFileMinindump.cpp) would calculate the address ranges to save in 
different ways. This patch adds a new function to Process.h/.cpp:

```
Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style, 
CoreFileMemoryRanges &ranges);
```

The patch updates the ObjectFileMachO::SaveCore(...) and 
ObjectFileMinindump::SaveCore(...) to use same code. This will allow core files 
to be consistent with the lldb::SaveCoreStyle across different core file 
creators and will allow us to add new core file saving features that do more 
complex things in future patches.
---
 lldb/include/lldb/Target/MemoryRegionInfo.h   |   8 +-
 lldb/include/lldb/Target/Process.h|  43 +++-
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 137 +++-
 .../Minidump/MinidumpFileBuilder.cpp  |  37 +---
 .../ObjectFile/Minidump/MinidumpFileBuilder.h |   3 +-
 .../Minidump/ObjectFileMinidump.cpp   |   9 +-
 lldb/source/Target/Process.cpp| 196 +-
 lldb/source/Target/TraceDumper.cpp|   7 +-
 8 files changed, 274 insertions(+), 166 deletions(-)

diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h 
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 47d4c9d6398728c..66a4b3ed1b42d5f 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -81,11 +81,11 @@ class MemoryRegionInfo {
   // lldb::Permissions
   uint32_t GetLLDBPermissions() const {
 uint32_t permissions = 0;
-if (m_read)
+if (m_read == eYes)
   permissions |= lldb::ePermissionsReadable;
-if (m_write)
+if (m_write == eYes)
   permissions |= lldb::ePermissionsWritable;
-if (m_execute)
+if (m_execute == eYes)
   permissions |= lldb::ePermissionsExecutable;
 return permissions;
   }
@@ -151,7 +151,7 @@ class MemoryRegionInfo {
   int m_pagesize = 0;
   std::optional> m_dirty_pages;
 };
-  
+
 inline bool operator<(const MemoryRegionInfo &lhs,
   const MemoryRegionInfo &rhs) {
   return lhs.GetRange() < rhs.GetRange();
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a6d3e6c2d16926e..335cb64768a682d 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -54,6 +54,7 @@
 #include "lldb/Utility/UserIDResolver.h"
 #include "lldb/lldb-private.h"
 
+#include "llvm/ADT/AddressRanges.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VersionTuple.h"
@@ -354,11 +355,11 @@ class Process : public 
std::enable_shared_from_this,
   };
   // This is all the event bits the public process broadcaster broadcasts.
   // The process shadow listener signs up for all these bits...
-  static constexpr int g_all_event_bits = eBroadcastBitStateChanged 
+  static constexpr int g_all_event_bits = eBroadcastBitStateChanged
 | eBroadcastBitInterrupt
-| eBroadcastBitSTDOUT 
+| eBroadcastBitSTDOUT
 | eBroadcastBitSTDERR
-| eBroadcastBitProfileData 
+| eBroadcastBitProfileData
 | eBroadcastBitStructuredData;
 
   enum {
@@ -390,7 +391,7 @@ class Process : public 
std::enable_shared_from_this,
   ConstString &GetBroadcasterClass() const override {
 return GetStaticBroadcasterClass();
   }
-  
+
 /// A notification structure that can be used by clients to listen
 /// for changes in a process's lifetime.
 ///
@@ -579,7 +580,7 @@ class Process : public 
std::enable_shared_from_this,
   /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
   /// or CommandObjectMultiword.
   virtual CommandObject *GetPluginCommandObject() { return nullptr; }
-  
+
   /// The underlying plugi

[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -2104,9 +2113,10 @@ class CommandObjectTargetModulesDumpSymtab
 result.GetOutputStream().EOL();
 result.GetOutputStream().EOL();
   }
-  if (INTERRUPT_REQUESTED(GetDebugger(), 
-"Interrupted in dump symtab list with {0} of {1} dumped.", 
-num_dumped, num_matches))
+  if (INTERRUPT_REQUESTED(
+  GetDebugger(),
+  "Interrupted in dump symtab list with {0} of {1} 
dumped.",
+  num_dumped, num_matches))

JDevlieghere wrote:

Please upstage unrelated code changes. I suspect this is the result of our 
editor removing trailing whitespace (I do the same) and then clang-format 
considers this a modified line and formats it.

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


[Lldb-commits] [lldb] Centralize the code that figures out which memory ranges to save into core files (PR #71772)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Greg Clayton (clayborg)


Changes

Prior to this patch, each core file plugin (ObjectFileMachO.cpp and 
ObjectFileMinindump.cpp) would calculate the address ranges to save in 
different ways. This patch adds a new function to Process.h/.cpp:

```
Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style, 
CoreFileMemoryRanges &ranges);
```

The patch updates the ObjectFileMachO::SaveCore(...) and 
ObjectFileMinindump::SaveCore(...) to use same code. This will allow core files 
to be consistent with the lldb::SaveCoreStyle across different core file 
creators and will allow us to add new core file saving features that do more 
complex things in future patches.

---

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


8 Files Affected:

- (modified) lldb/include/lldb/Target/MemoryRegionInfo.h (+4-4) 
- (modified) lldb/include/lldb/Target/Process.h (+37-6) 
- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
(+28-109) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
(+9-28) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h 
(+2-1) 
- (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
(+4-5) 
- (modified) lldb/source/Target/Process.cpp (+186-10) 
- (modified) lldb/source/Target/TraceDumper.cpp (+4-3) 


``diff
diff --git a/lldb/include/lldb/Target/MemoryRegionInfo.h 
b/lldb/include/lldb/Target/MemoryRegionInfo.h
index 47d4c9d6398728c..66a4b3ed1b42d5f 100644
--- a/lldb/include/lldb/Target/MemoryRegionInfo.h
+++ b/lldb/include/lldb/Target/MemoryRegionInfo.h
@@ -81,11 +81,11 @@ class MemoryRegionInfo {
   // lldb::Permissions
   uint32_t GetLLDBPermissions() const {
 uint32_t permissions = 0;
-if (m_read)
+if (m_read == eYes)
   permissions |= lldb::ePermissionsReadable;
-if (m_write)
+if (m_write == eYes)
   permissions |= lldb::ePermissionsWritable;
-if (m_execute)
+if (m_execute == eYes)
   permissions |= lldb::ePermissionsExecutable;
 return permissions;
   }
@@ -151,7 +151,7 @@ class MemoryRegionInfo {
   int m_pagesize = 0;
   std::optional> m_dirty_pages;
 };
-  
+
 inline bool operator<(const MemoryRegionInfo &lhs,
   const MemoryRegionInfo &rhs) {
   return lhs.GetRange() < rhs.GetRange();
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index a6d3e6c2d16926e..335cb64768a682d 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -54,6 +54,7 @@
 #include "lldb/Utility/UserIDResolver.h"
 #include "lldb/lldb-private.h"
 
+#include "llvm/ADT/AddressRanges.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VersionTuple.h"
@@ -354,11 +355,11 @@ class Process : public 
std::enable_shared_from_this,
   };
   // This is all the event bits the public process broadcaster broadcasts.
   // The process shadow listener signs up for all these bits...
-  static constexpr int g_all_event_bits = eBroadcastBitStateChanged 
+  static constexpr int g_all_event_bits = eBroadcastBitStateChanged
 | eBroadcastBitInterrupt
-| eBroadcastBitSTDOUT 
+| eBroadcastBitSTDOUT
 | eBroadcastBitSTDERR
-| eBroadcastBitProfileData 
+| eBroadcastBitProfileData
 | eBroadcastBitStructuredData;
 
   enum {
@@ -390,7 +391,7 @@ class Process : public 
std::enable_shared_from_this,
   ConstString &GetBroadcasterClass() const override {
 return GetStaticBroadcasterClass();
   }
-  
+
 /// A notification structure that can be used by clients to listen
 /// for changes in a process's lifetime.
 ///
@@ -579,7 +580,7 @@ class Process : public 
std::enable_shared_from_this,
   /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
   /// or CommandObjectMultiword.
   virtual CommandObject *GetPluginCommandObject() { return nullptr; }
-  
+
   /// The underlying plugin might store the low-level communication history for
   /// this session.  Dump it into the provided stream.
   virtual void DumpPluginHistory(Stream &s) { return; }
@@ -614,7 +615,7 @@ class Process : public 
std::enable_shared_from_this,
 return error;
   }
 
-  /// The "ShadowListener" for a process is just an ordinary Listener that 
+  /// The "ShadowListener" for a process is just an ordinary Listener that
   /// listens for all the Process event bits.  It's convenient because you can
   /// specify it in the LaunchInfo or AttachInfo, so it will get events from
   /// the very start of the process.
@@ -704,7 +705,37 @@ class Process : public 
std::enable_shared_f

[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread Jonas Devlieghere via lldb-commits

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

I left some comments inline. 

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


[Lldb-commits] [lldb] [lldb] Read Checksum from DWARF line tables (PR #71458)

2023-11-08 Thread Jonas Devlieghere via lldb-commits


@@ -443,6 +455,9 @@ class FileSpec {
   /// The unique'd filename path.
   ConstString m_filename;
 
+  /// The optional MD5 checksum of the file.
+  Checksum m_checksum;
+

JDevlieghere wrote:

To close the loop on this for others, Greg measured the impact of the size 
increase in #71457 (thank you!) and we think the size increase is acceptable in 
the grand scheme of things. As I mentioned in the commit message, we can always 
revisit this in the future. 

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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
21861991e760e7e845dc1be5b804c950543d699a..e7fb5814d7ef7ad28543978567db9f8305630f90
 lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
``





View the diff from darker here.


``diff
--- TestLinuxCore.py2023-11-09 02:11:05.00 +
+++ TestLinuxCore.py2023-11-09 05:22:39.189499 +
@@ -757,12 +757,12 @@
 
 self.dbg.DeleteTarget(target)
 
 def do_test_fd(self, filename, pid, region_count, thread_name):
 file_object = open(filename + ".core", "r")
-fd=file_object.fileno()
-file = lldb.SBFile(fd, 'r', True)
+fd = file_object.fileno()
+file = lldb.SBFile(fd, "r", True)
 target = self.dbg.CreateTarget(filename + ".out")
 process = target.LoadCore(file)
 
 self.check_all(process, pid, region_count, thread_name)
 

``




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


[Lldb-commits] [lldb] Add new API in SBTarget for loading core from SBFile (PR #71769)

2023-11-08 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 21861991e760e7e845dc1be5b804c950543d699a 
e7fb5814d7ef7ad28543978567db9f8305630f90 -- lldb/include/lldb/API/SBTarget.h 
lldb/include/lldb/Target/PostMortemProcess.h lldb/include/lldb/Target/Process.h 
lldb/include/lldb/Target/ProcessTrace.h lldb/include/lldb/Target/Target.h 
lldb/include/lldb/lldb-private-interfaces.h lldb/source/API/SBTarget.cpp 
lldb/source/Commands/CommandObjectTarget.cpp 
lldb/source/Core/IOHandlerCursesGUI.cpp 
lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp 
lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.h 
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.cpp 
lldb/source/Plugins/Process/MacOSX-Kernel/ProcessKDP.h 
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
lldb/source/Plugins/Process/elf-core/ProcessElfCore.h 
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h 
lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp 
lldb/source/Plugins/Process/mach-core/ProcessMachCore.h 
lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp 
lldb/source/Plugins/Process/minidump/ProcessMinidump.h 
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
lldb/source/Target/Process.cpp lldb/source/Target/ProcessTrace.cpp 
lldb/source/Target/Target.cpp lldb/unittests/Target/LocateModuleCallbackTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 62284b29886a..9950f3a4519a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1468,7 +1468,6 @@ public:
 
   virtual bool IsLiveDebugSession() const { return true; };
 
-
   /// Provide a way to retrieve the core dump file that is loaded for 
debugging.
   /// Only available if IsLiveDebugSession() returns true.
   ///
diff --git a/lldb/include/lldb/Target/ProcessTrace.h 
b/lldb/include/lldb/Target/ProcessTrace.h
index ee684a97a5be..de535243744a 100644
--- a/lldb/include/lldb/Target/ProcessTrace.h
+++ b/lldb/include/lldb/Target/ProcessTrace.h
@@ -27,7 +27,8 @@ public:
 
   static llvm::StringRef GetPluginDescriptionStatic();
 
-  ProcessTrace(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, 
lldb::FileSP core_file_sp);
+  ProcessTrace(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+   lldb::FileSP core_file_sp);
 
   ~ProcessTrace() override;
 
diff --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 21fd34faee80..55f2c794c274 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -77,8 +77,8 @@ typedef Status 
(*StructuredDataFilterLaunchInfo)(ProcessLaunchInfo &launch_info,
 typedef SystemRuntime *(*SystemRuntimeCreateInstance)(Process *process);
 typedef lldb::PlatformSP (*PlatformCreateInstance)(bool force,
const ArchSpec *arch);
-typedef lldb::ProcessSP (*ProcessCreateInstance)(
-lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
+typedef lldb::ProcessSP (*ProcessCreateInstance)(lldb::TargetSP target_sp,
+ lldb::ListenerSP listener_sp,
  lldb::FileSP crash_file_sp,
  bool can_connect);
 typedef lldb::RegisterTypeBuilderSP (*RegisterTypeBuilderCreateInstance)(
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index f86effdd2ecc..a44e208df0a9 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2085,7 +2085,8 @@ protected:
   }
   if (INTERRUPT_REQUESTED(GetDebugger(),
   "Interrupted in dump all symtabs with {0} "
-  "of {1} dumped.", num_dumped, num_modules))
+  "of {1} dumped.",
+  num_dumped, num_modules))
 break;
 
   num_dumped++;
diff --git a/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp 
b/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
index c0c6cd8a9b2e..8e256e0c782b 100644
--- a/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/Process/FreeBSDKernel/ProcessFreeBSDKernel.cpp
@@ -84,8 +84,8 @@ lldb::ProcessSP 
ProcessFreeBSDKernel::CreateInstance(lldb::TargetSP target_sp,
 fvc_open(executable->GetFileSpec().GetPath().c_str(),
  file_spec->GetPath().c_str(), nullptr, nullptr, nullptr);
   

[Lldb-commits] [lldb] Centralize the code that figures out which memory ranges to save into core files (PR #71772)

2023-11-08 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 21861991e760e7e845dc1be5b804c950543d699a 
9ff1e92175f90613de6f07dfb4821b8fc0226939 -- 
lldb/include/lldb/Target/MemoryRegionInfo.h lldb/include/lldb/Target/Process.h 
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h 
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp 
lldb/source/Target/Process.cpp lldb/source/Target/TraceDumper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 335cb64768a6..96811cd93bb2 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -355,12 +355,10 @@ public:
   };
   // This is all the event bits the public process broadcaster broadcasts.
   // The process shadow listener signs up for all these bits...
-  static constexpr int g_all_event_bits = eBroadcastBitStateChanged
-| eBroadcastBitInterrupt
-| eBroadcastBitSTDOUT
-| eBroadcastBitSTDERR
-| eBroadcastBitProfileData
-| eBroadcastBitStructuredData;
+  static constexpr int g_all_event_bits =
+  eBroadcastBitStateChanged | eBroadcastBitInterrupt | eBroadcastBitSTDOUT 
|
+  eBroadcastBitSTDERR | eBroadcastBitProfileData |
+  eBroadcastBitStructuredData;
 
   enum {
 eBroadcastInternalStateControlStop = (1 << 0),
@@ -706,7 +704,7 @@ public:
   virtual llvm::Expected SaveCore(llvm::StringRef outfile);
 
   struct CoreFileMemoryRange {
-llvm::AddressRange range; /// The address range to save into the core file.
+llvm::AddressRange range;  /// The address range to save into the core 
file.
 uint32_t lldb_permissions; /// A bit set of lldb::Permissions bits.
 
 bool operator==(const CoreFileMemoryRange &rhs) const {
@@ -735,7 +733,6 @@ public:
  CoreFileMemoryRanges &ranges);
 
 protected:
-
   virtual JITLoaderList &GetJITLoaders();
 
 public:
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 4277555e5219..abeb6129e4c4 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6306,14 +6306,13 @@ static void AddRegion(const MemoryRegionInfo ®ion, 
bool try_dirty_pages,
 
 // Save all memory regions that are not empty or have at least some permissions
 // for a full core file style.
-static Status
-GetCoreFileSaveRangesFull(Process &process,
-  const MemoryRegionInfos ®ions,
-  Process::CoreFileMemoryRanges &ranges) {
+static Status GetCoreFileSaveRangesFull(Process &process,
+const MemoryRegionInfos ®ions,
+Process::CoreFileMemoryRanges &ranges) 
{
 
   // Don't add only dirty pages, add full regions.
   const bool try_dirty_pages = false;
-  for (const auto ®ion: regions)
+  for (const auto ®ion : regions)
 AddRegion(region, try_dirty_pages, ranges);
   return Status();
 }
@@ -6328,7 +6327,7 @@ GetCoreFileSaveRangesDirtyOnly(Process &process,
Process::CoreFileMemoryRanges &ranges) {
   // Iterate over the regions and find all dirty pages.
   bool have_dirty_page_info = false;
-  for (const auto ®ion: regions) {
+  for (const auto ®ion : regions) {
 if (AddDirtyPages(region, ranges))
   have_dirty_page_info = true;
   }
@@ -6358,7 +6357,7 @@ GetCoreFileSaveRangesStackOnly(Process &process,
   std::set stack_bases;
 
   const bool try_dirty_pages = true;
-  for (const auto ®ion: regions) {
+  for (const auto ®ion : regions) {
 if (region.IsStackMemory() == MemoryRegionInfo::eYes) {
   stack_bases.insert(region.GetRange().GetRangeBase());
   AddRegion(region, try_dirty_pages, ranges);
@@ -6369,9 +6368,9 @@ GetCoreFileSaveRangesStackOnly(Process &process,
   // and add those regions if not already added above
   ThreadList &thread_list = process.GetThreadList();
   const size_t num_threads = thread_list.GetSize();
-  for (size_t idx=0; idxGetStackFrameAtIndex(0);
@@ -6386,7 +6385,7 @@ GetCoreFileSaveRangesStackOnly(Process &process,
   // Only add this region if not already added above. If our stack pointer
   // is pointing off in the weeds, we will want this range.
   if (stack_bases.count(sp_region.GetRange().GetRangeBase()) == 0)
- AddRegion(sp_region, try_dirty_pages, ranges);
+AddRegion(sp_region, try_dirty_pages, ranges);
 }
   }
   return Status();

``




https://github.com/llvm/llvm

[Lldb-commits] [lldb] [clang] Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (PR #71780)

2023-11-08 Thread Michael Buch via lldb-commits

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

This patch relands https://github.com/llvm/llvm-project/pull/70639

It was reverted because under certain conditions we triggered an assertion
in `DIBuilder`. Specifically, in the original patch we called 
`EmitGlobalVariable`
at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s have
been uniqued. With limited debug-info such temporary nodes would be created
more frequently, leaving us with non-uniqued nodes by the time we got to
`DIBuilder::finalize`; this violated its pre-condition and caused
assertions to trigger.

To fix this, the latest iteration of the patch moves `EmitGlobalVariable` to the
beginning of `CGDebugInfo::finalize`. Now, when we create a temporary
`DIType` node as a result of emitting a variable definition, it will get uniqued
in time. A test-case was added for this scenario.

Original commit message:
"""
When an LLDB user asks for the value of a static data member, LLDB starts
by searching the Names accelerator table for the corresponding variable
definition DIE. For static data members with out-of-class definitions that
works fine, because those get represented as global variables with a location
and making them eligible to be added to the Names table. However, in-class
definitions won’t get indexed because we usually don't emit global variables
for them. So in DWARF we end up with a single `DW_TAG_member` that
usually holds the constant initializer.  But we don't get a corresponding
CU-level `DW_TAG_variable` like we do for out-of-class definitions.

To make it more convenient for debuggers to get to the value of inline static 
data
members, this patch makes sure we emit definitions for static variables with
constant initializers the same way we do for other static variables. This also 
aligns
Clang closer to GCC, which produces CU-level definitions for inline statics and 
also
emits these into `.debug_pubnames`.

The implementation keeps track of newly created static data members.
Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a
`DW_AT_const_value` for any of those declarations that didn't end up with a
definition in the `DeclCache`.

The newly emitted `DW_TAG_variable` will look as follows:
```
0x007b:   DW_TAG_structure_type
DW_AT_calling_convention(DW_CC_pass_by_value)
DW_AT_name  ("Foo")
...

0x008d: DW_TAG_member
  DW_AT_name("i")
  DW_AT_type(0x0062 "const int")
  DW_AT_external(true)
  DW_AT_declaration (true)
  DW_AT_const_value (4)

Newly added
v

0x009a:   DW_TAG_variable
DW_AT_specification (0x008d "i")
DW_AT_const_value   (4)
DW_AT_linkage_name  ("_ZN2t2IiE1iIfEE")
```

This patch also drops the `DW_AT_const_value` off of the declaration since we
now always have it on the definition. This ensures that the 
`DWARFParallelLinker`
can type-merge class with static members where we couldn't attach the constant
on the declaration in some CUs.
"""

Dependent changes:
* https://github.com/llvm/llvm-project/pull/71004
* https://github.com/llvm/llvm-project/pull/70641

>From e5bc858c35b479d29174c9945c6c67f4d2dc085b Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 9 Nov 2023 01:13:21 +
Subject: [PATCH] Reland "[clang][DebugInfo] Emit global variable definitions
 for static data members with constant initializers"

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 58 +++
 clang/lib/CodeGen/CGDebugInfo.h   |  6 ++
 clang/test/CodeGenCXX/debug-info-class.cpp| 13 +++--
 .../CodeGenCXX/debug-info-static-member.cpp   | 52 ++---
 .../TestConstStaticIntegralMember.py  |  7 ++-
 .../lldb-dap/variables/TestDAP_variables.py   |  9 +--
 6 files changed, 103 insertions(+), 42 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..245f7516640d098 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1677,22 +1677,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
 
   unsigned LineNumber = getLineNumber(Var->getLocation());
   StringRef VName = Var->getName();
-  llvm::Constant *C = nullptr;
-  if (Var->getInit()) {
-const APValue *Value = Var->evaluateValue();
-if (Value) {
-  if (Value->isInt())
-C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
-  if (Value->isFloat())
-C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
-}
-  }
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV =

[Lldb-commits] [lldb] [clang] Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (PR #71780)

2023-11-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

This patch relands https://github.com/llvm/llvm-project/pull/70639

It was reverted because under certain conditions we triggered an assertion
in `DIBuilder`. Specifically, in the original patch we called 
`EmitGlobalVariable`
at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s have
been uniqued. With limited debug-info such temporary nodes would be created
more frequently, leaving us with non-uniqued nodes by the time we got to
`DIBuilder::finalize`; this violated its pre-condition and caused
assertions to trigger.

To fix this, the latest iteration of the patch moves `EmitGlobalVariable` to the
beginning of `CGDebugInfo::finalize`. Now, when we create a temporary
`DIType` node as a result of emitting a variable definition, it will get uniqued
in time. A test-case was added for this scenario.

Original commit message:
"""
When an LLDB user asks for the value of a static data member, LLDB starts
by searching the Names accelerator table for the corresponding variable
definition DIE. For static data members with out-of-class definitions that
works fine, because those get represented as global variables with a location
and making them eligible to be added to the Names table. However, in-class
definitions won’t get indexed because we usually don't emit global variables
for them. So in DWARF we end up with a single `DW_TAG_member` that
usually holds the constant initializer.  But we don't get a corresponding
CU-level `DW_TAG_variable` like we do for out-of-class definitions.

To make it more convenient for debuggers to get to the value of inline static 
data
members, this patch makes sure we emit definitions for static variables with
constant initializers the same way we do for other static variables. This also 
aligns
Clang closer to GCC, which produces CU-level definitions for inline statics and 
also
emits these into `.debug_pubnames`.

The implementation keeps track of newly created static data members.
Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with a
`DW_AT_const_value` for any of those declarations that didn't end up with a
definition in the `DeclCache`.

The newly emitted `DW_TAG_variable` will look as follows:
```
0x007b:   DW_TAG_structure_type
DW_AT_calling_convention(DW_CC_pass_by_value)
DW_AT_name  ("Foo")
...

0x008d: DW_TAG_member
  DW_AT_name("i")
  DW_AT_type(0x0062 "const int")
  DW_AT_external(true)
  DW_AT_declaration (true)
  DW_AT_const_value (4)

Newly added
v

0x009a:   DW_TAG_variable
DW_AT_specification (0x008d "i")
DW_AT_const_value   (4)
DW_AT_linkage_name  ("_ZN2t2IiE1iIfEE")
```

This patch also drops the `DW_AT_const_value` off of the declaration since we
now always have it on the definition. This ensures that the 
`DWARFParallelLinker`
can type-merge class with static members where we couldn't attach the constant
on the declaration in some CUs.
"""

Dependent changes:
* https://github.com/llvm/llvm-project/pull/71004
* https://github.com/llvm/llvm-project/pull/70641

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+47-11) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (+6) 
- (modified) clang/test/CodeGenCXX/debug-info-class.cpp (+9-4) 
- (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+32-20) 
- (modified) 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
 (+4-3) 
- (modified) lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py (+5-4) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..245f7516640d098 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1677,22 +1677,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
 
   unsigned LineNumber = getLineNumber(Var->getLocation());
   StringRef VName = Var->getName();
-  llvm::Constant *C = nullptr;
-  if (Var->getInit()) {
-const APValue *Value = Var->evaluateValue();
-if (Value) {
-  if (Value->isInt())
-C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
-  if (Value->isFloat())
-C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
-}
-  }
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
+  RecordTy, VName, VUnit, LineNumbe

[Lldb-commits] [lldb] [clang] Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (PR #71780)

2023-11-08 Thread Michael Buch via lldb-commits

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

>From e5bc858c35b479d29174c9945c6c67f4d2dc085b Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 9 Nov 2023 01:13:21 +
Subject: [PATCH 1/2] Reland "[clang][DebugInfo] Emit global variable
 definitions for static data members with constant initializers"

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 58 +++
 clang/lib/CodeGen/CGDebugInfo.h   |  6 ++
 clang/test/CodeGenCXX/debug-info-class.cpp| 13 +++--
 .../CodeGenCXX/debug-info-static-member.cpp   | 52 ++---
 .../TestConstStaticIntegralMember.py  |  7 ++-
 .../lldb-dap/variables/TestDAP_variables.py   |  9 +--
 6 files changed, 103 insertions(+), 42 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..245f7516640d098 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1677,22 +1677,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl 
*Var, llvm::DIType *RecordTy,
 
   unsigned LineNumber = getLineNumber(Var->getLocation());
   StringRef VName = Var->getName();
-  llvm::Constant *C = nullptr;
-  if (Var->getInit()) {
-const APValue *Value = Var->evaluateValue();
-if (Value) {
-  if (Value->isInt())
-C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
-  if (Value->isFloat())
-C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
-}
-  }
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
+  StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
 }
 
@@ -5596,6 +5587,39 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
   TemplateParameters, Align));
 }
 
+void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
+  assert(VD->hasInit());
+  assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
+  if (VD->hasAttr())
+return;
+
+  auto &GV = DeclCache[VD];
+  if (GV)
+return;
+
+  auto const *InitVal = VD->evaluateValue();
+  if (!InitVal)
+return;
+
+  llvm::DIFile *Unit = nullptr;
+  llvm::DIScope *DContext = nullptr;
+  unsigned LineNo;
+  StringRef DeclName, LinkageName;
+  QualType T;
+  llvm::MDTuple *TemplateParameters = nullptr;
+  collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName,
+  TemplateParameters, DContext);
+
+  auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
+  llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
+  llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal);
+
+  GV.reset(DBuilder.createGlobalVariableExpression(
+  TheCU, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
+  true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VD),
+  TemplateParameters, Align, Annotations));
+}
+
 void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
   assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
@@ -5800,6 +5824,18 @@ void CGDebugInfo::setDwoId(uint64_t Signature) {
 }
 
 void CGDebugInfo::finalize() {
+  for (auto const *VD : StaticDataMemberDefinitionsToEmit) {
+assert(VD->isStaticDataMember());
+
+if (DeclCache.contains(VD))
+  continue;
+
+if (!VD->hasInit())
+  continue;
+
+EmitGlobalVariable(VD);
+  }
+
   // Creating types might create further types - invalidating the current
   // element and the size(), so don't cache/reference them.
   for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 7b60e94555d0608..3e4c133b7f2b9f1 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -161,6 +161,9 @@ class CGDebugInfo {
   llvm::DenseMap>
   StaticDataMemberCache;
 
+  /// Keeps track of static data members for which we should emit a definition.
+  std::vector StaticDataMemberDefinitionsToEmit;
+
   using ParamDecl2StmtTy = llvm::DenseMap;
   using Param2DILocTy =
   llvm::DenseMap;
@@ -526,6 +529,9 @@ class CGDebugInfo {
   /// Emit a constant global variable's debug info.
   void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
 
+  /// Emit debug-info for a variable with a constant initializer.
+  void EmitGlobalVariable(const VarDecl *VD);
+
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
diff --git a/clang/test/CodeGenCXX/debug-info-class.cpp 
b/clang/