6. 適当なコードをコンパイル
$ cat Main.hs
main :: IO ()
main = putChar 'H'
$ /usr/local/ghc7.4.1/bin/ghc -eventlog -debug -rtsopts Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
$ ./Main
H
ふつーのHaskellコードです。
7. 天下り的にブレークポイントを決める
$ uname -a
Linux casper 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012
x86_64 GNU/Linux
$ gdb Main
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/
licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show
copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/kiwamu/src/DiveIntoRTS/Main...done.
(gdb) b StgRun # 天下り!
Breakpoint 1 at 0x68c9cc: file rts/StgCRun.c, line 236.
8. バックトレースを取ってみると。。。
(gdb) run
Starting program: /home/kiwamu/src/DiveIntoRTS/Main
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/
libthread_db.so.1".
Breakpoint 1, StgRunIsImplementedInAssembler () at rts/
StgCRun.c:236
236 __asm__ volatile (
(gdb) bt
#0 StgRunIsImplementedInAssembler () at rts/StgCRun.c:236
#1 0x0000000000689ef5 in scheduleWaitThread (tso=0x7ffff6c05390,
ret=0x0, pcap=0x7fffffffe040) at rts/Schedule.c:2154
#2 0x00000000006c75a6 in rts_evalLazyIO (cap=0x7fffffffe040,
p=0x90c8a0, ret=0x0) at rts/RtsAPI.c:497
#3 0x0000000000683688 in real_main () at rts/RtsMain.c:63
#4 0x0000000000683784 in hs_main (argc=1, argv=0x7fffffffe1a8,
main_closure=0x90c8a0, rts_config=...) at rts/RtsMain.c:115
#5 0x0000000000404347 in main ()
(gdb)
32. 例3 known functionへの部分適用
module KnownFun (knownUndersaturatedApp, knownFun2) where
{-# NOINLINE knownFun2 #-}
knownFun2 :: a -> a -> a
knownFun2 x _ = x
knownUndersaturatedApp :: () -> Int -> Int
knownUndersaturatedApp _ = knownFun2 10
KnownFun_knownUndersaturatedApp_info() {
cdm:
R2 = stg_INTLIKE_closure+417;
jump KnownFun_knownFun2_info ();
}
knownUndersaturatedAppの引数は2なの
で部分適用でもknownFun2の引数は足りて
る
33. 例4 unknown function
module Main where
import KnownFun
main :: IO ()
main = do
return $! unknownApp id 10
return ()
module KnownFun (unknownApp) where
{-# NOINLINE unknownApp #-}
unknownApp :: (Int -> Int) -> Int -> Int
unknownApp f x = f x -- fがどんな関数かコンパイル時に判別できない
KnownFun_unknownApp_info() {
c9Y:
R1 = R2; // <= 何入ってるの?
R2 = R3; // <=
jump stg_ap_p_fast (); // generic apply
}