Debug support in the x86-64-assembly track

Hi, folks.

We added a file (debug.mac) to all exercises, with various macros for debugging support. This file was based on a similar one in the test runner repo, but expanded and documented.

The macros have a name with the following format:

debug + type + size

The type here indicates how the value should be interpreted:

  1. d - signed integer in decimal format.
  2. u - unsigned integer in decimal format.
  3. x - unsigned integer in hexadecimal format.
  4. f - a floating-point number.
  5. c - a character.
  6. s - a NUL-terminated string.

The size indicates the number of bits of the operand. It can be 8, 16, 32 or 64. It is necessary for all macros except those that print characters (debugc) or strings (debugs).

For example, debugd64 prints 64-bit signed integers and debugf32 prints 32-bit floating-point numbers.

There are also macros to print the contents of a 128-bit SIMD operand. In that case, the size indicates the width of each lane, and they have a “_xmm” at the end, e.g., debugu8_xmm.

For example, debugu32_xmm interprets its arguments as 4 packed 32-bit unsigned integers, while debugf64_xmm interprets its arguments as 2 packed 64-bit floating-point numbers.

All macros should be called with one or more arguments of the appropriate size. In case of multiple arguments, they should be separated by a comma: debugx8 al, cl, dl, r8b.

Memory arguments should be passed in brackets, e.g., [rax] or [my_label]. The exception is debugs, which expects a memory address without brackets.

To use these macros, the file must be explicitly included at the top of the solution file:

%include "debug.mac"

All of this is documented on the file itself and should also be mentioned on help.md (if you work locally) or below the instructions for the exercise (if you use the online editor).

In the future, we will try to add support for 256-bit and 512-bit SIMD operands and for printing flags such as ZF or CF.

3 Likes

I love how debugging is even an exercise here haha. Did you also add DEBUG.md or whatever the file is called?

1 Like

I did! But I thought it would only appear for practice exercises. Now I’m wondering how I can make the instructions more friendly for students going through the syllabus :sweat_smile:

1 Like

You may add concrete examples to the instructions.md of each concept exercise, as well as some common ones to the hints.md. Still it depends on students interest in reading docs :slight_smile:

2 Likes

We’ve just added support for debugging flags and conditions.

The debug_flag macro takes one or more arguments corresponding to the suffix of a jcc that matches the condition being tested. It then prints if the condition is true or false at that point in the code.

For example, debug_flag e prints true if je would jump and false otherwise.

The documentation was also updated and moved to the beginning of the file for ease of reference.

Lastly, all debugging macros should now work on macOS as well.