Viewing Stanford collections in the debugger


When debugging a program that uses variables of Stanford collection type (Vector, Map, Queue, …), it is very helpful to be able to examine the contents of the collection in the debugger. To enable you to view inside a collection, we use a custom debugging helper written by one of our awesome section leaders Jeremy Barenholtz. Thanks, Jeremy!

Automatic install within the CS106 package

The custom debugging helper is included in our package of CS106 specific components that you previously installed. When installing the CS106 package, it copies the debugging helper into the appropriate place so that Qt Creator will automatically use it. In most cases, this effort is successful, but if it didn't take, we have instructions below on how you can manually configure it. You may also need to manually configure the helper if an update to Qt Creator wipes out your previous configuration.

Check if debugger helper is configured

To determine if your Qt Creator is configured for the custom debugging helper, run any program under the debugger that uses a variable of a Stanford collection type and look at how the collection is displayed in the debugger variable pane. If the helper is configured, the collection contents will display in a readable, labeled layout. Without the helper, the collection innards are displayed in their raw form.

For example, if your program declares myQueue as:

Queue<int> myQueue = {10, 15, 7, 3};

Viewing myQueue without the helper configured shows the raw display:

screenshot of debugger without helper configured

With the helper, you get the pretty display (including size of queue, values for queue elements, and labels for the front and back elements):

screenshot of debugger with helper configured

As of 9/26/2020, we have learned of a third possible outcome, Stanford collections display as <not accessible> due to an incompatibility between Qt Creator and the latest Xcode update.

screenshot of debugger with not accessible displayed

What to do

  • If you see the pretty display, your Qt Creator is already configured to use the debugging helper and you do not need to take further action. You are good to go!
  • If you see the raw display, follow the instructions in the next section to manually configure the helper.
  • If you see <not accessible>, scroll to bottom of this file and follow the instructions to fix the incompatibility. Then repeat the steps above to see whether you have pretty or raw display and follow up accordingly.

To manually configure the debugging helper when you are not getting the pretty display

  1. Download this file: stanfordtypes.py and store it somewhere on your computer where you will be able to easily find it later.
  2. Open Qt Creator. If you have any projects already open in Qt Creator, close them now.
  3. From the top menu, select Qt Creator > Preferences if you're on Mac, or Tools > Options if you're on Windows / Linux.
  4. Select Debugger from the list of options on left side and Locals and Expressions from the top tab bar. Find the section labeled Extra Debugging Helpers. In the screenshot below, we use a red rectangle to frame the section you're looking for.

    screenshot of debugger/locals section of preferences

  5. Click the Choose button to bring up a file browser. In the file browser, find and select the stanfordtypes.py file that you downloaded in Step 1.
  6. Click the Ok button in the bottom-right corner to apply these changes. You should be good to go!

If you re-run the check from above (to view a Stanford collection in debugger), you should now see the pretty display. If it didn't seem to take, re-do steps 4 and 5 and be sure you have selected the correct file. If you still can't get it to work, post on Ed or come to Lair so we can help you out.

To correct the <not accessible> incompatibility

  1. Download this file: lldbbridge.py and store it somewhere on your computer where you will be able to find it later.
  2. If you have Qt Creator open, close it now. In the Finder, locate your Qt Creator Application.
  3. Select the "Qt Creator" application icon and control-click to bring up the context menu and choose Show Package Contents.

    screenshot of open app package contents

  4. This opens a folder in which there is a subfolder named Contents. Open Contents then open subfolder Resources, then open subfolder debugger.

    screenshot of debugger subfolder

  5. Copy the lldbbridge.py file that you downloaded in Step 1 into the debugger subfolder, replacing the file of the same name that is already there.

Open Qt Creator and re-run the check from above (to view a Stanford collection in the debugger). If you see the pretty display, you're all set. If you see the raw display, follow the steps above to manually configure the debugging helper. If you still can't get it to work, post on Ed or come to Lair so we can help you out.