On Fri, 3 Nov 2000, Mike Redick wrote: > Ok... one more question then... how do you go about fixing a segmentation > fault? I'm not even exactly sure what one is.. :blush: > First, run for cover! I'm willing to lay money on a wager that you're going to be flamed very soon. Asking how to fix a seg fault is akin to asking how to write a book, very nebulous. ;) It all depends on the cause. Some of the common ones that I've come across are NULL pointers being dereferenced, such as ch pointing to NULL and then GET_NAME(ch) being used, writing past the boundary of a char array, and dereferencing a non-initialized variable. The difference between the last and first in that list is sometimes the non-initialized variable doesn't cause a segmentation fault immediately, sometimes you actually get back a garbage value. As for how to fix it, find the line that's causing the seg fault (using gdb or ddd or whatever your favorite debugger is), and, well fix the line. :) Try printing the value of the variable referenced if you can. Sometimes a backtrace is enough and you'll see the line and right away hit your forehead because it was so obvious and you missed it. Sometimes you'll have to list the lines around it to see if there's any possibly damaging statements that could come before. And for when you get those very annoying ?? frames from the backtrace, there's not much I know of to get info out of gdb when that happens unless gdb is attached to the process running. In which case I don't get those ?? frames, and can inspect all the values I want. Inside gdb you can type help to see a list of topics and help topic to get information on how to use the commands inside gdb. Todd Laycock +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 04/11/01 PDT