Thread: GDB Question??

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    167

    GDB Question??

    How do you make GDB step through function calls when the function is in a different .h/.cpp file (different class)?

    I had everything in one file, and when it seg faulted, it gave me the exact line within that class where the problem occurred. Now I just spent a ton of time separating everything out into different .h/.cpp files, and I have lost that functionality... Doh... It just says "seg fault in function of class x blah blah" without the line number.

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x08049c75 in Trie::Getptr2item ()
    No line numbers anymore

    -----

    Alternatively, is there a way to use Makefiles with Visual C++ (or any other Windows programs)?
    Last edited by Paul22000; 07-06-2008 at 09:51 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Set a breakpoint in said class. I don't remember how and haven't done it for years, but gdb has help.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Compile everything with the "-g" flag to get better debug information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by Salem View Post
    Compile everything with the "-g" flag to get better debug information.
    Genius!

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x08049c75 in Trie::Getptr2item (this=0x8100008, x=@0xbff898b8) at Trie.cpp:100
    100                     if ( current->Getptr(j) == 0 )
    My makefile was only using -g for the main program, not all the classes.

    Thanks!

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Another question: is there a way to run your main file in Visual C++ with command line parameters?

    In linux at my school, I do "./proj < input1.txt" (proj is my main)

    Is there a way to do that with Visual C++?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Project -> Settings.
    On the debug tab, you can set the command line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Yes, you can pass command line parameters to programs in Visual C++. Again, this is something you should be able to find if you do a modicum of searching in the help files, or just by poking around the VC++ interface.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by Salem View Post
    Project -> Settings.
    On the debug tab, you can set the command line.
    Ah yes, there we go.

    It keeps saying my file isn't found.

    If I put: "inputfile" it runs, but doesn't actually get that input (ignores what I typed)

    If I put: "< inputfile", it says file not found.

    Is the < valid? Or only linux?
    Last edited by Paul22000; 07-06-2008 at 10:54 AM.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Ah I see, I had to set the working directory field.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gdb command or alternative
    By trinli in forum C Programming
    Replies: 8
    Last Post: 05-15-2009, 11:49 AM
  2. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. gdb drive me crazy!!!!
    By gandalf_bar in forum Linux Programming
    Replies: 5
    Last Post: 04-07-2004, 06:38 AM
  5. Could someone explain this code, string
    By sjalesho in forum C Programming
    Replies: 7
    Last Post: 11-26-2003, 02:54 PM