[Lldb-commits] [PATCH] D146297: [lldb][gnustep][PDB] Parse ObjC base classes and recognize NSObject type

2023-04-25 Thread Saleem Abdulrasool via Phabricator via lldb-commits
compnerd added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp:399
 // Such symbols will be handled here.
 
 // Ignore unnamed-tag UDTs.

Does it make sense to drop a note here that the 0-length UDT is used as a 
marker for the NSObject root?  Although, shouldn't `NSObject`'s `isa` be 
`NSObject`?  Or does GNUStep not do that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146297

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


[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: bulbazord, jingham.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch updates the `lldbutil.fetch_next_event` helper function to
either match a specific broadcaster or match a whole broadcaster class.

This is very handy when testing process events for interactive scripted
process debugging.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149175

Files:
  lldb/packages/Python/lldbsuite/test/lldbutil.py


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,24 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, 
timeout=10):
 """Fetch one event from the listener and return it if it matches the 
provided broadcaster.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,24 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, timeout=10):
 """Fetch one event from the listener and return it if it matches the provided broadcaster.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1206-1207
+def fetch_next_event(test, listener, broadcaster, match_class=False, 
timeout=10):
 """Fetch one event from the listener and return it if it matches the 
provided broadcaster.
 Fails otherwise."""
 

Maybe update the docstring to reflect this new parameter? Something like `If 
match_class is true, the provided broadcaster will be matched by class rather 
than instance`?



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1219-1220
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %

I'm not sure why you added this part? Is there something not great about 
calling `SBEvent::GetDescription` directly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149175

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


[Lldb-commits] [PATCH] D148662: [lldb] Make the libcxx unique_ptr prettyprinter support custom deleters.

2023-04-25 Thread Jorge Gorbe Moya via Phabricator via lldb-commits
jgorbe added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148662

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


[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 516854.
mib marked 2 inline comments as done.
mib edited the summary of this revision.
mib added a comment.

Address @bulbazord comments.


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

https://reviews.llvm.org/D149175

Files:
  lldb/packages/Python/lldbsuite/test/lldbutil.py


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,25 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, 
timeout=10):
 """Fetch one event from the listener and return it if it matches the 
provided broadcaster.
+If `match_class` is set to True, this will match an event with an entire 
broadcaster class.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,25 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, timeout=10):
 """Fetch one event from the listener and return it if it matches the provided broadcaster.
+If `match_class` is set to True, this will match an event with an entire broadcaster class.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added inline comments.



Comment at: lldb/packages/Python/lldbsuite/test/lldbutil.py:1219-1220
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %

bulbazord wrote:
> I'm not sure why you added this part? Is there something not great about 
> calling `SBEvent::GetDescription` directly?
This is actually a fix of the original implementation 
(`SBEvent::GetDescription` requires a `SBStream` argument but when added this 
helper function, we never took this code path, so we never hit that error).


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

https://reviews.llvm.org/D149175

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


[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D149175

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


[Lldb-commits] [PATCH] D149179: [lldb/test] Consolidate interactive scripted process debugging test

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added reviewers: jingham, bulbazord, JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch improve the interactive scripted process debugging test by
adding test coverage for child process breakpoint setting and execution
state change.

This patch introduces a new test case for a multiplexed launch, which
does the same thing as the simple passthrough launch. After the
multiplexer process stops, this new test launches 2 other scripted processes
that should contain respectively the even and odd threads from the
multiplexer scripted process.

Then, we create a breakpoint on one the child scripted process, make
sure it was set probably on the child process, the multiplexer process
and the real process. This also test the breakpoint name tagging at the
multiplexer level.

Finally, we resume the child process that had a breakpoint and make sure
that all the processes has stopped at the right location.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149179

Files:
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Index: lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -12,15 +12,185 @@
 
 NO_DEBUG_INFO_TESTCASE = True
 
-def test_passthrough_launch(self):
-"""Test a simple pass-through process launch"""
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Build and load test program
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 self.script_module = "interactive_scripted_process"
 self.script_file = self.script_module + ".py"
+
+def test_passthrough_launch(self):
+"""Test a simple pass-through process launch"""
 self.passthrough_launch()
 
+lldbutil.run_break_set_by_source_regexp(self, "also break here")
+self.assertEqual(self.mux_target.GetNumBreakpoints(), 2)
+error = self.mux_process.Continue()
+self.assertSuccess(error, "Resuming multiplexer scripted process")
+self.assertTrue(self.mux_process.IsValid(), "Got a valid process")
+
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+def test_multiplexed_launch(self):
+"""Test a multiple interactive scripted process debugging"""
+self.passthrough_launch()
+self.assertEqual(self.dbg.GetNumTargets(), 2)
+
+driving_target = self.mux_process.GetScriptedImplementation().driving_target
+self.assertTrue(driving_target.IsValid(), "Driving target is invalid")
+
+# Create a target for the multiplexed even scripted process
+even_target = self.duplicate_target(driving_target)
+self.assertTrue(
+even_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed even scripted process",
+)
+
+class_name = f"{self.script_module}.MultiplexedScriptedProcess"
+dictionary = {"driving_target_idx": self.dbg.GetIndexOfTarget(self.mux_target)}
+
+dictionary["parity"] = 0
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Even Child Scripted Process
+error = lldb.SBError()
+even_process = even_target.Launch(muxed_launch_info, error)
+self.assertTrue(
+even_process, "Couldn't launch multiplexed even scripted process"
+)
+self.multiplex(even_process)
+
+# Check that the even process started running
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+# Check that the even process stopped
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+self.assertTrue(even_process.IsValid(), "Got a valid process")
+self.assertState(
+  

[Lldb-commits] [PATCH] D149180: [LLDB][REPL] Destroy the repl instances correctly

2023-04-25 Thread walter erquinigo via Phabricator via lldb-commits
wallace created this revision.
Herald added a project: All.
wallace requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This change ensures that the REPL map inside Target is destroyed correctly when 
`Target::Destroy()` is invoked. Not doing so results in the REPL not finishing 
its job when the debugger is initialized in REPL mode reading from a file. In 
my particular case, my REPL doesn't print the stdout of the last expression in 
the input file unless I include this change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149180

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -293,6 +293,7 @@
   m_stop_hooks.clear();
   m_stop_hook_next_id = 0;
   m_suppress_stop_hooks = false;
+  m_repl_map.clear();
   Args signal_args;
   ClearDummySignals(signal_args);
 }


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -293,6 +293,7 @@
   m_stop_hooks.clear();
   m_stop_hook_next_id = 0;
   m_suppress_stop_hooks = false;
+  m_repl_map.clear();
   Args signal_args;
   ClearDummySignals(signal_args);
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 59a39c2 - [LLDB][REPL] Destroy the repl instances correctly

2023-04-25 Thread walter erquinigo via lldb-commits

Author: walter erquinigo
Date: 2023-04-25T15:09:08-05:00
New Revision: 59a39c2fc91ed5b750083bc51dc43b6510a501b6

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

LOG: [LLDB][REPL] Destroy the repl instances correctly

This change ensures that the REPL map inside Target is destroyed correctly when 
`Target::Destroy()` is invoked. Not doing so results in the REPL not finishing 
its job when the debugger is initialized in REPL mode reading from a file. In 
my particular case, my REPL doesn't print the stdout of the last expression in 
the input file unless I include this change.

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

Added: 


Modified: 
lldb/source/Target/Target.cpp

Removed: 




diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index c5946d15a6bc3..4f3c644e82889 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -293,6 +293,7 @@ void Target::Destroy() {
   m_stop_hooks.clear();
   m_stop_hook_next_id = 0;
   m_suppress_stop_hooks = false;
+  m_repl_map.clear();
   Args signal_args;
   ClearDummySignals(signal_args);
 }



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


[Lldb-commits] [PATCH] D149180: [LLDB][REPL] Destroy the repl instances correctly

2023-04-25 Thread walter erquinigo 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 rG59a39c2fc91e: [LLDB][REPL] Destroy the repl instances 
correctly (authored by wallace).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149180

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -293,6 +293,7 @@
   m_stop_hooks.clear();
   m_stop_hook_next_id = 0;
   m_suppress_stop_hooks = false;
+  m_repl_map.clear();
   Args signal_args;
   ClearDummySignals(signal_args);
 }


Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -293,6 +293,7 @@
   m_stop_hooks.clear();
   m_stop_hook_next_id = 0;
   m_suppress_stop_hooks = false;
+  m_repl_map.clear();
   Args signal_args;
   ClearDummySignals(signal_args);
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149111: [lldb] Add support for specifying language when setting watchpoint by expression

2023-04-25 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda accepted this revision.
jasonmolenda added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lldb/source/Interpreter/OptionGroupWatchpoint.cpp:67
+ "Number of bytes to use to watch a region."},
+{LLDB_OPT_SET_2,
+ false,

I don't care much, but the formatting of this entry is pretty inconsistent with 
the two SET_1's above.  Should they match?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149111

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


[Lldb-commits] [PATCH] D149111: [lldb] Add support for specifying language when setting watchpoint by expression

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added inline comments.



Comment at: lldb/source/Interpreter/OptionGroupWatchpoint.cpp:67
+ "Number of bytes to use to watch a region."},
+{LLDB_OPT_SET_2,
+ false,

jasonmolenda wrote:
> I don't care much, but the formatting of this entry is pretty inconsistent 
> with the two SET_1's above.  Should they match?
I applied clang-format to the entire thing and this is what it gave me 
/shrug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149111

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


[Lldb-commits] [PATCH] D149111: [lldb] Add support for specifying language when setting watchpoint by expression

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib requested changes to this revision.
mib added a comment.
This revision now requires changes to proceed.

I think we should still be able to use this new flag with the previous ones 
(i.e. `watchpoint set -l c++ -w read -- &my_var`)




Comment at: lldb/source/Interpreter/OptionGroupWatchpoint.cpp:67
+ "Number of bytes to use to watch a region."},
+{LLDB_OPT_SET_2,
+ false,

bulbazord wrote:
> jasonmolenda wrote:
> > I don't care much, but the formatting of this entry is pretty inconsistent 
> > with the two SET_1's above.  Should they match?
> I applied clang-format to the entire thing and this is what it gave me 
> /shrug
Having a different option group for this flag means it can't be used with the 
other ones ... Is that really what you want ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149111

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


[Lldb-commits] [PATCH] D149111: [lldb] Add support for specifying language when setting watchpoint by expression

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord requested review of this revision.
bulbazord added a comment.

In D149111#4296670 , @mib wrote:

> I think we should still be able to use this new flag with the previous ones 
> (i.e. `watchpoint set -l c++ -w read -- &my_var`)

You can do that still with this patch. I'm placing the language flag in a 2nd 
group so that `watchpoint set variable` does not have access to this flag, but 
`watchpoint set expression` does. You can still mix and match the flags for 
`expression`.




Comment at: lldb/source/Interpreter/OptionGroupWatchpoint.cpp:67
+ "Number of bytes to use to watch a region."},
+{LLDB_OPT_SET_2,
+ false,

mib wrote:
> bulbazord wrote:
> > jasonmolenda wrote:
> > > I don't care much, but the formatting of this entry is pretty 
> > > inconsistent with the two SET_1's above.  Should they match?
> > I applied clang-format to the entire thing and this is what it gave me 
> > /shrug
> Having a different option group for this flag means it can't be used with the 
> other ones ... Is that really what you want ?
`OptionGroupWatchpoint` as far as I can tell is only used for `watchpoint set 
expression` and `watchpoint set variable`. I don't think this flag makes sense 
for `watchpoint set variable`, so I'm adding it to the 2nd group for expression 
and opting out for variable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149111

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


[Lldb-commits] [PATCH] D149179: [lldb/test] Consolidate interactive scripted process debugging test

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord added a comment.

Seems ok to me. You might want to update the dependencies of this diff so that 
the pre-merge checks don't fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149179

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


[Lldb-commits] [PATCH] D149179: [lldb/test] Consolidate interactive scripted process debugging test

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib updated this revision to Diff 516929.

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

https://reviews.llvm.org/D149179

Files:
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Index: lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -12,15 +12,185 @@
 
 NO_DEBUG_INFO_TESTCASE = True
 
-def test_passthrough_launch(self):
-"""Test a simple pass-through process launch"""
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Build and load test program
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 self.script_module = "interactive_scripted_process"
 self.script_file = self.script_module + ".py"
+
+def test_passthrough_launch(self):
+"""Test a simple pass-through process launch"""
 self.passthrough_launch()
 
+lldbutil.run_break_set_by_source_regexp(self, "also break here")
+self.assertEqual(self.mux_target.GetNumBreakpoints(), 2)
+error = self.mux_process.Continue()
+self.assertSuccess(error, "Resuming multiplexer scripted process")
+self.assertTrue(self.mux_process.IsValid(), "Got a valid process")
+
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+def test_multiplexed_launch(self):
+"""Test a multiple interactive scripted process debugging"""
+self.passthrough_launch()
+self.assertEqual(self.dbg.GetNumTargets(), 2)
+
+driving_target = self.mux_process.GetScriptedImplementation().driving_target
+self.assertTrue(driving_target.IsValid(), "Driving target is invalid")
+
+# Create a target for the multiplexed even scripted process
+even_target = self.duplicate_target(driving_target)
+self.assertTrue(
+even_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed even scripted process",
+)
+
+class_name = f"{self.script_module}.MultiplexedScriptedProcess"
+dictionary = {"driving_target_idx": self.dbg.GetIndexOfTarget(self.mux_target)}
+
+dictionary["parity"] = 0
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Even Child Scripted Process
+error = lldb.SBError()
+even_process = even_target.Launch(muxed_launch_info, error)
+self.assertTrue(
+even_process, "Couldn't launch multiplexed even scripted process"
+)
+self.multiplex(even_process)
+
+# Check that the even process started running
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+# Check that the even process stopped
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+self.assertTrue(even_process.IsValid(), "Got a valid process")
+self.assertState(
+even_process.GetState(), lldb.eStateStopped, "Process is stopped"
+)
+
+# Create a target for the multiplexed odd scripted process
+odd_target = self.duplicate_target(driving_target)
+self.assertTrue(
+odd_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed odd scripted process",
+)
+
+dictionary["parity"] = 1
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Odd Child Scripted Process
+error = lldb.SBError()
+odd_process = odd_target.Launch(muxed_launch_info, error)
+self.assertTrue(odd_process, "Couldn't launch multiplexed odd scripted process")
+self.multiplex(odd_process)
+
+# Check that the odd process started running
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), odd_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb

[Lldb-commits] [lldb] 0d77e03 - [lldb/API] Introduce SBProcess::ForceScriptedState method

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:33-07:00
New Revision: 0d77e034749f57676fd79e4a5b560be4d5b52b48

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

LOG: [lldb/API] Introduce SBProcess::ForceScriptedState method

This patch introduces a new method to the SBProcess API called
ForceScriptedState. As the name suggests, this affordance will allow the
user to alter the state of the scripted process programatically.

This is necessary to update the scripted process state when perform
interactive debugging.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/API/SBProcess.h
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Removed: 




diff  --git a/lldb/include/lldb/API/SBProcess.h 
b/lldb/include/lldb/API/SBProcess.h
index b7eb2036dbe47..d1e15cc5c1f71 100644
--- a/lldb/include/lldb/API/SBProcess.h
+++ b/lldb/include/lldb/API/SBProcess.h
@@ -186,6 +186,14 @@ class LLDB_API SBProcess {
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its state to the new state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 808226067d5a6..b4b75e52d572a 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2565,6 +2565,8 @@ void PruneThreadPlans();
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 

diff  --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index ca473175f18f0..2004b66eafe34 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@ SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) 
{
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 60f42cbaf7f2c..9837f7f2c7c00 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -90,6 +90,10 @@ class ScriptedProcess : public Process {
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);



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


[Lldb-commits] [lldb] 6c961ae - [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: 6c961ae1b5073699285fcdec242cdb4e84602c05

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

LOG: [lldb] Move ScriptedProcess private state update to implementation

While debugging a Scripted Process, in order to update its state and
work nicely with lldb's execution model, it needs to toggle its private
state from running to stopped, which will result in broadcasting a
process state changed event to the debugger listener.

Originally, this state update was done systematically in the Scripted
Process C++ plugin, however in order to make scripted process
interactive, we need to be able to update their state dynamically.

This patch makes use of the recent addition of the
SBProcess::ForceScriptedState to programatically, and moves the
process private state update to the python implementation of the resume
method instead of doing it in ScriptedProcess::DoResume.

This patch also removes the unused ShouldStop & Stop scripted
process APIs, and adds new ScriptedInterface transform methods for
boolean arguments. This allow the user to programmatically decide if
after running the process, we should stop it (which is the default setting).

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h

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

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

Removed: 




diff  --git a/lldb/examples/python/scripted_process/scripted_process.py 
b/lldb/examples/python/scripted_process/scripted_process.py
index e4d25214da766..5cd78ad9c45ae 100644
--- a/lldb/examples/python/scripted_process/scripted_process.py
+++ b/lldb/examples/python/scripted_process/scripted_process.py
@@ -161,30 +161,25 @@ def attach(self, attach_info):
 """
 return lldb.SBError()
 
-def resume(self):
+def resume(self, should_stop=True):
 """ Simulate the scripted process resume.
 
-Returns:
-lldb.SBError: An `lldb.SBError` with error code 0.
-"""
-return lldb.SBError()
-
-@abstractmethod
-def should_stop(self):
-""" Check if the scripted process plugin should produce the stop event.
-
-Returns:
-bool: True if scripted process should broadcast a stop event.
-  False otherwise.
-"""
-pass
-
-def stop(self):
-""" Trigger the scripted process stop.
+Args:
+should_stop (bool): If True, resume will also force the process
+state to stopped after running it.
 
 Returns:
 lldb.SBError: An `lldb.SBError` with error code 0.
 """
+process = self.target.GetProcess()
+if not process:
+error = lldb.SBError()
+error.SetErrorString("Invalid process.")
+return error
+
+process.ForceScriptedState(lldb.eStateRunning);
+if (should_stop):
+process.ForceScriptedState(lldb.eStateStopped);
 return lldb.SBError()
 
 @abstractmethod

diff  --git a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h 
b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
index 895fc5e2fd3d3..f37ba0f422913 100644
--- a/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
+++ b/lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
@@ -38,10 +38,6 @@ class ScriptedProcessInterface : virtual public 
ScriptedInterface {
 
   virtual Status Resume() { return Status("ScriptedProcess did not resume"); }
 
-  virtual bool ShouldStop() { return true; }
-
-  virtual Status Stop() { return Status("ScriptedProcess did not stop"); }
-
   virtual std::optional
   GetMemoryRegionContainingAddress(lldb::addr_t address, Status &error) {
 error.SetErrorString("ScriptedProcess have no memory region.");

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 23ff8811e3fd7..3c2e8f51aa039 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -150,22 +150,15 @@ Status ScriptedProcess::DoLoadCore() {
 
 Status ScriptedProcess::DoLaunch(Module *exe_module,
  ProcessLaunchInfo 

[Lldb-commits] [lldb] 46e93c9 - [lldb] Unify default/hijack listener between Process{Attach, Launch}Info (NFC)

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: 46e93c9df287bc06854c66e08658f757ff6cf6f1

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

LOG: [lldb] Unify default/hijack listener between Process{Attach,Launch}Info 
(NFC)

This patch is a simple refactor that unifies the default and hijack
listener methods and attributes between ProcessAttachInfo and
ProcessLaunchInfo.

These 2 classes are both derived from the ProcessInfo base class so this
patch moves the listeners attributes and getter/setter methods to the
base class.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/Host/ProcessLaunchInfo.h
lldb/include/lldb/Target/Process.h
lldb/include/lldb/Utility/ProcessInfo.h
lldb/source/Host/common/ProcessLaunchInfo.cpp
lldb/source/Utility/ProcessInfo.cpp

Removed: 




diff  --git a/lldb/include/lldb/Host/ProcessLaunchInfo.h 
b/lldb/include/lldb/Host/ProcessLaunchInfo.h
index b9beea4d11b8c..891f46f650c8c 100644
--- a/lldb/include/lldb/Host/ProcessLaunchInfo.h
+++ b/lldb/include/lldb/Host/ProcessLaunchInfo.h
@@ -120,19 +120,6 @@ class ProcessLaunchInfo : public ProcessInfo {
 
   PseudoTerminal &GetPTY() { return *m_pty; }
 
-  // Get and set the actual listener that will be used for the process events
-  lldb::ListenerSP GetListener() const { return m_listener_sp; }
-
-  void SetListener(const lldb::ListenerSP &listener_sp) {
-m_listener_sp = listener_sp;
-  }
-
-  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
-
-  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
-m_hijack_listener_sp = listener_sp;
-  }
-
   void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
 
   const char *GetLaunchEventData() const { return m_event_data.c_str(); }
@@ -154,8 +141,6 @@ class ProcessLaunchInfo : public ProcessInfo {
   Host::MonitorChildProcessCallback m_monitor_callback;
   std::string m_event_data; // A string passed to the plugin launch, having no
 // meaning to the upper levels of lldb.
-  lldb::ListenerSP m_listener_sp;
-  lldb::ListenerSP m_hijack_listener_sp;
 };
 }
 

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index b4b75e52d572a..68581e47184cb 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -122,8 +122,6 @@ class ProcessAttachInfo : public ProcessInstanceInfo {
 ProcessInfo::operator=(launch_info);
 SetProcessPluginName(launch_info.GetProcessPluginName());
 SetResumeCount(launch_info.GetResumeCount());
-SetListener(launch_info.GetListener());
-SetHijackListener(launch_info.GetHijackListener());
 m_detach_on_error = launch_info.GetDetachOnError();
   }
 
@@ -174,28 +172,13 @@ class ProcessAttachInfo : public ProcessInstanceInfo {
 return false;
   }
 
-  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
-
-  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
-m_hijack_listener_sp = listener_sp;
-  }
-
   bool GetDetachOnError() const { return m_detach_on_error; }
 
   void SetDetachOnError(bool enable) { m_detach_on_error = enable; }
 
-  // Get and set the actual listener that will be used for the process events
-  lldb::ListenerSP GetListener() const { return m_listener_sp; }
-
-  void SetListener(const lldb::ListenerSP &listener_sp) {
-m_listener_sp = listener_sp;
-  }
-
   lldb::ListenerSP GetListenerForProcess(Debugger &debugger);
 
 protected:
-  lldb::ListenerSP m_listener_sp;
-  lldb::ListenerSP m_hijack_listener_sp;
   std::string m_plugin_name;
   uint32_t m_resume_count = 0; // How many times do we resume after launching
   bool m_wait_for_launch = false;

diff  --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 8bddb04b1d474..a48acdddca3ab 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -97,6 +97,19 @@ class ProcessInfo {
 m_scripted_metadata_sp = metadata_sp;
   }
 
+  // Get and set the actual listener that will be used for the process events
+  lldb::ListenerSP GetListener() const { return m_listener_sp; }
+
+  void SetListener(const lldb::ListenerSP &listener_sp) {
+m_listener_sp = listener_sp;
+  }
+
+  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
+
+  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
+m_hijack_listener_sp = listener_sp;
+  }
+
 protected:
   FileSpec m_executable;
   std::string m_arg0; // argv[0] if supported. If empty, then use m_executable.
@@ -109,6 +122,8 @@ class ProcessInfo {
   ArchSpec m_arch;
   lldb::pid_t m_pid =

[Lldb-commits] [lldb] 6382fcb - [lldb/Utility] Add opt-in shadow mode to event listeners

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: 6382fcb16def5ae4a47082466fd8dc93e8fdf988

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

LOG: [lldb/Utility] Add opt-in shadow mode to event listeners

This patch augments lldb's event listeners with a new shadow mode.

As the name suggests, this mode allows events to be copied to an
additional listener to perform event monitoring, without interferring
with the event life cycle.

One of our use case for this, is to be able to listen to public process
events while making sure the events will still be delivered to the
default process listener (the debugger listener in most cases).

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/API/SBAttachInfo.h
lldb/include/lldb/API/SBLaunchInfo.h
lldb/include/lldb/Target/Process.h
lldb/include/lldb/Utility/Broadcaster.h
lldb/include/lldb/Utility/Listener.h
lldb/include/lldb/Utility/ProcessInfo.h
lldb/source/API/SBAttachInfo.cpp
lldb/source/API/SBLaunchInfo.cpp
lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
lldb/source/Target/Target.cpp
lldb/source/Utility/Broadcaster.cpp
lldb/source/Utility/Listener.cpp
lldb/source/Utility/ProcessInfo.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBAttachInfo.h 
b/lldb/include/lldb/API/SBAttachInfo.h
index a4dbce29855f2..ea1145e625856 100644
--- a/lldb/include/lldb/API/SBAttachInfo.h
+++ b/lldb/include/lldb/API/SBAttachInfo.h
@@ -168,6 +168,25 @@ class LLDB_API SBAttachInfo {
   /// allows a 
diff erent listener to be used to listen for process events.
   void SetListener(SBListener &listener);
 
+  /// Get the shadow listener that receive public process events,
+  /// additionally to the default process event listener.
+  ///
+  /// If no listener has been set via a call to
+  /// SBLaunchInfo::SetShadowListener(), then an invalid SBListener will
+  /// be returned (SBListener::IsValid() will return false). If a listener
+  /// has been set, then the valid listener object will be returned.
+  SBListener GetShadowListener();
+
+  /// Set the shadow listener that will receive public process events,
+  /// additionally to the default process event listener.
+  ///
+  /// By default a process have no shadow event listener.
+  /// Calling this function allows public process events to be broadcasted to 
an
+  /// additional listener on top of the default process event listener.
+  /// If the `listener` argument is invalid (SBListener::IsValid() will
+  /// return false), this will clear the shadow listener.
+  void SetShadowListener(SBListener &listener);
+
   const char *GetScriptedProcessClassName() const;
 
   void SetScriptedProcessClassName(const char *class_name);

diff  --git a/lldb/include/lldb/API/SBLaunchInfo.h 
b/lldb/include/lldb/API/SBLaunchInfo.h
index 8c625e1b9068e..06e72efc30f9f 100644
--- a/lldb/include/lldb/API/SBLaunchInfo.h
+++ b/lldb/include/lldb/API/SBLaunchInfo.h
@@ -92,6 +92,25 @@ class LLDB_API SBLaunchInfo {
   /// allows a 
diff erent listener to be used to listen for process events.
   void SetListener(SBListener &listener);
 
+  /// Get the shadow listener that receive public process events,
+  /// additionally to the default process event listener.
+  ///
+  /// If no listener has been set via a call to
+  /// SBLaunchInfo::SetShadowListener(), then an invalid SBListener will
+  /// be returned (SBListener::IsValid() will return false). If a listener
+  /// has been set, then the valid listener object will be returned.
+  SBListener GetShadowListener();
+
+  /// Set the shadow listener that will receive public process events,
+  /// additionally to the default process event listener.
+  ///
+  /// By default a process have no shadow event listener.
+  /// Calling this function allows public process events to be broadcasted to 
an
+  /// additional listener on top of the default process event listener.
+  /// If the `listener` argument is invalid (SBListener::IsValid() will
+  /// return false), this will clear the shadow listener.
+  void SetShadowListener(SBListener &listener);
+
   uint32_t GetNumArguments();
 
   const char *GetArgumentAtIndex(uint32_t idx);

diff  --git a/lldb/include/lldb/Target/Process.h 
b/lldb/include/lldb/Target/Process.h
index 68581e47184cb..207b4939d0232 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -380,6 +380,10 @@ class Process : public 
std::enable_shared_from_this,
 return GetStaticBroadcasterClass();
   }
 
+  void SetShadowListener(lldb::ListenerSP listener_sp) override {
+Broadcaster::SetShadowListener(liste

[Lldb-commits] [lldb] ad03aea - [lldb/Plugin] Add breakpoint setting support to ScriptedProcess

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: ad03aeadfb72e9c872b297bbaedbf46ebac3572c

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

LOG: [lldb/Plugin] Add breakpoint setting support to ScriptedProcess

This patch adds support for breakpoint setting to Scripted Processes.

For now, Scripted Processes only support setting software breakpoints.

When doing interactive scripted process debugging, it makes use of the
memory writing capability to write the trap opcodes in the memory of the
driving process. However the real process' target doesn't keep track of
the breakpoints that got added by the scripted process. This is a design
that we might need to change in the future, since we'll probably need to
do some book keeping to handle breakpoints that were set by different
scripted processes.

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

Signed-off-by: Med Ismail Bennani 

Added: 


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

Removed: 




diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 3c2e8f51aa039..dc27bcf425957 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -249,6 +249,20 @@ size_t ScriptedProcess::DoWriteMemory(lldb::addr_t 
vm_addr, const void *buf,
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }

diff  --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h 
b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index 594bd090fb988..24b5a317b54fa 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -74,6 +74,8 @@ class ScriptedProcess : public Process {
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status



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


[Lldb-commits] [lldb] 482a0ad - [lldb] Improve logging for process state change (NFC)

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: 482a0ad5ba72d2c306afd2d529f14eadcd8a

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

LOG: [lldb] Improve logging for process state change (NFC)

This patch improves process state change logging messages to include to
process plugin name.

It also replaces the `LLDB_LOGF` macro by `LLDB_LOG` macro that adds the
class and method name in the log message using the compiler instead of
having to change the string litteral for every method.

This is very useful when investigating interactions between different
types of process plugins. That comes very handy when investigating bugs
related to interactive scripted process debugging.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Target/Process.cpp

Removed: 




diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 5de32e277023..3f2e3b839480 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1055,14 +1055,16 @@ bool Process::SetExitStatus(int status, const char 
*cstr) {
   std::lock_guard guard(m_exit_status_mutex);
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(
-  log, "Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)",
-  status, status, cstr ? "\"" : "", cstr ? cstr : "NULL", cstr ? "\"" : 
"");
+  LLDB_LOG(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
+   GetPluginName().data(), status, status, cstr ? "\"" : "",
+   cstr ? cstr : "NULL", cstr ? "\"" : "");
 
   // We were already in the exited state
   if (m_private_state.GetValue() == eStateExited) {
-LLDB_LOGF(log, "Process::SetExitStatus () ignoring exit status because "
-   "state was already set to eStateExited");
+LLDB_LOG(log,
+ "(plugin = %s) ignoring exit status because state was already set 
"
+ "to eStateExited",
+ GetPluginName().data());
 return false;
   }
 
@@ -1314,8 +1316,8 @@ void Process::SetPublicState(StateType new_state, bool 
restarted) {
   }
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "Process::SetPublicState (state = %s, restarted = %i)",
-StateAsCString(new_state), restarted);
+  LLDB_LOG(log, "(plugin = %s, state = %s, restarted = %i)",
+   GetPluginName().data(), StateAsCString(new_state), restarted);
   const StateType old_state = m_public_state.GetValue();
   m_public_state.SetValue(new_state);
 
@@ -1324,16 +1326,16 @@ void Process::SetPublicState(StateType new_state, bool 
restarted) {
   // program to run.
   if (!StateChangedIsExternallyHijacked()) {
 if (new_state == eStateDetached) {
-  LLDB_LOGF(log,
-"Process::SetPublicState (%s) -- unlocking run lock for 
detach",
-StateAsCString(new_state));
+  LLDB_LOG(log,
+   "(plugin = %s, state = %s) -- unlocking run lock for detach",
+   GetPluginName().data(), StateAsCString(new_state));
   m_public_run_lock.SetStopped();
 } else {
   const bool old_state_is_stopped = StateIsStoppedState(old_state, false);
   if ((old_state_is_stopped != new_state_is_stopped)) {
 if (new_state_is_stopped && !restarted) {
-  LLDB_LOGF(log, "Process::SetPublicState (%s) -- unlocking run lock",
-StateAsCString(new_state));
+  LLDB_LOG(log, "(plugin = %s, state = %s) -- unlocking run lock",
+   GetPluginName().data(), StateAsCString(new_state));
   m_public_run_lock.SetStopped();
 }
   }
@@ -1343,10 +1345,11 @@ void Process::SetPublicState(StateType new_state, bool 
restarted) {
 
 Status Process::Resume() {
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "Process::Resume -- locking run lock");
+  LLDB_LOG(log, "(plugin = %s) -- locking run lock", GetPluginName().data());
   if (!m_public_run_lock.TrySetRunning()) {
 Status error("Resume request failed - process still running.");
-LLDB_LOGF(log, "Process::Resume: -- TrySetRunning failed, not resuming.");
+LLDB_LOG(log, "(plugin = %s) -- TrySetRunning failed, not resuming.",
+ GetPluginName().data());
 return error;
   }
   Status error = PrivateResume();
@@ -1419,7 +1422,8 @@ void Process::SetPrivateState(StateType new_state) {
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process | LLDBLog::Unwind));
   bool state_changed = false;
 
-  LLDB_LOGF(log, "Process::SetPrivateState (%s)", StateAsCString(new_state));
+  LLDB_LOG(log, "(plugin = %s, state = %s)", GetPluginName().data(),
+   StateAsCString(new_state));
 
   std::lock_guard thread_

[Lldb-commits] [lldb] af1fea8 - [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: af1fea818391f20d585414493adb3fcdc70b4756

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

LOG: [lldb/API] Add convenience constructor for SBError (NFC)

This patch adds a new convience constructor to the SBError to initialize
it with a string message to avoid having to create the object and call
the `SetErrorString` method afterwards.

This is very handy to report errors from lldb scripted affordances.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/API/SBError.h
lldb/source/API/SBError.cpp

Removed: 




diff  --git a/lldb/include/lldb/API/SBError.h b/lldb/include/lldb/API/SBError.h
index 16300bd93f69d..f6d5b748c56db 100644
--- a/lldb/include/lldb/API/SBError.h
+++ b/lldb/include/lldb/API/SBError.h
@@ -23,6 +23,8 @@ class LLDB_API SBError {
 
   SBError(const lldb::SBError &rhs);
 
+  SBError(const char *message);
+
 #ifndef SWIG
   SBError(const lldb_private::Status &error);
 #endif

diff  --git a/lldb/source/API/SBError.cpp b/lldb/source/API/SBError.cpp
index 1a034154955d8..2eb9e927514ac 100644
--- a/lldb/source/API/SBError.cpp
+++ b/lldb/source/API/SBError.cpp
@@ -25,6 +25,12 @@ SBError::SBError(const SBError &rhs) {
   m_opaque_up = clone(rhs.m_opaque_up);
 }
 
+SBError::SBError(const char *message) {
+  LLDB_INSTRUMENT_VA(this, message);
+
+  SetErrorString(message);
+}
+
 SBError::SBError(const lldb_private::Status &status)
 : m_opaque_up(new Status(status)) {
   LLDB_INSTRUMENT_VA(this, status);



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


[Lldb-commits] [PATCH] D145294: [lldb/API] Introduce SBProcess::ForceScriptedState method

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d77e034749f: [lldb/API] Introduce 
SBProcess::ForceScriptedState method (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145294

Files:
  lldb/include/lldb/API/SBProcess.h
  lldb/include/lldb/Target/Process.h
  lldb/source/API/SBProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -90,6 +90,10 @@
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2565,6 +2565,8 @@
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 
Index: lldb/include/lldb/API/SBProcess.h
===
--- lldb/include/lldb/API/SBProcess.h
+++ lldb/include/lldb/API/SBProcess.h
@@ -186,6 +186,14 @@
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its state to the new state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -90,6 +90,10 @@
 
   void *GetImplementation() override;
 
+  void ForceScriptedState(lldb::StateType state) override {
+SetPrivateState(state);
+  }
+
 protected:
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
Index: lldb/source/API/SBProcess.cpp
===
--- lldb/source/API/SBProcess.cpp
+++ lldb/source/API/SBProcess.cpp
@@ -466,6 +466,16 @@
   return sb_event;
 }
 
+void SBProcess::ForceScriptedState(StateType new_state) {
+  LLDB_INSTRUMENT_VA(this, new_state);
+
+  if (ProcessSP process_sp = GetSP()) {
+std::lock_guard guard(
+process_sp->GetTarget().GetAPIMutex());
+process_sp->ForceScriptedState(new_state);
+  }
+}
+
 StateType SBProcess::GetState() {
   LLDB_INSTRUMENT_VA(this);
 
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -2565,6 +2565,8 @@
 
   virtual void *GetImplementation() { return nullptr; }
 
+  virtual void ForceScriptedState(lldb::StateType state) {}
+
 protected:
   friend class Trace;
 
Index: lldb/include/lldb/API/SBProcess.h
===
--- lldb/include/lldb/API/SBProcess.h
+++ lldb/include/lldb/API/SBProcess.h
@@ -186,6 +186,14 @@
   ///   The stop event corresponding to stop ID.
   lldb::SBEvent GetStopEventForStopID(uint32_t stop_id);
 
+  /// If the process is a scripted process, changes its state to the new state.
+  /// No-op otherwise.
+  ///
+  /// \param [in] new_state
+  ///   The new state that the scripted process should be set to.
+  ///
+  void ForceScriptedState(StateType new_state);
+
   size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error);
 
   size_t WriteMemory(addr_t addr, const void *buf, size_t size,
__

[Lldb-commits] [lldb] 6cf6680 - [lldb] Add an example of interactive scripted process debugging

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:02:34-07:00
New Revision: 6cf668016efde05db8c9f179843ec457ad017ff7

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

LOG: [lldb] Add an example of interactive scripted process debugging

This patch is a proof of concept that shows how a scripted process could
be used with real process to perform interactive debugging.

In this example, we run a process that spawns 10 threads.
That process gets launched by an intermediary scripted process who's job
is to intercept all of it's process events and dispatching them
back either to the real process or to other child scripted processes.

In this example, we have 2 child scripted processes, with even and odd
thread indices. The goal is to be able to do thread filtering and
explore the various interactive debugging approaches, by letting a child
process running when stopping the other process and inspecting it.
Another approach would be to have the child processes execution in-sync
to force running every child process when one of them starts running.

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

Signed-off-by: Med Ismail Bennani 

Added: 
lldb/test/API/functionalities/interactive_scripted_process/Makefile

lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
lldb/test/API/functionalities/interactive_scripted_process/main.cpp

Modified: 


Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/Makefile 
b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
new file mode 100644
index 0..bbfb2c131ed51
--- /dev/null
+++ b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
@@ -0,0 +1,6 @@
+CXX_SOURCES := main.cpp
+CXXFLAGS=--std=c++17 -g
+ARCH=$(shell uname -m)
+
+include Makefile.rules
+

diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
new file mode 100644
index 0..a413317be867b
--- /dev/null
+++ 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -0,0 +1,122 @@
+"""
+Test the functionality of interactive scripted processes
+"""
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+import json, os
+
+
+class TestInteractiveScriptedProcess(TestBase):
+
+NO_DEBUG_INFO_TESTCASE = True
+
+def test_passthrough_launch(self):
+"""Test a simple pass-through process launch"""
+self.build()
+self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
+self.main_source_file = lldb.SBFileSpec("main.cpp")
+self.script_module = "interactive_scripted_process"
+self.script_file = self.script_module + ".py"
+self.passthrough_launch()
+
+def duplicate_target(self, driving_target):
+exe = driving_target.executable.fullpath
+triple = driving_target.triple
+return self.dbg.CreateTargetWithFileAndTargetTriple(exe, triple)
+
+def get_launch_info(self, class_name, script_dict):
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(json.dumps(script_dict))
+
+launch_info = lldb.SBLaunchInfo(None)
+launch_info.SetProcessPluginName("ScriptedProcess")
+launch_info.SetScriptedProcessClassName(class_name)
+launch_info.SetScriptedProcessDictionary(structured_data)
+return launch_info
+
+def passthrough_launch(self):
+"""Test that a simple passthrough wrapper functions correctly"""
+# First build the real target:
+self.assertEqual(self.dbg.GetNumTargets(), 1)
+real_target_id = 0
+real_target = self.dbg.GetTargetAtIndex(real_target_id)
+lldbutil.run_break_set_by_source_regexp(self, "Break here")
+self.assertEqual(real_target.GetNumBreakpoints(), 1)
+
+# Now source in the scripted module:
+script_path = os.path.join(self.getSourceDir(), self.script_file)
+self.runCmd(f"command script import '{script_path}'")
+
+mux_target = self.duplicate_target(real_target)
+self.assertTrue(mux_target.IsValid(), "duplicate target succeeded")
+
+mux_class = f"{self.script_module}.MultiplexerScriptedProcess"
+script_dict = {"driving_target_idx": real_target_id}
+mux_launch_info = self.get_launch_info(mux_class, script_dict)
+mux_process_listener = lldb.SBListener(
+"lldb.test.interactive-scripted-process.listener"
+)
+

[Lldb-commits] [lldb] e31d0c2 - [lldb] Improve breakpoint management for interactive scripted process

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:03:15-07:00
New Revision: e31d0c20e411f22a943f1ed5f8b618c529436c59

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

LOG: [lldb] Improve breakpoint management for interactive scripted process

This patch improves breakpoint management when doing interactive
scripted process debugging.

In other to know which process set a breakpoint, we need to do some book
keeping on the multiplexer scripted process. When initializing the
multiplexer, we will first copy breakpoints that are already set on the
driving target.

Everytime we launch or resume, we should copy breakpoints from the
multiplexer to the driving process.

When creating a breakpoint from a child process, it needs to be set both
on the multiplexer and on the driving process. We also tag the created
breakpoint with the name and pid of the originator process.

This patch also implements all the requirement to achieve proper
breakpoint management. That involves:

- Adding python interator for breakpoints and watchpoints in SBTarget
- Add a new `ScriptedProcess.create_breakpoint` python method

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/bindings/interface/SBTargetExtensions.i
lldb/bindings/python/python-wrapper.swig
lldb/examples/python/scripted_process/scripted_process.py
lldb/include/lldb/API/SBBreakpoint.h
lldb/include/lldb/Interpreter/ScriptInterpreter.h
lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
lldb/source/Interpreter/ScriptInterpreter.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h

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

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

lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Removed: 




diff  --git a/lldb/bindings/interface/SBTargetExtensions.i 
b/lldb/bindings/interface/SBTargetExtensions.i
index a062a109fa0b5..02c40b09c857f 100644
--- a/lldb/bindings/interface/SBTargetExtensions.i
+++ b/lldb/bindings/interface/SBTargetExtensions.i
@@ -88,7 +88,7 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, 
lldb::eDescriptionLevelBrief)
 
 def get_modules_access_object(self):
 '''An accessor function that returns a modules_access() object 
which allows lazy module access from a lldb.SBTarget object.'''
-return self.modules_access (self)
+return self.modules_access(self)
 
 def get_modules_array(self):
 '''An accessor function that returns a list() that contains all 
modules in a lldb.SBTarget object.'''
@@ -107,18 +107,80 @@ STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, 
lldb::eDescriptionLevelBrief)
 object.'''
 return lldb_iter(self, 'GetNumBreakpoints', 'GetBreakpointAtIndex')
 
+class bkpts_access(object):
+'''A helper object that will lazily hand out bkpts for a target 
when supplied an index.'''
+def __init__(self, sbtarget):
+self.sbtarget = sbtarget
+
+def __len__(self):
+if self.sbtarget:
+return int(self.sbtarget.GetNumBreakpoints())
+return 0
+
+def __getitem__(self, key):
+if isinstance(key, int):
+count = len(self)
+if -count <= key < count:
+key %= count
+return self.sbtarget.GetBreakpointAtIndex(key)
+return None
+
+def get_bkpts_access_object(self):
+'''An accessor function that returns a bkpts_access() object which 
allows lazy bkpt access from a lldb.SBtarget object.'''
+return self.bkpts_access(self)
+
+def get_target_bkpts(self):
+'''An accessor function that returns a list() that contains all 
bkpts in a lldb.SBtarget object.'''
+bkpts = []
+for idx in range(self.GetNumBreakpoints()):
+bkpts.append(self.GetBreakpointAtIndex(idx))
+return bkpts
+
 def watchpoint_iter(self):
 '''Returns an iterator over all watchpoints in a lldb.SBTarget
 object.'''
 return lldb_iter(self, 'GetNumWatchpoints', 'GetWatchpointAtIndex')
 
+class

[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c961ae1b507: [lldb] Move ScriptedProcess private state 
update to implementation (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D145295?vs=504877&id=516941#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

Files:
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h

Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -113,6 +113,11 @@
 return {object};
   }
 
+  python::PythonObject Transform(bool arg) {
+// Boolean arguments need to be turned into python objects.
+return python::PythonBoolean(arg);
+  }
+
   python::PythonObject Transform(Status arg) {
 return python::ToSWIGWrapper(arg);
   }
@@ -141,6 +146,19 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
+  template <>
+  void ReverseTransform(bool &original_arg,
+python::PythonObject transformed_arg, Status &error) {
+python::PythonBoolean boolean_arg = python::PythonBoolean(
+python::PyRefType::Borrowed, transformed_arg.get());
+if (boolean_arg.IsValid())
+  original_arg = boolean_arg.GetValue();
+else
+  error.SetErrorString(
+  llvm::formatv("{}: Invalid boolean argument.", LLVM_PRETTY_FUNCTION)
+  .str());
+  }
+
   template 
   auto TransformTuple(const std::tuple &args,
   std::index_sequence) {
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -37,10 +37,6 @@
 
   Status Resume() override;
 
-  bool ShouldStop() override;
-
-  Status Stop() override;
-
   std::optional
   GetMemoryRegionContainingAddress(lldb::addr_t address,
Status &error) override;
Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -81,21 +81,8 @@
 }
 
 Status ScriptedProcessPythonInterface::Resume() {
-  return GetStatusFromMethod("resume");
-}
-
-bool ScriptedProcessPythonInterface::ShouldStop() {
-  Status error;
-  StructuredData::ObjectSP obj = Dispatch("is_alive", error);
-
-  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
-return {};
-
-  return obj->GetBooleanValue();
-}
-
-Status ScriptedProcessPythonInterface::Stop() {
-  return GetStatusFromMethod("stop");
+  // When calling ScriptedProcess.Resume from lldb we should always stop.
+  return GetStatusFromMethod("resume", /*should_stop=*/true);
 }
 
 std::optional
Index: lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -201,6 +201,7 @@
 template <>
 struct PythonFormat : PassthroughFormat {};
 template <> struct PythonFormat : PassthroughFormat {};
+template <> struct PythonFormat : PassthroughFormat {};
 template <>
 struct PythonFormat : PassthroughFormat {};
 template <> struct PythonFormat : PassthroughFormat {};
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -98,8 +98,6 @@
   ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
   const ScriptedMetadata &scripted_metadata, Status &error);
 
-  Status DoStop();
-
   void Clear();
 
   bool DoUpdateThreadList(ThreadList &old_thread_list,
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
=

[Lldb-commits] [lldb] 34bd157 - [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:03:45-07:00
New Revision: 34bd15798ede2bc003783ed61d08f8d6c74c38f9

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

LOG: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

This patch updates the `lldbutil.fetch_next_event` helper function to
either match a specific broadcaster or match a whole broadcaster class.

This is very handy when testing process events for interactive scripted
process debugging.

This also fixes a bug in the failing case, where `SBEvent.GetDescription`
expects a `SBStream` argument. We never took that code path in the
original implementation so we didn't hit that bug.

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

Signed-off-by: Med Ismail Bennani 

Added: 


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

Removed: 




diff  --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py 
b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index d174c5af069b8..309b51baae9be 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,25 @@ def start_listening_from(broadcaster, event_mask):
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, 
timeout=10):
 """Fetch one event from the listener and return it if it matches the 
provided broadcaster.
+If `match_class` is set to True, this will match an event with an entire 
broadcaster class.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 



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


[Lldb-commits] [lldb] d3a6b93 - [lldb/test] Consolidate interactive scripted process debugging test

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:03:45-07:00
New Revision: d3a6b93135cd344737b2877b78afe9c862e40041

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

LOG: [lldb/test] Consolidate interactive scripted process debugging test

This patch improve the interactive scripted process debugging test by
adding test coverage for child process breakpoint setting and execution
state change.

This patch introduces a new test case for a multiplexed launch, which
does the same thing as the simple passthrough launch. After the
multiplexer process stops, this new test launches 2 other scripted processes
that should contain respectively the even and odd threads from the
multiplexer scripted process.

Then, we create a breakpoint on one the child scripted process, make
sure it was set probably on the child process, the multiplexer process
and the real process. This also test the breakpoint name tagging at the
multiplexer level.

Finally, we resume the child process that had a breakpoint and make sure
that all the processes has stopped at the right location.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 

lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
index dac05b0f70d2..ce05764b3f90 100644
--- 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -12,15 +12,185 @@ class TestInteractiveScriptedProcess(TestBase):
 
 NO_DEBUG_INFO_TESTCASE = True
 
-def test_passthrough_launch(self):
-"""Test a simple pass-through process launch"""
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Build and load test program
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), 
CURRENT_EXECUTABLE_SET)
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 self.script_module = "interactive_scripted_process"
 self.script_file = self.script_module + ".py"
+
+def test_passthrough_launch(self):
+"""Test a simple pass-through process launch"""
 self.passthrough_launch()
 
+lldbutil.run_break_set_by_source_regexp(self, "also break here")
+self.assertEqual(self.mux_target.GetNumBreakpoints(), 2)
+error = self.mux_process.Continue()
+self.assertSuccess(error, "Resuming multiplexer scripted process")
+self.assertTrue(self.mux_process.IsValid(), "Got a valid process")
+
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), 
lldb.eStateRunning)
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), 
lldb.eStateStopped)
+
+def test_multiplexed_launch(self):
+"""Test a multiple interactive scripted process debugging"""
+self.passthrough_launch()
+self.assertEqual(self.dbg.GetNumTargets(), 2)
+
+driving_target = 
self.mux_process.GetScriptedImplementation().driving_target
+self.assertTrue(driving_target.IsValid(), "Driving target is invalid")
+
+# Create a target for the multiplexed even scripted process
+even_target = self.duplicate_target(driving_target)
+self.assertTrue(
+even_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed even 
scripted process",
+)
+
+class_name = f"{self.script_module}.MultiplexedScriptedProcess"
+dictionary = {"driving_target_idx": 
self.dbg.GetIndexOfTarget(self.mux_target)}
+
+dictionary["parity"] = 0
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Even Child Scripted Process
+error = lldb.SBError()
+even_process = even_target.Launch(muxed_launch_info, error)
+self.assertTrue(
+even_process, "Couldn't launch multiplexed even scripted process"
+)
+self.multiplex(even_process)
+
+# Check that the even process started running
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(

[Lldb-commits] [PATCH] D148395: [lldb] Unify default/hijack listener between Process{Attach, Launch}Info (NFC)

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46e93c9df287: [lldb] Unify default/hijack listener between 
Process{Attach,Launch}Info (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148395

Files:
  lldb/include/lldb/Host/ProcessLaunchInfo.h
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Utility/ProcessInfo.h
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Utility/ProcessInfo.cpp

Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -22,12 +22,14 @@
 using namespace lldb_private;
 
 ProcessInfo::ProcessInfo()
-: m_executable(), m_arguments(), m_environment(), m_arch() {}
+: m_executable(), m_arguments(), m_environment(), m_arch(), m_listener_sp(),
+  m_hijack_listener_sp(), m_passthrough_listener_sp() {}
 
 ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch,
  lldb::pid_t pid)
 : m_executable(name), m_arguments(), m_environment(), m_arch(arch),
-  m_pid(pid) {}
+  m_pid(pid), m_listener_sp(), m_hijack_listener_sp(),
+  m_passthrough_listener_sp() {}
 
 void ProcessInfo::Clear() {
   m_executable.Clear();
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -31,8 +31,8 @@
 
 ProcessLaunchInfo::ProcessLaunchInfo()
 : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
-  m_file_actions(), m_pty(new PseudoTerminal), m_monitor_callback(nullptr),
-  m_listener_sp(), m_hijack_listener_sp() {}
+  m_file_actions(), m_pty(new PseudoTerminal), m_monitor_callback(nullptr) {
+}
 
 ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec,
  const FileSpec &stdout_file_spec,
Index: lldb/include/lldb/Utility/ProcessInfo.h
===
--- lldb/include/lldb/Utility/ProcessInfo.h
+++ lldb/include/lldb/Utility/ProcessInfo.h
@@ -97,6 +97,19 @@
 m_scripted_metadata_sp = metadata_sp;
   }
 
+  // Get and set the actual listener that will be used for the process events
+  lldb::ListenerSP GetListener() const { return m_listener_sp; }
+
+  void SetListener(const lldb::ListenerSP &listener_sp) {
+m_listener_sp = listener_sp;
+  }
+
+  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
+
+  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
+m_hijack_listener_sp = listener_sp;
+  }
+
 protected:
   FileSpec m_executable;
   std::string m_arg0; // argv[0] if supported. If empty, then use m_executable.
