[Lldb-commits] [lldb] [lldb] Fix a regression in Status::GetErrorType() (PR #117095)

2024-11-20 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl created 
https://github.com/llvm/llvm-project/pull/117095

The refactored code did not correctly determine the type of expression errors.

rdar://139699028

>From 27308496b00d90e798d4c73940602d3e3cf1684b Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 20 Nov 2024 17:45:54 -0800
Subject: [PATCH] [lldb] Fix a regression in Status::GetErrorType()

The refactored code did not correctly determine the type of expression
errors.

rdar://139699028
---
 lldb/source/Utility/Status.cpp   |  6 +-
 .../expression/diagnostics/TestExprDiagnostics.py| 12 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 1d171c6b6c3746..5757935fb86228 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -258,7 +258,11 @@ ErrorType Status::GetType() const {
 // Return the first only.
 if (result != eErrorTypeInvalid)
   return;
-result = ErrorCodeToErrorType(error.convertToErrorCode());
+if (error.isA())
+  result = static_cast(error).GetErrorType();
+else
+  result = ErrorCodeToErrorType(error.convertToErrorCode());
+
   });
   return result;
 }
diff --git 
a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py 
b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
index fac562edf9ece0..c411d632d7a71f 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -184,6 +184,18 @@ def test_source_locations_from_objc_modules(self):
 # the first argument are probably stable enough that this test can 
check for them.
 self.assertIn("void NSLog(NSString *format", 
value.GetError().GetCString())
 
+def test_error_type(self):
+"""Test the error reporting in the API"""
+self.build()
+
+(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "// Break here", self.main_source_spec
+)
+frame = thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression('#error("I am error.")')
+error = value.GetError()
+self.assertEqual(error.GetType(), lldb.eErrorTypeExpression);
+
 def test_command_expr_sbdata(self):
 """Test the structured diagnostics data"""
 self.build()

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


[Lldb-commits] [lldb] [lldb] Fix a regression in Status::GetErrorType() (PR #117095)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)


Changes

The refactored code did not correctly determine the type of expression errors.

rdar://139699028

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


2 Files Affected:

- (modified) lldb/source/Utility/Status.cpp (+5-1) 
- (modified) 
lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py (+12) 


``diff
diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 1d171c6b6c3746..5757935fb86228 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -258,7 +258,11 @@ ErrorType Status::GetType() const {
 // Return the first only.
 if (result != eErrorTypeInvalid)
   return;
-result = ErrorCodeToErrorType(error.convertToErrorCode());
+if (error.isA())
+  result = static_cast(error).GetErrorType();
+else
+  result = ErrorCodeToErrorType(error.convertToErrorCode());
+
   });
   return result;
 }
diff --git 
a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py 
b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
index fac562edf9ece0..c411d632d7a71f 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -184,6 +184,18 @@ def test_source_locations_from_objc_modules(self):
 # the first argument are probably stable enough that this test can 
check for them.
 self.assertIn("void NSLog(NSString *format", 
value.GetError().GetCString())
 
+def test_error_type(self):
+"""Test the error reporting in the API"""
+self.build()
+
+(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "// Break here", self.main_source_spec
+)
+frame = thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression('#error("I am error.")')
+error = value.GetError()
+self.assertEqual(error.GetType(), lldb.eErrorTypeExpression);
+
 def test_command_expr_sbdata(self):
 """Test the structured diagnostics data"""
 self.build()

``




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


[Lldb-commits] [lldb] [lldb] Fix a regression in Status::GetErrorType() (PR #117095)

2024-11-20 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
darker --check --diff -r 
14667119bcc78fe7d8a2d8f6c31407f2b6a6f8a5...27308496b00d90e798d4c73940602d3e3cf1684b
 lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
``





View the diff from darker here.


``diff
--- TestExprDiagnostics.py  2024-11-21 01:46:50.00 +
+++ TestExprDiagnostics.py  2024-11-21 01:51:00.446586 +
@@ -192,11 +192,11 @@
 self, "// Break here", self.main_source_spec
 )
 frame = thread.GetFrameAtIndex(0)
 value = frame.EvaluateExpression('#error("I am error.")')
 error = value.GetError()
-self.assertEqual(error.GetType(), lldb.eErrorTypeExpression);
+self.assertEqual(error.GetType(), lldb.eErrorTypeExpression)
 
 def test_command_expr_sbdata(self):
 """Test the structured diagnostics data"""
 self.build()
 

``




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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits

https://github.com/splhack created 
https://github.com/llvm/llvm-project/pull/117070

Addressing two issues on ELF core debugging

1. ProcessElfCore::FindBuidIdInCoreMemory reads wrong address for ELF header 
(fixed by @clayborg)
2. DynamicLoader does not use ProcessElfCore NT_FILE entries to get UUID. Add 
FindBuildId to get UUID from Process.

>From 179a68a91a0a3eddead9bbf47f70d7a33dbc8018 Mon Sep 17 00:00:00 2001
From: Kazuki Sakamoto 
Date: Wed, 20 Nov 2024 13:49:26 -0800
Subject: [PATCH] [lldb] Fix ELF core debugging

Addressing two issues on ELF core debugging

1. ProcessElfCore::FindBuidIdInCoreMemory reads wrong address for ELF
   header (fixed by @clayborg)
2. DynamicLoader does not use ProcessElfCore NT_FILE entries to get
   UUID. Add FindBuildId to get UUID from Process.
---
 lldb/include/lldb/Target/Process.h |  2 ++
 lldb/source/Core/DynamicLoader.cpp |  4 
 .../source/Plugins/Process/elf-core/ProcessElfCore.cpp | 10 +-
 lldb/source/Plugins/Process/elf-core/ProcessElfCore.h  |  3 +++
 lldb/source/Target/Process.cpp |  5 +
 5 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index b8c53a474ba6b9..2f0cf78f260c5a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1380,6 +1380,8 @@ class Process : public 
std::enable_shared_from_this,
 
   virtual bool GetProcessInfo(ProcessInstanceInfo &info);
 
+  virtual lldb_private::UUID FindBuildId(const llvm::StringRef path);
+
   /// Get the exit status for a process.
   ///
   /// \return
diff --git a/lldb/source/Core/DynamicLoader.cpp 
b/lldb/source/Core/DynamicLoader.cpp
index 68d6ab0850853f..cc396e92721123 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP 
module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+// Process may have the UUID for the module, e.g. ELF core.
+module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());
+  }
 
   if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
 return module_sp;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..8ad6b83d77effe 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -281,6 +281,13 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
   }
 }
 
