Search code examples
debuggingopenglgdbbreakpoints

Is it possible to set breakpoint at OpenGL functions?


Sometimes I need to find out which part of the code call a certain OpenGL function, so I try this:

b glEnableVertexAttribArray
----------------------------
Breakpoint 3 at 0x7ffff0326c80 (2 locations)

But it doesn't work, is there any way to make this work?

I'm using gdb in ubuntu18.04, my GPU is GeForce GTX 1050 Ti


Solution

  • If you look at your GL/glew.h header, you will see that it contains lines similar to the following:

    #define GLEW_GET_FUN(x) x
    #define glCopyTexSubImage3D GLEW_GET_FUN(__glewCopyTexSubImage3D)
    #define glDrawRangeElements GLEW_GET_FUN(__glewDrawRangeElements)
    #define glTexImage3D GLEW_GET_FUN(__glewTexImage3D)
    #define glTexSubImage3D GLEW_GET_FUN(__glewTexSubImage3D)
    

    When you call glewInit, these __glew* variables are populated with pointers extracted from your OpenGL implementation. In your case, you should set a breakpoint on the contents of such a pointer, so *__glewEnableVertexAttribArray.

    For GLAD you will have to put a breakpoint on *glad_glEnableVertexAttribArray. Note the * in both cases: that tells your debugger to dereference the pointer and put the breakpoint at the correct location.