Christopher Ferris | 11526e2 | 2021-10-14 22:44:47 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 50 | |
| 51 | #if __BIONIC_AVAILABILITY_GUARD(33) |
zijunzhao | e951acd | 2023-01-13 02:14:10 +0000 | [diff] [blame] | 52 | int backtrace(void* _Nonnull * _Nonnull buffer, int size) __INTRODUCED_IN(33); |
Christopher Ferris | 11526e2 | 2021-10-14 22:44:47 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * [backtrace_symbols(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols.3.html) |
| 56 | * Given an array of void* pointers, translate the addresses into an array |
| 57 | * of strings that represent the backtrace. |
| 58 | * |
| 59 | * Returns a pointer to allocated memory, on error NULL is returned. It is |
| 60 | * the responsibility of the caller to free the returned memory. |
| 61 | * |
| 62 | * Available since API level 33. |
| 63 | */ |
zijunzhao | e951acd | 2023-01-13 02:14:10 +0000 | [diff] [blame] | 64 | char* _Nullable * _Nullable backtrace_symbols(void* _Nonnull const* _Nonnull buffer, int size) __INTRODUCED_IN(33); |
Christopher Ferris | 11526e2 | 2021-10-14 22:44:47 +0000 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * [backtrace_symbols_fd(3)](https://man7.org/linux/man-pages/man3/backtrace_symbols_fd.3.html) |
| 68 | * Given an array of void* pointers, translate the addresses into an array |
| 69 | * of strings that represent the backtrace and write to the file represented |
| 70 | * by "fd". The file is written such that one line equals one void* address. |
| 71 | * |
| 72 | * Available since API level 33. |
| 73 | */ |
zijunzhao | e951acd | 2023-01-13 02:14:10 +0000 | [diff] [blame] | 74 | void backtrace_symbols_fd(void* _Nonnull const* _Nonnull buffer, int size, int fd) __INTRODUCED_IN(33); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 75 | #endif /* __BIONIC_AVAILABILITY_GUARD(33) */ |
| 76 | |
Christopher Ferris | 11526e2 | 2021-10-14 22:44:47 +0000 | [diff] [blame] | 77 | |
| 78 | __END_DECLS |