CS136 - Tools and Techniques for Software Development
T 12:30PM - 2:20PM
MC 3003
Ege Ciklabakkal

0 | Linux Shell

0.1 | Introduction

ssh watiam@linux.student.cs.uwaterloo.ca
yes
password
echo $0
bash --version

0.2 | Basic Commands

ls
ls -a
ls -r
 
man ls
 
pwd
 
cd /usr/share/dict/
 
mkdir testing
DirectoryMeaning
.Current Directory
..Parent Directory
~User’s home directory
~useridUserid’s home directory
/Root Directory
starts with / or ~Absolute Path
Does not start with / or ~Relative Path

0.3 | More Commands

cat /usr/share/dict/words
 
cp main.c backup/main.c
 
mv hello.c backup/hello.c
 
zip file.zip foo1 foo2.txt foo3.out
 
find . -name .gitignore
 
alias marmsubmit="/u2/cs136l/pub/marmoset_submit"

0.4 | “Remote” Commands

scp hello.c watiam@linux.student.cs.uwaterloo.ca:~/cs136/a1/main.c

0.5 | Shortcuts

Ctrl + c = Kill the shell process Ctrl + d = End-of=file signal, process the input

0.6 | Editors

vi / vim cheat sheets

  1. https://cheatography.com/ericg/cheat-sheets/vi-editor/
  2. https://i.imgur.com/YLInLlY.pngi
keystrokesMeaning
:wsave
:wqsave and quit
:q!force quit without saving
Aappend to end of current line
Iinsert at the beginning of current line
bgo to the beginning of the current word
ego to the end of the current word
yycopy the current line
Xyycopy X lines starting at the current line
ppaste a line of copied text
dddelete the current line
Xdddelete X lines starting at the current line
:numshow current line number
gggo to the first line in the file
Ggo to the last line in the file
XGgo to line number X

0.7 | Streams

wc < /usr/share/dict/words # input redirection
wc /usr/share/didct/words # CLI argument (adds file name too)
 
< # stdin
> # stdout
&> # stderr
 
echo "text" > hi.txt
touch hi.txt # allows echo with >> to not output

0.8 | Terminal Configuration

PS1="Laptop Prompt \$" # note there is no whitespace between PS1, = and "
PS1="\u@\h:\w\$"
cp ~/.profile ~/.profile_backup
source my_customizations

0.9 | Summary

clang -o myprog hello.c
./myprog < myinput.txt > myoutput.txt

1 | More Linux Shell

1.1 | Globbing

Globbing Pattens / Wildcard Matching

  • ? matches one character - ?.txt is any one char
  • * matches zero or more characters - *.txt ends in txt
  • [] specifies one character from a set [aeiou].txt is a vowel
  • [!] is the inverse - [!aeiou].txt is not a vowel
  • {} is a way to say “or” - *.{cc,cpp} is anything ending in cc or cpp

Use 'single' or "double" quotes to suppress globbing

1.2 | Pipes

head - c 20 sample.txt # -c is bytes, -n is lines
head -n 20 sample.txt > first20.txt
wc -w < first20.txt # coutns the number of words
head -n 20 sample.txt | wc -w
cat sample.txt | head -n 20 | wc -w
cat words*.txt | sort | uniq
shuf entrants.csv | head -n 10
shuf entrants.csv | head -n 10 | cut -f2 -d,
shuf -n 10 entrants.csv | cut -f2 -d,

1.3 | Embedded

echo "It is currently $(date) and I am $(whoami)"
echo 'It is currently $(date) and I am $(whoami)' # suppresses formatting
wc $(cat myfile.args) myfile.txt # runs wc on the txt file with the args file

1.4 | egrep

egrep CS136 sample.txt # is the same as
cat sample.txt | egrep CS136
 
| # and then
-i # case insensitive
"" # ignore egrep
cs136|CS136 = (cs|CS)136
[cC][sS]136 = (c|C)(s|S)136
[[:alpha:]] = [A-Za-z].
[^abc] = # not a,b,c
cs*(136) = # 136, cs136, cscs136
cs+(136) = # cs136, cscs136
(cs)?135 = # 136 or cs136
.* = #anything
^cs136 = # line starts with cs136
cs136$ = # line ends with cs136
\. = # escape character then period

1.5 | File Permissions

ls -l # file perms
OwnershipChanging Permissions
uowner/user
ggroup
oother
aall
Operator
+add permission
-revoke permission
=set permission exactly
Permission
rread
wwrite
xexecute
chmod o+r file.txt # adds read perms
chmod g-x *.sh # revokes executing perms for all files ending in .sh
chmod a=rx file.txt = all users are read and execute
 
# chmod could alo be binary
# 756 would translate to 111101110 since 7 is 111, 5 is 101 and 6 is 110
# 777 would be 111111111 = everything (rwx)

1.6 | Quick Reference

Commands

CommandMeaningOptions
exitlog out
passwdchange your password
clearclear screen
man commandshow the manual page for commandman -k word shows a list of man pages that mention word
historyshow all previously-issued commands
whoamidisplay your login name
datedisplay current date and time
pwddisplay current directory
lslist contents of current directoryls -a show all files, including hidden files,
ls -l show in long format
cp file1 file2copy file1 to file2cp -r dir1 dir2 recursively copy dir1 to dir2
mv file1 file2move file1 to file2 (also used to rename)
rm fileremove filecan be used to recursively remove a directory, if -r option is used
touch fileupdate file’s last modified time to current timecan be used to create an empty file if file does not exist
cd dirchange directory to dircd - return to most recently visited directory
mkdir dircreate new directory dir in current directorycan specify more than one directory at once
rmdir dirremove directory dironly works if dir is empty; if not empty, use rm -r dir; can specify more than directory at once
echo stringdisplay string to screen
chmod perms fileset permissions on file to perms
psdisplay current processesps -a show all users’ processes,
ps -A show ALL processes (incl. system processes)}
kill pidkill process with number pidkill -9 pid more forceful kill, for stubborn processes
whoshow who is logged into this machine
time commandshow amount of time taken executing command
fgbring background job to the foregrounduseful if you accidentally ran vim or emacs with an & (causing it to run in the background)
find dir -name “pattern”find all files whose names match pattern in dir and its subdirectories
zip file.zip file1 [more files]create a zipped archive named file.zip containing the files given as arguments-r to recursively compress/archieve directories
Tools
ToolPurposeOptions
cat f1 f2 …display files f1, f2, … one after the othercat -n f1 f2 … attaches line numbers
less filedisplay file one screen at a time
diff f1 f2compare files f1 and f2; outputs instructions for converting f1 to f2diff -w f1 f2 ignores whitespace
cmp f1 f2compare files f1 and f2; outputs the first position where they differ
wc filecount the number of words, lines, and characters in filewc -c file show just the number of characters
wc -l file show just the number of lines
wc -w file show just the number of words
egrep pat fileprint all lines in file that contain pattern pategrep -n pat file print matching lines with line numbers
egrep -v pat file print lines that do not match pat
egrep -i to ignore case
egrep -o only print matches
head fileprint first 10 lines of file-num prints num lines (e.g. head -5 file)
head -n as alternate syntax
tail filelike head, but prints last 10 lines of filetail -n +N instead of last 10 lines, output starting from line N
sort filesorts the lines of filesort -n file sorts strings of digits in numerical order
uniq fileremoves consecutive duplicate lines from fileremoves all duplicates if file is sorted
shuf filerandomly shuffles the lines in fileshuf -n num outputs num random lines from file
cut options fileextract portions from each line in filecut -fN -dD extract field N from each line, where fields are separated by a delimiter D
Programs
ProgramPurposeOptions
vim fileinvoke vi IMproved text editor on file
vi fileinvoke vi text editor on file (often redirects to vim)
emacs fileinvoke emacs text editor on file
nano fileinvoke nano text editor on file
wget urlfetch file from the web at url
curlused to transfer data
less fileused to view file contents one screen at a time
xpdf filedisplay pdf file (requires the ability to launch graphical programs)
ssh machinemake SSH connection to machine; opens a secure shell on remote machine; type exit to end SSH connectionssh -Y (or -X) machine enable X forwarding to allow use of graphical programs (must have X server running on local machine)
scp mach1:file1 mach2:file2securely copy file1 on mach1 to file2 on mach2can omit mach1 if it is the local machine; similarly for mach2

2 | Testing and Debugging

2.1 | Terminology

Black Box Testing = When tester has no/minimal knowledge of implementation

  • Corner case = more than one edge White-box = Tester has full knowledge of implementation Unit testing = Testing components in isolation Regression testing = All tests should be rerun after a code change

Errors

  • RTE = Illegal operation (div 0)
  • Logical error = logical msitake
  • Memory error = unexpected / illegal memory use (eg. trying to read value in a variable with no value, or trying to access memory outside of allocated memory)

