Skip to content

Commit a21c704

Browse files
authored
feat(debug): add AmxDbg::function_address for function breakpoints (#55)
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).
1 parent 336f8de commit a21c704

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

samp-sdk/src/debug/query.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ impl AmxDbg {
7171
.map(|s| s.name.as_str())
7272
}
7373

74+
/// Address to break at when a function is entered, given its name — the
75+
/// counterpart of [`Self::lookup_function`], for **function breakpoints**.
76+
/// Finds the `iFUNCTN` symbol with that exact name (ignoring internal `@`
77+
/// names) and returns the first breakable line address inside its body
78+
/// (`[codestart, codeend)`), or `codestart` if the function has no line
79+
/// entries. `None` if there is no such function.
80+
#[must_use]
81+
pub fn function_address(&self, name: &str) -> Option<u32> {
82+
let func = self
83+
.symbols
84+
.iter()
85+
.find(|s| s.ident == Ident::Function && s.name == name && !s.name.starts_with('@'))?;
86+
let first_line = self
87+
.lines
88+
.iter()
89+
.filter(|l| l.address >= func.codestart && l.address < func.codeend)
90+
.map(|l| l.address)
91+
.min();
92+
Some(first_line.unwrap_or(func.codestart))
93+
}
94+
7495
/// Code address of a source line (`dbg_GetLineAddress`), to set a
7596
/// breakpoint by line. Moves to the next "breakable" line if the exact one
7697
/// does not exist; use [`Self::lookup_line`] to learn which line it landed

0 commit comments

Comments
 (0)