Monday, February 22, 2016

Step To Debug C Program in Linux Platform

**************** Step To Debug C Program in Linux Platform ******************

Step 1 : Write a C program and Compile it by using command

             gcc -g programname.c

Step 2 : Launch GNU debugger using Command

            gdb exename ( e.g gdb a.out)

Step 3 : Set Break Point as our choice by line number or function name.

           break line number/ function name

e.g   break 1  or break main

Step 4 : Run the program using the command

          run

Step 5 : For next step use S.  To print variable value use p variable name or print variable name.

e.g. p iNum

Step 6 : For exit debugging mode we have press q or quit .

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

We create Your own .c , .S .o and exe file

Step 1 : Create the file name as Demo.c

Step 2 : Compile that file using command

            gcc -S -o Demo.S Demo.c

S - Option to give assembly file.

o - Option to give output.

Demo.S - is Output File.

Demo.c - is Input File.

This command give the output file in assembly language named as Demo.S.

Step 3 : Pass that Assembly file to assembler which gives output as object file names as Demo.o

           as -o Demo.o Demo.S

Step 4 : Pass that object file to linker which gives output as a executable file.

           ld -o Demo -lc -dynamic -linker/lib/ld/linux.so.2 Demo.o -e main

-e - Option for entry point is main.
-lc - Option for linker.
ld - Option for loader.

Step 5 : Run that executable using command.

          ./Demo  

. - Option is current directory.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        

No comments:

Post a Comment

SYBSc (CS) Sem III : Data Structure Slip 14 Que - 2

  SAVITIBAI PHULE UNIVERSITY OF PUNE S. Y. B.Sc. (Computer Science) Semester III Practical Examination       SUBJECT: CS-233 Practical cours...