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

2022-02-09 Thread Pavel Labath via Phabricator via lldb-commits
labath added inline comments.



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

kastiglione wrote:
> aprantl wrote:
> > kastiglione wrote:
> > > augusto2112 wrote:
> > > > Could we add a new value in the enumeration? Something like 
> > > > ePermissionsLinkerWritable? As it is right now this would be dangerous 
> > > > for the existing file-cache optimization as we'd happily read pointers 
> > > > that are supposed to be fixed by the linker from the file-cache.
> > > That works for me. I think we'd want `ePermissionsLoaderWritable`.
> > That sounds good.
> Some idle questions:
> 
> 1. Some code turns permissions into a string, like `rw-` or `r-x`, but 
> there's no string character for this "hybrid" writable flag.
> 2. Other code might make r/w/x assumptions, and have bugs because of this 
> extra state?
> 3. Do any other binary file formats have this notion, or would this be 
> forcing a Mach-O specific flag into a portable concept?
> 
> I haven't looked yet, but I'm thinking it would be good if there were some 
> other set of flags this information could be stored in.
> 
> I'm also not even sure if `SG_READ_ONLY` should modify permissions. For such 
> a segment, should the permissions say it's writable, and something else say 
> "actually no it's not", or should the permissions say it's non-writable, and 
> something else says "actually it is written to by the loader".
> Do any other binary file formats have this notion, or would this be forcing a 
> Mach-O specific flag into a portable concept?

There is a `PT_GNU_RELRO` in linux land:
```
PT_GNU_RELRO

The array element specifies the location and size of a segment which may be 
made read-only after relocations have been processed.
```

I haven't checked windows, but I'd expect it to have something similar -- 
security hardening is a hot topic these days and writable vtables are a 
tempting target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118494

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


[Lldb-commits] [lldb] 5a4fe16 - [lldb/test] Remove sleeps from some lldb-server tests

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T11:05:02+01:00
New Revision: 5a4fe166d13bf89e6bc387bd96232e8c0f706d27

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

LOG: [lldb/test] Remove sleeps from some lldb-server tests

Instead of using sleeps, have the inferior notify us (via a trap opcode) that
the requested number of threads have been created.

This allows us to get rid of some fairly dodgy test utility code --
wait_for_thread_count seemed like it was waiting for the threads to
appear, but it never actually let the inferior run, so it only succeeded
if the threads were already started when the function was called. Since
the function was called after a fairly small delay (1s, usually), this
is probably the reason why the tests were failing on some bots.

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

Added: 


Modified: 
lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
lldb/test/API/tools/lldb-server/main.cpp

Removed: 




diff  --git 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 619d0f1c21729..cea963e456592 100644
--- 
a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ 
b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -772,29 +772,20 @@ def parse_threadinfo_packets(self, context):
 thread_ids.extend(new_thread_infos)
 return thread_ids
 
-def wait_for_thread_count(self, thread_count):
-start_time = time.time()
-timeout_time = start_time + self.DEFAULT_TIMEOUT
-
-actual_thread_count = 0
-while actual_thread_count < thread_count:
-self.reset_test_sequence()
-self.add_threadinfo_collection_packets()
-
-context = self.expect_gdbremote_sequence()
-self.assertIsNotNone(context)
-
-threads = self.parse_threadinfo_packets(context)
-self.assertIsNotNone(threads)
-
-actual_thread_count = len(threads)
-
-if time.time() > timeout_time:
-raise Exception(
-'timed out after {} seconds while waiting for threads: 
waiting for at least {} threads, found {}'.format(
-self.DEFAULT_TIMEOUT, thread_count, 
actual_thread_count))
+def launch_with_threads(self, thread_count):
+procs = self.prep_debug_monitor_and_inferior(
+inferior_args=["thread:new"]*(thread_count-1) + ["trap"])
 
-return threads
+self.test_sequence.add_log_lines([
+"read packet: $c#00",
+{"direction": "send",
+"regex": r"^\$T([0-9a-fA-F]{2})([^#]*)#..$",
+"capture": {1: "stop_signo", 2: "stop_reply_kv"}}], True)
+self.add_threadinfo_collection_packets()
+context = self.expect_gdbremote_sequence()
+threads = self.parse_threadinfo_packets(context)
+self.assertGreaterEqual(len(threads), thread_count)
+return context, threads
 
 def add_set_breakpoint_packets(
 self,
@@ -896,28 +887,6 @@ def parse_qSupported_response(self, context):
 
 return supported_dict
 
-def run_process_then_stop(self, run_seconds=1):
-# Tell the stub to continue.
-self.test_sequence.add_log_lines(
-["read packet: $vCont;c#a8"],
-True)
-context = self.expect_gdbremote_sequence()
-
-# Wait for run_seconds.
-time.sleep(run_seconds)
-
-# Send an interrupt, capture a T response.
-self.reset_test_sequence()
-self.test_sequence.add_log_lines(
-["read packet: {}".format(chr(3)),
- {"direction": "send", "regex": 
r"^\$T([0-9a-fA-F]+)([^#]+)#[0-9a-fA-F]{2}$", "capture": {1: "stop_result"}}],
-True)
-context = self.expect_gdbremote_sequence()
-self.assertIsNotNone(context)
-self.assertIsNotNone(context.get("stop_result"))
-
-return context
-
 def continue_process_and_wait_for_stop(self):
 self.test_sequence.add_log_lines(
 [

diff  --git 
a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
index e66424f962957..fcab1ea0e49a9 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
@@ -16,71 +16,21 @@ class TestGdbRemot

[Lldb-commits] [PATCH] D119167: [lldb/test] Remove sleeps from some lldb-server tests

2022-02-09 Thread Pavel Labath via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5a4fe166d13b: [lldb/test] Remove sleeps from some 
lldb-server tests (authored by labath).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119167

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
  lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
  lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
  lldb/test/API/tools/lldb-server/main.cpp

Index: lldb/test/API/tools/lldb-server/main.cpp
===
--- lldb/test/API/tools/lldb-server/main.cpp
+++ lldb/test/API/tools/lldb-server/main.cpp
@@ -137,6 +137,22 @@
 #endif
 }
 
+static void trap() {
+#if defined(__x86_64__) || defined(__i386__)
+  asm volatile("int3");
+#elif defined(__aarch64__)
+  asm volatile("brk #0xf000");
+#elif defined(__arm__)
+  asm volatile("udf #254");
+#elif defined(__powerpc__)
+  asm volatile("trap");
+#elif __has_builtin(__builtin_debugtrap())
+  __builtin_debugtrap();
+#else
+#warning Don't know how to generate a trap. Some tests may fail.
+#endif
+}
+
 static void hello() {
   std::lock_guard lock(g_print_mutex);
   printf("hello, world\n");
@@ -330,6 +346,8 @@
   // Print the value of specified envvar to stdout.
   const char *value = getenv(arg.c_str());
   printf("%s\n", value ? value : "__unset__");
+} else if (consume_front(arg, "trap")) {
+  trap();
 } else {
   // Treat the argument as text for stdout.
   printf("%s\n", argv[i]);
Index: lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
===
--- lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -355,18 +355,7 @@
 reg_index += 1
 
 def Hg_switches_to_3_threads(self, pass_pid=False):
-# Startup the inferior with three threads (main + 2 new ones).
-procs = self.prep_debug_monitor_and_inferior(
-inferior_args=["thread:new", "thread:new"])
-
-# Let the inferior process have a few moments to start up the thread
-# when launched.  (The launch scenario has no time to run, so threads
-# won't be there yet.)
-self.run_process_then_stop(run_seconds=1)
-
-# Wait at most x seconds for 3 threads to be present.
-threads = self.wait_for_thread_count(3)
-self.assertEqual(len(threads), 3)
+_, threads = self.launch_with_threads(3)
 
 pid_str = ""
 if pass_pid:
@@ -397,30 +386,8 @@
 self.set_inferior_startup_launch()
 self.Hg_switches_to_3_threads()
 
-@expectedFailureAll(oslist=["windows"]) # expecting one more thread
-@skipIf(compiler="clang", compiler_version=['<', '11.0'])
-def test_Hg_switches_to_3_threads_attach(self):
-self.build()
-self.set_inferior_startup_attach()
-self.Hg_switches_to_3_threads()
-
-@expectedFailureAll(oslist=["windows"]) # expect 4 threads
-@add_test_categories(["llgs"])
-@skipIf(compiler="clang", compiler_version=['<', '11.0'])
-def test_Hg_switches_to_3_threads_attach_pass_correct_pid(self):
-self.build()
-self.set_inferior_startup_attach()
-self.Hg_switches_to_3_threads(pass_pid=True)
-
 def Hg_fails_on_pid(self, pass_pid):
-# Start the inferior.
-procs = self.prep_debug_monitor_and_inferior(
-inferior_args=["thread:new"])
-
-self.run_process_then_stop(run_seconds=1)
-
-threads = self.wait_for_thread_count(2)
-self.assertEqual(len(threads), 2)
+_, threads = self.launch_with_threads(2)
 
 if pass_pid == -1:
 pid_str = "p-1."
@@ -479,13 +446,6 @@
 self.test_sequence.add_log_lines(["read packet: $c#63"], True)
 context = self.expect_gdbremote_sequence()
 
-# Let the inferior process have a few moments to start up the thread when launched.
-# context = self.run_process_then_stop(run_seconds=1)
-
-# Wait at most x seconds for all threads to be present.
-# threads = self.wait_for_thread_count(NUM_THREADS)
-# self.assertEquals(len(threads), NUM_THREADS)
-
 signaled_tids = {}
 print_thread_ids = {}
 
@@ -1155,8 +1115,9 @@
 self.set_inferior_startup_launch()
 
 # Startup the inferior with three threads.
-procs = self.prep_debug_monitor_and_inferior(
-inferior_args=["thread:new", "thread:new"])
+_, threads = self.launch_with_threads(3)
+
+self.reset_test_sequence()
 self.add_thread_suffix_request_packets()
 self.add_register_info_collection_packets()
 self.add_process_info_collection_packets()
@@ -1178,15 +1139,6 @@

[Lldb-commits] [lldb] 9e69959 - [lldb] Adjust windows xfails for D119167

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T12:04:13+01:00
New Revision: 9e6995957ac2df6978d7ff1b9ae97d937d6ac85a

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

LOG: [lldb] Adjust windows xfails for D119167

A couple of additional tests pass with that patch. One new test fails
(because it's not testing a slightly different thing). I'll update it
later to restore the original meaning (I don't want to revert as the net
effect is still very positive), but for now this gets the bot green.

Added: 


Modified: 
lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
index fcab1ea0e49a9..fafaf953be522 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
@@ -125,11 +125,6 @@ def test_QListThreadsInStopReply_supported(self):
 context = self.expect_gdbremote_sequence()
 self.assertIsNotNone(context)
 
-# In current implementation of llgs on Windows, as a response to '\x03' 
packet, the debugger
-# of the native process will trigger a call to DebugBreakProcess that will 
create a new thread
-# to handle the exception debug event. So one more stop thread will be 
notified to the
-# delegate, e.g. llgs.  So tests below to assert the stop threads number 
will all fail.
-@expectedFailureAll(oslist=["windows"])
 @skipIfNetBSD
 def test_stop_reply_reports_multiple_threads(self):
 self.build()
@@ -141,7 +136,6 @@ def test_stop_reply_reports_multiple_threads(self):
 stop_reply_threads = self.gather_stop_reply_threads(5)
 self.assertEqual(len(stop_reply_threads), 5)
 
-@expectedFailureAll(oslist=["windows"])
 @skipIfNetBSD
 def test_no_QListThreadsInStopReply_supplies_no_threads(self):
 self.build()
@@ -151,7 +145,6 @@ def 
test_no_QListThreadsInStopReply_supplies_no_threads(self):
 stop_reply_threads = self.gather_stop_reply_threads(5)
 self.assertEqual(len(stop_reply_threads), 0)
 
-@expectedFailureAll(oslist=["windows"])
 @skipIfNetBSD
 def test_stop_reply_reports_correct_threads(self):
 self.build()
@@ -178,7 +171,6 @@ def test_stop_reply_reports_correct_threads(self):
 for tid in threads:
 self.assertIn(tid, stop_reply_threads)
 
-@expectedFailureAll(oslist=["windows"])
 @skipIfNetBSD
 def test_stop_reply_contains_thread_pcs(self):
 self.build()

diff  --git a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
index 92e0596731da8..e03756f240d09 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
@@ -78,6 +78,7 @@ def test_qThreadStopInfo_works_for_multiple_threads(self):
 
 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48418")
 @expectedFailureNetBSD
+@expectedFailureAll(oslist=["windows"])
 def 
test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self):
 self.build()
 self.set_inferior_startup_launch()

diff  --git a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py 
b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
index 4f19bac7441fa..c6ff42a9a522f 100644
--- a/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ b/lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -379,7 +379,6 @@ def Hg_switches_to_3_threads(self, pass_pid=False):
 self.assertIsNotNone(context.get("thread_id"))
 self.assertEqual(int(context.get("thread_id"), 16), thread)
 
-@expectedFailureAll(oslist=["windows"]) # expect 4 threads
 @skipIf(compiler="clang", compiler_version=['<', '11.0'])
 def test_Hg_switches_to_3_threads_launch(self):
 self.build()
@@ -402,21 +401,18 @@ def Hg_fails_on_pid(self, pass_pid):
 
 self.expect_gdbremote_sequence()
 
-@expectedFailureAll(oslist=["windows"])
 @add_test_categories(["llgs"])
 def test_Hg_fails_on_another_pid(self):
 self.build()
 self.set_inferior_startup_launch()
 self.Hg_fails_on_pid(1)
 
-@expectedFailureAll(oslist=["windows"])
 @add_test_categories(["llgs"])
 def test_Hg_fails_on_zero_pid(self):
 self.build()
 self.set_inferior_startup_launch()
 self.Hg_fails_on_pid(0)
 
-@expectedFailureAll(oslist=["windows"])
 @add_test_catego

[Lldb-commits] [lldb] 29caa85 - [lldb] Restore original meaning to test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T12:34:55+01:00
New Revision: 29caa8583f60ed5aa668144491ce65be00986947

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

LOG: [lldb] Restore original meaning to 
test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt

D119167 changed the meaning of that test by removing the use of the
interrupt packet. I did not notice this because the interrupting
happened in a shared utility function.

This patch restores the original meaning of the test, but (almost)
avoids sleeps by using process stdout to synchronize. Sadly, this means
the test stays disabled on windows, as it does not implement output
forwarding.

Added: 


Modified: 
lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py

Removed: 




diff  --git a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
index e03756f240d0..8fe3f777205a 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemote_qThreadStopInfo.py
@@ -9,18 +9,7 @@ class 
TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
 mydir = TestBase.compute_mydir(__file__)
 THREAD_COUNT = 5
 
-def gather_stop_replies_via_qThreadStopInfo(self, thread_count):
-context, threads = self.launch_with_threads(thread_count)
-
-# On Windows, there could be more threads spawned. For example, 
DebugBreakProcess will
-# create a new thread from the debugged process to handle an exception 
event. So here we
-# assert 'GreaterEqual' condition.
-triple = self.dbg.GetSelectedPlatform().GetTriple()
-if re.match(".*-.*-windows", triple):
-self.assertGreaterEqual(len(threads), thread_count)
-else:
-self.assertEqual(len(threads), thread_count)
-
+def gather_stop_replies_via_qThreadStopInfo(self, threads):
 # Grab stop reply for each thread via qThreadStopInfo{tid:hex}.
 stop_replies = {}
 thread_dicts = {}
@@ -62,13 +51,14 @@ def gather_stop_replies_via_qThreadStopInfo(self, 
thread_count):
 # Hang on to the key-val dictionary for the thread.
 thread_dicts[kv_thread_id] = kv_dict
 
-return (stop_replies, thread_dicts)
+return stop_replies
 
 @skipIfNetBSD
 def test_qThreadStopInfo_works_for_multiple_threads(self):
 self.build()
 self.set_inferior_startup_launch()
-(stop_replies, _) = 
self.gather_stop_replies_via_qThreadStopInfo(self.THREAD_COUNT)
+_, threads = self.launch_with_threads(self.THREAD_COUNT)
+stop_replies = self.gather_stop_replies_via_qThreadStopInfo(threads)
 triple = self.dbg.GetSelectedPlatform().GetTriple()
 # Consider one more thread created by calling DebugBreakProcess.
 if re.match(".*-.*-windows", triple):
@@ -78,12 +68,25 @@ def test_qThreadStopInfo_works_for_multiple_threads(self):
 
 @expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr48418")
 @expectedFailureNetBSD
-@expectedFailureAll(oslist=["windows"])
+@expectedFailureAll(oslist=["windows"]) # Output forwarding not implemented
 def 
test_qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self):
 self.build()
 self.set_inferior_startup_launch()
-
-(stop_replies, _) = 
self.gather_stop_replies_via_qThreadStopInfo(self.THREAD_COUNT)
+procs = self.prep_debug_monitor_and_inferior(
+inferior_args=["thread:new"]*4 + ["stop-me-now", "sleep:60"])
+
+self.test_sequence.add_log_lines([
+"read packet: $c#00",
+{"type": "output_match",
+"regex": 
self.maybe_strict_output_regex(r"stop-me-now\r\n")},
+"read packet: \x03",
+{"direction": "send",
+"regex": r"^\$T([0-9a-fA-F]{2})([^#]*)#..$"}], True)
+self.add_threadinfo_collection_packets()
+context = self.expect_gdbremote_sequence()
+threads = self.parse_threadinfo_packets(context)
+
+stop_replies = self.gather_stop_replies_via_qThreadStopInfo(threads)
 self.assertIsNotNone(stop_replies)
 
 no_stop_reason_count = sum(



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


[Lldb-commits] [PATCH] D117676: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-02-09 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
omjavaid added a comment.

ping!


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

https://reviews.llvm.org/D117676

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


[Lldb-commits] [PATCH] D117676: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-02-09 Thread Muhammad Omair Javaid via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG73a961b9cca1: [LLDB] Port toolchain-msvc.test for Arm/AArch4 
Windows (authored by omjavaid).
Herald added a project: LLDB.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117676

Files:
  lldb/test/Shell/BuildScript/toolchain-msvc.test

Index: lldb/test/Shell/BuildScript/toolchain-msvc.test
===
--- lldb/test/Shell/BuildScript/toolchain-msvc.test
+++ lldb/test/Shell/BuildScript/toolchain-msvc.test
@@ -1,62 +1,62 @@
-REQUIRES: system-windows, msvc
-
-RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X86 %s
-
-RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X64 %s
-
-X86: Script Arguments:
-X86:   Arch: 32
-X86:   Compiler: msvc
-X86:   Outdir: {{.*}}
-X86:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86:   Nodefaultlib: False
-X86:   Opt: none
-X86:   Mode: compile
-X86:   Clean: True
-X86:   Verbose: True
-X86:   Dryrun: True
-X86:   Inputs: foobar.c
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86: compiling foobar.c -> foo.exe-foobar.obj
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\cl.exe
-X86: linking foo.exe-foobar.obj -> foo.exe
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\link.exe
-X86:   Env
-X86: LIB = {{.*}}\ATLMFC\lib\x86
-X86:   {{.*}}\lib\x86
-X86:   {{.*}}\ucrt\x86
-X86:   {{.*}}\um\x86
-X86: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
-
-
-X64: Script Arguments:
-X64:   Arch: 64
-X64:   Compiler: msvc
-X64:   Outdir: {{.*}}
-X64:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64:   Nodefaultlib: False
-X64:   Opt: none
-X64:   Mode: compile
-X64:   Clean: True
-X64:   Verbose: True
-X64:   Dryrun: True
-X64:   Inputs: foobar.c
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64: compiling foobar.c -> foo.exe-foobar.obj
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\cl.exe
-X64: linking foo.exe-foobar.obj -> foo.exe
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\link.exe
-X64:   Env
-X64: LIB = {{.*}}\ATLMFC\lib\x64
-X64:   {{.*}}\lib\x64
-X64:   {{.*}}\ucrt\x64
-X64:   {{.*}}\um\x64
-X64: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
+REQUIRES: system-windows, msvc
+
+RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=32BIT %s
+
+RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o %t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=64BIT %s
+
+32BIT: Script Arguments:
+32BIT:   Arch: 32
+32BIT:   Compiler: msvc
+32BIT:   Outdir: {{.*}}
+32BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT:   Nodefaultlib: False
+32BIT:   Opt: none
+32BIT:   Mode: compile
+32BIT:   Clean: True
+32BIT:   Verbose: True
+32BIT:   Dryrun: True
+32BIT:   Inputs: foobar.c
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT: compiling foobar.c -> foo.exe-foobar.obj
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.exe
+32BIT: linking foo.exe-foobar.obj -> foo.exe
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.exe
+32BIT:   Env
+32BIT: LIB = {{.*}}\ATLMFC\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\ucrt\{{(x86|arm)}}
+32BIT:   {{.*}}\um\{{(x86|arm)}}
+32BIT: PATH = {{.*}}\bin\{{[Hh]ost[Xx](64|86)}}\{{(x86|x64)}}
+
+
+64BIT: Script Arguments:
+64BIT:   Arch: 64
+64BIT:   Compiler: msvc
+64BIT:   Outdir: {{.*}}
+64BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+64BIT:   Nodefaultlib: False
+64BIT:   Opt: none
+64BIT:   Mode: compile
+64BIT:   Clean: True
+64BIT:   Verbose: True
+64BIT:   Dryrun: True
+64BIT:   Inputs: foobar.c
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
+64BIT: compiling foobar.c -> foo.exe-foobar.obj
+64BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.exe
+64BIT: linking foo.exe-foobar.obj -> foo.exe
+64BIT:   Command Line: {{.*}}\{{[H

[Lldb-commits] [lldb] 73a961b - [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

2022-02-09 Thread Muhammad Omair Javaid via lldb-commits

Author: Muhammad Omair Javaid
Date: 2022-02-09T17:40:39+05:00
New Revision: 73a961b9cca1ecaa16ca7d9a456961ab6510bd1c

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

LOG: [LLDB] Port toolchain-msvc.test for Arm/AArch4 Windows

This patch updates toolchain-msvc.test to cater for Arm64 windows platform.

Reviewed By: labath

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

Added: 


Modified: 
lldb/test/Shell/BuildScript/toolchain-msvc.test

Removed: 




diff  --git a/lldb/test/Shell/BuildScript/toolchain-msvc.test 
b/lldb/test/Shell/BuildScript/toolchain-msvc.test
index 85a8f0d62f0ca..0ffd44489729f 100644
--- a/lldb/test/Shell/BuildScript/toolchain-msvc.test
+++ b/lldb/test/Shell/BuildScript/toolchain-msvc.test
@@ -1,62 +1,62 @@
-REQUIRES: system-windows, msvc
-
-RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o 
%t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X86 %s
-
-RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o 
%t/foo.exe foobar.c \
-RUN:| FileCheck --check-prefix=X64 %s
-
-X86: Script Arguments:
-X86:   Arch: 32
-X86:   Compiler: msvc
-X86:   Outdir: {{.*}}
-X86:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86:   Nodefaultlib: False
-X86:   Opt: none
-X86:   Mode: compile
-X86:   Clean: True
-X86:   Verbose: True
-X86:   Dryrun: True
-X86:   Inputs: foobar.c
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X86: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X86: compiling foobar.c -> foo.exe-foobar.obj
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\cl.exe
-X86: linking foo.exe-foobar.obj -> foo.exe
-X86:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x86\link.exe
-X86:   Env
-X86: LIB = {{.*}}\ATLMFC\lib\x86
-X86:   {{.*}}\lib\x86
-X86:   {{.*}}\ucrt\x86
-X86:   {{.*}}\um\x86
-X86: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
-
-
-X64: Script Arguments:
-X64:   Arch: 64
-X64:   Compiler: msvc
-X64:   Outdir: {{.*}}
-X64:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64:   Nodefaultlib: False
-X64:   Opt: none
-X64:   Mode: compile
-X64:   Clean: True
-X64:   Verbose: True
-X64:   Dryrun: True
-X64:   Inputs: foobar.c
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
-X64: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
-X64: compiling foobar.c -> foo.exe-foobar.obj
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\cl.exe
-X64: linking foo.exe-foobar.obj -> foo.exe
-X64:   Command Line: {{.*}}\{{[Hh]ost[Xx]64}}\x64\link.exe
-X64:   Env
-X64: LIB = {{.*}}\ATLMFC\lib\x64
-X64:   {{.*}}\lib\x64
-X64:   {{.*}}\ucrt\x64
-X64:   {{.*}}\um\x64
-X64: PATH = {{.*}}\bin\{{[Hh]ost[Xx]64}}\x64
+REQUIRES: system-windows, msvc
+
+RUN: %build -n --verbose --arch=32 --compiler=msvc --mode=compile-and-link -o 
%t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=32BIT %s
+
+RUN: %build -n --verbose --arch=64 --compiler=msvc --mode=compile-and-link -o 
%t/foo.exe foobar.c \
+RUN:| FileCheck --check-prefix=64BIT %s
+
+32BIT: Script Arguments:
+32BIT:   Arch: 32
+32BIT:   Compiler: msvc
+32BIT:   Outdir: {{.*}}
+32BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT:   Nodefaultlib: False
+32BIT:   Opt: none
+32BIT:   Mode: compile
+32BIT:   Clean: True
+32BIT:   Verbose: True
+32BIT:   Dryrun: True
+32BIT:   Inputs: foobar.c
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foobar.obj
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
+32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
+32BIT: compiling foobar.c -> foo.exe-foobar.obj
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.exe
+32BIT: linking foo.exe-foobar.obj -> foo.exe
+32BIT:   Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.exe
+32BIT:   Env
+32BIT: LIB = {{.*}}\ATLMFC\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\lib\{{(x86|arm)}}
+32BIT:   {{.*}}\ucrt\{{(x86|arm)}}
+32BIT:   {{.*}}\um\{{(x86|arm)}}
+32BIT: PATH = {{.*}}\bin\{{[Hh]ost[Xx](64|86)}}\{{(x86|x64)}}
+
+
+64BIT: Script Arguments:
+64BIT:   Arch: 64
+64BIT:   Compiler: msvc
+64BIT:   Outdir: {{.*}}
+64BIT:   Output: {{.*}}toolchain-msvc.test.tmp\foo.exe
+64BIT:   Nodefaultlib: False
+64BIT:   Opt: none
+64BIT:   Mode: compile
+64BIT:   Clean: True
+64BIT:   Verbose: True
+64BIT:   Dryrun: True
+64BIT:   Inputs: foobar.c
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foobar.ilk
+64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe-foob

[Lldb-commits] [lldb] 96000f5 - [lldb] Simplify SBCommandInterpreter::SourceInitFileInHomeDirectory

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T16:18:27+01:00
New Revision: 96000f5c2bf99365bb45528898c864fcb1c7780b

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

LOG: [lldb] Simplify SBCommandInterpreter::SourceInitFileInHomeDirectory

just have it delegate to the new overload.

Added: 


Modified: 
lldb/include/lldb/Interpreter/CommandInterpreter.h
lldb/source/API/SBCommandInterpreter.cpp

Removed: 




diff  --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h 
b/lldb/include/lldb/Interpreter/CommandInterpreter.h
index 3efb59fc05647..85eefcc899724 100644
--- a/lldb/include/lldb/Interpreter/CommandInterpreter.h
+++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h
@@ -252,7 +252,7 @@ class CommandInterpreter : public Broadcaster,
   }
 
   void SourceInitFileCwd(CommandReturnObject &result);
-  void SourceInitFileHome(CommandReturnObject &result, bool is_repl = false);
+  void SourceInitFileHome(CommandReturnObject &result, bool is_repl);
 
   bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
   bool can_replace);

diff  --git a/lldb/source/API/SBCommandInterpreter.cpp 
b/lldb/source/API/SBCommandInterpreter.cpp
index 073c1a1b042c2..4a1c3c6042c49 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -421,16 +421,7 @@ void SBCommandInterpreter::SourceInitFileInHomeDirectory(
 SBCommandReturnObject &result) {
   LLDB_INSTRUMENT_VA(this, result);
 
-  result.Clear();
-  if (IsValid()) {
-TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
-std::unique_lock lock;
-if (target_sp)
-  lock = std::unique_lock(target_sp->GetAPIMutex());
-m_opaque_ptr->SourceInitFileHome(result.ref());
-  } else {
-result->AppendError("SBCommandInterpreter is not valid");
-  }
+  SourceInitFileInHomeDirectory(result, /*is_repl=*/false);
 }
 
 void SBCommandInterpreter::SourceInitFileInHomeDirectory(



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


[Lldb-commits] [lldb] 9611282 - [lldb] Stabilize threaded windows lldb-server tests

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T16:18:27+01:00
New Revision: 9611282c64f4cec1d6d0d997202762fa38e99663

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

LOG: [lldb] Stabilize threaded windows lldb-server tests

The tests enabled in 9e699595 are not passing reliably -- sometimes they
report seeing fewer threads than expected.

Based on my (limited) research, this is not a lldb bug, but simply a
consequence of the operating system reporting their presence
asynchronously -- they're reported when they are scheduled to run (or
something similar), and not at the time of the CreateThread call.

To fix this, I add some additional synchronization to the test inferior,
which makes sure that the created thread is alive before continuing to
do other things.

Added: 


Modified: 
lldb/test/API/tools/lldb-server/main.cpp

Removed: 




diff  --git a/lldb/test/API/tools/lldb-server/main.cpp 
b/lldb/test/API/tools/lldb-server/main.cpp
index 59e921f312f43..0383acc68fccf 100644
--- a/lldb/test/API/tools/lldb-server/main.cpp
+++ b/lldb/test/API/tools/lldb-server/main.cpp
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -158,7 +159,8 @@ static void hello() {
   printf("hello, world\n");
 }
 
-static void *thread_func(void *arg) {
+static void *thread_func(std::promise ready) {
+  ready.set_value();
   static std::atomic s_thread_index(1);
   const int this_thread_index = s_thread_index++;
   if (g_print_thread_ids) {
@@ -328,7 +330,10 @@ int main(int argc, char **argv) {
 _exit(0);
 #endif
 } else if (consume_front(arg, "thread:new")) {
-threads.push_back(std::thread(thread_func, nullptr));
+  std::promise promise;
+  std::future ready = promise.get_future();
+  threads.push_back(std::thread(thread_func, std::move(promise)));
+  ready.wait();
 } else if (consume_front(arg, "thread:print-ids")) {
   // Turn on thread id announcing.
   g_print_thread_ids = true;



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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3305973 , @shafik wrote:

> I believe this a program like this
>
>   int main() {
> int arr[2]{0};
>   
> return arr[1];
>   } 
>
> and an expression like this `expr arr[0]` will give us the constant 
> expression `getelementptr` at least my testing seems to show that.

This example produces the following code for me:

  %4 = load [2 x i32]*, [2 x i32]** %1, align 8
  %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
  store i32* %arrayidx, i32** %3, align 8
  br label %init.end

This is successfully interpreted via IRInterpreter with the current patch (i.e. 
all arguments seem to be `ConstantInt`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [lldb] afb446e - [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via lldb-commits

Author: Andy Yankovsky
Date: 2022-02-09T17:38:38+01:00
New Revision: afb446e8a61de4a41504a71f61a4b1d93ce22716

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

LOG: [lldb] Constant-resolve operands to `getelementptr`

Operands to `getelementptr` can be constants or constant expressions. Check
that all operands can be constant-resolved and resolve them during the
evaluation. If some operands can't be resolved as constants -- the expression
evaluation will fallback to JIT.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=52449

Reviewed By: #lldb, shafik

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

Added: 


Modified: 
lldb/source/Expression/IRInterpreter.cpp
lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py

Removed: 




diff  --git a/lldb/source/Expression/IRInterpreter.cpp 
b/lldb/source/Expression/IRInterpreter.cpp
index 21348be1578ff..2ad51d0e84027 100644
--- a/lldb/source/Expression/IRInterpreter.cpp
+++ b/lldb/source/Expression/IRInterpreter.cpp
@@ -285,9 +285,11 @@ class InterpreterStackFrame {
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
-
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
+
+  // DataLayout::getIndexedOffsetInType assumes the indices are
+  // instances of ConstantInt.
   uint64_t offset =
   m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
 
@@ -466,12 +468,20 @@ static bool CanResolveConstant(llvm::Constant *constant) {
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
+// Check that the base can be constant-resolved.
 ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
 Constant *base = dyn_cast(*op_cursor);
-if (!base)
+if (!base || !CanResolveConstant(base))
   return false;
 
-return CanResolveConstant(base);
+// Check that all other operands are just ConstantInt.
+for (Value *op : make_range(constant_expr->op_begin() + 1,
+constant_expr->op_end())) {
+  ConstantInt *constant_int = dyn_cast(op);
+  if (!constant_int)
+return false;
+}
+return true;
   }
   }
 } else {

diff  --git a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py 
b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
index 07ec5c52ea4c7..503e0d1341566 100644
--- a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@ def test_access_without_scope(self):
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertSuccess(value.GetError())



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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGafb446e8a61d: [lldb] Constant-resolve operands to 
`getelementptr` (authored by werat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

Files:
  lldb/source/Expression/IRInterpreter.cpp
  lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression 
involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", 
lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, opts)
+self.assertTrue(value.GetError().Fail())
+self.assertIn(
+"Can't evaluate the expression without a running target",
+value.GetError().GetCString())
+
+# Evaluating the expression via JIT should work fine.
+value = self.target().EvaluateExpression(expr)
+self.assertSuccess(value.GetError())
Index: lldb/source/Expression/IRInterpreter.cpp
===
--- lldb/source/Expression/IRInterpreter.cpp
+++ lldb/source/Expression/IRInterpreter.cpp
@@ -285,9 +285,11 @@
 return true; // no offset to apply!
 
   SmallVector indices(op_cursor, op_end);
-
   Type *src_elem_ty =
   cast(constant_expr)->getSourceElementType();
+
+  // DataLayout::getIndexedOffsetInType assumes the indices are
+  // instances of ConstantInt.
   uint64_t offset =
   m_target_data.getIndexedOffsetInType(src_elem_ty, indices);
 
@@ -466,12 +468,20 @@
   case Instruction::BitCast:
 return CanResolveConstant(constant_expr->getOperand(0));
   case Instruction::GetElementPtr: {
+// Check that the base can be constant-resolved.
 ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin();
 Constant *base = dyn_cast(*op_cursor);
-if (!base)
+if (!base || !CanResolveConstant(base))
   return false;
 
-return CanResolveConstant(base);
+// Check that all other operands are just ConstantInt.
+for (Value *op : make_range(constant_expr->op_begin() + 1,
+constant_expr->op_end())) {
+  ConstantInt *constant_int = dyn_cast(op);
+  if (!constant_int)
+return false;
+}
+return true;
   }
   }
 } else {


Index: lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
===
--- lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -41,3 +41,31 @@
 self.createTestTarget()
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
+
+def test_no_crash_in_IR_arithmetic(self):
+"""
+Test that LLDB doesn't crash on evaluating specific expression involving
+pointer arithmetic and taking the address of a static class member.
+See https://bugs.llvm.org/show_bug.cgi?id=52449
+"""
+self.build()
+lldbutil.run_to_source_breakpoint(self, "// stop in main", lldb.SBFileSpec("main.cpp"))
+
+# This expression contains the following IR code:
+# ... i64 ptrtoint (i32* @_ZN1A3s_cE to i64)) ...
+expr = "(int*)100 + (long long)(&A::s_c)"
+
+# The IR interpreter doesn't support non-const operands to the
+# `GetElementPtr` IR instruction, so verify that it correctly fails to
+# evaluate expression.
+opts = lldb.SBExpressionOptions()
+opts.SetAllowJIT(False)
+value = self.target().EvaluateExpression(expr, 

[Lldb-commits] [lldb] 1046b72 - [lldb] Account for extra threads in TestGdbRemoteThreadsInStopReply on windows

2022-02-09 Thread Pavel Labath via lldb-commits

Author: Pavel Labath
Date: 2022-02-09T17:42:54+01:00
New Revision: 1046b726ad4461d0ba0a8c9391836b679a719a60

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

LOG: [lldb] Account for extra threads in TestGdbRemoteThreadsInStopReply on 
windows

After 9611282c, TestGdbRemoteThreadsInStopReply is not non-deterministic
-- instead it deterministically fails due to extra threads created by
std::thread thread pool.

Adjust the tests to account for that.

Added: 


Modified: 
lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py

Removed: 




diff  --git 
a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py 
b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
index fafaf953be52..11ebba827515 100644
--- a/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteThreadsInStopReply.py
@@ -126,6 +126,7 @@ def test_QListThreadsInStopReply_supported(self):
 self.assertIsNotNone(context)
 
 @skipIfNetBSD
+@expectedFailureAll(oslist=["windows"]) # Extra threads present
 def test_stop_reply_reports_multiple_threads(self):
 self.build()
 self.set_inferior_startup_launch()
@@ -165,7 +166,7 @@ def test_stop_reply_reports_correct_threads(self):
 
 threads = self.parse_threadinfo_packets(context)
 self.assertIsNotNone(threads)
-self.assertEqual(len(threads), thread_count)
+self.assertGreaterEqual(len(threads), thread_count)
 
 # Ensure each thread in q{f,s}ThreadInfo appears in stop reply threads
 for tid in threads:
@@ -182,12 +183,12 @@ def test_stop_reply_contains_thread_pcs(self):
 stop_reply_pcs = results["thread_pcs"]
 pc_register = results["pc_register"]
 little_endian = results["little_endian"]
-self.assertEqual(len(stop_reply_pcs), thread_count)
+self.assertGreaterEqual(len(stop_reply_pcs), thread_count)
 
 threads_info_pcs = self.gather_threads_info_pcs(pc_register,
 little_endian)
 
-self.assertEqual(len(threads_info_pcs), thread_count)
+self.assertEqual(len(threads_info_pcs), len(stop_reply_pcs))
 for thread_id in stop_reply_pcs:
 self.assertIn(thread_id, threads_info_pcs)
 self.assertEqual(int(stop_reply_pcs[thread_id], 16),



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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Stella Stamenova via Phabricator via lldb-commits
stella.stamenova added a comment.

It looks like the new test is failing on the Windows bot:

https://lab.llvm.org/buildbot/#/builders/83/builds/15049


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D119146: [lldb/Platform] Decouple instance and plugin names

2022-02-09 Thread Greg Clayton via Phabricator via lldb-commits
clayborg added a comment.

I am fine with this. Only suggestion is to use ConstString still for the 
m_instance_name since we might compare against this name if we are looking for 
one with a matching name (instead of std::string).




Comment at: lldb/include/lldb/Target/Platform.h:889
   bool m_system_arch_set_while_connected;
+  const std::string m_instance_name;
   ConstString

Do we want to make this a ConstString so finding matching instances is quick 
and just a pointer compare?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119146

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


[Lldb-commits] [lldb] e0f2375 - [lldb] Disable failing test on Windows

2022-02-09 Thread Andy Yankovsky via lldb-commits

Author: Andy Yankovsky
Date: 2022-02-09T20:40:50+01:00
New Revision: e0f2375b5262d0dd778ecaf0628f905d241da733

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

LOG: [lldb] Disable failing test on Windows

Test was introduced in https://reviews.llvm.org/D113498.

Added: 


Modified: 
lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py

Removed: 




diff  --git a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py 
b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
index 503e0d1341566..7cb4c51b02b30 100644
--- a/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
+++ b/lldb/test/API/lang/cpp/static_members/TestCPPStaticMembers.py
@@ -42,6 +42,8 @@ def test_access_without_scope(self):
 self.expect("expression s_c", error=True,
 startstr="error: use of undeclared identifier 's_d'")
 
+# We fail to lookup static members on Windows.
+@expectedFailureAll(oslist=["windows"])
 def test_no_crash_in_IR_arithmetic(self):
 """
 Test that LLDB doesn't crash on evaluating specific expression 
involving



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


[Lldb-commits] [PATCH] D113498: [lldb] Constant-resolve operands to `getelementptr`

2022-02-09 Thread Andy Yankovsky via Phabricator via lldb-commits
werat added a comment.

In D113498#3308499 , 
@stella.stamenova wrote:

> It looks like the new test is failing on the Windows bot:
>
> https://lab.llvm.org/buildbot/#/builders/83/builds/15049

Whoops, static lookup seem to be broken on Windows (other tests in this file 
skip Windows altogether). I've disabled this test in 
https://github.com/llvm/llvm-project/commit/e0f2375b5262d0dd778ecaf0628f905d241da733
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113498

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


[Lldb-commits] [PATCH] D118482: [lldb/Plugins] Add lldb.ScriptedProcess.get_most_relevant_thread_index interpreter method

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib abandoned this revision.
mib added a comment.

@jingham I just got rid of all of this, and added a `is_stopped` variable to 
the `stack_core_scripted_process.StackCoreScriptedThread` class in D118484 
.


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

https://reviews.llvm.org/D118482

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


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

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 407264.
mib edited the summary of this revision.
mib added a comment.

Added a `is_stopped` member variable to StackCoreScriptedThread since I 
abandoned D118482 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118484

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

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -30,6 +30,9 @@
 
 self.threads[corefile_thread.GetThreadID()] = StackCoreScriptedThread(self, structured_data)
 
+if len(self.threads) == 3:
+self.threads[len(self.threads) - 1].is_stopped = True
+
 def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
 mem_region = lldb.SBMemoryRegionInfo()
 error = self.corefile_process.GetMemoryRegionInfo(addr, mem_region)
@@ -80,6 +83,7 @@
 super().__init__(process, args)
 backing_target_idx = args.GetValueForKey("backing_target_idx")
 thread_idx = args.GetValueForKey("thread_idx")
+self.is_stopped = False
 
 def extract_value_from_structured_data(data, default_val):
 if data and data.IsValid():
@@ -119,17 +123,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
+if self.corefile_thread and self.corefile_thread.IsValid() \
+and self.get_thread_id() == self.corefile_thread.GetThreadID():
+stop_reason["type"] = lldb.eStopReasonNone
 
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.is_stopped:
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -196,6 +196,22 @@
 self.assertTrue(thread, "Invalid thread.")
 self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
+self.assertTrue(target.triple, "Invalid target triple")
+arch = target.triple.split('-')[0]
+supported_arch = ['x86_64', 'arm64', 'arm64e']
+self.assertIn(arch, supported_arch)
+# When creating a corefile of a arm process, lldb saves the exception
+# that triggers the breakpoint in the LC_NOTES of the corefile, so they
+# can be reloaded with the corefile on the next debug session.
+if arch in 'arm64e':
+self.assertTrue(thread.GetStopReason(), lldb.eStopReasonException)
+# However, it's archite

[Lldb-commits] [lldb] 48d8890 - [LLDB][NativePDB] fix that FindSymbolScope never finds scope of a symbol if it doesn't open a scope

2022-02-09 Thread Zequan Wu via lldb-commits

Author: Zequan Wu
Date: 2022-02-09T13:20:45-08:00
New Revision: 48d889079a8a050bb41defd5688e0b213c1c5655

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

LOG: [LLDB][NativePDB] fix that FindSymbolScope never finds scope of a symbol 
if it doesn't open a scope

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp 
b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
index dc0969a0ce7c6..ddc52a6ec9276 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp
@@ -118,12 +118,6 @@ static llvm::Optional 
FindSymbolScope(PdbIndex &index,
   std::vector scope_stack;
 
   while (begin != end) {
-if (id.offset == begin.offset()) {
-  // We have a match!  Return the top of the stack
-  if (scope_stack.empty())
-return llvm::None;
-  return scope_stack.back();
-}
 if (begin.offset() > id.offset) {
   // We passed it.  We couldn't even find this symbol record.
   lldbassert(false && "Invalid compiland symbol id!");
@@ -136,7 +130,7 @@ static llvm::Optional 
FindSymbolScope(PdbIndex &index,
   // We can use the end offset of the scope to determine whether or not
   // we can just outright skip this entire scope.
   uint32_t scope_end = getScopeEndOffset(*begin);
-  if (scope_end < id.modi) {
+  if (scope_end < id.offset) {
 begin = syms.at(scope_end);
   } else {
 // The symbol we're looking for is somewhere in this scope.
@@ -147,8 +141,10 @@ static llvm::Optional 
FindSymbolScope(PdbIndex &index,
 }
 ++begin;
   }
-
-  return llvm::None;
+  if (scope_stack.empty())
+return llvm::None;
+  // We have a match!  Return the top of the stack
+  return scope_stack.back();
 }
 
 static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr) {



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


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

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 407269.
mib edited the summary of this revision.
mib added a comment.

Disable debug info testing.


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

https://reviews.llvm.org/D118513

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

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

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

2022-02-09 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.

Ship it


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

https://reviews.llvm.org/D118513

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


[Lldb-commits] [lldb] f5e5074 - [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

2022-02-09 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-02-09T13:28:20-08:00
New Revision: f5e5074c40be29d3a0c5d4ac616df8e61e4ddc63

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

LOG: [lldb/test] Fix TestScriptedProcess.py timeout on x86_64

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

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

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

Signed-off-by: Med Ismail Bennani 

Added: 


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

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

Removed: 




diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index 83ec3513cfcd7..363d39a43960b 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -32,8 +32,12 @@ def __init__(self, target, args):
 """
 self.target = None
 self.args = None
+self.arch = None
 if isinstance(target, lldb.SBTarget) and target.IsValid():
 self.target = target
+triple = self.target.triple
+if triple:
+self.arch = triple.split('-')[0]
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -201,19 +205,21 @@ class ScriptedThread:
 """
 
 @abstractmethod
-def __init__(self, process, args):
+def __init__(self, scripted_process, args):
 """ Construct a scripted thread.
 
 Args:
-process (lldb.SBProcess): The scripted process owning this thread.
+process (ScriptedProcess): The scripted process owning this thread.
 args (lldb.SBStructuredData): A Dictionary holding arbitrary
 key/value pairs used by the scripted thread.
 """
 self.target = None
+self.scripted_process = None
 self.process = None
 self.args = None
-if isinstance(process, ScriptedProcess):
-self.target = process.target
+if isinstance(scripted_process, ScriptedProcess):
+self.target = scripted_process.target
+self.scripted_process = scripted_process
 self.process = self.target.GetProcess()
 
 self.id = None
@@ -302,73 +308,13 @@ def __init__(idx, cfa, pc, symbol_ctx):
 def get_register_info(self):
 if self.register_info is None:
 self.register_info = dict()
-triple = self.target.triple
-if triple:
-arch = triple.split('-')[0]
-if arch == 'x86_64':
-self.register_info['sets'] = ['General Purpose Registers']
-self.register_info['registers'] = [
-{'name': 'rax', 'bitsize': 64, 'offset': 0, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 0, 'dwarf': 0},
-{'name': 'rbx', 'bitsize': 64, 'offset': 8, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 3, 'dwarf': 3},
-{'name': 'rcx', 'bitsize': 64, 'offset': 16, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 2, 'dwarf': 2, 'generic': 
'arg4', 'alt-name': 'arg4'},
-{'name': 'rdx', 'bitsize': 64, 'offset': 24, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 1, 'dwarf': 1, 'generic': 
'arg3', 'alt-name': 'arg3'},
-{'name': 'rdi', 'bitsize': 64, 'offset': 32, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 5, 'dwarf': 5, 'generic': 
'arg1', 'alt-name': 'arg1'},
-{'name': 'rsi', 'bitsize': 64, 'offset': 40, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 4, 'dwarf': 4, 'generic': 
'arg2', 'alt-name': 'arg2'},
-{'name': 'rbp', 'bitsize': 64, 'offset': 48, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 6, 'dwarf': 6, 'generic': 
'fp', 'alt-name': 'fp'},
-{'name': 'rsp', 'bitsize': 64, 'offset': 56, 
'encoding': 'uint', 'format': 'hex', 'set': 0, 'gcc': 7, 'dwarf': 7, 'generic': 
'sp', 'alt-name': 'sp'},
-{'name

[Lldb-commits] [lldb] 9a9bf12 - [lldb/crashlog] Fix arm64 register parsing on crashlog.py

2022-02-09 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-02-09T13:28:20-08:00
New Revision: 9a9bf12c4a10aa87f15463fbe0021f99012a88df

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

LOG: [lldb/crashlog] Fix arm64 register parsing on crashlog.py

This patch fixes the register parser for arm64 crashlogs.

Compared to x86_64 crashlogs, the arm64 crashlogs nests the general
purpose registers into a separate dictionary within `thread_state`
dictionary. It uses the dictionary key as the the register number.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/crashlog.py

Removed: 




diff  --git a/lldb/examples/python/crashlog.py 
b/lldb/examples/python/crashlog.py
index 54fc888c509c8..b8fe642db849d 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -520,17 +520,21 @@ def parse_threads(self, json_threads):
 self.crashlog.threads.append(thread)
 idx += 1
 
-def parse_thread_registers(self, json_thread_state):
+def parse_thread_registers(self, json_thread_state, prefix=None):
 registers = dict()
 for key, state in json_thread_state.items():
 if key == "rosetta":
-   registers.update(self.parse_thread_registers(state))
-   continue
+registers.update(self.parse_thread_registers(state))
+continue
+if key == "x":
+gpr_dict = { str(idx) : reg for idx,reg in enumerate(state) }
+registers.update(self.parse_thread_registers(gpr_dict, key))
+continue
 try:
-   value = int(state['value'])
-   registers[key] = value
+value = int(state['value'])
+registers["{}{}".format(prefix,key)] = value
 except (KeyError, ValueError, TypeError):
-   pass
+pass
 return registers
 
 def parse_errors(self, json_data):



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


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

2022-02-09 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2022-02-09T13:28:20-08:00
New Revision: d327108d175fc5d1d4f5c018d129e337d162810c

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

LOG: [lldb/test] Split Scripted Process test in multiple tests (NFC)

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

This also disables debug info testing.

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

Signed-off-by: Med Ismail Bennani 

Added: 

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

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

Removed: 




diff  --git 
a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py 
b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
index c8ce37c24d49..4f0981d8f3ac 100644
--- a/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ b/lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -2,7 +2,7 @@
 Test python scripted process in lldb
 """
 
-import os, json, tempfile
+import os
 
 import lldb
 from lldbsuite.test.decorators import *
@@ -12,6 +12,8 @@
 
 class ScriptedProcesTestCase(TestBase):
 
+NO_DEBUG_INFO_TESTCASE = True
+
 mydir = TestBase.compute_mydir(__file__)
 
 def setUp(self):
@@ -131,90 +133,3 @@ def cleanup():
 break
 self.assertEqual(idx, int(reg.value, 16))
 
-def create_stack_skinny_corefile(self, file):
-self.build()
-target, process, thread, _ = lldbutil.run_to_source_breakpoint(self, 
"// break here",
-   
lldb.SBFileSpec("main.cpp"))
-self.assertTrue(process.IsValid(), "Process is invalid.")
-# FIXME: Use SBAPI to save the process corefile.
-self.runCmd("process save-core -s stack  " + file)
-self.assertTrue(os.path.exists(file), "No stack-only corefile found.")
-self.assertTrue(self.dbg.DeleteTarget(target), "Couldn't delete 
target")
-
-@skipUnlessDarwin
-@skipIf(archs=no_match(['arm64', 'arm64e']))
-@skipIfOutOfTreeDebugserver
-def test_launch_scripted_process_stack_frames(self):
-"""Test that we can launch an lldb scripted process from the command
-line, check its process ID and read string from memory."""
-self.build()
-target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
-self.assertTrue(target, VALID_TARGET)
-
-for module in target.modules:
-if 'a.out' in module.GetFileSpec().GetFilename():
-main_module = module
-break
-
-self.assertTrue(main_module, "Invalid main module.")
-error = target.SetModuleLoadAddress(main_module, 0)
-self.assertTrue(error.Success(), "Reloading main module at offset 0 
failed.")
-
-os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
-def cleanup():
-  del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"]
-self.addTearDownHook(cleanup)
-
-scripted_process_example_relpath = 'stack_core_scripted_process.py'
-self.runCmd("command script import " + 
os.path.join(self.getSourceDir(),
-
scripted_process_example_relpath))
-
-corefile_process = None
-with tempfile.NamedTemporaryFile() as file:
-self.create_stack_skinny_corefile(file.name)
-corefile_target = self.dbg.CreateTarget(None)
-corefile_process = 
corefile_target.LoadCore(self.getBuildArtifact(file.name))
-self.assertTrue(corefile_process, PROCESS_IS_VALID)
-
-structured_data = lldb.SBStructuredData()
-structured_data.SetFromJSON(json.dumps({
-"backing_target_idx" : 
self.dbg.GetIndexOfTarget(corefile_process.GetTarget())
-}))
-launch_info = lldb.SBLaunchInfo(None)
-launch_info.SetProcessPluginName("ScriptedProcess")
-
launch_info.SetScriptedProcessClassName("stack_core_scripted_process.StackCoreScriptedProcess")
-launch_info.SetScriptedProcessDictionary(structured_data)
-
-error = lldb.SBError()
-process = target.Launch(launch_info, error)
-self.assertTrue(error.Success(), error.GetCString())
-self.assertTrue(process, PROCESS_IS_VALID)
-self.assertEqual(process.GetProcessID(), 42)
-
-self.assertEqual(process.GetNumThreads(), 3)
-thread = process.GetThreadAtIndex(2)
-self.assertTrue(thread, "Invalid thread.")
-self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
-
-self.assertTrue(target.triple, "Invalid target tripl

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

2022-02-09 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 rGf5e5074c40be: [lldb/test] Fix TestScriptedProcess.py timeout 
on x86_64 (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118484

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

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -30,6 +30,9 @@
 
 self.threads[corefile_thread.GetThreadID()] = StackCoreScriptedThread(self, structured_data)
 
+if len(self.threads) == 3:
+self.threads[len(self.threads) - 1].is_stopped = True
+
 def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
 mem_region = lldb.SBMemoryRegionInfo()
 error = self.corefile_process.GetMemoryRegionInfo(addr, mem_region)
@@ -80,6 +83,7 @@
 super().__init__(process, args)
 backing_target_idx = args.GetValueForKey("backing_target_idx")
 thread_idx = args.GetValueForKey("thread_idx")
+self.is_stopped = False
 
 def extract_value_from_structured_data(data, default_val):
 if data and data.IsValid():
@@ -119,17 +123,19 @@
 def get_stop_reason(self) -> Dict[str, Any]:
 stop_reason = { "type": lldb.eStopReasonInvalid, "data": {  }}
 
-if self.corefile_thread and self.corefile_thread.IsValid:
-stop_reason["type"] = self.corefile_thread.GetStopReason()
+if self.corefile_thread and self.corefile_thread.IsValid() \
+and self.get_thread_id() == self.corefile_thread.GetThreadID():
+stop_reason["type"] = lldb.eStopReasonNone
 
-if self.corefile_thread.GetStopReasonDataCount() > 0:
-if stop_reason["type"] == lldb.eStopReasonBreakpoint:
-stop_reason["data"]["break_id"] = self.corefile_thread.GetStopReasonDataAtIndex(0)
-stop_reason["data"]["break_loc_id"] = self.corefile_thread.GetStopReasonDataAtIndex(1)
-elif stop_reason["type"] == lldb.eStopReasonSignal:
-stop_reason["data"]["signal"] = signal.SIGINT
-elif stop_reason["type"] == lldb.eStopReasonException:
+if self.is_stopped:
+if 'arm64' in self.scripted_process.arch:
+stop_reason["type"] = lldb.eStopReasonException
 stop_reason["data"]["desc"] = self.corefile_thread.GetStopDescription(100)
+elif self.scripted_process.arch == 'x86_64':
+stop_reason["type"] = lldb.eStopReasonSignal
+stop_reason["data"]["signal"] = signal.SIGTRAP
+else:
+stop_reason["type"] = self.corefile_thread.GetStopReason()
 
 return stop_reason
 
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -54,7 +54,7 @@
 
 def get_stop_reason(self) -> Dict[str, Any]:
 return { "type": lldb.eStopReasonSignal, "data": {
-"signal": signal.SIGINT
+"signal": signal.SIGTRAP
 } }
 
 def get_stackframes(self):
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -196,6 +196,22 @@
 self.assertTrue(thread, "Invalid thread.")
 self.assertEqual(thread.GetName(), "StackCoreScriptedThread.thread-2")
 
+self.assertTrue(target.triple, "Invalid target triple")
+arch = target.triple.split('-')[0]
+supported_arch = ['x86_64', 'arm64', 'arm64e']
+self.assertIn(arch, supported_arch)
+# When creating a corefile of a arm process, lldb saves the exception
+# that triggers the breakpoint in the LC_NOTES of the corefile, so they
+# can be reloaded with the corefile on the next debug session.
+if arch in 'arm64e':
+self.assertTrue(thread.GetStopReason(), lldb.eStopReasonException)
+# However, it's

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

2022-02-09 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 rGd327108d175f: [lldb/test] Split Scripted Process test in 
multiple tests (NFC) (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D118513?vs=407269&id=407276#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118513

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

Index: lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestStackCoreScriptedProcess.py
@@ -10,7 +10,9 @@
 from lldbsuite.test import lldbutil
 from lldbsuite.test import lldbtest
 
-class ScriptedProcesTestCase(TestBase):
+class StackCoreScriptedProcesTestCase(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
 
 mydir = TestBase.compute_mydir(__file__)
 
@@ -20,117 +22,6 @@
 def tearDown(self):
 TestBase.tearDown(self)
 
-def test_python_plugin_package(self):
-"""Test that the lldb python module has a `plugins.scripted_process`
-package."""
-self.expect('script import lldb.plugins',
-substrs=["ModuleNotFoundError"], matching=False)
-
-self.expect('script dir(lldb.plugins)',
-substrs=["scripted_process"])
-
-self.expect('script import lldb.plugins.scripted_process',
-substrs=["ModuleNotFoundError"], matching=False)
-
-self.expect('script dir(lldb.plugins.scripted_process)',
-substrs=["ScriptedProcess"])
-
-self.expect('script from lldb.plugins.scripted_process import ScriptedProcess',
-substrs=["ImportError"], matching=False)
-
-self.expect('script dir(ScriptedProcess)',
-substrs=["launch"])
-
-@skipUnlessDarwin
-def test_invalid_scripted_register_context(self):
-"""Test that we can launch an lldb scripted process with an invalid
-Scripted Thread, with invalid register context."""
-self.build()
-target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
-self.assertTrue(target, VALID_TARGET)
-log_file = self.getBuildArtifact('thread.log')
-self.runCmd("log enable lldb thread -f " + log_file)
-self.assertTrue(os.path.isfile(log_file))
-
-os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
-def cleanup():
-  del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"]
-self.addTearDownHook(cleanup)
-
-scripted_process_example_relpath = 'invalid_scripted_process.py'
-self.runCmd("command script import " + os.path.join(self.getSourceDir(),
-scripted_process_example_relpath))
-
-launch_info = lldb.SBLaunchInfo(None)
-launch_info.SetProcessPluginName("ScriptedProcess")
-launch_info.SetScriptedProcessClassName("invalid_scripted_process.InvalidScriptedProcess")
-error = lldb.SBError()
-
-process = target.Launch(launch_info, error)
-
-self.assertTrue(error.Success(), error.GetCString())
-self.assertTrue(process, PROCESS_IS_VALID)
-self.assertEqual(process.GetProcessID(), 666)
-self.assertEqual(process.GetNumThreads(), 0)
-
-with open(log_file, 'r') as f:
-log = f.read()
-
-self.assertIn("Failed to get scripted thread registers data.", log)
-
-@skipIf(archs=no_match(['x86_64', 'arm64', 'arm64e']))
-def test_scripted_process_and_scripted_thread(self):
-"""Test that we can launch an lldb scripted process using the SBAPI,
-check its process ID, read string from memory, check scripted thread
-id, name stop reason and register context.
-"""
-self.build()
-target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
-self.assertTrue(target, VALID_TARGET)
-
-os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
-def cleanup():
-  del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"]
-self.addTearDownHook(cleanup)
-
-scripted_process_example_relpath = 'dummy_scripted_process.py'
-self.runCmd("command script import " + os.path.join(self.getSourceDir(),
-scripted_process_example_relpath))
-
-launch_info = lldb.SBLaunchInfo(None)
-launch_info.SetProcessPluginName("ScriptedProcess")
-launch_info.SetScriptedProcessClassName("dummy_scripted_process.DummyScriptedProcess")
-
-error = lldb.SBError()
-process = target.Launch(l

[Lldb-commits] [PATCH] D119168: [lldb/crashlog] Fix arm64 register parsing on crashlog.py

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a9bf12c4a10: [lldb/crashlog] Fix arm64 register parsing on 
crashlog.py (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119168

Files:
  lldb/examples/python/crashlog.py


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -520,17 +520,21 @@
 self.crashlog.threads.append(thread)
 idx += 1
 
-def parse_thread_registers(self, json_thread_state):
+def parse_thread_registers(self, json_thread_state, prefix=None):
 registers = dict()
 for key, state in json_thread_state.items():
 if key == "rosetta":
-   registers.update(self.parse_thread_registers(state))
-   continue
+registers.update(self.parse_thread_registers(state))
+continue
+if key == "x":
+gpr_dict = { str(idx) : reg for idx,reg in enumerate(state) }
+registers.update(self.parse_thread_registers(gpr_dict, key))
+continue
 try:
-   value = int(state['value'])
-   registers[key] = value
+value = int(state['value'])
+registers["{}{}".format(prefix,key)] = value
 except (KeyError, ValueError, TypeError):
-   pass
+pass
 return registers
 
 def parse_errors(self, json_data):


Index: lldb/examples/python/crashlog.py
===
--- lldb/examples/python/crashlog.py
+++ lldb/examples/python/crashlog.py
@@ -520,17 +520,21 @@
 self.crashlog.threads.append(thread)
 idx += 1
 
-def parse_thread_registers(self, json_thread_state):
+def parse_thread_registers(self, json_thread_state, prefix=None):
 registers = dict()
 for key, state in json_thread_state.items():
 if key == "rosetta":
-   registers.update(self.parse_thread_registers(state))
-   continue
+registers.update(self.parse_thread_registers(state))
+continue
+if key == "x":
+gpr_dict = { str(idx) : reg for idx,reg in enumerate(state) }
+registers.update(self.parse_thread_registers(gpr_dict, key))
+continue
 try:
-   value = int(state['value'])
-   registers[key] = value
+value = int(state['value'])
+registers["{}{}".format(prefix,key)] = value
 except (KeyError, ValueError, TypeError):
-   pass
+pass
 return registers
 
 def parse_errors(self, json_data):
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D119386: [lldb/Plugins] Clean-up ScriptedProcess python script (NFC)

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

This patch removes the `my_scripted_process.py` blueprint since it's not
used anymore.

The patch also updates the base ScriptedProcess and ScriptedThread
initializers to automatically initialize convinience variables, to
access debugger from the ScriptedProcess, access the SBProcess and
ScriptedProcess object from a ScriptedThread instance.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119386

Files:
  lldb/examples/python/scripted_process/my_scripted_process.py
  lldb/examples/python/scripted_process/scripted_process.py

Index: lldb/examples/python/scripted_process/scripted_process.py
===
--- lldb/examples/python/scripted_process/scripted_process.py
+++ lldb/examples/python/scripted_process/scripted_process.py
@@ -38,6 +38,7 @@
 triple = self.target.triple
 if triple:
 self.arch = triple.split('-')[0]
+self.dbg = target.GetDebugger()
 if isinstance(args, lldb.SBStructuredData) and args.IsValid():
 self.args = args
 
@@ -217,10 +218,6 @@
 self.scripted_process = None
 self.process = None
 self.args = None
-if isinstance(scripted_process, ScriptedProcess):
-self.target = scripted_process.target
-self.scripted_process = scripted_process
-self.process = self.target.GetProcess()
 
 self.id = None
 self.idx = None
@@ -232,6 +229,13 @@
 self.register_ctx = {}
 self.frames = []
 
+if isinstance(scripted_process, ScriptedProcess):
+self.target = scripted_process.target
+self.scripted_process = scripted_process
+self.process = self.target.GetProcess()
+self.get_register_info()
+
+
 @abstractmethod
 def get_thread_id(self):
 """ Get the scripted thread identifier.
@@ -257,6 +261,7 @@
 eStateRunning,   ///< Process or thread is running and can't be examined.
 eStateStepping,  ///< Process or thread is in the process of stepping and can
  /// not be examined.
+eStateCrashed,   ///< Process or thread has crashed and can be examined.
 
 Returns:
 int: The state type of the scripted thread.
Index: lldb/examples/python/scripted_process/my_scripted_process.py
===
--- lldb/examples/python/scripted_process/my_scripted_process.py
+++ /dev/null
@@ -1,136 +0,0 @@
-import os,struct,signal
-
-from typing import Any, Dict
-
-import lldb
-from lldb.plugins.scripted_process import ScriptedProcess
-from lldb.plugins.scripted_process import ScriptedThread
-
-class MyScriptedProcess(ScriptedProcess):
-memory_regions = [
-lldb.SBMemoryRegionInfo("stack", 0x1040b2000, 0x1040b4000, 0b110, True,
-True)
-]
-
-stack_memory_dump = os.path.join(os.path.dirname(os.path.abspath(__file__)),
- 'main.stack-dump')
-
-def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
-super().__init__(target, args)
-
-def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
-for region in self.memory_regions:
-if region.GetRegionBase() <= addr < region.GetRegionEnd():
-return region
-return None
-
-def get_thread_with_id(self, tid: int):
-return {}
-
-def get_registers_for_thread(self, tid: int):
-return {}
-
-def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData:
-data = lldb.SBData()
-
-with open(self.stack_memory_dump, 'rb') as f:
-stack_mem = f.read(-1)
-if not stack_mem:
-return data
-
-mem_region = self.get_memory_region_containing_address(addr)
-
-if not mem_region or addr + size > mem_region.GetRegionEnd():
-return data
-
-offset = addr - mem_region.GetRegionBase()
-shrunk_stack_mem = stack_mem[offset:offset + size]
-
-error = lldb.SBError()
-data.SetData(error, shrunk_stack_mem,
-self.target.GetByteOrder(),
-self.target.GetAddressByteSize())
-return data
-
-def get_loaded_images(self):
-return self.loaded_images
-
-def get_process_id(self) -> int:
-return 42
-
-def should_stop(self) -> bool:
-return True
-
-def is_alive(self) -> bool:
-return True
-
-def get_scripted_thread_plugin(self):
-return MyScriptedThread.__module__ + "." + MyScriptedThread.__name__
-
-
-class M

[Lldb-commits] [PATCH] D119388: [lldb/Plugin] Add artificial stackframe loading in ScriptedThread

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

This patch adds the ability for ScriptedThread to load artificial stack
frames. To do so, the interpreter instance can create a list that will
contain the frame index and its pc address.

Then, when the Scripted Process plugin stops, it will refresh its
Scripted Threads state by invalidating their register context and load
to list from the interpreter object and reconstruct each frame.

This patch also removes all of the default implementation for
`get_stackframes` from the derived ScriptedThread classes, and add the
interface code for the Scripted Thread Interface.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119388

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Target/StackFrameList.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -139,21 +139,6 @@
 
 return stop_reason
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -57,21 +57,6 @@
 "signal": signal.SIGTRAP
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return None
 
Index: lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
@@ -46,6 +46,7 @@
 class DummyScriptedThread(ScriptedThread):
 def __init__(self, process, args):
 super().__init__(process, args)
+self.frames.append({"idx": 0, "pc": 0x011b00 })
 
 def get_thread_id(self) -> int:
 return 0x19
@@ -61,21 +62,6 @@
 "signal": signal.SIGINT
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return struct.pack(
 '21Q', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
=

[Lldb-commits] [PATCH] D119389: [lldb/crashlog] Add CrashLogScriptedProcess and resurrect_crashlog method

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

This patch introduces a new type of ScriptedProcess: CrashLogScriptedProcess.
It takes advantage of lldb's crashlog parsers and Scripted Processes to
reconstruct a static debugging session with symbolicated stackframes, instead
of just dumping out everything in the user's terminal.

To create a CrashLogScriptedProcess, the user can just import the
crashlog module and run the new `resurrect_crashlog` command with the
path the crashlog file. This will fetch and load all the libraries that
were used by the crashed thread and re-create all the frames artificially.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119389

Files:
  lldb/bindings/python/CMakeLists.txt
  lldb/examples/python/crashlog.py
  lldb/examples/python/scripted_process/crashlog_scripted_process.py
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -303,6 +303,9 @@
 
   StructuredData::DictionarySP thread_info_sp = GetInterface().GetThreadsInfo();
 
+  // FIXME: Need to sort the dictionary otherwise the thread ids won't match the
+  // thread indices.
+
   if (!thread_info_sp)
 return ScriptedInterface::ErrorWithMessage(
 LLVM_PRETTY_FUNCTION,
Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py
===
--- /dev/null
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -0,0 +1,151 @@
+import os,json,struct,signal
+
+from typing import Any, Dict
+
+import lldb
+from lldb.plugins.scripted_process import ScriptedProcess
+from lldb.plugins.scripted_process import ScriptedThread
+
+from lldb.macosx.crashlog import CrashLog,CrashLogParser
+
+class CrashLogScriptedProcess(ScriptedProcess):
+# NOTE: https://at.apple.com/json-crashlog-spec
+def parse_crashlog(self):
+try:
+crash_log = CrashLogParser().parse(self.dbg, self.crashlog_path, False)
+except Exception as e:
+return
+
+self.pid = crash_log.process_id
+self.crashed_thread_idx = crash_log.crashed_thread_idx
+self.loaded_images = []
+
+for thread in crash_log.threads:
+if thread.did_crash():
+for ident in thread.idents:
+images = crash_log.find_images_with_identifier(ident)
+if images:
+for image in images:
+#FIXME: Add to self.loaded_images and load images in lldb
+err = image.add_module(self.target)
+if err:
+print(err)
+else:
+self.loaded_images.append(image)
+self.threads[thread.index] = CrashLogScriptedThread(self, None, thread)
+
+def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
+super().__init__(target, args)
+
+if not self.target or not self.target.IsValid():
+return
+
+self.crashlog_path = None
+
+crashlog_path = args.GetValueForKey("crashlog_path")
+if crashlog_path and crashlog_path.IsValid():
+if crashlog_path.GetType() == lldb.eStructuredDataTypeString:
+self.crashlog_path = crashlog_path.GetStringValue(100)
+
+if not self.crashlog_path:
+return
+
+self.pid = super().get_process_id()
+self.crashed_thread_idx = super().get_most_relevant_thread_index()
+self.parse_crashlog()
+
+def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
+return None
+
+def get_thread_with_id(self, tid: int):
+return {}
+
+def get_most_relevant_thread_index(self) -> int:
+return self.crashed_thread_idx
+
+def get_registers_for_thread(self, tid: int):
+return {}
+
+def read_memory_at_address(self, addr: int, size: int) -> lldb.SBData:
+# FIXME: Return None ?
+return lldb.SBData()
+
+def get_loaded_images(self):
+# TODO: Iterate over corefile_target modules and build a data structure
+# from it.
+return self.loaded_images
+
+def get_process_id(self) -> int:
+return self.pid
+
+def should_stop(self) -> bool:
+return True
+
+def is_alive(self) -> bool:
+return True
+
+def get_scripted_thread_plugin(self):
+return CrashLogScriptedThread.__module__ + "." + CrashLogScriptedThread.__name__
+
+class CrashLogScripte

[Lldb-commits] [PATCH] D119388: [lldb/Plugin] Add artificial stackframe loading in ScriptedThread

2022-02-09 Thread Jim Ingham via Phabricator via lldb-commits
jingham added a comment.

Some nits.  Mostly I think the "idx" field in the frame list is redundant and 
only allows you to get the order wrong w/o adding useful functionality.

I haven't studied Pavel's changes to the Python lifecycle management yet, so I 
can't comment on whether that part of the patch is done correctly.

I don't think it's necessary at this point, but at some point you are going to 
have to make ScriptedStackFrame be a thing or there won't be a natural way to 
produce variables from the frame.  The other way to program it would be to fake 
a CFA, and then fake memory reads so that the regular Variable printing code 
will produce the ValueObjectVariable's.  I can see that being a useful method 
in some cases, but super-labor intensive in others...




Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:151
+bool ScriptedThread::LoadArtificialStackFrames() {
+  StructuredData::ArraySP arr_sp = GetInterface()->GetStackFrames();
+

The GetStackFrames call should take a Status parameter, in case it has some 
good reason why it couldn't fetch the stack frames.  It will make debugging 
these things a lot easier if you can pass the real error back to yourself.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:171
+
+uint32_t frame_idx = GetStackFrameCount();
+if (!dict->GetValueForKeyAsInteger("idx", frame_idx))

As I say below, I don't think the specified frame_idx is necessary.  But it's 
also odd that you initialize it to the total number of frames, then immediately 
overwrite is with the value from the dictionary.  If you don't get a value, you 
exit from this closure, so this seems wasted work.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:172
+uint32_t frame_idx = GetStackFrameCount();
+if (!dict->GetValueForKeyAsInteger("idx", frame_idx))
+  return ScriptedInterface::ErrorWithMessage(

It seems awkward to have the producer of artificial stack frames number the 
frames.  After all, they are already putting them into an array, and the 
natural way to do that is in stack frame order.  Unless you see some really 
good use case for putting them in scrambled and using the "idx" key to 
unscramble them, the redundant idx seems like something you could get wrong w/o 
adding much value.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:273
   GetRegisterContext()->InvalidateIfNeeded(/*force=*/false);
+  LoadArtificialStackFrames();
 }

LoadArtificialStackFrames returns a bool for success/failure.  It always bugs 
me when returns signifying errors get dropped on the floor like this.



Comment at: 
lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py:78
 % (__name__, DummyScriptedProcess.__name__))
\ No newline at end of file


newline


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119388

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


[Lldb-commits] [PATCH] D119388: [lldb/Plugin] Add artificial stackframe loading in ScriptedThread

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



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:151
+bool ScriptedThread::LoadArtificialStackFrames() {
+  StructuredData::ArraySP arr_sp = GetInterface()->GetStackFrames();
+

jingham wrote:
> The GetStackFrames call should take a Status parameter, in case it has some 
> good reason why it couldn't fetch the stack frames.  It will make debugging 
> these things a lot easier if you can pass the real error back to yourself.
For now the Scripted{Process,Thread}Interface will log the error to the 
appropriate channel, but I can see having all the interface methods return an 
`llvm::Expected` object with an error message instead. I'll do it in a 
follow-up patch. 



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:172
+uint32_t frame_idx = GetStackFrameCount();
+if (!dict->GetValueForKeyAsInteger("idx", frame_idx))
+  return ScriptedInterface::ErrorWithMessage(

jingham wrote:
> It seems awkward to have the producer of artificial stack frames number the 
> frames.  After all, they are already putting them into an array, and the 
> natural way to do that is in stack frame order.  Unless you see some really 
> good use case for putting them in scrambled and using the "idx" key to 
> unscramble them, the redundant idx seems like something you could get wrong 
> w/o adding much value.
Makes sense.



Comment at: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp:273
   GetRegisterContext()->InvalidateIfNeeded(/*force=*/false);
+  LoadArtificialStackFrames();
 }

jingham wrote:
> LoadArtificialStackFrames returns a bool for success/failure.  It always bugs 
> me when returns signifying errors get dropped on the floor like this.
`Thread::RefreshStateAfterStop` doesn't return anything, and the failure case 
is already handled in `LoadArtificialStackFrames` by logging an error message 
in the appropriate channel.

Do you have any other suggestion on how I could improve this ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119388

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


[Lldb-commits] [PATCH] D119388: [lldb/Plugin] Add artificial stackframe loading in ScriptedThread

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 407368.
mib marked 2 inline comments as done.
mib edited the summary of this revision.
mib added a comment.

Address @jingham's comments


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

https://reviews.llvm.org/D119388

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Target/StackFrameList.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -139,21 +139,6 @@
 
 return stop_reason
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -57,21 +57,6 @@
 "signal": signal.SIGTRAP
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return None
 
Index: lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
@@ -46,6 +46,7 @@
 class DummyScriptedThread(ScriptedThread):
 def __init__(self, process, args):
 super().__init__(process, args)
+self.frames.append({"pc": 0x011b00 })
 
 def get_thread_id(self) -> int:
 return 0x19
@@ -61,21 +62,6 @@
 "signal": signal.SIGINT
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return struct.pack(
 '21Q', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)
@@ -88,4 +74,4 @@
  DummyScriptedProcess.__name__))
 else:
 print("Name of the class that will manage the scripted process: '%s.%s'"
-% (__name__, DummyScriptedProcess.__name__))
\ No newline at end of file
+% (__name__, DummyScriptedProcess.__name__))
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -133,3 +133,6 @@
 break
 self.assertEqual(idx, int(reg.value, 16))
 
+  

[Lldb-commits] [PATCH] D119388: [lldb/Plugin] Add artificial stackframe loading in ScriptedThread

2022-02-09 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 407370.
mib added a comment.

Reformat and update error messages.


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

https://reviews.llvm.org/D119388

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Target/StackFrameList.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
  lldb/source/Plugins/Process/scripted/ScriptedThread.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
  lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
  lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
  lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
  lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py

Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
@@ -139,21 +139,6 @@
 
 return stop_reason
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 if not self.corefile_thread or self.corefile_thread.GetNumFrames() == 0:
 return None
Index: lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/invalid_scripted_process.py
@@ -57,21 +57,6 @@
 "signal": signal.SIGTRAP
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return None
 
Index: lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
===
--- lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
+++ lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
@@ -46,6 +46,7 @@
 class DummyScriptedThread(ScriptedThread):
 def __init__(self, process, args):
 super().__init__(process, args)
+self.frames.append({"pc": 0x011b00 })
 
 def get_thread_id(self) -> int:
 return 0x19
@@ -61,21 +62,6 @@
 "signal": signal.SIGINT
 } }
 
-def get_stackframes(self):
-class ScriptedStackFrame:
-def __init__(idx, cfa, pc, symbol_ctx):
-self.idx = idx
-self.cfa = cfa
-self.pc = pc
-self.symbol_ctx = symbol_ctx
-
-
-symbol_ctx = lldb.SBSymbolContext()
-frame_zero = ScriptedStackFrame(0, 0x42424242, 0x500, symbol_ctx)
-self.frames.append(frame_zero)
-
-return self.frame_zero[0:0]
-
 def get_register_context(self) -> str:
 return struct.pack(
 '21Q', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)
@@ -88,4 +74,4 @@
  DummyScriptedProcess.__name__))
 else:
 print("Name of the class that will manage the scripted process: '%s.%s'"
-% (__name__, DummyScriptedProcess.__name__))
\ No newline at end of file
+% (__name__, DummyScriptedProcess.__name__))
Index: lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
===
--- lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
+++ lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py
@@ -133,3 +133,6 @@
 break
 self.assertEqual(idx, int(reg.value, 16))
 
+self.assertTrue(frame.IsArtificial(), "Frame is not artificial")
+   

[Lldb-commits] [PATCH] D119400: Fix a double debug info size counting in top level stats for "statistics dump".

2022-02-09 Thread Greg Clayton via Phabricator via lldb-commits
clayborg created this revision.
clayborg added reviewers: labath, JDevlieghere, jingham, wallace.
Herald added a subscriber: kristof.beyls.
clayborg requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This mainly affects Darwin targets (macOS, iOS, tvOS and watchOS) when these 
targets don't use dSYM files and the debug info was in the .o files. All 
modules, including the .o files that are loaded by the debug maps, were in the 
global module list. This was great because it allows us to see each .o file and 
how much it contributes. There were virtual functions on the SymbolFile class 
to fetch the symtab/debug info parse and index times, and also the total debug 
info size. So the main executable would add all of the .o file's stats together 
and report them as its own data. Then the "totalDebugInfoSize" and many other 
"totalXXX" top level totals were all being added together. This stems from the 
fact that my original patch only emitted the modules for a target at the start 
of the patch, but as comments from the reviews came in, we switched to emitting 
all of the modules from the global module list.

So this patch fixes it so when we have a SymbolFileDWARFDebugMap that loads .o 
files, the main executable will have no debug info size or symtab/debug info 
parse/index times, but each .o file will have its own data as a separate 
module. Also, to be able to tell when/if we have a dSYM file I have added a 
"symbolFilePath" if the SymbolFile for the main modules path doesn't match that 
of the main executable. We also include a "symbolFileModuleIdentifiers" key in 
each module if the module does have multiple lldb_private::Module objects that 
contain debug info so that you can track down the information for a module and 
add up the contributions of all of the .o files.

Tests were added that are labeled with @skipUnlessDarwin and 
@no_debug_info_test that test all of this functionality so it doesn't regress.

For a module with a dSYM file, we can see the "symbolFilePath" is included:

  "modules": [
{
  "debugInfoByteSize": 1070,
  "debugInfoIndexLoadedFromCache": false,
  "debugInfoIndexSavedToCache": false,
  "debugInfoIndexTime": 0,
  "debugInfoParseTime": 0,
  "identifier": 4873280600,
  "path": 
"/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_dsym_binary_has_symfile_in_stats/a.out",
  "symbolFilePath": 
"/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_dsym_binary_has_symfile_in_stats/a.out.dSYM/Contents/Resources/DWARF/a.out",
  "symbolTableIndexTime": 7.9996e-06,
  "symbolTableLoadedFromCache": false,
  "symbolTableParseTime": 7.8996e-05,
  "symbolTableSavedToCache": false,
  "triple": "arm64-apple-macosx12.0.0",
  "uuid": "E1F7D85B-3A42-321E-BF0D-29B103F5F2E3"
},

And for the DWARF in .o file case we can see the "symbolFileModuleIdentifiers" 
in the executable's module stats:

  "modules": [
{
  "debugInfoByteSize": 0,
  "debugInfoIndexLoadedFromCache": false,
  "debugInfoIndexSavedToCache": false,
  "debugInfoIndexTime": 0,
  "debugInfoParseTime": 0,
  "identifier": 4603526968,
  "path": 
"/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_no_dsym_binary_has_symfile_identifiers_in_stats/a.out",
  "symbolFileModuleIdentifiers": [
4604429832
  ],
  "symbolTableIndexTime": 7.9996e-06,
  "symbolTableLoadedFromCache": false,
  "symbolTableParseTime": 0.000112,
  "symbolTableSavedToCache": false,
  "triple": "arm64-apple-macosx12.0.0",
  "uuid": "57008BF5-A726-3DE9-B1BF-3A9AD3EE8569"
},

And the .o file for 4604429832 looks like:

  {
"debugInfoByteSize": 1028,
"debugInfoIndexLoadedFromCache": false,
"debugInfoIndexSavedToCache": false,
"debugInfoIndexTime": 0,
"debugInfoParseTime": 6.0999e-05,
"identifier": 4604429832,
"path": 
"/Users/gclayton/Documents/src/lldb/main/Debug/lldb-test-build.noindex/commands/statistics/basic/TestStats.test_no_dsym_binary_has_symfile_identifiers_in_stats/main.o",
"symbolTableIndexTime": 0,
"symbolTableLoadedFromCache": false,
"symbolTableParseTime": 0,
"symbolTableSavedToCache": false,
"triple": "arm64-apple-macosx"
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119400

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/include/lldb/Target/Statistics.h
  lldb/source/Core/Section.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/source/Target/Statistics.cpp
  lldb/test/API/commands/statistics/basic/TestStats.py

Index: lldb/test/API/commands/statistics/basic/TestStats.py
==