Thread: debugging C code

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    10

    debugging C code

    Hi everyone,
    I have written a code for a single board computer (PC104). the board has linux as its operating system.
    I am having some trouble debugging the code. The way i am doin it now is to insert printf commands at several points in my code. the printf output is sent to a text file. I check the output of the program later on from this text file.
    Right now, When executing the code, the PC get stuck and I have to switch off the PC and turn it on again. I open the text file where i sent the printf commands to find it empty.
    Is the text file empty because I aborted the system while it was running the c code?
    Is there some error log I can access that saved the activities of my code?
    Note: I dont have a debugger on my sytem (dgb).
    Thanks.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Yep, the file is empty because you reset the computer before the buffers were written to disk.

    Have a look at fflush() in your library documentation.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    remote debugging with gdb - Google Search
    Seriously, try and get the remote debug up and running.
    You can spend days poking around with printf statements to guess where the problem is.

    You might need to do this
    fflush(fp);

    Or even fopen + fprintf + fclose each time you want to print a message.


    How much testing have you done on your host Linux system?
    Consider writing some wrapper code for any functionality that is specific to the SBC. You should be able to test at least 90% of the code on the host.
    Last edited by Salem; 03-14-2011 at 02:34 AM. Reason: Yet another double post
    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
    Feb 2011
    Posts
    10
    Thank you. I think I will use fflush for now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Illegal Instruction at perfectly fine Code
    By m00ni in forum C Programming
    Replies: 24
    Last Post: 02-14-2011, 02:56 AM
  2. dynamic array
    By mouse666666 in forum C Programming
    Replies: 36
    Last Post: 04-11-2010, 02:27 AM
  3. Replies: 8
    Last Post: 04-28-2003, 07:29 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Debugging leads to buggy code and longer hours?
    By no-one in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-28-2002, 11:14 AM