[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread Luka Markušić via Phabricator via lldb-commits
mark2185 added a comment.

In D136465#3884047 , @clayborg wrote:

> Looks ok to me. I don't do Android stuff on a daily basis. As long as the old 
> way of connecting still works I think this is ok.

Great! I'd just like to note that I do not have commit access, per the guide's 
instructions .

> It would be great to get more stuff in the Android remove platform connection 
> working at some point. Users still have to manually install things and a lot 
> of the work gets done by the Android Studio IDE kind of like Xcode does. I 
> would love to us add some features in the future:
>
> - allow a lldb_private::Target to have an application bundle FileSpec, which 
> could be pointed to a .apk file for Android and a .ipa file for iOS
> - Implement PlatformAndroid::LaunchProcess
>   - implement "Status PlatformAndroid::Install(const FileSpec , const 
> FileSpec )" and handle APK files from target by doing "adb install" if 
> needed
>   - Have PlatformAndroid::LaunchProcess do everything that is needed to debug 
> the app
> - start lldb-server for the new process via the connect to the 
> "lldb-server platform" process
> - forward any ports needed
>
> It would be great at some point to be able to do something like:
>
>   (lldb) platform select remote-android
>   (lldb) platform connect ...
>   (lldb) target create --app-bundle /path/to/foo.apk
>   (lldb) run
>
> And have PlatformAndroid take care of everything for us.

That does sound pretty useful, and even Android Studio would benefit from it 
since currently it just pushes a shell script that launches the `lldb-server`. 
I'll see what I can do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

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


[Lldb-commits] [PATCH] D136650: Add a check for TypeSystem use-after-free problems

2022-10-25 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/source/Symbol/CompilerType.cpp:35
+  bool unused;
+  if (GetTypeSystemGraveyard().Lookup(m_type_system, unused)) {
+lldbassert(false && "CompilerType belongs to deleted Typesystem");

hawkinsw wrote:
> I am sorry if this is obvious, but is `CompilerType` used in a multithreaded 
> environment? So, is there a possibility that we could pass the check on line 
> 32 but become invalid by the use of `m_type_system` here and fall victim to 
> an attempt (in `Lookup`, perhaps?) to dereference a `NULL` pointer? Again, I 
> am sorry if that is a stupid question!
Yes, CompilerType could be used on any thread and this will not catch a 
use-after-free if the TypeSystem is deleted between the IsValid check and its 
use.

A solution would be to store a TypeSystemSP/WP in CompilerType, but I'm 
expecting this to be rather expensive. The intention of this patch is as a 
bug-finding tool. It's not intended to make holding on to CompilerType objects 
safe. That said, I'm open to explore ideas for how to efficiently make this 
safe in a future patch.


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

https://reviews.llvm.org/D136650

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


[Lldb-commits] [PATCH] D136650: Add a check for TypeSystem use-after-free problems

2022-10-25 Thread Will Hawkins via Phabricator via lldb-commits
hawkinsw added a comment.

There are *so* many reasons that I love this patch.

First and foremost: I am a professor of computer science at University of 
Cincinnati and teaching Programming Languages this semester and I am about to 
teach *this very technique* for protecting against use-after-free errors. 
Having seen this patch I now have a great example of where it is used in real 
life! So, thank you!

Second, I have left some comments but please take what I said with a grain of 
salt. I hope that it is helpful and not a waste of time.

Thank you!
Will




Comment at: lldb/source/Symbol/CompilerType.cpp:35
+  bool unused;
+  if (GetTypeSystemGraveyard().Lookup(m_type_system, unused)) {
+lldbassert(false && "CompilerType belongs to deleted Typesystem");

I am sorry if this is obvious, but is `CompilerType` used in a multithreaded 
environment? So, is there a possibility that we could pass the check on line 32 
but become invalid by the use of `m_type_system` here and fall victim to an 
attempt (in `Lookup`, perhaps?) to dereference a `NULL` pointer? Again, I am 
sorry if that is a stupid question!



Comment at: lldb/source/Symbol/CompilerType.cpp:36
+  if (GetTypeSystemGraveyard().Lookup(m_type_system, unused)) {
+lldbassert(false && "CompilerType belongs to deleted Typesystem");
+return false;

I know that this is a nit, but should we write `TypeSystem`?



Comment at: lldb/source/Symbol/TypeSystem.cpp:22
+  // Intentionally leaked to avoid C++ destructor ordering issue.
+  static TypeSystemSet *g_typesystem_graveyard = new TypeSystemSet();
+  return *g_typesystem_graveyard;

I spent *way* too long researching to make sure that this initialization is 
thread safe and wanted to drop a link here in case anyone is wondering the same 
thing:

[C++ standard: stmt.dcl para 3, sentence 
3](http://eel.is/c++draft/stmt.dcl#3.sentence-3)


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

https://reviews.llvm.org/D136650

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


[Lldb-commits] [PATCH] D136177: [lldb-vscode] Send Statistics Dump in terminated event

2022-10-25 Thread Wanyi Ye via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
kusmour marked 3 inline comments as done.
Closed by commit rGc8a26f8c6de3: [lldb-vscode] Send Statistics Dump in 
terminated event (authored by kusmour).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136177

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/terminated-event/Makefile
  lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
  lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
  lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
  lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -204,7 +204,7 @@
 g_vsc.sent_terminated_event = true;
 g_vsc.RunTerminateCommands();
 // Send a "terminated" event
-llvm::json::Object event(CreateEventObject("terminated"));
+llvm::json::Object event(CreateTerminatedEventObject());
 g_vsc.SendJSON(llvm::json::Value(std::move(event)));
   }
 }
Index: lldb/tools/lldb-vscode/JSONUtils.h
===
--- lldb/tools/lldb-vscode/JSONUtils.h
+++ lldb/tools/lldb-vscode/JSONUtils.h
@@ -485,6 +485,12 @@
   llvm::StringRef debug_adaptor_path,
   llvm::StringRef comm_file);
 
+/// Create a "Terminated" JSON object that contains statistics
+///
+/// \return
+/// A body JSON object with debug info and breakpoint info
+llvm::json::Object CreateTerminatedEventObject();
+
 /// Convert a given JSON object to a string.
 std::string JSONToString(const llvm::json::Value );
 
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -19,6 +19,7 @@
 #include "lldb/API/SBBreakpoint.h"
 #include "lldb/API/SBBreakpointLocation.h"
 #include "lldb/API/SBDeclaration.h"
+#include "lldb/API/SBStructuredData.h"
 #include "lldb/API/SBValue.h"
 #include "lldb/Host/PosixApi.h"
 
@@ -1139,6 +1140,21 @@
   return reverse_request;
 }
 
