[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

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

> Then we have SIMD (v0-31) which is a bit of a wrench in this. We must read 
> SIMD via the SVE regset even while SSVE is active, but writing to that same 
> set brings us out of SSVE mode (into SIMD mode, I think, but it could just be 
> SVE mode).

In my testing it did work to just use the active mode instead but this is one 
of those things that is likely unintentional or a result of QEMU's 
implementation choices.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154926

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


[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

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

> You mention a couple of times that when in SSVE mode, we can only write to 
> the SVE registers and doing so forces the processor out of SSVE Mode. We can 
> read the SSVE registers while in SSVE mode though right?

We are always able to read the header for either mode, which tells us the 
vector length among other useful metadata. Register data though...

Maybe I should just enumerate the states.

Write to SVE while in SSVE - switch to SVE mode
Write to SSVE while in SVE - switch to SSVE mode
Write to SVE while in SVE - no change
Write to SSVE while in SSVE - no change

Read SVE while in SSVE - no register data returned
Read SSVE while in SVE - no register data returned
Read SSVE while in SSVE - SSVE registers returned
Read SVE while in SVE - SVE registers returned

Then we have SIMD (v0-31) which is a bit of a wrench in this. We must read SIMD 
via the SVE regset even while SSVE is active, but writing to that same set 
brings us out of SSVE mode (into SIMD mode, I think, but it could just be SVE 
mode).

So perhaps you see from that why I don't plan to use the mode switching this 
way in lldb.

I will in follow on patches report the current mode via a pseudo control 
register, and report the streaming vector length again with a pseudo. To 
resolve the ambiguity of naming the registers the same thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154926

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


[Lldb-commits] [PATCH] D155037: Improve error messaging when debugserver fails to complete attaching to another process on Darwin systems

2023-07-11 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 modulo code duplication.




Comment at: lldb/tools/debugserver/source/RNBRemote.cpp:3639-3644
+  struct proc_bsdshortinfo proc;
+  int ppid = 0;
+  if (proc_pidinfo(pid, PROC_PIDT_SHORTBSDINFO, 0, &proc,
+   PROC_PIDT_SHORTBSDINFO_SIZE) == sizeof(proc)) {
+ppid = proc.pbsi_ppid;
+  }

As this is the exact same code as in `MachProcess.mm`, is this worth factoring 
out? Something like 

```
std::optional GetAttachedProcPID() {
  struct proc_bsdshortinfo proc;
  if (proc_pidinfo(pid, PROC_PIDT_SHORTBSDINFO, 0, &proc,
   PROC_PIDT_SHORTBSDINFO_SIZE) == sizeof(proc)) {
return proc.pbsi_ppid;
  }
  return std::null opt;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155037

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

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

In D149213#4491889 , @VladimirMakaev 
wrote:

> In D149213#4491594 , @bulbazord 
> wrote:
>
>> I'm curious to know why you don't try and implement some kind of 
>> `TypeSystemRust`? I assume it's going to be a lengthy process, but 
>> eventually you (or somebody else) is going to want to implement a 
>> `TypeSystemRust` in some form and they'll have to revisit all of 
>> rust-specific things we've tacked onto various parts of LLDB (e.g. this 
>> functionality with DWARFASTParserClang). I suppose the question I'm trying 
>> to answer is "How much do we add to LLDB before actually adding proper rust 
>> support?"
>
> I think there was an attempt in the past to build TypeSystemRust. Rust 
> Project had a fork of LLDB with this implemented by Tom Tromey and CodeLLDB 
> maintainer(vadimcn) has one. Both of them were not able to merge that into 
> LLDB codebase. A relevant link to a discussion 
> https://rust-lang.zulipchat.com/#narrow/stream/317568-t-compiler.2Fwg-debugging/topic/upstreaming.20rust.20support.20into.20lldb
>
> Apart from just implementing type system itself (which is much bigger scope 
> than this change) there are other non-trivial issues:
>
> 1. There is no "compiler-as-a-service" in Rust so getting expressions to work 
> is non-trivial. An interpreter of some sort needs to be built with subset of 
> Rust support
> 2. Infra changes (DEVOPS) changes are required to start building Rust 
> inferiors to run tests on CI
> 3. LLVM / rustc cross repository logistics. Rustc probably needs to live in 
> LLVM to make this work well.
>
> Given the fact that the majority of the things "just work" when debugging 
> Rust with LLDB (using Clang declarations effectively as of today) I kinda 
> believe this is not a bad solution to try to do a bit of extra care for Rust 
> types in TypeSystemClang and the debugging experience will be great for Rust 
> users. As long as LLDB emits enough information a conversion can be made in 
> synthetic provider to display it nicely in debugger. Tests can be written to 
> make sure it doesn't rot. This is definitely something I want to improve in 
> this PR too.
>
> I think if Rust Project Debugging WG decides to invest into native 
> TypeSystemRust I think having these fixes around isn't going to slow down the 
> progress but quite the contrary (in my opinion). And cleaning them up will 
> also be trivial since they're specifically guarded by CU check.

Thanks for giving that background, I was aware there were conversations about 
this somewhere but I didn't have the full context.

>> I was also curious about the test. I'm not sure how the test is supposed to 
>> work here, is the rust source file actually built or is that just to show 
>> how the yaml file was generated? There's no rust support in our testing 
>> infrastructure AFAICT so I assume this just makes sure that something 
>> already generated doesn't get broken in the future.
>
> I'm gonna work on the test more and try to make assertions against global 
> SBValue. Greg suggested this might work. So since we don't have access to 
> rustc in the testing setup I've generated object file from main.rs manually 
> and converted it to yaml. This makes the test portable. (main.rs is kept for 
> the reference)

Sounds good. I added a comment inline about that.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3184
+case DW_TAG_variant_part:
+  ParseVariantPart(die, parent_die, class_clang_type, 
default_accessibility,
+   layout_info);

clayborg wrote:
> clayborg wrote:
> > I would add a check here for the Rust language. We might also want to 
> > rename "ParseVariantPart" to "ParseRustVariant" to indicate this is 
> > specific to the Rust language.
> Something like:
> 
> ```
> if (die.GetCU()->GetDWARFLanguageType() == eLanguageTypeRust) 
>   ParseRustVariant(die, parent_die, class_clang_type, default_accessibility, 
> layout_info);
> break;
> ```
+1, I'm partial to the `ParseRustVariantPart` name myself.

IMO, I think it would be helpful knowing that this functionality was written 
with rust in mind (especially since it's a clang-based codepath). That way if 
we need to support this in the future for something in clang (or any other 
language), it makes it easy to see at a glance that `ParseVariantPart` is 
intended for rust.



Comment at: lldb/test/API/lang/rust/enum-structs/main.rs:1-4
+#![no_std]
+#![no_main]
+use core::ptr::NonNull;
+

VladimirMakaev wrote:
> clayborg wrote:
> > Is this file used at all? I don't see any references to it. I am guessing 
> > that the main.yaml is expected to reference this file?
> It's not used I've just put it as a reference of the program that the object 
> file was taken from. I used rustc to produce object file from this program
In that case, could you

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 539359.
kastiglione added a comment.

Change `bool IsSwift()` to `LanguageType GetImplementationLanguage()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152837

Files:
  lldb/include/lldb/Target/LanguageRuntime.h
  lldb/include/lldb/Target/Process.h
  lldb/source/Core/ValueObjectDynamicValue.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/source/Target/Process.cpp

Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -22,6 +22,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Core/ValueObject.h"
 #include "lldb/Expression/DiagnosticManager.h"
 #include "lldb/Expression/DynamicCheckerFunctions.h"
 #include "lldb/Expression/UserExpression.h"
@@ -1553,6 +1554,13 @@
   return runtime;
 }
 
+LanguageRuntime *Process::GetLanguageRuntime(ValueObject &in_value) {
+  auto language = in_value.GetObjectRuntimeLanguage();
+  if (auto *runtime = GetLanguageRuntime(language))
+return runtime->GetPreferredLanguageRuntime(in_value);
+  return nullptr;
+}
+
 bool Process::IsPossibleDynamicValue(ValueObject &in_value) {
   if (m_finalizing)
 return false;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -24,6 +24,7 @@
 #include "lldb/Target/LanguageRuntime.h"
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/ThreadSafeDenseMap.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 class CommandObjectObjC_ClassTable_Dump;
@@ -86,6 +87,11 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+/// Determine whether this class is implemented in Swift.
+virtual lldb::LanguageType GetImplementationLanguage() const {
+  return lldb::eLanguageTypeObjC;
+}
+
 virtual bool IsValid() = 0;
 
 /// There are two routines in the ObjC runtime that tagged pointer clients
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -38,6 +38,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "apple-objc-v2"; }
 
+  LanguageRuntime *GetPreferredLanguageRuntime(ValueObject &in_value) override;
+
   static char ID;
 
   bool isA(const void *ClassID) const override {
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -712,6 +712,20 @@
   RegisterObjCExceptionRecognizer(process);
 }
 
+LanguageRuntime *
+AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
+  if (auto process_sp = in_value.GetProcessSP()) {
+assert(process_sp.get() == m_process);
+if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value)) {
+  LanguageType impl_lang = descriptor_sp->GetImplementationLanguage();
+  if (impl_lang != eLanguageTypeUnknown)
+if (auto *impl_runtime = process_sp->GetLanguageRuntime(impl_lang))
+  return impl_runtime;
+}
+  }
+  return this;
+}
+
 bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
 ValueObject &in_value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName &class_type_or_name, Address &address,
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
@@ -12,6 +12,7 @@
 #include 
 
 #include "AppleObjCRuntimeV2.h"
+#include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private.h"
 
 #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
@@ -34,6 +35,8 @@
 return true; // any Objective-C v2 runtime class descriptor we vend is valid
   }
 
+  lldb::LanguageTyp

[Lldb-commits] [PATCH] D155037: Improve error messaging when debugserver fails to complete attaching to another process on Darwin systems

2023-07-11 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added a reviewer: jingham.
jasonmolenda added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

On Darwin, we first get a process' mach task port with task_for_pid(), and then 
we do a ptrace(PT_ATTACHEXC).  We need to complete both before we are 
successfully attached.  There are unusual failures where we get the task port 
and the ptrace may not have completed entirely, so lldb is going to exit out.  
An error message isn't created at the layer where this failure was detected, 
and then at a higher layer where we try to find a reason why the attach failed, 
we notice that the process is being "debugged" -- by ourselves -- and emit an 
error message saying it's being debugged.

This patch adds an error string at all the points where we can fail to complete 
this two-step attach process, and also adds a refinement to the "last ditch 
error reporting" scheme to confirm that the process' parent process isn't 
already this debugserver.  (we half-attached to it)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155037

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
@@ -3636,10 +3636,23 @@
   if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &kinfo, &len, NULL, 0) != 0) {
 return false; // pid doesn't exist? well, it's not being debugged...
   }
-  if (kinfo.kp_proc.p_flag & P_TRACED)
-return true; // is being debugged already
-  else
-return false;
+  struct proc_bsdshortinfo proc;
+  int ppid = 0;
+  if (proc_pidinfo(pid, PROC_PIDT_SHORTBSDINFO, 0, &proc,
+   PROC_PIDT_SHORTBSDINFO_SIZE) == sizeof(proc)) {
+ppid = proc.pbsi_ppid;
+  }
+  if (kinfo.kp_proc.p_flag & P_TRACED) {
+if (ppid != getpid()) {
+  return true; // is being debugged already
+} else {
+  // being debugged, but by us. The attach
+  // failed for some reason after we had
+  // ptrace'd the process and become parent.
+  return false;
+}
+  }
+  return false;
 }
 
 // Test if this current login session has a connection to the
Index: lldb/tools/debugserver/source/MacOSX/MachProcess.mm
===
--- lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -2821,16 +2821,31 @@
   "attach to pid %d",
   getpid(), pid);
 
+  struct proc_bsdshortinfo proc;
+  int ppid = 0;
+  if (proc_pidinfo(pid, PROC_PIDT_SHORTBSDINFO, 0, &proc,
+   PROC_PIDT_SHORTBSDINFO_SIZE) == sizeof(proc)) {
+ppid = proc.pbsi_ppid;
+  }
   struct kinfo_proc kinfo;
   int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
   size_t len = sizeof(struct kinfo_proc);
   if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &kinfo, &len, NULL, 0) == 0 && len > 0) {
 if (kinfo.kp_proc.p_flag & P_TRACED) {
-  ::snprintf(err_str, err_len, "%s - process %d is already being debugged", err.AsString(), pid);
-  DNBLogError(
-  "[LaunchAttach] (%d) MachProcess::AttachForDebug pid %d is "
-  "already being debugged",
-  getpid(), pid);
+  if (ppid != getpid()) {
+snprintf(err_str, err_len,
+ "%s - process %d is already being debugged by pid %d",
+ err.AsString(), pid, ppid);
+DNBLogError(
+"[LaunchAttach] (%d) MachProcess::AttachForDebug pid %d is "
+"already being debugged by pid %d",
+getpid(), pid, ppid);
+  } else {
+snprintf(err_str, err_len,
+ "%s - Failed to attach to pid %d, AttachForDebug() "
+ "unable to ptrace(PT_ATTACHEXC)",
+ err.AsString(), m_pid);
+  }
 }
   }
 }
@@ -3401,7 +3416,13 @@
   "%d (err = %i, errno = %i (%s))",
  m_pid, err, ptrace_err.Status(),
  ptrace_err.AsString());
