Home
Contact Information
Announcements
Discussion Forum (LMS)
Syllabus
Learning Outcomes
Prerequisites
iClickers in Lecture
Course Grades
Calendar
Lecture notes
Lab materials
Homework
Test reviews
Weekly Schedule
Office Hours
Lab Times
Getting Help
Tutoring
Advice from TAs
Advice from Students
Homework
Due Date and Time
Late Day Policy
Compilers
Submitty
HW Grading Criteria
Collaboration Policy &
Academic Integrity
C++ Development
Code Editors & IDEs
OS Choices
Install WSL
Install Cygwin
Memory Debugging
Dr. Memory
Valgrind
Test Your Installation
References
Optional Textbooks
Web Resources
Misc. C++ Programming
Command Line Args
File I/O
string → int/float
|
Simple Test of Compilation
-
To check that you're good to go, download this simple program and save
it into your data structures course directory:
temperature.cpp
-
Open a terminal and change directory to navigate to your data structures directory:
cd INSERT_DATA_STRUCTURES_DIRECTORY_NAME
Confirm you're in the right location by listing the directory contents typing:
ls
You should see the file temperature.cpp and maybe some other stuff.
-
Compile the temperature program by typing:
g++ -Wall temperature.cpp -o temperature.out
(Alternatively, use clang++ instead of g++.) This
should creates an executable named temperature.out. Type ls
again to confirm the executable appeared!
-
Now run that executable:
./temperature.out
And you should be able to interact with this program at the keyboard.
Simple Test of Terminating an Infinite Loop
-
Download and save this file to your data structures directory:
infinite_loop.cpp
-
Compile and run this program. It should start printing dots and not
stop.
-
Now let's confirm that your computer is spending alot of CPU resources
on this infinite loop. We'll view the list of all programs running on
your computer sorted by CPU usage.
-
On Mac or Linux or WSL, in another terminal type:
top -o %CPU
You should see the program name at or near the top of the list.
And it should be using a large amount of CPU (depending on the number
of processors on your machine).
-
On Windows:
- Search for and launch "Task Manager"
- Click "More Details"
- Click on the "CPU" column
You should see the program name at or near the top of the list.
And it should be using a large amount of CPU (depending on the number
of processors on your machine).
-
Confirm that you can terminate the runaway program by pressing Ctrl-c (or
Ctrl-k).
Simple Test of Memory Debugger Installation & Usage
-
Download and save this short (intentionally buggy) program:
memory_bugs.cpp
-
Follow the instructions for your system to compile this program for
Memory Debugging. You'll need to
add a few additional compiler flags, and you may need to use a
different compiler.
-
Now run the program under the memory debugger and locate the report
generated by the memory debugger. (It may be printed directly to the
terminal and/or saved to a file.)
NOTE: The memory debugger report contains lots of data which can
be intimidating the first time you see it. This tiny program has 4
different errors! We'll discuss the code, and the errors, and how to
understand this report a few weeks into the term.
Simple Test of the Traditional Debugger
Launch the temperature program (or another executable) inside of the gdb debugger:
gdb ./temperature.out
At the gdb prompt, start the program:
run
If the program is still running, press Ctrl-C. To see the
stack backtrace of the program (listing the functions you are in the
middle of), type:
bt
Finally, close gdb:
quit
(You will have to press 'y' if the program is still running.)
If you're using LLVM's clang++ instead of g++, you'll also use LLVM's
lldb instead of gdb. The above commands are the
same (just substitute lldb for gdb), and many of the
other commands are similar:
A handy table of the different gdb/lldb commands
NOTE: The traditional debugger has many powerful features that you
should learn over the term. Follow online tutorials and ask for help
in lab and office hours to most effectively debug your programming
assignments.
|