[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

labath wrote:

> This patch as-is is NFC?
NFC**I**, I would say :) I don't think this should change the behavior in any 
way, but it's pretty hard to guarantee that.

> (no tests) but without this patch, the other delay-definition-die patch would 
> have had a problem?
> 
> Is it possible to add a test in this patch that would exercise the thing that 
> would become buggy if the delay-definition-die patch were to be recommitted?

Sort of. The situation is a bit complicated, because this touches pretty much 
the same code as the other patch, so the other patch will not apply cleanly or 
become magically correct. It's more like a building block that enables us to 
rewrite the other patch in a more robust manner -- which brings us to the 
second way this is complicated: It's not that the other patch was wrong on its 
own. It was just very sensitive to the other bugs. Previously, if we failed to 
unique the types correctly, we would "just" get the wrong type (or maybe no 
type). With the patch, that situation would trigger a hard assert. On its own, 
that might even be considered a good thing (easier to find bugs), we're it not 
for the fact that this made the logic of the patch very hard to follow. So, 
this is my attempt to make it more straight-forward.

As for tests, it is possible to write a test which would reproduce a crash with 
the original patch, but that test is contingent on the existence of another 
bug. When I reverted that patch, I added a test (in 
de3f1b6d68ab8a0e827db84b328803857a4f60df) which triggered the crash. However, 
now that that bug is fixed (#95905), it does not crash anymore. Now, I happen 
to know of another bug (which happens to be triggered by the same code, only 
compiled with type units), but the same thing will happen once that bug is 
fixed. Given all of that, I don't think another test case is needed with this 
particular patch. It might be interesting for the final delay patch, if we 
don't fix the type unit thing by then, but I think of this patch mostly as a 
cleanup.

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


[Lldb-commits] [lldb] [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (PR #96511)

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

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


[Lldb-commits] [lldb] 33a9c57 - [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (#96511)

2024-06-24 Thread via lldb-commits

Author: Miro Bucko
Date: 2024-06-24T11:38:05-07:00
New Revision: 33a9c57b89c3ea901a057c3fcc9c9160eaf5a625

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

LOG: [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (#96511)

This is to unblock #95007. Will investigate why the assertion is failing
on some arch.

Added: 


Modified: 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py

Removed: 




diff  --git a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py 
b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
index 0544100f97b29..2c11fba80766f 100644
--- a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
+++ b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
@@ -35,7 +35,6 @@ def GetRangeFromAddrValue(test_base, addr):
 )
 
 test_base.assertTrue(region.IsReadable())
-test_base.assertFalse(region.IsExecutable())
 
 address_start = lldb.SBAddress(region.GetRegionBase(), test_base.target)
 stack_size = region.GetRegionEnd() - region.GetRegionBase()



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


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

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

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


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

2024-06-24 Thread via lldb-commits

Author: Jacob Lalonde
Date: 2024-06-24T10:48:01-07:00
New Revision: a27164cb33162bb42642c091703f9c6f8829785c

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

LOG: [LLDB][Minidump] Add 64b support to LLDB's minidump file builder. (#95312)

Currently, LLDB does not support taking a minidump over the 4.2gb limit imposed 
by uint32. In fact, currently it writes the RVA's and the headers to the end of 
the file, which can become corrupted due to the header offset only supporting a 
32b offset.

This change reorganizes how the file structure is laid out. LLDB will 
precalculate the number of directories required and preallocate space at the 
top of the file to fill in later. Additionally, thread stacks require a 32b 
offset, and we provision empty descriptors and keep track of them to clean up 
once we write the 32b memory list.

For
[MemoryList64](https://learn.microsoft.com/en-us/windows/win32/api/minidumpapiset/ns-minidumpapiset-minidump_memory64_list),
the RVA to the start of the section itself will remain in a 32b addressable 
space. We achieve this by predetermining the space the memory regions will 
take, and only writing up to 4.2 gb of data with some buffer to allow all the 
MemoryDescriptor64s to also still be 32b addressable.

I did not add any explicit tests to this PR because allocating 4.2gb+ to test 
is very expensive. However, we have 32b automation tests and I validated with 
in several ways, including with 5gb+ array/object and would be willing to add 
this as a test case.

Added: 


Modified: 
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp
llvm/include/llvm/BinaryFormat/Minidump.h

Removed: 




diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp 
b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index 7231433619ffb..7a09c6104d08c 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -20,25 +20,100 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/StopInfo.h"
 #include "lldb/Target/ThreadList.h"
+#include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/DataExtractor.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
+#include "lldb/Utility/RangeMap.h"
 #include "lldb/Utility/RegisterValue.h"
 
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Minidump.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
+#include "llvm/TargetParser/Triple.h"
 
 #include "Plugins/Process/minidump/MinidumpTypes.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-types.h"
 
+#include 
 #include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace lldb;
 using namespace lldb_private;
 using namespace llvm::minidump;
 
-void MinidumpFileBuilder::AddDirectory(StreamType type, size_t stream_size) {
+Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
+  // First set the offset on the file, and on the bytes saved
+  m_saved_data_size = HEADER_SIZE;
+  // We know we will have at least Misc, SystemInfo, Modules, and ThreadList
+  // (corresponding memory list for stacks) And an additional memory list for
+  // non-stacks.
+  lldb_private::Target  = m_process_sp->GetTarget();
+  m_expected_directories = 6;
+  // Check if OS is linux and reserve directory space for all linux specific
+  // breakpad extension directories.
+  if (target.GetArchitecture().GetTriple().getOS() ==
+  llvm::Triple::OSType::Linux)
+m_expected_directories += 9;
+
+  // Go through all of the threads and check for exceptions.
+  lldb_private::ThreadList thread_list = m_process_sp->GetThreadList();
+  const uint32_t num_threads = thread_list.GetSize();
+  for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
+ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx));
+StopInfoSP stop_info_sp = thread_sp->GetStopInfo();
+if (stop_info_sp) {
+  const StopReason _reason = stop_info_sp->GetStopReason();
+  if (stop_reason == StopReason::eStopReasonException ||
+  stop_reason == StopReason::eStopReasonSignal)
+m_expected_directories++;
+}
+  }
+
+  m_saved_data_size +=
+  m_expected_directories * sizeof(llvm::minidump::Directory);
+  Status error;
+  offset_t new_offset = m_core_file->SeekFromStart(m_saved_data_size);
+  if (new_offset != m_saved_data_size)
+error.SetErrorStringWithFormat("Failed to fill in header and directory "
+ 

[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits

https://github.com/mattweingarten updated 
https://github.com/llvm/llvm-project/pull/94264

error: too big or took too long to generate
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

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

clayborg wrote:

An extra character snuck in and messed with the buildbots, fixed with:
```
commit fc066ca1c32b4aef549f3e371dc70589804aba0f (HEAD -> main, origin/main, 
origin/HEAD)
Author: Greg Clayton 
Date:   Mon Jun 24 10:15:55 2024 -0700

Fix buildbots for https://github.com/llvm/llvm-project/pull/87740
```

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


[Lldb-commits] [lldb] fc066ca - Fix buildbots for https://github.com/llvm/llvm-project/pull/87740

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

Author: Greg Clayton
Date: 2024-06-24T10:16:39-07:00
New Revision: fc066ca1c32b4aef549f3e371dc70589804aba0f

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

LOG: Fix buildbots for https://github.com/llvm/llvm-project/pull/87740

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index bd81618ac914d..70aa4b9e1f203 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1746,7 +1746,7 @@ SymbolFileDWARF 
*SymbolFileDWARF::GetDIERefSymbolFile(const DIERef _ref) {
 
   if (file_index) {
   // We have a SymbolFileDWARFDebugMap, so let it find the right file
-\if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile())
+if (SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile())
   return debug_map->GetSymbolFileByOSOIndex(*file_index);
 
 // Handle the .dwp file case correctly



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


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

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

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


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

2024-06-24 Thread via lldb-commits

Author: Greg Clayton
Date: 2024-06-24T09:59:59-07:00
New Revision: 3b5b814647ef83ab763cf7871b6d74edfca67438

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

LOG: Add support for using foreign type units in .debug_names. (#87740)

This patch adds support for the new foreign type unit support in
.debug_names. Features include:
- don't manually index foreign TUs if we have info for them
- only use the type unit entries that match the .dwo files when we have
a .dwp file
- fix type unit lookups for .dwo files
- fix crashers that happen due to PeekDIEName() using wrong offsets where an 
entry had DW_IDX_comp_unit and DW_IDX_type_unit entries and when we had no type 
unit support, it would cause us to think it was a normal DIE in .debug_info 
from the main executable.

-

Co-authored-by: paperchalice 

Added: 
lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
index c37cc91e08ed1..f7df38d240191 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -232,6 +232,10 @@ DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section 
section,
   return result;
 }
 
+const std::shared_ptr ::GetDwpSymbolFile() {
+  return m_dwarf.GetDwpSymbolFile();
+}
+
 DWARFTypeUnit *DWARFDebugInfo::GetTypeUnitForHash(uint64_t hash) {
   auto pos = llvm::lower_bound(m_type_hash_to_unit_index,
std::make_pair(hash, 0u), llvm::less_first());

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
index 4706b55d38ea9..598739bf3cb95 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
@@ -52,6 +52,8 @@ class DWARFDebugInfo {
 
   const DWARFDebugAranges ();
 
+  const std::shared_ptr ();
+
 protected:
   typedef std::vector UnitColl;
 

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
index 1d17f20670eed..7e66b3dccf97f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -10,6 +10,7 @@
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
 #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
@@ -34,6 +35,17 @@ DebugNamesDWARFIndex::Create(Module , 
DWARFDataExtractor debug_names,
   module, std::move(index_up), debug_names, debug_str, dwarf));
 }
 
+llvm::DenseSet
+DebugNamesDWARFIndex::GetTypeUnitSignatures(const DebugNames _names) {
+  llvm::DenseSet result;
+  for (const DebugNames::NameIndex  : debug_names) {
+const uint32_t num_tus = ni.getForeignTUCount();
+for (uint32_t tu = 0; tu < num_tus; ++tu)
+  result.insert(ni.getForeignTUSignature(tu));
+  }
+  return result;
+}
+
 llvm::DenseSet
 DebugNamesDWARFIndex::GetUnits(const DebugNames _names) {
   llvm::DenseSet result;
@@ -48,20 +60,80 @@ DebugNamesDWARFIndex::GetUnits(const DebugNames 
_names) {
   return result;
 }
 
+std::optional
+DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry ) const 
{
+  std::optional type_sig = entry.getForeignTUTypeSignature();
+  if (!type_sig.has_value())
+return std::nullopt;
+
+  // Ask the entry for the skeleton compile unit offset and fetch the .dwo
+  // file from it and get the type unit by signature from there. If we find
+  // the type unit in the .dwo file, we don't need to check that the
+  // DW_AT_dwo_name matches because each .dwo file can have its own type unit.
+  std::optional cu_offset = entry.getRelatedCUOffset();
+  if 

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

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

https://github.com/clayborg updated 
https://github.com/llvm/llvm-project/pull/87740

>From 3f99b41eac0e04e15bdb99bea2ee75703936ea00 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Sat, 30 Mar 2024 10:50:34 -0700
Subject: [PATCH 01/12] Add support for using foreign type units in
 .debug_names.

This patch adds support for the new foreign type unit support in .debug_names. 
Features include:
- don't manually index foreign TUs if we have info for them
- only use the type unit entries that match the .dwo files when we have a .dwp 
file
- fix crashers that happen due to PeekDIEName() using wrong offsets
---
 .../SymbolFile/DWARF/DWARFDebugInfo.cpp   | 18 
 .../Plugins/SymbolFile/DWARF/DWARFDebugInfo.h |  2 +
 .../SymbolFile/DWARF/DebugNamesDWARFIndex.cpp | 65 -
 .../SymbolFile/DWARF/DebugNamesDWARFIndex.h   |  6 +-
 .../SymbolFile/DWARF/ManualDWARFIndex.cpp |  6 +-
 .../SymbolFile/DWARF/ManualDWARFIndex.h   |  7 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 66 --
 .../SymbolFile/DWARF/SymbolFileDWARF.h|  9 ++
 .../DWARF/x86/dwp-foreign-type-units.cpp  | 91 +++
 .../DebugInfo/DWARF/DWARFAcceleratorTable.h   | 11 +++
 .../DebugInfo/DWARF/DWARFAcceleratorTable.cpp | 13 +++
 11 files changed, 257 insertions(+), 37 deletions(-)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
index c37cc91e08ed12..056c6d4b0605f8 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
@@ -222,6 +222,20 @@ DWARFUnit *DWARFDebugInfo::GetUnitAtOffset(DIERef::Section 
section,
   return result;
 }
 
+DWARFUnit *DWARFDebugInfo::GetUnit(const DIERef _ref) {
+  // Make sure we get the correct SymbolFileDWARF from the DIERef before
+  // asking for information from a debug info object. We might start with the
+  // DWARFDebugInfo for the main executable in a split DWARF and the DIERef
+  // might be pointing to a specific .dwo file or to the .dwp file. So this
+  // makes sure we get the right SymbolFileDWARF instance before finding the
+  // DWARFUnit that contains the offset. If we just use this object to do the
+  // search, we might be using the wrong .debug_info section from the wrong
+  // file with an offset meant for a different section.
+  SymbolFileDWARF *dwarf = m_dwarf.GetDIERefSymbolFile(die_ref);
+  return dwarf->DebugInfo().GetUnitContainingDIEOffset(die_ref.section(),
+   die_ref.die_offset());
+}
+
 DWARFUnit *
 DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section section,
dw_offset_t die_offset) {
@@ -232,6 +246,10 @@ DWARFDebugInfo::GetUnitContainingDIEOffset(DIERef::Section 
section,
   return result;
 }
 
+const std::shared_ptr DWARFDebugInfo::GetDwpSymbolFile() {
+  return m_dwarf.GetDwpSymbolFile();
+}
+
 DWARFTypeUnit *DWARFDebugInfo::GetTypeUnitForHash(uint64_t hash) {
   auto pos = llvm::lower_bound(m_type_hash_to_unit_index,
std::make_pair(hash, 0u), llvm::less_first());
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
index 4706b55d38ea98..4d4555a3382529 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
@@ -52,6 +52,8 @@ class DWARFDebugInfo {
 
   const DWARFDebugAranges ();
 
+  const std::shared_ptr GetDwpSymbolFile();
+
 protected:
   typedef std::vector UnitColl;
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
index 1d17f20670eed4..d815d345b08ee7 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
@@ -34,6 +34,18 @@ DebugNamesDWARFIndex::Create(Module , 
DWARFDataExtractor debug_names,
   module, std::move(index_up), debug_names, debug_str, dwarf));
 }
 
+
+llvm::DenseSet
+DebugNamesDWARFIndex::GetTypeUnitSigs(const DebugNames _names) {
+  llvm::DenseSet result;
+  for (const DebugNames::NameIndex  : debug_names) {
+const uint32_t num_tus = ni.getForeignTUCount();
+for (uint32_t tu = 0; tu < num_tus; ++tu)
+  result.insert(ni.getForeignTUSignature(tu));
+  }
+  return result;
+}
+
 llvm::DenseSet
 DebugNamesDWARFIndex::GetUnits(const DebugNames _names) {
   llvm::DenseSet result;
@@ -48,17 +60,22 @@ DebugNamesDWARFIndex::GetUnits(const DebugNames 
_names) {
   return result;
 }
 
+DWARFTypeUnit *
+DebugNamesDWARFIndex::GetForeignTypeUnit(const DebugNames::Entry ) const 
{
+  std::optional type_sig = entry.getForeignTUTypeSignature();
+  if (type_sig)
+if (auto dwp_sp = m_debug_info.GetDwpSymbolFile())
+  

[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-24 Thread Chelsea Cassanova via lldb-commits

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


[Lldb-commits] [lldb] 347206f - Add a unit test for SBBreakpoint::SetCallback (#96001)

2024-06-24 Thread via lldb-commits

Author: Chelsea Cassanova
Date: 2024-06-24T09:50:42-07:00
New Revision: 347206f9570446340da6d7dadc13d10b0aac4528

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

LOG: Add a unit test for SBBreakpoint::SetCallback (#96001)

This commit adds a unit test for SBBreakpoint::SetCallback as it wasn't
being tested before.

Added: 
lldb/unittests/Callback/CMakeLists.txt
lldb/unittests/Callback/TestBreakpointSetCallback.cpp

Modified: 
lldb/include/lldb/lldb-private-interfaces.h
lldb/source/Breakpoint/BreakpointOptions.cpp
lldb/unittests/CMakeLists.txt

Removed: 




diff  --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 53d5fbb84cc92..cdd9b51d9329c 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -99,10 +99,10 @@ typedef std::optional 
(*SymbolLocatorLocateExecutableSymbolFile)(
 typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
 ModuleSpec _spec, Status , bool force_lookup,
 bool copy_executable);
-typedef bool (*BreakpointHitCallback)(void *baton,
-  StoppointCallbackContext *context,
-  lldb::user_id_t break_id,
-  lldb::user_id_t break_loc_id);
+using BreakpointHitCallback =
+std::function;
+
 typedef bool (*WatchpointHitCallback)(void *baton,
   StoppointCallbackContext *context,
   lldb::user_id_t watch_id);

diff  --git a/lldb/source/Breakpoint/BreakpointOptions.cpp 
b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 6c6037dd9edd3..1db8401698114 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -102,19 +102,11 @@ const char *BreakpointOptions::g_option_names[(
 "ConditionText", "IgnoreCount", 
 "EnabledState", "OneShotState", "AutoContinue"};
 
-bool BreakpointOptions::NullCallback(void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id) {
-  return true;
-}
-
 // BreakpointOptions constructor
 BreakpointOptions::BreakpointOptions(bool all_flags_set)
-: m_callback(BreakpointOptions::NullCallback),
-  m_baton_is_command_baton(false), m_callback_is_synchronous(false),
-  m_enabled(true), m_one_shot(false), m_ignore_count(0),
-  m_condition_text_hash(0), m_inject_condition(false),
+: m_callback(nullptr), m_baton_is_command_baton(false),
+  m_callback_is_synchronous(false), m_enabled(true), m_one_shot(false),
+  m_ignore_count(0), m_condition_text_hash(0), m_inject_condition(false),
   m_auto_continue(false), m_set_flags(0) {
   if (all_flags_set)
 m_set_flags.Set(~((Flags::ValueType)0));
@@ -420,7 +412,7 @@ void BreakpointOptions::SetCallback(
 }
 
 void BreakpointOptions::ClearCallback() {
-  m_callback = BreakpointOptions::NullCallback;
+  m_callback = nullptr;
   m_callback_is_synchronous = false;
   m_callback_baton_sp.reset();
   m_baton_is_command_baton = false;
@@ -449,7 +441,7 @@ bool 
BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
 }
 
 bool BreakpointOptions::HasCallback() const {
-  return m_callback != BreakpointOptions::NullCallback;
+  return static_cast(m_callback);
 }
 
 bool BreakpointOptions::GetCommandLineCallbacks(StringList _list) {

diff  --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index a2585a94b6155..cc9d45ebf981d 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   add_subdirectory(API)
 endif()
 add_subdirectory(Breakpoint)
+add_subdirectory(Callback)
 add_subdirectory(Core)
 add_subdirectory(DataFormatter)
 add_subdirectory(Disassembler)

diff  --git a/lldb/unittests/Callback/CMakeLists.txt 
b/lldb/unittests/Callback/CMakeLists.txt
new file mode 100644
index 0..b9e0ef5a396e3
--- /dev/null
+++ b/lldb/unittests/Callback/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_unittest(LLDBCallbackTests
+  TestBreakpointSetCallback.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
+  LINK_COMPONENTS
+Support
+  )

diff  --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..2a7070f9349c0
--- /dev/null
+++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
@@ -0,0 +1,85 @@
+//===-- TestBreakpointSetCallback.cpp

[Lldb-commits] [lldb] [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (PR #96511)

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

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


[Lldb-commits] [lldb] [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (PR #96511)

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

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

Looks like this is to unblock the bots? Is the test actually incorrect or is 
this a temporary fix while you investigate? Would be nice to mention that in 
the commit message. 

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


[Lldb-commits] [lldb] [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (PR #96511)

2024-06-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Miro Bucko (mbucko)


Changes

Tests added in #95007.

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


1 Files Affected:

- (modified) lldb/test/API/python_api/find_in_memory/address_ranges_helper.py 
(-1) 


``diff
diff --git a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py 
b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
index 0544100f97b29..2c11fba80766f 100644
--- a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
+++ b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
@@ -35,7 +35,6 @@ def GetRangeFromAddrValue(test_base, addr):
 )
 
 test_base.assertTrue(region.IsReadable())
-test_base.assertFalse(region.IsExecutable())
 
 address_start = lldb.SBAddress(region.GetRegionBase(), test_base.target)
 stack_size = region.GetRegionEnd() - region.GetRegionBase()

``




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


[Lldb-commits] [lldb] [lldb] Fix failing TestFind(Ranges)InMemory.py tests. (PR #96511)

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

https://github.com/mbucko created 
https://github.com/llvm/llvm-project/pull/96511

Tests added in #95007.

>From 4f5588a6928080833a428fc7e1356a807a333a0e Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Mon, 24 Jun 2024 09:15:36 -0700
Subject: [PATCH] [lldb] Fix TestFind(Ranges)InMemory.py tests.

---
 lldb/test/API/python_api/find_in_memory/address_ranges_helper.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py 
b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
index 0544100f97b29..2c11fba80766f 100644
--- a/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
+++ b/lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
@@ -35,7 +35,6 @@ def GetRangeFromAddrValue(test_base, addr):
 )
 
 test_base.assertTrue(region.IsReadable())
-test_base.assertFalse(region.IsExecutable())
 
 address_start = lldb.SBAddress(region.GetRegionBase(), test_base.target)
 stack_size = region.GetRegionEnd() - region.GetRegionBase()

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


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

2024-06-24 Thread Chelsea Cassanova via lldb-commits

chelcassanova wrote:

Hey Miro, looks like this change broke the LLDB MacOS buildbot: 
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/6353/

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


[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

dwblaikie wrote:

This patch as-is is NFC? (no tests) but without this patch, the other 
delay-definition-die patch would have had a problem?

Is it possible to add a test in this patch that would exercise the thing that 
would become buggy if the delay-definition-die patch were to be recommitted?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -124,6 +124,13 @@ struct PortableMemInfoBlock {
   OS << "" << #Name << ": " << Name << "\n";
 #include "llvm/ProfileData/MIBEntryDef.inc"
 #undef MIBEntryDef
+if (AccessHistogramSize > 0) {
+  OS << "" << "AccessHistogramValues" << ":";
+  for (uint32_t I = 0; I < AccessHistogramSize; ++I) {
+OS << " -" << ((uint64_t *)AccessHistogram)[I];

mattweingarten wrote:

I though only having space delimiting did not produce valid yaml, I double 
checked and was wrong. Changed to space delimiting, thanks!

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -20,25 +20,25 @@ CHECK-NEXT:  -
 
 CHECK:  Records:
 CHECK-NEXT:  -
-CHECK-NEXT:FunctionGUID: 15505678318020221912
+CHECK-NEXT:FunctionGUID: 3873612792189045660
 CHECK-NEXT:AllocSites:
 CHECK-NEXT:-
 CHECK-NEXT:  Callstack:
 CHECK-NEXT:  -
-CHECK-NEXT:Function: 15505678318020221912
-CHECK-NEXT:SymbolName: qux
+CHECK-NEXT:Function: 3873612792189045660
+CHECK-NEXT:SymbolName: _Z3quxi

mattweingarten wrote:

good question, I suspect this test has not been regenerated in a long time and 
something changed in meantime in memprof? I think it might have to do with the 
SymbolNames being mangled vs demangled, which changes the hash value? Is it a 
problem that the hash value changed?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -0,0 +1,101 @@
+REQUIRES: x86_64-linux
+
+This is a copy of memprof-basict.test with slight changes to check that we can 
still read v3 of memprofraw.
+
+To update the inputs used below run Inputs/update_memprof_inputs.sh 
/path/to/updated/clang

mattweingarten wrote:

yes, good point! 

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -0,0 +1,101 @@
+REQUIRES: x86_64-linux
+
+This is a copy of memprof-basict.test with slight changes to check that we can 
still read v3 of memprofraw.

mattweingarten wrote:

done

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module ) {
   }
 }
 
+// Set MemprofHistogramFlag as a Global veriable in IR. This makes it 
accessible
+// to
+// the runtime, changing shadow count behavior.
+void createMemprofHistogramFlagVar(Module ) {
+  const StringRef VarName(MemProfHistogramFlagVar);
+  Type *IntTy1 = Type::getInt1Ty(M.getContext());
+  auto MemprofHistogramFlag = new GlobalVariable(
+  M, IntTy1, true, GlobalValue::WeakAnyLinkage,
+  Constant::getIntegerValue(IntTy1, APInt(1, ClHistogram)), VarName);
+  // MemprofHistogramFlag->setVisibility(GlobalValue::HiddenVisibility);

mattweingarten wrote:

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module ) {
   }
 }
 
+// Set MemprofHistogramFlag as a Global veriable in IR. This makes it 
accessible
+// to

mattweingarten wrote:

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -610,13 +670,33 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
   return BuildIds.takeVector();
 }
 
+// FIXME: Add a schema for serializing similiar to IndexedMemprofReader. This
+// will help being able to deserialize different versions raw memprof versions
+// more easily.
+llvm::SmallVector>
+RawMemProfReader::readMemInfoBlocks(const char *Ptr) {
+  if (MemprofRawVersion == 3ULL) {
+errs() << "Reading V3\n";

mattweingarten wrote:

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -96,19 +102,63 @@ llvm::SmallVector readSegmentEntries(const 
char *Ptr) {
 }
 
 llvm::SmallVector>
-readMemInfoBlocks(const char *Ptr) {
+readMemInfoBlocksV3(const char *Ptr) {
   using namespace support;
 
   const uint64_t NumItemsToRead =
-  endian::readNext(Ptr);
+  endian::readNext(Ptr);
+
   llvm::SmallVector> Items;
   for (uint64_t I = 0; I < NumItemsToRead; I++) {
 const uint64_t Id =
-endian::readNext(Ptr);
-const MemInfoBlock MIB = *reinterpret_cast(Ptr);
+endian::readNext(Ptr);
+
+// We cheat a bit here and remove the const from cast to set the
+// Histogram Pointer to newly allocated buffer. We also cheat, since V3 and
+// V4 do not have the same fields. V3 is missing AccessHistogramSize and
+// AccessHistogram. This means we read "dirty" data in here, but it should
+// not segfault, since there will be callstack data placed after this in 
the
+// binary format.
+MemInfoBlock MIB = *reinterpret_cast(Ptr);
+// Overwrite dirty data.

mattweingarten wrote:

My thought process is that the MemInfoBlock MIB is a allocated on the stack, 
since its a local variable and not a pointer. Meaning the reinterpret_cast 
copies the information from the data-buffer  into the stack variable. Correct 
me if I am wrong

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -205,8 +205,14 @@ class RawMemProfReader final : public MemProfReader {
 
   object::SectionedAddress getModuleOffset(uint64_t VirtualAddress);
 
+  llvm::SmallVector>
+  readMemInfoBlocks(const char *Ptr);
+
   // The profiled binary.
   object::OwningBinary Binary;
+  // Version of raw memprof binary currently being read. Defaults to most 
update

mattweingarten wrote:

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -38,4 +38,5 @@ MEMPROF_FLAG(bool, 
allocator_frees_and_returns_null_on_realloc_zero, true,
 MEMPROF_FLAG(bool, print_text, false,
   "If set, prints the heap profile in text format. Else use the raw binary 
serialization format.")
 MEMPROF_FLAG(bool, print_terse, false,
- "If set, prints memory profile in a terse format. Only applicable 
if print_text = true.")
+ "If set, prints memory profile in a terse format. Only applicable 
"

mattweingarten wrote:

done.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) {
   return count;
 }
 
+// Accumulates the access count from the shadow for the given pointer and size.
+// See memprof_mapping.h for an overview on histogram counters.
+u64 GetShadowCountHistogram(uptr p, u32 size) {
+  u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p);
+  u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size);
+  u64 count = 0;
+  for (; shadow <= shadow_end; shadow++)
+count += *shadow;
+  return count;
+}
+
+// If we use the normal approach from clearCountersWithoutHistogram, the
+// histogram will clear too much data and may overwrite shadow counters that 
are
+// in use. Likely because of rounding up the shadow_end pointer.
+// See memprof_mapping.h for an overview on histogram counters.
+void clearCountersHistogram(uptr addr, uptr size) {
+  u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr);
+  u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size);
+  for (; shadow_8 < shadow_end_8; shadow_8++) {
+*shadow_8 = 0;
+  }
+}
+
+void clearCountersWithoutHistogram(uptr addr, uptr size) {
+  uptr shadow_beg = MEM_TO_SHADOW(addr);
+  uptr shadow_end = MEM_TO_SHADOW(addr + size - SHADOW_GRANULARITY) + 1;
+  REAL(memset)((void *)shadow_beg, 0, shadow_end - shadow_beg);
+}
+
 // Clears the shadow counters (when memory is allocated).
 void ClearShadow(uptr addr, uptr size) {

mattweingarten wrote:

This function uses the MEM_TO_SHADOW computed pointers "kind of", but in 
reality it just rounds these pointers up to nearest page_sizes. So in effect, 
full pages should be cleared no matter if it is with histogram or without.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-24 Thread Matthew Weingarten via lldb-commits


@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) {
   return count;
 }
 
+// Accumulates the access count from the shadow for the given pointer and size.
+// See memprof_mapping.h for an overview on histogram counters.
+u64 GetShadowCountHistogram(uptr p, u32 size) {
+  u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p);
+  u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size);
+  u64 count = 0;
+  for (; shadow <= shadow_end; shadow++)
+count += *shadow;
+  return count;
+}
+
+// If we use the normal approach from clearCountersWithoutHistogram, the
+// histogram will clear too much data and may overwrite shadow counters that 
are
+// in use. Likely because of rounding up the shadow_end pointer.
+// See memprof_mapping.h for an overview on histogram counters.
+void clearCountersHistogram(uptr addr, uptr size) {
+  u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr);
+  u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size);
+  for (; shadow_8 < shadow_end_8; shadow_8++) {

mattweingarten wrote:

changed.


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


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

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

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


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

2024-06-24 Thread via lldb-commits

Author: Miro Bucko
Date: 2024-06-24T11:06:20-04:00
New Revision: 10bd5ad0a133fe73ffc1b05e63bc3fb2d56ba79c

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

LOG: [lldb][API] Add Find(Ranges)InMemory() to Process SB API (#95007)

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

llvm-project/lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py

Reviewers: clayborg

Tasks: lldb

Added: 
lldb/test/API/python_api/find_in_memory/Makefile
lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
lldb/test/API/python_api/find_in_memory/main.cpp

Modified: 
lldb/bindings/python/python-typemaps.swig
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Core/AddressRangeListImpl.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();

diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 

diff  --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..ceaf547ebddaf 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,11 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  virtual void DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+  const uint8_t *buf, size_t size,
+  AddressRanges , size_t alignment,
+  size_t max_matches);
+
   /// DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has
   /// removed non address bits from 

[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

Michael137 wrote:

Latest update LGTM

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


[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

labath wrote:

> Makes sense to me Do we make sure that the type lookup map is updated so we 
> don't re-parse when calling `ParseTypeFromDWARF` with either the declaration 
> or the definition DIE?

Good catch. I've been meaning to add that, but I forgot. Things should still 
work even without the DieToType update, as the type will be caught by the 
UniqueDWARFASTTypeMap, but this is definitely faster.

The way that the definition dies are currently handled is a bit clumsy now, but 
I didn't want to implement anything more elaborate as this should go away once 
we stop eagerly searching for the definition.

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


[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

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

>From 52db8db036c24264647340c15ec4ee6d3553cf60 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 24 Jun 2024 11:17:47 +0200
Subject: [PATCH 1/2] [lldb/DWARF] Remove parsing recursion when searching for
 definition DIEs

If ParseStructureLikeDIE (or ParseEnum) encountered a declaration DIE,
it would call FindDefinitionTypeForDIE. This returned a fully formed
type, which it achieved by recursing back into ParseStructureLikeDIE
with the definition DIE.

This obscured the control flow and caused us to repeat some work (e.g.
the UniqueDWARFASTTypeMap lookup), but it mostly worked until we tried
to delay the definition search in #90663. After this patch, the two
ParseStructureLikeDIE calls were no longer recursive, but rather
the second call happened as a part of the CompleteType() call. This
opened the door to inconsistencies, as the second ParseStructureLikeDIE
call was not aware it was called to process a definition die for an
existing type.

To make that possible, this patch removes the recusive type resolution
from this function, and leaves just the "find definition die"
functionality. After finding the definition DIE, we just go back to the
original ParseStructureLikeDIE call, and have it finish the parsing
process with the new DIE.

While this patch is motivated by the work on delaying the definition
searching, I believe it is also useful on its own.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 210 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 187 
 .../SymbolFile/DWARF/SymbolFileDWARF.h|   3 +-
 .../DWARF/SymbolFileDWARFDebugMap.cpp |  11 +-
 .../DWARF/SymbolFileDWARFDebugMap.h   |   2 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.cpp   |   5 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.h |   3 +-
 7 files changed, 208 insertions(+), 213 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 52f4d765cbbd4..ad58e0cbb5a59 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -39,10 +39,12 @@
 #include "lldb/Utility/StreamString.h"
 
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Type.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -835,54 +837,50 @@ DWARFASTParserClang::GetDIEClassTemplateParams(const 
DWARFDIE ) {
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext ,
-  const DWARFDIE ,
+  const DWARFDIE _die,
   ParsedDWARFTypeAttributes ) {
   Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  const dw_tag_t tag = die.Tag();
-  TypeSP type_sp;
+  SymbolFileDWARF *dwarf = decl_die.GetDWARF();
+  const dw_tag_t tag = decl_die.Tag();
 
+  DWARFDIE def_die;
   if (attrs.is_forward_declaration) {
-type_sp = ParseTypeFromClangModule(sc, die, log);
-if (type_sp)
+if (TypeSP type_sp = ParseTypeFromClangModule(sc, decl_die, log))
   return type_sp;
 
-type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
+def_die = dwarf->FindDefinitionDIE(decl_die);
 
-if (!type_sp) {
+if (!def_die) {
   SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
   if (debug_map_symfile) {
 // We weren't able to find a full declaration in this DWARF,
 // see if we have a declaration anywhere else...
-type_sp = 
debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
+def_die = debug_map_symfile->FindDefinitionDIE(decl_die);
   }
 }
 
-if (type_sp) {
-  if (log) {
-dwarf->GetObjectFile()->GetModule()->LogMessage(
-log,
-"SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \"{4}\" is a "
-"forward declaration, complete type is {5:x8}",
-static_cast(this), die.GetOffset(),
-DW_TAG_value_to_name(tag), tag, attrs.name.GetCString(),
-type_sp->GetID());
-  }
-
-  // We found a real definition for this type elsewhere so must link its
-  // DeclContext to this die.
-  if (clang::DeclContext *defn_decl_ctx =
-  GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID(
-LinkDeclContextToDIE(defn_decl_ctx, die);
-  return type_sp;
+if (log) {
+  dwarf->GetObjectFile()->GetModule()->LogMessage(
+  log,
+  "SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \"{4}\" is a "
+  "forward declaration, complete DIE is {5}",
+  static_cast(this), 

[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

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

Makes sense to me
Do we make sure that the type lookup map is updated so we don't re-parse when 
calling `ParseTypeFromDWARF` with either the declaration or the definition DIE?

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

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

labath wrote:

Hi there. Nice to see interest in this patch. Zequan has been OOO for the past 
couple of weeks, so I've sort of taken this up in the mean time.

The problem with the simplified template names is actually already fixed (by 
#95905), but in the mean time, I've discovered a very similar problem with type 
units (basically, just take the test case from #95905, but build it with 
-fdebug-types-section instead). While this could (and should) be fixed in 
similar way, this led me to believe that the overall approach in this patch was 
too fragile. When completing a type, it basically does something like:
- look up the (declaration) die for the type being completed (using the 
`ForwardDeclCompilerTypeToDIE` map)
- look up the definition die (using the dwarf index)
- look up the type for the definition die (using the UniqueDWARFASTTypeMap)

The last step, besides being completely unnecessary (we already know the type 
we're supposed to complete), is also a big liability, because here we are 
implicitly relying on the the map to return the same type that we started with. 
If it does not then we will end up creating a new type instead of completing 
the existing one, and things will quickly go sideways.

The meeting that David alluded to is tomorrow, and I hope we're going to try to 
figure out who's going to do what and in what order. In the mean time, I've 
added you as a reviewer to one of my pending patches.

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


[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

2024-06-24 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

If ParseStructureLikeDIE (or ParseEnum) encountered a declaration DIE, it would 
call FindDefinitionTypeForDIE. This returned a fully formed type, which it 
achieved by recursing back into ParseStructureLikeDIE with the definition DIE.

This obscured the control flow and caused us to repeat some work (e.g. the 
UniqueDWARFASTTypeMap lookup), but it mostly worked until we tried to delay the 
definition search in #90663. After this patch, the two 
ParseStructureLikeDIE calls were no longer recursive, but rather the second 
call happened as a part of the CompleteType() call. This opened the door to 
inconsistencies, as the second ParseStructureLikeDIE call was not aware it was 
called to process a definition die for an existing type.

To make that possible, this patch removes the recusive type resolution from 
this function, and leaves just the "find definition die" functionality. After 
finding the definition DIE, we just go back to the original 
ParseStructureLikeDIE call, and have it finish the parsing process with the new 
DIE.

While this patch is motivated by the work on delaying the definition searching, 
I believe it is also useful on its own.

---

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


7 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+107-103) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+91-96) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (+1-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp 
(+5-6) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h 
(+1-1) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp (+2-3) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h (+1-2) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 52f4d765cbbd4..ad58e0cbb5a59 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -39,10 +39,12 @@
 #include "lldb/Utility/StreamString.h"
 
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Type.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -835,54 +837,50 @@ DWARFASTParserClang::GetDIEClassTemplateParams(const 
DWARFDIE ) {
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext ,
-  const DWARFDIE ,
+  const DWARFDIE _die,
   ParsedDWARFTypeAttributes ) {
   Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  const dw_tag_t tag = die.Tag();
-  TypeSP type_sp;
+  SymbolFileDWARF *dwarf = decl_die.GetDWARF();
+  const dw_tag_t tag = decl_die.Tag();
 
+  DWARFDIE def_die;
   if (attrs.is_forward_declaration) {
-type_sp = ParseTypeFromClangModule(sc, die, log);
-if (type_sp)
+if (TypeSP type_sp = ParseTypeFromClangModule(sc, decl_die, log))
   return type_sp;
 
-type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
+def_die = dwarf->FindDefinitionDIE(decl_die);
 
-if (!type_sp) {
+if (!def_die) {
   SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
   if (debug_map_symfile) {
 // We weren't able to find a full declaration in this DWARF,
 // see if we have a declaration anywhere else...
-type_sp = 
debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(die);
+def_die = debug_map_symfile->FindDefinitionDIE(decl_die);
   }
 }
 
-if (type_sp) {
-  if (log) {
-dwarf->GetObjectFile()->GetModule()->LogMessage(
-log,
-"SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \"{4}\" is a "
-"forward declaration, complete type is {5:x8}",
-static_cast(this), die.GetOffset(),
-DW_TAG_value_to_name(tag), tag, attrs.name.GetCString(),
-type_sp->GetID());
-  }
-
-  // We found a real definition for this type elsewhere so must link its
-  // DeclContext to this die.
-  if (clang::DeclContext *defn_decl_ctx =
-  GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID(
-LinkDeclContextToDIE(defn_decl_ctx, die);
-  return type_sp;
+if (log) {
+  dwarf->GetObjectFile()->GetModule()->LogMessage(
+  log,
+  "SymbolFileDWARF({0:p}) - {1:x16}}: {2} ({3}) type \"{4}\" is a "
+  "forward declaration, complete DIE is 

[Lldb-commits] [lldb] [lldb/DWARF] Remove parsing recursion when searching for definition DIEs (PR #96484)

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

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

If ParseStructureLikeDIE (or ParseEnum) encountered a declaration DIE, it would 
call FindDefinitionTypeForDIE. This returned a fully formed type, which it 
achieved by recursing back into ParseStructureLikeDIE with the definition DIE.

This obscured the control flow and caused us to repeat some work (e.g. the 
UniqueDWARFASTTypeMap lookup), but it mostly worked until we tried to delay the 
definition search in #90663. After this patch, the two ParseStructureLikeDIE 
calls were no longer recursive, but rather the second call happened as a part 
of the CompleteType() call. This opened the door to inconsistencies, as the 
second ParseStructureLikeDIE call was not aware it was called to process a 
definition die for an existing type.

To make that possible, this patch removes the recusive type resolution from 
this function, and leaves just the "find definition die" functionality. After 
finding the definition DIE, we just go back to the original 
ParseStructureLikeDIE call, and have it finish the parsing process with the new 
DIE.

While this patch is motivated by the work on delaying the definition searching, 
I believe it is also useful on its own.

>From 52db8db036c24264647340c15ec4ee6d3553cf60 Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 24 Jun 2024 11:17:47 +0200
Subject: [PATCH] [lldb/DWARF] Remove parsing recursion when searching for
 definition DIEs

If ParseStructureLikeDIE (or ParseEnum) encountered a declaration DIE,
it would call FindDefinitionTypeForDIE. This returned a fully formed
type, which it achieved by recursing back into ParseStructureLikeDIE
with the definition DIE.

This obscured the control flow and caused us to repeat some work (e.g.
the UniqueDWARFASTTypeMap lookup), but it mostly worked until we tried
to delay the definition search in #90663. After this patch, the two
ParseStructureLikeDIE calls were no longer recursive, but rather
the second call happened as a part of the CompleteType() call. This
opened the door to inconsistencies, as the second ParseStructureLikeDIE
call was not aware it was called to process a definition die for an
existing type.

To make that possible, this patch removes the recusive type resolution
from this function, and leaves just the "find definition die"
functionality. After finding the definition DIE, we just go back to the
original ParseStructureLikeDIE call, and have it finish the parsing
process with the new DIE.

While this patch is motivated by the work on delaying the definition
searching, I believe it is also useful on its own.
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 210 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 187 
 .../SymbolFile/DWARF/SymbolFileDWARF.h|   3 +-
 .../DWARF/SymbolFileDWARFDebugMap.cpp |  11 +-
 .../DWARF/SymbolFileDWARFDebugMap.h   |   2 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.cpp   |   5 +-
 .../SymbolFile/DWARF/SymbolFileDWARFDwo.h |   3 +-
 7 files changed, 208 insertions(+), 213 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 52f4d765cbbd4..ad58e0cbb5a59 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -39,10 +39,12 @@
 #include "lldb/Utility/StreamString.h"
 
 #include "clang/AST/CXXInheritance.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Type.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -835,54 +837,50 @@ DWARFASTParserClang::GetDIEClassTemplateParams(const 
DWARFDIE ) {
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext ,
-  const DWARFDIE ,
+  const DWARFDIE _die,
   ParsedDWARFTypeAttributes ) {
   Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
-  SymbolFileDWARF *dwarf = die.GetDWARF();
-  const dw_tag_t tag = die.Tag();
-  TypeSP type_sp;
+  SymbolFileDWARF *dwarf = decl_die.GetDWARF();
+  const dw_tag_t tag = decl_die.Tag();
 
+  DWARFDIE def_die;
   if (attrs.is_forward_declaration) {
-type_sp = ParseTypeFromClangModule(sc, die, log);
-if (type_sp)
+if (TypeSP type_sp = ParseTypeFromClangModule(sc, decl_die, log))
   return type_sp;
 
-type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die);
+def_die = dwarf->FindDefinitionDIE(decl_die);
 
-if (!type_sp) {
+if (!def_die) {
   SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
   if (debug_map_symfile) {
 // We weren't able to find a full declaration in this DWARF,
 // see if we have a declaration anywhere 

[Lldb-commits] [lldb] c053ec9 - [lldb] Fix TestDAP_runInTerminal for #96256

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

Author: Pavel Labath
Date: 2024-06-24T14:16:24+02:00
New Revision: c053ec95f7e66ff212c8a867426cc7275a4dace6

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

LOG: [lldb] Fix TestDAP_runInTerminal for #96256

change the expected error msg.

Added: 


Modified: 
lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py 
b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
index 9fcd210122d54..b214b512c0de3 100644
--- a/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
+++ b/lldb/test/API/tools/lldb-dap/runInTerminal/TestDAP_runInTerminal.py
@@ -105,7 +105,7 @@ def test_runInTerminalInvalidTarget(self):
 )
 self.assertFalse(response["success"])
 self.assertIn(
-"Could not create a target for a program 'INVALIDPROGRAM': unable 
to find executable",
+"Could not create a target for a program 'INVALIDPROGRAM': 
'INVALIDPROGRAM' does not exist",
 response["message"],
 )
 



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


[Lldb-commits] [lldb] [lldb/DWARF] Optimize DIEToType handling (PR #96308)

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

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


[Lldb-commits] [lldb] 41a4db1 - [lldb/DWARF] Optimize DIEToType handling (#96308)

2024-06-24 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-06-24T13:35:16+02:00
New Revision: 41a4db1ba6591169069dd2352e00364d9113fbeb

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

LOG: [lldb/DWARF] Optimize DIEToType handling (#96308)

- move type insertion from individual parse methods into
ParseTypeFromDWARF
- optimize sentinel (TYPE_IS_BEING_PARSED) insertion to avoid double map
lookup
- as this requires the map to not have nullptr values, I've replaced all
`operator[]` queries with calls to `lookup`.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index ae3eaf88ff4a8..52f4d765cbbd4 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -223,7 +223,6 @@ TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const 
SymbolContext ,
   nullptr, LLDB_INVALID_UID, Type::eEncodingInvalid,
   _type_sp->GetDeclaration(), type, Type::ResolveState::Forward,
   TypePayloadClang(GetOwningClangModule(die)));
-  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
   clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl(type);
   if (tag_decl) {
 LinkDeclContextToDIE(tag_decl, die);
@@ -458,90 +457,78 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext ,
 DW_TAG_value_to_name(die.Tag()), die.Tag(), die.GetName());
   }
 
-  Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE());
-  if (type_ptr == DIE_IS_BEING_PARSED)
-return nullptr;
-  if (type_ptr)
-return type_ptr->shared_from_this();
   // Set a bit that lets us know that we are currently parsing this
-  dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
+  if (auto [it, inserted] =
+  dwarf->GetDIEToType().try_emplace(die.GetDIE(), DIE_IS_BEING_PARSED);
+  !inserted) {
+if (it->getSecond() == nullptr || it->getSecond() == DIE_IS_BEING_PARSED)
+  return nullptr;
+return it->getSecond()->shared_from_this();
+  }
 
   ParsedDWARFTypeAttributes attrs(die);
 
+  TypeSP type_sp;
   if (DWARFDIE signature_die = attrs.signature.Reference()) {
-if (TypeSP type_sp =
-ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) {
-  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
+type_sp = ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr);
+if (type_sp) {
   if (clang::DeclContext *decl_ctx =
   GetCachedClangDeclContextForDIE(signature_die))
 LinkDeclContextToDIE(decl_ctx, die);
-  return type_sp;
 }
-return nullptr;
-  }
-
-  if (type_is_new_ptr)
-*type_is_new_ptr = true;
-
-  const dw_tag_t tag = die.Tag();
-
-  TypeSP type_sp;
-
-  switch (tag) {
-  case DW_TAG_typedef:
-  case DW_TAG_base_type:
-  case DW_TAG_pointer_type:
-  case DW_TAG_reference_type:
-  case DW_TAG_rvalue_reference_type:
-  case DW_TAG_const_type:
-  case DW_TAG_restrict_type:
-  case DW_TAG_volatile_type:
-  case DW_TAG_LLVM_ptrauth_type:
-  case DW_TAG_atomic_type:
-  case DW_TAG_unspecified_type: {
-type_sp = ParseTypeModifier(sc, die, attrs);
-break;
-  }
-
-  case DW_TAG_structure_type:
-  case DW_TAG_union_type:
-  case DW_TAG_class_type: {
-type_sp = ParseStructureLikeDIE(sc, die, attrs);
-break;
-  }
+  } else {
+if (type_is_new_ptr)
+  *type_is_new_ptr = true;
 
-  case DW_TAG_enumeration_type: {
-type_sp = ParseEnum(sc, die, attrs);
-break;
-  }
+const dw_tag_t tag = die.Tag();
 
-  case DW_TAG_inlined_subroutine:
-  case DW_TAG_subprogram:
-  case DW_TAG_subroutine_type: {
-type_sp = ParseSubroutine(die, attrs);
-break;
-  }
-  case DW_TAG_array_type: {
-type_sp = ParseArrayType(die, attrs);
-break;
-  }
-  case DW_TAG_ptr_to_member_type: {
-type_sp = ParsePointerToMemberType(die, attrs);
-break;
+switch (tag) {
+case DW_TAG_typedef:
+case DW_TAG_base_type:
+case DW_TAG_pointer_type:
+case DW_TAG_reference_type:
+case DW_TAG_rvalue_reference_type:
+case DW_TAG_const_type:
+case DW_TAG_restrict_type:
+case DW_TAG_volatile_type:
+case DW_TAG_LLVM_ptrauth_type:
+case DW_TAG_atomic_type:
+case DW_TAG_unspecified_type:
+  type_sp = ParseTypeModifier(sc, die, attrs);
+  break;
+case DW_TAG_structure_type:
+case DW_TAG_union_type:
+case DW_TAG_class_type:
+  type_sp = ParseStructureLikeDIE(sc, die, attrs);
+  break;
+case DW_TAG_enumeration_type:
+  type_sp = ParseEnum(sc, die, attrs);
+  break;
+case DW_TAG_inlined_subroutine:
+case DW_TAG_subprogram:
+case DW_TAG_subroutine_type:
+  type_sp 

[Lldb-commits] [lldb] [lldb] Change lldb's breakpoint handling behavior (PR #96260)

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

AlexK0 wrote:

> Anyway, tl;dr, I believe this will fix it:
> 
> ```
> --- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
> +++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
> @@ -442,6 +442,7 @@ void ProcessWindows::RefreshStateAfterStop() {
> m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
> site->GetID());
>  
> +  stop_thread->SetThreadHitBreakpointAtAddr(pc);
>if (site->ValidForThisThread(*stop_thread)) {
>  LLDB_LOG(log,
>   "Breakpoint site {0} is valid for this thread ({1:x}), "
> ```
> 
> I'll push it right now. Sorry for my confusion, and thanks again for looking 
> at it, this was a big help.

@jasonmolenda unfortunately, the test still fails :(
I did a little investigation, here is a possible patch that fixes the test:

```
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 231b22f5f189..fb0404f1c4b9 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -382,7 +382,7 @@ void ProcessWindows::RefreshStateAfterStop() {
 RegisterContextSP register_context = stop_thread->GetRegisterContext();
 const uint64_t pc = register_context->GetPC();
 BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
-if (site)
+if (site && site->ValidForThisThread(*stop_thread))
   stop_thread->SetThreadStoppedAtBreakpointSite(pc);
 auto *reg_ctx = static_cast(
 stop_thread->GetRegisterContext().get());
```




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


[Lldb-commits] [lldb] [lldb/DWARF] Optimize DIEToType handling (PR #96308)

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

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

Nice, this is much more understandable, thanks!

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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


@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")"
+   | dynamic_cast "<" type_id ">" "(" expression ")"
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;

Michael137 wrote:

Wouldn't `C-style` casts suffice?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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


@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")"
+   | dynamic_cast "<" type_id ">" "(" expression ")"
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  | "bool"
+  | "short"
+  | "int"
+  | "long"
+  | "signed"
+  | "unsigned"
+  | "float"
+  | "double"
+  | "void" ;
+
+nested_name_specifier = type_name "::"
+  | namespace_name '::'
+  | nested_name_specifier identifier "::"
+  | nested_name_specifier simple_template_id "::";
+
+type_name = class_name
+  | enum_name
+  | typedef_name
+  | simple_template_id ;
+
+class_name = identifier ;
+
+enum_name = identifier ;
+
+typedef_name = identifier ;
+
+simple_template_id = template_name "<" [template_argument_list] ">" ;

Michael137 wrote:

Also how will this be implemented? I guess the simple-template-names 
infrastructure could help here?
AFAIU in the expression evaluator templates would ideally be supported by 
either using modules or extending DWARF in a way that allows us to construct 
more faithful ASTs.

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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


@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")"
+   | dynamic_cast "<" type_id ">" "(" expression ")"
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  | "bool"
+  | "short"
+  | "int"
+  | "long"
+  | "signed"
+  | "unsigned"
+  | "float"
+  | "double"
+  | "void" ;
+
+nested_name_specifier = type_name "::"
+  | namespace_name '::'
+  | nested_name_specifier identifier "::"
+  | nested_name_specifier simple_template_id "::";
+
+type_name = class_name
+  | enum_name
+  | typedef_name
+  | simple_template_id ;
+
+class_name = identifier ;
+
+enum_name = identifier ;
+
+typedef_name = identifier ;
+
+simple_template_id = template_name "<" [template_argument_list] ">" ;

Michael137 wrote:

Curious what the use-case for instantiating templates is in the DIL. I guess 
referencing static data members of different instantiations?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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


@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")"
+   | dynamic_cast "<" type_id ">" "(" expression ")"
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  | "bool"
+  | "short"
+  | "int"
+  | "long"
+  | "signed"
+  | "unsigned"
+  | "float"
+  | "double"
+  | "void" ;
+
+nested_name_specifier = type_name "::"
+  | namespace_name '::'
+  | nested_name_specifier identifier "::"
+  | nested_name_specifier simple_template_id "::";
+
+type_name = class_name
+  | enum_name
+  | typedef_name
+  | simple_template_id ;
+
+class_name = identifier ;
+
+enum_name = identifier ;
+
+typedef_name = identifier ;
+
+simple_template_id = template_name "<" [template_argument_list] ">" ;
+
+template_name = identifier ;
+
+template_argument_list = template_argument
+   | template_argument_list "," template_argument ;
+
+template_argument = type_id
+  | numeric_literal
+  | id_expression ;
+
+namespace_name = identifier ;
+
+cv_qualifier = "const" | "volatile" ;
+
+cv_qualifier_seq = cv_qualifier [cv_qualifier_seq] ;
+
+abstract_declarator = ptr_operator [abstract_declarator] ;
+
+ptr_operator = "*" [cv_qualifier_seq]
+ | "&" ;
+

[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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

https://github.com/Michael137 commented:

Haven't gone through this in detail yet (having an example of how these 
structures will be used would be helpful), but something I was curious about is 
whether this `DIL` is going to be used in the implementation of a new command, 
or if we're going to extend the `frame var` language? I didn't see a concrete 
conclusion on this in the RFC

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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


@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression

Michael137 wrote:

Do we really want to allow state-changing expressions in the `frame var` 
language?

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


[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

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

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


[Lldb-commits] [lldb] 599ca71 - [lldb] Merge CompilerContextKind::{Class, Struct} (#96145)

2024-06-24 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-06-24T08:56:21+02:00
New Revision: 599ca7165edcf7d226bd658c450801044b46ce7c

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

LOG: [lldb] Merge CompilerContextKind::{Class,Struct} (#96145)

Our dwarf parsing code treats structures and classes as interchangable.
CompilerContextKind is used when looking DIEs for types. This makes sure
we always they're treated the same way.

See also
[#95905#discussion_r1645686628](https://github.com/llvm/llvm-project/pull/95905#discussion_r1645686628).

Added: 


Modified: 
lldb/include/lldb/lldb-private-enumerations.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Symbol/Type.cpp
lldb/test/Shell/SymbolFile/DWARF/clang-gmodules-type-lookup.c
lldb/test/Shell/SymbolFile/DWARF/x86/compilercontext.ll
lldb/test/Shell/SymbolFile/DWARF/x86/find-basic-function.cpp
lldb/test/Shell/SymbolFile/DWARF/x86/module-ownership.mm
lldb/tools/lldb-test/lldb-test.cpp
lldb/unittests/Symbol/TestType.cpp
lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp

Removed: 




diff  --git a/lldb/include/lldb/lldb-private-enumerations.h 
b/lldb/include/lldb/lldb-private-enumerations.h
index 68e060f2393f7..9d18316dcea25 100644
--- a/lldb/include/lldb/lldb-private-enumerations.h
+++ b/lldb/include/lldb/lldb-private-enumerations.h
@@ -10,6 +10,7 @@
 #define LLDB_LLDB_PRIVATE_ENUMERATIONS_H
 
 #include "lldb/lldb-enumerations.h"
+#include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/raw_ostream.h"
@@ -197,8 +198,7 @@ enum class CompilerContextKind : uint16_t {
   TranslationUnit = 1,
   Module = 1 << 1,
   Namespace = 1 << 2,
-  Class = 1 << 3,
-  Struct = 1 << 4,
+  ClassOrStruct = 1 << 3,
   Union = 1 << 5,
   Function = 1 << 6,
   Variable = 1 << 7,
@@ -210,10 +210,12 @@ enum class CompilerContextKind : uint16_t {
   /// Match 0..n nested modules.
   AnyModule = Any | Module,
   /// Match any type.
-  AnyType = Any | Class | Struct | Union | Enum | Typedef | Builtin,
+  AnyType = Any | ClassOrStruct | Union | Enum | Typedef | Builtin,
   /// Math any declaration context.
-  AnyDeclContext = Any | Namespace | Class | Struct | Union | Enum | Function
+  AnyDeclContext = Any | Namespace | ClassOrStruct | Union | Enum | Function,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/AnyDeclContext),
 };
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 
 // Enumerations that can be used to specify the kind of metric we're looking at
 // when collecting stats.

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
index ada3da85112fe..fb32e2adeb3fe 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -394,15 +394,13 @@ static void GetDeclContextImpl(DWARFDIE die,
 case DW_TAG_namespace:
   push_ctx(CompilerContextKind::Namespace, die.GetName());
   break;
+case DW_TAG_class_type:
 case DW_TAG_structure_type:
-  push_ctx(CompilerContextKind::Struct, die.GetName());
+  push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
   break;
 case DW_TAG_union_type:
   push_ctx(CompilerContextKind::Union, die.GetName());
   break;
-case DW_TAG_class_type:
-  push_ctx(CompilerContextKind::Class, die.GetName());
-  break;
 case DW_TAG_enumeration_type:
   push_ctx(CompilerContextKind::Enum, die.GetName());
   break;
@@ -456,15 +454,13 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
 case DW_TAG_namespace:
   push_ctx(CompilerContextKind::Namespace, die.GetName());
   break;
+case DW_TAG_class_type:
 case DW_TAG_structure_type:
-  push_ctx(CompilerContextKind::Struct, die.GetName());
+  push_ctx(CompilerContextKind::ClassOrStruct, die.GetName());
   break;
 case DW_TAG_union_type:
   push_ctx(CompilerContextKind::Union, die.GetName());
   break;
-case DW_TAG_class_type:
-  push_ctx(CompilerContextKind::Class, die.GetName());
-  break;
 case DW_TAG_enumeration_type:
   push_ctx(CompilerContextKind::Enum, die.GetName());
   break;

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index eb7f6232ac981..cd1c500d9aa29 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -9173,10 +9173,8 @@ static CompilerContextKind 
GetCompilerKind(clang::Decl::Kind clang_kind,
 if (decl_ctx) {
   if (decl_ctx->isFunctionOrMethod())
 return 

[Lldb-commits] [lldb] [lldb] Merge CompilerContextKind::{Class, Struct} (PR #96145)

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

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


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

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

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


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


[Lldb-commits] [lldb] [lldb] fix(lldb/**.py): fix invalid escape sequences (PR #94034)

2024-06-23 Thread Eisuke Kawashima via lldb-commits

https://github.com/e-kwsm updated 
https://github.com/llvm/llvm-project/pull/94034

>From 0fed01ab57c06cf3b601539a4a9259973eb5031d Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima 
Date: Sat, 11 May 2024 02:39:21 +0900
Subject: [PATCH] fix(lldb/**.py): fix invalid escape sequences

---
 lldb/examples/python/crashlog.py  |   8 +-
 lldb/examples/python/delta.py |   2 +-
 lldb/examples/python/gdbremote.py |   4 +-
 lldb/examples/python/jump.py  |   6 +-
 lldb/examples/python/performance.py   |   2 +-
 lldb/examples/python/symbolication.py |   6 +-
 .../Python/lldbsuite/test/lldbpexpect.py  |   2 +-
 .../test/test_runner/process_control.py   |   2 +-
 .../command/backticks/TestBackticksInAlias.py |   4 +-
 .../TestMemoryAllocSettings.py|   2 +-
 .../API/commands/expression/test/TestExprs.py |   2 +-
 .../TestGuiExpandThreadsTree.py   |   2 +-
 lldb/test/API/commands/help/TestHelp.py   |   6 +-
 .../TestLaunchWithShellExpand.py  |   2 +-
 .../register/TestRegistersUnavailable.py  |   4 +-
 .../API/commands/settings/TestSettings.py |  12 +-
 .../target/basic/TestTargetCommand.py |   2 +-
 .../dwo/TestDumpDwo.py|  16 +-
 .../oso/TestDumpOso.py|  16 +-
 .../API/commands/trace/TestTraceDumpInfo.py   |   2 +-
 .../API/commands/trace/TestTraceEvents.py |   4 +-
 .../API/commands/trace/TestTraceStartStop.py  |  12 +-
 lldb/test/API/commands/trace/TestTraceTSC.py  |  10 +-
 .../driver/quit_speed/TestQuitWithProcess.py  |   2 +-
 .../TestBreakpointByLineAndColumn.py  |   2 +-
 .../TestBreakpointLocations.py|   2 +-
 .../TestDataFormatterAdv.py   |   6 +-
 .../TestDataFormatterCpp.py   |   6 +-
 .../TestDataFormatterObjCNSContainer.py   |  16 +-
 .../TestDataFormatterSkipSummary.py   |   2 +-
 .../TestDataFormatterGenericUnordered.py  |  22 +--
 .../libcxx/atomic/TestLibCxxAtomic.py |   2 +-
 .../initializerlist/TestInitializerList.py|   2 +-
 .../TestTypeSummaryListArg.py |   4 +-
 .../memory-region/TestMemoryRegion.py |   2 +-
 .../target_var/TestTargetVar.py   |   2 +-
 .../completion/TestIOHandlerCompletion.py |   2 +-
 .../c/function_types/TestFunctionTypes.py |   2 +-
 .../TestRegisterVariables.py  |   2 +-
 .../API/lang/c/set_values/TestSetValues.py|   4 +-
 lldb/test/API/lang/c/strings/TestCStrings.py  |   2 +-
 .../API/lang/c/tls_globals/TestTlsGlobals.py  |   8 +-
 .../API/lang/cpp/char1632_t/TestChar1632T.py  |   8 +-
 .../cpp/class_static/TestStaticVariables.py   |   4 +-
 .../lang/cpp/class_types/TestClassTypes.py|   2 +-
 .../cpp/dynamic-value/TestDynamicValue.py |   2 +-
 .../API/lang/cpp/namespace/TestNamespace.py   |   4 +-
 .../lang/cpp/signed_types/TestSignedTypes.py  |   4 +-
 .../cpp/unsigned_types/TestUnsignedTypes.py   |   2 +-
 .../test/API/lang/mixed/TestMixedLanguages.py |   4 +-
 .../lang/objc/foundation/TestObjCMethods.py   |   2 +-
 .../objc/foundation/TestObjCMethodsNSArray.py |  10 +-
 .../objc/foundation/TestObjCMethodsNSError.py |   2 +-
 .../objc/foundation/TestObjCMethodsString.py  |  10 +-
 .../TestObjCDynamicValue.py   |   2 +-
 .../TestObjCBuiltinTypes.py   |   4 +-
 .../TestAArch64LinuxMTEMemoryTagCoreFile.py   |  44 ++---
 .../TestAArch64LinuxMTEMemoryTagAccess.py | 160 +-
 .../TestAArch64LinuxMTEMemoryTagFaults.py |   6 +-
 .../TestAArch64LinuxTaggedMemoryRegion.py |   4 +-
 .../macosx/add-dsym/TestAddDsymDownload.py|   2 +-
 .../TestFirmwareCorefiles.py  |   2 +-
 .../kern-ver-str/TestKernVerStrLCNOTE.py  |   2 +-
 .../TestMultipleBinaryCorefile.py |   2 +-
 .../macosx/simulator/TestSimulatorPlatform.py |   2 +-
 .../skinny-corefile/TestSkinnyCorefile.py |   2 +-
 .../TestTargetArchFromModule.py   |   2 +-
 .../API/source-manager/TestSourceManager.py   |   2 +-
 .../lldb-server/TestGdbRemoteModuleInfo.py|   6 +-
 .../API/tools/lldb-server/TestPtyServer.py|   2 +-
 .../TestGdbRemoteTargetXmlPacket.py   |   2 +-
 lldb/test/API/types/AbstractBase.py   |   6 +-
 lldb/utils/lui/sourcewin.py   |   2 +-
 73 files changed, 263 insertions(+), 263 deletions(-)

diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 1c0d717ce455c..2db9857006b0a 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -296,7 +296,7 @@ class DarwinImage(symbolication.Image):
 except:
 dsymForUUIDBinary = ""
 
-dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) 
.*")
+dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) 
.*")
 
 def __init__(
 self, 

[Lldb-commits] [lldb] [lldb] fix(lldb/**.py): fix comparison to True/False (PR #94039)

2024-06-23 Thread Eisuke Kawashima via lldb-commits

https://github.com/e-kwsm updated 
https://github.com/llvm/llvm-project/pull/94039

>From f0db39bec2499964d0af619148c453d526b6fde4 Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima 
Date: Sun, 12 May 2024 00:06:53 +0900
Subject: [PATCH] fix(lldb/**.py): fix comparison to True/False

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
---
 lldb/examples/python/crashlog.py| 2 +-
 lldb/examples/python/disasm-stress-test.py  | 4 ++--
 lldb/examples/summaries/cocoa/CFString.py   | 6 +++---
 lldb/examples/summaries/pysummary.py| 2 +-
 lldb/examples/synthetic/bitfield/example.py | 2 +-
 lldb/packages/Python/lldbsuite/test/lldbtest.py | 2 +-
 lldb/test/API/commands/command/script/welcome.py| 2 +-
 .../commands/expression/call-throws/TestCallThatThrows.py   | 6 +++---
 .../disassemble/aarch64-adrp-add/TestAArch64AdrpAdd.py  | 2 +-
 .../gdb_remote_client/TestNoWatchpointSupportInfo.py| 2 +-
 lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py | 2 +-
 lldb/test/API/tools/lldb-server/TestLldbGdbServer.py| 2 +-
 12 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 1c0d717ce455c..368437ed63e46 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -166,7 +166,7 @@ def dump_symbolicated(self, crash_log, options):
 this_thread_crashed = self.app_specific_backtrace
 if not this_thread_crashed:
 this_thread_crashed = self.did_crash()
-if options.crashed_only and this_thread_crashed == False:
+if options.crashed_only and not this_thread_crashed:
 return
 
 print("%s" % self)
diff --git a/lldb/examples/python/disasm-stress-test.py 
b/lldb/examples/python/disasm-stress-test.py
index 2d3314ee8e8ff..62b2b90a2860a 100755
--- a/lldb/examples/python/disasm-stress-test.py
+++ b/lldb/examples/python/disasm-stress-test.py
@@ -95,13 +95,13 @@ def GetLLDBFrameworkPath():
 
 debugger = lldb.SBDebugger.Create()
 
-if debugger.IsValid() == False:
+if not debugger.IsValid():
 print("Couldn't create an SBDebugger")
 sys.exit(-1)
 
 target = debugger.CreateTargetWithFileAndArch(None, arg_ns.arch)
 
-if target.IsValid() == False:
+if not target.IsValid():
 print("Couldn't create an SBTarget for architecture " + arg_ns.arch)
 sys.exit(-1)
 
diff --git a/lldb/examples/summaries/cocoa/CFString.py 
b/lldb/examples/summaries/cocoa/CFString.py
index 13c294ca34122..74bd927e9db21 100644
--- a/lldb/examples/summaries/cocoa/CFString.py
+++ b/lldb/examples/summaries/cocoa/CFString.py
@@ -253,9 +253,9 @@ def get_child_at_index(self, index):
 elif (
 self.inline
 and self.explicit
-and self.unicode == False
-and self.special == False
-and self.mutable == False
+and not self.unicode
+and not self.special
+and not self.mutable
 ):
 return self.handle_inline_explicit()
 elif self.unicode:
diff --git a/lldb/examples/summaries/pysummary.py 
b/lldb/examples/summaries/pysummary.py
index e63a0bff56a13..2a05c1cbf8f28 100644
--- a/lldb/examples/summaries/pysummary.py
+++ b/lldb/examples/summaries/pysummary.py
@@ -2,7 +2,7 @@
 
 
 def pyobj_summary(value, unused):
-if value is None or value.IsValid() == False or 
value.GetValueAsUnsigned(0) == 0:
+if value is None or not value.IsValid() or value.GetValueAsUnsigned(0) == 
0:
 return ""
 refcnt = value.GetChildMemberWithName("ob_refcnt")
 expr = "(char*)PyString_AsString( (PyObject*)PyObject_Str( 
(PyObject*)0x%x) )" % (
diff --git a/lldb/examples/synthetic/bitfield/example.py 
b/lldb/examples/synthetic/bitfield/example.py
index 2f58123268aa1..45416477bfef2 100644
--- a/lldb/examples/synthetic/bitfield/example.py
+++ b/lldb/examples/synthetic/bitfield/example.py
@@ -51,7 +51,7 @@ def get_child_at_index(self, index):
 return None
 if index > self.num_children():
 return None
-if self.valobj.IsValid() == False:
+if not self.valobj.IsValid():
 return None
 if index == 0:
 return self.valobj.GetChildMemberWithName("value")
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py 
b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 1ad8ab6e6e462..1854f6c2c2e7b 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2446,7 +2446,7 @@ def found_str(matched):
 log_lines.append(pattern_line)
 
 # Convert to bool because match 

[Lldb-commits] [lldb] [lldb] fix(lldb/**.py): fix comparison to None (PR #94017)

2024-06-23 Thread Eisuke Kawashima via lldb-commits

https://github.com/e-kwsm updated 
https://github.com/llvm/llvm-project/pull/94017

>From a10dbbe288bdb115df56ef60c48f9efbf6642bd3 Mon Sep 17 00:00:00 2001
From: Eisuke Kawashima 
Date: Sat, 11 May 2024 23:57:11 +0900
Subject: [PATCH] fix(lldb/**.py): fix comparison to None

from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or
> is not, never the equality operators.
---
 lldb/bindings/interface/SBBreakpointDocstrings.i  | 2 +-
 lldb/bindings/interface/SBDataExtensions.i| 8 
 lldb/docs/use/python.rst  | 4 ++--
 lldb/examples/python/armv7_cortex_m_target_defintion.py   | 2 +-
 lldb/packages/Python/lldbsuite/test/dotest.py | 2 +-
 lldb/packages/Python/lldbsuite/test/lldbtest.py   | 6 +++---
 lldb/packages/Python/lldbsuite/test/lldbutil.py   | 6 +++---
 .../lldbsuite/test/tools/intelpt/intelpt_testcase.py  | 2 +-
 .../address_breakpoints/TestBadAddressBreakpoints.py  | 2 +-
 .../API/functionalities/step_scripted/TestStepScripted.py | 2 +-
 .../TestStopOnSharedlibraryEvents.py  | 2 +-
 lldb/test/API/lua_api/TestLuaAPI.py   | 2 +-
 .../macosx/thread_suspend/TestInternalThreadSuspension.py | 2 +-
 lldb/test/API/python_api/event/TestEvents.py  | 2 +-
 .../process/read-mem-cstring/TestReadMemCString.py| 2 +-
 lldb/test/API/python_api/type/TestTypeList.py | 2 +-
 lldb/test/API/python_api/was_interrupted/interruptible.py | 2 +-
 lldb/test/Shell/lit.cfg.py| 2 +-
 18 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/lldb/bindings/interface/SBBreakpointDocstrings.i 
b/lldb/bindings/interface/SBBreakpointDocstrings.i
index 74c139d5d9fb6..dca2819a9927b 100644
--- a/lldb/bindings/interface/SBBreakpointDocstrings.i
+++ b/lldb/bindings/interface/SBBreakpointDocstrings.i
@@ -39,7 +39,7 @@ TestBreakpointIgnoreCount.py),::
 #lldbutil.print_stacktraces(process)
 from lldbutil import get_stopped_thread
 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
-self.assertTrue(thread != None, 'There should be a thread stopped due 
to breakpoint')
+self.assertTrue(thread is not None, 'There should be a thread stopped 
due to breakpoint')
 frame0 = thread.GetFrameAtIndex(0)
 frame1 = thread.GetFrameAtIndex(1)
 frame2 = thread.GetFrameAtIndex(2)
diff --git a/lldb/bindings/interface/SBDataExtensions.i 
b/lldb/bindings/interface/SBDataExtensions.i
index d980e79221c6d..ddea77a088dfa 100644
--- a/lldb/bindings/interface/SBDataExtensions.i
+++ b/lldb/bindings/interface/SBDataExtensions.i
@@ -40,19 +40,19 @@ STRING_EXTENSION_OUTSIDE(SBData)
 lldbtarget = lldbdict['target']
 else:
 lldbtarget = None
-if target == None and lldbtarget != None and lldbtarget.IsValid():
+if target is None and lldbtarget is not None and 
lldbtarget.IsValid():
 target = lldbtarget
-if ptr_size == None:
+if ptr_size is None:
 if target and target.IsValid():
 ptr_size = target.addr_size
 else:
 ptr_size = 8
-if endian == None:
+if endian is None:
 if target and target.IsValid():
 endian = target.byte_order
 else:
 endian = lldbdict['eByteOrderLittle']
-if size == None:
+if size is None:
 if value > 2147483647:
 size = 8
 elif value < -2147483648:
diff --git a/lldb/docs/use/python.rst b/lldb/docs/use/python.rst
index 6183d6935d80e..d9c29d95708c1 100644
--- a/lldb/docs/use/python.rst
+++ b/lldb/docs/use/python.rst
@@ -75,13 +75,13 @@ later explanations:
12: if root_word == word:
13: return cur_path
14: elif word < root_word:
-   15: if left_child_ptr.GetValue() == None:
+   15: if left_child_ptr.GetValue() is None:
16: return ""
17: else:
18: cur_path = cur_path + "L"
19: return DFS (left_child_ptr, word, cur_path)
20: else:
-   21: if right_child_ptr.GetValue() == None:
+   21: if right_child_ptr.GetValue() is None:
22: return ""
23: else:
24: cur_path = cur_path + "R"
diff --git a/lldb/examples/python/armv7_cortex_m_target_defintion.py 
b/lldb/examples/python/armv7_cortex_m_target_defintion.py
index 42eaa39993dae..8225670f33e6b 100755
--- a/lldb/examples/python/armv7_cortex_m_target_defintion.py
+++ b/lldb/examples/python/armv7_cortex_m_target_defintion.py
@@ -222,7 +222,7 @@ def get_reg_num(reg_num_dict, reg_name):
 
 def get_target_definition():
 global 

[Lldb-commits] [clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

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

Michael137 wrote:

> It's not that hard to compute "no-data": non-RecordDecls are never no-data, 
> RecordDecls are no-data if they don't have a vtable pointer 
> (isDynamicClass()), and all fields are no-data. We can save it in the 
> CGRecordLayout.
> 
> Assuming that's the route we want to go, of course, as opposed to just making 
> LLDB add no_unique_address markings to fields.

Turns out there's `CodeGen::isEmptyField` which seems usable for this purpose. 
Created a draft PR here: https://github.com/llvm/llvm-project/pull/96422 for now

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


[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

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

dwblaikie wrote:

> @ZequanWu, @labath, since this PR got reverted due to crash for 
> `--gsimple-template-names`, do you guys have a timeline to revise a new 
> version without crashing? I ask this because our internal customers have many 
> forward declarations that are suffering from the slow definition lookup. cc 
> @clayborg

It's certainly stuff that @ZequanWu, @labath, and myself are looking into. We 
could do a better job of communicating that upstream though :) I think we're 
meeting next week to chat a bit more about it, and can perhaps formalize that 
into some tracking bugs, etc.

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


[Lldb-commits] [lldb] c3fe1c4 - [lldb] Resolve executables more aggressively on the host

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

Author: Jonas Devlieghere
Date: 2024-06-22T08:18:15-07:00
New Revision: c3fe1c4472e72a3832be911e8fa9098fa84762a0

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

LOG: [lldb] Resolve executables more aggressively on the host

When unifying the ResolveExecutable implementations in #96256, I missed
that RemoteAwarePlatform was able to resolve executables more
aggressively. The host platform can rely on the current working
directory to make relative paths absolute and resolve things like home
directories.

This should fix command-target-create-resolve-exe.test.

Added: 


Modified: 
lldb/include/lldb/Target/RemoteAwarePlatform.h
lldb/source/Target/RemoteAwarePlatform.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/RemoteAwarePlatform.h 
b/lldb/include/lldb/Target/RemoteAwarePlatform.h
index 6fbeec7888a98..fb2eecfaa23a8 100644
--- a/lldb/include/lldb/Target/RemoteAwarePlatform.h
+++ b/lldb/include/lldb/Target/RemoteAwarePlatform.h
@@ -20,6 +20,11 @@ class RemoteAwarePlatform : public Platform {
 public:
   using Platform::Platform;
 
+  virtual Status
+  ResolveExecutable(const ModuleSpec _spec,
+lldb::ModuleSP _module_sp,
+const FileSpecList *module_search_paths_ptr) override;
+
   bool GetModuleSpec(const FileSpec _file_spec, const ArchSpec ,
  ModuleSpec _spec) override;
 

diff  --git a/lldb/source/Target/RemoteAwarePlatform.cpp 
b/lldb/source/Target/RemoteAwarePlatform.cpp
index 63243d6e71307..5fc2d63876b92 100644
--- a/lldb/source/Target/RemoteAwarePlatform.cpp
+++ b/lldb/source/Target/RemoteAwarePlatform.cpp
@@ -29,6 +29,29 @@ bool RemoteAwarePlatform::GetModuleSpec(const FileSpec 
_file_spec,
   return false;
 }
 
+Status RemoteAwarePlatform::ResolveExecutable(
+const ModuleSpec _spec, lldb::ModuleSP _module_sp,
+const FileSpecList *module_search_paths_ptr) {
+  ModuleSpec resolved_module_spec(module_spec);
+
+  // The host platform can resolve the path more aggressively.
+  if (IsHost()) {
+FileSpec _file_spec = resolved_module_spec.GetFileSpec();
+
+if (!FileSystem::Instance().Exists(resolved_file_spec)) {
+  resolved_module_spec.GetFileSpec().SetFile(resolved_file_spec.GetPath(),
+ FileSpec::Style::native);
+  FileSystem::Instance().Resolve(resolved_file_spec);
+}
+
+if (!FileSystem::Instance().Exists(resolved_file_spec))
+  FileSystem::Instance().ResolveExecutableLocation(resolved_file_spec);
+  }
+
+  return Platform::ResolveExecutable(resolved_module_spec, exe_module_sp,
+ module_search_paths_ptr);
+}
+
 Status RemoteAwarePlatform::RunShellCommand(
 llvm::StringRef command, const FileSpec _dir, int *status_ptr,
 int *signo_ptr, std::string *command_output,



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


[Lldb-commits] [lldb] [lldb][ExpressionParser][NFCI] Add new DoPrepareForExecution interface to be implemented by language plugins (PR #96290)

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

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


[Lldb-commits] [lldb] bfd263a - [lldb][ExpressionParser][NFCI] Add new DoPrepareForExecution interface to be implemented by language plugins (#96290)

2024-06-22 Thread via lldb-commits

Author: Michael Buch
Date: 2024-06-22T07:20:13+01:00
New Revision: bfd263a34df5d3916eb8425bb070618324acabfa

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

LOG: [lldb][ExpressionParser][NFCI] Add new DoPrepareForExecution interface to 
be implemented by language plugins (#96290)

This patch adds a new `DoPrepareForExecution` API, which can be
implemented by the Clang and Swift language plugins. This also moves
`RunStaticInitializers` into `ExpressionParser::PrepareForExecution`, so
we call it consistently between language plugins.

This *should* be mostly NFC (the static initializers will still only run
after we finished parsing). We've been living on this patch downstream
for sometime now.

rdar://130267058

Added: 
lldb/source/Expression/ExpressionParser.cpp

Modified: 
lldb/include/lldb/Expression/ExpressionParser.h
lldb/source/Expression/CMakeLists.txt
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

Removed: 




diff  --git a/lldb/include/lldb/Expression/ExpressionParser.h 
b/lldb/include/lldb/Expression/ExpressionParser.h
index ab5223c915530..2ef7e036909c7 100644
--- a/lldb/include/lldb/Expression/ExpressionParser.h
+++ b/lldb/include/lldb/Expression/ExpressionParser.h
@@ -119,14 +119,35 @@ class ExpressionParser {
   /// \return
   /// An error code indicating the success or failure of the operation.
   /// Test with Success().
-  virtual Status
+  Status
   PrepareForExecution(lldb::addr_t _addr, lldb::addr_t _end,
   std::shared_ptr _unit_sp,
   ExecutionContext _ctx, bool _interpret,
-  lldb_private::ExecutionPolicy execution_policy) = 0;
+  lldb_private::ExecutionPolicy execution_policy);
 
   bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
 
+protected:
+  virtual Status
+  DoPrepareForExecution(lldb::addr_t _addr, lldb::addr_t _end,
+std::shared_ptr _unit_sp,
+ExecutionContext _ctx, bool _interpret,
+lldb_private::ExecutionPolicy execution_policy) = 0;
+
+private:
+  /// Run all static initializers for an execution unit.
+  ///
+  /// \param[in] execution_unit_sp
+  /// The execution unit.
+  ///
+  /// \param[in] exe_ctx
+  /// The execution context to use when running them.  Thread can't be 
null.
+  ///
+  /// \return
+  /// The error code indicating the
+  Status RunStaticInitializers(lldb::IRExecutionUnitSP _unit_sp,
+   ExecutionContext _ctx);
+
 protected:
   Expression _expr; ///< The expression to be parsed
   bool m_generate_debug_info;

diff  --git a/lldb/source/Expression/CMakeLists.txt 
b/lldb/source/Expression/CMakeLists.txt
index 9ba5fefc09b6a..be1e132f7aaad 100644
--- a/lldb/source/Expression/CMakeLists.txt
+++ b/lldb/source/Expression/CMakeLists.txt
@@ -3,6 +3,7 @@ add_lldb_library(lldbExpression NO_PLUGIN_DEPENDENCIES
   DWARFExpression.cpp
   DWARFExpressionList.cpp
   Expression.cpp
+  ExpressionParser.cpp
   ExpressionTypeSystemHelper.cpp
   ExpressionVariable.cpp
   FunctionCaller.cpp

diff  --git a/lldb/source/Expression/ExpressionParser.cpp 
b/lldb/source/Expression/ExpressionParser.cpp
new file mode 100644
index 0..e9f7121c2499e
--- /dev/null
+++ b/lldb/source/Expression/ExpressionParser.cpp
@@ -0,0 +1,72 @@
+//===-- ExpressionParser.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/Expression/ExpressionParser.h"
+#include "lldb/Expression/DiagnosticManager.h"
+#include "lldb/Expression/IRExecutionUnit.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ThreadPlanCallFunction.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+Status ExpressionParser::PrepareForExecution(
+addr_t _addr, addr_t _end,
+std::shared_ptr _unit_sp,
+ExecutionContext _ctx, bool _interpret,
+ExecutionPolicy execution_policy) {
+  Status status =
+  DoPrepareForExecution(func_addr, func_end, execution_unit_sp, exe_ctx,
+can_interpret, execution_policy);
+  if (status.Success() && exe_ctx.GetProcessPtr() && exe_ctx.HasThreadScope())
+status = RunStaticInitializers(execution_unit_sp, exe_ctx);
+
+  return status;
+}
+
+Status

[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits

medismailben wrote:

Awesome!  it!

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/96001

>From a59949cc908d5216950f2530fe1455da8ad39b5f Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Thu, 13 Jun 2024 16:02:07 -0700
Subject: [PATCH] add unit test for breakpoint::setcallback

---
 lldb/include/lldb/lldb-private-interfaces.h   |  8 +-
 lldb/source/Breakpoint/BreakpointOptions.cpp  | 18 ++--
 lldb/unittests/CMakeLists.txt |  1 +
 lldb/unittests/Callback/CMakeLists.txt| 12 +++
 .../Callback/TestBreakpointSetCallback.cpp| 85 +++
 5 files changed, 107 insertions(+), 17 deletions(-)
 create mode 100644 lldb/unittests/Callback/CMakeLists.txt
 create mode 100644 lldb/unittests/Callback/TestBreakpointSetCallback.cpp

diff --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 53d5fbb84cc92..cdd9b51d9329c 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -99,10 +99,10 @@ typedef std::optional 
(*SymbolLocatorLocateExecutableSymbolFile)(
 typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
 ModuleSpec _spec, Status , bool force_lookup,
 bool copy_executable);
-typedef bool (*BreakpointHitCallback)(void *baton,
-  StoppointCallbackContext *context,
-  lldb::user_id_t break_id,
-  lldb::user_id_t break_loc_id);
+using BreakpointHitCallback =
+std::function;
+
 typedef bool (*WatchpointHitCallback)(void *baton,
   StoppointCallbackContext *context,
   lldb::user_id_t watch_id);
diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp 
b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 6c6037dd9edd3..1db8401698114 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -102,19 +102,11 @@ const char *BreakpointOptions::g_option_names[(
 "ConditionText", "IgnoreCount", 
 "EnabledState", "OneShotState", "AutoContinue"};
 
-bool BreakpointOptions::NullCallback(void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id) {
-  return true;
-}
-
 // BreakpointOptions constructor
 BreakpointOptions::BreakpointOptions(bool all_flags_set)
-: m_callback(BreakpointOptions::NullCallback),
-  m_baton_is_command_baton(false), m_callback_is_synchronous(false),
-  m_enabled(true), m_one_shot(false), m_ignore_count(0),
-  m_condition_text_hash(0), m_inject_condition(false),
+: m_callback(nullptr), m_baton_is_command_baton(false),
+  m_callback_is_synchronous(false), m_enabled(true), m_one_shot(false),
+  m_ignore_count(0), m_condition_text_hash(0), m_inject_condition(false),
   m_auto_continue(false), m_set_flags(0) {
   if (all_flags_set)
 m_set_flags.Set(~((Flags::ValueType)0));
@@ -420,7 +412,7 @@ void BreakpointOptions::SetCallback(
 }
 
 void BreakpointOptions::ClearCallback() {
-  m_callback = BreakpointOptions::NullCallback;
+  m_callback = nullptr;
   m_callback_is_synchronous = false;
   m_callback_baton_sp.reset();
   m_baton_is_command_baton = false;
@@ -449,7 +441,7 @@ bool 
BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
 }
 
 bool BreakpointOptions::HasCallback() const {
-  return m_callback != BreakpointOptions::NullCallback;
+  return static_cast(m_callback);
 }
 
 bool BreakpointOptions::GetCommandLineCallbacks(StringList _list) {
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index a2585a94b6155..cc9d45ebf981d 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   add_subdirectory(API)
 endif()
 add_subdirectory(Breakpoint)
+add_subdirectory(Callback)
 add_subdirectory(Core)
 add_subdirectory(DataFormatter)
 add_subdirectory(Disassembler)
diff --git a/lldb/unittests/Callback/CMakeLists.txt 
b/lldb/unittests/Callback/CMakeLists.txt
new file mode 100644
index 0..b9e0ef5a396e3
--- /dev/null
+++ b/lldb/unittests/Callback/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_unittest(LLDBCallbackTests
+  TestBreakpointSetCallback.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
+  LINK_COMPONENTS
+Support
+  )
diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..2a7070f9349c0
--- /dev/null
+++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
@@ -0,0 +1,85 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM 

[Lldb-commits] [lldb] Reapply [lldb][DWARF] Delay struct/class/union definition DIE searching when parsing declaration DIEs. (PR #92328)

2024-06-21 Thread via lldb-commits

jeffreytan81 wrote:

@ZequanWu, @labath, since this PR got reverted due to crash for 
`--gsimple-template-names`, do you guys have a timeline to revise a new version 
without crashing? I ask this because our internal customers have many forward 
declarations that are suffering from the slow definition lookup. cc @clayborg 

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits

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

LGTM with comment

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.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 "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+static constexpr lldb::user_id_t expected_breakpoint_id = 1;
+static constexpr lldb::user_id_t expected_breakpoint_location_id = 0;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id,

medismailben wrote:

no need to pass them here, since they're static

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/96001

>From 44ea5e0d0a319fa12463129ff072bcaef6112544 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Thu, 13 Jun 2024 16:02:07 -0700
Subject: [PATCH] add unit test for breakpoint::setcallback

---
 lldb/include/lldb/lldb-private-interfaces.h   |  8 +-
 lldb/source/Breakpoint/BreakpointOptions.cpp  | 18 ++--
 lldb/unittests/CMakeLists.txt |  1 +
 lldb/unittests/Callback/CMakeLists.txt| 12 +++
 .../Callback/TestBreakpointSetCallback.cpp| 89 +++
 5 files changed, 111 insertions(+), 17 deletions(-)
 create mode 100644 lldb/unittests/Callback/CMakeLists.txt
 create mode 100644 lldb/unittests/Callback/TestBreakpointSetCallback.cpp

diff --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 53d5fbb84cc92..cdd9b51d9329c 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -99,10 +99,10 @@ typedef std::optional 
(*SymbolLocatorLocateExecutableSymbolFile)(
 typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
 ModuleSpec _spec, Status , bool force_lookup,
 bool copy_executable);
-typedef bool (*BreakpointHitCallback)(void *baton,
-  StoppointCallbackContext *context,
-  lldb::user_id_t break_id,
-  lldb::user_id_t break_loc_id);
+using BreakpointHitCallback =
+std::function;
+
 typedef bool (*WatchpointHitCallback)(void *baton,
   StoppointCallbackContext *context,
   lldb::user_id_t watch_id);
diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp 
b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 6c6037dd9edd3..1db8401698114 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -102,19 +102,11 @@ const char *BreakpointOptions::g_option_names[(
 "ConditionText", "IgnoreCount", 
 "EnabledState", "OneShotState", "AutoContinue"};
 
-bool BreakpointOptions::NullCallback(void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id) {
-  return true;
-}
-
 // BreakpointOptions constructor
 BreakpointOptions::BreakpointOptions(bool all_flags_set)
-: m_callback(BreakpointOptions::NullCallback),
-  m_baton_is_command_baton(false), m_callback_is_synchronous(false),
-  m_enabled(true), m_one_shot(false), m_ignore_count(0),
-  m_condition_text_hash(0), m_inject_condition(false),
+: m_callback(nullptr), m_baton_is_command_baton(false),
+  m_callback_is_synchronous(false), m_enabled(true), m_one_shot(false),
+  m_ignore_count(0), m_condition_text_hash(0), m_inject_condition(false),
   m_auto_continue(false), m_set_flags(0) {
   if (all_flags_set)
 m_set_flags.Set(~((Flags::ValueType)0));
@@ -420,7 +412,7 @@ void BreakpointOptions::SetCallback(
 }
 
 void BreakpointOptions::ClearCallback() {
-  m_callback = BreakpointOptions::NullCallback;
+  m_callback = nullptr;
   m_callback_is_synchronous = false;
   m_callback_baton_sp.reset();
   m_baton_is_command_baton = false;
@@ -449,7 +441,7 @@ bool 
BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
 }
 
 bool BreakpointOptions::HasCallback() const {
-  return m_callback != BreakpointOptions::NullCallback;
+  return static_cast(m_callback);
 }
 
 bool BreakpointOptions::GetCommandLineCallbacks(StringList _list) {
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index a2585a94b6155..cc9d45ebf981d 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   add_subdirectory(API)
 endif()
 add_subdirectory(Breakpoint)
+add_subdirectory(Callback)
 add_subdirectory(Core)
 add_subdirectory(DataFormatter)
 add_subdirectory(Disassembler)
diff --git a/lldb/unittests/Callback/CMakeLists.txt 
b/lldb/unittests/Callback/CMakeLists.txt
new file mode 100644
index 0..b9e0ef5a396e3
--- /dev/null
+++ b/lldb/unittests/Callback/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_unittest(LLDBCallbackTests
+  TestBreakpointSetCallback.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
+  LINK_COMPONENTS
+Support
+  )
diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..d82ca660ab73f
--- /dev/null
+++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM 

[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.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 "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+#define EXPECTED_BREAKPOINT_ID 1
+#define EXPECTED_BREAKPOINT_LOCATION_ID 0
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id,
+TargetSP expected_target_sp) {
+EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp);
+EXPECT_EQ(baton, "hello");
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  BreakpointSP m_breakpoint_sp;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  // Set up the debugger, make sure that was done properly.
+  TargetSP m_target_sp;

medismailben wrote:

It's not an class member, why prepend the `m_`

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.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 "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+#define EXPECTED_BREAKPOINT_ID 1
+#define EXPECTED_BREAKPOINT_LOCATION_ID 0
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id,
+TargetSP expected_target_sp) {
+EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp);
+EXPECT_EQ(baton, "hello");
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  BreakpointSP m_breakpoint_sp;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  // Set up the debugger, make sure that was done properly.
+  TargetSP m_target_sp;
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, ));
+
+  m_debugger_sp = Debugger::CreateInstance();
+
+  // Create target
+  m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+  lldb_private::eLoadDependentsNo,
+  m_platform_sp, m_target_sp);
+
+  // Create breakpoint
+  m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);

medismailben wrote:

I guess you don't need to make the breakpoint a class member here

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.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 "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+#define EXPECTED_BREAKPOINT_ID 1
+#define EXPECTED_BREAKPOINT_LOCATION_ID 0
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id,
+TargetSP expected_target_sp) {
+EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp);
+EXPECT_EQ(baton, "hello");
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+  };
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  BreakpointSP m_breakpoint_sp;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  // Set up the debugger, make sure that was done properly.
+  TargetSP m_target_sp;
+  ArchSpec arch("x86_64-apple-macosx-");
+  Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, ));
+
+  m_debugger_sp = Debugger::CreateInstance();
+
+  // Create target
+  m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+  lldb_private::eLoadDependentsNo,
+  m_platform_sp, m_target_sp);
+
+  // Create breakpoint
+  m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+
+  m_breakpoint_sp->SetCallback(
+  [m_target_sp](void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id, lldb::user_id_t break_loc_id) {
+CheckCallbackArgs(baton, context, break_id, break_loc_id,
+  EXPECTED_BREAKPOINT_ID,
+  EXPECTED_BREAKPOINT_LOCATION_ID, m_target_sp);
+return true;
+  },
+  baton, true);
+  ExecutionContext m_exe_ctx(m_target_sp, false);

medismailben wrote:

Ditto

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits

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


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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits

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


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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Med Ismail Bennani via lldb-commits


@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.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 "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+#define EXPECTED_BREAKPOINT_ID 1

medismailben wrote:

You can make these `static constexpr lldb::user_id_t` if you want

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -0,0 +1,101 @@
+REQUIRES: x86_64-linux
+
+This is a copy of memprof-basict.test with slight changes to check that we can 
still read v3 of memprofraw.
+
+To update the inputs used below run Inputs/update_memprof_inputs.sh 
/path/to/updated/clang

teresajohnson wrote:

I think this comment is wrong - we can't update the v3 version, is that 
correct? Nor would we want to.

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -38,4 +38,5 @@ MEMPROF_FLAG(bool, 
allocator_frees_and_returns_null_on_realloc_zero, true,
 MEMPROF_FLAG(bool, print_text, false,
   "If set, prints the heap profile in text format. Else use the raw binary 
serialization format.")
 MEMPROF_FLAG(bool, print_terse, false,
- "If set, prints memory profile in a terse format. Only applicable 
if print_text = true.")
+ "If set, prints memory profile in a terse format. Only applicable 
"

teresajohnson wrote:

Formatting change only, remove from patch

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -205,8 +205,14 @@ class RawMemProfReader final : public MemProfReader {
 
   object::SectionedAddress getModuleOffset(uint64_t VirtualAddress);
 
+  llvm::SmallVector>
+  readMemInfoBlocks(const char *Ptr);
+
   // The profiled binary.
   object::OwningBinary Binary;
+  // Version of raw memprof binary currently being read. Defaults to most 
update

teresajohnson wrote:

typo: s/update to date/up to date/

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -610,13 +670,33 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
   return BuildIds.takeVector();
 }
 
+// FIXME: Add a schema for serializing similiar to IndexedMemprofReader. This
+// will help being able to deserialize different versions raw memprof versions
+// more easily.
+llvm::SmallVector>
+RawMemProfReader::readMemInfoBlocks(const char *Ptr) {
+  if (MemprofRawVersion == 3ULL) {
+errs() << "Reading V3\n";

teresajohnson wrote:

Once you do that, the braces can be removed from all of the if else conditions 
here which have single statement bodies

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -610,13 +670,33 @@ RawMemProfReader::peekBuildIds(MemoryBuffer *DataBuffer) {
   return BuildIds.takeVector();
 }
 
+// FIXME: Add a schema for serializing similiar to IndexedMemprofReader. This
+// will help being able to deserialize different versions raw memprof versions
+// more easily.
+llvm::SmallVector>
+RawMemProfReader::readMemInfoBlocks(const char *Ptr) {
+  if (MemprofRawVersion == 3ULL) {
+errs() << "Reading V3\n";

teresajohnson wrote:

Leftover debugging message that should be removed?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -0,0 +1,101 @@
+REQUIRES: x86_64-linux
+
+This is a copy of memprof-basict.test with slight changes to check that we can 
still read v3 of memprofraw.

teresajohnson wrote:

typo: basict

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) {
   return count;
 }
 
+// Accumulates the access count from the shadow for the given pointer and size.
+// See memprof_mapping.h for an overview on histogram counters.
+u64 GetShadowCountHistogram(uptr p, u32 size) {
+  u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p);
+  u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size);
+  u64 count = 0;
+  for (; shadow <= shadow_end; shadow++)
+count += *shadow;
+  return count;
+}
+
+// If we use the normal approach from clearCountersWithoutHistogram, the
+// histogram will clear too much data and may overwrite shadow counters that 
are
+// in use. Likely because of rounding up the shadow_end pointer.
+// See memprof_mapping.h for an overview on histogram counters.
+void clearCountersHistogram(uptr addr, uptr size) {
+  u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr);
+  u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size);
+  for (; shadow_8 < shadow_end_8; shadow_8++) {
+*shadow_8 = 0;
+  }
+}
+
+void clearCountersWithoutHistogram(uptr addr, uptr size) {
+  uptr shadow_beg = MEM_TO_SHADOW(addr);
+  uptr shadow_end = MEM_TO_SHADOW(addr + size - SHADOW_GRANULARITY) + 1;
+  REAL(memset)((void *)shadow_beg, 0, shadow_end - shadow_beg);
+}
+
 // Clears the shadow counters (when memory is allocated).
 void ClearShadow(uptr addr, uptr size) {

teresajohnson wrote:

Looking at this function more, there are a lot of uses of the MEM_TO_SHADOW 
computed values, which is not the right mapping function to use with the 
smaller granularity of the histogram case. I think you probably need to version 
the calls to MEM_TO_SHADOW here, then all of the rest of the code can work as 
is? I.e. you wouldn't need the 2 versions of `clearCounters*`

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -124,6 +124,13 @@ struct PortableMemInfoBlock {
   OS << "" << #Name << ": " << Name << "\n";
 #include "llvm/ProfileData/MIBEntryDef.inc"
 #undef MIBEntryDef
+if (AccessHistogramSize > 0) {
+  OS << "" << "AccessHistogramValues" << ":";
+  for (uint32_t I = 0; I < AccessHistogramSize; ++I) {
+OS << " -" << ((uint64_t *)AccessHistogram)[I];

teresajohnson wrote:

Why the " -" in the outputs? I noticed when looking at the text that they look 
like negative values as a result. Any reason not to just delimit with the space?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module ) {
   }
 }
 
+// Set MemprofHistogramFlag as a Global veriable in IR. This makes it 
accessible
+// to

teresajohnson wrote:

nit: fix line wrapping

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -96,19 +102,63 @@ llvm::SmallVector readSegmentEntries(const 
char *Ptr) {
 }
 
 llvm::SmallVector>
-readMemInfoBlocks(const char *Ptr) {
+readMemInfoBlocksV3(const char *Ptr) {
   using namespace support;
 
   const uint64_t NumItemsToRead =
-  endian::readNext(Ptr);
+  endian::readNext(Ptr);
+
   llvm::SmallVector> Items;
   for (uint64_t I = 0; I < NumItemsToRead; I++) {
 const uint64_t Id =
-endian::readNext(Ptr);
-const MemInfoBlock MIB = *reinterpret_cast(Ptr);
+endian::readNext(Ptr);
+
+// We cheat a bit here and remove the const from cast to set the
+// Histogram Pointer to newly allocated buffer. We also cheat, since V3 and
+// V4 do not have the same fields. V3 is missing AccessHistogramSize and
+// AccessHistogram. This means we read "dirty" data in here, but it should
+// not segfault, since there will be callstack data placed after this in 
the
+// binary format.
+MemInfoBlock MIB = *reinterpret_cast(Ptr);
+// Overwrite dirty data.

teresajohnson wrote:

Isn't this going to overwrite some callstack data?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -20,25 +20,25 @@ CHECK-NEXT:  -
 
 CHECK:  Records:
 CHECK-NEXT:  -
-CHECK-NEXT:FunctionGUID: 15505678318020221912
+CHECK-NEXT:FunctionGUID: 3873612792189045660
 CHECK-NEXT:AllocSites:
 CHECK-NEXT:-
 CHECK-NEXT:  Callstack:
 CHECK-NEXT:  -
-CHECK-NEXT:Function: 15505678318020221912
-CHECK-NEXT:SymbolName: qux
+CHECK-NEXT:Function: 3873612792189045660
+CHECK-NEXT:SymbolName: _Z3quxi

teresajohnson wrote:

Why did the function symbol names change with your patch?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -508,7 +519,26 @@ void createProfileFileNameVar(Module ) {
   }
 }
 
+// Set MemprofHistogramFlag as a Global veriable in IR. This makes it 
accessible
+// to
+// the runtime, changing shadow count behavior.
+void createMemprofHistogramFlagVar(Module ) {
+  const StringRef VarName(MemProfHistogramFlagVar);
+  Type *IntTy1 = Type::getInt1Ty(M.getContext());
+  auto MemprofHistogramFlag = new GlobalVariable(
+  M, IntTy1, true, GlobalValue::WeakAnyLinkage,
+  Constant::getIntegerValue(IntTy1, APInt(1, ClHistogram)), VarName);
+  // MemprofHistogramFlag->setVisibility(GlobalValue::HiddenVisibility);

teresajohnson wrote:

remove?

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


[Lldb-commits] [clang-tools-extra] [compiler-rt] [lldb] [llvm] [Memprof] Adds the option to collect AccessCountHistograms for memprof. (PR #94264)

2024-06-21 Thread Teresa Johnson via lldb-commits


@@ -216,6 +228,35 @@ u64 GetShadowCount(uptr p, u32 size) {
   return count;
 }
 
+// Accumulates the access count from the shadow for the given pointer and size.
+// See memprof_mapping.h for an overview on histogram counters.
+u64 GetShadowCountHistogram(uptr p, u32 size) {
+  u8 *shadow = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p);
+  u8 *shadow_end = (u8 *)HISTOGRAM_MEM_TO_SHADOW(p + size);
+  u64 count = 0;
+  for (; shadow <= shadow_end; shadow++)
+count += *shadow;
+  return count;
+}
+
+// If we use the normal approach from clearCountersWithoutHistogram, the
+// histogram will clear too much data and may overwrite shadow counters that 
are
+// in use. Likely because of rounding up the shadow_end pointer.
+// See memprof_mapping.h for an overview on histogram counters.
+void clearCountersHistogram(uptr addr, uptr size) {
+  u8 *shadow_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr);
+  u8 *shadow_end_8 = (u8 *)HISTOGRAM_MEM_TO_SHADOW(addr + size);
+  for (; shadow_8 < shadow_end_8; shadow_8++) {

teresajohnson wrote:

Why not use REAL(memset) like the non-histogram version below?

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


[Lldb-commits] [lldb] Add a unit test for SBBreakpoint::SetCallback (PR #96001)

2024-06-21 Thread Chelsea Cassanova via lldb-commits

https://github.com/chelcassanova updated 
https://github.com/llvm/llvm-project/pull/96001

>From 86dcffcc7a1820756fe8104d8239f25185a27733 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Thu, 13 Jun 2024 16:02:07 -0700
Subject: [PATCH] add unit test for breakpoint::setcallback

---
 lldb/include/lldb/lldb-private-interfaces.h   |  8 +-
 lldb/source/Breakpoint/BreakpointOptions.cpp  | 18 ++--
 lldb/unittests/CMakeLists.txt |  1 +
 lldb/unittests/Callback/CMakeLists.txt| 12 +++
 .../Callback/TestBreakpointSetCallback.cpp| 89 +++
 5 files changed, 111 insertions(+), 17 deletions(-)
 create mode 100644 lldb/unittests/Callback/CMakeLists.txt
 create mode 100644 lldb/unittests/Callback/TestBreakpointSetCallback.cpp

diff --git a/lldb/include/lldb/lldb-private-interfaces.h 
b/lldb/include/lldb/lldb-private-interfaces.h
index 53d5fbb84cc92..cdd9b51d9329c 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -99,10 +99,10 @@ typedef std::optional 
(*SymbolLocatorLocateExecutableSymbolFile)(
 typedef bool (*SymbolLocatorDownloadObjectAndSymbolFile)(
 ModuleSpec _spec, Status , bool force_lookup,
 bool copy_executable);
-typedef bool (*BreakpointHitCallback)(void *baton,
-  StoppointCallbackContext *context,
-  lldb::user_id_t break_id,
-  lldb::user_id_t break_loc_id);
+using BreakpointHitCallback =
+std::function;
+
 typedef bool (*WatchpointHitCallback)(void *baton,
   StoppointCallbackContext *context,
   lldb::user_id_t watch_id);
diff --git a/lldb/source/Breakpoint/BreakpointOptions.cpp 
b/lldb/source/Breakpoint/BreakpointOptions.cpp
index 6c6037dd9edd3..1db8401698114 100644
--- a/lldb/source/Breakpoint/BreakpointOptions.cpp
+++ b/lldb/source/Breakpoint/BreakpointOptions.cpp
@@ -102,19 +102,11 @@ const char *BreakpointOptions::g_option_names[(
 "ConditionText", "IgnoreCount", 
 "EnabledState", "OneShotState", "AutoContinue"};
 
-bool BreakpointOptions::NullCallback(void *baton,
- StoppointCallbackContext *context,
- lldb::user_id_t break_id,
- lldb::user_id_t break_loc_id) {
-  return true;
-}
-
 // BreakpointOptions constructor
 BreakpointOptions::BreakpointOptions(bool all_flags_set)
-: m_callback(BreakpointOptions::NullCallback),
-  m_baton_is_command_baton(false), m_callback_is_synchronous(false),
-  m_enabled(true), m_one_shot(false), m_ignore_count(0),
-  m_condition_text_hash(0), m_inject_condition(false),
+: m_callback(nullptr), m_baton_is_command_baton(false),
+  m_callback_is_synchronous(false), m_enabled(true), m_one_shot(false),
+  m_ignore_count(0), m_condition_text_hash(0), m_inject_condition(false),
   m_auto_continue(false), m_set_flags(0) {
   if (all_flags_set)
 m_set_flags.Set(~((Flags::ValueType)0));
@@ -420,7 +412,7 @@ void BreakpointOptions::SetCallback(
 }
 
 void BreakpointOptions::ClearCallback() {
-  m_callback = BreakpointOptions::NullCallback;
+  m_callback = nullptr;
   m_callback_is_synchronous = false;
   m_callback_baton_sp.reset();
   m_baton_is_command_baton = false;
@@ -449,7 +441,7 @@ bool 
BreakpointOptions::InvokeCallback(StoppointCallbackContext *context,
 }
 
 bool BreakpointOptions::HasCallback() const {
-  return m_callback != BreakpointOptions::NullCallback;
+  return static_cast(m_callback);
 }
 
 bool BreakpointOptions::GetCommandLineCallbacks(StringList _list) {
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index a2585a94b6155..cc9d45ebf981d 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   add_subdirectory(API)
 endif()
 add_subdirectory(Breakpoint)
+add_subdirectory(Callback)
 add_subdirectory(Core)
 add_subdirectory(DataFormatter)
 add_subdirectory(Disassembler)
diff --git a/lldb/unittests/Callback/CMakeLists.txt 
b/lldb/unittests/Callback/CMakeLists.txt
new file mode 100644
index 0..b9e0ef5a396e3
--- /dev/null
+++ b/lldb/unittests/Callback/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_unittest(LLDBCallbackTests
+  TestBreakpointSetCallback.cpp
+
+  LINK_LIBS
+lldbBreakpoint
+lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
+  LINK_COMPONENTS
+Support
+  )
diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..998b001d400c5
--- /dev/null
+++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM 

[Lldb-commits] [lldb] [lldb] Change lldb's breakpoint handling behavior (PR #96260)

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

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

>From 9b541e6a035635e26c6a24eca022de8552fa4c17 Mon Sep 17 00:00:00 2001
From: Jason Molenda 
Date: Thu, 20 Jun 2024 17:53:17 -0700
Subject: [PATCH 1/3] [lldb] Change lldb's breakpoint handling behavior

lldb today has two rules:  When a thread stops at a BreakpointSite,
we set the thread's StopReason to be "breakpoint hit" (regardless
if we've actually hit the breakpoint, or if we've merely stopped
*at* the breakpoint instruction/point and haven't tripped it yet).
And second, when resuming a process, any thread sitting at a
BreakpointSite is silently stepped over the BreakpointSite -- because
we've already flagged the breakpoint hit when we stopped there
originally.

In this patch, I change lldb to only set a thread's stop reason to
breakpoint-hit when we've actually executed the instruction/triggered
the breakpoint.  When we resume, we only silently step past a
BreakpointSite that we've registered as hit.  We preserve this state
across inferior function calls that the user may do while stopped,
etc.

Also, when a user adds a new breakpoint at $pc while stopped, or
changes $pc to be the address of a BreakpointSite, we will silently
step past that breakpoint when the process resumes.  This is purely
a UX call, I don't think there's any person who wants to set a
breakpoint at $pc and then hit it immediately on resuming.

One non-intuitive UX from this change, but I'm convinced it is
necessary:  If you're stopped at a BreakpointSite that has not yet
executed, you `stepi`, you will hit the breakpoint and the pc will
not yet advance.  This thread has not completed its stepi, and the
thread plan is still on the stack.  If you then `continue` the
thread, lldb will now stop and say, "instruction step completed",
one instruction past the BreakpointSite.  You can continue a second
time to resume execution.  I discussed this with Jim, and trying
to paper over this behavior will lead to more complicated scenarios
behaving non-intuitively.  And mostly it's the testsuite that was
trying to instruction step past a breakpoint and getting thrown off
-- and I changed those tests to expect the new behavior.

The bugs driving this change are all from lldb dropping the real
stop reason for a thread and setting it to breakpoint-hit when that
was not the case.  Jim hit one where we have an aarch64 watchpoint
that triggers one instruction before a BreakpointSite.  On this
arch we are notified of the watchpoint hit after the instruction
has been unrolled -- we disable the watchpoint, instruction step,
re-enable the watchpoint and collect the new value.  But now we're
on a BreakpointSite so the watchpoint-hit stop reason is lost.

Another was reported by ZequanWu in
https://discourse.llvm.org/t/lldb-unable-to-break-at-start/78282
we attach to/launch a process with the pc at a BreakpointSite and
misbehave.  Caroline Tice mentioned it is also a problem they've
had with putting a breakpoint on _dl_debug_state.

The change to each Process plugin that does execution control
is that

1. If we've stopped at a BreakpointSite (whether we hit it or not),
we call Thread::SetThreadStoppedAtBreakpointSite(pc) to record the
state at the point when the thread stopped.  (so we can detect
newly-added breakpoints, or when the pc is changed to an instruction
that is a BreakpointSite)

2. When we have actually hit a breakpoint, and it is enabled for
this thread, we call Thread::SetThreadHitBreakpointAtAddr(pc) so
we know that it should be silently stepped past when we resume
execution.

When resuming, we silently step over a breakpoint if we've hit it,
or if it is newly added (or the pc was changed to an existing
BreakpointSite).

The biggest set of changes is to StopInfoMachException where we
translate a Mach Exception into a stop reason.  The Mach exception
codes differ in a few places depending on the target (unambiguously),
and I didn't want to duplicate the new code for each target so I've
tested what mach exceptions we get for each action on each target,
and reorganized StopInfoMachException::CreateStopReasonWithMachException
to document these possible values, and handle them without specializing
based on the target arch.

rdar://123942164
---
 lldb/include/lldb/Target/Thread.h |  29 ++
 .../Process/Utility/StopInfoMachException.cpp | 296 +++---
 .../Process/Windows/Common/ProcessWindows.cpp |  16 +-
 .../Process/gdb-remote/ProcessGDBRemote.cpp   | 118 +++
 .../Process/scripted/ScriptedThread.cpp   |   9 +
 lldb/source/Target/Thread.cpp |  17 +-
 .../TestConsecutiveBreakpoints.py |  26 +-
 .../TestStepOverBreakpoint.py |   6 +-
 8 files changed, 235 insertions(+), 282 deletions(-)

diff --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index c17bddf4d98b8..1e1aead896018 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ 

[Lldb-commits] [lldb] [lldb] Change lldb's breakpoint handling behavior (PR #96260)

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

jasonmolenda wrote:

> > @AlexK0 if you have a setup to build and run the testsuite on windows, 
> > could you try it with this patch some time when you're able? I can't see 
> > this being merged for at least another 5-6 days, there's no rush. You can 
> > download the unidiff style diff of the patch from 
> > https://patch-diff.githubusercontent.com/raw/llvm/llvm-project/pull/96260.diff
> 
> @jasonmolenda I checked the tests with VS2022/x86-64/win11 in a debug build 
> with assertions enabled. Unfortunately, the main branch is a bit unstable, 
> and some tests constantly fail :( . Nonetheless, I noticed one new failure 
> with the applied patch:
> 
> `functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py`
>

These TestConcurrent / TestConsecutiveBreakpoints tests are great for finding 
corner cases with these changes, thanks so much.  I was a little uncertain 
about one part of my ProcessWindows change, where the pc is *past* the 
breakpoint when a software breakpoint instruction is used, on Windows.  For a 
moment, I thought, "oh, I don't need to record that we hit the breakpoint 
because we're already past it and we don't need to instruction past it" but of 
course that was wrong -- ProcessWindows::RefreshStateAfterStop decrements the 
$pc value by the size of its breakpoint instruction, which is necessary because 
e.g. the size of an x86 breakpoint instruction is 1 byte (0xcc) but x86_64 
instructions can be between 1 to 15 bytes long, so stopping 1 byte after the 
BreakpointSite means we are possibly in the middle of the real instruction.  We 
must set the pc to the BreakpointSite address and use lldb's normal logic.

Anyway, tl;dr, I believe this will fix it:

```
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -442,6 +442,7 @@ void ProcessWindows::RefreshStateAfterStop() {
m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
site->GetID());
 
+  stop_thread->SetThreadHitBreakpointAtAddr(pc);
   if (site->ValidForThisThread(*stop_thread)) {
 LLDB_LOG(log,
  "Breakpoint site {0} is valid for this thread ({1:x}), "
```

I'll push it right now.  Sorry for my confusion, and thanks again for looking 
at it, this was a big help.

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


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

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

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

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

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

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  14 ++
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 131 +++
 .../find_in_memory/TestFindRangesInMemory.py  | 221 ++
 .../find_in_memory/address_ranges_helper.py   |  73 ++
 .../API/python_api/find_in_memory/main.cpp|  27 +++
 11 files changed, 661 insertions(+), 6 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError );
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList ,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError );
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange , uint32_t alignment,
+SBError );
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent );
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend class lldb::SBProcess;
 
   AddressRanges ();
 
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index eec337c15f7ed..ceaf547ebddaf 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2685,6 +2685,15 @@ void PruneThreadPlans();
   lldb::addr_t FindInMemory(lldb::addr_t low, lldb::addr_t high,
 const uint8_t *buf, size_t size);
 
+  AddressRanges FindRangesInMemory(const uint8_t *buf, uint64_t size,
+   const AddressRanges ,
+   size_t alignment, size_t max_matches,
+   Status );
+
+  lldb::addr_t FindInMemory(const uint8_t *buf, uint64_t size,
+const AddressRange , size_t alignment,
+Status );
+
 protected:
   friend class Trace;
 
@@ -2800,6 +2809,11 @@ void PruneThreadPlans();
   virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
   Status ) = 0;
 
+  virtual void 

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

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


@@ -2007,6 +2007,135 @@ size_t Process::ReadMemory(addr_t addr, void *buf, 
size_t size, Status ) {
   }
 }
 
+void Process::DoFindInMemory(lldb::addr_t start_addr, lldb::addr_t end_addr,
+ const uint8_t *buf, size_t size,
+ AddressRanges , size_t alignment,
+ size_t max_matches) {
+  // Inputs are already validated in FindInMemory() functions.
+  assert(buf != nullptr);
+  assert(size > 0);
+  assert(alignment > 0);
+  assert(max_matches > 0);
+  assert(start_addr != LLDB_INVALID_ADDRESS);
+  assert(end_addr != LLDB_INVALID_ADDRESS);
+  assert(start_addr < end_addr);
+
+  lldb::addr_t start = start_addr;
+  if (alignment > 1) {
+// Align to an address alignment boundary
+const uint64_t align_offset = start % alignment;
+if (align_offset > 0)
+  start += alignment - align_offset;
+  }

mbucko wrote:

nice!

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


[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF] Refactor legacy ranges writers (PR #96006)

2024-06-21 Thread Sayhaan Siddiqui via lldb-commits

https://github.com/sayhaan updated 
https://github.com/llvm/llvm-project/pull/96006

>From 2f1db023b70fc0bd8e0c220ebc966584bda13236 Mon Sep 17 00:00:00 2001
From: Sayhaan Siddiqui 
Date: Mon, 17 Jun 2024 10:16:44 -0700
Subject: [PATCH 01/15] [BOLT][DWARF][NFC] Refactor
 updateDWARFObjectAddressRanges

Summary:

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: https://phabricator.intern.facebook.com/D58679290
---
 bolt/include/bolt/Core/DebugData.h|   2 +
 bolt/include/bolt/Rewrite/DWARFRewriter.h |   7 ++
 bolt/lib/Core/DebugData.cpp   |   7 ++
 bolt/lib/Rewrite/DWARFRewriter.cpp| 110 +++---
 bolt/test/X86/debug-fission-single-convert.s  |   6 +-
 bolt/test/X86/dwarf4-df-dualcu.test   |  34 +++---
 .../X86/dwarf4-df-input-lowpc-ranges-cus.test |  78 +++--
 .../X86/dwarf4-df-input-lowpc-ranges.test |  37 +++---
 8 files changed, 163 insertions(+), 118 deletions(-)

diff --git a/bolt/include/bolt/Core/DebugData.h 
b/bolt/include/bolt/Core/DebugData.h
index 585bafa088849..5c730e63ae0aa 100644
--- a/bolt/include/bolt/Core/DebugData.h
+++ b/bolt/include/bolt/Core/DebugData.h
@@ -210,6 +210,8 @@ class DebugRangesSectionWriter {
   static bool classof(const DebugRangesSectionWriter *Writer) {
 return Writer->getKind() == RangesWriterKind::DebugRangesWriter;
   }
+  
+  void updateRangeBuffer(std::unique_ptr );
 
   /// Writes out range lists for a current CU being processed.
   void virtual finalizeSection(){};
diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h 
b/bolt/include/bolt/Rewrite/DWARFRewriter.h
index 8dec32de9008e..c97f25125c099 100644
--- a/bolt/include/bolt/Rewrite/DWARFRewriter.h
+++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h
@@ -89,6 +89,13 @@ class DWARFRewriter {
   /// Store Rangelists writer for each DWO CU.
   RangeListsDWOWriers RangeListsWritersByCU;
 
+  using LegacyRangesDWOWriers =
+  std::unordered_map>;
+  /// Store Rangelists writer for each DWO CU.
+  LegacyRangesDWOWriers LegacyRangesWritersByCU;
+
+  std::unordered_map UpdatedDIEsByDWO;
+
   std::mutex LocListDebugInfoPatchesMutex;
 
   /// Dwo id specific its RangesBase.
diff --git a/bolt/lib/Core/DebugData.cpp b/bolt/lib/Core/DebugData.cpp
index f502a50312470..8895b4923294a 100644
--- a/bolt/lib/Core/DebugData.cpp
+++ b/bolt/lib/Core/DebugData.cpp
@@ -177,6 +177,13 @@ uint64_t DebugRangesSectionWriter::getSectionOffset() {
   return SectionOffset;
 }
 
+void 
DebugRangesSectionWriter::updateRangeBuffer(std::unique_ptr 
) {
+  for(auto DebugInfo : *CUBuffer){
+RangesBuffer->push_back(DebugInfo);
+  }
+  SectionOffset = RangesBuffer->size();
+}
+
 DebugAddrWriter *DebugRangeListsSectionWriter::AddrWriter = nullptr;
 
 uint64_t DebugRangeListsSectionWriter::addRanges(
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp 
b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 8814ebbd10aa5..e4e54f521ee19 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -646,6 +646,15 @@ void DWARFRewriter::updateDebugInfo() {
 
 } else {
   LocListWritersByCU[CUIndex] = std::make_unique();
+  if (std::optional DWOId = CU.getDWOId()) {
+assert(LegacyRangesWritersByCU.count(*DWOId) == 0 &&
+   "LegacyRangeLists writer for DWO unit already exists.");
+auto LegacyRangesSectionWriterByCU =
+std::make_unique();
+LegacyRangesSectionWriterByCU->initSection(CU);
+LegacyRangesWritersByCU[*DWOId] =
+std::move(LegacyRangesSectionWriterByCU);
+  }
 }
 return LocListWritersByCU[CUIndex++].get();
   };
@@ -692,6 +701,7 @@ void DWARFRewriter::updateDebugInfo() {
   if (Unit->getVersion() >= 5) {
 TempRangesSectionWriter = RangeListsWritersByCU[*DWOId].get();
   } else {
+TempRangesSectionWriter = LegacyRangesWritersByCU[*DWOId].get();
 RangesBase = RangesSectionWriter->getSectionOffset();
 setDwoRangesBase(*DWOId, *RangesBase);
   }
@@ -1270,10 +1280,14 @@ void DWARFRewriter::updateDWARFObjectAddressRanges(
 }
 
 if (RangesBaseInfo) {
-  DIEBldr.replaceValue(, RangesBaseInfo.getAttribute(),
-   RangesBaseInfo.getForm(),
-   DIEInteger(static_cast(*RangesBase)));
-  RangesBase = std::nullopt;
+  if (RangesBaseInfo.getAttribute() == dwarf::DW_AT_GNU_ranges_base) {
+UpdatedDIEsByDWO[*Unit.getDWOId()] = 
+  } else {
+DIEBldr.replaceValue(, RangesBaseInfo.getAttribute(),
+ RangesBaseInfo.getForm(),
+ DIEInteger(static_cast(*RangesBase)));
+RangesBase = std::nullopt;
+  }
 }
   }
 
@@ -1290,11 +1304,9 @@ void DWARFRewriter::updateDWARFObjectAddressRanges(
 RangesAttrInfo.getForm() == dwarf::DW_FORM_sec_offset)
   NeedConverted = true;
 
-uint64_t CurRangeBase = 0;
 if (Unit.isDWOUnit()) {
-  if (std::optional 

[Lldb-commits] [lldb] 9e6ea38 - Reland "[lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts"

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

Author: Michael Buch
Date: 2024-06-21T20:35:30+01:00
New Revision: 9e6ea387c877a50394aca4b02f18a05e88cf2690

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

LOG: Reland "[lldb][ObjC] Don't query objective-c runtime for decls in C++ 
contexts"

This relands https://github.com/llvm/llvm-project/pull/95963. It had to
be reverted because the `TestEarlyProcessLaunch.py` test was failing
on the incremental macOS bots. The test failed because it was relying on
expression log output from the ObjC introspection routines (but was
the expression was called from a C++ context). The relanded patch
simply ensures that the test runs the expressions as `ObjC` expressions.

When LLDB isn't able to find a `clang::Decl` in response
to a `FindExternalVisibleDeclsByName`, it will fall-back
to looking into the Objective-C runtime for that decl. This
ends up doing a lot of work which isn't necessary when we're
debugging a C++ program. This patch makes the ObjC lookup
conditional on the language that the ExpressionParser deduced
(which can be explicitly set using the `expr --language` option
or is set implicitly if we're stopped in an ObjC frame or a
C++ frame without debug-info).

rdar://96236519

Added: 
lldb/test/Shell/Expr/TestObjCInCXXContext.test

Modified: 
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py

Removed: 




diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 82a7a2cc3f1ef..1fdd272dcbece 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
 FindDeclInModules(context, name);
   }
 
-  if (!context.m_found_type) {
+  if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
 FindDeclInObjCRuntime(context, name);
   }
 }

diff  --git 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index ef8d5540fa4ef..497c0dd128f48 100644
--- 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -15,4 +15,11 @@ def test(self):
 (_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
 
 self.assertState(process.GetState(), lldb.eStateStopped)
+
+# Tests that we can use builtin Objective-C identifiers.
 self.expect("expr id", error=False)
+
+# Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
+self.expect_expr(
+"NSString *c; c == nullptr", result_value="true", 
result_type="bool"
+)

diff  --git 
a/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py 
b/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
index 32a7bc82f4745..c15abbabc2374 100644
--- a/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
+++ b/lldb/test/API/macosx/early-process-launch/TestEarlyProcessLaunch.py
@@ -38,14 +38,14 @@ def test_early_process_launch(self):
 logfile_early = os.path.join(self.getBuildDir(), "types-log-early.txt")
 self.addTearDownHook(lambda: self.runCmd("log disable lldb types"))
 self.runCmd("log enable -f %s lldb types" % logfile_early)
-self.runCmd("expression global = 15")
+self.runCmd("expression --language objc -- global = 15")
 
 err = process.Continue()
 self.assertTrue(err.Success())
 
 logfile_later = os.path.join(self.getBuildDir(), "types-log-later.txt")
 self.runCmd("log enable -f %s lldb types" % logfile_later)
-self.runCmd("expression global = 25")
+self.runCmd("expression --language objc -- global = 25")
 
 self.assertTrue(os.path.exists(logfile_early))
 self.assertTrue(os.path.exists(logfile_later))

diff  --git a/lldb/test/Shell/Expr/TestObjCInCXXContext.test 
b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
new file mode 100644
index 0..8537799bdeb67
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
@@ -0,0 +1,21 @@
+// UNSUPPORTED: system-linux, system-windows
+
+// Tests that we don't consult the the Objective-C runtime
+// plugin when in a purely C++ context.
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// 

[Lldb-commits] [lldb] [lldb][ExpressionParser][NFCI] Add new DoPrepareForExecution interface to be implemented by language plugins (PR #96290)

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

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

>From 67d8bab2d2d42ca3ec5d07efd3be94e614dde2e9 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 20 Jun 2024 18:29:15 +0100
Subject: [PATCH 1/3] [lldb][ExpressionParser] Add DoPrepareForExecution API

---
 .../lldb/Expression/ExpressionParser.h| 25 ++-
 lldb/source/Expression/CMakeLists.txt |  1 +
 lldb/source/Expression/ExpressionParser.cpp   | 73 +++
 .../Clang/ClangExpressionParser.cpp   | 46 +---
 .../Clang/ClangExpressionParser.h | 23 ++
 .../Clang/ClangUserExpression.cpp | 15 
 6 files changed, 103 insertions(+), 80 deletions(-)
 create mode 100644 lldb/source/Expression/ExpressionParser.cpp

diff --git a/lldb/include/lldb/Expression/ExpressionParser.h 
b/lldb/include/lldb/Expression/ExpressionParser.h
index ab5223c915530..2ef7e036909c7 100644
--- a/lldb/include/lldb/Expression/ExpressionParser.h
+++ b/lldb/include/lldb/Expression/ExpressionParser.h
@@ -119,14 +119,35 @@ class ExpressionParser {
   /// \return
   /// An error code indicating the success or failure of the operation.
   /// Test with Success().
-  virtual Status
+  Status
   PrepareForExecution(lldb::addr_t _addr, lldb::addr_t _end,
   std::shared_ptr _unit_sp,
   ExecutionContext _ctx, bool _interpret,
-  lldb_private::ExecutionPolicy execution_policy) = 0;
+  lldb_private::ExecutionPolicy execution_policy);
 
   bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
 
+protected:
+  virtual Status
+  DoPrepareForExecution(lldb::addr_t _addr, lldb::addr_t _end,
+std::shared_ptr _unit_sp,
+ExecutionContext _ctx, bool _interpret,
+lldb_private::ExecutionPolicy execution_policy) = 0;
+
+private:
+  /// Run all static initializers for an execution unit.
+  ///
+  /// \param[in] execution_unit_sp
+  /// The execution unit.
+  ///
+  /// \param[in] exe_ctx
+  /// The execution context to use when running them.  Thread can't be 
null.
+  ///
+  /// \return
+  /// The error code indicating the
+  Status RunStaticInitializers(lldb::IRExecutionUnitSP _unit_sp,
+   ExecutionContext _ctx);
+
 protected:
   Expression _expr; ///< The expression to be parsed
   bool m_generate_debug_info;
diff --git a/lldb/source/Expression/CMakeLists.txt 
b/lldb/source/Expression/CMakeLists.txt
index 9ba5fefc09b6a..be1e132f7aaad 100644
--- a/lldb/source/Expression/CMakeLists.txt
+++ b/lldb/source/Expression/CMakeLists.txt
@@ -3,6 +3,7 @@ add_lldb_library(lldbExpression NO_PLUGIN_DEPENDENCIES
   DWARFExpression.cpp
   DWARFExpressionList.cpp
   Expression.cpp
+  ExpressionParser.cpp
   ExpressionTypeSystemHelper.cpp
   ExpressionVariable.cpp
   FunctionCaller.cpp
diff --git a/lldb/source/Expression/ExpressionParser.cpp 
b/lldb/source/Expression/ExpressionParser.cpp
new file mode 100644
index 0..ac727be78e8d3
--- /dev/null
+++ b/lldb/source/Expression/ExpressionParser.cpp
@@ -0,0 +1,73 @@
+//===-- ExpressionParser.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/Expression/ExpressionParser.h"
+#include "lldb/Expression/DiagnosticManager.h"
+#include "lldb/Expression/IRExecutionUnit.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/Target/ThreadPlanCallFunction.h"
+
+using namespace lldb_private;
+
+Status ExpressionParser::PrepareForExecution(
+lldb::addr_t _addr, lldb::addr_t _end,
+std::shared_ptr _unit_sp,
+ExecutionContext _ctx, bool _interpret,
+lldb_private::ExecutionPolicy execution_policy) {
+  Status status =
+  DoPrepareForExecution(func_addr, func_end, execution_unit_sp, exe_ctx,
+can_interpret, execution_policy);
+  if (status.Success() && exe_ctx.GetProcessPtr() && exe_ctx.HasThreadScope()) 
{
+status = RunStaticInitializers(execution_unit_sp, exe_ctx);
+  }
+  return status;
+}
+
+Status ExpressionParser::RunStaticInitializers(
+lldb::IRExecutionUnitSP _unit_sp, ExecutionContext _ctx) {
+  lldb_private::Status err;
+
+  lldbassert(execution_unit_sp.get());
+  lldbassert(exe_ctx.HasThreadScope());
+
+  if (!execution_unit_sp.get()) {
+err.SetErrorString(
+"can't run static initializers for a NULL execution unit");
+return err;
+  }
+
+  if (!exe_ctx.HasThreadScope()) {
+err.SetErrorString("can't run static initializers without a thread");
+return err;
+  }
+
+  std::vector static_initializers;
+
+  

  1   2   3   4   5   6   7   8   9   10   >