Skip to content
This repository

Scripting other people's programs.

branch: master
Octocat-spinner-32 examples added connect as call that can be instrumented March 19, 2011
Octocat-spinner-32 lua-5.1.4 Trying to make a build that works in multiple places. November 12, 2010
Octocat-spinner-32 .gitignore Rudimentary configure script. December 06, 2010
Octocat-spinner-32 Makefile.in Don't make the lua binaries. December 07, 2010
Octocat-spinner-32 README.markdown README.markdown doesn't support wiki image tags. November 22, 2010
Octocat-spinner-32 buildfunctions.h Generate all the wrapper functions. November 19, 2010
Octocat-spinner-32 calls.defs added connect as call that can be instrumented March 19, 2011
Octocat-spinner-32 configure Hacked up a make install. December 06, 2010
Octocat-spinner-32 definecalls.h Generating more call mappings. November 18, 2010
Octocat-spinner-32 gen_invoker.hh More arounder. November 18, 2010
Octocat-spinner-32 init.lua Make the list of hook points available to the user. December 08, 2010
Octocat-spinner-32 labrea Better usage command. December 07, 2010
Octocat-spinner-32 labrea.cc Added function_cast. November 29, 2010
Octocat-spinner-32 labrea.h Use custom allocation routines for lua state. November 20, 2010
Octocat-spinner-32 labrea.spec Install examples. December 07, 2010
Octocat-spinner-32 labreatypes.h Added function_cast. November 29, 2010
Octocat-spinner-32 locks.hh Fixed some compiler warnings. November 29, 2010
Octocat-spinner-32 mkcallfuns.py Implemented listen() November 22, 2010
Octocat-spinner-32 mkgeninvoker.py Added function_cast. November 29, 2010
Octocat-spinner-32 mkwrapfuns.py Added function_cast. November 29, 2010
Octocat-spinner-32 script_state.hh Hold the lua mutex while running any script. November 27, 2010
Octocat-spinner-32 scripting.cc Special case usleep when < 1 December 09, 2010
Octocat-spinner-32 scripting.hh Initialize pthread keys before trying to use them. November 27, 2010
README.markdown

OPP Scripting

Hackitecture

La Brea allows you to inject scripts into an existing application without recompiling.

Initially, this was built to slow down specific parts of an application programatically. It's great for simulating a slow network, disk, or other types of things within a process.

Implemented Injection Points

The following patterns are available for injection:

before_fname

Invoked before the function fname is called. The arguments to be given to fname are provided.

These functions should not return values.

after_fname

Invoked after the function fname has completed. Both the return value and the original arguments are provided (in that order). This is invoked before returning control back to the application, but you have little opportuntity to do anything particularly destructive here.

These functions should not return values.

around_fname

Invoked instead of fname. This allows for ridiculous magic. Since it's a bit complex, I'll cover it in more detail here.

First, the arguments are as follows:

  1. A reference to the original function.
  2. Any additional arguments required by that function.

The original function can be invoked using the invoke function in lua and that function can pass along whatever parameters may be interesting. For example, if you'd like to truncate all reads so that the application never reads more than 64 bytes, you can do the following:

function around_read(f, d, buf, size)
    if size > 64 then
        size = 64
    end
    return labrea.invoke(f, d, buf, size)
end

Alternatively, you can just cause an error as shown in the random errors example.

Usage

First, write a script to slow stuff down. For example, if you'd like to slow random seeks down, you can create a script that looks like the following:

function before_lseek(fd, offset, whence)
   if math.random(1, 100) == 13 then
      io.write(string.format("Slowing down a seek on fd=%d to %d (%d)\n",
                             fd, offset, whence))
      labrea.usleep(1000000)
   end
end

Save that in a file, say, /tmp/slowseek.lua and then use the labrea as follows:

labrea /tmp/slowseek.lua myprogram -and -its -arguments
Something went wrong with that request. Please try again.