Unix/Linux Go Back    


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

Good C debugger ?

Programming


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-02-2010
cyler cyler is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 11 June 2010, 6:14 AM EDT
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Good C debugger ?

I'm a C newbie using gcc. I wrote a program but a part of it outputs gibberish onto the terminal. Its weird because identical parts of the program work correctly in another program I wrote Linux. My program uses c99 + some POSIX headers. It compiles with no errors/warnings even though I have included all the flags I could get hold of.

I do not understand how to use -g so can anybody recommend a C debugger (that speaks english, lol)? At this point I am even willing to switch to Windows...

Can anybody at least add other useful flags ?

Quote:
gcc -std=c99 -D_POSIX_C_SOURCE=200112L -pedantic -O -pipe -g -fstack-protector-all -fstack-protector -funit-at-a-time -Wall -Wextra -Wformat-security -Wformat=2 -Wuninitialized -Winit-self -Wmissing-include-dirs -Wunused -Wfloat-equal -Wshadow -Wunsafe-loop-optimizations -Wbad-function-cast -Wc++-compat -Wcast-qual -Wcast-align -Wconversion -Wlogical-op -Waggregate-return -Wold-style-definition -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvariadic-macros -Wvla -Wdisabled-optimization -Wstack-protector -Wwrite-strings -Wlong-long programname.c
Sponsored Links
    #2  
Old Unix and Linux 02-02-2010
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 21 July 2017, 9:46 AM EDT
Location: Asia pacific region
Posts: 13,586
Thanks: 853
Thanked 1,142 Times in 535 Posts
Have you heard of gdb - The GNU Debugger ?
Sponsored Links
    #3  
Old Unix and Linux 02-02-2010
pludi's Unix or Linux Image
pludi pludi is offline Forum Advisor  
Cat herder
 
Join Date: Dec 2008
Last Activity: 28 March 2014, 8:35 AM EDT
Location: Vienna, Austria, Earth
Posts: 5,521
Thanks: 38
Thanked 335 Times in 308 Posts
If you've can, install DDD, which is a graphical frontend to gdb (and a few others). Then, compile your program using
Code:
gcc -Wall -ggdb -o programname programname.c

Don't enable any optimization settings, as that will make debugging all the harder. Same goes for inlineing, ...

Start it using
Code:
ddd ./progname

, and start debugging.

See also: http://www.unix.com/man-page/Linux/1/ddd/
    #4  
Old Unix and Linux 02-02-2010
cyler cyler is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 11 June 2010, 6:14 AM EDT
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, I have heard and used it before with no success. I'm trying to debug a CGI program written in C. It seems to segfault when using getenv. I tried running the program with Firefox and using sleep(30) to make time to attach PID but it still segfaults on this line.

Any ideas ?

PHP Code:
char DOCUMENTROOT[128] = "";
strcat(DOCUMENTROOTgetenv("DOCUMENT_ROOT")); // This line is ok, right ? I mean it is far less than 128 chars long. 
Sponsored Links
    #5  
Old Unix and Linux 02-02-2010
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 21 July 2017, 9:46 AM EDT
Location: Asia pacific region
Posts: 13,586
Thanks: 853
Thanked 1,142 Times in 535 Posts
Do you call any other environmental var C routines?

Are you sure your CGI has permissions to call these routines?

---------- Post updated at 16:15 ---------- Previous update was at 16:12 ----------

Also, I've not programmed in C for a very long time.... so maybe this is a dumb suggestion, sorry:

getenv() returns a pointer to a char.

You defined


Code:
char DOCUMENTROOT[128] = "";

Does this work?


Code:
char *DOCUMENTROOT[128] = "";

Sponsored Links
    #6  
Old Unix and Linux 02-02-2010
cyler cyler is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 11 June 2010, 6:14 AM EDT
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Actually, the problem is using "DOCUMENT_ROOT" because it is apache specific. Using "PATH" works.

So how could I debug my CGI program using apache and using GDB ??? (Like I said, running my CGI w/ Firefox and attaching its PID to GDB does not solve the problem.)

Seems I will have to temporarily substitute the getenv's with strings. Linux
Sponsored Links
    #7  
Old Unix and Linux 02-02-2010
Neo's Unix or Linux Image
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 21 July 2017, 9:46 AM EDT
Location: Asia pacific region
Posts: 13,586
Thanks: 853
Thanked 1,142 Times in 535 Posts
Quote:
Originally Posted by cyler View Post
Seems I will have to temporarily substitute the getenv's with strings.
Good idea.

Environmental vars often cause problems in CGI.

Sorry, I can't help with C CGI debugging. I focus on PHP for web programming.

On the other hand, I have always found that print statements work well when debugging, even if it is so crude, it works well.

Maybe you can simply print to a string and pass it to your HTML when debugging. That is what I do, which does sound a bit primitive, I know.

Again, sorry, I use PHP on the server side for most web programming.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
multiprocess debugger rvan Programming 1 07-20-2007 04:14 AM
unix debugger naamas03 UNIX for Dummies Questions & Answers 1 09-14-2006 01:31 PM
Kernel debugger sriram.ec UNIX for Advanced & Expert Users 0 03-23-2006 06:06 AM
where to get Kernel debugger sriram.ec UNIX for Advanced & Expert Users 0 03-22-2006 09:51 AM
wdb debugger Sven28 Programming 4 12-07-2001 11:44 AM



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