C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-10-2009, 03:01 PM   #16
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,845
Quote:
Meaning, the only way to know it was null was via printf. I am sure you can do that with gdb too, it is just 10x more awkward.
Run the command "backtrace full" after loading a core dump that occurred due to your NULL pointer. I guarantee that you would be able to fix your problem faster than you could with print statements. Even if you don't want to learn various gdb commands, the one command "backtrace full" will often times give you enough information to fix most issues. Just having the line number which caused the seg fault is extremely valuable. How long does it take you to narrow it down to the exact like with print statements? It takes me about 5 seconds with GDB.

The best thing about GDB is that most of the time you don't even need to run your application in GDB to solve crash issues. Just load the core dump after your application crashed, and take a look at the backtrace.
bithub is offline   Reply With Quote
Old 06-10-2009, 03:27 PM   #17
Registered User
 
Homer_Simpson's Avatar
 
Join Date: May 2009
Posts: 15
Talking

Quote:
Originally Posted by matsp View Post
I have probably spent more time in front of a debugger window than I have spent actually writing code - because when you get to LARGE code projects, often you track down bugs in some part of code that you have NO IDEA what it does, and it may be 15-20 calls from YOUR code to the actual place where it starts going wrong
Sounds like someone should have been using printf...
Homer_Simpson is offline   Reply With Quote
Old 06-10-2009, 03:51 PM   #18
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
Quote:
Originally Posted by Homer_Simpson View Post
Sounds like someone should have been using printf...
Yeah, because hey. Recompiling a twelve million line project because you inserted a printf() is oh so very efficient.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 06-10-2009, 03:57 PM   #19
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Quote:
Originally Posted by Homer_Simpson View Post
Sounds like someone should have been using printf...
I'm not talking about a few hundred lines of hobby code here. Just one of the smaller modules in the driver is 15K lines of code (about 400KB of code). Another module is 90K lines (about 3MB of code).

The total size of the driver code is about 24MB, and if we interpolate the above bits, that means somewhere around 400K lines of code. None of which I, or anyone else at my comapny, has written [well, ok so we have a few hundred lines of interface code, but 99%+ of the code is written by people we can't talk to directly].

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 06-10-2009, 11:02 PM   #20
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,355
Quote:
Originally Posted by MK27
I also work in more languages than just C, so it is nice not to be dependant on a method which requires more software which may not exist. They all seem to have a "print", tho.
Well, it is good to know how to use a hand driven screwdriver, but why should the possible lack of an electrically powered screwdriver stop you from using one when it is available and suitable for the job?

Quote:
Originally Posted by MK27
And printf does not fault on a null pointer, whereas some commands do. Meaning, the only way to know it was null was via printf.
Use assertions to document assumed facts in your code.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault problem odedbobi Linux Programming 1 11-19-2008 03:36 AM
Segmentation fault bennyandthejets C++ Programming 7 09-07-2005 05:04 PM
Segmentation fault NoUse C Programming 4 03-26-2005 03:29 PM
Locating A Segmentation Fault Stack Overflow C Programming 12 12-14-2004 01:33 PM
Segmentation fault... alvifarooq C++ Programming 14 09-26-2004 12:53 PM


All times are GMT -6. The time now is 03:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22