[Lldb-commits] [PATCH] D117004: [lldb] Don't print "Command Options Usage:" for an alias with no options

2022-01-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a subscriber: jeroen.dobbelaere.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

"shell" is an alias to "platform shell -h --". Previously you would get this
help text:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell 

Command Options Usage:

'shell' is an abbreviation for 'platform shell -h   --'

Since the code doesn't handle the base command having options
but the alias removing them. With these changes you get:

(lldb) help shell
Run a shell command on the host.  Expects 'raw' input (see 'help raw-input'.)

Syntax: shell 

'shell' is an abbreviation for 'platform shell -h   --'

Note that we already handle a non-alias command having no options,
for example "quit":

(lldb) help quit
Quit the LLDB debugger.

Syntax: quit [exit-code]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117004

Files:
  lldb/source/Interpreter/Options.cpp
  lldb/test/API/commands/platform/basic/TestPlatformCommand.py


Index: lldb/test/API/commands/platform/basic/TestPlatformCommand.py
===
--- lldb/test/API/commands/platform/basic/TestPlatformCommand.py
+++ lldb/test/API/commands/platform/basic/TestPlatformCommand.py
@@ -20,10 +20,12 @@
 self.runCmd("help platform")
 
 @no_debug_info_test
-def test_help_platform(self):
+def test_help_shell_alias(self):
 self.expect("help shell", substrs=["Run a shell command on the host.",
-   "shell "])
-
+   "shell ",
+   "'shell' is an abbreviation"])
+# "platform shell" has options. The "shell" alias for it does not.
+self.expect("help shell", substrs=["Command Options:"], matching=False)
 
 @no_debug_info_test
 def test_list(self):
Index: lldb/source/Interpreter/Options.cpp
===
--- lldb/source/Interpreter/Options.cpp
+++ lldb/source/Interpreter/Options.cpp
@@ -403,7 +403,12 @@
   } else
 name = "";
 
-  strm.PutCString("\nCommand Options Usage:\n");
+  const uint32_t num_options = NumCommandOptions();
+  if (num_options == 0)
+return;
+
+  if (!only_print_args)
+strm.PutCString("\nCommand Options Usage:\n");
 
   strm.IndentMore(2);
 
@@ -413,10 +418,6 @@
   //   [options-for-level-1]
   //   etc.
 
-  const uint32_t num_options = NumCommandOptions();
-  if (num_options == 0)
-return;
-
   uint32_t num_option_sets = GetRequiredOptions().size();
 
   uint32_t i;
@@ -531,9 +532,9 @@
 strm << " " << arguments_str.GetString();
   }
 
-  strm.Printf("\n\n");
-
   if (!only_print_args) {
+strm.Printf("\n\n");
+
 // Now print out all the detailed information about the various options:
 // long form, short form and help text:
 //   -short  ( --long_name  )


Index: lldb/test/API/commands/platform/basic/TestPlatformCommand.py
===
--- lldb/test/API/commands/platform/basic/TestPlatformCommand.py
+++ lldb/test/API/commands/platform/basic/TestPlatformCommand.py
@@ -20,10 +20,12 @@
 self.runCmd("help platform")
 
 @no_debug_info_test
-def test_help_platform(self):
+def test_help_shell_alias(self):
 self.expect("help shell", substrs=["Run a shell command on the host.",
-   "shell "])
-
+   "shell ",
+   "'shell' is an abbreviation"])
+# "platform shell" has options. The "shell" alias for it does not.
+self.expect("help shell", substrs=["Command Options:"], matching=False)
 
 @no_debug_info_test
 def test_list(self):
Index: lldb/source/Interpreter/Options.cpp
===
--- lldb/source/Interpreter/Options.cpp
+++ lldb/source/Interpreter/Options.cpp
@@ -403,7 +403,12 @@
   } else
 name = "";
 
-  strm.PutCString("\nCommand Options Usage:\n");
+  const uint32_t num_options = NumCommandOptions();
+  if (num_options == 0)
+return;
+
+  if (!only_print_args)
+strm.PutCString("\nCommand Options Usage:\n");
 
   strm.IndentMore(2);
 
@@ -413,10 +418,6 @@
   //   [options-for-level-1]
   //   etc.
 
-  const uint32_t num_options = NumCommandOptions();
-  if (num_options == 0)
-return;
-
   uint32_t num_option_sets = GetRequiredOptions().size();
 
   uint32_t i;
@@ -531,9 +532,9 @@
 strm << " " << arguments_str.GetString();
   }
 
