[Lldb-commits] [PATCH] D156483: [lldb] Support CTF forward declarations

2023-07-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c70a3d9178f: [lldb] Support CTF forward declarations 
(authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D156483?vs=544925&id=545324#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156483

Files:
  lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
  lldb/test/API/macosx/ctf/test.c

Index: lldb/test/API/macosx/ctf/test.c
===
--- lldb/test/API/macosx/ctf/test.c
+++ lldb/test/API/macosx/ctf/test.c
@@ -1,5 +1,7 @@
 #include 
 
+struct ForwardDecl;
+
 typedef int MyInt;
 
 void populate(MyInt i);
@@ -30,6 +32,7 @@
 } MyStructT;
 
 MyStructT foo;
+struct ForwardDecl *forward;
 
 void populate(MyInt i) {
   foo.n.i = i;
@@ -41,6 +44,7 @@
   foo.n.a[3] = 'd';
   foo.n.e = eOne;
   foo.f = NULL;
+  forward = NULL;
 }
 
 int main(int argc, char** argv) {
Index: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
===
--- lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
+++ lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
@@ -225,6 +225,7 @@
   llvm::Expected CreateEnum(const CTFEnum &ctf_enum);
   llvm::Expected CreateFunction(const CTFFunction &ctf_function);
   llvm::Expected CreateRecord(const CTFRecord &ctf_record);
+  llvm::Expected CreateForward(const CTFForward &ctf_forward);
 
   llvm::StringRef ReadString(lldb::offset_t offset) const;
 
Index: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
===
--- lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -525,6 +525,17 @@
   decl, record_type, lldb_private::Type::ResolveState::Full);
 }
 
+llvm::Expected
+SymbolFileCTF::CreateForward(const CTFForward &ctf_forward) {
+  CompilerType forward_compiler_type = m_ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), eAccessPublic, ctf_forward.name,
+  clang::TTK_Struct, eLanguageTypeC);
+  Declaration decl;
+  return MakeType(ctf_forward.uid, ConstString(ctf_forward.name), 0, nullptr,
+  LLDB_INVALID_UID, Type::eEncodingIsUID, decl,
+  forward_compiler_type, Type::ResolveState::Forward);
+}
+
 llvm::Expected SymbolFileCTF::CreateType(CTFType *ctf_type) {
   if (!ctf_type)
 return llvm::make_error(
@@ -549,9 +560,10 @@
   case CTFType::Kind::eStruct:
   case CTFType::Kind::eUnion:
 return CreateRecord(*static_cast(ctf_type));
+  case CTFType::Kind::eForward:
+return CreateForward(*static_cast(ctf_type));
   case CTFType::Kind::eUnknown:
   case CTFType::Kind::eFloat:
-  case CTFType::Kind::eForward:
   case CTFType::Kind::eSlice:
 return llvm::make_error(
 llvm::formatv("unsupported type (uid = {0}, name = {1}, kind = {2})",
@@ -637,11 +649,12 @@
 return std::make_unique(static_cast(kind), uid,
name, variable_length, size, fields);
   }
+  case TypeKind::eForward:
+return std::make_unique(uid, name);
   case TypeKind::eUnknown:
 return std::make_unique(static_cast(kind), uid,
  name);
   case TypeKind::eFloat:
-  case TypeKind::eForward:
   case TypeKind::eSlice:
 offset += (variable_length * sizeof(uint32_t));
 break;
Index: lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
===
--- lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
+++ lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
@@ -163,6 +163,11 @@
   : CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
 };
 
+struct CTFForward : public CTFType {
+  CTFForward(lldb::user_id_t uid, llvm::StringRef name)
+  : CTFType(eForward, uid, name) {}
+};
+
 } // namespace lldb_private
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 9c70a3d - [lldb] Support CTF forward declarations

2023-07-28 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2023-07-28T19:10:36-07:00
New Revision: 9c70a3d9178f46c3eccb2243286deb1830c276f4

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

LOG: [lldb] Support CTF forward declarations

Add support for parsing CTF forward declarations and converting them
into LLDB types.

Differential revision: https://reviews.llvm.org/D156483

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
lldb/test/API/macosx/ctf/test.c

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h 
b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
index 8c6ee278bbe356..b2cf5cf3191b64 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
+++ b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
@@ -163,6 +163,11 @@ struct CTFUnion : public CTFRecord {
   : CTFRecord(eUnion, uid, name, nfields, size, std::move(fields)){};
 };
 
+struct CTFForward : public CTFType {
+  CTFForward(lldb::user_id_t uid, llvm::StringRef name)
+  : CTFType(eForward, uid, name) {}
+};
+
 } // namespace lldb_private
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H

diff  --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp 
b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
index 2798bc674471e1..f737db3ed4e4b2 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
@@ -525,6 +525,17 @@ SymbolFileCTF::CreateRecord(const CTFRecord &ctf_record) {
   decl, record_type, lldb_private::Type::ResolveState::Full);
 }
 
+llvm::Expected
+SymbolFileCTF::CreateForward(const CTFForward &ctf_forward) {
+  CompilerType forward_compiler_type = m_ast->CreateRecordType(
+  nullptr, OptionalClangModuleID(), eAccessPublic, ctf_forward.name,
+  clang::TTK_Struct, eLanguageTypeC);
+  Declaration decl;
+  return MakeType(ctf_forward.uid, ConstString(ctf_forward.name), 0, nullptr,
+  LLDB_INVALID_UID, Type::eEncodingIsUID, decl,
+  forward_compiler_type, Type::ResolveState::Forward);
+}
+
 llvm::Expected SymbolFileCTF::CreateType(CTFType *ctf_type) {
   if (!ctf_type)
 return llvm::make_error(
@@ -549,9 +560,10 @@ llvm::Expected SymbolFileCTF::CreateType(CTFType 
*ctf_type) {
   case CTFType::Kind::eStruct:
   case CTFType::Kind::eUnion:
 return CreateRecord(*static_cast(ctf_type));
+  case CTFType::Kind::eForward:
+return CreateForward(*static_cast(ctf_type));
   case CTFType::Kind::eUnknown:
   case CTFType::Kind::eFloat:
-  case CTFType::Kind::eForward:
   case CTFType::Kind::eSlice:
 return llvm::make_error(
 llvm::formatv("unsupported type (uid = {0}, name = {1}, kind = {2})",
@@ -637,11 +649,12 @@ SymbolFileCTF::ParseType(lldb::offset_t &offset, 
lldb::user_id_t uid) {
 return std::make_unique(static_cast(kind), uid,
name, variable_length, size, fields);
   }
+  case TypeKind::eForward:
+return std::make_unique(uid, name);
   case TypeKind::eUnknown:
 return std::make_unique(static_cast(kind), uid,
  name);
   case TypeKind::eFloat:
-  case TypeKind::eForward:
   case TypeKind::eSlice:
 offset += (variable_length * sizeof(uint32_t));
 break;

diff  --git a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h 
b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
index 73854275ff674b..f5a78e5b59a908 100644
--- a/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
+++ b/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
@@ -225,6 +225,7 @@ class SymbolFileCTF : public lldb_private::SymbolFileCommon 
{
   llvm::Expected CreateEnum(const CTFEnum &ctf_enum);
   llvm::Expected CreateFunction(const CTFFunction &ctf_function);
   llvm::Expected CreateRecord(const CTFRecord &ctf_record);
+  llvm::Expected CreateForward(const CTFForward &ctf_forward);
 
   llvm::StringRef ReadString(lldb::offset_t offset) const;
 

diff  --git a/lldb/test/API/macosx/ctf/test.c b/lldb/test/API/macosx/ctf/test.c
index a844a01f82a3db..30be60320c47ff 100644
--- a/lldb/test/API/macosx/ctf/test.c
+++ b/lldb/test/API/macosx/ctf/test.c
@@ -1,5 +1,7 @@
 #include 
 
+struct ForwardDecl;
+
 typedef int MyInt;
 
 void populate(MyInt i);
@@ -30,6 +32,7 @@ typedef struct MyStruct {
 } MyStructT;
 
 MyStructT foo;
+struct ForwardDecl *forward;
 
 void populate(MyInt i) {
   foo.n.i = i;
@@ -41,6 +44,7 @@ void populate(MyInt i) {
   foo.n.a[3] = 'd';
   foo.n.e = eOne;
   foo.f = NULL;
+  forward = NULL;
 }
 
 int main(int argc, char** argv) {



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

[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D156562#4543743 , @jasonmolenda 
wrote:

> This is fine to me but maybe instead of `ifndef apple` we could do a `if 
> __has_include()` and include the system header if it's avail.

One reason I decided not to do this is because I don't want to accidentally 
pull in a different `uuid.h` on other platforms that may have an incompatible 
`uuid_t` definition. I'm not sure what other definition it may have that would 
make it incompatible, but it might be a headache to figure that out.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

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


[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Alex Langford via Phabricator via lldb-commits
bulbazord updated this revision to Diff 545289.
bulbazord added a comment.

Fix incorrect includes that @jasonmolenda pointed out


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

Files:
  lldb/include/lldb/Utility/AppleUuidCompatibility.h
  lldb/source/Expression/ObjectFileJIT.cpp
  lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Utility/UuidCompatibility.h

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -63,7 +63,7 @@
 #endif
 
 #ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
+#include "lldb/Utility/AppleUuidCompatibility.h"
 #else
 #include 
 #endif
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -40,7 +40,7 @@
 #endif
 
 #ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
+#include "lldb/Utility/AppleUuidCompatibility.h"
 #else
 #include 
 #endif
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
===
--- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -43,12 +43,6 @@
 #define DEBUG_PRINTF(fmt, ...)
 #endif
 
-#ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
-#else
-#include 
-#endif
-
 #include 
 
 using namespace lldb;
Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
===
--- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -7,7 +7,6 @@
 //===--===//
 
 #include "lldb/Host/macosx/HostInfoMacOSX.h"
-#include "Utility/UuidCompatibility.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
@@ -32,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 // Objective-C/C++ includes
 #include 
Index: lldb/source/Expression/ObjectFileJIT.cpp
===
--- lldb/source/Expression/ObjectFileJIT.cpp
+++ lldb/source/Expression/ObjectFileJIT.cpp
@@ -25,10 +25,6 @@
 #include "lldb/Utility/Timer.h"
 #include "lldb/Utility/UUID.h"
 
-#ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
-#endif
-
 using namespace lldb;
 using namespace lldb_private;
 
Index: lldb/include/lldb/Utility/AppleUuidCompatibility.h
===
--- lldb/include/lldb/Utility/AppleUuidCompatibility.h
+++ lldb/include/lldb/Utility/AppleUuidCompatibility.h
@@ -6,20 +6,11 @@
 //
 //===--===//
 
-// Include this header if your system does not have a definition of uuid_t
+// Include this header for a definition of uuid_t compatible with Darwin's
+// definition.
 
 #ifndef utility_UUID_COMPATIBILITY_H
 #define utility_UUID_COMPATIBILITY_H
-
 // uuid_t is guaranteed to always be a 16-byte array
 typedef unsigned char uuid_t[16];
-
-// Return 1 if uuid is null, that is, all zeroes.
-inline __attribute__((always_inline)) int uuid_is_null(uuid_t uuid) {
-  for (int i = 0; i < 16; i++)
-if (uuid[i])
-  return 0;
-  return 1;
-}
-
 #endif // utility_UUID_COMPATIBILITY_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

In D156562#4543743 , @jasonmolenda 
wrote:

> This is fine to me but maybe instead of `ifndef apple` we could do a `if 
> __has_include()` and include the system header if it's avail.  I 
> must be misreading the patch but it seems like you're changing the filename 
> to AppleUuidCompatbility.h but the two places it's included still call it 
> UuidCompatibility.h.

You're not reading it wrong, that was just my mistake. I built this on a Darwin 
machine so that codepath never ran... Good catch!

> The uuid_is_null is probably my fault, I think I had something that I had a 
> uuid_t that I didn't want to turn in to a "valid" UUID object when I assigned 
> the bytes, and either I misunderstood the contract or I used the wrong one 
> and once I fixed that, I didn't need the test any more.

Thanks for the context 👍


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

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


[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda added a comment.

This is fine to me but maybe instead of `ifndef apple` we could do a `if 
__has_include()` and include the system header if it's avail.  I 
must be misreading the patch but it seems like you're changing the filename to 
AppleUuidCompatbility.h but the two places it's included still call it 
UuidCompatibility.h.

The uuid_is_null is probably my fault, I think I had something that I had a 
uuid_t that I didn't want to turn in to a "valid" UUID object when I assigned 
the bytes, and either I misunderstood the contract or I used the wrong one and 
once I fixed that, I didn't need the test any more.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

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


[Lldb-commits] [PATCH] D156493: [lldb-vsocde] Adding support for the "disassemble" request.

2023-07-28 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 545278.
ashgti added a comment.

Adjusting the unit test to only check 2 frames instead of 3 and adjusted the 
assertions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156493

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/coreFile/TestVSCode_coreFile.py
  lldb/test/API/tools/lldb-vscode/disassemble/Makefile
  lldb/test/API/tools/lldb-vscode/disassemble/TestVSCode_disassemble.py
  lldb/test/API/tools/lldb-vscode/disassemble/main.c
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/SourceReference.h
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.h
  lldb/tools/lldb-vscode/VSCodeForward.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
@@ -50,6 +50,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
@@ -1563,6 +1564,8 @@
   body.try_emplace("supportsStepInTargetsRequest", false);
   // The debug adapter supports the completions request.
   body.try_emplace("supportsCompletionsRequest", true);
+  // The debug adapter supports the disassembly request.
+  body.try_emplace("supportsDisassembleRequest", true);
 
   llvm::json::Array completion_characters;
   completion_characters.emplace_back(".");
@@ -2588,18 +2591,7 @@
 void request_source(const llvm::json::Object &request) {
   llvm::json::Object response;
   FillResponse(request, response);
-  llvm::json::Object body;
-
-  auto arguments = request.getObject("arguments");
-  auto source = arguments->getObject("source");
-  auto sourceReference = GetSigned(source, "sourceReference", -1);
-  auto pos = g_vsc.source_map.find((lldb::addr_t)sourceReference);
-  if (pos != g_vsc.source_map.end()) {
-EmplaceSafeString(body, "content", pos->second.content);
-  } else {
-response["success"] = llvm::json::Value(false);
-  }
-  EmplaceSafeString(body, "mimeType", "text/x-lldb.disassembly");
+  llvm::json::Object body{{"content", ""}};
   response.try_emplace("body", std::move(body));
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
@@ -3290,6 +3282,211 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
 
+// "DisassembleRequest": {
+//   "allOf": [ { "$ref": "#/definitions/Request" }, {
+// "type": "object",
+// "description": "Disassembles code stored at the provided
+// location.\nClients should only call this request if the corresponding
+// capability `supportsDisassembleRequest` is true.", "properties": {
+//   "command": {
+// "type": "string",
+// "enum": [ "disassemble" ]
+//   },
+//   "arguments": {
+// "$ref": "#/definitions/DisassembleArguments"
+//   }
+// },
+// "required": [ "command", "arguments" ]
+//   }]
+// },
+// "DisassembleArguments": {
+//   "type": "object",
+//   "description": "Arguments for `disassemble` request.",
+//   "properties": {
+// "memoryReference": {
+//   "type": "string",
+//   "description": "Memory reference to the base location containing the
+//   instructions to disassemble."
+// },
+// "offset": {
+//   "type": "integer",
+//   "description": "Offset (in bytes) to be applied to the reference
+//   location before disassembling. Can be negative."
+// },
+// "instructionOffset": {
+//   "type": "integer",
+//   "description": "Offset (in instructions) to be applied after the byte
+//   offset (if any) before disassembling. Can be negative."
+// },
+// "instructionCount": {
+//   "type": "integer",
+//   "description": "Number of instructions to disassemble starting at the
+//   specified location and offset.\nAn adapter must return exactly this
+//   number of instructions - any unavailable instructions should be
+//   replaced with an implementation-defined 'invalid instruction' value."
+// },
+// "resolveSymbols": {
+//   "type": "boolean",
+//   "description": "If true, the adapter should attempt to resolve memory
+//   addresses and other values to symbolic names."
+// }
+//   },
+//   "required": [ "memoryReference", "instructionCount" ]
+// },
+// "DisassembleResponse": {
+//   "allOf": [ { "$ref": "#/definitions/Response" }, {
+// "type": "object",
+// "description": "Response to `disassemble` request.",
+// "properties": {
+//   "body": {
+// "type": "object",
+// "properties": {
+//  

[Lldb-commits] [lldb] 1bf6f55 - [lldb-vscode] Adding support for displaying backtraces.

2023-07-28 Thread David Goldman via lldb-commits

Author: John Harrison
Date: 2023-07-28T16:54:27-04:00
New Revision: 1bf6f55911ca6427789093b1df8a63d7e72dac51

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

LOG: [lldb-vscode] Adding support for displaying backtraces.

On Apple platforms when debugging with libBacktraceRecording.dylib backtraces 
are stored as part of the thread stack. This change includes support for 
displaying the back traces when they are present in the stack trace.

To use this on macOS a binary needs to be run with the following environment 
variables configured:

DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/usr/lib/libBacktraceRecording.dylib
{F28473587}

Reviewed By: wallace

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

Added: 


Modified: 
lldb/tools/lldb-vscode/JSONUtils.cpp
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp 
b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 98dbba32b033e3..06359e1c76ff91 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -815,17 +815,30 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
 llvm::json::Value CreateThread(lldb::SBThread &thread) {
   llvm::json::Object object;
   object.try_emplace("id", (int64_t)thread.GetThreadID());
-  char thread_str[64];
-  snprintf(thread_str, sizeof(thread_str), "Thread #%u", thread.GetIndexID());
-  const char *name = thread.GetName();
-  if (name) {
-std::string thread_with_name(thread_str);
-thread_with_name += ' ';
-thread_with_name += name;
-EmplaceSafeString(object, "name", thread_with_name);
+  const char *thread_name = thread.GetName();
+  const char *queue_name = thread.GetQueueName();
+
+  std::string thread_str;
+  if (thread_name) {
+thread_str = std::string(thread_name);
+  } else if (queue_name) {
+auto kind = thread.GetQueue().GetKind();
+std::string queue_kind_label = "";
+if (kind == lldb::eQueueKindSerial) {
+  queue_kind_label = " (serial)";
+} else if (kind == lldb::eQueueKindConcurrent) {
+  queue_kind_label = " (concurrent)";
+}
+
+thread_str = llvm::formatv("Thread {0} Queue: {1}{2}", thread.GetIndexID(),
+   queue_name, queue_kind_label)
+ .str();
   } else {
-EmplaceSafeString(object, "name", std::string(thread_str));
+thread_str = llvm::formatv("Thread {0}", thread.GetIndexID()).str();
   }
+
+  EmplaceSafeString(object, "name", thread_str);
+
   return llvm::json::Value(std::move(object));
 }
 

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp 
b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 72ebe4825024e3..4421202566066f 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -2687,13 +2687,72 @@ void request_stackTrace(const llvm::json::Object 
&request) {
 const auto startFrame = GetUnsigned(arguments, "startFrame", 0);
 const auto levels = GetUnsigned(arguments, "levels", 0);
 const auto endFrame = (levels == 0) ? INT64_MAX : (startFrame + levels);
+auto totalFrames = thread.GetNumFrames();
+
+// This will always return an invalid thread when
+// libBacktraceRecording.dylib is not loaded or if there is no extended
+// backtrace.
+lldb::SBThread queue_backtrace_thread =
+thread.GetExtendedBacktraceThread("libdispatch");
+if (queue_backtrace_thread.IsValid()) {
+  // One extra frame as a label to mark the enqueued thread.
+  totalFrames += queue_backtrace_thread.GetNumFrames() + 1;
+}
+
+// This will always return an invalid thread when there is no exception in
+// the current thread.
+lldb::SBThread exception_backtrace_thread =
+thread.GetCurrentExceptionBacktrace();
+if (exception_backtrace_thread.IsValid()) {
+  // One extra frame as a label to mark the exception thread.
+  totalFrames += exception_backtrace_thread.GetNumFrames() + 1;
+}
+
 for (uint32_t i = startFrame; i < endFrame; ++i) {
-  auto frame = thread.GetFrameAtIndex(i);
+  lldb::SBFrame frame;
+  std::string prefix;
+  if (i < thread.GetNumFrames()) {
+frame = thread.GetFrameAtIndex(i);
+  } else if (queue_backtrace_thread.IsValid() &&
+ i < (thread.GetNumFrames() +
+  queue_backtrace_thread.GetNumFrames() + 1)) {
+if (i == thread.GetNumFrames()) {
+  const uint32_t thread_idx =
+  queue_backtrace_thread.GetExtendedBacktraceOriginatingIndexID();
+  const char *queue_name = queue_backtrace_thread.GetQueueName();
+  auto name = llvm::formatv("Enqueued from {0} (Thread {1})",
+   

[Lldb-commits] [PATCH] D156465: [lldb-vscode] Adding support for displaying backtraces.

2023-07-28 Thread David Goldman via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1bf6f55911ca: [lldb-vscode] Adding support for displaying 
backtraces. (authored by ashgti, committed by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156465

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  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
@@ -2687,13 +2687,72 @@
 const auto startFrame = GetUnsigned(arguments, "startFrame", 0);
 const auto levels = GetUnsigned(arguments, "levels", 0);
 const auto endFrame = (levels == 0) ? INT64_MAX : (startFrame + levels);
+auto totalFrames = thread.GetNumFrames();
+
+// This will always return an invalid thread when
+// libBacktraceRecording.dylib is not loaded or if there is no extended
+// backtrace.
+lldb::SBThread queue_backtrace_thread =
+thread.GetExtendedBacktraceThread("libdispatch");
+if (queue_backtrace_thread.IsValid()) {
+  // One extra frame as a label to mark the enqueued thread.
+  totalFrames += queue_backtrace_thread.GetNumFrames() + 1;
+}
+
+// This will always return an invalid thread when there is no exception in
+// the current thread.
+lldb::SBThread exception_backtrace_thread =
+thread.GetCurrentExceptionBacktrace();
+if (exception_backtrace_thread.IsValid()) {
+  // One extra frame as a label to mark the exception thread.
+  totalFrames += exception_backtrace_thread.GetNumFrames() + 1;
+}
+
 for (uint32_t i = startFrame; i < endFrame; ++i) {
-  auto frame = thread.GetFrameAtIndex(i);
+  lldb::SBFrame frame;
+  std::string prefix;
+  if (i < thread.GetNumFrames()) {
+frame = thread.GetFrameAtIndex(i);
+  } else if (queue_backtrace_thread.IsValid() &&
+ i < (thread.GetNumFrames() +
+  queue_backtrace_thread.GetNumFrames() + 1)) {
+if (i == thread.GetNumFrames()) {
+  const uint32_t thread_idx =
+  queue_backtrace_thread.GetExtendedBacktraceOriginatingIndexID();
+  const char *queue_name = queue_backtrace_thread.GetQueueName();
+  auto name = llvm::formatv("Enqueued from {0} (Thread {1})",
+queue_name, thread_idx);
+  stackFrames.emplace_back(
+  llvm::json::Object{{"id", thread.GetThreadID() + 1},
+ {"name", name},
+ {"presentationHint", "label"}});
+  continue;
+}
+frame = queue_backtrace_thread.GetFrameAtIndex(
+i - thread.GetNumFrames() - 1);
+  } else if (exception_backtrace_thread.IsValid()) {
+if (i == thread.GetNumFrames() +
+ (queue_backtrace_thread.IsValid()
+  ? queue_backtrace_thread.GetNumFrames() + 1
+  : 0)) {
+  stackFrames.emplace_back(
+  llvm::json::Object{{"id", thread.GetThreadID() + 2},
+ {"name", "Original Exception Backtrace"},
+ {"presentationHint", "label"}});
+  continue;
+}
+
+frame = exception_backtrace_thread.GetFrameAtIndex(
+i - thread.GetNumFrames() -
+(queue_backtrace_thread.IsValid()
+ ? queue_backtrace_thread.GetNumFrames() + 1
+ : 0));
+  }
   if (!frame.IsValid())
 break;
   stackFrames.emplace_back(CreateStackFrame(frame));
 }
-const auto totalFrames = thread.GetNumFrames();
+
 body.try_emplace("totalFrames", totalFrames);
   }
   body.try_emplace("stackFrames", std::move(stackFrames));
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -815,17 +815,30 @@
 llvm::json::Value CreateThread(lldb::SBThread &thread) {
   llvm::json::Object object;
   object.try_emplace("id", (int64_t)thread.GetThreadID());
-  char thread_str[64];
-  snprintf(thread_str, sizeof(thread_str), "Thread #%u", thread.GetIndexID());
-  const char *name = thread.GetName();
-  if (name) {
-std::string thread_with_name(thread_str);
-thread_with_name += ' ';
-thread_with_name += name;
-EmplaceSafeString(object, "name", thread_with_name);
+  const char *thread_name = thread.GetName();
+  const char *queue_name = thread.GetQueueName();
+
+  std::string thread_str;
+  if (thread_name) {
+thread_str = std::string(thread_name);
+  } else if (queue_name) {
+auto kind = thread.GetQueue().GetKind();
+std::string queue_kind_label = "";
+if (kind == lldb::eQueueKindSe

[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/include/lldb/Utility/AppleUuidCompatibility.h:15
 // uuid_t is guaranteed to always be a 16-byte array
 typedef unsigned char uuid_t[16];
 #endif // utility_UUID_COMPATIBILITY_H

mib wrote:
> May be this could be moved to `lldb-types.h` (if it's even used) so we can 
> remove the whole file ?
I thought about this but I went with this as a safer option. I'm not sure what 
definition of `uuid_t` other platforms provide (hopefully the same but I 
haven't verified). We really only use this definition in two places: 
ObjectFileMachO and DynamicLoaderMacOSXDYLD. In those places, we just need a 
compatible definition of `uuid_t`. Putting it in `lldb-types.h` would mean we 
would get that definition everywhere (even if it was already provided by the 
underlying system, excluding Darwin).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

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


[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/include/lldb/Utility/AppleUuidCompatibility.h:15
 // uuid_t is guaranteed to always be a 16-byte array
 typedef unsigned char uuid_t[16];
 #endif // utility_UUID_COMPATIBILITY_H

May be this could be moved to `lldb-types.h` (if it's even used) so we can 
remove the whole file ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156562

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


[Lldb-commits] [PATCH] D156562: [lldb] Clean up uses of UuidCompatibility.h

2023-07-28 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, jingham, jasonmolenda.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This commit does a few related things:

- Removes unused function `uuid_is_null`
- Removes unneeded includes of UuidCompatibility.h
- Renames UuidCompatibility to AppleUuidCompatibility and adds a comment to 
clarify intent of header.
- Moves AppleUuidCompatibility to the include directory


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156562

Files:
  lldb/include/lldb/Utility/AppleUuidCompatibility.h
  lldb/source/Expression/ObjectFileJIT.cpp
  lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
  lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/source/Utility/UuidCompatibility.h

Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -63,7 +63,7 @@
 #endif
 
 #ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
+#include "lldb/Utility/UuidCompatibility.h"
 #else
 #include 
 #endif
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
===
--- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -40,7 +40,7 @@
 #endif
 
 #ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
+#include "lldb/Utility/UuidCompatibility.h"
 #else
 #include 
 #endif
Index: lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
===
--- lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
+++ lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp
@@ -43,12 +43,6 @@
 #define DEBUG_PRINTF(fmt, ...)
 #endif
 
-#ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
-#else
-#include 
-#endif
-
 #include 
 
 using namespace lldb;
Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
===
--- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -7,7 +7,6 @@
 //===--===//
 
 #include "lldb/Host/macosx/HostInfoMacOSX.h"
-#include "Utility/UuidCompatibility.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/HostInfo.h"
@@ -32,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 // Objective-C/C++ includes
 #include 
Index: lldb/source/Expression/ObjectFileJIT.cpp
===
--- lldb/source/Expression/ObjectFileJIT.cpp
+++ lldb/source/Expression/ObjectFileJIT.cpp
@@ -25,10 +25,6 @@
 #include "lldb/Utility/Timer.h"
 #include "lldb/Utility/UUID.h"
 
-#ifndef __APPLE__
-#include "Utility/UuidCompatibility.h"
-#endif
-
 using namespace lldb;
 using namespace lldb_private;
 
Index: lldb/include/lldb/Utility/AppleUuidCompatibility.h
===
--- lldb/include/lldb/Utility/AppleUuidCompatibility.h
+++ lldb/include/lldb/Utility/AppleUuidCompatibility.h
@@ -6,20 +6,11 @@
 //
 //===--===//
 
-// Include this header if your system does not have a definition of uuid_t
+// Include this header for a definition of uuid_t compatible with Darwin's
+// definition.
 
 #ifndef utility_UUID_COMPATIBILITY_H
 #define utility_UUID_COMPATIBILITY_H
-
 // uuid_t is guaranteed to always be a 16-byte array
 typedef unsigned char uuid_t[16];
-
-// Return 1 if uuid is null, that is, all zeroes.
-inline __attribute__((always_inline)) int uuid_is_null(uuid_t uuid) {
-  for (int i = 0; i < 16; i++)
-if (uuid[i])
-  return 0;
-  return 1;
-}
-
 #endif // utility_UUID_COMPATIBILITY_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 0a5e0d3 - [lldb] Split CTF parsing and type creation (NFC)

2023-07-28 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2023-07-28T09:41:47-07:00
New Revision: 0a5e0d3fad8dfdebc8bb2f51f6008bdd41e27580

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

LOG: [lldb] Split CTF parsing and type creation (NFC)

Separate parsing CTF and creating LLDB types. This is a prerequisite to
parsing forward references and recursive types.

Differential revision: https://reviews.llvm.org/D156447

Added: 
lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h

Modified: 
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
lldb/test/API/macosx/ctf/TestCTF.py

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h 
b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
new file mode 100644
index 00..8c6ee278bbe356
--- /dev/null
+++ b/lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
@@ -0,0 +1,168 @@
+//===-- CTFTypes.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_SYMBOLFILE_CTF_CTFTYPES_H
+#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_CTFTYPES_H
+
+#include "lldb/lldb-types.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace lldb_private {
+
+struct CTFType {
+  enum Kind : uint32_t {
+eUnknown = 0,
+eInteger = 1,
+eFloat = 2,
+ePointer = 3,
+eArray = 4,
+eFunction = 5,
+eStruct = 6,
+eUnion = 7,
+eEnum = 8,
+eForward = 9,
+eTypedef = 10,
+eVolatile = 11,
+eConst = 12,
+eRestrict = 13,
+eSlice = 14,
+  };
+
+  Kind kind;
+  lldb::user_id_t uid;
+  llvm::StringRef name;
+
+  CTFType(Kind kind, lldb::user_id_t uid, llvm::StringRef name)
+  : kind(kind), uid(uid), name(name) {}
+};
+
+struct CTFInteger : public CTFType {
+  CTFInteger(lldb::user_id_t uid, llvm::StringRef name, uint32_t bits,
+ uint32_t encoding)
+  : CTFType(eInteger, uid, name), bits(bits), encoding(encoding) {}
+
+  uint32_t bits;
+  uint32_t encoding;
+};
+
+struct CTFModifier : public CTFType {
+protected:
+  CTFModifier(Kind kind, lldb::user_id_t uid, uint32_t type)
+  : CTFType(kind, uid, ""), type(type) {}
+
+public:
+  uint32_t type;
+};
+
+struct CTFPointer : public CTFModifier {
+  CTFPointer(lldb::user_id_t uid, uint32_t type)
+  : CTFModifier(ePointer, uid, type) {}
+};
+
+struct CTFConst : public CTFModifier {
+  CTFConst(lldb::user_id_t uid, uint32_t type)
+  : CTFModifier(eConst, uid, type) {}
+};
+
+struct CTFVolatile : public CTFModifier {
+  CTFVolatile(lldb::user_id_t uid, uint32_t type)
+  : CTFModifier(eVolatile, uid, type) {}
+};
+
+struct CTFRestrict : public CTFModifier {
+  CTFRestrict(lldb::user_id_t uid, uint32_t type)
+  : CTFModifier(eRestrict, uid, type) {}
+};
+
+struct CTFTypedef : public CTFType {
+  CTFTypedef(lldb::user_id_t uid, llvm::StringRef name, uint32_t type)
+  : CTFType(eTypedef, uid, name), type(type) {}
+
+  uint32_t type;
+};
+
+struct CTFArray : public CTFType {
+  CTFArray(lldb::user_id_t uid, llvm::StringRef name, uint32_t type,
+   uint32_t index, uint32_t nelems)
+  : CTFType(eArray, uid, name), type(type), index(index), nelems(nelems) {}
+
+  uint32_t type;
+  uint32_t index;
+  uint32_t nelems;
+};
+
+struct CTFEnum : public CTFType {
+  struct Value {
+Value(llvm::StringRef name, uint32_t value) : name(name), value(value){};
+llvm::StringRef name;
+uint32_t value;
+  };
+
+  CTFEnum(lldb::user_id_t uid, llvm::StringRef name, uint32_t nelems,
+  uint32_t size, std::vector values)
+  : CTFType(eEnum, uid, name), nelems(nelems), size(size),
+values(std::move(values)) {
+assert(this->values.size() == nelems);
+  }
+
+  uint32_t nelems;
+  uint32_t size;
+  std::vector values;
+};
+
+struct CTFFunction : public CTFType {
+  CTFFunction(lldb::user_id_t uid, llvm::StringRef name, uint32_t nargs,
+  uint32_t return_type, std::vector args, bool variadic)
+  : CTFType(eFunction, uid, name), nargs(nargs), return_type(return_type),
+args(std::move(args)), variadic(variadic) {}
+
+  uint32_t nargs;
+  uint32_t return_type;
+
+  std::vector args;
+  bool variadic = false;
+};
+
+struct CTFRecord : public CTFType {
+public:
+  struct Field {
+Field(llvm::StringRef name, uint32_t type, uint16_t offset,
+  uint16_t padding)
+: name(name), type(type), offset(offset), padding(padding) {}
+
+llvm::StringRef name;
+uint32_t type;
+uint16_t offset;
+uint16_t padding;
+  };
+
+  

[Lldb-commits] [PATCH] D156447: [lldb] Split CTF parsing and type creation (NFC)

2023-07-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Closed by commit rG0a5e0d3fad8d: [lldb] Split CTF parsing and type creation 
(NFC) (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D156447?vs=544880&id=545204#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156447

Files:
  lldb/source/Plugins/SymbolFile/CTF/CTFTypes.h
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp
  lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
  lldb/test/API/macosx/ctf/TestCTF.py

Index: lldb/test/API/macosx/ctf/TestCTF.py
===
--- lldb/test/API/macosx/ctf/TestCTF.py
+++ lldb/test/API/macosx/ctf/TestCTF.py
@@ -78,3 +78,14 @@
 "target variable foo.f",
 substrs=["(void (*)(int)) foo.f = 0x"],
 )
+
+self.expect(
+"type lookup MyEnum",
+substrs=[
+"enum MyEnum {",
+"eOne,",
+"eTwo,",
+"eThree",
+"}",
+],
+)
Index: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
===
--- lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
+++ lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 
+#include "CTFTypes.h"
 #include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/SymbolFile.h"
 
@@ -85,9 +86,6 @@
 
   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
 
-  lldb::TypeSP GetTypeForUID(lldb::user_id_t type_uid);
-  void AddTypeForUID(lldb::user_id_t type_uid, lldb::TypeSP type);
-
   Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
   std::optional GetDynamicArrayInfoForUID(
   lldb::user_id_t type_uid,
@@ -216,60 +214,17 @@
 uint32_t GetSize() const { return size; }
   };
 
-  struct ctf_member_t {
-uint32_t name;
-uint32_t type;
-uint16_t offset;
-uint16_t padding;
-  };
-
-  struct ctf_array_t {
-uint32_t contents;
-uint32_t index;
-uint32_t nelems;
-  };
-
-  struct ctf_enum_t {
-uint32_t name;
-int32_t value;
-  };
-
-  llvm::Expected ParseType(lldb::offset_t &offset,
- lldb::user_id_t uid,
- llvm::StringRef name, uint32_t kind,
- uint32_t variable_length,
- uint32_t type, uint32_t size);
+  llvm::Expected> ParseType(lldb::offset_t &offset,
+ lldb::user_id_t uid);
 
-  llvm::Expected ParseInteger(lldb::offset_t &offset,
-lldb::user_id_t uid,
-llvm::StringRef name);
-
-  llvm::Expected ParseModifierType(lldb::offset_t &offset,
- lldb::user_id_t uid,
- uint32_t kind, uint32_t type);
-
-  llvm::Expected ParseTypedef(lldb::offset_t &offset,
-lldb::user_id_t uid,
-llvm::StringRef name,
-uint32_t type);
-
-  llvm::Expected
-  ParseArray(lldb::offset_t &offset, lldb::user_id_t uid, llvm::StringRef name);
-
-  llvm::Expected ParseEnum(lldb::offset_t &offset,
- lldb::user_id_t uid,
- llvm::StringRef name,
- uint32_t elements, uint32_t size);
-
-  llvm::Expected ParseFunction(lldb::offset_t &offset,
- lldb::user_id_t uid,
- llvm::StringRef name,
- uint32_t num_args, uint32_t type);
-
-  llvm::Expected ParseRecord(lldb::offset_t &offset,
-   lldb::user_id_t uid,
-   llvm::StringRef name, uint32_t kind,
-   uint32_t fields, uint32_t size);
+  llvm::Expected CreateType(CTFType *ctf_type);
+  llvm::Expected CreateInteger(const CTFInteger &ctf_integer);
+  llvm::Expected CreateModifier(const CTFModifier &ctf_modifier);
+  llvm::Expected CreateTypedef(const CTFTypedef &ctf_typedef);
+  llvm::Expected CreateArray(const CTFArray &ctf_array);
+  llvm::Expected CreateEnum(const CTFEnum &ctf_enum);
+  llvm::Expected CreateFunction(const CTFFunction &ctf_function);
+  llvm::Expected CreateRecord(const CTFRecord &ctf_record);
 
   llvm::StringRef ReadString(lldb::offset_t offset) const;
 
@@ -288,7 +243,11 @@
   lldb::CompUnitSP m_comp_unit_sp;

[Lldb-commits] [PATCH] D156493: [lldb-vsocde] Adding support for the "disassemble" request.

2023-07-28 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

I have no excuse to not try vcsode with lldb now, thanks for working on this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156493

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


[Lldb-commits] [PATCH] D156465: [lldb-vscode] Adding support for displaying backtraces.

2023-07-28 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.

fancy


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156465

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


[Lldb-commits] [PATCH] D156493: [lldb-vsocde] Adding support for the "disassemble" request.

2023-07-28 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.

you are my hero


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156493

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


[Lldb-commits] [PATCH] D156498: [lldb] Support recursive record types in CTF

2023-07-28 Thread Michael Buch via Phabricator via lldb-commits
Michael137 added a comment.

Generally LGTM, just some clarifications questions




Comment at: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp:508
   ctf_record.name.data(), tag_kind, 
eLanguageTypeC);
+  m_compiler_types[record_type.GetOpaqueQualType()] = &ctf_record;
+  Declaration decl;

Just to clarify the lifetimes. This `ctf_record` lives on `m_ast` while the 
`m_compiler_types` on the SymbolFile, so we're guaranteed that the `ctf_record` 
lives long enough?



Comment at: lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.cpp:524-529
+  // We only support resolving record types.
+  assert(ctf_type->kind == CTFType::Kind::eStruct ||
+ ctf_type->kind == CTFType::Kind::eUnion);
 
-  m_ast->StartTagDeclarationDefinition(record_type);
-  for (const CTFRecord::Field &field : ctf_record.fields) {
-if (Type *field_type = ResolveTypeUID(field.type)) {
-  const uint32_t field_size = field_type->GetByteSize(nullptr).value_or(0);
-  TypeSystemClang::AddFieldToRecordType(record_type, field.name,
-field_type->GetFullCompilerType(),
-eAccessPublic, field_size);
+  // Cast to the appropriate CTF type.
+  const CTFRecord *ctf_record = static_cast(ctf_type);

Nit: would it make sense to just add `classof` methods to `CTFType` and use the 
llvm cast facilities?

Feel free to ignore since there's just one instance of such cast afaict


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

https://reviews.llvm.org/D156498

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


[Lldb-commits] [PATCH] D156512: [lldb][AArch64] Save/restore TLS registers around expressions

2023-07-28 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 545045.
DavidSpickett added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156512

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
  lldb/test/API/linux/aarch64/tls_registers/main.c

Index: lldb/test/API/linux/aarch64/tls_registers/main.c
===
--- lldb/test/API/linux/aarch64/tls_registers/main.c
+++ lldb/test/API/linux/aarch64/tls_registers/main.c
@@ -22,8 +22,18 @@
   __asm__ volatile("msr S3_3_C13_C0_5, %0" ::"r"(value));
 }
 
+bool use_tpidr2 = false;
+const uint64_t tpidr_pattern = 0x1122334455667788;
+const uint64_t tpidr2_pattern = 0x8877665544332211;
+
+void expr_func() {
+  set_tpidr(~tpidr_pattern);
+  if (use_tpidr2)
+set_tpidr2(~tpidr2_pattern);
+}
+
 int main(int argc, char *argv[]) {
-  bool use_tpidr2 = argc > 1;
+  use_tpidr2 = argc > 1;
 
   uint64_t original_tpidr = get_tpidr();
   // Accessing this on a core without it produces SIGILL. Only do this if
@@ -32,10 +42,8 @@
   if (use_tpidr2)
 original_tpidr2 = get_tpidr2();
 
-  uint64_t tpidr_pattern = 0x1122334455667788;
   set_tpidr(tpidr_pattern);
 
-  uint64_t tpidr2_pattern = 0x8877665544332211;
   if (use_tpidr2)
 set_tpidr2(tpidr2_pattern);
 
Index: lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
===
--- lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
+++ lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
@@ -42,13 +42,20 @@
 substrs=["stopped", "stop reason = breakpoint"],
 )
 
-def check_tls_reg(self, registers):
-self.setup(registers)
-
+def check_registers(self, registers, values):
 regs = self.thread().GetSelectedFrame().GetRegisters()
 tls_regs = regs.GetFirstValueByName("Thread Local Storage Registers")
 self.assertTrue(tls_regs.IsValid(), "No TLS registers found.")
 
+for register in registers:
+tls_reg = tls_regs.GetChildMemberWithName(register)
+self.assertTrue(tls_reg.IsValid(), "{} register not found.".format(
+register))
+self.assertEqual(tls_reg.GetValueAsUnsigned(), values[register])
+
+def check_tls_reg(self, registers):
+self.setup(registers)
+
 # Since we can't predict what the value will be, the program has set
 # a target value for us to find.
 initial_values = {
@@ -56,11 +63,12 @@
 "tpidr2": 0x8877665544332211,
 }
 
-for register in registers:
-tls_reg = tls_regs.GetChildMemberWithName(register)
-self.assertTrue(tls_reg.IsValid(), "{} register not found.".format(
-register))
-self.assertEqual(tls_reg.GetValueAsUnsigned(), initial_values[register])
+self.check_registers(registers, initial_values)
+
+# Their values should be restored if an expression modifies them.
+self.runCmd("expression expr_func()")
+
+self.check_registers(registers, initial_values)
 
 set_values = {
 "tpidr": 0x,
@@ -95,7 +103,7 @@
 @skipUnlessPlatform(["linux"])
 def test_tls_sme(self):
 if not self.isAArch64SME():
-self.skipTest("SME must present.")
+self.skipTest("SME must be present.")
 
 self.check_tls_reg(["tpidr", "tpidr2"])
 
Index: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -559,8 +559,10 @@
 dst += GetFPRSize();
   }
 
-  if (GetRegisterInfo().IsMTEEnabled())
+  if (GetRegisterInfo().IsMTEEnabled()) {
 ::memcpy(dst, GetMTEControl(), GetMTEControlSize());
+dst += GetMTEControlSize();
+  }
 
   ::memcpy(dst, GetTLSBuffer(), GetTLSBufferSize());
 
@@ -671,8 +673,17 @@
 ::memcpy(GetMTEControl(), src, GetMTEControlSize());
 m_mte_ctrl_is_valid = true;
 error = WriteMTEControl();
+if (error.Fail())
+  return error;
+src += GetMTEControlSize();
   }
 
+  // There is always a TLS set. It changes size based on system properties, it's
+  // not something an expression can change.
+  ::memcpy(GetTLSBuffer(), src, GetTLSBufferSize());
+  m_tls_is_valid = true;
+  error = WriteTLS();
+
   return error;
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156118: [lldb][AArch64] Add reading of TLS tpidr register from core files

2023-07-28 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 545044.
DavidSpickett added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156118

Files:
  lldb/include/lldb/Host/linux/Ptrace.h
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterContextPOSIX_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
  lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
  lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
  lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
  lldb/test/API/functionalities/postmortem/elf-core/linux-aarch64-neon.c
  lldb/test/API/functionalities/postmortem/elf-core/linux-aarch64-neon.core
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -131,6 +131,9 @@
 Changes to LLDB
 -
 
+* AArch64 Linux targets now provide access to the Thread Local Storage
+  register ``tpidr``.
+
 Changes to Sanitizers
 -
 * HWASan now defaults to detecting use-after-scope bugs.
Index: lldb/test/API/functionalities/postmortem/elf-core/linux-aarch64-neon.c
===
--- lldb/test/API/functionalities/postmortem/elf-core/linux-aarch64-neon.c
+++ lldb/test/API/functionalities/postmortem/elf-core/linux-aarch64-neon.c
@@ -1,6 +1,8 @@
 // compile with -march=armv8-a+simd on compatible aarch64 compiler
 // linux-aarch64-neon.core was generated by: aarch64-linux-gnu-gcc-8
 // commandline: -march=armv8-a+simd -nostdlib -static -g linux-aarch64-neon.c
+#include 
+
 static void bar(char *boom) {
   char F = 'b';
   asm volatile("fmov d0,  #0.5\n\t");
@@ -14,6 +16,9 @@
   asm volatile("movi v8.16b, #0x11\n\t");
   asm volatile("movi v31.16b, #0x30\n\t");
 
+  uint64_t pattern = 0x1122334455667788;
+  asm volatile("msr tpidr_el0, %0" ::"r"(pattern));
+
   *boom = 47; // Frame bar
 }
 
Index: lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
===
--- lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
+++ lldb/test/API/functionalities/postmortem/elf-core/TestLinuxCore.py
@@ -304,10 +304,10 @@
 values = {}
 values["x1"] = "0x002f"
 values["w1"] = "0x002f"
-values["fp"] = "0x007fc5dd7f20"
-values["lr"] = "0x00400180"
-values["sp"] = "0x007fc5dd7f00"
-values["pc"] = "0x0040014c"
+values["fp"] = "0xdab7c770"
+values["lr"] = "0x0040019c"
+values["sp"] = "0xdab7c750"
+values["pc"] = "0x00400168"
 values[
 "v0"
 ] = "{0x00 0x00 0x00 0x00 0x00 0x00 0xe0 0x3f 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00}"
@@ -366,6 +366,7 @@
 values["d31"] = "1.3980432860952889E-76"
 values["fpsr"] = "0x"
 values["fpcr"] = "0x"
+values["tpidr"] = "0x1122334455667788"
 
 for regname, value in values.items():
 self.expect(
Index: lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
===
--- lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
+++ lldb/source/Plugins/Process/elf-core/RegisterUtilities.h
@@ -123,6 +123,10 @@
 {llvm::Triple::Linux, llvm::Triple::aarch64, llvm::ELF::NT_ARM_PAC_MASK},
 };
 
+constexpr RegsetDesc AARCH64_TLS_Desc[] = {
+{llvm::Triple::Linux, llvm::Triple::aarch64, llvm::ELF::NT_ARM_TLS},
+};
+
 constexpr RegsetDesc PPC_VMX_Desc[] = {
 {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
 {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
===
--- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
+++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.h
@@ -57,6 +57,7 @@
   lldb_private::DataExtractor m_fpr_data;
   lldb_private::DataExtractor m_sve_data;
   lldb_private::DataExtractor m_pac_data;
+  lldb_private::DataExtractor m_tls_data;
 
   SVEState m_sve_state;
   uint16_t m_sve_vector_length = 0;
Index: lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
===
--- lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
+++ lldb/source/Plugins/Process/elf-core/RegisterContextPOSIXCore_arm64.cpp
@@ -34,6 +34,12 @@
   if (pac_data.GetByteSize(

[Lldb-commits] [PATCH] D156512: [lldb][AArch64] Save/restore TLS registers around expressions

2023-07-28 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Previously we were storing them but not restoring them. This fixes
that and expands the testing to check for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156512

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
  lldb/test/API/linux/aarch64/tls_registers/main.c

Index: lldb/test/API/linux/aarch64/tls_registers/main.c
===
--- lldb/test/API/linux/aarch64/tls_registers/main.c
+++ lldb/test/API/linux/aarch64/tls_registers/main.c
@@ -22,8 +22,18 @@
   __asm__ volatile("msr S3_3_C13_C0_5, %0" ::"r"(value));
 }
 
+bool use_tpidr2 = false;
+const uint64_t tpidr_pattern = 0x1122334455667788;
+const uint64_t tpidr2_pattern = 0x8877665544332211;
+
+void expr_func() {
+  set_tpidr(~tpidr_pattern);
+  if (use_tpidr2)
+set_tpidr2(~tpidr2_pattern);
+}
+
 int main(int argc, char *argv[]) {
-  bool use_tpidr2 = argc > 1;
+  use_tpidr2 = argc > 1;
 
   uint64_t original_tpidr = get_tpidr();
   // Accessing this on a core without it produces SIGILL. Only do this if
@@ -32,10 +42,8 @@
   if (use_tpidr2)
 original_tpidr2 = get_tpidr2();
 
-  uint64_t tpidr_pattern = 0x1122334455667788;
   set_tpidr(tpidr_pattern);
 
-  uint64_t tpidr2_pattern = 0x8877665544332211;
   if (use_tpidr2)
 set_tpidr2(tpidr2_pattern);
 
Index: lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
===
--- lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
+++ lldb/test/API/linux/aarch64/tls_registers/TestAArch64LinuxTLSRegisters.py
@@ -42,13 +42,20 @@
 substrs=["stopped", "stop reason = breakpoint"],
 )
 
-def check_tls_reg(self, registers):
-self.setup(registers)
-
+def check_registers(self, registers, values):
 regs = self.thread().GetSelectedFrame().GetRegisters()
 tls_regs = regs.GetFirstValueByName("Thread Local Storage Registers")
 self.assertTrue(tls_regs.IsValid(), "No TLS registers found.")
 
+for register in registers:
+tls_reg = tls_regs.GetChildMemberWithName(register)
+self.assertTrue(tls_reg.IsValid(), "{} register not found.".format(
+register))
+self.assertEqual(tls_reg.GetValueAsUnsigned(), values[register])
+
+def check_tls_reg(self, registers):
+self.setup(registers)
+
 # Since we can't predict what the value will be, the program has set
 # a target value for us to find.
 initial_values = {
@@ -56,11 +63,12 @@
 "tpidr2": 0x8877665544332211,
 }
 
-for register in registers:
-tls_reg = tls_regs.GetChildMemberWithName(register)
-self.assertTrue(tls_reg.IsValid(), "{} register not found.".format(
-register))
-self.assertEqual(tls_reg.GetValueAsUnsigned(), initial_values[register])
+self.check_registers(registers, initial_values)
+
+# Their values should be restored if an expression modifies them.
+self.runCmd("expression expr_func()")
+
+self.check_registers(registers, initial_values)
 
 set_values = {
 "tpidr": 0x,
@@ -95,7 +103,7 @@
 @skipUnlessPlatform(["linux"])
 def test_tls_sme(self):
 if not self.isAArch64SME():
-self.skipTest("SME must present.")
+self.skipTest("SME must be present.")
 
 self.check_tls_reg(["tpidr", "tpidr2"])
 
Index: lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
===
--- lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -559,8 +559,10 @@
 dst += GetFPRSize();
   }
 
-  if (GetRegisterInfo().IsMTEEnabled())
+  if (GetRegisterInfo().IsMTEEnabled()) {
 ::memcpy(dst, GetMTEControl(), GetMTEControlSize());
+dst += GetMTEControlSize();
+  }
 
   ::memcpy(dst, GetTLSBuffer(), GetTLSBufferSize());
 
@@ -671,8 +673,17 @@
 ::memcpy(GetMTEControl(), src, GetMTEControlSize());
 m_mte_ctrl_is_valid = true;
 error = WriteMTEControl();
+if (error.Fail())
+  return error;
+src += GetMTEControlSize();
   }
 
+  // There is always a TLS set. It changes size based on system properties, it's
+  // not something an expression can change.
+  ::memcpy(GetTLSBuffer(), src, GetTLSBufferSize());
+  m_tls_is_valid = true;
+  error = WriteTLS();
+
   return error;
 }
 
___
lldb-commits mailing li