This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Lua] add support for Lua function breakpoint
ClosedPublic

Authored by tammela on Dec 21 2020, 10:13 AM.

Details

Summary

Adds support for running a Lua function when a breakpoint is hit.

Example:

breakpoint command add -s lua -F abc

The above runs the Lua function 'abc' passing 2 arguments. 'frame', 'bp_loc' and 'extra_args'.

A third parameter 'extra_args' is only present when there is structured data
declared in the command line.

Example:

breakpoint command add -s lua -F abc -k foo -v bar

Diff Detail

Event Timeline

tammela requested review of this revision.Dec 21 2020, 10:13 AM
tammela created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2020, 10:13 AM
JDevlieghere added inline comments.Jan 5 2021, 10:04 AM
lldb/bindings/lua/lua-wrapper.swig
25–29

I don't think you need the lambda. I used unique_ptr but llvm:Optional would work as well.

lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test
16

Can we unpack the SBStructuredData and check for foo or 123 in the output?

tammela added inline comments.Jan 9 2021, 10:44 AM
lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test
16

While I was doing this change, I noted that the SBStructuredData API for GetStringValue is quite odd.
For Lua, the auto-generated SWIG wrapper enforces code like this:

local result = "xxxx"
sd:GetStringValue(result, 3) -- 'sd' should be a value with at most 3 characters

This sort of API leaks all sorts of details to the Lua script. I think it could be improved to just return a std::string / llvm::StringRef object.

The SWIG wrapper also has some bugs for this class. For instance it's using lua_pushnumber where it should be lua_pushinteger for the GetIntegerValue method.

I will report this to the SWIG authors.

tammela updated this revision to Diff 317395.Jan 18 2021, 11:19 AM

Addressing comment

tammela added inline comments.Jan 18 2021, 11:20 AM
lldb/bindings/lua/lua-wrapper.swig
25–29

{} is not valid on the ternary operator, but I think the version suits your suggestion.

tammela updated this revision to Diff 318775.Jan 23 2021, 10:47 AM

Rebasing and unwrapping the SBStructuredData test case

@JDevlieghere Addressed all your comments.

JDevlieghere accepted this revision.Jan 25 2021, 1:58 PM

LGTM

lldb/test/Shell/ScriptInterpreter/Lua/breakpoint_function_callback.test
16

I still think this is important. Can you add a FIXME so we remember update this in the future?

This revision is now accepted and ready to land.Jan 25 2021, 1:58 PM
This revision was landed with ongoing or failed builds.Jan 25 2021, 3:41 PM
This revision was automatically updated to reflect the committed changes.