diff options
author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-04-25 15:03:15 -0700 |
---|---|---|
committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2023-04-25 15:03:15 -0700 |
commit | e31d0c20e411f22a943f1ed5f8b618c529436c59 (patch) | |
tree | b3f50b582688a02c9de511d3bc0482538de8c948 /lldb/test | |
parent | 6cf668016efde05db8c9f179843ec457ad017ff7 (diff) | |
download | llvm-e31d0c20e411f22a943f1ed5f8b618c529436c59.tar.gz |
[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 <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/test')
2 files changed, 82 insertions, 2 deletions
diff --git a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py index a413317be867..dac05b0f70d2 100644 --- a/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py +++ b/lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py @@ -107,7 +107,7 @@ class TestInteractiveScriptedProcess(TestBase): self.assertEqual(real_pc, mux_pc, f"PC's equal for {id}") lldbutil.run_break_set_by_source_regexp(self, "also break here") - self.assertEqual(mux_target.GetNumBreakpoints(), 1) + self.assertEqual(mux_target.GetNumBreakpoints(), 2) error = mux_process.Continue() self.assertSuccess(error, "Resuming multiplexer scripted process") self.assertTrue(mux_process.IsValid(), "Got a valid process") diff --git a/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py b/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py index 1f61afab5c4a..c97909906679 100644 --- a/lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py +++ b/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 @@ class MultiplexedScriptedProcess(PassthruScriptedProcess): ) ) + 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 @@ class MultiplexerScriptedProcess(PassthruScriptedProcess): ) 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 @@ class MultiplexerScriptedProcess(PassthruScriptedProcess): parity = pid % 2 return dict(filter(lambda pair: pair[0] % 2 == parity, self.threads.items())) + def create_breakpoint(self, addr, error, pid=None): + if not self.driving_target: + error.SetErrorString("%s has no driving target." % self.__class__.__name__) + return False + + def create_breakpoint_with_name(target, load_addr, name, error): + addr = lldb.SBAddress(load_addr, target) + if not addr.IsValid(): + error.SetErrorString("Invalid breakpoint address %s" % hex(load_addr)) + return False + bkpt = target.BreakpointCreateBySBAddress(addr) + if not bkpt.IsValid(): + error.SetErrorString( + "Failed to create breakpoint at address %s" + % hex(addr.GetLoadAddress()) + ) + return False + error = bkpt.AddNameWithErrorHandling(name) + return error.Success() + + name = ( + "multiplexer_scripted_process" + if not pid + else f"multiplexed_scripted_process_{pid}" + ) + + if pid is not None: + # This means that this method has been called from one of the + # multiplexed scripted process. That also means that the multiplexer + # target doesn't have this breakpoint created. + mux_error = lldb.SBError() + bkpt = create_breakpoint_with_name(self.target, addr, name, mux_error) + if mux_error.Fail(): + error.SetError( + "Failed to create breakpoint in multiplexer \ + target: %s" + % mux_error.GetCString() + ) + return False + return create_breakpoint_with_name(self.driving_target, addr, name, error) + def multiplex(mux_process, muxed_process): muxed_process.GetScriptedImplementation().multiplexer = ( |