Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disassembly: How can you determine the correct PC location #335

Closed
puremourning opened this issue Oct 5, 2022 · 2 comments
Closed

Disassembly: How can you determine the correct PC location #335

puremourning opened this issue Oct 5, 2022 · 2 comments

Comments

@puremourning
Copy link
Contributor

In my DAP client, I want to display source code in one window and disassembly in another window, and have the correct source line highlighted in the source window and the exact instruction highlighted in the disassembly window. When stepping by instruction, the highlighted line moves in the disassembly window, and the code window may stay the same line.

This seems pretty simple on the face of it. The stack frame can tell me the current instruction pointer address, and the disassembly result can tell me address of each instruction. Then I can just compare until they match.

Except, unfortunately, I don't think I can. The StackFrame current instruction pointer is defined as a "memory references" but DisassembledInstruction is defined in terms of an "address" (and does not include a "memory reference"). As far as I know, these two things are not "the same" so there's no way to compare them. As a result, I don't think it's possible to determine the current "instruction" in the result of a disassemble request based on a given stack frame, which appears to make the "stepping granularity" of "instruction" somewhat non-functional.

Did I miss something? Is there a way to canonically determine which instruction in the disassembly is the current one for a given stack frame?

@gregg-miskelly
Copy link
Member

gregg-miskelly commented Oct 5, 2022

Is your question how do obtain disassembly around the current instruction?
Or how do you decide that a disassembly that you previously requested is still valid?

For the former, assuming you would like to put the instruction in the center of your text buffer of height lines, what should work is:

  • Take the StackFrame.instructionPointerReference to see where you are
  • Issue a disassemble request with
    • memoryReference = instructionPointerReference
    • instructionOffset = -height/2 (or more if you want to be able to page back without requesting more instructions)
    • instructionCount = height (or more if you want)
    • resolveSymbols = true (or false, up to you)

If the later, you could either:

  • Just always update, to make sure that self-modifying code is handled. You could do something so that if the instructions you get back are the same and scrolling is unnecessary, you just move the current instruction indicator.
    -or-
  • Issue a readMemory request with count=0, and check if the address is within the range of disassembly that you have.

@puremourning
Copy link
Contributor Author

puremourning commented Oct 6, 2022

Ok thanks. I was really just trying to work out which instruction was current.

But I think you answered with the fist part, combined with this :

An adapter must return exactly this number of instructions - any

  • unavailable instructions should be replaced with an implementation-defined
  • 'invalid instruction' value.

Point being, if I ask for 100 instructions with an offset of -50 then the 51st instruction is the one matching the memory reference.

Seems obvious now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants