In order to run a {break,watch}point command, lldb can resolve to the
script interpreter to run an arbitrary piece of code or call into a
user-provided function. To do so, we will generate a wrapping function,
where we first copy lldb's internal dictionary keys into the
interpreter's global dictionary, copied inline the user code before
resetting the global dictionary to its previous state.
However, {break,watch}point commands can optionally return a value that
would tell lldb whether we should stop or not. This feature was
only implemented for breakpoint commands and since we inlined the user
code directly into the wrapping function, introducing an early return,
that caused lldb to let the interpreter global dictionary tinted with the
internal dictionary keys.
This patch fixes that issue while also adding the stopping behaviour to
watchpoint commands.
To do so, this patch refactors the {break,watch}point command creation
method, to let the lldb wrapper function generator know if the user code is
a function call or a arbitrary expression.
Then the wrapper generator, if the user input was a function call, the
wrapper function will call the user function and save the return value into
a variable. If the user input was an arbitrary expression, the wrapper will
inline it into a nested function, call the nested function and save the
return value into the same variable. After resetting the interpreter global
dictionary to its previous state, the generated wrapper function will return
the varible containing the return value.
rdar://105461140
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
@mib There's a reason I didn't do it this way when I tried to fix this locally.
The python stub function we generate would look something like this with your patch.
with your early return the logic for updating internal_dict and global_dict will not run. I'm not entirely sure what the purpose of this is but if its important then we need to implement this patch another way.
Here's another way we could do it. You could take the patch I originally wrote but change ScriptInterpreterPythonImpl::GenerateFunction(...) to take an additional parameter bool ReturnValue that is false by default. This parameter when true would do the work my patch did to make sure we use the return value from the last user statement evaluated. For the watchpoint evaluation we can pass a true value. For the other cases ReturnValue will be false so there will be no behavior change there.