GDB and GCC union

My concept may sound a bit cryptic but I what some startup information as to how we can use GDB APIs / debugging techniques in programs with GCC when we compile the program. We can definitely tell gcc to link GDB libs also. The ultimate aid would be that when the compiled programs executes it should produce logs in following format:

filename.cpp:linenumber

Is there any way we can achieve it - I do believe it is cause how would GDB knows these details and I looking for some knowhow�s to begin with.

C99 specifies the follwing macros: __FILE__ __LINE__ __FUNCTION__

/* define a global macro in a header file */
#define F printf("%s %s %d:\n", __FILE__ , __FUNCTION__, __LINE__);

Using the gdb api is not difficult, but would require a big code change.
You can use sed or awk to add

F;

in any function for each app; these C macros are specifically meant for the purpose you described. Pick the ones you want, probably __FILE__ __LINE__

Thanks Jim, can you please provide some pointers for using gdb api in cpp programs - I can see more usage and benefits than just using the macros.

Thanks in advance.

If you build your program with -ggdb that'll include extra debugging information gdb can use. I don't know any way to make this debugging information available to the program itself at runtime -- would you want a program that could only be built with gdb, and only built for debugging? Talk about unportable.

Even if you end up using gdb for something else I don't see the harm in using the __FILE__, etc. C macros to do what they were designed to do.

The linux debugger is based on the ptrace system call. Every different unix OS has its own version of ptrace - it may be called something else.

Consider looking at ptrace. Using the api for gdb will be more trouble than benefit.
Look into gprof and gcover as well. Consider that with all of the effort put into gcover, gprof, and gdb -- the people who have developed them over the past 15 years have got a handle on uses and presented them to us.

In other words, corona's assessment is correct - it ain't worth the time and frustration.