I know there are PHP debugging tools available, but I'm curious about doing something like this myself.
Is there a way to obtain the data that is being processed by PHP for debugging purposes? For example, without having to change the code of my PHP application, is there some way, when I run a function, I can see what variables exist within that function, what called that function, what the return value was etc?
The solution doesn't specifically doesn't need to be in PHP, ie this could be somethig that is written in C etc
Well, may I suggest you look into adding firePHP to your code. FirePHP has 2 components, a server side component, and a browser component for firefox, it uses the firebug addon. Once installed properly you can do things like FB::Log($variable) and you will see this information inside of the log portion of firebug, when you click on it, it shows the entire variable broken out. Also if you were to install the error handler, when you get a caught exception, you are able to see the entire stack trace of how this exception was invoked.