Debug.mac cannot handle argument involving rsp correctly

Reproducible code snippet:

    push 2
    debugx64 [rsp]
    mov rax, rsp
    debugx64 [rax]
    pop rax
    debugx64 rax

Expected result: print 2 three times.

Actual result:

debug hexadecimal... 75BF700F1CB0
debug hexadecimal... 2
debug hexadecimal... 2

(Note that 75BF700F1CB0 part is always changing)

It might because of debug routine using stack to preserve other registers.

If it is implementation limitation, I recommended to document involving rsp causes unexpected result.

1 Like

Yes, this is documented in the document on the section CALLING CONVENTION

; Note that the stack is modified temporarily by all macros.
; This means any value pointed by RSP won't be valid at the time it is dereferenced.
; Such value should be loaded on a register before debugging.

Do you think this message could be more evident? Perhaps I could reinforce it on the other sections.

Then, this is my fault not looking debug.mac thoughtfully.

For excuse, it would be good to mention this on “How to debug” part on instruction of each exercise.

1 Like

You’re right, I’ll add this information. Thank you!

This PR added a note on “How to debug”.