GDB and GCC union | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

GDB and GCC union

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2011
uunniixx uunniixx is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 November 2011, 11:55 AM EST
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 03-14-2011
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 20 August 2014, 12:29 PM EDT
Location: NM
Posts: 10,173
Thanks: 273
Thanked 784 Times in 733 Posts
C99 specifies the follwing macros: __FILE__ __LINE__ __FUNCTION__

Code:
/* 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
Code:
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__
Sponsored Links
    #3  
Old 03-15-2011
uunniixx uunniixx is offline
Registered User
 
Join Date: May 2008
Last Activity: 30 November 2011, 11:55 AM EST
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
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.
    #4  
Old 03-15-2011
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 August 2014, 4:37 PM EDT
Location: Saskatchewan
Posts: 19,217
Thanks: 772
Thanked 3,221 Times in 3,019 Posts
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.
Sponsored Links
    #5  
Old 03-15-2011
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 20 August 2014, 12:29 PM EDT
Location: NM
Posts: 10,173
Thanks: 273
Thanked 784 Times in 733 Posts
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.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk: union regions phoeberunner Shell Programming and Scripting 2 07-15-2010 04:26 AM
Union of multiple files rd42 Shell Programming and Scripting 15 05-13-2010 09:06 AM
Text files union tal Shell Programming and Scripting 2 03-11-2009 01:42 PM
union of two files sherkaner Shell Programming and Scripting 3 10-02-2007 05:22 PM
How to find union of two files stevefox Shell Programming and Scripting 7 12-07-2005 08:32 PM



All times are GMT -4. The time now is 06:24 PM.