xref: /xnu-10002.61.3/bsd/man/man9/backtrace_pack.9 (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1.\" Copyright (c) 2021, Apple Inc.  All rights reserved.
2.
3.Dd June 30, 2021
4.Dt BACKTRACE_PACK 9
5.Os Darwin
6.
7.Sh NAME
8.Nm backtrace_pack ,
9.Nm backtrace_unpack
10.Nd convert a backtrace to and from compact formats
11.
12.Sh SYNOPSIS
13.In kern/backtrace.h
14.Ft size_t
15.Fo backtrace_pack
16.Fa "backtrace_pack_t packing"
17.Fa "uint8_t *dst"
18.Fa "size_t dst_size"
19.Fa "uintptr_t *src"
20.Fa "unsigned int src_len"
21.Fc
22.
23.Ft unsigned int
24.Fo backtrace_unpack
25.Fa "backtrace_pack_t packing"
26.Fa "uintptr_t *dst"
27.Fa "unsigned int dst_len"
28.Fa "uint8_t *src"
29.Fa "size_t src_size"
30.Fc
31.
32.Sh DESCRIPTION
33The
34.Nm backtrace_pack
35and
36.Nm backtrace_unpack
37functions convert to and from a compact representation of a backtrace.
38.Sh RETURN VALUES
39The
40.Fn backtrace_pack
41function returns the number of bytes written to the destination buffer.
42The
43.Fn backtrace_unpack
44function returns the number of addresses written to the destination buffer.
45.Sh FORMATS
46.Bl -tag -width indent
47.It Sy BTP_NONE
48Just copy the addresses unpacked to the destination buffer.
49.It Sy BTP_KERN_OFFSET_32
50Subtract the kernel base address from each address so they fit in 4 bytes.
51.El
52.
53.Sh EXAMPLE
54.Bd -literal
55uintptr_t bt[8] = { 0 };
56enum backtrace_info bti = BTI_NONE;
57unsigned int len = backtrace(bt, sizeof(bt) / sizeof(bt[0]), NULL, &bti);
58uint8_t bt_packed[1024] = { 0 };
59size_t packed_size = backtrace_pack(BTP_KERN_OFFSET_32, bt_packed,
60		sizeof(bt_packed), bt, len);
61uintptr_t bt_unpacked[8] = { 0 };
62unsigned int unpacked_len = backtrace_unpack(BTP_KERN_OFFSET_32, bt_unpacked,
63		sizeof(bt_unpacked) / sizeof(bt_unpacked[0]), bt_packed, packed_size);
64assert(len == unpacked_len);
65for (unsigned int i = 0; i < len; i++) {
66	assert(bt[i] == unpacked_bt[i]);
67}
68.Ed
69.
70.Sh SEE ALSO
71.Xr backtrace 9
72