[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-24 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

Could you try replacing the new function with the old one and seeing if that 
helps? Or alternatively, trying to build a kernel from the commit just before 
that change and with that change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117928

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


[Lldb-commits] [lldb] 7d19566 - [lldb] Ignore non-address bits in "memory find" arguments

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

Author: David Spickett
Date: 2022-01-24T10:42:49Z
New Revision: 7d19566c3bfb3efacb629d18839e2d85761156ab

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

LOG: [lldb] Ignore non-address bits in "memory find" arguments

This removes the non-address bits before we try to use
the addresses.

Meaning that when results are shown, those results won't
show non-address bits either. This follows what "memory read"
has done. On the grounds that non-address bits are a property
of a pointer, not the memory pointed to.

I've added testing and merged the find and read tests into one
file.

Note that there are no API side changes because "memory find"
does not have an equivalent API call.

Reviewed By: omjavaid

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

Added: 
lldb/test/API/linux/aarch64/tagged_memory_access/Makefile

lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
lldb/test/API/linux/aarch64/tagged_memory_access/main.c

Modified: 
lldb/source/Commands/CommandObjectMemory.cpp

Removed: 
lldb/test/API/linux/aarch64/tagged_memory_read/Makefile

lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
lldb/test/API/linux/aarch64/tagged_memory_read/main.c



diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index 0b5f39bc7a8f4..f5e2cb4ed44ea 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1032,6 +1032,12 @@ class CommandObjectMemoryFind : public 
CommandObjectParsed {
   return false;
 }
 
+ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+if (abi) {
+  low_addr = abi->FixDataAddress(low_addr);
+  high_addr = abi->FixDataAddress(high_addr);
+}
+
 if (high_addr <= low_addr) {
   result.AppendError(
   "starting address must be smaller than ending address");

diff  --git a/lldb/test/API/linux/aarch64/tagged_memory_read/Makefile 
b/lldb/test/API/linux/aarch64/tagged_memory_access/Makefile
similarity index 100%
rename from lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
rename to lldb/test/API/linux/aarch64/tagged_memory_access/Makefile

diff  --git 
a/lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
 
b/lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
similarity index 62%
rename from 
lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
rename to 
lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
index 2f55b951a7548..3cc0d70a3ce34 100644
--- 
a/lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
+++ 
b/lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
@@ -1,6 +1,9 @@
 """
-Test that "memory read" removes non address bits from
-memory read arguments.
+Test that "memory read" and "memory find" remove non address bits from
+address arguments.
+
+These tests use the top byte ignore feature of AArch64. Which Linux
+always enables.
 """
 
 
@@ -17,10 +20,7 @@ class AArch64LinuxTaggedMemoryReadTestCase(TestBase):
 
 NO_DEBUG_INFO_TESTCASE = True
 
-# AArch64 Linux always enables top byte ignore
-@skipUnlessArch("aarch64")
-@skipUnlessPlatform(["linux"])
-def test_tagged_memory_read(self):
+def setup_test(self):
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
 
@@ -37,6 +37,11 @@ def test_tagged_memory_read(self):
 substrs=['stopped',
  'stop reason = breakpoint'])
 
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_read(self):
+self.setup_test()
+
 # If we do not remove non address bits, this can fail in two ways.
 # 1. We attempt to read much more than 16 bytes, probably more than
 #the default 1024 byte read size. Which will error.
@@ -53,3 +58,26 @@ def test_tagged_memory_read(self):
 # Would fail if we don't remove non address bits because 0x56... > 
0x34...
 self.expect("memory read ptr2 ptr1+16", 
patterns=[tagged_addr_pattern], matching=False)
 self.expect("memory read", patterns=[tagged_addr_pattern], 
matching=False)
+
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_find(self):
+self.setup_test()
+
+# If memory find doesn't remove non-address bits one of two
+# things happen.
+# 1. It tries to search a gigantic amount of memory.
+#We're not going to test for this because a failure
+#would take a very long t

[Lldb-commits] [PATCH] D117299: [lldb] Ignore non-address bits in "memory find" arguments

2022-01-24 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d19566c3bfb: [lldb] Ignore non-address bits in "memory 
find" arguments (authored by DavidSpickett).

Changed prior to commit:
  https://reviews.llvm.org/D117299?vs=401904&id=402441#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117299

Files:
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/test/API/linux/aarch64/tagged_memory_access/Makefile
  
lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
  lldb/test/API/linux/aarch64/tagged_memory_access/main.c
  lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
  
lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
  lldb/test/API/linux/aarch64/tagged_memory_read/main.c

Index: lldb/test/API/linux/aarch64/tagged_memory_access/main.c
===
--- lldb/test/API/linux/aarch64/tagged_memory_access/main.c
+++ lldb/test/API/linux/aarch64/tagged_memory_access/main.c
@@ -5,11 +5,15 @@
   return (char *)((size_t)ptr | (tag << 56));
 }
 
-int main(int argc, char const *argv[]) {
-  char buf[32];
+// Global to zero init
+char buf[32];
 
+int main(int argc, char const *argv[]) {
   char *ptr1 = set_non_address_bits(buf, 0x34);
   char *ptr2 = set_non_address_bits(buf, 0x56);
 
+  // Target value for "memory find"
+  buf[15] = '?';
+
   return 0; // Set break point at this line.
 }
Index: lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
===
--- lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
+++ lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py
@@ -1,6 +1,9 @@
 """
-Test that "memory read" removes non address bits from
-memory read arguments.
+Test that "memory read" and "memory find" remove non address bits from
+address arguments.
+
+These tests use the top byte ignore feature of AArch64. Which Linux
+always enables.
 """
 
 
@@ -17,10 +20,7 @@
 
 NO_DEBUG_INFO_TESTCASE = True
 
-# AArch64 Linux always enables top byte ignore
-@skipUnlessArch("aarch64")
-@skipUnlessPlatform(["linux"])
-def test_tagged_memory_read(self):
+def setup_test(self):
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 
@@ -37,6 +37,11 @@
 substrs=['stopped',
  'stop reason = breakpoint'])
 
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_read(self):
+self.setup_test()
+
 # If we do not remove non address bits, this can fail in two ways.
 # 1. We attempt to read much more than 16 bytes, probably more than
 #the default 1024 byte read size. Which will error.
@@ -53,3 +58,26 @@
 # Would fail if we don't remove non address bits because 0x56... > 0x34...
 self.expect("memory read ptr2 ptr1+16", patterns=[tagged_addr_pattern], matching=False)
 self.expect("memory read", patterns=[tagged_addr_pattern], matching=False)
+
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_find(self):
+self.setup_test()
+
+# If memory find doesn't remove non-address bits one of two
+# things happen.
+# 1. It tries to search a gigantic amount of memory.
+#We're not going to test for this because a failure
+#would take a very long time and perhaps even find the
+#target value randomly.
+# 2. It thinks high address <= low address, which we check below.
+
+self.runCmd("memory find -s '?' ptr2 ptr1+32")
+
+self.assertTrue(self.res.Succeeded())
+out = self.res.GetOutput()
+# memory find does not fail when it doesn't find the data.
+# First check we actually got something.
+self.assertRegexpMatches(out, "data found at location: 0x[0-9A-Fa-f]+")
+# Then that the location found does not display the tag bits.
+self.assertNotRegexpMatches(out, "data found at location: 0x(34|56)[0-9A-Fa-f]+")
Index: lldb/source/Commands/CommandObjectMemory.cpp
===
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -1032,6 +1032,12 @@
   return false;
 }
 
+ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+if (abi) {
+  low_addr = abi->FixDataAddress(low_addr);
+  high_addr = abi->FixDataAddress(high_addr);
+}
+
 if (high_addr <= low_addr) {
   result.AppendError(
   "starting address must be smaller than ending address");
___
lldb-commits mailing list
lldb-commits@li

[Lldb-commits] [lldb] 5f290c0 - Move STLFunctionalExtras out of STLExtras

2022-01-24 Thread via lldb-commits

Author: serge-sans-paille
Date: 2022-01-24T14:13:21+01:00
New Revision: 5f290c090a2404238a5b0ae4233f3ae9daec319e

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

LOG: Move STLFunctionalExtras out of STLExtras

Only using that change in StringRef already decreases the number of
preoprocessed lines from 7837621 to 7776151 for LLVMSupport

Perhaps more interestingly, it shows that many files were relying on the
inclusion of StringRef.h to have the declaration from STLExtras.h. This
patch tries hard to patch relevant part of llvm-project impacted by this
hidden dependency removal.

Potential impact:
- "llvm/ADT/StringRef.h" no longer includes ,
  "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h"

Related Discourse thread:
https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831

Added: 
llvm/include/llvm/ADT/STLFunctionalExtras.h
llvm/include/llvm/ADT/identity.h

Modified: 
clang/include/clang/Basic/DirectoryEntry.h
clang/tools/diagtool/DiagTool.cpp
lld/ELF/Relocations.h
lldb/include/lldb/Utility/UserIDResolver.h
llvm/include/llvm/ADT/CombinationGenerator.h
llvm/include/llvm/ADT/STLExtras.h
llvm/include/llvm/ADT/SmallSet.h
llvm/include/llvm/ADT/SparseMultiSet.h
llvm/include/llvm/ADT/SparseSet.h
llvm/include/llvm/ADT/StringMap.h
llvm/include/llvm/ADT/StringMapEntry.h
llvm/include/llvm/ADT/StringRef.h
llvm/include/llvm/ADT/StringSwitch.h
llvm/include/llvm/ExecutionEngine/JITLink/MemoryFlags.h
llvm/include/llvm/IR/LLVMContext.h
llvm/include/llvm/MC/SubtargetFeature.h
llvm/include/llvm/Support/CrashRecoveryContext.h
llvm/include/llvm/Support/JSON.h
llvm/include/llvm/Support/TimeProfiler.h
llvm/include/llvm/Support/Timer.h
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/include/llvm/Support/raw_ostream.h
llvm/include/llvm/Testing/Support/Annotations.h
llvm/lib/CodeGen/NonRelocatableStringpool.cpp
llvm/lib/Support/CommandLine.cpp
llvm/lib/Support/StringRef.cpp
llvm/lib/Support/TimeProfiler.cpp
llvm/lib/Target/AMDGPU/AMDGPULibFunc.h
llvm/unittests/ADT/SequenceTest.cpp
llvm/unittests/ADT/SimpleIListTest.cpp
llvm/unittests/ADT/SmallPtrSetTest.cpp
llvm/unittests/ADT/StringMapTest.cpp
llvm/unittests/ADT/StringSetTest.cpp
llvm/unittests/Support/ReverseIterationTest.cpp
mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h
mlir/lib/Parser/Token.h

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index edb8031a20b80..ac8e790230fcc 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -19,6 +19,7 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorOr.h"
 
 namespace clang {

diff  --git a/clang/tools/diagtool/DiagTool.cpp 
b/clang/tools/diagtool/DiagTool.cpp
index 81d4e7e44..99abe5755f713 100644
--- a/clang/tools/diagtool/DiagTool.cpp
+++ b/clang/tools/diagtool/DiagTool.cpp
@@ -12,6 +12,7 @@
 
 #include "DiagTool.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include 
 
 using namespace diagtool;

diff  --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h
index f9909f236d12e..73f6970b80f13 100644
--- a/lld/ELF/Relocations.h
+++ b/lld/ELF/Relocations.h
@@ -11,6 +11,7 @@
 
 #include "lld/Common/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
 #include 
 #include 
 

diff  --git a/lldb/include/lldb/Utility/UserIDResolver.h 
b/lldb/include/lldb/Utility/UserIDResolver.h
index e0f7b69cc075f..15afafd65a1aa 100644
--- a/lldb/include/lldb/Utility/UserIDResolver.h
+++ b/lldb/include/lldb/Utility/UserIDResolver.h
@@ -10,6 +10,7 @@
 #define LLDB_UTILITY_USERIDRESOLVER_H
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include 
 

diff  --git a/llvm/include/llvm/ADT/CombinationGenerator.h 
b/llvm/include/llvm/ADT/CombinationGenerator.h
index ab6afd555726d..a0bec68eaad60 100644
--- a/llvm/include/llvm/ADT/CombinationGenerator.h
+++ b/llvm/include/llvm/ADT/CombinationGenerator.h
@@ -28,7 +28,7 @@
 #define LLVM_ADT_COMBINATIONGENERATOR_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include 
 #include 

diff  --git a/llvm/include/llvm/ADT/STLExtras.h 
b/llvm/include/llvm/ADT/STLExtras.h
index ed5321821a3a2..c3200c9265182 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -16,8 +16,10 @@
 #ifndef LLVM_ADT_STLEXTRAS_H
 #define LLVM_ADT_STLEXTRAS_H
 
+#include "llvm/ADT/identity.h"
 #i

[Lldb-commits] [lldb] 25e8f5f - Add missing STLExtras.h include from lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp

2022-01-24 Thread via lldb-commits

Author: serge-sans-paille
Date: 2022-01-24T15:03:11+01:00
New Revision: 25e8f5f827bfbc8aed24c9db116c4869f437fb9d

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

LOG: Add missing STLExtras.h include from 
lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp

Added: 


Modified: 
lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp

Removed: 




diff  --git a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp 
b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp
index 2e103b9e61f1f..b34e01bd01a05 100644
--- a/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp
+++ b/lldb/unittests/TestingSupport/MockTildeExpressionResolver.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "MockTildeExpressionResolver.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Path.h"
 
 using namespace lldb_private;



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


[Lldb-commits] [PATCH] D115508: Reland "[lldb] Remove non address bits when looking up memory regions"

2022-01-24 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 402542.
DavidSpickett added a comment.

Rebase and update release notes format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115508

Files:
  lldb/include/lldb/Target/Process.h
  lldb/source/Commands/CommandObjectMemory.cpp
  lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
  lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
  lldb/source/Plugins/Process/elf-core/ProcessElfCore.h
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
  lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp
  lldb/source/Plugins/Process/mach-core/ProcessMachCore.h
  lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
  lldb/source/Plugins/Process/minidump/ProcessMinidump.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Target/Process.cpp
  lldb/test/API/linux/aarch64/tagged_memory_region/Makefile
  
lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py
  lldb/test/API/linux/aarch64/tagged_memory_region/main.c
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -169,9 +169,16 @@
 
   * ``memory find``
   * ``memory read``
+  * ``memory region`` (see below)
   * ``memory tag read``
   * ``memory tag write``
 
+* The ``memory region`` command and ``GetMemoryRegionInfo`` API method now
+  ignore non-address bits in the address parameter. This also means that on those
+  systems the last (usually unmapped) memory region will not extend to 0xF...F.
+  Instead it will end at the end of the mappable range that the virtual address
+  size allows.
+
 Changes to Sanitizers
 -
 
Index: lldb/test/API/linux/aarch64/tagged_memory_region/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_region/main.c
@@ -0,0 +1,17 @@
+#include 
+#include 
+#include 
+#include 
+
+int main(int argc, char const *argv[]) {
+  void *the_page = mmap(0, sysconf(_SC_PAGESIZE), PROT_READ | PROT_EXEC,
+MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+  if (the_page == MAP_FAILED)
+return 1;
+
+  // Put something in the top byte (AArch64 Linux always enables top byte
+  // ignore)
+  the_page = (void *)((size_t)the_page | ((size_t)0x34 << 56));
+
+  return 0; // Set break point at this line.
+}
Index: lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py
@@ -0,0 +1,70 @@
+"""
+Test that "memory region" lookup uses the ABI plugin to remove
+non address bits from addresses before lookup.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTaggedMemoryRegionTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+NO_DEBUG_INFO_TESTCASE = True
+
+# AArch64 Linux always enables the top byte ignore feature
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_mte_regions(self):
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(self, "main.c",
+line_number('main.c', '// Set break point at this line.'),
+num_expected_locations=1)
+
+self.runCmd("run", RUN_SUCCEEDED)
+
+if self.process().GetState() == lldb.eStateExited:
+self.fail("Test program failed to run.")
+
+self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
+substrs=['stopped',
+ 'stop reason = breakpoint'])
+
+# Despite the non address bits we should find a region
+self.expect("memory region the_page", patterns=[
+"\[0x[0-9A-Fa-f]+-0x[0-9A-Fa-f]+\) r-x"])
+
+# Check that the usual error message is displayed after repeating
+# the command until the last region.
+self.runCmd("memory region 0")
+
+# Count the number of repeats for use in the next check
+repeats = 0
+interp = self.dbg.GetCommandInterpreter()
+result = lldb.SBCommandReturnObject()
+
+while True:
+interp.HandleCommand("memory region", result)
+if result.Succeeded():
+repeats += 1
+else:
+self.assertRegexpMatches(result.GetError(), "Usage: memory region ADDR")
+br

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

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

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


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/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,47 @@
  lldb.eStopReasonSignal)
 self.assertEqual(process.threads[0].GetStopDescription(100),
  'signal SIGUSR1')
+
+def test_siginfo(self):
+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 "\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xbf\xf7\x0b\x00\xe8\x03\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", False
+else:
+return None, False
+
+def haltReason(self):
+return "T02"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+self.runCmd("platform select remote-linux")
+target = self.createTarget("a.yaml")
+process = self.connect(target)
+
+error = lldb.SBError()
+siginfo = process.threads[0].GetSiginfo(error)
+assert siginfo, error
+
+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_status": 12,
+"_sifields._sigchld.si_utime": 0,
+"_sifields._sigchld.si_stime": 0,
+}
+
+for key, value in expected.items():
+self.assertEqual(siginfo.GetValueForExpressionPath("." + key)
+ .GetValueAsUnsigned(),
+ value)
Index: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
===
--- lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
+++ lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
@@ -90,6 +90,9 @@
 
   StructuredData::ObjectSP FetchThreadExtendedInfo() override;
 
+  llvm::Expected>
+  GetSiginfo(size_t max_size) const override;
+
 protected:
   friend class ProcessGDBRemote;
 
Index: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
===
--- lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -346,3 +346,23 @@
 ->CalculateThreadStopInfo(this);
   return false;
 }
+
+llvm::Expected>
+ThreadGDBRemote::GetSiginfo(size_t max_size) const {
+  ProcessSP process_sp(GetProcess());
+  if (!process_sp)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "no process");
+  ProcessGDBRemote *gdb_process =
+  static_cast(process_sp.get());
+  if (!gdb_process->m_gdb_comm.GetQXferSigInfoReadSupported())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "qXfer:siginfo:read not supported");
+
+  llvm::Expected response =
+  gdb_process->m_gdb_comm.ReadExtFeature("siginfo", "");
+  if (!response)
+return response.takeError();
+
+  return llvm::MemoryBuffer::getMemBufferCopy(response.get());
+}
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
===
--- lldb/source/Plugins/Process/gdb-remote/G

[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-24 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D117928#3265048 , @ljmf00 wrote:

> In D117928#3263992 , @mgorny wrote:
>
>> Thank you. Yes, please test on an older kernel, in case it's specifically a 
>> kernel regression.
>
> I can confirm regression on Linux LTS 5.10.93. Probably later and introduced 
> by the patch I mentioned. I reported to the kernel bug tracker. See 
> https://bugzilla.kernel.org/show_bug.cgi?id=215524 .
>
> In D117928#3264795 , @labath wrote:
>
>> If this is a problem with PTRACE_SETREGSET(NT_FPREGSET), then we might be 
>> able to work around it by using PTRACE_POKEUSER instead. But it'd definitely 
>> be good to confirm this, so that we can report the bug to kernel devs.
>
> According to `ptrace` documentation `PTRACE_SETFPREGS` seems a better fit, 
> although either this and `PTRACE_POKEUSER` disallow writing in some specific 
> general-purpose registers, so we should only use this for FP/XMM registers?

I think either would be fine, if it works (I'm not sure how early the 
PTRACE_SETFPREGS and PTRACE_SETREGSET codepaths converge inside the kernel). I 
wouldn't be too worried about the write prohibition clause. I'm pretty sure 
that applies to things like setting the single-step bit inside the flags 
register, and similar mischief that could confuse/crash the kernel. Those 
restrictions should be enforced for any register-writing method. And now, 
thanks to @mgorny, we actually have tests that would catch situations when 
we're not able to change some register.

If you want, I can try to create a patch for this, though it might take me a 
couple of days to get around to it.

> AFAIK BSD-based kernels implements `PT_SETXMMREGS` although I don't see any 
> documentation on the Linux kernel side about this.

Yeah, linux doesn't have those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117928

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


[Lldb-commits] [lldb] 4858fe0 - [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:53+01:00
New Revision: 4858fe04a1571e78ff97b778c0fb6a46855c3d6a

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

LOG: [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface

This patch adds a new method to the Scripted Process interface to
retrive a dictionary of Scripted Threads. It uses the thread ID as a key
and the Scripted Thread instance as the value.

This dictionary will be used to create Scripted Threads in lldb and
perform calls to the python scripted thread object.

rdar://87427126

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h

Removed: 




diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index 16dcc72748532..ec751b495fdb6 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -19,6 +19,7 @@ class ScriptedProcess:
 memory_regions = None
 stack_memory_dump = None
 loaded_images = None
+threads = {}
 
 @abstractmethod
 def __init__(self, target, args):
@@ -51,6 +52,16 @@ def get_memory_region_containing_address(self, addr):
 """
 pass
 
+def get_threads_info(self):
+""" Get the dictionary describing the process' Scripted Threads.
+
+Returns:
+Dict: The dictionary of threads, with the thread ID as the key and
+a Scripted Thread instance as the value.
+The dictionary can be empty.
+"""
+return self.threads
+
 @abstractmethod
 def get_thread_with_id(self, tid):
 """ Get the scripted process thread with a specific ID.

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index 26fd956f96bbc..efdea6df2d417 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -41,6 +41,8 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 return {};
   }
 
+  virtual StructuredData::DictionarySP GetThreadsInfo() { return nullptr; }
+
   virtual StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) {
 return nullptr;
   }

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index da8ff42213552..447bceebb00b4 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -92,6 +92,17 @@ 
ScriptedProcessPythonInterface::GetMemoryRegionContainingAddress(
   return mem_region;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
+  Status error;
+  StructuredData::DictionarySP dict =
+  Dispatch("get_threads_info", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+return {};
+
+  return dict;
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
   Status error;

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
index 421bdd59887ce..ac4e768b2d31b 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -39,6 +39,8 @@ class ScriptedProcessPythonInterface : public 
ScriptedProcessInterface,
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
 
+  StructuredData::DictionarySP GetThreadsInfo() override;
+
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;



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


[Lldb-commits] [lldb] 1b86344 - [lldb/Plugins] Move ScriptedThreadInterface to ScriptedThread

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:53+01:00
New Revision: 1b86344fa80bd11853e0347ea33dc6cb5a460c4f

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

LOG: [lldb/Plugins] Move ScriptedThreadInterface to ScriptedThread

Since we can have multiple Scripted Threads per Scripted Process, having
only a single ScriptedThreadInterface (with a single object instance)
will cause the method calls to be done on the wrong object.

Instead, this patch creates a separate ScriptedThreadInterface for each
new lldb_private::ScriptedThread to make sure we interact with the right
instance.

rdar://87427911

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index efdea6df2d417..d62767417f339 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -68,11 +68,9 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 
 protected:
   friend class ScriptedThread;
-  virtual lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() {
+  virtual lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() {
 return nullptr;
   }
-
-  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
 };
 
 class ScriptedThreadInterface : virtual public ScriptedInterface {

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 959b8c5818852..4185e1b67587b 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -29,7 +29,9 @@ void ScriptedThread::CheckInterpreterAndScriptObject() const {
 }
 
 ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process) {
+: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
+  m_scripted_thread_interface_sp(
+  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
   if (!process.IsValid()) {
 error.SetErrorString("Invalid scripted process");
 return;
@@ -190,7 +192,7 @@ void ScriptedThread::RefreshStateAfterStop() {
 }
 
 lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface() const {
-  return m_scripted_process.GetInterface().GetScriptedThreadInterface();
+  return m_scripted_thread_interface_sp;
 }
 
 std::shared_ptr ScriptedThread::GetDynamicRegisterInfo() {

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.h 
b/lldb/source/Plugins/Process/scripted/ScriptedThread.h
index cdcd543702a48..54b095777ab73 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -59,6 +59,7 @@ class ScriptedThread : public lldb_private::Thread {
   std::shared_ptr GetDynamicRegisterInfo();
 
   const ScriptedProcess &m_scripted_process;
+  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
   lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index 447bceebb00b4..29516c4c4501e 100644
--- 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -165,12 +165,8 @@ 
ScriptedProcessPythonInterface::GetScriptedThreadPluginName() {
 }
 
 lldb::ScriptedThreadInterfaceSP
-ScriptedProcessPythonInterface::GetScriptedThreadInterface() {
-  if (!m_scripted_thread_interface_sp)
-m_scripted_thread_interface_sp =
-std::make_shared(m_interpreter);
-
-  return m_scripted_thread_interface_sp;
+ScriptedProcessPythonInterface::CreateScriptedThreadInterface() {
+  return std::make_shared(m_interpreter);
 }
 
 #endif

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
index ac4e768b2d31b..83507a93bb973 100644
--- 
a/lldb/source/Plugins/Sc

[Lldb-commits] [lldb] d3e0f7e - [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:53+01:00
New Revision: d3e0f7e1503b1bca8baa6483d3b5c452a91f60a6

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

LOG: [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

This patch adds support of multiple Scripted Threads in a ScriptedProcess.

This is done by fetching the Scripted Threads info dictionary at every
ScriptedProcess::DoUpdateThreadList and iterate over each element to
create a new ScriptedThread using the object instance, if it was not
already available.

This patch also adds the ability to pass a pointer of a script interpreter
object instance to initialize a ScriptedInterface instead of having to call
the script object initializer in the ScriptedInterface constructor.

This is used to instantiate the ScriptedThreadInterface from the
ScriptedThread constructor, to be able to perform call on that script
interpreter object instance.

Finally, the patch also updates the scripted process test to check for
multiple threads.

rdar://84507704

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

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/test/API/functionalities/scripted_process/main.cpp

Modified: 
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedInterface.h
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
lldb/test/API/functionalities/scripted_process/Makefile
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

Removed: 
lldb/test/API/functionalities/scripted_process/main.c



diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index ec751b495fdb6..83ec3513cfcd7 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -70,7 +70,7 @@ def get_thread_with_id(self, tid):
 tid (int): Thread ID to look for in the scripted process.
 
 Returns:
-Dict: The thread represented as a dictionary, withr the
+Dict: The thread represented as a dictionary, with the
 tid thread ID. None if tid doesn't match any of the scripted
 process threads.
 """
@@ -212,11 +212,12 @@ def __init__(self, process, args):
 self.target = None
 self.process = None
 self.args = None
-if isinstance(process, lldb.SBProcess) and process.IsValid():
-self.process = process
-self.target = process.GetTarget()
+if isinstance(process, ScriptedProcess):
+self.target = process.target
+self.process = self.target.GetProcess()
 
 self.id = None
+self.idx = None
 self.name = None
 self.queue = None
 self.state = None

diff  --git a/lldb/include/lldb/Interpreter/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedInterface.h
index 427fa3f4f793a..27cf9f036e5fd 100644
--- a/lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -27,7 +27,8 @@ class ScriptedInterface {
 
   virtual StructuredData::GenericSP
   CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
- StructuredData::DictionarySP args_sp) = 0;
+ StructuredData::DictionarySP args_sp,
+ StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
   Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index d62767417f339..0712b3bf4a3ee 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -23,7 +23,8 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 public:
   StructuredData::GenericSP
   CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx

[Lldb-commits] [lldb] cfa55bf - [lldb/Plugins] Enrich ScriptedThreads Stop Reasons with Exceptions

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:54+01:00
New Revision: cfa55bfe781474a30467b1bbf2e7874985171196

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

LOG: [lldb/Plugins] Enrich ScriptedThreads Stop Reasons with Exceptions

This patch adds Exceptions to the list of supported stop reasons for
Scripted Threads.

The main motivation for this is that breakpoints are triggered as a
special exception class on ARM platforms, so adding it as a stop reason
allows the ScriptedProcess to selected the ScriptedThread that stopped at
a breakpoint (or crashed :p).

rdar://87430376

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Removed: 




diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index f01e599ad5585..e28658e33cdad 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -357,7 +357,6 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList 
&old_thread_list,
 void ScriptedProcess::RefreshStateAfterStop() {
   // Let all threads recover from stopping and do any clean up based on the
   // previous thread state (if any).
-  m_thread_list.RefreshStateAfterStop();
 }
 
 bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) {

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 1b9841c2048ea..14f4f99cf9c4a 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -145,6 +145,11 @@ bool ScriptedThread::CalculateStopInfo() {
   StructuredData::DictionarySP dict_sp = GetInterface()->GetStopReason();
 
   Status error;
+  if (!dict_sp)
+return GetInterface()->ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "Failed to get scripted thread stop info.", 
error,
+LIBLLDB_LOG_THREAD);
+
   lldb::StopInfoSP stop_info_sp;
   lldb::StopReason stop_reason_type;
 
@@ -158,12 +163,12 @@ bool ScriptedThread::CalculateStopInfo() {
   if (!dict_sp->GetValueForKeyAsDictionary("data", data_dict))
 return GetInterface()->ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
-"Couldn't find value for key 'type' in stop reason dictionary.", error,
+"Couldn't find value for key 'data' in stop reason dictionary.", error,
 LIBLLDB_LOG_THREAD);
 
   switch (stop_reason_type) {
   case lldb::eStopReasonNone:
-break;
+return true;
   case lldb::eStopReasonBreakpoint: {
 lldb::break_id_t break_id;
 data_dict->GetValueForKeyAsInteger("break_id", break_id,
@@ -180,6 +185,13 @@ bool ScriptedThread::CalculateStopInfo() {
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, signal, 
description.data());
   } break;
+  case lldb::eStopReasonException: {
+llvm::StringRef description;
+data_dict->GetValueForKeyAsString("desc", description);
+
+stop_info_sp =
+StopInfo::CreateStopReasonWithException(*this, description.data());
+  } break;
   default:
 return GetInterface()->ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
@@ -189,6 +201,9 @@ bool ScriptedThread::CalculateStopInfo() {
 error, LIBLLDB_LOG_THREAD);
   }
 
+  if (!stop_info_sp)
+return false;
+
   SetStopInfo(stop_info_sp);
   return true;
 }

diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py 
b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index be55771c14fb1..4831d48a0b5a9 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -188,13 +188,13 @@ def cleanup():
 self.assertEqual(process.GetProcessID(), 42)
 
 self.assertEqual(process.GetNumThreads(), 3)
-thread = process.GetSelectedThread()
+thread = process.GetThreadAtIndex(2)
 self.assertTrue(thread, "Invalid thread.")
-self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-0")
+self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
-self.assertEqual(thread.GetNumFrames(), 2)
+self.assertEqual(thread.GetNumFrames(), 6)
 frame = thread.GetSelectedFrame()
 self.assertTrue(frame, "Invalid frame.")
-# self.assertEqual(frame.GetFunctionName(), "bar")
-  

[Lldb-commits] [lldb] 45148bf - [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:54+01:00
New Revision: 45148bfe8aece6ca319dcc32351e20bba26b2ea7

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

LOG: [lldb/Plugins] Fix ScriptedThread IndexID reporting

When listing all the Scripted Threads of a ScriptedProcess, we can see that all
have the thread index set to 1. This is caused by the lldb_private::Thread
constructor, which sets the m_index_id member using the provided thread id 
`tid`.

Because the call to the super constructor is done before instantiating
the `ScriptedThreadInterface`, lldb can't fetch the thread id from the
script instance, so it uses `LLDB_INVALID_THREAD_ID` instead.

To mitigate this, this patch takes advantage of the `ScriptedThread::Create`
fallible constructor idiom to defer calling the `ScriptedThread` constructor
(and the `Thread` super constructor with it), until we can fetch a valid
thread id `tid` from the `ScriptedThreadInterface`.

rdar://87432065

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Target/Thread.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
lldb/source/Plugins/Process/scripted/ScriptedThread.h

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp

Removed: 




diff  --git a/lldb/include/lldb/Target/Thread.h 
b/lldb/include/lldb/Target/Thread.h
index 91feed310eb97..587b29eb4c661 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -1244,7 +1244,7 @@ class Thread : public 
std::enable_shared_from_this,
  // the stop info was checked against
  // the stop info override
   const uint32_t m_index_id; ///< A unique 1 based index assigned to each 
thread
- ///for easy UI/command line access.
+ /// for easy UI/command line access.
   lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this
 ///thread's current register state.
   lldb::StateType m_state;  ///< The state of our process.

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index e28658e33cdad..e71a0fdf8de92 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -328,12 +328,14 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList 
&old_thread_list,
   return true;
 }
 
-lldb::ThreadSP thread_sp =
-std::make_shared(*this, error, val->GetAsGeneric());
+auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric());
 
-if (!thread_sp || error.Fail())
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   error.AsCString(), error);
+if (!thread_or_error)
+  return GetInterface().ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error);
+
+ThreadSP thread_sp = thread_or_error.get();
+lldbassert(thread_sp && "Couldn't initialize scripted thread.");
 
 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
 if (!reg_ctx_sp)

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index 14f4f99cf9c4a..b6cbb62fd6e6a 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -28,52 +28,60 @@ void ScriptedThread::CheckInterpreterAndScriptObject() 
const {
   lldbassert(GetInterface() && "Invalid Scripted Thread Interface.");
 }
 
-ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error,
-   StructuredData::Generic *script_object)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
-  m_scripted_thread_interface_sp(
-  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
-  if (!process.IsValid()) {
-error.SetErrorString("Invalid scripted process");
-return;
-  }
+llvm::Expected>
+ScriptedThread::Create(ScriptedProcess &process,
+   StructuredData::Generic *script_object) {
+  if (!process.IsValid())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Invalid scripted process.");
 
   process.CheckInterpreterAndScriptObject();
 
-  auto scripted_thread_interface = GetInterface();
-  if (!scripted_thread_interface) {
-error.Se

[Lldb-commits] [lldb] 91bb116 - [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T20:25:54+01:00
New Revision: 91bb116190cdc598863a7a3fda57e431dd832449

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

LOG: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

This patch changes the `ScriptedInterface::ErrorWithMessage` method to
make it `static` which makes it easier to call.

The patch also updates its various call sites to reflect this change.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Interpreter/ScriptedInterface.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/ScriptedInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedInterface.h
index 27cf9f036e5fd..9eb11832003e6 100644
--- a/lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -31,9 +31,9 @@ class ScriptedInterface {
  StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
-  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
-   Status &error,
-   uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+  static Ret ErrorWithMessage(llvm::StringRef caller_name,
+  llvm::StringRef error_msg, Status &error,
+  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
 LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
   caller_name.data(), error_msg.data());
 error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index e71a0fdf8de92..5eb7cb0e6a5c8 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@ bool ScriptedProcess::IsAlive() {
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "No interpreter.", error);
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "No interpreter.", error);
 
   lldb::DataExtractorSP data_extractor_sp =
   GetInterface().ReadMemoryAtAddress(addr, size, error);
@@ -235,7 +235,7 @@ size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, 
void *buf, size_t size,
   0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder());
 
   if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error);
 
   return size;
@@ -293,7 +293,7 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList 
&old_thread_list,
   ScriptLanguage language = m_interpreter->GetLanguage();
 
   if (language != eScriptLanguagePython)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 llvm::Twine("ScriptInterpreter language (" +
 llvm::Twine(m_interpreter->LanguageToString(language)) +
@@ -304,7 +304,7 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList 
&old_thread_list,
   StructuredData::DictionarySP thread_info_sp = 
GetInterface().GetThreadsInfo();
 
   if (!thread_info_sp)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 "Couldn't fetch thread list from Scripted Process.", error);
 
@@ -312,13 +312,13 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList 
&old_thread_list,
   [this, &old_thread_list, &error,
&new_thread_list](ConstString key, StructuredData::Object *val) -> bool 
{
 if (!val)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Invalid thread info object", error);
 
 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
 if (!llvm::to_integer(key.AsCString(), tid))
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "Invalid thread id", error);
+  return ScriptedInterface::ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Invalid thread id", error);
 
 if (ThreadSP thread_sp =
 old_thread_list.FindThreadByID(tid, false /*=can_update*/)) {
@@ -331,7 +331,7 @@ bool ScriptedProcess::DoUpdateThreadList(T

[Lldb-commits] [PATCH] D117068: [lldb/Plugins] Add ScriptedProcess::GetThreadsInfo interface

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4858fe04a157: [lldb/Plugins] Add 
ScriptedProcess::GetThreadsInfo interface (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117068

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -39,6 +39,8 @@
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
 
+  StructuredData::DictionarySP GetThreadsInfo() override;
+
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -92,6 +92,17 @@
   return mem_region;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
+  Status error;
+  StructuredData::DictionarySP dict =
+  Dispatch("get_threads_info", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+return {};
+
+  return dict;
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
   Status error;
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -41,6 +41,8 @@
 return {};
   }
 
+  virtual StructuredData::DictionarySP GetThreadsInfo() { return nullptr; }
+
   virtual StructuredData::DictionarySP GetThreadWithID(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
@@ -19,6 +19,7 @@
 memory_regions = None
 stack_memory_dump = None
 loaded_images = None
+threads = {}
 
 @abstractmethod
 def __init__(self, target, args):
@@ -51,6 +52,16 @@
 """
 pass
 
+def get_threads_info(self):
+""" Get the dictionary describing the process' Scripted Threads.
+
+Returns:
+Dict: The dictionary of threads, with the thread ID as the key and
+a Scripted Thread instance as the value.
+The dictionary can be empty.
+"""
+return self.threads
+
 @abstractmethod
 def get_thread_with_id(self, tid):
 """ Get the scripted process thread with a specific ID.


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -39,6 +39,8 @@
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
 
+  StructuredData::DictionarySP GetThreadsInfo() override;
+
   StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override;
 
   StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -92,6 +92,17 @@
   return mem_region;
 }
 
+StructuredData::DictionarySP ScriptedProcessPythonInterface::GetThreadsInfo() {
+  Status error;
+  StructuredData::DictionarySP dict =
+  Dispatch("get_threads_info", error);
+
+  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
+return {};
+
+  return dict;
+}
+
 StructuredData::DictionarySP
 ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid

[Lldb-commits] [PATCH] D117070: [lldb/Plugins] Move ScriptedThreadInterface to ScriptedThread

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b86344fa80b: [lldb/Plugins] Move ScriptedThreadInterface to 
ScriptedThread (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117070

Files:
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h


Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -57,7 +57,7 @@
   llvm::Optional GetScriptedThreadPluginName() override;
 
 private:
-  lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() override;
+  lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
 };
 } // namespace lldb_private
 
Index: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -165,12 +165,8 @@
 }
 
 lldb::ScriptedThreadInterfaceSP
-ScriptedProcessPythonInterface::GetScriptedThreadInterface() {
-  if (!m_scripted_thread_interface_sp)
-m_scripted_thread_interface_sp =
-std::make_shared(m_interpreter);
-
-  return m_scripted_thread_interface_sp;
+ScriptedProcessPythonInterface::CreateScriptedThreadInterface() {
+  return std::make_shared(m_interpreter);
 }
 
 #endif
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -59,6 +59,7 @@
   std::shared_ptr GetDynamicRegisterInfo();
 
   const ScriptedProcess &m_scripted_process;
+  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
   lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -29,7 +29,9 @@
 }
 
 ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process) {
+: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
+  m_scripted_thread_interface_sp(
+  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
   if (!process.IsValid()) {
 error.SetErrorString("Invalid scripted process");
 return;
@@ -190,7 +192,7 @@
 }
 
 lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface() const {
-  return m_scripted_process.GetInterface().GetScriptedThreadInterface();
+  return m_scripted_thread_interface_sp;
 }
 
 std::shared_ptr ScriptedThread::GetDynamicRegisterInfo() {
Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -68,11 +68,9 @@
 
 protected:
   friend class ScriptedThread;
-  virtual lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() {
+  virtual lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() {
 return nullptr;
   }
-
-  lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
 };
 
 class ScriptedThreadInterface : virtual public ScriptedInterface {


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -57,7 +57,7 @@
   llvm::Optional GetScriptedThreadPluginName() override;
 
 private:
-  lldb::ScriptedThreadInterfaceSP GetScriptedThreadInterface() override;
+  lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
 };
 } // namespace lldb_private
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===

[Lldb-commits] [PATCH] D117071: [lldb/Plugins] Add support of multiple ScriptedThreads in a ScriptedProcess

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd3e0f7e1503b: [lldb/Plugins] Add support of multiple 
ScriptedThreads in a ScriptedProcess (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117071

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/main.c
  lldb/test/API/functionalities/scripted_process/main.cpp
  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
@@ -1,4 +1,4 @@
-import os,struct,signal
+import os,json,struct,signal
 
 from typing import Any, Dict
 
@@ -21,6 +21,14 @@
 idx = int(self.backing_target_idx.GetStringValue(100))
 self.corefile_target = target.GetDebugger().GetTargetAtIndex(idx)
 self.corefile_process = self.corefile_target.GetProcess()
+for corefile_thread in self.corefile_process:
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(json.dumps({
+"backing_target_idx" : idx,
+"thread_idx" : corefile_thread.GetIndexID()
+}))
+
+self.threads[corefile_thread.GetThreadID()] = StackCoreScriptedThread(self, structured_data)
 
 def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
 mem_region = lldb.SBMemoryRegionInfo()
@@ -70,23 +78,43 @@
 class StackCoreScriptedThread(ScriptedThread):
 def __init__(self, process, args):
 super().__init__(process, args)
-self.backing_target_idx = args.GetValueForKey("backing_target_idx")
+backing_target_idx = args.GetValueForKey("backing_target_idx")
+thread_idx = args.GetValueForKey("thread_idx")
+
+def extract_value_from_structured_data(data, default_val):
+if data and data.IsValid():
+if data.GetType() == lldb.eStructuredDataTypeInteger:
+return data.GetIntegerValue(default_val)
+if data.GetType() == lldb.eStructuredDataTypeString:
+return int(data.GetStringValue(100))
+return None
+
+#TODO: Change to Walrus operator (:=) with oneline if assignment
+# Requires python 3.8
+val = extract_value_from_structured_data(thread_idx, 0)
+if val is not None:
+self.idx = val
 
 self.corefile_target = None
 self.corefile_process = None
-if (self.backing_target_idx and self.backing_target_idx.IsValid()):
-if self.backing_target_idx.GetType() == lldb.eStructuredDataTypeInteger:
-idx = self.backing_target_idx.GetIntegerValue(42)
-if self.backing_target_idx.GetType() == lldb.eStructuredDataTypeString:
-idx = int(self.backing_target_idx.GetStringValue(100))
-self.corefile_target = self.target.GetDebugger().GetTargetAtIndex(idx)
+self.corefile_thread = None
+
+#TODO: Change to Walrus operator (:=) with oneline if assignment
+# Requires python 3.8
+val = extract_value_from_structured_data(backing_target_idx, 42)
+if val is not None:
+self.corefile_target = self.target.GetDebugger().GetTargetAtIndex(val)
 self.corefile_process = self.corefile_target.GetProcess()
+self.corefile_thread = self.corefile_process.GetThreadByIndexID(self.idx)
+
+if self.corefile_thread:
+self.id = self.corefile_thread.GetThreadID()
 
 def get_thread_id(self) -> int:
-return 0x19
+return self.id
 
 def get_name(self) -> str:
-return StackCoreScriptedThread.__name__ + ".thread-1"
+   

[Lldb-commits] [PATCH] D117074: [lldb/Plugins] Enrich ScriptedThreads Stop Reasons with Exceptions

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcfa55bfe7814: [lldb/Plugins] Enrich ScriptedThreads Stop 
Reasons with Exceptions (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D117074?vs=400802&id=402614#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117074

Files:
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.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
@@ -117,9 +117,21 @@
 return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
-return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
-} }
+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:
+stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+
+return stop_reason
 
 def get_stackframes(self):
 class ScriptedStackFrame:
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
@@ -188,13 +188,13 @@
 self.assertEqual(process.GetProcessID(), 42)
 
 self.assertEqual(process.GetNumThreads(), 3)
-thread = process.GetSelectedThread()
+thread = process.GetThreadAtIndex(2)
 self.assertTrue(thread, "Invalid thread.")
-self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-0")
+self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
-self.assertEqual(thread.GetNumFrames(), 2)
+self.assertEqual(thread.GetNumFrames(), 6)
 frame = thread.GetSelectedFrame()
 self.assertTrue(frame, "Invalid frame.")
-# self.assertEqual(frame.GetFunctionName(), "bar")
-# self.assertEqual(int(frame.FindValue("i", lldb.eValueTypeVariableArgument).GetValue()), 42)
-# self.assertEqual(int(frame.FindValue("j", lldb.eValueTypeVariableLocal).GetValue()), 42 * 42)
+self.assertIn("bar", frame.GetFunctionName())
+self.assertEqual(int(frame.FindValue("i", lldb.eValueTypeVariableArgument).GetValue()), 42)
+self.assertEqual(int(frame.FindValue("j", lldb.eValueTypeVariableLocal).GetValue()), 42 * 42)
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -145,6 +145,11 @@
   StructuredData::DictionarySP dict_sp = GetInterface()->GetStopReason();
 
   Status error;
+  if (!dict_sp)
+return GetInterface()->ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "Failed to get scripted thread stop info.", error,
+LIBLLDB_LOG_THREAD);
+
   lldb::StopInfoSP stop_info_sp;
   lldb::StopReason stop_reason_type;
 
@@ -158,12 +163,12 @@
   if (!dict_sp->GetValueForKeyAsDictionary("data", data_dict))
 return GetInterface()->ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
-"Couldn't find value for key 'type' in stop reason dictionary.", error,
+"Couldn't find value for key 'data' in stop reason dictionary.", error,
 LIBLLDB_LOG_THREAD);
 
   switch (stop_reason_type) {
   case lldb::eStopReasonNone:
-break;
+return true;
   case lldb::eStopReasonBreakpoint: {
 lldb::break_id_t break_id;
 data_dict->GetValueForKeyAsInteger("break_id", break_id,
@@ -180,6 +185,13 @@
 stop_info_sp =
  

[Lldb-commits] [PATCH] D117076: [lldb/Plugins] Fix ScriptedThread IndexID reporting

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG45148bfe8aec: [lldb/Plugins] Fix ScriptedThread IndexID 
reporting (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117076

Files:
  lldb/include/lldb/Target/Thread.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
@@ -32,7 +32,7 @@
 StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
 StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
-  if (class_name.empty())
+  if (class_name.empty() && !script_obj)
 return {};
 
   ProcessSP process_sp = exe_ctx.GetProcessSP();
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.h
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.h
@@ -25,12 +25,18 @@
 namespace lldb_private {
 
 class ScriptedThread : public lldb_private::Thread {
+
 public:
-  ScriptedThread(ScriptedProcess &process, Status &error,
- StructuredData::Generic *script_object = nullptr);
+  ScriptedThread(ScriptedProcess &process,
+ lldb::ScriptedThreadInterfaceSP interface_sp, lldb::tid_t tid,
+ StructuredData::GenericSP script_object_sp = nullptr);
 
   ~ScriptedThread() override;
 
+  static llvm::Expected>
+  Create(ScriptedProcess &process,
+ StructuredData::Generic *script_object = nullptr);
+
   lldb::RegisterContextSP GetRegisterContext() override;
 
   lldb::RegisterContextSP
@@ -61,8 +67,8 @@
 
   const ScriptedProcess &m_scripted_process;
   lldb::ScriptedThreadInterfaceSP m_scripted_thread_interface_sp = nullptr;
+  lldb_private::StructuredData::GenericSP m_script_object_sp = nullptr;
   std::shared_ptr m_register_info_sp = nullptr;
-  lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
 };
 
 } // namespace lldb_private
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -28,52 +28,60 @@
   lldbassert(GetInterface() && "Invalid Scripted Thread Interface.");
 }
 
-ScriptedThread::ScriptedThread(ScriptedProcess &process, Status &error,
-   StructuredData::Generic *script_object)
-: Thread(process, LLDB_INVALID_THREAD_ID), m_scripted_process(process),
-  m_scripted_thread_interface_sp(
-  m_scripted_process.GetInterface().CreateScriptedThreadInterface()) {
-  if (!process.IsValid()) {
-error.SetErrorString("Invalid scripted process");
-return;
-  }
+llvm::Expected>
+ScriptedThread::Create(ScriptedProcess &process,
+   StructuredData::Generic *script_object) {
+  if (!process.IsValid())
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Invalid scripted process.");
 
   process.CheckInterpreterAndScriptObject();
 
-  auto scripted_thread_interface = GetInterface();
-  if (!scripted_thread_interface) {
-error.SetErrorString("Failed to get scripted thread interface.");
-return;
-  }
-
-  llvm::Optional class_name =
-  process.GetInterface().GetScriptedThreadPluginName();
-  if (!class_name || class_name->empty()) {
-error.SetErrorString("Failed to get scripted thread class name.");
-return;
+  auto scripted_thread_interface =
+  process.GetInterface().CreateScriptedThreadInterface();
+  if (!scripted_thread_interface)
+return llvm::createStringError(
+llvm::inconvertibleErrorCode(),
+"Failed to create scripted thread interface.");
+
+  llvm::StringRef thread_class_name;
+  if (!script_object) {
+llvm::Optional class_name =
+process.GetInterface().GetScriptedThreadPluginName();
+if (!class_name || class_name->empty())
+  return llvm::createStringError(
+  llvm::inconvertibleErrorCode(),
+  "Failed to get scripted thread class name.");
+thread_class_name = *class_name;
   }
 
   ExecutionContext exe_ctx(process);
-
-  m_script_object_sp = scripted_thread_interface->CreatePluginObject(
-  class_na

[Lldb-commits] [PATCH] D117374: [lldb/Interpreter] Make `ScriptedInterface::ErrorWithMessage` static (NFC)

2022-01-24 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91bb116190cd: [lldb/Interpreter] Make 
`ScriptedInterface::ErrorWithMessage` static (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117374

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -222,8 +222,8 @@
 size_t ScriptedProcess::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
  Status &error) {
   if (!m_interpreter)
-return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "No interpreter.", error);
+return ScriptedInterface::ErrorWithMessage(
+LLVM_PRETTY_FUNCTION, "No interpreter.", error);
 
   lldb::DataExtractorSP data_extractor_sp =
   GetInterface().ReadMemoryAtAddress(addr, size, error);
@@ -235,7 +235,7 @@
   0, data_extractor_sp->GetByteSize(), buf, size, GetByteOrder());
 
   if (!bytes_copied || bytes_copied == LLDB_INVALID_OFFSET)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION, "Failed to copy read memory to buffer.", error);
 
   return size;
@@ -293,7 +293,7 @@
   ScriptLanguage language = m_interpreter->GetLanguage();
 
   if (language != eScriptLanguagePython)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 llvm::Twine("ScriptInterpreter language (" +
 llvm::Twine(m_interpreter->LanguageToString(language)) +
@@ -304,7 +304,7 @@
   StructuredData::DictionarySP thread_info_sp = 
GetInterface().GetThreadsInfo();
 
   if (!thread_info_sp)
-return GetInterface().ErrorWithMessage(
+return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
 "Couldn't fetch thread list from Scripted Process.", error);
 
@@ -312,13 +312,13 @@
   [this, &old_thread_list, &error,
&new_thread_list](ConstString key, StructuredData::Object *val) -> bool 
{
 if (!val)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, "Invalid thread info object", error);
 
 lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
 if (!llvm::to_integer(key.AsCString(), tid))
-  return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION,
-   "Invalid thread id", error);
+  return ScriptedInterface::ErrorWithMessage(
+  LLVM_PRETTY_FUNCTION, "Invalid thread id", error);
 
 if (ThreadSP thread_sp =
 old_thread_list.FindThreadByID(tid, false /*=can_update*/)) {
@@ -331,7 +331,7 @@
 auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric());
 
 if (!thread_or_error)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error);
 
 ThreadSP thread_sp = thread_or_error.get();
@@ -339,7 +339,7 @@
 
 RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
 if (!reg_ctx_sp)
-  return GetInterface().ErrorWithMessage(
+  return ScriptedInterface::ErrorWithMessage(
   LLVM_PRETTY_FUNCTION,
   llvm::Twine("Invalid Register Context for thread " +
   llvm::Twine(key.AsCString()))
Index: lldb/include/lldb/Interpreter/ScriptedInterface.h
===
--- lldb/include/lldb/Interpreter/ScriptedInterface.h
+++ lldb/include/lldb/Interpreter/ScriptedInterface.h
@@ -31,9 +31,9 @@
  StructuredData::Generic *script_obj = nullptr) = 0;
 
   template 
-  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
-   Status &error,
-   uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
+  static Ret ErrorWithMessage(llvm::StringRef caller_name,
+  llvm::StringRef error_msg, Status &error,
+  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
 LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
   caller_name.data(), error_msg.data());
 error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scrip

[Lldb-commits] [PATCH] D117914: [lldb] Add ConstString memory usage statistics

2022-01-24 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

@clayborg Does the latest scheme look good to you?


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

https://reviews.llvm.org/D117914

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


[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-24 Thread Michał Górny via Phabricator via lldb-commits
mgorny added a comment.

To explain a bit, `PT_SETXMMREGS` exists because originally `PT_SETFPREGS` used 
FSAVE format on i386, and this format didn't support setting XMM registers. 
Newer CPUs support FXSAVE instead, and this is exposed via `PT_SETFPREGS` on 
amd64 and `PT_SETXMMREGS` on i386.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117928

___
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-24 Thread Michał Górny via Phabricator via lldb-commits
mgorny updated this revision to Diff 402622.
mgorny added a comment.

Add another test using FreeBSD `siginfo_t`, to make sure we select the platform 
correctly.


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/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,86 @@
  lldb.eStopReasonSignal)
 self.assertEqual(process.threads[0].GetStopDescription(100),
  'signal SIGUSR1')
+
+def test_siginfo_linux(self):
+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 "\x11\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xbf\xf7\x0b\x00\xe8\x03\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", False
+else:
+return None, False
+
+def haltReason(self):
+return "T02"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+self.runCmd("platform select remote-linux")
+target = self.createTarget("a.yaml")
+process = self.connect(target)
+
+error = lldb.SBError()
+siginfo = process.threads[0].GetSiginfo(error)
+self.assertTrue(siginfo, error)
+
+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,
+}
+
+for key, value in expected.items():
+self.assertEqual(siginfo.GetValueForExpressionPath("." + key)
+ .GetValueAsUnsigned(),
+ value)
+
+def test_siginfo_freebsd(self):
+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 "\x0b\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00v\x98\xba\xdc\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", False
+else:
+return None, False
+
+def haltReason(self):
+return "T02"
+
+def cont(self):
+return self.haltReason()
+
+self.server.responder = MyResponder()
+
+self.runCmd("platform select remote-freebsd")
+target = self.createTarget("a.yaml")
+process = self.connect(target)
+
+error = lldb.SBError()
+siginfo = process.threads[0].GetSiginfo(error)
+self.assertTrue(siginfo, error)
+
+expected = {
+"si_signo": 11,  # SIGSEGV
+"si_errno": 0,
+"si_code": 1,  # SEGV_MAPERR
+"si_addr": 0xfedcba9876,
+}
+
+for key, value in expected.items():
+self.assertEqual(siginfo.GetValueForExpressionPath("." + key)
+ .GetValueAsUnsigned(),
+ value,
+ key)
Index: lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
===
--- l

[Lldb-commits] [lldb] c3ca2c6 - [lldb/test] Fix `TestScriptedProcess.test_scripted_process_and_scripted_thread`

2022-01-24 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-01-24T21:48:31+01:00
New Revision: c3ca2c6b14f91f8232525373c4f5b1dc504a39a1

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

LOG: [lldb/test] Fix 
`TestScriptedProcess.test_scripted_process_and_scripted_thread`

This patch updates `dummy_scripted_process.py` to report the dummy
thread correctly to reflect the changes introduced by `d3e0f7e`.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py 
b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index 4831d48a0b5a..0c215f082c5d 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -41,6 +41,7 @@ def test_python_plugin_package(self):
 self.expect('script dir(ScriptedProcess)',
 substrs=["launch"])
 
+@skipUnlessDarwin
 def test_invalid_scripted_register_context(self):
 """Test that we can launch an lldb scripted process with an invalid
 Scripted Thread, with invalid register context."""
@@ -77,7 +78,7 @@ def cleanup():
 
 self.assertIn("Failed to get scripted thread registers data.", log)
 
-@skipIf(archs=no_match(['x86_64']))
+@skipIf(archs=no_match(['x86_64', 'arm64', 'arm64e']))
 def test_scripted_process_and_scripted_thread(self):
 """Test that we can launch an lldb scripted process using the SBAPI,
 check its process ID, read string from memory, check scripted thread
@@ -124,8 +125,10 @@ def cleanup():
 break
 
 self.assertTrue(GPRs, "Invalid General Purpose Registers Set")
-self.assertEqual(GPRs.GetNumChildren(), 21)
+self.assertGreater(GPRs.GetNumChildren(), 0)
 for idx, reg in enumerate(GPRs, start=1):
+if idx > 21:
+break
 self.assertEqual(idx, int(reg.value, 16))
 
 def create_stack_skinny_corefile(self, file):

diff  --git 
a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py 
b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
index d7f428d40845..67850cf57a73 100644
--- a/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
+++ b/lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
@@ -9,6 +9,7 @@
 class DummyScriptedProcess(ScriptedProcess):
 def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
 super().__init__(target, args)
+self.threads[0] = DummyScriptedThread(self, None)
 
 def get_memory_region_containing_address(self, addr: int) -> 
lldb.SBMemoryRegionInfo:
 return None



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


[Lldb-commits] [PATCH] D117490: [lldb] Make logging machinery type-safe

2022-01-24 Thread Pavel Labath via Phabricator via lldb-commits
labath marked 7 inline comments as done.
labath added a comment.

In D117490#3261743 , @shafik wrote:

> This is a nice refactor, I am curious was there a motivating bug or issue for 
> this change or just refactoring?

Well.. my motivation was D117382 . I don't 
know what motivated him to do the big refactor (I know he was running out of 
log category bits, but I think that could be solved without it), but one of the 
things both of us are trying to solve is to make sure one cannot mismatch log 
category flags and log getter function (we have some code doing that right now).




Comment at: lldb/include/lldb/Utility/Log.h:57
+  /// };
+  using MaskType = uint32_t;
+

clayborg wrote:
> JDevlieghere wrote:
> > Didn't this all start with Greg wanting to make this a `uint64_t`?
> yes, uint64_t please!
I wanted to keep that for a separate patch. I was preparing for that by 
introducing the new type(def). Though, since this is now really just about 
changing this single identifier, I guess I might as well do it immediately.



Comment at: lldb/include/lldb/Utility/Logging.h:19-50
+  API = Log::ChannelFlag<0>,
+  AST = Log::ChannelFlag<1>,
+  Breakpoints = Log::ChannelFlag<2>,
+  Commands = Log::ChannelFlag<3>,
+  Communication = Log::ChannelFlag<4>,
+  Connection = Log::ChannelFlag<5>,
+  DataFormatters = Log::ChannelFlag<6>,

JDevlieghere wrote:
> I would put this into a `.def` file and have it generate both this list as 
> well as the one with the macros below. The last entry is annoying. We could 
> either omit it from the list but then you risk someone updating the def file 
> but not this. I don't think there's a way to do this automatically? Maybe 
> just an additional define? 
I'm planning to delete the macros more-or-less immediately after this patch 
goes in. I didn't want to do that in the same patch as it would make hide the 
"interesting" changes between thousands of machanical edits.

So, I wouldn't want to create a def file just because of that. I can imagine 
creating both this list and the Log::Category definition with a def file, 
though I'm not sure if it's really worth it.

As for `LLVM_MARK_AS_BITMASK_ENUM`, if I was going with a def file, I'd 
probably make this 
`LLVM_MARK_AS_BITMASK_ENUM(std::numeric_limits::max())` (it does not 
have to refer to an actual constant). The only thing we'd "lose" that way is 
some assertion failures if someone passes an out-of-range constant in some 
way...



Comment at: lldb/unittests/Utility/LogTest.cpp:34-38
+static Log::Channel test_channel(test_categories, TestChannel::FOO);
+
+namespace lldb_private {
+template <> Log::Channel &LogChannelFor() { return test_channel; }
+} // namespace lldb_private

clayborg wrote:
> Should we make a macro for this in Log.h? Something that would define the log 
> channel global variable, and make the template for us?
> 
> ```
> LLDB_CREATE_LOG(test_categories, TestChannel, TestChannel::FOO);
> ```
> which would expand to the above code?
I thought about this for a long time. The macro adds some convenience, but it 
does not seem right to me. The macro would hide the fact that there are two 
objects being declared here, with different storage classes. The storage class 
part is important, because if one tried to put this declaration in a header, it 
could almost work, except that the `LogChannelFor` function would return a 
different (static) object in each compile unit (which would be an odr 
violation, of course).

And I am actually thinking about moving this stuff to a header, since ideally 
we'd want to compiler to inline the `LogChannelFor` function call. That would 
mean the user would need to forward-declare the Channel object in the header, 
and define it in the cpp file, and it would be weird to define an object 
declared by a macro.

I think that moving this to a header would also reduce the boilerplate 
slightly, since one wouldn't need to forward-declare *and* define the 
`LogChannelFor` specialization.

At the end of the day, I don't think this matters much, as we don't create 
logging channels very often.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [PATCH] D117490: [lldb] Make logging machinery type-safe

2022-01-24 Thread Pavel Labath via Phabricator via lldb-commits
labath updated this revision to Diff 402636.
labath marked an inline comment as done.
labath edited the summary of this revision.
labath added a comment.

- use uint64_t for channel mask
- ensure constants are in ascending order


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/include/lldb/Utility/Log.h
  lldb/include/lldb/Utility/Logging.h
  lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.cpp
  lldb/source/Plugins/Process/POSIX/ProcessPOSIXLog.h
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.cpp
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h
  lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
  lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/LogChannelDWARF.h
  lldb/source/Utility/Log.cpp
  lldb/source/Utility/Logging.cpp
  lldb/tools/lldb-server/lldb-gdbserver.cpp
  lldb/unittests/Utility/LogTest.cpp

Index: lldb/unittests/Utility/LogTest.cpp
===
--- lldb/unittests/Utility/LogTest.cpp
+++ lldb/unittests/Utility/LogTest.cpp
@@ -18,13 +18,24 @@
 using namespace lldb;
 using namespace lldb_private;
 
-enum { FOO = 1, BAR = 2 };
+enum class TestChannel : Log::MaskType {
+  FOO = Log::ChannelFlag<0>,
+  BAR = Log::ChannelFlag<1>,
+  LLVM_MARK_AS_BITMASK_ENUM(BAR),
+};
+
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+
 static constexpr Log::Category test_categories[] = {
-{{"foo"}, {"log foo"}, FOO}, {{"bar"}, {"log bar"}, BAR},
+{{"foo"}, {"log foo"}, TestChannel::FOO},
+{{"bar"}, {"log bar"}, TestChannel::BAR},
 };
-static constexpr uint32_t default_flags = FOO;
 
-static Log::Channel test_channel(test_categories, default_flags);
+static Log::Channel test_channel(test_categories, TestChannel::FOO);
+
+namespace lldb_private {
+template <> Log::Channel &LogChannelFor() { return test_channel; }
+} // namespace lldb_private
 
 // Wrap enable, disable and list functions to make them easier to test.
 static bool EnableChannel(std::shared_ptr stream_sp,
@@ -93,7 +104,7 @@
   std::string error;
   ASSERT_TRUE(EnableChannel(m_stream_sp, 0, "chan", {}, error));
 
-  m_log = test_channel.GetLogIfAll(FOO);
+  m_log = GetLog(TestChannel::FOO);
   ASSERT_NE(nullptr, m_log);
 }
 
@@ -124,18 +135,18 @@
 TEST(LogTest, Unregister) {
   llvm::llvm_shutdown_obj obj;
   Log::Register("chan", test_channel);
-  EXPECT_EQ(nullptr, test_channel.GetLogIfAny(FOO));
+  EXPECT_EQ(nullptr, GetLog(TestChannel::FOO));
   std::string message;
   std::shared_ptr stream_sp(
   new llvm::raw_string_ostream(message));
   EXPECT_TRUE(Log::EnableLogChannel(stream_sp, 0, "chan", {"foo"}, llvm::nulls()));
-  EXPECT_NE(nullptr, test_channel.GetLogIfAny(FOO));
+  EXPECT_NE(nullptr, GetLog(TestChannel::FOO));
   Log::Unregister("chan");
-  EXPECT_EQ(nullptr, test_channel.GetLogIfAny(FOO));
+  EXPECT_EQ(nullptr, GetLog(TestChannel::FOO));
 }
 
 TEST_F(LogChannelTest, Enable) {
-  EXPECT_EQ(nullptr, test_channel.GetLogIfAll(FOO));
+  EXPECT_EQ(nullptr, GetLog(TestChannel::FOO));
   std::string message;
   std::shared_ptr stream_sp(
   new llvm::raw_string_ostream(message));
@@ -144,20 +155,22 @@
   EXPECT_EQ("Invalid log channel 'chanchan'.\n", error);
 
   EXPECT_TRUE(EnableChannel(stream_sp, 0, "chan", {}, error));
-  EXPECT_NE(nullptr, test_channel.GetLogIfAll(FOO));
-  EXPECT_EQ(nullptr, test_channel.GetLogIfAll(BAR));
+  EXPECT_NE(nullptr, GetLog(TestChannel::FOO));
+  EXPECT_EQ(nullptr, GetLog(TestChannel::BAR));
 
   EXPECT_TRUE(EnableChannel(stream_sp, 0, "chan", {"bar"}, error));
-  EXPECT_NE(nullptr, test_channel.GetLogIfAll(FOO | BAR));
+  EXPECT_NE(nullptr, test_channel.GetLogIfAll(
+ Log::MaskType(TestChannel::FOO | TestChannel::BAR)));
 
   EXPECT_TRUE(EnableChannel(stream_sp, 0, "chan", {"baz"}, error));
   EXPECT_NE(std::string::npos, error.find("unrecognized log category 'baz'"))
   << "error: " << error;
-  EXPECT_NE(nullptr, test_channel.GetLogIfAll(FOO | BAR));
+  EXPECT_NE(nullptr, test_channel.GetLogIfAll(
+ Log::MaskType(TestChannel::FOO | TestChannel::BAR)));
 }
 
 TEST_F(LogChannelTest, EnableOptions) {
-  EXPECT_EQ(nullptr, test_channel.GetLogIfAll(FOO));
+  EXPECT_EQ(nullptr, GetLog(TestChannel::FOO));
   std::string message;
   std::shared_ptr stream_sp(
   new llvm::raw_string_ostream(message));
@@ -165,32 +178,33 @@
   EXPECT_TRUE(
   EnableChannel(stream_sp, LLDB_LOG_OPTION_VERBOSE, "chan", {}, error));
 
-  Log *log = test_channel.GetLogIfAll(FOO);
+  Log *log = GetLog(TestChannel::FOO);
   ASSERT_NE(nullptr, log);
   EXPECT_TRUE(log->GetVerbose());
 }
 
 TEST_F(LogChannelTest, Disable) {
-  EXPECT_EQ(

[Lldb-commits] [PATCH] D117490: [lldb] Make logging machinery type-safe

2022-01-24 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.

I'm happy with this. LGTM assuming Greg feels the same way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [PATCH] D117914: [lldb] Add ConstString memory usage statistics

2022-01-24 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.

Yep! Looks good.

As a follow up patch it would be great to ask the SymbolFile classes to break 
down some memory usage. I know in the SymbolFileDWARF we have each DWARFUnit 
that may or may not parse the unit DIE or all of the DIEs. These data 
structures take up memory and we lazily try to only parse all DIEs in a 
DWARFUnit when we need to. If we index the debug info, we will load the info 
and remembers which DWARFUnits had all of their DIEs parsed, and after indexing 
we will free the memory to keep memory usage down.


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

https://reviews.llvm.org/D117914

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


[Lldb-commits] [PATCH] D117914: [lldb] Add ConstString memory usage statistics

2022-01-24 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added a comment.

In D117914#3267657 , @clayborg wrote:

> Yep! Looks good.
>
> As a follow up patch it would be great to ask the SymbolFile classes to break 
> down some memory usage. I know in the SymbolFileDWARF we have each DWARFUnit 
> that may or may not parse the unit DIE or all of the DIEs. These data 
> structures take up memory and we lazily try to only parse all DIEs in a 
> DWARFUnit when we need to. If we index the debug info, we will load the info 
> and remembers which DWARFUnits had all of their DIEs parsed, and after 
> indexing we will free the memory to keep memory usage down.

Are you referring to the `m_die_array` in `DWARFUnit` and `ClearDIEsRWLocked`? 
If so that actually looks like a good fit for the BumpPtrAllocator in which 
case it should be fairly easy to report.


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

https://reviews.llvm.org/D117914

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


[Lldb-commits] [lldb] cd8122b - [lldb] Add ConstString memory usage statistics

2022-01-24 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-01-24T15:13:17-08:00
New Revision: cd8122b27f8fb9cbf222ef946bff3b698625e2f4

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

LOG: [lldb] Add ConstString memory usage statistics

Add statistics about the memory usage of the string pool. I'm
particularly interested in the memory used by the allocator, i.e. the
number of bytes actually used by the allocator it self as well as the
number of bytes allocated through the allocator.

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

Added: 


Modified: 
lldb/include/lldb/Target/Statistics.h
lldb/include/lldb/Utility/ConstString.h
lldb/source/Target/Statistics.cpp
lldb/source/Utility/ConstString.cpp
lldb/test/API/commands/statistics/basic/TestStats.py

Removed: 




diff  --git a/lldb/include/lldb/Target/Statistics.h 
b/lldb/include/lldb/Target/Statistics.h
index 185389b2eeafe..d2b8f746a38c8 100644
--- a/lldb/include/lldb/Target/Statistics.h
+++ b/lldb/include/lldb/Target/Statistics.h
@@ -9,6 +9,7 @@
 #ifndef LLDB_TARGET_STATISTICS_H
 #define LLDB_TARGET_STATISTICS_H
 
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/lldb-forward.h"
 #include "llvm/Support/JSON.h"
@@ -110,6 +111,11 @@ struct ModuleStats {
   bool debug_info_index_saved_to_cache = false;
 };
 
+struct ConstStringStats {
+  llvm::json::Value ToJSON() const;
+  ConstString::MemoryStats stats = ConstString::GetMemoryStats();
+};
+
 /// A class that represents statistics for a since lldb_private::Target.
 class TargetStats {
 public:

diff  --git a/lldb/include/lldb/Utility/ConstString.h 
b/lldb/include/lldb/Utility/ConstString.h
index 2756f1fd72038..937f8271a9a8e 100644
--- a/lldb/include/lldb/Utility/ConstString.h
+++ b/lldb/include/lldb/Utility/ConstString.h
@@ -408,6 +408,16 @@ class ConstString {
   /// in memory.
   static size_t StaticMemorySize();
 
+  struct MemoryStats {
+size_t GetBytesTotal() const { return bytes_total; }
+size_t GetBytesUsed() const { return bytes_used; }
+size_t GetBytesUnused() const { return bytes_total - bytes_used; }
+size_t bytes_total = 0;
+size_t bytes_used = 0;
+  };
+
+  static MemoryStats GetMemoryStats();
+
 protected:
   template  friend struct ::llvm::DenseMapInfo;
   /// Only used by DenseMapInfo.

diff  --git a/lldb/source/Target/Statistics.cpp 
b/lldb/source/Target/Statistics.cpp
index 8d1e982c3b988..ebddad837d14b 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -65,6 +65,14 @@ json::Value ModuleStats::ToJSON() const {
   return module;
 }
 
+llvm::json::Value ConstStringStats::ToJSON() const {
+  json::Object obj;
+  obj.try_emplace("bytesTotal", stats.GetBytesTotal());
+  obj.try_emplace("bytesUsed", stats.GetBytesUsed());
+  obj.try_emplace("bytesUnused", stats.GetBytesUnused());
+  return obj;
+}
+
 json::Value TargetStats::ToJSON(Target &target) {
   CollectStats(target);
 
@@ -212,9 +220,15 @@ llvm::json::Value DebuggerStats::ReportStatistics(Debugger 
&debugger,
 json_modules.emplace_back(module_stat.ToJSON());
   }
 
+  ConstStringStats const_string_stats;
+  json::Object json_memory{
+  {"strings", const_string_stats.ToJSON()},
+  };
+
   json::Object global_stats{
   {"targets", std::move(json_targets)},
   {"modules", std::move(json_modules)},
+  {"memory", std::move(json_memory)},
   {"totalSymbolTableParseTime", symtab_parse_time},
   {"totalSymbolTableIndexTime", symtab_index_time},
   {"totalSymbolTablesLoadedFromCache", symtabs_loaded},

diff  --git a/lldb/source/Utility/ConstString.cpp 
b/lldb/source/Utility/ConstString.cpp
index e5e1b2387e64d..76270e3f53b96 100644
--- a/lldb/source/Utility/ConstString.cpp
+++ b/lldb/source/Utility/ConstString.cpp
@@ -171,6 +171,17 @@ class Pool {
 return mem_size;
   }
 
+  ConstString::MemoryStats GetMemoryStats() const {
+ConstString::MemoryStats stats;
+for (const auto &pool : m_string_pools) {
+  llvm::sys::SmartScopedReader rlock(pool.m_mutex);
+  const Allocator &alloc = pool.m_string_map.getAllocator();
+  stats.bytes_total += alloc.getTotalMemory();
+  stats.bytes_used += alloc.getBytesAllocated();
+}
+return stats;
+  }
+
 protected:
   uint8_t hash(const llvm::StringRef &s) const {
 uint32_t h = llvm::djbHash(s);
@@ -332,6 +343,10 @@ size_t ConstString::StaticMemorySize() {
   return StringPool().MemorySize();
 }
 
+ConstString::MemoryStats ConstString::GetMemoryStats() {
+  return StringPool().GetMemoryStats();
+}
+
 void llvm::format_provider::format(const ConstString &CS,
 llvm::raw_ostream &OS,
 llvm::StringRef Options) {

diff  --git a

[Lldb-commits] [PATCH] D117914: [lldb] Add ConstString memory usage statistics

2022-01-24 Thread Jonas Devlieghere via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd8122b27f8f: [lldb] Add ConstString memory usage statistics 
(authored by JDevlieghere).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117914

Files:
  lldb/include/lldb/Target/Statistics.h
  lldb/include/lldb/Utility/ConstString.h
  lldb/source/Target/Statistics.cpp
  lldb/source/Utility/ConstString.cpp
  lldb/test/API/commands/statistics/basic/TestStats.py

Index: lldb/test/API/commands/statistics/basic/TestStats.py
===
--- lldb/test/API/commands/statistics/basic/TestStats.py
+++ lldb/test/API/commands/statistics/basic/TestStats.py
@@ -135,6 +135,7 @@
 
 (lldb) statistics dump
 {
+  "memory" : {...},
   "modules" : [...],
   "targets" : [
 {
@@ -160,6 +161,7 @@
 target = self.createTestTarget()
 debug_stats = self.get_stats()
 debug_stat_keys = [
+'memory',
 'modules',
 'targets',
 'totalSymbolTableParseTime',
@@ -197,6 +199,7 @@
 
 (lldb) statistics dump
 {
+  "memory" : {...},
   "modules" : [...],
   "targets" : [
 {
@@ -227,6 +230,7 @@
   lldb.SBFileSpec("main.c"))
 debug_stats = self.get_stats()
 debug_stat_keys = [
+'memory',
 'modules',
 'targets',
 'totalSymbolTableParseTime',
@@ -254,6 +258,44 @@
 self.assertGreater(stats['launchOrAttachTime'], 0.0)
 self.assertGreater(stats['targetCreateTime'], 0.0)
 
+def test_memory(self):
+"""
+Test "statistics dump" and the memory information.
+"""
+exe = self.getBuildArtifact("a.out")
+target = self.createTestTarget(file_path=exe)
+debug_stats = self.get_stats()
+debug_stat_keys = [
+'memory',
+'modules',
+'targets',
+'totalSymbolTableParseTime',
+'totalSymbolTableIndexTime',
+'totalSymbolTablesLoadedFromCache',
+'totalSymbolTablesSavedToCache',
+'totalDebugInfoParseTime',
+'totalDebugInfoIndexTime',
+'totalDebugInfoIndexLoadedFromCache',
+'totalDebugInfoIndexSavedToCache',
+'totalDebugInfoByteSize'
+]
+self.verify_keys(debug_stats, '"debug_stats"', debug_stat_keys, None)
+
+memory = debug_stats['memory']
+memory_keys= [
+'strings',
+]
+self.verify_keys(memory, '"memory"', memory_keys, None)
+
+strings = memory['strings']
+strings_keys= [
+'bytesTotal',
+'bytesUsed',
+'bytesUnused',
+]
+self.verify_keys(strings, '"strings"', strings_keys, None)
+
+
 def find_module_in_metrics(self, path, stats):
 modules = stats['modules']
 for module in modules:
@@ -269,6 +311,7 @@
 target = self.createTestTarget(file_path=exe)
 debug_stats = self.get_stats()
 debug_stat_keys = [
+'memory',
 'modules',
 'targets',
 'totalSymbolTableParseTime',
@@ -312,6 +355,7 @@
 Output expected to be something like:
 
 {
+  "memory" : {...},
   "modules" : [...],
   "targets" : [
 {
@@ -355,6 +399,7 @@
 self.runCmd("b a_function")
 debug_stats = self.get_stats()
 debug_stat_keys = [
+'memory',
 'modules',
 'targets',
 'totalSymbolTableParseTime',
Index: lldb/source/Utility/ConstString.cpp
===
--- lldb/source/Utility/ConstString.cpp
+++ lldb/source/Utility/ConstString.cpp
@@ -171,6 +171,17 @@
 return mem_size;
   }
 
+  ConstString::MemoryStats GetMemoryStats() const {
+ConstString::MemoryStats stats;
+for (const auto &pool : m_string_pools) {
+  llvm::sys::SmartScopedReader rlock(pool.m_mutex);
+  const Allocator &alloc = pool.m_string_map.getAllocator();
+  stats.bytes_total += alloc.getTotalMemory();
+  stats.bytes_used += alloc.getBytesAllocated();
+}
+return stats;
+  }
+
 protected:
   uint8_t hash(const llvm::StringRef &s) const {
 uint32_t h = llvm::djbHash(s);
@@ -332,6 +343,10 @@
   return StringPool().MemorySize();
 }
 
+ConstString::MemoryStats ConstString::GetMemoryStats() {
+  return StringPool().GetMemoryStats();
+}
+
 void llvm::format_provider::format(const ConstString &CS,
 llvm::raw_ostream &OS,
 llvm::StringRef Options) {
Index: lldb/source/Target/Statistics.cpp

[Lldb-commits] [PATCH] D117490: [lldb] Make logging machinery type-safe

2022-01-24 Thread Greg Clayton via Phabricator via lldb-commits
clayborg accepted this revision.
clayborg added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117490

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


[Lldb-commits] [lldb] 16bff06 - [lldb] Make PythonDataObjects work with Python 2

2022-01-24 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-01-24T17:23:09-08:00
New Revision: 16bff06790a7652b282352b07250b627e5787c8c

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

LOG: [lldb] Make PythonDataObjects work with Python 2

I considered keeping this change strictly downstream. Since we still
have a bunch of places that check for Python 2, I figured it doesn't
harm to land it upstream and avoid the conflict when I eventually do
remove them (hopefully soon!).

Added: 


Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 32020f983f605..68f4e90d70f6e 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -70,7 +70,9 @@ Expected 
python::As(Expected &&obj) {
 }
 
 static bool python_is_finalizing() {
-#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+#if PY_MAJOR_VERSION == 2
+  return false;
+#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
   return _Py_Finalizing != nullptr;
 #else
   return _Py_IsFinalizing();
@@ -279,7 +281,9 @@ PythonObject 
PythonObject::GetAttributeValue(llvm::StringRef attr) const {
 }
 
 StructuredData::ObjectSP PythonObject::CreateStructuredObject() const {
+#if PY_MAJOR_VERSION >= 3
   assert(PyGILState_Check());
+#endif
   switch (GetObjectType()) {
   case PyObjectType::Dictionary:
 return PythonDictionary(PyRefType::Borrowed, m_py_obj)



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


[Lldb-commits] [PATCH] D118091: [lldb] Remove ConstString::StaticMemorySize

2022-01-24 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, clayborg, kastiglione.
JDevlieghere requested review of this revision.

Remove `ConstString::StaticMemorySize` as it is unused. It is referenced in a 
bunch of doc comments but I don't really understand why. My best guess it that 
the comments were copy-pasted from `ConstString::MemorySize()` even though it 
didn't make sense there either. The implementation of `StaticMemorySize` was 
being called on the MemoryPool, not on the ConstString itself.


https://reviews.llvm.org/D118091

Files:
  lldb/include/lldb/Core/Declaration.h
  lldb/include/lldb/Core/FileSpecList.h
  lldb/include/lldb/Core/Mangled.h
  lldb/include/lldb/Symbol/Function.h
  lldb/include/lldb/Utility/ConstString.h
  lldb/include/lldb/Utility/FileSpec.h
  lldb/source/Utility/ConstString.cpp

Index: lldb/source/Utility/ConstString.cpp
===
--- lldb/source/Utility/ConstString.cpp
+++ lldb/source/Utility/ConstString.cpp
@@ -159,18 +159,6 @@
 return nullptr;
   }
 
-  // Return the size in bytes that this object and any items in its collection
-  // of uniqued strings + data count values takes in memory.
-  size_t MemorySize() const {
-size_t mem_size = sizeof(Pool);
-for (const auto &pool : m_string_pools) {
-  llvm::sys::SmartScopedReader rlock(pool.m_mutex);
-  for (const auto &entry : pool.m_string_map)
-mem_size += sizeof(StringPoolEntryType) + entry.getKey().size();
-}
-return mem_size;
-  }
-
   ConstString::MemoryStats GetMemoryStats() const {
 ConstString::MemoryStats stats;
 for (const auto &pool : m_string_pools) {
@@ -338,11 +326,6 @@
   m_string = StringPool().GetConstTrimmedCStringWithLength(cstr, cstr_len);
 }
 
-size_t ConstString::StaticMemorySize() {
-  // Get the size of the static string pool
-  return StringPool().MemorySize();
-}
-
 ConstString::MemoryStats ConstString::GetMemoryStats() {
   return StringPool().GetMemoryStats();
 }
Index: lldb/include/lldb/Utility/FileSpec.h
===
--- lldb/include/lldb/Utility/FileSpec.h
+++ lldb/include/lldb/Utility/FileSpec.h
@@ -334,8 +334,6 @@
   ///
   /// \return
   /// The number of bytes that this object occupies in memory.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const;
 
   /// Change the file specified with a new path.
Index: lldb/include/lldb/Utility/ConstString.h
===
--- lldb/include/lldb/Utility/ConstString.h
+++ lldb/include/lldb/Utility/ConstString.h
@@ -394,20 +394,8 @@
   ///
   /// \return
   /// The number of bytes that this object occupies in memory.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const { return sizeof(ConstString); }
 
-  /// Get the size in bytes of the current global string pool.
-  ///
-  /// Reports the size in bytes of all shared C string values, containers and
-  /// any other values as a byte size for the entire string pool.
-  ///
-  /// \return
-  /// The number of bytes that the global string pool occupies
-  /// in memory.
-  static size_t StaticMemorySize();
-
   struct MemoryStats {
 size_t GetBytesTotal() const { return bytes_total; }
 size_t GetBytesUsed() const { return bytes_used; }
Index: lldb/include/lldb/Symbol/Function.h
===
--- lldb/include/lldb/Symbol/Function.h
+++ lldb/include/lldb/Symbol/Function.h
@@ -110,8 +110,6 @@
   /// The number of bytes that this object occupies in memory.
   /// The returned value does not include the bytes for any
   /// shared string values.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   virtual size_t MemorySize() const;
 
 protected:
@@ -238,8 +236,6 @@
   /// The number of bytes that this object occupies in memory.
   /// The returned value does not include the bytes for any
   /// shared string values.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const override;
 
 private:
@@ -595,8 +591,6 @@
   /// The number of bytes that this object occupies in memory.
   /// The returned value does not include the bytes for any
   /// shared string values.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const;
 
   /// Get whether compiler optimizations were enabled for this function
Index: lldb/include/lldb/Core/Mangled.h
===
--- lldb/include/lldb/Core/Mangled.h
+++ lldb/include/lldb/Core/Mangled.h
@@ -183,8 +183,6 @@
   ///
   /// \return
   /// The number of bytes that this object occupies in memory.
-  ///
-  /// \see ConstString::StaticMemorySize ()
   size_t MemorySize() const;
 
   /// Set the string value in this object.
Index: lldb/include/lldb/Core/FileSpecList.h
==

[Lldb-commits] [PATCH] D117928: [lldb] Disable tests for x86 that uses write command on XMM registers

2022-01-24 Thread Luís Ferreira via Phabricator via lldb-commits
ljmf00 added a comment.

In D117928#3265583 , @mgorny wrote:

> Could you try replacing the new function with the old one and seeing if that 
> helps? Or alternatively, trying to build a kernel from the commit just before 
> that change and with that change.

I can reproduce with the introduced change and by removing the `memset` call, I 
can write to the registers. I submitted a patch to the kernel mailing list. See 
the kernel bug tracker for discussion. I talked a bit about the flow of LLDB to 
discover XSAVE and FXSAVE, although correct me there if I'm wrong.

In D117928#3266895 , @labath wrote:

> If you want, I can try to create a patch for this, though it might take me a 
> couple of days to get around to it.

I'm probably not getting the full picture but my idea on this is: if we propose 
this change due to this specific kernel regression is not worth it, although we 
should consider it if there is any other benefit on using `PTRACE_POKEUSER`.

In D117928#3267103 , @mgorny wrote:

> To explain a bit, `PT_SETXMMREGS` exists because originally `PT_SETFPREGS` 
> used FSAVE format on i386, and this format didn't support setting XMM 
> registers. Newer CPUs support FXSAVE instead, and this is exposed via 
> `PT_SETFPREGS` on amd64 and `PT_SETXMMREGS` on i386.

Ok, makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117928

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