@@ -109,6 +122,8 @@
   ArchSpec m_arch;
   lldb::pid_t m_pid = LLDB_INVALID_PROCESS_ID;
   lldb::ScriptedMetadataSP m_scripted_metadata_sp = nullptr;
+  lldb::ListenerSP m_listener_sp = nullptr;
+  lldb::ListenerSP m_hijack_listener_sp = nullptr;
 };
 
 // ProcessInstanceInfo
Index: lldb/include/lldb/Target/Process.h
===
--- lldb/include/lldb/Target/Process.h
+++ lldb/include/lldb/Target/Process.h
@@ -122,8 +122,6 @@
 ProcessInfo::operator=(launch_info);
 SetProcessPluginName(launch_info.GetProcessPluginName());
 SetResumeCount(launch_info.GetResumeCount());
-SetListener(launch_info.GetListener());
-SetHijackListener(launch_info.GetHijackListener());
 m_detach_on_error = launch_info.GetDetachOnError();
   }
 
@@ -174,28 +172,13 @@
 return false;
   }
 
-  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
-
-  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
-m_hijack_listener_sp = listener_sp;
-  }
-
   bool GetDetachOnError() const { return m_detach_on_error; }
 
   void SetDetachOnError(bool enable) { m_detach_on_error = enable; }
 
