0

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

2
  • 2
    Does your program use an OpenGL loader like GLAD or GLEW by any chance? Commented Dec 19, 2019 at 14:52
  • @Botje I have tried GLAD c-debug generator, it works nicely. How to do it with GLEW? Commented Dec 20, 2019 at 3:17

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The same approach doesn't work on GLAD, gdb doesn't let me set breakpoint on functions populated with OpenGL implementation, I can only set breakpont on glad_debug_impl_*, which is real function that calls populated function. I havn't try it with glew, it looks suspicious, I will try it later.
Can't you put a breakpoint on *glad_glEnableVertexAttribArray after GLAD has loaded all the pointers? (note the *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.