[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

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

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

With simple template names the template arguments aren't embedded in the 
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized template 
arguments on the leaf (most deeply nested) DIE, but was not sufficient, as the 
difference get be at any level above that (Foo::Bar vs. Foo::Bar). This 
patch makes sure we compare the entire context.

As a drive-by I also remove the completely unnecessary ConstStringification of 
the GetDIEClassTemplateParams result.

>From 9429eefc79b310731bafa63cf4db46eea3b0756e Mon Sep 17 00:00:00 2001
From: Pavel Labath 
Date: Mon, 17 Jun 2024 13:45:24 +0200
Subject: [PATCH] [lldb/DWARF] Fix type definition search with simple template
 names

With simple template names the template arguments aren't embedded in the
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized
template arguments on the leaf (most deeply nested) DIE, but was not
sufficient, as the difference get be at any level above that
(Foo::Bar vs. Foo::Bar). This patch makes sure we compare the
entire context.

As a drive-by I also remove the completely unnecessary
ConstStringification of the GetDIEClassTemplateParams result.
---
 .../Plugins/SymbolFile/DWARF/DWARFASTParser.h |  2 +-
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 16 ++---
 .../SymbolFile/DWARF/DWARFASTParserClang.h|  4 +-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp  | 70 ++-
 .../x86/simple-template-names-context.cpp |  2 +-
 5 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 66db396279e06..abaeb2502cbbd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -58,7 +58,7 @@ class DWARFASTParser {
   virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
   CompilerDeclContext decl_context) = 0;
 
-  virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
+  virtual std::string GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
 
   static std::optional
   ParseChildArrayInfo(const DWARFDIE &parent_die,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 02c91ddc57f83..cffe3f7dd6128 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return "";
 
   TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos)) {
-return ConstString(m_ast.PrintTemplateParams(template_param_infos));
-  }
-  return ConstString();
+  if (ParseTemplateParameterInfos(die, template_param_infos))
+return m_ast.PrintTemplateParams(template_param_infos);
+
+  return "";
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
@@ -1632,7 +1632,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 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).AsCString(""));
+0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
 qualified_name.insert(0, class_union_struct_name);
   }
@@ -1650,7 +1650,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 qualified_name.append("::");
 
   qualified_name.append(name);
-  qualified_name.append(GetDIEClassTemplateParams(die).AsCString(""));
+  qualified_name.append(GetDIEClassTemplateParams(die));
 
   return qualified_name;
 }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 136a49e462fbb..7b5ddbaa2a6b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -104,9 +104,9 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   ///
   /// \param die The struct/class DWARFDIE containing template parameters.
   /// \return A string, including surrounding '<>', of the template parameters.
-  /// If the DIE's name already has '<>', returns an empty ConstString because
+  /// If the DIE's name already has '<>', returns an empty string because
   /// it's assumed that the caller is using the 

[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)

2024-06-18 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)


Changes

With simple template names the template arguments aren't embedded in the 
DW_AT_name attribute of the type. The code in
FindDefinitionTypeForDWARFDeclContext was comparing the synthesized template 
arguments on the leaf (most deeply nested) DIE, but was not sufficient, as the 
difference get be at any level above that (Foo::Bar vs. 
Foo::Bar). This patch makes sure we compare the entire context.

As a drive-by I also remove the completely unnecessary ConstStringification of 
the GetDIEClassTemplateParams result.

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


5 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h (+1-1) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
(+8-8) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h (+2-2) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+36-34) 
- (modified) 
lldb/test/Shell/SymbolFile/DWARF/x86/simple-template-names-context.cpp (+1-1) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
index 66db396279e06..abaeb2502cbbd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -58,7 +58,7 @@ class DWARFASTParser {
   virtual void EnsureAllDIEsInDeclContextHaveBeenParsed(
   CompilerDeclContext decl_context) = 0;
 
-  virtual ConstString GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
+  virtual std::string GetDIEClassTemplateParams(const DWARFDIE &die) = 0;
 
   static std::optional
   ParseChildArrayInfo(const DWARFDIE &parent_die,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 02c91ddc57f83..cffe3f7dd6128 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return "";
 
   TypeSystemClang::TemplateParameterInfos template_param_infos;
-  if (ParseTemplateParameterInfos(die, template_param_infos)) {
-return ConstString(m_ast.PrintTemplateParams(template_param_infos));
-  }
-  return ConstString();
+  if (ParseTemplateParameterInfos(die, template_param_infos))
+return m_ast.PrintTemplateParams(template_param_infos);
+
+  return "";
 }
 
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
@@ -1632,7 +1632,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 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).AsCString(""));
+0, GetDIEClassTemplateParams(parent_decl_ctx_die));
 qualified_name.insert(0, "::");
 qualified_name.insert(0, class_union_struct_name);
   }
@@ -1650,7 +1650,7 @@ DWARFASTParserClang::GetCPlusPlusQualifiedName(const 
DWARFDIE &die) {
 qualified_name.append("::");
 
   qualified_name.append(name);
-  qualified_name.append(GetDIEClassTemplateParams(die).AsCString(""));
+  qualified_name.append(GetDIEClassTemplateParams(die));
 
   return qualified_name;
 }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
index 136a49e462fbb..7b5ddbaa2a6b5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -104,9 +104,9 @@ class DWARFASTParserClang : public 
lldb_private::plugin::dwarf::DWARFASTParser {
   ///
   /// \param die The struct/class DWARFDIE containing template parameters.
   /// \return A string, including surrounding '<>', of the template parameters.
-  /// If the DIE's name already has '<>', returns an empty ConstString because
+  /// If the DIE's name already has '<>', returns an empty string because
   /// it's assumed that the caller is using the DIE name anyway.
-  lldb_private::ConstString GetDIEClassTemplateParams(
+  std::string GetDIEClassTemplateParams(
   const lldb_private::plugin::dwarf::DWARFDIE &die) override;
 
 protected:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 369c742a5ee02..1dd19dbaac137 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeF

[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)


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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)


https://github.com/Michael137 commented:

makes sense to me, just left some nits

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)



@@ -12,7 +12,7 @@
 // CHECK: (lldb) target variable
 // CHECK-NEXT: (ReferencesBoth<'A'>) both_a = {
 // CHECK-NEXT:   (Outer<'A'>::Inner *) a = 0x{{[0-9A-Fa-f]*}} {}
-// CHECK-NEXT:   (Outer<'A'>::Inner *) b = 0x{{[0-9A-Fa-f]*}} {}
+// CHECK-NEXT:   (Outer<'B'>::Inner *) b = 0x{{[0-9A-Fa-f]*}} {}

Michael137 wrote:

yay

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)



@@ -838,16 +838,16 @@ DWARFASTParserClang::ParseTypeModifier(const 
SymbolContext &sc,
   return type_sp;
 }
 
-ConstString
+std::string
 DWARFASTParserClang::GetDIEClassTemplateParams(const DWARFDIE &die) {
   if (llvm::StringRef(die.GetName()).contains("<"))
-return ConstString();
+return "";

Michael137 wrote:

Very small nit, but `return {};` might do slightly less work here? (most likely 
doesn't matter)

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)



@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");

Michael137 wrote:

Would the following be more readable?
```suggestion
  if (ctx_die.IsStructUnionOrClass() && dwarf_ast)

template_params.push_back(dwarf_ast->GetDIEClassTemplateParams(ctx_die));
```

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)



@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));
+  if (!tag_matches)
+return false;

Michael137 wrote:

is it worth asserting `die_dwarf_decl_ctx.GetSize() == template_params.size()` 
somewhere around here?

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)


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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)


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


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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)



@@ -2380,7 +2380,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
   }
 
   FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
+   /*TInfo=*/nullptr, SC_None,

AaronBallman wrote:

Ah, you're right, it's only *objects* declared at local scope that have no 
linkage (the following paragraph), not *functions*.

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


[Lldb-commits] [lldb] [lldb/DWARF] Fix type definition search with simple template names (PR #95905)



@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
 // See comments below about -gsimple-template-names for why we attempt to
 // compute missing template parameter names.
-ConstString template_params;
-if (type_system) {
-  DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-  if (dwarf_ast)
-template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+std::vector template_params;
+DWARFDeclContext die_dwarf_decl_ctx;
+DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+ ctx_die = ctx_die.GetParentDeclContextDIE()) {
+  die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+  template_params.push_back(
+  (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+  ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+  : "");
 }
+const bool any_template_params = llvm::any_of(
+template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+auto die_matches = [&](DWARFDIE type_die) {
+  // Resolve the type if both have the same tag or {class, struct} tags.
+  const bool tag_matches =
+  type_die.Tag() == tag ||
+  (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));

Michael137 wrote:

At some point we should probably extract this into a standalone helper. We're 
accumulating a lot of these checks

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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)


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

LGTM with another small improvement that could be made.

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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)



@@ -2380,7 +2380,7 @@ FunctionDecl *Sema::CreateBuiltin(IdentifierInfo *II, 
QualType Type,
   }
 
   FunctionDecl *New = FunctionDecl::Create(Context, Parent, Loc, Loc, II, Type,
-   /*TInfo=*/nullptr, SC_Extern,
+   /*TInfo=*/nullptr, SC_None,

AaronBallman wrote:

I think I've come around to being okay with these changes, thank you!

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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)



@@ -576,13 +576,18 @@ template  static bool 
isFirstInExternCContext(T *D) {
   return First->isInExternCContext();
 }
 
-static bool isSingleLineLanguageLinkage(const Decl &D) {
-  if (const auto *SD = dyn_cast(D.getDeclContext()))
-if (!SD->hasBraces())
-  return true;
+static bool isUnbracedLanguageLinkage(const DeclContext *DC) {
+  if (!DC)
+return false;
+  if (const auto *SD = dyn_cast(DC))
+return !SD->hasBraces();
   return false;
 }

AaronBallman wrote:

```suggestion
  if (const auto *SD = dyn_cast_if_present(DC))
return !SD->hasBraces();
  return false;
}
```
Sorry for not noticing this earlier, but we can simplify even further this way.

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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)


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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;

DavidSpickett wrote:

Do we call this a bug fix, or keep the original behaviour of always returning 
true? Given that this is part of the API, whereas the interactive commands are 
internal.

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;

DavidSpickett wrote:

The docs are non-existent, but just from the prototype I'd assume it can return 
false already: 
https://lldb.llvm.org/python_api/lldb.SBValue.html#lldb.SBValue.GetDescription

So it might break someone's existing script but not in a totally unexpected 
way. I'd lean toward this being a bug fix.

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)


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

>From a9b542a1686be0afd73ad89a504d2c66ba6c4a4f Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Mon, 11 Mar 2024 10:56:29 +
Subject: [PATCH] [lldb] Parse and display register field enums

This teaches lldb to parse the enum XML elements sent by
lldb-server, and make use of the information in `register read`
and `register info`.

The format is described in
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Enum-Target-Types.html.

The target XML parser will drop any invalid enum or evalue. If
we find multiple evalue for the same value, we will use the last
one we find.

The order of evalues from the XML is preserved as there may be
good reason they are not in numerical order.
---
 lldb/include/lldb/Target/RegisterFlags.h  |   7 +
 lldb/source/Core/DumpRegisterInfo.cpp |   7 +-
 .../Process/gdb-remote/ProcessGDBRemote.cpp   | 188 +-
 .../Process/gdb-remote/ProcessGDBRemote.h |   5 +
 .../RegisterTypeBuilderClang.cpp  |  30 +-
 lldb/source/Target/RegisterFlags.cpp  |  10 +
 .../gdb_remote_client/TestXMLRegisterFlags.py | 322 ++
 lldb/unittests/Core/DumpRegisterInfoTest.cpp  |  26 ++
 8 files changed, 573 insertions(+), 22 deletions(-)

diff --git a/lldb/include/lldb/Target/RegisterFlags.h 
b/lldb/include/lldb/Target/RegisterFlags.h
index 1c6bf5dcf4a7f..628c841c10d95 100644
--- a/lldb/include/lldb/Target/RegisterFlags.h
+++ b/lldb/include/lldb/Target/RegisterFlags.h
@@ -32,10 +32,15 @@ class FieldEnum {
 : m_value(value), m_name(std::move(name)) {}
 
 void ToXML(Stream &strm) const;
+
+void log(Log *log) const;
   };
 
   typedef std::vector Enumerators;
 
+  // GDB also includes a "size" that is the size of the underlying register.
+  // We will not store that here but instead use the size of the register
+  // this gets attached to when emitting XML.
   FieldEnum(std::string id, const Enumerators &enumerators);
 
   const Enumerators &GetEnumerators() const { return m_enumerators; }
@@ -44,6 +49,8 @@ class FieldEnum {
 
   void ToXML(Stream &strm, unsigned size) const;
 
+  void log(Log *log) const;
+
 private:
   std::string m_id;
   Enumerators m_enumerators;
diff --git a/lldb/source/Core/DumpRegisterInfo.cpp 
b/lldb/source/Core/DumpRegisterInfo.cpp
index 8334795416902..eccc6784cd497 100644
--- a/lldb/source/Core/DumpRegisterInfo.cpp
+++ b/lldb/source/Core/DumpRegisterInfo.cpp
@@ -111,6 +111,11 @@ void lldb_private::DoDumpRegisterInfo(
   };
   DumpList(strm, "In sets: ", in_sets, emit_set);
 
-  if (flags_type)
+  if (flags_type) {
 strm.Printf("\n\n%s", flags_type->AsTable(terminal_width).c_str());
+
+std::string enumerators = flags_type->DumpEnums(terminal_width);
+if (enumerators.size())
+  strm << "\n\n" << enumerators;
+  }
 }
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index a5a731981299f..4754698e6e88f 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4179,21 +4179,124 @@ struct GdbServerTargetInfo {
   RegisterSetMap reg_set_map;
 };
 