-  // Get and set the actual listener that will be used for the process events
-  lldb::ListenerSP GetListener() const { return m_listener_sp; }
-
-  void SetListener(const lldb::ListenerSP &listener_sp) {
-m_listener_sp = listener_sp;
-  }
-
   lldb::ListenerSP GetListenerForProcess(Debugger &debugger);
 
 protected:
-  lldb::ListenerSP m_listener_sp;
-  lldb::ListenerSP m_hijack_listener_sp;
   std::string m_plugin_name;
   uint32_t m_resume_count = 0; // How many times do we resume after launching
   bool m_wait_for_launch = false;
Index: lldb/include/lldb/Host/ProcessLaunchInfo.h
===
--- lldb/include/lldb/Host/ProcessLaunchInfo.h
+++ lldb/include/lldb/Host/ProcessLaunchInfo.h
@@ -120,19 +120,6 @@
 
   PseudoTerminal &GetPTY() { return *m_pty; }
 
-  // Get and set the actual listene

[Lldb-commits] [PATCH] D148397: [lldb/Utility] Add opt-in shadow mode to event listeners

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6382fcb16def: [lldb/Utility] Add opt-in shadow mode to event 
listeners (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148397

Files:
  lldb/include/lldb/API/SBAttachInfo.h
  lldb/include/lldb/API/SBLaunchInfo.h
  lldb/include/lldb/Target/Process.h
  lldb/include/lldb/Utility/Broadcaster.h
  lldb/include/lldb/Utility/Listener.h
  lldb/include/lldb/Utility/ProcessInfo.h
  lldb/source/API/SBAttachInfo.cpp
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
  lldb/source/Target/Target.cpp
  lldb/source/Utility/Broadcaster.cpp
  lldb/source/Utility/Listener.cpp
  lldb/source/Utility/ProcessInfo.cpp

Index: lldb/source/Utility/ProcessInfo.cpp
===
--- lldb/source/Utility/ProcessInfo.cpp
+++ lldb/source/Utility/ProcessInfo.cpp
@@ -23,13 +23,13 @@
 
 ProcessInfo::ProcessInfo()
 : m_executable(), m_arguments(), m_environment(), m_arch(), m_listener_sp(),
-  m_hijack_listener_sp(), m_passthrough_listener_sp() {}
+  m_hijack_listener_sp(), m_shadow_listener_sp() {}
 
 ProcessInfo::ProcessInfo(const char *name, const ArchSpec &arch,
  lldb::pid_t pid)
 : m_executable(name), m_arguments(), m_environment(), m_arch(arch),
   m_pid(pid), m_listener_sp(), m_hijack_listener_sp(),
-  m_passthrough_listener_sp() {}
+  m_shadow_listener_sp() {}
 
 void ProcessInfo::Clear() {
   m_executable.Clear();
Index: lldb/source/Utility/Listener.cpp
===
--- lldb/source/Utility/Listener.cpp
+++ lldb/source/Utility/Listener.cpp
@@ -35,7 +35,7 @@
 
 Listener::Listener(const char *name)
 : m_name(name), m_broadcasters(), m_broadcasters_mutex(), m_events(),
-  m_events_mutex() {
+  m_events_mutex(), m_is_shadow() {
   Log *log = GetLog(LLDBLog::Object);
   if (log != nullptr)
 LLDB_LOGF(log, "%p Listener::Listener('%s')", static_cast(this),
@@ -302,7 +302,8 @@
   // to return it so it should be okay to get the next event off the queue
   // here - and it might be useful to do that in the "DoOnRemoval".
   lock.unlock();
-  event_sp->DoOnRemoval();
+  if (!m_is_shadow)
+event_sp->DoOnRemoval();
 }
 return true;
   }
Index: lldb/source/Utility/Broadcaster.cpp
===
--- lldb/source/Utility/Broadcaster.cpp
+++ lldb/source/Utility/Broadcaster.cpp
@@ -228,6 +228,8 @@
   &m_broadcaster, event_type))
   return;
 hijacking_listener_sp->AddEvent(event_sp);
+if (m_shadow_listener)
+  m_shadow_listener->AddEvent(event_sp);
   } else {
 for (auto &pair : GetListeners()) {
   if (!(pair.second & event_type))
@@ -237,6 +239,8 @@
 continue;
 
   pair.first->AddEvent(event_sp);
+  if (m_shadow_listener)
+m_shadow_listener->AddEvent(event_sp);
 }
   }
 }
Index: lldb/source/Target/Target.cpp
===
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -3194,6 +3194,7 @@
 // Since we didn't have a platform launch the process, launch it here.
 if (m_process_sp) {
   m_process_sp->HijackProcessEvents(launch_info.GetHijackListener());
+  m_process_sp->SetShadowListener(launch_info.GetShadowListener());
   error = m_process_sp->Launch(launch_info);
 }
   }
Index: lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
===
--- lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -423,6 +423,7 @@
 
 if (process_sp) {
   process_sp->HijackProcessEvents(launch_info.GetHijackListener());
+  process_sp->SetShadowListener(launch_info.GetShadowListener());
 
   error = process_sp->ConnectRemote(connect_url.c_str());
   // Retry the connect remote one time...
@@ -515,6 +516,7 @@
   ListenerSP listener_sp = attach_info.GetHijackListener();
   if (listener_sp)
 process_sp->HijackProcessEvents(listener_sp);
+  process_sp->SetShadowListener(attach_info.GetShadowListener());
   error = process_sp->Attach(attach_info);
 }
 
Index: lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===
--- lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -401,6 +401,7 @@
   attach_info.SetHijackListener(listener_sp);
 }

[Lldb-commits] [PATCH] D148399: [lldb] Improve logging for process state change (NFC)

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG482a0ad5ba72: [lldb] Improve logging for process state 
change (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148399

Files:
  lldb/source/Target/Process.cpp

Index: lldb/source/Target/Process.cpp
===
--- lldb/source/Target/Process.cpp
+++ lldb/source/Target/Process.cpp
@@ -1055,14 +1055,16 @@
   std::lock_guard guard(m_exit_status_mutex);
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(
-  log, "Process::SetExitStatus (status=%i (0x%8.8x), description=%s%s%s)",
-  status, status, cstr ? "\"" : "", cstr ? cstr : "NULL", cstr ? "\"" : "");
+  LLDB_LOG(log, "(plugin = %s status=%i (0x%8.8x), description=%s%s%s)",
+   GetPluginName().data(), status, status, cstr ? "\"" : "",
+   cstr ? cstr : "NULL", cstr ? "\"" : "");
 
   // We were already in the exited state
   if (m_private_state.GetValue() == eStateExited) {
-LLDB_LOGF(log, "Process::SetExitStatus () ignoring exit status because "
-   "state was already set to eStateExited");
+LLDB_LOG(log,
+ "(plugin = %s) ignoring exit status because state was already set "
+ "to eStateExited",
+ GetPluginName().data());
 return false;
   }
 
@@ -1314,8 +1316,8 @@
   }
 
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "Process::SetPublicState (state = %s, restarted = %i)",
-StateAsCString(new_state), restarted);
+  LLDB_LOG(log, "(plugin = %s, state = %s, restarted = %i)",
+   GetPluginName().data(), StateAsCString(new_state), restarted);
   const StateType old_state = m_public_state.GetValue();
   m_public_state.SetValue(new_state);
 
@@ -1324,16 +1326,16 @@
   // program to run.
   if (!StateChangedIsExternallyHijacked()) {
 if (new_state == eStateDetached) {
-  LLDB_LOGF(log,
-"Process::SetPublicState (%s) -- unlocking run lock for detach",
-StateAsCString(new_state));
+  LLDB_LOG(log,
+   "(plugin = %s, state = %s) -- unlocking run lock for detach",
+   GetPluginName().data(), StateAsCString(new_state));
   m_public_run_lock.SetStopped();
 } else {
   const bool old_state_is_stopped = StateIsStoppedState(old_state, false);
   if ((old_state_is_stopped != new_state_is_stopped)) {
 if (new_state_is_stopped && !restarted) {
-  LLDB_LOGF(log, "Process::SetPublicState (%s) -- unlocking run lock",
-StateAsCString(new_state));
+  LLDB_LOG(log, "(plugin = %s, state = %s) -- unlocking run lock",
+   GetPluginName().data(), StateAsCString(new_state));
   m_public_run_lock.SetStopped();
 }
   }
@@ -1343,10 +1345,11 @@
 
 Status Process::Resume() {
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process));
-  LLDB_LOGF(log, "Process::Resume -- locking run lock");
+  LLDB_LOG(log, "(plugin = %s) -- locking run lock", GetPluginName().data());
   if (!m_public_run_lock.TrySetRunning()) {
 Status error("Resume request failed - process still running.");
-LLDB_LOGF(log, "Process::Resume: -- TrySetRunning failed, not resuming.");
+LLDB_LOG(log, "(plugin = %s) -- TrySetRunning failed, not resuming.",
+ GetPluginName().data());
 return error;
   }
   Status error = PrivateResume();
@@ -1419,7 +1422,8 @@
   Log *log(GetLog(LLDBLog::State | LLDBLog::Process | LLDBLog::Unwind));
   bool state_changed = false;
 
-  LLDB_LOGF(log, "Process::SetPrivateState (%s)", StateAsCString(new_state));
+  LLDB_LOG(log, "(plugin = %s, state = %s)", GetPluginName().data(),
+   StateAsCString(new_state));
 
   std::lock_guard thread_guard(m_thread_list.GetMutex());
   std::lock_guard guard(m_private_state.GetMutex());
@@ -1460,15 +1464,15 @@
   if (!m_mod_id.IsLastResumeForUserExpression())
 m_mod_id.SetStopEventForLastNaturalStopID(event_sp);
   m_memory_cache.Clear();
-  LLDB_LOGF(log, "Process::SetPrivateState (%s) stop_id = %u",
-StateAsCString(new_state), m_mod_id.GetStopID());
+  LLDB_LOG(log, "(plugin = %s, state = %s, stop_id = %u",
+   GetPluginName().data(), StateAsCString(new_state),
+   m_mod_id.GetStopID());
 }
 
 m_private_state_broadcaster.BroadcastEvent(event_sp);
   } else {
-LLDB_LOGF(log,
-  "Process::SetPrivateState (%s) state didn't change. Ignoring...",
-  StateAsCString(new_state));
+LLDB_LOG(log, "(plugin = %s, state = %s) state didn't change. Ignoring...",
+ GetPluginName().data(), StateAsCString(new_state));
   }
 }
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailma

[Lldb-commits] [PATCH] D145296: [lldb/Plugin] Add breakpoint setting support to ScriptedProcesses.

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGad03aeadfb72: [lldb/Plugin] Add breakpoint setting support 
to ScriptedProcess (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145296

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


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -74,6 +74,8 @@
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -249,6 +249,20 @@
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -74,6 +74,8 @@
   size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
Status &error) override;
 
+  Status EnableBreakpointSite(BreakpointSite *bp_site) override;
+
   ArchSpec GetArchitecture();
 
   Status
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -249,6 +249,20 @@
   return bytes_written;
 }
 
+Status ScriptedProcess::EnableBreakpointSite(BreakpointSite *bp_site) {
+  assert(bp_site != nullptr);
+
+  if (bp_site->IsEnabled()) {
+return {};
+  }
+
+  if (bp_site->HardwareRequired()) {
+return Status("Scripted Processes don't support hardware breakpoints");
+  }
+
+  return EnableSoftwareBreakpoint(bp_site);
+}
+
 ArchSpec ScriptedProcess::GetArchitecture() {
   return GetTarget().GetArchitecture();
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D148401: [lldb/API] Add convenience constructor for SBError (NFC)

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf1fea818391: [lldb/API] Add convenience constructor for 
SBError (NFC) (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148401

Files:
  lldb/include/lldb/API/SBError.h
  lldb/source/API/SBError.cpp


Index: lldb/source/API/SBError.cpp
===
--- lldb/source/API/SBError.cpp
+++ lldb/source/API/SBError.cpp
@@ -25,6 +25,12 @@
   m_opaque_up = clone(rhs.m_opaque_up);
 }
 
+SBError::SBError(const char *message) {
+  LLDB_INSTRUMENT_VA(this, message);
+
+  SetErrorString(message);
+}
+
 SBError::SBError(const lldb_private::Status &status)
 : m_opaque_up(new Status(status)) {
   LLDB_INSTRUMENT_VA(this, status);
Index: lldb/include/lldb/API/SBError.h
===
--- lldb/include/lldb/API/SBError.h
+++ lldb/include/lldb/API/SBError.h
@@ -23,6 +23,8 @@
 
   SBError(const lldb::SBError &rhs);
 
+  SBError(const char *message);
+
 #ifndef SWIG
   SBError(const lldb_private::Status &error);
 #endif


Index: lldb/source/API/SBError.cpp
===
--- lldb/source/API/SBError.cpp
+++ lldb/source/API/SBError.cpp
@@ -25,6 +25,12 @@
   m_opaque_up = clone(rhs.m_opaque_up);
 }
 
+SBError::SBError(const char *message) {
+  LLDB_INSTRUMENT_VA(this, message);
+
+  SetErrorString(message);
+}
+
 SBError::SBError(const lldb_private::Status &status)
 : m_opaque_up(new Status(status)) {
   LLDB_INSTRUMENT_VA(this, status);
Index: lldb/include/lldb/API/SBError.h
===
--- lldb/include/lldb/API/SBError.h
+++ lldb/include/lldb/API/SBError.h
@@ -23,6 +23,8 @@
 
   SBError(const lldb::SBError &rhs);
 
+  SBError(const char *message);
+
 #ifndef SWIG
   SBError(const lldb_private::Status &error);
 #endif
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D145297: [lldb] Add an example of interactive scripted process debugging

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6cf668016efd: [lldb] Add an example of interactive scripted 
process debugging (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145297

Files:
  lldb/test/API/functionalities/interactive_scripted_process/Makefile
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
  
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
  lldb/test/API/functionalities/interactive_scripted_process/main.cpp

Index: lldb/test/API/functionalities/interactive_scripted_process/main.cpp
===
--- /dev/null
+++ lldb/test/API/functionalities/interactive_scripted_process/main.cpp
@@ -0,0 +1,35 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+
+void spawn_thread(int index) {
+  std::string name = "I'm thread " + std::to_string(index) + " !";
+  bool done = false;
+  std::string state = "Started execution!";
+  while (true) {
+if (done) // also break here
+  break;
+  }
+
+  state = "Stopped execution!";
+}
+
+int main() {
+  constexpr size_t num_threads = 10;
+  std::vector threads;
+
+  for (size_t i = 0; i < num_threads; i++) {
+threads.push_back(std::thread(spawn_thread, i));
+  }
+
+  std::cout << "Spawned " << threads.size() << " threads!" << std::endl; // Break here
+
+  for (auto &t : threads) {
+if (t.joinable())
+  t.join();
+  }
+
+  return 0;
+}
Index: lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
===
--- /dev/null
+++ lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
@@ -0,0 +1,494 @@
+# Usage:
+# ./bin/lldb $LLVM/lldb/test/API/functionalities/interactive_scripted_process/main \
+#   -o "br set -p 'Break here'" \
+#   -o "command script import $LLVM/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py" \
+#   -o "create_mux" \
+#   -o "create_sub" \
+#   -o "br set -p 'also break here'" -o 'continue'
+
+import os, json, struct, signal
+
+from threading import Thread
+from typing import Any, Dict
+
+import lldb
+from lldb.plugins.scripted_process import ScriptedProcess
+from lldb.plugins.scripted_process import ScriptedThread
+
+
+class PassthruScriptedProcess(ScriptedProcess):
+driving_target = None
+driving_process = None
+
+def __init__(
+self,
+exe_ctx: lldb.SBExecutionContext,
+args: lldb.SBStructuredData,
+launched_driving_process: bool = True,
+):
+super().__init__(exe_ctx, args)
+
+self.driving_target = None
+self.driving_process = None
+
+self.driving_target_idx = args.GetValueForKey("driving_target_idx")
+if self.driving_target_idx and self.driving_target_idx.IsValid():
+if self.driving_target_idx.GetType() == lldb.eStructuredDataTypeInteger:
+idx = self.driving_target_idx.GetIntegerValue(42)
+if self.driving_target_idx.GetType() == lldb.eStructuredDataTypeString:
+idx = int(self.driving_target_idx.GetStringValue(100))
+self.driving_target = self.target.GetDebugger().GetTargetAtIndex(idx)
+
+if launched_driving_process:
+self.driving_process = self.driving_target.GetProcess()
+for driving_thread in self.driving_process:
+structured_data = lldb.SBStructuredData()
+structured_data.SetFromJSON(
+json.dumps(
+{
+"driving_target_idx": idx,
+"thread_idx": driving_thread.GetIndexID(),
+}
+)
+)
+
+self.threads[driving_thread.GetThreadID()] = PassthruScriptedThread(
+self, structured_data
+)
+
+for module in self.driving_target.modules:
+path = module.file.fullpath
+load_addr = module.GetObjectFileHeaderAddress().GetLoadAddress(
+self.driving_target
+)
+self.loaded_images.append({"path": path, "load_addr": load_addr})
+
+def get_memory_region_containing_address(
+self, addr: int
+) -> lldb.SBMemoryRegionInfo:
+mem_region = lldb.SBMemoryRegionInfo()
+error = self.driving_process.GetMemoryRegionInfo(addr, mem_region)
+if error.Fail():
+return None
+return mem_region
+
+def read_memory_at_address(
+self, addr: int, size: int, error: lldb.SBError
+) -> lldb.SBData:
+data = lldb.SBData()
+b

[Lldb-commits] [PATCH] D148548: [lldb] Improve breakpoint management for interactive scripted process

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe31d0c20e411: [lldb] Improve breakpoint management for 
interactive scripted process (authored by mib).

Changed prior to commit:
  https://reviews.llvm.org/D148548?vs=515902&id=516948#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148548

Files:
  lldb/bindings/interface/SBTargetExtensions.i
  lldb/bindings/python/python-wrapper.swig
  lldb/examples/python/scripted_process/scripted_process.py
  lldb/include/lldb/API/SBBreakpoint.h
  lldb/include/lldb/Interpreter/ScriptInterpreter.h
  lldb/include/lldb/Interpreter/ScriptedProcessInterface.h
  lldb/source/Interpreter/ScriptInterpreter.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
  
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

Index: lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
===
--- lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
+++ lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
@@ -139,6 +139,10 @@
   return nullptr;
 }
 
+void *lldb_private::LLDBSWIGPython_CastPyObjectToSBBreakpoint(PyObject *data) {
+  return nullptr;
+}
+
 void *lldb_private::LLDBSWIGPython_CastPyObjectToSBAttachInfo(PyObject *data) {
   return nullptr;
 }
Index: lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
+++ lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
@@ -6,7 +6,7 @@
 #   -o "create_sub" \
 #   -o "br set -p 'also break here'" -o 'continue'
 
-import os, json, struct, signal
+import os, json, struct, signal, tempfile
 
 from threading import Thread
 from typing import Any, Dict
@@ -152,6 +152,11 @@
 )
 )
 
+def create_breakpoint(self, addr, error, pid=None):
+if not self.multiplexer:
+error.SetErrorString("Multiplexer is not set.")
+return self.multiplexer.create_breakpoint(addr, error, self.get_process_id())
+
 def get_scripted_thread_plugin(self) -> str:
 return f"{MultiplexedScriptedThread.__module__}.{MultiplexedScriptedThread.__name__}"
 
@@ -300,6 +305,40 @@
 )
 self.multiplexed_processes = {}
 
+# Copy breakpoints from real target to passthrough
+with tempfile.NamedTemporaryFile() as tf:
+bkpt_file = lldb.SBFileSpec(tf.name)
+error = self.driving_target.BreakpointsWriteToFile(bkpt_file)
+if error.Fail():
+log(
+"Failed to save breakpoints from driving target (%s)"
+% error.GetCString()
+)
+bkpts_list = lldb.SBBreakpointList(self.target)
+error = self.target.BreakpointsCreateFromFile(bkpt_file, bkpts_list)
+if error.Fail():
+log(
+"Failed create breakpoints from driving target \
+(bkpt file: %s)"
+% tf.name
+)
+
+# Copy breakpoint from passthrough to real target
+if error.Success():
+self.driving_target.DeleteAllBreakpoints()
+for bkpt in self.target.breakpoints:
+if bkpt.IsValid():
+for bl in bkpt:
+real_bpkt = self.driving_target.BreakpointCreateBySBAddress(
+bl.GetAddress()
+)
+if not real_bpkt.IsValid():
+log(
+"Failed to set breakpoint at address %s in \
+driving target"
+% hex(bl.GetLoadAddress())
+)
+
 self.listener_thread = Thread(
 target=self.wait_for_driving_process_to_stop, daemon=True
 )
@@ -364,6 +403,47 @@
 parity = pid % 2
 return dict(filter(lambda pair: pair[0] % 2 == parity, self.threads.items()))
 

[Lldb-commits] [PATCH] D149175: [lldb/test] Update lldbutil.fetch_next_event to match broadcaster class

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34bd15798ede: [lldb/test] Update lldbutil.fetch_next_event 
to match broadcaster class (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149175

Files:
  lldb/packages/Python/lldbsuite/test/lldbutil.py


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,25 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, 
timeout=10):
 """Fetch one event from the listener and return it if it matches the 
provided broadcaster.
+If `match_class` is set to True, this will match an event with an entire 
broadcaster class.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 


Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1202,18 +1202,25 @@
 broadcaster.AddListener(listener, event_mask)
 return listener
 
-def fetch_next_event(test, listener, broadcaster, timeout=10):
+def fetch_next_event(test, listener, broadcaster, match_class=False, timeout=10):
 """Fetch one event from the listener and return it if it matches the provided broadcaster.
