Reputation: 13
I have three files foo1
, foo2
, and foo3
.
foo2
and foo3
call a function in foo1
.
I am trying to have foo1 detect the file name and line number of the caller without passing those as parameters in the function.
How can I do this?
Upvotes: 1
Views: 724
Reputation: 8874
When running a native program, the concept of files and lines doesn't hold ground any more. The program is just a stream of commands to the processor - the names of the functions, variables, the line numbers, the file names, all is lost during compilation.
Extracting debugging information from a program is virtually impossible. That program would have to be specifically compiled to have the debugging information attached. Sometimes (like the Visual C++), the debugging info is extracted into a separate file - but you would need that file and know its format, to extract that info. And you would be getting only the debug info. Not the compiled code.
The parameters are the way to go.
Upvotes: 1
Reputation: 409196
This is highly platform and compiler dependant, and can't generally be done. Your system may have extensions such as the GNU backtrace
function.
Upvotes: 2