Quick Emacs/GDB (Unix) Question

This is a discussion on Quick Emacs/GDB (Unix) Question within the C Programming forums, part of the General Programming Boards category; Say I have a main.c So I run "gdb main.c" main.c calls/goes into a function in somefile.c How do I ...

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

    Quick Emacs/GDB (Unix) Question

    Say I have a main.c

    So I run "gdb main.c"

    main.c calls/goes into a function in somefile.c

    How do I set a breakpoint in somefile.c?

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Print this out and keep it near by whenever you need to use GDB: GDB Quick Reference card

    Looks like you'd type: b [file:]line
    ex. b somefile.c:31

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by cpjust View Post
    Print this out and keep it near by whenever you need to use GDB: GDB Quick Reference card

    Looks like you'd type: b [file:]line
    ex. b somefile.c:31
    Wow you are awesome! Worked like a charm!

    And this time I know that your red words = link

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Another quick question:

    When you are in Putty, and the cursor is at the top of the window, you press UP and it does a Page Up.

    Is there any way to scroll up line-by-line? (IE you press up, ONE line disappears at the bottom and ONE more line is visible at the top. Rather than 20 lines at a time). (Useful for when you want to keep looking at two different things in a file.)

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Putty is just a telnet client.
    Which editor are you using once you login? ex. vi, emacs...

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by cpjust View Post
    Putty is just a telnet client.
    Which editor are you using once you login? ex. vi, emacs...
    Oh, Emacs

    Is this particular functionality not controlled by Putty?

    If not, is there a way to change Emacs to do this?

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Paul22000 View Post
    Oh, Emacs

    Is this particular functionality not controlled by Putty?

    If not, is there a way to change Emacs to do this?
    I never use emacs, so I can't help much there; I just use plain old vi.
    Does anyone else here know how to change the behavior of emacs?

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by cpjust View Post
    I never use emacs, so I can't help much there; I just use plain old vi.
    Does anyone else here know how to change the behavior of emacs?
    Try adding this to your .emacs file:

    Code:
    (setq scroll-step 1)
    EDIT: You can do it interactively by typing:

    M-x set-variable <enter> scroll-step <enter> 1 <enter>

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by brewbuck View Post
    Try adding this to your .emacs file:

    Code:
    (setq scroll-step 1)
    Where can I find that file?

    (I'm using Putty to SSH into my school's Unix terminals)

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by Paul22000 View Post
    Where can I find that file?

    (I'm using Putty to SSH into my school's Unix terminals)
    It's a file in your home directory. If it's not there, create it and add that line to it (but it should be there)

  11. #11
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by brewbuck View Post
    It's a file in your home directory. If it's not there, create it and add that line to it (but it should be there)
    Created a " .emacs" file and added that line.

    Worked great!!! Thanks!!!

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    I have a while loop that just randomly stops on one of the iterations (after a few hundred times). How can I set a breakpoint (or a watch point) for that time?

    I set a breakpoint for the line number in the loop. Then set a watchpoint (watch variable="BLACK"). Then delete the breakpoint so it can keep running so I don't have go through all 500 loops. But inside the loop, a function is called, and once it goes to that function, the watchpoint is automatically deleted.

    Any tips?

  13. #13
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by Paul22000 View Post
    I have a while loop that just randomly stops on one of the iterations (after a few hundred times). How can I set a breakpoint (or a watch point) for that time?

    I set a breakpoint for the line number in the loop. Then set a watchpoint (watch variable="BLACK"). Then delete the breakpoint so it can keep running so I don't have go through all 500 loops. But inside the loop, a function is called, and once it goes to that function, the watchpoint is automatically deleted.

    Any tips?
    For purposes of debugging, alter the variable you are watching to be a global variable. That way, the watchpoint can persist across calls. Of course, change it back when done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

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