This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add an example of interactive scripted process debugging
ClosedPublic

Authored by mib on Mar 3 2023, 9:45 PM.

Details

Summary

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.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Mar 3 2023, 9:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2023, 9:45 PM
mib requested review of this revision.Mar 3 2023, 9:45 PM

This depends on D145294, D145295 & D145296 so make sure you take a look at those diffs :)

mib updated this revision to Diff 513817.EditedApr 14 2023, 5:14 PM
mib retitled this revision from [lldb] Add an example of interactive scripted process debugging (NFC) to [lldb] Add an example of interactive scripted process debugging.
mib edited the summary of this revision. (Show Details)

Many changes:

  • Fixed many bugs
  • Added test case
mib updated this revision to Diff 513818.Apr 14 2023, 5:16 PM

A few high-level comments:

  • You're doing a lot of type-annotations in python which is good, but you're not being very consistent about it. It would be tremendously helpful if you could add type annotations everywhere.
  • I would recommend using f-strings over % and .format for string interpolation. They are available as of python 3.6 and the minimum version to use lit is 3.6 (if LLVM's CMakeLists.txt is to be believed).
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
3

nit

9

nit: import json

55
61–62

Remove these log lines, I don't think they're needed for the test.

90

Defaults to 0 if you don't specify a start.

103–104

Did you mean to get info from the mux_process_listener twice? Was one of these supposed to be for the real process?

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

nit: import these all on different lines

75–90

Some functions have their parameter types and return types annotated but others don't. Can you add all the annotations to be consistent?

90
133
166
169
205
210
224
248
254
270

f-string this

274

f-string this

311

f-string

345–351

This function is a little confusing to me. Why does default_val only apply if the data is valid? Why not return the default_val when it's invalid?

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

nit: constexpr

28
mib marked 23 inline comments as done.Apr 20 2023, 3:23 PM
mib added inline comments.
lldb/test/API/functionalities/interactive_scripted_process/TestInteractiveScriptedProcess.py
103–104

We're only listening to the mux_process events so this is how its supposed to be.

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

why :p ?

mib updated this revision to Diff 515505.Apr 20 2023, 3:24 PM
mib marked 2 inline comments as done.

Address @bulbazord comments:

  • f-string everything
  • remove logs
  • add type annotations
mib updated this revision to Diff 515523.Apr 20 2023, 4:20 PM

Fix typo in one of the type annotation

mib updated this revision to Diff 515529.Apr 20 2023, 4:42 PM

More f-string

Looks good to me. Might want to let @jingham or @JDevlieghere give it a look-over though.

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

I don't actually think it matters a ton, which is why it was a nit, but I think there's something to be said for consistency with the rest of lldb.

JDevlieghere added inline comments.Apr 21 2023, 12:52 PM
lldb/test/API/functionalities/interactive_scripted_process/interactive_scripted_process.py
10

Given the discussion in https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style, let's format new tests with black. It doesn't look like the tool has a preference between those two so I would vote for consistency.

mib updated this revision to Diff 515899.Apr 21 2023, 1:35 PM
mib marked 2 inline comments as done.

Re-format python code with black

JDevlieghere accepted this revision.Apr 21 2023, 2:10 PM
This revision is now accepted and ready to land.Apr 21 2023, 2:10 PM