OpenResty XRay YLua Analyzer

About YLua Analyzer

The YLua parser allows you to write a Lua analyzer using the Lua syntax. Sometimes we want to be able to identify what data is in a Lua table and what the values of the data are. This is where the YLua parser can come in handy.

YLua Analyzer Example

The following example outputs the regular expressions cached in resty.core.regex.

probe process.begin
    local max_output_cnt = 1000
    local regex = package.loaded["resty.core.regex"]
    local regex_match_cache = upval(regex.re_match_compile, "regex_match_cache")

    if regex_match_cache ~= nil then
        local match_regex_cache_count = 0
        for key, _ in pairs(regex_match_cache.key2node) do
            if match_regex_cache_count < max_output_cnt then
                print("match-pattern: ", key)
            end
            match_regex_cache_count = match_regex_cache_count + 1
        end

        print("match_regex_cache_count: ", match_regex_cache_count)
    end

    exit()
end

After executing the tool, we will get the following output:

To the right of the YSQL tab is the Learn YLua shortcut link to the YLua user manual. Users can click on the link for a description of YLua syntax and features.