[Lldb-commits] [lldb] d1c124e - [lldb][ARM/AArch64] Update dissembler to v9.3-a

2022-01-28 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2022-01-28T09:10:04Z
New Revision: d1c124e6e7006ff5597981f8adcb48b2e26b110d

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

LOG: [lldb][ARM/AArch64] Update dissembler to v9.3-a

This means sve2 is enabled by default and the v8.8 mops (memcpy
and memset acceleration instructions) and HBC (hinted conditional
branch) extensions can be disassembled.

v9.3-a is equivalent to v8.8-a except that in v9.0-a sve2 was
enabled by default so v9.3-a includes that too.

MTE remains an optional extension, only enabled for specific CPUs.

Reviewed By: omjavaid

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

Added: 


Modified: 
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

Removed: 




diff  --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp 
b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index 8c54219f0a140..edc5f005c7ac3 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1097,19 +1097,19 @@ DisassemblerLLVMC::DisassemblerLLVMC(const ArchSpec 
&arch,
   thumb_arch_name.erase(0, 3);
   thumb_arch_name.insert(0, "thumb");
 } else {
-  thumb_arch_name = "thumbv8.7a";
+  thumb_arch_name = "thumbv9.3a";
 }
 thumb_arch.GetTriple().setArchName(llvm::StringRef(thumb_arch_name));
   }
 
   // If no sub architecture specified then use the most recent arm architecture
-  // so the disassembler will return all instruction. Without it we will see a
-  // lot of unknow opcode in case the code uses instructions which are not
-  // available in the oldest arm version (used when no sub architecture is
-  // specified)
+  // so the disassembler will return all instructions. Without it we will see a
+  // lot of unknown opcodes if the code uses instructions which are not
+  // available in the oldest arm version (which is used when no sub 
architecture
+  // is specified).
   if (triple.getArch() == llvm::Triple::arm &&
   triple.getSubArch() == llvm::Triple::NoSubArch)
-triple.setArchName("armv8.7a");
+triple.setArchName("armv9.3a");
 
   std::string features_str;
   const char *triple_str = triple.getTriple().c_str();
@@ -1179,9 +1179,9 @@ DisassemblerLLVMC::DisassemblerLLVMC(const ArchSpec &arch,
   }
 
   // If any AArch64 variant, enable latest ISA with any optional
-  // extensions like SVE.
+  // extensions like MTE.
   if (triple.isAArch64()) {
-features_str += "+v8.7a,+sve2,+mte";
+features_str += "+v9.3a,+mte";
 
 if (triple.getVendor() == llvm::Triple::Apple)
   cpu = "apple-latest";



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


[Lldb-commits] [PATCH] D118358: [lldb][ARM/AArch64] Update dissembler to v9.3-a

2022-01-28 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd1c124e6e700: [lldb][ARM/AArch64] Update dissembler to 
v9.3-a (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118358

Files:
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1097,19 +1097,19 @@
   thumb_arch_name.erase(0, 3);
   thumb_arch_name.insert(0, "thumb");
 } else {
-  thumb_arch_name = "thumbv8.7a";
+  thumb_arch_name = "thumbv9.3a";
 }
 thumb_arch.GetTriple().setArchName(llvm::StringRef(thumb_arch_name));
   }
 
   // If no sub architecture specified then use the most recent arm architecture
-  // so the disassembler will return all instruction. Without it we will see a
-  // lot of unknow opcode in case the code uses instructions which are not
-  // available in the oldest arm version (used when no sub architecture is
-  // specified)
+  // so the disassembler will return all instructions. Without it we will see a
+  // lot of unknown opcodes if the code uses instructions which are not
+  // available in the oldest arm version (which is used when no sub 
architecture
+  // is specified).
   if (triple.getArch() == llvm::Triple::arm &&
   triple.getSubArch() == llvm::Triple::NoSubArch)
-triple.setArchName("armv8.7a");
+triple.setArchName("armv9.3a");
 
   std::string features_str;
   const char *triple_str = triple.getTriple().c_str();
@@ -1179,9 +1179,9 @@
   }
 
   // If any AArch64 variant, enable latest ISA with any optional
-  // extensions like SVE.
+  // extensions like MTE.
   if (triple.isAArch64()) {
-features_str += "+v8.7a,+sve2,+mte";
+features_str += "+v9.3a,+mte";
 
 if (triple.getVendor() == llvm::Triple::Apple)
   cpu = "apple-latest";


Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1097,19 +1097,19 @@
   thumb_arch_name.erase(0, 3);
   thumb_arch_name.insert(0, "thumb");
 } else {
-  thumb_arch_name = "thumbv8.7a";
+  thumb_arch_name = "thumbv9.3a";
 }
 thumb_arch.GetTriple().setArchName(llvm::StringRef(thumb_arch_name));
   }
 
   // If no sub architecture specified then use the most recent arm architecture
-  // so the disassembler will return all instruction. Without it we will see a
-  // lot of unknow opcode in case the code uses instructions which are not
-  // available in the oldest arm version (used when no sub architecture is
-  // specified)
+  // so the disassembler will return all instructions. Without it we will see a
+  // lot of unknown opcodes if the code uses instructions which are not
+  // available in the oldest arm version (which is used when no sub architecture
+  // is specified).
   if (triple.getArch() == llvm::Triple::arm &&
   triple.getSubArch() == llvm::Triple::NoSubArch)
-triple.setArchName("armv8.7a");
+triple.setArchName("armv9.3a");
 
   std::string features_str;
   const char *triple_str = triple.getTriple().c_str();
@@ -1179,9 +1179,9 @@
   }
 
   // If any AArch64 variant, enable latest ISA with any optional
