Skip to main content
Engineering LibreTexts

10.4: Test/Debug the Program

  • Page ID
    19921
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Once the program is written, testing should be performed to ensure that the program works. The testing will be based on the specific parameters of the program.

    In this case, the program can be executed using the debugger and stopped near the end of the program (e.g., at the label “last” in this example). After starting the debugger with ddd, the command b last and run can be entered which will run the program up to, but not executing the line referenced by the label “last”. The resulting string, strNum can be viewed in the debugger with x/s &strNum will display the string address and the contents which should be “1498”. For example;

        (gdb) x/s &strNum 
        0x600104: "1498"

    If the string is not displayed properly, it might be worth checking each character of the five (5) byte array with the x/5cb &strNum debugger command. The output will show the address of the string followed by both the decimal and ASCII representation.

    For example;

        (gdb) x/5cb &strNum
        0x600104: 49 '1' 52 '4' 57 '9' 56 '8' 0 '\000' 
    

    The format of this output can be confusing initially.

    If the correct output is not provided, the programmer will need to debug the code. For this example, there are two main steps; successive division and conversion/storing the remainders. The second step requires the first step to work, so the first step should be verified. This can be done by using the debugger to focus only on the first section. In this example, the first step should iterate exactly 4 times, so rcx should be 4. Additionally, 8, 9, 4, and 1 should be pushed on the stack in that order. This is easily verified in the debugger by looking at the register contents of rdx when it is pushed or by viewing the top 4 entries in the stack.

    If that section works, the second section can be verified. Here, the values 1, 4, 9, and 8 should be coming off the stack (in that order). If so, the integer is converted into a character by adding “0” (0x30) and that stored in the string, one character at a time. The string can be viewed character by character to see if they are being entered into the string correctly.

    In this manner, the problem can be narrowed down fairly quickly. Efficient debugging is a critical skill and must be honed by practice.

    Refer to Chapter 6, DDD Debugger for additional information on specific debugger commands.


    This page titled 10.4: Test/Debug the Program is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?