Skip to main content

Simple Test of Compilation

  1. To check that you're good to go, download this simple program and save it into your data structures course directory:

    temperature.cpp

  2. Open a terminal and change directory to navigate to your data structures directory:

        cd INSERT_DATA_STRUCTURES_DIRECTORY_NAME
    

  3. 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.

  4. Compile the temperature program by typing:

      g++ -Wall -g 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!

  5. 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

  1. Download and save this file to your data structures directory:

    infinite_loop.cpp

  2. Compile and run this program. It should start printing dots and not stop.

  3. 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:

      1. Search for and launch "Task Manager"
      2. Click "More Details"
      3. 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).

  4. Confirm that you can terminate the runaway program by pressing Ctrl-c.

 

Simple Test of Memory Debugger Installation & Usage

  1. Download and save this short (intentionally buggy) program:

    memory_bugs.cpp

  2. Follow the instructions for your system to compile this program for Memory Debugging. If you're not on Linux or WSL, you'll need to add a few additional compiler flags, and you may need to use a different compiler.

  3. 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

  1. Launch the temperature program (or another executable) inside of the gdb debugger:

        gdb ./temperature.out
    

  2. At the gdb prompt, start the program:

        run
    

  3. 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
    

  4. 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.