File: strings.lua

package info (click to toggle)
uftrace 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 5,212 kB
  • sloc: ansic: 53,313; python: 9,846; makefile: 838; asm: 703; cpp: 602; sh: 560; javascript: 191
file content (41 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--
-- strings.lua - print the unique strings of runtime function arguments and return values.
--
-- uftrace-option: --nest-libcall --auto-args
--

local strset = {}

function uftrace_entry(ctx)
    if ctx['args'] ~= nil then
        for i, arg in ipairs(ctx['args']) do
            if type(arg) == 'string' then
                arg = string.gsub(arg, '^%s+', '')
                arg = string.gsub(arg, '%s+$', '')
                if arg ~= '' and arg:sub(1, 8) ~= 'struct: ' then
                    strset[arg] = true
                end
            end
        end
    end
end

function uftrace_exit(ctx)
    if ctx['retval'] ~= nil then
        local ret = ctx['retval']
        if type(ctx['retval']) == 'string' then
            ret = string.gsub(ret, '^%s+', '')
            ret = string.gsub(ret, '%s+$', '')
            if ret ~= '' and ret:sub(1, 8) ~= 'struct: ' then
                strset[ret] = true
            end
        end
    end
end

function uftrace_end()
    for strval, _ in pairs(strset) do
        print('"' .. strval .. '"')
        print("---")
    end
end