MCPcopy Create free account
hub / github.com/axhlzy/FridaDebugger / logStack

Function logStack

agent/stack.ts:12–50  ·  view source on GitHub ↗
(
    context: CpuContext,
    maxEntries = DEFAULT_MAX_ENTRIES,
    previous?: StackSnapshot | null,
)

Source from the content-addressed store, hash-verified

10export type StackSnapshot = Record<string, string>;
11
12export function logStack(
13 context: CpuContext,
14 maxEntries = DEFAULT_MAX_ENTRIES,
15 previous?: StackSnapshot | null,
16): StackSnapshot {
17 const sp = getStackPointer(context);
18 const fp = getFramePointer(context);
19 if (sp === null) {
20 log("[stk] no stack pointer in current context", "yellow");
21 return {};
22 }
23
24 const snapshot: StackSnapshot = {};
25 const markers = getContextMarkers(context, sp, fp);
26 const totalEntries = getEntryCount(sp, fp, maxEntries);
27 const headEntries = Math.min(DEFAULT_HEAD_ENTRIES, maxEntries);
28 const tailEntries = Math.min(DEFAULT_TAIL_ENTRIES, Math.max(maxEntries - headEntries, 0));
29 const omitted = totalEntries > maxEntries;
30
31 log("[stk] ------------------------------------------------------------", "cyan");
32 log(`[stk] fp=${fp ?? "n/a"} -> sp=${sp} entries=${totalEntries}${omitted ? " (truncated)" : ""}`, "green");
33
34 let didOmit = false;
35 for (const index of getDisplayIndices(totalEntries, omitted, headEntries, tailEntries)) {
36 if (index === -1) {
37 if (!didOmit) {
38 const omittedCount = totalEntries - headEntries - tailEntries;
39 log(`[stk] ... ${omittedCount} entries omitted ...`, "yellow");
40 didOmit = true;
41 }
42 continue;
43 }
44
45 const slot = sp.add(index * Process.pointerSize);
46 logStackSlot(index, slot, snapshot, previous, markers);
47 }
48
49 return snapshot;
50}
51
52function getDisplayIndices(totalEntries: number, omitted: boolean, headEntries: number, tailEntries: number): number[] {
53 if (!omitted) {

Callers 2

stackMethod · 0.85
onInstructionMethod · 0.85

Calls 8

getStackPointerFunction · 0.85
getFramePointerFunction · 0.85
logFunction · 0.85
getContextMarkersFunction · 0.85
getEntryCountFunction · 0.85
getDisplayIndicesFunction · 0.85
logStackSlotFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected