This past few weeks I’ve been working on an Infinity client library. This is what GDB will use to execute notes it finds. It’s early days, but it executed its first note this morning so I thought I’d put something together so people can see what I’m doing. Here’s how to try it out:
- Install elfutils libelf development stuff if you don’t have it already, the
tlsdump
example program needs it:sudo yum install elfutils-libelf-devel # Fedora, RHEL, etc... sudo apt-get install libelf-dev # Debian, Ubuntu, etc...
- Download and build the Infinity client library and example program:
git clone -b libi8x-0.0.1 https://github.com/gbenson/libi8x.git libi8x-0.0.1 cd libi8x-0.0.1 ./autogen.sh ./configure --enable-logging --enable-debug make
- Check the
tlsdump
example program built:bash$ ls -l examples/tlsdump -rwxr-xr-x. 1 gary gary 5540 Apr 20 12:52 examples/tlsdump
Yeah, there it is! (if it’s not there go back to step 0)
- Build a program with notes to run the example program against:
gcc -o tests/ifact tests/ifact.S tests/main.c
- Run the program you just built:
bash$ tests/ifact & [2] 8301 Hello world I'm 8301
- Run the libi8x
tlsdump
example program with the test program’s PID as it’s argument:$ examples/tlsdump 8301 0! = 1 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 6! = 720 7! = 5040 8! = 40320 9! = 362880 10! = 3628800 11! = 39916800 12! = 479001600
What just happened? The executable test/ifact
you built contains a single Infinity note, test::factorial(i)i
, the source for which is in tests/ifact.i8
. The tlsdump
example located the ifact
executable, loaded test::factorial(i)i
from it, and ran it a few times printing the result:
err = i8x_ctx_get_funcref (ctx, "test", "factorial", "i", "i", &fr); if (err != I8X_OK) error_i8x (ctx, err); err = i8x_xctx_new (ctx, 512, &xctx); if (err != I8X_OK) error_i8x (ctx, err); for (int i = 0; i < 13; i++) { union i8x_value args[1], rets[1]; args[0].i = i; err = i8x_xctx_call (xctx, fr, NULL, args, rets); if (err != I8X_OK) error_i8x (ctx, err); printf ("%d! = %d\n", i, rets[0].i); }
To see some debug output try this:
I8X_LOG=debug examples/tlsdump PID
Also try I8X_DEBUG=true
in addition to I8X_LOG=debug
to trace the bytecode as it executes.