All Projects → cloudflare → Loom

cloudflare / Loom

Licence: mit
Easier to read LuaJIT dumps

Programming Languages

lua
6591 projects
bytecode
52 projects

Projects that are alternatives of or similar to Loom

Frodo
Android Library for Logging RxJava Observables and Subscribers.
Stars: ✭ 1,496 (+984.06%)
Mutual labels:  debugging
Ndb
ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools
Stars: ✭ 10,581 (+7567.39%)
Mutual labels:  debugging
Shadows
Shädows - A Shadows & Lights engine for löve
Stars: ✭ 134 (-2.9%)
Mutual labels:  luajit
Remix Ide
Documentation for Remix IDE
Stars: ✭ 1,768 (+1181.16%)
Mutual labels:  debugging
Luafun
Lua Fun is a high-performance functional programming library for Lua designed with LuaJIT's trace compiler in mind.
Stars: ✭ 1,654 (+1098.55%)
Mutual labels:  luajit
Rexbug
A thin Elixir wrapper for the redbug Erlang tracing debugger.
Stars: ✭ 126 (-8.7%)
Mutual labels:  debugging
Lua Resty Http
Lua HTTP client cosocket driver for OpenResty / ngx_lua.
Stars: ✭ 1,647 (+1093.48%)
Mutual labels:  luajit
Gdb Frontend
☕ GDBFrontend is an easy, flexible and extensionable gui debugger.
Stars: ✭ 2,104 (+1424.64%)
Mutual labels:  debugging
Dbg Macro
A dbg(…) macro for C++
Stars: ✭ 1,825 (+1222.46%)
Mutual labels:  debugging
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-4.35%)
Mutual labels:  debugging
Bsodsurvivor
This project aims to facilitate debugging a kernel driver in windows by adding support for a code change on the fly without reboot/unload, and more!
Stars: ✭ 122 (-11.59%)
Mutual labels:  debugging
Iopipe Js Core
Observe and develop serverless apps with confidence on AWS Lambda with Tracing, Metrics, Profiling, Monitoring, and more.
Stars: ✭ 123 (-10.87%)
Mutual labels:  debugging
Api Umbrella
Open source API management platform
Stars: ✭ 1,735 (+1157.25%)
Mutual labels:  luajit
Luakit
Fast, small, webkit based browser framework extensible by Lua.
Stars: ✭ 1,640 (+1088.41%)
Mutual labels:  luajit
Cargo Flash
a cargo extension for programming microcontrollers
Stars: ✭ 134 (-2.9%)
Mutual labels:  debugging
Motan Openresty
A cross-language RPC framework for rapid development of high performance distributed services based on OpenResty.
Stars: ✭ 117 (-15.22%)
Mutual labels:  luajit
Asm
Assembly Tutorial for DOS
Stars: ✭ 125 (-9.42%)
Mutual labels:  debugging
Rogcat
A `adb logcat` wrapper
Stars: ✭ 137 (-0.72%)
Mutual labels:  debugging
Pdt
PHP Development Tools project (PDT)
Stars: ✭ 135 (-2.17%)
Mutual labels:  debugging
Androidsnooper
Android library to record the network calls through the interceptor mechanism of the http clients.
Stars: ✭ 132 (-4.35%)
Mutual labels:  debugging

LOOM

It's a replacement / enhancement of the -jdump option included in LuaJIT.

As a command line argument

Just put it in a jit/ directory within package.path or $LUA_PATH, typically '/usr/local/share/luajit-2.1..../jit/'; but it also works in '/usr/local/share/lua/5.1/jit/' or even './jit/'. Then it can be used as an argument to LuaJIT in the form:

-jloom[=<tmpl>[,<out>]]

<tmpl> is a template file (default 'loom.html') and <out> is an output file name (default io.stdout).

Lua API

If you want to report traces on just part of your code, it's better to use it explicitly.

local loom = require 'jit.loom'

As any module, you have to require() it first.

loom.on()

Starts recording all JIT events and traces.

traces, funcs = loom.off()

report = loom.off([f [, ...]])

Stops recording and performs any processing and cross references needed to actually generate a report.

Called without any arguments, returns two Lua tables, one with the processed trace information and a second one with all the functions involved in those traces execution.

The second form is equivalent to

do
    local traces, funcs = loom.off()
    report = f(traces, funcs, ...)
end

That is, both return values (the traces and funcs arrays) are passed to the given function f, together with any extra argument, and returns any return value(s) of f.

loom.start(tmpl, out)

Implements the -jloom[=tmpl[,out]] option. The tmpl argument is passed to loom.template() to create a reporting function. If omitted, defaults to 'loom.html'. The out parameter is either a writeable open file or a file name where the report is written into (after formatting by the template), defaults to io.stdout. When the Lua VM is terminated normally, loom.off() is called with the reporting function created by the given template.,

Utility Functions

There are some functions included in the loom package to help formatting a report.

f = loom.template(tmpl)

The string tmpl is a report template using the template syntax described below. If it doesn't contain any line break, is interpreted as a pathname to read the template from a text file.

The template is compiled into a Lua function that takes some arguments (named with {@ name ...} tags) and outputs the result as a string.

loom.annotated(funcs, traces)

Returns an annotated listing of the source code of the given funcs and traces arrays.

loom.allipairs(t)

Like ipairs(t), but stops at table.maxn(t) instead of the first nil value.

loom.sortedpairs(t)

Returns an iterator that visits the same pairs as pairs(t), but sorted by keys.

Template syntax

The included template implementation is based on Danila Poyarkov's lua-template, with a syntax more like Django's or Handlebar's, to make it more friendly to editors that help with HTML content.

{% lua code %}

Embeds any Lua code

{{ expression }}

Outputs the result of the Lua expression, with the &, ", < and > characters escaped.

{{= expression }}

Outputs the result of the Lua expression verbatim, without any character escaping.

{{: 'fmt', args, ... }}

Outputs the result of string.format(fmt, args, ...) without any escaping.

{@ name ... }

Defines template argument names. Each name must be a valid Lua variable name (that is, a sequence of letters, numbers or underscores not beginning with a number), separated by commas or spaces (or any non-alfanumeric-underscore character).

Included Template

The included loom.html template renders the trace report as an HTML document. It's divided in two sections: a Sourcecode -> Bytecode -> Traces one, and a list of traces, with the Bytecode -> IR -> mcode progression for each one.

1.- Source list

For each function that appears in the traces, the source code is shown on the left column (if the source was in a file) and the bytecode at right of it with a random background color (a different one for each function).

The bytecode is shown in the order it appears in memory, so some source lines are in a different order as in the original source or repeated, for example the opening of a for loop appears again (in a lighter gray) in the bottom of the loop.

At the right of the bytecode, there are links of the form <tr>/<seq>, showing some trace executed it at some sequential number. For example 3/4 means it's the fourth bytecode executed by trace #3. A single bytecode can appear several times in the same trace (for example, when unrolling a loop). Each trace have assigned a random background color.

Trace start and abort events are also marked to the right of the relevant bytecode, with [n=xx] notes telling how many times they happened until the trace gets compiled or blacklisted.

2.- Trace list

Each trace gets a three-column table framed on the same color as the respective links in the previous section.

The first column lists the bytecode in the order it was executed. On the left there are links that go back to the same bytecode on the previous section. The bytecodes keep the same background colour of the function. Clicking on the column title toggles source code annotations.

The second column lists the IR code generated by the trace. While the total semantics is supposed to be maintained, there's no direct correspondence between IR and bytecode instructions. For example, as much code as possible is moved before the start of an inner loop, and compilable library functions are just checked (to assure they're the right functions) and IR code is emitted instead of a call to the function.

Snapshot points are inserted in the IR code, but the snapshot content isn't shown by default. To see them, either hover the mouse over the snapshot or click in the column title to reveal all at the same time.

The third column is the generated mcode that is natively executed by the processor. Exit points are labelled by the snapshot number or a trace number if a later trace patched itself in.

Examples

The 'sample.lua' file includes some small code snippets to play with. For example, the comments about -jv option show:

luajit -jv -e "for i=1,1000 do for j=1,1000 do end end"

To output just two lines (one per trace). Changing to -jdump results in:

---- TRACE 1 start (command line):1
0009  FORL     4 => 0009
---- TRACE 1 IR
0001    int SLOAD  #5    CI
0002  + int ADD    0001  +1
0003 >  int LE     0002  +1000
0004 ------ LOOP ------------
0005  + int ADD    0002  +1
0006 >  int LE     0005  +1000
0007    int PHI    0002  0005
---- TRACE 1 mcode 47
0bcbffd1  mov dword [0x41a94410], 0x1
0bcbffdc  cvttsd2si ebp, [rdx+0x20]
0bcbffe1  add ebp, +0x01
0bcbffe4  cmp ebp, 0x3e8
0bcbffea  jg 0x0bcb0014	->1
->LOOP:
0bcbfff0  add ebp, +0x01
0bcbfff3  cmp ebp, 0x3e8
0bcbfff9  jle 0x0bcbfff0	->LOOP
0bcbfffb  jmp 0x0bcb001c	->3
---- TRACE 1 stop -> loop

---- TRACE 2 start 1/3 (command line):1
0010  FORL     0 => 0005
0005  KSHORT   4   1
0006  KSHORT   5 1000
0007  KSHORT   6   1
0008  JFORI    4 => 0010
---- TRACE 2 IR
0001    num SLOAD  #1    I
0002    num ADD    0001  +1
0003 >  num LE     0002  +1000
---- TRACE 2 mcode 81
0bcbff79  mov dword [0x41a94410], 0x2
0bcbff84  movsd xmm6, [0x403382b8]
0bcbff8d  movsd xmm5, [0x403382c8]
0bcbff96  movsd xmm7, [rdx]
0bcbff9a  addsd xmm7, xmm6
0bcbff9e  ucomisd xmm5, xmm7
0bcbffa2  jb 0x0bcb0014	->1
0bcbffa8  movsd [rdx+0x38], xmm6
0bcbffad  movsd [rdx+0x30], xmm6
0bcbffb2  movsd [rdx+0x28], xmm5
0bcbffb7  movsd [rdx+0x20], xmm6
0bcbffbc  movsd [rdx+0x18], xmm7
0bcbffc1  movsd [rdx], xmm7
0bcbffc5  jmp 0x0bcbffd1
---- TRACE 2 stop -> 1

To recreate under loom, try:

luajit -jloom -e "require('sample').lulu()" > out.html

And open the resulting out.html with a browser to see the same thing with nice colours and links to help following how the traces flow together.

screenshot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].