This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Plugin] Add artificial stackframe loading in ScriptedThread
ClosedPublic

Authored by mib on Feb 9 2022, 4:26 PM.

Details

Summary

This patch adds the ability for ScriptedThread to load artificial stack
frames. To do so, the interpreter instance can create a list that will
contain the frame index and its pc address.

Then, when the Scripted Process plugin stops, it will refresh its
Scripted Threads state by invalidating their register context and load
to list from the interpreter object and reconstruct each frame.

This patch also removes all of the default implementation for
get_stackframes from the derived ScriptedThread classes, and add the
interface code for the Scripted Thread Interface.

rdar://88721095

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

Diff Detail

Event Timeline

mib requested review of this revision.Feb 9 2022, 4:26 PM
mib created this revision.

Some nits. Mostly I think the "idx" field in the frame list is redundant and only allows you to get the order wrong w/o adding useful functionality.

I haven't studied Pavel's changes to the Python lifecycle management yet, so I can't comment on whether that part of the patch is done correctly.

I don't think it's necessary at this point, but at some point you are going to have to make ScriptedStackFrame be a thing or there won't be a natural way to produce variables from the frame. The other way to program it would be to fake a CFA, and then fake memory reads so that the regular Variable printing code will produce the ValueObjectVariable's. I can see that being a useful method in some cases, but super-labor intensive in others...

lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
151

The GetStackFrames call should take a Status parameter, in case it has some good reason why it couldn't fetch the stack frames. It will make debugging these things a lot easier if you can pass the real error back to yourself.

171

As I say below, I don't think the specified frame_idx is necessary. But it's also odd that you initialize it to the total number of frames, then immediately overwrite is with the value from the dictionary. If you don't get a value, you exit from this closure, so this seems wasted work.

172

It seems awkward to have the producer of artificial stack frames number the frames. After all, they are already putting them into an array, and the natural way to do that is in stack frame order. Unless you see some really good use case for putting them in scrambled and using the "idx" key to unscramble them, the redundant idx seems like something you could get wrong w/o adding much value.

286

LoadArtificialStackFrames returns a bool for success/failure. It always bugs me when returns signifying errors get dropped on the floor like this.

lldb/test/API/functionalities/scripted_process/dummy_scripted_process.py
78

newline

mib marked 4 inline comments as done.Feb 9 2022, 6:57 PM
mib added inline comments.
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
151

For now the Scripted{Process,Thread}Interface will log the error to the appropriate channel, but I can see having all the interface methods return an llvm::Expected<T> object with an error message instead. I'll do it in a follow-up patch.

172

Makes sense.

286

Thread::RefreshStateAfterStop doesn't return anything, and the failure case is already handled in LoadArtificialStackFrames by logging an error message in the appropriate channel.

Do you have any other suggestion on how I could improve this ?

mib updated this revision to Diff 407368.Feb 9 2022, 6:58 PM
mib marked 2 inline comments as done.
mib edited the summary of this revision. (Show Details)

Address @jingham's comments

mib updated this revision to Diff 407370.Feb 9 2022, 7:04 PM

Reformat and update error messages.

jingham accepted this revision.Feb 11 2022, 1:48 PM

LGTM

This revision is now accepted and ready to land.Feb 11 2022, 1:48 PM
shafik added a subscriber: shafik.Feb 11 2022, 1:49 PM
shafik added inline comments.
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
159

const

195

const

196

const

286

If we are never going to check the return value, we should not have one, it is meaningless.

This revision was landed with ongoing or failed builds.Feb 16 2022, 11:45 AM
This revision was automatically updated to reflect the committed changes.