+UUID ProcessElfCore::FindBuildId(const llvm::StringRef path) {
+  for (NT_FILE_Entry &entry : m_nt_file_entries)
+if (path == entry.path)
+  return entry.uuid;
+  return UUID();
+}
+
 lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader() {
   if (m_dyld_up.get() == nullptr)
 m_dyld_up.reset(DynamicLoader::FindPlugin(
@@ -1034,7 +1041,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t 
address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
+const lldb::addr_t program_header_vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(program_header_vaddr, note_bytes.data(),
program_header.p_memsz, error);
 if (byte_read != program_header.p_memsz)
   continue;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
index 280c61ed376396..303f18249a976e 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -97,6 +97,9 @@ class ProcessElfCore : public lldb_private::PostMortemProcess 
{
 
   bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
 
+  // Returns the gnu uuid from matched NT_FILE entry
+  lldb_private::UUID FindBuildId(const llvm::StringRef path) override;
+
 protected:
   void Clear();
 
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9125ceca74a003..d2921f623bbefc 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6080,6 +6080,11 @@ bool Process::GetProcessInfo(ProcessInstanceInfo &info) {
   return platform_sp->GetProcessInfo(GetID(), info);
 }
 
+lldb_private::UUID Process::FindBuildId(const llvm::StringRef path) {
+  lldb_private::UUID invalid_uuid;
+  return invalid_uuid;
+}
+
 ThreadCollectionSP Process::GetHistoryThreads(lldb::addr_t addr) {
   ThreadCollectionSP threads;
 

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

[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Kazuki Sakamoto (splhack)


Changes

Addressing two issues on ELF core debugging

1. ProcessElfCore::FindBuidIdInCoreMemory reads wrong address for ELF header 
(fixed by @clayborg)
2. DynamicLoader does not use ProcessElfCore NT_FILE entries to get UUID. Add 
FindBuildId to get UUID from Process.

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


5 Files Affected:

- (modified) lldb/include/lldb/Target/Process.h (+2) 
- (modified) lldb/source/Core/DynamicLoader.cpp (+4) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+9-1) 
- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.h (+3) 
- (modified) lldb/source/Target/Process.cpp (+5) 


``diff
diff --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index b8c53a474ba6b9..2f0cf78f260c5a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -1380,6 +1380,8 @@ class Process : public 
std::enable_shared_from_this,
 
   virtual bool GetProcessInfo(ProcessInstanceInfo &info);
 
+  virtual lldb_private::UUID FindBuildId(const llvm::StringRef path);
+
   /// Get the exit status for a process.
   ///
   /// \return
diff --git a/lldb/source/Core/DynamicLoader.cpp 
b/lldb/source/Core/DynamicLoader.cpp
index 68d6ab0850853f..cc396e92721123 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP 
module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+// Process may have the UUID for the module, e.g. ELF core.
+module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());
+  }
 
   if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
 return module_sp;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..8ad6b83d77effe 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -281,6 +281,13 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
   }
 }
 
+UUID ProcessElfCore::FindBuildId(const llvm::StringRef path) {
+  for (NT_FILE_Entry &entry : m_nt_file_entries)
+if (path == entry.path)
+  return entry.uuid;
+  return UUID();
+}
+
 lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader() {
   if (m_dyld_up.get() == nullptr)
 m_dyld_up.reset(DynamicLoader::FindPlugin(
@@ -1034,7 +1041,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t 
address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
+const lldb::addr_t program_header_vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(program_header_vaddr, note_bytes.data(),
program_header.p_memsz, error);
 if (byte_read != program_header.p_memsz)
   continue;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
index 280c61ed376396..303f18249a976e 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
@@ -97,6 +97,9 @@ class ProcessElfCore : public lldb_private::PostMortemProcess 
{
 
   bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
 
+  // Returns the gnu uuid from matched NT_FILE entry
+  lldb_private::UUID FindBuildId(const llvm::StringRef path) override;
+
 protected:
   void Clear();
 
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9125ceca74a003..d2921f623bbefc 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6080,6 +6080,11 @@ bool Process::GetProcessInfo(ProcessInstanceInfo &info) {
   return platform_sp->GetProcessInfo(GetID(), info);
 }
 
+lldb_private::UUID Process::FindBuildId(const llvm::StringRef path) {
+  lldb_private::UUID invalid_uuid;
+  return invalid_uuid;
+}
+
 ThreadCollectionSP Process::GetHistoryThreads(lldb::addr_t addr) {
   ThreadCollectionSP threads;
 

``




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


[Lldb-commits] [lldb] [llvm] [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (PR #117071)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Zequan Wu (ZequanWu)


Changes

This is a reland of https://github.com/llvm/llvm-project/pull/112811. Fixed the 
bot breakage by running ld.lld explicitly.

---

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


14 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+14-7) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h (+8) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp (+37) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h (+17) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp (+25) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h (+6) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+9-27) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (-20) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h (-4) 
- (added) lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp 
(+36) 
- (modified) lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp (+125) 
- (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h (+2) 
- (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h (+21-12) 
- (modified) llvm/lib/DebugInfo/DWARF/DWARFDie.cpp (+9) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index d9bdeb560e1220..37c1132c1c9f9a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -45,6 +45,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -826,11 +827,11 @@ std::string 
DWARFASTParserClang::GetDIEClassTemplateParams(DWARFDIE die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
 return {};
 
-  TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos))
-return m_ast.PrintTemplateParams(template_param_infos);
-
-  return {};
+  std::string name;
+  llvm::raw_string_ostream os(name);
+  llvm::DWARFTypePrinter type_printer(os);
+  type_printer.appendAndTerminateTemplateParameters(die);
+  return name;
 }
 
 void DWARFASTParserClang::MapDeclDIEToDefDIE(
@@ -1618,9 +1619,9 @@ void DWARFASTParserClang::GetUniqueTypeNameAndDeclaration(
 case DW_TAG_structure_type:
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
-qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
+qualified_name.insert(0,
+  GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, class_union_struct_name);
   }
   parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
@@ -1673,6 +1674,12 @@ DWARFASTParserClang::ParseStructureLikeDIE(const 
SymbolContext &sc,
   if (attrs.name) {
 GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
 unique_decl);
+if (log) {
+  dwarf->GetObjectFile()->GetModule()->LogMessage(
+  log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
+  static_cast(this), die.GetID(), DW_TAG_value_to_name(tag),
+  unique_typename.AsCString());
+}
 if (UniqueDWARFASTType *unique_ast_entry_type =
 dwarf->GetUniqueDWARFASTTypeMap().Find(
 unique_typename, die, unique_decl, byte_size,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
index 235343d2271223..d92de658a49e89 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
@@ -24,9 +24,11 @@ class DWARFUnit;
 class DWARFDebugInfoEntry;
 class DWARFDeclContext;
 class SymbolFileDWARF;
+class DWARFFormValue;
 
 class DWARFBaseDIE {
 public:
+  using DWARFFormValue = dwarf::DWARFFormValue;
   DWARFBaseDIE() = default;
 
   DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
@@ -117,6 +119,12 @@ class DWARFBaseDIE {
   enum class Recurse : bool { no, yes };
   DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const;
 
+  // The following methods use LLVM naming convension in order to be are used 
by
+  // LLVM libraries.
+  dw_tag_t getTag() const { return Tag(); }
+
+  const char *getShortName() const { return GetName(); }
+
 protected:
   DWARFUnit *m_cu = nullptr;
   DWARFDebugInfoEntry *m_die = nullptr;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp

[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits


@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP 
module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+// Process may have the UUID for the module, e.g. ELF core.
+module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());

splhack wrote:

already. UUID operator bool() is IsValid()

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


[Lldb-commits] [lldb] Fix loading UUIDs from ELF headers. (PR #117028)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -281,6 +281,13 @@ void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
   }
 }
 
+UUID ProcessElfCore::FindBuildId(const llvm::StringRef path) {

clayborg wrote:

Change to overrite `GetModuleSpec` instead.

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP 
module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+// Process may have the UUID for the module, e.g. ELF core.
+module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());

clayborg wrote:

Use `Process::GetModuleSpec`:
```
ModuleSpec module_spec(file, target.GetArchitecture()); 
// Process may be able to augment the module_spec with UUID, e.g. ELF core.
m_process->GetModuleSpec(file, target.GetArchitecture(), module_spec);
```

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -97,6 +97,9 @@ class ProcessElfCore : public lldb_private::PostMortemProcess 
{
 
   bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
 
+  // Returns the gnu uuid from matched NT_FILE entry
+  lldb_private::UUID FindBuildId(const llvm::StringRef path) override;
+

clayborg wrote:

Change to overridew `GetModuleSpec`

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


[Lldb-commits] [lldb] [lldb] Improve rendering of inline diagnostics on the same column (PR #116727)

2024-11-20 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -130,6 +131,25 @@ void RenderDiagnosticDetails(Stream &stream,
   }
   stream << '\n';
 
+  // Reverse the order within groups of diagnostics that are on the same 
column.
+  auto group = [](const std::vector &details) {
+uint16_t column = 0;
+std::vector result, group;
+for (auto &d : details) {
+  if (d.source_location->column == column) {
+group.push_back(d);
+continue;
+  }
+  result.insert(result.end(), group.rbegin(), group.rend());
+  group.clear();
+  column = d.source_location->column;
+  group.push_back(d);
+}
+result.insert(result.end(), group.rbegin(), group.rend());
+return result;
+  };
+  remaining_details = group(remaining_details);
+

felipepiovezan wrote:

Oh, it's already been merged, nvm

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits

splhack wrote:

> The reading of build IDs is tracked in this PR: #117028

will rebase onto #117028

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits

clayborg wrote:

The reading of build IDs is tracked in this PR: 
https://github.com/llvm/llvm-project/pull/117028

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -1034,7 +1041,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t 
address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
+const lldb::addr_t program_header_vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(program_header_vaddr, note_bytes.data(),

clayborg wrote:

This fix is being tracked by https://github.com/llvm/llvm-project/pull/117028. 
Remove and make this dependent on that PR

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -1380,6 +1380,8 @@ class Process : public 
std::enable_shared_from_this,
 
   virtual bool GetProcessInfo(ProcessInstanceInfo &info);
 
+  virtual lldb_private::UUID FindBuildId(const llvm::StringRef path);
+

clayborg wrote:

There is already a function in Process.h that can do this:
```
  virtual bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec 
&arch, ModuleSpec &module_spec);
```
Remove this and use that call.


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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Greg Clayton via lldb-commits


@@ -6080,6 +6080,11 @@ bool Process::GetProcessInfo(ProcessInstanceInfo &info) {
   return platform_sp->GetProcessInfo(GetID(), info);
 }
 
+lldb_private::UUID Process::FindBuildId(const llvm::StringRef path) {
+  lldb_private::UUID invalid_uuid;
+  return invalid_uuid;
+}
+

clayborg wrote:

remove

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


[Lldb-commits] [lldb] [llvm] [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (PR #117071)

2024-11-20 Thread David Blaikie via lldb-commits

dwblaikie wrote:

if you're sending things for presubmit checks, but not for precommit review, 
please include the `skip-precommit-approval` label - but in this case it looks 
like you requested review, but then submitted without waiting for that review? 
Please don't do that, per: 
https://llvm.org/docs/CodeReview.html#code-review-workflow
> Specifically, once a patch is sent out for review, it needs an explicit 
> approval before it is committed. 


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


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

2024-11-20 Thread Adrian Prantl via lldb-commits


@@ -2809,6 +2956,374 @@ ValueObjectSP ValueObject::CastPointerType(const char 
*name, TypeSP &type_sp) {
   return valobj_sp;
 }
 
+lldb::addr_t ValueObject::GetLoadAddress() {
+  lldb::addr_t addr_value = LLDB_INVALID_ADDRESS;
+  if (auto target_sp = GetTargetSP()) {
+const bool scalar_is_load_address = true;
+AddressType addr_type;
+addr_value = GetAddressOf(scalar_is_load_address, &addr_type);
+if (addr_type == eAddressTypeFile) {
+  lldb::ModuleSP module_sp(GetModule());
+  if (!module_sp)
+addr_value = LLDB_INVALID_ADDRESS;
+  else {
+Address tmp_addr;
+module_sp->ResolveFileAddress(addr_value, tmp_addr);
+addr_value = tmp_addr.GetLoadAddress(target_sp.get());
+  }
+} else if (addr_type == eAddressTypeHost ||
+   addr_type == eAddressTypeInvalid)
+  addr_value = LLDB_INVALID_ADDRESS;
+  }
+  return addr_value;
+}
+
+llvm::Expected ValueObject::CastDerivedToBaseType(
+CompilerType type, const llvm::ArrayRef &base_type_indices) {
+  // Make sure the starting type and the target type are both valid for this
+  // type of cast; otherwise return the shared pointer to the original
+  // (unchanged) ValueObject.
+  if (!type.IsPointerType() && !type.IsReferenceType())
+return llvm::make_error(
+"Invalid target type: should be a pointer or a reference",
+llvm::inconvertibleErrorCode());
+
+  CompilerType start_type = GetCompilerType();
+  if (start_type.IsReferenceType())
+start_type = start_type.GetNonReferenceType();
+
+  auto target_record_type =
+  type.IsPointerType() ? type.GetPointeeType() : 
type.GetNonReferenceType();
+  auto start_record_type =
+  start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
+
+  if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
+return llvm::make_error(
+"Underlying start & target types should be record types",
+llvm::inconvertibleErrorCode());
+
+  if (target_record_type.CompareTypes(start_record_type))
+return llvm::make_error(
+"Underlying start & target types should be different",
+llvm::inconvertibleErrorCode());
+
+  if (base_type_indices.empty())
+return llvm::make_error(
+"Children sequence must be non-empty", llvm::inconvertibleErrorCode());
+
+  // Both the starting & target types are valid for the cast, and the list of
+  // base class indices is non-empty, so we can proceed with the cast.
+
+  lldb::TargetSP target = GetTargetSP();
+  // The `value` can be a pointer, but GetChildAtIndex works for pointers too.
+  lldb::ValueObjectSP inner_value = GetSP();
+
+  for (const uint32_t i : base_type_indices)
+// Create synthetic value if needed.
+inner_value =
+inner_value->GetChildAtIndex(i, /*can_create_synthetic*/ true);
+
+  // At this point type of `inner_value` should be the dereferenced target
+  // type.
+  CompilerType inner_value_type = inner_value->GetCompilerType();
+  if (type.IsPointerType()) {
+if (!inner_value_type.CompareTypes(type.GetPointeeType()))
+  return llvm::make_error(
+  "casted value doesn't match the desired type",
+  llvm::inconvertibleErrorCode());
+
+uintptr_t addr = inner_value->GetLoadAddress();
+llvm::StringRef name = "";
+ExecutionContext exe_ctx(target.get(), false);
+return ValueObject::CreateValueObjectFromAddress(name, addr, exe_ctx, type,
+ /* do deref */ false);
+  }
+
+  // At this point the target type should be a reference.
+  if (!inner_value_type.CompareTypes(type.GetNonReferenceType()))
+return llvm::make_error(
+"casted value doesn't match the desired type",
+llvm::inconvertibleErrorCode());
+
+  return lldb::ValueObjectSP(inner_value->Cast(type.GetNonReferenceType()));
+}
+
+llvm::Expected
+ValueObject::CastBaseToDerivedType(CompilerType type, uint64_t offset) {
+  // Make sure the starting type and the target type are both valid for this
+  // type of cast; otherwise return the shared pointer to the original
+  // (unchanged) ValueObject.
+  if (!type.IsPointerType() && !type.IsReferenceType())
+return llvm::make_error(
+"Invalid target type: should be a pointer or a reference",
+llvm::inconvertibleErrorCode());
+
+  CompilerType start_type = GetCompilerType();
+  if (start_type.IsReferenceType())
+start_type = start_type.GetNonReferenceType();
+
+  auto target_record_type =
+  type.IsPointerType() ? type.GetPointeeType() : 
type.GetNonReferenceType();
+  auto start_record_type =
+  start_type.IsPointerType() ? start_type.GetPointeeType() : start_type;
+
+  if (!target_record_type.IsRecordType() || !start_record_type.IsRecordType())
+return llvm::make_error(
+"Underlying start & target types should be record types",
+llvm::inconvertibleErrorCode());
+
+  if (target_record_type.CompareTypes(start_record_type))
+

[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Chad Smith via lldb-commits

cs01 wrote:

Thank you! Are there any unit tests that can exercise this? 

Or at least repro steps to generate a core with the elf headers in case any one 
wants to manually test.

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


[Lldb-commits] [lldb] [llvm] [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (PR #117071)

2024-11-20 Thread Zequan Wu via lldb-commits

https://github.com/ZequanWu created 
https://github.com/llvm/llvm-project/pull/117071

This is a reland of https://github.com/llvm/llvm-project/pull/112811. Fixed the 
bot breakage by running ld.lld explicitly.

>From 88aac9780b33410b0fb119c07eec6b4005149cf4 Mon Sep 17 00:00:00 2001
From: Zequan Wu 
Date: Wed, 20 Nov 2024 13:59:57 -0800
Subject: [PATCH 1/2] [lldb][dwarf] Compute fully qualified names on simplified
 template names with DWARFTypePrinter

---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  |  21 ++-
 .../Plugins/SymbolFile/DWARF/DWARFBaseDIE.h   |   8 ++
 .../Plugins/SymbolFile/DWARF/DWARFDIE.cpp |  37 ++
 .../Plugins/SymbolFile/DWARF/DWARFDIE.h   |  17 +++
 .../SymbolFile/DWARF/DWARFFormValue.cpp   |  25 
 .../Plugins/SymbolFile/DWARF/DWARFFormValue.h |   6 +
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  |  36 ++---
 .../TypeSystem/Clang/TypeSystemClang.cpp  |  20 ---
 .../TypeSystem/Clang/TypeSystemClang.h|   4 -
 .../DWARF/x86/simplified-template-names.cpp   |  36 +
 .../SymbolFile/DWARF/DWARFDIETest.cpp | 125 ++
 llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h  |   2 +
 .../llvm/DebugInfo/DWARF/DWARFTypePrinter.h   |  33 +++--
 llvm/lib/DebugInfo/DWARF/DWARFDie.cpp |   9 ++
 14 files changed, 309 insertions(+), 70 deletions(-)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index d9bdeb560e1220..37c1132c1c9f9a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -45,6 +45,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -826,11 +827,11 @@ std::string 
DWARFASTParserClang::GetDIEClassTemplateParams(DWARFDIE die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
 return {};
 
-  TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos))
-return m_ast.PrintTemplateParams(template_param_infos);
-
-  return {};
+  std::string name;
+  llvm::raw_string_ostream os(name);
+  llvm::DWARFTypePrinter type_printer(os);
+  type_printer.appendAndTerminateTemplateParameters(die);
+  return name;
 }
 
 void DWARFASTParserClang::MapDeclDIEToDefDIE(
@@ -1618,9 +1619,9 @@ void DWARFASTParserClang::GetUniqueTypeNameAndDeclaration(
 case DW_TAG_structure_type:
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
-qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
+qualified_name.insert(0,
+  GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, class_union_struct_name);
   }
   parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
@@ -1673,6 +1674,12 @@ DWARFASTParserClang::ParseStructureLikeDIE(const 
SymbolContext &sc,
   if (attrs.name) {
 GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
 unique_decl);
+if (log) {
+  dwarf->GetObjectFile()->GetModule()->LogMessage(
+  log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
+  static_cast(this), die.GetID(), DW_TAG_value_to_name(tag),
+  unique_typename.AsCString());
+}
 if (UniqueDWARFASTType *unique_ast_entry_type =
 dwarf->GetUniqueDWARFASTTypeMap().Find(
 unique_typename, die, unique_decl, byte_size,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
index 235343d2271223..d92de658a49e89 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
@@ -24,9 +24,11 @@ class DWARFUnit;
 class DWARFDebugInfoEntry;
 class DWARFDeclContext;
 class SymbolFileDWARF;
+class DWARFFormValue;
 
 class DWARFBaseDIE {
 public:
+  using DWARFFormValue = dwarf::DWARFFormValue;
   DWARFBaseDIE() = default;
 
   DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
@@ -117,6 +119,12 @@ class DWARFBaseDIE {
   enum class Recurse : bool { no, yes };
   DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const;
 
+  // The following methods use LLVM naming convension in order to be are used 
by
+  // LLVM libraries.
+  dw_tag_t getTag() const { return Tag(); }
+
+  const char *getShortName() const { return GetName(); }
+
 protected:
   DWARFUnit *m_cu = nullptr;
   DWARFDebugInfoEntry *m_die = nullptr;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 
b/lldb/source/Plugins/SymbolFile/DW

[Lldb-commits] [lldb] [llvm] [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (PR #112811)

2024-11-20 Thread Zequan Wu via lldb-commits

ZequanWu wrote:

> This patch broke the lldb incremental bot on greendragon
> 
> https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/15486/
> 
>  TEST 'lldb-shell :: 
> SymbolFile/DWARF/x86/simplified-template-names.cpp' FAILED 
>  Exit Code: 1
> 
> ## Command Output (stderr):
> RUN: at line 7: 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 
> --driver-mode=g++ --target=specify-a-target-or-use-a-_host-substitution 
> --target=x86_64-pc-linux -g -gsimple-template-names 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp
>  -o 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/simplified-template-names.cpp.tmp
> 
> * 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang 
> --driver-mode=g++ --target=specify-a-target-or-use-a-_host-substitution 
> --target=x86_64-pc-linux -g -gsimple-template-names 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp
>  -o 
> /Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/tools/lldb/test/Shell/SymbolFile/DWARF/x86/Output/simplified-template-names.cpp.tmp
>   ld: warning: -m is obsolete
>   ld: unknown option: --hash-style=gnu
>   clang: error: linker command failed with exit code 1 (use -v to see 
> invocation)

I should explicitly call ld.lld. Relanded 
[here](https://github.com/llvm/llvm-project/commit/f06c187799d910fd3ac3e9106397e5eecff9f265)

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Sim Sun via lldb-commits


@@ -157,6 +157,10 @@ DynamicLoader::GetSectionListFromModule(const ModuleSP 
module) const {
 ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec &file) {
   Target &target = m_process->GetTarget();
   ModuleSpec module_spec(file, target.GetArchitecture());
+  if (UUID uuid = m_process->FindBuildId(file.GetPath())) {
+// Process may have the UUID for the module, e.g. ELF core.
+module_spec.GetUUID().SetFromStringRef(uuid.GetAsString());

simpleton wrote:

maybe check the uuid.IsValid before set?

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


[Lldb-commits] [lldb] Rename GetLanguageInfo to GetLanguageSpecificData (PR #117012)

2024-11-20 Thread Jonas Devlieghere via lldb-commits

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


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


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

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)


Changes

I backed this out due to a problem on one of the bots that myself and others 
have problems reproducing locally. I'd like to try to land it again, at least 
to gain more information.

Summary:
This improves the performance of ObjectFileMacho::ParseSymtab by removing eager 
and expensive work in favor of doing it later in a less-expensive fashion.

Experiment:
My goal was to understand LLDB's startup time.
First, I produced a Debug build of LLDB (no dSYM) and a Release+NoAsserts build 
of LLDB. The Release build debugged the Debug build as it debugged a small C++ 
program. I found that ObjectFileMachO::ParseSymtab accounted for somewhere 
between 1.2 and 1.3 seconds consistently. After applying this change, I 
consistently measured a reduction of approximately 100ms, putting the time 
closer to 1.1s and 1.2s on average.

Background:
ObjectFileMachO::ParseSymtab will incrementally create symbols by parsing nlist 
entries from the symtab section of a MachO binary. As it does this, it eagerly 
tries to determine the size of symbols (e.g. how long a function is) using 
LC_FUNCTION_STARTS data (or eh_frame if LC_FUNCTION_STARTS is unavailable). 
Concretely, this is done by performing a binary search on the function starts 
array and calculating the distance to the next function or the end of the 
section (whichever is smaller).

However, this work is unnecessary for 2 reasons:
1. If you have debug symbol entries (i.e. STABs), the size of a function is 
usually stored right after the function's entry. Performing this work right 
before parsing the next entry is unnecessary work.
2. Calculating symbol sizes for symbols of size 0 is already performed in 
`Symtab::InitAddressIndexes` after all the symbols are added to the Symtab. It 
also does this more efficiently by walking over a list of symbols sorted by 
address, so the work to calculate the size per symbol is constant instead of 
O(log n).

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


1 Files Affected:

- (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (-63) 


``diff
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index b542e237f023d4..85edf4bd5494ae 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,7 +3768,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
-  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4354,47 +4353,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
-if (symbol_byte_size == 0 && function_starts_count > 0) {
-  addr_t symbol_lookup_file_addr = nlist.n_value;
-  // Do an exact address match for non-ARM addresses, else get the
-  // closest since the symbol might be a thumb symbol which has an
-  // address with bit zero set.
-  FunctionStarts::Entry *func_start_entry =
-  function_starts.FindEntry(symbol_lookup_file_addr, !is_arm);
-  if (is_arm && func_start_entry) {
-// Verify that the function start address is the symbol address
-// (ARM) or the symbol address + 1 (thumb).
-if (func_start_entry->addr != symbol_lookup_file_addr &&
-func_start_entry->addr != (symbol_lookup_file_addr + 1)) {
-  // Not the right entry, NULL it out...
-  func_start_entry = nullptr;
-}
-  }
-  if (func_start_entry) {
-func_start_entry->data = true;
-
-addr_t symbol_file_addr = func_start_entry->addr;
-if (is_arm)
-  symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-
-const FunctionStarts::Entry *next_func_start_entry =
-function_starts.FindNextEntry(func_start_entry);
-const addr_t section_end_file_addr =
-section_file_addr + symbol_section->GetByteSize();
-if (next_func_start_entry) {
-  addr_t next_symbol_file_addr = next_func_start_entry->addr;
-  // Be sure the clear the Thumb address bit when we calculate the
-  // size from the current and next address
-  if (is_arm)
-next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
-  symbol_byte_size = std::min(
-  next_symbol_file_addr - symbol_file_addr,
-  section_end_file_addr - symbol_file_addr);
-} else {
-  symbol_byte_size = section_end_file_addr - symbol_file_addr;
-}
- 

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

2024-11-20 Thread Alex Langford via lldb-commits

https://github.com/bulbazord created 
https://github.com/llvm/llvm-project/pull/117079

I backed this out due to a problem on one of the bots that myself and others 
have problems reproducing locally. I'd like to try to land it again, at least 
to gain more information.

Summary:
This improves the performance of ObjectFileMacho::ParseSymtab by removing eager 
and expensive work in favor of doing it later in a less-expensive fashion.

Experiment:
My goal was to understand LLDB's startup time.
First, I produced a Debug build of LLDB (no dSYM) and a Release+NoAsserts build 
of LLDB. The Release build debugged the Debug build as it debugged a small C++ 
program. I found that ObjectFileMachO::ParseSymtab accounted for somewhere 
between 1.2 and 1.3 seconds consistently. After applying this change, I 
consistently measured a reduction of approximately 100ms, putting the time 
closer to 1.1s and 1.2s on average.

Background:
ObjectFileMachO::ParseSymtab will incrementally create symbols by parsing nlist 
entries from the symtab section of a MachO binary. As it does this, it eagerly 
tries to determine the size of symbols (e.g. how long a function is) using 
LC_FUNCTION_STARTS data (or eh_frame if LC_FUNCTION_STARTS is unavailable). 
Concretely, this is done by performing a binary search on the function starts 
array and calculating the distance to the next function or the end of the 
section (whichever is smaller).

However, this work is unnecessary for 2 reasons:
1. If you have debug symbol entries (i.e. STABs), the size of a function is 
usually stored right after the function's entry. Performing this work right 
before parsing the next entry is unnecessary work.
2. Calculating symbol sizes for symbols of size 0 is already performed in 
`Symtab::InitAddressIndexes` after all the symbols are added to the Symtab. It 
also does this more efficiently by walking over a list of symbols sorted by 
address, so the work to calculate the size per symbol is constant instead of 
O(log n).

>From 167e57fa90354390ae7833a2550e6f8ffbc2c649 Mon Sep 17 00:00:00 2001
From: Alex Langford 
Date: Fri, 13 Sep 2024 10:33:43 -0700
Subject: [PATCH] [lldb] Do not use LC_FUNCTION_STARTS data to determine symbol
 size as symbols are created (#106791)

Summary:
This improves the performance of ObjectFileMacho::ParseSymtab by
removing eager and expensive work in favor of doing it later in a
less-expensive fashion.

Experiment:
My goal was to understand LLDB's startup time.
First, I produced a Debug build of LLDB (no dSYM) and a
Release+NoAsserts build of LLDB. The Release build debugged the Debug
build as it debugged a small C++ program. I found that
ObjectFileMachO::ParseSymtab accounted for somewhere between 1.2 and 1.3
seconds consistently. After applying this change, I consistently
measured a reduction of approximately 100ms, putting the time closer to
1.1s and 1.2s on average.

Background:
ObjectFileMachO::ParseSymtab will incrementally create symbols by
parsing nlist entries from the symtab section of a MachO binary. As it
does this, it eagerly tries to determine the size of symbols (e.g. how
long a function is) using LC_FUNCTION_STARTS data (or eh_frame if
LC_FUNCTION_STARTS is unavailable). Concretely, this is done by
performing a binary search on the function starts array and calculating
the distance to the next function or the end of the section (whichever
is smaller).

However, this work is unnecessary for 2 reasons:
1. If you have debug symbol entries (i.e. STABs), the size of a function
is usually stored right after the function's entry. Performing this work
right before parsing the next entry is unnecessary work.
2. Calculating symbol sizes for symbols of size 0 is already performed
in `Symtab::InitAddressIndexes` after all the symbols are added to the
Symtab. It also does this more efficiently by walking over a list of
symbols sorted by address, so the work to calculate the size per symbol
is constant instead of O(log n).
---
 .../ObjectFile/Mach-O/ObjectFileMachO.cpp | 63 ---
 1 file changed, 63 deletions(-)

diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp 
b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index b542e237f023d4..85edf4bd5494ae 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -3768,7 +3768,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   SymbolType type = eSymbolTypeInvalid;
   SectionSP symbol_section;
-  lldb::addr_t symbol_byte_size = 0;
   bool add_nlist = true;
   bool is_gsym = false;
   bool demangled_is_synthesized = false;
@@ -4354,47 +4353,6 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
 
   if (symbol_section) {
 const addr_t section_file_addr = symbol_section->GetFileAddress();
-if (symbol_byte_size == 0 && function_starts_count > 0) {
-  addr_t symbol_lookup_file_addr = nlist.n_value;

[Lldb-commits] [lldb] f06c187 - [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (#117071)

2024-11-20 Thread via lldb-commits

Author: Zequan Wu
Date: 2024-11-20T17:19:35-05:00
New Revision: f06c187799d910fd3ac3e9106397e5eecff9f265

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

LOG:  [lldb][dwarf] Compute fully qualified names on simplified template names 
with DWARFTypePrinter (#117071)

This is a reland of https://github.com/llvm/llvm-project/pull/112811.
Fixed the bot breakage by running ld.lld explicitly.

Added: 
lldb/test/Shell/SymbolFile/DWARF/x86/simplified-template-names.cpp

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index d9bdeb560e1220..37c1132c1c9f9a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -45,6 +45,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/DebugInfo/DWARF/DWARFTypePrinter.h"
 #include "llvm/Demangle/Demangle.h"
 
 #include 
@@ -826,11 +827,11 @@ std::string 
DWARFASTParserClang::GetDIEClassTemplateParams(DWARFDIE die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
 return {};
 
-  TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos))
-return m_ast.PrintTemplateParams(template_param_infos);
-
-  return {};
+  std::string name;
+  llvm::raw_string_ostream os(name);
+  llvm::DWARFTypePrinter type_printer(os);
+  type_printer.appendAndTerminateTemplateParameters(die);
+  return name;
 }
 
 void DWARFASTParserClang::MapDeclDIEToDefDIE(
@@ -1618,9 +1619,9 @@ void DWARFASTParserClang::GetUniqueTypeNameAndDeclaration(
 case DW_TAG_structure_type:
 case DW_TAG_union_type: {
   if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) 
{
-qualified_name.insert(
-0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
+qualified_name.insert(0,
+  GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, class_union_struct_name);
   }
   parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
@@ -1673,6 +1674,12 @@ DWARFASTParserClang::ParseStructureLikeDIE(const 
SymbolContext &sc,
   if (attrs.name) {
 GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
 unique_decl);
+if (log) {
+  dwarf->GetObjectFile()->GetModule()->LogMessage(
+  log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
+  static_cast(this), die.GetID(), DW_TAG_value_to_name(tag),
+  unique_typename.AsCString());
+}
 if (UniqueDWARFASTType *unique_ast_entry_type =
 dwarf->GetUniqueDWARFASTTypeMap().Find(
 unique_typename, die, unique_decl, byte_size,

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
index 235343d2271223..d92de658a49e89 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h
@@ -24,9 +24,11 @@ class DWARFUnit;
 class DWARFDebugInfoEntry;
 class DWARFDeclContext;
 class SymbolFileDWARF;
+class DWARFFormValue;
 
 class DWARFBaseDIE {
 public:
+  using DWARFFormValue = dwarf::DWARFFormValue;
   DWARFBaseDIE() = default;
 
   DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
@@ -117,6 +119,12 @@ class DWARFBaseDIE {
   enum class Recurse : bool { no, yes };
   DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const;
 
+  // The following methods use LLVM naming convension in order to be are used 
by
+  // LLVM libraries.
+  dw_tag_t getTag() const { return Tag(); }
+
+  const char *getShortName() const { return GetName(); }
+
 protected:
   DWARFUnit *m_cu = nullptr;
   DWARFDebugInfoEntry *m_die = nullptr;

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp 

[Lldb-commits] [lldb] [llvm] [lldb][dwarf] Compute fully qualified names on simplified template names with DWARFTypePrinter (PR #117071)

2024-11-20 Thread Zequan Wu via lldb-commits

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


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

2024-11-20 Thread Jennifer Phillips via lldb-commits


@@ -4332,6 +4339,232 @@ void request_setInstructionBreakpoints(const 
llvm::json::Object &request) {
   g_dap.SendJSON(llvm::json::Value(std::move(response)));
 }
 
+// "ReadMemoryRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Reads bytes from memory at the provided location.\n
+// Clients should only call this request if the corresponding capability
+// `supportsReadMemoryRequest` is true.",
+// "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "readMemory" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/ReadMemoryArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "ReadMemoryArguments": {
+//   "type": "object",
+//   "description": "Arguments for `readMemory` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location from which data
+//   should be read."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before reading data. Can be negative."
+// },
+// "count": {
+//   "type": "integer",
+//   "description": "Number of bytes to read at the specified location and
+//   offset."
+// }
+//   },
+//   "required": [ "memoryReference", "count" ]
+// },
+// "ReadMemoryResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `readMemory` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//   "address": {
+// "type": "string",
+// "description": "The address of the first byte of data returned.
+// \nTreated as a hex value if prefixed with `0x`, or as a decimal
+// value otherwise."
+//   },
+//   "unreadableBytes": {
+// "type": "integer",
+// "description": "The number of unreadable bytes encountered after
+// the last successfully read byte.\nThis can be used to determine
+// the number of bytes that should be skipped before a subsequent
+// `readMemory` request succeeds."
+//   },
+//   "data": {
+// "type": "string",
+// "description": "The bytes read from memory, encoded using
+// base64. If the decoded length of `data` is less than the
+// requested `count` in the original `readMemory` request, and
+// `unreadableBytes` is zero or omitted, then the client should
+// assume it's reached the end of readable memory."
+//   }
+// },
+// "required": [ "address" ]
+//   }
+// }
+//   }]
+// },
+void request_readMemory(const llvm::json::Object &request) {
+  llvm::json::Object response;
+  llvm::json::Array response_readMemory;
+  llvm::json::Object body;
+  lldb::SBError error;
+  FillResponse(request, response);
+
+  auto arguments = request.getObject("arguments");
+  llvm::StringRef memoryReference = GetString(arguments, "memoryReference");
+  const size_t count = GetUnsigned(arguments, "count", 0);
+  const auto offset = GetSigned(arguments, "offset", 0);
+
+  lldb::addr_t address;
+  memoryReference.getAsInteger(0, address);
+  lldb::addr_t address_offset = address + offset;
+  // address as string
+  std::string address_offset_str(std::to_string(address_offset));
+
+  // make storage for the memory to read
+  //  need to use a vector because VC++ 2019 errors out on char buffer[count]

jennphilqc wrote:

removed justification

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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/2] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[Lldb-commits] [lldb] Fix loading UUIDs from ELF headers. (PR #117028)

2024-11-20 Thread Greg Clayton via lldb-commits

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

A previous patch added the ability to load UUID from ELF headers using the 
program header and finding PT_NOTE entries. The fix would attempt to read the 
data for the PT_NOTE from memory, but it didn't slide the address so it ended 
up only working for the main executable if it wasn't moved in memory. This 
patch slides the address and adds logging.

>From 37eccb509ea6468879cf530c6952aab7adec4001 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Wed, 20 Nov 2024 10:55:12 -0800
Subject: [PATCH] Fix loading UUIDs from ELF headers.

A previous patch added the ability to load UUID from ELF headers using the 
program header and finding PT_NOTE entries. The fix would attempt to read the 
data for the PT_NOTE from memory, but it didn't slide the address so it ended 
up only working for the main executable if it wasn't moved in memory. This 
patch slides the address and adds logging.
---
 .../Process/elf-core/ProcessElfCore.cpp   | 20 ++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..e58c06b9bd333c 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -224,7 +224,7 @@ Status ProcessElfCore::DoLoadCore() {
   ArchSpec core_arch(m_core_module_sp->GetArchitecture());
   target_arch.MergeFrom(core_arch);
   GetTarget().SetArchitecture(target_arch);
- 
+
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
   // Ensure we found at least one thread that was stopped on a signal.
@@ -276,8 +276,13 @@ Status ProcessElfCore::DoLoadCore() {
 }
 
 void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
+  Log *log = GetLog(LLDBLog::Process);
   for (NT_FILE_Entry &entry : m_nt_file_entries) {
 entry.uuid = FindBuidIdInCoreMemory(entry.start);
+if (log && entry.uuid.IsValid())
+  LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
+__FUNCTION__, entry.start, entry.uuid.GetAsString().c_str(),
+entry.path.c_str());
   }
 }
 
@@ -875,7 +880,7 @@ llvm::Error 
ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef notes) {
 /// - NT_SIGINFO - Information about the signal that terminated the process
 /// - NT_AUXV - Process auxiliary vector
 /// - NT_FILE - Files mapped into memory
-/// 
+///
 /// Additionally, for each thread in the process the core file will contain at
 /// least the NT_PRSTATUS note, containing the thread id and general purpose
 /// registers. It may include additional notes for other register sets 
(floating
@@ -1034,15 +1039,20 @@ UUID 
ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
-   program_header.p_memsz, error);
+// We need to slide the address of the p_vaddr as these values don't get
+// relocated in memory.
+const lldb::addr_t vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz,
+   error);
 if (byte_read != program_header.p_memsz)
   continue;
 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
GetByteOrder(), addr_size);
 auto notes_or_error = parseSegment(segment_data);
-if (!notes_or_error)
+if (!notes_or_error) {
+  llvm::consumeError(notes_or_error.takeError());
   return invalid_uuid;
+}
 for (const CoreNote ¬e : *notes_or_error) {
   if (note.info.n_namesz == 4 &&
   note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&

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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

bwendling wrote:

> The main thing I’m concerned about here is that I feel like there ought to be 
> a better way of doing this than checking for and disallowing it in every 
> place where we can have a subexpression in C.

Yeah, but we don't have such a method, partially due to the languages Clang 
supports. How is this any different from the vast array of other features that 
are checked in Sema?

> Also, if we’re doing it this way, then the check should definitely be 
> factored out into a function in `Sema`.

Okay.

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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/4] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[Lldb-commits] [lldb] [lldb] Make sure completions don't end with newlines (PR #117054)

2024-11-20 Thread Jonas Devlieghere via lldb-commits

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

The logic that prints completions and their descriptions assumes neither the 
completion itself nor the description ends with a newline. I considered making 
this an assert, but decided against it as completions can indirectly come from 
user input (e.g. oddly crafted names). Instead, avoid the potential for 
mistakes by defensively stripping them.

>From e5dfed25b6dd1523a1818fe82a921537956d0693 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Wed, 20 Nov 2024 13:22:09 -0800
Subject: [PATCH] [lldb] Make sure completions don't end with newlines

The logic that prints completions and their descriptions assumes neither
the completion itself nor the description ends with a newline. I
considered making this an assert, but decided against it as completions
can indirectly come from user input (e.g. oddly crafted names). Instead,
avoid the potential for mistakes by defensively stripping them.
---
 lldb/include/lldb/Utility/CompletionRequest.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/Utility/CompletionRequest.h 
b/lldb/include/lldb/Utility/CompletionRequest.h
index 650158a197dbd9..865d6db5762984 100644
--- a/lldb/include/lldb/Utility/CompletionRequest.h
+++ b/lldb/include/lldb/Utility/CompletionRequest.h
@@ -52,8 +52,8 @@ class CompletionResult {
   public:
 Completion(llvm::StringRef completion, llvm::StringRef description,
CompletionMode mode)
-: m_completion(completion.str()), m_descripton(description.str()),
-  m_mode(mode) {}
+: m_completion(completion.rtrim().str()),
+  m_descripton(description.rtrim().str()), m_mode(mode) {}
 const std::string &GetCompletion() const { return m_completion; }
 const std::string &GetDescription() const { return m_descripton; }
 CompletionMode GetMode() const { return m_mode; }

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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

bwendling wrote:

> > Could you point to a place in the code where it creates a placeholder?
> 
> I mean, e.g. `CheckPointerToMemberOperands()` can return `BoundMemberTy` as 
> the type of a `.*` expression, and `CreateBuiltinMatrixSubscriptExpr()` 
> creates a `MatrixSubscriptExpr` with type `IncompleteMatrixIdxTy` if that’s 
> what you’re asking.

`CheckPointerToMemberOperands` only returns the placeholder type. The matrix 
one isn't a `CallExpr`, so it doesn't help me much. Anyway, this is irrelevant 
now as I'm going another way.

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


[Lldb-commits] [lldb] [lldb] Make sure completions don't end with newlines (PR #117054)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

The logic that prints completions and their descriptions assumes neither the 
completion itself nor the description ends with a newline. I considered making 
this an assert, but decided against it as completions can indirectly come from 
user input (e.g. oddly crafted names). Instead, avoid the potential for 
mistakes by defensively stripping them.

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


1 Files Affected:

- (modified) lldb/include/lldb/Utility/CompletionRequest.h (+2-2) 


``diff
diff --git a/lldb/include/lldb/Utility/CompletionRequest.h 
b/lldb/include/lldb/Utility/CompletionRequest.h
index 650158a197dbd9..865d6db5762984 100644
--- a/lldb/include/lldb/Utility/CompletionRequest.h
+++ b/lldb/include/lldb/Utility/CompletionRequest.h
@@ -52,8 +52,8 @@ class CompletionResult {
   public:
 Completion(llvm::StringRef completion, llvm::StringRef description,
CompletionMode mode)
-: m_completion(completion.str()), m_descripton(description.str()),
-  m_mode(mode) {}
+: m_completion(completion.rtrim().str()),
+  m_descripton(description.rtrim().str()), m_mode(mode) {}
 const std::string &GetCompletion() const { return m_completion; }
 const std::string &GetDescription() const { return m_descripton; }
 CompletionMode GetMode() const { return m_mode; }

``




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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/6] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/7] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[Lldb-commits] [lldb] 2c63e6d - [lldb] Fix double newline typo in PrintCompletion

2024-11-20 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2024-11-20T10:18:08-08:00
New Revision: 2c63e6d94261d6c9d045523f37f350f9e60ed35b

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

LOG: [lldb] Fix double newline typo in PrintCompletion

While addressing code review feedback I accidentally introduced a
spurious second newline.

Added: 


Modified: 
lldb/source/Host/common/Editline.cpp

Removed: 




diff  --git a/lldb/source/Host/common/Editline.cpp 
b/lldb/source/Host/common/Editline.cpp
index 1dc1c3fc180848..c9e890304ae1ec 100644
--- a/lldb/source/Host/common/Editline.cpp
+++ b/lldb/source/Host/common/Editline.cpp
@@ -953,7 +953,7 @@ PrintCompletion(FILE *output_file,
 } else {
   // If the completion doesn't fit on the screen, print ellipsis and don't
   // bother with the description.
-  fprintf(output_file, "%.*s...\n\n",
+  fprintf(output_file, "%.*s...\n",
   static_cast(max_length - padding_length - ellipsis_length),
   c.GetCompletion().c_str());
   continue;



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


[Lldb-commits] [lldb] Fix loading UUIDs from ELF headers. (PR #117028)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Greg Clayton (clayborg)


Changes

A previous patch added the ability to load UUID from ELF headers using the 
program header and finding PT_NOTE entries. The fix would attempt to read the 
data for the PT_NOTE from memory, but it didn't slide the address so it ended 
up only working for the main executable if it wasn't moved in memory. This 
patch slides the address and adds logging.

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


1 Files Affected:

- (modified) lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp (+15-5) 


``diff
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..e58c06b9bd333c 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -224,7 +224,7 @@ Status ProcessElfCore::DoLoadCore() {
   ArchSpec core_arch(m_core_module_sp->GetArchitecture());
   target_arch.MergeFrom(core_arch);
   GetTarget().SetArchitecture(target_arch);
- 
+
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
   // Ensure we found at least one thread that was stopped on a signal.
@@ -276,8 +276,13 @@ Status ProcessElfCore::DoLoadCore() {
 }
 
 void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
+  Log *log = GetLog(LLDBLog::Process);
   for (NT_FILE_Entry &entry : m_nt_file_entries) {
 entry.uuid = FindBuidIdInCoreMemory(entry.start);
+if (log && entry.uuid.IsValid())
+  LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
+__FUNCTION__, entry.start, entry.uuid.GetAsString().c_str(),
+entry.path.c_str());
   }
 }
 
@@ -875,7 +880,7 @@ llvm::Error 
ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef notes) {
 /// - NT_SIGINFO - Information about the signal that terminated the process
 /// - NT_AUXV - Process auxiliary vector
 /// - NT_FILE - Files mapped into memory
-/// 
+///
 /// Additionally, for each thread in the process the core file will contain at
 /// least the NT_PRSTATUS note, containing the thread id and general purpose
 /// registers. It may include additional notes for other register sets 
(floating
@@ -1034,15 +1039,20 @@ UUID 
ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
-   program_header.p_memsz, error);
+// We need to slide the address of the p_vaddr as these values don't get
+// relocated in memory.
+const lldb::addr_t vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz,
+   error);
 if (byte_read != program_header.p_memsz)
   continue;
 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
GetByteOrder(), addr_size);
 auto notes_or_error = parseSegment(segment_data);
-if (!notes_or_error)
+if (!notes_or_error) {
+  llvm::consumeError(notes_or_error.takeError());
   return invalid_uuid;
+}
 for (const CoreNote ¬e : *notes_or_error) {
   if (note.info.n_namesz == 4 &&
   note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&

``




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


[Lldb-commits] [lldb] Fix loading UUIDs from ELF headers. (PR #117028)

2024-11-20 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 012dd8be4b5a4c00deb22345c630990f160b3aa3 
37eccb509ea6468879cf530c6952aab7adec4001 --extensions cpp -- 
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index e58c06b9bd..cd95b00046 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -1042,8 +1042,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t 
address) {
 // We need to slide the address of the p_vaddr as these values don't get
 // relocated in memory.
 const lldb::addr_t vaddr = program_header.p_vaddr + address;
-byte_read = ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz,
-   error);
+byte_read =
+ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
 if (byte_read != program_header.p_memsz)
   continue;
 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),

``




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


[Lldb-commits] [lldb] 6473a36 - Make SBFrame::GetLanguageSpecificData() const (#117019)

2024-11-20 Thread via lldb-commits

Author: Adrian Prantl
Date: 2024-11-20T10:07:23-08:00
New Revision: 6473a36edc571cf0734a2e8d4354e332efb170e9

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

LOG: Make SBFrame::GetLanguageSpecificData() const (#117019)

One last diff I missed between Swift and LLVM.

Added: 


Modified: 
lldb/include/lldb/API/SBFrame.h
lldb/source/API/SBFrame.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index 629d4e5bc61f46..3635ee5a537ad8 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageSpecificData();
+  SBStructuredData GetLanguageSpecificData() const;
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables

diff  --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 5c735dd35e1cf3..2300bec4d685d2 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageSpecificData() {
+SBStructuredData SBFrame::GetLanguageSpecificData() const {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;



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


[Lldb-commits] [lldb] [lldb] Fix inline function resolution for discontinuous functions (PR #116777)

2024-11-20 Thread Jason Molenda via lldb-commits

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

Sorry for the delay, I read the patch quickly yesterday without reading the 
description and was a little confused.  Read the description and seeing the 
test case, I see what this is doing.  Looks good to me.  I didn't realize the 
discontiguous regions would be split into different sections with this codegen 
pattern.

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


[Lldb-commits] [lldb] 8f8dced - Rename GetLanguageInfo to GetLanguageSpecificData (#117012)

2024-11-20 Thread via lldb-commits

Author: Adrian Prantl
Date: 2024-11-20T09:43:57-08:00
New Revision: 8f8dcedb007c21412956208e524ff245c0ba5f58

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

LOG: Rename GetLanguageInfo to GetLanguageSpecificData (#117012)

Unbeknownst to me the Swift LLDB branch already had an almost identical
API with this name, so it makes sense to merge the two.

Added: 
lldb/test/API/lang/objc/languageinfo/TestObjCLanguageSpecificData.py

Modified: 
lldb/include/lldb/API/SBFrame.h
lldb/include/lldb/Target/LanguageRuntime.h
lldb/include/lldb/Target/StackFrame.h
lldb/source/API/SBFrame.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
lldb/source/Target/LanguageRuntime.cpp
lldb/source/Target/StackFrame.cpp

Removed: 
lldb/test/API/lang/objc/languageinfo/TestObjCLanguageInfo.py



diff  --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index e1ff217767cb98..629d4e5bc61f46 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageInfo();
+  SBStructuredData GetLanguageSpecificData();
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables

diff  --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index 4f4d426eaa1dab..4a0214b04e235e 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -244,7 +244,7 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
   /// Language runtime plugins can use this API to report
   /// language-specific runtime information about this compile unit,
   /// such as additional language version details or feature flags.
-  virtual StructuredData::ObjectSP GetLanguageInfo(SymbolContext sc);
+  virtual StructuredData::ObjectSP GetLanguageSpecificData(SymbolContext sc);
 
 protected:
   // The static GetRuntimeUnwindPlan method above is only implemented in the

diff  --git a/lldb/include/lldb/Target/StackFrame.h 
b/lldb/include/lldb/Target/StackFrame.h
index 5e82657706339c..3f51c9a7f22f09 100644
--- a/lldb/include/lldb/Target/StackFrame.h
+++ b/lldb/include/lldb/Target/StackFrame.h
@@ -412,7 +412,7 @@ class StackFrame : public ExecutionContextScope,
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  StructuredData::ObjectSP GetLanguageInfo();
+  StructuredData::ObjectSP GetLanguageSpecificData();
 
   /// Get the frame's demangled name.
   ///

diff  --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index d17bb5cc146086..5c735dd35e1cf3 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageInfo() {
+SBStructuredData SBFrame::GetLanguageSpecificData() {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;
@@ -1165,7 +1165,7 @@ SBStructuredData SBFrame::GetLanguageInfo() {
   if (!frame)
 return sb_data;
 
-  StructuredData::ObjectSP data(frame->GetLanguageInfo());
+  StructuredData::ObjectSP data(frame->GetLanguageSpecificData());
   sb_data.m_impl_up->SetObjectSP(data);
   return sb_data;
 }

diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 7298ab0e7336bf..0083b499656979 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -3398,7 +3398,8 @@ std::optional 
AppleObjCRuntimeV2::GetSharedCacheImageHeaderVersion() {
   return std::nullopt;
 }
 
-StructuredData::ObjectSP AppleObjCRuntimeV2::GetLanguageInfo(SymbolContext sc) 
{
+StructuredData::ObjectSP
+AppleObjCRuntimeV2::GetLanguageSpecificData(SymbolContext sc) {
   auto dict_up = std::make_unique();
   dict_up->AddItem("Objective-C runtime version",
std::make_unique(2));

diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRunt

[Lldb-commits] [lldb] Rename GetLanguageInfo to GetLanguageSpecificData (PR #117012)

2024-11-20 Thread Adrian Prantl via lldb-commits

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


[Lldb-commits] [lldb] Make SBFrame::GetLanguageSpecificData() const (PR #117019)

2024-11-20 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] Make SBFrame::GetLanguageSpecificData() const (PR #117019)

2024-11-20 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl created 
https://github.com/llvm/llvm-project/pull/117019

One last diff I missed between Swift and LLVM.

>From a91cd8e02b41a3028df671806eb78cb7c5251546 Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 20 Nov 2024 09:58:52 -0800
Subject: [PATCH] Make SBFrame::GetLanguageSpecificData() const

---
 lldb/include/lldb/API/SBFrame.h | 2 +-
 lldb/source/API/SBFrame.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index 629d4e5bc61f46..3635ee5a537ad8 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageSpecificData();
+  SBStructuredData GetLanguageSpecificData() const;
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 5c735dd35e1cf3..2300bec4d685d2 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageSpecificData() {
+SBStructuredData SBFrame::GetLanguageSpecificData() const {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;

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


[Lldb-commits] [lldb] Make SBFrame::GetLanguageSpecificData() const (PR #117019)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)


Changes

One last diff I missed between Swift and LLVM.

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


2 Files Affected:

- (modified) lldb/include/lldb/API/SBFrame.h (+1-1) 
- (modified) lldb/source/API/SBFrame.cpp (+1-1) 


``diff
diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index 629d4e5bc61f46..3635ee5a537ad8 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageSpecificData();
+  SBStructuredData GetLanguageSpecificData() const;
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 5c735dd35e1cf3..2300bec4d685d2 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageSpecificData() {
+SBStructuredData SBFrame::GetLanguageSpecificData() const {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;

``




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


[Lldb-commits] [lldb] Fix loading UUIDs from ELF headers. (PR #117028)

2024-11-20 Thread Greg Clayton via lldb-commits

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

>From 37eccb509ea6468879cf530c6952aab7adec4001 Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Wed, 20 Nov 2024 10:55:12 -0800
Subject: [PATCH 1/2] Fix loading UUIDs from ELF headers.

A previous patch added the ability to load UUID from ELF headers using the 
program header and finding PT_NOTE entries. The fix would attempt to read the 
data for the PT_NOTE from memory, but it didn't slide the address so it ended 
up only working for the main executable if it wasn't moved in memory. This 
patch slides the address and adds logging.
---
 .../Process/elf-core/ProcessElfCore.cpp   | 20 ++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..e58c06b9bd333c 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -224,7 +224,7 @@ Status ProcessElfCore::DoLoadCore() {
   ArchSpec core_arch(m_core_module_sp->GetArchitecture());
   target_arch.MergeFrom(core_arch);
   GetTarget().SetArchitecture(target_arch);
- 
+
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
   // Ensure we found at least one thread that was stopped on a signal.
@@ -276,8 +276,13 @@ Status ProcessElfCore::DoLoadCore() {
 }
 
 void ProcessElfCore::UpdateBuildIdForNTFileEntries() {
+  Log *log = GetLog(LLDBLog::Process);
   for (NT_FILE_Entry &entry : m_nt_file_entries) {
 entry.uuid = FindBuidIdInCoreMemory(entry.start);
+if (log && entry.uuid.IsValid())
+  LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
+__FUNCTION__, entry.start, entry.uuid.GetAsString().c_str(),
+entry.path.c_str());
   }
 }
 
@@ -875,7 +880,7 @@ llvm::Error 
ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef notes) {
 /// - NT_SIGINFO - Information about the signal that terminated the process
 /// - NT_AUXV - Process auxiliary vector
 /// - NT_FILE - Files mapped into memory
-/// 
+///
 /// Additionally, for each thread in the process the core file will contain at
 /// least the NT_PRSTATUS note, containing the thread id and general purpose
 /// registers. It may include additional notes for other register sets 
(floating
@@ -1034,15 +1039,20 @@ UUID 
ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t address) {
 std::vector note_bytes;
 note_bytes.resize(program_header.p_memsz);
 
-byte_read = ReadMemory(program_header.p_vaddr, note_bytes.data(),
-   program_header.p_memsz, error);
+// We need to slide the address of the p_vaddr as these values don't get
+// relocated in memory.
+const lldb::addr_t vaddr = program_header.p_vaddr + address;
+byte_read = ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz,
+   error);
 if (byte_read != program_header.p_memsz)
   continue;
 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
GetByteOrder(), addr_size);
 auto notes_or_error = parseSegment(segment_data);
-if (!notes_or_error)
+if (!notes_or_error) {
+  llvm::consumeError(notes_or_error.takeError());
   return invalid_uuid;
+}
 for (const CoreNote ¬e : *notes_or_error) {
   if (note.info.n_namesz == 4 &&
   note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&

>From eacf4f967b9250dca0439d84612a2d6c53421f8e Mon Sep 17 00:00:00 2001
From: Greg Clayton 
Date: Wed, 20 Nov 2024 11:44:03 -0800
Subject: [PATCH 2/2] Run clang format.

---
 lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index e58c06b9bd333c..cd95b000469dc5 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -1042,8 +1042,8 @@ UUID ProcessElfCore::FindBuidIdInCoreMemory(lldb::addr_t 
address) {
 // We need to slide the address of the p_vaddr as these values don't get
 // relocated in memory.
 const lldb::addr_t vaddr = program_header.p_vaddr + address;
-byte_read = ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz,
-   error);
+byte_read =
+ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
 if (byte_read != program_header.p_memsz)
   continue;
 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),

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


[Lldb-commits] [clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)

2024-11-20 Thread Bill Wendling via lldb-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/116719

>From 2dcf18163de2ccce959f46bf82df1fa40e3fd1fc Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Fri, 15 Nov 2024 15:41:48 -0800
Subject: [PATCH 1/5] [Clang] Improve Sema diagnostic performance for
 __builtin_counted_by_ref

Implement the sema checks with a placeholder. We then check for that
placeholder in all of the places we care to emit a diagnostic.
---
 clang/include/clang/AST/ASTContext.h  |   1 +
 clang/include/clang/AST/BuiltinTypes.def  |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 .../include/clang/Serialization/ASTBitCodes.h |   5 +-
 clang/lib/AST/ASTContext.cpp  |   4 +
 clang/lib/AST/NSAPI.cpp   |   1 +
 clang/lib/AST/Type.cpp|   3 +
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/Sema/SemaChecking.cpp   |   1 +
 clang/lib/Sema/SemaDecl.cpp   |  11 ++
 clang/lib/Sema/SemaExpr.cpp   | 138 +-
 clang/lib/Sema/SemaStmt.cpp   |  10 ++
 clang/lib/Serialization/ASTCommon.cpp |   3 +
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/Modules/no-external-type-id.cppm   |   2 +-
 clang/test/Sema/builtin-counted-by-ref.c  |  77 +-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   2 +
 17 files changed, 154 insertions(+), 113 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 89fcb6789d880a..39cad95d911a33 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1184,6 +1184,7 @@ class ASTContext : public RefCountedBase {
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnresolvedTemplateTy,
   UnknownAnyTy;
   CanQualType BuiltinFnTy;
+  CanQualType BuiltinCountedByRefTy;
   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
   CanQualType ObjCBuiltinBoolTy;
diff --git a/clang/include/clang/AST/BuiltinTypes.def 
b/clang/include/clang/AST/BuiltinTypes.def
index 444be4311a7431..4eae6962a46de6 100644
--- a/clang/include/clang/AST/BuiltinTypes.def
+++ b/clang/include/clang/AST/BuiltinTypes.def
@@ -314,6 +314,9 @@ PLACEHOLDER_TYPE(UnknownAny, UnknownAnyTy)
 
 PLACEHOLDER_TYPE(BuiltinFn, BuiltinFnTy)
 
+// A placeholder type for __builtin_counted_by_ref.
+PLACEHOLDER_TYPE(BuiltinCountedByRef, BuiltinCountedByRefTy)
+
 // The type of a cast which, in ARC, would normally require a
 // __bridge, but which might be okay depending on the immediate
 // context.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3caf471d3037f9..37fb44d4bf74cd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6673,7 +6673,7 @@ def err_builtin_counted_by_ref_must_be_flex_array_member 
: Error<
 def err_builtin_counted_by_ref_cannot_leak_reference : Error<
   "value returned by '__builtin_counted_by_ref' cannot be assigned to a "
   "variable, have its address taken, or passed into or returned from a 
function">;
-def err_builtin_counted_by_ref_invalid_lhs_use : Error<
+def err_builtin_counted_by_ref_invalid_use : Error<
   "value returned by '__builtin_counted_by_ref' cannot be used in "
   "%select{an array subscript|a binary}0 expression">;
 def err_builtin_counted_by_ref_has_side_effects : Error<
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index fd834c14ce790f..f4b71861968e77 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -,6 +,9 @@ enum PredefinedTypeIDs {
   /// \brief The '__ibm128' type
   PREDEF_TYPE_IBM128_ID = 74,
 
+  /// \brief The placeholder type for __builtin_counted_by_ref.
+  PREDEF_TYPE_BUILTIN_COUNTED_BY_REF = 75,
+
 /// OpenCL image types with auto numeration
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
   PREDEF_TYPE_##Id##_ID,
@@ -1148,7 +1151,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 513;
+const unsigned NUM_PREDEF_TYPE_IDS = 514;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..06226afaf23aab 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1390,6 +1390,10 @@ void ASTContext::InitBuiltinTypes(const TargetInfo 
&Target,
   if (LangOpts.MatrixTypes)
 InitBuiltinType(IncompleteMatrixIdxTy, BuiltinType::IncompleteMatrixIdx);
 
+  // Placeholder for __builtin_counted_by_ref().
+  if (!LangOpts.CPlusPlus)
+InitBuiltinType(

[Lldb-commits] [lldb] [lldb/www] Garbage collect old videos and add new ones (PR #116838)

2024-11-20 Thread Adrian Prantl via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix comment in ~Thread (NFC) (PR #116850)

2024-11-20 Thread Dave Lee via lldb-commits

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


[Lldb-commits] [lldb] 0394e08 - [lldb] Reword the "line 0" warning (#116827)

2024-11-20 Thread via lldb-commits

Author: Pavel Labath
Date: 2024-11-20T09:09:00+01:00
New Revision: 0394e08bfbb110d606ace49bd10d951eb904e5d6

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

LOG: [lldb] Reword the "line 0" warning (#116827)

We got a bug report that this message is confusing. In this particular
case, the line zero was due to compiler tail merging (in optimized
code). The main issue was the "no source code" part: in this case it's
kind of incorrect because -- even though we can't really know that --
the address is arguably associated with *multiple* lines of source code.

I've tried to make the new wording more neutral, and added a wink
towards compiler optimizations. I left out the "compiler generated" part
of the message because I couldn't find a way to squeeze that in nicely.
I'm also not entirely sure what it was referring to -- if this was
(just) function prologue/epilogue, then maybe leaving it out is fine, as
we're not likely to stop there anyway (?)

I also left out the function name, because:
- for template functions it gets rather long
- it's already present in the message, potentially twice (once in the
"frame summary" line and once in the snippet of code we show for the
function declaration)

-

Co-authored-by: Jonas Devlieghere 

Added: 


Modified: 
lldb/source/Target/StackFrame.cpp
lldb/test/API/source-manager/TestSourceManager.py

Removed: 




diff  --git a/lldb/source/Target/StackFrame.cpp 
b/lldb/source/Target/StackFrame.cpp
index 1bca9786fb7c70..ca02de15295cac 100644
--- a/lldb/source/Target/StackFrame.cpp
+++ b/lldb/source/Target/StackFrame.cpp
@@ -2007,19 +2007,9 @@ bool StackFrame::GetStatus(Stream &strm, bool 
show_frame_info, bool show_source,
   if (num_lines != 0)
 have_source = true;
   // TODO: Give here a one time warning if source file is missing.
-  if (!m_sc.line_entry.line) {
-ConstString fn_name = m_sc.GetFunctionName();
-
-if (!fn_name.IsEmpty())
-  strm.Printf(
-  "Note: this address is compiler-generated code in function "
-  "%s that has no source code associated with it.",
-  fn_name.AsCString());
-else
-  strm.Printf("Note: this address is compiler-generated code that "
-  "has no source code associated with it.");
-strm.EOL();
-  }
+  if (!m_sc.line_entry.line)
+strm << "note: This address is not associated with a specific line 
"
+"of code. This may be due to compiler optimizations.\n";
 }
   }
   switch (disasm_display) {

diff  --git a/lldb/test/API/source-manager/TestSourceManager.py 
b/lldb/test/API/source-manager/TestSourceManager.py
index 7071f094e20f7e..7d9ce86cdc353a 100644
--- a/lldb/test/API/source-manager/TestSourceManager.py
+++ b/lldb/test/API/source-manager/TestSourceManager.py
@@ -336,8 +336,8 @@ def test_artificial_source_location(self):
 "stop reason = breakpoint",
 f"{src_file}:0",
 "static int foo();",
-"Note: this address is compiler-generated code in function",
-"that has no source code associated with it.",
+"note: This address is not associated with a specific line "
+"of code. This may be due to compiler optimizations.",
 ],
 )
 



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


[Lldb-commits] [lldb] [lldb] Reword the "line 0" warning (PR #116827)

2024-11-20 Thread Pavel Labath via lldb-commits

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


[Lldb-commits] [lldb] e660e65 - [lldb] Add an API to derive language-specific runtime information (#116904)

2024-11-20 Thread via lldb-commits

Author: Adrian Prantl
Date: 2024-11-20T08:49:07-08:00
New Revision: e660e6503ba14684bd460b7baaf3da7336d0f46e

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

LOG: [lldb] Add an API to derive language-specific runtime information (#116904)

This is motivated by exposing some Swift language-specific flags through
the API, in the example here it is used to communicate the Objective-C
runtime version. This could also be a meaningful extension point to get
information about "embedded: languages, such as extracting the C++
version in an Objective-C++ frame or something along those lines.

Added: 
lldb/test/API/lang/objc/languageinfo/Makefile
lldb/test/API/lang/objc/languageinfo/TestObjCLanguageInfo.py
lldb/test/API/lang/objc/languageinfo/main.m

Modified: 
lldb/include/lldb/API/SBFrame.h
lldb/include/lldb/API/SBStructuredData.h
lldb/include/lldb/Target/LanguageRuntime.h
lldb/include/lldb/Target/StackFrame.h
lldb/source/API/SBFrame.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
lldb/source/Target/LanguageRuntime.cpp
lldb/source/Target/StackFrame.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index e0d15c3ecc5b1c..e1ff217767cb98 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -122,6 +122,11 @@ class LLDB_API SBFrame {
   lldb::SBValue EvaluateExpression(const char *expr,
const SBExpressionOptions &options);
 
+  /// Language plugins can use this API to report language-specific
+  /// runtime information about this compile unit, such as additional
+  /// language version details or feature flags.
+  SBStructuredData GetLanguageInfo();
+
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
   /// for a stack frame. Inlined functions are represented as SBBlock objects

diff  --git a/lldb/include/lldb/API/SBStructuredData.h 
b/lldb/include/lldb/API/SBStructuredData.h
index ccdd12cab94b2f..c0d214a7374c65 100644
--- a/lldb/include/lldb/API/SBStructuredData.h
+++ b/lldb/include/lldb/API/SBStructuredData.h
@@ -114,6 +114,7 @@ class SBStructuredData {
   friend class SBCommandReturnObject;
   friend class SBLaunchInfo;
   friend class SBDebugger;
+  friend class SBFrame;
   friend class SBTarget;
   friend class SBProcess;
   friend class SBThread;

diff  --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index 21bdc61b8cbcf0..4f4d426eaa1dab 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -241,6 +241,11 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
lldb_private::RegisterContext *regctx,
bool &behaves_like_zeroth_frame);
 
+  /// Language runtime plugins can use this API to report
+  /// language-specific runtime information about this compile unit,
+  /// such as additional language version details or feature flags.
+  virtual StructuredData::ObjectSP GetLanguageInfo(SymbolContext sc);
+
 protected:
   // The static GetRuntimeUnwindPlan method above is only implemented in the
   // base class; subclasses may override this protected member if they can

diff  --git a/lldb/include/lldb/Target/StackFrame.h 
b/lldb/include/lldb/Target/StackFrame.h
index e85430791b7d93..5e82657706339c 100644
--- a/lldb/include/lldb/Target/StackFrame.h
+++ b/lldb/include/lldb/Target/StackFrame.h
@@ -22,6 +22,7 @@
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/ValueObject/ValueObjectList.h"
 
@@ -408,6 +409,11 @@ class StackFrame : public ExecutionContextScope,
   /// system implementation details this way.
   bool IsHidden();
 
+  /// Language plugins can use this API to report language-specific
+  /// runtime information about this compile unit, such as additional
+  /// language version details or feature flags.
+  StructuredData::ObjectSP GetLanguageInfo();
+
   /// Get the frame's demangled name.
   ///
   ///  /// \return

diff  --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index e2c691fa9bfd45..d17bb5cc146086 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -47,6 +47,7 @@
 #include "lldb/API/SBExpressionOptions.h"
 #include "lldb/API/SBFormat.h"
 #include "lldb/API/SBStream.h"
+#include "lldb/API/SBStructuredData.h"
 #include "lldb/API/SBSymbolContext.h"
 

[Lldb-commits] [lldb] [lldb] Add an API to derive language-specific runtime information (PR #116904)

2024-11-20 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl closed 
https://github.com/llvm/llvm-project/pull/116904
___
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 duplicate type filtering (PR #116989)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

In #108907, the index classes started filtering the DIEs according to 
the full type query (instead of just the base name). This means that the checks 
in SymbolFileDWARF are now redundant.

I've also moved the non-redundant checks so that now all checking is done in 
the DWARFIndex class and the caller can expect to get the final filtered list 
of types.

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


2 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp (+12-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+2-50) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index c18edd10b96819..30c890d6d01388 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -137,9 +137,19 @@ void DWARFIndex::GetTypesWithQuery(
 bool DWARFIndex::ProcessTypeDIEMatchQuery(
 TypeQuery &query, DWARFDIE die,
 llvm::function_ref callback) {
-  // Nothing to match from query
-  if (query.GetContextRef().size() <= 1)
+  // Check the language, but only if we have a language filter.
+  if (query.HasLanguage() &&
+  !query.LanguageMatches(SymbolFileDWARF::GetLanguageFamily(*die.GetCU(
+return true; // Keep iterating over index types, language mismatch.
+
+  // Since mangled names are unique, we only need to check if the names are
+  // the same.
+  if (query.GetSearchByMangledName()) {
+if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
+query.GetTypeBasename().GetStringRef())
+  return true; // Keep iterating over index types, mangled name mismatch.
 return callback(die);
+  }
 
   std::vector die_context;
   if (query.GetModuleSearch())
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 8ce0db4588a46a..c900f330b481bb 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2726,39 +2726,8 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, 
TypeResults &results) {
   TypeQuery query_full(query);
   bool have_index_match = false;
   m_index->GetTypesWithQuery(query_full, [&](DWARFDIE die) {
-// Check the language, but only if we have a language filter.
-if (query.HasLanguage()) {
-  if (!query.LanguageMatches(GetLanguageFamily(*die.GetCU(
-return true; // Keep iterating over index types, language mismatch.
-}
-
-// Since mangled names are unique, we only need to check if the names are
-// the same.
-if (query.GetSearchByMangledName()) {
-  if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
-  query.GetTypeBasename().GetStringRef())
-return true; // Keep iterating over index types, mangled name mismatch.
-  if (Type *matching_type = ResolveType(die, true, true)) {
-results.InsertUnique(matching_type->shared_from_this());
-return !results.Done(query); // Keep iterating if we aren't done.
-  }
-  return true; // Keep iterating over index types, weren't able to resolve
-   // this type
-}
-
-// Check the context matches
-std::vector die_context;
-if (query.GetModuleSearch())
-  die_context = die.GetDeclContext();
-else
-  die_context = die.GetTypeLookupContext();
-assert(!die_context.empty());
-if (!query.ContextMatches(die_context))
-  return true; // Keep iterating over index types, context mismatch.
-
-// Try to resolve the type.
 if (Type *matching_type = ResolveType(die, true, true)) {
-  if (matching_type->IsTemplateType()) {
+  if (!query.GetSearchByMangledName() && matching_type->IsTemplateType()) {
 // We have to watch out for case where we lookup a type by basename and
 // it matches a template with simple template names. Like looking up
 // "Foo" and if we have simple template names then we will match
@@ -2790,7 +2759,7 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, 
TypeResults &results) {
   // With -gsimple-template-names, a templated type's DW_AT_name will not
   // contain the template parameters. Try again stripping '<' and anything
   // after, filtering out entries with template parameters that don't match.
-  if (!have_index_match) {
+  if (!have_index_match && !query.GetSearchByMangledName()) {
 // Create a type matcher with a compiler context that is tuned for
 // -gsimple-template-names. We will use this for the index lookup and the
 // context matching, but will use the original "match" to insert matches
@@ -2804,23 +2773,6 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, 
TypeResults &results) {
   // Copy our match's context and update the basename 

[Lldb-commits] [lldb] [lldb] Refactor helper by using iterators and in-place edits (NFC) (PR #116876)

2024-11-20 Thread Adrian Prantl via lldb-commits

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


[Lldb-commits] [lldb] Rename GetLanguageInfo to GetLanguageSpecificData (PR #117012)

2024-11-20 Thread Adrian Prantl via lldb-commits

https://github.com/adrian-prantl created 
https://github.com/llvm/llvm-project/pull/117012

Unbeknownst to me the Swift LLDB branch already had an almost identical API 
with this name, so it makes sense to merge the two.

>From 92408ce615fe9abdfa69f0e6309a39d9f87a764a Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 20 Nov 2024 09:14:09 -0800
Subject: [PATCH] Rename GetLanguageInfo to GetLanguageSpecificData

Unbeknownst to me the Swift LLDB branch already had an almost
identical API with this name, so it makes sense to merge the two.
---
 lldb/include/lldb/API/SBFrame.h   | 2 +-
 lldb/include/lldb/Target/LanguageRuntime.h| 2 +-
 lldb/include/lldb/Target/StackFrame.h | 2 +-
 lldb/source/API/SBFrame.cpp   | 4 ++--
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp  | 3 ++-
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h| 2 +-
 lldb/source/Target/LanguageRuntime.cpp| 3 ++-
 lldb/source/Target/StackFrame.cpp | 4 ++--
 ...estObjCLanguageInfo.py => TestObjCLanguageSpecificData.py} | 2 +-
 9 files changed, 13 insertions(+), 11 deletions(-)
 rename lldb/test/API/lang/objc/languageinfo/{TestObjCLanguageInfo.py => 
TestObjCLanguageSpecificData.py} (90%)

diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index e1ff217767cb98..629d4e5bc61f46 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageInfo();
+  SBStructuredData GetLanguageSpecificData();
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
diff --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index 4f4d426eaa1dab..4a0214b04e235e 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -244,7 +244,7 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
   /// Language runtime plugins can use this API to report
   /// language-specific runtime information about this compile unit,
   /// such as additional language version details or feature flags.
-  virtual StructuredData::ObjectSP GetLanguageInfo(SymbolContext sc);
+  virtual StructuredData::ObjectSP GetLanguageSpecificData(SymbolContext sc);
 
 protected:
   // The static GetRuntimeUnwindPlan method above is only implemented in the
diff --git a/lldb/include/lldb/Target/StackFrame.h 
b/lldb/include/lldb/Target/StackFrame.h
index 5e82657706339c..3f51c9a7f22f09 100644
--- a/lldb/include/lldb/Target/StackFrame.h
+++ b/lldb/include/lldb/Target/StackFrame.h
@@ -412,7 +412,7 @@ class StackFrame : public ExecutionContextScope,
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  StructuredData::ObjectSP GetLanguageInfo();
+  StructuredData::ObjectSP GetLanguageSpecificData();
 
   /// Get the frame's demangled name.
   ///
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index d17bb5cc146086..5c735dd35e1cf3 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageInfo() {
+SBStructuredData SBFrame::GetLanguageSpecificData() {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;
@@ -1165,7 +1165,7 @@ SBStructuredData SBFrame::GetLanguageInfo() {
   if (!frame)
 return sb_data;
 
-  StructuredData::ObjectSP data(frame->GetLanguageInfo());
+  StructuredData::ObjectSP data(frame->GetLanguageSpecificData());
   sb_data.m_impl_up->SetObjectSP(data);
   return sb_data;
 }
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 7298ab0e7336bf..0083b499656979 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -3398,7 +3398,8 @@ std::optional 
AppleObjCRuntimeV2::GetSharedCacheImageHeaderVersion() {
   return std::nullopt;
 }
 
-StructuredData::ObjectSP AppleObjCRuntimeV2::GetLanguageInfo(SymbolContext sc) 
{
+StructuredData::ObjectSP
+AppleObjCRuntimeV2::GetLanguageSpecificData(SymbolContext sc) {
   auto dict_up = std::make_unique();
   dict_up->AddItem("Objective-C runtime version",

[Lldb-commits] [lldb] Rename GetLanguageInfo to GetLanguageSpecificData (PR #117012)

2024-11-20 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Adrian Prantl (adrian-prantl)


Changes

Unbeknownst to me the Swift LLDB branch already had an almost identical API 
with this name, so it makes sense to merge the two.

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


9 Files Affected:

- (modified) lldb/include/lldb/API/SBFrame.h (+1-1) 
- (modified) lldb/include/lldb/Target/LanguageRuntime.h (+1-1) 
- (modified) lldb/include/lldb/Target/StackFrame.h (+1-1) 
- (modified) lldb/source/API/SBFrame.cpp (+2-2) 
- (modified) 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 (+2-1) 
- (modified) 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h 
(+1-1) 
- (modified) lldb/source/Target/LanguageRuntime.cpp (+2-1) 
- (modified) lldb/source/Target/StackFrame.cpp (+2-2) 
- (renamed) 
lldb/test/API/lang/objc/languageinfo/TestObjCLanguageSpecificData.py (+1-1) 


``diff
diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index e1ff217767cb98..629d4e5bc61f46 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -125,7 +125,7 @@ class LLDB_API SBFrame {
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  SBStructuredData GetLanguageInfo();
+  SBStructuredData GetLanguageSpecificData();
 
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
diff --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index 4f4d426eaa1dab..4a0214b04e235e 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -244,7 +244,7 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
   /// Language runtime plugins can use this API to report
   /// language-specific runtime information about this compile unit,
   /// such as additional language version details or feature flags.
-  virtual StructuredData::ObjectSP GetLanguageInfo(SymbolContext sc);
+  virtual StructuredData::ObjectSP GetLanguageSpecificData(SymbolContext sc);
 
 protected:
   // The static GetRuntimeUnwindPlan method above is only implemented in the
diff --git a/lldb/include/lldb/Target/StackFrame.h 
b/lldb/include/lldb/Target/StackFrame.h
index 5e82657706339c..3f51c9a7f22f09 100644
--- a/lldb/include/lldb/Target/StackFrame.h
+++ b/lldb/include/lldb/Target/StackFrame.h
@@ -412,7 +412,7 @@ class StackFrame : public ExecutionContextScope,
   /// Language plugins can use this API to report language-specific
   /// runtime information about this compile unit, such as additional
   /// language version details or feature flags.
-  StructuredData::ObjectSP GetLanguageInfo();
+  StructuredData::ObjectSP GetLanguageSpecificData();
 
   /// Get the frame's demangled name.
   ///
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index d17bb5cc146086..5c735dd35e1cf3 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1155,7 +1155,7 @@ lldb::SBValue SBFrame::EvaluateExpression(const char 
*expr,
   return expr_result;
 }
 
-SBStructuredData SBFrame::GetLanguageInfo() {
+SBStructuredData SBFrame::GetLanguageSpecificData() {
   LLDB_INSTRUMENT_VA(this);
 
   SBStructuredData sb_data;
@@ -1165,7 +1165,7 @@ SBStructuredData SBFrame::GetLanguageInfo() {
   if (!frame)
 return sb_data;
 
-  StructuredData::ObjectSP data(frame->GetLanguageInfo());
+  StructuredData::ObjectSP data(frame->GetLanguageSpecificData());
   sb_data.m_impl_up->SetObjectSP(data);
   return sb_data;
 }
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 7298ab0e7336bf..0083b499656979 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -3398,7 +3398,8 @@ std::optional 
AppleObjCRuntimeV2::GetSharedCacheImageHeaderVersion() {
   return std::nullopt;
 }
 
-StructuredData::ObjectSP AppleObjCRuntimeV2::GetLanguageInfo(SymbolContext sc) 
{
+StructuredData::ObjectSP
+AppleObjCRuntimeV2::GetLanguageSpecificData(SymbolContext sc) {
   auto dict_up = std::make_unique();
   dict_up->AddItem("Objective-C runtime version",
std::make_unique(2));
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
index 7117b778a1c0e9..2422539b13f13d 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRu

[Lldb-commits] [lldb] [lldb/DWARF] Remove duplicate type filtering (PR #116989)

2024-11-20 Thread Pavel Labath via lldb-commits


@@ -137,9 +137,19 @@ void DWARFIndex::GetTypesWithQuery(
 bool DWARFIndex::ProcessTypeDIEMatchQuery(
 TypeQuery &query, DWARFDIE die,
 llvm::function_ref callback) {
-  // Nothing to match from query
-  if (query.GetContextRef().size() <= 1)

labath wrote:

This wasn't correct because it wasn't checking the "ComilerContextKind" part of 
the query. It didn't matter because of the "second line of defense" (which is 
now gone).

https://github.com/llvm/llvm-project/pull/116989
___
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 duplicate type filtering (PR #116989)

2024-11-20 Thread Pavel Labath via lldb-commits

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

In #108907, the index classes started filtering the DIEs according to the full 
type query (instead of just the base name). This means that the checks in 
SymbolFileDWARF are now redundant.

I've also moved the non-redundant checks so that now all checking is done in 
the DWARFIndex class and the caller can expect to get the final filtered list 
of types.

>From aa1fde4817997d86a89086cb53092459a02e112b Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Wed, 20 Nov 2024 15:13:05 +0100
Subject: [PATCH] [lldb/DWARF] Remove duplicate type filtering

In #108907, the index classes started filtering the DIEs according to
the full type query (instead of just the base name). This means that the
checks in SymbolFileDWARF are now redundant.

I've also moved the non-redundant checks so that now all checking is
done in the DWARFIndex class and the caller can expect to get the final
filtered list of types.
---
 .../Plugins/SymbolFile/DWARF/DWARFIndex.cpp   | 14 -
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 52 +--
 2 files changed, 14 insertions(+), 52 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index c18edd10b96819..30c890d6d01388 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -137,9 +137,19 @@ void DWARFIndex::GetTypesWithQuery(
 bool DWARFIndex::ProcessTypeDIEMatchQuery(
 TypeQuery &query, DWARFDIE die,
 llvm::function_ref callback) {
-  // Nothing to match from query
-  if (query.GetContextRef().size() <= 1)
+  // Check the language, but only if we have a language filter.
+  if (query.HasLanguage() &&
+  !query.LanguageMatches(SymbolFileDWARF::GetLanguageFamily(*die.GetCU(
+return true; // Keep iterating over index types, language mismatch.
+
+  // Since mangled names are unique, we only need to check if the names are
+  // the same.
+  if (query.GetSearchByMangledName()) {
+if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
+query.GetTypeBasename().GetStringRef())
+  return true; // Keep iterating over index types, mangled name mismatch.
 return callback(die);
+  }
 
   std::vector die_context;
   if (query.GetModuleSearch())
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 8ce0db4588a46a..c900f330b481bb 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2726,39 +2726,8 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, 
TypeResults &results) {
   TypeQuery query_full(query);
   bool have_index_match = false;
   m_index->GetTypesWithQuery(query_full, [&](DWARFDIE die) {
-// Check the language, but only if we have a language filter.
-if (query.HasLanguage()) {
-  if (!query.LanguageMatches(GetLanguageFamily(*die.GetCU(
-return true; // Keep iterating over index types, language mismatch.
-}
-
-// Since mangled names are unique, we only need to check if the names are
-// the same.
-if (query.GetSearchByMangledName()) {
-  if (die.GetMangledName(/*substitute_name_allowed=*/false) !=
-  query.GetTypeBasename().GetStringRef())
-return true; // Keep iterating over index types, mangled name mismatch.
-  if (Type *matching_type = ResolveType(die, true, true)) {
-results.InsertUnique(matching_type->shared_from_this());
-return !results.Done(query); // Keep iterating if we aren't done.
-  }
-  return true; // Keep iterating over index types, weren't able to resolve
-   // this type
-}
-
-// Check the context matches
-std::vector die_context;
-if (query.GetModuleSearch())
-  die_context = die.GetDeclContext();
-else
-  die_context = die.GetTypeLookupContext();
-assert(!die_context.empty());
-if (!query.ContextMatches(die_context))
-  return true; // Keep iterating over index types, context mismatch.
-
-// Try to resolve the type.
 if (Type *matching_type = ResolveType(die, true, true)) {
-  if (matching_type->IsTemplateType()) {
+  if (!query.GetSearchByMangledName() && matching_type->IsTemplateType()) {
 // We have to watch out for case where we lookup a type by basename and
 // it matches a template with simple template names. Like looking up
 // "Foo" and if we have simple template names then we will match
@@ -2790,7 +2759,7 @@ void SymbolFileDWARF::FindTypes(const TypeQuery &query, 
TypeResults &results) {
   // With -gsimple-template-names, a templated type's DW_AT_name will not
   // contain the template parameters. Try again stripping '<' and anything
   // after, filtering out entries with template parameters that don't match.
-  if (!hav

[Lldb-commits] [lldb] [lldb] Add an API to derive language-specific runtime information (PR #116904)

2024-11-20 Thread Adrian Prantl via lldb-commits

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

>From ac342fac93ee63c21e0797af5a7c9d6d6088d260 Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Tue, 19 Nov 2024 17:30:10 -0800
Subject: [PATCH] [lldb] Add an API to derive language-specific runtime
 information

This is motivated by exposing some Swift language-specific flags
through the API, in the example here it is used to communicate the
Objective-C runtime version. This could also be a meaningful extension
point to get information about "embedded: languages, such as
extracting the C++ version in an Objective-C++ frame or something
along those lines.
---
 lldb/include/lldb/API/SBFrame.h  |  5 +
 lldb/include/lldb/API/SBStructuredData.h |  1 +
 lldb/include/lldb/Target/LanguageRuntime.h   |  5 +
 lldb/include/lldb/Target/StackFrame.h|  6 ++
 lldb/source/API/SBFrame.cpp  | 16 
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp |  7 +++
 .../ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h   |  2 ++
 lldb/source/Target/LanguageRuntime.cpp   |  4 
 lldb/source/Target/StackFrame.cpp| 13 +
 lldb/test/API/lang/objc/languageinfo/Makefile|  4 
 .../objc/languageinfo/TestObjCLanguageInfo.py| 16 
 lldb/test/API/lang/objc/languageinfo/main.m  |  1 +
 12 files changed, 80 insertions(+)
 create mode 100644 lldb/test/API/lang/objc/languageinfo/Makefile
 create mode 100644 lldb/test/API/lang/objc/languageinfo/TestObjCLanguageInfo.py
 create mode 100644 lldb/test/API/lang/objc/languageinfo/main.m

diff --git a/lldb/include/lldb/API/SBFrame.h b/lldb/include/lldb/API/SBFrame.h
index e0d15c3ecc5b1c..e1ff217767cb98 100644
--- a/lldb/include/lldb/API/SBFrame.h
+++ b/lldb/include/lldb/API/SBFrame.h
@@ -122,6 +122,11 @@ class LLDB_API SBFrame {
   lldb::SBValue EvaluateExpression(const char *expr,
const SBExpressionOptions &options);
 
+  /// Language plugins can use this API to report language-specific
+  /// runtime information about this compile unit, such as additional
+  /// language version details or feature flags.
+  SBStructuredData GetLanguageInfo();
+
   /// Gets the lexical block that defines the stack frame. Another way to think
   /// of this is it will return the block that contains all of the variables
   /// for a stack frame. Inlined functions are represented as SBBlock objects
diff --git a/lldb/include/lldb/API/SBStructuredData.h 
b/lldb/include/lldb/API/SBStructuredData.h
index ccdd12cab94b2f..c0d214a7374c65 100644
--- a/lldb/include/lldb/API/SBStructuredData.h
+++ b/lldb/include/lldb/API/SBStructuredData.h
@@ -114,6 +114,7 @@ class SBStructuredData {
   friend class SBCommandReturnObject;
   friend class SBLaunchInfo;
   friend class SBDebugger;
+  friend class SBFrame;
   friend class SBTarget;
   friend class SBProcess;
   friend class SBThread;
diff --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index 21bdc61b8cbcf0..4f4d426eaa1dab 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -241,6 +241,11 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
lldb_private::RegisterContext *regctx,
bool &behaves_like_zeroth_frame);
 
+  /// Language runtime plugins can use this API to report
+  /// language-specific runtime information about this compile unit,
+  /// such as additional language version details or feature flags.
+  virtual StructuredData::ObjectSP GetLanguageInfo(SymbolContext sc);
+
 protected:
   // The static GetRuntimeUnwindPlan method above is only implemented in the
   // base class; subclasses may override this protected member if they can
diff --git a/lldb/include/lldb/Target/StackFrame.h 
b/lldb/include/lldb/Target/StackFrame.h
index e85430791b7d93..5e82657706339c 100644
--- a/lldb/include/lldb/Target/StackFrame.h
+++ b/lldb/include/lldb/Target/StackFrame.h
@@ -22,6 +22,7 @@
 #include "lldb/Utility/Scalar.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/StructuredData.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/ValueObject/ValueObjectList.h"
 
@@ -408,6 +409,11 @@ class StackFrame : public ExecutionContextScope,
   /// system implementation details this way.
   bool IsHidden();
 
+  /// Language plugins can use this API to report language-specific
+  /// runtime information about this compile unit, such as additional
+  /// language version details or feature flags.
+  StructuredData::ObjectSP GetLanguageInfo();
+
   /// Get the frame's demangled name.
   ///
   ///  /// \return
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index e2c691fa9bfd45..d17bb5cc146086 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -47,6 +47,7 @@
 

[Lldb-commits] [lldb] Make SBFrame::GetLanguageSpecificData() const (PR #117019)

2024-11-20 Thread Adrian Prantl via lldb-commits

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


[Lldb-commits] [lldb] [lldb] Fix a regression in Status::GetErrorType() (PR #117095)

2024-11-20 Thread Adrian Prantl via lldb-commits

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

>From fc6cc65d4673de145989b334f67eeb4fb54aa25c Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Wed, 20 Nov 2024 17:45:54 -0800
Subject: [PATCH] [lldb] Fix a regression in Status::GetErrorType()

The refactored code did not correctly determine the type of expression
errors.

rdar://139699028
---
 lldb/source/Utility/Status.cpp   |  6 +-
 .../expression/diagnostics/TestExprDiagnostics.py| 12 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Utility/Status.cpp b/lldb/source/Utility/Status.cpp
index 1d171c6b6c3746..5757935fb86228 100644
--- a/lldb/source/Utility/Status.cpp
+++ b/lldb/source/Utility/Status.cpp
@@ -258,7 +258,11 @@ ErrorType Status::GetType() const {
 // Return the first only.
 if (result != eErrorTypeInvalid)
   return;
-result = ErrorCodeToErrorType(error.convertToErrorCode());
+if (error.isA())
+  result = static_cast(error).GetErrorType();
+else
+  result = ErrorCodeToErrorType(error.convertToErrorCode());
+
   });
   return result;
 }
diff --git 
a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py 
b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
index fac562edf9ece0..b9b5bffb87e817 100644
--- a/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ b/lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -184,6 +184,18 @@ def test_source_locations_from_objc_modules(self):
 # the first argument are probably stable enough that this test can 
check for them.
 self.assertIn("void NSLog(NSString *format", 
value.GetError().GetCString())
 
+def test_error_type(self):
+"""Test the error reporting in the API"""
+self.build()
+
+(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
+self, "// Break here", self.main_source_spec
+)
+frame = thread.GetFrameAtIndex(0)
+value = frame.EvaluateExpression('#error("I am error.")')
+error = value.GetError()
+self.assertEqual(error.GetType(), lldb.eErrorTypeExpression)
+
 def test_command_expr_sbdata(self):
 """Test the structured diagnostics data"""
 self.build()

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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread via lldb-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 53a6a11e0d51229d341b8906252645cd8a5de796 
b285bba80b7b7ad4e351485d59df41f328462867 --extensions h,cpp -- 
lldb/source/Core/DynamicLoader.cpp 
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Core/DynamicLoader.cpp 
b/lldb/source/Core/DynamicLoader.cpp
index 03f360c59d..6b3187790d 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -159,7 +159,8 @@ ModuleSP DynamicLoader::FindModuleViaTarget(const FileSpec 
&file) {
   ModuleSpec module_spec(file, target.GetArchitecture());
   ModuleSpec module_spec_from_process;
   // Process may be able to augment the module_spec with UUID, e.g. ELF core.
-  if (m_process->GetModuleSpec(file, target.GetArchitecture(), 
module_spec_from_process)) {
+  if (m_process->GetModuleSpec(file, target.GetArchitecture(),
+   module_spec_from_process)) {
 module_spec = module_spec_from_process;
   }
 

``




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


[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits

https://github.com/splhack updated 
https://github.com/llvm/llvm-project/pull/117070

>From 6b8f4a824d39ce557230e610a846d316358b4f20 Mon Sep 17 00:00:00 2001
From: Kazuki Sakamoto 
Date: Wed, 20 Nov 2024 16:20:40 -0800
Subject: [PATCH 1/2] Run clang format.

---
 lldb/source/Core/DynamicLoader.cpp|  7 +++---
 .../Process/elf-core/ProcessElfCore.cpp   | 25 +--
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/lldb/source/Core/DynamicLoader.cpp 
b/lldb/source/Core/DynamicLoader.cpp
index 68d6ab0850853f..34f0661a312bb6 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -368,8 +368,7 @@ addr_t DynamicLoader::ReadPointer(addr_t addr) {
 return value;
 }
 
-void DynamicLoader::LoadOperatingSystemPlugin(bool flush)
-{
-if (m_process)
-m_process->LoadOperatingSystemPlugin(flush);
+void DynamicLoader::LoadOperatingSystemPlugin(bool flush) {
+  if (m_process)
+m_process->LoadOperatingSystemPlugin(flush);
 }
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp 
b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 7955594bf5d94c..3a4f42bb8ca392 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -224,7 +224,7 @@ Status ProcessElfCore::DoLoadCore() {
   ArchSpec core_arch(m_core_module_sp->GetArchitecture());
   target_arch.MergeFrom(core_arch);
   GetTarget().SetArchitecture(target_arch);
- 
+
   SetUnixSignals(UnixSignals::Create(GetArchitecture()));
 
   // Ensure we found at least one thread that was stopped on a signal.
@@ -393,7 +393,7 @@ size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void 
*buf, size_t size,
   const lldb::addr_t file_start = address_range->data.GetRangeBase();
   const lldb::addr_t file_end = address_range->data.GetRangeEnd();
   size_t bytes_to_read = size; // Number of bytes to read from the core file
-  size_t bytes_copied = 0;   // Number of bytes actually read from the core 
file
+  size_t bytes_copied = 0; // Number of bytes actually read from the core file
   lldb::addr_t bytes_left =
   0; // Number of bytes available in the core file from the given address
 
@@ -476,8 +476,7 @@ lldb::addr_t ProcessElfCore::GetImageInfoAddress() {
 
 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
 static void ParseFreeBSDPrStatus(ThreadData &thread_data,
- const DataExtractor &data,
- bool lp64) {
+ const DataExtractor &data, bool lp64) {
   lldb::offset_t offset = 0;
   int pr_version = data.GetU32(&offset);
 
@@ -504,8 +503,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
 
 // Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
 static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
- const DataExtractor &data,
- bool lp64) {
+ const DataExtractor &data, bool lp64) {
   lldb::offset_t offset = 0;
   int pr_version = data.GetU32(&offset);
 
@@ -524,8 +522,7 @@ static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
 }
 
 static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
-   uint32_t &cpi_nlwps,
-   uint32_t &cpi_signo,
+   uint32_t &cpi_nlwps, uint32_t 
&cpi_signo,
uint32_t &cpi_siglwp,
uint32_t &cpi_pid) {
   lldb::offset_t offset = 0;
@@ -693,8 +690,8 @@ llvm::Error 
ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef notes) {
 
 if (name == "NetBSD-CORE") {
   if (note.info.n_type == NETBSD::NT_PROCINFO) {
-llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
-siglwp, pr_pid);
+llvm::Error error =
+ParseNetBSDProcInfo(note.data, nlwps, signo, siglwp, pr_pid);
 if (error)
   return error;
 SetID(pr_pid);
@@ -875,7 +872,7 @@ llvm::Error 
ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef notes) {
 /// - NT_SIGINFO - Information about the signal that terminated the process
 /// - NT_AUXV - Process auxiliary vector
 /// - NT_FILE - Files mapped into memory
-/// 
+///
 /// Additionally, for each thread in the process the core file will contain at
 /// least the NT_PRSTATUS note, containing the thread id and general purpose
 /// registers. It may include additional notes for other register sets 
(floating
@@ -920,7 +917,9 @@ llvm::Error 
ProcessElfCore::parseLinuxNotes(llvm::ArrayRef notes) {
   Status status = prpsinfo.Parse(note.data, arch);
   if (status.Fail())
 return status.ToError();
-  thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, 
sizeof (prpsinfo.pr_fname

[Lldb-commits] [lldb] [lldb] Fix ELF core debugging (PR #117070)

2024-11-20 Thread Kazuki Sakamoto via lldb-commits

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