-static std::vector ParseFlagsFields(XMLNode flags_node,
-  unsigned size) {
+static FieldEnum::Enumerators ParseEnumEvalues(const XMLNode &enum_node) {
+  Log *log(GetLog(GDBRLog::Process));
+  // We will use the last instance of each value. Also we preserve the order
+  // of declaration in the XML, as it may not be numerical.
+  std::map enumerators;
+
+  enum_node.ForEachChildElementWithName(
+  "evalue", [&enumerators, &log](const XMLNode &enumerator_node) {
+std::optional name;
+std::optional value;
+
+enumerator_node.ForEachAttribute(
+[&name, &value, &log](const llvm::StringRef &attr_name,
+  const llvm::StringRef &attr_value) {
+  if (attr_name == "name") {
+if (attr_value.size())
+  name = attr_value;
+else
+  LLDB_LOG(log, "ProcessGDBRemote::ParseEnumEvalues "
+"Ignoring empty name in evalue");
+  } else if (attr_name == "value") {
+uint64_t parsed_value = 0;
+if (llvm::to_integer(attr_value, parsed_value))
+  value = parsed_value;
+else
+  LLDB_LOG(log,
+   "ProcessGDBRemote::ParseEnumEvalues "
+   "Invalid value \"{0}\" in "
+   "evalue",
+   attr_value.data());
+  } else
+LLDB_LOG(log,
+ "ProcessGDBRemote::ParseEnumEvalues Ignoring "
+ "unknown attribute "
+ "\

[Lldb-commits] [lldb] [LLDB] Don't cache module sp when Activate() fails. (PR #95586)


https://github.com/thetruestblue updated 
https://github.com/llvm/llvm-project/pull/95586

>From db161e5c87eecbd5607f78e7afd00af183aa415c Mon Sep 17 00:00:00 2001
From: Blue Gaston 
Date: Fri, 14 Jun 2024 12:53:27 -0400
Subject: [PATCH 1/2] [LLDB] Don't cache module sp when Activate() fails.

Currently, the instrumentation runtime is caching a library the first time it 
sees it in the module list. However, in some rare cases on Darwin, the cached 
pre-run unloaded modules are different from the runtime module that is loaded 
at runtime. This patch removes the cached module if the plugin fails to 
activate, ensuring that on subsequent calls we don't try to activate using the 
unloaded cached module.

There are a few related bugs to fix in a follow up: CheckIfRuntimeValid should 
have a stronger check to ensure the module is loaded and can be activated. 
Further investigation in UpdateSpecialBinariesFromNewImageInfos calling 
ModulesDidLoad when the module list may have unloaded modules.

I have not included a test for the following reasons:
1. This is an incredibly rare occurance and is only observed in a specific 
circumstance on Darwin. It is tied to behavior in the DynamicLoader thai is not 
commonly encountered.

2. It is difficult to reproduce -- this bug requires precise conditions on 
darwin and it is unclear how we'd reproduce that in a controlled testing 
environment.

rdar://128971453
---
 lldb/source/Target/InstrumentationRuntime.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lldb/source/Target/InstrumentationRuntime.cpp 
b/lldb/source/Target/InstrumentationRuntime.cpp
index 9f22a1be20ccb..94f4ca353d7ef 100644
--- a/lldb/source/Target/InstrumentationRuntime.cpp
+++ b/lldb/source/Target/InstrumentationRuntime.cpp
@@ -60,6 +60,8 @@ void InstrumentationRuntime::ModulesDidLoad(
   if (CheckIfRuntimeIsValid(module_sp)) {
 SetRuntimeModuleSP(module_sp);
 Activate();
+if (IsActive())
+  SetRuntimeModuleSP({}); // Don't cache module if activation failed.
 return false; // Stop iterating, we're done.
   }
 }

>From f3731ad28824f38ef556665b9ec49d7f610f58b6 Mon Sep 17 00:00:00 2001
From: thetruestblue <92476612+thetruestb...@users.noreply.github.com>
Date: Fri, 14 Jun 2024 19:22:43 -0400
Subject: [PATCH 2/2] Update InstrumentationRuntime.cpp

---
 lldb/source/Target/InstrumentationRuntime.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Target/InstrumentationRuntime.cpp 
b/lldb/source/Target/InstrumentationRuntime.cpp
index 94f4ca353d7ef..9da06e8e155af 100644
--- a/lldb/source/Target/InstrumentationRuntime.cpp
+++ b/lldb/source/Target/InstrumentationRuntime.cpp
@@ -60,7 +60,7 @@ void InstrumentationRuntime::ModulesDidLoad(
   if (CheckIfRuntimeIsValid(module_sp)) {
 SetRuntimeModuleSP(module_sp);
 Activate();
-if (IsActive())
+if (!IsActive())
   SetRuntimeModuleSP({}); // Don't cache module if activation failed.
 return false; // Stop iterating, we're done.
   }

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


[Lldb-commits] [lldb] 41f6aee - [LLDB] Don't cache module sp when Activate() fails. (#95586)


Author: thetruestblue
Date: 2024-06-18T07:23:28-07:00
New Revision: 41f6aee769a900558e58eba7b5f9044f8f8a05b7

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

LOG: [LLDB] Don't cache module sp when Activate() fails. (#95586)

Currently, the instrumentation runtime is caching a library the first
time it sees it in the module list. However, in some rare cases on
Darwin, the cached pre-run unloaded modules are different from the
runtime module that is loaded at runtime. This patch removes the cached
module if the plugin fails to activate, ensuring that on subsequent
calls we don't try to activate using the unloaded cached module.

There are a few related bugs to fix in a follow up: CheckIfRuntimeValid
should have a stronger check to ensure the module is loaded and can be
activated. Further investigation in
UpdateSpecialBinariesFromNewImageInfos calling ModulesDidLoad when the
module list may have unloaded modules.

I have not included a test for the following reasons:
1. This is an incredibly rare occurance and is only observed in a
specific circumstance on Darwin. It is tied to behavior in the
DynamicLoader thai is not commonly encountered.

2. It is difficult to reproduce -- this bug requires precise conditions
on darwin and it is unclear how we'd reproduce that in a controlled
testing environment.

rdar://128971453

Added: 


Modified: 
lldb/source/Target/InstrumentationRuntime.cpp

Removed: 




diff  --git a/lldb/source/Target/InstrumentationRuntime.cpp 
b/lldb/source/Target/InstrumentationRuntime.cpp
index 9f22a1be20ccb..9da06e8e155af 100644
--- a/lldb/source/Target/InstrumentationRuntime.cpp
+++ b/lldb/source/Target/InstrumentationRuntime.cpp
@@ -60,6 +60,8 @@ void InstrumentationRuntime::ModulesDidLoad(
   if (CheckIfRuntimeIsValid(module_sp)) {
 SetRuntimeModuleSP(module_sp);
 Activate();
+if (!IsActive())
+  SetRuntimeModuleSP({}); // Don't cache module if activation failed.
 return false; // Stop iterating, we're done.
   }
 }



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


[Lldb-commits] [lldb] [LLDB] Don't cache module sp when Activate() fails. (PR #95586)


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


[Lldb-commits] [lldb] 7dbc168 - [lldb] Extend Python interpreter workaround to Xcode Python (attempt #2.5)


Author: Jonas Devlieghere
Date: 2024-06-18T08:12:11-07:00
New Revision: 7dbc1688b550510b6777acbbbcfea8e02ba34ed2

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

LOG: [lldb] Extend Python interpreter workaround to Xcode Python (attempt #2.5)

The Python interpreter in Xcode cannot be copied because of a relative
RPATH. Our workaround would just use that Python interpreter directly
when it detects this. For the reasons explained in my previous commit,
that doesn't work in a virtual environment. Address this case by
creating a symlink to the "real" interpreter in the virtual environment.

Added: 


Modified: 
lldb/test/API/lit.cfg.py

Removed: 




diff  --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index 6d45508ccb916..96520c7c82624 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -99,10 +99,11 @@ def find_python_interpreter():
 except subprocess.CalledProcessError:
 # The copied Python didn't work. Assume we're dealing with the Python
 # interpreter in Xcode. Given that this is not a system binary SIP
-# won't prevent us form injecting the interceptors so we get away with
-# not copying the executable.
+# won't prevent us form injecting the interceptors, but when running in
+# a virtual environment, we can't use it directly. Create a symlink
+# instead.
 os.remove(copied_python)
-return real_python
+os.symlink(real_python, copied_python)
 
 # The copied Python works.
 return copied_python



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


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


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

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

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

Reviewers: clayborg

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

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange &ref() const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges &ref() const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList &ranges,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend c

[Lldb-commits] [lldb] fcee033 - [lldb] Suppress unsupported language warning for assembly (#95871)


Author: Jonas Devlieghere
Date: 2024-06-18T08:51:40-07:00
New Revision: fcee0333bab6747ca34188f3a781f4fef900b7fe

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

LOG: [lldb] Suppress unsupported language warning for assembly (#95871)

The following warning is technically correct, but pretty much useless,
since there aren't any frame variables that we'd expect the debugger to
understand.

> This version of LLDB has no plugin for the language "assembler".
> Inspection of frame variables will be limited.

This message is useful in the general case but should be suppressed for
the "assembler" case.

rdar://92745462

Added: 


Modified: 
lldb/source/Target/Process.cpp
lldb/test/Shell/Process/UnsupportedLanguage.test

Removed: 




diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 1e321f8bde391..9b905663a2c32 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5924,7 +5924,9 @@ void Process::PrintWarningUnsupportedLanguage(const 
SymbolContext &sc) {
   if (!sc.module_sp)
 return;
   LanguageType language = sc.GetLanguage();
-  if (language == eLanguageTypeUnknown)
+  if (language == eLanguageTypeUnknown ||
+  language == lldb::eLanguageTypeAssembly ||
+  language == lldb::eLanguageTypeMipsAssembler)
 return;
   LanguageSet plugins =
   PluginManager::GetAllTypeSystemSupportedLanguagesForTypes();

diff  --git a/lldb/test/Shell/Process/UnsupportedLanguage.test 
b/lldb/test/Shell/Process/UnsupportedLanguage.test
index 8cf0c048e366b..d7e6e5de77512 100644
--- a/lldb/test/Shell/Process/UnsupportedLanguage.test
+++ b/lldb/test/Shell/Process/UnsupportedLanguage.test
@@ -1,8 +1,17 @@
-Test warnings.
+Test unsupported language warning
+
 REQUIRES: shell
+
 RUN: %clang_host %S/Inputs/true.c -std=c99 -g -c -S -emit-llvm -o - \
 RUN:   | sed -e 's/DW_LANG_C99/DW_LANG_Mips_Assembler/g' >%t.ll
 RUN: %clang_host %t.ll -g -o %t.exe
-RUN: %lldb -o "b main" -o r -o q -b %t.exe 2>&1 | FileCheck %s
+RUN: %lldb -o "b main" -o r -o q -b %t.exe 2>&1 | FileCheck %s --check-prefix 
ASM
+
+ASM-NOT: This version of LLDB has no plugin for the language "assembler"
+
+RUN: %clang_host %S/Inputs/true.c -std=c99 -g -c -S -emit-llvm -o - \
+RUN:   | sed -e 's/DW_LANG_C99/DW_LANG_Cobol74/g' >%t.ll
+RUN: %clang_host %t.ll -g -o %t.exe
+RUN: %lldb -o "b main" -o r -o q -b %t.exe 2>&1 | FileCheck %s --check-prefix 
COBOL
 
-CHECK: This version of LLDB has no plugin for the language "assembler"
+COBOL: This version of LLDB has no plugin for the language "cobol74"



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


[Lldb-commits] [lldb] [lldb] Suppress unsupported language warning for assembly (PR #95871)


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


[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)


https://github.com/temyurchenko updated 
https://github.com/llvm/llvm-project/pull/93913

>From 410c7ba9fb7667dabdfbc48fdbda427401ca8df0 Mon Sep 17 00:00:00 2001
From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com>
Date: Thu, 30 May 2024 16:18:47 -0400
Subject: [PATCH 1/3] [clang][AST] fix ast-print of `extern ` with >=2
 declarators (#93131)

Problem: the printer used to ignore all but the first declarator for
unbraced language linkage declarators. Furthemore, that one would
be printed without the final semicolon.

Solution: for unbraced case we traverse all declarators via
`VisitDeclContext`. Furthermore, in appropriate visitors we query
for whether they are a part of the unbraced extern language linkage
spec, and if so, print appropriately.
---
 clang/lib/AST/DeclPrinter.cpp | 55 ++-
 clang/test/AST/ast-print-language-linkage.cpp | 31 +++
 2 files changed, 72 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/AST/ast-print-language-linkage.cpp

diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 0cf4e64f83b8d..9250a7f6eceb2 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, 
llvm::raw_ostream &Out,
   Out << Proto;
 }
 
-static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
+static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
QualType T,
llvm::raw_ostream &Out) {
   StringRef prefix = T->isClassType()   ? "class "
@@ -643,6 +643,22 @@ static void 
MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
   Out << prefix;
 }
 
+/// Return the language of the linkage spec of `D`, if applicable.
+///
+/// \Return - "C" if `D` has been declared with unbraced `extern "C"`
+/// - "C++" if `D` has been declared with unbraced `extern "C++"`
+/// - nullptr in any other case
+static const char *tryGetUnbracedLinkageLanguage(const Decl *D) {
+  const auto *SD = dyn_cast(D->getDeclContext());
+  if (!SD || SD->hasBraces())
+return nullptr;
+  if (SD->getLanguage() == LinkageSpecLanguageIDs::C)
+return "C";
+  assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX &&
+ "unknown language in linkage specification");
+  return "C++";
+}
+
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   if (!D->getDescribedFunctionTemplate() &&
   !D->isFunctionTemplateSpecialization()) {
@@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   CXXConversionDecl *ConversionDecl = dyn_cast(D);
   CXXDeductionGuideDecl *GuideDecl = dyn_cast(D);
   if (!Policy.SuppressSpecifiers) {
+if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) {
+  // the "extern" specifier is implicit
+  assert(D->getStorageClass() == SC_None);
+  Out << "extern \"" << Lang << "\" ";
+}
 switch (D->getStorageClass()) {
 case SC_None: break;
 case SC_Extern: Out << "extern "; break;
@@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   }
   if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
   !Policy.SuppressUnwrittenScope)
-MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(),
+maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(),
Out);
   AFT->getReturnType().print(Out, Policy, Proto);
   Proto.clear();
@@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
 : D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
 
   if (!Policy.SuppressSpecifiers) {
+if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) {
+  // the "extern" specifier is implicit
+  assert(D->getStorageClass() == SC_None);
+  Out << "extern \"" << Lang << "\" ";
+}
 StorageClass SC = D->getStorageClass();
 if (SC != SC_None)
   Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
@@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
 
   if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
   !Policy.SuppressUnwrittenScope)
-MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out);
+maybePrintTagKeywordIfSupressingScopes(Policy, T, Out);
 
   printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters &&
 D->getIdentifier())
@@ -1064,6 +1090,8 @@ void 
DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
 
 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
   prettyPrintAttributes(D);
+  if (const char *Lang = tryGetUnbracedLinkageLanguage(D))
+Out << "extern \"" << Lang << "\";";
 }
 
 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
@@ -1136,22 +1164,21 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
 }
 
 void DeclPrinter::VisitLinkageSpecDecl(Li

[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)


https://github.com/temyurchenko updated 
https://github.com/llvm/llvm-project/pull/93913

>From 410c7ba9fb7667dabdfbc48fdbda427401ca8df0 Mon Sep 17 00:00:00 2001
From: Artem Yurchenko <44875844+temyurche...@users.noreply.github.com>
Date: Thu, 30 May 2024 16:18:47 -0400
Subject: [PATCH 1/2] [clang][AST] fix ast-print of `extern ` with >=2
 declarators (#93131)

Problem: the printer used to ignore all but the first declarator for
unbraced language linkage declarators. Furthemore, that one would
be printed without the final semicolon.

Solution: for unbraced case we traverse all declarators via
`VisitDeclContext`. Furthermore, in appropriate visitors we query
for whether they are a part of the unbraced extern language linkage
spec, and if so, print appropriately.
---
 clang/lib/AST/DeclPrinter.cpp | 55 ++-
 clang/test/AST/ast-print-language-linkage.cpp | 31 +++
 2 files changed, 72 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/AST/ast-print-language-linkage.cpp

diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 0cf4e64f83b8d..9250a7f6eceb2 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -633,7 +633,7 @@ static void printExplicitSpecifier(ExplicitSpecifier ES, 
llvm::raw_ostream &Out,
   Out << Proto;
 }
 
-static void MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
+static void maybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
QualType T,
llvm::raw_ostream &Out) {
   StringRef prefix = T->isClassType()   ? "class "
@@ -643,6 +643,22 @@ static void 
MaybePrintTagKeywordIfSupressingScopes(PrintingPolicy &Policy,
   Out << prefix;
 }
 
+/// Return the language of the linkage spec of `D`, if applicable.
+///
+/// \Return - "C" if `D` has been declared with unbraced `extern "C"`
+/// - "C++" if `D` has been declared with unbraced `extern "C++"`
+/// - nullptr in any other case
+static const char *tryGetUnbracedLinkageLanguage(const Decl *D) {
+  const auto *SD = dyn_cast(D->getDeclContext());
+  if (!SD || SD->hasBraces())
+return nullptr;
+  if (SD->getLanguage() == LinkageSpecLanguageIDs::C)
+return "C";
+  assert(SD->getLanguage() == LinkageSpecLanguageIDs::CXX &&
+ "unknown language in linkage specification");
+  return "C++";
+}
+
 void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   if (!D->getDescribedFunctionTemplate() &&
   !D->isFunctionTemplateSpecialization()) {
@@ -662,6 +678,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   CXXConversionDecl *ConversionDecl = dyn_cast(D);
   CXXDeductionGuideDecl *GuideDecl = dyn_cast(D);
   if (!Policy.SuppressSpecifiers) {
+if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) {
+  // the "extern" specifier is implicit
+  assert(D->getStorageClass() == SC_None);
+  Out << "extern \"" << Lang << "\" ";
+}
 switch (D->getStorageClass()) {
 case SC_None: break;
 case SC_Extern: Out << "extern "; break;
@@ -807,7 +828,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
   }
   if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
   !Policy.SuppressUnwrittenScope)
-MaybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(),
+maybePrintTagKeywordIfSupressingScopes(Policy, AFT->getReturnType(),
Out);
   AFT->getReturnType().print(Out, Policy, Proto);
   Proto.clear();
@@ -932,6 +953,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
 : D->getASTContext().getUnqualifiedObjCPointerType(D->getType());
 
   if (!Policy.SuppressSpecifiers) {
+if (const char *Lang = tryGetUnbracedLinkageLanguage(D)) {
+  // the "extern" specifier is implicit
+  assert(D->getStorageClass() == SC_None);
+  Out << "extern \"" << Lang << "\" ";
+}
 StorageClass SC = D->getStorageClass();
 if (SC != SC_None)
   Out << VarDecl::getStorageClassSpecifierString(SC) << " ";
@@ -961,7 +987,7 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
 
   if (!Policy.SuppressTagKeyword && Policy.SuppressScope &&
   !Policy.SuppressUnwrittenScope)
-MaybePrintTagKeywordIfSupressingScopes(Policy, T, Out);
+maybePrintTagKeywordIfSupressingScopes(Policy, T, Out);
 
   printDeclType(T, (isa(D) && Policy.CleanUglifiedParameters &&
 D->getIdentifier())
@@ -1064,6 +1090,8 @@ void 
DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
 
 void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
   prettyPrintAttributes(D);
+  if (const char *Lang = tryGetUnbracedLinkageLanguage(D))
+Out << "extern \"" << Lang << "\";";
 }
 
 void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
@@ -1136,22 +1164,21 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
 }
 
 void DeclPrinter::VisitLinkageSpecDecl(Li

[Lldb-commits] [clang] [lldb] [clang][AST] fix ast-print of extern with >=2 declarators, fixed (PR #93913)



@@ -576,13 +576,18 @@ template  static bool 
isFirstInExternCContext(T *D) {
   return First->isInExternCContext();
 }
 
-static bool isSingleLineLanguageLinkage(const Decl &D) {
-  if (const auto *SD = dyn_cast(D.getDeclContext()))
-if (!SD->hasBraces())
-  return true;
+static bool isUnbracedLanguageLinkage(const DeclContext *DC) {
+  if (!DC)
+return false;
+  if (const auto *SD = dyn_cast(DC))
+return !SD->hasBraces();
   return false;
 }

temyurchenko wrote:

Done!

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


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



@@ -791,26 +807,101 @@ void MinidumpFileBuilder::AddLinuxFileStreams(
   size_t size = memory_buffer->getBufferSize();
   if (size == 0)
 continue;
-  AddDirectory(stream, size);
+  error = AddDirectory(stream, size);
+  if (error.Fail())
+return error;
   m_data.AppendData(memory_buffer->getBufferStart(), size);
 }
   }
+
+  return error;
 }
 
-Status MinidumpFileBuilder::Dump(lldb::FileUP &core_file) const {
-  constexpr size_t header_size = sizeof(llvm::minidump::Header);
-  constexpr size_t directory_size = sizeof(llvm::minidump::Directory);
+Status MinidumpFileBuilder::AddMemoryList(SaveCoreStyle core_style) {
+  Status error;
+
+  // We first save the thread stacks to ensure they fit in the first UINT32_MAX
+  // bytes of the core file. Thread structures in minidump files can only use
+  // 32 bit memory descriptiors, so we emit them first to ensure the memory is
+  // in accessible with a 32 bit offset.
+  Process::CoreFileMemoryRanges ranges_32;
+  Process::CoreFileMemoryRanges ranges_64;
+  error = m_process_sp->CalculateCoreFileSaveRanges(
+  SaveCoreStyle::eSaveCoreStackOnly, ranges_32);
+  if (error.Fail())
+return error;
 
+  uint64_t total_size =
+  ranges_32.size() * sizeof(llvm::minidump::MemoryDescriptor);
+  std::unordered_set stack_start_addresses;
+  for (const auto &core_range : ranges_32) {
+stack_start_addresses.insert(core_range.range.start());
+total_size += core_range.range.size();
+  }
+
+  if (total_size >= UINT32_MAX) {
+error.SetErrorStringWithFormat("Unable to write minidump. Stack memory "
+   "exceeds 32b limit. (Num Stacks %zu)",
+   ranges_32.size());
+return error;
+  }
+
+  Process::CoreFileMemoryRanges all_core_memory_ranges;
+  if (core_style != SaveCoreStyle::eSaveCoreStackOnly) {
+error = m_process_sp->CalculateCoreFileSaveRanges(core_style,
+  all_core_memory_ranges);
+if (error.Fail())
+  return error;
+  }
+
+  // After saving the stacks, we start packing as much as we can into 32b.
+  // We apply a generous padding here so that the Directory, MemoryList and
+  // Memory64List sections all begin in 32b addressable space.
+  // Then anything overflow extends into 64b addressable space.
+  total_size +=
+  256 + (all_core_memory_ranges.size() - stack_start_addresses.size()) *
+sizeof(llvm::minidump::MemoryDescriptor_64);

Jlalond wrote:

This actually works, because we'll never enter the loop unless 
`all_core_memory_ranges` is non empty, where total_size will actually be used. 
Prior to code review feedback we always called to get memory ranges, even when 
it's just stacks, ensuring we would always have at least stacks in 
`all_core_memory_ranges`. 

I have added the check for empty and an explanation comment as well.

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


[Lldb-commits] [lldb] [API] add GetSyntheticValue (PR #95959)


https://github.com/v-bulle created 
https://github.com/llvm/llvm-project/pull/95959

Adds GetSyntheticValue to the API on top of GetNonSyntheticValue.

>From 27a00b54bc991dfb4747e0d37b15878beebaabba Mon Sep 17 00:00:00 2001
From: Vincent Belliard 
Date: Wed, 12 Jun 2024 14:23:15 -0700
Subject: [PATCH] [API] add GetSyntheticValue

---
 lldb/include/lldb/API/SBValue.h |  2 ++
 lldb/source/API/SBValue.cpp | 12 
 2 files changed, 14 insertions(+)

diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 65920c76df7a8..bec816fb45184 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -89,6 +89,8 @@ class LLDB_API SBValue {
 
   lldb::SBValue GetNonSyntheticValue();
 
+  lldb::SBValue GetSyntheticValue();
+
   lldb::DynamicValueType GetPreferDynamicValue();
 
   void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic);
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..6b77c0e95cedd 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -761,6 +761,18 @@ lldb::SBValue SBValue::GetNonSyntheticValue() {
   return value_sb;
 }
 
+lldb::SBValue SBValue::GetSyntheticValue() {
+  LLDB_INSTRUMENT_VA(this);
+
+  SBValue value_sb;
+  if (IsValid()) {
+ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
+   m_opaque_sp->GetUseDynamic(), true));
+value_sb.SetSP(proxy_sp);
+  }
+  return value_sb;
+}
+
 lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
   LLDB_INSTRUMENT_VA(this);
 

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


[Lldb-commits] [lldb] [API] add GetSyntheticValue (PR #95959)


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vincent Belliard (v-bulle)


Changes

Adds GetSyntheticValue to the API on top of GetNonSyntheticValue.

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


2 Files Affected:

- (modified) lldb/include/lldb/API/SBValue.h (+2) 
- (modified) lldb/source/API/SBValue.cpp (+12) 


``diff
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 65920c76df7a8..bec816fb45184 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -89,6 +89,8 @@ class LLDB_API SBValue {
 
   lldb::SBValue GetNonSyntheticValue();
 
+  lldb::SBValue GetSyntheticValue();
+
   lldb::DynamicValueType GetPreferDynamicValue();
 
   void SetPreferDynamicValue(lldb::DynamicValueType use_dynamic);
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..6b77c0e95cedd 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -761,6 +761,18 @@ lldb::SBValue SBValue::GetNonSyntheticValue() {
   return value_sb;
 }
 
+lldb::SBValue SBValue::GetSyntheticValue() {
+  LLDB_INSTRUMENT_VA(this);
+
+  SBValue value_sb;
+  if (IsValid()) {
+ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),
+   m_opaque_sp->GetUseDynamic(), true));
+value_sb.SetSP(proxy_sp);
+  }
+  return value_sb;
+}
+
 lldb::DynamicValueType SBValue::GetPreferDynamicValue() {
   LLDB_INSTRUMENT_VA(this);
 

``




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


[Lldb-commits] [lldb] [lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts (PR #95963)


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

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

rdar://96236519

>From 25e64a8a622496cbde447d0d5185f0e7ef06586d Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 18 Jun 2024 18:04:03 +0100
Subject: [PATCH] [lldb][ObjC] Don't query objective-c runtime for decls in C++
 contexts

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

rdar://96236519
---
 .../ExpressionParser/Clang/ClangASTSource.cpp |  2 +-
 .../TestObjCFromCppFramesWithoutDebugInfo.py  |  5 +
 .../test/Shell/Expr/TestObjCInCXXContext.test | 21 +++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 lldb/test/Shell/Expr/TestObjCInCXXContext.test

diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 82a7a2cc3f1ef..1fdd272dcbece 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
 FindDeclInModules(context, name);
   }
 
-  if (!context.m_found_type) {
+  if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
 FindDeclInObjCRuntime(context, name);
   }
 }
diff --git 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index ef8d5540fa4ef..2c2e072bba686 100644
--- 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -15,4 +15,9 @@ def test(self):
 (_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
 
 self.assertState(process.GetState(), lldb.eStateStopped)
+
+# Tests that we can use builtin Objective-C identifiers.
 self.expect("expr id", error=False)
+
+# Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
+self.expect_expr("NSString *c; c == nullptr", result_value="true", 
result_type="bool")
diff --git a/lldb/test/Shell/Expr/TestObjCInCXXContext.test 
b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
new file mode 100644
index 0..8537799bdeb67
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
@@ -0,0 +1,21 @@
+// UNSUPPORTED: system-linux, system-windows
+
+// Tests that we don't consult the the Objective-C runtime
+// plugin when in a purely C++ context.
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// RUN: %lldb %t \
+// RUN:   -o "b main" -o run \
+// RUN:   -o "expression --language objective-c -- NSString * a; a" \
+// RUN:   -o "expression --language objective-c++ -- NSString * b; b" \
+// RUN:   -o "expression NSString" \
+// RUN:   2>&1 | FileCheck %s
+
+// CHECK:  (lldb) expression --language objective-c -- NSString * a; a
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression --language objective-c++ -- NSString * b; b
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression NSString
+// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'

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


[Lldb-commits] [lldb] [lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts (PR #95963)


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)


Changes

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

rdar://96236519

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


3 Files Affected:

- (modified) lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
(+1-1) 
- (modified) 
lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 (+5) 
- (added) lldb/test/Shell/Expr/TestObjCInCXXContext.test (+21) 


``diff
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 82a7a2cc3f1ef..1fdd272dcbece 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
 FindDeclInModules(context, name);
   }
 
-  if (!context.m_found_type) {
+  if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
 FindDeclInObjCRuntime(context, name);
   }
 }
diff --git 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index ef8d5540fa4ef..2c2e072bba686 100644
--- 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -15,4 +15,9 @@ def test(self):
 (_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
 
 self.assertState(process.GetState(), lldb.eStateStopped)
+
+# Tests that we can use builtin Objective-C identifiers.
 self.expect("expr id", error=False)
+
+# Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
+self.expect_expr("NSString *c; c == nullptr", result_value="true", 
result_type="bool")
diff --git a/lldb/test/Shell/Expr/TestObjCInCXXContext.test 
b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
new file mode 100644
index 0..8537799bdeb67
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
@@ -0,0 +1,21 @@
+// UNSUPPORTED: system-linux, system-windows
+
+// Tests that we don't consult the the Objective-C runtime
+// plugin when in a purely C++ context.
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// RUN: %lldb %t \
+// RUN:   -o "b main" -o run \
+// RUN:   -o "expression --language objective-c -- NSString * a; a" \
+// RUN:   -o "expression --language objective-c++ -- NSString * b; b" \
+// RUN:   -o "expression NSString" \
+// RUN:   2>&1 | FileCheck %s
+
+// CHECK:  (lldb) expression --language objective-c -- NSString * a; a
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression --language objective-c++ -- NSString * b; b
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression NSString
+// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'

``




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


[Lldb-commits] [lldb] 295d574 - [lldb] Remove LLVM_PRETTY_FUNCTION from LLDB_SCOPED_TIMERF


Author: Jonas Devlieghere
Date: 2024-06-18T11:07:24-07:00
New Revision: 295d5746dfc1ff5ae7d5767c6ada6130a2a69533

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

LOG: [lldb] Remove LLVM_PRETTY_FUNCTION from LLDB_SCOPED_TIMERF

The macro already uses LLVM_PRETTY_FUNCTION as the timer category, so
there's no point in duplicating it in the timer message.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Symbol/DWARFCallFrameInfo.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
index da73891f66654..f383261e8a5fc 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
@@ -89,8 +89,7 @@ void DWARFDebugAranges::AppendRange(dw_offset_t offset, 
dw_addr_t low_pc,
 }
 
 void DWARFDebugAranges::Sort(bool minimize) {
-  LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
- static_cast(this));
+  LLDB_SCOPED_TIMER();
 
   m_aranges.Sort();
   m_aranges.CombineConsecutiveEntriesWithEqualData();

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 369c742a5ee02..55ddc94a8629f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -710,8 +710,8 @@ llvm::DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
 
 DWARFDebugInfo &SymbolFileDWARF::DebugInfo() {
   llvm::call_once(m_info_once_flag, [&] {
-LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
-   static_cast(this));
+LLDB_SCOPED_TIMER();
+
 m_info = std::make_unique(*this, m_context);
   });
   return *m_info;
@@ -732,8 +732,7 @@ DWARFCompileUnit 
*SymbolFileDWARF::GetDWARFCompileUnit(CompileUnit *comp_unit) {
 
 DWARFDebugRanges *SymbolFileDWARF::GetDebugRanges() {
   if (!m_ranges) {
-LLDB_SCOPED_TIMERF("%s this = %p", LLVM_PRETTY_FUNCTION,
-   static_cast(this));
+LLDB_SCOPED_TIMER();
 
 if (m_context.getOrLoadRangesData().GetByteSize() > 0)
   m_ranges = std::make_unique();

diff  --git a/lldb/source/Symbol/DWARFCallFrameInfo.cpp 
b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
index dc54d13ae23cb..f3df8a2c27f5a 100644
--- a/lldb/source/Symbol/DWARFCallFrameInfo.cpp
+++ b/lldb/source/Symbol/DWARFCallFrameInfo.cpp
@@ -423,8 +423,7 @@ void DWARFCallFrameInfo::GetFDEIndex() {
   if (m_fde_index_initialized) // if two threads hit the locker
 return;
 
-  LLDB_SCOPED_TIMERF("%s - %s", LLVM_PRETTY_FUNCTION,
- m_objfile.GetFileSpec().GetFilename().AsCString(""));
+  LLDB_SCOPED_TIMERF("%s", 
m_objfile.GetFileSpec().GetFilename().AsCString(""));
 
   bool clear_address_zeroth_bit = false;
   if (ArchSpec arch = m_objfile.GetArchitecture()) {



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


[Lldb-commits] [lldb] [lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts (PR #95963)


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 
b650764b16b5c8790325775ac5f87f0b1c0beca7...25e64a8a622496cbde447d0d5185f0e7ef06586d
 
lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
``





View the diff from darker here.


``diff
--- TestObjCFromCppFramesWithoutDebugInfo.py2024-06-18 18:00:52.00 +
+++ TestObjCFromCppFramesWithoutDebugInfo.py2024-06-18 18:08:30.343034 +
@@ -18,6 +18,8 @@
 
 # Tests that we can use builtin Objective-C identifiers.
 self.expect("expr id", error=False)
 
 # Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
-self.expect_expr("NSString *c; c == nullptr", result_value="true", 
result_type="bool")
+self.expect_expr(
+"NSString *c; c == nullptr", result_value="true", 
result_type="bool"
+)

``




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


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


dwblaikie wrote:

> That would mean if someone wrote `struct Empty {}; struct Z { Empty a,b,c; 
> }`, we'd lower it to `{ [3 x i8] }` instead of `{%Empty, %Empty, %Empty}`, 
> which is a bit ugly. Other than that, sure, I guess we could do that.

Ah, fair enough. Glad to understand and I don't feel /super/ strongly either 
way. Though it might help with confidence if codegen didn't depend on this 
property at all (that it depends on the property a bit may make it harder to 
detect if later codegen depends on the property in a real/ABI-breaking way).

The struct layout validation stuff that @Michael137 found may be adequate to 
provide confidence (especially combined with fuzzing, maybe) without the need 
for the codegen-is-zero-length-independent invariant.

I don't feel too strongly - mostly happy with whatever Clang owners are happy 
with.

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


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


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

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

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

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  61 +
 .../API/python_api/find_in_memory/main.cpp|  11 +
 15 files changed, 605 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange &ref() const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges &ref() const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList &ranges,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend c

[Lldb-commits] [lldb] [lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts (PR #95963)


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

>From 25e64a8a622496cbde447d0d5185f0e7ef06586d Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 18 Jun 2024 18:04:03 +0100
Subject: [PATCH 1/2] [lldb][ObjC] Don't query objective-c runtime for decls in
 C++ contexts

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

rdar://96236519
---
 .../ExpressionParser/Clang/ClangASTSource.cpp |  2 +-
 .../TestObjCFromCppFramesWithoutDebugInfo.py  |  5 +
 .../test/Shell/Expr/TestObjCInCXXContext.test | 21 +++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 lldb/test/Shell/Expr/TestObjCInCXXContext.test

diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp 
b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index 82a7a2cc3f1ef..1fdd272dcbece 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -637,7 +637,7 @@ void ClangASTSource::FindExternalVisibleDecls(
 FindDeclInModules(context, name);
   }
 
-  if (!context.m_found_type) {
+  if (!context.m_found_type && m_ast_context->getLangOpts().ObjC) {
 FindDeclInObjCRuntime(context, name);
   }
 }
diff --git 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index ef8d5540fa4ef..2c2e072bba686 100644
--- 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -15,4 +15,9 @@ def test(self):
 (_, process, _, _) = lldbutil.run_to_name_breakpoint(self, "main")
 
 self.assertState(process.GetState(), lldb.eStateStopped)
+
+# Tests that we can use builtin Objective-C identifiers.
 self.expect("expr id", error=False)
+
+# Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
+self.expect_expr("NSString *c; c == nullptr", result_value="true", 
result_type="bool")
diff --git a/lldb/test/Shell/Expr/TestObjCInCXXContext.test 
b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
new file mode 100644
index 0..8537799bdeb67
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCInCXXContext.test
@@ -0,0 +1,21 @@
+// UNSUPPORTED: system-linux, system-windows
+
+// Tests that we don't consult the the Objective-C runtime
+// plugin when in a purely C++ context.
+//
+// RUN: %clangxx_host %p/Inputs/objc-cast.cpp -g -o %t
+// RUN: %lldb %t \
+// RUN:   -o "b main" -o run \
+// RUN:   -o "expression --language objective-c -- NSString * a; a" \
+// RUN:   -o "expression --language objective-c++ -- NSString * b; b" \
+// RUN:   -o "expression NSString" \
+// RUN:   2>&1 | FileCheck %s
+
+// CHECK:  (lldb) expression --language objective-c -- NSString * a; a
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression --language objective-c++ -- NSString * b; b
+// CHECK-NEXT: (NSString *){{.*}}= nil
+
+// CHECK:  (lldb) expression NSString
+// CHECK-NEXT: error:{{.*}} use of undeclared identifier 'NSString'

>From 0d6597e36e5ede44c1b586e18e44f81aca90e8b9 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 18 Jun 2024 19:16:58 +0100
Subject: [PATCH 2/2] fixup! clang-format

---
 .../TestObjCFromCppFramesWithoutDebugInfo.py  | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
index 2c2e072bba686..497c0dd128f48 100644
--- 
a/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
+++ 
b/lldb/test/API/lang/objcxx/objc-from-cpp-frames-without-debuginfo/TestObjCFromCppFramesWithoutDebugInfo.py
@@ -20,4 +20,6 @@ def test(self):
 self.expect("expr id", error=False)
 
 # Tests that we can lookup Objective-C decls in the ObjC runtime 
plugin.
-self.expect_expr("NSString *c; c == nullptr", result_value="true", 
result_type="bool")
+self.expect_expr(
+"NSString *c; c == nullptr", result_value="true", 
result_type="bool"
+)

___

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


efriedma-quic wrote:

> > couldn't the inverse be true, then - that codegen should ignore if 
> > something isZeroSize or not?
> 
> Just to clarify, is the suggestion here to remove the special handling of 
> `isZeroSize` in the RecordLayoutBuilder?

We currently need to distinguish between empty fields and non-empty fields: 
various parts of CodeGen expect to be able to get the LLVM struct field 
associated with a non-empty clang field.  Maybe we can reduce that dependency, 
but that would be a deeper refactoring.

But we don't really care whether an empty field is formally "zero-size", so we 
could instead just check if the field is empty.

The change would be a bit wider than just RecordLayoutBuilder; there are other 
places in CodeGen that check isZeroSize for similar reasons.

> > That would mean if someone wrote `struct Empty {}; struct Z { Empty a,b,c; 
> > }`, we'd lower it to `{ [3 x i8] }` instead of `{%Empty, %Empty, %Empty}`, 
> > which is a bit ugly. Other than that, sure, I guess we could do that.
> 
> Ah, fair enough. Glad to understand and I don't feel /super/ strongly either 
> way. Though it might help with confidence if codegen didn't depend on this 
> property at all (that it depends on the property a bit may make it harder to 
> detect if later codegen depends on the property in a real/ABI-breaking way).

I think we have enough regression tests and assertions to detect breakage from 
minor adjustments here.

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


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


https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/95738

>From c703c473147e3e554a98014319294668a0ec790d Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Sun, 16 Jun 2024 16:32:47 -0700
Subject: [PATCH 1/2] [LLDB] Add AST node classes, functions, etc. for Data
 Inspection Language (DIL).

The Data Inspection Language (DIL), described in
https://discourse.llvm.org/t/rfc-data-inspection-language/69893 includes
its own parser and expression evaluator.

This change defines the AST nodes, classes and functions which are used by the
DIL parser and expression evaluator. It also adds the .ebnf file documenting
the (current) expression language handled by the DIL parser and expression
evaluator.
---
 lldb/docs/dil-expr-lang.ebnf| 165 
 lldb/include/lldb/Core/DILAST.h | 690 
 lldb/source/Core/CMakeLists.txt |   1 +
 lldb/source/Core/DILAST.cpp | 568 ++
 4 files changed, 1424 insertions(+)
 create mode 100644 lldb/docs/dil-expr-lang.ebnf
 create mode 100644 lldb/include/lldb/Core/DILAST.h
 create mode 100644 lldb/source/Core/DILAST.cpp

diff --git a/lldb/docs/dil-expr-lang.ebnf b/lldb/docs/dil-expr-lang.ebnf
new file mode 100644
index 0..40c678c25cda5
--- /dev/null
+++ b/lldb/docs/dil-expr-lang.ebnf
@@ -0,0 +1,165 @@
+(* LLDB Debug Expressions, a subset of C++ *)
+(* Insired by https://www.nongnu.org/hcb *)
+
+expression = assignment_expression ;
+
+assignment_expression = conditional_expression
+logical_or_expression assignment_operator 
assignment_expression ;
+
+assignment_operator = "="
+| "*="
+| "/="
+| "%="
+| "+="
+| "-="
+| ">>="
+| "<<="
+| "&="
+| "^="
+| "|=" ;
+
+conditional_expression = logical_or_expression
+   | logical_or_expression "?" expression ":" 
assignment_expression ;
+
+logical_or_expression = logical_and_expression {"||" logical_and_expression} ;
+
+logical_and_expression = inclusive_or_expression {"&&" 
inclusive_or_expression} ;
+
+inclusive_or_expression = exclusive_or_expression {"|" 
exclusive_or_expression} ;
+
+exclusive_or_expression = and_expression {"^" and_expression} ;
+
+and_expression = equality_expression {"&" equality_expression} ;
+
+equality_expression = relational_expression {"==" relational_expression}
+| relational_expression {"!=" relational_expression} ;
+
+relational_expression = shift_expression {"<" shift_expression}
+  | shift_expression {">" shift_expression}
+  | shift_expression {"<=" shift_expression}
+  | shift_expression {">=" shift_expression} ;
+
+shift_expression = additive_expression {"<<" additive_expression}
+ | additive_expression {">>" additive_expression} ;
+
+additive_expression = multiplicative_expression {"+" multiplicative_expression}
+| multiplicative_expression {"-" 
multiplicative_expression} ;
+
+multiplicative_expression = cast_expression {"*" cast_expression}
+  | cast_expression {"/" cast_expression}
+  | cast_expression {"%" cast_expression} ;
+
+cast_expression = unary_expression
+| "(" type_id ")" cast_expression ;
+
+unary_expression = postfix_expression
+ | "++" cast_expression
+ | "--" cast_expression
+ | unary_operator cast_expression
+ | "sizeof" unary_expression
+ | "sizeof" "(" type_id ")" ;
+
+unary_operator = "*" | "&" | "+" | "-" | "!" | "~" ;
+
+postfix_expression = primary_expression
+   | postfix_expression "[" expression "]"
+   | postfix_expression "." id_expression
+   | postfix_expression "->" id_expression
+   | postfix_expression "++"
+   | postfix_expression "--"
+   | static_cast "<" type_id ">" "(" expression ")" ;
+   | dynamic_cast "<" type_id ">" "(" expression ")" ;
+   | reinterpret_cast "<" type_id ">" "(" expression ")" ;
+
+primary_expression = numeric_literal
+   | boolean_literal
+   | pointer_literal
+   | id_expression
+   | "this"
+   | "(" expression ")"
+   | builtin_func ;
+
+type_id = type_specifier_seq [abstract_declarator] ;
+
+type_specifier_seq = type_specifier [type_specifier_seq] ;
+
+type_specifier = simple_type_specifier
+   | cv_qualifier ;
+
+simple_type_specifier = ["::"] [nested_name_specifier] type_name
+  | "char"
+  | "char16_t"
+  | "char32_t"
+  | "wchar_t"
+  

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



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

cmtice wrote:

Done.

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


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



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

cmtice wrote:

Done.

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


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



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

cmtice wrote:

Done.

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)


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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)


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

This is great! LGTM with nits :) 

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)



@@ -43,8 +43,7 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
   ScratchTypeSystemClang::GetForTarget(m_target);
   assert(type_system);
 
-  std::string register_type_name = "__lldb_register_fields_";
-  register_type_name += name;
+  std::string register_type_name = "__lldb_register_fields_" + name;

medismailben wrote:

nit: you could use a `llvm::Twine` here.

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


[Lldb-commits] [lldb] [lldb] Parse and display register field enums (PR #95768)



@@ -67,8 +66,33 @@ CompilerType RegisterTypeBuilderClang::GetRegisterType(
 // We assume that RegisterFlags has padded and sorted the fields
 // already.
 for (const RegisterFlags::Field &field : flags.GetFields()) {
+  CompilerType field_type = field_uint_type;
+
+  if (const FieldEnum *enum_type = field.GetEnum()) {
+const FieldEnum::Enumerators &enumerators = 
enum_type->GetEnumerators();
+
+if (enumerators.empty())
+  continue;
+
+std::string enum_type_name =

medismailben wrote:

ditto

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/3] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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 6c17f1cabdee3399feceb478921a8369bde18b16 
ff10ee2e39740e6b8491a9f5bdcb2f4af657fa65 --extensions 'c,cpp,h' -- 
lldb/include/lldb/Core/ValueObject.h 
lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
lldb/include/lldb/Target/LanguageRuntime.h lldb/source/API/SBValue.cpp 
lldb/source/Breakpoint/Watchpoint.cpp 
lldb/source/Commands/CommandObjectDWIMPrint.cpp 
lldb/source/Commands/CommandObjectExpression.cpp 
lldb/source/Commands/CommandObjectFrame.cpp 
lldb/source/Commands/CommandObjectMemory.cpp 
lldb/source/Commands/CommandObjectTarget.cpp 
lldb/source/Commands/CommandObjectThread.cpp 
lldb/source/Core/DumpRegisterValue.cpp lldb/source/Core/FormatEntity.cpp 
lldb/source/Core/ValueObject.cpp 
lldb/source/DataFormatters/ValueObjectPrinter.cpp 
lldb/source/Interpreter/CommandInterpreter.cpp 
lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp 
lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp 
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
 
lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.h
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp 
lldb/test/API/commands/dwim-print/main.c 
lldb/unittests/ValueObject/DumpValueObjectOptionsTests.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
index 5e1face756..58b838752b 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/GNUstepObjCRuntime/GNUstepObjCRuntime.cpp
@@ -110,8 +110,9 @@ llvm::Error GNUstepObjCRuntime::GetObjectDescription(Stream 
&str,
   "LLDB's GNUStep runtime does not support object description");
 }
 
-llvm::Error GNUstepObjCRuntime::GetObjectDescription(
-Stream &strm, Value &value, ExecutionContextScope *exe_scope) {
+llvm::Error
+GNUstepObjCRuntime::GetObjectDescription(Stream &strm, Value &value,
+ ExecutionContextScope *exe_scope) {
   return llvm::createStringError(
   "LLDB's GNUStep runtime does not support object description");
 }

``




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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


adrian-prantl wrote:

I pushed two more patches in the same vain on top of the PR. This is now the 
final state for what I want to achieve in the Swift plugin.

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;

adrian-prantl wrote:

Yeah this is a drive-by fix where I'm pretty sure that this is the better 
behavior.
In practice no ObjC object description ever fails completely, so I don't know 
how to test this.

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/3] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

[Lldb-commits] [lldb] [lldb][ObjC] Don't query objective-c runtime for decls in C++ contexts (PR #95963)


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


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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/4] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

[Lldb-commits] [lldb] [lldb][breakpoint] Grey out disabled breakpoints (PR #91404)


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

>From 5724d6c77d29ad80e9ca03ce7ac1c3e6ed33afc0 Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova 
Date: Thu, 9 May 2024 11:08:29 -0700
Subject: [PATCH] [lldb][breakpoint] Grey out disabled breakpoints

This commit adds colour settings to the list of breakpoints in order to
grey out breakpoints that have been disabled.
---
 lldb/include/lldb/API/SBStream.h  |  5 +
 lldb/include/lldb/Utility/Stream.h|  8 
 lldb/source/API/SBStream.cpp  | 10 ++
 lldb/source/Breakpoint/Breakpoint.cpp |  9 +
 lldb/source/Utility/Stream.cpp|  8 
 5 files changed, 40 insertions(+)

diff --git a/lldb/include/lldb/API/SBStream.h b/lldb/include/lldb/API/SBStream.h
index 0e33f05b69916..108ddc38b4028 100644
--- a/lldb/include/lldb/API/SBStream.h
+++ b/lldb/include/lldb/API/SBStream.h
@@ -12,6 +12,7 @@
 #include 
 
 #include "lldb/API/SBDefines.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace lldb {
 
@@ -43,6 +44,10 @@ class LLDB_API SBStream {
 
   void Print(const char *str);
 
+  bool HasColor();
+
+  void FormatAnsiTerminalCodes(llvm::StringRef format);
+
   void RedirectToFile(const char *path, bool append);
 
   void RedirectToFile(lldb::SBFile file);
diff --git a/lldb/include/lldb/Utility/Stream.h 
b/lldb/include/lldb/Utility/Stream.h
index 37bcdc9924171..1ab590202cd69 100644
--- a/lldb/include/lldb/Utility/Stream.h
+++ b/lldb/include/lldb/Utility/Stream.h
@@ -309,6 +309,12 @@ class Stream {
   /// The current indentation level.
   unsigned GetIndentLevel() const;
 
+  /// Whether or not the stream is using color.
+  ///
+  /// \return
+  /// The color setting of the stream.
+  bool HasColor();
+
   /// Indent the current line in the stream.
   ///
   /// Indent the current line using the current indentation level and print an
@@ -366,6 +372,8 @@ class Stream {
   /// The optional C string format that can be overridden.
   void QuotedCString(const char *cstr, const char *format = "\"%s\"");
 
+  void FormatAnsiTerminalCodes(llvm::StringRef format);
+
   /// Set the address size in bytes.
   ///
   /// \param[in] addr_size
diff --git a/lldb/source/API/SBStream.cpp b/lldb/source/API/SBStream.cpp
index fc8f09a7bb9ae..bc0f3356d4753 100644
--- a/lldb/source/API/SBStream.cpp
+++ b/lldb/source/API/SBStream.cpp
@@ -11,6 +11,7 @@
 #include "lldb/API/SBFile.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/StreamFile.h"
+#include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/Utility/Instrumentation.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Status.h"
@@ -77,6 +78,15 @@ void SBStream::Printf(const char *format, ...) {
   va_end(args);
 }
 
+bool SBStream::HasColor() {
+  return m_opaque_up->AsRawOstream().colors_enabled();
+}
+
+void SBStream::FormatAnsiTerminalCodes(llvm::StringRef format) {
+  if (HasColor())
+Printf("%s", ansi::FormatAnsiTerminalCodes(format).c_str());
+}
+
 void SBStream::RedirectToFile(const char *path, bool append) {
   LLDB_INSTRUMENT_VA(this, path, append);
 
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp 
b/lldb/source/Breakpoint/Breakpoint.cpp
index ae845e92762b9..95624f4ae3ad5 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -15,6 +15,7 @@
 #include "lldb/Breakpoint/BreakpointResolver.h"
 #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
 #include "lldb/Core/Address.h"
+#include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/SearchFilter.h"
@@ -26,6 +27,7 @@
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/ThreadSpec.h"
+#include "lldb/Utility/AnsiTerminal.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
@@ -837,6 +839,10 @@ void Breakpoint::GetDescription(Stream *s, 
lldb::DescriptionLevel level,
 bool show_locations) {
   assert(s != nullptr);
 
+  // Grey out any disabled breakpoints in the list of breakpoints.
+  if (!IsEnabled())
+s->FormatAnsiTerminalCodes("${ansi.faint}");
+
   if (!m_kind_description.empty()) {
 if (level == eDescriptionLevelBrief) {
   s->PutCString(GetBreakpointKind());
@@ -933,6 +939,9 @@ void Breakpoint::GetDescription(Stream *s, 
lldb::DescriptionLevel level,
 }
 s->IndentLess();
   }
+
+  // Reset the colors back to normal if they were previously greyed out.
+  s->FormatAnsiTerminalCodes("${ansi.normal}");
 }
 
 void Breakpoint::GetResolverDescription(Stream *s) {
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp
index 89dce9fb0e1f7..e4ca9ad5a1f14 100644
--- a/lldb/source/Utility/Stream.cpp
+++ b/lldb/source/Utility/Stream.cpp
@@ -103,6 +103,11 @@ void Stream::QuotedCString(const char *cstr, const char 
*format) {
   Printf(format, cstr);
 }
 
+void Stream::FormatAnsiTerminalCodes(llvm::Stri

[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)


https://github.com/dzhidzhoev created 
https://github.com/llvm/llvm-project/pull/95986

1. This commit adds LLDB_PLATFORM_URL, LLDB_TEST_SYSROOT,
LLDB_PLATFORM_WORKING_DIR cmake flags to pass arguments for
   cross-compilation and remote running of both Shell&API tests.
2. To run Shell tests remotely, It adds 'platform select' and 'platform 
connect' commands to %lldb
substitution.
3. 'remote-linux' feature added to lit to disable tests failing with remote 
execution.
4. A separate working directory is assigned to each test to avoid
conflicts during parallel test execution.

It has been tested on Ubuntu AArch64 with libcxx enabled for tests.

>From 817caef33c32200720006a21e4d27ad717085e1a Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev 
Date: Fri, 31 May 2024 21:39:56 +
Subject: [PATCH] [lldb][test] Support remote run of Shell tests

1. This commit adds LLDB_PLATFORM_URL, LLDB_TEST_SYSROOT,
   LLDB_PLATFORM_WORKING_DIR cmake flags to pass arguments for
   cross-compilation and remote running of both Shell&API tests.
2. To run Shell tests remotely, It adds 'platform select' and 'platform 
connect' commands to %lldb
   substitution.
3. 'remote-linux' feature added to lit to disable tests failing with remote 
execution.
4. A separate working directory is assigned to each test to avoid
   conflicts during parallel test execution.
---
 lldb/test/API/lit.cfg.py  |  7 ++
 lldb/test/API/lit.site.cfg.py.in  |  3 +
 .../test/Shell/Settings/TestEchoCommands.test |  2 +
 lldb/test/Shell/Target/target-label.test  | 20 +++---
 lldb/test/Shell/helper/toolchain.py   | 67 ++-
 lldb/test/Shell/lit.cfg.py|  6 +-
 lldb/test/Shell/lit.site.cfg.py.in|  6 +-
 7 files changed, 96 insertions(+), 15 deletions(-)

diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index 96520c7c82624..6a0a1b0a76675 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -303,6 +303,13 @@ def delete_module_cache(path):
 # In particular, (1) is visited at the top of the file, since the script
 # derives other information from it.
 
+if is_configured("lldb_platform_url"):
+dotest_cmd += ["--platform-url", config.lldb_platform_url]
+if is_configured("lldb_platform_working_dir"):
+dotest_cmd += ["--platform-working-dir", config.lldb_platform_working_dir]
+if is_configured("cmake_sysroot"):
+dotest_cmd += ["--sysroot", config.cmake_sysroot]
+
 if is_configured("dotest_user_args_str"):
 dotest_cmd.extend(config.dotest_user_args_str.split(";"))
 
diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index 8b2d09ae41cd2..ec388297e91eb 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -24,6 +24,9 @@ config.lua_executable = "@Lua_EXECUTABLE@"
 config.lua_test_entry = "TestLuaAPI.py"
 config.dotest_common_args_str = 
lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
 config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")
+config.lldb_platform_url = lit_config.substitute("@LLDB_PLATFORM_URL@")
+config.lldb_platform_working_dir = 
lit_config.substitute("@LLDB_PLATFORM_WORKING_DIR@")
+config.cmake_sysroot = lit_config.substitute("@LLDB_TEST_SYSROOT@" or 
"@DEFAULT_SYSROOT@")
 config.lldb_enable_python = @LLDB_ENABLE_PYTHON@
 config.dotest_lit_args_str = None
 config.enabled_plugins = []
diff --git a/lldb/test/Shell/Settings/TestEchoCommands.test 
b/lldb/test/Shell/Settings/TestEchoCommands.test
index 234b9742bfa2a..ce78f91e1cbd4 100644
--- a/lldb/test/Shell/Settings/TestEchoCommands.test
+++ b/lldb/test/Shell/Settings/TestEchoCommands.test
@@ -2,6 +2,8 @@
 # RUN: %lldb -x -b -o 'settings set interpreter.echo-comment-commands false' 
-s %S/Inputs/EchoCommandsTest.in | FileCheck 
%S/Inputs/EchoCommandsNoComments.out
 # RUN: %lldb -x -b -o 'settings set interpreter.echo-commands false' 
-s %S/Inputs/EchoCommandsTest.in | FileCheck %S/Inputs/EchoCommandsNone.out
 
+XFAIL: remote{{.*}}
+
 RUN: echo start >%t.file
 RUN: %lldb -x -b --source-quietly -s %S/Inputs/EchoCommandsTest.in >>%t.file
 RUN: echo done >>%t.file
diff --git a/lldb/test/Shell/Target/target-label.test 
b/lldb/test/Shell/Target/target-label.test
index 5ac430601e29a..7f4f31e09fa16 100644
--- a/lldb/test/Shell/Target/target-label.test
+++ b/lldb/test/Shell/Target/target-label.test
@@ -4,16 +4,16 @@
 
 target create -l "ls" /bin/ls
 target list
-# CHECK: * target #0 (ls): /bin/ls
+# CHECK: * target #0 (ls): [[LS_PATH:.*]]
 
 script lldb.target.SetLabel("")
 target list
-# CHECK: * target #0: /bin/ls
+# CHECK: * target #0: [[LS_PATH]]
 
 target create -l "cat" /bin/cat
 target list
-# CHECK: target #0: /bin/ls
-# CHECK-NEXT: * target #1 (cat): /bin/cat
+# CHECK: target #0: [[LS_PATH]]
+# CHECK-NEXT: * target #1 (cat): [[CAT_PATH:.*]]
 
 target create -l "cat" /bin/cat
 # CHECK: Cannot use label 'cat' since it's set in target #1.
@@ -22,12 +22,12 @@ target cre

[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Vladislav Dzhidzhoev (dzhidzhoev)


Changes

1. This commit adds LLDB_PLATFORM_URL, LLDB_TEST_SYSROOT,
LLDB_PLATFORM_WORKING_DIR cmake flags to pass arguments for
   cross-compilation and remote running of both Shell&API tests.
2. To run Shell tests remotely, It adds 'platform select' and 'platform 
connect' commands to %lldb
substitution.
3. 'remote-linux' feature added to lit to disable tests failing with remote 
execution.
4. A separate working directory is assigned to each test to avoid
conflicts during parallel test execution.

It has been tested on Ubuntu AArch64 with libcxx enabled for tests.

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


7 Files Affected:

- (modified) lldb/test/API/lit.cfg.py (+7) 
- (modified) lldb/test/API/lit.site.cfg.py.in (+3) 
- (modified) lldb/test/Shell/Settings/TestEchoCommands.test (+2) 
- (modified) lldb/test/Shell/Target/target-label.test (+10-10) 
- (modified) lldb/test/Shell/helper/toolchain.py (+64-3) 
- (modified) lldb/test/Shell/lit.cfg.py (+5-1) 
- (modified) lldb/test/Shell/lit.site.cfg.py.in (+5-1) 


``diff
diff --git a/lldb/test/API/lit.cfg.py b/lldb/test/API/lit.cfg.py
index 96520c7c82624..6a0a1b0a76675 100644
--- a/lldb/test/API/lit.cfg.py
+++ b/lldb/test/API/lit.cfg.py
@@ -303,6 +303,13 @@ def delete_module_cache(path):
 # In particular, (1) is visited at the top of the file, since the script
 # derives other information from it.
 
+if is_configured("lldb_platform_url"):
+dotest_cmd += ["--platform-url", config.lldb_platform_url]
+if is_configured("lldb_platform_working_dir"):
+dotest_cmd += ["--platform-working-dir", config.lldb_platform_working_dir]
+if is_configured("cmake_sysroot"):
+dotest_cmd += ["--sysroot", config.cmake_sysroot]
+
 if is_configured("dotest_user_args_str"):
 dotest_cmd.extend(config.dotest_user_args_str.split(";"))
 
diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index 8b2d09ae41cd2..ec388297e91eb 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -24,6 +24,9 @@ config.lua_executable = "@Lua_EXECUTABLE@"
 config.lua_test_entry = "TestLuaAPI.py"
 config.dotest_common_args_str = 
lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
 config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")
+config.lldb_platform_url = lit_config.substitute("@LLDB_PLATFORM_URL@")
+config.lldb_platform_working_dir = 
lit_config.substitute("@LLDB_PLATFORM_WORKING_DIR@")
+config.cmake_sysroot = lit_config.substitute("@LLDB_TEST_SYSROOT@" or 
"@DEFAULT_SYSROOT@")
 config.lldb_enable_python = @LLDB_ENABLE_PYTHON@
 config.dotest_lit_args_str = None
 config.enabled_plugins = []
diff --git a/lldb/test/Shell/Settings/TestEchoCommands.test 
b/lldb/test/Shell/Settings/TestEchoCommands.test
index 234b9742bfa2a..ce78f91e1cbd4 100644
--- a/lldb/test/Shell/Settings/TestEchoCommands.test
+++ b/lldb/test/Shell/Settings/TestEchoCommands.test
@@ -2,6 +2,8 @@
 # RUN: %lldb -x -b -o 'settings set interpreter.echo-comment-commands false' 
-s %S/Inputs/EchoCommandsTest.in | FileCheck 
%S/Inputs/EchoCommandsNoComments.out
 # RUN: %lldb -x -b -o 'settings set interpreter.echo-commands false' 
-s %S/Inputs/EchoCommandsTest.in | FileCheck %S/Inputs/EchoCommandsNone.out
 
+XFAIL: remote{{.*}}
+
 RUN: echo start >%t.file
 RUN: %lldb -x -b --source-quietly -s %S/Inputs/EchoCommandsTest.in >>%t.file
 RUN: echo done >>%t.file
diff --git a/lldb/test/Shell/Target/target-label.test 
b/lldb/test/Shell/Target/target-label.test
index 5ac430601e29a..7f4f31e09fa16 100644
--- a/lldb/test/Shell/Target/target-label.test
+++ b/lldb/test/Shell/Target/target-label.test
@@ -4,16 +4,16 @@
 
 target create -l "ls" /bin/ls
 target list
-# CHECK: * target #0 (ls): /bin/ls
+# CHECK: * target #0 (ls): [[LS_PATH:.*]]
 
 script lldb.target.SetLabel("")
 target list
-# CHECK: * target #0: /bin/ls
+# CHECK: * target #0: [[LS_PATH]]
 
 target create -l "cat" /bin/cat
 target list
-# CHECK: target #0: /bin/ls
-# CHECK-NEXT: * target #1 (cat): /bin/cat
+# CHECK: target #0: [[LS_PATH]]
+# CHECK-NEXT: * target #1 (cat): [[CAT_PATH:.*]]
 
 target create -l "cat" /bin/cat
 # CHECK: Cannot use label 'cat' since it's set in target #1.
@@ -22,12 +22,12 @@ target create -l 42 /bin/cat
 # CHECK: error: Cannot use integer as target label.
 
 target select 0
-# CHECK: * target #0: /bin/ls
-# CHECK-NEXT: target #1 (cat): /bin/cat
+# CHECK: * target #0: [[LS_PATH]]
+# CHECK-NEXT: target #1 (cat): [[CAT_PATH]]
 
 target select cat
-# CHECK: target #0: /bin/ls
-# CHECK-NEXT: * target #1 (cat): /bin/cat
+# CHECK: target #0: [[LS_PATH]]
+# CHECK-NEXT: * target #1 (cat): [[CAT_PATH]]
 
 script lldb.target.GetLabel()
 # CHECK: 'cat'
@@ -36,5 +36,5 @@ script lldb.debugger.GetTargetAtIndex(0).SetLabel('Not cat')
 # CHECK: success
 
 target list
-# CHECK: target #0 (Not cat): /bin/ls
-# CHECK-NEXT: * target #1 (cat): /bin/cat
+#

[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)


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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));

JDevlieghere wrote:

Would this be worth color highlighting? 

```
llvm::WithColor(strm.AsRawOstream(), llvm::HighlightColor::Error,
 llvm::ColorMode::Enable) << "error :";
strm <<  toString(std::move(error));
```

This should do the correct thing based on whether the stream has colors 
enabled. It's the same thing we do in `CommandReturnObject.cpp`. This applies 
to all the places where we write "error:" to the stream. 

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -461,34 +468,34 @@ bool 
ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed,
   return !error_printed;
 }
 
-bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
-bool summary_printed) {
+llvm::Error
+ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
+   bool summary_printed) {
   if (ShouldPrintValueObject()) {
 // let's avoid the overly verbose no description error for a nil thing
 if (m_options.m_use_objc && !IsNil() && !IsUninitialized() &&
 (!m_options.m_pointer_as_array)) {
   if (!m_options.m_hide_value || ShouldShowName())
-m_stream->Printf(" ");
-  const char *object_desc = nullptr;
-  if (value_printed || summary_printed)
-object_desc = GetMostSpecializedValue().GetObjectDescription();
-  else
-object_desc = GetDescriptionForDisplay();
-  if (object_desc && *object_desc) {
+*m_stream << ' ';
+  llvm::Expected object_desc =
+  (value_printed || summary_printed)
+  ? GetMostSpecializedValue().GetObjectDescription()
+  : GetDescriptionForDisplay();
+  if (!object_desc) {
+if (!value_printed && !summary_printed)
+  return object_desc.takeError();
+*m_stream << "warning: no object description available\n";
+llvm::consumeError(object_desc.takeError());

JDevlieghere wrote:

why not include the error in the warning? 

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -989,41 +989,45 @@ ValueObject::ReadPointedString(lldb::WritableDataBufferSP 
&buffer_sp,
   return {total_bytes_read, was_capped};
 }
 
-const char *ValueObject::GetObjectDescription() {
+llvm::Expected ValueObject::GetObjectDescription() {
   if (!UpdateValueIfNeeded(true))
-return nullptr;
+return llvm::createStringError("could not update value");
 
   // Return cached value.
   if (!m_object_desc_str.empty())
-return m_object_desc_str.c_str();
+return m_object_desc_str;
 
   ExecutionContext exe_ctx(GetExecutionContextRef());
   Process *process = exe_ctx.GetProcessPtr();
   if (!process)
-return nullptr;
+return llvm::createStringError("no process");
 
   // Returns the object description produced by one language runtime.
-  auto get_object_description = [&](LanguageType language) -> const char * {
+  auto get_object_description =
+  [&](LanguageType language) -> llvm::Expected {
 if (LanguageRuntime *runtime = process->GetLanguageRuntime(language)) {
   StreamString s;
-  if (runtime->GetObjectDescription(s, *this)) {
-m_object_desc_str.append(std::string(s.GetString()));
-return m_object_desc_str.c_str();
-  }
+  if (llvm::Error error = runtime->GetObjectDescription(s, *this))
+return error;
+  m_object_desc_str = s.GetString();
+  return m_object_desc_str;
 }
-return nullptr;
+return llvm::createStringError("no native language runtime");
   };
 
   // Try the native language runtime first.
   LanguageType native_language = GetObjectRuntimeLanguage();
-  if (const char *desc = get_object_description(native_language))
+  llvm::Expected desc = get_object_description(native_language);
+  if (desc)
 return desc;
 
   // Try the Objective-C language runtime. This fallback is necessary
   // for Objective-C++ and mixed Objective-C / C++ programs.
-  if (Language::LanguageIsCFamily(native_language))
+  if (Language::LanguageIsCFamily(native_language)) {
+llvm::consumeError(desc.takeError());

JDevlieghere wrote:

This is one of the few instances where it makes sense to use `consumeError` (as 
opposed to using `LLDB_LOG_ERROR`). Could you add a comment saying that this is 
the right thing? 

I know I'm going to see this at some point in the future and grumble before 
realizing that this is actually correct. Which definitely didn't happen during 
the code review :-) 

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


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


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

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

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

Reviewers: clayborg

Tasks: lldb
---
 lldb/bindings/python/python-typemaps.swig |   3 +-
 lldb/include/lldb/API/SBAddressRange.h|   2 +
 lldb/include/lldb/API/SBAddressRangeList.h|   2 +
 lldb/include/lldb/API/SBProcess.h |  10 +
 lldb/include/lldb/Core/AddressRangeListImpl.h |   4 +
 lldb/include/lldb/Target/Process.h|  13 ++
 lldb/source/API/SBAddressRange.cpp|   4 +-
 lldb/source/API/SBAddressRangeList.cpp|   4 +
 lldb/source/API/SBProcess.cpp |  58 -
 lldb/source/Target/Process.cpp| 123 ++
 .../API/python_api/find_in_memory/Makefile|   3 +
 .../find_in_memory/TestFindInMemory.py| 104 +
 .../find_in_memory/TestFindRangesInMemory.py  | 210 ++
 .../find_in_memory/address_ranges_helper.py   |  64 ++
 .../API/python_api/find_in_memory/main.cpp|  13 ++
 15 files changed, 610 insertions(+), 7 deletions(-)
 create mode 100644 lldb/test/API/python_api/find_in_memory/Makefile
 create mode 100644 lldb/test/API/python_api/find_in_memory/TestFindInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/TestFindRangesInMemory.py
 create mode 100644 
lldb/test/API/python_api/find_in_memory/address_ranges_helper.py
 create mode 100644 lldb/test/API/python_api/find_in_memory/main.cpp

diff --git a/lldb/bindings/python/python-typemaps.swig 
b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..f8c33e15c03e6 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -257,7 +257,8 @@ AND call SWIG_fail at the same time, because it will result 
in a double free.
 }
 // For SBProcess::WriteMemory, SBTarget::GetInstructions and 
SBDebugger::DispatchInput.
 %typemap(in) (const void *buf, size_t size),
- (const void *data, size_t data_len) {
+ (const void *data, size_t data_len),
+ (const void *buf, uint64_t size) {
   if (PythonString::Check($input)) {
 PythonString str(PyRefType::Borrowed, $input);
 $1 = (void *)str.GetString().data();
diff --git a/lldb/include/lldb/API/SBAddressRange.h 
b/lldb/include/lldb/API/SBAddressRange.h
index 152bd82426af1..ef8ce9ba9977d 100644
--- a/lldb/include/lldb/API/SBAddressRange.h
+++ b/lldb/include/lldb/API/SBAddressRange.h
@@ -58,6 +58,8 @@ class LLDB_API SBAddressRange {
   friend class SBFunction;
   friend class SBProcess;
 
+  lldb_private::AddressRange &ref() const;
+
   AddressRangeUP m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBAddressRangeList.h 
b/lldb/include/lldb/API/SBAddressRangeList.h
index a123287ef1b4f..9e4d747685e63 100644
--- a/lldb/include/lldb/API/SBAddressRangeList.h
+++ b/lldb/include/lldb/API/SBAddressRangeList.h
@@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
   friend class SBBlock;
   friend class SBProcess;
 
+  lldb_private::AddressRanges &ref() const;
+
   std::unique_ptr m_opaque_up;
 };
 
diff --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index f1b5d1fb92ce2..a6ab7ae759918 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -209,6 +209,16 @@ class LLDB_API SBProcess {
 
   lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error);
 
+  lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size,
+  const SBAddressRangeList &ranges,
+  uint32_t alignment,
+  uint32_t max_matches,
+  SBError &error);
+
+  lldb::addr_t FindInMemory(const void *buf, uint64_t size,
+const SBAddressRange &range, uint32_t alignment,
+SBError &error);
+
   // Events
   static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event);
 
diff --git a/lldb/include/lldb/Core/AddressRangeListImpl.h 
b/lldb/include/lldb/Core/AddressRangeListImpl.h
index 46ebfe73d4d92..6742e6ead87de 100644
--- a/lldb/include/lldb/Core/AddressRangeListImpl.h
+++ b/lldb/include/lldb/Core/AddressRangeListImpl.h
@@ -13,7 +13,9 @@
 #include 
 
 namespace lldb {
+class SBAddressRangeList;
 class SBBlock;
+class SBProcess;
 }
 
 namespace lldb_private {
@@ -39,7 +41,9 @@ class AddressRangeListImpl {
   lldb_private::AddressRange GetAddressRangeAtIndex(size_t index);
 
 private:
+  friend class lldb::SBAddressRangeList;
   friend class lldb::SBBlock;
+  friend

[Lldb-commits] [lldb] [lldb][test] Support remote run of Shell tests (PR #95986)


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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -461,34 +468,34 @@ bool 
ValueObjectPrinter::PrintValueAndSummaryIfNeeded(bool &value_printed,
   return !error_printed;
 }
 
-bool ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
-bool summary_printed) {
+llvm::Error
+ValueObjectPrinter::PrintObjectDescriptionIfNeeded(bool value_printed,
+   bool summary_printed) {
   if (ShouldPrintValueObject()) {
 // let's avoid the overly verbose no description error for a nil thing
 if (m_options.m_use_objc && !IsNil() && !IsUninitialized() &&
 (!m_options.m_pointer_as_array)) {
   if (!m_options.m_hide_value || ShouldShowName())
-m_stream->Printf(" ");
-  const char *object_desc = nullptr;
-  if (value_printed || summary_printed)
-object_desc = GetMostSpecializedValue().GetObjectDescription();
-  else
-object_desc = GetDescriptionForDisplay();
-  if (object_desc && *object_desc) {
+*m_stream << ' ';
+  llvm::Expected object_desc =
+  (value_printed || summary_printed)
+  ? GetMostSpecializedValue().GetObjectDescription()
+  : GetDescriptionForDisplay();
+  if (!object_desc) {
+if (!value_printed && !summary_printed)
+  return object_desc.takeError();
+*m_stream << "warning: no object description available\n";
+llvm::consumeError(object_desc.takeError());

adrian-prantl wrote:

The error will in practice be `could not evaluate print object function: 
expression interrupted`.
If we knew what the command was, this would be where we'd want to say they 
should use `p` instead of `po`, but we don't have enough information about this 
here. I'll add a comment about this.

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


[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)


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

None

>From 786e94dae236eafb71c2f001f48ed17651abd3e3 Mon Sep 17 00:00:00 2001
From: Miro Bucko 
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.

---
 lldb/source/API/SBAddressRange.cpp | 18 +++---
 .../address_range/TestAddressRange.py  |  2 +-
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..0fba252979093 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,8 +50,6 @@ const SBAddressRange &SBAddressRange::operator=(const 
SBAddressRange &rhs) {
 bool SBAddressRange::operator==(const SBAddressRange &rhs) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
   return m_opaque_up->operator==(*(rhs.m_opaque_up));
 }
 
@@ -64,28 +62,24 @@ bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  m_opaque_up->Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  return m_opaque_up->IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
   return lldb::SBAddress(m_opaque_up->GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
   return m_opaque_up->GetByteSize();
 }
 
@@ -93,11 +87,5 @@ bool SBAddressRange::GetDescription(SBStream &description,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream &stream = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(&stream, target.GetSP().get());
-  return true;
+  return m_opaque_up->GetDescription(&description.ref(), target.GetSP().get());
 }
diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index 86ca4a62155f0..ae4b8c7c90ce4 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -166,7 +166,7 @@ def test_address_range_list_iterator(self):
 def test_address_range_print_invalid(self):
 """Make sure the SBAddressRange can be printed when invalid."""
 range = lldb.SBAddressRange()
-self.assertEqual(str(range), "")
+self.assertEqual(str(range), "[0x-0x)")
 
 def test_address_range_print_resolved(self):
 """Make sure the SBAddressRange can be printed when resolved."""

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


[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Miro Bucko (mbucko)


Changes



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


2 Files Affected:

- (modified) lldb/source/API/SBAddressRange.cpp (+3-15) 
- (modified) lldb/test/API/python_api/address_range/TestAddressRange.py (+1-1) 


``diff
diff --git a/lldb/source/API/SBAddressRange.cpp 
b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..0fba252979093 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,8 +50,6 @@ const SBAddressRange &SBAddressRange::operator=(const 
SBAddressRange &rhs) {
 bool SBAddressRange::operator==(const SBAddressRange &rhs) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
-  if (!IsValid() || !rhs.IsValid())
-return false;
   return m_opaque_up->operator==(*(rhs.m_opaque_up));
 }
 
@@ -64,28 +62,24 @@ bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
 void SBAddressRange::Clear() {
   LLDB_INSTRUMENT_VA(this);
 
-  m_opaque_up.reset();
+  m_opaque_up->Clear();
 }
 
 bool SBAddressRange::IsValid() const {
   LLDB_INSTRUMENT_VA(this);
 
-  return m_opaque_up && m_opaque_up->IsValid();
+  return m_opaque_up->IsValid();
 }
 
 lldb::SBAddress SBAddressRange::GetBaseAddress() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return lldb::SBAddress();
   return lldb::SBAddress(m_opaque_up->GetBaseAddress());
 }
 
 lldb::addr_t SBAddressRange::GetByteSize() const {
   LLDB_INSTRUMENT_VA(this);
 
-  if (!IsValid())
-return 0;
   return m_opaque_up->GetByteSize();
 }
 
@@ -93,11 +87,5 @@ bool SBAddressRange::GetDescription(SBStream &description,
 const SBTarget target) {
   LLDB_INSTRUMENT_VA(this, description, target);
 
-  Stream &stream = description.ref();
-  if (!IsValid()) {
-stream << "";
-return true;
-  }
-  m_opaque_up->GetDescription(&stream, target.GetSP().get());
-  return true;
+  return m_opaque_up->GetDescription(&description.ref(), target.GetSP().get());
 }
diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py 
b/lldb/test/API/python_api/address_range/TestAddressRange.py
index 86ca4a62155f0..ae4b8c7c90ce4 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -166,7 +166,7 @@ def test_address_range_list_iterator(self):
 def test_address_range_print_invalid(self):
 """Make sure the SBAddressRange can be printed when invalid."""
 range = lldb.SBAddressRange()
-self.assertEqual(str(range), "")
+self.assertEqual(str(range), "[0x-0x)")
 
 def test_address_range_print_resolved(self):
 """Make sure the SBAddressRange can be printed when resolved."""

``




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


[Lldb-commits] [lldb] [lldb] Fix the semantics of SupportFile equivalence (PR #95606)


jasonmolenda wrote:


> > I hate to ruin a party, but I don't think this is a good use of 
> > `operator==`, precisely because it does not define an equivalence relation 
> > (it's not transitive). Might I suggest named function instead? 
> > `IsCompatible` ?
> 


I'd be fine with `SupportFile::IsSameFile(SupportFile&)`, I think that would 
make it clear what is being evaluated in caller locations.  But is it any 
different than operator==, which you'd expect to behave the same?

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)



@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));

adrian-prantl wrote:

Not a bad idea in general, but IMHO outside of the scope of this patch.
1. We'd need to audit the places where this makes sense. Right now all the 
places I added this manual logging are just random points where I stopped 
propagating the Error upwards, but domain experts should probably consider just 
passing the Error further up in most of these places.
2. In this particular example, this is a StreamString, so it wouldn'taccept 
color.
3. We probably want a Stream::LogError() method that encapsulates all of the 
code above.

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


[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/4] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

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


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

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

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

---
 lldb/unittests/Breakpoint/CMakeLists.txt  |  4 +
 .../Breakpoint/TestBreakpointSetCallback.cpp  | 90 +++
 2 files changed, 94 insertions(+)
 create mode 100644 lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp

diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt 
b/lldb/unittests/Breakpoint/CMakeLists.txt
index 757c2da1a4d9d..858a2151c503b 100644
--- a/lldb/unittests/Breakpoint/CMakeLists.txt
+++ b/lldb/unittests/Breakpoint/CMakeLists.txt
@@ -1,10 +1,14 @@
 add_lldb_unittest(LLDBBreakpointTests
   BreakpointIDTest.cpp
   WatchpointAlgorithmsTests.cpp
+  TestBreakpointSetCallback.cpp
 
   LINK_LIBS
 lldbBreakpoint
 lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
   LINK_COMPONENTS
 Support
   )
diff --git a/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..351384230f15f
--- /dev/null
+++ b/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp
@@ -0,0 +1,90 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+std::cout << "HELLO" << std::endl;
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);
+return true;
+  }
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  TargetSP m_target_sp;
+  BreakpointSP m_breakpoint_sp;
+  Event *m_event;
+  const ExecutionContext m_exe_ctx;
+  lldb::user_id_t expected_breakpoint_id;
+  lldb::user_id_t expected_breakpoint_loc_id;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  StoppointCallbackContext context(m_event, m_exe_ctx, true);
+  m_breakpoint_sp->SetCallback(BreakpointSetCallbackTest::callback, baton,
+   false);

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


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)


Changes

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

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


2 Files Affected:

- (modified) lldb/unittests/Breakpoint/CMakeLists.txt (+4) 
- (added) lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp (+90) 


``diff
diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt 
b/lldb/unittests/Breakpoint/CMakeLists.txt
index 757c2da1a4d9d..858a2151c503b 100644
--- a/lldb/unittests/Breakpoint/CMakeLists.txt
+++ b/lldb/unittests/Breakpoint/CMakeLists.txt
@@ -1,10 +1,14 @@
 add_lldb_unittest(LLDBBreakpointTests
   BreakpointIDTest.cpp
   WatchpointAlgorithmsTests.cpp
+  TestBreakpointSetCallback.cpp
 
   LINK_LIBS
 lldbBreakpoint
 lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
   LINK_COMPONENTS
 Support
   )
diff --git a/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..351384230f15f
--- /dev/null
+++ b/lldb/unittests/Breakpoint/TestBreakpointSetCallback.cpp
@@ -0,0 +1,90 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+std::cout << "HELLO" << std::endl;
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);
+return true;
+  }
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  TargetSP m_target_sp;
+  BreakpointSP m_breakpoint_sp;
+  Event *m_event;
+  const ExecutionContext m_exe_ctx;
+  lldb::user_id_t expected_breakpoint_id;
+  lldb::user_id_t expected_breakpoint_loc_id;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  StoppointCallbackContext context(m_event, m_exe_ctx, true);
+  m_breakpoint_sp->SetCallback(BreakpointSetCallbackTest::callback, baton,
+   false);
+  m_breakpoint_sp->InvokeCallback(&context, 0);
+}

``




https://github.com/llvm/llvm-project/pull/96001
___
lldb-commits mailing list

[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/4] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/4] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

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


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

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

---
 lldb/unittests/Breakpoint/CMakeLists.txt  |  3 +
 lldb/unittests/CMakeLists.txt |  1 +
 lldb/unittests/Callback/CMakeLists.txt| 12 +++
 .../Callback/TestBreakpointSetCallback.cpp| 89 +++
 4 files changed, 105 insertions(+)
 create mode 100644 lldb/unittests/Callback/CMakeLists.txt
 create mode 100644 lldb/unittests/Callback/TestBreakpointSetCallback.cpp

diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt 
b/lldb/unittests/Breakpoint/CMakeLists.txt
index 757c2da1a4d9d..629f86dfe65a7 100644
--- a/lldb/unittests/Breakpoint/CMakeLists.txt
+++ b/lldb/unittests/Breakpoint/CMakeLists.txt
@@ -5,6 +5,9 @@ add_lldb_unittest(LLDBBreakpointTests
   LINK_LIBS
 lldbBreakpoint
 lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
   LINK_COMPONENTS
 Support
   )
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index a2585a94b6155..cc9d45ebf981d 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -52,6 +52,7 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
   add_subdirectory(API)
 endif()
 add_subdirectory(Breakpoint)
+add_subdirectory(Callback)
 add_subdirectory(Core)
 add_subdirectory(DataFormatter)
 add_subdirectory(Disassembler)
diff --git a/lldb/unittests/Callback/CMakeLists.txt 
b/lldb/unittests/Callback/CMakeLists.txt
new file mode 100644
index 0..bb8797c513256
--- /dev/null
+++ b/lldb/unittests/Callback/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_lldb_unittest(LLDBCallbackTests
+  TestBreakpointSetCallback.cpp
+
+   LINK_LIBS
+lldbBreakpoint
+lldbCore
+LLVMTestingSupport
+lldbUtilityHelpers
+lldbPluginPlatformMacOSX
+  LINK_COMPONENTS
+Support
+  )
diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp 
b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
new file mode 100644
index 0..7eea9c42bfad3
--- /dev/null
+++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+

[Lldb-commits] [lldb] [lldb][swig] Refactor callback typemaps and functions (PR #95318)


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


[Lldb-commits] [lldb] [lldb][swig] Refactor callback typemaps and functions (PR #95318)


chelcassanova wrote:

Closing this PR, we wanted to be able to do this _without_ using the 
`PythonDataObjects` class in the swig wrapper that contains callback functions 
but this looks to be unfeasible for callbacks that return SB objects

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


[Lldb-commits] [clang] [lldb] [llvm] [BOLT][DWARF][NFC] Refactor updateDWARFObjectAddressRanges (PR #96006)


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

Refactoring updateDWARFObjectAddressRanges to create a writer for each instance 
of a DWO file. 

>From b2fe35ae825dc757ea1daaf49142e789c4a560fc Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Tue, 1 Jun 2021 11:37:41 -0700
Subject: [PATCH 1/6] Rebase: [Facebook] Add clang driver options to test debug
 info and BOLT

Summary:
This is an essential piece of infrastructure for us to be
continuously testing debug info with BOLT. We can't only make changes
to a test repo because we need to change debuginfo tests to call BOLT,
hence, this diff needs to sit in our opensource repo. But when upstreaming
to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming,
we need to git diff and check all folders that are being modified by our
commits and discard this one (and leave as an internal diff).

To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON.
Then run check-lldb and check-debuginfo.

Manual rebase conflict history:
https://phabricator.intern.facebook.com/D29205224
https://phabricator.intern.facebook.com/D29564078
https://phabricator.intern.facebook.com/D33289118
https://phabricator.intern.facebook.com/D34957174
https://phabricator.intern.facebook.com/D35317341

Test Plan:
tested locally
Configured with:
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests"
-DLLVM_TEST_BOLT=ON
Ran test suite with:
ninja check-debuginfo
ninja check-lldb

Reviewers: maks, #llvm-bolt

Reviewed By: maks

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D46256657

Tasks: T92898286
---
 clang/include/clang/Driver/Options.td  |  4 
 clang/lib/Driver/ToolChains/Gnu.cpp| 29 ++
 cross-project-tests/lit.cfg.py | 14 -
 cross-project-tests/lit.site.cfg.py.in |  4 
 lldb/test/API/lit.cfg.py   |  5 +
 lldb/test/API/lit.site.cfg.py.in   |  8 +++
 lldb/test/Shell/helper/toolchain.py|  5 +
 lldb/test/Shell/lit.site.cfg.py.in |  9 
 llvm/CMakeLists.txt|  4 
 9 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..63bb86717bb14 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5483,6 +5483,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount 
instrumentation">,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
   HelpText<"Use pipes between commands, when possible">;
+// Facebook T92898286
+def post_link_optimize : Flag<["--"], "post-link-optimize">,
+  HelpText<"Apply post-link optimizations using BOLT">;
+// End Facebook T92898286
 def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules">;
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b141e5f2adfab..f7611af5763ab 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation 
&C, const JobAction &JA,
 }
   }
 
+  // Facebook T92898286
+  if (Args.hasArg(options::OPT_post_link_optimize))
+CmdArgs.push_back("-q");
+  // End Facebook T92898286
+
   Args.AddAllArgs(CmdArgs, options::OPT_T);
 
   const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileCurCP(),
  Exec, CmdArgs, Inputs, Output));
+  // Facebook T92898286
+  if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
+return;
+
+  const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
+  ArgStringList MoveCmdArgs;
+  MoveCmdArgs.push_back(Output.getFilename());
+  const char *PreBoltBin =
+  Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
+  MoveCmdArgs.push_back(PreBoltBin);
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ MvExec, MoveCmdArgs, std::nullopt));
+
+  ArgStringList BoltCmdArgs;
+  const char *BoltExec =
+  Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
+  BoltCmdArgs.push_back(PreBoltBin);
+  BoltCmdArgs.push_back("-reorder-blocks=reverse");
+  BoltCmdArgs.push_back("-update-debug-sections");
+  BoltCmdArgs.push_back("-o");
+  BoltCmdArgs.push_back(Output.getFilename());
+  C.addCommand(std::make_unique(JA, *this, 
ResponseFileSupport::None(),
+ BoltExec, BoltCmdArgs, std::nullopt));
+  // End Facebook T92898286
 }
 
 void tools::gnutools::Assembler::ConstructJob(Compilation &C,
diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests

[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

>From 7e3d1420a941431de223098ee153d2d4c63cfbfc Mon Sep 17 00:00:00 2001
From: Adrian Prantl 
Date: Mon, 17 Jun 2024 14:29:01 -0700
Subject: [PATCH 1/4] Convert ValueObject::Dump() to return llvm::Error()
 (NFCish)

This change by itself has no measurable effect on the LLDB
testsuite. I'm making it in preparation for threading through more
errors in the Swift language plugin.
---
 lldb/include/lldb/Core/ValueObject.h   |  4 ++--
 .../lldb/DataFormatters/ValueObjectPrinter.h   |  2 +-
 lldb/source/API/SBValue.cpp|  5 -
 lldb/source/Breakpoint/Watchpoint.cpp  |  8 ++--
 .../source/Commands/CommandObjectDWIMPrint.cpp |  9 +++--
 .../Commands/CommandObjectExpression.cpp   |  6 +-
 lldb/source/Commands/CommandObjectFrame.cpp| 18 +-
 lldb/source/Commands/CommandObjectMemory.cpp   |  5 -
 lldb/source/Commands/CommandObjectTarget.cpp   |  3 ++-
 lldb/source/Commands/CommandObjectThread.cpp   | 14 ++
 lldb/source/Core/DumpRegisterValue.cpp |  3 ++-
 lldb/source/Core/FormatEntity.cpp  | 11 +--
 lldb/source/Core/ValueObject.cpp   |  9 ++---
 .../DataFormatters/ValueObjectPrinter.cpp  | 18 +++---
 lldb/source/Plugins/REPL/Clang/ClangREPL.cpp   |  4 +++-
 .../API/commands/dwim-print/TestDWIMPrint.py   | 16 
 lldb/test/API/commands/dwim-print/main.c   |  6 +-
 .../DWARF/x86/class-type-nullptr-deref.s   |  2 +-
 .../DWARF/x86/debug-types-signature-loop.s |  2 +-
 .../DumpValueObjectOptionsTests.cpp|  7 ---
 20 files changed, 108 insertions(+), 44 deletions(-)

diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index db1fdae170ed0..205d9ad9b1953 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -694,9 +694,9 @@ class ValueObject {
 
   virtual SymbolContextScope *GetSymbolContextScope();
 
-  void Dump(Stream &s);
+  llvm::Error Dump(Stream &s);
 
-  void Dump(Stream &s, const DumpValueObjectOptions &options);
+  llvm::Error Dump(Stream &s, const DumpValueObjectOptions &options);
 
   static lldb::ValueObjectSP
   CreateValueObjectFromExpression(llvm::StringRef name,
diff --git a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
index fb5d60ba30d77..7460370c77e80 100644
--- a/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
+++ b/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
@@ -33,7 +33,7 @@ class ValueObjectPrinter {
 
   ~ValueObjectPrinter() = default;
 
-  bool PrintValueObject();
+  llvm::Error PrintValueObject();
 
 protected:
   typedef std::set InstancePointersSet;
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 9d7efba024d11..1b9cae6e350aa 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -1233,7 +1233,10 @@ bool SBValue::GetDescription(SBStream &description) {
 DumpValueObjectOptions options;
 options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
 options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
-value_sp->Dump(strm, options);
+if (llvm::Error error = value_sp->Dump(strm, options)) {
+  strm << "error: " << toString(std::move(error));
+  return false;
+}
   } else {
 strm.PutCString("No value");
   }
diff --git a/lldb/source/Breakpoint/Watchpoint.cpp 
b/lldb/source/Breakpoint/Watchpoint.cpp
index edb1a0e93460c..715e83c76697b 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -299,7 +299,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_old_value_sp->Dump(strm, options);
+if (llvm::Error error = m_old_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("old value: %s", strm.GetData());
   }
@@ -322,7 +324,9 @@ bool Watchpoint::DumpSnapshots(Stream *s, const char 
*prefix) const {
 .SetHideRootType(true)
 .SetHideRootName(true)
 .SetHideName(true);
-m_new_value_sp->Dump(strm, options);
+if (llvm::Error error = m_new_value_sp->Dump(strm, options))
+  strm << "error: " << toString(std::move(error));
+
 if (strm.GetData())
   values_ss.Printf("new value: %s", strm.GetData());
   }
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp 
b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 57a372a762e15..c1549ca6933fc 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -133,12 +133,17 @@ void CommandObjectDWIMPrint::DoExecut

[Lldb-commits] [lldb] Convert ValueObject::Dump() to return llvm::Error() (NFCish) (PR #95857)


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

LGTM

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


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


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

Looks good to me!

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


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


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


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


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

This is a good start but still requires some work.

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


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





medismailben wrote:

Do you still need this ?

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);

medismailben wrote:

I thought the breakpoint (location) ids started at 1, how come your expected 
`break_id` & `break_loc_id` are 0 ? 

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);

medismailben wrote:

You should do more with these (i.e. check that _actually_ `baton` point to the 
`"hello"` string).

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);
+return true;
+  }
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  TargetSP m_target_sp;
+  BreakpointSP m_breakpoint_sp;
+  Event *m_event;
+  const ExecutionContext m_exe_ctx;
+  lldb::user_id_t expected_breakpoint_id;
+  lldb::user_id_t expected_breakpoint_loc_id;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  StoppointCallbackContext context(m_event, m_exe_ctx, true);
+  m_breakpoint_sp->SetCallback(BreakpointSetCallbackTest::callback, baton,

medismailben wrote:

You can swap these 2 lines.

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


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


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


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


[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)


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


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


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





chelcassanova wrote:

Not anymore, I'll remove these.

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);

chelcassanova wrote:

An `EXPECT_EQ` for `baton` being `"hello"` right? I'll add that. Also, should I 
check anything more for the `StoppointCallbackContext` being true here?

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);

chelcassanova wrote:

My mistake, those should be 1 😅 

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);

medismailben wrote:

You could check that the ExecutionContext's target matches the `m_target_sp` if 
you want.

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


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



@@ -0,0 +1,89 @@
+//===-- TestBreakpointSetCallback.cpp
+//===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
+#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Breakpoint/StoppointCallbackContext.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Progress.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/ExecutionContext.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-types.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+
+using namespace lldb_private;
+using namespace lldb;
+
+class BreakpointSetCallbackTest : public ::testing::Test {
+public:
+  static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
+lldb::user_id_t break_id,
+lldb::user_id_t break_loc_id,
+lldb::user_id_t expected_breakpoint_id,
+lldb::user_id_t expected_breakpoint_loc_id) {
+EXPECT_TRUE(baton);
+EXPECT_TRUE(context);
+EXPECT_EQ(break_id, expected_breakpoint_id);
+EXPECT_EQ(break_loc_id, expected_breakpoint_loc_id);
+  }
+
+protected:
+  // The debugger's initialization function can't be called with no arguments
+  // so calling it using SubsystemRAII will cause the test build to fail as
+  // SubsystemRAII will call Initialize with no arguments. As such we set it up
+  // here the usual way.
+  void SetUp() override {
+std::call_once(TestUtilities::g_debugger_initialize_flag,
+   []() { Debugger::Initialize(nullptr); });
+
+// Set up the debugger, make sure that was done properly.
+ArchSpec arch("x86_64-apple-macosx-");
+Platform::SetHostPlatform(
+PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+m_debugger_sp = Debugger::CreateInstance();
+m_debugger_sp->GetTargetList().CreateTarget(*m_debugger_sp, "", arch,
+
lldb_private::eLoadDependentsNo,
+m_platform_sp, m_target_sp);
+m_breakpoint_sp = m_target_sp->CreateBreakpoint(0xDEADBEEF, false, false);
+  };
+
+  static bool callback(void *baton, StoppointCallbackContext *context,
+   lldb::user_id_t break_id, lldb::user_id_t break_loc_id) 
{
+BreakpointSetCallbackTest::CheckCallbackArgs(baton, context, break_id,
+ break_loc_id, 0, 0);
+return true;
+  }
+
+  DebuggerSP m_debugger_sp;
+  PlatformSP m_platform_sp;
+  TargetSP m_target_sp;
+  BreakpointSP m_breakpoint_sp;
+  Event *m_event;
+  const ExecutionContext m_exe_ctx;
+  lldb::user_id_t expected_breakpoint_id;
+  lldb::user_id_t expected_breakpoint_loc_id;
+  SubsystemRAII
+  subsystems;
+};
+
+TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
+  void *baton = (void *)"hello";
+  StoppointCallbackContext context(m_event, m_exe_ctx, true);

medismailben wrote:

It looks like `m_event` never gets initialized so I'd just pass a `nullptr` 
here and remove it from the test class.

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


[Lldb-commits] [lldb] 70f41a8 - [lldb] Add/change options in `statistics dump` to control what sections are dumped (#95075)


Author: royitaqi
Date: 2024-06-18T17:21:20-07:00
New Revision: 70f41a8c305478cb16bcda9f9967af96ab1e3a20

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

LOG: [lldb] Add/change options in `statistics dump` to control what sections 
are dumped (#95075)

# Added/changed options

The following options are **added** to the `statistics dump` command:
* `--targets=bool`: Boolean. Dumps the `targets` section.
* `--modules=bool`: Boolean. Dumps the `modules` section.
When both options are given, the field `moduleIdentifiers` will be
dumped for each target in the `targets` section.

The following options are **changed**:
* `--transcript=bool`: Changed to a boolean. Dumps the `transcript`
section.

# Behavior of `statistics dump` with various options

The behavior is **backward compatible**:
- When no options are provided, `statistics dump` dumps all sections.
- When `--summary` is provided, only dumps the summary info.

**New** behavior:
- `--targets=bool`, `--modules=bool`, `--transcript=bool` overrides the
above "default".

For **example**:
- `statistics dump --modules=false` dumps summary + targets +
transcript. No modules.
- `statistics dump --summary --targets=true --transcript=true` dumps
summary + targets (in summary mode) + transcript.


# Added options into public API

In `SBStatisticsOptions`, add:
* `Set/GetIncludeTargets`
* `Set/GetIncludeModules`
* `Set/GetIncludeTranscript`

**Alternative considered**: Thought about adding
`Set/GetIncludeSections(string sections_spec)`, which receives a
comma-separated list of section names to be included ("targets",
"modules", "transcript"). The **benefit** of this approach is that the
API is more future-proof when it comes to possible adding/changing of
section names. **However**, I feel the section names are likely to
remain unchanged for a while - it's not like we plan to make big changes
to the output of `statistics dump` any time soon. The **downsides** of
this approach are: 1\ the readability of the API is worse (requires
reading doc to understand what string can be accepted), 2\ string input
are more prone to human error (e.g. typo "target" instead of expected
"targets").


# Tests

```
bin/llvm-lit -sv 
../external/llvm-project/lldb/test/API/commands/statistics/basic/TestStats.py
```

```
./tools/lldb/unittests/Interpreter/InterpreterTests
```

New test cases have been added to verify:
* Different sections are dumped/not dumped when different
`StatisticsOptions` are given through command line (CLI or
`HandleCommand`; see `test_sections_existence_through_command`) or API
(see `test_sections_existence_through_api`).
* The order in which the options are given in command line does not
matter (see `test_order_of_options_do_not_matter`).

-

Co-authored-by: Roy Shi 

Added: 


Modified: 
lldb/include/lldb/API/SBStatisticsOptions.h
lldb/include/lldb/Interpreter/OptionArgParser.h
lldb/include/lldb/Target/Statistics.h
lldb/source/API/SBStatisticsOptions.cpp
lldb/source/Commands/CommandObjectStats.cpp
lldb/source/Commands/Options.td
lldb/source/Interpreter/OptionArgParser.cpp
lldb/source/Target/Statistics.cpp
lldb/test/API/commands/statistics/basic/TestStats.py
lldb/unittests/Interpreter/TestOptionArgParser.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBStatisticsOptions.h 
b/lldb/include/lldb/API/SBStatisticsOptions.h
index a0055135e36c2..74bea03eff9c9 100644
--- a/lldb/include/lldb/API/SBStatisticsOptions.h
+++ b/lldb/include/lldb/API/SBStatisticsOptions.h
@@ -22,9 +22,46 @@ class LLDB_API SBStatisticsOptions {
 
   const SBStatisticsOptions &operator=(const lldb::SBStatisticsOptions &rhs);
 
+  /// If true, dump only high-level summary statistics. Exclude details like
+  /// targets, modules, breakpoints, etc. This turns off `IncludeTargets`,
+  /// `IncludeModules` and `IncludeTranscript` by default.
+  ///
+  /// Defaults to false.
   void SetSummaryOnly(bool b);
   bool GetSummaryOnly();
 
+  /// If true, dump statistics for the targets, including breakpoints,
+  /// expression evaluations, frame variables, etc.
+  ///
+  /// Defaults to true, unless the `SummaryOnly` mode is enabled, in which case
+  /// this is turned off unless specified.
+  ///
+  /// If both `IncludeTargets` and `IncludeModules` are true, a list of module
+  /// identifiers will be added to the "targets" section.
+  void SetIncludeTargets(bool b);
+  bool GetIncludeTargets() const;
+
+  /// If true, dump statistics for the modules, including time and size of
+  /// various aspects of the module and debug information, type system, path,
+  /// etc.
+  ///
+  /// Defaults to true, unless the `SummaryOnly` mode is enabled, in which case
+  /// this is turned off unless specified.
+  ///
+  /// If both `IncludeTar

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


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


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


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


[Lldb-commits] [lldb] New ThreadPlanSingleThreadTimeout to resolve potential deadlock in single thread stepping (PR #90930)


jeffreytan81 wrote:

@jimingham, hope WWDC is going well. Do you have time to review this now? 
Thanks.

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


[Lldb-commits] [lldb] [lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) (PR #96013)


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

Make LanguageRuntime::GetTypeBitSize return an optional. This should be NFC, 
though the ObjCLanguageRuntime implementation is (possibly) more defensive 
against returning 0.

I'm not sure if it's possible for both `m_ivar.size` and `m_ivar.offset` to be 
zero. Previously, we'd return 0 and cache it, only to discard it the next time 
when finding it in the cache, and recomputing it again. The new code will avoid 
putting it in the cache in the first place.

>From 663bee087c345ed0d5759906d780cb4a75facac8 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere 
Date: Tue, 18 Jun 2024 19:32:44 -0700
Subject: [PATCH] [lldb] Make LanguageRuntime::GetTypeBitSize return an
 optional (NFC)

Make LanguageRuntime::GetTypeBitSize return an optional. This should be
NFC, though the ObjCLanguageRuntime implementation is (possibly) more
defensive against returning 0.

I'm not sure if it's possible for both `m_ivar.size` and `m_ivar.offset`
to be zero. Previously, we'd return 0 and cache it, only to discard it
the next time when finding it in the cache, and recomputing it again.
The new code will avoid putting it in the cache in the first place.
---
 lldb/include/lldb/Target/LanguageRuntime.h|  6 +++---
 .../ObjC/ObjCLanguageRuntime.cpp  | 21 ++-
 .../ObjC/ObjCLanguageRuntime.h|  6 +++---
 .../TypeSystem/Clang/TypeSystemClang.cpp  | 11 +-
 4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index a2a9c0163f082..58874c4188034 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -169,9 +169,9 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
 return m_process->GetTarget().GetSearchFilterForModule(nullptr);
   }
 
-  virtual bool GetTypeBitSize(const CompilerType &compiler_type,
-  uint64_t &size) {
-return false;
+  virtual std::optional
+  GetTypeBitSize(const CompilerType &compiler_type) {
+return {};
   }
 
   virtual void SymbolsDidLoad(const ModuleList &module_list) {}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp 
b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
index ba52444f0c2fc..a812ffba7a648 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -350,18 +350,17 @@ ObjCLanguageRuntime::EncodingToTypeSP 
ObjCLanguageRuntime::GetEncodingToType() {
   return nullptr;
 }
 
-bool ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type,
- uint64_t &size) {
+std::optional
+ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type) {
   void *opaque_ptr = compiler_type.GetOpaqueQualType();
-  size = m_type_size_cache.Lookup(opaque_ptr);
-  // an ObjC object will at least have an ISA, so 0 is definitely not OK
-  if (size > 0)
-return true;
+  uint64_t cached_size = m_type_size_cache.Lookup(opaque_ptr);
+  if (cached_size > 0)
+return cached_size;
 
   ClassDescriptorSP class_descriptor_sp =
   GetClassDescriptorFromClassName(compiler_type.GetTypeName());
   if (!class_descriptor_sp)
-return false;
+return {};
 
   int32_t max_offset = INT32_MIN;
   uint64_t sizeof_max = 0;
@@ -377,11 +376,13 @@ bool ObjCLanguageRuntime::GetTypeBitSize(const 
CompilerType &compiler_type,
 }
   }
 
-  size = 8 * (max_offset + sizeof_max);
-  if (found)
+  uint64_t size = 8 * (max_offset + sizeof_max);
+  if (found && size > 0) {
 m_type_size_cache.Insert(opaque_ptr, size);
+return size;
+  }
 
-  return found;
+  return {};
 }
 
 lldb::BreakpointPreconditionSP
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h 
b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
index 0a8b6e8d56ed0..ffe9725fa6826 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -107,7 +107,7 @@ class ObjCLanguageRuntime : public LanguageRuntime {
 int64_t *value_bits = nullptr,
 uint64_t *payload = nullptr) = 0;
 /// @}
- 
+
 virtual uint64_t GetInstanceSize() = 0;
 
 // use to implement version-specific additional constraints on pointers
@@ -321,8 +321,8 @@ class ObjCLanguageRuntime : public LanguageRuntime {
 m_negative_complete_class_cache.clear();
   }
 
-  bool GetTypeBitSize(const CompilerType &compiler_type,
-  uint64_t &size) override;
+  std::optional
+  GetTypeBitSize(const CompilerType &compiler_type) override;
 
   /// Check whether the name is "self" or "_cmd" and should show up in
   /// "frame variable".
diff 

[Lldb-commits] [lldb] [lldb] Make LanguageRuntime::GetTypeBitSize return an optional (NFC) (PR #96013)


llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)


Changes

Make LanguageRuntime::GetTypeBitSize return an optional. This should be NFC, 
though the ObjCLanguageRuntime implementation is (possibly) more defensive 
against returning 0.

I'm not sure if it's possible for both `m_ivar.size` and `m_ivar.offset` to be 
zero. Previously, we'd return 0 and cache it, only to discard it the next time 
when finding it in the cache, and recomputing it again. The new code will avoid 
putting it in the cache in the first place.

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


4 Files Affected:

- (modified) lldb/include/lldb/Target/LanguageRuntime.h (+3-3) 
- (modified) lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp 
(+11-10) 
- (modified) lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h 
(+3-3) 
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+6-5) 


``diff
diff --git a/lldb/include/lldb/Target/LanguageRuntime.h 
b/lldb/include/lldb/Target/LanguageRuntime.h
index a2a9c0163f082..58874c4188034 100644
--- a/lldb/include/lldb/Target/LanguageRuntime.h
+++ b/lldb/include/lldb/Target/LanguageRuntime.h
@@ -169,9 +169,9 @@ class LanguageRuntime : public Runtime, public 
PluginInterface {
 return m_process->GetTarget().GetSearchFilterForModule(nullptr);
   }
 
-  virtual bool GetTypeBitSize(const CompilerType &compiler_type,
-  uint64_t &size) {
-return false;
+  virtual std::optional
+  GetTypeBitSize(const CompilerType &compiler_type) {
+return {};
   }
 
   virtual void SymbolsDidLoad(const ModuleList &module_list) {}
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp 
b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
index ba52444f0c2fc..a812ffba7a648 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.cpp
@@ -350,18 +350,17 @@ ObjCLanguageRuntime::EncodingToTypeSP 
ObjCLanguageRuntime::GetEncodingToType() {
   return nullptr;
 }
 
-bool ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type,
- uint64_t &size) {
+std::optional
+ObjCLanguageRuntime::GetTypeBitSize(const CompilerType &compiler_type) {
   void *opaque_ptr = compiler_type.GetOpaqueQualType();
-  size = m_type_size_cache.Lookup(opaque_ptr);
-  // an ObjC object will at least have an ISA, so 0 is definitely not OK
-  if (size > 0)
-return true;
+  uint64_t cached_size = m_type_size_cache.Lookup(opaque_ptr);
+  if (cached_size > 0)
+return cached_size;
 
   ClassDescriptorSP class_descriptor_sp =
   GetClassDescriptorFromClassName(compiler_type.GetTypeName());
   if (!class_descriptor_sp)
-return false;
+return {};
 
   int32_t max_offset = INT32_MIN;
   uint64_t sizeof_max = 0;
@@ -377,11 +376,13 @@ bool ObjCLanguageRuntime::GetTypeBitSize(const 
CompilerType &compiler_type,
 }
   }
 
-  size = 8 * (max_offset + sizeof_max);
-  if (found)
+  uint64_t size = 8 * (max_offset + sizeof_max);
+  if (found && size > 0) {
 m_type_size_cache.Insert(opaque_ptr, size);
+return size;
+  }
 
-  return found;
+  return {};
 }
 
 lldb::BreakpointPreconditionSP
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h 
b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
index 0a8b6e8d56ed0..ffe9725fa6826 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -107,7 +107,7 @@ class ObjCLanguageRuntime : public LanguageRuntime {
 int64_t *value_bits = nullptr,
 uint64_t *payload = nullptr) = 0;
 /// @}
- 
+
 virtual uint64_t GetInstanceSize() = 0;
 
 // use to implement version-specific additional constraints on pointers
@@ -321,8 +321,8 @@ class ObjCLanguageRuntime : public LanguageRuntime {
 m_negative_complete_class_cache.clear();
   }
 
-  bool GetTypeBitSize(const CompilerType &compiler_type,
-  uint64_t &size) override;
+  std::optional
+  GetTypeBitSize(const CompilerType &compiler_type) override;
 
   /// Check whether the name is "self" or "_cmd" and should show up in
   /// "frame variable".
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index dbe6238d4fe5a..f9cdf357acdde 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -4744,11 +4744,12 @@ 
TypeSystemClang::GetBitSize(lldb::opaque_compiler_type_t type,
   ExecutionContext exe_ctx(exe_scope);
   Process *process = exe_ctx.GetProcessPtr();
   if (process) {
-ObjCLanguageRuntime *objc_runtime = ObjCLanguageRunt

  1   2   >