For a flexible error trace mechanism, embodiments may be implemented for
C/C++ interface libraries, or in programs written in C/C++ or other
programming languages. In one embodiment, when an error occurs in a
function call, a trace element may be recorded that may include the
source file name, function name, line number and other information that
may be used to identify the error. In one embodiment, the library
function may call a plurality of library functions in a function call
stack. For each of the plurality of library functions, if the library
function generates an error, an error trace element may be added to the
error trace. After completion of the library function, the program may
obtain the error trace for the library function. The error(s), if any,
may be debugged using the information in the obtained error trace.