2.2 | Assertion-based Testing

speaker that’s an assertion

2.3 | I/O Testing

Test Harnesses = a program that is used to test specific functionality of a program or its subset

CS136

  • .in = input
  • .expect = output
$>cat sqr_test1.in
1 5
  
$>cat sqr_test1.expect
Squaring 5 gets us 25
 
$>cat abs_test1.in
2 -42
 
$>cat abs_test1.expect
Absolute value for -42 is 42
 
# What does Run with Tests do?
./myprogram < test.in > test.out
diff test.out test.expect

2.4 | Debugging

Common Bugs

  • Using = instead of ==
  • Using less than (<) where less than or equal () or greater than (>) is needed, or vice versa
  • Using greater than (>) where greater than or equal (>=) or less than (<) is needed, or vice versa
  • Off by one errors; often due to the two mistakes highlighted above
  • Using bitwise or (|) where they intended to use logical or (||)
  • Using bitwise and (&) where they intended to use logical and (&&)
  • Not checking return values e.g. read_int or scanf returns whether the read was successful
  • Dereferencing a NULL pointer
  • Dereferencing an incorrect or dangling pointer

3 | Shell Scripting

3.1 | Introduction

#!/bin/bash 
#File: basic.sh
# a script that prints the date, current user and current directory 
date 
whoami 
pwd
 
# alternate first line
#!/usr/bin/env bash
 
# executing (1)
./basic.sh
chmod a+x basic.sh
 
# executing (2)
bash filename

3.2 | Shell Variables

x=1 # string
fullname="Nomair Naeem"
echo ${x} #good practices
 
word=hard
echo ${word} #hard
echo ${word}er #harder
 
echo "$course" #/courses/CS136L
echo '$course' #$course
 
echo ${PATH} # /usr/bin/clang_14.0.0/...
VariableMeaning
${PWD}present working directory (equivalent to executing pwd)
${HOME}your home directory (equivalent to ~)
${SHELL}your default shell
${PRINTER}your default printer
${HOSTNAME}your machine’s name
${PATH}your default search path for commands and programs

3.3 | Command Line Arguments

