Lab 1

Know Your Tools

About Me

  • Wei-Chun (Steve) Lee
  • 2nd yr Master
  • Hobby: Violin, Basketball
  • Research Focus: Game Theory
  • Favorite Language: C++

Some Rules

Some Rules

  • Time: 10-minute rule.
  • Focus: Focus on lab material.
  • Do not forget to swipe out.
  • Email GA if you need an exemption.

Log in to your VMs

ssh NETID@fa16-cs241-xxx.cs.illinois.edu

Today's Mission

  1. Checkt out your SVN Repo.
  2. Write a (dumb) program.
  3. Play around with Valgrind and gdb.
  4. Add and commit your folder.

Valgrind

Valgrind

  1. A suit providing several tools.
  2. Memcheck is the most popular one.
  3. Memcheck detects memory-leak.

Valgrind-Usage

  1. Given a program test arg1 arg2.
  2. valgrind --leak-check=yes test arg1 arg2.

Example

#include <stdlib.h>
#include <stdio.h>
int main() {
    char* s = 0;
    scanf("%s", s);
    printf("%s\n", s);
    return 0;
}

Example - Demo

Popular Options

  • --leak-check=<no|summary|yes|full>
    • The way to show memory leaks.

Type of memory leak

  1. Memory block: a block of allocated, not-freed memory.
  2. Definitely Lost: No pointer to a memory block.
  3. Still Reachable: Have pointer to a memory block.
  4. Indirectly Lost: Memory blocks pointing to a memory block is lost
  5. Possibly Lost: Have a (moved) pointer pointing to a memory block

Reference: http://goo.gl/QMDDM

GDB

GDB

./gdb myProgram
./gdb --args myProgram arg1 arg2 arg3

Demo

Useful commands

  1. file: file source
  2. run(r): run program
  3. break(b) 90: set breakpoint
  4. delete(d) 1: remove breakpoint
  5. next(n): next line
  6. step(s): next line*

Reference: http://goo.gl/L5UreC

Questions?