[Lldb-commits] [PATCH] D121912: [lldb] Fix ^C handling in IOHandlerProcessSTDIO

2022-03-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

In D121912#3389378 , @DavidSpickett 
wrote:

> Do you know if the pexpect test will cleanup the debugee process if some part 
> of the test fails? Or will we have that hanging around in its infinite loop?

It won't, but the debuggee is not doing an infinite loop. The `while 
(std::getline(std::cin, str))` thingy will terminate when it reaches EOF, which 
will happen when lldb gets killed at the latest (if lldb is still somewhat 
functioning, it will kill the inferior first, when *it* detects the EOF).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121912

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


[Lldb-commits] [lldb] 0f362f9 - [lldb] Remove process->LoadModules call from DynamicLoaderPOSIXDYLD

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T08:58:29+01:00
New Revision: 0f362f9d25fd7b4baca56d3c76c688ca0113813a

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

LOG: [lldb] Remove process->LoadModules call from DynamicLoaderPOSIXDYLD

The call is useless, as any modules loaded there will be removed in
ResolveExecutableModule. Modules will be reloaded again through the
GetLoadedModuleList call in DYLDRendezvous.cpp.

Added: 


Modified: 
lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp 
b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
index 3505ba0b49c9b..12f438f79d043 100644
--- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
@@ -86,10 +86,6 @@ void DynamicLoaderPOSIXDYLD::DidAttach() {
   log, "DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data",
   __FUNCTION__, m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
 
-  // ask the process if it can load any of its own modules
-  auto error = m_process->LoadModules();
-  LLDB_LOG_ERROR(log, std::move(error), "Couldn't load modules: {0}");
-
   ModuleSP executable_sp = GetTargetExecutable();
   ResolveExecutableModule(executable_sp);
   m_rendezvous.UpdateExecutablePath();



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


[Lldb-commits] [lldb] c7fc720 - [lldb] Add more documentation on test variants

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T08:58:29+01:00
New Revision: c7fc7205bb45ee24193c519e9cd2f9f64bdde4ed

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

LOG: [lldb] Add more documentation on test variants

This formalizes some of the discussion on D121631.

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

Added: 


Modified: 
lldb/docs/resources/test.rst

Removed: 




diff  --git a/lldb/docs/resources/test.rst b/lldb/docs/resources/test.rst
index f76800b88f808..258a8083baca8 100644
--- a/lldb/docs/resources/test.rst
+++ b/lldb/docs/resources/test.rst
@@ -185,10 +185,22 @@ of variants. It's very tempting to add more variants 
because it's an easy way
 to increase test coverage. It doesn't scale. It's easy to set up, but increases
 the runtime of the tests and has a large ongoing cost.
 
-The key take away is that the 
diff erent variants don't obviate the need for
-focused tests. So relying on it to test say DWARF5 is a really bad idea.
-Instead you should write tests that check the specific DWARF5 feature, and have
-the variant as a nice-to-have.
+The test variants are most useful when developing a larger feature (e.g. 
support
+for a new DWARF version). The test suite contains a large number of fairly
+generic tests, so running the test suite with the feature enabled is a good way
+to gain confidence that you haven't missed an important aspect. However, this
+genericness makes them poor regression tests. Because it's not clear what a
+specific test covers, a random modification to the test case can make it start
+(or stop) testing a completely 
diff erent part of your feature. And since these
+tests tend to look very similar, it's easy for a simple bug to cause hundreds 
of
+tests to fail in the same way.
+
+For this reason, we recommend using test variants only while developing a new
+feature. This can often be done by running the test suite with 
diff erent
+arguments -- without any modifications to the code. You can create a focused
+test for any bug found that way. Often, there will be many tests failing, but a
+lot of then will have the same root cause.  These tests will be easier to debug
+and will not put undue burden on all other bots and developers.
 
 In conclusion, you'll want to opt for an API test to test the API itself or
 when you need the expressivity, either for the test case itself or for the



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


[Lldb-commits] [lldb] 53e9ee3 - Revert "[lldb] Fix ^C handling in IOHandlerProcessSTDIO"

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T08:58:30+01:00
New Revision: 53e9ee3027dbbee79585335f608bcf5b8f668d0a

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

LOG: Revert "[lldb] Fix ^C handling in IOHandlerProcessSTDIO"

This reverts commit f93d861349f923f6b7ca1a425d3632eec1ff2a72 -- looks
like a bad application of `patch -p`

Added: 


Modified: 


Removed: 
lldb/lldb/test/API/iohandler/sigint/Makefile
lldb/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
lldb/lldb/test/API/iohandler/sigint/cat.cpp



diff  --git a/lldb/lldb/test/API/iohandler/sigint/Makefile 
b/lldb/lldb/test/API/iohandler/sigint/Makefile
deleted file mode 100644
index 22f1051530f87..0
--- a/lldb/lldb/test/API/iohandler/sigint/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-include Makefile.rules

diff  --git 
a/lldb/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py 
b/lldb/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
deleted file mode 100644
index f1bd76e348caf..0
--- a/lldb/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
+++ /dev/null
@@ -1,42 +0,0 @@
-"""
-Test sending SIGINT Process IOHandler
-"""
-
-import os
-
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.lldbpexpect import PExpectTest
-
-class TestCase(PExpectTest):
-
-mydir = TestBase.compute_mydir(__file__)
-
-def test(self):
-self.build(dictionary={"CXX_SOURCES":"cat.cpp"})
-self.launch(executable=self.getBuildArtifact(), timeout=5)
-
-self.child.sendline("process launch")
-self.child.expect("Process .* launched")
-
-self.child.sendline("Hello cat")
-self.child.expect_exact("read: Hello cat")
-
-self.child.sendintr()
-self.child.expect("Process .* stopped")
-self.expect_prompt()
-
-self.expect("bt", substrs=["input_copy_loop"])
-
-self.child.sendline("continue")
-self.child.expect("Process .* resuming")
-
-self.child.sendline("Goodbye cat")
-self.child.expect_exact("read: Goodbye cat")
-
-self.child.sendeof()
-self.child.expect("Process .* exited")
-self.expect_prompt()
-
-self.quit()

diff  --git a/lldb/lldb/test/API/iohandler/sigint/cat.cpp 
b/lldb/lldb/test/API/iohandler/sigint/cat.cpp
deleted file mode 100644
index 5a3d9380e3826..0
--- a/lldb/lldb/test/API/iohandler/sigint/cat.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include 
-
-void input_copy_loop() {
-  std::string str;
-  while (std::getline(std::cin, str))
-std::cout << "read: " << str << std::endl;
-}
-
-int main() {
-  input_copy_loop();
-  return 0;
-}



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


[Lldb-commits] [lldb] 14bd14f - [lldb] Fix ^C handling in IOHandlerProcessSTDIO

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T08:58:30+01:00
New Revision: 14bd14f9f92f9f5eff43ec3a977b127dea1cb521

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

LOG: [lldb] Fix ^C handling in IOHandlerProcessSTDIO

D120762 accidentally moved the interrupt check into the block which was
reading stdio. This meant that a ^C only took effect after a regular
character has been pressed.

This patch fixes that and adds a (pexpect) test.

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

Added: 
lldb/test/API/iohandler/sigint/Makefile
lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
lldb/test/API/iohandler/sigint/cat.cpp

Modified: 
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 122f20b2a751e..54a19833c8a65 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -4361,18 +4361,18 @@ class IOHandlerProcessSTDIO : public IOHandler {
 break;
 } else
   break;
+  }
 
-if (select_helper.FDIsSetRead(pipe_read_fd)) {
-  size_t bytes_read;
-  // Consume the interrupt byte
-  Status error = m_pipe.Read(&ch, 1, bytes_read);
-  if (error.Success()) {
-if (ch == 'q')
-  break;
-if (ch == 'i')
-  if (StateIsRunningState(m_process->GetState()))
-m_process->SendAsyncInterrupt();
-  }
+  if (select_helper.FDIsSetRead(pipe_read_fd)) {
+size_t bytes_read;
+// Consume the interrupt byte
+Status error = m_pipe.Read(&ch, 1, bytes_read);
+if (error.Success()) {
+  if (ch == 'q')
+break;
+  if (ch == 'i')
+if (StateIsRunningState(m_process->GetState()))
+  m_process->SendAsyncInterrupt();
 }
   }
 }

diff  --git a/lldb/test/API/iohandler/sigint/Makefile 
b/lldb/test/API/iohandler/sigint/Makefile
new file mode 100644
index 0..22f1051530f87
--- /dev/null
+++ b/lldb/test/API/iohandler/sigint/Makefile
@@ -0,0 +1 @@
+include Makefile.rules

diff  --git a/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py 
b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
new file mode 100644
index 0..f1bd76e348caf
--- /dev/null
+++ b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
@@ -0,0 +1,42 @@
+"""
+Test sending SIGINT Process IOHandler
+"""
+
+import os
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.lldbpexpect import PExpectTest
+
+class TestCase(PExpectTest):
+
+mydir = TestBase.compute_mydir(__file__)
+
+def test(self):
+self.build(dictionary={"CXX_SOURCES":"cat.cpp"})
+self.launch(executable=self.getBuildArtifact(), timeout=5)
+
+self.child.sendline("process launch")
+self.child.expect("Process .* launched")
+
+self.child.sendline("Hello cat")
+self.child.expect_exact("read: Hello cat")
+
+self.child.sendintr()
+self.child.expect("Process .* stopped")
+self.expect_prompt()
+
+self.expect("bt", substrs=["input_copy_loop"])
+
+self.child.sendline("continue")
+self.child.expect("Process .* resuming")
+
+self.child.sendline("Goodbye cat")
+self.child.expect_exact("read: Goodbye cat")
+
+self.child.sendeof()
+self.child.expect("Process .* exited")
+self.expect_prompt()
+
+self.quit()

diff  --git a/lldb/test/API/iohandler/sigint/cat.cpp 
b/lldb/test/API/iohandler/sigint/cat.cpp
new file mode 100644
index 0..5a3d9380e3826
--- /dev/null
+++ b/lldb/test/API/iohandler/sigint/cat.cpp
@@ -0,0 +1,12 @@
+#include 
+
+void input_copy_loop() {
+  std::string str;
+  while (std::getline(std::cin, str))
+std::cout << "read: " << str << std::endl;
+}
+
+int main() {
+  input_copy_loop();
+  return 0;
+}



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


[Lldb-commits] [PATCH] D121900: [lldb] Add more documentation on test variants

2022-03-18 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7fc7205bb45: [lldb] Add more documentation on test variants 
(authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121900

Files:
  lldb/docs/resources/test.rst


Index: lldb/docs/resources/test.rst
===
--- lldb/docs/resources/test.rst
+++ lldb/docs/resources/test.rst
@@ -185,10 +185,22 @@
 to increase test coverage. It doesn't scale. It's easy to set up, but increases
 the runtime of the tests and has a large ongoing cost.
 
-The key take away is that the different variants don't obviate the need for
-focused tests. So relying on it to test say DWARF5 is a really bad idea.
-Instead you should write tests that check the specific DWARF5 feature, and have
-the variant as a nice-to-have.
+The test variants are most useful when developing a larger feature (e.g. 
support
+for a new DWARF version). The test suite contains a large number of fairly
+generic tests, so running the test suite with the feature enabled is a good way
+to gain confidence that you haven't missed an important aspect. However, this
+genericness makes them poor regression tests. Because it's not clear what a
+specific test covers, a random modification to the test case can make it start
+(or stop) testing a completely different part of your feature. And since these
+tests tend to look very similar, it's easy for a simple bug to cause hundreds 
of
+tests to fail in the same way.
+
+For this reason, we recommend using test variants only while developing a new
+feature. This can often be done by running the test suite with different
+arguments -- without any modifications to the code. You can create a focused
+test for any bug found that way. Often, there will be many tests failing, but a
+lot of then will have the same root cause.  These tests will be easier to debug
+and will not put undue burden on all other bots and developers.
 
 In conclusion, you'll want to opt for an API test to test the API itself or
 when you need the expressivity, either for the test case itself or for the


Index: lldb/docs/resources/test.rst
===
--- lldb/docs/resources/test.rst
+++ lldb/docs/resources/test.rst
@@ -185,10 +185,22 @@
 to increase test coverage. It doesn't scale. It's easy to set up, but increases
 the runtime of the tests and has a large ongoing cost.
 
-The key take away is that the different variants don't obviate the need for
-focused tests. So relying on it to test say DWARF5 is a really bad idea.
-Instead you should write tests that check the specific DWARF5 feature, and have
-the variant as a nice-to-have.
+The test variants are most useful when developing a larger feature (e.g. support
+for a new DWARF version). The test suite contains a large number of fairly
+generic tests, so running the test suite with the feature enabled is a good way
+to gain confidence that you haven't missed an important aspect. However, this
+genericness makes them poor regression tests. Because it's not clear what a
+specific test covers, a random modification to the test case can make it start
+(or stop) testing a completely different part of your feature. And since these
+tests tend to look very similar, it's easy for a simple bug to cause hundreds of
+tests to fail in the same way.
+
+For this reason, we recommend using test variants only while developing a new
+feature. This can often be done by running the test suite with different
+arguments -- without any modifications to the code. You can create a focused
+test for any bug found that way. Often, there will be many tests failing, but a
+lot of then will have the same root cause.  These tests will be easier to debug
+and will not put undue burden on all other bots and developers.
 
 In conclusion, you'll want to opt for an API test to test the API itself or
 when you need the expressivity, either for the test case itself or for the
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] a4d6de2 - [lldb] Fix TestProcessIOHandlerInterrupt.py for macos

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T11:51:55+01:00
New Revision: a4d6de2031ad2f92d399fc8d1b1301229ed8255b

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

LOG: [lldb] Fix TestProcessIOHandlerInterrupt.py for macos

On darwin, we don't completely suppress the signal used to interrupt the
inferior. The underlying read syscall returns EINTR, which causes premature
termination of the input loop.

Work around that by hand-rolling an EINTR-resistant version of getline.

Added: 


Modified: 
lldb/test/API/iohandler/sigint/cat.cpp

Removed: 




diff  --git a/lldb/test/API/iohandler/sigint/cat.cpp 
b/lldb/test/API/iohandler/sigint/cat.cpp
index 5a3d9380e3826..7e12cf7df7e58 100644
--- a/lldb/test/API/iohandler/sigint/cat.cpp
+++ b/lldb/test/API/iohandler/sigint/cat.cpp
@@ -1,9 +1,25 @@
-#include 
+#include 
+#include 
+#include 
+
+std::string getline() {
+  std::string result;
+  while (true) {
+int r;
+char c;
+do
+  r = read(fileno(stdin), &c, 1);
+while (r == -1 && errno == EINTR);
+if (r <= 0 || c == '\n')
+  return result;
+result += c;
+  }
+}
 
 void input_copy_loop() {
   std::string str;
-  while (std::getline(std::cin, str))
-std::cout << "read: " << str << std::endl;
+  while (str = getline(), !str.empty())
+printf("read: %s\n", str.c_str());
 }
 
 int main() {



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


[Lldb-commits] [lldb] af4da4f - [lldb] Increase timeout in TestProcessIOHandlerInterrupt

2022-03-18 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-03-18T12:14:10+01:00
New Revision: af4da4f995f830aee6fcd598c3c07ecaff89

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

LOG: [lldb] Increase timeout in TestProcessIOHandlerInterrupt

The small value was not meant to be checked in.

Added: 


Modified: 
lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py

Removed: 




diff  --git a/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py 
b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
index f1bd76e348caf..707c84eeacdac 100644
--- a/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
+++ b/lldb/test/API/iohandler/sigint/TestProcessIOHandlerInterrupt.py
@@ -15,7 +15,7 @@ class TestCase(PExpectTest):
 
 def test(self):
 self.build(dictionary={"CXX_SOURCES":"cat.cpp"})
-self.launch(executable=self.getBuildArtifact(), timeout=5)
+self.launch(executable=self.getBuildArtifact())
 
 self.child.sendline("process launch")
 self.child.expect("Process .* launched")



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


[Lldb-commits] [PATCH] D121999: [lldb][AArch64] Update disassembler feature list and add tests for all extensions

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

This updates the disassembler to enable every optional extension.
Previously we had added things that we added "support" for in lldb.
(where support means significant work like new registers, fault types, etc.)

Something like TME (transactional memory) wasn't added because
there are no new lldb features for it. However we should still be
disassembling the instructions.

So I went through the AArch64 extensions and added all the missing
ones. The new test is more documentation than anything but even so
it's an improvement.

The source file is not used in the test directly but I'm committing
it in case we need to regenerate it (e.g. formatting changes).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121999

Files:
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  
lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/TestDisassembleAArch64Extensions.py
  lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/extensions.s

Index: lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/extensions.s
===
--- /dev/null
+++ lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/extensions.s
@@ -0,0 +1,55 @@
+// This file is included in case we need to regenerate the test case. It is not used for
+// the test directly because we can't be sure that the test compiler supports all of this.
+//
+// Extensions are in the same order as llvm/include/llvm/Support/AArch64TargetParser.def.
+// Where the extension didn't add new instructions but did add sysregs, we use one of those.
+//
+// To regenerate the test, compile with:
+// ./bin/clang -c ../llvm-project/lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/extensions.s -o /tmp/test.o -march=armv8-a+tme+memtag+crc+lse+rdm+sm4+sha3+aes+dotprod+fp16+fp16fml+sve+sve2+sve2-aes+sve2-sm4+sve2-sha3+sve2-bitperm+profile+rcpc+ssbs+sb+predres+bf16+mops+hbc+sme+sme-i64+sme-f64+flagm+pauth+brbe+ls64+f64mm+f32mm+i8mm+rng
+//
+// Then use llvm-objdump with equivalent features to get the encodings:
+// ./bin/llvm-objdump -d /tmp/test.o --mattr=+tme,+mte,+crc,+lse,+rdm,+sm4,+sha3,+aes,+dotprod,+fullfp16,+fp16fml,+sve,+sve2,+sve2-aes,+sve2-sm4,+sve2-sha3,+sve2-bitperm,+spe,+rcpc,+ssbs,+sb,+predres,+bf16,+mops,+hbc,+sme,+sme-i64,+sme-f64,+flagm,+pauth,+brbe,+ls64,+f64mm,+f32mm,+i8mm,+rand
+// (some names change because their backend feature name is different)
+
+crc32b w0, w0, w0   // CRC
+ldaddab w0, w0, [sp]// LSE
+sqrdmlah v0.4h, v1.4h, v2.4h// RDM
+// CRYPTO enables a combination of other features
+sm4e v0.4s, v0.4s   // SM4
+bcax v0.16b, v0.16b, v0.16b, v0.16b // SHA3
+sha256h q0, q0, v0.4s   // SHA256
+aesd v0.16b, v0.16b // AES
+sdot v0.2s, v1.8b, v2.8b// DOTPROD
+fcvt d0, s0 // FP
+addp v0.4s, v0.4s, v0.4s// SIMD (neon)
+fabs h1, h2 // FP16
+fmlal v0.2s, v1.2h, v2.2h   // FP16FML
+psb csync   // PROFILE/SPE
+msr erxpfgctl_el1, x0   // RAS
+abs z31.h, p7/m, z31.h  // SVE
+sqdmlslbt z0.d, z1.s, z31.s // SVE2
+aesd z0.b, z0.b, z31.b  // SVE2AES
+sm4e z0.s, z0.s, z0.s   // SVE2SM4
+rax1 z0.d, z0.d, z0.d   // SVE2SHA3
+bdep z0.b, z1.b, z31.b  // SVE2BITPERM
+ldaprb w0, [x0, #0] // RCPC
+mrs x0, rndr// RAND
+irg x0, x0  // MTE
+mrs x2, ssbs// SSBS
+sb  // SB
+cfp rctx, x0// PREDRES
+bfdot v2.2s, v3.4h, v4.4h   // BF16
+smmla v1.4s, v16.16b, v31.16b   // I8MM
+fmmla z0.s, z1.s, z2.s  // F32MM
+fmmla z0.d, z1.d, z2.d  // F64MM
+tcommit // TME
+ld64b x0, [x13] // LS64
+brb iall// BRBE
+pacia x0, x1// PAUTH
+cfinv   // FLAGM
+addha za0.s, p0/m, p0/m, z0.s   // SME
+fmopa za0.d, p0/m, p0/m, z0.d, z0.d // SMEF64
+addha za0.d, p0/m, p0/m, z0.d   // SMEI64
+lbl: bc.eq lbl  // HBC
+cpyfp [x0]!, [x1]!, x2! // MOPS
+mrs x0, pmccntr_el0 // PERFMON
Index: lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/TestDisassembleAArch64Extensions.py
===
--- /dev/null
+++ lldb/test/API/python_api/disassemble-raw-data/aarch64-extensions/TestDisassembleAArch64Extensions.py
@@ -0,0 +1,141 @@
+"""
+Use lldb Python API to disassemble raw byte

[Lldb-commits] [PATCH] D121999: [lldb][AArch64] Update disassembler feature list and add tests for all extensions

2022-03-18 Thread Pavel Labath via Phabricator via lldb-commits
labath added a comment.

Can you make this a shell test? Something like llvm-mc | lldb -o "disassemble 
-n function_with_funky_insns" | FileCheck ?

Presumably, llvm-mc can assemble anything that we are able to disassemble...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121999

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


[Lldb-commits] [PATCH] D121999: [lldb][AArch64] Update disassembler feature list and add tests for all extensions

2022-03-18 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added a comment.

> Can you make this a shell test?

Great idea, I'll do that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121999

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


[Lldb-commits] [lldb] 9f052f3 - [lldb] Require x86 target for NativePDB test

2022-03-18 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2022-03-18T12:31:03Z
New Revision: 9f052f3dd2d8b59dde6278aa58c6e4477c2fdef6

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

LOG: [lldb] Require x86 target for NativePDB test

This test would fail if you only build for example,
just the AArch64 backend, due to the x86 triple.

Added: 


Modified: 
lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s

Removed: 




diff  --git a/lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s 
b/lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s
index e2b5da4a4c17d..35dda0a3c1c64 100644
--- a/lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s
+++ b/lldb/test/Shell/SymbolFile/NativePDB/local-variables-registers.s
@@ -1,5 +1,5 @@
 # clang-format off
-# REQUIRES: lld
+# 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 
/base:0x14000



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


[Lldb-commits] [PATCH] D121999: [lldb][AArch64] Update disassembler feature list and add tests for all extensions

2022-03-18 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 416476.
DavidSpickett added a comment.

Switch to a shell test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121999

Files:
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s

Index: lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
===
--- /dev/null
+++ lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
@@ -0,0 +1,101 @@
+# REQUIRES: aarch64
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnueabihf %s -o %t \
+# RUN: --mattr=+tme,+mte,+crc,+lse,+rdm,+sm4,+sha3,+aes,+dotprod,+fullfp16 \
+# RUN: --mattr=+fp16fml,+sve,+sve2,+sve2-aes,+sve2-sm4,+sve2-sha3,+sve2-bitperm \
+# RUN: --mattr=+spe,+rcpc,+ssbs,+sb,+predres,+bf16,+mops,+hbc,+sme,+sme-i64 \
+# RUN: --mattr=+sme-f64,+flagm,+pauth,+brbe,+ls64,+f64mm,+f32mm,+i8mm,+rand
+# RUN: %lldb %t -o "disassemble -n fn" -o exit 2>&1 | FileCheck %s
+
+.globl  fn
+.type   fn, @function
+fn:
+  // These are in the same order as llvm/include/llvm/Support/AArch64TargetParser.def
+  crc32b w0, w0, w0   // CRC
+  ldaddab w0, w0, [sp]// LSE
+  sqrdmlah v0.4h, v1.4h, v2.4h// RDM
+  // CRYPTO enables a combination of other features
+  sm4e v0.4s, v0.4s   // SM4
+  bcax v0.16b, v0.16b, v0.16b, v0.16b // SHA3
+  sha256h q0, q0, v0.4s   // SHA256
+  aesd v0.16b, v0.16b // AES
+  sdot v0.2s, v1.8b, v2.8b// DOTPROD
+  fcvt d0, s0 // FP
+  addp v0.4s, v0.4s, v0.4s// SIMD (neon)
+  fabs h1, h2 // FP16
+  fmlal v0.2s, v1.2h, v2.2h   // FP16FML
+  psb csync   // PROFILE/SPE
+  msr erxpfgctl_el1, x0   // RAS
+  abs z31.h, p7/m, z31.h  // SVE
+  sqdmlslbt z0.d, z1.s, z31.s // SVE2
+  aesd z0.b, z0.b, z31.b  // SVE2AES
+  sm4e z0.s, z0.s, z0.s   // SVE2SM4
+  rax1 z0.d, z0.d, z0.d   // SVE2SHA3
+  bdep z0.b, z1.b, z31.b  // SVE2BITPERM
+  ldaprb w0, [x0, #0] // RCPC
+  mrs x0, rndr// RAND
+  irg x0, x0  // MTE
+  mrs x2, ssbs// SSBS
+  sb  // SB
+  cfp rctx, x0// PREDRES
+  bfdot v2.2s, v3.4h, v4.4h   // BF16
+  smmla v1.4s, v16.16b, v31.16b   // I8MM
+  fmmla z0.s, z1.s, z2.s  // F32MM
+  fmmla z0.d, z1.d, z2.d  // F64MM
+  tcommit // TME
+  ld64b x0, [x13] // LS64
+  brb iall// BRBE
+  pacia x0, x1// PAUTH
+  cfinv   // FLAGM
+  addha za0.s, p0/m, p0/m, z0.s   // SME
+  fmopa za0.d, p0/m, p0/m, z0.d, z0.d // SMEF64
+  addha za0.d, p0/m, p0/m, z0.d   // SMEI64
+lbl:
+  bc.eq lbl   // HBC
+  cpyfp [x0]!, [x1]!, x2! // MOPS
+  mrs x0, pmccntr_el0 // PERFMON
+.fn_end:
+  .size   fn, .fn_end-fn
+
+# CHECK: command-disassemble-aarch64-extensions.s.tmp`fn:
+# CHECK: crc32b w0, w0, w0
+# CHECK: ldaddab w0, w0, [sp]
+# CHECK: sqrdmlah v0.4h, v1.4h, v2.4h
+# CHECK: sm4e   v0.4s, v0.4s
+# CHECK: bcax   v0.16b, v0.16b, v0.16b, v0.16b
+# CHECK: sha256h q0, q0, v0.4s
+# CHECK: aesd   v0.16b, v0.16b
+# CHECK: sdot   v0.2s, v1.8b, v2.8b
+# CHECK: fcvt   d0, s0
+# CHECK: addp   v0.4s, v0.4s, v0.4s
+# CHECK: fabs   h1, h2
+# CHECK: fmlal  v0.2s, v1.2h, v2.2h
+# CHECK: psbcsync
+# CHECK: msrERXPFGCTL_EL1, x0
+# CHECK: absz31.h, p7/m, z31.h
+# CHECK: sqdmlslbt z0.d, z1.s, z31.s
+# CHECK: aesd   z0.b, z0.b, z31.b
+# CHECK: sm4e   z0.s, z0.s, z0.s
+# CHECK: rax1   z0.d, z0.d, z0.d
+# CHECK: bdep   z0.b, z1.b, z31.b
+# CHECK: ldaprb w0, [x0]
+# CHECK: mrsx0, RNDR
+# CHECK: irgx0, x0
+# CHECK: mrsx2, SSBS
+# CHECK: sb
+# CHECK: cfprctx, x0
+# CHECK: bfdot  v2.2s, v3.4h, v4.4h
+# CHECK: smmla  v1.4s, v16.16b, v31.16b
+# CHECK: fmmla  z0.s, z1.s, z2.s
+# CHECK: fmmla  z0.d, z1.d, z2.d
+# CHECK: tcommit
+# CHECK: ld64b  x0, [x13]
+# CHECK: brbiall
+# CHECK: pacia  x0, x1
+# CHECK: cfinv
+# CHECK: addha  za0.s, p0/m, p0/m, z0.s
+# CHECK: fmopa  za0.d, p0/m, p0/m, z0.d, z0.d
+# CHECK: addha  za0.d, p0/m, p0/m, z0.d
+# CHECK: bc.eq  0x98
+# CHECK: cpyfp  [x0]!, [x1]!, x2!
+# CHECK: mrsx0, PMCCNTR_EL0
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -1180,7 +1180,9 @@
   // If any AArch64 variant, enable latest ISA with any optional

