using gdb

This is a discussion on using gdb within the C Programming forums, part of the General Programming Boards category; Hello everyone, I'm trying to learn to use gdb v5.3-25mdk (Mandrake Linux). I wrote a test.c file according to instructions ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    19

    using gdb

    Hello everyone,

    I'm trying to learn to use gdb v5.3-25mdk (Mandrake Linux).

    I wrote a test.c file according to instructions I found in "Sam's Teach Youself
    Linux Programming in 24 Hours"

    The test.c code is supposed to compile but produce a segmentation fault upon
    execution (which it does) as well as a core file (which I don't think it does).

    No core file is produced (that I can find with either ls or ls -a)???


    Here's the code:

    Code:
    static void fun1(void) {
       char *cp = 0;
    
       *cp = '!';   /*intentional bad dereference to produce segmentation fault*/
    }
    
    int main (int argc,char **argv) {
        fun1( );
        return 0;
    
    }
    The command for compiling is: bash$ gcc -g -D_GNU_SOURCE test.c -o test

    It compiles without error or warning.

    From bash$ ./test, I get "Segmentation fault".

    No core file.

    I ran bash$ gdb ./test core

    gdb tells me "/dir/dir/core no such file or directory"

    Have things changed for gdb since the book was published in 1999?

    Thanks

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    It's nothing to do with gdb. Linux can be set to dump core on segmentation fault, or not. Try typing ulimit -c 999999 before running the program. Then it should say "Segmentation fault - core dumped" or similar.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    19
    That worked!

    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. buffered vs unbuffered question
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 07-04-2008, 04:57 PM
  2. Memory allocation error
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2008, 03:24 PM
  3. Contiguous Array version of Linked List
    By ampersand11 in forum C Programming
    Replies: 19
    Last Post: 10-07-2007, 03:05 AM
  4. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  5. does gdb lie?
    By dinjas in forum C Programming
    Replies: 8
    Last Post: 03-10-2005, 04:17 PM

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