-launch_err.SetError(NUB_GENERIC_ERROR, DNBError::Generic);
+char err_msg[PATH_MAX];
+
+snprintf(err_msg, sizeof(err_msg),
+ "Failed to attach to pid %d, LaunchForDebug() unable to "
+ "ptrace(PT_ATTACHEXC)",
+ m_pid);
+launch_err.SetErrorString(err_msg);
   }
 } else {
   launch_err.Clear();
@@ -3777,6 +3798,10 @@
   m_flags |= eMachProcessFlagsAttached;
   DNBLogThreadedIf(LOG_PROCESS, "successfully attached to pid %d", m_pid);
 } else {

[Lldb-commits] [PATCH] D155035: [lldb][NFCI] Remove unneeded temporary std::string allocations in SBAPI

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

This uses some friend class trickery to avoid some unneeded temporary
std::string allocations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155035

Files:
  lldb/include/lldb/API/SBStringList.h
  lldb/source/API/SBDebugger.cpp
  lldb/source/API/SBStringList.cpp
  lldb/source/API/SBStructuredData.cpp
  lldb/source/API/SBThread.cpp


Index: lldb/source/API/SBThread.cpp
===
--- lldb/source/API/SBThread.cpp
+++ lldb/source/API/SBThread.cpp
@@ -457,7 +457,7 @@
 info_root_sp->GetObjectForDotSeparatedPath(path);
 if (node) {
   if (node->GetType() == eStructuredDataTypeString) {
-strm.Printf("%s", node->GetAsString()->GetValue().str().c_str());
+strm.ref() << node->GetAsString()->GetValue();
 success = true;
   }
   if (node->GetType() == eStructuredDataTypeInteger) {
Index: lldb/source/API/SBStructuredData.cpp
===
--- lldb/source/API/SBStructuredData.cpp
+++ lldb/source/API/SBStructuredData.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
+#include "lldb/Utility/StringList.h"
 #include "lldb/Utility/StructuredData.h"
 
 using namespace lldb;
@@ -138,9 +139,9 @@
   StructuredData::Array *key_arr = array_sp->GetAsArray();
   assert(key_arr);
 
-  key_arr->ForEach([&keys] (StructuredData::Object *object) -> bool {
+  key_arr->ForEach([&keys](StructuredData::Object *object) -> bool {
 llvm::StringRef key = object->GetStringValue("");
-keys.AppendString(key.str().c_str());
+keys->AppendString(key);
 return true;
   });
   return true;
Index: lldb/source/API/SBStringList.cpp
===
--- lldb/source/API/SBStringList.cpp
+++ lldb/source/API/SBStringList.cpp
@@ -37,6 +37,13 @@
 
 SBStringList::~SBStringList() = default;
 
+lldb_private::StringList *SBStringList::operator->() {
+  if (!IsValid())
+m_opaque_up = std::make_unique();
+
+  return m_opaque_up.get();
+}
+
 const lldb_private::StringList *SBStringList::operator->() const {
   return m_opaque_up.get();
 }
Index: lldb/source/API/SBDebugger.cpp
===
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -1399,9 +1399,9 @@
 
   Log *log = GetLog(LLDBLog::API);
 
-  LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"",
-static_cast(m_opaque_sp.get()),
-(m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : ""));
+  LLDB_LOG(log, "SBDebugger({0:x})::GetPrompt () => \"{1}\"",
+   static_cast(m_opaque_sp.get()),
+   (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
 
   return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString()
   : nullptr);
Index: lldb/include/lldb/API/SBStringList.h
===
--- lldb/include/lldb/API/SBStringList.h
+++ lldb/include/lldb/API/SBStringList.h
@@ -47,11 +47,14 @@
   friend class SBBreakpoint;
   friend class SBBreakpointLocation;
   friend class SBBreakpointName;
+  friend class SBStructuredData;
 
   SBStringList(const lldb_private::StringList *lldb_strings);
 
   void AppendList(const lldb_private::StringList &strings);
 
+  lldb_private::StringList *operator->();
+
   const lldb_private::StringList *operator->() const;
 
   const lldb_private::StringList &operator*() const;


Index: lldb/source/API/SBThread.cpp
===
--- lldb/source/API/SBThread.cpp
+++ lldb/source/API/SBThread.cpp
@@ -457,7 +457,7 @@
 info_root_sp->GetObjectForDotSeparatedPath(path);
 if (node) {
   if (node->GetType() == eStructuredDataTypeString) {
-strm.Printf("%s", node->GetAsString()->GetValue().str().c_str());
+strm.ref() << node->GetAsString()->GetValue();
 success = true;
   }
   if (node->GetType() == eStructuredDataTypeInteger) {
Index: lldb/source/API/SBStructuredData.cpp
===
--- lldb/source/API/SBStructuredData.cpp
+++ lldb/source/API/SBStructuredData.cpp
@@ -16,6 +16,7 @@
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/Utility/Stream.h"
+#include "lldb/Utility/StringList.h"
 #include "lldb/Utility/StructuredData.h"
 
 using namespace lldb;
@@ -138,9 +139,9 @@
   StructuredData::Array *key_arr = array_sp->GetAsArray();
   assert(key_arr);
 
-  key_arr->ForEach([&keys] (StructuredData::Object 

[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

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

I have no experience with the linux support so I'm not an ideal person to 
review, but when I was reading about watchpoints I saw the caveats about SSVE 
mode and false watchpoint hits so I read through the patch out of curiosity 
about SME/SSVE.  You mention a couple of times that when in SSVE mode, we can 
only write to the SVE registers and doing so forces the processor out of SSVE 
Mode.  We can read the SSVE registers while in SSVE mode though right?




Comment at: 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp:532
   // AArch64 register data must contain GPRs, either FPR or SVE registers
-  // and optional MTE register. Pointer Authentication (PAC) registers are
-  // read-only and will be skiped.
+  // (which can be non-streaming, SVE or streaming, SSVE) and optional MTE
+  // register. Pointer Authentication (PAC) registers are read-only and will be

it's super minor, but I think you're meaning to describe two states here, but 
it sounds like four.  Maybe "which can be non-streaming (SVE), or streaming  
(SSVE)" is the best I can come up with.



Comment at: 
lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp:534
+  // register. Pointer Authentication (PAC) registers are read-only and will be
+  // skiped.
 

skipped


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154926

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


[Lldb-commits] [PATCH] D153735: [lldb][LocateModuleCallback] Implement API, Python interface

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added inline comments.



Comment at: lldb/source/API/SBPlatform.cpp:664-689
+  if (platform_sp) {
+if (callback) {
+  platform_sp->SetLocateModuleCallback(
+  [callback, callback_baton](const ModuleSpec &module_spec,
+ FileSpec &module_file_spec,
+ FileSpec &symbol_file_spec) {
+SBModuleSpec module_spec_sb(module_spec);

bulbazord wrote:
> Suggestion: Invert the conditions and use early returns. This function has 
> quite a bit of nesting and I think the readability could be improved.
Thanks, yes it looks better. Also added a comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

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


[Lldb-commits] [PATCH] D153735: [lldb][LocateModuleCallback] Implement API, Python interface

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 539351.
splhack added a comment.

update SetLocateModuleCallback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

Files:
  lldb/bindings/python/python-typemaps.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/API/SBPlatform.h
  lldb/source/API/SBPlatform.cpp
  lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py

Index: lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py
===
--- /dev/null
+++ lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py
@@ -0,0 +1,338 @@
+"""
+Test platform locate module callback functionality
+"""
+
+import ctypes
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from pathlib import Path
+
+import lldb
+
+UNITTESTS_TARGET_INPUTS_PATH = "../../../../unittests/Target/Inputs"
+MODULE_PLATFORM_PATH = "/system/lib64/AndroidModule.so"
+MODULE_TRIPLE = "aarch64-none-linux"
+MODULE_RESOLVED_TRIPLE = "aarch64--linux-android"
+MODULE_UUID = "80008338-82A0-51E5-5922-C905D23890DA-BDDEFECC"
+MODULE_FUNCTION = "boom"
+MODULE_HIDDEN_FUNCTION = "boom_hidden"
+MODULE_FILE = "AndroidModule.so"
+MODULE_NON_EXISTENT_FILE = "non-existent-file"
+SYMBOL_FILE = "AndroidModule.unstripped.so"
+BREAKPAD_SYMBOL_FILE = "AndroidModule.so.sym"
+SYMBOL_STRIPPED = "stripped"
+SYMBOL_UNSTRIPPED = "unstripped"
+
+
+class LocateModuleCallbackTestCase(TestBase):
+def setUp(self):
+TestBase.setUp(self)
+self.platform = self.dbg.GetSelectedPlatform()
+self.target = self.dbg.CreateTarget("")
+self.assertTrue(self.target)
+
+self.input_dir = (
+Path(self.getSourceDir()) / UNITTESTS_TARGET_INPUTS_PATH
+).resolve()
+self.assertTrue(self.input_dir.is_dir())
+
+def check_module_spec(self, module_spec: lldb.SBModuleSpec):
+self.assertEqual(
+MODULE_UUID.replace("-", ""),
+ctypes.string_at(
+int(module_spec.GetUUIDBytes()),
+module_spec.GetUUIDLength(),
+)
+.hex()
+.upper(),
+)
+
+self.assertEqual(MODULE_TRIPLE, module_spec.GetTriple())
+
+self.assertEqual(MODULE_PLATFORM_PATH, module_spec.GetFileSpec().fullpath)
+
+def check_module(self, module: lldb.SBModule, symbol_file: str, symbol_kind: str):
+self.assertTrue(module.IsValid())
+
+self.assertEqual(
+MODULE_UUID,
+module.GetUUIDString(),
+)
+
+self.assertEqual(MODULE_RESOLVED_TRIPLE, module.GetTriple())
+
+self.assertEqual(MODULE_PLATFORM_PATH, module.GetPlatformFileSpec().fullpath)
+
+self.assertEqual(
+str(self.input_dir / MODULE_FILE),
+module.GetFileSpec().fullpath,
+)
+
+self.assertEqual(
+str(self.input_dir / symbol_file),
+module.GetSymbolFileSpec().fullpath,
+)
+
+sc_list = module.FindFunctions(MODULE_FUNCTION, lldb.eSymbolTypeCode)
+self.assertEqual(1, sc_list.GetSize())
+sc_list = module.FindFunctions(MODULE_HIDDEN_FUNCTION, lldb.eSymbolTypeCode)
+self.assertEqual(0 if symbol_kind == SYMBOL_STRIPPED else 1, sc_list.GetSize())
+
+def test_set_non_callable(self):
+# The callback should be callable.
+non_callable = "a"
+
+with self.assertRaises(TypeError, msg="Need a callable object or None!"):
+self.platform.SetLocateModuleCallback(non_callable)
+
+def test_set_wrong_args(self):
+# The callback should accept 3 argument.
+def test_args2(a, b):
+pass
+
+with self.assertRaises(TypeError, msg="Expected 3 argument callable object"):
+self.platform.SetLocateModuleCallback(test_args2)
+
+def test_default(self):
+# The default behavior is to locate the module with LLDB implementation
+# and AddModule should fail.
+module = self.target.AddModule(
+MODULE_PLATFORM_PATH,
+MODULE_TRIPLE,
+MODULE_UUID,
+)
+
+self.assertFalse(module)
+
+def test_set_none(self):
+# SetLocateModuleCallback should succeed to clear the callback with None.
+# and AddModule should fail.
+self.assertTrue(self.platform.SetLocateModuleCallback(None).Success())
+
+module = self.target.AddModule(
+MODULE_PLATFORM_PATH,
+MODULE_TRIPLE,
+MODULE_UUID,
+)
+
+self.assertFalse(module)
+
+def test_return_error(self):
+# The callback fails, AddModule should fail.
+def test_locate_module(
+module_spec: lldb.SBModuleSpec,
+module_file_spec: lldb.SBFileSpec,
+symbol_file_spec: lldb.SBFileSpec,
+):
+self.che

[Lldb-commits] [PATCH] D153734: [lldb][LocateModuleCallback] Call locate module callback

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:884-887
+  typedef std::function
+  LocateModuleCallback;

clayborg wrote:
> I think we still need a baton for the callback so clients can register a 
> callback + void *.
Yes, callback and baton(`void *`) are retained by SBPlatform.
The detailed flow is here https://reviews.llvm.org/D153735#4491892



Comment at: lldb/include/lldb/Target/Platform.h:944
   const std::unique_ptr m_module_cache;
+  LocateModuleCallback m_locate_module_callback;
 

splhack wrote:
> clayborg wrote:
> > We probably need a baton still. In order to make this work for python, we 
> > need to be able to set a callback and a baton for the python callable?
> @clayborg Yes, in D153735, both the callback and the baton are captured and 
> retained by SBPlatform. The reason of why SBPlatform captures and retains the 
> callback and the baton is the SBPlatformLocateModuleCallback type contains 
> SBModuleSpec type and SBFileSpec type in the argument. Which are not 
> available in Platform.h.
> 
> ```
> typedef SBError (*SBPlatformLocateModuleCallback)(
> void *baton, const SBModuleSpec &module_spec, SBFileSpec 
> &module_file_spec,
> SBFileSpec &symbol_file_spec);
> ```
commented the detailed callback and baton flow here.
https://reviews.llvm.org/D153735#4491892


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153734

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


[Lldb-commits] [PATCH] D153735: [lldb][LocateModuleCallback] Implement API, Python interface

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



Comment at: lldb/source/API/SBPlatform.cpp:664-689
+  if (platform_sp) {
+if (callback) {
+  platform_sp->SetLocateModuleCallback(
+  [callback, callback_baton](const ModuleSpec &module_spec,
+ FileSpec &module_file_spec,
+ FileSpec &symbol_file_spec) {
+SBModuleSpec module_spec_sb(module_spec);

Suggestion: Invert the conditions and use early returns. This function has 
quite a bit of nesting and I think the readability could be improved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

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


[Lldb-commits] [PATCH] D153735: [lldb][LocateModuleCallback] Implement API, Python interface

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added a comment.

@clayborg yes, it'd be possible to pass the baton down to Platform.h since it 
is just `void *`, so no dependencies required.

But, first, let me explain the callback and baton flow.



For Python, user will set a callable Python object as the callback.
For C++ API, user will set a function pointer with a baton as the callback.

Both Python callback and C++ API callback will go into SBPlatform 
SetLocateModuleCallback.
SetLocateModuleCallback will use a lambda in order to convert ModuleSpec and 
FileSpec to SBModuleSpec and SBFileSpec.
This is because Platform.h and Target.cpp are not able to use SBModuleSpec and 
SBFileSpec.

  |   |  |   |  
   |  |
  | user callback |<-(SBModuleSpec, SBFileSpec)->| SBPlatform lambda 
|<-(ModuleSpec, FileSpec)>| Platform |
  |  baton|  |  captures callback|  
   |  |
  |   |  |   baton   |  
   |  |

This summary is what things are retained by which layer.

- Python
  - the user callable object
- SBPlatform
  - C++ API: the user callback and the baton
  - Python: LLDBSwigPythonCallLocateModuleCallback and the user callable object 
as a baton
- Platform
  - SBPlatform lambda in std::function

There are three things.

- SBPlatform lambda created by SetLocateModuleCallback, the type is 
Platform::LocateModuleCallback.
- The user callback or LLDBSwigPythonCallLocateModuleCallback, the type is 
SBPlatformLocateModuleCallback.
- The baton (for Python, this is the callable object)



And back to 'passing the baton down to Platform.h'.
As the locate callback implementation in D153734 
 
lldb/unittests/Target/LocateModuleCallbackTest.cpp,
internal users can use lambda to capture/retain anything for the callback. For 
example, `this` is captured by the locate callback in this case.
Therefore, no need to pass the baton down to Platform.h.

  m_platform_sp->SetLocateModuleCallback([this](const ModuleSpec &module_spec,
FileSpec &module_file_spec,
FileSpec &symbol_file_spec) {
CheckCallbackArgs(module_spec, module_file_spec, symbol_file_spec);
symbol_file_spec.SetPath(GetInputFilePath(k_breakpad_symbol_file));
return Status();
  });




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

2023-07-11 Thread Vladimir Makaev via Phabricator via lldb-commits
VladimirMakaev added a comment.

In D149213#4491594 , @bulbazord wrote:

> I'm curious to know why you don't try and implement some kind of 
> `TypeSystemRust`? I assume it's going to be a lengthy process, but eventually 
> you (or somebody else) is going to want to implement a `TypeSystemRust` in 
> some form and they'll have to revisit all of rust-specific things we've 
> tacked onto various parts of LLDB (e.g. this functionality with 
> DWARFASTParserClang). I suppose the question I'm trying to answer is "How 
> much do we add to LLDB before actually adding proper rust support?"

I think there was an attempt in the past to build TypeSystemRust. Rust Project 
had a fork of LLDB with this implemented by Tom Tromey and CodeLLDB 
maintainer(vadimcn) has one. Both of them were not able to merge that into LLDB 
codebase. A relevant link to a discussion 
https://rust-lang.zulipchat.com/#narrow/stream/317568-t-compiler.2Fwg-debugging/topic/upstreaming.20rust.20support.20into.20lldb

Apart from just implementing type system itself (which is much bigger scope 
than this change) there are other non-trivial issues:

1. There is no "compiler-as-a-service" in Rust so getting expressions to work 
is non-trivial. An interpreter of some sort needs to be built with subset of 
Rust support
2. Infra changes (DEVOPS) changes are required to start building Rust inferiors 
to run tests on CI
3. LLVM / rustc cross repository logistics. Rustc probably needs to live in 
LLVM to make this work well.

Given the fact that the majority of the things "just work" when debugging Rust 
with LLDB (using Clang declarations effectively as of today) I kinda believe 
this is not a bad solution to try to do a bit of extra care for Rust types in 
TypeSystemClang and the debugging experience will be great for Rust users. As 
long as LLDB emits enough information a conversion can be made in synthetic 
provider to display it nicely in debugger. Tests can be written to make sure it 
doesn't rot. This is definitely something I want to improve in this PR too.

I think if Rust Project Debugging WG decides to invest into native 
TypeSystemRust I think having these fixes around isn't going to slow down the 
progress but quite the contrary (in my opinion). And cleaning them up will also 
be trivial since they're specifically guarded by CU check.

> I was also curious about the test. I'm not sure how the test is supposed to 
> work here, is the rust source file actually built or is that just to show how 
> the yaml file was generated? There's no rust support in our testing 
> infrastructure AFAICT so I assume this just makes sure that something already 
> generated doesn't get broken in the future.

I'm gonna work on the test more and try to make assertions against global 
SBValue. Greg suggested this might work. So since we don't have access to rustc 
in the testing setup I've generated object file from main.rs manually and 
converted it to yaml. This makes the test portable. (main.rs is kept for the 
reference)




Comment at: lldb/test/API/lang/rust/enum-structs/TestEnumStructsGenerated.py:14
+src_dir = self.getSourceDir()
+yaml_path = os.path.join(src_dir, "main.yaml")
+obj_path = self.getBuildArtifact("main.o")

clayborg wrote:
> the main.yaml below is empty? Will this test work?
It't not empty it's just big and not opened automatically



Comment at: lldb/test/API/lang/rust/enum-structs/main.rs:1-4
+#![no_std]
+#![no_main]
+use core::ptr::NonNull;
+

clayborg wrote:
> Is this file used at all? I don't see any references to it. I am guessing 
> that the main.yaml is expected to reference this file?
It's not used I've just put it as a reference of the program that the object 
file was taken from. I used rustc to produce object file from this program


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149213

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

2023-07-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

In D149213#4491594 , @bulbazord wrote:

> I'm curious to know why you don't try and implement some kind of 
> `TypeSystemRust`? I assume it's going to be a lengthy process, but eventually 
> you (or somebody else) is going to want to implement a `TypeSystemRust` in 
> some form and they'll have to revisit all of rust-specific things we've 
> tacked onto various parts of LLDB (e.g. this functionality with 
> DWARFASTParserClang). I suppose the question I'm trying to answer is "How 
> much do we add to LLDB before actually adding proper rust support?"

Yes this is a work around until a proper TypeSystemRust is created. It works 
for most things now and this will help enums work using TypeSystemClang.

> I was also curious about the test. I'm not sure how the test is supposed to 
> work here, is the rust source file actually built or is that just to show how 
> the yaml file was generated? There's no rust support in our testing 
> infrastructure AFAICT so I assume this just makes sure that something already 
> generated doesn't get broken in the future.

The yaml generates the binary so no rust compiler or anything is needed for the 
test. I suggested to use a yaml file that has global variables with all of the 
enum types so we can test the SBValue system out to ensure it is working as 
expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149213

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


[Lldb-commits] [PATCH] D153734: [lldb][LocateModuleCallback] Call locate module callback

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:944
   const std::unique_ptr m_module_cache;
+  LocateModuleCallback m_locate_module_callback;
 

clayborg wrote:
> We probably need a baton still. In order to make this work for python, we 
> need to be able to set a callback and a baton for the python callable?
@clayborg Yes, in D153735, both the callback and the baton are captured and 
retained by SBPlatform. The reason of why SBPlatform captures and retains the 
callback and the baton is the SBPlatformLocateModuleCallback type contains 
SBModuleSpec type and SBFileSpec type in the argument. Which are not available 
in Platform.h.

```
typedef SBError (*SBPlatformLocateModuleCallback)(
void *baton, const SBModuleSpec &module_spec, SBFileSpec &module_file_spec,
SBFileSpec &symbol_file_spec);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153734

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


[Lldb-commits] [PATCH] D155030: [lldb][NFCI] Avoid construction of temporary std::strings in RegisterValue

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155030

Files:
  lldb/source/Utility/RegisterValue.cpp


Index: lldb/source/Utility/RegisterValue.cpp
===
--- lldb/source/Utility/RegisterValue.cpp
+++ lldb/source/Utility/RegisterValue.cpp
@@ -342,9 +342,8 @@
   break;
 }
 if (value_str.getAsInteger(0, uval64)) {
-  error.SetErrorStringWithFormat(
-  "'%s' is not a valid unsigned integer string value",
-  value_str.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "'{0}' is not a valid unsigned integer string value", value_str);
   break;
 }
 
@@ -371,9 +370,8 @@
 }
 
 if (value_str.getAsInteger(0, ival64)) {
-  error.SetErrorStringWithFormat(
-  "'%s' is not a valid signed integer string value",
-  value_str.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "'{0}' is not a valid signed integer string value", value_str);
   break;
 }
 


Index: lldb/source/Utility/RegisterValue.cpp
===
--- lldb/source/Utility/RegisterValue.cpp
+++ lldb/source/Utility/RegisterValue.cpp
@@ -342,9 +342,8 @@
   break;
 }
 if (value_str.getAsInteger(0, uval64)) {
-  error.SetErrorStringWithFormat(
-  "'%s' is not a valid unsigned integer string value",
-  value_str.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "'{0}' is not a valid unsigned integer string value", value_str);
   break;
 }
 
@@ -371,9 +370,8 @@
 }
 
 if (value_str.getAsInteger(0, ival64)) {
-  error.SetErrorStringWithFormat(
-  "'%s' is not a valid signed integer string value",
-  value_str.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "'{0}' is not a valid signed integer string value", value_str);
   break;
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D155018: [Support] Move StringExtras.h include from Error.h to Error.cpp (part 5)

2023-07-11 Thread Fangrui Song via Phabricator via lldb-commits
MaskRay added a comment.

Still, would be good to land the lldb commit separately. And ensure that you 
have performed the last-minute testing...
Ensure that projects like `flang bolt` still build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155018

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


[Lldb-commits] [PATCH] D153735: [lldb][LocateModuleCallback] Implement API, Python interface

2023-07-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

It would be nice to pass the baton down into the platform layer if possible so 
that internal users could use the callback + baton. See comments in the other 
diff and see if you agree


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

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

I'm curious to know why you don't try and implement some kind of 
`TypeSystemRust`? I assume it's going to be a lengthy process, but eventually 
you (or somebody else) is going to want to implement a `TypeSystemRust` in some 
form and they'll have to revisit all of rust-specific things we've tacked onto 
various parts of LLDB (e.g. this functionality with DWARFASTParserClang). I 
suppose the question I'm trying to answer is "How much do we add to LLDB before 
actually adding proper rust support?"

I was also curious about the test. I'm not sure how the test is supposed to 
work here, is the rust source file actually built or is that just to show how 
the yaml file was generated? There's no rust support in our testing 
infrastructure AFAICT so I assume this just makes sure that something already 
generated doesn't get broken in the future.




Comment at: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2526-2527
 
+ConstString VariantMember::GetName() const {
+  return ConstString(this->variant_name);
+}

Store `variant_name` as a ConstString instead of creating one each time. 
Creating a `ConstString` (even if the string is in the StringPool) has a 
non-trivial creation cost.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2530
+
+bool VariantMember::IsDefault() const { return !discr_value.has_value(); }
+

`return !discr_value;`

`has_value` does the same thing as `operator bool` for `std::optional`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149213

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


[Lldb-commits] [PATCH] D153734: [lldb][LocateModuleCallback] Call locate module callback

2023-07-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/include/lldb/Target/Platform.h:884-887
+  typedef std::function
+  LocateModuleCallback;

I think we still need a baton for the callback so clients can register a 
callback + void *.



Comment at: lldb/include/lldb/Target/Platform.h:944
   const std::unique_ptr m_module_cache;
+  LocateModuleCallback m_locate_module_callback;
 

We probably need a baton still. In order to make this work for python, we need 
to be able to set a callback and a baton for the python callable?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153734

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

2023-07-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3184
+case DW_TAG_variant_part:
+  ParseVariantPart(die, parent_die, class_clang_type, 
default_accessibility,
+   layout_info);

clayborg wrote:
> I would add a check here for the Rust language. We might also want to rename 
> "ParseVariantPart" to "ParseRustVariant" to indicate this is specific to the 
> Rust language.
Something like:

```
if (die.GetCU()->GetDWARFLanguageType() == eLanguageTypeRust) 
  ParseRustVariant(die, parent_die, class_clang_type, default_accessibility, 
layout_info);
break;
```



Comment at: lldb/test/API/lang/rust/enum-structs/TestEnumStructsGenerated.py:14
+src_dir = self.getSourceDir()
+yaml_path = os.path.join(src_dir, "main.yaml")
+obj_path = self.getBuildArtifact("main.o")

the main.yaml below is empty? Will this test work?



Comment at: lldb/test/API/lang/rust/enum-structs/main.rs:1-4
+#![no_std]
+#![no_main]
+use core::ptr::NonNull;
+

Is this file used at all? I don't see any references to it. I am guessing that 
the main.yaml is expected to reference this file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149213

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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

2023-07-11 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

Overall this looks fine as a way to help rust users see rust enums without 
having to implement a new TypeSystem for rust. I would just ask that we check 
the language of the CU before calling the ParseVariantPart, so that this would 
only get enabled for Rust.




Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:3184
+case DW_TAG_variant_part:
+  ParseVariantPart(die, parent_die, class_clang_type, 
default_accessibility,
+   layout_info);

I would add a check here for the Rust language. We might also want to rename 
"ParseVariantPart" to "ParseRustVariant" to indicate this is specific to the 
Rust language.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149213

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti marked an inline comment as done.
ashgti added a comment.

In D154030#4491470 , @rastogishubham 
wrote:

> I am reverting the change for now, I apologize for any inconvenience

Thanks for reverting that, I'll take a look at the tests and double check them 
on linux as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [lldb] 78af051 - Revert "[lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands."

2023-07-11 Thread Shubham Sandeep Rastogi via lldb-commits

Author: Shubham Sandeep Rastogi
Date: 2023-07-11T15:16:03-07:00
New Revision: 78af051ff0e16db73201b1370e34206a6a4c1b93

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

LOG: Revert "[lldb-vscode] Creating a new flag for adjusting the behavior of 
evaluation repl expressions to allow users to more easily invoke lldb commands."

This reverts commit 16317f1ced77e1d8711188f2fcc6c86a783d9c56.

Reverting because of test failures:

 TEST 'lldb-api :: 
tools/lldb-vscode/console/TestVSCode_console.py' FAILED 
Script:
--
/usr/local/Frameworks/Python.framework/Versions/3.10/bin/python3.10 
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --codesign-identity lldb_codesign --env 
LLVM_LIBS_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./lib 
--env 
LLVM_INCLUDE_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/include
 --env 
LLVM_TOOLS_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin 
--libcxx-include-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/include/c++/v1 
--libcxx-library-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib --arch x86_64 
--build-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/lldb --compiler 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/clang 
--dsymutil 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/dsymutil 
--llvm-tools-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin --lldb-libs-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./lib --build-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex
 -t --env TERM=vt100 
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/API/tools/lldb-vscode/console
 -p TestVSCode_console.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/57586/

Added: 


Modified: 
lldb/tools/lldb-vscode/Options.td
lldb/tools/lldb-vscode/README.md
lldb/tools/lldb-vscode/VSCode.cpp
lldb/tools/lldb-vscode/VSCode.h
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/Options.td 
b/lldb/tools/lldb-vscode/Options.td
index 8c51a994ebc270..a73671ad749c47 100644
--- a/lldb/tools/lldb-vscode/Options.td
+++ b/lldb/tools/lldb-vscode/Options.td
@@ -39,7 +39,3 @@ def debugger_pid: Separate<["--", "-"], "debugger-pid">,
   MetaVarName<"">,
   HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal 
"
 "request when using --launch-target.">;
-
-def repl_mode: S<"repl-mode">,
-  MetaVarName<"">,
-  HelpText<"The mode for handling repl evaluation requests, supported modes: 
variable, command, auto.">;

diff  --git a/lldb/tools/lldb-vscode/README.md 
b/lldb/tools/lldb-vscode/README.md
index 154ccefc5f5979..cd249ed2fac7c6 100644
--- a/lldb/tools/lldb-vscode/README.md
+++ b/lldb/tools/lldb-vscode/README.md
@@ -236,22 +236,3 @@ This will launch a server and then request a child debug 
session for a client.
   ]
 }
 ```
-
-## repl-mode
-
-Inspect or adjust the behavior of lldb-vscode repl evaluation requests. The
-supported modes are `variable`, `command` and `auto`.
-
-*  `variable` - Variable mode expressions are evaluated in the context of the
-   current frame. Use a `\`` prefix on the command to run an lldb command.
-*  `command` - Command mode expressions are evaluated as lldb commands, as a
-   result, values printed by lldb are always stringified representations of the
-   expression output.
-*  `auto` - Auto mode will attempt to infer if the expression represents an 
lldb
-   command or a variable expression. A heuristic is used to infer if the input
-   represents a variable or a command. Use a `\`` prefix to ensure an 
expression
-   is evaluated as a command.
-
-The initial repl-mode can be configured with the cli flag `--repl-mode=`
-and may also be adjusted at runtime using the lldb command
-`lldb-vscode repl-mode `.

diff  --git a/lldb/tools/lldb-vscode/VSCode.cpp 
b/lldb/tools/lldb-vscode/VSCode.cpp
index f007e09eee1e1d..b1c6817c2128b9 100644
--- a/lldb/tools/lldb-vscode/VSCode.cpp
+++ b/lldb/tools/lldb-vscode/VSCode.cpp
@@ -44,8 +44,7 @@ VSCode::VSCode()
   configuration_done_sent(false), waiting_for_run_in_terminal(false),
   progress_event_reporter(
   [&](const Progress

[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread Shubham Sandeep Rastogi via Phabricator via lldb-commits
rastogishubham added a comment.

I am reverting the change for now, I apologize for any inconvenience


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread Shubham Sandeep Rastogi via Phabricator via lldb-commits
rastogishubham added a comment.

It looks like this change is breaking some lldb tests. 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/57586/consoleFull#-1731262255a1ca8a51-895e-46c6-af87-ce24fa4cd561

- TEST 'lldb-api :: tools/lldb-vscode/console/TestVSCode_console.py' FAILED 


Script:
---

/usr/local/Frameworks/Python.framework/Versions/3.10/bin/python3.10 
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --codesign-identity lldb_codesign --env 
LLVM_LIBS_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./lib 
--env 
LLVM_INCLUDE_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/include
 --env 
LLVM_TOOLS_DIR=/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin 
--libcxx-include-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/include/c++/v1 
--libcxx-library-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lib --arch x86_64 
--build-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex
 --lldb-module-cache-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/lldb --compiler 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/clang 
--dsymutil 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin/dsymutil 
--llvm-tools-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./bin --lldb-libs-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/./lib --build-dir 
/Users/buildslave/jenkins/workspace/lldb-cmake/lldb-build/lldb-test-build.noindex
 -t --env TERM=vt100 
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/lldb/test/API/tools/lldb-vscode/console
 -p TestVSCode_console.py


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

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

My concerns have been addressed, LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152837

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


[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

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

Applying clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154989

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
@@ -191,6 +191,28 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (!g_vsc.configuration_done_sent ||
+  g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued"));
+  llvm::json::Object body;
+  body.try_emplace("threadId", (int64_t)g_vsc.focus_tid);
+  body.try_emplace("allThreadsContinued", true);
+  event.try_emplace("body", std::move(body));
+  g_vsc.SendJSON(llvm::json::Value(std::move(event)));
+}
+
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
@@ -252,7 +274,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -262,6 +284,7 @@
   // we at least let the UI know we stopped.
   if (num_threads_with_reason == 0) {
 lldb::SBThread thread = process.GetThreadAtIndex(0);
+g_vsc.focus_tid = thread.GetThreadID();
 g_vsc.SendJSON(CreateThreadStopped(thread, stop_id));
   } else {
 for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
@@ -468,6 +491,7 @@
 break;
   case lldb::eStateRunning:
 g_vsc.WillContinue();
+SendContinuedEvent();
 break;
   case lldb::eStateExited:
 // When restarting, we can get an "exited" event for the process we
@@ -766,10 +790,6 @@
   llvm::json::Object response;
   FillResponse(request, response);
   lldb::SBProcess process = g_vsc.target.GetProcess();
-  auto arguments = request.getObject("arguments");
-  // Remember the thread ID that caused the resume so we can set the
-  // "threadCausedFocus" boolean value in the "stopped" events.
-  g_vsc.focus_tid = GetUnsigned(arguments, "threadId", LLDB_INVALID_THREAD_ID);
   lldb::SBError error = process.Continue();
   llvm::json::Object body;
   body.try_emplace("allThreadsContinued", true);
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -901,6 +901,8 @@
   uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
   snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64,
bp_id, bp_loc_id);
+  body.try_emplace("hitBreakpointIds",
+   llvm::json::Array{llvm::json::Value(bp_id)});
   EmplaceSafeString(body, "description", desc_str);
 }
   } break;
@@ -945,9 +947,6 @@
   EmplaceSafeString(body, "description", std::string(description));
 }
   }
-  if (tid == g_vsc.focus_tid) {
-body.try_emplace("threadCausedFocus", true);
-  }
   body.try_emplace("preserveFocusHint", tid != g_vsc.focus_tid);
   body.try_emplace("allThreadsStopped", true);
   event.try_emplace("body", std::move(body));


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -191,6 +191,28 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (!g_vsc.configuration_done_sent ||
+  g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued"));
+  llvm::json::Object body;
+  body.try_emplace("threadId", (int64_t)g_vsc.focus_tid);
+  body.try_emplace("allThreadsContinued", true);
+  event.try_emplace("

[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

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

Removing the focus_tid invalidation on the continue event, that was incorrectly 
setting the focus_tid to 0 for all continue events. Instead allow the existing 
logic in the SendThreadStoppedEvent to infer the correct focus_tid updates 
(if needed).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154989

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/VSCode.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
@@ -191,6 +191,27 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (!g_vsc.configuration_done_sent || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued"));
+  llvm::json::Object body;
+  body.try_emplace("threadId", (int64_t)g_vsc.focus_tid);
+  body.try_emplace("allThreadsContinued", true);
+  event.try_emplace("body", std::move(body));
+  g_vsc.SendJSON(llvm::json::Value(std::move(event)));
+}
+
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
@@ -252,7 +273,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -262,6 +283,7 @@
   // we at least let the UI know we stopped.
   if (num_threads_with_reason == 0) {
 lldb::SBThread thread = process.GetThreadAtIndex(0);
+g_vsc.focus_tid = thread.GetThreadID();
 g_vsc.SendJSON(CreateThreadStopped(thread, stop_id));
   } else {
 for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
@@ -468,6 +490,7 @@
 break;
   case lldb::eStateRunning:
 g_vsc.WillContinue();
+SendContinuedEvent();
 break;
   case lldb::eStateExited:
 // When restarting, we can get an "exited" event for the process we
@@ -766,10 +789,6 @@
   llvm::json::Object response;
   FillResponse(request, response);
   lldb::SBProcess process = g_vsc.target.GetProcess();
-  auto arguments = request.getObject("arguments");
-  // Remember the thread ID that caused the resume so we can set the
-  // "threadCausedFocus" boolean value in the "stopped" events.
-  g_vsc.focus_tid = GetUnsigned(arguments, "threadId", LLDB_INVALID_THREAD_ID);
   lldb::SBError error = process.Continue();
   llvm::json::Object body;
   body.try_emplace("allThreadsContinued", true);
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -264,7 +264,9 @@
   void RegisterRequestCallback(std::string request, RequestCallback callback);
 
   /// Debuggee will continue from stopped state.
-  void WillContinue() { variables.Clear(); }
+  void WillContinue() {
+variables.Clear();
+  }
 
   /// Poll the process to wait for it to reach the eStateStopped state.
   ///
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -901,6 +901,8 @@
   uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
   snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64,
bp_id, bp_loc_id);
+  body.try_emplace("hitBreakpointIds",
+   llvm::json::Array{llvm::json::Value(bp_id)});
   EmplaceSafeString(body, "description", desc_str);
 }
   } break;
@@ -945,9 +947,6 @@
   EmplaceSafeString(body, "description", std::string(description));
 }
   }
-  if (tid == g_vsc.focus_tid) {
-body.try_emplace("threadCausedFocus", true);
-  }
   body.try_emplace("preserveFocusHint", tid != g_vsc.focus_tid);
   body.try_emplace("allThreadsStopped", true);
   event.try_emplace("body", std::move(body));
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added a comment.

@bulbazord  @augusto2112 hopefully this is a quick review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152837

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


[Lldb-commits] [PATCH] D155018: [Support] Move StringExtras.h include from Error.h to Error.cpp (part 5)

2023-07-11 Thread Elliot Goodrich via Phabricator via lldb-commits
IncludeGuardian added inline comments.
Herald added a subscriber: JDevlieghere.



Comment at: lldb/tools/lldb-vscode/VSCode.cpp:17
 #include "llvm/Support/FormatVariadic.h"

 #if defined(_WIN32)
 #define NOMINMAX

This should be the final failure on the last time landing the `Error.h` change 
to `main` https://lab.llvm.org/buildbot#builders/68/builds/55847


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155018

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


[Lldb-commits] [PATCH] D155018: [Support] Move StringExtras.h include from Error.h to Error.cpp (part 5)

2023-07-11 Thread Elliot Goodrich via Phabricator via lldb-commits
IncludeGuardian created this revision.
IncludeGuardian added a reviewer: MaskRay.
Herald added a subscriber: hiraditya.
Herald added a project: All.
IncludeGuardian requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

**1st commit**
[lldb] Add missing StringExtras.h includes

In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.

This is fixing all files missed in b0abd4893fa1 
, 
39d8e6e22cd1 
,
a11efd49266f 
, and 
5551657b310b 
.

---

**2nd commit**
[Support] Move StringExtras.h include from Error.h to Error.cpp

Move the implementation of the `toString` function from
`llvm/Support/Error.h` to the source file, which allows us to move
`#include "llvm/ADT/StringExtras.h"` to the source file as well.

As `Error.h` is present in a large number of translation units this
means we are unnecessarily bringing in the contents of
`StringExtras.h` - itself a large file with lots of includes - and
slowing down compilation.

Also move the `#include "llvm/ADT/SmallVector.h"` directive to the
source file as it's no longer needed, but this does not give as much of
a benefit.

This reduces the total number of preprocessing tokens across the LLVM
source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a
reduction of ~0.87%. This should result in a small improvement in
compilation time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155018

Files:
  lldb/tools/lldb-vscode/VSCode.cpp
  llvm/include/llvm/Support/Error.h
  llvm/lib/Support/Error.cpp

Index: llvm/lib/Support/Error.cpp
===
--- llvm/lib/Support/Error.cpp
+++ llvm/lib/Support/Error.cpp
@@ -7,27 +7,29 @@
 //===--===//

 #include "llvm/Support/Error.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 

 using namespace llvm;

 namespace {

   enum class ErrorErrorCode : int {
 MultipleErrors = 1,
 FileError,
 InconvertibleError
   };

   // FIXME: This class is only here to support the transition to llvm::Error. It
   // will be removed once this transition is complete. Clients should prefer to
   // deal with the Error value directly, rather than converting to error_code.
   class ErrorErrorCategory : public std::error_category {
   public:
 const char *name() const noexcept override { return "Error"; }

 std::string message(int condition) const override {
   switch (static_cast(condition)) {
   case ErrorErrorCode::MultipleErrors:
@@ -70,17 +72,26 @@
   });
 }

+/// Write all error messages (if any) in E to a string. The newline character
+/// is used to separate error messages.
+std::string toString(Error E) {
+  SmallVector Errors;
+  handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) {
+Errors.push_back(EI.message());
+  });
+  return join(Errors.begin(), Errors.end(), "\n");
+}

 std::error_code ErrorList::convertToErrorCode() const {
   return std::error_code(static_cast(ErrorErrorCode::MultipleErrors),
  getErrorErrorCat());
 }

 std::error_code inconvertibleErrorCode() {
   return std::error_code(static_cast(ErrorErrorCode::InconvertibleError),
  getErrorErrorCat());
 }

 std::error_code FileError::convertToErrorCode() const {
   std::error_code NestedEC = Err->convertToErrorCode();
   if (NestedEC == inconvertibleErrorCode())
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -14,8 +14,6 @@
 #define LLVM_SUPPORT_ERROR_H

 #include "llvm-c/Error.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/abi-breaking.h"
 #include "llvm/Support/AlignOf.h"
@@ -1025,14 +1023,8 @@

 /// Write all error messages (if any) in E to a string. The newline character
 /// is used to separate error messages.
-inline std::string toString(Error E) {
-  SmallVector Errors;
-  handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) {
-Errors.push_back(EI.message());
-  });
-  return join(Errors.begin(), Errors.end(), "\n");
-}
+std::string toString(Error E);

 /// Consume a Error without doing anything. This method should be used
 /// only where an error can be considered a reasonable and expec

[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

2023-07-11 Thread David Goldman via Phabricator via lldb-commits
dgoldman added inline comments.



Comment at: lldb/tools/lldb-vscode/lldb-vscode.cpp:285
   if (num_threads_with_reason == 0) {
 lldb::SBThread thread = process.GetThreadAtIndex(0);
 g_vsc.SendJSON(CreateThreadStopped(thread, stop_id));

Should we also set g_vsc.focus_tid here if it's invalid?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154989

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread David Goldman via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16317f1ced77: [lldb-vscode] Creating a new flag for 
adjusting the behavior of evaluation repl… (authored by ashgti, committed by 
dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

Files:
  lldb/tools/lldb-vscode/Options.td
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.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
@@ -1065,50 +1065,63 @@
   FillResponse(request, response);
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
+
+  // If we have a frame, try to set the context for variable completions.
+  lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
+  if (frame.IsValid()) {
+frame.GetThread().GetProcess().SetSelectedThread(frame.GetThread());
+frame.GetThread().SetSelectedFrame(frame.GetFrameID());
+  }
+
   std::string text = std::string(GetString(arguments, "text"));
   auto original_column = GetSigned(arguments, "column", text.size());
-  auto actual_column = original_column - 1;
+  auto original_line = GetSigned(arguments, "line", 1);
+  auto offset = original_column - 1;
+  if (original_line > 1) {
+llvm::StringRef text_ref{text};
+::llvm::SmallVector<::llvm::StringRef, 2> lines;
+text_ref.split(lines, '\n');
+for (int i = 0; i < original_line - 1; i++) {
+  offset += lines[i].size();
+}
+  }
   llvm::json::Array targets;
-  // NOTE: the 'line' argument is not needed, as multiline expressions
-  // work well already
-  // TODO: support frameID. Currently
-  // g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions
-  // is frame-unaware.
-
-  if (!text.empty() && text[0] == '`') {
-text = text.substr(1);
-actual_column--;
-  } else {
-char command[] = "expression -- ";
+
+  if (g_vsc.DetectExpressionContext(frame, text) ==
+  ExpressionContext::Variable) {
+char command[] = "frame variable ";
 text = command + text;
-actual_column += strlen(command);
+offset += strlen(command);
   }
   lldb::SBStringList matches;
   lldb::SBStringList descriptions;
-  g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
-  text.c_str(), actual_column, 0, -1, matches, descriptions);
-  size_t count = std::min((uint32_t)100, matches.GetSize());
-  targets.reserve(count);
-  for (size_t i = 0; i < count; i++) {
-std::string match = matches.GetStringAtIndex(i);
-std::string description = descriptions.GetStringAtIndex(i);
-
-llvm::json::Object item;
-
-llvm::StringRef match_ref = match;
-for (llvm::StringRef commit_point : {".", "->"}) {
-  if (match_ref.contains(commit_point)) {
-match_ref = match_ref.rsplit(commit_point).second;
+
+  if (g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
+  text.c_str(), offset, 0, 100, matches, descriptions)) {
+// The first element is the common substring after the cursor position for
+// all the matches. The rest of the elements are the matches.
+targets.reserve(matches.GetSize() - 1);
+std::string common_pattern = matches.GetStringAtIndex(0);
+for (size_t i = 1; i < matches.GetSize(); i++) {
+  std::string match = matches.GetStringAtIndex(i);
+  std::string description = descriptions.GetStringAtIndex(i);
+
+  llvm::json::Object item;
+  llvm::StringRef match_ref = match;
+  for (llvm::StringRef commit_point : {".", "->"}) {
+if (match_ref.contains(commit_point)) {
+  match_ref = match_ref.rsplit(commit_point).second;
+}
   }
-}
-EmplaceSafeString(item, "text", match_ref);
+  EmplaceSafeString(item, "text", match_ref);
 
-if (description.empty())
-  EmplaceSafeString(item, "label", match);
-else
-  EmplaceSafeString(item, "label", match + " -- " + description);
+  if (description.empty())
+EmplaceSafeString(item, "label", match);
+  else
+EmplaceSafeString(item, "label", match + " -- " + description);
 
-targets.emplace_back(std::move(item));
+  targets.emplace_back(std::move(item));
+}
   }
 
   body.try_emplace("targets", std::move(targets));
@@ -1223,12 +1236,17 @@
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
   lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
-  const auto expression = GetString(arguments, "expression");
+  std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
 
-  if (!expression.empty() && expression[0] == '`') {
-auto result =
-RunLLDBCommands(llvm::StringRef(), {std:

[Lldb-commits] [lldb] 16317f1 - [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

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

Author: John Harrison
Date: 2023-07-11T16:37:25-04:00
New Revision: 16317f1ced77e1d8711188f2fcc6c86a783d9c56

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

LOG: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation 
repl expressions to allow users to more easily invoke lldb commands.

This adds a new flag and lldb runtime command to allow users to manage the 
behavior of the lldb-vscode evaluate repl request.

When evaluating a repl context this now has runtime managed flag for control 
how the repl behaviors with the follow values:

* `variable` - the existing behavior, with this mode requests are evaluted in 
the current frame context as variable expressions. To trigger a lldb command 
prefix an expression with ` and it will be evaluted as an lldb command.
* `command` - all expressions are evaluated as lldb commands.
* `auto` - An alternative mode that will attempt to determine if the expression 
is an lldb command or a variable expression. Based off the intepreted results 
the expression will be evaluted either as a command or an expression.

Additionally, I enabled completions and ensured they work with the new repl 
expression behavior to provide auto-completes.

RFC Discussion: 
https://discourse.llvm.org/t/rfc-lldb-vscode-evaluate-repl-behavior-and-improvements/71667

Reviewed By: wallace

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

Added: 


Modified: 
lldb/tools/lldb-vscode/Options.td
lldb/tools/lldb-vscode/README.md
lldb/tools/lldb-vscode/VSCode.cpp
lldb/tools/lldb-vscode/VSCode.h
lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 




diff  --git a/lldb/tools/lldb-vscode/Options.td 
b/lldb/tools/lldb-vscode/Options.td
index a73671ad749c47..8c51a994ebc270 100644
--- a/lldb/tools/lldb-vscode/Options.td
+++ b/lldb/tools/lldb-vscode/Options.td
@@ -39,3 +39,7 @@ def debugger_pid: Separate<["--", "-"], "debugger-pid">,
   MetaVarName<"">,
   HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal 
"
 "request when using --launch-target.">;
+
+def repl_mode: S<"repl-mode">,
+  MetaVarName<"">,
+  HelpText<"The mode for handling repl evaluation requests, supported modes: 
variable, command, auto.">;

diff  --git a/lldb/tools/lldb-vscode/README.md 
b/lldb/tools/lldb-vscode/README.md
index cd249ed2fac7c6..154ccefc5f5979 100644
--- a/lldb/tools/lldb-vscode/README.md
+++ b/lldb/tools/lldb-vscode/README.md
@@ -236,3 +236,22 @@ This will launch a server and then request a child debug 
session for a client.
   ]
 }
 ```
+
+## repl-mode
+
+Inspect or adjust the behavior of lldb-vscode repl evaluation requests. The
+supported modes are `variable`, `command` and `auto`.
+
+*  `variable` - Variable mode expressions are evaluated in the context of the
+   current frame. Use a `\`` prefix on the command to run an lldb command.
+*  `command` - Command mode expressions are evaluated as lldb commands, as a
+   result, values printed by lldb are always stringified representations of the
+   expression output.
+*  `auto` - Auto mode will attempt to infer if the expression represents an 
lldb
+   command or a variable expression. A heuristic is used to infer if the input
+   represents a variable or a command. Use a `\`` prefix to ensure an 
expression
+   is evaluated as a command.
+
+The initial repl-mode can be configured with the cli flag `--repl-mode=`
+and may also be adjusted at runtime using the lldb command
+`lldb-vscode repl-mode `.

diff  --git a/lldb/tools/lldb-vscode/VSCode.cpp 
b/lldb/tools/lldb-vscode/VSCode.cpp
index b1c6817c2128b9..f007e09eee1e1d 100644
--- a/lldb/tools/lldb-vscode/VSCode.cpp
+++ b/lldb/tools/lldb-vscode/VSCode.cpp
@@ -44,7 +44,8 @@ VSCode::VSCode()
   configuration_done_sent(false), waiting_for_run_in_terminal(false),
   progress_event_reporter(
   [&](const ProgressEvent &event) { SendJSON(event.ToJSON()); }),
-  reverse_request_seq(0) {
+  reverse_request_seq(0), repl_mode(ReplMode::Auto),
+  auto_repl_mode_collision_warning(false) {
   const char *log_file_path = getenv("LLDBVSCODE_LOG");
 #if defined(_WIN32)
   // Windows opens stdout and stdin in text mode which converts \n to 13,10
@@ -392,6 +393,50 @@ llvm::json::Value VSCode::CreateTopLevelScopes() {
   return llvm::json::Value(std::move(scopes));
 }
 
+ExpressionContext VSCode::DetectExpressionContext(lldb::SBFrame &frame,
+  std::string &text) {
+  // Include ` as an escape hatch.
+  if (!text.empty() && text[0] == '`') {
+text = text.substr(1);
+return ExpressionContext::Command;
+  }
+
+  switch (repl_mode) {
+  case ReplMode::Variable:
+return ExpressionContext::Variable;
+  case ReplMode::Command:
+return ExpressionContext::Comman

[Lldb-commits] [PATCH] D152837: [lldb] Identify Swift-implemented ObjC classes

2023-07-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione updated this revision to Diff 539268.
kastiglione added a comment.

Refactor for better API layering


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152837

Files:
  lldb/include/lldb/Target/LanguageRuntime.h
  lldb/include/lldb/Target/Process.h
  lldb/source/Core/ValueObjectDynamicValue.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
  
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
  lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
  lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
  lldb/source/Target/Process.cpp

Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -22,6 +22,7 @@
 #include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/StreamFile.h"
+#include "lldb/Core/ValueObject.h"
 #include "lldb/Expression/DiagnosticManager.h"
 #include "lldb/Expression/DynamicCheckerFunctions.h"
 #include "lldb/Expression/UserExpression.h"
@@ -1553,6 +1554,13 @@
   return runtime;
 }
 
+LanguageRuntime *Process::GetLanguageRuntime(ValueObject &in_value) {
+  auto language = in_value.GetObjectRuntimeLanguage();
+  if (auto *runtime = GetLanguageRuntime(language))
+return runtime->GetPreferredLanguageRuntime(in_value);
+  return nullptr;
+}
+
 bool Process::IsPossibleDynamicValue(ValueObject &in_value) {
   if (m_finalizing)
 return false;
Index: lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h
@@ -86,6 +86,9 @@
   return (m_is_cf == eLazyBoolYes);
 }
 
+/// Determine whether this class is implemented in Swift.
+virtual bool IsSwift() const { return false; }
+
 virtual bool IsValid() = 0;
 
 /// There are two routines in the ObjC runtime that tagged pointer clients
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
@@ -38,6 +38,8 @@
 
   static llvm::StringRef GetPluginNameStatic() { return "apple-objc-v2"; }
 
+  LanguageRuntime *GetPreferredLanguageRuntime(ValueObject &in_value) override;
+
   static char ID;
 
   bool isA(const void *ClassID) const override {
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -712,6 +712,20 @@
   RegisterObjCExceptionRecognizer(process);
 }
 
+LanguageRuntime *
+AppleObjCRuntimeV2::GetPreferredLanguageRuntime(ValueObject &in_value) {
+  if (auto process_sp = in_value.GetProcessSP()) {
+assert(process_sp.get() == m_process);
+if (auto descriptor_sp = GetNonKVOClassDescriptor(in_value))
+  if (descriptor_sp->IsSwift())
+// This class is implemented in Swift, making it the preferred runtime.
+if (auto *swift_runtime =
+process_sp->GetLanguageRuntime(lldb::eLanguageTypeSwift))
+  return swift_runtime;
+  }
+  return this;
+}
+
 bool AppleObjCRuntimeV2::GetDynamicTypeAndAddress(
 ValueObject &in_value, lldb::DynamicValueType use_dynamic,
 TypeAndOrName &class_type_or_name, Address &address,
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.h
@@ -34,6 +34,8 @@
 return true; // any Objective-C v2 runtime class descriptor we vend is valid
   }
 
+  bool IsSwift() const override;
+
   // a custom descriptor is used for tagged pointers
   bool GetTaggedPointerInfo(uint64_t *info_bits = nullptr,
 uint64_t *value_bits = nullptr,
Index: lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
===
--- lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
+++ lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV

[Lldb-commits] [PATCH] D154990: [lldb-vsocde] Cleaning up the usage of the Separate helper in Options.td.

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

wooo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154990

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


[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

2023-07-11 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!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154989

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

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

nice!!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [PATCH] D154992: Add a generic Process method to dump plugin history

2023-07-11 Thread Jim Ingham via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8402ad23104b: Add a generic Process method to dump plugin 
history. (authored by jingham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154992

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -77,6 +77,8 @@
 bool plugin_specified_by_name) override;
 
   CommandObject *GetPluginCommandObject() override;
+  
+  void DumpPluginHistory(Stream &s) override;
 
   // Creating a new process, or attaching to an existing one
   Status DoWillLaunch(Module *module) override;
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -113,7 +113,7 @@
 return;
   }
   StreamFile stream(std::move(file.get()));
-  ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(stream);
+  ((Process *)p)->DumpPluginHistory(stream);
 }
 } // namespace lldb
 
@@ -205,6 +205,11 @@
   return process_sp;
 }
 
+void ProcessGDBRemote::DumpPluginHistory(Stream &s) {
+  GDBRemoteCommunicationClient &gdb_comm(GetGDBRemote());
+  gdb_comm.DumpHistory(s);
+}
+
 std::chrono::seconds ProcessGDBRemote::GetPacketTimeout() {
   return std::chrono::seconds(GetGlobalPluginProperties().GetPacketTimeout());
 }
@@ -5217,7 +5222,7 @@
 ProcessGDBRemote *process =
 (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr();
 if (process) {
-  process->GetGDBRemote().DumpHistory(result.GetOutputStream());
+  process->DumpPluginHistory(result.GetOutputStream());
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return true;
 }
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -457,7 +457,7 @@
   if (log) {
 if (log->GetVerbose()) {
   StreamString strm;
-  gdb_comm.DumpHistory(strm);
+  process->DumpPluginHistory(strm);
   LLDB_LOGF(log,
 "error: failed to get packet sequence mutex, not sending "
 "write register for \"%s\":\n%s",
@@ -566,7 +566,7 @@
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "read all registers:\n%s",
@@ -741,7 +741,7 @@
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "write all registers:\n%s",
Index: lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
===
--- lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -744,6 +744,7 @@
   }
 }
   }
+  thread.GetProcess()->DumpPluginHistory(s);
   llvm::report_fatal_error(s.GetData());
   lldbassert(
   false &&
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -575,6 +575,10 @@
   /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
   /// or CommandObjectMultiword.
   virtual CommandObject *GetPluginCommandObject() { return nullptr; }
+  
+  /// The underlying plugin might store the low-level communication history for
+  /// this session.  Dump it into the provided stream.
+  virtual void DumpPluginHistory(Stream &s) { return; }
 
   /// Launch a new process.
   ///
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 8402ad2 - Add a generic Process method to dump plugin history.

2023-07-11 Thread Jim Ingham via lldb-commits

Author: Jim Ingham
Date: 2023-07-11T12:33:22-07:00
New Revision: 8402ad23104b6b20f07596738b02a4ab101a8af9

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

LOG: Add a generic Process method to dump plugin history.

I need to call this to figure out why the assert in
StopInfoMachException::CreateStopReasonWithMachException is triggering, but
it isn't appropriate to directly access the GDBRemoteCommunication there.  And
dumping whatever history the process plugin has collected during the run isn't
gdb-remote specific...

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

Added: 


Modified: 
lldb/include/lldb/Target/Process.h
lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Removed: 




diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index dfed3659432df0..affd3fbc37b07a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -575,6 +575,10 @@ class Process : public 
std::enable_shared_from_this,
   /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
   /// or CommandObjectMultiword.
   virtual CommandObject *GetPluginCommandObject() { return nullptr; }
+  
+  /// The underlying plugin might store the low-level communication history for
+  /// this session.  Dump it into the provided stream.
+  virtual void DumpPluginHistory(Stream &s) { return; }
 
   /// Launch a new process.
   ///

diff  --git a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp 
b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
index b4301f21ac1032..d60e6250c7c0ac 100644
--- a/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ b/lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -744,6 +744,7 @@ StopInfoSP 
StopInfoMachException::CreateStopReasonWithMachException(
   }
 }
   }
+  thread.GetProcess()->DumpPluginHistory(s);
   llvm::report_fatal_error(s.GetData());
   lldbassert(
   false &&

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 8ea93655d6bbf2..e8606ddae5674a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -457,7 +457,7 @@ bool GDBRemoteRegisterContext::WriteRegisterBytes(const 
RegisterInfo *reg_info,
   if (log) {
 if (log->GetVerbose()) {
   StreamString strm;
-  gdb_comm.DumpHistory(strm);
+  process->DumpPluginHistory(strm);
   LLDB_LOGF(log,
 "error: failed to get packet sequence mutex, not sending "
 "write register for \"%s\":\n%s",
@@ -566,7 +566,7 @@ bool GDBRemoteRegisterContext::ReadAllRegisterValues(
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "read all registers:\n%s",
@@ -741,7 +741,7 @@ bool GDBRemoteRegisterContext::WriteAllRegisterValues(
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "write all registers:\n%s",

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp 
b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 522dee9f768620..b6f146fd872e80 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -113,7 +113,7 @@ void DumpProcessGDBRemotePacketHistory(void *p, const char 
*path) {
 return;
   }
   StreamFile stream(std::move(file.get()));
-  ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(stream);
+  ((Process *)p)->DumpPluginHistory(stream);
 }
 } // namespace lldb
 
@@ -205,6 +205,11 @@ lldb::ProcessSP ProcessGDBRemote::CreateInstance(
   return process_sp;
 }
 
+void ProcessGDBRemote::DumpPluginHistory(Stream &s) {
+  GDBRemoteCommunicationClient &gdb_comm(GetGDBRemote());
+  gdb_comm.DumpHistory(s);
+}
+
 std::chrono::seconds ProcessGDBRemote::GetPacketTimeout() {
   return std::chrono::seconds(GetGlobalPluginProperties().GetPacketTimeout());
 }
@@ -5217,7 +

[Lldb-commits] [PATCH] D153735: [lldb][TargetGetModuleCallback] Implement Python interface

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 539238.
splhack added a comment.

- Rename 'get module callback' to 'locate module callback'
- SBPlatform will do
  - capture callback(SBPlatformLocateModuleCallback) and baton(void *)
  - convert ModuleSpec/FileSpec from/to SBModuleSpec/SBFileSpec for calling the 
callback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

Files:
  lldb/bindings/python/python-typemaps.swig
  lldb/bindings/python/python-wrapper.swig
  lldb/include/lldb/API/SBDefines.h
  lldb/include/lldb/API/SBPlatform.h
  lldb/source/API/SBPlatform.cpp
  lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py

Index: lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py
===
--- /dev/null
+++ lldb/test/API/python_api/sbplatform/TestLocateModuleCallback.py
@@ -0,0 +1,338 @@
+"""
+Test platform locate module callback functionality
+"""
+
+import ctypes
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from pathlib import Path
+
+import lldb
+
+UNITTESTS_TARGET_INPUTS_PATH = "../../../../unittests/Target/Inputs"
+MODULE_PLATFORM_PATH = "/system/lib64/AndroidModule.so"
+MODULE_TRIPLE = "aarch64-none-linux"
+MODULE_RESOLVED_TRIPLE = "aarch64--linux-android"
+MODULE_UUID = "80008338-82A0-51E5-5922-C905D23890DA-BDDEFECC"
+MODULE_FUNCTION = "boom"
+MODULE_HIDDEN_FUNCTION = "boom_hidden"
+MODULE_FILE = "AndroidModule.so"
+MODULE_NON_EXISTENT_FILE = "non-existent-file"
+SYMBOL_FILE = "AndroidModule.unstripped.so"
+BREAKPAD_SYMBOL_FILE = "AndroidModule.so.sym"
+SYMBOL_STRIPPED = "stripped"
+SYMBOL_UNSTRIPPED = "unstripped"
+
+
+class LocateModuleCallbackTestCase(TestBase):
+def setUp(self):
+TestBase.setUp(self)
+self.platform = self.dbg.GetSelectedPlatform()
+self.target = self.dbg.CreateTarget("")
+self.assertTrue(self.target)
+
+self.input_dir = (
+Path(self.getSourceDir()) / UNITTESTS_TARGET_INPUTS_PATH
+).resolve()
+self.assertTrue(self.input_dir.is_dir())
+
+def check_module_spec(self, module_spec: lldb.SBModuleSpec):
+self.assertEqual(
+MODULE_UUID.replace("-", ""),
+ctypes.string_at(
+int(module_spec.GetUUIDBytes()),
+module_spec.GetUUIDLength(),
+)
+.hex()
+.upper(),
+)
+
+self.assertEqual(MODULE_TRIPLE, module_spec.GetTriple())
+
+self.assertEqual(MODULE_PLATFORM_PATH, module_spec.GetFileSpec().fullpath)
+
+def check_module(self, module: lldb.SBModule, symbol_file: str, symbol_kind: str):
+self.assertTrue(module.IsValid())
+
+self.assertEqual(
+MODULE_UUID,
+module.GetUUIDString(),
+)
+
+self.assertEqual(MODULE_RESOLVED_TRIPLE, module.GetTriple())
+
+self.assertEqual(MODULE_PLATFORM_PATH, module.GetPlatformFileSpec().fullpath)
+
+self.assertEqual(
+str(self.input_dir / MODULE_FILE),
+module.GetFileSpec().fullpath,
+)
+
+self.assertEqual(
+str(self.input_dir / symbol_file),
+module.GetSymbolFileSpec().fullpath,
+)
+
+sc_list = module.FindFunctions(MODULE_FUNCTION, lldb.eSymbolTypeCode)
+self.assertEqual(1, sc_list.GetSize())
+sc_list = module.FindFunctions(MODULE_HIDDEN_FUNCTION, lldb.eSymbolTypeCode)
+self.assertEqual(0 if symbol_kind == SYMBOL_STRIPPED else 1, sc_list.GetSize())
+
+def test_set_non_callable(self):
+# The callback should be callable.
+non_callable = "a"
+
+with self.assertRaises(TypeError, msg="Need a callable object or None!"):
+self.platform.SetLocateModuleCallback(non_callable)
+
+def test_set_wrong_args(self):
+# The callback should accept 3 argument.
+def test_args2(a, b):
+pass
+
+with self.assertRaises(TypeError, msg="Expected 3 argument callable object"):
+self.platform.SetLocateModuleCallback(test_args2)
+
+def test_default(self):
+# The default behavior is to locate the module with LLDB implementation
+# and AddModule should fail.
+module = self.target.AddModule(
+MODULE_PLATFORM_PATH,
+MODULE_TRIPLE,
+MODULE_UUID,
+)
+
+self.assertFalse(module)
+
+def test_set_none(self):
+# SetLocateModuleCallback should succeed to clear the callback with None.
+# and AddModule should fail.
+self.assertTrue(self.platform.SetLocateModuleCallback(None).Success())
+
+module = self.target.AddModule(
+MODULE_PLATFORM_PATH,
+MODULE_TRIPLE,
+MODULE_UUID,
+)
+
+self.assertFalse(module)
+
+def test_return_error(self):
+# The callback fails, AddModule should fai

[Lldb-commits] [PATCH] D153734: [lldb][LocateModuleCallback] Call locate module callback

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack marked 3 inline comments as done.
splhack added a comment.

SBPlatform API and Python will use SBPlatformLocateModuleCallback type.

  typedef SBError (*SBPlatformLocateModuleCallback)(
  void *baton,
  const SBModuleSpec &module_spec,
  SBFileSpec &module_file_spec,
  SBFileSpec &symbol_file_spec);

Platform.h will use LocateModuleCallback type.

  typedef std::function LocateModuleCallback;

So, Platform.h does not need to have SB* dependencies,
and SBPlatform can convert ModuleSpec/FileSpec from/to SBModuleSpec/SBFileSpec 
for the callback.




Comment at: lldb/include/lldb/Target/Platform.h:888
+  /// from symbol servers.
+  void SetTargetGetModuleCallback(void *callback_baton);
+

clayborg wrote:
> You actually need a callback along with the baton here. We probably don't 
> need the word "Target" in the function name?
> 
> Maybe better named as 
> ```
> void SetLocationModuleCallback(PlatformLocateModuleCallback callback, void 
> *baton);
> ```
Platform.h now only retains a std::function for the locate module callback.

In D153735, SBPlatform will use a lambda
- to capture callback(SBPlatformLocateModuleCallback) and baton(void *)
- to convert ModuleSpec/FileSpec from/to SBModuleSpec/SBFileSpec

Therefore, Platform.h does not need SB* dependencies.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153734

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


[Lldb-commits] [PATCH] D154992: Add a generic Process method to dump plugin history

2023-07-11 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

Ah excellent, thanks for adding this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154992

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


[Lldb-commits] [PATCH] D153734: [lldb][TargetGetModuleCallback] Call get module callback

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 539213.
splhack added a comment.

- Rename 'get module callback' to 'locate module callback'
- Enable C++ callback aside from Python callback
- Introduce LocateModuleCallback typedef to use std::function in order to 
capture callback and baton, to convert ModuleSpec/FileSpec from/to 
SBModuleSpec/SBFileSpec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153734

Files:
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Target.h
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Target.cpp
  lldb/unittests/Target/CMakeLists.txt
  lldb/unittests/Target/Inputs/AndroidModule.c
  lldb/unittests/Target/Inputs/AndroidModule.so
  lldb/unittests/Target/Inputs/AndroidModule.so.sym
  lldb/unittests/Target/Inputs/AndroidModule.unstripped.so
  lldb/unittests/Target/LocateModuleCallbackTest.cpp

Index: lldb/unittests/Target/LocateModuleCallbackTest.cpp
===
--- /dev/null
+++ lldb/unittests/Target/LocateModuleCallbackTest.cpp
@@ -0,0 +1,640 @@
+//===-- LocateModuleCallbackTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h"
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/Platform/Android/PlatformAndroid.h"
+#include "Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h"
+#include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h"
+#include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/Target.h"
+#include "gmock/gmock.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_android;
+using namespace lldb_private::breakpad;
+using namespace testing;
+
+namespace {
+
+constexpr llvm::StringLiteral k_process_plugin("mock-process-plugin");
+constexpr llvm::StringLiteral k_platform_dir("remote-android");
+constexpr llvm::StringLiteral k_cache_dir(".cache");
+constexpr llvm::StringLiteral k_module_file("AndroidModule.so");
+constexpr llvm::StringLiteral k_symbol_file("AndroidModule.unstripped.so");
+constexpr llvm::StringLiteral k_breakpad_symbol_file("AndroidModule.so.sym");
+constexpr llvm::StringLiteral k_arch("aarch64-none-linux");
+constexpr llvm::StringLiteral
+k_module_uuid("80008338-82A0-51E5-5922-C905D23890DA-BDDEFECC");
+constexpr llvm::StringLiteral k_function_symbol("boom");
+constexpr llvm::StringLiteral k_hidden_function_symbol("boom_hidden");
+const size_t k_module_size = 3784;
+
+ModuleSpec GetTestModuleSpec();
+
+class MockProcess : public Process {
+public:
+  MockProcess(TargetSP target_sp, ListenerSP listener_sp)
+  : Process(target_sp, listener_sp) {}
+
+  llvm::StringRef GetPluginName() override { return k_process_plugin; };
+
+  bool CanDebug(TargetSP target, bool plugin_specified_by_name) override {
+return true;
+  }
+
+  Status DoDestroy() override { return Status(); }
+
+  void RefreshStateAfterStop() override {}
+
+  bool DoUpdateThreadList(ThreadList &old_thread_list,
+  ThreadList &new_thread_list) override {
+return false;
+  }
+
+  size_t DoReadMemory(addr_t vm_addr, void *buf, size_t size,
+  Status &error) override {
+return 0;
+  }
+
+  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
+ ModuleSpec &module_spec) override {
+module_spec = GetTestModuleSpec();
+return true;
+  }
+};
+
+FileSpec GetTestDir() {
+  const auto *info = UnitTest::GetInstance()->current_test_info();
+  FileSpec test_dir = HostInfo::GetProcessTempDir();
+  test_dir.AppendPathComponent(std::string(info->test_case_name()) + "-" +
+   info->name());
+  std::error_code ec = llvm::sys::fs::create_directory(test_dir.GetPath());
+  EXPECT_FALSE(ec);
+  return test_dir;
+}
+
+FileSpec GetRemotePath() {
+  FileSpec fs("/", FileSpec::Style::posix);
+  fs.AppendPathComponent("bin");
+  fs.AppendPathComponent(k_module_file);
+  return fs;
+}
+
+FileSpec GetUuidView(FileSpec spec) {
+  spec.AppendPathComponent(k_platform_dir);
+  spec.AppendPathComponent(k_cache_dir);
+  spec.AppendPathComponent(k_module_uuid);
+  spec.AppendPathComponent(k_module_file);
+  return spec;
+}
+
+void BuildEmptyCacheDir(const FileSpec &test_dir) {
+  FileSpec cache_dir(test_dir);
+  cache_dir.AppendPathComponent(k_platform_dir);
+  cache_dir.AppendPathComponent(k_cache_dir);
+  std::error_code ec = llvm::sys::fs::create_directories(cache_dir.GetPath(

[Lldb-commits] [PATCH] D153735: [lldb][TargetGetModuleCallback] Implement Python interface

2023-07-11 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

LGTM with @clayborg comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153735

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


[Lldb-commits] [PATCH] D153733: [lldb][TargetGetModuleCallback] Update SBFileSpec/SBModuleSpec

2023-07-11 Thread Kazuki Sakamoto via Phabricator via lldb-commits
splhack updated this revision to Diff 539207.
splhack added a comment.

sync with D153734  and D153735 
 changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153733

Files:
  lldb/bindings/python/python-swigsafecast.swig
  lldb/include/lldb/API/SBModuleSpec.h
  lldb/source/API/SBModuleSpec.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/test/API/python_api/module_spec/TestModuleSpec.py

Index: lldb/test/API/python_api/module_spec/TestModuleSpec.py
===
--- /dev/null
+++ lldb/test/API/python_api/module_spec/TestModuleSpec.py
@@ -0,0 +1,24 @@
+"""
+Test some SBModuleSpec APIs.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class ModuleSpecAPIsTestCase(TestBase):
+def test_object_offset_and_size(self):
+module_spec = lldb.SBModuleSpec()
+self.assertEqual(module_spec.GetObjectOffset(), 0)
+self.assertEqual(module_spec.GetObjectSize(), 0)
+
+module_spec.SetObjectOffset(4096)
+self.assertEqual(module_spec.GetObjectOffset(), 4096)
+
+module_spec.SetObjectSize(3600)
+self.assertEqual(module_spec.GetObjectSize(), 3600)
+
+module_spec.Clear()
+self.assertEqual(module_spec.GetObjectOffset(), 0)
+self.assertEqual(module_spec.GetObjectSize(), 0)
Index: lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -30,6 +30,8 @@
 class SBValue;
 class SBStream;
 class SBStructuredData;
+class SBFileSpec;
+class SBModuleSpec;
 } // namespace lldb
 
 namespace lldb_private {
@@ -102,6 +104,10 @@
   static PythonObject ToSWIGWrapper(std::unique_ptr stream_sb);
   static PythonObject
   ToSWIGWrapper(std::unique_ptr data_sb);
+  static PythonObject
+  ToSWIGWrapper(std::unique_ptr file_spec_sb);
+  static PythonObject
+  ToSWIGWrapper(std::unique_ptr module_spec_sb);
 
   static python::ScopedPythonObject
   ToSWIGWrapper(CommandReturnObject &cmd_retobj);
Index: lldb/source/API/SBModuleSpec.cpp
===
--- lldb/source/API/SBModuleSpec.cpp
+++ lldb/source/API/SBModuleSpec.cpp
@@ -29,6 +29,11 @@
   m_opaque_up = clone(rhs.m_opaque_up);
 }
 
+SBModuleSpec::SBModuleSpec(const lldb_private::ModuleSpec &module_spec)
+: m_opaque_up(new lldb_private::ModuleSpec(module_spec)) {
+  LLDB_INSTRUMENT_VA(this, module_spec);
+}
+
 const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
   LLDB_INSTRUMENT_VA(this, rhs);
 
@@ -145,6 +150,30 @@
   return true;
 }
 
+uint64_t SBModuleSpec::GetObjectOffset() {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetObjectOffset();
+}
+
+void SBModuleSpec::SetObjectOffset(uint64_t object_offset) {
+  LLDB_INSTRUMENT_VA(this, object_offset);
+
+  m_opaque_up->SetObjectOffset(object_offset);
+}
+
+uint64_t SBModuleSpec::GetObjectSize() {
+  LLDB_INSTRUMENT_VA(this);
+
+  return m_opaque_up->GetObjectSize();
+}
+
+void SBModuleSpec::SetObjectSize(uint64_t object_size) {
+  LLDB_INSTRUMENT_VA(this, object_size);
+
+  m_opaque_up->SetObjectSize(object_size);
+}
+
 SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
   LLDB_INSTRUMENT_VA(this);
 }
Index: lldb/include/lldb/API/SBModuleSpec.h
===
--- lldb/include/lldb/API/SBModuleSpec.h
+++ lldb/include/lldb/API/SBModuleSpec.h
@@ -77,13 +77,24 @@
 
   bool SetUUIDBytes(const uint8_t *uuid, size_t uuid_len);
 
+  uint64_t GetObjectOffset();
+
+  void SetObjectOffset(uint64_t object_offset);
+
+  uint64_t GetObjectSize();
+
+  void SetObjectSize(uint64_t object_size);
+
   bool GetDescription(lldb::SBStream &description);
 
 private:
   friend class SBModuleSpecList;
   friend class SBModule;
+  friend class SBPlatform;
   friend class SBTarget;
 
+  SBModuleSpec(const lldb_private::ModuleSpec &module_spec);
+
   std::unique_ptr m_opaque_up;
 };
 
Index: lldb/bindings/python/python-swigsafecast.swig
===
--- lldb/bindings/python/python-swigsafecast.swig
+++ lldb/bindings/python/python-swigsafecast.swig
@@ -120,5 +120,15 @@
SWIGTYPE_p_lldb__SBEvent);
 }
 
+PythonObject SWIGBridge::ToSWIGWrapper(
+std::unique_ptr file_spec_sb) {
+  return ToSWIGHelper(file_spec_sb.release(), SWIGTYPE_p_lldb__SBFileSpec);
+}
+
+PythonObject SWIGBridge::ToSWIGWrapper(
+std::unique_ptr module_spec_sb) {
+  return ToSWIGHelper(module_spec_sb.release(), SWIGTYPE_p_lldb__SBModuleSpec);
+}
+
 } // namespace python

[Lldb-commits] [PATCH] D154992: Add a generic Process method to dump plugin history

2023-07-11 Thread Jim Ingham via Phabricator via lldb-commits
jingham created this revision.
jingham added reviewers: jasonmolenda, JDevlieghere.
Herald added a project: All.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

I need to dump the gdb-remote communication history when we fail the "stepping 
or not" assertion Jason added to StopInfoMachException a week or so ago.  But 
that's a feature of GDBRemoteCommunication, or at best ProcessGDBRemote, and it 
really doesn't make sense to include that in StopInfoMachException.

However the notion of "dumping the low level plugin history for a process" 
seems like a generally useful one.  So I made a Process API for this, and then 
routed the other uses through that, and added dumping this when the assert is 
triggered.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154992

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -77,6 +77,8 @@
 bool plugin_specified_by_name) override;
 
   CommandObject *GetPluginCommandObject() override;
+  
+  void DumpPluginHistory(Stream &s) override;
 
   // Creating a new process, or attaching to an existing one
   Status DoWillLaunch(Module *module) override;
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -113,7 +113,7 @@
 return;
   }
   StreamFile stream(std::move(file.get()));
-  ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory(stream);
+  ((Process *)p)->DumpPluginHistory(stream);
 }
 } // namespace lldb
 
@@ -205,6 +205,11 @@
   return process_sp;
 }
 
+void ProcessGDBRemote::DumpPluginHistory(Stream &s) {
+  GDBRemoteCommunicationClient &gdb_comm(GetGDBRemote());
+  gdb_comm.DumpHistory(s);
+}
+
 std::chrono::seconds ProcessGDBRemote::GetPacketTimeout() {
   return std::chrono::seconds(GetGlobalPluginProperties().GetPacketTimeout());
 }
@@ -5217,7 +5222,7 @@
 ProcessGDBRemote *process =
 (ProcessGDBRemote *)m_interpreter.GetExecutionContext().GetProcessPtr();
 if (process) {
-  process->GetGDBRemote().DumpHistory(result.GetOutputStream());
+  process->DumpPluginHistory(result.GetOutputStream());
   result.SetStatus(eReturnStatusSuccessFinishResult);
   return true;
 }
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -457,7 +457,7 @@
   if (log) {
 if (log->GetVerbose()) {
   StreamString strm;
-  gdb_comm.DumpHistory(strm);
+  process->DumpPluginHistory(strm);
   LLDB_LOGF(log,
 "error: failed to get packet sequence mutex, not sending "
 "write register for \"%s\":\n%s",
@@ -566,7 +566,7 @@
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "read all registers:\n%s",
@@ -741,7 +741,7 @@
 if (log) {
   if (log->GetVerbose()) {
 StreamString strm;
-gdb_comm.DumpHistory(strm);
+process->DumpPluginHistory(strm);
 LLDB_LOGF(log,
   "error: failed to get packet sequence mutex, not sending "
   "write all registers:\n%s",
Index: lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
===
--- lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
+++ lldb/source/Plugins/Process/Utility/StopInfoMachException.cpp
@@ -744,6 +744,7 @@
   }
 }
   }
+  thread.GetProcess()->DumpPluginHistory(s);
   llvm::report_fatal_error(s.GetData());
   lldbassert(
   false &&
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -575,6 +575,10 @@
   /// of CommandObject like CommandObjectRaw, CommandObjectParsed,
   /// or CommandObjectMultiword.
   vir

[Lldb-commits] [PATCH] D154990: [lldb-vsocde] Cleaning up the usage of the Separate helper in Options.td.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti created this revision.
Herald added a project: All.
ashgti requested review of this revision.
Herald added subscribers: lldb-commits, wangpc.
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154990

Files:
  lldb/tools/lldb-vscode/Options.td


Index: lldb/tools/lldb-vscode/Options.td
===
--- lldb/tools/lldb-vscode/Options.td
+++ lldb/tools/lldb-vscode/Options.td
@@ -17,25 +17,25 @@
   Alias,
   HelpText<"Alias for --wait-for-debugger">;
 
-def port: Separate<["--", "-"], "port">,
+def port: S<"port">,
   MetaVarName<"">,
   HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
 def: Separate<["-"], "p">,
   Alias,
   HelpText<"Alias for --port">;
 
-def launch_target: Separate<["--", "-"], "launch-target">,
+def launch_target: S<"launch-target">,
   MetaVarName<"">,
   HelpText<"Launch a target for the launchInTerminal request. Any argument "
 "provided after this one will be passed to the target. The parameter "
 "--comm-file must also be specified.">;
 
-def comm_file: Separate<["--", "-"], "comm-file">,
+def comm_file: S<"comm-file">,
   MetaVarName<"">,
   HelpText<"The fifo file used to communicate the with the debug adaptor "
 "when using --launch-target.">;
 
-def debugger_pid: Separate<["--", "-"], "debugger-pid">,
+def debugger_pid: S<"debugger-pid">,
   MetaVarName<"">,
   HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal 
"
 "request when using --launch-target.">;


Index: lldb/tools/lldb-vscode/Options.td
===
--- lldb/tools/lldb-vscode/Options.td
+++ lldb/tools/lldb-vscode/Options.td
@@ -17,25 +17,25 @@
   Alias,
   HelpText<"Alias for --wait-for-debugger">;
 
-def port: Separate<["--", "-"], "port">,
+def port: S<"port">,
   MetaVarName<"">,
   HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
 def: Separate<["-"], "p">,
   Alias,
   HelpText<"Alias for --port">;
 
-def launch_target: Separate<["--", "-"], "launch-target">,
+def launch_target: S<"launch-target">,
   MetaVarName<"">,
   HelpText<"Launch a target for the launchInTerminal request. Any argument "
 "provided after this one will be passed to the target. The parameter "
 "--comm-file must also be specified.">;
 
-def comm_file: Separate<["--", "-"], "comm-file">,
+def comm_file: S<"comm-file">,
   MetaVarName<"">,
   HelpText<"The fifo file used to communicate the with the debug adaptor "
 "when using --launch-target.">;
 
-def debugger_pid: Separate<["--", "-"], "debugger-pid">,
+def debugger_pid: S<"debugger-pid">,
   MetaVarName<"">,
   HelpText<"The PID of the lldb-vscode instance that sent the launchInTerminal "
 "request when using --launch-target.">;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154883: [lldb][NFCI] Methods to load scripting resources should take a Stream by reference

2023-07-11 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d796b48e4d4: [lldb][NFCI] Methods to load scripting 
resources should take a Stream by… (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154883

Files:
  lldb/include/lldb/Core/Module.h
  lldb/include/lldb/Core/ModuleList.h
  lldb/include/lldb/Target/Platform.h
  lldb/include/lldb/Target/Target.h
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Core/Debugger.cpp
  lldb/source/Core/Module.cpp
  lldb/source/Core/ModuleList.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
  lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
  lldb/source/Target/Platform.cpp
  lldb/source/Target/Target.cpp

Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -1393,8 +1393,8 @@
Target *target) {
   Status error;
   StreamString feedback_stream;
-  if (module_sp && !module_sp->LoadScriptingResourceInTarget(
-   target, error, &feedback_stream)) {
+  if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error,
+ feedback_stream)) {
 if (error.AsCString())
   target->GetDebugger().GetErrorStream().Printf(
   "unable to load scripting data for module %s - error reported was "
Index: lldb/source/Target/Platform.cpp
===
--- lldb/source/Target/Platform.cpp
+++ lldb/source/Target/Platform.cpp
@@ -158,7 +158,7 @@
 
 FileSpecList
 Platform::LocateExecutableScriptingResources(Target *target, Module &module,
- Stream *feedback_stream) {
+ Stream &feedback_stream) {
   return FileSpecList();
 }
 
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -69,7 +69,7 @@
 
   FileSpecList
   LocateExecutableScriptingResources(Target *target, Module &module,
- Stream *feedback_stream) override;
+ Stream &feedback_stream) override;
 
   Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
  lldb::ModuleSP &module_sp,
Index: lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
===
--- lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -194,7 +194,7 @@
 }
 
 FileSpecList PlatformDarwin::LocateExecutableScriptingResources(
-Target *target, Module &module, Stream *feedback_stream) {
+Target *target, Module &module, Stream &feedback_stream) {
   FileSpecList file_list;
   if (target &&
   target->GetDebugger().GetScriptLanguage() == eScriptLanguagePython) {
@@ -266,33 +266,31 @@
   // if we did some replacements of reserved characters, and a
   // file with the untampered name exists, then warn the user
   // that the file as-is shall not be loaded
-  if (feedback_stream) {
-if (module_basename != original_module_basename &&
-FileSystem::Instance().Exists(orig_script_fspec)) {
-  const char *reason_for_complaint =
-  was_keyword ? "conflicts with a keyword"
-  : "contains reserved characters";
-  if (FileSystem::Instance().Exists(script_fspec))
-feedback_stream->Printf(
-"warning: the symbol file '%s' contains a debug "
-"script. However, its name"
-" '%s' %s and as such cannot be loaded. LLDB will"
-" load '%s' instead. Consider removing the file with "
-"the malformed name to"
-" eliminate this warning.\n",
-symfile_spec.GetPath().c_str(),
-original_path_string.GetData(), reason_for_complaint,
-path_string.GetData());
-  else
-feedback_stream->Printf(
-"warning: the symbol file '%s' contains a debug "
-"script. However, its name"
-" %s and as such cannot be loaded. If you intend"
-" to have this script loaded, please rename '%s' to "
-"'%s' and retry.\n",
-symfile_spec.GetPath().c_str(), reaso

[Lldb-commits] [lldb] 1d796b4 - [lldb][NFCI] Methods to load scripting resources should take a Stream by reference

2023-07-11 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-07-11T10:36:11-07:00
New Revision: 1d796b48e4d48bd0e4b29972a1b8d653493ee30c

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

LOG: [lldb][NFCI] Methods to load scripting resources should take a Stream by 
reference

These methods all take a `Stream *` to get feedback about what's going
on. By default, it's a nullptr, but we always feed it with a valid
pointer. It would therefore make more sense to have this take a
reference.

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

Added: 


Modified: 
lldb/include/lldb/Core/Module.h
lldb/include/lldb/Core/ModuleList.h
lldb/include/lldb/Target/Platform.h
lldb/include/lldb/Target/Target.h
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/Module.cpp
lldb/source/Core/ModuleList.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/source/Target/Platform.cpp
lldb/source/Target/Target.cpp

Removed: 




diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index 565c613f637021..67e15120f5e786 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -563,7 +563,7 @@ class Module : public std::enable_shared_from_this,
   bool IsLoadedInTarget(Target *target);
 
   bool LoadScriptingResourceInTarget(Target *target, Status &error,
- Stream *feedback_stream = nullptr);
+ Stream &feedback_stream);
 
   /// Get the number of compile units for this module.
   ///

diff  --git a/lldb/include/lldb/Core/ModuleList.h 
b/lldb/include/lldb/Core/ModuleList.h
index 631d7889f36796..28c1945c83c478 100644
--- a/lldb/include/lldb/Core/ModuleList.h
+++ b/lldb/include/lldb/Core/ModuleList.h
@@ -440,7 +440,7 @@ class ModuleList {
   bool IsEmpty() const { return !GetSize(); }
 
   bool LoadScriptingResourcesInTarget(Target *target, std::list 
&errors,
-  Stream *feedback_stream = nullptr,
+  Stream &feedback_stream,
   bool continue_on_error = true);
 
   static ModuleListProperties &GetGlobalModuleListProperties();

diff  --git a/lldb/include/lldb/Target/Platform.h 
b/lldb/include/lldb/Target/Platform.h
index b556e1aa3dd2e7..35227429b126ae 100644
--- a/lldb/include/lldb/Target/Platform.h
+++ b/lldb/include/lldb/Target/Platform.h
@@ -286,7 +286,7 @@ class Platform : public PluginInterface {
   // current computers global settings.
   virtual FileSpecList
   LocateExecutableScriptingResources(Target *target, Module &module,
- Stream *feedback_stream);
+ Stream &feedback_stream);
 
   virtual Status GetSharedModule(
   const ModuleSpec &module_spec, Process *process,

diff  --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 50cd315b0fdfa7..ed0ecbbddbf814 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -939,7 +939,7 @@ class Target : public std::enable_shared_from_this,
   LoadDependentFiles load_dependent_files = eLoadDependentsDefault);
 
   bool LoadScriptingResources(std::list &errors,
-  Stream *feedback_stream = nullptr,
+  Stream &feedback_stream,
   bool continue_on_error = true) {
 return m_images.LoadScriptingResourcesInTarget(
 this, errors, feedback_stream, continue_on_error);

diff  --git a/lldb/source/Commands/CommandObjectTarget.cpp 
b/lldb/source/Commands/CommandObjectTarget.cpp
index 1b40651b7a4345..3e024ff91b382d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4219,7 +4219,7 @@ class CommandObjectTargetSymbolsAdd : public 
CommandObjectParsed {
   Status error;
   StreamString feedback_stream;
   module_sp->LoadScriptingResourceInTarget(target, error,
-   &feedback_stream);
+   feedback_stream);
   if (error.Fail() && error.AsCString())
 result.AppendWarningWithFormat(
 "unable to load scripting data for module %s - error "

diff  --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 4f06ed07274914..f5410862918548 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -248,7 +248,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext 
*exe_ctx,
   eLoadScriptFromSymFileTrue) {
 std::list errors;
 

[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 539185.
ashgti added a comment.
Herald added a subscriber: JDevlieghere.

Applying clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154989

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/VSCode.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
@@ -191,6 +191,27 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued"));
+  llvm::json::Object body;
+  body.try_emplace("threadId", (int64_t)g_vsc.focus_tid);
+  body.try_emplace("allThreadsContinued", true);
+  event.try_emplace("body", std::move(body));
+  g_vsc.SendJSON(llvm::json::Value(std::move(event)));
+}
+
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
@@ -252,7 +273,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -468,6 +489,7 @@
 break;
   case lldb::eStateRunning:
 g_vsc.WillContinue();
+SendContinuedEvent();
 break;
   case lldb::eStateExited:
 // When restarting, we can get an "exited" event for the process we
@@ -766,10 +788,6 @@
   llvm::json::Object response;
   FillResponse(request, response);
   lldb::SBProcess process = g_vsc.target.GetProcess();
-  auto arguments = request.getObject("arguments");
-  // Remember the thread ID that caused the resume so we can set the
-  // "threadCausedFocus" boolean value in the "stopped" events.
-  g_vsc.focus_tid = GetUnsigned(arguments, "threadId", LLDB_INVALID_THREAD_ID);
   lldb::SBError error = process.Continue();
   llvm::json::Object body;
   body.try_emplace("allThreadsContinued", true);
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -264,7 +264,10 @@
   void RegisterRequestCallback(std::string request, RequestCallback callback);
 
   /// Debuggee will continue from stopped state.
-  void WillContinue() { variables.Clear(); }
+  void WillContinue() {
+variables.Clear();
+focus_tid = LLDB_INVALID_THREAD_ID;
+  }
 
   /// Poll the process to wait for it to reach the eStateStopped state.
   ///
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -901,6 +901,8 @@
   uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
   snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64,
bp_id, bp_loc_id);
+  body.try_emplace("hitBreakpointIds",
+   llvm::json::Array{llvm::json::Value(bp_id)});
   EmplaceSafeString(body, "description", desc_str);
 }
   } break;
@@ -945,9 +947,6 @@
   EmplaceSafeString(body, "description", std::string(description));
 }
   }
-  if (tid == g_vsc.focus_tid) {
-body.try_emplace("threadCausedFocus", true);
-  }
   body.try_emplace("preserveFocusHint", tid != g_vsc.focus_tid);
   body.try_emplace("allThreadsStopped", true);
   event.try_emplace("body", std::move(body));


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -191,6 +191,27 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued

[Lldb-commits] [PATCH] D154989: [lldb-vsocde] Add a 'continued' event for programmatic continue events.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti created this revision.
Herald added a project: All.
ashgti requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When the process is contiuned using an lldb command expression the thread state 
in VS Code is never informed and will be out of sync with the current state of 
the process. The new event will fire whenever the process is continued and 
keeps the debugger in sync with the dap client.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154989

Files:
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/VSCode.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
@@ -191,6 +191,27 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+return;
+  }
+
+  // If the focus thread is not set then we haven't reported any thread status
+  // to the client, so nothing to report.
+  if (g_vsc.focus_tid == LLDB_INVALID_THREAD_ID) {
+return;
+  }
+
+  llvm::json::Object event(CreateEventObject("continued"));
+  llvm::json::Object body;
+  body.try_emplace("threadId", (int64_t)g_vsc.focus_tid);  
+  body.try_emplace("allThreadsContinued", true);
+  event.try_emplace("body", std::move(body));
+  g_vsc.SendJSON(llvm::json::Value(std::move(event)));
+}
+
 // Send a "terminated" event to indicate the process is done being
 // debugged.
 void SendTerminatedEvent() {
@@ -252,7 +273,7 @@
 }
   }
 
-  // We will have cleared g_vsc.focus_tid if he focus thread doesn't have
+  // We will have cleared g_vsc.focus_tid if the focus thread doesn't have
   // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
   // then set the focus thread to the first thread with a stop reason.
   if (!focus_thread_exists || g_vsc.focus_tid == LLDB_INVALID_THREAD_ID)
@@ -468,6 +489,7 @@
 break;
   case lldb::eStateRunning:
 g_vsc.WillContinue();
+SendContinuedEvent();
 break;
   case lldb::eStateExited:
 // When restarting, we can get an "exited" event for the process we
@@ -766,10 +788,6 @@
   llvm::json::Object response;
   FillResponse(request, response);
   lldb::SBProcess process = g_vsc.target.GetProcess();
-  auto arguments = request.getObject("arguments");
-  // Remember the thread ID that caused the resume so we can set the
-  // "threadCausedFocus" boolean value in the "stopped" events.
-  g_vsc.focus_tid = GetUnsigned(arguments, "threadId", LLDB_INVALID_THREAD_ID);
   lldb::SBError error = process.Continue();
   llvm::json::Object body;
   body.try_emplace("allThreadsContinued", true);
Index: lldb/tools/lldb-vscode/VSCode.h
===
--- lldb/tools/lldb-vscode/VSCode.h
+++ lldb/tools/lldb-vscode/VSCode.h
@@ -264,7 +264,10 @@
   void RegisterRequestCallback(std::string request, RequestCallback callback);
 
   /// Debuggee will continue from stopped state.
-  void WillContinue() { variables.Clear(); }
+  void WillContinue() { 
+variables.Clear(); 
+focus_tid = LLDB_INVALID_THREAD_ID;
+  }
 
   /// Poll the process to wait for it to reach the eStateStopped state.
   ///
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -901,6 +901,8 @@
   uint64_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
   snprintf(desc_str, sizeof(desc_str), "breakpoint %" PRIu64 ".%" PRIu64,
bp_id, bp_loc_id);
+  body.try_emplace("hitBreakpointIds",
+   llvm::json::Array{llvm::json::Value(bp_id)});
   EmplaceSafeString(body, "description", desc_str);
 }
   } break;
@@ -945,9 +947,6 @@
   EmplaceSafeString(body, "description", std::string(description));
 }
   }
-  if (tid == g_vsc.focus_tid) {
-body.try_emplace("threadCausedFocus", true);
-  }
   body.try_emplace("preserveFocusHint", tid != g_vsc.focus_tid);
   body.try_emplace("allThreadsStopped", true);
   event.try_emplace("body", std::move(body));


Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -191,6 +191,27 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(event)));
 }
 
+// Send a "continued" event to indicate the process is in the running state.
+void SendContinuedEvent() {
+  lldb::SBProcess process = g_vsc.target.GetProcess();
+  if (!process.IsValid()) {
+retur

[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti marked 2 inline comments as done.
ashgti added inline comments.



Comment at: lldb/tools/lldb-vscode/Options.td:20-38
+def port: S<"port">,
   MetaVarName<"">,
   HelpText<"Communicate with the lldb-vscode tool over the defined port.">;
 def: Separate<["-"], "p">,
   Alias,
   HelpText<"Alias for --port">;
 

wallace wrote:
> +1
Moving this into its own commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

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


[Lldb-commits] [PATCH] D154030: [lldb-vscode] Creating a new flag for adjusting the behavior of evaluation repl expressions to allow users to more easily invoke lldb commands.

2023-07-11 Thread John Harrison via Phabricator via lldb-commits
ashgti updated this revision to Diff 539182.
ashgti marked an inline comment as done.
ashgti added a comment.

Apply clang-format and split out some parts of this into smaller commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154030

Files:
  lldb/tools/lldb-vscode/Options.td
  lldb/tools/lldb-vscode/README.md
  lldb/tools/lldb-vscode/VSCode.cpp
  lldb/tools/lldb-vscode/VSCode.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
@@ -1065,50 +1065,63 @@
   FillResponse(request, response);
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
+
+  // If we have a frame, try to set the context for variable completions.
+  lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
+  if (frame.IsValid()) {
+frame.GetThread().GetProcess().SetSelectedThread(frame.GetThread());
+frame.GetThread().SetSelectedFrame(frame.GetFrameID());
+  }
+
   std::string text = std::string(GetString(arguments, "text"));
   auto original_column = GetSigned(arguments, "column", text.size());
-  auto actual_column = original_column - 1;
+  auto original_line = GetSigned(arguments, "line", 1);
+  auto offset = original_column - 1;
+  if (original_line > 1) {
+llvm::StringRef text_ref{text};
+::llvm::SmallVector<::llvm::StringRef, 2> lines;
+text_ref.split(lines, '\n');
+for (int i = 0; i < original_line - 1; i++) {
+  offset += lines[i].size();
+}
+  }
   llvm::json::Array targets;
-  // NOTE: the 'line' argument is not needed, as multiline expressions
-  // work well already
-  // TODO: support frameID. Currently
-  // g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions
-  // is frame-unaware.
-
-  if (!text.empty() && text[0] == '`') {
-text = text.substr(1);
-actual_column--;
-  } else {
-char command[] = "expression -- ";
+
+  if (g_vsc.DetectExpressionContext(frame, text) ==
+  ExpressionContext::Variable) {
+char command[] = "frame variable ";
 text = command + text;
-actual_column += strlen(command);
+offset += strlen(command);
   }
   lldb::SBStringList matches;
   lldb::SBStringList descriptions;
-  g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
-  text.c_str(), actual_column, 0, -1, matches, descriptions);
-  size_t count = std::min((uint32_t)100, matches.GetSize());
-  targets.reserve(count);
-  for (size_t i = 0; i < count; i++) {
-std::string match = matches.GetStringAtIndex(i);
-std::string description = descriptions.GetStringAtIndex(i);
-
-llvm::json::Object item;
-
-llvm::StringRef match_ref = match;
-for (llvm::StringRef commit_point : {".", "->"}) {
-  if (match_ref.contains(commit_point)) {
-match_ref = match_ref.rsplit(commit_point).second;
+
+  if (g_vsc.debugger.GetCommandInterpreter().HandleCompletionWithDescriptions(
+  text.c_str(), offset, 0, 100, matches, descriptions)) {
+// The first element is the common substring after the cursor position for
+// all the matches. The rest of the elements are the matches.
+targets.reserve(matches.GetSize() - 1);
+std::string common_pattern = matches.GetStringAtIndex(0);
+for (size_t i = 1; i < matches.GetSize(); i++) {
+  std::string match = matches.GetStringAtIndex(i);
+  std::string description = descriptions.GetStringAtIndex(i);
+
+  llvm::json::Object item;
+  llvm::StringRef match_ref = match;
+  for (llvm::StringRef commit_point : {".", "->"}) {
+if (match_ref.contains(commit_point)) {
+  match_ref = match_ref.rsplit(commit_point).second;
+}
   }
-}
-EmplaceSafeString(item, "text", match_ref);
+  EmplaceSafeString(item, "text", match_ref);
 
-if (description.empty())
-  EmplaceSafeString(item, "label", match);
-else
-  EmplaceSafeString(item, "label", match + " -- " + description);
+  if (description.empty())
+EmplaceSafeString(item, "label", match);
+  else
+EmplaceSafeString(item, "label", match + " -- " + description);
 
-targets.emplace_back(std::move(item));
+  targets.emplace_back(std::move(item));
+}
   }
 
   body.try_emplace("targets", std::move(targets));
@@ -1223,12 +1236,17 @@
   llvm::json::Object body;
   auto arguments = request.getObject("arguments");
   lldb::SBFrame frame = g_vsc.GetLLDBFrame(*arguments);
-  const auto expression = GetString(arguments, "expression");
+  std::string expression = GetString(arguments, "expression").str();
   llvm::StringRef context = GetString(arguments, "context");
 
-  if (!expression.empty() && expression[0] == '`') {
-auto result =
-RunLLDBCommands(llvm::StringRef(), {std::string(expression.substr(1))});
+  if (context =

[Lldb-commits] [PATCH] D154890: [lldb][NFCI] Avoid construction of temporary std::strings in Variable

2023-07-11 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7c48ffde1c8: [lldb][NFCI] Avoid construction of temporary 
std::strings in Variable (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154890

Files:
  lldb/source/Symbol/Variable.cpp


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, &matches)) {
-  error.SetErrorStringWithFormat(
-  "unable to extract a variable name from '%s'",
-  variable_expr_path.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "unable to extract a variable name from '{0}'", variable_expr_path);
   return error;
 }
 std::string variable_name = matches[1].str();
@@ -411,10 +410,9 @@
 valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
 variable_sub_expr_path);
 if (!valobj_sp) {
-  error.SetErrorStringWithFormat(
-  "invalid expression path '%s' for variable '%s'",
-  variable_sub_expr_path.str().c_str(),
-  var_sp->GetName().GetCString());
+  error.SetErrorStringWithFormatv(
+  "invalid expression path '{0}' for variable '{1}'",
+  variable_sub_expr_path, var_sp->GetName().GetCString());
   variable_list.RemoveVariableAtIndex(i);
   continue;
 }


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, &matches)) {
-  error.SetErrorStringWithFormat(
-  "unable to extract a variable name from '%s'",
-  variable_expr_path.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "unable to extract a variable name from '{0}'", variable_expr_path);
   return error;
 }
 std::string variable_name = matches[1].str();
@@ -411,10 +410,9 @@
 valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
 variable_sub_expr_path);
 if (!valobj_sp) {
-  error.SetErrorStringWithFormat(
-  "invalid expression path '%s' for variable '%s'",
-  variable_sub_expr_path.str().c_str(),
-  var_sp->GetName().GetCString());
+  error.SetErrorStringWithFormatv(
+  "invalid expression path '{0}' for variable '{1}'",
+  variable_sub_expr_path, var_sp->GetName().GetCString());
   variable_list.RemoveVariableAtIndex(i);
   continue;
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] e7c48ff - [lldb][NFCI] Avoid construction of temporary std::strings in Variable

2023-07-11 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-07-11T10:22:02-07:00
New Revision: e7c48ffde1c8137822a1b0a1ba6c4be5b4624aa6

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

LOG: [lldb][NFCI] Avoid construction of temporary std::strings in Variable

A common thing to do is to call `str().c_str()` to get a null-terminated
string out of an existing StringRef. Most of the time this is to be able
to use a printf-style format string. However, llvm::formatv can handle
StringRefs without the need for the additional allocation. Using that
makes more sense.

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

Added: 


Modified: 
lldb/source/Symbol/Variable.cpp

Removed: 




diff  --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 5e1996b13bcccd..85ceadd20c611e 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@ Status Variable::GetValuesForVariableExpressionPath(
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, &matches)) {
-  error.SetErrorStringWithFormat(
-  "unable to extract a variable name from '%s'",
-  variable_expr_path.str().c_str());
+  error.SetErrorStringWithFormatv(
+  "unable to extract a variable name from '{0}'", variable_expr_path);
   return error;
 }
 std::string variable_name = matches[1].str();
@@ -411,10 +410,9 @@ Status Variable::GetValuesForVariableExpressionPath(
 valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
 variable_sub_expr_path);
 if (!valobj_sp) {
-  error.SetErrorStringWithFormat(
-  "invalid expression path '%s' for variable '%s'",
-  variable_sub_expr_path.str().c_str(),
-  var_sp->GetName().GetCString());
+  error.SetErrorStringWithFormatv(
+  "invalid expression path '{0}' for variable '{1}'",
+  variable_sub_expr_path, var_sp->GetName().GetCString());
   variable_list.RemoveVariableAtIndex(i);
   continue;
 }



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


[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

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

> SIMD registers must be read and written via the SVE regset when in SSVE mode. 
> Writing to them exits streaming mode.

In my testing it did actually work if you always used the current mode. I think 
that's an artifact of QEMU or the kernel's implementation choices though, and 
perhaps the data is actually stale in certain circumstances.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154926

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


[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

2023-07-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a reviewer: omjavaid.
DavidSpickett added a comment.

Feel free to bombard me with questions about SME, if it's quicker than reading 
the entire spec yourself. It has some quirks to it for sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154926

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


[Lldb-commits] [PATCH] D154930: [lldb][AArch64] Add the tpidr2 TLS register that comes with SME

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

This changes the TLS regset to not only be dynamic in that it could
exist or not (though it always does) but also of a dynamic size.

If SME is present then the regset is 16 bytes and contains both tpidr
and tpidr2.

Testing is the same as tpidr. Write from assembly, read from lldb and
vice versa since we have no way to predict what its value should be
by just running a program.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154930

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  lldb/test/API/linux/aarch64/tls_register/Makefile
  lldb/test/API/linux/aarch64/tls_register/TestAArch64LinuxTLSRegister.py
  lldb/test/API/linux/aarch64/tls_register/main.c
  lldb/test/API/linux/aarch64/tls_registers/Makefile
  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
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tls_registers/main.c
@@ -0,0 +1,57 @@
+#include 
+#include 
+
+uint64_t get_tpidr(void) {
+  uint64_t tpidr = 0;
+  __asm__ volatile("mrs %0, tpidr_el0" : "=r"(tpidr));
+  return tpidr;
+}
+
+uint64_t get_tpidr2(void) {
+  uint64_t tpidr2 = 0;
+  // S3_3_C13_C0_5 means tpidr2, and will work with older tools.
+  __asm__ volatile("mrs %0, S3_3_C13_C0_5" : "=r"(tpidr2));
+  return tpidr2;
+}
+
+void set_tpidr(uint64_t value) {
+  __asm__ volatile("msr tpidr_el0, %0" ::"r"(value));
+}
+
+void set_tpidr2(uint64_t value) {
+  __asm__ volatile("msr S3_3_C13_C0_5, %0" ::"r"(value));
+}
+
+int main(int argc, char *argv[]) {
+  uint64_t (*getter)(void) = get_tpidr;
+  void (*setter)(uint64_t) = set_tpidr;
+
+  // Expect just the register number.
+  if (argc != 2)
+return 1;
+
+  switch (argv[1][0]) {
+  case '1':
+break;
+  case '2':
+getter = get_tpidr2;
+setter = set_tpidr2;
+break;
+  default:
+return 1;
+  }
+
+  uint64_t original = getter();
+  uint64_t pattern = 0x1122334455667788;
+  setter(pattern);
+
+  // Set break point at this line.
+  // lldb will now set its own pattern for us to find.
+
+  uint64_t new_value = getter();
+  volatile bool reg_was_set = new_value == 0x8877665544332211;
+
+  setter(original);
+
+  return 0; // Set break point 2 at this line.
+}
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
@@ -1,5 +1,5 @@
 """
-Test lldb's ability to read and write the AArch64 TLS register tpidr.
+Test lldb's ability to read and write the AArch64 TLS registers.
 """
 
 import lldb
@@ -8,12 +8,10 @@
 from lldbsuite.test import lldbutil
 
 
-class AArch64LinuxTLSRegister(TestBase):
+class AArch64LinuxTLSRegisters(TestBase):
 NO_DEBUG_INFO_TESTCASE = True
 
-@skipUnlessArch("aarch64")
-@skipUnlessPlatform(["linux"])
-def test_tls(self):
+def setup(self, register_name):
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 
@@ -31,6 +29,8 @@
 num_expected_locations=1,
 )
 
+self.runCmd("settings set target.run-args {}".format(
+{"tpidr": 1, "tpidr2": 2}[register_name]))
 self.runCmd("run", RUN_SUCCEEDED)
 
 if self.process().GetState() == lldb.eStateExited:
@@ -42,19 +42,24 @@
 substrs=["stopped", "stop reason = breakpoint"],
 )
 
+def check_tls_reg(self, register_name):
+self.setup(register_name)
+
 # Since we can't predict what the value will be, the program has set
 # a target value for us to find.
 
 regs = self.thread().GetSelectedFrame().GetRegisters()
 tls_regs = regs.GetFirstValueByName("Thread Local Storage Registers")
 self.assertTrue(tls_regs.IsValid(), "No TLS registers found.")
-tpidr = tls_regs.GetChildMemberWithName("tpidr")
-self.assertTrue(tpidr.IsValid(), "No tpidr register found.")
+tls_reg = tls_regs.GetChildMemberWithName(register_name)
+self.assertTrue(tls_reg.IsValid(), "{} register not found.".format(
+register_name))
 
-self.assertEqual(tpidr.GetValueAsUnsigned(), 0x1122334455667788)
+self.assertEqual(tls_reg.GetValueAsUnsigned(), 0x1122334455667788)
 
 # Set our own value fo

[Lldb-commits] [PATCH] D154927: [lldb][AArch64] Add SME's streaming vector control register

2023-07-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: ctetreau, kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added subscribers: lldb-commits, alextsao1999.
Herald added a project: LLDB.

Software can tell if it is in streaming SVE mode by checking
the Streaming Vector Control Register (SVCR).

"E3.1.9 SVCR, Streaming Vector Control Register" in
"Arm® Architecture Reference Manual Supplement, The Scalable Matrix
Extension (SME), for Armv9-A"

This is especially useful for debug because the names of the
SVE registers are the same betweeen non-streaming and streaming mode.

The Linux Kernel chose to not put this register behind ptrace,
and it can be read from EL0. However, this would mean running code
in process to read it. That can be done but we already know all
the information just from ptrace.

So this is a pseudo register that matches the architectural
content, and it is read only for now until all bits are implemented.
The name is just "svcr", which aligns with GDB's proposed naming.

It is in a new dynamic register set named for the SME exention.
There will also be a streaming vector length pseduo register here
in future.

The register contains two bits:
0 : Whether streaming SVE mode is enabled.
1 : Whether the array storage is enabled.

This patch only adds bit 0, bit 1 will be added in a later patch
after the array storage (ZA) is supported. The register is read
only and may be made writeable in a later patch.

An existing test has been updated to check the expected SVCR value.
There's not much point adding a dedicated test given that the content
is just whatever m_sme_state is. If lldb gets it wrong, svcr will be
wrong too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154927

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py

Index: lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
===
--- lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
+++ lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
@@ -22,7 +22,12 @@
 reg_value.GetByteSize(), expected, 'Verify "%s" == %i' % (name, expected)
 )
 
-def check_sve_regs_read(self, z_reg_size):
+def check_sve_regs_read(self, z_reg_size, expected_mode):
+if self.isAArch64SME():
+expected_value = "1" if expected_mode == Mode.SSVE else "0"
+self.expect("register read svcr", substrs=[
+"0x000" + expected_value])
+
 p_reg_size = int(z_reg_size / 8)
 
 for i in range(32):
@@ -162,7 +167,7 @@
 
 vg_reg_value = sve_registers.GetChildMemberWithName("vg").GetValueAsUnsigned()
 z_reg_size = vg_reg_value * 8
-self.check_sve_regs_read(z_reg_size)
+self.check_sve_regs_read(z_reg_size, start_mode)
 
 # Evaluate simple expression and print function expr_eval_func address.
 self.expect("expression expr_eval_func", substrs=["= 0x"])
@@ -174,7 +179,7 @@
 
 # We called a jitted function above which must not have changed SVE
 # vector length or register values.
-self.check_sve_regs_read(z_reg_size)
+self.check_sve_regs_read(z_reg_size, start_mode)
 
 self.check_sve_regs_read_after_write(z_reg_size)
 
Index: lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
===
--- lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
+++ lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
@@ -106,6 +106,8 @@
 
   void AddRegSetTLS();
 
+  void AddRegSetSME();
+
   uint32_t ConfigureVectorLength(uint32_t sve_vq);
 
   bool VectorSizeIsValid(uint32_t vq) {
@@ -127,6 +129,7 @@
   bool IsPAuthReg(unsigned reg) const;
   bool IsMTEReg(unsigned reg) const;
   bool IsTLSReg(unsigned reg) const;
+  bool IsSMEReg(unsigned reg) const;
 
   uint32_t GetRegNumSVEZ0() const;
   uint32_t GetRegNumSVEFFR() const;
@@ -136,6 +139,7 @@
   uint32_t GetPAuthOffset() const;
   uint32_t GetMTEOffset() const;
   uint32_t GetTLSOffset() const;
+  uint32_t GetSMEOffset() const;
 
 private:
   typedef std::map>
@@ -163,6 +167,7 @@
   std::vector pauth_regnum_collection;
   std::vector m_mte_regnum_collection;
   std::vector m_tls_regnum_collection;
+  std::vector m_sme_regnum_collection;
 };
 
 #endif
Index: lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
===

[Lldb-commits] [PATCH] D154926: [lldb][AArch64] Add support for SME's SVE streaming mode registers

2023-07-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added subscribers: ctetreau, kristof.beyls.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added subscribers: lldb-commits, alextsao1999.
Herald added a project: LLDB.

The Scalable Matrix Extension (SME) adds a new Scalable Vector mode
called "streaming SVE mode".

In this mode a lot of things change, but my understanding overall
is that this mode assumes you are not going to move data out of
the vector unit very often or read flags.

Based on "E1.3" of "Arm® Architecture Reference Manual Supplement,
The Scalable Matrix Extension (SME), for Armv9-A".

https://developer.arm.com/documentation/ddi0616/latest/

The important details for debug are that this adds another set
of SVE registers. This set is only active when we are in streaming
mode and is read from a new ptrace regset NT_ARM_SSVE.
We are able to read the header of either mode at all times but
only one will be active and contain register data.

SIMD registers must be read and written via the SVE regset when
in SSVE mode. Writing to them exits streaming mode.

"Note that when SME is present and streaming SVE mode is in use the
FPSIMD subset of registers will be read via NT_ARM_SVE and NT_ARM_SVE
writes will exit streaming mode in the target."

https://kernel.org/doc/html/v6.2/arm64/sve.html

The streaming mode registers do not have different names in the
architecture, so I do not plan to allow users to read or write the
inactive mode's registers. "z0" will always mean "z0" of the active
mode.

(ptrace does allow this but you would be reading invalid state,
and writing switches you into that mode which is probably not what
you want)

I've chosen to have 2 sets of state in the register context.
I did try reusing the same one, but it gets tricky to read SIMD
while in streaming mode.

Existing SVE tests have been updated to check streaming mode and
mode switches. However, we are limited in what we can check given
that state for the other mode is trashed on mode switch.

The only way to know what mode you are in for testing purposes would
be to execute a streaming only, or non-streaming only instruction in
the opposite mode. However, the CPU feature smefa64 actually allows
all non-streaming mode instructions in streaming mode.

This is enabled by default in QEMU emulation and rather than mess
about trying to disable it I'm just going to use the pseduo streaming
control register added in a later patch to make the testing a bit
more robust.

A new test has been added to check SIMD read/write from all the modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154926

Files:
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
  lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.h
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.cpp
  lldb/source/Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/TestSVEThreadedDynamic.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_dynamic_resize/main.c
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/Makefile
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/TestSVERegisters.py
  
lldb/test/API/commands/register/register/aarch64_sve_registers/rw_access_static_config/main.c
  lldb/test/API/commands/register/register/aarch64_sve_simd_registers/Makefile
  
lldb/test/API/commands/register/register/aarch64_sve_simd_registers/TestSVESIMDRegisters.py
  lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c

Index: lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c
===
--- /dev/null
+++ lldb/test/API/commands/register/register/aarch64_sve_simd_registers/main.c
@@ -0,0 +1,108 @@
+#include 
+#include 
+
+void write_simd_regs() {
+#define WRITE_SIMD(NUM)\
+  asm volatile("MOV v" #NUM ".d[0], %0\n\t"\
+   "MOV v" #NUM ".d[1], %0\n\t" ::"r"(NUM))
+
+  WRITE_SIMD(0);
+  WRITE_SIMD(1);
+  WRITE_SIMD(2);
+  WRITE_SIMD(3);
+  WRITE_SIMD(4);
+  WRITE_SIMD(5);
+  WRITE_SIMD(6);
+  WRITE_SIMD(7);
+  WRITE_SIMD(8);
+  WRITE_SIMD(9);
+  WRITE_SIMD(10);
+  WRITE_SIMD(11);
+  WRITE_SIMD(12);
+  WRITE_SIMD(13);
+  WRITE_SIMD(14);
+  WRITE_SIMD(15);
+  WRITE_SIMD(16);
+  WRITE_SIMD(17);
+  WRITE_SIMD(18);
+  WRITE_SIMD(19);
+  WRITE_SIMD(20);
+  WRITE_SIMD(21);
+  WRITE_SIMD(22);
+  WRITE_SIMD(23);
+  WRITE_SIMD(24);
+  WRITE_SIMD(25);
+  WRITE_SIMD(26);
+  WRITE_SIMD(27);
+  WRITE_SIMD(28);
+  WRITE_SIMD(29);
+  WRITE_SIMD(30);
+  WRITE_SIMD(31);
+}
+
+unsigned verify_simd_regs() {
+  uint64_t got_low = 0;
+  uint64_t got_high = 0;
+  uint64_t target = 0;
+
+#define VERIFY_SIMD(NUM)