blob: 347ae928984a578d0207d0d7fa88462e7b98c6c6 [file] [log] [blame]
Christopher Ferris11526e22021-10-14 22:44:47 +00001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#pragma once
29
30#include <sys/cdefs.h>
31
32/**
33 * @file execinfo.h
34 * @brief Functions to do in process backtracing.
35 */
36
37__BEGIN_DECLS
38
39/**
40 * [backtrace(3)](https://man7.org/linux/man-pages/man3/backtrace.3.html)
41 * Saves a backtrace for the current call in the array pointed to by buffer.
42 * "size" indicates the maximum number of void* pointers that can be set.
43 *
44 * Returns the number of addresses stored in "buffer", which is not greater
45 * than "size". If the return value is equal to "size" then the number of
46 * addresses may have been truncated.
47 *
48 * Available since API level 33.
49 */
50int backtrace(void** buffer, int size) __INTRODUCED_IN(33);
51
52/**
53 * [backtrace_symbols(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols.3.html)
54 * Given an array of void* pointers, translate the addresses into an array
55 * of strings that represent the backtrace.
56 *
57 * Returns a pointer to allocated memory, on error NULL is returned. It is
58 * the responsibility of the caller to free the returned memory.
59 *
60 * Available since API level 33.
61 */
62char** backtrace_symbols(void* const* buffer, int size) __INTRODUCED_IN(33);
63
64/**
65 * [backtrace_symbols_fd(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols_fd.3.html)
66 * Given an array of void* pointers, translate the addresses into an array
67 * of strings that represent the backtrace and write to the file represented
68 * by "fd". The file is written such that one line equals one void* address.
69 *
70 * Available since API level 33.
71 */
72void backtrace_symbols_fd(void* const* buffer, int size, int fd) __INTRODUCED_IN(33);
73
74__END_DECLS