-  // extensions like SVE.
+  // extensions like MTE.
   if (triple.isAArch64()) {
-features_str += "+v8.7a,+sve2,+mte";
+features_str += "+v9.3a,+mte";
 
 if (triple.getVendor() == llvm::Triple::Apple)
   cpu = "apple-latest";
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 59a3f65 - Revert "[lldb] [gdb-remote] Support getting siginfo via API"

2022-01-28 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2022-01-28T10:15:52+01:00
New Revision: 59a3f65f5ed6b25b584d504fe4cf8473d4029ff3

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

LOG: Revert "[lldb] [gdb-remote] Support getting siginfo via API"

This reverts commit 1a8f60f5f5b8638a3e8e7fb31ba7ae9e17a7ff2d.
The API requires further work.

Added: 


Modified: 
lldb/bindings/interface/SBThread.i
lldb/include/lldb/API/SBPlatform.h
lldb/include/lldb/API/SBTarget.h
lldb/include/lldb/API/SBThread.h
lldb/include/lldb/API/SBType.h
lldb/include/lldb/Target/Thread.h
lldb/source/API/SBThread.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Removed: 




diff  --git a/lldb/bindings/interface/SBThread.i 
b/lldb/bindings/interface/SBThread.i
index ba7f5b3fdf765..d847d38f0d66e 100644
--- a/lldb/bindings/interface/SBThread.i
+++ b/lldb/bindings/interface/SBThread.i
@@ -405,12 +405,6 @@ public:
 bool
 SafeToCallFunctions ();
 
-%feature("autodoc","
-Retruns a SBValue object representing the siginfo for the current signal.
-") GetSiginfo;
-lldb::SBValue
-GetSiginfo(SBError &error);
-
 STRING_EXTENSION(SBThread)
 
 #ifdef SWIGPYTHON

diff  --git a/lldb/include/lldb/API/SBPlatform.h 
b/lldb/include/lldb/API/SBPlatform.h
index 4f5d04a24e95e..dcc8a14ff0c1f 100644
--- a/lldb/include/lldb/API/SBPlatform.h
+++ b/lldb/include/lldb/API/SBPlatform.h
@@ -172,7 +172,6 @@ class LLDB_API SBPlatform {
 protected:
   friend class SBDebugger;
   friend class SBTarget;
-  friend class SBThread;
 
   lldb::PlatformSP GetSP() const;
 

diff  --git a/lldb/include/lldb/API/SBTarget.h 
b/lldb/include/lldb/API/SBTarget.h
index 9e75b5e503a8c..abd9ebf074076 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -875,7 +875,6 @@ class LLDB_API SBTarget {
   friend class SBSection;
   friend class SBSourceManager;
   friend class SBSymbol;
-  friend class SBThread;
   friend class SBValue;
   friend class SBVariablesOptions;
 

diff  --git a/lldb/include/lldb/API/SBThread.h 
b/lldb/include/lldb/API/SBThread.h
index 76f794c25d9e8..ac1b8407a2200 100644
--- a/lldb/include/lldb/API/SBThread.h
+++ b/lldb/include/lldb/API/SBThread.h
@@ -208,8 +208,6 @@ class LLDB_API SBThread {
 
   bool SafeToCallFunctions();
 
-  SBValue GetSiginfo(SBError &error);
-
 private:
   friend class SBBreakpoint;
   friend class SBBreakpointLocation;

diff  --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h
index 5885432d06243..529b4d0eeffc4 100644
--- a/lldb/include/lldb/API/SBType.h
+++ b/lldb/include/lldb/API/SBType.h
@@ -225,7 +225,6 @@ class SBType {
   friend class SBFunction;
   friend class SBModule;
   friend class SBTarget;
-  friend class SBThread;
   friend class SBTypeEnumMember;
   friend class SBTypeEnumMemberList;
   friend class SBTypeNameSpecifier;

diff  --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index f1d4e6c7ef01a..587b29eb4c661 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -22,7 +22,6 @@
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/StructuredData.h"
-#include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-private.h"
 
@@ -1185,11 +1184,6 @@ class Thread : public 
std::enable_shared_from_this,
 
   lldb::ThreadSP GetCurrentExceptionBacktrace();
 
-  virtual llvm::Expected>
-  GetSiginfo(size_t max_size) const {
-return llvm::make_error();
-  }
-
 protected:
   friend class ThreadPlan;
   friend class ThreadList;

diff  --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index dcc2a6ed3d18f..46a6c2759140b 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -1317,50 +1317,3 @@ lldb_private::Thread *SBThread::operator->() {
 lldb_private::Thread *SBThread::get() {
   return m_opaque_sp->GetThreadSP().get();
 }
-
-SBValue SBThread::GetSiginfo(SBError &error) {
-  LLDB_INSTRUMENT_VA(this, error);
-
-  SBValue value;
-  SBProcess process = GetProcess();
-  if (!process.IsValid()) {
-error.SetErrorString("no process");
-return value;
-  }
-  SBTarget target = process.GetTarget();
-  if (!target.IsValid()) {
-error.SetErrorString("unable to get target");
-return value;
-  }
-  SBPlatform platform = target.GetPlatform();
-  if (!platform.IsValid()) {
-error.SetErrorString("unable to get platform");
-retur

[Lldb-commits] [lldb] 2d75f62 - [lldb] Convert DWARF log to the new API

2022-01-28 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-01-28T10:41:10+01:00
New Revision: 2d75f627221e434c9ff64cdd2c47da9dcb437967

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

LOG: [lldb] Convert DWARF log to the new API

This also deletes some dead log statements (log initialization commented
out).

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h
lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
index 4e09b523b7781..ec4057efbbc54 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/AppleDWARFIndex.cpp
@@ -122,8 +122,7 @@ void AppleDWARFIndex::GetTypes(
   if (!m_apple_types_up)
 return;
 
-  Log *log = LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-  DWARF_LOG_LOOKUPS);
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
   const bool has_tag = m_apple_types_up->GetHeader().header_data.ContainsAtom(
   DWARFMappedHash::eAtomTypeTag);
   const bool has_qualified_name_hash =

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index be555c130bfee..2daffecee58e9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -443,8 +443,7 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const 
SymbolContext &sc,
   if (!die)
 return nullptr;
 
-  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-DWARF_LOG_LOOKUPS));
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
 
   SymbolFileDWARF *dwarf = die.GetDWARF();
   if (log) {
@@ -548,8 +547,7 @@ lldb::TypeSP
 DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
const DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs) {
-  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-DWARF_LOG_LOOKUPS));
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
   SymbolFileDWARF *dwarf = die.GetDWARF();
   const dw_tag_t tag = die.Tag();
   LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
@@ -771,8 +769,7 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext 
&sc,
 TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
   const DWARFDIE &die,
   ParsedDWARFTypeAttributes &attrs) {
-  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-DWARF_LOG_LOOKUPS));
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
   SymbolFileDWARF *dwarf = die.GetDWARF();
   const dw_tag_t tag = die.Tag();
   TypeSP type_sp;
@@ -900,8 +897,7 @@ ConvertDWARFCallingConventionToClang(const 
ParsedDWARFTypeAttributes &attrs) {
 break;
   }
 
-  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-DWARF_LOG_LOOKUPS));
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
   LLDB_LOG(log, "Unsupported DW_AT_calling_convention value: {0}",
attrs.calling_convention);
   // Use the default calling convention as a fallback.
@@ -910,8 +906,7 @@ ConvertDWARFCallingConventionToClang(const 
ParsedDWARFTypeAttributes &attrs) {
 
 TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
ParsedDWARFTypeAttributes &attrs) {
-  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
-DWARF_LOG_LOOKUPS));
+  Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
 
   SymbolFileDWARF *dwarf = die.GetDWARF();
   const dw_tag_t tag = die.Tag();
@@ -1562,8 +1557,7 @@ DWARFASTParserClang::ParseStructureLikeDIE(const 
SymbolContext &sc,
   const dw_tag_t tag = die.Tag();
   SymbolFileDWARF *dwarf = die.GetDWARF();
   LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
-  Log *log = Log

[Lldb-commits] [PATCH] D118055: [lldb] [gdb-remote] Support getting siginfo via API

2022-01-28 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 403948.
mgorny added a comment.

Add `Thread::GetSiginfoValue()` to perform baseline value construction, and 
limit `SBThread::GetSiginfo()` to wrapping that. Return errors via 
`ValueObjectConstResult`.


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

https://reviews.llvm.org/D118055

Files:
  lldb/bindings/interface/SBThread.i
  lldb/include/lldb/API/SBThread.h
  lldb/include/lldb/Target/Thread.h
  lldb/source/API/SBThread.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
  lldb/source/Target/Thread.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -490,3 +490,98 @@
  lldb.eStopReasonSignal)
 self.assertEqual(process.threads[0].GetStopDescription(100),
  'signal SIGUSR1')
+
+def do_siginfo_test(self, platform, target_yaml, raw_data, expected):
+class MyResponder(MockGDBServerResponder):
+def qSupported(self, client_supported):
+return "PacketSize=3fff;QStartNoAckMode+;qXfer:siginfo:read+"
+
+def qXferRead(self, obj, annex, offset, length):
+if obj == "siginfo":
+return raw_data, False
+else:
+return None, False
+
+def haltReason(self):
+return "T02"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+self.runCmd("platform select " + platform)
+target = self.createTarget(target_yaml)
+process = self.connect(target)
+
+siginfo = process.threads[0].GetSiginfo()
+self.assertTrue(siginfo.GetError().Success(), siginfo.GetError())
+
+for key, value in expected.items():
+self.assertEqual(siginfo.GetValueForExpressionPath("." + key)
+ .GetValueAsUnsigned(),
+ value)
+
+
+def test_siginfo_linux_amd64(self):
+data = (
+  # si_signo si_errnosi_code
+"\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # __pad0   si_pid  si_uid
+"\x00\x00\x00\x00\xbf\xf7\x0b\x00\xe8\x03\x00\x00"
+  # si_status
+"\x0c\x00\x00\x00" + "\x00" * 100)
+expected = {
+"si_signo": 17,  # SIGCHLD
+"si_errno": 0,
+"si_code": 1,  # CLD_EXITED
+"_sifields._sigchld.si_pid": 784319,
+"_sifields._sigchld.si_uid": 1000,
+"_sifields._sigchld.si_status": 12,
+"_sifields._sigchld.si_utime": 0,
+"_sifields._sigchld.si_stime": 0,
+}
+self.do_siginfo_test("remote-linux", "basic_eh_frame.yaml",
+ data, expected)
+
+def test_siginfo_linux_i386(self):
+data = (
+  # si_signo si_errnosi_code
+"\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # si_pid   si_uid  si_status
+"\x49\x43\x07\x00\xe8\x03\x00\x00\x0c\x00\x00\x00"
++ "\x00" * 104)
+expected = {
+"si_signo": 17,  # SIGCHLD
+"si_errno": 0,
+"si_code": 1,  # CLD_EXITED
+"_sifields._sigchld.si_pid": 475977,
+"_sifields._sigchld.si_uid": 1000,
+"_sifields._sigchld.si_status": 12,
+"_sifields._sigchld.si_utime": 0,
+"_sifields._sigchld.si_stime": 0,
+}
+self.do_siginfo_test("remote-linux", "basic_eh_frame-i386.yaml",
+ data, expected)
+
+def test_siginfo_freebsd_amd64(self):
+data = (
+  # si_signo si_errnosi_code
+"\x0b\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # si_pid   si_uid  si_status
+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+  # si_addr
+"\x76\x98\xba\xdc\xfe\x00\x00\x00"
+  # si_statussi_trapno
+"\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00"
++ "\x00" * 36)
+
+expected = {
+"si_signo": 11,  # SIGSEGV
+"si_errno": 0,
+"si_code": 1,  # SEGV_MAPERR
+"si_addr": 0xfedcba9876,
+"_reason._fault._trapno": 12,
+}
+self.do_siginfo_test("remote-freebsd", "basic_eh_frame.yaml",
+ 

[Lldb-commits] [PATCH] D118473: [lldb] [Commands] Implement "thread siginfo"

2022-01-28 Thread Michał Górny via Phabricator via lldb-commits
mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski.
mgorny requested review of this revision.

https://reviews.llvm.org/D118473

Files:
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/test/Shell/Commands/Inputs/sigchld.c
  lldb/test/Shell/Commands/command-thread-siginfo.test

Index: lldb/test/Shell/Commands/command-thread-siginfo.test
===
--- /dev/null
+++ lldb/test/Shell/Commands/command-thread-siginfo.test
@@ -0,0 +1,19 @@
+# REQUIRES: system-linux
+# RUN: %clang_host -g %S/Inputs/sigchld.c -o %t
+# RUN: %lldb %t -b -s %s | FileCheck %s
+
+process launch -s
+process handle SIGCHLD -s true
+process continue
+# CHECK: signo = [[SIGNO:[0-9]+]]
+# CHECK: code = [[CODE:[0-9]+]]
+# CHECK: child_pid = [[PID:[0-9]+]]
+# CHECK: uid = [[UID:[0-9]+]]
+# CHECK: stop reason = signal SIGCHLD
+thread siginfo
+# CHECK-DAG: si_signo = [[SIGNO]]
+# CHECK-DAG: si_errno = 0
+# CHECK-DAG: si_code = [[CODE]]
+# CHECK-DAG: si_pid = [[PID]]
+# CHECK-DAG: si_uid = [[UID]]
+# CHECK-DAG: si_status = 14
Index: lldb/test/Shell/Commands/Inputs/sigchld.c
===
--- /dev/null
+++ lldb/test/Shell/Commands/Inputs/sigchld.c
@@ -0,0 +1,31 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void handler(int signo) {
+  printf("SIGCHLD\n");
+}
+
+int main() {
+  void *ret = signal(SIGINT, handler);
+  assert (ret != SIG_ERR);
+
+  pid_t child_pid = fork();
+  assert (child_pid != -1);
+
+  if (child_pid == 0) {
+sleep(1);
+_exit(14);
+  }
+
+  printf("signo = %d\n", SIGCHLD);
+  printf("code = %d\n", CLD_EXITED);
+  printf("child_pid = %d\n", child_pid);
+  printf("uid = %d\n", getuid());
+  pid_t waited = wait(NULL);
+  assert(waited == child_pid);
+
+  return 0;
+}
Index: lldb/source/Commands/CommandObjectThread.cpp
===
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -1320,6 +1320,47 @@
   }
 };
 
+// CommandObjectThreadSiginfo
+
+class CommandObjectThreadSiginfo : public CommandObjectIterateOverThreads {
+public:
+  CommandObjectThreadSiginfo(CommandInterpreter &interpreter)
+  : CommandObjectIterateOverThreads(
+interpreter, "thread siginfo",
+"Display the current siginfo object for a thread. Defaults to "
+"the current thread.",
+"thread siginfo",
+eCommandRequiresProcess | eCommandTryTargetAPILock |
+eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
+
+  ~CommandObjectThreadSiginfo() override = default;
+
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+   OptionElementVector &opt_element_vector) override {
+CommandCompletions::InvokeCommonCompletionCallbacks(
+GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
+request, nullptr);
+  }
+
+  bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
+ThreadSP thread_sp =
+m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
+if (!thread_sp) {
+  result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
+   tid);
+  return false;
+}
+
+Stream &strm = result.GetOutputStream();
+ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
+if (exception_object_sp)
+  exception_object_sp->Dump(strm);
+
+return true;
+  }
+};
+
 // CommandObjectThreadReturn
 #define LLDB_OPTIONS_thread_return
 #include "CommandOptions.inc"
@@ -2293,6 +2334,8 @@
  CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
   LoadSubCommand("exception", CommandObjectSP(new CommandObjectThreadException(
   interpreter)));
+  LoadSubCommand("siginfo",
+ CommandObjectSP(new CommandObjectThreadSiginfo(interpreter)));
   LoadSubCommand("step-in",
  CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
  interpreter, "thread step-in",
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] b414954 - [lldb] Make ReadCStringFromMemory default to read from the file-cache.

2022-01-28 Thread Augusto Noronha via lldb-commits

Author: Augusto Noronha
Date: 2022-01-28T13:08:30-03:00
New Revision: b414954a5f1c2f8f6adecf20e5a433dfbc320cc2

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

LOG: [lldb] Make ReadCStringFromMemory default to read from the file-cache.

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

Added: 


Modified: 
lldb/include/lldb/Target/Target.h
lldb/source/Target/Target.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Target.h 
b/lldb/include/lldb/Target/Target.h
index 2c8b36d1e3d9c..42a641f6d52ab 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -1019,10 +1019,11 @@ class Target : public 
std::enable_shared_from_this,
 lldb::addr_t *load_addr_ptr = nullptr);
 
   size_t ReadCStringFromMemory(const Address &addr, std::string &out_str,
-   Status &error);
+   Status &error, bool force_live_memory = false);
 
   size_t ReadCStringFromMemory(const Address &addr, char *dst,
-   size_t dst_max_len, Status &result_error);
+   size_t dst_max_len, Status &result_error,
+   bool force_live_memory = false);
 
   /// Read a NULL terminated string from memory
   ///

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 01e51c0577aae..6d33db6554d2e 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1829,13 +1829,14 @@ size_t Target::ReadMemory(const Address &addr, void 
*dst, size_t dst_len,
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
- Status &error) {
+ Status &error, bool force_live_memory) {
   char buf[256];
   out_str.clear();
   addr_t curr_addr = addr.GetLoadAddress(this);
   Address address(addr);
   while (true) {
-size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
+size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
+  force_live_memory);
 if (length == 0)
   break;
 out_str.append(buf, length);
@@ -1851,7 +1852,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, 
std::string &out_str,
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
- size_t dst_max_len, Status &result_error) 
{
+ size_t dst_max_len, Status &result_error,
+ bool force_live_memory) {
   size_t total_cstr_len = 0;
   if (dst && dst_max_len) {
 result_error.Clear();
@@ -1874,8 +1876,8 @@ size_t Target::ReadCStringFromMemory(const Address &addr, 
char *dst,
   cache_line_size - (curr_addr % cache_line_size);
   addr_t bytes_to_read =
   std::min(bytes_left, cache_line_bytes_left);
-  size_t bytes_read =
-  ReadMemory(address, curr_dst, bytes_to_read, error, true);
+  size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
+ force_live_memory);
 
   if (bytes_read == 0) {
 result_error = error;



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


[Lldb-commits] [PATCH] D118265: [lldb] Make ReadCStringFromMemory default to read from the file-cache.

2022-01-28 Thread Augusto Noronha via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb414954a5f1c: [lldb] Make ReadCStringFromMemory default to 
read from the file-cache. (authored by augusto2112).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118265

Files:
  lldb/include/lldb/Target/Target.h
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -1829,13 +1829,14 @@
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
- Status &error) {
+ Status &error, bool force_live_memory) {
   char buf[256];
   out_str.clear();
   addr_t curr_addr = addr.GetLoadAddress(this);
   Address address(addr);
   while (true) {
-size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
+size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
+  force_live_memory);
 if (length == 0)
   break;
 out_str.append(buf, length);
@@ -1851,7 +1852,8 @@
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
- size_t dst_max_len, Status &result_error) 
{
+ size_t dst_max_len, Status &result_error,
+ bool force_live_memory) {
   size_t total_cstr_len = 0;
   if (dst && dst_max_len) {
 result_error.Clear();
@@ -1874,8 +1876,8 @@
   cache_line_size - (curr_addr % cache_line_size);
   addr_t bytes_to_read =
   std::min(bytes_left, cache_line_bytes_left);
-  size_t bytes_read =
-  ReadMemory(address, curr_dst, bytes_to_read, error, true);
+  size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
+ force_live_memory);
 
   if (bytes_read == 0) {
 result_error = error;
Index: lldb/include/lldb/Target/Target.h
===
--- lldb/include/lldb/Target/Target.h
+++ lldb/include/lldb/Target/Target.h
@@ -1019,10 +1019,11 @@
 lldb::addr_t *load_addr_ptr = nullptr);
 
   size_t ReadCStringFromMemory(const Address &addr, std::string &out_str,
-   Status &error);
+   Status &error, bool force_live_memory = false);
 
   size_t ReadCStringFromMemory(const Address &addr, char *dst,
-   size_t dst_max_len, Status &result_error);
+   size_t dst_max_len, Status &result_error,
+   bool force_live_memory = false);
 
   /// Read a NULL terminated string from memory
   ///


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -1829,13 +1829,14 @@
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
- Status &error) {
+ Status &error, bool force_live_memory) {
   char buf[256];
   out_str.clear();
   addr_t curr_addr = addr.GetLoadAddress(this);
   Address address(addr);
   while (true) {
-size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
+size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error,
+  force_live_memory);
 if (length == 0)
   break;
 out_str.append(buf, length);
@@ -1851,7 +1852,8 @@
 }
 
 size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
