although
http://stackoverflow.com/questions/
10123040/ghci-doesnt-work-with-ffi-export-declarations-shared-libaries
fixed an issue, there is now a different one:
> $ make ghci
> [...]
> Ok, modules loaded: Main, Mate.X86CodeGen, Mate.MethodPool, Mate.BasicBlocks, Mate.Utilities.
> Prelude Main> main
>
>
> GHCi runtime linker: fatal error: I found a duplicate definition for symbol
> MateziUtilities_lookupMethod_srt
> whilst processing object file
> ./Mate/Utilities.o
> This could be caused by:
> * Loading two different object files which export the same symbol
> * Specifying the same object file twice on the GHCi command line
> * An incorrect `package.conf' entry, causing some object to be
> loaded twice.
> GHCi cannot safely continue in this situation. Exiting now. Sorry.
>
> make: *** [ghci] Error 1
so, `make ghci' and `make tags' still doesn't work due to FFI stuff.
we have to use `make test' until we fix it :-(
JAVA_FILES := $(wildcard tests/*.java)
CLASS_FILES := $(JAVA_FILES:.java=.class)
HS_FILES := $(wildcard Mate/*.hs)
+O_FILES = $(shell ls Mate/*.o) $(wildcard ffi/*.o)
+PACKAGES_ := bytestring harpy hs-java
+PACKAGES := $(addprefix -package ,$(PACKAGES_))
-GHC_OPT := -Wall -O2 -fno-warn-unused-do-bind
+GHC_OPT := -Wall -O0 -fno-warn-unused-do-bind
+GHC_LD := -optl-Xlinker -optl-x
+
+
+.PHONY: all test clean ghci
all: mate $(CLASS_FILES)
%.class: %.java
$(JAVAC) $<
-trap.o mate: Mate.hs trap.c $(HS_FILES)
- ghc --make $(GHC_OPT) Mate.hs trap.c -o mate
+mate: Mate.hs ffi/trap.c $(HS_FILES)
+ ghc --make $(GHC_OPT) Mate.hs ffi/trap.c -o $@ $(GHC_LD)
clean:
- rm -f {Mate/,}*.hi {Mate/,}*.o mate tests/*.class
+ rm -f {Mate/,}*.hi {Mate/,ffi,}*.o mate tests/*.class
+
+ghci: mate
+ ghci $(PACKAGES) $(O_FILES) Mate.hs $(GHC_LD)
-tags: Mate.hs $(HS_FILES) trap.o
+tags: mate
@# @-fforce-recomp, see
@# http://stackoverflow.com/questions/7137414/how-do-i-force-interpretation-in-hint
- ghc -fforce-recomp -e :ctags $^
+ ghc -fforce-recomp -e :ctags $(PACKAGES) $(HS_FILES) $(O_FILES) Mate.hs
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <asm/ucontext.h>
+
+unsigned int getMethodEntry(void *, char *);
+void *method_map = NULL;
+
+void set_mmap(void *mmap)
+{
+ printf("set_mmap: 0x%08x\n", (unsigned int) mmap);
+ method_map = mmap;
+}
+
+void *get_mmap()
+{
+ printf("get_mmap: 0x%08x\n", (unsigned int) method_map);
+ return method_map;
+}
+
+void demo_mmap()
+{
+ printf("mmap: 0x%08x\n", getMethodEntry(method_map, "fib"));
+}
+
+
+unsigned int patchme = 0;
+void print_foo(unsigned int addr)
+{
+ // printf("\n\nprint foo: 0x%08x\n", addr);
+ patchme = addr;
+}
+
+void callertrap(int nSignal, siginfo_t *info, void *ctx)
+{
+ struct ucontext *uctx = (struct ucontext *) ctx;
+
+ printf("callertrap(mctx) by 0x%08x\n", (unsigned int) uctx->uc_mcontext.eip);
+ // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
+ // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
+
+ unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
+ unsigned char *insn = (unsigned char *) (uctx->uc_mcontext.eip);
+ *insn = 0x90; // nop
+ insn++;
+ *insn = 0xe8; // call
+ printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
+ printf("*to_patch: 0x%08x\n", *to_patch);
+ if (*to_patch != 0x00000000) {
+ printf("something is wrong here. abort\n");
+ exit(0);
+ }
+ *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
+ printf("*to_patch: 0x%08x\n", *to_patch);
+ uctx->uc_mcontext.eip = (unsigned long) insn;
+ // while (1) ;
+}
+
+void register_signal(void)
+{
+ struct sigaction segvaction;
+ segvaction.sa_sigaction = callertrap;
+ sigemptyset(&segvaction.sa_mask);
+ segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
+ sigaction(SIGSEGV, &segvaction, NULL);
+}
+
+unsigned int getaddr(void)
+{
+ return (unsigned int) print_foo;
+}
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <asm/ucontext.h>
-
-unsigned int getMethodEntry(void *, char *);
-void *method_map = NULL;
-
-void set_mmap(void *mmap)
-{
- printf("set_mmap: 0x%08x\n", (unsigned int) mmap);
- method_map = mmap;
-}
-
-void *get_mmap()
-{
- printf("get_mmap: 0x%08x\n", (unsigned int) method_map);
- return method_map;
-}
-
-void demo_mmap()
-{
- printf("mmap: 0x%08x\n", getMethodEntry(method_map, "fib"));
-}
-
-
-unsigned int patchme = 0;
-void print_foo(unsigned int addr)
-{
- // printf("\n\nprint foo: 0x%08x\n", addr);
- patchme = addr;
-}
-
-void callertrap(int nSignal, siginfo_t *info, void *ctx)
-{
- struct ucontext *uctx = (struct ucontext *) ctx;
-
- printf("callertrap(mctx) by 0x%08x\n", (unsigned int) uctx->uc_mcontext.eip);
- // printf("callertrap(addr) by 0x%08x\n", info->si_addr);
- // printf("callertrap(*esp) by 0x%08x\n", * (unsigned int *) uctx->uc_mcontext.esp);
-
- unsigned int *to_patch = (unsigned int *) (uctx->uc_mcontext.eip + 2);
- unsigned char *insn = (unsigned char *) (uctx->uc_mcontext.eip);
- *insn = 0x90; // nop
- insn++;
- *insn = 0xe8; // call
- printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
- printf("*to_patch: 0x%08x\n", *to_patch);
- if (*to_patch != 0x00000000) {
- printf("something is wrong here. abort\n");
- exit(0);
- }
- *to_patch = (unsigned int) patchme - ((unsigned int) insn + 5);
- printf("*to_patch: 0x%08x\n", *to_patch);
- uctx->uc_mcontext.eip = (unsigned long) insn;
- // while (1) ;
-}
-
-void register_signal(void)
-{
- struct sigaction segvaction;
- segvaction.sa_sigaction = callertrap;
- sigemptyset(&segvaction.sa_mask);
- segvaction.sa_flags = SA_SIGINFO | SA_RESTART;
- sigaction(SIGSEGV, &segvaction, NULL);
-}
-
-unsigned int getaddr(void)
-{
- return (unsigned int) print_foo;
-}