debugging kernel functions with gdb

I have compiled a library (libssrcDE) for emulation mode with debugging symbols:

nvcc -o obj/debug/ssrc.cu_o -c ssrc.cu -g -G -D_DEBUG -deviceemu -I. -I/usr/local/cuda/include -I…/…/common/inc -DUNIX
g++ -fPIC -shared -Wl -o …/…/lib/libssrcDE.so obj/debug/ssrc.cu_o -L/usr/local/cuda/lib -L…/…/lib -L…/…/common/lib -lglut -lparamgl -lgsl -lgslcblas -lcudart -lGL -lGLU -lglut -lGLEW -L/usr/local/cuda/lib -L…/…/lib -L…/…/common/lib -lglut -lparamgl -lgsl -lgslcblas -g

and an executable (ssrcDE) which calls this library:

g++ -fPIC -o …/…/bin/linux/emudebug/ssrcDE ssrcMain.c -L/usr/local/cuda/lib -L…/…/lib -L…/…/common/lib -lglut -lparamgl -lssrcDE -lcudart -lGL -lGLU -lglut -L/usr/local/cuda/lib -L…/…/lib -L…/…/common/lib -lglut -lparamgl -lssrcDE -lcutilD -g

When I debug with gdb I can step into the library code, but not the kernel functions:

__device_stub__Z11wssrcKernelPhS_PfS0_iii (__par0=0x808a800 “\001”,
__par1=0x808a800 “\001”, __par2=0x808c700, __par3=0xb68d1100, __par4=239,
__par5=239, __par6=10) at /tmp/tmpxft_00002b3c_00000000-0.stub.c:73
73 /tmp/tmpxft_00002b3c_00000000-0.stub.c: No such file or directory.
in /tmp/tmpxft_00002b3c_00000000-0.stub.c

What am I doing wrong? (or is it not possible to step into kernel functions?)

You’re supposed to be able to step into emulated device functions. I didn’t go over your build syntax, but you could take a look at common/common.mk, to see how NVIDIA builds emulated libraries. Also, you could do make emulation=1 verbose=1 in one of the examples to see how it’s done. Hopefully that does the trick.

hello

I am having same problem with my kernel. After reading your post i have tried to debug bitsonic sample project form sdk, with make emulation=1 verbose=1 and make dbg=1 verbose=1 but i could not debug kernels in both ways.

gdb with make dbg=1 returns

1094 }

(gdb)

Using device 0: Device Emulation (CPU)

Cuda error in file ‘bitonic.cu’ in line 60 : initialization error.

Program exited with code 01.

(gdb)

gdb with make emulation=1 returns

(gdb) break main

Breakpoint 1 at 0x804a8ca

(gdb) r

Starting program: /home/shiggy/NVIDIA_CUDA_SDK/bin/linux/release/bitonic

(no debugging symbols found)

(no debugging symbols found)

(no debugging symbols found)

(no debugging symbols found)

(no debugging symbols found)

(no debugging symbols found)

(no debugging symbols found)

[Thread debugging using libthread_db enabled]

[New Thread -1208825632 (LWP 10586)]

(no debugging symbols found)

(no debugging symbols found)

[Switching to Thread -1208825632 (LWP 10586)]

Breakpoint 1, 0x0804a8ca in main ()

(gdb) s

Single stepping until exit from function main,

which has no line number information.

(no debugging symbols found)

(no debugging symbols found)

NVIDIA: could not open the device file /dev/nvidiactl (No such file or directory).

Using device 0: Device Emulation (CPU)

Test FAILED

Press ENTER to exit…

is there any tutorial on debugging kernels ? how do you debug your kernels ?