Discussion:
[brlcad-devel] Debugging OpenCL kernel with GDB
Marco Domingues
2017-04-06 13:51:54 UTC
Permalink
Hello everyone,

I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble using the command: (gdb) break filename:linenum

My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel” (in src/librt/primitives/primitive_util.c) because I read online that kernels are only visible to ‘gdb’ after they are compiled.

But when I run the following commands inside the brlcad main directory:

$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063

I get “no source file named src/librt/primitives/primitive_util.c”, even when i try to specify the full path to the file

Maybe someone that have used ‘gdb’ with brlcad before could point me what is missing?

Thanks in advance!

Cheers, Marco Domingues
Vasco Alexandre da Silva Costa
2017-04-06 18:50:27 UTC
Permalink
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble
using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel”
(in src/librt/primitives/primitive_util.c) because I read online that
kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after
they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”, even
when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me what
is missing?
There's another thing you can do, other than set a breakpoint. You can emit
an interrupt in the code (e.g. with kill(0, SIGINT)). Then the executable
will stop. Then you can just use the 'continue' command. Or just hit CTRL-C
in the middle of execution. Assuming the code takes long enough to run that
you can do it...

Still, if you want to debug the raytracer backend, it is not 'mged' you
want to debug. What you want to debug is the 'rt' command. 'mged' is just a
graphic interface that IIRC has no rendering code in it. That's probably
why you can't set the breakpoint in the first place. The code isn't in
'mged'. One good way to check this out, assuming you compiled with debug
symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in
the list of linked libraries.

If you can also a list of the debug symbols in an executable or a library
with the 'nm' command. e.g. 'nm -S build/bin/mged'.

Regards,
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
Vasco Alexandre da Silva Costa
2017-04-06 18:54:07 UTC
Permalink
On Thu, Apr 6, 2017 at 7:50 PM, Vasco Alexandre da Silva Costa <
On Thu, Apr 6, 2017 at 2:51 PM, Marco Domingues <
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble
using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel”
(in src/librt/primitives/primitive_util.c) because I read online that
kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after
they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”, even
when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me what
is missing?
There's another thing you can do, other than set a breakpoint. You can
emit an interrupt in the code (e.g. with kill(0, SIGINT)). Then the
executable will stop. Then you can just use the 'continue' command. Or just
hit CTRL-C in the middle of execution. Assuming the code takes long enough
to run that you can do it...
Still, if you want to debug the raytracer backend, it is not 'mged' you
want to debug. What you want to debug is the 'rt' command. 'mged' is just a
graphic interface that IIRC has no rendering code in it. That's probably
why you can't set the breakpoint in the first place. The code isn't in
'mged'. One good way to check this out, assuming you compiled with debug
symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in
the list of linked libraries.
If you can also a list of the debug symbols in an executable or a library
with the 'nm' command. e.g. 'nm -S build/bin/mged'.
PS: Of course what I meant to say was:
You can also list the debug symbols in an executable or library with the
'nm' command. e.g. 'nm -S build/bin/mged'.

Heh,
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
Vasco Alexandre da Silva Costa
2017-04-06 19:09:49 UTC
Permalink
On Thu, Apr 6, 2017 at 7:54 PM, Vasco Alexandre da Silva Costa <
Post by Vasco Alexandre da Silva Costa
On Thu, Apr 6, 2017 at 7:50 PM, Vasco Alexandre da Silva Costa <
On Thu, Apr 6, 2017 at 2:51 PM, Marco Domingues <
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble
using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel”
(in src/librt/primitives/primitive_util.c) because I read online that
kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after
they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”,
even when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me
what is missing?
There's another thing you can do, other than set a breakpoint. You can
emit an interrupt in the code (e.g. with kill(0, SIGINT)). Then the
executable will stop. Then you can just use the 'continue' command. Or just
hit CTRL-C in the middle of execution. Assuming the code takes long enough
to run that you can do it...
Still, if you want to debug the raytracer backend, it is not 'mged' you
want to debug. What you want to debug is the 'rt' command. 'mged' is just a
graphic interface that IIRC has no rendering code in it. That's probably
why you can't set the breakpoint in the first place. The code isn't in
'mged'. One good way to check this out, assuming you compiled with debug
symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in
the list of linked libraries.
If you can also a list of the debug symbols in an executable or a library
with the 'nm' command. e.g. 'nm -S build/bin/mged'.
You can also list the debug symbols in an executable or library with the
'nm' command. e.g. 'nm -S build/bin/mged'.
PPS: You can run 'rt' outside 'mged' like this:
$ rt -w 640 -n 480 -o image.png build.g my_object
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal

On Thu, Apr 6, 2017 at 7:54 PM, Vasco Alexandre da Silva Costa <
Post by Vasco Alexandre da Silva Costa
On Thu, Apr 6, 2017 at 7:50 PM, Vasco Alexandre da Silva Costa <
On Thu, Apr 6, 2017 at 2:51 PM, Marco Domingues <
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble
using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel”
(in src/librt/primitives/primitive_util.c) because I read online that
kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after
they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”,
even when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me
what is missing?
There's another thing you can do, other than set a breakpoint. You can
emit an interrupt in the code (e.g. with kill(0, SIGINT)). Then the
executable will stop. Then you can just use the 'continue' command. Or just
hit CTRL-C in the middle of execution. Assuming the code takes long enough
to run that you can do it...
Still, if you want to debug the raytracer backend, it is not 'mged' you
want to debug. What you want to debug is the 'rt' command. 'mged' is just a
graphic interface that IIRC has no rendering code in it. That's probably
why you can't set the breakpoint in the first place. The code isn't in
'mged'. One good way to check this out, assuming you compiled with debug
symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in
the list of linked libraries.
If you can also a list of the debug symbols in an executable or a library
with the 'nm' command. e.g. 'nm -S build/bin/mged'.
You can also list the debug symbols in an executable or library with the
'nm' command. e.g. 'nm -S build/bin/mged'.
Heh,
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
Marco Domingues
2017-04-07 13:59:58 UTC
Permalink
Hi Vasco,

Thanks a lot for your help!

By following your instructions i could run the command: "$ gdb --args build/bin/rt -z1 -l5 -w 640 -n 480 -o image.png build/bool.g sp.r”, and was able to set the breakpoint at the desired location in the ‘primitive_util.c’ file!

Cheers,
Marco Domingues
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel” (in src/librt/primitives/primitive_util.c) because I read online that kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”, even when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me what is missing?
There's another thing you can do, other than set a breakpoint. You can emit an interrupt in the code (e.g. with kill(0, SIGINT)). Then the executable will stop. Then you can just use the 'continue' command. Or just hit CTRL-C in the middle of execution. Assuming the code takes long enough to run that you can do it...
Still, if you want to debug the raytracer backend, it is not 'mged' you want to debug. What you want to debug is the 'rt' command. 'mged' is just a graphic interface that IIRC has no rendering code in it. That's probably why you can't set the breakpoint in the first place. The code isn't in 'mged'. One good way to check this out, assuming you compiled with debug symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in the list of linked libraries.
If you can also a list of the debug symbols in an executable or a library with the 'nm' command. e.g. 'nm -S build/bin/mged'.
You can also list the debug symbols in an executable or library with the 'nm' command. e.g. 'nm -S build/bin/mged'.
$ rt -w 640 -n 480 -o image.png build.g my_object
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
I’m trying to use ‘gdb’ to debug an OpenCL kernel but I’m having trouble using the command: (gdb) break filename:linenum
My idea was to set a breakpoint in the function “clEnqueueNDRangeKernel” (in src/librt/primitives/primitive_util.c) because I read online that kernels are only visible to ‘gdb’ after they are compiled.
It is probably worse than that. The kernels likely are only visible after they're both compiled and linked.
$ gdb --args build/bin/mged build/bool.g
(gdb) b src/librt/primitives/primitive_util.c:1063
I get “no source file named src/librt/primitives/primitive_util.c”, even when i try to specify the full path to the file
Maybe someone that have used ‘gdb’ with brlcad before could point me what is missing?
There's another thing you can do, other than set a breakpoint. You can emit an interrupt in the code (e.g. with kill(0, SIGINT)). Then the executable will stop. Then you can just use the 'continue' command. Or just hit CTRL-C in the middle of execution. Assuming the code takes long enough to run that you can do it...
Still, if you want to debug the raytracer backend, it is not 'mged' you want to debug. What you want to debug is the 'rt' command. 'mged' is just a graphic interface that IIRC has no rendering code in it. That's probably why you can't set the breakpoint in the first place. The code isn't in 'mged'. One good way to check this out, assuming you compiled with debug symbols, is to run 'ldd build/bin/mged' and see if 'librt.so' shows up in the list of linked libraries.
If you can also a list of the debug symbols in an executable or a library with the 'nm' command. e.g. 'nm -S build/bin/mged'.
You can also list the debug symbols in an executable or library with the 'nm' command. e.g. 'nm -S build/bin/mged'.
Heh,
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
BRL-CAD Developer mailing list
https://lists.sourceforge.net/lists/listinfo/brlcad-devel
Loading...