I have been trying to debug cuda programs that use inline PTX assembly. Specifically, I am debugging at the instruction level, and am trying to determine the values of arguments to the instructions. Occasionally, the disassembly includes a reference to constant memory. I am trying to have gdb print the value of this constant memory, but have not found any documentation that shows how to do this. For instance, a disassembly includes IADD R0, R0, c[0x0] [0x148]
I want to determine how to have gdb print the value of c[0x0] [0x148]. I have tried using print * (@constant) ... but this does not seem to work (I pass 0x148 here and it prints out nothing). Is this possible to do in cuda-gdb?
I have tried to avoid this by passing the compiler option --disable-optimizer-constants during compilation, but this does not work.
The way to do this is to print *(void * @parameter *) addr
where addr is the address inside the constant bank 0 that should be printed.
Example
Suppose we have a simple kernel in a file called
foo.cu:which is compiled via
Next, suppose we are interested in disassembling this program, so we execute
cuda-gdbwith a command-line for our program:Inside
cuda-gdb, we get to the kernel by typingInside the kernel, we view the disassembly we are interested in debugging:
The second argument being passed to the
IADDinstruction is in one of the constant memory banks. Let's find out what its value actually is. We advance go to theIADDinstruction:We can now obtain the contents of
c[0x0][0x140]as follows:Here, we knew the argument should have 32 bits, so we cast it as an (32-bit)
int. If we hadn't done this, we would get too many bits, e.g.:Note the hexadecimal format can be retained by adding /x after the
printcommand: