1#ifndef AWS_COMMON_SYSTEM_INFO_H
2#define AWS_COMMON_SYSTEM_INFO_H
3
4/*
5 * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License").
8 * You may not use this file except in compliance with the License.
9 * A copy of the License is located at
10 *
11 * http://aws.amazon.com/apache2.0
12 *
13 * or in the "license" file accompanying this file. This file is distributed
14 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
15 * express or implied. See the License for the specific language governing
16 * permissions and limitations under the License.
17 */
18
19#include <aws/common/common.h>
20
21AWS_EXTERN_C_BEGIN
22
23/* Returns the number of online processors available for usage. */
24AWS_COMMON_API
25size_t aws_system_info_processor_count(void);
26
27/* Returns true if a debugger is currently attached to the process. */
28AWS_COMMON_API
29bool aws_is_debugger_present(void);
30
31/* If a debugger is attached to the process, trip a breakpoint. */
32AWS_COMMON_API
33void aws_debug_break(void);
34
35#if defined(AWS_HAVE_EXECINFO) || defined(WIN32) || defined(__APPLE__)
36# define AWS_BACKTRACE_STACKS_AVAILABLE
37#endif
38
39/*
40 * Records a stack trace from the call site.
41 * Returns the number of stack entries/stack depth captured, or 0 if the operation
42 * is not supported on this platform
43 */
44AWS_COMMON_API
45size_t aws_backtrace(void **frames, size_t num_frames);
46
47/*
48 * Converts stack frame pointers to symbols, if symbols are available
49 * Returns an array up to stack_depth long, that needs to be free()ed.
50 * stack_depth should be the length of frames.
51 * Returns NULL if the platform does not support stack frame translation
52 * or an error occurs
53 */
54char **aws_backtrace_symbols(void *const *frames, size_t stack_depth);
55
56/*
57 * Converts stack frame pointers to symbols, using all available system
58 * tools to try to produce a human readable result. This call will not be
59 * quick, as it shells out to addr2line or similar tools.
60 * On Windows, this is the same as aws_backtrace_symbols()
61 * Returns an array up to stack_depth long that needs to be free()ed. Missing
62 * frames will be NULL.
63 * Returns NULL if the platform does not support stack frame translation
64 * or an error occurs
65 */
66char **aws_backtrace_addr2line(void *const *frames, size_t stack_depth);
67
68/**
69 * Print a backtrace from either the current stack, or (if provided) the current exception/signal
70 * call_site_data is siginfo_t* on POSIX, and LPEXCEPTION_POINTERS on Windows, and can be null
71 */
72AWS_COMMON_API
73void aws_backtrace_print(FILE *fp, void *call_site_data);
74
75/* Log the callstack from the current stack to the currently configured aws_logger */
76AWS_COMMON_API
77void aws_backtrace_log(void);
78
79AWS_EXTERN_C_END
80
81#endif /* AWS_COMMON_SYSTEM_INFO_H */
82