如何让 NVCC 包含宏定义信息?
通常,使用 gcc,您可以使用 -g 指定调试信息的级别,如果使用 -g3,它将在可执行文件中包含预处理器宏定义,gdb 等调试器可以读取这些宏定义,并允许您在调试期间使用。我想用 nvcc 来调试 CUDA 程序。
我目前正在修改 SDK 中的模板程序,因此我使用 Makefile 中包含的默认 Makefile 和 common.mk。在 common.mk 中的 'ifeq ($(dbg), 1)' 块中,我尝试了以下操作:
- put -g3 under COMMONFLAGS
- put -g3 under NVCCFLAGS
- put -g3 under CXXFLAGS and CFLAGS
- put --compiler-options -g3在 NVCCFLAGS 下。
前两个给出了无法识别的选项错误。后两个似乎没有解决问题,因为当我使用 cuda-gdb 进行调试时,我没有获得宏信息。
我想这样做的原因是因为我想使用程序本身用来访问该内存的相同宏来检查一些内存。例如,
#define ARROW(state, arrow) ((c_arrow_t *)(&((state)->arrows) + (arrow) * sizeof(c_arrow_t)))
#define STATE(nfa, state) ((c_state_t *)(&((nfa)->states) + (state) * sizeof(c_state_t)))
我使用一些宏来访问非确定性有限状态自动机的状态和箭头。
感谢您的帮助!
Normally with gcc you can specify the level of debugging information with -g and if you use -g3 it will include preprocessor macro definitions in the executable which debuggers like gdb can read and allow you to use during debugging. I would like to do this with nvcc for debugging CUDA programs.
I am currently working by modifying the template program in the SDK so I'm using the default Makefile and common.mk included from the Makefile. In common.mk within the 'ifeq ($(dbg), 1)' block, I have tried the following:
- put -g3 under COMMONFLAGS
- put -g3 under NVCCFLAGS
- put -g3 under CXXFLAGS and CFLAGS
- put --compiler-options -g3 under NVCCFLAGS.
The first two give an unrecognized option error. The second two do not seem to do the trick because when I debug using cuda-gdb I don't get the macro information.
The reason I would like to do this is because I would like to inspect some memory using the same macros the program itself uses to access that memory. For example,
#define ARROW(state, arrow) ((c_arrow_t *)(&((state)->arrows) + (arrow) * sizeof(c_arrow_t)))
#define STATE(nfa, state) ((c_state_t *)(&((nfa)->states) + (state) * sizeof(c_state_t)))
are some macros I use to access states and arrows of a non-deterministic finite state automaton.
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要将 -g 传递给 nvcc 以将其设置为使用主机调试进行构建,并且还需要通过 -Xcompiler(或 --compiler-options)将 -g3 传递给主机编译器。
只是一个观察,但您确实不应该将该 SDK makefile 用于任何用途。这确实是邪恶的——对一些自动工具生成的 make 语句进行了粗暴的破坏,这既不必要地复杂,又非常不灵活。就连与我打交道的 NVIDIA 开发人员也警告不要使用它。
You probably need to pass both -g to nvcc to set it to build with host debugging, and also pass -g3 to the host compiler via the -Xcompiler (or --compiler-options).
Just an observation, but you really shouldn't be using that SDK makefile for anything. It is truly evil - a crude broken hack on some autotools generated make statements, which is both unnecessarily complex and very inflexible. Even the NVIDIA developers I interact with warn not to use it.