glDebug and the callstack

I’ve recently been working on an OpenGL debugger for OSX similar to PIX so I can better get to the root problem bugs.

I will basically intercept the OpenGL calls and transmit them to a debugger that will check for errors, and allow me to view all active resources within a frame.

One bit of code that will be helpful is knowing where each call originated from. Luckily I found some methods that retrieve the symbol names for each level in the callstack. While this doesn’t give me a file or line number, I can get function and class name.

void glDebugLib_ReportCallstack(const uint64_t inContext)
{
	struct glDebugPacket * packet = glDebug_packet_create(glDebugPacketType_Command, "glCallstackReportCIP", inContext);
	{
		void * callstack[128];
		int frameCount;
 
		//
		frameCount = backtrace(callstack, 128);
 
		//
		if(frameCount > 0)
		{
			char ** frameStrings = backtrace_symbols(callstack, frameCount);
 
			if(frameStrings != NULL)
			{
				glDebug_packet_add_uint32(packet, frameCount - 1);
 
				// The first index is the current method
				for(int i = 1; i < frameCount; ++i)
				{
					glDebug_packet_add_string(packet, frameStrings[i]);
				}
 
				free(frameStrings);
			}
		}
	}
	glDebugComm_send_packet(packet);
}

At some point in the future I’ll look into retrieving the file and line number associated with the symbols.