-  strm.Printf("\n\n");
-
   if (!only_print_args) {
+   

[Lldb-commits] [PATCH] D116845: [LLDB][NativePDB] Add support for inlined functions

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

In D116845#3232971 , @zequanwu wrote:

>> The one part that bothers me is the "two-phased" setting of line tables. 
>> IIUC, the problem is that the inline line info is in the block descriptor, 
>> so you need to parse block info in order to create a line table, but in 
>> order to actually create an lldb_private::Block, you need the call site info 
>> from the caller, which is in the pdb line table. This creates a sort of a 
>> dependency loop, is that right?
>
> Yes. The temporary line table is in `CompileUnitIndex` now.

This looks better. Thanks.




Comment at: lldb/include/lldb/Symbol/LineTable.h:305-335
   struct EntrySearchInfo {
 LineTable *line_table;
 lldb_private::Section *a_section;
 Entry *a_entry;
   };
 
   // Types

The rest of this can stay protected, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116845

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


[Lldb-commits] [lldb] 6d8d1c5 - [lldb/qemu] Implement GetMmapArgumentList

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

Author: Pavel Labath
Date: 2022-01-11T14:08:03+01:00
New Revision: 6d8d1c5ea307a6f8f86bb870535e426ccddccb4d

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

LOG: [lldb/qemu] Implement GetMmapArgumentList

By forwarding it to the host platform.

Added: 


Modified: 
lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h

Removed: 




diff  --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h 
b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
index 71df1b7b7811d..c5439e126db11 100644
--- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
+++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
@@ -47,6 +47,14 @@ class PlatformQemuUser : public Platform {
 
   Environment GetEnvironment() override;
 
+  MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+  lldb::addr_t length, unsigned prot,
+  unsigned flags, lldb::addr_t fd,
+  lldb::addr_t offset) override {
+return Platform::GetHostPlatform()->GetMmapArgumentList(
+arch, addr, length, prot, flags, fd, offset);
+  }
+
 private:
   static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
   static void DebuggerInitialize(Debugger &debugger);



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


[Lldb-commits] [PATCH] D103626: [lldb][AArch64] Remove non address bits from memory read arguments

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

Rebase, update some comment wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103626

Files:
  lldb/source/Commands/CommandObjectMemory.cpp
  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
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -163,6 +163,9 @@
 * A change in Clang's type printing has changed the way LLDB names array types
   (from ``int [N]`` to ``int[N]``) - LLDB pretty printer type name matching
   code may need to be updated to handle this.
+* The ``memory read`` command now ignores non-address bits in start and end
+  addresses. In addition, non-address bits will not be shown in the addresses
+  in the output.
 
 Changes to Sanitizers
 -
Index: lldb/test/API/linux/aarch64/tagged_memory_read/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/main.c
@@ -0,0 +1,15 @@
+#include 
+
+static char *set_non_address_bits(char *ptr, size_t tag) {
+  // Set top byte tag (AArch64 Linux always enables top byte ignore)
+  return (char *)((size_t)ptr | (tag << 56));
+}
+
+int main(int argc, char const *argv[]) {
+  char buf[32];
+
+  char *ptr1 = set_non_address_bits(buf, 0x34);
+  char *ptr2 = set_non_address_bits(buf, 0x56);
+
+  return 0; // Set break point at this line.
+}
Index: lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
@@ -0,0 +1,55 @@
+"""
+Test that "memory read" removes non address bits from
+memory read arguments.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTaggedMemoryReadTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+NO_DEBUG_INFO_TESTCASE = True
+
+# AArch64 Linux always enables top byte ignore
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_read(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'])
+
+# 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.
+# 2. We error because end address is < start address since end's
+#tag is < start's tag.
+#
+# Each time we check that the printed line addresses do not include
+# either of the tags we set. Those bits are a property of the
+# pointer not of the memory it points to.
+tagged_addr_pattern = "0x(34|46)[0-9A-Fa-f]{14}:.*"
+self.expect("memory read ptr1 ptr2+16", patterns=[tagged_addr_pattern], matching=False)
+# Check that the stored previous end address is stripped
+self.expect("memory read", patterns=[tagged_addr_pattern], matching=False)
+# 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)
Index: lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -march=armv8.3-a
+
+include Makefile.rules
Index: lldb/source/Commands/CommandObjectMemory.cpp
===
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -23,6 +23,7 @@
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target

[Lldb-commits] [PATCH] D103626: [lldb] Remove non address bits from memory read arguments

2022-01-11 Thread David Spickett 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 rG88fdce5be696: [lldb] Remove non address bits from memory 
read arguments (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103626

Files:
  lldb/source/Commands/CommandObjectMemory.cpp
  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
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -163,6 +163,9 @@
 * A change in Clang's type printing has changed the way LLDB names array types
   (from ``int [N]`` to ``int[N]``) - LLDB pretty printer type name matching
   code may need to be updated to handle this.
+* The ``memory read`` command now ignores non-address bits in start and end
+  addresses. In addition, non-address bits will not be shown in the addresses
+  in the output.
 
 Changes to Sanitizers
 -
Index: lldb/test/API/linux/aarch64/tagged_memory_read/main.c
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/main.c
@@ -0,0 +1,15 @@
+#include 
+
+static char *set_non_address_bits(char *ptr, size_t tag) {
+  // Set top byte tag (AArch64 Linux always enables top byte ignore)
+  return (char *)((size_t)ptr | (tag << 56));
+}
+
+int main(int argc, char const *argv[]) {
+  char buf[32];
+
+  char *ptr1 = set_non_address_bits(buf, 0x34);
+  char *ptr2 = set_non_address_bits(buf, 0x56);
+
+  return 0; // Set break point at this line.
+}
Index: lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
@@ -0,0 +1,55 @@
+"""
+Test that "memory read" removes non address bits from
+memory read arguments.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTaggedMemoryReadTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+NO_DEBUG_INFO_TESTCASE = True
+
+# AArch64 Linux always enables top byte ignore
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_read(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'])
+
+# 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.
+# 2. We error because end address is < start address since end's
+#tag is < start's tag.
+#
+# Each time we check that the printed line addresses do not include
+# either of the tags we set. Those bits are a property of the
+# pointer not of the memory it points to.
+tagged_addr_pattern = "0x(34|46)[0-9A-Fa-f]{14}:.*"
+self.expect("memory read ptr1 ptr2+16", patterns=[tagged_addr_pattern], matching=False)
+# Check that the stored previous end address is stripped
+self.expect("memory read", patterns=[tagged_addr_pattern], matching=False)
+# 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)
Index: lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -march=armv8.3-a
+
+include Makefile.rules
Index: lldb/source/Commands/CommandObjectMemory.cpp
===
--- lldb/source/Commands/CommandObjectMemory.cpp
+++ lldb/source/Commands/CommandObjectMemory.cpp
@@ -23,6 +23,7 @@
 #include "lldb/Interpreter/Option

[Lldb-commits] [lldb] 88fdce5 - [lldb] Remove non address bits from memory read arguments

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

Author: David Spickett
Date: 2022-01-11T13:24:09Z
New Revision: 88fdce5be696c7ef992cffce9da9ec6895a1abfc

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

LOG: [lldb] Remove non address bits from memory read arguments

Addresses on AArch64 can have top byte tags, memory tags and pointer
authentication signatures in the upper bits.

While testing memory tagging I found that memory read couldn't
read a range if the two addresses had different tags. The same
could apply to signed pointers given the right circumstance.

(lldb) memory read mte_buf_alt_tag mte_buf+16
error: end address (0x900f7ff8010) must be greater than the start
address (0xa00f7ff8000).

Or it would try to read a lot more memory than expected.

(lldb) memory read mte_buf mte_buf_alt_tag+16
error: Normally, 'memory read' will not read over 1024 bytes of data.
error: Please use --force to override this restriction just once.
error: or set target.max-memory-read-size if you will often need a
larger limit.

Fix this by removing non address bits before we calculate the read
range. A test is added for AArch64 Linux that confirms this by using
the top byte ignore feature.

This means that if you do read with a tagged pointer the output
does not include those tags. This is potentially confusing but I think
overall it's better that we don't pretend that we're reading memory
from a range that the process is unable to map.

(lldb) p ptr1
(char *) $4 = 0x3400f140 "\x80\xf1\xff\xff\xff\xff"
(lldb) p ptr2
(char *) $5 = 0x5600f140 "\x80\xf1\xff\xff\xff\xff"
(lldb) memory read ptr1 ptr2+16
0xf140: 80 f1 ff ff ff ff 00 00 38 70 bc f7 ff ff 00 00  
8p..

Reviewed By: omjavaid, danielkiss

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

Added: 
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

Modified: 
lldb/source/Commands/CommandObjectMemory.cpp
llvm/docs/ReleaseNotes.rst

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp 
b/lldb/source/Commands/CommandObjectMemory.cpp
index 9df42f36fafdc..e59cd8028998a 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -23,6 +23,7 @@
 #include "lldb/Interpreter/Options.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/TypeList.h"
+#include "lldb/Target/ABI.h"
 #include "lldb/Target/Language.h"
 #include "lldb/Target/MemoryHistory.h"
 #include "lldb/Target/MemoryRegionInfo.h"
@@ -590,9 +591,16 @@ class CommandObjectMemoryRead : public CommandObjectParsed 
{
   return false;
 }
 
+ABISP abi = m_exe_ctx.GetProcessPtr()->GetABI();
+if (abi)
+  addr = abi->FixDataAddress(addr);
+
 if (argc == 2) {
   lldb::addr_t end_addr = OptionArgParser::ToAddress(
   &m_exe_ctx, command[1].ref(), LLDB_INVALID_ADDRESS, nullptr);
+  if (end_addr != LLDB_INVALID_ADDRESS && abi)
+end_addr = abi->FixDataAddress(end_addr);
+
   if (end_addr == LLDB_INVALID_ADDRESS) {
 result.AppendError("invalid end address expression.");
 result.AppendError(error.AsCString());

diff  --git a/lldb/test/API/linux/aarch64/tagged_memory_read/Makefile 
b/lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
new file mode 100644
index 0..c6ea179d22524
--- /dev/null
+++ b/lldb/test/API/linux/aarch64/tagged_memory_read/Makefile
@@ -0,0 +1,4 @@
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -march=armv8.3-a
+
+include Makefile.rules

diff  --git 
a/lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
 
b/lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
new file mode 100644
index 0..2f55b951a7548
--- /dev/null
+++ 
b/lldb/test/API/linux/aarch64/tagged_memory_read/TestAArch64LinuxTaggedMemoryRead.py
@@ -0,0 +1,55 @@
+"""
+Test that "memory read" removes non address bits from
+memory read arguments.
+"""
+
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class AArch64LinuxTaggedMemoryReadTestCase(TestBase):
+
+mydir = TestBase.compute_mydir(__file__)
+
+NO_DEBUG_INFO_TESTCASE = True
+
+# AArch64 Linux always enables top byte ignore
+@skipUnlessArch("aarch64")
+@skipUnlessPlatform(["linux"])
+def test_tagged_memory_read(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

[Lldb-commits] [PATCH] D103626: [lldb] Remove non address bits from memory read arguments

2022-01-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

Since there was no great pushback on this I've landed it. With the final 
justification being that the non-address bits are properties of the pointer not 
of the memory pointed to.

I will do a follow up where I apply the same logic to the ReadMemory calls via 
the API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103626

___
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-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 398921.
DavidSpickett added a comment.

- Revert back to the do...while structure.
- Reword the explanatory comments.


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
@@ -163,6 +163,11 @@
 * A change in Clang's type printing has changed the way LLDB names array types
   (from ``int [N]`` to ``int[N]``) - LLDB pretty printer type name matching
   code may need to be updated to handle this.
+* The ``memory region`` command and ``GetMemoryRegionInfo`` API method now
+  ignore non-address bits in the address parameter. This means that on those
+  systems the last (usually unmapped) memory region will not extend to 0xF...F.
+  Instead it will end at the last address that the process could possibly map
+  if you account for the non-address bits.
 
 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,42 @@
+"""
+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"])
Index: lldb/test/API/linux/aarch64/tagged_memory_region/Makefile
===
--- /dev/null
+++ lldb/test/API/linux/aarch64/tagged_memory_region/Makefile
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -5853,12 +5853,20 @@
   return retval;
 }
 
+

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

2022-01-11 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

@omjavaid ping!

Using `fixed address != original address` inspired by 
https://reviews.llvm.org/D115431#change-7Gybl0dcCOwp. I first used `<` which I 
think works out the same but `!=` is clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115508

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


[Lldb-commits] [PATCH] D116845: [LLDB][NativePDB] Add support for inlined functions

2022-01-11 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu updated this revision to Diff 399001.
zequanwu marked an inline comment as done.
zequanwu added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116845

Files:
  lldb/include/lldb/Symbol/LineTable.h
  lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/test/Shell/SymbolFile/NativePDB/Inputs/inline_sites.lldbinit
  lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s

Index: lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
@@ -0,0 +1,667 @@
+# clang-format off
+# REQUIRES: lld, x86
+
+# RUN: llvm-mc -triple=x86_64-windows-msvc --filetype=obj %s > %t.obj
+# RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj  -out:%t.exe
+# RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
+# RUN: %p/Inputs/inline_sites.lldbinit 2>&1 | FileCheck %s
+
+# Compiled from the following files, but replaced the call to abort with nop.
+# a.cpp:
+# #include "stdlib.h"
+# #include "a.h"
+# int main(int argc, char** argv) {
+#   Namespace1::foo(2);
+#   return 0;
+# }
+# a.h:
+# #include "b.h"
+# namespace Namespace1 {
+# inline void foo(int x) {
+#   static volatile int gv_foo;
+#   ++gv_foo;
+#   if (!gv_foo)
+# abort();
+#   Class1::bar(x + 1);
+# }
+# }
+# b.h:
+# #include "c.h"
+# class Class1 {
+# public:
+#   inline static void bar(int x) {
+# static volatile int gv_bar;
+# ++gv_bar;
+# Namespace2::Class2::func(x + 1);
+#   }
+# };
+# c.h:
+# namespace Namespace2{
+#   class Class2{
+# public:
+# inline static void func(int x) {
+#   static volatile int gv_func;
+#   gv_func += x;
+# }
+#   };
+# }
+
+# CHECK:  (lldb) image dump line-table a.cpp -v
+# CHECK-NEXT: Line table for /tmp/a.cpp in
+# CHECK-NEXT: 0x000140001000: /tmp/a.cpp:3
+# CHECK-NEXT: 0x000140001004: /tmp/a.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x00014000100a: /tmp/a.h:6
+# CHECK-NEXT: 0x000140001014: /tmp/b.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x00014000101a: /tmp/c.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x000140001021: /tmp/a.cpp:5
+# CHECK-NEXT: 0x000140001028: /tmp/a.h:7, is_start_of_statement = TRUE
+# CHECK-NEXT: 0x00014000102a: /tmp/a.cpp:5, is_terminal_entry = TRUE
+
+# CEHCK: (lldb) b a.cpp:5
+# CHECK: Breakpoint 1: where = {{.*}}`main + 33 at a.cpp:5, address = 0x000140001021
+# CEHCK: (lldb) b a.h:5
+# CHECK: Breakpoint 2: where = {{.*}}`main + 4 [inlined] Namespace1::foo at a.h:5, address = 0x000140001004
+# CEHCK: (lldb) b a.h:6
+# CHECK: Breakpoint 3: where = {{.*}}`main + 10 [inlined] Namespace1::foo + 6 at a.h:6, address = 0x00014000100a
+# CEHCK: (lldb) b a.h:7
+# CHECK: Breakpoint 4: where = {{.*}}`main + 40 [inlined] Namespace1::foo at a.h:7, address = 0x000140001028
+# CEHCK: (lldb) b b.h:6
+# CHECK: Breakpoint 5: where = {{.*}}`main + 20 [inlined] Class1::bar at b.h:6, address = 0x000140001014
+# CEHCK: (lldb) b c.h:6
+# CHECK: Breakpoint 6: where = {{.*}}`main + 26 [inlined] Namespace2::Class2::func at c.h:6, address = 0x00014000101a
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001003 -v
+# CHECK:  Summary: {{.*}}`main + 3 at a.cpp:3
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK:LineEntry: [0x000140001000-0x000140001004): /tmp/a.cpp:3
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001004 -v
+# CHECK:  Summary: {{.*}}`main + 4 [inlined] Namespace1::foo at a.h:5
+# CHECK-NEXT:  {{.*}}`main + 4 at a.cpp:4
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK-NEXT:  id = {{.*}}, ranges = [0x140001004-0x140001021)[0x140001028-0x14000102a), name = "Namespace1::foo", decl = a.h:3
+# CHECK:LineEntry: [0x000140001004-0x00014000100a): /tmp/a.h:5
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001014 -v
+# CHECK:  Summary: {{.*}}`main + 20 [inlined] Class1::bar at b.h:6
+# CHECK-NEXT:  {{.*}}`main + 20 [inlined] Namespace1::foo + 16 at a.h:8
+# CHECK-NEXT:  {{.*}}`main + 4 at a.cpp:4
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK-NEXT:  id = {{.*}}, ranges = [0x140001004-0x140001021)[0x140001028-0x14000102a), name = "Name

[Lldb-commits] [lldb] c0e4154 - Fix clang-tidy bugprone-argument-comment that was mixed up

2022-01-11 Thread Shafik Yaghmour via lldb-commits

Author: Shafik Yaghmour
Date: 2022-01-11T11:12:28-08:00
New Revision: c0e415471136a16cc98c9ce57392efd62db51c1f

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

LOG: Fix clang-tidy bugprone-argument-comment that was mixed up

Several of the comments were annotating the wrong argument.

I caught this while reviewing this clean-up: 
https://github.com/llvm/llvm-project/commit/8afcfbfb8fc1e53023ffac9d9bdc424248d6d2ff

which was changing booleans to use true and false and in the this case the 
comment and the type looked mismatched.

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

Added: 


Modified: 
lldb/source/Target/TraceInstructionDumper.cpp

Removed: 




diff  --git a/lldb/source/Target/TraceInstructionDumper.cpp 
b/lldb/source/Target/TraceInstructionDumper.cpp
index f0947d8f88b82..d58d2dff7383a 100644
--- a/lldb/source/Target/TraceInstructionDumper.cpp
+++ b/lldb/source/Target/TraceInstructionDumper.cpp
@@ -148,9 +148,8 @@ static void DumpInstructionDisassembly(Stream &s, 
InstructionSymbolInfo &insn) {
   if (!insn.instruction)
 return;
   s.Printf("");
-  insn.instruction->Dump(&s, /*show_address=*/false, /*show_bytes=*/false,
- /*max_opcode_byte_size=*/false, &insn.exe_ctx,
- &insn.sc,
+  insn.instruction->Dump(&s, /*max_opcode_byte_size=*/0, 
/*show_address=*/false,
+ /*show_bytes=*/false, &insn.exe_ctx, &insn.sc,
  /*prev_sym_ctx=*/nullptr,
  /*disassembly_addr_format=*/nullptr,
  /*max_address_text_size=*/0);



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


[Lldb-commits] [PATCH] D116982: Fix clang-tidy bugprone-argument-comment that was mixed up

2022-01-11 Thread Shafik Yaghmour via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0e415471136: Fix clang-tidy bugprone-argument-comment that 
was mixed up (authored by shafik).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116982

Files:
  lldb/source/Target/TraceInstructionDumper.cpp


Index: lldb/source/Target/TraceInstructionDumper.cpp
===
--- lldb/source/Target/TraceInstructionDumper.cpp
+++ lldb/source/Target/TraceInstructionDumper.cpp
@@ -148,9 +148,8 @@
   if (!insn.instruction)
 return;
   s.Printf("");
-  insn.instruction->Dump(&s, /*show_address=*/false, /*show_bytes=*/false,
- /*max_opcode_byte_size=*/false, &insn.exe_ctx,
- &insn.sc,
+  insn.instruction->Dump(&s, /*max_opcode_byte_size=*/0, 
/*show_address=*/false,
+ /*show_bytes=*/false, &insn.exe_ctx, &insn.sc,
  /*prev_sym_ctx=*/nullptr,
  /*disassembly_addr_format=*/nullptr,
  /*max_address_text_size=*/0);


Index: lldb/source/Target/TraceInstructionDumper.cpp
===
--- lldb/source/Target/TraceInstructionDumper.cpp
+++ lldb/source/Target/TraceInstructionDumper.cpp
@@ -148,9 +148,8 @@
   if (!insn.instruction)
 return;
   s.Printf("");
-  insn.instruction->Dump(&s, /*show_address=*/false, /*show_bytes=*/false,
- /*max_opcode_byte_size=*/false, &insn.exe_ctx,
- &insn.sc,
+  insn.instruction->Dump(&s, /*max_opcode_byte_size=*/0, /*show_address=*/false,
+ /*show_bytes=*/false, &insn.exe_ctx, &insn.sc,
  /*prev_sym_ctx=*/nullptr,
  /*disassembly_addr_format=*/nullptr,
  /*max_address_text_size=*/0);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D117004: [lldb] Don't print "Command Options Usage:" for an alias with no options

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117004

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


[Lldb-commits] [PATCH] D117004: [lldb] Don't print "Command Options Usage:" for an alias with no options

2022-01-11 Thread Jim Ingham via Phabricator via lldb-commits
jingham accepted this revision.
jingham added a comment.

I was confused by your example of the "quit" command since the previous code 
output the banner before checking the NumCommandOptions, so that shouldn't have 
worked.  Actually, there's a check in CommandObject::GenerateHelp  for a null 
return from GetOptions before this GenerateOptionUsage gets called, which 
bypasses the call.  Anyway, with this change we'll do this correctly even if we 
get here in some other way, so that's all good.

I also think this function is pretty confusing to read.  First off, 
only_print_args is a really confusing name for "is_dash_dash_command", which is 
what that bool really signifies.  Also, we do a bunch of checking for both 
only_print_args and !only_print_args inside the first "if (!only_print_args)" 
block, but that variable is a const so that's just weird.

So far as I can see, the only thing we do in the `only_print_args == true` case 
is this block:

  if (cmd && (only_print_args || cmd->WantsRawCommandString()) &&
  arguments_str.GetSize() > 0) {
if (!only_print_args)
  strm.PutChar('\n');
strm.Indent(name);
strm << " " << arguments_str.GetString();
  }

plus resetting the indentation.

This function would be much easier to read if we handle IsDashDash commands as 
an early return, emitting the command name and arguments, and returning.  Then 
we could remove of both the if (!only_print_args) blocks, and the weird checks 
inside those blocks, and this would make more sense.  That little snippet is 
sufficiently obvious I don't think repeating it would be a big deal.

OTOH, you didn't originally write this code, so if you don't have time to clean 
it up further, then this LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117004

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


[Lldb-commits] [PATCH] D116788: [lldb] Set result error state in 'frame variable'

2022-01-11 Thread Dave Lee via Phabricator via lldb-commits
kastiglione added a comment.

> if I run “frame var” from HandleCommand in a script, with this change I can’t 
> rely on the command status to tell whether the command output had anything 
> interesting in it. That seems awkward.

This could be resolved by introducing a new enum value to indicate partial 
success, partial failure. I think that would be reasonable. I don't think that 
should block this change though, do you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116788

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


[Lldb-commits] [PATCH] D116845: [LLDB][NativePDB] Add support for inlined functions

2022-01-11 Thread Zequan Wu via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG945aa520ef07: [LLDB][NativePDB] Add support for inlined 
functions (authored by zequanwu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116845

Files:
  lldb/include/lldb/Symbol/LineTable.h
  lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/test/Shell/SymbolFile/NativePDB/Inputs/inline_sites.lldbinit
  lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s

Index: lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
===
--- /dev/null
+++ lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
@@ -0,0 +1,667 @@
+# clang-format off
+# REQUIRES: lld, x86
+
+# RUN: llvm-mc -triple=x86_64-windows-msvc --filetype=obj %s > %t.obj
+# RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj  -out:%t.exe
+# RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \
+# RUN: %p/Inputs/inline_sites.lldbinit 2>&1 | FileCheck %s
+
+# Compiled from the following files, but replaced the call to abort with nop.
+# a.cpp:
+# #include "stdlib.h"
+# #include "a.h"
+# int main(int argc, char** argv) {
+#   Namespace1::foo(2);
+#   return 0;
+# }
+# a.h:
+# #include "b.h"
+# namespace Namespace1 {
+# inline void foo(int x) {
+#   static volatile int gv_foo;
+#   ++gv_foo;
+#   if (!gv_foo)
+# abort();
+#   Class1::bar(x + 1);
+# }
+# }
+# b.h:
+# #include "c.h"
+# class Class1 {
+# public:
+#   inline static void bar(int x) {
+# static volatile int gv_bar;
+# ++gv_bar;
+# Namespace2::Class2::func(x + 1);
+#   }
+# };
+# c.h:
+# namespace Namespace2{
+#   class Class2{
+# public:
+# inline static void func(int x) {
+#   static volatile int gv_func;
+#   gv_func += x;
+# }
+#   };
+# }
+
+# CHECK:  (lldb) image dump line-table a.cpp -v
+# CHECK-NEXT: Line table for /tmp/a.cpp in
+# CHECK-NEXT: 0x000140001000: /tmp/a.cpp:3
+# CHECK-NEXT: 0x000140001004: /tmp/a.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x00014000100a: /tmp/a.h:6
+# CHECK-NEXT: 0x000140001014: /tmp/b.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x00014000101a: /tmp/c.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x000140001021: /tmp/a.cpp:5
+# CHECK-NEXT: 0x000140001028: /tmp/a.h:7, is_start_of_statement = TRUE
+# CHECK-NEXT: 0x00014000102a: /tmp/a.cpp:5, is_terminal_entry = TRUE
+
+# CEHCK: (lldb) b a.cpp:5
+# CHECK: Breakpoint 1: where = {{.*}}`main + 33 at a.cpp:5, address = 0x000140001021
+# CEHCK: (lldb) b a.h:5
+# CHECK: Breakpoint 2: where = {{.*}}`main + 4 [inlined] Namespace1::foo at a.h:5, address = 0x000140001004
+# CEHCK: (lldb) b a.h:6
+# CHECK: Breakpoint 3: where = {{.*}}`main + 10 [inlined] Namespace1::foo + 6 at a.h:6, address = 0x00014000100a
+# CEHCK: (lldb) b a.h:7
+# CHECK: Breakpoint 4: where = {{.*}}`main + 40 [inlined] Namespace1::foo at a.h:7, address = 0x000140001028
+# CEHCK: (lldb) b b.h:6
+# CHECK: Breakpoint 5: where = {{.*}}`main + 20 [inlined] Class1::bar at b.h:6, address = 0x000140001014
+# CEHCK: (lldb) b c.h:6
+# CHECK: Breakpoint 6: where = {{.*}}`main + 26 [inlined] Namespace2::Class2::func at c.h:6, address = 0x00014000101a
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001003 -v
+# CHECK:  Summary: {{.*}}`main + 3 at a.cpp:3
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK:LineEntry: [0x000140001000-0x000140001004): /tmp/a.cpp:3
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001004 -v
+# CHECK:  Summary: {{.*}}`main + 4 [inlined] Namespace1::foo at a.h:5
+# CHECK-NEXT:  {{.*}}`main + 4 at a.cpp:4
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK-NEXT:  id = {{.*}}, ranges = [0x140001004-0x140001021)[0x140001028-0x14000102a), name = "Namespace1::foo", decl = a.h:3
+# CHECK:LineEntry: [0x000140001004-0x00014000100a): /tmp/a.h:5
+
+# CEHCK-LABEL: (lldb) image lookup -a 0x140001014 -v
+# CHECK:  Summary: {{.*}}`main + 20 [inlined] Class1::bar at b.h:6
+# CHECK-NEXT:  {{.*}}`main + 20 [inlined] Namespace1::foo + 16 at a.h:8
+# CHECK-NEXT:  {{.*}}`main + 4 at a.cpp:4
+# CHECK: Function: id = {{.*}}, name = "main", range = [0x000140001000-0x00014000102a)
+# CHECK:   Blocks: id = {{.*}}, range = [0x140001000-0x14000102a)
+# CHECK-NEXT:  id = {{.*}}, ranges = [0x140

[Lldb-commits] [lldb] 945aa52 - [LLDB][NativePDB] Add support for inlined functions

2022-01-11 Thread Zequan Wu via lldb-commits

Author: Zequan Wu
Date: 2022-01-11T16:10:39-08:00
New Revision: 945aa520ef07a3edb655f3f38e4c3023658dd623

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

LOG: [LLDB][NativePDB] Add support for inlined functions

This adds inline function support to NativePDB by parsing S_INLINESITE records
to retrieve inlinee line info and add them into line table at `ParseLineTable`.

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

Added: 
lldb/test/Shell/SymbolFile/NativePDB/Inputs/inline_sites.lldbinit
lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s

Modified: 
lldb/include/lldb/Symbol/LineTable.h
lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h

Removed: 




diff  --git a/lldb/include/lldb/Symbol/LineTable.h 
b/lldb/include/lldb/Symbol/LineTable.h
index 5cd22bd831eef..b5121b29fe028 100644
--- a/lldb/include/lldb/Symbol/LineTable.h
+++ b/lldb/include/lldb/Symbol/LineTable.h
@@ -206,7 +206,6 @@ class LineTable {
 
   LineTable *LinkLineTable(const FileRangeMap &file_range_map);
 
-protected:
   struct Entry {
 Entry()
 : line(0), is_start_of_statement(false), 
is_start_of_basic_block(false),
@@ -303,6 +302,7 @@ class LineTable {
 uint16_t file_idx = 0;
   };
 
+protected:
   struct EntrySearchInfo {
 LineTable *line_table;
 lldb_private::Section *a_section;

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
index 9f09c0accc876..d8f737612c257 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp
@@ -106,6 +106,24 @@ static void ParseExtendedInfo(PdbIndex &index, 
CompilandIndexItem &item) {
   }
 }
 
+static void ParseInlineeLineTableForCompileUnit(CompilandIndexItem &item) {
+  for (const auto &ss : item.m_debug_stream.getSubsectionsArray()) {
+if (ss.kind() != DebugSubsectionKind::InlineeLines)
+  continue;
+
+DebugInlineeLinesSubsectionRef inlinee_lines;
+llvm::BinaryStreamReader reader(ss.getRecordData());
+if (llvm::Error error = inlinee_lines.initialize(reader)) {
+  consumeError(std::move(error));
+  continue;
+}
+
+for (const InlineeSourceLine &Line : inlinee_lines) {
+  item.m_inline_map[Line.Header->Inlinee] = Line;
+}
+  }
+}
+
 CompilandIndexItem::CompilandIndexItem(
 PdbCompilandId id, llvm::pdb::ModuleDebugStreamRef debug_stream,
 llvm::pdb::DbiModuleDescriptor descriptor)
@@ -142,6 +160,7 @@ CompilandIndexItem 
&CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) {
   cci = std::make_unique(
   PdbCompilandId{modi}, std::move(debug_stream), std::move(descriptor));
   ParseExtendedInfo(m_index, *cci);
+  ParseInlineeLineTableForCompileUnit(*cci);
 
   cci->m_strings.initialize(debug_stream.getSubsectionsArray());
   PDBStringTable &strings = cantFail(m_index.pdb().getStringTable());

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h 
b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
index 088de970cbf32..4ad27de986954 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h
@@ -9,10 +9,12 @@
 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_COMPILEUNITINDEX_H
 
+#include "lldb/Utility/RangeMap.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntervalMap.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
 #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h"
 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
@@ -69,6 +71,17 @@ struct CompilandIndexItem {
   // command line, etc.  This usually contains exactly 5 items which
   // are references to other strings.
   llvm::SmallVector m_build_info;
+
+  // Inlinee lines table in this compile unit.
+  std::map
+  m_inline_map;
+
+  // It's the line table parsed from DEBUG_S_LINES sections, mapping the file
+  // address range to file index and source line number.
+  using GlobalLineTable =
+  lldb_private::RangeDataVector>;
+  GlobalLineTable m_global_line_table;
 };
 
 /// Indexes information about all compile units.  This is really just a map of

diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
index e859b1d5a86cf..578b36

Re: [Lldb-commits] [PATCH] D116788: [lldb] Set result error state in 'frame variable'

2022-01-11 Thread Jim Ingham via lldb-commits
Indeed not.  Since you can get everything you would need straightforwardly 
using SBFrame::FindVariables, there’s no pressing need to give another way to 
do it using HandleCommand.

Jim

> On Jan 11, 2022, at 2:02 PM, Dave Lee via Phabricator 
>  wrote:
> 
> kastiglione added a comment.
> 
>> if I run “frame var” from HandleCommand in a script, with this change I 
>> can’t rely on the command status to tell whether the command output had 
>> anything interesting in it. That seems awkward.
> 
> This could be resolved by introducing a new enum value to indicate partial 
> success, partial failure. I think that would be reasonable. I don't think 
> that should block this change though, do you?
> 
> 
> Repository:
>  rG LLVM Github Monorepo
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D116788/new/
> 
> https://reviews.llvm.org/D116788
> 

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


[Lldb-commits] [PATCH] D117065: [lldb/Plugins] Fix ScriptedInterface object ptr use-after-free

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

This patch replaces all the ScriptedInterface object instance shared
pointer by a raw pointer. The reason behind the change is that when the
smart pointer gets re-assigned, that triggers calling the default
deleter to the previously pointer object.

However, in this case, the pointed memory was allocated in Python, so
when another object tries to read it, it causes a heap-use-after-free.

By switching to a raw pointer, it prevents lldb from decrementing the
reference counting to 0 and calling the deleter for that object.

rdar://87425859

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117065

Files:
  lldb/include/lldb/Interpreter/ScriptedInterface.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.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
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h
@@ -22,7 +22,7 @@
 public:
   ScriptedThreadPythonInterface(ScriptInterpreterPythonImpl &interpreter);
 
-  StructuredData::GenericSP
+  StructuredData::Generic *
   CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
  StructuredData::DictionarySP args_sp) override;
 
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
@@ -29,7 +29,7 @@
 ScriptInterpreterPythonImpl &interpreter)
 : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
 
-StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
+StructuredData::Generic *ScriptedThreadPythonInterface::CreatePluginObject(
 const llvm::StringRef class_name, ExecutionContext &exe_ctx,
 StructuredData::DictionarySP args_sp) {
 
@@ -50,10 +50,10 @@
   if (!ret_val)
 return {};
 
-  m_object_instance_sp =
-  StructuredData::GenericSP(new StructuredPythonObject(ret_val));
+  m_object_instance = static_cast(
+  new StructuredPythonObject(ret_val));
 
-  return m_object_instance_sp;
+  return m_object_instance;
 }
 
 lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -42,15 +42,16 @@
 llvm::Twine(LLVM_PRETTY_FUNCTION + llvm::Twine(" (") +
 llvm::Twine(method_name) + llvm::Twine(")"))
 .str();
-if (!m_object_instance_sp)
-  return ErrorWithMessage(caller_signature, "Python object ill-formed",
- error);
 
 Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);
 
+if (!m_object_instance && m_object_instance->IsValid())
+  return ErrorWithMessage(caller_signature, "Python object ill-formed",
+ error);
+
 PythonObject implementor(PyRefType::Borrowed,
- (PyObject *)m_object_instance_sp->GetValue());
+ (PyObject *)m_object_instance->GetValue());
 
 if (!implementor.IsAllocated())
   return ErrorWithMessage(caller_signature,
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -22,7 +22,7 @@
 public:
   ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter);
 
-  StructuredData::GenericSP
+  StructuredData::Gen

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

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

This patch 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

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

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

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

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

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

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

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::Generic *m_script_object = 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 GetScriptedThreadInterfa

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

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

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

This is done by fetch 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 update the test to make it multi-threaded.

rdar://84507704

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117071

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/test/API/functionalities/scripted_process/Makefile
  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"
+return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
@@ -109,10 +137,9 @@
 return self.frame_zero[0:0]
 
 def get_register_context(self) -> str:
-thread = self.corefile_

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

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

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/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.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"
+return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
@@ -109,10 +137,9 @@
 return self.frame_zero[0:0]
 
 def get_register_context(self) -> str:
-thread = self.corefile_process.GetSelectedThread()
-if not thread or thread.GetNumFrames() == 0:
+if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
-frame = thread.GetFrameAtIndex(0)
+frame = self.corefile_thread.GetFrameAtIndex(0)
 
 GPRs = None
 registerSet = frame.registers # Returns an SBValueList.
Index: lldb/test/API/functiona

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

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

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/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/test/API/functionalities/scripted_process/Makefile
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.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"
+return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
@@ -109,10 +137,9 @@
 return self.frame_zero[0:0]
 
 def get_register_context(self) -> str:
-thread = self.corefile_process.GetSelectedThread()
-if not thread or thread.GetNumFrames() == 0:
+if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
-frame = thread.GetFrameAtIndex(0)
+frame = self.corefile_thread.GetFrameAtIndex(0)
 
 GPRs = None
 registerSet = frame.registers # Returns an SBValueList.
Index: lldb/test/API/functionalities/scripted_process/main.cpp
==

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

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

Update `invalid_scripted_process.py`


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/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.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"
+return StackCoreScriptedThread.__name__ + ".thread-" + str(self.id)
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
@@ -109,10 +137,9 @@
 return self.frame_zero[0:0]
 
 def get_register_context(self) -> str:
-thread = self.corefile_process.GetSelectedThread()
-if not thread or thread.GetNumFrames() == 0:
+if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
-frame = thread.GetFrameAtIndex(0)
+frame = self.corefile_thread.GetFrameAtIndex(0)
 
 GPRs = No

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

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

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

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

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/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/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -148,6 +148,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;
 
@@ -161,7 +166,7 @@
   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) {
@@ -169,8 +174,11 @@
 break;
   case lldb::eStopReasonBreakpoint: {
 lldb::break_id_t break_id;
+lldb::break_id_t break_loc_id;
 data_dict->GetValueForKeyAsInteger("break_id", break_id,
LLDB_INVALID_BREAK_ID);
+data_dict->GetValueForKeyAsInteger("break_loc_id", break_loc_id,
+   LLDB_INVALID_BREAK_ID);
 stop_info_sp =
 StopInfo::CreateStopReasonWithBreakpointSiteID(*this, break_id);
   } break;
@@ -183,6 +191,13 @@
 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,
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -357,7 +357,14 @@
 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();
+  // TODO: Update
+  lldb::StopInfoSP stop_info;
+
+  lldb::tid_t selected_tid = 0;
+  m_thread_list.SetSele

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

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

Update test.


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
@@ -190,11 +190,11 @@
 self.assertEqual(process.GetNumThreads(), 3)
 thread = process.GetSelectedThread()
 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
@@ -148,6 +148,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;
 
@@ -161,7 +166,7 @@
   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) {
@@ -169,8 +174,11 @@
 break;
   case lldb::eStopReasonBreakpoint: {
 lldb::break_id_t break_id;
+lldb::break_id_t break_loc_id;
 data_dict->GetValueForKeyAsInteger("break_id", break_id,
LLDB_INVALID_BREAK_ID);
+data_dict->GetValueForKeyAsInteger("break_loc_id", break_loc_id,
+   LLDB_INVALID_BREAK_ID);
 stop_info_sp =
 StopInfo::CreateStopReasonWithBreakpointSiteID(*this, break_id);
   } break;
@@ -183,6 +191,13 @@
 stop_info_sp =
 StopInfo::CreateStopReasonWithSignal(*this, si

[Lldb-commits] [lldb] 06c7bdc - [lldb] Specify LLVM target requirements in TestLaunchProcessPosixSpawn

2022-01-11 Thread Dave Lee via lldb-commits

Author: Dave Lee
Date: 2022-01-11T19:00:47-08:00
New Revision: 06c7bdc8f1950dfa0cee19aabf13b8fce859ec98

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

LOG: [lldb] Specify LLVM target requirements in TestLaunchProcessPosixSpawn

Added: 


Modified: 
lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py

Removed: 




diff  --git a/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py 
b/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py
index 4893c137c322..8c3017630b99 100644
--- a/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py
+++ b/lldb/test/API/macosx/posix_spawn/TestLaunchProcessPosixSpawn.py
@@ -41,6 +41,8 @@ def run_arch(self, exe, arch):
 
 @skipUnlessDarwin
 @skipIfDarwinEmbedded
+@skipIfLLVMTargetMissing("AArch64")
+@skipIfLLVMTargetMissing("X86")
 @skipTestIfFn(no_haswell)
 def test_haswell(self):
 self.build()
@@ -50,6 +52,8 @@ def test_haswell(self):
 
 @skipUnlessDarwin
 @skipIfDarwinEmbedded
+@skipIfLLVMTargetMissing("AArch64")
+@skipIfLLVMTargetMissing("X86")
 @skipTestIfFn(no_apple_silicon)
 def test_apple_silicon(self):
 self.build()



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


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

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

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 instanciating
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 drops the `const` qualifier for the
`m_index_id` Thread member, so it can be set later in the ScriptedThread
constructor body. Dropping the `const` qualifier in this case shouldn't
be too problematic, since `m_index_id` doesn't have any getter and can
only be modified by a derived class (`ScriptedThread` in this case).

rdar://87432065

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D117076

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


Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -75,6 +75,8 @@
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
   SetID(tid);
+  process.AssignIndexIDToThread(tid);
+  m_index_id = process.GetNextThreadIndexID(tid);
 }
 
 ScriptedThread::~ScriptedThread() { DestroyThread(); }
Index: lldb/include/lldb/Target/Thread.h
===
--- lldb/include/lldb/Target/Thread.h
+++ lldb/include/lldb/Target/Thread.h
@@ -1243,8 +1243,8 @@
   uint32_t m_stop_info_override_stop_id; // The stop ID containing the last 
time
  // 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.
+  uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
+   /// 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.


Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -75,6 +75,8 @@
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
   SetID(tid);
+  process.AssignIndexIDToThread(tid);
+  m_index_id = process.GetNextThreadIndexID(tid);
 }
 
 ScriptedThread::~ScriptedThread() { DestroyThread(); }
Index: lldb/include/lldb/Target/Thread.h
===
--- lldb/include/lldb/Target/Thread.h
+++ lldb/include/lldb/Target/Thread.h
@@ -1243,8 +1243,8 @@
   uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time
  // 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.
+  uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
+   /// 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.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


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

2022-01-11 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 399172.
mib edited the summary of this revision.

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/ScriptedThread.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -75,6 +75,8 @@
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
   SetID(tid);
+  process.AssignIndexIDToThread(tid);
+  m_index_id = process.GetNextThreadIndexID(tid);
 }
 
 ScriptedThread::~ScriptedThread() { DestroyThread(); }
Index: lldb/include/lldb/Target/Thread.h
===
--- lldb/include/lldb/Target/Thread.h
+++ lldb/include/lldb/Target/Thread.h
@@ -1243,8 +1243,8 @@
   uint32_t m_stop_info_override_stop_id; // The stop ID containing the last 
time
  // 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.
+  uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
+   /// 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.


Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -75,6 +75,8 @@
 
   lldb::tid_t tid = scripted_thread_interface->GetThreadID();
   SetID(tid);
+  process.AssignIndexIDToThread(tid);
+  m_index_id = process.GetNextThreadIndexID(tid);
 }
 
 ScriptedThread::~ScriptedThread() { DestroyThread(); }
Index: lldb/include/lldb/Target/Thread.h
===
--- lldb/include/lldb/Target/Thread.h
+++ lldb/include/lldb/Target/Thread.h
@@ -1243,8 +1243,8 @@
   uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time
  // 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.
+  uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
+   /// 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.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits