[Lldb-commits] [PATCH] D144688: [lldb] Fix {break, watch}point command function stopping behavior

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 24 15:44:14 PST 2023


bulbazord added inline comments.


================
Comment at: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:1314-1324
+    if (line.startswith("return ")) {
+      llvm::StringRef return_val =
+          line.substr(llvm::StringRef("return ").size());
+      sstr.Printf("      __return_val = %s", return_val.data());
+    } else {
+      sstr.Printf("      %s", line.data());
+    }
----------------
bulbazord wrote:
> I feel like this is subtly wrong. For example, given the user provided function:
> ```
> def func(frame, bp_loc, internal_dict):
>     if frame.name == "main":
>         return True
>     return False
> ```
> 
> This will be transformed into:
> ```
> def __user_callback():
>     nonlocal __return_val
>     if frame.name == "main":
>         __return_val = True
>     __return_val = False
> ```
> Assume frame.name == "main": In the first one, we will return True. In the second one, `__return_val` will be False. 
> 
> Maybe we can insert the input into `__user_callback` as-is and do `__return_val = __user_callback()`?
To be clear, I think this will work with `-F` because there's just one `return` statement inserted a few frames up.

This also may fail with `-o` if you concatenate multiple lines in one. For example, `-o "print('foo'); return frame.name == 'main'"`. This is one line, so we'll never set `__return_val` to `frame.name == 'main'`. You might need to do further processing on the input to break it into multiple lines.


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

https://reviews.llvm.org/D144688



More information about the lldb-commits mailing list