+If `match_class` is set to True, this will match an event with an entire broadcaster class.
 Fails otherwise."""
 
 event = lldb.SBEvent()
 
 if listener.WaitForEvent(timeout, event):
-if event.BroadcasterMatchesRef(broadcaster):
-return event
+if match_class:
+if event.GetBroadcasterClass() == broadcaster:
+return event
+else:
+if event.BroadcasterMatchesRef(broadcaster):
+return event
 
+stream = lldb.SBStream()
+event.GetDescription(stream)
 test.fail("received event '%s' from unexpected broadcaster '%s'." %
-  (event.GetDescription(), event.GetBroadcaster().GetName()))
+  (stream.GetData(), event.GetBroadcaster().GetName()))
 
 test.fail("couldn't fetch an event before reaching the timeout.")
 
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149179: [lldb/test] Consolidate interactive scripted process debugging test

2023-04-25 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 rGd3a6b93135cd: [lldb/test] Consolidate interactive scripted 
process debugging test (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149179

Files:
  
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Index: lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
===
--- lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -12,15 +12,185 @@
 
 NO_DEBUG_INFO_TESTCASE = True
 
-def test_passthrough_launch(self):
-"""Test a simple pass-through process launch"""
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+# Build and load test program
 self.build()
 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 self.script_module = "interactive_scripted_process"
 self.script_file = self.script_module + ".py"
+
+def test_passthrough_launch(self):
+"""Test a simple pass-through process launch"""
 self.passthrough_launch()
 
+lldbutil.run_break_set_by_source_regexp(self, "also break here")
+self.assertEqual(self.mux_target.GetNumBreakpoints(), 2)
+error = self.mux_process.Continue()
+self.assertSuccess(error, "Resuming multiplexer scripted process")
+self.assertTrue(self.mux_process.IsValid(), "Got a valid process")
+
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+event = lldbutil.fetch_next_event(
+self, self.mux_process_listener, self.mux_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+def test_multiplexed_launch(self):
+"""Test a multiple interactive scripted process debugging"""
+self.passthrough_launch()
+self.assertEqual(self.dbg.GetNumTargets(), 2)
+
+driving_target = self.mux_process.GetScriptedImplementation().driving_target
+self.assertTrue(driving_target.IsValid(), "Driving target is invalid")
+
+# Create a target for the multiplexed even scripted process
+even_target = self.duplicate_target(driving_target)
+self.assertTrue(
+even_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed even scripted process",
+)
+
+class_name = f"{self.script_module}.MultiplexedScriptedProcess"
+dictionary = {"driving_target_idx": self.dbg.GetIndexOfTarget(self.mux_target)}
+
+dictionary["parity"] = 0
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Even Child Scripted Process
+error = lldb.SBError()
+even_process = even_target.Launch(muxed_launch_info, error)
+self.assertTrue(
+even_process, "Couldn't launch multiplexed even scripted process"
+)
+self.multiplex(even_process)
+
+# Check that the even process started running
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateRunning)
+# Check that the even process stopped
+event = lldbutil.fetch_next_event(
+self, self.dbg.GetListener(), even_process.GetBroadcaster()
+)
+self.assertState(lldb.SBProcess.GetStateFromEvent(event), lldb.eStateStopped)
+
+self.assertTrue(even_process.IsValid(), "Got a valid process")
+self.assertState(
+even_process.GetState(), lldb.eStateStopped, "Process is stopped"
+)
+
+# Create a target for the multiplexed odd scripted process
+odd_target = self.duplicate_target(driving_target)
+self.assertTrue(
+odd_target.IsValid(),
+"Couldn't duplicate driving target to launch multiplexed odd scripted process",
+)
+
+dictionary["parity"] = 1
+muxed_launch_info = self.get_launch_info(class_name, dictionary)
+
+# Launch Odd Child Scripted Process
+error = lldb.SBError()
+odd_process = odd_target.Launch(muxed_launch_info, error)
+self.assertTrue(odd_process, "Couldn't launch multiplexed odd scripted process")
+self.multiplex(odd_process)
+
+   

[Lldb-commits] [lldb] 30f4adf - [lldb/test] Enable threads for TestInteractiveScriptedProcess.py (NFC)

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T15:19:57-07:00
New Revision: 30f4adfd4d6ca73b1dae1d14f43ac363e005ccec

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

LOG: [lldb/test] Enable threads for TestInteractiveScriptedProcess.py (NFC)

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/test/API/functionalities/interactive_scripted_process/Makefile

Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/Makefile 
b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
index bbfb2c131ed5..669f80a17ae6 100644
--- a/lldb/test/API/functionalities/interactive_scripted_process/Makefile
+++ b/lldb/test/API/functionalities/interactive_scripted_process/Makefile
@@ -1,6 +1,7 @@
 CXX_SOURCES := main.cpp
 CXXFLAGS=--std=c++17 -g
 ARCH=$(shell uname -m)
+ENABLE_THREADS := YES
 
 include Makefile.rules
 



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


[Lldb-commits] [lldb] d0d902d - [lldb/test] Disable Interactive Scripted Process test unless Darwin

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T16:00:58-07:00
New Revision: d0d902df0698f94957e13df159e9cd159a99344c

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

LOG: [lldb/test] Disable Interactive Scripted Process test unless Darwin

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 

lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
index ce05764b3f90..7a0d2f2d817e 100644
--- 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -22,6 +22,7 @@ def setUp(self):
 self.script_module = "interactive_scripted_process"
 self.script_file = self.script_module + ".py"
 
+@skipUnlessDarwin
 def test_passthrough_launch(self):
 """Test a simple pass-through process launch"""
 self.passthrough_launch()
@@ -41,6 +42,7 @@ def test_passthrough_launch(self):
 )
 self.assertState(lldb.SBProcess.GetStateFromEvent(event), 
lldb.eStateStopped)
 
+@skipUnlessDarwin
 def test_multiplexed_launch(self):
 """Test a multiple interactive scripted process debugging"""
 self.passthrough_launch()



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


[Lldb-commits] [PATCH] D149213: [lldb] Add basic support to Rust enums in TypeSystemClang

2023-04-25 Thread Vladimir Makaev via Phabricator via lldb-commits
VladimirMakaev created this revision.
VladimirMakaev added reviewers: clayborg, ayermolo, Michael137.
VladimirMakaev added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a reviewer: shafik.
Herald added a project: All.
VladimirMakaev requested review of this revision.
Herald added a subscriber: lldb-commits.

LLDB doesn't yet have a TypeSystemRust implemented however it is used to debug 
Rust applications. Most of the types map well enough to Clang types and there 
are python formatters implemented to display those types reasonably well in a 
debugger. We discussed this with Greg Clayton internally and this approach 
looks like a reasonable thing to implement and fix one of the major pain points 
when debugging Rust with LLDB.

However, Rust enums are completely ignored by LLDB as Clang never emits 
DW_TAG_variant_part inside DW_TAG_structure_type

This diff adds a parser for DW_TAG_variant_part (Rust-only) that creates a 
matching valid Clang declaration that represents a Rust enum. As long as there 
is enough information and all fields have correct offsets synthetic/summary 
providers can be implemented to display it correctly when debugging Rust code

For example given a Rust enum:

  enum EnumOpt2 {
  A(u8),
  B(bool),
  }

The following is a matching Clang declaration:

  struct EnumOpt2 {
  union debugger_test::EnumOpt2$Inner {
  struct A$Variant {
  unsigned char $discr$;
  debugger_test::EnumOpt2::A value : 8;
  };
  debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner::A$Variant 
$variant$0;
  struct B$Variant {
  unsigned char $discr$;
  debugger_test::EnumOpt2::B value : 8;
  };
  debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner::B$Variant 
$variant$1;
  };
  struct A {
  unsigned char __0;
  };
  struct B {
  bool __0;
  };
  debugger_test::EnumOpt2::debugger_test::EnumOpt2$Inner inner;
  }

Now this declaration contains all the necessary information to interpret the 
original Rust enum in a Python synthetic formatter and display back on UI as 
Rust enum.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149213

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/test/API/lang/rust/enum-structs/TestEnumStructsGenerated.py
  lldb/test/API/lang/rust/enum-structs/main.rs
  lldb/test/API/lang/rust/enum-structs/main.yaml

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


[Lldb-commits] [lldb] f8d6542 - [lldb/test] Fix test failure from missing decorator

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T16:08:55-07:00
New Revision: f8d6542e873be7821636fd5ae313e8249c235438

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

LOG: [lldb/test] Fix test failure from missing decorator

This should fix a test failure in TestInteractiveScriptedProcess.py
caused by a missing decorator added in d0d902d.

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 

lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
index 7a0d2f2d817e..807fcd76fd54 100644
--- 
a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
+++ 
b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
@@ -4,6 +4,7 @@
 
 import lldb
 import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 import json, os
 



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


[Lldb-commits] [PATCH] D149214: [lldb] Speed up DebugAbbrev parsing

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: aprantl, JDevlieghere.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

While measuring some performance in LLDB I noticed that we were
spending a decent amount of time parsing the debug abbrev section.

There are 2 very easy ways to improve speed here:

- Move DWARFAbbreviationDeclarationSets into the the DWARFDebugAbbrev map
- Use an `llvm::SmallVector` instead of a `std::vector` for 
DWARFAbbreviationDeclaration's m_attributes field. These things hardly ever 
have more than 10-11 attributes, so SmallVector seems like a better fit.

To measure performance impact, I took a project with 10,000 c++ source
files, built objects out of them all, and linked them into one binary.
Then I loaded it into lldb, placed a breakpoint on `main`, and then
exited.

Without this patch, it took about 5.2 seconds on my machine. With this
patch, it took about 4.9 seconds, so this shaves off about 300ms of
time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149214

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -112,7 +112,7 @@
 if (error)
   return error;
 
-m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
+m_abbrevCollMap[initial_cu_offset] = std::move(abbrevDeclSet);
   }
   m_prev_abbr_offset_pos = m_abbrevCollMap.end();
   return llvm::ErrorSuccess();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -58,7 +58,7 @@
   dw_uleb128_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
+  llvm::SmallVector m_attributes;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -112,7 +112,7 @@
 if (error)
   return error;
 
-m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
+m_abbrevCollMap[initial_cu_offset] = std::move(abbrevDeclSet);
   }
   m_prev_abbr_offset_pos = m_abbrevCollMap.end();
   return llvm::ErrorSuccess();
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
@@ -58,7 +58,7 @@
   dw_uleb128_t m_code = InvalidCode;
   dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
   uint8_t m_has_children = 0;
-  DWARFAttribute::collection m_attributes;
+  llvm::SmallVector m_attributes;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149111: [lldb] Add support for specifying language when setting watchpoint by expression

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib accepted this revision.
mib added a comment.
This revision is now accepted and ready to land.

In D149111#4296709 , @bulbazord wrote:

> In D149111#4296670 , @mib wrote:
>
>> I think we should still be able to use this new flag with the previous ones 
>> (i.e. `watchpoint set -l c++ -w read -- &my_var`)
>
> You can do that still with this patch. I'm placing the language flag in a 2nd 
> group so that `watchpoint set variable` does not have access to this flag, 
> but `watchpoint set expression` does. You can still mix and match the flags 
> for `expression`.

Thanks for clarifying that. LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149111

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


[Lldb-commits] [lldb] fc28560 - [lldb][NFCI] Remove unused swig macros

2023-04-25 Thread Alex Langford via lldb-commits

Author: Alex Langford
Date: 2023-04-25T16:47:00-07:00
New Revision: fc28560fd675a93f06d73628b469fbe3c6850282

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

LOG: [lldb][NFCI] Remove unused swig macros

These should have been removed in 662548c82683.

Added: 


Modified: 
lldb/bindings/macros.swig

Removed: 




diff  --git a/lldb/bindings/macros.swig b/lldb/bindings/macros.swig
index eee504cb2e6f4..cb013daa158d9 100644
--- a/lldb/bindings/macros.swig
+++ b/lldb/bindings/macros.swig
@@ -1,18 +1,3 @@
-%define STRING_EXTENSION_LEVEL(Class, Level)
-%extend {
-  std::string lldb:: ## Class ## ::__repr__(){
-lldb::SBStream stream;
-$self->GetDescription (stream, Level);
-const char *desc = stream.GetData();
-size_t desc_len = stream.GetSize();
-if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == 
'\r')) {
-  --desc_len;
-}
-return std::string(desc, desc_len);
-  }
-}
-%enddef
-
 %define STRING_EXTENSION_LEVEL_OUTSIDE(Class, Level)
 %extend lldb:: ## Class ## {
   std::string __repr__(){
@@ -28,25 +13,6 @@
 }
 %enddef
 
-%define STRING_EXTENSION(Class)
-%extend {
-  std::string lldb:: ## Class ## ::__repr__(){
-lldb::SBStream stream;
-$self->GetDescription (stream);
-const char *desc = stream.GetData();
-size_t desc_len = stream.GetSize();
-if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == 
'\r')) {
-  --desc_len;
-}
-return std::string(desc, desc_len);
-  }
-}
-%enddef
-
-// NOTE:
-// This is for when you are peforming the extension from outside of the class
-// instead of inside of it. If this change works out, it will replace
-// STRING_EXTENSION entirely.
 %define STRING_EXTENSION_OUTSIDE(Class)
 %extend lldb:: ## Class ## {
   std::string __repr__(){



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


[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Douglas Yung via Phabricator via lldb-commits
dyung added a comment.

Hi @mib, your change is causing a build failure on two build bots, can you take 
a look and revert if you need time to investigate?

https://lab.llvm.org/buildbot/#/builders/217/builds/20430
https://lab.llvm.org/buildbot/#/builders/243/builds/5438


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

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


[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D145295#4297312 , @dyung wrote:

> Hi @mib, your change is causing a build failure on two build bots, can you 
> take a look and revert if you need time to investigate?
>
> https://lab.llvm.org/buildbot/#/builders/217/builds/20430
> https://lab.llvm.org/buildbot/#/builders/243/builds/5438

Yep, I have a fix already. I'll push it in a few minutes. Thanks for the 
follow-up @dyung.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

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


[Lldb-commits] [PATCH] D149218: [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib created this revision.
mib added a reviewer: bulbazord.
mib added a project: LLDB.
Herald added a subscriber: JDevlieghere.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

In 6c961ae 
, I've 
introduced a new explicit full specialized templated method
`ScriptedPythonInterface::ReverseTransform(bool&, PythonObject, Status&)`.

However, that explicit specialization is causing GCC to choke when
building the file as shown here:

https://lab.llvm.org/buildbot/#/builders/217/builds/20430

To address that issue, this patch turns the method explicit specialization
into an method overload.

Signed-off-by: Med Ismail Bennani 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149218

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -146,7 +146,7 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
-  template <>
+
   void ReverseTransform(bool &original_arg,
 python::PythonObject transformed_arg, Status &error) {
 python::PythonBoolean boolean_arg = python::PythonBoolean(


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -146,7 +146,7 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
-  template <>
+
   void ReverseTransform(bool &original_arg,
 python::PythonObject transformed_arg, Status &error) {
 python::PythonBoolean boolean_arg = python::PythonBoolean(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149218: [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

2023-04-25 Thread Alex Langford via Phabricator via lldb-commits
bulbazord accepted this revision.
bulbazord added a comment.
This revision is now accepted and ready to land.

Unfortunate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149218

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


[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

In D145295#4297322 , @mib wrote:

> In D145295#4297312 , @dyung wrote:
>
>> Hi @mib, your change is causing a build failure on two build bots, can you 
>> take a look and revert if you need time to investigate?
>>
>> https://lab.llvm.org/buildbot/#/builders/217/builds/20430
>> https://lab.llvm.org/buildbot/#/builders/243/builds/5438
>
> Yep, I have a fix already. I'll push it in a few minutes. Thanks for the 
> follow-up @dyung.

@dyung D149218  should fix the build failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

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


[Lldb-commits] [lldb] da07008 - [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T17:26:45-07:00
New Revision: da0700829f163ad5d8bbd61aa137e586a816e06e

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

LOG: [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

In 6c961ae, I've introduced a new explicit fully specialized templated method
`ScriptedPythonInterface::ReverseTransform(bool&, PythonObject, Status&)`.

However, that explicit specialization is causing GCC to choke when
building the file as shown here:

https://lab.llvm.org/buildbot/#/builders/217/builds/20430

To address that issue, this patch turns the method explicit specialization
into an method overload.

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

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h

Removed: 




diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
index 2a8ca262b91d..04e265159e43 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -146,7 +146,7 @@ class ScriptedPythonInterface : virtual public 
ScriptedInterface {
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
-  template <>
+
   void ReverseTransform(bool &original_arg,
 python::PythonObject transformed_arg, Status &error) {
 python::PythonBoolean boolean_arg = python::PythonBoolean(



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


[Lldb-commits] [PATCH] D149218: [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

2023-04-25 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 rGda0700829f16: [lldb] Fix another GCC build failure in 
ScriptedPythonInterface.h (authored by mib).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149218

Files:
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -146,7 +146,7 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
-  template <>
+
   void ReverseTransform(bool &original_arg,
 python::PythonObject transformed_arg, Status &error) {
 python::PythonBoolean boolean_arg = python::PythonBoolean(


Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
===
--- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -146,7 +146,7 @@
 original_arg = ExtractValueFromPythonObject(transformed_arg, error);
   }
 
-  template <>
+
   void ReverseTransform(bool &original_arg,
 python::PythonObject transformed_arg, Status &error) {
 python::PythonBoolean boolean_arg = python::PythonBoolean(
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D149218: [lldb] Fix another GCC build failure in ScriptedPythonInterface.h

2023-04-25 Thread Med Ismail Bennani via Phabricator via lldb-commits
mib added a comment.

Fixed the problem: https://lab.llvm.org/buildbot/#/builders/217/builds/20435


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149218

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


[Lldb-commits] [PATCH] D145295: [lldb] Move ScriptedProcess private state update to implementation

2023-04-25 Thread Douglas Yung via Phabricator via lldb-commits
dyung added a comment.

In D145295#4297347 , @mib wrote:

> In D145295#4297322 , @mib wrote:
>
>> In D145295#4297312 , @dyung wrote:
>>
>>> Hi @mib, your change is causing a build failure on two build bots, can you 
>>> take a look and revert if you need time to investigate?
>>>
>>> https://lab.llvm.org/buildbot/#/builders/217/builds/20430
>>> https://lab.llvm.org/buildbot/#/builders/243/builds/5438
>>
>> Yep, I have a fix already. I'll push it in a few minutes. Thanks for the 
>> follow-up @dyung.
>
> @dyung D149218  should fix the build 
> failure.

It does, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145295

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


[Lldb-commits] [PATCH] D149224: Fix an off-by-one error with armv7 mach-o corefile register contexts (LC_THREADs)

2023-04-25 Thread Jason Molenda via Phabricator via lldb-commits
jasonmolenda created this revision.
jasonmolenda added reviewers: fixathon, JDevlieghere.
jasonmolenda added a project: LLDB.
Herald added subscribers: omjavaid, kristof.beyls.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

Slava was doing some fixups in ObjectFileMachO last August and one of the 
changes had a small off-by-one error, https://reviews.llvm.org/D131554 .  A 
bunch of folks (including myself) looked at this specific bit of code and 
didn't see the issue, and there's no testsuite coverage for it.

This bit of code in 
`RegisterContextDarwin_arm_Mach::SetRegisterDataFrom_LC_THREAD` is reading the 
data for an ARM_THREAD_STATE register context, which has a fixed size for all 
practical purposes here.  (the whole scheme of having ARM_THREAD_STATE + 
ARM_THREAD_STATE_COUNT is to allow for new registers to be added in the future 
and code to be able to detect which version it is based on size -- but I don't 
expect us to add additional register to the armv7 register context as this 
point).

Slava's change added a bounds check to ensure it was non-zero and within the 
max size of the ARM_THREAD_STATE state size.  This bounds check didn't account 
for the cpsr register after the set of general purpose registers, so the 
register context wasn't being loaded from corefiles.  We can simplify this by 
checking for equality for the total number of words for ARM_THREAD_STATE.

I also added a new test case that creates an empty armv7 and arm64 mach-o 
corefile with two register contexts, loads them into lldb and confirms that it 
could retrieve registers from both of the register contexts in both.  I only 
have this test set to build & run on Darwin systems because I use Mach-O 
constants in the utility I wrote to create the nearly-empty corefiles.  Too 
easy to miss a tiny problem like this when there's no test coverage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149224

Files:
  lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
  lldb/test/API/macosx/arm-corefile-regctx/Makefile
  lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py
  lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp

Index: lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
===
--- /dev/null
+++ lldb/test/API/macosx/arm-corefile-regctx/create-arm-corefiles.cpp
@@ -0,0 +1,199 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+union uint32_buf {
+  uint8_t bytebuf[4];
+  uint32_t val;
+};
+
+union uint64_buf {
+  uint8_t bytebuf[8];
+  uint64_t val;
+};
+
+void add_uint64(std::vector &buf, uint64_t val) {
+  uint64_buf conv;
+  conv.val = val;
+  for (int i = 0; i < 8; i++)
+buf.push_back(conv.bytebuf[i]);
+}
+
+void add_uint32(std::vector &buf, uint32_t val) {
+  uint32_buf conv;
+  conv.val = val;
+  for (int i = 0; i < 4; i++)
+buf.push_back(conv.bytebuf[i]);
+}
+
+std::vector armv7_lc_thread_load_command() {
+  std::vector data;
+  add_uint32(data, LC_THREAD);  // thread_command.cmd
+  add_uint32(data, 104);// thread_command.cmdsize
+  add_uint32(data, ARM_THREAD_STATE);   // thread_command.flavor
+  add_uint32(data, ARM_THREAD_STATE_COUNT); // thread_command.count
+  add_uint32(data, 0x0001); // r0
+  add_uint32(data, 0x0002); // r1
+  add_uint32(data, 0x0003); // r2
+  add_uint32(data, 0x0004); // r3
+  add_uint32(data, 0x0005); // r4
+  add_uint32(data, 0x0006); // r5
+  add_uint32(data, 0x0007); // r6
+  add_uint32(data, 0x0008); // r7
+  add_uint32(data, 0x0009); // r8
+  add_uint32(data, 0x000a); // r9
+  add_uint32(data, 0x000b); // r10
+  add_uint32(data, 0x000c); // r11
+  add_uint32(data, 0x000d); // r12
+  add_uint32(data, 0x000e); // sp
+  add_uint32(data, 0x000f); // lr
+  add_uint32(data, 0x0010); // pc
+  add_uint32(data, 0x0011); // cpsr
+
+  add_uint32(data, ARM_EXCEPTION_STATE);   // thread_command.flavor
+  add_uint32(data, ARM_EXCEPTION_STATE_COUNT); // thread_command.count
+  add_uint32(data, 0x3f5c);// far
+  add_uint32(data, 0xf200);// esr
+  add_uint32(data, 0x);// exception
+
+  return data;
+}
+
+std::vector arm64_lc_thread_load_command() {
+  std::vector data;
+  add_uint32(data, LC_THREAD);// thread_command.cmd
+  add_uint32(data, 312);  // thread_command.cmdsize
+  add_uint32(data, ARM_THREAD_STATE64);   // thread_command.flavor
+  add_uint32(data, ARM_THREAD_STATE64_COUNT); // thread_command.count
+  add_uint64(data, 0x0001);   // x0
+  add

[Lldb-commits] [PATCH] D149224: Fix an off-by-one error with armv7 mach-o corefile register contexts (LC_THREADs)

2023-04-25 Thread Slava Gurevich via Phabricator via lldb-commits
fixathon accepted this revision.
fixathon added a comment.
This revision is now accepted and ready to land.

Great catch. Thank you for finding and fixing this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149224

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


[Lldb-commits] [lldb] 7b5bf3a - [lldb] Add entry to code owner

2023-04-25 Thread Med Ismail Bennani via lldb-commits

Author: Med Ismail Bennani
Date: 2023-04-25T23:15:07-07:00
New Revision: 7b5bf3a473ca26e3572f9f88c6e1bc3c85a2138c

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

LOG: [lldb] Add entry to code owner

Signed-off-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/CODE_OWNERS.txt

Removed: 




diff  --git a/lldb/CODE_OWNERS.txt b/lldb/CODE_OWNERS.txt
index ae679e90d924..c62c5ade7634 100644
--- a/lldb/CODE_OWNERS.txt
+++ b/lldb/CODE_OWNERS.txt
@@ -18,8 +18,7 @@ N: Jim Ingham
 E: jing...@apple.com
 D: Overall LLDB architecture, Thread plans, Expression parser, ValueObject, 
Breakpoints, ABI
 D: Watchpoints, Trampolines, Target, Command Interpreter, C++ / Objective-C 
Language runtime
-D: Expression evaluator, IR interpreter, Clang integration
-D: Data Formatters
+D: Expression evaluator, IR interpreter, Clang integration, Data Formatters
 
 N: Ed Maste
 E: ema...@freebsd.org
@@ -47,3 +46,9 @@ N: Walter Erquinigo
 E: a20012...@gmail.com
 E: walterme...@fb.com
 D: Trace, TraceCursor, TraceExport, intel-pt, lldb-vscode, Data Formatters
+
+N: Med Ismail Bennani
+E: ism...@bennani.ma
+E: m@apple.com
+D: Breakpoints, Target, General Process Execution, Command Interpreter
+D: Script Interpreter, API, Data Formatters, CrashLog, Scripted Process



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