- size_t dst_max_len, Status &result_error) {
+ size_t dst_max_len, Status &result_error,
+ bool force_live_memory) {
   size_t total_cstr_len = 0;
   if (dst && dst_max_len) {
 result_error.Clear();
@@ -1874,8 +1876,8 @@
   cache_line_size - (curr_addr % cache_line_size);
   addr_t bytes_to_read =
   std::min(bytes_left, cache_line_bytes_left);
-  size_t bytes_read =
-  ReadMemory(address, curr_dst, bytes_to_read, error, true);
+  size_t bytes_read = ReadMemory(address, curr_dst, bytes_to_read, error,
+ force_live_memory);
 
   if (bytes_read == 0) {
 result_error = error;
Index: lldb/include/lldb/Target/Target.h
===
--- lldb/include/lldb/Target/Target.h
+++ lldb/include/lldb/Target/Target.h
@@ -1019,10 +1019,11 @@
 lldb::addr_t *load_addr_ptr = nullptr);
 
   size_t ReadCStringFromMemory(const Address &addr, std::string &o

[Lldb-commits] [PATCH] D118055: [lldb] [gdb-remote] Support getting siginfo via API

2022-01-28 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.
This revision is now accepted and ready to land.

Thanks for making that change!  LGTM.


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

https://reviews.llvm.org/D118055

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


[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
Herald added a subscriber: arphaman.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch adds a new method to the Scripted Process Interface to fetch
the index to the thread that should be selected in the Scripted Process.

This can be very helpful to ensure lldb will stop with the right thread
selected by the user in the script.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118482

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -57,6 +57,9 @@
 
 return data
 
+def get_selected_thread_index(self):
+return 3
+
 def get_loaded_images(self):
 # TODO: Iterate over corefile_target modules and build a data structure
 # from it.
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -44,6 +44,8 @@
 
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
+  uint32_t GetSelectedThreadIndex() override;
+
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
 
   lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -113,6 +113,21 @@
   return dict;
 }
 
+uint32_t ScriptedProcessPythonInterface::GetSelectedThreadIndex() {
+  Status error;
+  StructuredData::ObjectSP obj = Dispatch("get_selected_thread_index", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
+return LLDB_INVALID_INDEX32;
+
+  uint64_t val = obj->GetIntegerValue(LLDB_INVALID_INDEX32);
+
+  if (std::numeric_limits::max() <= val)
+return LLDB_INVALID_INDEX32;
+
+  return static_cast(val);
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) {
   // TODO: Implement
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -359,6 +359,11 @@
 void ScriptedProcess::RefreshStateAfterStop() {
   // Let all threads recover from stopping and do any clean up based on the
   // previous thread state (if any).
+  uint32_t selected_thread_index = GetInterface().GetSelectedThreadIndex();
+
+  if (selected_thread_index != LLDB_INVALID_INDEX32 &&
+  selected_thread_index <= m_thread_list.GetSize())
+m_thread_list.SetSelectedThreadByIndexID(selected_thread_index);
 }
 
 bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -48,6 +48,8 @@
 return nullptr;
   }
 
+  virtual uint32_t GetSelectedThreadIndex() { return LLDB_INVALID_INDEX32; }
+
   virtual StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) {
 return nullptr;
   }
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -76,6 +76,15 @@
 """
 pass
 
+def get_selected_thread_index(self):
+""" Get the index of the selected scripted process thread.
+
+Returns:
+Int: The thread index that should be selected by lldb.
+ (default: 1)
+"""
+return 1
+
 @abstractmethod
 def get_registers_for_

[Lldb-commits] [lldb] ac666d1 - [lldb] [gdb-remote] Support getting siginfo via API

2022-01-28 Thread Michał Górny via lldb-commits

Author: Michał Górny
Date: 2022-01-28T17:47:47+01:00
New Revision: ac666d1799c45a1ecd59f7503e1fc649deffd4d4

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

LOG: [lldb] [gdb-remote] Support getting siginfo via API

Add Thread::GetSiginfo() and SBThread::GetSiginfo() methods to retrieve
the siginfo value from server.

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

Added: 


Modified: 
lldb/bindings/interface/SBThread.i
lldb/include/lldb/API/SBThread.h
lldb/include/lldb/Target/Thread.h
lldb/source/API/SBThread.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
lldb/source/Target/Thread.cpp
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Removed: 




diff  --git a/lldb/bindings/interface/SBThread.i 
b/lldb/bindings/interface/SBThread.i
index d847d38f0d66..1e46bd6e21f6 100644
--- a/lldb/bindings/interface/SBThread.i
+++ b/lldb/bindings/interface/SBThread.i
@@ -405,6 +405,12 @@ public:
 bool
 SafeToCallFunctions ();
 
+%feature("autodoc","
+Retruns a SBValue object representing the siginfo for the current signal.
+") GetSiginfo;
+lldb::SBValue
+GetSiginfo();
+
 STRING_EXTENSION(SBThread)
 
 #ifdef SWIGPYTHON

diff  --git a/lldb/include/lldb/API/SBThread.h 
b/lldb/include/lldb/API/SBThread.h
index ac1b8407a220..924aae2f109a 100644
--- a/lldb/include/lldb/API/SBThread.h
+++ b/lldb/include/lldb/API/SBThread.h
@@ -208,6 +208,8 @@ class LLDB_API SBThread {
 
   bool SafeToCallFunctions();
 
+  SBValue GetSiginfo();
+
 private:
   friend class SBBreakpoint;
   friend class SBBreakpointLocation;

diff  --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index 587b29eb4c66..2fd7d8859f52 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -22,6 +22,7 @@
 #include "lldb/Utility/CompletionRequest.h"
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/StructuredData.h"
+#include "lldb/Utility/UnimplementedError.h"
 #include "lldb/Utility/UserID.h"
 #include "lldb/lldb-private.h"
 
@@ -1184,6 +1185,8 @@ class Thread : public 
std::enable_shared_from_this,
 
   lldb::ThreadSP GetCurrentExceptionBacktrace();
 
+  lldb::ValueObjectSP GetSiginfoValue();
+
 protected:
   friend class ThreadPlan;
   friend class ThreadList;
@@ -1233,6 +1236,11 @@ class Thread : public 
std::enable_shared_from_this,
 
   void FrameSelectedCallback(lldb_private::StackFrame *frame);
 
+  virtual llvm::Expected>
+  GetSiginfo(size_t max_size) const {
+return llvm::make_error();
+  }
+
   // Classes that inherit from Process can see and modify these
   lldb::ProcessWP m_process_wp;///< The process that owns this thread.
   lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread

diff  --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index 46a6c2759140..a08cb741814b 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -1317,3 +1317,12 @@ lldb_private::Thread *SBThread::operator->() {
 lldb_private::Thread *SBThread::get() {
   return m_opaque_sp->GetThreadSP().get();
 }
+
+SBValue SBThread::GetSiginfo() {
+  LLDB_INSTRUMENT_VA(this);
+
+  ThreadSP thread_sp = m_opaque_sp->GetThreadSP();
+  if (!thread_sp)
+return SBValue();
+  return thread_sp->GetSiginfoValue();
+}

diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index b5b105351de5..f6526d03863b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -173,6 +173,13 @@ bool 
GDBRemoteCommunicationClient::GetQXferMemoryMapReadSupported() {
   return m_supports_qXfer_memory_map_read == eLazyBoolYes;
 }
 
+bool GDBRemoteCommunicationClient::GetQXferSigInfoReadSupported() {
+  if (m_supports_qXfer_siginfo_read == eLazyBoolCalculate) {
+GetRemoteQSupported();
+  }
+  return m_supports_qXfer_siginfo_read == eLazyBoolYes;
+}
+
 uint64_t GDBRemoteCommunicationClient::GetRemoteMaxPacketSize() {
   if (m_max_packet_size == 0) {
 GetRemoteQSupported();
@@ -273,6 +280,7 @@ void 
GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) {
 m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate;
 m_supports_qXfer_features_read = eLazyBoolCalculate;
 m_supports_qXfer_memory_map_read = eLazyBoolCalculate;
+m_supports_qXfer_siginfo_read = eLazyBoolCalculate;
 m_supports_a

[Lldb-commits] [PATCH] D78801: [LLDB] Add class WasmProcess for WebAssembly debugging

2022-01-28 Thread Paolo Severini via Phabricator via lldb-commits
paolosev added a comment.

Thanks @xujuntwt95329! I am very happy that this was useful for WebAssembly 
Micro Runtime!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78801

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


[Lldb-commits] [PATCH] D118055: [lldb] [gdb-remote] Support getting siginfo via API

2022-01-28 Thread Michał Górny via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac666d1799c4: [lldb] [gdb-remote] Support getting siginfo 
via API (authored by mgorny).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118055

Files:
  lldb/bindings/interface/SBThread.i
  lldb/include/lldb/API/SBThread.h
  lldb/include/lldb/Target/Thread.h
  lldb/source/API/SBThread.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
  lldb/source/Target/Thread.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py

Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
===
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py
@@ -490,3 +490,98 @@
  lldb.eStopReasonSignal)
 self.assertEqual(process.threads[0].GetStopDescription(100),
  'signal SIGUSR1')
+
+def do_siginfo_test(self, platform, target_yaml, raw_data, expected):
+class MyResponder(MockGDBServerResponder):
+def qSupported(self, client_supported):
+return "PacketSize=3fff;QStartNoAckMode+;qXfer:siginfo:read+"
+
+def qXferRead(self, obj, annex, offset, length):
+if obj == "siginfo":
+return raw_data, False
+else:
+return None, False
+
+def haltReason(self):
+return "T02"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+self.runCmd("platform select " + platform)
+target = self.createTarget(target_yaml)
+process = self.connect(target)
+
+siginfo = process.threads[0].GetSiginfo()
+self.assertTrue(siginfo.GetError().Success(), siginfo.GetError())
+
+for key, value in expected.items():
+self.assertEqual(siginfo.GetValueForExpressionPath("." + key)
+ .GetValueAsUnsigned(),
+ value)
+
+
+def test_siginfo_linux_amd64(self):
+data = (
+  # si_signo si_errnosi_code
+"\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # __pad0   si_pid  si_uid
+"\x00\x00\x00\x00\xbf\xf7\x0b\x00\xe8\x03\x00\x00"
+  # si_status
+"\x0c\x00\x00\x00" + "\x00" * 100)
+expected = {
+"si_signo": 17,  # SIGCHLD
+"si_errno": 0,
+"si_code": 1,  # CLD_EXITED
+"_sifields._sigchld.si_pid": 784319,
+"_sifields._sigchld.si_uid": 1000,
+"_sifields._sigchld.si_status": 12,
+"_sifields._sigchld.si_utime": 0,
+"_sifields._sigchld.si_stime": 0,
+}
+self.do_siginfo_test("remote-linux", "basic_eh_frame.yaml",
+ data, expected)
+
+def test_siginfo_linux_i386(self):
+data = (
+  # si_signo si_errnosi_code
+"\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # si_pid   si_uid  si_status
+"\x49\x43\x07\x00\xe8\x03\x00\x00\x0c\x00\x00\x00"
++ "\x00" * 104)
+expected = {
+"si_signo": 17,  # SIGCHLD
+"si_errno": 0,
+"si_code": 1,  # CLD_EXITED
+"_sifields._sigchld.si_pid": 475977,
+"_sifields._sigchld.si_uid": 1000,
+"_sifields._sigchld.si_status": 12,
+"_sifields._sigchld.si_utime": 0,
+"_sifields._sigchld.si_stime": 0,
+}
+self.do_siginfo_test("remote-linux", "basic_eh_frame-i386.yaml",
+ data, expected)
+
+def test_siginfo_freebsd_amd64(self):
+data = (
+  # si_signo si_errnosi_code
+"\x0b\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"
+  # si_pid   si_uid  si_status
+"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+  # si_addr
+"\x76\x98\xba\xdc\xfe\x00\x00\x00"
+  # si_statussi_trapno
+"\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00"
++ "\x00" * 36)
+
+expected = {
+"si_signo": 11,  # SIGSEGV
+"si_errno": 0,
+"si_code": 1,  # SEGV_MAPERR
+"si_addr": 0xfedcba9876,
+"_reason._fault._trapno": 12,
+}
+self.do_siginfo_test("remote-freebsd", "basic_eh_frame.yaml",
+  

[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

This seems wrong to me.  Normal Processes don't get to choose which thread the 
generic "which stop event is most important" logic selects, they just report 
the stop events and then the higher level logic decides which one to select.  
It seems more symmetric to have the ScriptedThreads work the same way - after 
all they are free to assign whatever StopInfo they want to each stop.  Why do 
you need to force the result in the ScriptedProcess case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

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


[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch fixes a timeout issue on the ScriptedProcess test that was
happening on intel platforms. The timeout was due to a misreporting of
the StopInfo on the ScriptedThread that caused the ScriptedProcess to
never stop.

To solve this, this patch changes the way a ScriptedThread reports its
stop reason by making it more architecture specific. In order to do so,
this patch also refactors the ScriptedProcess & ScriptedThread
initializer methods to provide an easy access to the target architecture.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118484

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -122,17 +122,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
-
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.corefile_thread and self.corefile_thread.IsValid():
+stop_reason["type"] = lldb.eStopReasonNone
+
+selected_thread_idx = self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -32,8 +32,12 @@
 """
 self.target = None
 self.args = None
+self.arch = None
 if isinstance(target, lldb.SBTarget) and target.IsValid():
 self.target = target
+triple = self.target.triple
+if triple:
+self.arch = triple.split('-')[0]
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -210,19 +214,21 @@
 """
 
 @abstractmethod
-def __init__(self, process, args):
+def __init__(self, scripted_process, args):
 """ Construct a scripted thread.
 
 Args:
-process (lldb.SBProcess): The scripted process owning this thread.
+process (ScriptedProcess): The scripted process owning this thread.
 args (lldb.SBStructuredData): A Dictionary holding arbitrary
 key/value pairs used by the scripted thread.
 """
 self.target = None
+self.scripted_process = None
 self.process = None
 self.args = None
-if isinstance(process, ScriptedProcess):
-self.target = process.target
+i

[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D118482#3279843 , @jingham wrote:

> This seems wrong to me.  Normal Processes don't get to choose which thread 
> the generic "which stop event is most important" logic selects, they just 
> report the stop events and then the higher level logic decides which one to 
> select.  It seems more symmetric to have the ScriptedThreads work the same 
> way - after all they are free to assign whatever StopInfo they want to each 
> stop.  Why do you need to force the result in the ScriptedProcess case?

This is completely optional.  The user doesn't really have to override the base 
method, in which case lldb won't force the ScriptedProcess to select a specific 
thread. It will use its current stopping logic to look at the ScriptedThreads 
stop reasons and determine which one it should select.

However, in some cases (i.e. crashlogs), we only have very sparse metadata to 
construct the ScriptedThreads, so having the ability to select the most 
relevant thread to the user can be quite helpful.

Also, I'm not sure a Scripted Process should share the exact same behavior as a 
Normal Process as they will eventually be able to report fully synthetic 
threads / frames, but I might be wrong on that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

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


[Lldb-commits] [PATCH] D118425: [lldb] Update the lldb build instructions on Windows

2022-01-28 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova updated this revision to Diff 404065.
stella.stamenova added a comment.

Add more details for developer command prompt


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

https://reviews.llvm.org/D118425

Files:
  lldb/docs/resources/build.rst


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -92,24 +92,30 @@
 * `GnuWin32 `_ for CoreUtils and Make.
 * `Python 3 `_.  Make sure to (1) 
get
   the x64 variant if that's what you're targetting and (2) install the debug
-  library if you want to build a debug lldb.
+  library if you want to build a debug lldb. The standalone installer is the
+  easiest way to get the debug library.
 * `Python Tools for Visual Studio
-  `_. If you plan to debug test
-  failures or even write new tests at all, PTVS is an indispensable debugging
+  `_. If you plan to debug test failures
+  or even write new tests at all, PTVS is an indispensable debugging
   extension to VS that enables full editing and debugging support for Python
   (including mixed native/managed debugging).
+* `SWIG for Windows _`
 
 The steps outlined here describes how to set up your system and install the
 required dependencies such that they can be found when needed during the build
 process. They only need to be performed once.
 
-#. Install Visual Studio with the Windows SDK and ATL components.
+#. Install Visual Studio with the "Desktop Development with C++" workload and
+   the "Python Development" workload.
 #. Install GnuWin32, making sure ``\bin`` is added to
your PATH environment variable. Verify that utilities like ``dirname`` and
``make`` are available from your terminal.
 #. Install SWIG for Windows, making sure  is added to
your PATH environment variable. Verify that ``swig`` is available from your
terminal.
+#. Install Python 3 from the standalone installer and include the debug 
libraries
+   in the install, making sure the Python install path is added to your PATH
+   environment variable.
 #. Register the Debug Interface Access DLLs with the Registry from a privileged
terminal.
 
@@ -119,9 +125,10 @@
 > regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA 
 > SDK\bin\amd64\msdia140.dll"
 
 Any command prompt from which you build LLDB should have a valid Visual Studio
-environment setup. This means you should run ``vcvarsall.bat`` or open an
-appropriate Visual Studio Command Prompt corresponding to the version you wish
-to use.
+environment setup. This means you should open an appropriate `Developer Command
+Prompt for VS 
`_
+corresponding to the version you wish to use or run ``vcvarsall.bat`` or
+``VsDevCmd.bat``.
 
 macOS
 *


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -92,24 +92,30 @@
 * `GnuWin32 `_ for CoreUtils and Make.
 * `Python 3 `_.  Make sure to (1) get
   the x64 variant if that's what you're targetting and (2) install the debug
-  library if you want to build a debug lldb.
+  library if you want to build a debug lldb. The standalone installer is the
+  easiest way to get the debug library.
 * `Python Tools for Visual Studio
-  `_. If you plan to debug test
-  failures or even write new tests at all, PTVS is an indispensable debugging
+  `_. If you plan to debug test failures
+  or even write new tests at all, PTVS is an indispensable debugging
   extension to VS that enables full editing and debugging support for Python
   (including mixed native/managed debugging).
+* `SWIG for Windows _`
 
 The steps outlined here describes how to set up your system and install the
 required dependencies such that they can be found when needed during the build
 process. They only need to be performed once.
 
-#. Install Visual Studio with the Windows SDK and ATL components.
+#. Install Visual Studio with the "Desktop Development with C++" workload and
+   the "Python Development" workload.
 #. Install GnuWin32, making sure ``\bin`` is added to
your PATH environment variable. Verify that utilities like ``dirname`` and
``make`` are available from your terminal.
 #. Install SWIG for Windows, making sure  is added to
your PATH environment variable. Verify that ``swig`` is available from your
terminal.
+#. Install Python 3 from the standalone installer and inclu

[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

My preference for things like crash reports would be that you make up a stop 
reason that's significant for the thread(s) you think are interesting and then 
let lldb figure out how to display them.  After all, if you set a selected 
thread w/o having a StopInfo that would warrant selecting that thread, it's 
going to look weird.  We selected thread 100, but it hadn't stopped for any 
particular reason is an odd experience.

And I don't think the default behavior should be to select thread 1, as that 
forces the upper layers hand.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

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


[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404068.
mib added a reviewer: jingham.
mib added a comment.

Address @jingham concerns by making this fully optional:

- Change python default value to 0. Thread indices in lldb are 1-based, so 0 
sounds like a good error_value.
- Check for python returned integer and replace it by `LLDB_INVALID_INDEX32` to 
prevent `ScriptedProcess::RefreshStateAfterStop` to select a thread with it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -57,6 +57,9 @@
 
 return data
 
+def get_selected_thread_index(self):
+return 3
+
 def get_loaded_images(self):
 # TODO: Iterate over corefile_target modules and build a data structure
 # from it.
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -44,6 +44,8 @@
 
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
+  uint32_t GetSelectedThreadIndex() override;
+
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
 
   lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -113,6 +113,21 @@
   return dict;
 }
 
+uint32_t ScriptedProcessPythonInterface::GetSelectedThreadIndex() {
+  Status error;
+  StructuredData::ObjectSP obj = Dispatch("get_selected_thread_index", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
+return LLDB_INVALID_INDEX32;
+
+  uint64_t val = obj->GetIntegerValue(LLDB_INVALID_INDEX32);
+
+  if (!val || std::numeric_limits::max() <= val)
+return LLDB_INVALID_INDEX32;
+
+  return static_cast(val);
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) {
   // TODO: Implement
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -359,6 +359,11 @@
 void ScriptedProcess::RefreshStateAfterStop() {
   // Let all threads recover from stopping and do any clean up based on the
   // previous thread state (if any).
+  uint32_t selected_thread_index = GetInterface().GetSelectedThreadIndex();
+
+  if (selected_thread_index != LLDB_INVALID_INDEX32 &&
+  selected_thread_index <= m_thread_list.GetSize())
+m_thread_list.SetSelectedThreadByIndexID(selected_thread_index);
 }
 
 bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -48,6 +48,8 @@
 return nullptr;
   }
 
+  virtual uint32_t GetSelectedThreadIndex() { return LLDB_INVALID_INDEX32; }
+
   virtual StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) {
 return nullptr;
   }
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -76,6 +76,15 @@
 """
 pass
 
+def get_selected_thread_index(self):
+""" Get the index of the selected scripted process thread.
+
+Returns:
+Int: The thread index that should be selected by lldb.
+ (default: 0)
+"""
+return 0
+
 @abstractmethod
 def get_registers_for_th

[Lldb-commits] [PATCH] D118425: [lldb] Update the lldb build instructions on Windows

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

Nice. Thanks!


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

https://reviews.llvm.org/D118425

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


[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Shafik Yaghmour via Phabricator via lldb-commits
shafik added a comment.

Just nitpicks




Comment at: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp:362
   // previous thread state (if any).
+  uint32_t selected_thread_index = GetInterface().GetSelectedThreadIndex();
+

`const`



Comment at: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:123
+
+  uint64_t val = obj->GetIntegerValue(LLDB_INVALID_INDEX32);
+

`const`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

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


[Lldb-commits] [PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2022-01-28 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added inline comments.



Comment at: lldb/docs/resources/build.rst:296
 
-  $ cmake -G "Visual Studio 15 2017 Win64" -Thost=x64  
+  $ cmake -G "Visual Studio 16 2019 Win64" -Thost=x64  
 

This line should change a bit more. For VS2019, it also needs to include `-A 
64` like so: `cmake -G "Visual Studio 16 2019" -A x64 -T host=x64`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[Lldb-commits] [PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2022-01-28 Thread Simon Pilgrim via Phabricator via lldb-commits
RKSimon updated this revision to Diff 403924.
RKSimon added a comment.

update lldb cmake command


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/UsersManual.rst
  lldb/docs/resources/build.rst
  lldb/docs/resources/test.rst
  llvm/cmake/modules/CheckCompilerVersion.cmake
  llvm/docs/CMake.rst
  llvm/docs/GettingStarted.rst
  llvm/docs/GettingStartedVS.rst
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compiler.h

Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -77,12 +77,21 @@
 /// * 1916: VS2017, version 15.9
 /// * 1920: VS2019, version 16.0
 /// * 1921: VS2019, version 16.1
+/// * 1922: VS2019, version 16.2
+/// * 1923: VS2019, version 16.3
+/// * 1924: VS2019, version 16.4
+/// * 1925: VS2019, version 16.5
+/// * 1926: VS2019, version 16.6
+/// * 1927: VS2019, version 16.7
+/// * 1928: VS2019, version 16.8 + 16.9
+/// * 1929: VS2019, version 16.10 + 16.11
+/// * 1930: VS2022, version 17.0
 #ifdef _MSC_VER
 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
 
-// We require at least MSVC 2017.
-#if !LLVM_MSC_PREREQ(1910)
-#error LLVM requires at least MSVC 2017.
+// We require at least VS 2019.
+#if !LLVM_MSC_PREREQ(1920)
+#error LLVM requires at least VS 2019.
 #endif
 
 #else
@@ -94,12 +103,8 @@
 /// Sadly, this is separate from just rvalue reference support because GCC
 /// and MSVC implemented this later than everything else. This appears to be
 /// corrected in MSVC 2019 but not MSVC 2017.
-#if __has_feature(cxx_rvalue_references) || defined(__GNUC__) ||   \
-LLVM_MSC_PREREQ(1920)
+/// FIXME: Remove LLVM_HAS_RVALUE_REFERENCE_THIS macro
 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
-#else
-#define LLVM_HAS_RVALUE_REFERENCE_THIS 0
-#endif
 
 /// Expands to '&' if ref-qualifiers for *this are supported.
 ///
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -65,7 +65,7 @@
 Changes to building LLVM
 
 
-* ...
+* Building LLVM with Visual Studio now requires version 2019 or later.
 
 Changes to TableGen
 ---
Index: llvm/docs/GettingStartedVS.rst
===
--- llvm/docs/GettingStartedVS.rst
+++ llvm/docs/GettingStartedVS.rst
@@ -36,7 +36,7 @@
 
 Hardware
 
-Any system that can adequately run Visual Studio 2017 is fine. The LLVM
+Any system that can adequately run Visual Studio 2019 is fine. The LLVM
 source tree including the git index consumes approximately 3GB.
 Object files, libraries and executables consume approximately 5GB in
 Release mode and much more in Debug mode. SSD drive and >16GB RAM are
@@ -45,13 +45,14 @@
 
 Software
 
-You will need `Visual Studio `_ 2017 or
-higher, with the latest Update installed. Visual Studio Community Edition
+You will need `Visual Studio `_ 2019 or
+later, with the latest Update installed. Visual Studio Community Edition
 suffices.
 
 You will also need the `CMake `_ build system since it
 generates the project files you will use to build with. CMake is bundled with
-Visual Studio 2019 so separate installation is not required.
+Visual Studio 2019 so separate installation is not required. If you do install
+CMake separately, Visual Studio 2022 will require CMake Version 3.21 or later.
 
 If you would like to run the LLVM tests you will need `Python
 `_. Version 3.6 and newer are known to work. You can
Index: llvm/docs/GettingStarted.rst
===
--- llvm/docs/GettingStarted.rst
+++ llvm/docs/GettingStarted.rst
@@ -238,7 +238,7 @@
 * Clang 3.5
 * Apple Clang 6.0
 * GCC 5.1
-* Visual Studio 2017
+* Visual Studio 2019
 
 Anything older than these toolchains *may* work, but will require forcing the
 build system with a special option and is not really a supported host platform.
@@ -273,8 +273,8 @@
 This section mostly applies to Linux and older BSDs. On macOS, you should
 have a sufficiently modern Xcode, or you will likely need to upgrade until you
 do. Windows does not have a "system compiler", so you must install either Visual
-Studio 2017 or a recent version of mingw64. FreeBSD 10.0 and newer have a modern
-Clang as the system compiler.
+Studio 2019 (or later), or a recent version of mingw64. FreeBSD 10.0 and newer
+have a modern Clang as the system compiler.
 
 However, some Linux distributions and some other or older BSDs sometimes have
 extremely old versions of GCC. These steps attempt to help you upgrade you
Index: llvm/docs/CMake

[Lldb-commits] [PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2022-01-28 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added inline comments.



Comment at: lldb/docs/resources/build.rst:296
 
-  $ cmake -G "Visual Studio 15 2017 Win64" -Thost=x64  
+  $ cmake -G "Visual Studio 16 2019" -A x64 -T host=x64 -Thost=x64  
 

You accidentally added `-T host=x64` twice now. It can be included with or 
without the space, but it's only needed once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

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


[Lldb-commits] [PATCH] D114639: Raise the minimum Visual Studio version to VS2019

2022-01-28 Thread Simon Pilgrim via Phabricator via lldb-commits
RKSimon updated this revision to Diff 404076.
RKSimon added a comment.

fix cut+paste typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114639

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/UsersManual.rst
  lldb/docs/resources/build.rst
  lldb/docs/resources/test.rst
  llvm/cmake/modules/CheckCompilerVersion.cmake
  llvm/docs/CMake.rst
  llvm/docs/GettingStarted.rst
  llvm/docs/GettingStartedVS.rst
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/Compiler.h

Index: llvm/include/llvm/Support/Compiler.h
===
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -77,12 +77,21 @@
 /// * 1916: VS2017, version 15.9
 /// * 1920: VS2019, version 16.0
 /// * 1921: VS2019, version 16.1
+/// * 1922: VS2019, version 16.2
+/// * 1923: VS2019, version 16.3
+/// * 1924: VS2019, version 16.4
+/// * 1925: VS2019, version 16.5
+/// * 1926: VS2019, version 16.6
+/// * 1927: VS2019, version 16.7
+/// * 1928: VS2019, version 16.8 + 16.9
+/// * 1929: VS2019, version 16.10 + 16.11
+/// * 1930: VS2022, version 17.0
 #ifdef _MSC_VER
 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
 
-// We require at least MSVC 2017.
-#if !LLVM_MSC_PREREQ(1910)
-#error LLVM requires at least MSVC 2017.
+// We require at least VS 2019.
+#if !LLVM_MSC_PREREQ(1920)
+#error LLVM requires at least VS 2019.
 #endif
 
 #else
@@ -94,12 +103,8 @@
 /// Sadly, this is separate from just rvalue reference support because GCC
 /// and MSVC implemented this later than everything else. This appears to be
 /// corrected in MSVC 2019 but not MSVC 2017.
-#if __has_feature(cxx_rvalue_references) || defined(__GNUC__) ||   \
-LLVM_MSC_PREREQ(1920)
+/// FIXME: Remove LLVM_HAS_RVALUE_REFERENCE_THIS macro
 #define LLVM_HAS_RVALUE_REFERENCE_THIS 1
-#else
-#define LLVM_HAS_RVALUE_REFERENCE_THIS 0
-#endif
 
 /// Expands to '&' if ref-qualifiers for *this are supported.
 ///
Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -65,7 +65,7 @@
 Changes to building LLVM
 
 
-* ...
+* Building LLVM with Visual Studio now requires version 2019 or later.
 
 Changes to TableGen
 ---
Index: llvm/docs/GettingStartedVS.rst
===
--- llvm/docs/GettingStartedVS.rst
+++ llvm/docs/GettingStartedVS.rst
@@ -36,7 +36,7 @@
 
 Hardware
 
-Any system that can adequately run Visual Studio 2017 is fine. The LLVM
+Any system that can adequately run Visual Studio 2019 is fine. The LLVM
 source tree including the git index consumes approximately 3GB.
 Object files, libraries and executables consume approximately 5GB in
 Release mode and much more in Debug mode. SSD drive and >16GB RAM are
@@ -45,13 +45,14 @@
 
 Software
 
-You will need `Visual Studio `_ 2017 or
-higher, with the latest Update installed. Visual Studio Community Edition
+You will need `Visual Studio `_ 2019 or
+later, with the latest Update installed. Visual Studio Community Edition
 suffices.
 
 You will also need the `CMake `_ build system since it
 generates the project files you will use to build with. CMake is bundled with
-Visual Studio 2019 so separate installation is not required.
+Visual Studio 2019 so separate installation is not required. If you do install
+CMake separately, Visual Studio 2022 will require CMake Version 3.21 or later.
 
 If you would like to run the LLVM tests you will need `Python
 `_. Version 3.6 and newer are known to work. You can
Index: llvm/docs/GettingStarted.rst
===
--- llvm/docs/GettingStarted.rst
+++ llvm/docs/GettingStarted.rst
@@ -238,7 +238,7 @@
 * Clang 3.5
 * Apple Clang 6.0
 * GCC 5.1
-* Visual Studio 2017
+* Visual Studio 2019
 
 Anything older than these toolchains *may* work, but will require forcing the
 build system with a special option and is not really a supported host platform.
@@ -273,8 +273,8 @@
 This section mostly applies to Linux and older BSDs. On macOS, you should
 have a sufficiently modern Xcode, or you will likely need to upgrade until you
 do. Windows does not have a "system compiler", so you must install either Visual
-Studio 2017 or a recent version of mingw64. FreeBSD 10.0 and newer have a modern
-Clang as the system compiler.
+Studio 2019 (or later), or a recent version of mingw64. FreeBSD 10.0 and newer
+have a modern Clang as the system compiler.
 
 However, some Linux distributions and some other or older BSDs sometimes have
 extremely old versions of GCC. These steps attempt to help you upgrade you
Index: llvm/docs/CMake.rst
==

[Lldb-commits] [lldb] 738d73f - [lldb] Update the lldb build instructions on Windows

2022-01-28 Thread Stella Stamenova via lldb-commits

Author: Stella Stamenova
Date: 2022-01-28T10:18:19-08:00
New Revision: 738d73fbf4edc1ae4e6fc2e40f734df267420420

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

LOG: [lldb] Update the lldb build instructions on Windows

The existing instructions for lldb on Windows can be more explicit. This adds a 
few details on how to install various components and the easiest way to get to 
a working build.

Reviewed By: JDevlieghere

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

Added: 


Modified: 
lldb/docs/resources/build.rst

Removed: 




diff  --git a/lldb/docs/resources/build.rst b/lldb/docs/resources/build.rst
index aadd57aedf882..c333134408f1d 100644
--- a/lldb/docs/resources/build.rst
+++ b/lldb/docs/resources/build.rst
@@ -92,24 +92,30 @@ Windows
 * `GnuWin32 `_ for CoreUtils and Make.
 * `Python 3 `_.  Make sure to (1) 
get
   the x64 variant if that's what you're targetting and (2) install the debug
-  library if you want to build a debug lldb.
+  library if you want to build a debug lldb. The standalone installer is the
+  easiest way to get the debug library.
 * `Python Tools for Visual Studio
-  `_. If you plan to debug test
-  failures or even write new tests at all, PTVS is an indispensable debugging
+  `_. If you plan to debug test failures
+  or even write new tests at all, PTVS is an indispensable debugging
   extension to VS that enables full editing and debugging support for Python
   (including mixed native/managed debugging).
+* `SWIG for Windows _`
 
 The steps outlined here describes how to set up your system and install the
 required dependencies such that they can be found when needed during the build
 process. They only need to be performed once.
 
-#. Install Visual Studio with the Windows SDK and ATL components.
+#. Install Visual Studio with the "Desktop Development with C++" workload and
+   the "Python Development" workload.
 #. Install GnuWin32, making sure ``\bin`` is added to
your PATH environment variable. Verify that utilities like ``dirname`` and
``make`` are available from your terminal.
 #. Install SWIG for Windows, making sure  is added to
your PATH environment variable. Verify that ``swig`` is available from your
terminal.
+#. Install Python 3 from the standalone installer and include the debug 
libraries
+   in the install, making sure the Python install path is added to your PATH
+   environment variable.
 #. Register the Debug Interface Access DLLs with the Registry from a privileged
terminal.
 
@@ -119,9 +125,10 @@ process. They only need to be performed once.
 > regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA 
 > SDK\bin\amd64\msdia140.dll"
 
 Any command prompt from which you build LLDB should have a valid Visual Studio
-environment setup. This means you should run ``vcvarsall.bat`` or open an
-appropriate Visual Studio Command Prompt corresponding to the version you wish
-to use.
+environment setup. This means you should open an appropriate `Developer Command
+Prompt for VS 
`_
+corresponding to the version you wish to use or run ``vcvarsall.bat`` or
+``VsDevCmd.bat``.
 
 macOS
 *



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


[Lldb-commits] [PATCH] D118425: [lldb] Update the lldb build instructions on Windows

2022-01-28 Thread Stella Stamenova via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG738d73fbf4ed: [lldb] Update the lldb build instructions on 
Windows (authored by stella.stamenova).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118425

Files:
  lldb/docs/resources/build.rst


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -92,24 +92,30 @@
 * `GnuWin32 `_ for CoreUtils and Make.
 * `Python 3 `_.  Make sure to (1) 
get
   the x64 variant if that's what you're targetting and (2) install the debug
-  library if you want to build a debug lldb.
+  library if you want to build a debug lldb. The standalone installer is the
+  easiest way to get the debug library.
 * `Python Tools for Visual Studio
-  `_. If you plan to debug test
-  failures or even write new tests at all, PTVS is an indispensable debugging
+  `_. If you plan to debug test failures
+  or even write new tests at all, PTVS is an indispensable debugging
   extension to VS that enables full editing and debugging support for Python
   (including mixed native/managed debugging).
+* `SWIG for Windows _`
 
 The steps outlined here describes how to set up your system and install the
 required dependencies such that they can be found when needed during the build
 process. They only need to be performed once.
 
-#. Install Visual Studio with the Windows SDK and ATL components.
+#. Install Visual Studio with the "Desktop Development with C++" workload and
+   the "Python Development" workload.
 #. Install GnuWin32, making sure ``\bin`` is added to
your PATH environment variable. Verify that utilities like ``dirname`` and
``make`` are available from your terminal.
 #. Install SWIG for Windows, making sure  is added to
your PATH environment variable. Verify that ``swig`` is available from your
terminal.
+#. Install Python 3 from the standalone installer and include the debug 
libraries
+   in the install, making sure the Python install path is added to your PATH
+   environment variable.
 #. Register the Debug Interface Access DLLs with the Registry from a privileged
terminal.
 
@@ -119,9 +125,10 @@
 > regsvr32 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\DIA 
 > SDK\bin\amd64\msdia140.dll"
 
 Any command prompt from which you build LLDB should have a valid Visual Studio
-environment setup. This means you should run ``vcvarsall.bat`` or open an
-appropriate Visual Studio Command Prompt corresponding to the version you wish
-to use.
+environment setup. This means you should open an appropriate `Developer Command
+Prompt for VS 
`_
+corresponding to the version you wish to use or run ``vcvarsall.bat`` or
+``VsDevCmd.bat``.
 
 macOS
 *


Index: lldb/docs/resources/build.rst
===
--- lldb/docs/resources/build.rst
+++ lldb/docs/resources/build.rst
@@ -92,24 +92,30 @@
 * `GnuWin32 `_ for CoreUtils and Make.
 * `Python 3 `_.  Make sure to (1) get
   the x64 variant if that's what you're targetting and (2) install the debug
-  library if you want to build a debug lldb.
+  library if you want to build a debug lldb. The standalone installer is the
+  easiest way to get the debug library.
 * `Python Tools for Visual Studio
-  `_. If you plan to debug test
-  failures or even write new tests at all, PTVS is an indispensable debugging
+  `_. If you plan to debug test failures
+  or even write new tests at all, PTVS is an indispensable debugging
   extension to VS that enables full editing and debugging support for Python
   (including mixed native/managed debugging).
+* `SWIG for Windows _`
 
 The steps outlined here describes how to set up your system and install the
 required dependencies such that they can be found when needed during the build
 process. They only need to be performed once.
 
-#. Install Visual Studio with the Windows SDK and ATL components.
+#. Install Visual Studio with the "Desktop Development with C++" workload and
+   the "Python Development" workload.
 #. Install GnuWin32, making sure ``\bin`` is added to
your PATH environment variable. Verify that utilities like ``dirname`` and
``make`` are available from your terminal.
 #. Install SWIG for Windows, making sure  is added to
your PATH environment variable. Verify that ``swig`` is

[Lldb-commits] [PATCH] D118494: [lldb] Observe SG_READ_ONLY flag in MachO binaries

2022-01-28 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: aprantl, augusto2112.
kastiglione requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

Change `Section::GetPermissions()` to indicate non-writability when the Mach-O
segment has the `SG_READ_ONLY` flag.

MachO has a segment flag named `SG_READ_ONLY` which indicates that the segment
is semantically read-only, even if its permissions are marked writable.
Segments such as `__DATA_CONST` contain data that is semantically "const", but
needs to be writable for dyld to perform fixups (bindings or rebases).

The header documentation for `SG_READ_ONLY` states:

> This segment is made read-only after fixups.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118494

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  llvm/include/llvm/BinaryFormat/MachO.h


Index: llvm/include/llvm/BinaryFormat/MachO.h
===
--- llvm/include/llvm/BinaryFormat/MachO.h
+++ llvm/include/llvm/BinaryFormat/MachO.h
@@ -106,6 +106,7 @@
   SG_FVMLIB = 0x2u,
   SG_NORELOC = 0x4u,
   SG_PROTECTED_VERSION_1 = 0x8u,
+  SG_READ_ONLY = 0x10u,
 
   // Constant masks for the "flags" field in llvm::MachO::section and
   // llvm::MachO::section_64
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1433,7 +1433,7 @@
   uint32_t result = 0;
   if (seg_cmd.initprot & VM_PROT_READ)
 result |= ePermissionsReadable;
-  if (seg_cmd.initprot & VM_PROT_WRITE)
+  if ((seg_cmd.initprot & VM_PROT_WRITE) && !(seg_cmd.flags & SG_READ_ONLY))
 result |= ePermissionsWritable;
   if (seg_cmd.initprot & VM_PROT_EXECUTE)
 result |= ePermissionsExecutable;


Index: llvm/include/llvm/BinaryFormat/MachO.h
===
--- llvm/include/llvm/BinaryFormat/MachO.h
+++ llvm/include/llvm/BinaryFormat/MachO.h
@@ -106,6 +106,7 @@
   SG_FVMLIB = 0x2u,
   SG_NORELOC = 0x4u,
   SG_PROTECTED_VERSION_1 = 0x8u,
+  SG_READ_ONLY = 0x10u,
 
   // Constant masks for the "flags" field in llvm::MachO::section and
   // llvm::MachO::section_64
Index: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
===
--- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1433,7 +1433,7 @@
   uint32_t result = 0;
   if (seg_cmd.initprot & VM_PROT_READ)
 result |= ePermissionsReadable;
-  if (seg_cmd.initprot & VM_PROT_WRITE)
+  if ((seg_cmd.initprot & VM_PROT_WRITE) && !(seg_cmd.flags & SG_READ_ONLY))
 result |= ePermissionsWritable;
   if (seg_cmd.initprot & VM_PROT_EXECUTE)
 result |= ePermissionsExecutable;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/examples/python/scripted_process/scripted_process.py:323-344
+{'name': 'rax', 'bitsize': 64, 'offset': 0, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 0, 'dwarf': 0},
+{'name': 'rbx', 'bitsize': 64, 'offset': 8, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 3, 'dwarf': 3},
+{'name': 'rcx', 'bitsize': 64, 'offset': 16, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 2, 'dwarf': 2, 'generic': 'arg4', 
'alt-name': 'arg4'},
+{'name': 'rdx', 'bitsize': 64, 'offset': 24, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 1, 'dwarf': 1, 'generic': 'arg3', 
'alt-name': 'arg3'},
+{'name': 'rdi', 'bitsize': 64, 'offset': 32, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 5, 'dwarf': 5, 'generic': 'arg1', 
'alt-name': 'arg1'},
+{'name': 'rsi', 'bitsize': 64, 'offset': 40, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 4, 'dwarf': 4, 'generic': 'arg2', 
'alt-name': 'arg2'},
+{'name': 'rbp', 'bitsize': 64, 'offset': 48, 'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 6, 'dwarf': 6, 'generic': 'fp', 
'alt-name': 'fp'},

Since you're already modifying these lines, maybe it's worth moving this into a 
constant. That'll make the class itself a lot more readable. 



Comment at: 
lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py:57
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }

What's the motivation from switching from SIGINT to SIGTRAP?



Comment at: 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py:128-137
+selected_thread_idx = 
self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = 
self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal

Can you remind me why we can't read this information from the thread in the 
core file? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118484

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


[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked 2 inline comments as done.
mib added inline comments.



Comment at: 
lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py:57
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }

JDevlieghere wrote:
> What's the motivation from switching from SIGINT to SIGTRAP?
I don't think this is very important, but reporting it as a SIGTRAP is more in 
line with what debugserver does for breakpoints.



Comment at: 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py:128-137
+selected_thread_idx = 
self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = 
self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal

JDevlieghere wrote:
> Can you remind me why we can't read this information from the thread in the 
> core file? 
Besides on arm, we don't save any breakpoint info in the core file, so all of 
the core file threads reports a `eStopReasonNone`. So when I try to emulate the 
core file process from a Scripted Process, the scripted process never stops 
because none of its threads has a stop reason. That's why we have to fake a 
SIGTRAP for x86_64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118484

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


[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add ScriptedProcessInterface::GetSelectedThreadIndex method

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404107.
mib marked 2 inline comments as done.
mib added a comment.

Address @shafik feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118482

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -57,6 +57,9 @@
 
 return data
 
+def get_selected_thread_index(self):
+return 3
+
 def get_loaded_images(self):
 # TODO: Iterate over corefile_target modules and build a data structure
 # from it.
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -44,6 +44,8 @@
 
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
+  uint32_t GetSelectedThreadIndex() override;
+
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
 
   lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -113,6 +113,21 @@
   return dict;
 }
 
+uint32_t ScriptedProcessPythonInterface::GetSelectedThreadIndex() {
+  Status error;
+  StructuredData::ObjectSP obj = Dispatch("get_selected_thread_index", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
+return LLDB_INVALID_INDEX32;
+
+  const uint64_t val = obj->GetIntegerValue(LLDB_INVALID_INDEX32);
+
+  if (!val || std::numeric_limits::max() <= val)
+return LLDB_INVALID_INDEX32;
+
+  return static_cast(val);
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) {
   // TODO: Implement
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -359,6 +359,11 @@
 void ScriptedProcess::RefreshStateAfterStop() {
   // Let all threads recover from stopping and do any clean up based on the
   // previous thread state (if any).
+  const uint32_t selected_thread_idx = GetInterface().GetSelectedThreadIndex();
+
+  if (selected_thread_idx != LLDB_INVALID_INDEX32 &&
+  selected_thread_idx <= m_thread_list.GetSize())
+m_thread_list.SetSelectedThreadByIndexID(selected_thread_idx);
 }
 
 bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -48,6 +48,8 @@
 return nullptr;
   }
 
+  virtual uint32_t GetSelectedThreadIndex() { return LLDB_INVALID_INDEX32; }
+
   virtual StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) {
 return nullptr;
   }
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -76,6 +76,15 @@
 """
 pass
 
+def get_selected_thread_index(self):
+""" Get the index of the selected scripted process thread.
+
+Returns:
+Int: The thread index that should be selected by lldb.
+ (default: 0)
+"""
+return 0
+
 @abstractmethod
 def get_registers_for_thread(self, tid):
 """ Get the register context dictionary for a certain thread of
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404117.
mib marked 3 inline comments as done.
mib added a comment.

Address @JDevlieghere comments


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

https://reviews.llvm.org/D118484

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -122,17 +122,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
-
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.corefile_thread and self.corefile_thread.IsValid():
+stop_reason["type"] = lldb.eStopReasonNone
+
+selected_thread_idx = self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -32,8 +32,12 @@
 """
 self.target = None
 self.args = None
+self.arch = None
 if isinstance(target, lldb.SBTarget) and target.IsValid():
 self.target = target
+triple = self.target.triple
+if triple:
+self.arch = triple.split('-')[0]
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -210,19 +214,21 @@
 """
 
 @abstractmethod
-def __init__(self, process, args):
+def __init__(self, scripted_process, args):
 """ Construct a scripted thread.
 
 Args:
-process (lldb.SBProcess): The scripted process owning this thread.
+process (ScriptedProcess): The scripted process owning this thread.
 args (lldb.SBStructuredData): A Dictionary holding arbitrary
 key/value pairs used by the scripted thread.
 """
 self.target = None
+self.scripted_process = None
 self.process = None
 self.args = None
-if isinstance(process, ScriptedProcess):
-self.target = process.target
+if isinstance(scripted_process, ScriptedProcess):
+self.target = scripted_process.target
+self.scripted_process = scripted_process
 self.process = self.target.GetProcess()
 
 self.id = None
@@ -311,73 +317,13 @@
 def get_register_info(self):
 if self.register_info is None:
 self.register_info = dict()
-triple = self.target.triple
-if triple:
-arch = triple.split('-')[0]
-if arch == 'x86_64':
-self.regist

[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404128.
mib added a comment.

Re-enabling a test function for intel.


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

https://reviews.llvm.org/D118484

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -122,17 +122,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
-
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.corefile_thread and self.corefile_thread.IsValid():
+stop_reason["type"] = lldb.eStopReasonNone
+
+selected_thread_idx = self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -142,7 +142,6 @@
 self.assertTrue(self.dbg.DeleteTarget(target), "Couldn't delete target")
 
 @skipUnlessDarwin
-@skipIf(archs=no_match(['arm64', 'arm64e']))
 @skipIfOutOfTreeDebugserver
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -32,8 +32,12 @@
 """
 self.target = None
 self.args = None
+self.arch = None
 if isinstance(target, lldb.SBTarget) and target.IsValid():
 self.target = target
+triple = self.target.triple
+if triple:
+self.arch = triple.split('-')[0]
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -210,19 +214,21 @@
 """
 
 @abstractmethod
-def __init__(self, process, args):
+def __init__(self, scripted_process, args):
 """ Construct a scripted thread.
 
 Args:
-process (lldb.SBProcess): The scripted process owning this thread.
+process (ScriptedProcess): The scripted process owning this thread.
 args (lldb.SBStructuredData): A Dictionary holding arbitrary
 key/value pairs used by the scripted thread.
 """
 self.target = None
+self.scripted_process = None
 self.process = No

[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 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 the test comment.




Comment at: lldb/examples/python/scripted_process/scripted_process.py:338
+
+ARM64_GPR = [ {'name': 'x0',   'bitsize': 64, 'offset': 0,   'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 0,  'dwarf': 0,  'generic': 'arg0', 
'alt-name': 'arg0'},
+  {'name': 'x1',   'bitsize': 64, 'offset': 8,   'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 1,  'dwarf': 1,  'generic': 'arg1', 
'alt-name': 'arg1'},

Generally constants go at the top of the file, but this is rather bulky, so I 
don't mind it being at the bottom. 



Comment at: 
lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py:128-137
+selected_thread_idx = 
self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = 
self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal

mib wrote:
> JDevlieghere wrote:
> > Can you remind me why we can't read this information from the thread in the 
> > core file? 
> Besides on arm, we don't save any breakpoint info in the core file, so all of 
> the core file threads reports a `eStopReasonNone`. So when I try to emulate 
> the core file process from a Scripted Process, the scripted process never 
> stops because none of its threads has a stop reason. That's why we have to 
> fake a SIGTRAP for x86_64.
That sounds like something worth mentioning as a comment in the test. 


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

https://reviews.llvm.org/D118484

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


[Lldb-commits] [PATCH] D118494: [lldb] Observe SG_READ_ONLY flag in MachO binaries

2022-01-28 Thread Augusto Noronha via Phabricator via lldb-commits
augusto2112 requested changes to this revision.
augusto2112 added inline comments.
This revision now requires changes to proceed.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1436
 result |= ePermissionsReadable;
-  if (seg_cmd.initprot & VM_PROT_WRITE)
+  if ((seg_cmd.initprot & VM_PROT_WRITE) && !(seg_cmd.flags & SG_READ_ONLY))
 result |= ePermissionsWritable;

Could we add a new value in the enumeration? Something like 
ePermissionsLinkerWritable? As it is right now this would be dangerous for the 
existing file-cache optimization as we'd happily read pointers that are 
supposed to be fixed by the linker from the file-cache.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118494

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


[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404142.
mib marked 2 inline comments as done.
mib added a comment.

Add stop reason type test and comment explaining why it's different depending 
on the architecture.


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

https://reviews.llvm.org/D118484

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -122,17 +122,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
-
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.corefile_thread and self.corefile_thread.IsValid():
+stop_reason["type"] = lldb.eStopReasonNone
+
+selected_thread_idx = self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -142,7 +142,6 @@
 self.assertTrue(self.dbg.DeleteTarget(target), "Couldn't delete target")
 
 @skipUnlessDarwin
-@skipIf(archs=no_match(['arm64', 'arm64e']))
 @skipIfOutOfTreeDebugserver
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -32,8 +32,12 @@
 """
 self.target = None
 self.args = None
+self.arch = None
 if isinstance(target, lldb.SBTarget) and target.IsValid():
 self.target = target
+triple = self.target.triple
+if triple:
+self.arch = triple.split('-')[0]
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -210,19 +214,21 @@
 """
 
 @abstractmethod
-def __init__(self, process, args):
+def __init__(self, scripted_process, args):
 """ Construct a scripted thread.
 
 Args:
-process (lldb.SBProcess): The scripted process owning this thread.
+process (ScriptedProcess): The scripted process owning this thread.
 args (lldb.SBStructuredData): A Dictionary holding arbitrary
 key/value pairs used by the scripted thread.
  

[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 404147.

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

https://reviews.llvm.org/D118484

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -122,17 +122,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
-
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.corefile_thread and self.corefile_thread.IsValid():
+stop_reason["type"] = lldb.eStopReasonNone
+
+selected_thread_idx = self.scripted_process.get_selected_thread_index()
+if selected_thread_idx == self.corefile_thread.GetIndexID():
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -142,7 +142,6 @@
 self.assertTrue(self.dbg.DeleteTarget(target), "Couldn't delete target")
 
 @skipUnlessDarwin
-@skipIf(archs=no_match(['arm64', 'arm64e']))
 @skipIfOutOfTreeDebugserver
 def test_launch_scripted_process_stack_frames(self):
 """Test that we can launch an lldb scripted process from the command
@@ -196,6 +195,22 @@
 self.assertTrue(thread, "Invalid thread.")
 self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
+self.assertTrue(target.triple, "Invalid target triple")
+arch = target.triple.split('-')[0]
+supported_arch = ['x86_64', 'arm64', 'arm64e']
+self.assertIn(arch, supported_arch)
+# When creating a corefile of a arm process, lldb saves the exception
+# that triggers the breakpoint in the LC_NOTES of the corefile, so they
+# can be reloaded with the corefile on the next debug session.
+if arch in 'arm64e':
+self.assertTrue(thread.GetStopReason(), lldb.eStopReasonException)
+# However, it's architecture specific, and corefiles made from intel
+# process don't save any metadata to retrieve to stop reason.
+# To mitigate this, the StackCoreScriptedProcess will report a
+# eStopReasonSignal with a SIGTRAP, mimicking what debugserver does.
+else:
+self.assertTrue(thread.GetStopReason(), lldb.eStopReasonSignal)
+
 self.assertEqual(thread.GetNumFrames(), 6)
 frame = thread.GetSelectedFrame()
 self.assertTrue(frame, "Invalid frame.")
Index: lldb/examples/python/scripted_process/scripted_process.py
==

[Lldb-commits] [PATCH] D118484: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a subscriber: jingham.
mib added inline comments.



Comment at: lldb/examples/python/scripted_process/scripted_process.py:338
+
+ARM64_GPR = [ {'name': 'x0',   'bitsize': 64, 'offset': 0,   'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 0,  'dwarf': 0,  'generic': 'arg0', 
'alt-name': 'arg0'},
+  {'name': 'x1',   'bitsize': 64, 'offset': 8,   'encoding': 
'uint', 'format': 'hex', 'set': 0, 'gcc': 1,  'dwarf': 1,  'generic': 'arg1', 
'alt-name': 'arg1'},

JDevlieghere wrote:
> Generally constants go at the top of the file, but this is rather bulky, so I 
> don't mind it being at the bottom. 
Felt the same, so I put it here.



Comment at: 
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py:202-212
+# When creating a corefile of a arm process, lldb saves the exception
+# that triggers the breakpoint in the LC_NOTES of the corefile, so they
+# can be reloaded with the corefile on the next debug session.
+if arch in 'arm64e':
+self.assertTrue(thread.GetStopReason(), lldb.eStopReasonException)
+# However, it's architecture specific, and corefiles made from intel
+# process don't save any metadata to retrieve to stop reason.

@jingham This is also another reason why D118482 is "necessary":

On intel, the corefile threads all report an `eStopReasonNone`, so having a 
python `lldb.ScriptedProcess.get_selected_thread_index` allows me to create the 
signal stop reason, otherwise, all of the scripted process threads report 
`eStopReasonNone` and the process runs forever.


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

https://reviews.llvm.org/D118484

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


[Lldb-commits] [PATCH] D118513: [lldb/test] Split Scripted Process test in multiple tests (NFC)

2022-01-28 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: aprantl, JDevlieghere.
mib added a project: LLDB.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This splits the scripted process tests to be able to run in parallel
since some of test functions can take a very long time to run.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118513

Files:
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py

Index: lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
===
--- /dev/null
+++ lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -0,0 +1,108 @@
+"""
+Test python scripted process in lldb
+"""
+
+import os, json, tempfile
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+from lldbsuite.test import lldbtest
+
+class StackCoreScriptedProcesTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def setUp(self):
+TestBase.setUp(self)
+
+def tearDown(self):
+TestBase.tearDown(self)
+
+def create_stack_skinny_corefile(self, file):
+self.build()
+target, process, thread, _ = lldbutil.run_to_source_breakpoint(self, "// break here",
+   lldb.SBFileSpec("main.cpp"))
+self.assertTrue(process.IsValid(), "Process is invalid.")
+# FIXME: Use SBAPI to save the process corefile.
+self.runCmd("process save-core -s stack  " + file)
+self.assertTrue(os.path.exists(file), "No stack-only corefile found.")
+self.assertTrue(self.dbg.DeleteTarget(target), "Couldn't delete target")
+
+@skipUnlessDarwin
+@skipIfOutOfTreeDebugserver
+def test_launch_scripted_process_stack_frames(self):
+"""Test that we can launch an lldb scripted process from the command
+line, check its process ID and read string from memory."""
+self.build()
+target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
+self.assertTrue(target, VALID_TARGET)
+
+for module in target.modules:
+if 'a.out' in module.GetFileSpec().GetFilename():
+main_module = module
+break
+
+self.assertTrue(main_module, "Invalid main module.")
+error = target.SetModuleLoadAddress(main_module, 0)
+self.assertTrue(error.Success(), "Reloading main module at offset 0 failed.")
+
+os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
+def cleanup():
+  del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"]
+self.addTearDownHook(cleanup)
+
+scripted_process_example_relpath = 'stack_core_scripted_process.py'
+self.runCmd("command script import " + os.path.join(self.getSourceDir(),
+scripted_process_example_relpath))
+
+corefile_process = None
+with tempfile.NamedTemporaryFile() as file:
+self.create_stack_skinny_corefile(file.name)
+corefile_target = self.dbg.CreateTarget(None)
+corefile_process = corefile_target.LoadCore(self.getBuildArtifact(file.name))
+self.assertTrue(corefile_process, PROCESS_IS_VALID)
+
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(json.dumps({
+"backing_target_idx" : self.dbg.GetIndexOfTarget(corefile_process.GetTarget())
+}))
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetProcessPluginName("ScriptedProcess")
+launch_info.SetScriptedProcessClassName("stack_core_scripted_process.StackCoreScriptedProcess")
+launch_info.SetScriptedProcessDictionary(structured_data)
+
+error = lldb.SBError()
+process = target.Launch(launch_info, error)
+self.assertTrue(error.Success(), error.GetCString())
+self.assertTrue(process, PROCESS_IS_VALID)
+self.assertEqual(process.GetProcessID(), 42)
+
+self.assertEqual(process.GetNumThreads(), 3)
+thread = process.GetSelectedThread()
+self.assertTrue(thread, "Invalid thread.")
+self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
+
+self.assertTrue(target.triple, "Invalid target triple")
+arch = target.triple.split('-')[0]
+supported_arch = ['x86_64', 'arm64', 'arm64e']
+self.assertIn(arch, supported_arch)
+# When creating a corefile of a arm process, lldb saves the exception
+# that triggers the breakpoint in the LC_NOTES of the corefile, so they
+# can be reloaded with the corefile on the next debug session.
+if arch in 'arm64e':
+self.assertTrue(thread.GetStop

[Lldb-commits] [PATCH] D118494: [lldb] Observe SG_READ_ONLY flag in MachO binaries

2022-01-28 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added inline comments.



Comment at: lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp:1436
 result |= ePermissionsReadable;
-  if (seg_cmd.initprot & VM_PROT_WRITE)
+  if ((seg_cmd.initprot & VM_PROT_WRITE) && !(seg_cmd.flags & SG_READ_ONLY))
 result |= ePermissionsWritable;

augusto2112 wrote:
> Could we add a new value in the enumeration? Something like 
> ePermissionsLinkerWritable? As it is right now this would be dangerous for 
> the existing file-cache optimization as we'd happily read pointers that are 
> supposed to be fixed by the linker from the file-cache.
That works for me. I think we'd want `ePermissionsLoaderWritable`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118494

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


[Lldb-commits] [PATCH] D78801: [LLDB] Add class WasmProcess for WebAssembly debugging

2022-01-28 Thread Xu Jun via Phabricator via lldb-commits
xujuntwt95329 added a comment.

In D78801#3279811 , @paolosev wrote:

> Thanks @xujuntwt95329! I am very happy that this was useful for WebAssembly 
> Micro Runtime!

I believe we are making the world of WebAssembly better!

BTW, I find an issue when trying to debug multi-thread wasm app:
The `qWasmLocal` package doesn't contain the thread id, which means it can only 
get locals of the current thread. If we have thread A, B and C, and they 
stopped at the same time, then LLDB will send three `qWasmLocal` package, and 
the wasm runtime will give same reply.

I think we should add thread id into `qWasmLocal` so that wasm runtime will 
know which thread to process, Am I right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78801

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