XRef
Documentation menu
xrefcode.com / docs / cli / callargs

$ xref callargs

On this page
  1. Usage
  2. Arguments and options
  3. Examples
  4. A constant passed in one register
  5. Reading the output
  6. Limits
  7. Provenance

Every call site in the binary that passes a given constant as an argument, grouped by callee.

xref args lists the arguments at the call sites of a function you already know. callargs goes the other way. You know a value, such as an enum tag, a status or an error code, and you want the code that passes it. A producer often never stores such a value itself. It hands the value to a shared helper (mov r9d, 0x27; call helper), and the helper writes it. callargs scans every function for direct calls and tail jumps whose argument registers (rdi..r9) or stack slots hold the constant at the call. It groups the hits by callee and argument position. For each group it also lists the other constants that callee receives in the same position. A helper that receives 13, 15, 16 and 39 in one register is a status-taking helper, and it stands out.

Usage

xref callargs [OPTIONS] <VALUE>

Arguments and options

Arguments

<VALUE>
The constant (decimal or 0x hex), compared with the whole argument register or stack slot.

Options

--arg <ARG>
Only this argument: rdi, rsi, rdx, rcx, r8, r9 or stack0..stack7.
--callee <CALLEE>
Only calls to this function (address or symbol name).
--limit <LIMIT>
Call sites listed; every callee is summarized.
default 100

Examples

All examples were recorded on public binaries; see Provenance.

A constant passed in one register

Command
$ xref -b rg callargs 0x2c --arg rdx
Output
callee 0x4740a0  rdx: 1 of 523 call sites pass 0x2c; constants there: 0x1 ×15, 0x2 ×5, 0x3 ×6, 0x4 ×93, 0x5 ×44, 0x6 ×19, 0x7 ×20, 0x8 ×20, 0x9 ×16, 0xa ×19, 0xb ×16, 0xc ×28, 0xd ×23, 0xe ×27, 0xf ×14, 0x10 ×19, +18 more
  0x236abb  in 0x236880..0x236ad9  jump  rdx=0x2c
callee 0x477060  rdx: 1 of 2 call sites pass 0x2c; constants there: 0x28 ×1, 0x2c ×1
  0x47720d  in 0x477180..0x4772b1  call  rdx=0x2c  r8=0xc4  stack0=0x1c2
2 call sites pass 0x2c to 2 callee arguments
constants are those set in the call's straight-line run: mov reg, imm; xor reg, reg; copies of such registers; mov [rsp+8k], imm; push imm
stderr
xref: load 2.6ms, total 12.1ms

0x4740a0 receives 34 distinct constants in rdx across 523 call sites. That is a general helper taking a length or a code, and the one call passing 0x2c is a tail jump from 0x236880, the serde_json ErrorCode Display used in the origin example. 0x477060 has two call sites, and the constants show both of them.

Reading the output

Limits

xref origin uses the same scan: a call passing an enum tag to a function that writes that argument into the tag is listed as an argument site.

Provenance

Recorded with a development build of xref after 0.4.0 on Linux x86-64, on rg = ripgrep 14.1.1 (official stripped release). Output is unchanged except that whitespace at the end of each line and empty lines at the end of the output are removed; long outputs are cut where marked.

Source: docs/cli/callargs.md · generated for the site; edit the Markdown, not this page.