VariableMeaning
${0}name of currently-running script
{2},…arguments 1, 2, … of current script/function
${#}number of args supplied to current script/function (not including script name)
${@}all args supplied to current script/function as separate strings (not including script name)
#!/bin/bash
#usage:  ./isItAWord.sh [word]
egrep "^$1$" /usr/share/dict/words
 
#assumes that isItAWord is available in the environment
./isItAWord.sh hello # hello
./isItAWord.sh hel # nothing
 

3.4 | Reading from Standard Input

#!/bin/bash
#usage:  ./isItAWordFromStdin.sh
 
echo -n "Input word: "
read input
egrep "^$input$" /usr/share/dict/words
 
# difference: script prompts the user to "Input word:"
 
#!/bin/bash
#usage:  ./isItAWordFromStdin.sh
 
read -p "Input word: "
egrep "^${REPLY}$" /usr/share/dict/words

3.5 | Conditional Statements

test 1 -eq 2 # OR
[ 1 -eq 2 ]
# 3 CLI arguemnts which represent the test that evaluates whether 1=2
# NOTE: whitespace here matters
 
$[ 1 -eq 1 ]
$echo $?
0
$[ 1 -eq 2 ]
$echo $?
1
$echo $?
0 # success code
Operator(s)Meaning
==, !=string equality and inequality
-eq, -neinteger equality and inequality
-gt, -geinteger greater than, integer greater than or equal to
-lt, -leinteger less than, integer less than or equal to
deprecated: -a, -oand, or
!negation
-efile exists
-dfile exists and is a directory
-ffile exists and is a regular file
-r, -w, -xfile exists and is readable/writable/executable
-zcheck if the length of a string is zero
[ -e $filename ] # checks whether the file exists, unary operator
 
[ expr1 -eq expr2 -a expr3 == expr4 ]
[ expr1 -eq expr2 ] && [ expr3 == expr4 ]
[ $var -gt 5 ] && [ $var -lt 10 ]
[ -f $file ] || [ -d $file ]
# use $$ and || instead of 'and' and 'or'
[[ 1 -eq $var && -r $file ]]
# [[]] allows you to use &&, || without wrapping in []
 
#!/bin/bash
#usage: ./goodPassword.sh [word]
egrep "^$1$" /usr/share/dict/words > /dev/null
if [ $? -eq 0 ]; then 
   echo Not a good password
else
   echo Maybe a good password
fi # reverse if, closes it off
 
# REVISED
 
#!/bin/bash
#usage: ./goodPasswordWithChecks.sh [word]
usage() {
  echo Usage: $0 password
}
if [ $# -ne 1 ]; then
  usage
  exit 1
fi
egrep "^$1$" /usr/share/dict/words > /dev/null
if [ $? -eq 0 ]; then 
   echo Not a good password
else
   echo Maybe a good password
fi
 
# CONCEPT CHECK
#!/bin/bash
course="CS136L"
 
if [ $course == 1 ]; then
  echo Found
else
  echo Not Found
fi

3.6 | Loops

#!/bin/bash
#usage: ./OneToN.sh [number]
x=1
while [ $x -le $1 ]; do # $1 as in the first argument
   echo $x
   x=$((x+1))
done
 
# UPDATED
 
#!/bin/bash
re='^[1-9][0-9]*$'
if [ $# -ne 1 ]; then
  echo Usage: $0 [positive integer]
  exit 1
elif ! [[ $1 =~ $re ]]; then
  echo "Argument provided is not a positive integer"
  exit 2
fi
 
x=1
while [ $x -le $1 ]; do
   echo $x
   x=$((x+1))
done

#!/bin/bash
for x in a b c d
do
  echo $x
done
 
for item in a b c d; do echo $item; done
 
mv ${filename} ${filename%cpp}cc # % truncates cpp from strings
 
#!/bin/bash
for filename in *.cpp; do
  mv ${filename} ${filename%cpp}cc
done
 
#!/bin/bash
# Usage: ./countWords.sh word file
count=0
for word in $(cat $2); do # without brackets, this would return 0
   if [ $word == $1 ]; then  
      count=$((count+1))
   fi
done
echo $count
 
# QUESTION 1
 
#!/bin/bash
# Usage: ./ArgIterator.sh [any number of arguments]
while [ "$1" != "" ]; do
  echo "Number of arguments is $#"
  echo "Argument 1 is: $1"
  shift
done
 
# QUESTION 2
 
#!/bin/bash
sum=0;
for n in "$@"; do
  sum=$((sum+n))
done
echo $sum

4 | IDEs and VSCode

4.1 | Setup

Extensions

  1. C/C++ Language
  2. Remote Development

Working Remotely

watiam@ubuntu2204-004.student.cs.uwaterloo.ca

4.2 | Editor

4.3 | The clang Compiler (DON’T PUBLISH THIS)

Running code

  1. Open a terminal and compile with command line
  2. Set up a compiler and debugger to use VSCode GUI

Common compilers

  • Microsoft Visual C/C++ Compiler
  • GNU Compiler Collection (gcc)
  • clang/LVVM
    • We MUST use this for CS136
$which clang
/bin/clang
 
$clang --version
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /bin
 
clang main.c 
./a.out 
./a.out < test.in > test.out
 
clang -std=c99 -g -Wall main.c -o myprogram
 
CFLAGS="-std=c99 -g -Wall -I/u2/cs136l/pub/common"
clang ${CFLAGS} main.c /u2/cs136l/pub/common/cs136.o -o myprogram
 
clang change.c 
# runs change.c
clang -std=c99 -Wall main.c -I/u2/cs136l/pub/common executable.c myexec.c -g
# produces the executable a.out
clang main.c linalg.o vec.o -I/u2/cs136l/pub/lab4/q2 -o mathlib
# same as
clang main.c linalg.o vec.o -o mathlib -I/u2/cs136l/pub/lab4/q2
 
clang -O2 main.c
# does moderate optimization

4.4 | Compiling via VSCode

#tasks.json

"tasks": [
  {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/clang",
            "args": [
                "-fdiagnostics-color=always",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "compiler: /usr/bin/clang"
        }
	]

5 | Git and Version Control

5.1 | Introduction

Core Concepts

  • Repository (repo): The location of the canonical/main version of source code
  • Working Directory: Copy of repository where you make changes before saving them
  • Staging area: Local collection of changes in working directory that you want to collect

Repositories can be local or remote

  • Local = storing projects only for yourself
  • Remote = Setup on a central server (GitHub)

git help X where X is any command is pretty helpful

5.2 | Basics

  • git init creates a .git directory
  • git status shows status (git status > step1.log) redirects output
  • git add tells git to track a file
  • git commit -m "message"
  • git log shows a log
  • git diff shows differences (eg. git diff --staged hello.c)
  • git rm removes a file and tracks it (same as rm main.c and git add main.c)
  • git mv moves a file
  • git clean shows which files are untracked

5.3 | Branches

master is the default, auto-created branch. note that HEAD does not always point to master

  • git branch makes a branch
  • git checkoutswitches branches
  • git merge merges branches

5.4 | Collaboration

git init initializes a local repository, but if we wanted to make a remote one:

  • git init -- bare initializes a remote repository
  • git push (origin master) uploads changes to remote repo
  • git pull downloads changes
  • git clone creates an existing copy

5.5 | Merging

Say we wanted to merge editor_prototype with master

  • git merge editor_prototype
  • git branch -d editor_prototype deletes the old branch

Merge Conflicts

  • are really annoying

5.6 | Undo

  • git revert inverts the changes in a specific commit, given the commit ID
  • git reset resets the HEAD and referenced branch to the specified commit ID
    • --hard is dangerous and resets the staging area and working directory
    • --mixed resets the staging area
    • --soft only updates HEAD and branch reference
  • git checkout is used to switch branches, but can also switch commits and individual files
    • $git checkout [SHA-1_for_a_commit]; -- path/to/file

5.7 | Git in VSCode

exists

6 | C/C++ Preprocessor

6.1 | Introduction and Header Files Includes

Specifying Header Files

  1. Angled brackets: for files in the standard C library
  2. Double quotes: for files you create
clang -E hello.c

6.2 | Macro Expansion

We used to use define, now we use const

const int x = 10;
  
int array[x];

6.3 | Conditional Compilation

Directives for conditional compilation:

  • #if, #ifdef, #ifndef, #elif, #else and #endif
  • At compile time if the condition is true (nonzero), block following the condition is forwarded to the compiler
#ifdef __unix__ /* __unix__ is usually defined by compilers targeting Unix systems */
# include <unistd.h>
#elif defined _WIN32 /* _WIN32 is usually defined by compilers targeting 32 or 64 bit Windows systems */
# include <windows.h>
#endif

6.4 | Commenting and Debugging

#include <stdio.h>
 
int main(void) {
  #ifdef DEBUG
  printf("Setting x to  1\n");
  #endif
  int x = 1;
  while (x < 10) {
    ++x;
    #ifdef DEBUG
    printf("x is now %d\n",x);
    #endif
  }
  printf("%d\n",x);
  return 0;
}

To turn debug on/off

clang -E -DDEBUG debug.c

6.5 | Include guards

Using include guards requires that every header file in the program adhere to the following pattern (include guards are not added in implementation files):

#ifndef UNIQUE_MACRO_NAME
#define UNIQUE_MACRO_NAME
// original header file
#endif

7 | Memory Checkers

7.1 | Introduction

Valgrind (the memcheck detector in Valgrind)

  • Use gcc
  • CS246 requires g++ and valgrind
  • valgrind ./prog
gcc -Wall -g -O0 test.c -o test
valgrind ./test

AddressSanitizer (asan)

  • Only produces output if something goes wrong
clang -O1 -fsanitize=address -fno-omit-frame-pointer -Wall -g test.c -o test
./test

Compiler flags/arguments

  • -wall turn on all warnings
  • -g0 produces debugging info
  • O0 turns off optimizatinos
  • -0 specifies the name of the executable file

7.2 | Uninitialized Memory

// File test1.c
#include <stdio.h>
 
int main(void){ 
  int i;
  printf("%d",i); 
  return 0;
}

Compiler initializes all variables to 0 - bad idea

7.3 | NULL addresses

Don’t dereference it - this compiles, then crashes at execution

// File test3.c
#include <stdio.h>
 
int main(void){
  int *p = NULL;
  *p = 5;
  printf("%d\n",*p);
}

7.4 | Buffer Overflow

This compiles but prints garbage output

//File: buffer1.c
#include <stdio.h>
 
void print_element(int *arr, int index){
   printf("%d",arr[index]);
}
int main(void) {
  int a[10] = {0};
  print_element(a,10);
}

Buffer error, detectable with clang -fsanitize=addres O0

#include <stdio.h>
int main(void){
  int a = 5;
  printf("%d\n",*(&a + 1));
}

7.5 | Improper Stack Use

Compiles, crashes, produces garbave

// File stack0.c
#include <stdlib.h>
#include <stdio.h>
 
char *get_hello(){
  char str[20] = "Hello World!"; 
  char *toRet = str;
  return toRet;
}
int main (){
  printf("%s\n",get_hello()); 
  return 0;
}

7.6 | Heap Memory

What might go wrong?

  • Incorrect call to malloc
  • Invalid free
  • Premature free

Compiles but crashes

// File: heap3.c
#include <stdlib.h>
 
void memory_cleanup(int *memory){
  free(memory); 
}
 
int main (){
  int elements [3]; 
  memory_cleanup(elements);
  return 0; 
}

7.7 | Linked Structures

May be asked to determine how many bytes were leaked

8 | Separate Compilation and Build Automation

8.1 | Separate Compilation

clang *.c clang vec.c linalg.c main.c; echo 'Done compilation'

clang -c vec.c # NOTE: -c means separate, non-linked compilation
clang -c linalg.c
clang -c main.c
echo Done

Header (.h) files: We don’t provide header files: Header files are meant to be included and implementation files compiled. Object (.o) files: An object file contains the binary for the compiled code and additional information for the linker such as what identifiers are defined by the file and what identifiers are required.

clang -c vec.c
clang -c linalg.c
clang -c main.c
echo Separate Compilation Done
clang vec.o linalg.o main.o -o myexec
echo Linking Done
./myexec
echo Running Program Done

Order of executable components: Preprocessor, Compiler, Linker

8.2 | Build Automation

Modern build automation software can be used to perform a variety of tasks such as:

  • downloading and importing new versions of libraries being used
  • automatically retrieving the latest version of the source code e.g. from a git repository
  • running a code analysis tool against the source code to check for suspicious code, formatting etc.
  • running a documentation tool to generate revised documentation
  • building a directory structure containing images, fonts and other resources for the executable to use
  • compiling the code, to one or more targets e.g. iOS and Android
  • running and reporting on automated tests
  • creating an installer so that the program can be easily deployed

Popular build automation software

  • Make
  • Ant
  • Maven
  • Gradle
  • Bazel

8.3 | Make

A Makefile has rules, each with the format

target: prerequisites  
        recipe # NOTE: this is tabbed in

PHONY target:

  • Any prerequisites for the .PHONY targets get their recipes run first

Generalizing using variables

  • Make variables are not bash variables
  • Assign using := not =, = overrides existing values
  • -MMD generates a special file with .d for dependencies for each implementation file

9 | Debuggers

9.1 | GDB

Testing and Debugging

  • Testing = running code, Debugging = investigating
  • A failed assertion or unexpected output is the manifestation of the defect, not the source

$gdb ./basic - running (gdb) layout src - window mode (gdb) set style enable off - no syntax highlighting -g - embeds debugging information that GDB can use

9.2 | GDB Commands

run - runs the program

  • run Hello 123 < file.in break (b) - sets up a breakpoint, must be used before run
  • break main watch - sets up a watchpoints continue
  • info breakpoints delete - deletes all breakpoints
  • delete 1 deletes one breakpoints enable / disable ID - deactivates a breakpoint / watchpoint print - shows the value of a variable display - shows the value of a variable at each step
  • undisplay / enable display / disable display next (n) step refresh list

9.3 | Stack Navigation and going in reverse

backtrace - displays one line in each of the stack frames up / down - navigates the call stack record / reverse-next / reverse/step finish - executes all of the current function call and stops once stack frame is popped

  • GREAT FOR RECURSIVE FUNCTIONS

9.4 | More features and Reference Sheet

CommandAbbreviationDescription
runrRuns the selected program until the next Breakpoint or Watch
breakbSets a breakpoint at a line or function (Current line by default)
watchwaSets a watchpoint
nextnSteps through next line of code (Does not enter function call)
stepsSteps into next line of code (Enters function call if any)
continuecRun from current point to next Breakpoint or Watch
info breakpointsi bList out all breakpoints and watchpoints
deletedDelete breakpoint or watchpoint with given id
printpPrints out the value of the given variable
whatiswhatPrints out the type of the given variable
displaydispPrint out the value of a variable at each step
undisplayundispUndo a display command
upupMove up the call stack
downdoMove down the call stack
backtracebtPrint a trace of the current call stack
finishfinRun to the end of the current function call
recordrecordBegin recording additional information to enable reverse debugging (must be called after run)
reverse-nextrnSteps backward through code (Does not enter function call)
reverse-steprsSteps backward through code (Enters function call if any)
set varset varModify the value stored in a variable during execution

9.5 | Debugging in VS Code

Run -> Start Debugging