[Lldb-commits] [PATCH] D121999: [lldb][AArch64] Update disassembler feature list and add tests for all extensions

2022-03-18 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett updated this revision to Diff 416477.
DavidSpickett added a comment.

Add comment explaining test purpose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121999

Files:
  lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
  lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s

Index: lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
===
--- /dev/null
+++ lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
@@ -0,0 +1,104 @@
+# REQUIRES: aarch64
+
+# This checks that lldb's disassembler enables every extension that an AArch64
+# target could have.
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux-gnueabihf %s -o %t \
+# RUN: --mattr=+tme,+mte,+crc,+lse,+rdm,+sm4,+sha3,+aes,+dotprod,+fullfp16 \
+# RUN: --mattr=+fp16fml,+sve,+sve2,+sve2-aes,+sve2-sm4,+sve2-sha3,+sve2-bitperm \
+# RUN: --mattr=+spe,+rcpc,+ssbs,+sb,+predres,+bf16,+mops,+hbc,+sme,+sme-i64 \
+# RUN: --mattr=+sme-f64,+flagm,+pauth,+brbe,+ls64,+f64mm,+f32mm,+i8mm,+rand
+# RUN: %lldb %t -o "disassemble -n fn" -o exit 2>&1 | FileCheck %s
+
+.globl  fn
+.type   fn, @function
+fn:
+  // These are in the same order as llvm/include/llvm/Support/AArch64TargetParser.def
+  crc32b w0, w0, w0   // CRC
+  ldaddab w0, w0, [sp]// LSE
+  sqrdmlah v0.4h, v1.4h, v2.4h// RDM
+  // CRYPTO enables a combination of other features
+  sm4e v0.4s, v0.4s   // SM4
+  bcax v0.16b, v0.16b, v0.16b, v0.16b // SHA3
+  sha256h q0, q0, v0.4s   // SHA256
+  aesd v0.16b, v0.16b // AES
+  sdot v0.2s, v1.8b, v2.8b// DOTPROD
+  fcvt d0, s0 // FP
+  addp v0.4s, v0.4s, v0.4s// SIMD (neon)
+  fabs h1, h2 // FP16
+  fmlal v0.2s, v1.2h, v2.2h   // FP16FML
+  psb csync   // PROFILE/SPE
+  msr erxpfgctl_el1, x0   // RAS
+  abs z31.h, p7/m, z31.h  // SVE
+  sqdmlslbt z0.d, z1.s, z31.s // SVE2
+  aesd z0.b, z0.b, z31.b  // SVE2AES
+  sm4e z0.s, z0.s, z0.s   // SVE2SM4
+  rax1 z0.d, z0.d, z0.d   // SVE2SHA3
+  bdep z0.b, z1.b, z31.b  // SVE2BITPERM
+  ldaprb w0, [x0, #0] // RCPC
+  mrs x0, rndr// RAND
+  irg x0, x0  // MTE
+  mrs x2, ssbs// SSBS
+  sb  // SB
+  cfp rctx, x0// PREDRES
+  bfdot v2.2s, v3.4h, v4.4h   // BF16
+  smmla v1.4s, v16.16b, v31.16b   // I8MM
+  fmmla z0.s, z1.s, z2.s  // F32MM
+  fmmla z0.d, z1.d, z2.d  // F64MM
+  tcommit // TME
+  ld64b x0, [x13] // LS64
+  brb iall// BRBE
+  pacia x0, x1// PAUTH
+  cfinv   // FLAGM
+  addha za0.s, p0/m, p0/m, z0.s   // SME
+  fmopa za0.d, p0/m, p0/m, z0.d, z0.d // SMEF64
+  addha za0.d, p0/m, p0/m, z0.d   // SMEI64
+lbl:
+  bc.eq lbl   // HBC
+  cpyfp [x0]!, [x1]!, x2! // MOPS
+  mrs x0, pmccntr_el0 // PERFMON
+.fn_end:
+  .size   fn, .fn_end-fn
+
+# CHECK: command-disassemble-aarch64-extensions.s.tmp`fn:
+# CHECK: crc32b w0, w0, w0
+# CHECK: ldaddab w0, w0, [sp]
+# CHECK: sqrdmlah v0.4h, v1.4h, v2.4h
+# CHECK: sm4e   v0.4s, v0.4s
+# CHECK: bcax   v0.16b, v0.16b, v0.16b, v0.16b
+# CHECK: sha256h q0, q0, v0.4s
+# CHECK: aesd   v0.16b, v0.16b
+# CHECK: sdot   v0.2s, v1.8b, v2.8b
+# CHECK: fcvt   d0, s0
+# CHECK: addp   v0.4s, v0.4s, v0.4s
+# CHECK: fabs   h1, h2
+# CHECK: fmlal  v0.2s, v1.2h, v2.2h
+# CHECK: psbcsync
+# CHECK: msrERXPFGCTL_EL1, x0
+# CHECK: absz31.h, p7/m, z31.h
+# CHECK: sqdmlslbt z0.d, z1.s, z31.s
+# CHECK: aesd   z0.b, z0.b, z31.b
+# CHECK: sm4e   z0.s, z0.s, z0.s
+# CHECK: rax1   z0.d, z0.d, z0.d
+# CHECK: bdep   z0.b, z1.b, z31.b
+# CHECK: ldaprb w0, [x0]
+# CHECK: mrsx0, RNDR
+# CHECK: irgx0, x0
+# CHECK: mrsx2, SSBS
+# CHECK: sb
+# CHECK: cfprctx, x0
+# CHECK: bfdot  v2.2s, v3.4h, v4.4h
+# CHECK: smmla  v1.4s, v16.16b, v31.16b
+# CHECK: fmmla  z0.s, z1.s, z2.s
+# CHECK: fmmla  z0.d, z1.d, z2.d
+# CHECK: tcommit
+# CHECK: ld64b  x0, [x13]
+# CHECK: brbiall
+# CHECK: pacia  x0, x1
+# CHECK: cfinv
+# CHECK: addha  za0.s, p0/m, p0/m, z0.s
+# CHECK: fmopa  za0.d, p0/m, p0/m, z0.d, z0.d
+# CHECK: addha  za0.d, p0/m, p0/m, z0.d
+# CHECK: bc.eq  0x98
+# CHECK: cpyfp  [x0]!, [x1]!, x2!
+# CHECK: mrsx0, PMCCNTR_EL0
Index: lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
===
--- lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ lldb/source/Plugins/Disassembler

[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

2022-03-18 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 416506.
zrthxn added a comment.
Herald added a subscriber: arphaman.

Referenced IPT doc from main page


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

Files:
  lldb/docs/index.rst
  lldb/docs/use/intel_pt.rst

Index: lldb/docs/use/intel_pt.rst
===
--- /dev/null
+++ lldb/docs/use/intel_pt.rst
@@ -0,0 +1,209 @@
+Tracing with Intel Processor Trace (Intel PT)
+=
+
+.. contents::
+  :local:
+
+Intel PT is a technology available in modern Intel CPUs that allows efficient 
+tracing of all the instructions executed by a process. LLDB can collect traces and dump 
+them using its symbolication stack. You can read more here https://easyperf.net/blog/2019/08/23/Intel-Processor-Trace.
+
+Prerequisites
+-
+
+Confirm that your CPU supports Intel PT (see https://www.intel.com/content/www/us/en/support/articles/56730/processors.html) 
+and that your operating system is Linux.
+
+Check for the existence of this particular file on your Linux system
+:: 
+
+  $ cat /sys/bus/event_source/devices/intel_pt/type
+
+The output should be a number. Otherwise, try upgrading your kernel.
+
+
+Build Instructions
+--
+
+Clone and build the low level Intel PT decoder library [LibIPT library](https://github.com/intel/libipt).
+:: 
+
+  $ git clone g...@github.com:intel/libipt.git
+  $ mkdir libipt-build
+  $ cmake -S libipt -B libipt-build
+  $ cd libipt-build
+  $ make
+
+This will generate a few files in the `/lib` and `/libipt/include` directories.
+
+Configure and build LLDB with Intel PT support
+:: 
+
+  $ cmake \
+  -DLLDB_BUILD_INTEL_PT=ON \
+  -DLIBIPT_INCLUDE_PATH="/libipt/include" \
+  -DLIBIPT_LIBRARY_PATH="/lib" \
+  ... other common configuration parameters 
+
+:: 
+
+  $ cd  && ninja lldb lldb-server # if using Ninja
+
+
+How to Use
+--
+
+When you are debugging a process, you can turn on intel-pt tracing, which will “record” all the instructions 
+that the process will execute. After turning it on, you can continue debugging, and at any breakpoint, 
+you can inspect the instruction list.
+ 
+For example:
+::
+  lldb 
+  > b main
+  > run
+  > process trace start # start tracing on all threads, including future ones
+  # keep debugging until you hit a breakpoint
+  
+  > thread trace dump instructions
+  # this should output something like
+
+  thread #2: tid = 2861133, total instructions = 5305673
+libc.so.6`__GI___libc_read + 45 at read.c:25:1
+  [4962255] 0x7fffeb64c63dsubq   $0x10, %rsp
+  [4962256] 0x7fffeb64c641movq   %rdi, -0x18(%rbp)
+libc.so.6`__GI___libc_read + 53 [inlined] __libc_read at read.c:26:10
+  [4962257] 0x7fffeb64c645callq  0x7fffeb66b640; __libc_enable_asynccancel
+libc.so.6`__libc_enable_asynccancel
+  [4962258] 0x7fffeb66b640movl   %fs:0x308, %eax
+libc.so.6`__libc_enable_asynccancel + 8
+  [4962259] 0x7fffeb66b648movl   %eax, %r11d
+
+  # you can keep pressing ENTER to see more and more instructions
+ 
+The number between brackets is the instruction index, and by default the current thread will be picked.
+ 
+Configuring the trace size
+--
+ 
+The CPU stores the instruction list in a compressed format in a ring buffer, which keeps the latest information. By default, LLDB uses a buffer of 4KB per thread, but you can change it by running. The size must be a power of 2 and at least 4KB.
+::
+  thread trace start all -s 
+ 
+For reference, a 1MB trace buffer can easily store around 5M instructions.
+ 
+Printing more instructions
+--
+ 
+If you want to dump more instructions at a time, you can run
+::
+  thread trace dump instructions -c 
+ 
+Printing the instructions of another thread
+---
+
+By default the current thread will be picked when dumping instructions, but you can do
+:: 
+  thread trace dump instructions <#thread index>
+  #e.g.
+  thread trace dump instructions 8
+ 
+to select another thread.
+ 
+Crash Analysis
+--
+ 
+What if you are debugging + tracing a process that crashes? Then you can just do
+::
+  thread trace dump instructions
+ 
+To inspect how it crashed! There's nothing special that you need to do. For example
+:: 
+* thread #1, name = 'a.out', stop reason = signal SIGFPE: integer divide by zero
+frame #0: 0x004009f1 a.out`main at main.cpp:8:14
+  6   int x;
+  7   cin >> x;
+   -> 8   cout << 12 / x << endl;
+  9   return 0;
+  10  }
+(lldb) thread trace dump instructions -c 5
+thread #1: tid = 604302, total instructions = 8388
+  libstdc++.so.6`std::istream::operator>>(int&) + 181
+[8383] 0x77b41665p

[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

2022-03-18 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn added a comment.

Here is the screenshot as well as the HTML file
The screenshot doesn't have the CSS theming...

F22478403: 
_home_alisamar_Desktop_lldb-build_tools_lldb_docs_html_use_intel_pt.html.png 


F22478406: intel_pt.html 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

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


[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

2022-03-18 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

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


[Lldb-commits] [lldb] 453f8c8 - [lldb] Remove lldb/lldb subdir created by wrong patch level

2022-03-18 Thread Jonas Devlieghere via lldb-commits

Author: Jonas Devlieghere
Date: 2022-03-18T09:06:15-07:00
New Revision: 453f8c87ff20932c79890d93474e862d52f6fe46

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

LOG: [lldb] Remove lldb/lldb subdir created by wrong patch level

Bad application of patch -p.

Added: 


Modified: 


Removed: 
lldb/lldb/test/API/functionalities/gdb_remote_client/TestPlatformMacOSX.py
lldb/lldb/unittests/Platform/PlatformMacOSXTest.cpp



diff  --git 
a/lldb/lldb/test/API/functionalities/gdb_remote_client/TestPlatformMacOSX.py 
b/lldb/lldb/test/API/functionalities/gdb_remote_client/TestPlatformMacOSX.py
deleted file mode 100644
index 3d3de0a9707c0..0
--- a/lldb/lldb/test/API/functionalities/gdb_remote_client/TestPlatformMacOSX.py
+++ /dev/null
@@ -1,60 +0,0 @@
-import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
-from lldbsuite.test.gdbclientutils import *
-from lldbsuite.test.lldbgdbclient import GDBRemoteTestBase
-
-
-class TestPlatformMacOSX(GDBRemoteTestBase):
-
-mydir = TestBase.compute_mydir(__file__)
-
-class MyResponder(MockGDBServerResponder):
-
-def __init__(self, host):
-self.host_ostype = host
-MockGDBServerResponder.__init__(self)
-
-def respond(self, packet):
-if packet == "qProcessInfo":
-return self.qProcessInfo()
-return MockGDBServerResponder.respond(self, packet)
-
-def qHostInfo(self):
-return 
"cputype:16777223;cpusubtype:2;ostype:%s;vendor:apple;os_version:10.15.4;maccatalyst_version:13.4;endian:little;ptrsize:8;"
 % self.host_ostype
-
-def qProcessInfo(self):
-return 
"pid:a860;parent-pid:d2a0;real-uid:1f5;real-gid:14;effective-uid:1f5;effective-gid:14;cputype:10c;cpusubtype:2;ptrsize:8;ostype:ios;vendor:apple;endian:little;"
-
-def vCont(self):
-return "vCont;"
-
-def platform_test(self, host, expected_triple, expected_platform):
-self.server.responder = self.MyResponder(host)
-if self.TraceOn():
-self.runCmd("log enable gdb-remote packets")
-self.addTearDownHook(
-lambda: self.runCmd("log disable gdb-remote packets"))
-
-target = self.dbg.CreateTargetWithFileAndArch(None, None)
-process = self.connect(target)
-
-triple = target.GetTriple()
-self.assertEqual(triple, expected_triple)
-
-platform = target.GetPlatform()
-self.assertEqual(platform.GetName(), expected_platform)
-
-@skipIfRemote
-def test_ios(self):
-self.platform_test(host="ios",
-   expected_triple="arm64e-apple-ios-",
-   expected_platform="remote-ios")
-
-@skipIfRemote
-@skipUnlessDarwin
-@skipUnlessArch("arm64")
-def test_macos(self):
-self.platform_test(host="macosx",
-   expected_triple="arm64e-apple-ios-",
-   expected_platform="host")

diff  --git a/lldb/lldb/unittests/Platform/PlatformMacOSXTest.cpp 
b/lldb/lldb/unittests/Platform/PlatformMacOSXTest.cpp
deleted file mode 100644
index e35489a47d87e..0
--- a/lldb/lldb/unittests/Platform/PlatformMacOSXTest.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-//===-- PlatformMacOSXTest.cpp ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "gtest/gtest.h"
-
-#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
-#include "TestingSupport/SubsystemRAII.h"
-#include "lldb/Host/FileSystem.h"
-#include "lldb/Host/HostInfo.h"
-#include "lldb/Target/Platform.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-class PlatformMacOSXTest : public ::testing::Test {
-  SubsystemRAII subsystems;
-};
-
-static bool containsArch(const std::vector &archs,
- const ArchSpec &arch) {
-  return std::find_if(archs.begin(), archs.end(), [&](const ArchSpec &other) {
-   return arch.IsExactMatch(other);
- }) != archs.end();
-}
-
-TEST_F(PlatformMacOSXTest, TestGetSupportedArchitectures) {
-  PlatformMacOSX platform;
-
-  const ArchSpec x86_macosx_arch("x86_64-apple-macosx");
-
-  EXPECT_TRUE(containsArch(platform.GetSupportedArchitectures(x86_macosx_arch),
-   x86_macosx_arch));
-  EXPECT_TRUE(
-  containsArch(platform.GetSupportedArchitectures({}), x86_macosx_arch));
-
-#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
-  const ArchSpec arm64_macosx_arch("arm6

[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

2022-03-18 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.

Please reflow the document to match the 80 column limit observed in the other 
docs. LGTM with that addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

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


[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

2022-03-18 Thread Alisamar Husain via Phabricator via lldb-commits
zrthxn updated this revision to Diff 416532.
zrthxn added a comment.

Reflow to 80 cols


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

Files:
  lldb/docs/index.rst
  lldb/docs/use/intel_pt.rst

Index: lldb/docs/use/intel_pt.rst
===
--- /dev/null
+++ lldb/docs/use/intel_pt.rst
@@ -0,0 +1,232 @@
+Tracing with Intel Processor Trace (Intel PT)
+=
+
+.. contents::
+  :local:
+
+Intel PT is a technology available in modern Intel CPUs that allows efficient 
+tracing of all the instructions executed by a process. 
+LLDB can collect traces and dump them using its symbolication stack. 
+You can read more here 
+https://easyperf.net/blog/2019/08/23/Intel-Processor-Trace.
+
+Prerequisites
+-
+
+Confirm that your CPU supports Intel PT 
+(see https://www.intel.com/content/www/us/en/support/articles/56730/processors.html) 
+and that your operating system is Linux.
+
+Check for the existence of this particular file on your Linux system
+:: 
+
+  $ cat /sys/bus/event_source/devices/intel_pt/type
+
+The output should be a number. Otherwise, try upgrading your kernel.
+
+
+Build Instructions
+--
+
+Clone and build the low level Intel PT 
+decoder library [LibIPT library](https://github.com/intel/libipt).
+:: 
+
+  $ git clone g...@github.com:intel/libipt.git
+  $ mkdir libipt-build
+  $ cmake -S libipt -B libipt-build
+  $ cd libipt-build
+  $ make
+
+This will generate a few files in the `/lib` 
+and `/libipt/include` directories.
+
+Configure and build LLDB with Intel PT support
+:: 
+
+  $ cmake \
+  -DLLDB_BUILD_INTEL_PT=ON \
+  -DLIBIPT_INCLUDE_PATH="/libipt/include" \
+  -DLIBIPT_LIBRARY_PATH="/lib" \
+  ... other common configuration parameters 
+
+:: 
+
+  $ cd  && ninja lldb lldb-server # if using Ninja
+
+
+How to Use
+--
+
+When you are debugging a process, you can turn on intel-pt tracing, 
+which will “record” all the instructions that the process will execute. 
+After turning it on, you can continue debugging, and at any breakpoint, 
+you can inspect the instruction list.
+ 
+For example:
+::
+  lldb 
+  > b main
+  > run
+  > process trace start # start tracing on all threads, including future ones
+  # keep debugging until you hit a breakpoint
+  
+  > thread trace dump instructions
+  # this should output something like
+
+  thread #2: tid = 2861133, total instructions = 5305673
+libc.so.6`__GI___libc_read + 45 at read.c:25:1
+  [4962255] 0x7fffeb64c63dsubq   $0x10, %rsp
+  [4962256] 0x7fffeb64c641movq   %rdi, -0x18(%rbp)
+libc.so.6`__GI___libc_read + 53 [inlined] __libc_read at read.c:26:10
+  [4962257] 0x7fffeb64c645callq  0x7fffeb66b640; __libc_enable_asynccancel
+libc.so.6`__libc_enable_asynccancel
+  [4962258] 0x7fffeb66b640movl   %fs:0x308, %eax
+libc.so.6`__libc_enable_asynccancel + 8
+  [4962259] 0x7fffeb66b648movl   %eax, %r11d
+
+  # you can keep pressing ENTER to see more and more instructions
+ 
+The number between brackets is the instruction index, 
+and by default the current thread will be picked.
+ 
+Configuring the trace size
+--
+ 
+The CPU stores the instruction list in a compressed format in a ring buffer, 
+which keeps the latest information. 
+By default, LLDB uses a buffer of 4KB per thread, 
+but you can change it by running. 
+The size must be a power of 2 and at least 4KB.
+::
+  thread trace start all -s 
+ 
+For reference, a 1MB trace buffer can easily store around 5M instructions.
+ 
+Printing more instructions
+--
+ 
+If you want to dump more instructions at a time, you can run
+::
+  thread trace dump instructions -c 
+ 
+Printing the instructions of another thread
+---
+
+By default the current thread will be picked when dumping instructions, 
+but you can do
+:: 
+  thread trace dump instructions <#thread index>
+  #e.g.
+  thread trace dump instructions 8
+ 
+to select another thread.
+ 
+Crash Analysis
+--
+ 
+What if you are debugging + tracing a process that crashes? 
+Then you can just do
+::
+  thread trace dump instructions
+ 
+To inspect how it crashed! There's nothing special that you need to do. 
+For example
+:: 
+* thread #1, name = 'a.out', stop reason = signal SIGFPE: integer divide by zero
+frame #0: 0x004009f1 a.out`main at main.cpp:8:14
+  6   int x;
+  7   cin >> x;
+   -> 8   cout << 12 / x << endl;
+  9   return 0;
+  10  }
+(lldb) thread trace dump instructions -c 5
+thread #1: tid = 604302, total instructions = 8388
+  libstdc++.so.6`std::istream::operator>>(int&) + 181
+[8383] 0x77b41665popq   %rbp
+[8384

[Lldb-commits] [PATCH] D121935: added intel-pt build instructions for lldb

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

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121935

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


[Lldb-commits] [PATCH] D122023: [trace][intelpt] fix some test failures

2022-03-18 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
wallace added a reviewer: jj10306.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Minor fixes needed and now `./bin/lldb-dotest -p TestTrace` passes
correctly.

- There was an incorrect iteration.
- Some error messages changed.
- The way repeat commands are handled changed a bit, so I had to create

a new --continue arg in "thread trace dump instructions" to handle this
correctly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122023

Files:
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/TestTraceExport.py
  lldb/test/API/commands/trace/TestTraceSave.py

Index: lldb/test/API/commands/trace/TestTraceSave.py
===
--- lldb/test/API/commands/trace/TestTraceSave.py
+++ lldb/test/API/commands/trace/TestTraceSave.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("process trace save",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceExport.py
===
--- lldb/test/API/commands/trace/TestTraceExport.py
+++ lldb/test/API/commands/trace/TestTraceExport.py
@@ -23,7 +23,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect(f"thread trace export ctf --file {ctf_test_file}",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
@@ -172,4 +172,3 @@
 data_index = index_of_first_layer_1_block
 for i in range(len(expected_block_names)):
 self.assertTrue(data[data_index + i]['name'] == expected_block_names[i])
-
Index: lldb/test/API/commands/trace/TestTraceDumpInstructions.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInstructions.py
+++ lldb/test/API/commands/trace/TestTraceDumpInstructions.py
@@ -19,7 +19,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump instructions",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump info",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/source/Commands/Options.td
===
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -1116,6 +1116,12 @@
   def thread_trace_dump_instructions_show_tsc : Option<"tsc", "t">,
 Group<1>,
 Desc<"For each instruction, print the corresponding timestamp counter if available.">;
+  def thread_trace_dump_instructions_continue: Option<"continue", "C">,
+Group<1>,
+Desc<"Continue dumping instructions right where the previous invocation of this "
+"command was left, or from the beginning if this is the first invocation. The --skip "
+"argument is discarded and the --forwards value is preserved from the previous "
+"invocation if possible.">;
 }
 
 let Command = "thread trace dump info" in {
Index: lldb/source/Commands/CommandObjectThread.cpp
===
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -2032,7 +2032,7 @@
 
 unsigned i = 0;
 for (llvm::StringRef plugin_name =
- PluginManager::GetTraceExporterPluginNameAtIndex(i++);
+ PluginManager::GetTraceExporterPluginNameAtIndex(i);
  !plugin_name.empty();
  plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
   if (ThreadTraceExportCommandCreator command_creator =
@@ -2147,6 +2147,10 @@
 m_show_t

[Lldb-commits] [PATCH] D122023: [trace][intelpt] fix some test failures

2022-03-18 Thread walter erquinigo via Phabricator via lldb-commits
wallace updated this revision to Diff 416558.
wallace added a comment.
Herald added a subscriber: JDevlieghere.

nit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122023

Files:
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/TestTraceExport.py
  lldb/test/API/commands/trace/TestTraceSave.py

Index: lldb/test/API/commands/trace/TestTraceSave.py
===
--- lldb/test/API/commands/trace/TestTraceSave.py
+++ lldb/test/API/commands/trace/TestTraceSave.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("process trace save",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceExport.py
===
--- lldb/test/API/commands/trace/TestTraceExport.py
+++ lldb/test/API/commands/trace/TestTraceExport.py
@@ -23,7 +23,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect(f"thread trace export ctf --file {ctf_test_file}",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
@@ -172,4 +172,3 @@
 data_index = index_of_first_layer_1_block
 for i in range(len(expected_block_names)):
 self.assertTrue(data[data_index + i]['name'] == expected_block_names[i])
-
Index: lldb/test/API/commands/trace/TestTraceDumpInstructions.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInstructions.py
+++ lldb/test/API/commands/trace/TestTraceDumpInstructions.py
@@ -19,7 +19,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump instructions",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump info",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/source/Commands/Options.td
===
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -1116,6 +1116,12 @@
   def thread_trace_dump_instructions_show_tsc : Option<"tsc", "t">,
 Group<1>,
 Desc<"For each instruction, print the corresponding timestamp counter if available.">;
+  def thread_trace_dump_instructions_continue: Option<"continue", "C">,
+Group<1>,
+Desc<"Continue dumping instructions right where the previous invocation of this "
+"command was left, or from the beginning if this is the first invocation. The --skip "
+"argument is discarded and the other arguments are preserved from the previous "
+"invocation when possible.">;
 }
 
 let Command = "thread trace dump info" in {
Index: lldb/source/Commands/CommandObjectThread.cpp
===
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -2032,7 +2032,7 @@
 
 unsigned i = 0;
 for (llvm::StringRef plugin_name =
- PluginManager::GetTraceExporterPluginNameAtIndex(i++);
+ PluginManager::GetTraceExporterPluginNameAtIndex(i);
  !plugin_name.empty();
  plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
   if (ThreadTraceExportCommandCreator command_creator =
@@ -2147,6 +2147,10 @@
 m_show_tsc = true;
 break;
   }
+  case 'C': {
+m_continue = true;
+break;
+  }
   default:
 llvm_unreachable("Unimplemented option");
   }
@@ -2159,6 +2163,7 @@
   m_raw = false;
   m_forwards = false;
   m_show_tsc = false;
+  m_continue = false;
 }
 
 llv

[Lldb-commits] [PATCH] D122023: [trace][intelpt] fix some test failures

2022-03-18 Thread Jakob Johnson via Phabricator via lldb-commits
jj10306 accepted this revision.
jj10306 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/D122023/new/

https://reviews.llvm.org/D122023

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


[Lldb-commits] [lldb] b7d525a - [trace][intelpt] fix some test failures

2022-03-18 Thread Walter Erquinigo via lldb-commits

Author: Walter Erquinigo
Date: 2022-03-18T10:35:34-07:00
New Revision: b7d525ad38a9378c1669a22b9f92e5548db9b409

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

LOG: [trace][intelpt] fix some test failures

Minor fixes needed and now `./bin/lldb-dotest -p TestTrace` passes
correctly.

- There was an incorrect iteration.
- Some error messages changed.
- The way repeat commands are handled changed a bit, so I had to create
a new --continue arg in "thread trace dump instructions" to handle this
correctly.

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

Added: 


Modified: 
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Commands/Options.td
lldb/test/API/commands/trace/TestTraceDumpInfo.py
lldb/test/API/commands/trace/TestTraceDumpInstructions.py
lldb/test/API/commands/trace/TestTraceExport.py
lldb/test/API/commands/trace/TestTraceSave.py

Removed: 




diff  --git a/lldb/source/Commands/CommandObjectThread.cpp 
b/lldb/source/Commands/CommandObjectThread.cpp
index 0ad3cc090f7d6..f12d90603ec7e 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -2032,7 +2032,7 @@ class CommandObjectTraceExport : public 
CommandObjectMultiword {
 
 unsigned i = 0;
 for (llvm::StringRef plugin_name =
- PluginManager::GetTraceExporterPluginNameAtIndex(i++);
+ PluginManager::GetTraceExporterPluginNameAtIndex(i);
  !plugin_name.empty();
  plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
   if (ThreadTraceExportCommandCreator command_creator =
@@ -2147,6 +2147,10 @@ class CommandObjectTraceDumpInstructions
 m_show_tsc = true;
 break;
   }
+  case 'C': {
+m_continue = true;
+break;
+  }
   default:
 llvm_unreachable("Unimplemented option");
   }
@@ -2159,6 +2163,7 @@ class CommandObjectTraceDumpInstructions
   m_raw = false;
   m_forwards = false;
   m_show_tsc = false;
+  m_continue = false;
 }
 
 llvm::ArrayRef GetDefinitions() override {
@@ -2173,6 +2178,7 @@ class CommandObjectTraceDumpInstructions
 bool m_raw;
 bool m_forwards;
 bool m_show_tsc;
+bool m_continue;
   };
 
   CommandObjectTraceDumpInstructions(CommandInterpreter &interpreter)
@@ -2192,24 +2198,19 @@ class CommandObjectTraceDumpInstructions
 
   llvm::Optional GetRepeatCommand(Args ¤t_command_args,
uint32_t index) override {
-current_command_args.GetCommandString(m_repeat_command);
-m_create_repeat_command_just_invoked = true;
-return m_repeat_command;
+std::string cmd;
+current_command_args.GetCommandString(cmd);
+if (cmd.find("--continue") == std::string::npos)
+  cmd += " --continue";
+return cmd;
   }
 
 protected:
   bool DoExecute(Args &args, CommandReturnObject &result) override {
-if (!IsRepeatCommand())
+if (!m_options.m_continue)
   m_dumpers.clear();
 
-bool status = CommandObjectIterateOverThreads::DoExecute(args, result);
-
-m_create_repeat_command_just_invoked = false;
-return status;
-  }
-
-  bool IsRepeatCommand() {
-return !m_repeat_command.empty() && !m_create_repeat_command_just_invoked;
+return CommandObjectIterateOverThreads::DoExecute(args, result);
   }
 
   bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
@@ -2249,10 +2250,6 @@ class CommandObjectTraceDumpInstructions
   }
 
   CommandOptions m_options;
-
-  // Repeat command helpers
-  std::string m_repeat_command;
-  bool m_create_repeat_command_just_invoked = false;
   std::map> m_dumpers;
 };
 

diff  --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index 13f9fb70f9da8..2720666cc5f0d 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -1116,6 +1116,12 @@ let Command = "thread trace dump instructions" in {
   def thread_trace_dump_instructions_show_tsc : Option<"tsc", "t">,
 Group<1>,
 Desc<"For each instruction, print the corresponding timestamp counter if 
available.">;
+  def thread_trace_dump_instructions_continue: Option<"continue", "C">,
+Group<1>,
+Desc<"Continue dumping instructions right where the previous invocation of 
this "
+"command was left, or from the beginning if this is the first invocation. 
The --skip "
+"argument is discarded and the other arguments are preserved from the 
previous "
+"invocation when possible.">;
 }
 
 let Command = "thread trace dump info" in {

diff  --git a/lldb/test/API/commands/trace/TestTraceDumpInfo.py 
b/lldb/test/API/commands/trace/TestTraceDumpInfo.py
index b06840865232b..99877aaa27ae5 100644
--- a/lldb/test/API/comman

[Lldb-commits] [PATCH] D122023: [trace][intelpt] fix some test failures

2022-03-18 Thread Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7d525ad38a9: [trace][intelpt] fix some test failures 
(authored by Walter Erquinigo ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122023

Files:
  lldb/source/Commands/CommandObjectThread.cpp
  lldb/source/Commands/Options.td
  lldb/test/API/commands/trace/TestTraceDumpInfo.py
  lldb/test/API/commands/trace/TestTraceDumpInstructions.py
  lldb/test/API/commands/trace/TestTraceExport.py
  lldb/test/API/commands/trace/TestTraceSave.py

Index: lldb/test/API/commands/trace/TestTraceSave.py
===
--- lldb/test/API/commands/trace/TestTraceSave.py
+++ lldb/test/API/commands/trace/TestTraceSave.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("process trace save",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceExport.py
===
--- lldb/test/API/commands/trace/TestTraceExport.py
+++ lldb/test/API/commands/trace/TestTraceExport.py
@@ -23,7 +23,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect(f"thread trace export ctf --file {ctf_test_file}",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
@@ -172,4 +172,3 @@
 data_index = index_of_first_layer_1_block
 for i in range(len(expected_block_names)):
 self.assertTrue(data[data_index + i]['name'] == expected_block_names[i])
-
Index: lldb/test/API/commands/trace/TestTraceDumpInstructions.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInstructions.py
+++ lldb/test/API/commands/trace/TestTraceDumpInstructions.py
@@ -19,7 +19,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump instructions",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/test/API/commands/trace/TestTraceDumpInfo.py
===
--- lldb/test/API/commands/trace/TestTraceDumpInfo.py
+++ lldb/test/API/commands/trace/TestTraceDumpInfo.py
@@ -18,7 +18,7 @@
 os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))
 
 self.expect("thread trace dump info",
-substrs=["error: invalid process"],
+substrs=["error: Command requires a current process."],
 error=True)
 
 # Now we check the output when there's a running target without a trace
Index: lldb/source/Commands/Options.td
===
--- lldb/source/Commands/Options.td
+++ lldb/source/Commands/Options.td
@@ -1116,6 +1116,12 @@
   def thread_trace_dump_instructions_show_tsc : Option<"tsc", "t">,
 Group<1>,
 Desc<"For each instruction, print the corresponding timestamp counter if available.">;
+  def thread_trace_dump_instructions_continue: Option<"continue", "C">,
+Group<1>,
+Desc<"Continue dumping instructions right where the previous invocation of this "
+"command was left, or from the beginning if this is the first invocation. The --skip "
+"argument is discarded and the other arguments are preserved from the previous "
+"invocation when possible.">;
 }
 
 let Command = "thread trace dump info" in {
Index: lldb/source/Commands/CommandObjectThread.cpp
===
--- lldb/source/Commands/CommandObjectThread.cpp
+++ lldb/source/Commands/CommandObjectThread.cpp
@@ -2032,7 +2032,7 @@
 
 unsigned i = 0;
 for (llvm::StringRef plugin_name =
- PluginManager::GetTraceExporterPluginNameAtIndex(i++);
+ PluginManager::GetTraceExporterPluginNameAtIndex(i);
  !plugin_name.empty();
  plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
   if (ThreadTraceExportCommandCreator command_creator =
@@ -2147,6 +2147,10 @@
 m_show_tsc = true;
 break;
   }
+  case 'C': {
+m_continue = true;
+break;
+  }
   default:
 llvm_unreachable("Unimplemented option");
   }
@@ -2159,6 +2163,7 @@
   m_raw = false;
   m_forwards =

[Lldb-commits] [PATCH] D121977: [lldb/test] Add progress events listener helper class to lldbutil

2022-03-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1624
+# ==
+# Utility class to setup a progress event listener
+# ==

We should make this more generic so that the warning and error events can also 
use this. The way I imagined this was that the thread would be generic and you 
would pass it in the broadcaster, the listener and the event type and finally a 
function callback to have the test do whatever it wants with the event. 


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add progress events listener helper class to lldbutil

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked an inline comment as done.
mib added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1624
+# ==
+# Utility class to setup a progress event listener
+# ==

JDevlieghere wrote:
> We should make this more generic so that the warning and error events can 
> also use this. The way I imagined this was that the thread would be generic 
> and you would pass it in the broadcaster, the listener and the event type and 
> finally a function callback to have the test do whatever it wants with the 
> event. 
@JDevlieghere I think this could be achieved very easily by assuming the 
`_fetch_events` method will always be called and replace the `callback` 
argument by a "pointer" to the event_data_extractor function. wdyk ?'

Do you think it's a fair assumption (that we should always call `_fetch_events` 
and match the event against the `src_broadcaster` argument) ?


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add progress events listener helper class to lldbutil

2022-03-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1624
+# ==
+# Utility class to setup a progress event listener
+# ==

mib wrote:
> JDevlieghere wrote:
> > We should make this more generic so that the warning and error events can 
> > also use this. The way I imagined this was that the thread would be generic 
> > and you would pass it in the broadcaster, the listener and the event type 
> > and finally a function callback to have the test do whatever it wants with 
> > the event. 
> @JDevlieghere I think this could be achieved very easily by assuming the 
> `_fetch_events` method will always be called and replace the `callback` 
> argument by a "pointer" to the event_data_extractor function. wdyk ?'
> 
> Do you think it's a fair assumption (that we should always call 
> `_fetch_events` and match the event against the `src_broadcaster` argument) ?
Yes, that's one way to do it. I'm happy as long as we can use it for both 
`TestDiagnosticReporting.py` and `TestProgressReporting.py`. I was on the fence 
about the broadcaster and listener being part of the utility, but I think it 
can work. The diagnostics are slightly different because they listen for two 
event types, but I guess we can abstract over that by ORing the types.

If we do go that route, I think we might want to make this a `TestBase` class 
instead that starts and stops the event thread at the beginning and end of the 
test. Something like `GDBRemoteTestBase` and `PExpectTest`.


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D122025: [lldb] Remove lldbassert from CommandInterpreter::PrintCommandOutput

2022-03-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, lemo, jingham, mib.
Herald added a project: All.
JDevlieghere requested review of this revision.

The assertion checks that the command output doesn't contain any null
bytes. I'm not sure if the intention was to make sure the string wasn't
shorter than the reported length or if this was a way to catch us
accidentally writing an (unformatted) null byte.

Regardless, the command output can be based on user input, so an
assertion doesn't make sense. For example, you should be totally allowed
to call print("\0") from Python. The latter doesn't trigger this bug
because it writes directly to the output stream and therefore bypasses
PrintCommandOutput but that's just an implementation detail.


https://reviews.llvm.org/D122025

Files:
  lldb/source/Interpreter/CommandInterpreter.cpp


Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2987,7 +2987,6 @@
   while (size > 0 && !WasInterrupted()) {
 size_t chunk_size = 0;
 for (; chunk_size < size; ++chunk_size) {
-  lldbassert(data[chunk_size] != '\0');
   if (data[chunk_size] == '\n') {
 ++chunk_size;
 break;


Index: lldb/source/Interpreter/CommandInterpreter.cpp
===
--- lldb/source/Interpreter/CommandInterpreter.cpp
+++ lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2987,7 +2987,6 @@
   while (size > 0 && !WasInterrupted()) {
 size_t chunk_size = 0;
 for (; chunk_size < size; ++chunk_size) {
-  lldbassert(data[chunk_size] != '\0');
   if (data[chunk_size] == '\n') {
 ++chunk_size;
 break;
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D121977: [lldb/test] Add progress events listener helper class to lldbutil

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 416581.
mib added a comment.

Address @JDevlieghere comments:

- Move the `EventListener` class to a separate module and make it inherit from 
`TestBase` to start/stop the background listener thread in `setUp`/`tearDown`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121977

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/packages/Python/lldbsuite/test/lldbutil.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,26 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListener
+
 
-mydir = TestBase.compute_mydir(__file__)
+class TestProgressReporting(EventListener):
 
-eBroadcastBitStopProgressThread = (1 << 0)
+mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
-
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+TestBase.setUp(self) # we need this to be able to access `self.dbg`
+EventListener.setUp(self, self.dbg.GetBroadcaster(),
+lldb.SBDebugger.eBroadcastBitProgress,
+lldb.SBDebugger.GetProgressFromEvent)
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
-
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
-
-self.assertGreater(len(self.progress_events), 0)
+self.assertGreater(len(self.fetched_events), 0)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,24 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListener
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListener):
 
 mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
 def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
- 

[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 416586.
mib added a comment.

Update `EventListener.tearDown` comment


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

https://reviews.llvm.org/D121977

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,26 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListener
+
 
-mydir = TestBase.compute_mydir(__file__)
+class TestProgressReporting(EventListener):
 
-eBroadcastBitStopProgressThread = (1 << 0)
+mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
-
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+TestBase.setUp(self) # we need this to be able to access `self.dbg`
+EventListener.setUp(self, self.dbg.GetBroadcaster(),
+lldb.SBDebugger.eBroadcastBitProgress,
+lldb.SBDebugger.GetProgressFromEvent)
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
-
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
-
-self.assertGreater(len(self.progress_events), 0)
+self.assertGreater(len(self.fetched_events), 0)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,24 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListener
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListener):
 
 mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
 def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopDiagnosticThread:
-done = True
-elif event.BroadcasterMatchesRef(self.diagnostic_broadcaster):
-self.diagnostic_events.append(
-

[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:19
+eBroadcastBitStopListenerThread = (1 << 0)
+fetched_events = []
+

Just `events` maybe?



Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:22
+
+def setUp(self, src_broadcaster, event_mask, event_data_extractor):
+self.src_broadcaster = src_broadcaster

Could we avoid the arguments by making these two things properties of the test? 
I'm trying to avoid the:

```
TestBase.setUp(self) 
EventListener.setUp(self)
```
So that tests would have to set:

```
class TestDiagnosticReporting(EventListenerTest):
  event_mask = lldb.SBDebugger.eBroadcastBitWarning | 
lldb.SBDebugger.eBroadcastBitError
  event_extractor = lldb.SBDebugger.GetDiagnosticFromEvent
```

Presumable those two things don't need the debugger and I think we can avoid 
the `self.src_broadcaster` too (see below). 






Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:23
+def setUp(self, src_broadcaster, event_mask, event_data_extractor):
+self.src_broadcaster = src_broadcaster
+self.broadcaster = lldb.SBBroadcaster('lldb.test.broadcaster')

Would this always be ` self.dbg.GetBroadcaster()`? 



Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:6
+
+class EventListener(TestBase):
+

`EventListenerTest`


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Jim Ingham via Phabricator via lldb-commits
jingham added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1624
+# ==
+# Utility class to setup a progress event listener
+# ==

JDevlieghere wrote:
> mib wrote:
> > JDevlieghere wrote:
> > > We should make this more generic so that the warning and error events can 
> > > also use this. The way I imagined this was that the thread would be 
> > > generic and you would pass it in the broadcaster, the listener and the 
> > > event type and finally a function callback to have the test do whatever 
> > > it wants with the event. 
> > @JDevlieghere I think this could be achieved very easily by assuming the 
> > `_fetch_events` method will always be called and replace the `callback` 
> > argument by a "pointer" to the event_data_extractor function. wdyk ?'
> > 
> > Do you think it's a fair assumption (that we should always call 
> > `_fetch_events` and match the event against the `src_broadcaster` argument) 
> > ?
> Yes, that's one way to do it. I'm happy as long as we can use it for both 
> `TestDiagnosticReporting.py` and `TestProgressReporting.py`. I was on the 
> fence about the broadcaster and listener being part of the utility, but I 
> think it can work. The diagnostics are slightly different because they listen 
> for two event types, but I guess we can abstract over that by ORing the types.
> 
> If we do go that route, I think we might want to make this a `TestBase` class 
> instead that starts and stops the event thread at the beginning and end of 
> the test. Something like `GDBRemoteTestBase` and `PExpectTest`.
It might be good to put an error in there if some one tries to do this with 
process events.  That's pretty unlikely to work, since it would fight with the 
debugger for those events.


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D122041: [llvm][utils] Fix llvm::Optional summary provider

2022-03-18 Thread Dave Lee via Phabricator via lldb-commits
kastiglione created this revision.
kastiglione added reviewers: jingham, aprantl.
kastiglione added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Returning `None` from a Python type summary results in a summary string of 
"None". To indicate no summary string, the implementation should return the 
empty string.

This change fixes a bug where the summary provider for `llvm::Optional` would 
incorrectly show `None`. This would happen when the underlying type itself had 
no summary provider. Now, when the underlying type has a summary string, that 
string is used, but when there is no summary, then the `Optional` will also 
have no summary (`return ''`).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122041

Files:
  llvm/utils/lldbDataFormatters.py


Index: llvm/utils/lldbDataFormatters.py
===
--- llvm/utils/lldbDataFormatters.py
+++ llvm/utils/lldbDataFormatters.py
@@ -137,7 +137,11 @@
 
 def OptionalSummaryProvider(valobj, internal_dict):
 val = GetOptionalValue(valobj)
-return val.summary if val else 'None'
+if val is None:
+return 'None'
+if val.summary:
+return val.summary
+return ''
 
 class OptionalSynthProvider:
 """Provides deref support to llvm::Optional"""


Index: llvm/utils/lldbDataFormatters.py
===
--- llvm/utils/lldbDataFormatters.py
+++ llvm/utils/lldbDataFormatters.py
@@ -137,7 +137,11 @@
 
 def OptionalSummaryProvider(valobj, internal_dict):
 val = GetOptionalValue(valobj)
-return val.summary if val else 'None'
+if val is None:
+return 'None'
+if val.summary:
+return val.summary
+return ''
 
 class OptionalSynthProvider:
 """Provides deref support to llvm::Optional"""
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib marked 4 inline comments as done.
mib added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/eventlistener.py:23
+def setUp(self, src_broadcaster, event_mask, event_data_extractor):
+self.src_broadcaster = src_broadcaster
+self.broadcaster = lldb.SBBroadcaster('lldb.test.broadcaster')

JDevlieghere wrote:
> Would this always be ` self.dbg.GetBroadcaster()`? 
For now, it's always the debugger broadcaster so we can assume that I think.


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 416612.
mib marked an inline comment as done.
mib added a comment.

Address @JDevlieghere comments


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

https://reviews.llvm.org/D121977

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,25 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
+
 
-mydir = TestBase.compute_mydir(__file__)
+class TestProgressReporting(EventListenerTestBase):
 
-eBroadcastBitStopProgressThread = (1 << 0)
+mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
-
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+self.event_mask = lldb.SBDebugger.eBroadcastBitProgress
+self.event_data_extractor = lldb.SBDebugger.GetProgressFromEvent
+EventListenerTestBase.setUp(self)
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
-
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
-
-self.assertGreater(len(self.progress_events), 0)
+self.assertGreater(len(self.events), 0)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,23 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListenerTestBase):
 
 mydir = TestBase.compute_mydir(__file__)
 
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
 def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopDiagnosticThread:
-done = True
-elif event.BroadcasterMatchesRef(self.diagnostic_broadcaster):
-self.diagnostic_events.append(
-lldb.SBDebugger.GetDiag

[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

@jingham It's a bit restrictive, but as I stated before, this class will expect 
to receive events from the debugger broadcaster. If you can think of other 
broadcasters that could be tested with this class, please let me know so we can 
think of another solution.


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 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.

Nice, thanks for bearing with me. LGTM.


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

https://reviews.llvm.org/D121977

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


[Lldb-commits] [PATCH] D121967: [LLDB][NativePDB] Create inline function decls

2022-03-18 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu updated this revision to Diff 416621.
zequanwu added a comment.

Fixing bugs and refactor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121967

Files:
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/test/Shell/SymbolFile/NativePDB/Inputs/inline_sites.lldbinit
  lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
  lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp

Index: lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp
===
--- lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp
+++ lldb/test/Shell/SymbolFile/NativePDB/local-variables.cpp
@@ -157,6 +157,7 @@
 // CHECK-NEXT: | |-ParmVarDecl {{.*}} argc 'int'
 // CHECK-NEXT: | `-ParmVarDecl {{.*}} argv 'char **'
 // CHECK-NEXT: |-FunctionDecl {{.*}} __scrt_common_main_seh 'int ()' static 
+// CHECK-NEXT: |-FunctionDecl {{.*}} invoke_main 'int ()' inline
 // CHECK-NEXT: `-FunctionDecl {{.*}} Function 'int (int, char)'
 // CHECK-NEXT:   |-ParmVarDecl {{.*}} Param1 'int'
 // CHECK-NEXT:   `-ParmVarDecl {{.*}} Param2 'char'
Index: lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
===
--- lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
+++ lldb/test/Shell/SymbolFile/NativePDB/inline_sites.s
@@ -7,121 +7,199 @@
 # RUN: %p/Inputs/inline_sites.lldbinit 2>&1 | FileCheck %s
 
 # Compiled from the following files, but replaced the call to abort with nop.
+# clang-cl -fuse-ld=lld-link /Z7 /O1 /Faa.asm /winsysroot~/win_toolchain a.cpp
 # a.cpp:
-# #include "stdlib.h"
 # #include "a.h"
 # int main(int argc, char** argv) {
-#   Namespace1::foo(2);
+#   volatile int main_local = Namespace1::foo(2);
 #   return 0;
 # }
 # a.h:
+# #include 
 # #include "b.h"
 # namespace Namespace1 {
-# inline void foo(int x) {
-#   static volatile int gv_foo;
-#   ++gv_foo;
-#   if (!gv_foo)
+# inline int foo(int x) {
+#   volatile int foo_local = x + 1;
+#   ++foo_local;
+#   if (!foo_local)
 # abort();
-#   Class1::bar(x + 1);
-# }
+#   return Class1::bar(foo_local);
 # }
+# } // namespace Namespace1
 # 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);
+#   inline static int bar(int x) {
+# volatile int bar_local = x + 1;
+# ++bar_local;
+# return Namespace2::Class2::func(bar_local);
 #   }
 # };
 # c.h:
-# namespace Namespace2{
-#   class Class2{
-# public:
-# inline static void func(int x) {
-#   static volatile int gv_func;
-#   gv_func += x;
-# }
-#   };
-# }
+# namespace Namespace2 {
+# class Class2 {
+# public:
+#   inline static int func(int x) {
+# volatile int func_local = x + 1;
+# func_local += x;
+# return func_local;
+#   }
+# };
+# } // namespace Namespace2
 
 # CHECK:  (lldb) image dump line-table a.cpp -v
-# CHECK-NEXT: Line table for {{.*}}a.cpp in
-# CHECK-NEXT: 0x000140001000: {{.*}}a.cpp:3
-# CHECK-NEXT: 0x000140001004: {{.*}}a.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
-# CHECK-NEXT: 0x00014000100a: {{.*}}a.h:6
-# CHECK-NEXT: 0x000140001014: {{.*}}b.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
-# CHECK-NEXT: 0x00014000101a: {{.*}}c.h:6, is_start_of_statement = TRUE, is_prologue_end = TRUE
-# CHECK-NEXT: 0x000140001021: {{.*}}a.cpp:5
-# CHECK-NEXT: 0x000140001028: {{.*}}a.h:7, is_start_of_statement = TRUE
-# CHECK-NEXT: 0x00014000102a: {{.*}}a.cpp:5, is_terminal_entry = TRUE
+# CHECK-NEXT: Line table
+# CHECK-NEXT: 0x000140001000: /tmp/a.cpp:2
+# CHECK-NEXT: 0x000140001004: /tmp/a.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x00014000100c: /tmp/a.h:6
+# CHECK-NEXT: 0x000140001010: /tmp/a.h:7
+# CHECK-NEXT: 0x000140001018: /tmp/a.h:9
+# CHECK-NEXT: 0x00014000101c: /tmp/b.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x000140001022: /tmp/b.h:6
+# CHECK-NEXT: 0x000140001026: /tmp/b.h:7
+# CHECK-NEXT: 0x00014000102a: /tmp/c.h:5, is_start_of_statement = TRUE, is_prologue_end = TRUE
+# CHECK-NEXT: 0x000140001031: /tmp/c.h:6
+# CHECK-NEXT: 0x000140001035: /tmp/c.h:7
+# CHECK-NEXT: 0x000140001039: /tmp/a.cpp:3
+# CHECK-NEXT: 0x00014000103d: /tmp/a.cpp:4
+# CHECK-NEXT: 0x000140001044: /tmp/a.h:8, is_start_of_statement = TRUE
+# CHECK-NEXT: 0x000140001046: /tmp/a.cpp:4, 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 = 0x

[Lldb-commits] [PATCH] D121967: [LLDB][NativePDB] Create inline function decls

2022-03-18 Thread Zequan Wu via Phabricator via lldb-commits
zequanwu added a comment.

I think adding a live debugging test case is necessary. I found several bugs 
when working on this via live debugging the compiled `inline_sites.s` and 
printing variables, and those bugs were not revealed by `image lookup`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121967

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


[Lldb-commits] [PATCH] D121408: Fixing DWARFExpression handling of ValueType::FileAddress case for DW_OP_deref_size

2022-03-18 Thread Adrian Prantl via Phabricator via lldb-commits
aprantl added inline comments.



Comment at: lldb/source/Expression/DWARFExpression.cpp:971
+  "need module to resolve file address for %s", dw_op_type);
+return {};
+  }

