我正在Haskell中执行低级IO (用于库绑定),并且遇到了segfault。我想使用GHCi的:break来弄清楚发生了什么,但下面是发生的事情:
> import SDL
> :break SDL.setPaletteColors
cannot set breakpoint on setPaletteColors: module SDL.Video.Renderer is not interpreted
因为有问题的代码不在我自己的模块中,而是在外部包中的模块中,所以它是作为编译代码加载的,显然我不能对编译后的模块使用:break。
GHCi manual证实了这一点,并提供了一个提示:
有一个主要限制:断点和单步执行只在解释模块中可用;编译后的代码对debugger5是不可见的。
5请注意,包只包含已编译的代码,因此调试包需要找到其源代码并直接加载。
让我们直接尝试一下:
> :load some_path/sdl2/src/SDL/Video/Renderer.hs
some_path/sdl2/src/SDL/Video/Renderer.hs:101:8:
Could not find module ‘Control.Monad.IO.Class’
It is a member of the hidden package ‘transformers-0.3.0.0’.
Perhaps you need to add ‘transformers’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
我可以将依赖项添加到我的.cabal文件中,但我感觉这是错误的。一旦我做到了这一点:
> :load some_path/sdl2/src/SDL/Video/Renderer.hs
some_path/sdl2/src/SDL/Video/Renderer.hs:119:8:
Could not find module ‘SDL.Internal.Numbered’
it is a hidden module in the package ‘sdl2-2.0.0’
Use -v to see a list of the files searched for.
我可以将这些模块公开(也许?通过修改包.cabal?),但在这一点上,这似乎是一种非常笨拙的方式,我没有进一步研究它。
编辑:
我真的试过了,得到了令人费解的结果:
> :load some_path/sdl2/src/SDL/Video/Renderer.hs
[1 of 1] Compiling SDL.Video.Renderer ( some_path/sdl2/src/SDL/Video/Renderer.hs, interpreted )
Ok, modules loaded: SDL.Video.Renderer.
> :break SDL.setPaletteColors
cannot set breakpoint on SDL.setPaletteColors: module SDL.Video.Renderer is not interpreted
我(没有经验的)猜测:这是因为外部模块仍然以二进制形式链接到我的代码,并且以解释模式动态加载它不会改变这一点。
所以,总结这个问题:在外部包中调试IO的好方法是什么?
其他注意事项:
添加到了项目中
https://stackoverflow.com/questions/28570367
复制相似问题