Last Updated: February 25, 2016
·
2.117K
· x3ro

Debugging SSE and AVX registers in LLDB

Since LLDB's approach to here seems to be a bit different than GDB's it took me a while to get right, so here's how I did it:

Let's say we've stopped our program at some point and wish to know the state of the xmm0 register containing 4 floats. A simple print will only yield the following:

(lldb) po $xmm0
(unsigned char __attribute__((ext_vector_type(16)))) $6 = {
  [0] = '\0'
  ...
  [15] = '@'
}

Not really helpful. In order to get proper output, we need to cast the register to the proper type, like this:

po (float __attribute__((ext_vector_type(4)))) $xmm0
([0] = 1, [1] = 2, [2] = 3, [3] = 4)

For this to work, one must modify both the type (in this case char -> float) as well as the amount of elements in the vector (16 -> 4). The size of the type multiplied with the number of elements must match the size of the SIMD register, or otherwise LLDB will complain. In this case xmm0 is 128bits wide and 32 (size of float) * 4 equals 128.