From 8cce0bebc102531155bece6f56200cb7cf12d976 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Tue, 17 Jul 2012 20:27:06 +0200 Subject: [PATCH] gdb: disable ghc's rts timer and disable signal handlers debugging jitted code is nice again (as it was with 6.12.*) --- .gdbcmds | 3 +++ HACKING | 8 ++++++++ Makefile | 5 ++++- Mate/MethodPool.hs | 11 ++++++----- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .gdbcmds diff --git a/.gdbcmds b/.gdbcmds new file mode 100644 index 0000000..f40cd9e --- /dev/null +++ b/.gdbcmds @@ -0,0 +1,3 @@ +handle SIGILL nostop +handle SIGSEGV nostop +run diff --git a/HACKING b/HACKING index 2d12341..c70e194 100644 --- a/HACKING +++ b/HACKING @@ -1,11 +1,19 @@ for testing with a release build, use $ make tests/Fib + for testing a release build against OpenJDK output, use $ make tests/Fib.test + for testing with a debug build, use $ DBGFLAGS='-DDBG_JIT -DDBG_BB' make tests/Fib.dbg `make clean' is needed if you change $DBGFLAGS. for all available flags, see `debug.h'. + + +for debugging with gdb, modify Mate/MethodPool.hs and make a debug build with at +least -DDBG_JIT enabled, then use +$ make tests/Fib.gdb +and follow the instructions in the source file. diff --git a/Makefile b/Makefile index c3fc8e8..cd0e887 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ O_STATIC_FILES = $(shell ls $(B_STATIC)/Mate/*.o) $(wildcard $(B_STATIC)/ffi/*.o PACKAGES_ := bytestring harpy hs-java plugins PACKAGES := $(addprefix -package ,$(PACKAGES_)) -GHC_OPT := -I. -Wall -O0 -fno-warn-unused-do-bind +GHC_OPT := -I. -Wall -O0 -fno-warn-unused-do-bind -rtsopts GHC_LD := -optl-Xlinker -optl-x @@ -58,6 +58,9 @@ mate.static: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILE %.dbg: %.class mate.dbg ./mate.dbg $(basename $<) +%.gdb: %.class mate.dbg + gdb -x .gdbcmds -q --args mate.dbg $(basename $<) +RTS -V0 --install-signal-handlers=no + ifeq (${DBGFLAGS},) DEBUGFLAGS = -DDBG_JIT -DDBG_MP else diff --git a/Mate/MethodPool.hs b/Mate/MethodPool.hs index f7038f3..1403eae 100644 --- a/Mate/MethodPool.hs +++ b/Mate/MethodPool.hs @@ -146,11 +146,12 @@ compileBB hmap methodinfo = do mapM_ (printfJit "%s\n" . showAtt) (snd right) printfJit "\n\n" -- UNCOMMENT NEXT LINES FOR GDB FUN - --if (toString $ methName methodinfo) == "thejavamethodIwant2debug" - -- then getLine - -- else return "foo" - -- (1) start it with `gdb ./mate' and then `run ' - -- (2) on getLine, press ctrl+c + -- if (toString $ methName methodinfo) == "thejavamethodIwant2debug" + -- then putStrLn "press CTRL+C now for setting a breakpoint. then `c' and ENTER for continue" >> getLine + -- else return "foo" + -- (1) build a debug build (see HACKING) and execute `make tests/Fib.gdb' + -- for example, where the suffix is important + -- (2) on getLine, press CTRL+C -- (3) `br *0x'; obtain the address from the disasm above -- (4) `cont' and press enter return $ fromIntegral $ ptrToIntPtr entry -- 2.25.1