Commit 0a028012 authored by Eric Krawczyk's avatar Eric Krawczyk
Browse files

add 9/17 discussion notes

parent d10fb3ef
## EECS 281 - Discussion
### 17 SEP 2015 - Testing, Debugging,
#### Intro
- Laura
#### Makefile
- invoking g++ from CLI is verbose
- easy to mess up
- `g++ main.cpp -o main.cpp` will fuck your source.
- `make` is easier to type.
- Makefile structure
- Macros (kinda like vars)
- targets eg `all: <dependencies>`, `proj.o: <dependencies>`, `clean:`, etc.
- object files are already compiled
- object files are then linked into the executable
- Executable dependencies
- data.o
- dependent on data.c and data.h
- main.o
- dependent on data.h, main.c, common.h
- io.o
- common.h, io.h, io.c
#### Valgrind
- Detects undefined behavior
- out of bound read/writes (eg. index vector past scope)
- Memory leaks
- STL is good at managing memory though
- plugins!
- `callgrind` - program speed (akin to `gprof`)
- `massif` - profile mem usage
- `helgrind` - threads and stuff (not super applicable to 281)
- run valgrind before submitting. just do it.
- must compile in debug mode (with `-g` flag)
- `valgrind ./program -args`
- `--leak-check=full` for full details of leaked memory
#### GDB
- GNU debugger!
- Useful for testing segfaults
- must compile in debug mode (with `-g` flag)
- cool commands are cool (slide 11)
- `gdb program`
- `break 9` (alt `b 9`) - break at line 9
- `next`/`n` - advance lines
- `print <stack>`
- `continue` - continue running program
- `quit` to exit
#### Unit Testing
- test chunks of code
- separate class of tests
- simple unit testing with `assert`
- `assert`
- C++ Macro
- assert(true)
- run tests when changing code
#### I/O
- i/o options
- cin
- cout
- cerr
- ifstream
- ofstream
- fstream
- i/o redirection
- `./prog < input.txt > output.txt` - sh parses `<` and `>` as input/output commands (they're NOT args)
- input
- `getline(cin, var)`
- `cin >> var`
- mixing them [gets weird](http://40.media.tumblr.com/e434240766c765eff72e27a378a683e9/tumblr_n2yo2if9iR1twc22ho1_1280.jpg)
- endl is slow
- use `ostringstream` for speed!
- `ostringstream ss`
- write to ss
- `cout << ss.str();`
- `std::ios_base::sync_withstdio=false` will speed up shit
- but valgrind will be mad
#### getopt
- for flags
- `getopt_long` is for `--stuff`
- make a struct defining args
- `optarg` c-string of argument
- char *
- `case '?':` fallback for unknown flags
#### CAEN Remote
- Virtual Sites
- VNC
- `ssh`
- puTTY for wandowz
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment