Skip to content

CIS380/toolchain-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CIS 380 Review Session


Usage Information

  • sample.c is compiled into the samp executable using make
    • Depending on an argument it calls different function.
    • 'm' => myFunction just adds numbers and prints.
    • 's' => segf segfaults.
    • 'f' => fork_example forks a child process and then waits on it.
    • 'u' => useAfterFree use after free error.
    • 'l' => leak creates a memory leak.
  • samp_san executable via make samp_san
    • Compilied with clang sanatizers turned on.
    • Use for memory leak and use after free.

Debugging with gdb

  • How to use:
    • Compile with -g flag (and - Wall)
    • start via $ gdb <executable>
    • Begin debugging (gdb) start <args>
    • Toggle in/out of terminal UI (TUI) via ctrl-x a
      • If the ui looks wonky, simple leave and re-enter ui mode.
  • Simple usage [use myFunction() ./samp m]
    • step (s)
    • breakpoint (b)
      • info breakpoints
      • d <breakpoint>
      • clear (Deletes all breakpoints)
    • continue (c)
    • finish (f)
  • How to debug with segfaults [use segf() ./samp s]:
    • backtrace (bt)
  • How to debugg multi-threaded programs [use fork_example() ./samp f]
    • set follow-fork-mode <child/parent>
  • Signal Handling
    • catch signal <code>
      • stops gdb from passing the signal to program
    • handle <signal> <action>
  • Sanitziers
    • Compile options for clang/gcc
      • Wrap malloc, free, etc.
      • Maintain metadata, find problems
    • Great for memory leaks, use after free, etc.
    • What do we need?
      • Compile options (see Makefile)
      • llvm-symbolizer
        • You probably need to install it (usually in the llvm package)
        • You may also already have it installed as llvm-symbolizer-6.0 or llvm-symbolizer-3.6
          • In either of these cases symlink the newer version to the default path
          • sudo ln -s /usr/bin/llvm-symbolizer-<version> /usr/bin/llvm-symbolizer
    • How to debug use after free [useAfterFree() ./samp_san u]
    • How to debug leak [leak() ./samp_san l]
  • Resources

TMUX (Terminal Multiplexing)

  • What does it do?
    • One ssh session, multiple terminals
    • Keep session state.
  • Basic operation
    • $ tmux new-session -c ~/path/to/project -s <name>
    • tmux attach -t <name>
      • tmux a for most recent
  • Once you're in...
    • prefix ctrl-b
      • most commands are prefix then action
    • Panes
      • horizontal split <prefix> "
      • vertical split <prefix> %
      • switch panes with arrow keys or h j k l (vim)
      • delete pane <prefix> x
    • Tabs
      • create <prefix> c
      • switch <prefix> <number>
  • Good Config

Git

  • I'm assuming you have basic git familiarity.
  • Collaboration
    • Often we are in a scenario when two people want to push to the same branch.
    • This creates a problem, as only one will be able to do it and the other will need to merge.
    • What we really want is whoever is second to have their changes be on top of first's.
    • git pull --rebase
      • Will apply the commits you are pulling under your current work.

Vim

  • I'm going to assume you're familiar with basic vim.
  • Settings
    • jj escapes to normal mode from insert mode.
    • Line numbering on.
    • Tabs are 4 spaces.
  • Extra goodies
    • ctrl p search for files in git repo which are opened in buffers.
      • :buffer or :b ...
        • d delete
        • p previous
        • n next
      • :b <Tab> to autocomplete with open buffers.
    • linting
    • auto formatting (with a .clang-format file)
      • Make one here, click on a line to see what it does.
      • Simply put it in the project root.
    • Good syntax highlighting
    • git integration
      • :GBlame = see who messed up the code
    • git line status
  • Plenty of plugins are there, check them out, look at ~/.vimrc

Makefiles

  • Most of what make is doing is dependancy resolution.
  • What comes before the : is a target.
    • What comes after are the things it depends on.
  • Beneath the target and dependancies is the receipe.
    • This means, given all the dependancies, it will construct the target.
  • Essentially, a Makefile defines a graph from your source files/directories to executable binaries.
  • Please see the Makefile in the repo for more details.

About

Files used for demoing tools, etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 54.1%
  • Makefile 45.9%