Kevin Brosius on Tue, 24 Sep 2002 16:10:10 +0200 |
Fred K Ollinger wrote: > > In C, how may a C function determine which function called it? > > If I have a function called by lots of other function and there's an > error, I might want to know where the call came from so I can trace it > back. > > Fred Ollinger (follinge@sas.upenn.edu) > CCN sysadmin > Lot's of people mentioned a debugger (like gdb, or the easier to use wrapper ddd), but if you're new to programming a debugger has a learning curve to it also. You can easily add printf() functions inside the code which print out the function name, or variables inside the program. Doing this for the function you are worried about, along with a few of the places it is called, will give you a printout of the program flow the next time you run the program. If there are a lot of these calls, you'll want to log the output to a file and review it after you run the program. A debugger generally gives more flexibility, but requires you build the program with debugging symbols if you want the full ability to trace through it. Both methods have their places of use. -- Kevin Brosius _________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce General Discussion -- http://lists.netisland.net/mailman/listinfo/plug
|
|