clayborg wrote:
> Do we prefer "return {}" over "return llvm::None"?
Personally, I do, but there's no rule about that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121408

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


[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 416630.
mib added a comment.

Make `event_mask` and `event_data_extractor` class attributes to remove 
`EventListenerTestBase.setUp` overloading in the derived class tests.


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

https://reviews.llvm.org/D121977

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,22 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
-import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
-
-mydir = TestBase.compute_mydir(__file__)
-
-eBroadcastBitStopProgressThread = (1 << 0)
+import lldbsuite.test.lldbutil as lldbutil
 
-def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-def fetch_events(self):
-event = lldb.SBEvent()
 
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
+class TestProgressReporting(EventListenerTestBase):
 
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+mydir = TestBase.compute_mydir(__file__)
+event_mask = lldb.SBDebugger.eBroadcastBitProgress
+event_data_extractor = lldb.SBDebugger.GetProgressFromEvent
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
-
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
-
-self.assertGreater(len(self.progress_events), 0)
+self.assertGreater(len(self.events), 0)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,20 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListenerTestBase):
 
 mydir = TestBase.compute_mydir(__file__)
-
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
-def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopDiagnosticThread:
-done = True
-elif event.BroadcasterMatchesRef(self.diagnostic_broadcaster):
-self.diagnostic_events.app

