--- c-repl-0.0.20071223.orig/debian/README +++ c-repl-0.0.20071223/debian/README @@ -0,0 +1,67 @@ +Adapted from the author's homepage, : + +c-repl +====== + +Many programming languages come with a REPL (read-eval-print loop), which +allows you to type in code line by line and see what it does. This is quite +useful for prototyping, experimentation, and debugging code. + +Other programming languages, and especially C, use a "compile-run" model, and +don't provide a REPL. Let's fix that. + +WHAT YOU GET +------------ +This approach is actually more of a read-eval loop, as c-repl doesn't know +anything about the types and parse trees of the code it's running. But unlike +other approaches to solving the "C interpreter" problem, c-repl works directly +with unmodified libraries and system headers. + +This means you can experiment with a new library without writing a test program +or any bindings. Or just use it as a simple calculator, content in knowing it +is much faster than your neighbors using irb, like driving a Ferarri on city +streets. + +EXAMPLE SESSION +--------------- +Here's an example session demonstrating using c-repl: + +% ./repl +> int x = 3 +> int y = 4 +> printf("%d\n", x + y); +7 +> int mystrlen(char *p) { int i; for (i = 0; *p; i++) p++; return i } +: In function 'mystrlen': +:5: error: syntax error before '}' token +> int mystrlen(char *p) { int i; for (i = 0; *p; i++) p++; return i; }; +> x = mystrlen("hello"); +> x +p x +$1 = 5 +> x = mystrlen(NULL); +segfault detected. +resuming. +7 +> x +p x +$1 = 5 + +HOW TO USE IT +------------- +Type in any C code you can imagine, and try .help to learn about the +meta-commands (which bring in other system headers or shared libraries). +Please report bugs as you find them! + +HOW IT WORKS +------------ + +Many of the ideas are due to Satoru Takabayashi, who is responsible for a +prototype implementation and continues to advise. + +The approach is surprisingly simple: for each line of code you enter, we +compile a shared object in the background. If the compilation succeeds, the +object is loaded into a child process via dlopen(). If the child process +segfaults, we know that the code was bad and so we can "rewind" by replaying +all n-1 steps. Printing variables is handled by attaching gdb to the child +process. --- c-repl-0.0.20071223.orig/debian/c-repl.install +++ c-repl-0.0.20071223/debian/c-repl.install @@ -0,0 +1,4 @@ +child usr/lib/c-repl +codesnippet.rb usr/lib/c-repl +gdbmi.rb usr/lib/c-repl +c-repl usr/bin --- c-repl-0.0.20071223.orig/debian/changelog +++ c-repl-0.0.20071223/debian/changelog @@ -0,0 +1,8 @@ +c-repl (0.0.20071223-1) unstable; urgency=low + + * Initial release; closes: #459401. + - Modify upstream repl script to run with helpers in /usr/lib/c-repl. + - Store temporary DSOs in a /tmp directory and delete on exit. + - Rename the 'repl' script to 'c-repl' to match the package name. + + -- Robert S. Edmonds Sun, 06 Jan 2008 02:07:20 -0500 --- c-repl-0.0.20071223.orig/debian/compat +++ c-repl-0.0.20071223/debian/compat @@ -0,0 +1 @@ +5 --- c-repl-0.0.20071223.orig/debian/control +++ c-repl-0.0.20071223/debian/control @@ -0,0 +1,27 @@ +Source: c-repl +Section: interpreters +Priority: extra +Maintainer: Robert S. Edmonds +Build-Depends: debhelper (>= 5), dpatch +Standards-Version: 3.7.3 + +Package: c-repl +Architecture: any +Depends: ${shlibs:Depends}, ruby, libreadline-ruby +Description: read-eval-print loop for C + Many programming languages come with a REPL (read-eval-print loop), which + allows you to type in code line by line and see what it does. This is quite + useful for prototyping, experimentation, and debugging code. + . + Other programming languages, and especially C, use a "compile-run" model, + and don't provide a REPL. Let's fix that. + . + This approach is actually more of a read-eval loop, as c-repl doesn't know + anything about the types and parse trees of the code it's running. But + unlike other approaches to solving the "C interpreter" problem, c-repl + works directly with unmodified libraries and system headers. + . + This means you can experiment with a new library without writing a test + program or any bindings. Or just use it as a simple calculator, content in + knowing it is much faster than your neighbors using irb, like driving a + Ferarri on city streets. --- c-repl-0.0.20071223.orig/debian/copyright +++ c-repl-0.0.20071223/debian/copyright @@ -0,0 +1,37 @@ +This package was debianized by Robert S. Edmonds on +Sat, 22 Dec 2007 22:12:29 -0500. + +It was downloaded from + http://neugierig.org/software/c-repl/ + +Copyright Holder: + Copyright (C) 2007 Evan Martin + +License: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The Debian packaging is (C) 2007, Robert S. Edmonds and +is licensed under the GPL, see `/usr/share/common-licenses/GPL'. --- c-repl-0.0.20071223.orig/debian/dirs +++ c-repl-0.0.20071223/debian/dirs @@ -0,0 +1,2 @@ +usr/bin +usr/lib/c-repl --- c-repl-0.0.20071223.orig/debian/patches/00list +++ c-repl-0.0.20071223/debian/patches/00list @@ -0,0 +1 @@ +10_debian.dpatch --- c-repl-0.0.20071223.orig/debian/patches/10_debian.dpatch +++ c-repl-0.0.20071223/debian/patches/10_debian.dpatch @@ -0,0 +1,70 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 10_debian.dpatch by Robert S. Edmonds +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: debian environment; look for helpers in /usr/lib/c-repl +## DP: use a mktemp'd directory +## DP: compile DSOs with -fPIC +## DP: don't write a #include when @headers is empty + +@DPATCH@ +diff -urNad c-repl-0.0.20071223~/c-repl c-repl-0.0.20071223/c-repl +--- c-repl-0.0.20071223~/c-repl 2007-12-22 22:07:55.000000000 -0500 ++++ c-repl-0.0.20071223/c-repl 2007-12-22 22:52:09.000000000 -0500 +@@ -1,7 +1,9 @@ +-#!/usr/bin/ruby ++#!/usr/bin/env ruby + # c-repl -- a C read-eval-print loop. + # Copyright (C) 2006 Evan Martin + ++$:.unshift("/usr/lib/c-repl") ++ + require 'readline' + require 'gdbmi' + require 'codesnippet' +@@ -20,7 +22,7 @@ + response_pipe[0].close + STDIN.reopen(command_pipe[0]) + command_pipe[0].close +- exec('./child', response_pipe[1].fileno.to_s) ++ exec('/usr/lib/c-repl/child', response_pipe[1].fileno.to_s) + end + command_pipe[0].close + command_pipe[1].sync = true +@@ -59,6 +61,14 @@ + + class CREPL + def initialize ++ @tmpdir = `mktemp -d /tmp/c-repl.XXXXXXXXXX`.strip ++ if $?.to_i != 0 ++ $stderr.print "unable to create temporary directory" ++ Process.exit!(1) ++ end ++ Dir.chdir(@tmpdir) ++ at_exit { system "rm -rf #{@tmpdir}" } ++ + @debug = false + @cur_so_id = 1 + @runner = Runner.new +@@ -94,7 +104,7 @@ + writer.close + STDIN.reopen(reader) + reader.close +- cmd = "gcc -xc -g -shared -o #{name}.so" ++ cmd = "gcc -xc -g -fPIC -shared -o #{@tmpdir}/#{name}.so" + # add in all libraries + cmd += ' ' + @libraries.map{|l| "-l#{l}"}.join(' ') + # tell it to read input through stdin +@@ -116,8 +126,10 @@ + # Generate code from snippet, writing it to out. + def generate_code(name, snippet, out) + out.puts "#include " +- @headers.each do |header| +- out.puts "#include \"#{header}\"" ++ if @headers ++ @headers.each do |header| ++ out.puts "#include \"#{header}\"" ++ end + end + @externs.each do |extern| + out.puts "extern #{extern}" --- c-repl-0.0.20071223.orig/debian/rules +++ c-repl-0.0.20071223/debian/rules @@ -0,0 +1,49 @@ +#!/usr/bin/make -f + +include /usr/share/dpatch/dpatch.make + +CFLAGS = -Wall -g +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +child: child.c + $(CC) $(CFLAGS) -o $@ $< -ldl + +build: patch-stamp child + dh_testdir + +clean: unpatch + dh_testdir + dh_testroot + rm -f child + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + dh_install + +binary-indep: build install +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs debian/README + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install