[Lldb-commits] [PATCH] D130219: [lldb][NFCI] Refactor regex filtering logic in CommandObjectTypeFormatterList

2022-07-20 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe created this revision.
jgorbe added a reviewer: labath.
jgorbe added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jgorbe requested review of this revision.

Extract a bit of copy/pasted regex filtering logic into a separate function and 
simplify it a little bit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130219

Files:
  lldb/source/Commands/CommandObjectType.cpp

Index: lldb/source/Commands/CommandObjectType.cpp
===
--- lldb/source/Commands/CommandObjectType.cpp
+++ lldb/source/Commands/CommandObjectType.cpp
@@ -1055,6 +1055,15 @@
 return false;
   }
 
+  static bool ShouldListItem(llvm::StringRef s, RegularExpression *regex) {
+// If we have a regex, it can match two kinds of results:
+//   - An item created with that same regex string (exact string match), so
+// the user can list it using the same string it used at creation time.
+//   - Items that match the regex.
+// No regex means list everything.
+return (regex == nullptr || (s == regex->GetText() || regex->Execute(s)));
+  }
+
   bool DoExecute(Args , CommandReturnObject ) override {
 const size_t argc = command.GetArgumentCount();
 
@@ -1096,24 +1105,13 @@
 .SetExact([, _regex, _printed](
   const TypeMatcher _matcher,
   const FormatterSharedPointer _sp) -> bool {
-  if (formatter_regex) {
-bool escape = true;
-if (type_matcher.CreatedBySameMatchString(
-ConstString(formatter_regex->GetText( {
-  escape = false;
-} else if (formatter_regex->Execute(
-   type_matcher.GetMatchString().GetStringRef())) {
-  escape = false;
-}
-
-if (escape)
-  return true;
+  if (ShouldListItem(type_matcher.GetMatchString().GetStringRef(),
+ formatter_regex.get())) {
+any_printed = true;
+result.GetOutputStream().Printf(
+"%s: %s\n", type_matcher.GetMatchString().GetCString(),
+format_sp->GetDescription().c_str());
   }
-
-  any_printed = true;
-  result.GetOutputStream().Printf(
-  "%s: %s\n", type_matcher.GetMatchString().GetCString(),
-  format_sp->GetDescription().c_str());
   return true;
 });
 
@@ -1121,24 +1119,13 @@
 .SetWithRegex([, _regex, _printed](
   const TypeMatcher _matcher,
   const FormatterSharedPointer _sp) -> bool {
-  if (formatter_regex) {
-bool escape = true;
-if (type_matcher.CreatedBySameMatchString(
-ConstString(formatter_regex->GetText( {
-  escape = false;
-} else if (formatter_regex->Execute(
-   type_matcher.GetMatchString().GetStringRef())) {
-  escape = false;
-}
-
-if (escape)
-  return true;
+  if (ShouldListItem(type_matcher.GetMatchString().GetStringRef(),
+ formatter_regex.get())) {
+any_printed = true;
+result.GetOutputStream().Printf(
+"%s: %s\n", type_matcher.GetMatchString().GetCString(),
+format_sp->GetDescription().c_str());
   }
-
-  any_printed = true;
-  result.GetOutputStream().Printf(
-  "%s: %s\n", type_matcher.GetMatchString().GetCString(),
-  format_sp->GetDescription().c_str());
   return true;
 });
 
@@ -1155,20 +1142,9 @@
   DataVisualization::Categories::ForEach(
   [_regex, _closure](
   const lldb::TypeCategoryImplSP ) -> bool {
-if (category_regex) {
-  bool escape = true;
-  if (category->GetName() == category_regex->GetText()) {
-escape = false;
-  } else if (category_regex->Execute(category->GetName())) {
-escape = false;
-  }
-
-  if (escape)
-return true;
+if (ShouldListItem(category->GetName(), category_regex.get())) {
+  category_closure(category);
 }
-
-category_closure(category);
-
 return true;
   });
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446316.
Michael137 added a comment.

- Remove drive-by whitespace change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,7 +7538,7 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if 

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446315.
Michael137 added a comment.

- Add test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+  using EnumAliasAlias = EnumAlias;
+  static constexpr EnumAliasAlias enum_alias_alias =
+  ScopedEnum::scoped_enum_case1;
+};
+
 int main() {
   A a;
 
@@ -98,5 +107,9 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+  auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+

[Lldb-commits] [PATCH] D130054: [trace][intel pt] Introduce wall clock time for each trace item

2022-07-20 Thread walter erquinigo via Phabricator via lldb-commits
wallace added inline comments.



Comment at: lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp:288
 
+decoded_thread.NotifyTsc(execution.thread_execution.GetLowestKnownTSC());
 decoded_thread.NotifyCPU(execution.thread_execution.cpu_id);

jj10306 wrote:
> if we have both a start and end TSC, shouldn't we emit the start here (like 
> you're doing) and then after decoding all the instructions we should also 
> emit the the end TSC?
you are right


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130054/new/

https://reviews.llvm.org/D130054

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


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Doing this instead:

  if (const EnumType *enum_type = 
llvm::dyn_cast(qt.getTypePtr()->getUnqualifiedDesugaredType())) {

resolves the crash, though unclear if that's the right thing to do

In D81471#3666071 , @Michael137 wrote:

> This seems to cause issues when `var->getType() == const 
> llvm::APFloatBase::roundingMode`.
>
> The following assertion triggered:
>
>   Assertion failed: (type->isIntegerType() && "Illegal type in 
> IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892
>
> Reproduces with:
>
> 1. `lldb -- ./bin/lldb a.out`
> 2. `b LookupLocalVariable`
> 3. step a couple of times until `decl_context` is declared
> 4. `p decl_context`
>
> It looks ike the `dyn_cast` to `EnumType` fails and thus 
> `qt.getUnqualifiedType()` which we pass into `IntegerLiteral::Create` remains 
> an EnumType, which breaks the invariant
>
> Investigating further...

Tried to address this in https://reviews.llvm.org/D130213


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D130054: [trace][intel pt] Introduce wall clock time for each trace item

2022-07-20 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 446306.
wallace added a comment.

fix test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130054/new/

https://reviews.llvm.org/D130054

Files:
  lldb/include/lldb/Target/TraceCursor.h
  lldb/include/lldb/Target/TraceDumper.h
  lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.h
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.h
  lldb/source/Target/TraceCursor.cpp
  lldb/source/Target/TraceDumper.cpp
  lldb/test/API/commands/trace/TestTraceEvents.py
  lldb/test/API/commands/trace/TestTraceLoad.py
  lldb/test/API/commands/trace/TestTraceTSC.py

Index: lldb/test/API/commands/trace/TestTraceTSC.py
===
--- lldb/test/API/commands/trace/TestTraceTSC.py
+++ lldb/test/API/commands/trace/TestTraceTSC.py
@@ -16,8 +16,8 @@
 self.traceStartThread(enableTsc=True)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=\d+\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=[": \[\d+.\d+ ns\] 0x00400511movl"])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -34,18 +34,18 @@
 self.expect("si")
 
 # We'll get the most recent instructions, with at least 3 different TSCs
-self.runCmd("thread trace dump instructions --tsc --raw --forward")
-id_to_tsc = {}
+self.runCmd("thread trace dump instructions -t --raw --forward")
+id_to_timestamp = {}
 for line in self.res.GetOutput().splitlines():
-m = re.search("(.+): \[tsc=(.+)\].*", line)
+m = re.search("(.+): \[(.+)\ ns].*", line)
 if m:
-id_to_tsc[int(m.group(1))] = m.group(2)
-self.assertEqual(len(id_to_tsc), 3)
+id_to_timestamp[int(m.group(1))] = m.group(2)
+self.assertEqual(len(id_to_timestamp), 3)
 
 # We check that the values are right when dumping a specific id
-for id, tsc in id_to_tsc.items():
-self.expect(f"thread trace dump instructions --tsc --id {id} -c 1",
-substrs=[f"{id}: [tsc={tsc}"])
+for id, timestamp in id_to_timestamp.items():
+self.expect(f"thread trace dump instructions -t --id {id} -c 1",
+substrs=[f"{id}: [{timestamp} ns]"])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -57,11 +57,11 @@
 self.traceStartProcess(enableTsc=True)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=\d+\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=[": \[\d+.\d+ ns\] 0x00400511movl"])
 
-self.expect("thread trace dump instructions --tsc -c 1 --pretty-json",
-patterns=['''"tsc": "\d+"'''])
+self.expect("thread trace dump instructions -t -c 1 --pretty-json",
+patterns=['''"timestamp_ns": "\d+.\d+"'''])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -73,11 +73,11 @@
 self.traceStartThread(enableTsc=False)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=unavailable\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=[": \[unavailable\] 0x00400511movl"])
 
-self.expect("thread trace dump instructions --tsc -c 1 --json",
-substrs=['''"tsc":null'''])
+self.expect("thread trace dump instructions -t -c 1 --json",
+substrs=['''"timestamp_ns":null'''])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ 

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 updated this revision to Diff 446305.
Michael137 added a comment.

- Remove redundant header


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130213/new/

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +103,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", 
result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +103,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType 

[Lldb-commits] [PATCH] D130213: [LLDB][ClangExpression] Fix evaluation of types with constant initialized enum typedefs

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 created this revision.
Michael137 added reviewers: aprantl, jingham, werat, labath.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

`IntegerLiteral::Create` expects integer types. For that reason
when we parse DWARF into an AST, when we encounter a constant
initialized enum member variable, we try to determine the underlying
integer type before creating the `IntegerLiteral`. However, we
currently don't desugar the type and the `dyn_cast`
fails. In debug builds this triggers following assert:

  Assertion failed: (type->isIntegerType() && "Illegal type in
  IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892

This patch turns the `dyn_cast` into a `getAs`
which desguars the enum if necessary, allowing us to get to the
underlying integer type.

**Testing**

- API test
- Manual repro is fixed


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130213

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -1,3 +1,4 @@
+#include 
 #include 
 
 enum Enum {
@@ -69,6 +70,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +104,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ 
lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
 
+# Test an aliased enum with fixed underlying type.
+self.expect_expr("ClassWithEnumAlias::enum_alias", 
result_value="scoped_enum_case2")
+
 # Test taking address.
 if lldbplatformutil.getPlatform() == "windows":
 # On Windows data members without the out-of-class definitions 
still have
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7538,10 +7538,11 @@
  "only integer or enum types supported");
   // If the variable is an enum type, take the underlying integer type as
   // the type of the integer literal.
-  if (const EnumType *enum_type = llvm::dyn_cast(qt.getTypePtr())) {
+  if (const EnumType *enum_type = qt->getAs()) {
 const EnumDecl *enum_decl = enum_type->getDecl();
 qt = enum_decl->getIntegerType();
   }
+
   var->setInit(IntegerLiteral::Create(ast, init_value, qt.getUnqualifiedType(),
   SourceLocation()));
 }


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -1,3 +1,4 @@
+#include 
 #include 
 
 enum Enum {
@@ -69,6 +70,11 @@
   constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
 } cwc;
 
+struct ClassWithEnumAlias {
+  using EnumAlias = ScopedEnum;
+  static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+};
+
 int main() {
   A a;
 
@@ -98,5 +104,8 @@
   se = A::invalid_scoped_enum_val;
   ScopedCharEnum sce = A::scoped_char_enum_val;
   ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+  auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+
   return 0; // break here
 }
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,9 @@
 self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
 

[Lldb-commits] [PATCH] D130054: [trace][intel pt] Introduce wall clock time for each trace item

2022-07-20 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 446303.
wallace edited the summary of this revision.
wallace added a comment.

final version


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130054/new/

https://reviews.llvm.org/D130054

Files:
  lldb/include/lldb/Target/TraceCursor.h
  lldb/include/lldb/Target/TraceDumper.h
  lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.h
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.h
  lldb/source/Target/TraceCursor.cpp
  lldb/source/Target/TraceDumper.cpp
  lldb/test/API/commands/trace/TestTraceEvents.py
  lldb/test/API/commands/trace/TestTraceLoad.py
  lldb/test/API/commands/trace/TestTraceTSC.py

Index: lldb/test/API/commands/trace/TestTraceTSC.py
===
--- lldb/test/API/commands/trace/TestTraceTSC.py
+++ lldb/test/API/commands/trace/TestTraceTSC.py
@@ -16,8 +16,8 @@
 self.traceStartThread(enableTsc=True)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=\d+\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=["1: \[\d+.\d+ ns\] 0x00400511movl"])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -34,18 +34,18 @@
 self.expect("si")
 
 # We'll get the most recent instructions, with at least 3 different TSCs
-self.runCmd("thread trace dump instructions --tsc --raw --forward")
-id_to_tsc = {}
+self.runCmd("thread trace dump instructions -t --raw --forward")
+id_to_timestamp = {}
 for line in self.res.GetOutput().splitlines():
-m = re.search("(.+): \[tsc=(.+)\].*", line)
+m = re.search("(.+): \[(.+)\ ns].*", line)
 if m:
-id_to_tsc[int(m.group(1))] = m.group(2)
-self.assertEqual(len(id_to_tsc), 3)
+id_to_timestamp[int(m.group(1))] = m.group(2)
+self.assertEqual(len(id_to_timestamp), 3)
 
 # We check that the values are right when dumping a specific id
-for id, tsc in id_to_tsc.items():
-self.expect(f"thread trace dump instructions --tsc --id {id} -c 1",
-substrs=[f"{id}: [tsc={tsc}"])
+for id, timestamp in id_to_timestamp.items():
+self.expect(f"thread trace dump instructions -t --id {id} -c 1",
+substrs=[f"{id}: [{timestamp} ns]"])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -57,11 +57,11 @@
 self.traceStartProcess(enableTsc=True)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=\d+\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=["1: \[\d+.\d+ ns\] 0x00400511movl"])
 
-self.expect("thread trace dump instructions --tsc -c 1 --pretty-json",
-patterns=['''"tsc": "\d+"'''])
+self.expect("thread trace dump instructions -t -c 1 --pretty-json",
+patterns=['''"timestamp_ns": "\d+.\d+"'''])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
@@ -73,11 +73,11 @@
 self.traceStartThread(enableTsc=False)
 
 self.expect("n")
-self.expect("thread trace dump instructions --tsc -c 1",
-patterns=["0: \[tsc=unavailable\] 0x00400511movl"])
+self.expect("thread trace dump instructions -t -c 1",
+patterns=["0: \[unavailable\] 0x00400511movl"])
 
-self.expect("thread trace dump instructions --tsc -c 1 --json",
-substrs=['''"tsc":null'''])
+self.expect("thread trace dump instructions -t -c 1 --json",
+substrs=['''"timestamp_ns":null'''])
 
 @testSBAPIAndCommands
 @skipIf(oslist=no_match(['linux']), archs=no_match(['i386', 'x86_64']))
Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- 

[Lldb-commits] [PATCH] D130054: [trace][intel pt] Introduce wall clock time for each trace item

2022-07-20 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 446281.
wallace added a comment.

.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130054/new/

https://reviews.llvm.org/D130054

Files:
  lldb/include/lldb/Target/TraceCursor.h
  lldb/include/lldb/Target/TraceDumper.h
  lldb/include/lldb/Utility/TraceIntelPTGDBRemotePackets.h
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
  lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.h
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/ThreadDecoder.h
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTMultiCpuDecoder.h
  lldb/source/Target/TraceCursor.cpp
  lldb/source/Target/TraceDumper.cpp

Index: lldb/source/Target/TraceDumper.cpp
===
--- lldb/source/Target/TraceDumper.cpp
+++ lldb/source/Target/TraceDumper.cpp
@@ -128,16 +128,26 @@
 
 m_s.Format("{0}: ", item.id);
 
-if (m_options.show_tsc) {
-  m_s.Format("[tsc={0}] ",
- item.tsc ? std::to_string(*item.tsc) : "unavailable");
+if (m_options.show_timestamps) {
+  m_s.Format("[{0}] ", item.timestamp
+   ? (formatv("{0:2}", *item.timestamp) + " ns")
+   : "unavailable");
 }
 
 if (item.event) {
   m_s << "(event) " << TraceCursor::EventKindToString(*item.event);
-  if (*item.event == eTraceEventCPUChanged) {
+  switch (*item.event) {
+  case eTraceEventCPUChanged:
 m_s.Format(" [new CPU={0}]",
item.cpu_id ? std::to_string(*item.cpu_id) : "unavailable");
+break;
+  case eTraceEventHWClockTick:
+m_s.Format(" [{0}]", item.hw_clock ? std::to_string(*item.hw_clock)
+   : "unavailable");
+break;
+  case eTraceEventDisabledHW:
+  case eTraceEventDisabledSW:
+break;
   }
 } else if (item.error) {
   m_s << "(error) " << *item.error;
@@ -181,7 +191,8 @@
 | {
   "loadAddress": string decimal,
   "id": decimal,
-  "tsc"?: string decimal,
+  "hwClock"?: string decimal,
+  "timestamp_ns"?: string decimal,
   "module"?: string,
   "symbol"?: string,
   "line"?: decimal,
@@ -202,8 +213,17 @@
 
   void DumpEvent(const TraceDumper::TraceItem ) {
 m_j.attribute("event", TraceCursor::EventKindToString(*item.event));
-if (item.event == eTraceEventCPUChanged)
+switch (*item.event) {
+case eTraceEventCPUChanged:
   m_j.attribute("cpuId", item.cpu_id);
+  break;
+case eTraceEventHWClockTick:
+  m_j.attribute("hwClock", item.hw_clock);
+  break;
+case eTraceEventDisabledHW:
+case eTraceEventDisabledSW:
+  break;
+}
   }
 
   void DumpInstruction(const TraceDumper::TraceItem ) {
@@ -234,10 +254,11 @@
   void TraceItem(const TraceDumper::TraceItem ) override {
 m_j.object([&] {
   m_j.attribute("id", item.id);
-  if (m_options.show_tsc)
-m_j.attribute(
-"tsc",
-item.tsc ? Optional(std::to_string(*item.tsc)) : None);
+  if (m_options.show_timestamps)
+m_j.attribute("timestamp_ns", item.timestamp
+  ? Optional(
+std::to_string(*item.timestamp))
+  : None);
 
   if (item.event) {
 DumpEvent(item);
@@ -289,8 +310,8 @@
   TraceItem item;
   item.id = m_cursor_up->GetId();
 
-  if (m_options.show_tsc)
-item.tsc = m_cursor_up->GetCounter(lldb::eTraceCounterTSC);
+  if (m_options.show_timestamps)
+item.timestamp = m_cursor_up->GetWallClockTime();
   return item;
 }
 
@@ -366,8 +387,17 @@
   if (!m_options.show_events)
 continue;
   item.event = m_cursor_up->GetEventType();
-  if (*item.event == eTraceEventCPUChanged)
+  switch (*item.event) {
+  case eTraceEventCPUChanged:
 item.cpu_id = m_cursor_up->GetCPU();
+break;
+  case eTraceEventHWClockTick:
+item.hw_clock = m_cursor_up->GetHWClock();
+break;
+  case eTraceEventDisabledHW:
+  case eTraceEventDisabledSW:
+break;
+  }
 } else if (m_cursor_up->IsError()) {
   item.error = m_cursor_up->GetError();
 } else {
Index: lldb/source/Target/TraceCursor.cpp
===
--- 

[Lldb-commits] [lldb] 459cfa5 - [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Slava Gurevich via lldb-commits

Author: Slava Gurevich
Date: 2022-07-20T14:50:48-07:00
New Revision: 459cfa5e94d75b08aa421b79765ba1cd2126c4a4

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

LOG: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

Improve LLDB reliability by fixing the following "uninitialized variables" 
static code inspection warnings from
scan.coverity.com:

1094796 1095721 1095728 1095737 1095741
1095756 1095779 1095789 1095805 1214552
1229457 1232475 1274006 1274010 1293427
1364800 1364802 1364804 1364812 1364816
1374902 1374909 1384975 1399312 1420451
1431704 1454230 1454554 1454615 1454579
1454594 1454832 1457759 1458696 1461909
1467658 1487814 1487830 1487845

Differential Revision: https://reviews.llvm.org/D130098

Added: 


Modified: 
lldb/include/lldb/Core/EmulateInstruction.h
lldb/include/lldb/DataFormatters/TypeCategory.h
lldb/include/lldb/DataFormatters/TypeSynthetic.h
lldb/source/Commands/CommandObjectMemory.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Commands/CommandObjectType.cpp
lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
lldb/source/Plugins/Language/ObjC/CFBasicHash.h
lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
lldb/source/Plugins/Language/ObjC/NSError.cpp
lldb/source/Plugins/Language/ObjC/NSSet.cpp

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h

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

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h

lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/EmulateInstruction.h 
b/lldb/include/lldb/Core/EmulateInstruction.h
index f50fee095a8bb..e5421e5e91d1a 100644
--- a/lldb/include/lldb/Core/EmulateInstruction.h
+++ b/lldb/include/lldb/Core/EmulateInstruction.h
@@ -179,7 +179,7 @@ class EmulateInstruction : public PluginInterface {
 eInfoTypeISAAndImmediateSigned,
 eInfoTypeISA,
 eInfoTypeNoArgs
-  } InfoType;
+  };
 
   struct Context {
 ContextType type = eContextInvalid;

diff  --git a/lldb/include/lldb/DataFormatters/TypeCategory.h 
b/lldb/include/lldb/DataFormatters/TypeCategory.h
index 2c93059018372..16255f9488bda 100644
--- a/lldb/include/lldb/DataFormatters/TypeCategory.h
+++ b/lldb/include/lldb/DataFormatters/TypeCategory.h
@@ -331,7 +331,7 @@ class TypeCategoryImpl {
 
   std::vector m_languages;
 
-  uint32_t m_enabled_position;
+  uint32_t m_enabled_position = 0;
 
   void Enable(bool value, uint32_t position);
 

diff  --git a/lldb/include/lldb/DataFormatters/TypeSynthetic.h 
b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
index 3f58297a529b3..890a6eb4f4487 100644
--- a/lldb/include/lldb/DataFormatters/TypeSynthetic.h
+++ b/lldb/include/lldb/DataFormatters/TypeSynthetic.h
@@ -266,7 +266,7 @@ class SyntheticChildren {
   uint32_t () { return m_my_revision; }
 
 protected:
-  uint32_t m_my_revision;
+  uint32_t m_my_revision = 0;
   Flags m_flags;
 
 private:

diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index 3c07d19b35b26..ca0384cf9453d 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -275,7 +275,7 @@ class OptionGroupReadMemory : public OptionGroup {
   OptionValueUInt64 m_num_per_line;
   bool m_output_as_binary = false;
   OptionValueString m_view_as_type;
-  bool m_force;
+  bool m_force = false;
   OptionValueUInt64 m_offset;
   OptionValueLanguage m_language_for_type;
 };

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp

[Lldb-commits] [PATCH] D130098: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Slava Gurevich via Phabricator via lldb-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG459cfa5e94d7: [LLDB][NFC][Reliability] Fix uninitialized 
variables from Coverity scan (authored by fixathon).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130098/new/

https://reviews.llvm.org/D130098

Files:
  lldb/include/lldb/Core/EmulateInstruction.h
  lldb/include/lldb/DataFormatters/TypeCategory.h
  lldb/include/lldb/DataFormatters/TypeSynthetic.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/CommandObjectType.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp
  lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
  lldb/source/Plugins/Language/ObjC/CFBasicHash.h
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSError.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
  lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
  lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Index: lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
===
--- lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -24,11 +24,12 @@
 : m_cur_insn(nullptr), m_machine_ip_regnum(LLDB_INVALID_REGNUM),
   m_machine_sp_regnum(LLDB_INVALID_REGNUM),
   m_machine_fp_regnum(LLDB_INVALID_REGNUM),
+  m_machine_alt_fp_regnum(LLDB_INVALID_REGNUM),
   m_lldb_ip_regnum(LLDB_INVALID_REGNUM),
   m_lldb_sp_regnum(LLDB_INVALID_REGNUM),
   m_lldb_fp_regnum(LLDB_INVALID_REGNUM),
-
-  m_reg_map(), m_arch(arch), m_cpu(k_cpu_unspecified), m_wordsize(-1),
+  m_lldb_alt_fp_regnum(LLDB_INVALID_REGNUM), m_reg_map(), m_arch(arch),
+  m_cpu(k_cpu_unspecified), m_wordsize(-1),
   m_register_map_initialized(false), m_disasm_context() {
   m_disasm_context =
   ::LLVMCreateDisasm(arch.GetTriple().getTriple().c_str(), nullptr,
Index: lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
===
--- lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
+++ lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
@@ -64,8 +64,8 @@
   lldb_private::EmulateInstruction *inst_emulator)
   : UnwindAssembly(arch), m_inst_emulator_up(inst_emulator),
 m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_curr_row(),
-m_cfa_reg_info(), m_fp_is_cfa(false), m_register_values(),
-m_pushed_regs(), m_curr_row_modified(false),
+m_initial_sp(0), m_cfa_reg_info(), m_fp_is_cfa(false),
+m_register_values(), m_pushed_regs(), m_curr_row_modified(false),
 m_forward_branch_offset(0) {
 if (m_inst_emulator_up.get()) {
   m_inst_emulator_up->SetBaton(this);
Index: lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
===
--- lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
+++ lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
@@ -174,6 +174,14 @@
   dqo_target_queue = UINT16_MAX;
   dqo_target_queue = UINT16_MAX;
   dqo_priority = UINT16_MAX;
+  dqo_label_size = 0;
+  dqo_flags_size = 0;
+  dqo_serialnum_size = 0;
+  dqo_width_size = 0;
+  dqo_running_size = 0;
+  dqo_suspend_cnt_size = 0;
+  dqo_target_queue_size = 0;
+  dqo_priority_size = 0;
 }
 
 bool IsValid() { return dqo_version != UINT16_MAX; }
Index: 

[Lldb-commits] [PATCH] D130045: Implement better path matching in FileSpecList::FindFileIndex(...).

2022-07-20 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

sounds good, I will split out the caching into a separate patch. I will try to 
use the llvm::Optional as long as it doesn't increase the size of 
FileSpec which is currently at 24 bytes.

I will also split out the file index matching into a new function that allows 
relative matches and only switch the line table search stuff over to use it so 
we don't affect any other clients of FileSpecList.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130045/new/

https://reviews.llvm.org/D130045

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


[Lldb-commits] [PATCH] D130098: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Slava Gurevich via Phabricator via lldb-commits
fixathon marked 3 inline comments as done.
fixathon added a comment.

Address the comments: revert the formatting for lines unrelated to my changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130098/new/

https://reviews.llvm.org/D130098

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


[Lldb-commits] [PATCH] D130098: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Slava Gurevich via Phabricator via lldb-commits
fixathon updated this revision to Diff 446262.
fixathon added a comment.

Remove formatting for unrelated lines


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130098/new/

https://reviews.llvm.org/D130098

Files:
  lldb/include/lldb/Core/EmulateInstruction.h
  lldb/include/lldb/DataFormatters/TypeCategory.h
  lldb/include/lldb/DataFormatters/TypeSynthetic.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/CommandObjectType.cpp
  lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/HexagonDYLDRendezvous.cpp
  lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.h
  lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
  lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp
  lldb/source/Plugins/Language/ObjC/CFBasicHash.h
  lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
  lldb/source/Plugins/Language/ObjC/NSError.cpp
  lldb/source/Plugins/Language/ObjC/NSSet.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
  
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
  lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_x86.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
  lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
  lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
  lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp

Index: lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
===
--- lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
+++ lldb/source/Plugins/UnwindAssembly/x86/x86AssemblyInspectionEngine.cpp
@@ -24,11 +24,12 @@
 : m_cur_insn(nullptr), m_machine_ip_regnum(LLDB_INVALID_REGNUM),
   m_machine_sp_regnum(LLDB_INVALID_REGNUM),
   m_machine_fp_regnum(LLDB_INVALID_REGNUM),
+  m_machine_alt_fp_regnum(LLDB_INVALID_REGNUM),
   m_lldb_ip_regnum(LLDB_INVALID_REGNUM),
   m_lldb_sp_regnum(LLDB_INVALID_REGNUM),
   m_lldb_fp_regnum(LLDB_INVALID_REGNUM),
-
-  m_reg_map(), m_arch(arch), m_cpu(k_cpu_unspecified), m_wordsize(-1),
+  m_lldb_alt_fp_regnum(LLDB_INVALID_REGNUM), m_reg_map(), m_arch(arch),
+  m_cpu(k_cpu_unspecified), m_wordsize(-1),
   m_register_map_initialized(false), m_disasm_context() {
   m_disasm_context =
   ::LLVMCreateDisasm(arch.GetTriple().getTriple().c_str(), nullptr,
Index: lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
===
--- lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
+++ lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h
@@ -64,8 +64,8 @@
   lldb_private::EmulateInstruction *inst_emulator)
   : UnwindAssembly(arch), m_inst_emulator_up(inst_emulator),
 m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_curr_row(),
-m_cfa_reg_info(), m_fp_is_cfa(false), m_register_values(),
-m_pushed_regs(), m_curr_row_modified(false),
+m_initial_sp(0), m_cfa_reg_info(), m_fp_is_cfa(false),
+m_register_values(), m_pushed_regs(), m_curr_row_modified(false),
 m_forward_branch_offset(0) {
 if (m_inst_emulator_up.get()) {
   m_inst_emulator_up->SetBaton(this);
Index: lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
===
--- lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
+++ lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h
@@ -174,6 +174,14 @@
   dqo_target_queue = UINT16_MAX;
   dqo_target_queue = UINT16_MAX;
   dqo_priority = UINT16_MAX;
+  dqo_label_size = 0;
+  dqo_flags_size = 0;
+  dqo_serialnum_size = 0;
+  dqo_width_size = 0;
+  dqo_running_size = 0;
+  dqo_suspend_cnt_size = 0;
+  dqo_target_queue_size = 0;
+  dqo_priority_size = 0;
 }
 
 bool IsValid() { return dqo_version != UINT16_MAX; }
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===
--- 

[Lldb-commits] [PATCH] D130045: Implement better path matching in FileSpecList::FindFileIndex(...).

2022-07-20 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

The relative/absolute caching seems like a nice improvement. Splitting it into 
a separate patch would make it easier to review.

I'm slightly worried about the change to make the new "fuzzy" matching the 
default. While it makes sense for the breakpoints, I wouldn't generally expect 
`./a/b/c/main.cpp` to match `/build/a/b/c/main.cpp`, at least not unless my 
current working directory is `/build`. While doing the reproducers, the CWD was 
probably the hardest thing to get right consistently. I'm worried that this new 
matching is going to lead to really subtle bugs that are going to be tricky to 
figure out.

To make this more obvious and explicit: would it make sense to have another 
matches in FileSpec and have FindFileIndex take a `std::function` or 
`llvm::FunctionRef` with the desired matcher. Something like:

  static bool FuzzyMatch(const FileSpec , const FileSpec );



  size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec 
_spec,
 bool full, std::function matcher = FileSpec::Match) const {
...
  }




Comment at: lldb/include/lldb/Utility/FileSpec.h:408-409
   mutable bool m_is_resolved = false; ///< True if this path has been resolved.
+  mutable bool m_is_absolute = false; ///< True if this path is absolute.
+  mutable bool m_is_absolute_valid = false; ///< True if m_is_absolute is 
valid.
   Style m_style; ///< The syntax that this path uses (e.g. Windows / Posix)

Should this be an `llvm::Optional` instead or maybe even better an enum 
value with values `absolute, relative, unknown` or something? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130045/new/

https://reviews.llvm.org/D130045

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Kim Gräsman via Phabricator via lldb-commits
kimgr added a comment.

From a purely personal perspective, I'd prefer if this landed after the branch 
for llvm-15.

We try to co-release IWYU shortly after LLVM/Clang are released, to get a 
public API-compatible release out there. So it would be really nice if we 
didn't have to spend time working around AST changes while the clock is ticking 
to get a release out the door.

That said, I know we're just an out-of-tree project and the LLVM project as 
such doesn't make any promises (and shouldn't have to!). I just thought I'd 
raise the concern to see if anybody shares it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Raphael Isemann via Phabricator via lldb-commits
teemperor added a comment.

import-std-module test changes look good to me, thanks for fixing that up.

And yes, ideally the tests should never use any libc++ internal names (and LLDB 
should never print them for those tests). So I think not having those in the 
here is a step in the right direction.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D112374#3665989 , @mizvekov wrote:

> If anyone wants to take a look at the new changes to lldb tests, be my guest. 
> Otherwise I will try to land this again soon. It might well be that we figure 
> out some other in-tree user is affected, but I'd rather do that sooner than 
> later.

Please allow @teemperor some time to take a look at the llvm changes before 
landing this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [PATCH] D81471: [lldb] Add support for using integral const static data members in the expression evaluator

2022-07-20 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

This seems to cause issues when `var->getType() == const 
llvm::APFloatBase::roundingMode`. Triggered assertion `Assertion failed: 
(type->isIntegerType() && "Illegal type in IntegerLiteral"), function 
IntegerLiteral, file Expr.cpp, line 892` when doing the following:

1. `lldb -- ./bin/lldb a.out`
2. `b LookupLocalVariable`
3. step a couple of times until `decl_context` is declared
4. `p decl_context`

It looks ike the `dyn_cast` to `EnumType` fails and thus 
`qt.getUnqualifiedType()` which we pass into `IntegerLiteral::Create` remains 
an EnumType, which breaks the invariant

Investigating further...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81471/new/

https://reviews.llvm.org/D81471

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


[Lldb-commits] [PATCH] D130098: [LLDB][NFC][Reliability] Fix uninitialized variables from Coverity scan

2022-07-20 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.

The changes themselves look good, but please undo the formatting/unrelated 
changes before landing this. When I've been in a situation like this where I 
accidentally formatted unrelated things, I usually unstage my changes and use 
`git add -p` to interactively pick the chunks I want to stage.

There's a script called `git-clang-format` that allows you to format only the 
lines that have been changed: 
https://clang.llvm.org/docs/ClangFormat.html#git-integration. Once you've added 
it to your PATH, you can run `git clang-format` after staging your changes (but 
before committing).




Comment at: lldb/source/Commands/CommandObjectTarget.cpp:4640
 uint32_t m_line_start = 0;
-uint32_t m_line_end;
+uint32_t m_line_end = UINT_MAX;
 std::string m_file_name;

`LLDB_INVALID_LINE_NUMBER`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130098/new/

https://reviews.llvm.org/D130098

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov added a comment.

In D112374#3665249 , @sammccall wrote:

> I've seen plenty of (useful) out-of-tree tidy checks written by people fuzzy 
> on the difference between a Type and a TypeLoc, or what sugar is. Clang makes 
> it (almost) easy to write tools but hard to write robust tools.

I agree.

> All of this is to say I like this change & appreciate how willing you are to 
> help out-of-tree tools (which is best-effort), but I expect a lot of churn 
> downstream. (And LLVM has a clear policy that that's OK).

Thanks!

> (BTW, last time I landed such a change, investigating the LLDB tests was 
> indeed the most difficult part, and I'm not even on windows. Running a linux 
> VM of some sort might be your best bet, unfortunately)

Yeah I finally managed to build and run the tests on WSL2 running debian 
testing. The exact configuration used by the lldb-bot seems not to be supported 
there anymore.

I added the needed changes there, it was really only a change in expectation on 
the type printer.
These tests are so easy to break not only because they depend exactly on how 
clang prints types, but they also depend on how libc++ devs write internal 
implementation details.

If anyone wants to take a look at the new changes to lldb tests, be my guest. 
Otherwise I will try to land this again soon. It might well be that we figure 
out some other in-tree user is affected, but I'd rather do that sooner than 
later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [lldb] 360c111 - Use llvm::is_contained (NFC)

2022-07-20 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2022-07-20T09:09:19-07:00
New Revision: 360ce358c4c7e8591953ce9548d60c9410a6

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

LOG: Use llvm::is_contained (NFC)

Added: 


Modified: 
lld/MachO/Driver.cpp
lldb/source/API/SBBreakpoint.cpp
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
lldb/source/Target/TargetList.cpp
llvm/lib/Support/CommandLine.cpp
mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
mlir/lib/IR/AffineExpr.cpp
polly/include/polly/ScopInfo.h

Removed: 




diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 63a0e7f3a8434..f5c4e82c5b4c3 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -503,8 +503,7 @@ static bool markReexport(StringRef searchName, 
ArrayRef extensions) {
 if (auto *dylibFile = dyn_cast(file)) {
   StringRef filename = path::filename(dylibFile->getName());
   if (filename.consume_front(searchName) &&
-  (filename.empty() ||
-   find(extensions, filename) != extensions.end())) {
+  (filename.empty() || llvm::is_contained(extensions, filename))) {
 dylibFile->reexport = true;
 return true;
   }

diff  --git a/lldb/source/API/SBBreakpoint.cpp 
b/lldb/source/API/SBBreakpoint.cpp
index 5fe8f7fe05837..19b2a4376cf8a 100644
--- a/lldb/source/API/SBBreakpoint.cpp
+++ b/lldb/source/API/SBBreakpoint.cpp
@@ -835,8 +835,7 @@ class SBBreakpointListImpl {
 if (bkpt->GetTargetSP() != target_sp)
   return false;
 lldb::break_id_t bp_id = bkpt->GetID();
-if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) ==
-m_break_ids.end())
+if (!llvm::is_contained(m_break_ids, bp_id))
   return false;
 
 m_break_ids.push_back(bkpt->GetID());

diff  --git a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp 
b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
index 579ac6e36d0ba..4db7abe603d4c 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
@@ -396,15 +396,11 @@ bool RegisterInfoPOSIX_arm64::IsSVERegVG(unsigned reg) 
const {
 }
 
 bool RegisterInfoPOSIX_arm64::IsPAuthReg(unsigned reg) const {
-  return std::find(pauth_regnum_collection.begin(),
-   pauth_regnum_collection.end(),
-   reg) != pauth_regnum_collection.end();
+  return llvm::is_contained(pauth_regnum_collection, reg);
 }
 
 bool RegisterInfoPOSIX_arm64::IsMTEReg(unsigned reg) const {
-  return std::find(m_mte_regnum_collection.begin(),
-   m_mte_regnum_collection.end(),
-   reg) != m_mte_regnum_collection.end();
+  return llvm::is_contained(m_mte_regnum_collection, reg);
 }
 
 uint32_t RegisterInfoPOSIX_arm64::GetRegNumSVEZ0() const { return sve_z0; }

diff  --git a/lldb/source/Target/TargetList.cpp 
b/lldb/source/Target/TargetList.cpp
index 214e98ee91edb..829036976a219 100644
--- a/lldb/source/Target/TargetList.cpp
+++ b/lldb/source/Target/TargetList.cpp
@@ -509,8 +509,7 @@ uint32_t TargetList::GetIndexOfTarget(lldb::TargetSP 
target_sp) const {
 }
 
 void TargetList::AddTargetInternal(TargetSP target_sp, bool do_select) {
-  lldbassert(std::find(m_target_list.begin(), m_target_list.end(), target_sp) 
==
- m_target_list.end() &&
+  lldbassert(!llvm::is_contained(m_target_list, target_sp) &&
  "target already exists it the list");
   m_target_list.push_back(std::move(target_sp));
   if (do_select)

diff  --git a/llvm/lib/Support/CommandLine.cpp 
b/llvm/lib/Support/CommandLine.cpp
index e3df172ef1133..5e7d631651300 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -2382,7 +2382,7 @@ class CategorizedHelpPrinter : public HelpPrinter {
 for (size_t I = 0, E = Opts.size(); I != E; ++I) {
   Option *Opt = Opts[I].second;
   for (auto  : Opt->Categories) {
-assert(find(SortedCategories, Cat) != SortedCategories.end() &&
+assert(llvm::is_contained(SortedCategories, Cat) &&
"Option has an unregistered category");
 CategorizedOptions[Cat].push_back(Opt);
   }

diff  --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp 
b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
index d5e85519a09a0..0147da813dfb7 100644
--- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
@@ -84,7 +84,7 @@ void IntegerRangeAnalysis::visitOperation(
 auto result = v.dyn_cast();
 if (!result)
   return;
-assert(llvm::find(op->getResults(), result) != op->result_end());
+assert(llvm::is_contained(op->getResults(), result));
 
 LLVM_DEBUG(llvm::dbgs() << 

[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov updated this revision to Diff 446173.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

Files:
  clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/bindings/python/tests/cindex/test_type.py
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/ARCMigrate/ObjCMT.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/AST/ast-dump-using.cpp
  clang/test/AST/coroutine-locals-cleanup-exp-namespace.cpp
  clang/test/AST/coroutine-locals-cleanup.cpp
  clang/test/AST/float16.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  clang/test/Analysis/analyzer-display-progress.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/blocks.mm
  clang/test/Analysis/bug_hash_test.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp
  clang/test/Analysis/initializers-cfg-output.cpp
  clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
  clang/test/Analysis/lambdas.cpp
  clang/test/Analysis/lifetime-cfg-output.cpp
  

[Lldb-commits] [PATCH] D130054: [trace][intel pt] Introduce wall clock time for each trace item

2022-07-20 Thread Jakob Johnson via Phabricator via lldb-commits
jj10306 requested changes to this revision.
jj10306 added inline comments.



Comment at: lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp:288
 
+decoded_thread.NotifyTsc(execution.thread_execution.GetLowestKnownTSC());
 decoded_thread.NotifyCPU(execution.thread_execution.cpu_id);

if we have both a start and end TSC, shouldn't we emit the start here (like 
you're doing) and then after decoding all the instructions we should also emit 
the the end TSC?



Comment at: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp:100-103
+// This is the last TSC range, so we have to extrapolate. In this case, we
+// assume that each instruction took one TSC, which is what an instruction
+// would take if no parallelism is achieved and the frequency multiplier
+// is 1.

Is this correct?
I don't see an issue with choosing a 1 TSC per instruction as a heuristic in 
this case, but we should be cautious not to explain this heuristic as being 
tied to any "expected" performance of the hardware because there are way too 
many variables that influence IPC like differences in workload, 
microarchitecture (speculative execution/branch prediction implementation, 
vector units, super scalar, etc), etc not to mention the difference b/t TSC and 
CPU cycles (like you mentioned).



Comment at: lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp:105
+return m_tsc_conversion->ToNanosFloat(lowest_nanos,
+  range->tsc + items_since_last_tsc);
+  }

Won't our interpolation calculation be messed up since `items_since_last_tsc` 
will be counting all trace errors, events, etc and not just the 
instructions/events that we want to assign a timestamp to and thus should be 
part of this calculation?

I'm thinking of a case like below :
i - instruction, e - error

`tsc, cpu_change, i, e, e, e, tsc`
 in this case the items_since last_tsc would be 5 even though there is only 1 
instruction.

i guess this brings up a more general question around how timestamps should be 
assigned. For example, in this case I see a couple different options:
1. What we are doing now where we assign all events timestamps
Pro: easy implementation
Con: visualization may be weird bc timestamps are being influenced by events 
(ie errors) that users of the visualization don't care or know about
2. Ignore errors but treat all instructions and events the same (ie 
instructions and events get timestamps)
3. Ignore errors and treat instructions and events differently (ie instructions 
are the only things that contribute to `items_since_last_tsc`) and then events 
are simply assigned the same timestamp as an instruction

We can discuss this in more depth offline.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130054/new/

https://reviews.llvm.org/D130054

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Sam McCall via Phabricator via lldb-commits
sammccall added a comment.

In D112374#3657640 , @mizvekov wrote:

> In general, I would not expect external tools to care about the shape of the 
> AST. I would expect the type API would be used in a way where we ignore a 
> type sugar node we have no reason to acknowledge.
> Ie you query if some type is a (possible sugar to) X, and you would either 
> get X or nothing. The type sugar over it would just be skipped over and you 
> would have no reason to know what was in there or what shape it had.

I'm afraid your expectations are wrong, and not by a little bit :-)

I totally agree this is the best way to the use the AST: understanding what you 
want to depend on and what groups of differences (e.g. sugar) to ignore, and 
writing code that expresses that intent.

However this is empirically not how lots of downstream (and plenty of in-tree) 
code is written, because:

- it requires a deep understanding of the "philosophy" of the AST to understand 
where extensions are possible in future
- many people write AST traversals using matchers, which constrains and 
obscures exactly what's being matched
- many people write AST trawling code based on AST dumps of examples, rather 
than a first-principles approach
- it is difficult and tedious to test
- people are often only as careful as they're incentivized to be

I've seen plenty of (useful) out-of-tree tidy checks written by people fuzzy on 
the difference between a Type and a TypeLoc, or what sugar is. Clang makes it 
(almost) easy to write tools but hard to write robust tools.

All of this is to say I like this change & appreciate how willing you are to 
help out-of-tree tools (which is best-effort), but I expect a lot of churn 
downstream. (And LLVM has a clear policy that that's OK).

(BTW, last time I landed such a change, investigating the LLDB tests was indeed 
the most difficult part, and I'm not even on windows. Running a linux VM of 
some sort might be your best bet, unfortunately)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [PATCH] D129489: [lldb][AArch64] Add support for memory tags in core files

2022-07-20 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> You mean "memory read  --show-tags"? The details 
> are tested on live processes already but a simple smoke test wouldn't hurt, 
> I'll do that.

I checked and to include the memory contents takes the core file from 20k to 
300 something k. This isn't the end of the world but thinking about it, the 
code that powers "memory read --show-tags" is built on top of the stuff that's 
already tested here.

And that show tags code is tested via unit tests and live processes elsewhere, 
so I don't think we need anything for it here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129489/new/

https://reviews.llvm.org/D129489

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


[Lldb-commits] [PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-20 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov added a comment.

@JDevlieghere @teemperor ping

Can you please verify that everything works with LLDB, we just changed how 
those types are printed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374

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


[Lldb-commits] [PATCH] D129489: [lldb][AArch64] Add support for memory tags in core files

2022-07-20 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 446100.
DavidSpickett marked an inline comment as done.
DavidSpickett added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129489/new/

https://reviews.llvm.org/D129489

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
  
lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
  lldb/test/API/linux/aarch64/mte_core_file/core.mte
  lldb/test/API/linux/aarch64/mte_core_file/core.nomte
  lldb/test/API/linux/aarch64/mte_core_file/main.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/BinaryFormat/ELF.h

Index: llvm/include/llvm/BinaryFormat/ELF.h
===
--- llvm/include/llvm/BinaryFormat/ELF.h
+++ llvm/include/llvm/BinaryFormat/ELF.h
@@ -1366,6 +1366,8 @@
   // These all contain stack unwind tables.
   PT_ARM_EXIDX = 0x7001,
   PT_ARM_UNWIND = 0x7001,
+  // MTE memory tag segment type
+  PT_AARCH64_MEMTAG_MTE = 0x7002,
 
   // MIPS program header types.
   PT_MIPS_REGINFO = 0x7000,  // Register usage information.
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -289,6 +289,8 @@
 locations. This prevents us reading locations multiple times, or not
 writing out new values if the addresses have different non-address bits.
 
+* LLDB now supports reading memory tags from AArch64 Linux core files.
+
 Changes to Sanitizers
 -
 
Index: lldb/test/API/linux/aarch64/mte_core_file/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/mte_core_file/main.c
@@ -0,0 +1,78 @@
+// Program to generate core files to test MTE tag features.
+//
+// This file uses ACLE intrinsics as detailed in:
+// https://developer.arm.com/documentation/101028/0012/10--Memory-tagging-intrinsics?lang=en
+//
+// Compile with:
+//  -march=armv8.5-a+memtag -g main.c -o a.out.mte
+//  -march=armv8.5-a+memtag -g main.c -DNO_MTE -o a.out.nomte
+//
+// /proc/self/coredump_filter was set to 2 when the core files were made.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int main(int argc, char const *argv[]) {
+#ifdef NO_MTE
+  *(char *)(0) = 0;
+#endif
+
+  if (prctl(PR_SET_TAGGED_ADDR_CTRL,
+PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC |
+// Allow all tags to be generated by the addg
+// instruction __arm_mte_increment_tag produces.
+(0x << PR_MTE_TAG_SHIFT),
+0, 0, 0)) {
+return 1;
+  }
+
+  size_t page_size = sysconf(_SC_PAGESIZE);
+  char *mte_buf = mmap(0, page_size, PROT_READ | PROT_WRITE | PROT_MTE,
+   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  if (!mte_buf)
+return 1;
+
+  printf("mte_buf: %p\n", mte_buf);
+
+  // Allocate some untagged memory before the tagged memory.
+  char *buf = mmap(0, page_size, PROT_READ | PROT_WRITE,
+   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  if (!buf)
+return 1;
+
+  printf("buf: %p\n", buf);
+
+  // This write means that the memory for buf is included in the corefile.
+  // So we can read from the end of it into mte_buf during the test.
+  *buf = 1;
+
+  // These must be next to each other for the tests to work.
+  // 
+  // mte_buf
+  // buf
+  // 
+  if ((mte_buf - buf) != page_size) {
+return 1;
+  }
+
+  // Set incrementing tags until end of the page.
+  char *tagged_ptr = mte_buf;
+  // This ignores tag bits when subtracting the addresses.
+  while (__arm_mte_ptrdiff(tagged_ptr, mte_buf) < page_size) {
+// Set the allocation tag for this location.
+__arm_mte_set_tag(tagged_ptr);
+// + 16 for 16 byte granules.
+// Earlier we allowed all tag values, so this will give us an
+// incrementing pattern 0-0xF wrapping back to 0.
+tagged_ptr = __arm_mte_increment_tag(tagged_ptr + 16, 1);
+  }
+
+  // Will fault because logical tag 0 != allocation tag 1.
+  *(mte_buf + 16) = 1;
+
+  return 0;
+}
Index: lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/mte_core_file/TestAArch64LinuxMTEMemoryTagCoreFile.py
@@ -0,0 +1,170 @@
+"""
+Test that memory tagging features work with Linux core files.
+"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class AArch64LinuxMTEMemoryTagCoreFileTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+NO_DEBUG_INFO_TESTCASE = True
+
+MTE_BUF_ADDR = hex(0x82c74000)
+BUF_ADDR = hex(0x82c73000)
+
+@skipIfLLVMTargetMissing("AArch64")
+def 

[Lldb-commits] [PATCH] D129487: [lldb][AArch64] Add UnpackTagsFromCoreFileSegment to MemoryTagManager

2022-07-20 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 446099.
DavidSpickett added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129487/new/

https://reviews.llvm.org/D129487

Files:
  lldb/include/lldb/Target/MemoryTagManager.h
  lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
  lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
  lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp

Index: lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
===
--- lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
+++ lldb/unittests/Process/Utility/MemoryTagManagerAArch64MTETest.cpp
@@ -80,6 +80,72 @@
   ASSERT_THAT(expected, testing::ContainerEq(*packed));
 }
 
+TEST(MemoryTagManagerAArch64MTETest, UnpackTagsFromCoreFileSegment) {
+  MemoryTagManagerAArch64MTE manager;
+  // This is our fake segment data where tags are compressed as 2 4 bit tags
+  // per byte.
+  std::vector tags_data;
+  MemoryTagManager::CoreReaderFn reader =
+  [_data](lldb::offset_t offset, size_t length, void *dst) {
+std::memcpy(dst, tags_data.data() + offset, length);
+return length;
+  };
+
+  // Zero length is ok.
+  std::vector tags =
+  manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 0, 0);
+  ASSERT_EQ(tags.size(), (size_t)0);
+
+  // In the simplest case we read 2 tags which are in the same byte.
+  tags_data.push_back(0x21);
+  // The least significant bits are the first tag in memory.
+  std::vector expected{1, 2};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 0, 32);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // If we read just one then it will have to trim off the second one.
+  expected = std::vector{1};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 0, 16);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // If we read the second tag only then the first one must be trimmed.
+  expected = std::vector{2};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 16, 16);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // This trimming logic applies if you read a larger set of tags.
+  tags_data = std::vector{0x21, 0x43, 0x65, 0x87};
+
+  // Trailing tag should be trimmed.
+  expected = std::vector{1, 2, 3};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 0, 48);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // Leading tag should be trimmed.
+  expected = std::vector{2, 3, 4};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 16, 48);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // Leading and trailing trimmmed.
+  expected = std::vector{2, 3, 4, 5};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 0, 16, 64);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // The address given is an offset into the whole file so the address requested
+  // from the reader should be beyond that.
+  tags_data = std::vector{0xFF, 0xFF, 0x21, 0x43, 0x65, 0x87};
+  expected = std::vector{1, 2};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 0, 2, 0, 32);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+
+  // addr is a virtual address that we expect to be >= the tag segment's
+  // starting virtual address. So again an offset must be made from the
+  // difference.
+  expected = std::vector{3, 4};
+  tags = manager.UnpackTagsFromCoreFileSegment(reader, 32, 2, 64, 32);
+  ASSERT_THAT(expected, testing::ContainerEq(tags));
+}
+
 TEST(MemoryTagManagerAArch64MTETest, GetLogicalTag) {
   MemoryTagManagerAArch64MTE manager;
 
Index: lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
===
--- lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
+++ lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.h
@@ -44,6 +44,12 @@
   UnpackTagsData(const std::vector ,
  size_t granules = 0) const override;
 
+  std::vector
+  UnpackTagsFromCoreFileSegment(CoreReaderFn reader,
+lldb::addr_t tag_segment_virtual_address,
+lldb::addr_t tag_segment_data_address,
+lldb::addr_t addr, size_t len) const override;
+
   llvm::Expected>
   PackTags(const std::vector ) const override;
 
Index: lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
===
--- lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
+++ lldb/source/Plugins/Process/Utility/MemoryTagManagerAArch64MTE.cpp
@@ -247,6 +247,70 @@
   return unpacked;
 }
 
+std::vector
+MemoryTagManagerAArch64MTE::UnpackTagsFromCoreFileSegment(
+CoreReaderFn reader, lldb::addr_t tag_segment_virtual_address,
+lldb::addr_t tag_segment_data_address,