feat(debug): opcode decoding, call-stack walking and range reads - #56
Merged
Conversation
Contraparte de lookup_function: resolve o nome de uma função no endereço da primeira linha quebrável do corpo (ou codestart), para o PawnPro-Debugger implementar breakpoints de função (parar ao entrar numa função por nome).
Adds the AMX facts a debugger had to reimplement on top of the SDK: - samp::debug::opcode — opcode numbering, STK_MARGIN, OP_NUM_OPCODES and operand_cells(op) for instruction sizes (None on variable-length or out-of-range: the signal to stop scanning). - OpcodeMap — inverts the VM dispatch table to undo the computed-goto rewrite, with Amx::opcode_map() building one from a VM. Replaces the hand-rolled HashMap the docs used to show. - samp::debug::stack::walk — frame-chain walking with an injected cell reader, plus Amx::call_stack(top_cip). MAX_DEPTH guards a corrupted stack. - Amx::read_cells / read_bytes — range reads with amx_GetAddr bounds checking, stopping early at the first inaccessible address; read_bytes is alignment free. The get_ref path needs a function table and cannot serve a debug hook. - Amx::data_only(ptr) — states data-side-only intent instead of a bare 0 as the function table. Extracted from the PawnPro Debugger, where each piece already ran against live SA-MP and open.mp servers. Docs and CHANGELOG updated; crate versions bumped per the project policy (samp-sdk and samp 3.3.0 -> 3.4.0, codegen unchanged).
Adds crates.io version and downloads, docs.rs, MSRV and stars to the badge row, alongside the CI, license, Scorecard and dependency badges already there. The debug feature description no longer says 'parser': it now also covers the opcode helpers and call-stack walking added in this release.
The v3.5.0 section only had the three commits of this branch. It now covers all 20 commits since the tag: Amx::hlw (#54), which was public API and had no entry at all, plus a Changed section for the CI work (CodeQL advanced setup #52, the ci-status gate #51, grouped Dependabot #44) and the dependency bumps, following how earlier releases record them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves into the SDK the AMX facts a debugger had to reimplement on top of it. Every piece here was extracted from the PawnPro Debugger, where it already ran against live SA-MP and open.mp servers (compilers 3.10.10 and 3.10.11).
AmxDbg::function_address(#55, now merged) had no CHANGELOG entry, and neither didAmx::hlw(#54) — both are recorded in this release section, along with the CI and dependency work since the v3.4.0 tag.Added
samp::debug::opcode— opcode numbering (the order of the opcode enum inamx.c, identical on SA-MP and open.mp),OP_NUM_OPCODES, the VM'sSTK_MARGIN, andoperand_cells(op)for instruction sizes. ReturnsNoneon a variable-length instruction (casetbl) or an out-of-range opcode — the signal for a scanner to stop rather than guess.OpcodeMapandAmx::opcode_map()— inverts the VM dispatch table (label address → opcode) to undo the computed-goto rewrite the loader applies on GCC/Clang builds.is_identity()reports a non-relocated image. This replaces the hand-rolledHashMapthatdocs/vm-debugging.mdused to show consumers writing themselves.samp::debug::stack::walkandAmx::call_stack(top_cip)— walks the frame chain ([frm]= caller's FRM,[frm + CELL]= return address) into(cip, frm)per frame, top first. The cell reader is injected, so it is unit-testable against a fake memory map and usable host-side;MAX_DEPTHkeeps a corrupted stack from spinning a debug hook.Amx::read_cells/Amx::read_bytes— range reads with the sameamx_GetAddrbounds checking asread_cell. They stop early at the first inaccessible address and return what they read (the natural case at the end of the data segment), returningNoneonly when the start itself is inaccessible;read_bytesneeds no alignment. Theget_ref-basedBuffer/AmxStringpath needs a function table and cannot serve a debug hook, which is why only single cells were reachable there before.Amx::data_only(ptr)— wraps a raw*mut AMXfor data-side access only, stating the intent instead of passing a bare0as the function table (the usual situation while a VM is paused).Changelog completeness
The
v3.5.0section covers all 20 commits since thev3.4.0tag, not just this branch:Amx::hlw()(feat(amx): add Amx::hlw() accessor for the heap low-water mark #54) — public API that had no entry anywhere.ci-statusgate (ci: add stable ci-status gate as the required status check #51), grouped Dependabot (chore: group Dependabot updates into a single PR per ecosystem #44).Validation
i686-unknown-linux-gnu;cargo clippy --all-targets -D warningsclean;cargo fmtclean.clippy::pedanticwarnings — the project's existing pedantic baseline is untouched.Docs
debugfeature description widened and its badge row extended (crates.io version and downloads, docs.rs, MSRV, stars).Crate versions
Per the project's independent-versioning policy:
rust-samp(libsamp): 3.3.0 → 3.4.0 — re-exports the widened surface; requiresrust-samp-sdk3.4.0.rust-samp-sdk(libsamp_sdk): 3.3.0 → 3.4.0 — additive public API.rust-samp-codegen: 1.4.0, unchanged.Downstream
The debugger already consumes this branch and dropped ~250 lines: its local
stack.rs, the 44OP_*constants, theOP_PARAMStable, its ownOpcodeMap, and the manual alignment in its memory reads.