[Lldb-commits] [lldb] 09ff41a - [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-03-18T16:35:33-07:00
New Revision: 09ff41a087760ea7e80b8e5390a05101c5a5b929

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

LOG: [lldb/test] Add events listener helper class to lldbtest

This patch introduces a generic helper class that will listen for
event in a background thread and match it against a source broadcaster.

If the event received matches the source broadcaster, the event is
queued up in a list that the user can access later on.

The motivation behind this is to easily test new kinds of events
(i.e. Swift type-system progress events). However, this patch also
updates `TestProgressReporting.py` and `TestDiagnosticReporting.py`
to make use of this new helper class.

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

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/packages/Python/lldbsuite/test/eventlistener.py

Modified: 

lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/eventlistener.py 
b/lldb/packages/Python/lldbsuite/test/eventlistener.py
new file mode 100644
index 0..336d65a3f067a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/eventlistener.py
@@ -0,0 +1,72 @@
+import threading
+
+import lldb
+from lldbsuite.test.lldbtest import *
+
+class EventListenerTestBase(TestBase):
+
+"""
+Base class for lldb event listener tests.
+
+This class will setup and start an event listener for the test to use.
+
+If the event received matches the source broadcaster, the event is
+queued up in a list that the user can access later on.
+"""
+NO_DEBUG_INFO_TESTCASE = True
+
+eBroadcastBitStopListenerThread = (1 << 0)
+events = []
+event_mask = None
+event_data_extractor = None
+
+def setUp(self):
+TestBase.setUp(self)
+
+self.src_broadcaster = self.dbg.GetBroadcaster()
+self.broadcaster = lldb.SBBroadcaster('lldb.test.broadcaster')
+self.listener = lldb.SBListener("lldb.test.listener")
+self.listener.StartListeningForEvents(self.broadcaster,
+  
self.eBroadcastBitStopListenerThread)
+
+self.src_broadcaster.AddListener(self.listener, self.event_mask)
+
+self.listener_thread = threading.Thread(target=self._fetch_events)
+self.listener_thread.start()
+
+def tearDown(self):
+# Broadcast a eBroadcastBitStopListenerThread` event so the background
+# thread stops listening to events, then join the background thread.
+
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
+self.listener_thread.join()
+TestBase.tearDown(self)
+
+def _fetch_events(self):
+event = lldb.SBEvent()
+
+done = False
+while not done:
+if self.listener.GetNextEvent(event):
+event_mask = event.GetType();
+if event.BroadcasterMatchesRef(self.broadcaster):
+if event_mask & self.eBroadcastBitStopListenerThread:
+done = True;
+elif event.BroadcasterMatchesRef(self.src_broadcaster):
+# NOTE: https://wiki.python.org/moin/FromFunctionToMethod
+#
+# When assigning the `event_data_extractor` function 
pointer
+# to the `EventListenerTestBase` instance, it turns the
+# function object into an instance method which 
subsequently
+# passes `self` as an extra argument.
+
+# However, because most of the event data extractor
+# functions are static, passing the `self` argument makes
+# the number of passed arguments exceeds the function 
definition
+
+# This is why we unwrap the function from the instance
+# method object calling `__func__` instead.
+ret_args = self.event_data_extractor.__func__(event);
+if not ret_args:
+continue
+
+self.events.append(ret_args)

diff  --git 
a/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py 
b/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
index 1bfc313e8381f..e78c34b599e11 100644
--- 
a/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ 
b/lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,20 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import ll

[Lldb-commits] [PATCH] D121977: [lldb/test] Add events listener helper class to lldbtest

2022-03-18 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG09ff41a08776: [lldb/test] Add events listener helper class 
to lldbtest (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D121977?vs=416630&id=416631#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121977

Files:
  lldb/packages/Python/lldbsuite/test/eventlistener.py
  lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py

Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
===
--- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -2,57 +2,22 @@
 Test that we are able to broadcast and receive progress events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
-import lldbsuite.test.lldbutil as lldbutil
-import threading
 
-class TestProgressReporting(TestBase):
-
-mydir = TestBase.compute_mydir(__file__)
-
-eBroadcastBitStopProgressThread = (1 << 0)
+import lldbsuite.test.lldbutil as lldbutil
 
-def setUp(self):
-TestBase.setUp(self)
-self.progress_events = []
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-def fetch_events(self):
-event = lldb.SBEvent()
 
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType();
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopProgressThread:
-done = True;
-elif event.BroadcasterMatchesRef(self.progress_broadcaster):
-ret_args = lldb.SBDebugger().GetProgressFromEvent(event);
-self.assertGreater(len(ret_args), 1)
+class TestProgressReporting(EventListenerTestBase):
 
-message = ret_args[0]
-if message:
-self.progress_events.append((message, event))
+mydir = TestBase.compute_mydir(__file__)
+event_mask = lldb.SBDebugger.eBroadcastBitProgress
+event_data_extractor = lldb.SBDebugger.GetProgressFromEvent
 
 def test_dwarf_symbol_loading_progress_report(self):
 """Test that we are able to fetch dwarf symbol loading progress events"""
 self.build()
 
-self.listener = lldb.SBListener("lldb.progress.listener")
-self.test_broadcaster = lldb.SBBroadcaster('lldb.broadcaster.test')
-self.listener.StartListeningForEvents(self.test_broadcaster,
-  self.eBroadcastBitStopProgressThread)
-
-self.progress_broadcaster = self.dbg.GetBroadcaster()
-self.progress_broadcaster.AddListener(self.listener, lldb.SBDebugger.eBroadcastBitProgress)
-
-listener_thread = threading.Thread(target=self.fetch_events)
-listener_thread.start()
-
 lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
-
-self.test_broadcaster.BroadcastEventByType(self.eBroadcastBitStopProgressThread)
-listener_thread.join()
-
-self.assertGreater(len(self.progress_events), 0)
+self.assertGreater(len(self.events), 0)
Index: lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
===
--- lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
+++ lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py
@@ -2,51 +2,20 @@
 Test that we are able to broadcast and receive diagnostic events from lldb
 """
 import lldb
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test.decorators import *
+
 import lldbsuite.test.lldbutil as lldbutil
-import threading
 
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.eventlistener import EventListenerTestBase
 
-class TestDiagnosticReporting(TestBase):
+class TestDiagnosticReporting(EventListenerTestBase):
 
 mydir = TestBase.compute_mydir(__file__)
-
-eBroadcastBitStopDiagnosticThread = (1 << 0)
-
-def setUp(self):
-TestBase.setUp(self)
-self.diagnostic_events = []
-
-def fetch_events(self):
-event = lldb.SBEvent()
-
-done = False
-while not done:
-if self.listener.WaitForEvent(1, event):
-event_mask = event.GetType()
-if event.BroadcasterMatchesRef(self.test_broadcaster):
-if event_mask & self.eBroadcastBitStopDiagnosticThread:
-   

[Lldb-commits] [lldb] acdd41b - [lldb/test] Fix typo in eventlistener.py (NFC)

2022-03-18 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-03-18T21:59:11-07:00
New Revision: acdd41b4590935e39208a941fbac7889d778e8e5

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

LOG: [lldb/test] Fix typo in eventlistener.py (NFC)

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/eventlistener.py

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/eventlistener.py 
b/lldb/packages/Python/lldbsuite/test/eventlistener.py
index 336d65a3f067a..2bf53fe2d75b5 100644
--- a/lldb/packages/Python/lldbsuite/test/eventlistener.py
+++ b/lldb/packages/Python/lldbsuite/test/eventlistener.py
@@ -35,7 +35,7 @@ def setUp(self):
 self.listener_thread.start()
 
 def tearDown(self):
-# Broadcast a eBroadcastBitStopListenerThread` event so the background
+# Broadcast a `eBroadcastBitStopListenerThread` event so the background
 # thread stops listening to events, then join the background thread.
 
self.broadcaster.BroadcastEventByType(self.eBroadcastBitStopListenerThread)
 self.listener_thread.join()
@@ -65,7 +65,7 @@ def _fetch_events(self):
 
 # This is why we unwrap the function from the instance
 # method object calling `__func__` instead.
-ret_args = self.event_data_extractor.__func__(event);
+ret_args = self.event_data_extractor.__func__(event)
 if not ret_args:
 continue
 



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