how to trace C in linux

This is a discussion on how to trace C in linux within the Linux Programming forums, part of the Platform Specific Boards category; Now I write a c program in linux using vi and gcc. But if there is something wrong in my ...

  1. #1
    Microsoft Lover afreedboy's Avatar
    Join Date
    Nov 2003
    Posts
    189

    how to trace C in linux

    Now I write a c program in linux using vi and gcc. But if there is something wrong in my program, i don't know how to trace.

    For Turbo C in windows, i just need to press F7 and add variables to watch by using Ctrl+F7. For Linux, anyone could tell me?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    used gdb, its the debugger

  3. #3
    Microsoft Lover afreedboy's Avatar
    Join Date
    Nov 2003
    Posts
    189
    Quote Originally Posted by Thantos
    used gdb, its the debugger
    Well, I am writing "more1" program now.

    I use gdb more1
    and then I type run
    just run.
    I want to trace and I found from googling, I should type step. So I type step. but gdb say your more1 is not running. So I try to type run abc.txt. And then it halt. How to trace line by line?

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    you need to set a breakpoint. type: "help b" without the "" to get the exact syntax. You can use list to show the 10 lines around the currentline along with the line number.

    So basic steps is:
    list to get the line number
    set the break point on the line you want
    run to start the program
    and then use step and next to move through the program

  5. #5
    .
    Join Date
    Nov 2003
    Posts
    307
    Try
    Code:
    gdb more1
    ....... you are now in the gdb program "gdb>" is the prompt.
    gdb> br main
    gdb> r
    ...............
    gdb> step
    you can use "print varname" to look at a variable named varname, "step" to execute the next line of code. To stop debugging type "quit"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 12:03 PM
  2. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  3. Dabbling with Linux.
    By Hunter2 in forum Tech Board
    Replies: 21
    Last Post: 04-21-2005, 05:17 PM
  4. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM

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