+llvm::json::Object CreateTerminatedEventObject() {
+  llvm::json::Object event(CreateEventObject("terminated"));
+  lldb::SBStructuredData statistics = g_vsc.target.GetStatistics();
+  bool is_dictionary =
+  statistics.GetType() == lldb::eStructuredDataTypeDictionary;
+  if (!is_dictionary) {
+return event;
+  }
+
+  lldb::SBStream stats_stream;
+  statistics.GetAsJSON(stats_stream);
+  event.try_emplace("statistics", llvm::json::fixUTF8(stats_stream.GetData()));
+  return event;
+}
+
 std::string JSONToString(const llvm::json::Value ) {
   std::string data;
   llvm::raw_string_ostream os(data);
Index: lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/main.cpp
@@ -0,0 +1,8 @@
+#include 
+#include "foo.h"
+
+int main(int argc, char const *argv[]) {
+  std::cout << "Hello World!" << std::endl; // main breakpoint 1
+  foo();
+  return 0;
+}
Index: lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/foo.h
@@ -0,0 +1 @@
+int foo();
Index: lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/foo.cpp
@@ -0,0 +1,3 @@
+int foo() {
+return 12;
+}
Index: lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/terminated-event/TestVSCode_terminatedEvent.py
@@ -0,0 +1,60 @@
+"""
+Test lldb-vscode terminated event
+"""
+
+import vscode
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+import lldbvscode_testcase
+import re
+import json
+
+class TestVSCode_terminatedEvent(lldbvscode_testcase.VSCodeTestCaseBase):
+
+@skipIfWindows
+@skipIfRemote
+def test_terminated_event(self):
+'''
+Terminated Event
+Now contains the statistics of a debug session:
+metatdata:
+totalDebugInfoByteSize > 0
+totalDebugInfoEnabled > 0
+

[Lldb-commits] [lldb] c8a26f8 - [lldb-vscode] Send Statistics Dump in terminated event

2022-10-25 Thread Wanyi Ye via lldb-commits

Author: Wanyi Ye
Date: 2022-10-25T18:47:29-07:00
New Revision: c8a26f8c6de30dbd814546f02e4c89a4fcb2b4ef

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

LOG: [lldb-vscode] Send Statistics Dump in terminated event

This patch will gather debug info & breakpoint info from the statistics dump 
and send to DAP in terminated event.

We will return full contents of statistics dump (`SBTarget.GetStatistics()`) as 
a JSON string. So that every time a new field being added, we will be able to 
capture them from DAP log without changing lldb-vscode.

All the info above will be append to `statistics` field in the terminated event

Test Plan

Debugged a simple hello world program from VSCode. Exit debug session in two 
ways: 1) run to program exit; 2) user initiated debug session end (quit 
debugging before program exit).
Check DAP log and see both debug sessions have statistics returned in 
terminated event.

Here's an example when debugging the test program:

```

[Lldb-commits] [PATCH] D136565: [clang] Instantiate alias templates with sugar

2022-10-25 Thread Matheus Izvekov via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c44c91ad980: [clang] Instantiate alias templates with sugar 
(authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136565

Files:
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/test/Misc/diag-template-diffing.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  
lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
  
lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py

Index: lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr/TestWeakPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::weak_ptr",
  result_summary="3 strong=1 weak=2",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="int", result_value="3")
-self.expect_expr("*w.lock() = 5", result_type="int", result_value="5")
-self.expect_expr("*w.lock()", result_type="int", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="3")
+self.expect_expr("*w.lock() = 5", result_type="element_type", result_value="5")
+self.expect_expr("*w.lock()", result_type="element_type", result_value="5")
 self.expect_expr("w.use_count()", result_type="long", result_value="1")
 self.expect("expr w.reset()")
 self.expect_expr("w.use_count()", result_type="long", result_value="0")
Index: lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/weak_ptr-dbg-info-content/TestDbgInfoContentWeakPtrFromStdModule.py
@@ -23,7 +23,7 @@
 self.expect_expr("w",
  result_type="std::weak_ptr",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*w.lock()", result_type="Foo")
+self.expect_expr("*w.lock()", result_type="element_type")
 self.expect_expr("w.lock()->a", result_type="int", result_value="3")
 self.expect_expr("w.lock()->a = 5",
  result_type="int",
Index: lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
===
--- lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
+++ lldb/test/API/commands/expression/import-std-module/shared_ptr/TestSharedPtrFromStdModule.py
@@ -24,9 +24,9 @@
  result_type="std::shared_ptr",
  result_summary="3 strong=1 weak=1",
  result_children=[ValueCheck(name="__ptr_")])
-self.expect_expr("*s", result_type="int", result_value="3")
-self.expect_expr("*s = 5", result_type="int", result_value="5")
-self.expect_expr("*s", result_type="int", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="3")
+self.expect_expr("*s = 5", result_type="element_type", result_value="5")
+self.expect_expr("*s", result_type="element_type", result_value="5")
 self.expect_expr("(bool)s", result_type="bool", result_value="true")
 self.expect("expr s.reset()")
 self.expect_expr("(bool)s", result_type="bool", result_value="false")
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -437,7 +437,7 @@
 
   template class X> struct A {
 template N> struct B; // expected-note 2{{here}}
-template struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'type-parameter-0-0 *')}}
+template  struct B {}; // expected-error {{non-type template argument specializes a template parameter with dependent type 'Y' (aka 'T *')}}

[Lldb-commits] [PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

2022-10-25 Thread Matheus Izvekov via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4c2a3c65684: [clang] Implement sugared substitution changes 
to infrastructure (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp

Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext , QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext , QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto  : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder , CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder ,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder ,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder ,
   FunctionProtoTypeLoc TL,
@@ -1285,9 +1293,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument ,
-   Decl *AssociatedDecl, unsigned Index) {
+   Decl *AssociatedDecl, unsigned Index,
+   bool Final) {
 return getSema().Context.getSubstTemplateTemplateParmPack(
-ArgPack, AssociatedDecl, Index);
+ArgPack, AssociatedDecl, Index, Final);
   }
 
   /// Build a new compound statement.
@@ -4152,9 +4161,13 @@
 

[Lldb-commits] [PATCH] D134604: [clang] Implement sugared substitution changes to infrastructure

2022-10-25 Thread Matheus Izvekov via Phabricator via lldb-commits
mizvekov updated this revision to Diff 470660.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134604

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/test/SemaTemplate/nested-name-spec-template.cpp

Index: clang/test/SemaTemplate/nested-name-spec-template.cpp
===
--- clang/test/SemaTemplate/nested-name-spec-template.cpp
+++ clang/test/SemaTemplate/nested-name-spec-template.cpp
@@ -147,3 +147,10 @@
 
   template void f(); // expected-note{{in instantiation of}}
 }
+
+namespace sugared_template_instantiation {
+  // Test that we ignore local qualifiers.
+  template  struct A {};
+  struct B { typedef int type1; };
+  typedef A type2;
+} // namespace sugated_template_instantiation
Index: clang/lib/Sema/TypeLocBuilder.h
===
--- clang/lib/Sema/TypeLocBuilder.h
+++ clang/lib/Sema/TypeLocBuilder.h
@@ -64,6 +64,10 @@
   /// must be empty for this to work.
   void pushFullCopy(TypeLoc L);
 
+  /// Pushes 'T' with all locations pointing to 'Loc'.
+  /// The builder must be empty for this to work.
+  void pushTrivial(ASTContext , QualType T, SourceLocation Loc);
+
   /// Pushes space for a typespec TypeLoc.  Invalidates any TypeLocs
   /// previously retrieved from this builder.
   TypeSpecTypeLoc pushTypeSpec(QualType T) {
Index: clang/lib/Sema/TypeLocBuilder.cpp
===
--- clang/lib/Sema/TypeLocBuilder.cpp
+++ clang/lib/Sema/TypeLocBuilder.cpp
@@ -41,6 +41,29 @@
   }
 }
 
+void TypeLocBuilder::pushTrivial(ASTContext , QualType T,
+ SourceLocation Loc) {
+  auto L = TypeLoc(T, nullptr);
+  reserve(L.getFullDataSize());
+
+  SmallVector TypeLocs;
+  for (auto CurTL = L; CurTL; CurTL = CurTL.getNextTypeLoc())
+TypeLocs.push_back(CurTL);
+
+  for (const auto  : llvm::reverse(TypeLocs)) {
+switch (CurTL.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+  case TypeLoc::CLASS: {   \
+auto NewTL = push(CurTL.getType());  \
+NewTL.initializeLocal(Context, Loc);   \
+break; \
+  }
+#include "clang/AST/TypeLocNodes.def"
+}
+  }
+}
+
 void TypeLocBuilder::grow(size_t NewCapacity) {
   assert(NewCapacity > Capacity);
 
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -636,6 +636,14 @@
   QualType Transform##CLASS##Type(TypeLocBuilder , CLASS##TypeLoc T);
 #include "clang/AST/TypeLocNodes.def"
 
+  QualType TransformTemplateTypeParmType(TypeLocBuilder ,
+ TemplateTypeParmTypeLoc TL,
+ bool SuppressObjCLifetime);
+  QualType
+  TransformSubstTemplateTypeParmPackType(TypeLocBuilder ,
+ SubstTemplateTypeParmPackTypeLoc TL,
+ bool SuppressObjCLifetime);
+
   template
   QualType TransformFunctionProtoType(TypeLocBuilder ,
   FunctionProtoTypeLoc TL,
@@ -1285,9 +1293,10 @@
   /// template name. Subclasses may override this routine to provide different
   /// behavior.
   TemplateName RebuildTemplateName(const TemplateArgument ,
-   Decl *AssociatedDecl, unsigned Index) {
+   Decl *AssociatedDecl, unsigned Index,
+   bool Final) {
 return getSema().Context.getSubstTemplateTemplateParmPack(
-ArgPack, AssociatedDecl, Index);
+ArgPack, AssociatedDecl, Index, Final);
   }
 
   /// Build a new compound statement.
@@ -4152,9 +4161,13 @@
 NestedNameSpecifierLoc NNS, QualType ObjectType,
 NamedDecl *FirstQualifierInScope) {
   SmallVector Qualifiers;
-  for (NestedNameSpecifierLoc Qualifier = NNS; 

[Lldb-commits] [PATCH] D136719: change debugserver to return an empty platform name for unknown platforms, instead of crashing

2022-10-25 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda updated this revision to Diff 470652.
jasonmolenda added a comment.

Update patch to also update the loop in HandlePacket_qProcessInfo() which 
iterates over the binaries, looking for a binary that declares its platform.  
The first binary in the list is dyld, and this binary does not have a platform, 
but the loop would get back an empty string and terminate its search.  Update 
this to recognize an empty platform name and continue searching, to preserve 
its original intended behavior for `qProcessInfo`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136719

Files:
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm
  lldb/tools/debugserver/source/RNBRemote.cpp


Index: lldb/tools/debugserver/source/RNBRemote.cpp
===
--- lldb/tools/debugserver/source/RNBRemote.cpp
+++ lldb/tools/debugserver/source/RNBRemote.cpp
@@ -6261,7 +6261,7 @@
 auto *platform =
 DNBGetDeploymentInfo(pid, is_executable, lc, load_command_addr,
  major_version, minor_version, patch_version);
-if (platform) {
+if (platform && *platform != '\0') {
   os_handled = true;
   rep << "ostype:" << platform << ";";
   break;
Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -742,8 +742,12 @@
 return "bridgeos";
   case PLATFORM_DRIVERKIT:
 return "driverkit";
+  default:
+DNBLogError(
+"Unknown platform %u found for one binary, returning empty string",
+platform);
+return "";
   }
-  return nullptr;
 }
 
 static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {


Index: lldb/tools/debugserver/source/RNBRemote.cpp
===
--- lldb/tools/debugserver/source/RNBRemote.cpp
+++ lldb/tools/debugserver/source/RNBRemote.cpp
@@ -6261,7 +6261,7 @@
 auto *platform =
 DNBGetDeploymentInfo(pid, is_executable, lc, load_command_addr,
  major_version, minor_version, patch_version);
-if (platform) {
+if (platform && *platform != '\0') {
   os_handled = true;
   rep << "ostype:" << platform << ";";
   break;
Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -742,8 +742,12 @@
 return "bridgeos";
   case PLATFORM_DRIVERKIT:
 return "driverkit";
+  default:
+DNBLogError(
+"Unknown platform %u found for one binary, returning empty string",
+platform);
+return "";
   }
-  return nullptr;
 }
 
 static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D136719: change debugserver to return an empty platform name for unknown platforms, instead of crashing

2022-10-25 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

Ah, one minute on this one.  Going over the testsuite, there's a change in 
behavior of TestMacCatalyst.py and I'm not positive if it's a bug or the test 
case being overly sensitive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136719

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


[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

Looks ok to me. I don't do Android stuff on a daily basis. As long as the old 
way of connecting still works I think this is ok.

It would be great to get more stuff in the Android remove platform connection 
working at some point. Users still have to manually install things and a lot of 
the work gets done by the Android Studio IDE kind of like Xcode does. I would 
love to us add some features in the future:

- allow a lldb_private::Target to have an application bundle FileSpec, which 
could be pointed to a .apk file for Android and a .ipa file for iOS
- Implement PlatformAndroid::LaunchProcess
  - implement "Status PlatformAndroid::Install(const FileSpec , const 
FileSpec )" and handle APK files from target by doing "adb install" if 
needed
  - Have PlatformAndroid::LaunchProcess do everything that is needed to debug 
the app
- start lldb-server for the new process via the connect to the "lldb-server 
platform" process
- forward any ports needed

It would be great at some point to be able to do something like:

  (lldb) platform select remote-android
  (lldb) platform connect ...
  (lldb) target create --app-bundle /path/to/foo.apk
  (lldb) run

And have PlatformAndroid take care of everything for us.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

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


[Lldb-commits] [PATCH] D134991: [lldb] Add diagnostics

2022-10-25 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/lldb/include/lldb/Utility/Diagnostics.h:1
+//===-- Diagnostics.h ---*- C++ 
-*-===//
+//

There are two of these files:
```
lldb/include/lldb/Utility/Diagnostics.h
lldb/lldb/include/lldb/Utility/Diagnostics.h
```
Remove this one I assume?



Comment at: lldb/lldb/source/Utility/Diagnostics.cpp:1
+//===-- Diagnostics.cpp 
---===//
+//

Is "lldb/lldb/source/Utility/Diagnostics.cpp" the right directory? Seems wrong



Comment at: lldb/source/Utility/Diagnostics.cpp:1
+//===-- Diagnostics.cpp 
---===//
+//

Ah, this is the right lldb/source/Utility/Diagnostics.cpp file. Remove the 
previous lldb/lldb/source/Utility/Diagnostics.cpp incorrect pathed file.


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

https://reviews.llvm.org/D134991

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


[Lldb-commits] [PATCH] D136648: [lldb] Emit diagnostic events in the diagnostic dump

2022-10-25 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/include/lldb/Core/Debugger.h:431
+  /// Progress events will be delivered to any debuggers that have listeners
+  /// for the eBroadcastBitError.
+  ///

This comment seems wrong? The code below asserts and returns in 
PrivateReportDiagnostic(). Do we want to add a eBroadcastBitInfo?


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

https://reviews.llvm.org/D136648

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


[Lldb-commits] [PATCH] D136719: change debugserver to return an empty platform name for unknown platforms, instead of crashing

2022-10-25 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

debugserver is sometimes run in bringup environments, where debugserver doesn't 
yet recognize its platform code.  debugserver will crash shortly after when 
strlen() is run on the nullptr returned, creating a std::string.

Instead, have debugserver return an empty platform name back up to lldb.  lldb 
is in a better position to handle a triple with a missing component and surface 
an error message to the user, instead of having debugserver cease to be running.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136719

Files:
  lldb/tools/debugserver/source/MacOSX/MachProcess.mm


Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -743,7 +743,10 @@
   case PLATFORM_DRIVERKIT:
 return "driverkit";
   }
-  return nullptr;
+  DNBLogError(
+  "Unknown platform %u found for one binary, returning empty string",
+  platform);
+  return "";
 }
 
 static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {


Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -743,7 +743,10 @@
   case PLATFORM_DRIVERKIT:
 return "driverkit";
   }
-  return nullptr;
+  DNBLogError(
+  "Unknown platform %u found for one binary, returning empty string",
+  platform);
+  return "";
 }
 
 static bool mach_header_validity_test(uint32_t magic, uint32_t cputype) {
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D136697: Add formatting support for VSCode logpoints message

2022-10-25 Thread Greg Clayton via Phabricator via lldb-commits
clayborg requested changes to this revision.
clayborg added inline comments.
This revision now requires changes to proceed.



Comment at: 
lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py:52
 logMessage_prefix = "This is log message for { -- "
-# Trailing newline is needed for splitlines()
-logMessage = logMessage_prefix + "{i + 3}\n"
+logMessage = logMessage_prefix + "{i + 3}"
 [loop_breakpoint_id, post_loop_breakpoint_id] = 
self.set_source_breakpoints(

Are we now auto appending a newline if there isn't one? If so we need to test 
this functionality. We should append on if the string doesn't end with "\n" and 
not if it does?



Comment at: lldb/tools/lldb-vscode/BreakpointBase.cpp:47-52
+  while (!text.empty()) {
+if (text[0] != '\\') {
+  formatted.push_back(text[0]);
+  text = text.drop_front();
+  continue;
+}

Please use StringRef::find(char). Something like:

Please use StringRef::find_first_of(...) instead of iterating per character. 
Something like:

```
formatted.clear();
while (!text.empty()) {
  size_t backslash_pos = text.find_first_of('\\');
  if (backslash_pos = StringRef::npos) {
// No more backslash chars append the rest of the string
formatted += text.str();
return error;
  }
  // Append anything before the backslash character.
  if (backslash_pos > 0)
formatted += text.drop_front(backslash_pos).str();
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136697

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


[Lldb-commits] [lldb] 2098e2f - [trace][intel pt][simple] Fix errors after switching to libipt's top of tree

2022-10-25 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-10-25T14:34:27-07:00
New Revision: 2098e2f472578f793c565b669500dca454b4a608

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

LOG: [trace][intel pt][simple] Fix errors after switching to libipt's top of 
tree

These tests were being tested against a version of libipt from last
year. We just updated libipt to top of tree and many errors broke
because the new version of libipt emits more events than the older one,
which is fine.

`./bin/lldb-dotest -p TestTrace` passes

Added: 


Modified: 
lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py
lldb/test/API/commands/trace/TestTraceDumpInfo.py
lldb/test/API/commands/trace/TestTraceDumpInstructions.py
lldb/test/API/commands/trace/TestTraceEvents.py
lldb/test/API/commands/trace/TestTraceLoad.py
lldb/test/API/commands/trace/TestTraceStartStop.py

Removed: 




diff  --git a/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py 
b/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py
index d37920bc719b2..0a8b4f4d2a3dd 100644
--- a/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py
+++ b/lldb/test/API/commands/trace/TestTraceDumpFunctionCalls.py
@@ -11,15 +11,15 @@ def testDumpSimpleFunctionCalls(self):
 error=True, substrs=['error: no thread with index: "2"'])
 
   self.expect("thread trace dump function-calls 1 -j",
-
substrs=['[{"tracedSegments":[{"firstInstructionId":"1","lastInstructionId":"22"}]}]'])
+
substrs=['[{"tracedSegments":[{"firstInstructionId":"3","lastInstructionId":"26"}]}]'])
 
   self.expect("thread trace dump function-calls 1 -J",
 substrs=['''[
   {
 "tracedSegments": [
   {
-"firstInstructionId": "1",
-"lastInstructionId": "22"
+"firstInstructionId": "3",
+"lastInstructionId": "26"
   }
 ]
   }
@@ -30,7 +30,7 @@ def testDumpSimpleFunctionCalls(self):
 substrs=['''thread #1: tid = 3842849
 
 [call tree #0]
-a.out`main + 4 at main.cpp:2 to 4:0  [1, 22]'''])
+a.out`main + 4 at main.cpp:2 to 4:0  [3, 26]'''])
 
 def testFunctionCallsWithErrors(self):
   self.expect("trace load -v " +
@@ -104,43 +104,43 @@ def testInlineFunctionCalls(self):
   self.expect("c")
   self.expect("thread trace dump function-calls",
 substrs=['''[call tree #0]
-a.out`main + 8 at inline.cpp:15:7 to 16:14  [1, 5]
-  a.out`foo(int) at inline.cpp:8:16 to 9:15  [6, 13]
-a.out`foo(int) + 22 [inlined] mult(int, int) at inline.cpp:2:7 to 5:10  
[14, 21]
-  a.out`foo(int) + 49 at inline.cpp:9:15 to 12:1  [22, 26]
-a.out`main + 25 at inline.cpp:16:14 to 16:14  [27, 27]'''])
+a.out`main + 8 at inline.cpp:15:7 to 16:14  [2, 6]
+  a.out`foo(int) at inline.cpp:8:16 to 9:15  [7, 14]
+a.out`foo(int) + 22 [inlined] mult(int, int) at inline.cpp:2:7 to 5:10  
[15, 22]
+  a.out`foo(int) + 49 at inline.cpp:9:15 to 12:1  [23, 27]
+a.out`main + 25 at inline.cpp:16:14 to 16:14  [28, 28]'''])
 
   self.expect("thread trace dump function-calls -J",
 substrs=['''[
   {
 "tracedSegments": [
   {
-"firstInstructionId": "1",
-"lastInstructionId": "5",
+"firstInstructionId": "2",
+"lastInstructionId": "6",
 "nestedCall": {
   "tracedSegments": [
 {
-  "firstInstructionId": "6",
-  "lastInstructionId": "13",
+  "firstInstructionId": "7",
+  "lastInstructionId": "14",
   "nestedCall": {
 "tracedSegments": [
   {
-"firstInstructionId": "14",
-"lastInstructionId": "21"
+"firstInstructionId": "15",
+"lastInstructionId": "22"
   }
 ]
   }
 },
 {
-  "firstInstructionId": "22",
-  "lastInstructionId": "26"
+  "firstInstructionId": "23",
+  "lastInstructionId": "27"
 }
   ]
 }
   },
   {
-"firstInstructionId": "27",
-"lastInstructionId": "27"
+"firstInstructionId": "28",
+"lastInstructionId": "28"
   }
 ]
   }
@@ -157,9 +157,9 @@ def testIncompleteInlineFunctionCalls(self):
 substrs=['''[call tree #0]
 a.out`main
   a.out`foo(int)
-a.out`foo(int) + 36 [inlined] mult(int, int) + 14 at inline.cpp:4:5 to 
5:10  [1, 5]
-  a.out`foo(int) + 49 at inline.cpp:9:15 to 12:1  [6, 10]
-a.out`main + 25 at inline.cpp:16:14 to 16:14  [11, 11]'''])
+a.out`foo(int) + 36 [inlined] mult(int, int) + 14 at inline.cpp:4:5 to 
5:10  [2, 6]
+  a.out`foo(int) + 49 at inline.cpp:9:15 to 12:1  [7, 11]
+a.out`main + 25 at inline.cpp:16:14 to 16:14  

[Lldb-commits] [PATCH] D134378: [lldb] Support simplified template names

2022-10-25 Thread Arthur Eubanks via Phabricator via lldb-commits
aeubanks updated this revision to Diff 470617.
aeubanks added a comment.

revert breakpoint test change
we can leave that to a later change, so I think this change is ready to go


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134378

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/lang/cpp/complete-type-check/TestCppIsTypeComplete.py
  lldb/test/API/lang/cpp/unique-types2/Makefile
  lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py
  lldb/test/API/lang/cpp/unique-types2/main.cpp

Index: lldb/test/API/lang/cpp/unique-types2/main.cpp
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types2/main.cpp
@@ -0,0 +1,22 @@
+template  class Foo {
+  T t;
+};
+
+template  class FooPack {
+  T t;
+};
+
+int main() {
+  Foo t1;
+  Foo t2;
+  Foo> t3;
+
+  FooPack p1;
+  FooPack p2;
+  FooPack> p3;
+  FooPack t4;
+  FooPack t5;
+  FooPack t6;
+  FooPack t7;
+  // Set breakpoint here
+}
Index: lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py
@@ -0,0 +1,40 @@
+"""
+Test that we return only the requested template instantiation.
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+class UniqueTypesTestCase(TestBase):
+def do_test(self, debug_flags):
+"""Test that we only display the requested Foo instantiation, not all Foo instantiations."""
+self.build(dictionary=debug_flags)
+lldbutil.run_to_source_breakpoint(self, "// Set breakpoint here", lldb.SBFileSpec("main.cpp"))
+
+self.expect("image lookup -A -t 'Foo'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'Foo'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'Foo >'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'Foo'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True)
+
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack >'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"])
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True)
+self.expect("image lookup -A -t 'FooPack'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True)
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_simple_template_name(self):
+self.do_test(dict(CFLAGS_EXTRAS="-gsimple-template-names"))
+
+@skipIf(compiler=no_match("clang"))
+@skipIf(compiler_version=["<", "15.0"])
+def test_no_simple_template_name(self):
+self.do_test(dict(CFLAGS_EXTRAS="-gno-simple-template-names"))
+
Index: lldb/test/API/lang/cpp/unique-types2/Makefile
===
--- /dev/null
+++ lldb/test/API/lang/cpp/unique-types2/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: lldb/test/API/lang/cpp/complete-type-check/TestCppIsTypeComplete.py
===
--- lldb/test/API/lang/cpp/complete-type-check/TestCppIsTypeComplete.py
+++ lldb/test/API/lang/cpp/complete-type-check/TestCppIsTypeComplete.py
@@ -51,7 +51,7 @@
 # Record types without a defining declaration are not complete.
 self.assertPointeeIncomplete("FwdClass *", "fwd_class")
 self.assertPointeeIncomplete("FwdClassTypedef *", "fwd_class_typedef")
-self.assertPointeeIncomplete("FwdTemplateClass<> *", "fwd_template_class")
+self.assertPointeeIncomplete("FwdTemplateClass *", "fwd_template_class")
 
 # A pointer type is complete even when it points to an incomplete type.
 fwd_class_ptr = self.expect_expr("fwd_class", result_type="FwdClass *")
Index: 

[Lldb-commits] [lldb] 779a455 - Quick fix for previous commit; small code change before commit

2022-10-25 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2022-10-25T13:56:02-07:00
New Revision: 779a45515134a040006c17d8b85f91a4d9f810ed

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

LOG: Quick fix for previous commit; small code change before commit

Added: 


Modified: 
lldb/tools/debugserver/source/DNB.cpp

Removed: 




diff  --git a/lldb/tools/debugserver/source/DNB.cpp 
b/lldb/tools/debugserver/source/DNB.cpp
index 7c6fd4b0177b0..89f573d54bf97 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -1834,7 +1834,7 @@ bool DNBGetAddressingBits(uint32_t _bits) {
NULL, 0) != 0) {
   g_addressing_bits = 0;
 }
-  }
+  });
 
   addressing_bits = g_addressing_bits;
 



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


[Lldb-commits] [PATCH] D136620: Change how debugserver clears auth bits from pc/fp/sp/lr with thread_get_state on Darwin

2022-10-25 Thread Jason Molenda via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG256c16e8f4e4: Change debugserver to clear PAC auth bits 
manually (authored by jasonmolenda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136620

Files:
  lldb/tools/debugserver/source/DNB.cpp
  lldb/tools/debugserver/source/DNB.h
  lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
  lldb/tools/debugserver/source/RNBRemote.cpp

Index: lldb/tools/debugserver/source/RNBRemote.cpp
===
--- lldb/tools/debugserver/source/RNBRemote.cpp
+++ lldb/tools/debugserver/source/RNBRemote.cpp
@@ -4781,24 +4781,6 @@
   return g_host_cputype != 0;
 }
 
-static bool GetAddressingBits(uint32_t _bits) {
-  static uint32_t g_addressing_bits = 0;
-  static bool g_tried_addressing_bits_syscall = false;
-  if (g_tried_addressing_bits_syscall == false) {
-size_t len = sizeof (uint32_t);
-if (::sysctlbyname("machdep.virtual_address_size",
-  _addressing_bits, , NULL, 0) != 0) {
-  g_addressing_bits = 0;
-}
-  }
-  g_tried_addressing_bits_syscall = true;
-  addressing_bits = g_addressing_bits;
-  if (addressing_bits > 0)
-return true;
-  else
-return false;
-}
-
 rnb_err_t RNBRemote::HandlePacket_qHostInfo(const char *p) {
   std::ostringstream strm;
 
@@ -4812,7 +4794,7 @@
   }
 
   uint32_t addressing_bits = 0;
-  if (GetAddressingBits(addressing_bits)) {
+  if (DNBGetAddressingBits(addressing_bits)) {
 strm << "addressing_bits:" << std::dec << addressing_bits << ';';
   }
 
Index: lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
===
--- lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
+++ lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
@@ -94,11 +94,35 @@
 
 uint32_t DNBArchMachARM64::GetCPUType() { return CPU_TYPE_ARM64; }
 
+static uint64_t clear_pac_bits(uint64_t value) {
+  uint32_t addressing_bits = 0;
+  if (!DNBGetAddressingBits(addressing_bits))
+return value;
+
+// On arm64_32, no ptrauth bits to clear
+#if !defined(__LP64__)
+  return value;
+#endif
+
+  uint64_t mask = ((1ULL << addressing_bits) - 1);
+
+  // Normally PAC bit clearing needs to check b55 and either set the
+  // non-addressing bits, or clear them.  But the register values we
+  // get from thread_get_state on an arm64e process don't follow this
+  // convention?, at least when there's been a PAC auth failure in
+  // the inferior.
+  // Userland processes are always in low memory, so this
+  // hardcoding b55 == 0 PAC stripping behavior here.
+
+  return value & mask; // high bits cleared to 0
+}
+
 uint64_t DNBArchMachARM64::GetPC(uint64_t failValue) {
   // Get program counter
   if (GetGPRState(false) == KERN_SUCCESS)
-#if defined(__LP64__)
-return arm_thread_state64_get_pc(m_state.context.gpr);
+#if __has_feature(ptrauth_calls) && defined(__LP64__)
+return clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_pc));
 #else
 return m_state.context.gpr.__pc;
 #endif
@@ -128,8 +152,9 @@
 uint64_t DNBArchMachARM64::GetSP(uint64_t failValue) {
   // Get stack pointer
   if (GetGPRState(false) == KERN_SUCCESS)
-#if defined(__LP64__)
-return arm_thread_state64_get_sp(m_state.context.gpr);
+#if __has_feature(ptrauth_calls) && defined(__LP64__)
+return clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_sp));
 #else
 return m_state.context.gpr.__sp;
 #endif
@@ -150,16 +175,20 @@
   if (DNBLogEnabledForAny(LOG_THREAD)) {
 uint64_t *x = _state.context.gpr.__x[0];
 
-#if defined(__LP64__)
-uint64_t log_fp = arm_thread_state64_get_fp(m_state.context.gpr);
-uint64_t log_lr = arm_thread_state64_get_lr(m_state.context.gpr);
-uint64_t log_sp = arm_thread_state64_get_sp(m_state.context.gpr);
-uint64_t log_pc = arm_thread_state64_get_pc(m_state.context.gpr);
+#if __has_feature(ptrauth_calls) && defined(__LP64__)
+uint64_t log_fp = clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_fp));
+uint64_t log_lr = clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_lr));
+uint64_t log_sp = clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_sp));
+uint64_t log_pc = clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_pc));
 #else
-uint64_t log_fp = m_state.context.gpr.__fp;
-uint64_t log_lr = m_state.context.gpr.__lr;
-uint64_t log_sp = m_state.context.gpr.__sp;
-uint64_t log_pc = m_state.context.gpr.__pc;
+uint64_t log_fp = m_state.context.gpr.__fp;
+uint64_t log_lr = m_state.context.gpr.__lr;
+uint64_t log_sp = m_state.context.gpr.__sp;
+uint64_t log_pc = m_state.context.gpr.__pc;
 #endif
 DNBLogThreaded(
 

[Lldb-commits] [lldb] 256c16e - Change debugserver to clear PAC auth bits manually

2022-10-25 Thread Jason Molenda via lldb-commits

Author: Jason Molenda
Date: 2022-10-25T13:49:05-07:00
New Revision: 256c16e8f4e483ff19ed7096d3c41947a8a93144

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

LOG: Change debugserver to clear PAC auth bits manually

debugserver is currently using kernel supplied macros,
arm_thread_state64_get_{pc,fp,sp,lr} which can crash on an authorization
failure when the inferior has crashed with an invalid pc value, for
instance.  debugserver needs to be resistant to crashing in this
scenario, and we're merely clearing the bits, so do it with a bit
mask operation instead.

Differential Revision: https://reviews.llvm.org/D136620
rdar://98073271
rdar://100663221

Added: 


Modified: 
lldb/tools/debugserver/source/DNB.cpp
lldb/tools/debugserver/source/DNB.h
lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
lldb/tools/debugserver/source/RNBRemote.cpp

Removed: 




diff  --git a/lldb/tools/debugserver/source/DNB.cpp 
b/lldb/tools/debugserver/source/DNB.cpp
index ebb76074670b1..7c6fd4b0177b0 100644
--- a/lldb/tools/debugserver/source/DNB.cpp
+++ b/lldb/tools/debugserver/source/DNB.cpp
@@ -1824,3 +1824,19 @@ bool DNBDebugserverIsTranslated() {
 return false;
   return ret == 1;
 }
+
+bool DNBGetAddressingBits(uint32_t _bits) {
+  static uint32_t g_addressing_bits = 0;
+  static std::once_flag g_once_flag;
+  std::call_once(g_once_flag, [&](){
+size_t len = sizeof(uint32_t);
+if (::sysctlbyname("machdep.virtual_address_size", _addressing_bits, 
,
+   NULL, 0) != 0) {
+  g_addressing_bits = 0;
+}
+  }
+
+  addressing_bits = g_addressing_bits;
+
+  return addressing_bits > 0;
+}

diff  --git a/lldb/tools/debugserver/source/DNB.h 
b/lldb/tools/debugserver/source/DNB.h
index f29078ce6c145..b0ab37adad00c 100644
--- a/lldb/tools/debugserver/source/DNB.h
+++ b/lldb/tools/debugserver/source/DNB.h
@@ -245,4 +245,6 @@ std::string DNBGetMacCatalystVersionString();
 /// \return true if debugserver is running in translation
 /// (is an x86_64 process on arm64)
 bool DNBDebugserverIsTranslated();
+
+bool DNBGetAddressingBits(uint32_t _bits);
 #endif

diff  --git a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp 
b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
index fa4ba5f67263a..5a8a256948023 100644
--- a/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
+++ b/lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
@@ -94,11 +94,35 @@ DNBArchMachARM64::SoftwareBreakpointOpcode(nub_size_t 
byte_size) {
 
 uint32_t DNBArchMachARM64::GetCPUType() { return CPU_TYPE_ARM64; }
 
+static uint64_t clear_pac_bits(uint64_t value) {
+  uint32_t addressing_bits = 0;
+  if (!DNBGetAddressingBits(addressing_bits))
+return value;
+
+// On arm64_32, no ptrauth bits to clear
+#if !defined(__LP64__)
+  return value;
+#endif
+
+  uint64_t mask = ((1ULL << addressing_bits) - 1);
+
+  // Normally PAC bit clearing needs to check b55 and either set the
+  // non-addressing bits, or clear them.  But the register values we
+  // get from thread_get_state on an arm64e process don't follow this
+  // convention?, at least when there's been a PAC auth failure in
+  // the inferior.
+  // Userland processes are always in low memory, so this
+  // hardcoding b55 == 0 PAC stripping behavior here.
+
+  return value & mask; // high bits cleared to 0
+}
+
 uint64_t DNBArchMachARM64::GetPC(uint64_t failValue) {
   // Get program counter
   if (GetGPRState(false) == KERN_SUCCESS)
-#if defined(__LP64__)
-return arm_thread_state64_get_pc(m_state.context.gpr);
+#if __has_feature(ptrauth_calls) && defined(__LP64__)
+return clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_pc));
 #else
 return m_state.context.gpr.__pc;
 #endif
@@ -128,8 +152,9 @@ kern_return_t DNBArchMachARM64::SetPC(uint64_t value) {
 uint64_t DNBArchMachARM64::GetSP(uint64_t failValue) {
   // Get stack pointer
   if (GetGPRState(false) == KERN_SUCCESS)
-#if defined(__LP64__)
-return arm_thread_state64_get_sp(m_state.context.gpr);
+#if __has_feature(ptrauth_calls) && defined(__LP64__)
+return clear_pac_bits(
+reinterpret_cast(m_state.context.gpr.__opaque_sp));
 #else
 return m_state.context.gpr.__sp;
 #endif
@@ -150,16 +175,20 @@ kern_return_t DNBArchMachARM64::GetGPRState(bool force) {
   if (DNBLogEnabledForAny(LOG_THREAD)) {
 uint64_t *x = _state.context.gpr.__x[0];
 
-#if defined(__LP64__)
-uint64_t log_fp = arm_thread_state64_get_fp(m_state.context.gpr);
-uint64_t log_lr = arm_thread_state64_get_lr(m_state.context.gpr);
-uint64_t log_sp = arm_thread_state64_get_sp(m_state.context.gpr);
-uint64_t log_pc = arm_thread_state64_get_pc(m_state.context.gpr);
+#if 

[Lldb-commits] [PATCH] D136295: Fix exception description in lldb-vscode

2022-10-25 Thread jeffrey tan via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51effa57818b: Fix exception description in lldb-vscode 
(authored by yinghuitan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136295

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/test/API/tools/lldb-vscode/exception/Makefile
  lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
  lldb/test/API/tools/lldb-vscode/exception/main.cpp
  lldb/tools/lldb-vscode/JSONUtils.cpp


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -930,7 +930,7 @@
   // If no description has been set, then set it to the default thread stopped
   // description. If we have breakpoints that get hit and shouldn't be reported
   // as breakpoints, then they will set the description above.
-  if (ObjectContainsKey(body, "description")) {
+  if (!ObjectContainsKey(body, "description")) {
 char description[1024];
 if (thread.GetStopDescription(description, sizeof(description))) {
   EmplaceSafeString(body, "description", std::string(description));
Index: lldb/test/API/tools/lldb-vscode/exception/main.cpp
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/exception/main.cpp
@@ -0,0 +1,6 @@
+#include 
+
+int main() {
+  raise(SIGABRT);
+  return 0;
+}
Index: lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
@@ -0,0 +1,24 @@
+"""
+Test exception behavior in VSCode
+"""
+
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbvscode_testcase
+
+
+class TestVSCode_exception(lldbvscode_testcase.VSCodeTestCaseBase):
+
+@skipIfWindows
+def test_stopped_description(self):
+'''
+Test that exception description is shown correctly in stopped
+event.
+'''
+program = self.getBuildArtifact("a.out")
+print("test_stopped_description called", flush=True)
+self.build_and_launch(program)
+
+self.vscode.request_continue()
+self.assertTrue(self.verify_stop_exception_info("signal SIGABRT"))
Index: lldb/test/API/tools/lldb-vscode/exception/Makefile
===
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/exception/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
Index: 
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
===
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -93,10 +93,10 @@
 return
 self.assertTrue(False, "breakpoint not hit")
 
-def verify_exception_breakpoint_hit(self, filter_label):
+def verify_stop_exception_info(self, expected_description):
 '''Wait for the process we are debugging to stop, and verify the stop
reason is 'exception' and that the description matches
-   'filter_label'
+   'expected_description'
 '''
 stopped_events = self.vscode.wait_for_stopped()
 for stopped_event in stopped_events:
@@ -109,7 +109,7 @@
 if 'description' not in body:
 continue
 description = body['description']
-if filter_label == description:
+if expected_description == description:
 return True
 return False
 
@@ -236,7 +236,7 @@
 
 def continue_to_exception_breakpoint(self, filter_label):
 self.vscode.request_continue()
-self.assertTrue(self.verify_exception_breakpoint_hit(filter_label),
+self.assertTrue(self.verify_stop_exception_info(filter_label),
 'verify we got "%s"' % (filter_label))
 
 def continue_to_exit(self, exitCode=0):


Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -930,7 +930,7 @@
   // If no description has been set, then set it to the default thread stopped
   // description. If we have breakpoints that get hit and shouldn't be reported
   // as breakpoints, then they will set the description above.
-  if (ObjectContainsKey(body, "description")) {
+  if (!ObjectContainsKey(body, "description")) {
 char description[1024];
 if (thread.GetStopDescription(description, sizeof(description))) 

[Lldb-commits] [lldb] 51effa5 - Fix exception description in lldb-vscode

2022-10-25 Thread Jeffrey Tan via lldb-commits

Author: Jeffrey Tan
Date: 2022-10-25T13:24:22-07:00
New Revision: 51effa57818bf937fb7c889b8f567c146bb4eefe

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

LOG: Fix exception description in lldb-vscode

There is a bug in lldb-vscode that only shows stop reason ("exception") in
stopped event without showing the stop description of thrown exception. This
causes VSCode UI to only show "Paused on Exception" general message in
callstack window UI.

This patch fixes the bug so that VSCode callstack will show the detailed
exceptioni description, like "signal SIGABRT" or "EXC_BAD_ACCESS..." which
aligns with command line lldb experience.

I use C++ exception in testcase because the hardware exception description is
platform dependent and hard to verify.

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

Added: 
lldb/test/API/tools/lldb-vscode/exception/Makefile
lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
lldb/test/API/tools/lldb-vscode/exception/main.cpp

Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
lldb/tools/lldb-vscode/JSONUtils.cpp

Removed: 




diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
index 8ba8e0e4bf3b4..a91f3b2b8feff 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
@@ -93,10 +93,10 @@ def verify_breakpoint_hit(self, breakpoint_ids):
 return
 self.assertTrue(False, "breakpoint not hit")
 
-def verify_exception_breakpoint_hit(self, filter_label):
+def verify_stop_exception_info(self, expected_description):
 '''Wait for the process we are debugging to stop, and verify the stop
reason is 'exception' and that the description matches
-   'filter_label'
+   'expected_description'
 '''
 stopped_events = self.vscode.wait_for_stopped()
 for stopped_event in stopped_events:
@@ -109,7 +109,7 @@ def verify_exception_breakpoint_hit(self, filter_label):
 if 'description' not in body:
 continue
 description = body['description']
-if filter_label == description:
+if expected_description == description:
 return True
 return False
 
@@ -236,7 +236,7 @@ def continue_to_breakpoints(self, breakpoint_ids):
 
 def continue_to_exception_breakpoint(self, filter_label):
 self.vscode.request_continue()
-self.assertTrue(self.verify_exception_breakpoint_hit(filter_label),
+self.assertTrue(self.verify_stop_exception_info(filter_label),
 'verify we got "%s"' % (filter_label))
 
 def continue_to_exit(self, exitCode=0):

diff  --git a/lldb/test/API/tools/lldb-vscode/exception/Makefile 
b/lldb/test/API/tools/lldb-vscode/exception/Makefile
new file mode 100644
index 0..8b20bcb05
--- /dev/null
+++ b/lldb/test/API/tools/lldb-vscode/exception/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules

diff  --git a/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py 
b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
new file mode 100644
index 0..2fc0d9c638c3a
--- /dev/null
+++ b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py
@@ -0,0 +1,24 @@
+"""
+Test exception behavior in VSCode
+"""
+
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+import lldbvscode_testcase
+
+
+class TestVSCode_exception(lldbvscode_testcase.VSCodeTestCaseBase):
+
+@skipIfWindows
+def test_stopped_description(self):
+'''
+Test that exception description is shown correctly in stopped
+event.
+'''
+program = self.getBuildArtifact("a.out")
+print("test_stopped_description called", flush=True)
+self.build_and_launch(program)
+
+self.vscode.request_continue()
+self.assertTrue(self.verify_stop_exception_info("signal SIGABRT"))

diff  --git a/lldb/test/API/tools/lldb-vscode/exception/main.cpp 
b/lldb/test/API/tools/lldb-vscode/exception/main.cpp
new file mode 100644
index 0..b940d07c6f2bb
--- /dev/null
+++ b/lldb/test/API/tools/lldb-vscode/exception/main.cpp
@@ -0,0 +1,6 @@
+#include 
+
+int main() {
+  raise(SIGABRT);
+  return 0;
+}

diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp 
b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 4bc965e61b81e..baeed2a81105c 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ 

[Lldb-commits] [PATCH] D136557: [trace][intel pt] Simple detection of infinite decoding loops

2022-10-25 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc49d14aca5c7: [trace][intel pt] Simple detection of infinite 
decoding loops (authored by Walter Erquinigo wall...@fb.com).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136557

Files:
  lldb/include/lldb/Core/PluginManager.h
  lldb/source/Core/PluginManager.cpp
  lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
  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/TraceIntelPT.cpp
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
  lldb/source/Plugins/Trace/intel-pt/TraceIntelPTProperties.td
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceLoad.py

Index: lldb/test/API/commands/trace/TestTraceLoad.py
===
--- lldb/test/API/commands/trace/TestTraceLoad.py
+++ lldb/test/API/commands/trace/TestTraceLoad.py
@@ -37,6 +37,12 @@
   "totalCount": 0,
   "individualCounts": {}
 },
+"errors": {
+  "totalCount": 0,
+  "libiptErrors": {},
+  "fatalErrors": 0,
+  "otherErrors": 0
+},
 "continuousExecutions": 0,
 "PSBBlocks": 0
   },
@@ -72,6 +78,12 @@
 "HW clock tick": 8
   }
 },
+"errors": {
+  "totalCount": 1,
+  "libiptErrors": {},
+  "fatalErrors": 0,
+  "otherErrors": 1
+},
 "continuousExecutions": 1,
 "PSBBlocks": 1
   },
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -78,6 +78,12 @@
 "software disabled tracing": 2,
 "trace synchronization point": 1
   }
+},
+"errors": {
+  "totalCount": 0,
+  "libiptErrors": {},
+  "fatalErrors": 0,
+  "otherErrors": 0
 }
   },
   "globalStats": {
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPTProperties.td
===
--- /dev/null
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPTProperties.td
@@ -0,0 +1,24 @@
+include "../../../../include/lldb/Core/PropertiesBase.td"
+
+let Definition = "traceintelpt" in {
+  def InfiniteDecodingLoopVerificationThreshold:
+  Property<"infinite-decoding-loop-verification-threshold", "UInt64">,
+Global,
+DefaultUnsignedValue<1>,
+Desc<"Specify how many instructions following an individual Intel PT "
+  "packet must have been decoded before triggering the verification of "
+  "infinite decoding loops. If no decoding loop has been found after this "
+  "threshold T, another attempt will be done after 2T instructions, then "
+  "4T, 8T and so on, which guarantees a total linear time spent checking "
+  "this anomaly. If a loop is found, then decoding of the corresponding "
+  "PSB block is stopped. An error is hence emitted in the trace and "
+  "decoding is resumed in the next PSB block.">;
+  def ExtremelyLargeDecodingThreshold:
+  Property<"extremely-large-decoding-threshold", "UInt64">,
+Global,
+DefaultUnsignedValue<50>,
+Desc<"Specify how many instructions following an individual Intel PT "
+  "packet must have been decoded before stopping the decoding of the "
+  "corresponding PSB block. An error is hence emitted in the trace and "
+  "decoding is resumed in the next PSB block.">;
+}
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
+++ lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
@@ -22,6 +22,23 @@
 
 class TraceIntelPT : public Trace {
 public:
+  /// Properties to be used with the `settings` command.
+  class PluginProperties : public Properties {
+  public:
+static ConstString GetSettingName();
+
+PluginProperties();
+
+~PluginProperties() override = default;
+
+uint64_t GetInfiniteDecodingLoopVerificationThreshold();
+
+uint64_t GetExtremelyLargeDecodingThreshold();
+  };
+
+  /// Return the global properties for this trace plug-in.
+  static PluginProperties ();
+
   void Dump(Stream *s) const override;
 
   llvm::Expected SaveToDisk(FileSpec directory,
@@ -59,6 +76,8 @@
   CreateInstanceForLiveProcess(Process );
 
   static llvm::StringRef GetPluginNameStatic() { return "intel-pt"; }
+
+  static void DebuggerInitialize(Debugger );
   /// \}
 
   lldb::CommandObjectSP
Index: lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
+++ 

[Lldb-commits] [lldb] c49d14a - [trace][intel pt] Simple detection of infinite decoding loops

2022-10-25 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-10-25T10:20:49-07:00
New Revision: c49d14aca5c7b06a4f896e9923bdab8a33f2866d

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

LOG: [trace][intel pt] Simple detection of infinite decoding loops

The low-level decoder might fall into an infinite decoding loop for
various reasons, the simplest being an infinite direct loop reached due
to wrong handling of self-modified code in the kernel, e.g. it might
reach

```
0x0A: pause
0x0C: jump to 0x0A
```

In this case, all the code is sequential and requires no packets to be
decoded. The low-level decoder would produce an output like the
following

```
0x0A: pause
0x0C: jump to 0x0A
0x0A: pause
0x0C: jump to 0x0A
0x0A: pause
0x0C: jump to 0x0A
... infinite amount of times
```

These cases require stopping the decoder to avoid infinite work and signal this
at least as a trace error.

- Add a check that breaks decoding of a single PSB once 500k instructions have 
been decoded since the last packet was processed.
- Add a check that looks for infinite loops after certain amount of 
instructions have been decoded since the last packet was processed.
- Add some `settings` properties for tweaking the thresholds of the checks 
above. This is also nice because it does the basic work needed for future 
settings.
- Add an AnomalyDetector class that inspects the DecodedThread and the libipt 
decoder in search for anomalies. These anomalies are then signaled as fatal 
errors in the trace.
- Add an ErrorStats class that keeps track of all the errors in a 
DecodedThread, with a special counter for fatal errors.
- Add an entry for decoded thread errors in the `dump info` command.

Some notes are added in the code and in the documention of the settings,
so please read them.

Besides that, I haven't been unable to create a test case in LLVM style, but
I've found an anomaly in the thread #12 of the trace
72533820-3eb8-4465-b8e4-4e6bf0ccca99 at Meta. We have to figure out how to
artificially create traces with this kind of anomalies in LLVM style.

With this change, that anomalous thread now shows:

```
(lldb)thread trace dump instructions 12 -e -i 23101

thread #12: tid = 8
...missing instructions
23101: (error) anomalous trace: possible infinite loop detected of size 2
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 
[inlined] rep_nop at processor.h:13:2
23100: 0x81342785pause
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at 
panic.c:87:2
23099: 0x81342787jmp0x81342785; <+5> 
[inlined] rep_nop at processor.h:13:2
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 
[inlined] rep_nop at processor.h:13:2
23098: 0x81342785pause
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at 
panic.c:87:2
23097: 0x81342787jmp0x81342785; <+5> 
[inlined] rep_nop at processor.h:13:2
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 5 
[inlined] rep_nop at processor.h:13:2
23096: 0x81342785pause
  vmlinux-5.12.0-0_fbk8_clang_6656_gc85768aa64da`panic_smp_self_stop + 7 at 
panic.c:87:2
23095: 0x81342787jmp0x81342785; <+5> 
[inlined] rep_nop at processor.h:13:2
```

It used to be in an infinite loop where the decoder never stopped.

Besides that, the dump info command shows

```
(lldb) thread trace dump info 12

 Errors:
Number of individual errors: 32
  Number of fatal errors: 1
  Number of other errors: 31
```

and in json format

```
(lldb) thread trace dump info 12 -j

 "errors": {
  "totalCount": 32,
  "libiptErrors": {},
  "fatalErrors": 1,
  "otherErrors": 31
}
```

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

Added: 
lldb/source/Plugins/Trace/intel-pt/TraceIntelPTProperties.td

Modified: 
lldb/include/lldb/Core/PluginManager.h
lldb/source/Core/PluginManager.cpp
lldb/source/Plugins/Trace/intel-pt/CMakeLists.txt
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/TraceIntelPT.cpp
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.h
lldb/test/API/commands/trace/TestTraceDumpInfo.py
lldb/test/API/commands/trace/TestTraceLoad.py

Removed: 




diff  --git a/lldb/include/lldb/Core/PluginManager.h 
b/lldb/include/lldb/Core/PluginManager.h
index ed8917f059cd4..4e036e0d4caa0 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -342,7 +342,8 @@ class PluginManager {
   llvm::StringRef name, 

[Lldb-commits] [PATCH] D136610: [trace][intelpt] Fix multi CPU decoding TSC assertion error

2022-10-25 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

thanks. Your explanation of why the verbose error is useful was good :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136610

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


[Lldb-commits] [PATCH] D136697: Add formatting support for VSCode logpoints message

2022-10-25 Thread jeffrey tan via Phabricator via lldb-commits
yinghuitan created this revision.
yinghuitan added reviewers: clayborg, labath, jingham, jdoerfert, JDevlieghere, 
aadsm, kusmour, fixathon.
Herald added a project: All.
yinghuitan requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

https://reviews.llvm.org/D127702 adds the initial logpoints support in 
lldb-vscode. This patch further improves it by:

1. Adding a newline at the end of each log message
2. Support most of the format specifiers like \t, \n, \x etc..

The implementation is borrowed from FormatEntity::ParseInternal(). Future
patch should merge these two implementations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136697

Files:
  lldb/test/API/tools/lldb-vscode/breakpoint/TestVSCode_logpoints.py
  lldb/tools/lldb-vscode/BreakpointBase.cpp
  lldb/tools/lldb-vscode/BreakpointBase.h

Index: lldb/tools/lldb-vscode/BreakpointBase.h
===
--- lldb/tools/lldb-vscode/BreakpointBase.h
+++ lldb/tools/lldb-vscode/BreakpointBase.h
@@ -22,7 +22,7 @@
   struct LogMessagePart {
 LogMessagePart(llvm::StringRef text, bool is_expr)
 : text(text), is_expr(is_expr) {}
-llvm::StringRef text;
+std::string text;
 bool is_expr;
   };
   // An optional expression for conditional breakpoints.
@@ -45,6 +45,13 @@
   void SetHitCondition();
   void SetLogMessage();
   void UpdateBreakpoint(const BreakpointBase _bp);
+
+  // Format \param text and return formatted text in \param formatted.
+  // \return any formatting failures.
+  lldb::SBError FormatLogText(llvm::StringRef text, std::string );
+  lldb::SBError AppendLogMessagePart(llvm::StringRef part, bool is_expr);
+  void NotifyLogMessageError(llvm::StringRef error);
+
   static const char *GetBreakpointLabel();
   static bool BreakpointHitCallback(void *baton, lldb::SBProcess ,
 lldb::SBThread ,
Index: lldb/tools/lldb-vscode/BreakpointBase.cpp
===
--- lldb/tools/lldb-vscode/BreakpointBase.cpp
+++ lldb/tools/lldb-vscode/BreakpointBase.cpp
@@ -25,6 +25,141 @@
 bp.SetIgnoreCount(hitCount - 1);
 }
 
+lldb::SBError BreakpointBase::AppendLogMessagePart(llvm::StringRef part,
+  bool is_expr) {
+  if (is_expr) {
+logMessageParts.emplace_back(part, is_expr);
+  } else {
+std::string formatted;
+lldb::SBError error = FormatLogText(part, formatted);
+if (error.Fail())
+  return error;
+logMessageParts.emplace_back(formatted, is_expr);
+  }
+  return lldb::SBError();
+}
+
+// TODO: consolidate this code with the implementation in
+// FormatEntity::ParseInternal().
+lldb::SBError BreakpointBase::FormatLogText(llvm::StringRef text,
+   std::string ) {
+  lldb::SBError error;
+  while (!text.empty()) {
+if (text[0] != '\\') {
+  formatted.push_back(text[0]);
+  text = text.drop_front();
+  continue;
+}
+// Skip the '\' character
+text = text.drop_front();
+if (text.empty()) {
+  error.SetErrorString(
+  "'\\' character was not followed by another character");
+  return error;
+}
+
+const char desens_char = text[0];
+text = text.drop_front(); // Skip the desensitized char character
+switch (desens_char) {
+case 'a':
+  formatted.push_back('\a');
+  break;
+case 'b':
+  formatted.push_back('\b');
+  break;
+case 'f':
+  formatted.push_back('\f');
+  break;
+case 'n':
+  formatted.push_back('\n');
+  break;
+case 'r':
+  formatted.push_back('\r');
+  break;
+case 't':
+  formatted.push_back('\t');
+  break;
+case 'v':
+  formatted.push_back('\v');
+  break;
+case '\'':
+  formatted.push_back('\'');
+  break;
+case '\\':
+  formatted.push_back('\\');
+  break;
+case '0':
+  // 1 to 3 octal chars
+  {
+if (text.empty()) {
+  error.SetErrorString("missing octal number following '\\0'");
+  return error;
+}
+
+// Make a string that can hold onto the initial zero char, up to 3
+// octal digits, and a terminating NULL.
+char oct_str[5] = {0, 0, 0, 0, 0};
+
+size_t i;
+for (i = 0;
+ i < text.size() && i < 4 && (text[i] >= '0' && text[i] <= '7');
+ ++i) {
+  oct_str[i] = text[i];
+}
+
+text = text.drop_front(i);
+unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
+if (octal_value <= UINT8_MAX) {
+  formatted.push_back((char)octal_value);
+} else {
+  error.SetErrorString("octal number is larger than a single byte");
+  return error;
+}
+  }
+  break;
+
+case 'x': {
+  if (text.empty()) {
+error.SetErrorString("missing 

[Lldb-commits] [lldb] 93a5a03 - [lldb] Host::ShellExpandArguments - fix error check for valid dictionary

2022-10-25 Thread Simon Pilgrim via lldb-commits

Author: Simon Pilgrim
Date: 2022-10-25T17:44:04+01:00
New Revision: 93a5a03030ab9f49120f7bd2ec8e84f063da9987

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

LOG: [lldb] Host::ShellExpandArguments - fix error check for valid dictionary

Fix repeated check for a valid JSON parse and actually check the dictionary 
pointer

Reported here: https://pvs-studio.com/en/blog/posts/cpp/1003/ (N40)

Added: 


Modified: 
lldb/source/Host/windows/Host.cpp

Removed: 




diff  --git a/lldb/source/Host/windows/Host.cpp 
b/lldb/source/Host/windows/Host.cpp
index df7859d9b46c9..6908f0003eaf7 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -245,7 +245,7 @@ Status Host::ShellExpandArguments(ProcessLaunchInfo 
_info) {
 }
 
 auto dict_sp = data_sp->GetAsDictionary();
-if (!data_sp) {
+if (!dict_sp) {
   error.SetErrorString("invalid JSON");
   return error;
 }



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


[Lldb-commits] [PATCH] D135622: [lldb] Add a "diagnostics dump" command

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D135622

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


[Lldb-commits] [PATCH] D136620: Change how debugserver clears auth bits from pc/fp/sp/lr with thread_get_state on Darwin

2022-10-25 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136620

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


[Lldb-commits] [PATCH] D135622: [lldb] Add a "diagnostics dump" command

2022-10-25 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/source/Utility/Diagnostics.cpp:70
 
-  Error error = Create(FileSpec(diagnostics_dir.str()));
+  Error error = Create(*diagnostics_dir);
   if (error) {

DavidSpickett wrote:
> JDevlieghere wrote:
> > DavidSpickett wrote:
> > > Silly question, is it intentional that we write out files after saying 
> > > they have been written?
> > > 
> > > Of course it makes sense to print something up front, otherwise the error 
> > > here would come out of the blue, but perhaps "LLDB diagnostics will be 
> > > written to..." instead?
> > > 
> > > (this is probably better changed in that earlier patch not sure if that 
> > > went in yet)
> > Yes, that was @labath's suggestion because when we call this from the 
> > signal handler, we might crash again in the process and wouldn't print 
> > anything at all. 
> Maybe I can be clearer:
> ```
> LLDB diagnostics written to <...>
> Please include the directory content when filing a bug report
> 
> ```
> 
> So the files haven't been written, or at least they are in an undefined 
> state, but the output looks like we finished writing them. So `will be 
> written` is more accurate. If I see this in a test log file I'm going to 
> wonder did it crash writing them or did it already write them, which means 
> I'd have to reproduce locally. With the sequence of events clearer, I can at 
> least check obvious things like a full disk before needing to do that.
> 
> Small thing but it's a few words might save some annoyance down the road.
> 
> (printing up front I agree with, that part is good)
Makes sense!


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

https://reviews.llvm.org/D135622

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


[Lldb-commits] [PATCH] D135622: [lldb] Add a "diagnostics dump" command

2022-10-25 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere updated this revision to Diff 470503.
JDevlieghere marked an inline comment as done.
JDevlieghere added a comment.

Update wording


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

https://reviews.llvm.org/D135622

Files:
  lldb/include/lldb/Utility/Diagnostics.h
  lldb/source/Commands/CMakeLists.txt
  lldb/source/Commands/CommandObjectDiagnostics.cpp
  lldb/source/Commands/CommandObjectDiagnostics.h
  lldb/source/Commands/Options.td
  lldb/source/Interpreter/CommandInterpreter.cpp
  lldb/source/Utility/Diagnostics.cpp
  lldb/test/Shell/Diagnostics/TestDump.test

Index: lldb/test/Shell/Diagnostics/TestDump.test
===
--- /dev/null
+++ lldb/test/Shell/Diagnostics/TestDump.test
@@ -0,0 +1,15 @@
+# Check that the diagnostics dump command uses the correct directory and
+# creates one if needed.
+
+# Dump to an existing directory.
+# RUN: rm -rf %t.existing
+# RUN: mkdir -p %t.existing
+# RUN: %lldb -o 'diagnostics dump -d %t.existing'
+# RUN: file %t.existing | FileCheck %s
+
+# Dump to a non-existing directory.
+# RUN: rm -rf %t.nonexisting
+# RUN: %lldb -o 'diagnostics dump -d %t.nonexisting'
+# RUN: file %t.nonexisting | FileCheck %s
+
+# CHECK: : directory
Index: lldb/source/Utility/Diagnostics.cpp
===
--- lldb/source/Utility/Diagnostics.cpp
+++ lldb/source/Utility/Diagnostics.cpp
@@ -44,19 +44,21 @@
 }
 
 bool Diagnostics::Dump(raw_ostream ) {
-  SmallString<128> diagnostics_dir;
-  std::error_code ec =
-  sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
-  if (ec) {
+  Expected diagnostics_dir = CreateUniqueDirectory();
+  if (!diagnostics_dir) {
 stream << "unable to create diagnostic dir: "
-   << toString(errorCodeToError(ec)) << '\n';
+   << toString(diagnostics_dir.takeError()) << '\n';
 return false;
   }
 
-  stream << "LLDB diagnostics written to " << diagnostics_dir << "\n";
+  return Dump(stream, *diagnostics_dir);
+}
+
+bool Diagnostics::Dump(raw_ostream , const FileSpec ) {
+  stream << "LLDB diagnostics will be written to " << dir.GetPath() << "\n";
   stream << "Please include the directory content when filing a bug report\n";
 
-  Error error = Create(FileSpec(diagnostics_dir.str()));
+  Error error = Create(dir);
   if (error) {
 stream << toString(std::move(error)) << '\n';
 return false;
@@ -65,6 +67,15 @@
   return true;
 }
 
+llvm::Expected Diagnostics::CreateUniqueDirectory() {
+  SmallString<128> diagnostics_dir;
+  std::error_code ec =
+  sys::fs::createUniqueDirectory("diagnostics", diagnostics_dir);
+  if (ec)
+return errorCodeToError(ec);
+  return FileSpec(diagnostics_dir.str());
+}
+
 Error Diagnostics::Create(const FileSpec ) {
   for (Callback c : m_callbacks) {
 if (Error err = c(dir))
Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -15,6 +15,7 @@
 #include "Commands/CommandObjectApropos.h"
 #include "Commands/CommandObjectBreakpoint.h"
 #include "Commands/CommandObjectCommands.h"
+#include "Commands/CommandObjectDiagnostics.h"
 #include "Commands/CommandObjectDisassemble.h"
 #include "Commands/CommandObjectExpression.h"
 #include "Commands/CommandObjectFrame.h"
@@ -518,6 +519,7 @@
   REGISTER_COMMAND_OBJECT("apropos", CommandObjectApropos);
   REGISTER_COMMAND_OBJECT("breakpoint", CommandObjectMultiwordBreakpoint);
   REGISTER_COMMAND_OBJECT("command", CommandObjectMultiwordCommands);
+  REGISTER_COMMAND_OBJECT("diagnostics", CommandObjectDiagnostics);
   REGISTER_COMMAND_OBJECT("disassemble", CommandObjectDisassemble);
   REGISTER_COMMAND_OBJECT("expression", CommandObjectExpression);
   REGISTER_COMMAND_OBJECT("frame", CommandObjectMultiwordFrame);
Index: lldb/source/Commands/Options.td
===
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -343,6 +343,11 @@
 Desc<"Force disassembly of large functions.">;
 }
 
+let Command = "diagnostics dump" in {
+  def diagnostics_dump_directory : Option<"directory", "d">, Group<1>,
+Arg<"Path">, Desc<"Dump the diagnostics to the given directory.">;
+}
+
 let Command = "expression" in {
   def expression_options_all_threads : Option<"all-threads", "a">,
 Groups<[1,2]>, Arg<"Boolean">, Desc<"Should we run all threads if the "
Index: lldb/source/Commands/CommandObjectDiagnostics.h
===
--- /dev/null
+++ lldb/source/Commands/CommandObjectDiagnostics.h
@@ -0,0 +1,29 @@
+//===-- CommandObjectDiagnostics.h --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license 

[Lldb-commits] [PATCH] D136674: [LLDB] Fix RISCV build

2022-10-25 Thread Emmmer S via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc094b1eef08c: [LLDB] Fix RISCV build (authored by Emmmer).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136674

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp


Index: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
+++ lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
@@ -135,7 +135,7 @@
 return Status("failed - register wasn't recognized to be a GPR or an FPR, "
   "write strategy unknown");
 
-  reg_value.SetFromMemoryData(reg_info, src, reg_info->byte_size,
+  reg_value.SetFromMemoryData(*reg_info, src, reg_info->byte_size,
   eByteOrderLittle, error);
 
   return error;


Index: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
+++ lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
@@ -135,7 +135,7 @@
 return Status("failed - register wasn't recognized to be a GPR or an FPR, "
   "write strategy unknown");
 
-  reg_value.SetFromMemoryData(reg_info, src, reg_info->byte_size,
+  reg_value.SetFromMemoryData(*reg_info, src, reg_info->byte_size,
   eByteOrderLittle, error);
 
   return error;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] c094b1e - [LLDB] Fix RISCV build

2022-10-25 Thread via lldb-commits

Author: Emmmer
Date: 2022-10-25T23:03:16+08:00
New Revision: c094b1eef08cee93e4dd9e69d0f7f511037c8500

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

LOG: [LLDB] Fix RISCV build

After https://reviews.llvm.org/D135670

Reviewed By: DavidSpickett

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

Added: 


Modified: 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
index 342fc1aa1a416..1d51726a86df1 100644
--- a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_riscv64.cpp
@@ -135,7 +135,7 @@ NativeRegisterContextLinux_riscv64::ReadRegister(const 
RegisterInfo *reg_info,
 return Status("failed - register wasn't recognized to be a GPR or an FPR, "
   "write strategy unknown");
 
-  reg_value.SetFromMemoryData(reg_info, src, reg_info->byte_size,
+  reg_value.SetFromMemoryData(*reg_info, src, reg_info->byte_size,
   eByteOrderLittle, error);
 
   return error;



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


[Lldb-commits] [PATCH] D134991: [lldb] Add diagnostics

2022-10-25 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

Ping


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

https://reviews.llvm.org/D134991

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


[Lldb-commits] [PATCH] D136462: [LLDB] Add color to output text when searching for symbols

2022-10-25 Thread Varun Kumar E via Phabricator via lldb-commits
varunkumare99 added a comment.

In D136462#3878895 , @DavidSpickett 
wrote:

> I agree that this change names - print - restore names is going to cause 
> problems. Pavel is right that this should happen in some dump function 
> somewhere.
>
> But, assuming what you've got works to an extent, you should add some testing 
> first. That will allow you to refactor with less risk. You'll be able to 
> reuse a lot of the tests later, so it's not wasted effort and it'll flush out 
> some corner cases you haven't thought of.

Thanks. I start out with adding some testing first. Then look into adding 
colouration in dump functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136462

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


[Lldb-commits] [PATCH] D136462: [LLDB] Add color to output text when searching for symbols

2022-10-25 Thread Varun Kumar E via Phabricator via lldb-commits
varunkumare99 added a comment.



In D136462#3878682 , @labath wrote:

> This is definitely not a good way to implement this functionality. There's no 
> telling who else might be accessing the symbols while their names are being 
> changed.
>
> The colouration should be implemented inside the dumping function, without 
> modifying the state of the debugger. I realize that's not currently easy to 
> do, but that's not a reason to do this. It's possible the dumping machinery 
> needs to be refactored to support this kind of customized colouration.

thank you for the feedback. I will try adding colouration inside a dumping 
function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136462

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


[Lldb-commits] [PATCH] D136610: [trace][intelpt] Fix multi CPU decoding TSC assertion error

2022-10-25 Thread Jakob Johnson via Phabricator via lldb-commits
jj10306 added inline comments.



Comment at: lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp:299-307
+  uint64_t offset;
+  int status = pt_insn_get_offset(m_decoder_up.get(), );
+  if (!IsLibiptError(status)) {
+err_msg =
+formatv("At byte offset {0} of PSB with size {1} bytes, {2}",
+offset, m_psb_block.size, err_msg)
+.str();

wallace wrote:
> I think let's better not include this to keep the error a bit smaller. In any 
> case, you can do `thread trace dump instructions  -E` and then look 
> for the error prefix when debugging.
> 
> but if you insist, the byte offset message should come after the textual 
> description of the error
I included the byte offset information so we can get an idea of what % of data 
we are losing each time this occurs. I'll clean this up a bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136610

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


[Lldb-commits] [PATCH] D136610: [trace][intelpt] Fix multi CPU decoding TSC assertion error

2022-10-25 Thread Jakob Johnson via Phabricator via lldb-commits
jj10306 updated this revision to Diff 470472.
jj10306 marked 7 inline comments as done.
jj10306 added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136610

Files:
  lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp

Index: lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
===
--- lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
+++ lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
@@ -153,11 +153,17 @@
   /// \param[in] decoded_thread
   /// A \a DecodedThread object where the decoded instructions will be
   /// appended to. It might have already some instructions.
+  ///
+  /// \param[in] tsc_upper_bound
+  ///   Maximum allowed value of TSCs decoded from this PSB block.
+  ///   Any of this PSB's data occurring after this TSC will be excluded.
   PSBBlockDecoder(PtInsnDecoderUP &_up, const PSBBlock _block,
   Optional next_block_ip,
-  DecodedThread _thread)
+  DecodedThread _thread,
+  llvm::Optional tsc_upper_bound)
   : m_decoder_up(std::move(decoder_up)), m_psb_block(psb_block),
-m_next_block_ip(next_block_ip), m_decoded_thread(decoded_thread) {}
+m_next_block_ip(next_block_ip), m_decoded_thread(decoded_thread),
+m_tsc_upper_bound(tsc_upper_bound) {}
 
   /// \param[in] trace_intel_pt
   /// The main Trace object that own the PSB block.
@@ -185,14 +191,15 @@
   static Expected
   Create(TraceIntelPT _intel_pt, const PSBBlock _block,
  ArrayRef buffer, Process ,
- Optional next_block_ip, DecodedThread _thread) {
+ Optional next_block_ip, DecodedThread _thread,
+ llvm::Optional tsc_upper_bound) {
 Expected decoder_up =
 CreateInstructionDecoder(trace_intel_pt, buffer, process);
 if (!decoder_up)
   return decoder_up.takeError();
 
 return PSBBlockDecoder(std::move(*decoder_up), psb_block, next_block_ip,
-   decoded_thread);
+   decoded_thread, tsc_upper_bound);
   }
 
   void DecodePSBBlock() {
@@ -259,6 +266,41 @@
 }
   }
 
+  /// Process the TSC of a decoded PT event. Specifically, check if this TSC
+  /// is below the TSC upper bound for this PSB. If the TSC exceeds the upper
+  /// bound, return an error to abort decoding. Otherwise add the it to the
+  /// underlying DecodedThread and decoding should continue as expected.
+  ///
+  /// \param[in] tsc
+  ///   The TSC of the a decoded event.
+  Error ProcessPTEventTSC(DecodedThread::TSC tsc) {
+if (m_tsc_upper_bound && tsc >= *m_tsc_upper_bound) {
+  // This event and all the remaining events of this PSB have a TSC
+  // outside the range of the "owning" ThreadContinuousExecution. For
+  // now we drop all of these events/instructions, future work can
+  // improve upon this by determining the "owning"
+  // ThreadContinuousExecution of the remaining PSB data.
+  std::string err_msg = formatv("decoding truncated: TSC {0} exceeds "
+"maximum TSC value {1}, will skip decoding"
+" the remaining data of the PSB",
+tsc, *m_tsc_upper_bound)
+.str();
+
+  uint64_t offset;
+  int status = pt_insn_get_offset(m_decoder_up.get(), );
+  if (!IsLibiptError(status)) {
+err_msg = formatv("{2} (skipping {0} of {1} bytes)", offset,
+  m_psb_block.size, err_msg)
+  .str();
+  }
+  m_decoded_thread.AppendCustomError(err_msg);
+  return createStringError(inconvertibleErrorCode(), err_msg);
+} else {
+  m_decoded_thread.NotifyTsc(tsc);
+  return Error::success();
+}
+  }
+
   /// Before querying instructions, we need to query the events associated with
   /// that instruction, e.g. timing and trace disablement events.
   ///
@@ -279,8 +321,12 @@
 return status;
   }
 
-  if (event.has_tsc)
-m_decoded_thread.NotifyTsc(event.tsc);
+  if (event.has_tsc) {
+if (Error err = ProcessPTEventTSC(event.tsc)) {
+  consumeError(std::move(err));
+  return -pte_internal;
+}
+  }
 
   switch (event.type) {
   case ptev_disabled:
@@ -313,6 +359,7 @@
   PSBBlock m_psb_block;
   Optional m_next_block_ip;
   DecodedThread _decoded_thread;
+  llvm::Optional m_tsc_upper_bound;
 };
 
 Error lldb_private::trace_intel_pt::DecodeSingleTraceForThread(
@@ -330,7 +377,7 @@
 trace_intel_pt, block, buffer.slice(block.psb_offset, block.size),
 *decoded_thread.GetThread()->GetProcess(),
 i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : None,
-decoded_thread);
+decoded_thread, llvm::None);
 if (!decoder)
   return 

[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Landed as 
https://github.com/llvm/llvm-project/commit/a3be778ed09b7badcda20c5c8738ba19531dad48.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3be778ed09b: [LLDB] [LoongArch] Add minimal LoongArch 
support (authored by seehearfeel, committed by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

Files:
  lldb/source/Plugins/Process/Linux/CMakeLists.txt
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.h
  lldb/source/Plugins/Process/Utility/CMakeLists.txt
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h

Index: lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h
===
--- /dev/null
+++ lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h
@@ -0,0 +1,64 @@
+//===-- RegisterInfoPOSIX_loongarch64.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERINFOPOSIX_LOONGARCH64_H
+#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_REGISTERINFOPOSIX_LOONGARCH64_H
+
+#include "RegisterInfoAndSetInterface.h"
+#include "lldb/Target/RegisterContext.h"
+#include "lldb/lldb-private.h"
+#include 
+
+class RegisterInfoPOSIX_loongarch64
+: public lldb_private::RegisterInfoAndSetInterface {
+public:
+  static const lldb_private::RegisterInfo *
+  GetRegisterInfoPtr(const lldb_private::ArchSpec _arch);
+  static uint32_t
+  GetRegisterInfoCount(const lldb_private::ArchSpec _arch);
+
+public:
+  struct GPR {
+uint64_t gpr[32];
+
+uint64_t orig_a0;
+uint64_t csr_era;
+uint64_t csr_badv;
+uint64_t reserved[10];
+  };
+
+  struct FPR {
+uint64_t fpr[32];
+uint64_t fcc;
+uint32_t fcsr;
+  };
+
+  RegisterInfoPOSIX_loongarch64(const lldb_private::ArchSpec _arch,
+lldb_private::Flags flags);
+
+  size_t GetGPRSize() const override;
+
+  size_t GetFPRSize() const override;
+
+  const lldb_private::RegisterInfo *GetRegisterInfo() const override;
+
+  uint32_t GetRegisterCount() const override;
+
+  const lldb_private::RegisterSet *
+  GetRegisterSet(size_t reg_set) const override;
+
+  size_t GetRegisterSetCount() const override;
+
+  size_t GetRegisterSetFromRegisterIndex(uint32_t reg_index) const override;
+
+private:
+  const lldb_private::RegisterInfo *m_register_info_p;
+  uint32_t m_register_info_count;
+};
+
+#endif
Index: lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.cpp
===
--- /dev/null
+++ lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.cpp
@@ -0,0 +1,68 @@
+//===-- RegisterInfoPOSIX_loongarch64.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 
+#include 
+#include 
+
+#include "lldb/lldb-defines.h"
+#include "llvm/Support/Compiler.h"
+
+#include "RegisterInfoPOSIX_loongarch64.h"
+
+const lldb_private::RegisterInfo *
+RegisterInfoPOSIX_loongarch64::GetRegisterInfoPtr(
+const lldb_private::ArchSpec _arch) {
+  switch (target_arch.GetMachine()) {
+  default:
+assert(false && "Unhandled target architecture.");
+return nullptr;
+  }
+}
+
+uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterInfoCount(
+const lldb_private::ArchSpec _arch) {
+  switch (target_arch.GetMachine()) {
+  default:
+assert(false && "Unhandled target architecture.");
+return 0;
+  }
+}
+
+RegisterInfoPOSIX_loongarch64::RegisterInfoPOSIX_loongarch64(
+const lldb_private::ArchSpec _arch, lldb_private::Flags flags)
+: lldb_private::RegisterInfoAndSetInterface(target_arch),
+  m_register_info_p(GetRegisterInfoPtr(target_arch)),
+  m_register_info_count(GetRegisterInfoCount(target_arch)) {}
+
+uint32_t RegisterInfoPOSIX_loongarch64::GetRegisterCount() const { return 0; }
+
+size_t RegisterInfoPOSIX_loongarch64::GetGPRSize() const {
+  return sizeof(struct RegisterInfoPOSIX_loongarch64::GPR);
+}
+
+size_t RegisterInfoPOSIX_loongarch64::GetFPRSize() const {
+  return sizeof(struct RegisterInfoPOSIX_loongarch64::FPR);
+}
+
+const lldb_private::RegisterInfo *
+RegisterInfoPOSIX_loongarch64::GetRegisterInfo() const {
+  return m_register_info_p;
+}
+
+size_t 

[Lldb-commits] [lldb] a3be778 - [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread David Spickett via lldb-commits

Author: Tiezhu Yang
Date: 2022-10-25T12:59:15Z
New Revision: a3be778ed09b7badcda20c5c8738ba19531dad48

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

LOG: [LLDB] [LoongArch] Add minimal LoongArch support

Add as little code as possible to allow compiling lldb on LoongArch.
Actual functionality will be implemented later.

Reviewed By: SixWeining, DavidSpickett

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

Added: 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.h
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.cpp
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h

Modified: 
lldb/source/Plugins/Process/Linux/CMakeLists.txt
lldb/source/Plugins/Process/Utility/CMakeLists.txt

Removed: 




diff  --git a/lldb/source/Plugins/Process/Linux/CMakeLists.txt 
b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
index b35c7de7c0028..d697bb7b7e071 100644
--- a/lldb/source/Plugins/Process/Linux/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/Linux/CMakeLists.txt
@@ -8,6 +8,7 @@ add_lldb_library(lldbPluginProcessLinux
   NativeRegisterContextLinux.cpp
   NativeRegisterContextLinux_arm.cpp
   NativeRegisterContextLinux_arm64.cpp
+  NativeRegisterContextLinux_loongarch64.cpp
   NativeRegisterContextLinux_ppc64le.cpp
   NativeRegisterContextLinux_riscv64.cpp
   NativeRegisterContextLinux_s390x.cpp

diff  --git 
a/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
new file mode 100644
index 0..a788248f03c1f
--- /dev/null
+++ 
b/lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_loongarch64.cpp
@@ -0,0 +1,92 @@
+//===-- NativeRegisterContextLinux_loongarch64.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
+//
+//===--===//
+
+#if defined(__loongarch__) && __loongarch_grlen == 64
+
+#include "NativeRegisterContextLinux_loongarch64.h"
+
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/RegisterValue.h"
+#include "lldb/Utility/Status.h"
+
+#include "Plugins/Process/Linux/NativeProcessLinux.h"
+#include "Plugins/Process/Linux/Procfs.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_linux;
+
+std::unique_ptr
+NativeRegisterContextLinux::CreateHostNativeRegisterContextLinux(
+const ArchSpec _arch, NativeThreadLinux _thread) {
+  switch (target_arch.GetMachine()) {
+  case llvm::Triple::loongarch64: {
+Flags opt_regsets;
+auto register_info_up = std::make_unique(
+target_arch, opt_regsets);
+return std::make_unique(
+target_arch, native_thread, std::move(register_info_up));
+  }
+  default:
+llvm_unreachable("have no register context for architecture");
+  }
+}
+
+llvm::Expected
+NativeRegisterContextLinux::DetermineArchitecture(lldb::tid_t tid) {
+  return HostInfo::GetArchitecture();
+}
+
+NativeRegisterContextLinux_loongarch64::NativeRegisterContextLinux_loongarch64(
+const ArchSpec _arch, NativeThreadProtocol _thread,
+std::unique_ptr register_info_up)
+: NativeRegisterContextRegisterInfo(native_thread,
+register_info_up.release()),
+  NativeRegisterContextLinux(native_thread) {
+  ::memset(_fpr, 0, sizeof(m_fpr));
+  ::memset(_gpr, 0, sizeof(m_gpr));
+}
+
+const RegisterInfoPOSIX_loongarch64 &
+NativeRegisterContextLinux_loongarch64::GetRegisterInfo() const {
+  return static_cast(
+  NativeRegisterContextRegisterInfo::GetRegisterInfoInterface());
+}
+
+uint32_t NativeRegisterContextLinux_loongarch64::GetRegisterSetCount() const {
+  return GetRegisterInfo().GetRegisterSetCount();
+}
+
+const RegisterSet *NativeRegisterContextLinux_loongarch64::GetRegisterSet(
+uint32_t set_index) const {
+  return GetRegisterInfo().GetRegisterSet(set_index);
+}
+
+Status NativeRegisterContextLinux_loongarch64::ReadRegister(
+const RegisterInfo *reg_info, RegisterValue _value) {
+  return Status("Failed to read register value");
+}
+
+Status NativeRegisterContextLinux_loongarch64::WriteRegister(
+const RegisterInfo *reg_info, const RegisterValue _value) {
+  return Status("Failed to write register value");
+}
+
+Status NativeRegisterContextLinux_loongarch64::ReadAllRegisterValues(
+lldb::WritableDataBufferSP _sp) {
+  return 

[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> I am a newcomer, here are some of my thoughts:
> (1) Add the minimal changes to fix the build errors.
> (2) Submit other more patches step by step to make
> the basic command "run", "breakpoint", "next" ...
> can be used to debug, single patch or patch series.
> (3) Add more code to make more commands work well.

Sounds like a good approach to me.

I believe the riscv effort focused on parts of the test suite in turn, sounds 
like you'll do the same.

> can land on my behalf

Will do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [lldb] 891eb20 - [LLDB][Docs][NFC] Fix formatting in -gmodules documentation

2022-10-25 Thread Michael Buch via lldb-commits

Author: Michael Buch
Date: 2022-10-25T12:34:00+01:00
New Revision: 891eb20104b6b77c7ff85f532bbce2a28ee9eeb0

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

LOG: [LLDB][Docs][NFC] Fix formatting in -gmodules documentation

Added: 


Modified: 
lldb/docs/use/extensions.rst

Removed: 




diff  --git a/lldb/docs/use/extensions.rst b/lldb/docs/use/extensions.rst
index 4a3f1ac177ab..3c73326dfa2b 100644
--- a/lldb/docs/use/extensions.rst
+++ b/lldb/docs/use/extensions.rst
@@ -8,7 +8,7 @@ Clang ``-gmodules`` debug info
 
 On Darwin platforms, including Apple macOS and iOS, Clang can emit
 DWARF debug info for types found in `Clang
-modules`_ more efficiently.
+modules `_ more efficiently.
 
 From an on-disk storage perspective, Clang modules are precompiled
 header files that contain serialized Clang ASTs of all the
@@ -16,7 +16,7 @@ declarations found in a Clang module. In traditional DWARF 
debug info,
 two object files that were built from sources that imported the same
 header file will both contain DWARF debug type info for types in that
 header file. This can lead to a lot of redundant `debug
-info`_.
+info `_.
 
 When Clang compiles a Clang module or precompiled header with the
 ``-gmodules`` option, the precompiled header (``.pch``) or module
@@ -57,6 +57,7 @@ M.h
 M.pcm
 
 ::
+
DW_TAG_compile_unit
  DW_AT_GNU_dwo_id  (0xabcdef)
  DW_TAG_module
@@ -69,11 +70,13 @@ M.pcm
 A.c

 ::
+
A a;
 
 A.o
 
 ::
+
DW_TAG_compile_unit
  DW_TAG_module
DW_AT_name "M"



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


[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread Lu Weining via Phabricator via lldb-commits
SixWeining accepted this revision.
SixWeining added a comment.

LGTM for LoongArch related changes.




Comment at: 
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h:26
+public:
+  struct GPR {
+uint64_t gpr[32];

xry111 wrote:
> SixWeining wrote:
> > Why is this structure and below `FPR` defined like this? Do you intent to 
> > keep the layout same as some structures of Linux? If yes, is it necessary?
> It seems necessary because lldb invokes `ptrace` system call which directly 
> stores into the pointer returned by `GetGPRBuffer`.
Make sense. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread Tiezhu Yang via Phabricator via lldb-commits
seehearfeel added a comment.

In D136578#3881955 , @DavidSpickett 
wrote:

> This LGTM from the lldb side.

OK, thank you.

> Feel free to upload a series of patches in future if you want. You don't have 
> to do one at a time, just update the whole stack as needed. Plus it gives the 
> reviewers some context of what the changes are working towards.

I am a newcomer, here are some of my thoughts:
(1) Add the minimal changes to fix the build errors.
(2) Submit other more patches step by step to make
the basic command "run", "breakpoint", "next" ...
can be used to debug, single patch or patch series.
(3) Add more code to make more commands work well.

> Do you have commit access? If not it's fine to wait until you have 
> (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access), or 
> someone else can land on your behalf. Just provide a name and email address 
> you'd like to be on the commit.

I have no commit access now, @SixWeining luwein...@loongson.cn
can land on my behalf, here are my name and email:
Tiezhu Yang
yangtie...@loongson.cn


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [PATCH] D136362: [LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV

2022-10-25 Thread Emmmer S via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05ae747a5353: [LLDB][RISCV] Add RV64C instruction support 
for EmulateInstructionRISCV (authored by Emmmer).
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136362

Files:
  lldb/source/Host/common/NativeProcessProtocol.cpp
  lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
  lldb/source/Plugins/Instruction/RISCV/RISCVCInstructions.h
  lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h
  lldb/source/Target/Platform.cpp
  lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp

Index: lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp
===
--- lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp
+++ lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp
@@ -256,6 +256,88 @@
   ASSERT_EQ(this->gpr.gpr[0], uint64_t(16));
 }
 
+struct TestDecode {
+  uint32_t inst;
+  RISCVInst inst_type;
+};
+
+bool compareInst(const RISCVInst , const RISCVInst ) {
+  if (lhs.index() != rhs.index())
+return false;
+  return std::visit(
+  [&](auto &) {
+return std::visit(
+[&](auto &) {
+  // guaranteed by
+  // 1. lhs.index() == rhs.index()
+  // (they are the same instruction type)
+  // 2. all instruction representations are plain data objects
+  // consisting of primitive types.
+  return std::memcmp(, , sizeof(L)) == 0;
+},
+rhs);
+  },
+  lhs);
+}
+
+TEST_F(RISCVEmulatorTester, TestCDecode) {
+  std::vector tests = {
+  {0x, INVALID{0x}},
+  {0x0010, RESERVED{0x0010}},
+  // ADDI4SPN here, decode as ADDI
+  {0x0024, ADDI{Rd{9}, Rs{2}, 8}},
+  {0x4488, LW{Rd{10}, Rs{9}, 8}},
+  {0x6488, LD{Rd{10}, Rs{9}, 8}},
+  {0xC488, SW{Rs{9}, Rs{10}, 8}},
+  {0xE488, SD{Rs{9}, Rs{10}, 8}},
+  {0x1001, NOP{0x1001}},
+  {0x1085, ADDI{Rd{1}, Rs{1}, uint32_t(-31)}},
+  {0x2081, ADDIW{Rd{1}, Rs{1}, 0}},
+  // ADDI16SP here, decode as ADDI
+  {0x7101, ADDI{Rd{2}, Rs{2}, uint32_t(-512)}},
+  {0x4081, ADDI{Rd{1}, Rs{0}, 0}},
+  {0x7081, LUI{Rd{1}, uint32_t(-131072)}},
+  {0x8085, SRLI{Rd{9}, Rs{9}, 1}},
+  {0x8485, SRAI{Rd{9}, Rs{9}, 1}},
+  {0x8881, ANDI{Rd{9}, Rs{9}, 0}},
+  {0x8C85, SUB{Rd{9}, Rs{9}, Rs{9}}},
+  {0x8CA5, XOR{Rd{9}, Rs{9}, Rs{9}}},
+  {0x8CC5, OR{Rd{9}, Rs{9}, Rs{9}}},
+  {0x8CE5, AND{Rd{9}, Rs{9}, Rs{9}}},
+  {0x9C85, SUBW{Rd{9}, Rs{9}, Rs{9}}},
+  {0x9CA5, ADDW{Rd{9}, Rs{9}, Rs{9}}},
+  // C.J here, decoded as JAL
+  {0xA001, JAL{Rd{0}, 0}},
+  {0xC081, B{Rs{9}, Rs{0}, 0, 0b000}},
+  {0xE081, B{Rs{9}, Rs{0}, 0, 0b001}},
+  {0x1082, SLLI{Rd{1}, Rs{1}, 32}},
+  {0x1002, HINT{0x1002}},
+  // SLLI64 here, decoded as HINT if not in RV128
+  {0x0082, HINT{0x0082}},
+  // LWSP here, decoded as LW
+  {0x4082, LW{Rd{1}, Rs{2}, 0}},
+  // LDSP here, decoded as LD
+  {0x6082, LD{Rd{1}, Rs{2}, 0}},
+  // C.JR here, decoded as JALR
+  {0x8082, JALR{Rd{0}, Rs{1}, 0}},
+  // C.MV here, decoded as ADD
+  {0x8086, ADD{Rd{1}, Rs{0}, Rs{1}}},
+  {0x9002, EBREAK{0x9002}},
+  {0x9082, JALR{Rd{1}, Rs{1}, 0}},
+  {0x9086, ADD{Rd{1}, Rs{1}, Rs{1}}},
+  // C.SWSP here, decoded as SW
+  {0xC006, SW{Rs{2}, Rs{1}, 0}},
+  // C.SDSP here, decoded as SD
+  {0xE006, SD{Rs{2}, Rs{1}, 0}},
+  };
+
+  for (auto i : tests) {
+auto decode = this->Decode(i.inst);
+ASSERT_TRUE(decode.has_value());
+ASSERT_TRUE(compareInst(decode->decoded, i.inst_type));
+  }
+}
+
 // GEN_BRANCH_TEST(opcode, imm1, imm2, imm3):
 // It should branch for instruction `opcode imm1, imm2`
 // It should do nothing for instruction `opcode imm1, imm3`
@@ -274,7 +356,6 @@
 };
 
 TEST_F(RISCVEmulatorTester, TestDecodeAndExcute) {
-
   std::vector tests = {
   // RV32I & RV64I Tests
   {0x00010113, "ADDI", false, [](RS1 rs1, RS2, PC) { return rs1 + 0; }},
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -1929,8 +1929,14 @@
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64: {
 static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00}; // ebreak
-trap_opcode = g_riscv_opcode;
-trap_opcode_size = sizeof(g_riscv_opcode);
+static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90}; // c.ebreak
+if (arch.GetFlags() & ArchSpec::eRISCV_rvc) {
+  trap_opcode = g_riscv_opcode_c;
+  trap_opcode_size = sizeof(g_riscv_opcode_c);
+} else {
+  trap_opcode = g_riscv_opcode;
+  trap_opcode_size = sizeof(g_riscv_opcode);
+}
   } break;
 
   default:
Index: 

[Lldb-commits] [lldb] 05ae747 - [LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV

2022-10-25 Thread via lldb-commits

Author: Emmmer
Date: 2022-10-25T19:12:45+08:00
New Revision: 05ae747a5353811f93f5814f24d2335e6229d78a

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

LOG: [LLDB][RISCV] Add RV64C instruction support for EmulateInstructionRISCV

Add:

- RV64C instructions sets.
- corresponding unittests.
- `c.break` code for lldb and lldb-server

Fix:
- wrong decoding of imm in `DecodeSType`

Reviewed By: DavidSpickett

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

Added: 
lldb/source/Plugins/Instruction/RISCV/RISCVCInstructions.h

Modified: 
lldb/source/Host/common/NativeProcessProtocol.cpp
lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h
lldb/source/Target/Platform.cpp
lldb/unittests/Instruction/RISCV/TestRISCVEmulator.cpp

Removed: 




diff  --git a/lldb/source/Host/common/NativeProcessProtocol.cpp 
b/lldb/source/Host/common/NativeProcessProtocol.cpp
index 363699344146f..cdb59842e658b 100644
--- a/lldb/source/Host/common/NativeProcessProtocol.cpp
+++ b/lldb/source/Host/common/NativeProcessProtocol.cpp
@@ -503,9 +503,10 @@ 
NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
   static const uint8_t g_mips64_opcode[] = {0x00, 0x00, 0x00, 0x0d};
   static const uint8_t g_mips64el_opcode[] = {0x0d, 0x00, 0x00, 0x00};
   static const uint8_t g_s390x_opcode[] = {0x00, 0x01};
-  static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08}; // trap
+  static const uint8_t g_ppc_opcode[] = {0x7f, 0xe0, 0x00, 0x08};   // trap
   static const uint8_t g_ppcle_opcode[] = {0x08, 0x00, 0xe0, 0x7f}; // trap
   static const uint8_t g_riscv_opcode[] = {0x73, 0x00, 0x10, 0x00}; // ebreak
+  static const uint8_t g_riscv_opcode_c[] = {0x02, 0x90};   // c.ebreak
 
   switch (GetArchitecture().GetMachine()) {
   case llvm::Triple::aarch64:
@@ -535,8 +536,10 @@ 
NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode(size_t size_hint) {
 return llvm::makeArrayRef(g_ppcle_opcode);
 
   case llvm::Triple::riscv32:
-  case llvm::Triple::riscv64:
-return llvm::makeArrayRef(g_riscv_opcode);
+  case llvm::Triple::riscv64: {
+return size_hint == 2 ? llvm::makeArrayRef(g_riscv_opcode_c)
+  : llvm::makeArrayRef(g_riscv_opcode);
+  }
 
   default:
 return llvm::createStringError(llvm::inconvertibleErrorCode(),

diff  --git a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp 
b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
index 8d1a4c999e8f8..1d8f3a2750277 100644
--- a/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
+++ b/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp
@@ -6,11 +6,10 @@
 //
 
//===--===//
 
-#include 
-
 #include "EmulateInstructionRISCV.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_riscv64.h"
 #include "Plugins/Process/Utility/lldb-riscv-register-enums.h"
+#include "RISCVCInstructions.h"
 #include "RISCVInstructions.h"
 
 #include "lldb/Core/Address.h"
@@ -86,8 +85,8 @@ constexpr uint32_t DecodeBImm(uint32_t inst) {
 }
 
 constexpr uint32_t DecodeSImm(uint32_t inst) {
-  return (uint64_t(int64_t(int32_t(inst & 0xFE0)) >> 20)) // imm[11:5]
- | ((inst & 0xF80) >> 7); // imm[4:0]
+  return (uint64_t(int64_t(int32_t(inst & 0xFE00)) >> 20)) // imm[11:5]
+ | ((inst & 0xF80) >> 7);  // imm[4:0]
 }
 
 constexpr uint32_t DecodeUImm(uint32_t inst) {
@@ -194,14 +193,14 @@ LoadStoreAddr(EmulateInstructionRISCV , I inst) {
 }
 
 // Read T from memory, then load its sign-extended value m_emu to register.
-template 
+template 
 static std::enable_if_t, bool>
-Load(EmulateInstructionRISCV , I inst, uint64_t (*extend)(m_emu)) {
+Load(EmulateInstructionRISCV , I inst, uint64_t (*extend)(E)) {
   auto addr = LoadStoreAddr(emulator, inst);
   if (!addr)
 return false;
   return emulator.ReadMem(*addr)
-  .transform([&](T t) { return inst.rd.Write(emulator, extend(m_emu(t))); 
})
+  .transform([&](T t) { return inst.rd.Write(emulator, extend(E(t))); })
   .value_or(false);
 }
 
@@ -461,6 +460,38 @@ static const InstrPattern PATTERNS[] = {
 {"AMOMAX_D", 0xF800707F, 0xA000302F, DecodeRType},
 {"AMOMINU_D", 0xF800707F, 0xC000302F, DecodeRType},
 {"AMOMAXU_D", 0xF800707F, 0xE000302F, DecodeRType},
+
+// RVC (Compressed Instructions) //
+{"C_LWSP", 0xE003, 0x4002, DecodeC_LWSP},
+{"C_LDSP", 0xE003, 0x6002, DecodeC_LDSP},
+{"C_SWSP", 0xE003, 0xC002, DecodeC_SWSP},
+{"C_SDSP", 0xE003, 0xE002, DecodeC_SDSP},
+{"C_LW", 0xE003, 0x4000, DecodeC_LW},
+{"C_LD", 0xE003, 0x6000, 

[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread Xi Ruoyao via Phabricator via lldb-commits
xry111 added inline comments.



Comment at: 
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h:26
+public:
+  struct GPR {
+uint64_t gpr[32];

SixWeining wrote:
> Why is this structure and below `FPR` defined like this? Do you intent to 
> keep the layout same as some structures of Linux? If yes, is it necessary?
It seems necessary because lldb invokes `ptrace` system call which directly 
stores into the pointer returned by `GetGPRBuffer`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [lldb] 3d9bf8c - [LLDB] Add missing breaks to current frame row in command map

2022-10-25 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2022-10-25T10:20:07Z
New Revision: 3d9bf8ce7bdf96f8b3cd9ed8b5ec696f537cc8de

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

LOG: [LLDB] Add missing breaks to current frame row in command map

Without these it was rendering as one line for all three commands.

Added: 


Modified: 
lldb/docs/use/map.rst

Removed: 




diff  --git a/lldb/docs/use/map.rst b/lldb/docs/use/map.rst
index 0447b24a88ae..fd02fb8ac15c 100644
--- a/lldb/docs/use/map.rst
+++ b/lldb/docs/use/map.rst
@@ -419,7 +419,9 @@ Execution Commands


   (lldb) frame select
+  
   (lldb) f
+  
   (lldb) process status

  



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


[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread Lu Weining via Phabricator via lldb-commits
SixWeining added inline comments.



Comment at: 
lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h:26
+public:
+  struct GPR {
+uint64_t gpr[32];

Why is this structure and below `FPR` defined like this? Do you intent to keep 
the layout same as some structures of Linux? If yes, is it necessary?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [PATCH] D135622: [lldb] Add a "diagnostics dump" command

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added inline comments.



Comment at: lldb/source/Utility/Diagnostics.cpp:70
 
-  Error error = Create(FileSpec(diagnostics_dir.str()));
+  Error error = Create(*diagnostics_dir);
   if (error) {

JDevlieghere wrote:
> DavidSpickett wrote:
> > Silly question, is it intentional that we write out files after saying they 
> > have been written?
> > 
> > Of course it makes sense to print something up front, otherwise the error 
> > here would come out of the blue, but perhaps "LLDB diagnostics will be 
> > written to..." instead?
> > 
> > (this is probably better changed in that earlier patch not sure if that 
> > went in yet)
> Yes, that was @labath's suggestion because when we call this from the signal 
> handler, we might crash again in the process and wouldn't print anything at 
> all. 
Maybe I can be clearer:
```
LLDB diagnostics written to <...>
Please include the directory content when filing a bug report

```

So the files haven't been written, or at least they are in an undefined state, 
but the output looks like we finished writing them. So `will be written` is 
more accurate. If I see this in a test log file I'm going to wonder did it 
crash writing them or did it already write them, which means I'd have to 
reproduce locally. With the sequence of events clearer, I can at least check 
obvious things like a full disk before needing to do that.

Small thing but it's a few words might save some annoyance down the road.

(printing up front I agree with, that part is good)


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

https://reviews.llvm.org/D135622

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


[Lldb-commits] [PATCH] D136578: [LLDB] [LoongArch] Add minimal LoongArch support

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett accepted this revision.
DavidSpickett added a comment.
This revision is now accepted and ready to land.

This LGTM from the lldb side.

Feel free to upload a series of patches in future if you want. You don't have 
to do one at a time, just update the whole stack as needed. Plus it gives the 
reviewers some context of what the changes are working towards.

Do you have commit access? If not it's fine to wait until you have 
(https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access), or 
someone else can land on your behalf. Just provide a name and email address 
you'd like to be on the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136578

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


[Lldb-commits] [PATCH] D136648: [lldb] Emit diagnostic events in the diagnostic dump

2022-10-25 Thread Pavel Labath via Phabricator via lldb-commits
labath accepted this revision.
labath added a comment.
This revision is now accepted and ready to land.

(Unsurprisingly, I guess), this looks much better to me. And I'm totally open 
to automatically logging these diagnostics somewhere as well (to a dedicated 
log channel/category, or by passing the log as an argument, or something else).




Comment at: lldb/source/Utility/Diagnostics.cpp:92
+
+llvm::Error Diagnostics::DumpAlwaysOnLog(const FileSpec ) const {
+  FileSpec log_file = dir.CopyByAppendingPathComponent("diagnostics.log");

Maybe call this DumpDiangosticsLog ?


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

https://reviews.llvm.org/D136648

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


[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread Luka Markušić via Phabricator via lldb-commits
mark2185 updated this revision to Diff 470421.
mark2185 added a comment.

Make remote-android local ports configurable

The local ports for `platform connect` and `attach` were always random, this 
allows the user to configure them.
This is useful for debugging a truly remote android (when the android in 
question is connected to a remote server).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

Files:
  lldb/docs/use/remote.rst
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h

Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -49,7 +49,8 @@
 
   void DeleteForwardPort(lldb::pid_t pid);
 
-  Status MakeConnectURL(const lldb::pid_t pid, const uint16_t remote_port,
+  Status MakeConnectURL(const lldb::pid_t pid, const uint16_t local_port,
+const uint16_t remote_port,
 llvm::StringRef remote_socket_name,
 std::string _url);
 
Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -90,8 +90,13 @@
 
   Log *log = GetLog(LLDBLog::Platform);
 
-  auto error =
-  MakeConnectURL(pid, remote_port, socket_name.c_str(), connect_url);
+  uint16_t local_port = 0;
+  const char *gdbstub_port = std::getenv("ANDROID_PLATFORM_LOCAL_GDB_PORT");
+  if (gdbstub_port)
+local_port = std::stoi(gdbstub_port);
+
+  auto error = MakeConnectURL(pid, local_port, remote_port, socket_name.c_str(),
+  connect_url);
   if (error.Success() && log)
 LLDB_LOGF(log, "gdbserver connect URL: %s", connect_url.c_str());
 
@@ -126,10 +131,15 @@
   else if (parsed_url->scheme == "unix-abstract-connect")
 m_socket_namespace = AdbClient::UnixSocketNamespaceAbstract;
 
+  uint16_t local_port = 0;
+  const char *platform_local_port = std::getenv("ANDROID_PLATFORM_LOCAL_PORT");
+  if (platform_local_port)
+local_port = std::stoi(platform_local_port);
+
   std::string connect_url;
-  auto error =
-  MakeConnectURL(g_remote_platform_pid, parsed_url->port.value_or(0),
- parsed_url->path, connect_url);
+  auto error = MakeConnectURL(g_remote_platform_pid, local_port,
+  parsed_url->port.value_or(0), parsed_url->path,
+  connect_url);
 
   if (error.Fail())
 return error;
@@ -170,11 +180,28 @@
 }
 
 Status PlatformAndroidRemoteGDBServer::MakeConnectURL(
-const lldb::pid_t pid, const uint16_t remote_port,
-llvm::StringRef remote_socket_name, std::string _url) {
+const lldb::pid_t pid, const uint16_t local_port,
+const uint16_t remote_port, llvm::StringRef remote_socket_name,
+std::string _url) {
   static const int kAttempsNum = 5;
 
   Status error;
+
+  auto forward = [&](const uint16_t local, const uint16_t remote) {
+error = ForwardPortWithAdb(local, remote, remote_socket_name,
+   m_socket_namespace, m_device_id);
+if (error.Success()) {
+  m_port_forwards[pid] = local;
+  std::ostringstream url_str;
+  url_str << "connect://127.0.0.1:" << local;
+  connect_url = url_str.str();
+}
+return error;
+  };
+
+  if (local_port != 0)
+return forward(local_port, remote_port);
+
   // There is a race possibility that somebody will occupy a port while we're
   // in between FindUnusedPort and ForwardPortWithAdb - adding the loop to
   // mitigate such problem.
@@ -184,15 +211,8 @@
 if (error.Fail())
   return error;
 
-error = ForwardPortWithAdb(local_port, remote_port, remote_socket_name,
-   m_socket_namespace, m_device_id);
-if (error.Success()) {
-  m_port_forwards[pid] = local_port;
-  std::ostringstream url_str;
-  url_str << "connect://127.0.0.1:" << local_port;
-  connect_url = url_str.str();
+if (forward(local_port, remote_port).Success())
   break;
-}
   }
 
   return error;
@@ -216,7 +236,7 @@
   }
 
   std::string new_connect_url;
-  error = MakeConnectURL(s_remote_gdbserver_fake_pid--,
+  error = MakeConnectURL(s_remote_gdbserver_fake_pid--, 0,
  parsed_url->port.value_or(0), parsed_url->path,
  new_connect_url);
   if (error.Fail())
Index: lldb/docs/use/remote.rst
===
--- lldb/docs/use/remote.rst
+++ 

[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Yes, somehow, and yes just update again.

Happens to us all, I have learned to not try to be clever with arc and just 
keep one commit per review.

Tip: if you look in the "Revision Contents" box there is a "history" and you 
can diff between versions of the patch, if you're ever not sure of what 
actually changed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

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


[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread Luka Markušić via Phabricator via lldb-commits
mark2185 marked 2 inline comments as done.
mark2185 added a comment.

Did I just overwrite the initial commit with a new one, instead of just 
creating a diff based on the two comments?

I'm terribly sorry, should I just squash my two commits and run `arc diff 
--update=D136465` again?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

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


[Lldb-commits] [PATCH] D136465: Make remote-android local ports configurable

2022-10-25 Thread Luka Markušić via Phabricator via lldb-commits
mark2185 updated this revision to Diff 470381.
mark2185 added a comment.

Remove {} for single line if statements per LLVM coding guidelines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136465

Files:
  lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp


Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -92,9 +92,8 @@
 
   uint16_t local_port = 0;
   const char *gdbstub_port = std::getenv("ANDROID_PLATFORM_LOCAL_GDB_PORT");
-  if (gdbstub_port) {
+  if (gdbstub_port)
 local_port = std::stoi(gdbstub_port);
-  }
 
   auto error = MakeConnectURL(pid, local_port, remote_port, 
socket_name.c_str(),
   connect_url);
@@ -134,9 +133,8 @@
 
   uint16_t local_port = 0;
   const char *platform_local_port = std::getenv("ANDROID_PLATFORM_LOCAL_PORT");
-  if (platform_local_port) {
+  if (platform_local_port)
 local_port = std::stoi(platform_local_port);
-  }
 
   std::string connect_url;
   auto error = MakeConnectURL(g_remote_platform_pid, local_port,
@@ -201,9 +199,8 @@
 return error;
   };
 
-  if (local_port != 0) {
+  if (local_port != 0)
 return forward(local_port, remote_port);
-  }
 
   // There is a race possibility that somebody will occupy a port while we're
   // in between FindUnusedPort and ForwardPortWithAdb - adding the loop to
@@ -214,9 +211,8 @@
 if (error.Fail())
   return error;
 
-if (forward(local_port, remote_port).Success()) {
+if (forward(local_port, remote_port).Success())
   break;
-}
   }
 
   return error;


Index: lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
===
--- lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -92,9 +92,8 @@
 
   uint16_t local_port = 0;
   const char *gdbstub_port = std::getenv("ANDROID_PLATFORM_LOCAL_GDB_PORT");
-  if (gdbstub_port) {
+  if (gdbstub_port)
 local_port = std::stoi(gdbstub_port);
-  }
 
   auto error = MakeConnectURL(pid, local_port, remote_port, socket_name.c_str(),
   connect_url);
@@ -134,9 +133,8 @@
 
   uint16_t local_port = 0;
   const char *platform_local_port = std::getenv("ANDROID_PLATFORM_LOCAL_PORT");
-  if (platform_local_port) {
+  if (platform_local_port)
 local_port = std::stoi(platform_local_port);
-  }
 
   std::string connect_url;
   auto error = MakeConnectURL(g_remote_platform_pid, local_port,
@@ -201,9 +199,8 @@
 return error;
   };
 
-  if (local_port != 0) {
+  if (local_port != 0)
 return forward(local_port, remote_port);
-  }
 
   // There is a race possibility that somebody will occupy a port while we're
   // in between FindUnusedPort and ForwardPortWithAdb - adding the loop to
@@ -214,9 +211,8 @@
 if (error.Fail())
   return error;
 
-if (forward(local_port, remote_port).Success()) {
+if (forward(local_port, remote_port).Success())
   break;
-}
   }
 
   return error;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits