Technotronics GCECT '091 Decode C This is a C Programming event, where you will be given problems to solve using C only. You will be given a Linux system.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Compiling. Your C, C++ or Fortran program won’t work unless you compile it The compiler will build your program as an executable file (typically in the.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
CS 202 Computer Science II Lab Fall 2009 September 24.
Linux/g++: Maze solving in CSE326. Linux machines at U. W. Machine Names: Ceylon, Sumatra, Fiji, Tahiti
1 UQC122S3 Real-Time and Embedded Systems GCC as a cross compiler.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Building User Libraries.
Guide To UNIX Using Linux Third Edition
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
1 CS 161 Introduction to Programming and Problem Solving Chapter 10 g++ Compiler Usage Herbert G. Mayer, PSU Status 10/21/2014.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
F13 Forensic tool analysis Dr. John P. Abraham Professor UTPA.
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Using Visual Studio 2013 An Integrated Development Environment (IDE)
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
CSC 215 : Procedural Programming with C C Compilers.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Programming With C.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
UNIT 13 Separate Compilation.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
ECE 103 Engineering Programming Chapter 9 gcc Compiler Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Minimal standard C program int main(void) { return 0 ; }
The Development Process Compilation. Compilation - Dr. Craig A. Struble 2 Programming Process Problem Solving Phase We will spend significant time on.
CS431-cotter1 Linux Programming, Processes, and Threads Man pages (fork, clone, execve, pthread_create) The Linux Programming Interface – Kerrisk, No Starch,
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
 Prepared by: Eng. Maryam Adel Abdel-Hady
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
KYC - Know your compiler Introduction to GCC
DEBUG.
Introduction to C Topics Compilation Using the gcc Compiler
a.k.a how we test Your code
CSC 215 : Procedural Programming with C
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Debugging with gdb gdb is the GNU debugger on our CS machines.
Day 01 Introduction to Linux and C
A Guide to Unix Using Linux Fourth Edition
Introduction to C Topics Compilation Using the gcc Compiler
CSE 351 Section 1: HW 0 + Intro to C
CS1010 Programming Methodology
Introduction to C Topics Compilation Using the gcc Compiler
CS1010 Programming Methodology
gdb gdb is the GNU debugger on our CS machines.
Operating System Discussion Section.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Program Control Structures
Compilers, Make and SubVersion
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
Functional interface.
Hacettepe University Computer Engineering Department
CSE 303 Concepts and Tools for Software Development
Appendix F C Programming Environment on UNIX Systems
Chapter 1 Introduction.
Video Notes.
Introduction to C Topics Compilation Using the gcc Compiler
Debugging.
Makefiles, GDB, Valgrind
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Presentation transcript:

Technotronics GCECT '091 Decode C This is a C Programming event, where you will be given problems to solve using C only. You will be given a Linux system with gcc, as the default C compiler. You may use gdb for debugging. Use of headers other than stdio.h, stdlib.h and math.h is probihited.

Technotronics GCECT '092 About the gcc compiler GCC stands for GNU Compiler Collection. It comprises of many language compilers like C, C++, Objective C, Java and Fortran. To compile your C file with gcc use the following minimal command line: gcc [ -o -g -lm ] The options in third brackets [] are optional and if omited a.out is the default output file.

Technotronics GCECT '093 More about gcc To add debug symbols to your output file, the optional command line option -g is used. This is useful when debugging your compiled file with gdb. The command line options -lm for linking math libraries. The command line options, which are present in pairs, may be present anywhere. For example: gcc -o my.out my.c is the same as gcc my.c -o my.out

Technotronics GCECT '094 Even some more about gcc To only compile a file (and not link), use the -c command line switch. You will get a corresponding.o file. To view all warnings generated by gcc use the command line switch: -Wall. For additional you may view the man page of gcc with man gcc or you may want to run gcc -- help.

Technotronics GCECT '095 Running compiled programs Since. is not included in the path, you have to execute the output file with the command at the shell prompt: $./a.out (If the output file is a.out). To pass arguments to the command line just type the arguments after the file-name. To divert command line arguments use the '<' operator. E.g., to divert inputs from a file: inp.in to a.out use: $./a.out < inp.in

Technotronics GCECT '096 Source Files The main source file of your solution must be named as main.c (a rule of the event, not gcc!). To use / compile multiple source files, you can use the command line option: gcc main.c... [ -o ] Also note that your source files must end with a lower case 'c' not a higher case 'C' or it may be assumed to a C++ source file.

Technotronics GCECT '097 Debugging Debugging is the process of inspecting a program to find out it's potential or known bugs. Bugs are programming mistakes that are generally hard to detect but debugging makes this process much easier. We will provide gdb and gdbtui as debuggers. To start debugging use: gdb [ ] You may alternatively also use gdbtui, however it's interface is a bit buggy.

Technotronics GCECT '098 Debugging with gdb To view the program source, use the command: (gdb) list If you omit, the from the gdb prompt, use the command to load the output file (if called a.out): (gdb) file a.out Reading symbols from /home/gcect/C/Problem1/a.out...done. To start running the program, use run command.

Technotronics GCECT '099 Debugging – Crashes To inspect crashes, you have to use breakpoints or inspect other data like stack information. To see the stack trace, use the command: backtrace. To set break-points use the command: break. For setting a break-point before main : (gdb) break main Breakpoint 1 at 0x8049b6c: file myfile.c, line 33.

Technotronics GCECT '0910 Debugging - Navigation Once you have paused at the first break-point you might want to step through the execution. A few modes of stepping in gdb are given below along with the corresponding command: Step into (for n-lines) : step [n] Step over (for n-lines) : next [n] Run till n-counts or next breakpoint : continue [n] Jump to specified line number (n) : jump n Return from current function : return [retval]

Technotronics GCECT '0911 Debugging – Data The print or p command is really helpful in gdb. print Format may be one of x (hex),d (signed int),u (unsigned int),o (octal),c (char),f (float). (gdb) p /x x $1 = 0x33 The output is in the form of $a, where a is a whole number. Thus the value of 'x' is 51 (decimal) or 33 (hex).

Technotronics GCECT '0912 Debugging - Breaks To set a break-point at the line number 17 (just for example) : (gdb) break 17 To set conditional break points use : break [ ] if (gdb) break 107 if x == 50 To enable or disable break points use the commands enable and disable followed by the break-point number.

Technotronics GCECT '0913 Debugging – Data manipulation Continuing from the earlier example, the output with $a can be used to compute values in gdb. To change the value of data use: (gdb) set variable x=15 In order to get / set the values of variables in a different stack frame (i.e., in a different scope), use the scopr resolution operator preceded by the name of the function it appears in. Example: (gdb) p main::x $2 = 15

Technotronics GCECT '0914 Common Pitfalls The return type of main must be int and not void. Thus void main is wrong. The header files conio.h and alloc.h are not available in gcc. So getch() will not work. The Dynamic Memory Allocation routines are found in stdlib.h