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
Directory | Meaning |
---|---|
. | Current Directory |
.. | Parent Directory |
~ | User’s home directory |
~userid | Userid’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
keystrokes | Meaning |
---|---|
:w | save |
:wq | save and quit |
:q! | force quit without saving |
A | append to end of current line |
I | insert at the beginning of current line |
b | go to the beginning of the current word |
e | go to the end of the current word |
yy | copy the current line |
Xyy | copy X lines starting at the current line |
p | paste a line of copied text |
dd | delete the current line |
Xdd | delete X lines starting at the current line |
:num | show current line number |
gg | go to the first line in the file |
G | go to the last line in the file |
XG | go 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
Ownership | Changing Permissions |
---|---|
u | owner/user |
g | group |
o | other |
a | all |
Operator | |
+ | add permission |
- | revoke permission |
= | set permission exactly |
Permission | |
r | read |
w | write |
x | execute |
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
Command | Meaning | Options |
---|---|---|
exit | log out | |
passwd | change your password | |
clear | clear screen | |
man command | show the manual page for command | man -k word shows a list of man pages that mention word |
history | show all previously-issued commands | |
whoami | display your login name | |
date | display current date and time | |
pwd | display current directory | |
ls | list contents of current directory | ls -a show all files, including hidden files, ls -l show in long format |
cp file1 file2 | copy file1 to file2 | cp -r dir1 dir2 recursively copy dir1 to dir2 |
mv file1 file2 | move file1 to file2 (also used to rename) | |
rm file | remove file | can be used to recursively remove a directory, if -r option is used |
touch file | update file’s last modified time to current time | can be used to create an empty file if file does not exist |
cd dir | change directory to dir | cd - return to most recently visited directory |
mkdir dir | create new directory dir in current directory | can specify more than one directory at once |
rmdir dir | remove directory dir | only works if dir is empty; if not empty, use rm -r dir; can specify more than directory at once |
echo string | display string to screen | |
chmod perms file | set permissions on file to perms | |
ps | display current processes | ps -a show all users’ processes, ps -A show ALL processes (incl. system processes)} |
kill pid | kill process with number pid | kill -9 pid more forceful kill, for stubborn processes |
who | show who is logged into this machine | |
time command | show amount of time taken executing command | |
fg | bring background job to the foreground | useful 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 |
Tool | Purpose | Options |
---|---|---|
cat f1 f2 … | display files f1, f2, … one after the other | cat -n f1 f2 … attaches line numbers |
less file | display file one screen at a time | |
diff f1 f2 | compare files f1 and f2; outputs instructions for converting f1 to f2 | diff -w f1 f2 ignores whitespace |
cmp f1 f2 | compare files f1 and f2; outputs the first position where they differ | |
wc file | count the number of words, lines, and characters in file | wc -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 file | print all lines in file that contain pattern pat | egrep -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 file | print first 10 lines of file | -num prints num lines (e.g. head -5 file) head -n as alternate syntax |
tail file | like head, but prints last 10 lines of file | tail -n +N instead of last 10 lines, output starting from line N |
sort file | sorts the lines of file | sort -n file sorts strings of digits in numerical order |
uniq file | removes consecutive duplicate lines from file | removes all duplicates if file is sorted |
shuf file | randomly shuffles the lines in file | shuf -n num outputs num random lines from file |
cut options file | extract portions from each line in file | cut -fN -dD extract field N from each line, where fields are separated by a delimiter D |
Programs |
Program | Purpose | Options |
---|---|---|
vim file | invoke vi IMproved text editor on file | |
vi file | invoke vi text editor on file (often redirects to vim) | |
emacs file | invoke emacs text editor on file | |
nano file | invoke nano text editor on file | |
wget url | fetch file from the web at url | |
curl | used to transfer data | |
less file | used to view file contents one screen at a time | |
xpdf file | display pdf file (requires the ability to launch graphical programs) | |
ssh machine | make SSH connection to machine; opens a secure shell on remote machine; type exit to end SSH connection | ssh -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:file2 | securely copy file1 on mach1 to file2 on mach2 | can 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/...
Variable | Meaning |
---|---|
${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
Variable | Meaning |
---|---|
${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, -ne | integer equality and inequality |
-gt, -ge | integer greater than, integer greater than or equal to |
-lt, -le | integer less than, integer less than or equal to |
deprecated: -a, -o | and, or |
! | negation |
-e | file exists |
-d | file exists and is a directory |
-f | file exists and is a regular file |
-r, -w, -x | file exists and is readable/writable/executable |
-z | check 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
- C/C++ Language
- 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
- Open a terminal and compile with command line
- 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 directorygit status
shows status (git status > step1.log)
redirects outputgit add
tells git to track a filegit commit -m "message"
git log
shows a loggit diff
shows differences (eg.git diff --staged hello.c
)git rm
removes a file and tracks it (same asrm main.c
andgit add main.c
)git mv
moves a filegit 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 branchgit checkout
switches branchesgit 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 repositorygit push (origin master)
uploads changes to remote repogit pull
downloads changesgit 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 IDgit 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
- Angled brackets: for files in the standard C library
- 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 infoO0
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 runbreak main
watch
- sets up a watchpointscontinue
info breakpoints
delete
- deletes all breakpointsdelete 1
deletes one breakpointsenable / disable ID
- deactivates a breakpoint / watchpointprint
- shows the value of a variabledisplay
- shows the value of a variable at each stepundisplay / 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
Command | Abbreviation | Description |
---|---|---|
run | r | Runs the selected program until the next Breakpoint or Watch |
break | b | Sets a breakpoint at a line or function (Current line by default) |
watch | wa | Sets a watchpoint |
next | n | Steps through next line of code (Does not enter function call) |
step | s | Steps into next line of code (Enters function call if any) |
continue | c | Run from current point to next Breakpoint or Watch |
info breakpoints | i b | List out all breakpoints and watchpoints |
delete | d | Delete breakpoint or watchpoint with given id |
p | Prints out the value of the given variable | |
whatis | what | Prints out the type of the given variable |
display | disp | Print out the value of a variable at each step |
undisplay | undisp | Undo a display command |
up | up | Move up the call stack |
down | do | Move down the call stack |
backtrace | bt | Print a trace of the current call stack |
finish | fin | Run to the end of the current function call |
record | record | Begin recording additional information to enable reverse debugging (must be called after run) |
reverse-next | rn | Steps backward through code (Does not enter function call) |
reverse-step | rs | Steps backward through code (Enters function call if any) |
set var | set var | Modify the value stored in a variable during execution |
9.5 | Debugging in VS Code
Run -> Start Debugging