2009-09-01 18:40:25 +00:00
|
|
|
/*
|
2013-12-05 15:04:53 +11:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2009-09-01 18:40:25 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2009-09-01 18:40:25 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
2009-09-01 18:40:25 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-04-27 16:20:03 +02:00
|
|
|
#ifdef HAVE_BACKTRACE_SYMBOLS
|
2009-09-01 18:40:25 +00:00
|
|
|
#include <execinfo.h>
|
2021-04-27 16:20:03 +02:00
|
|
|
#endif /* HAVE_BACKTRACE_SYMBOLS */
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
#include <isc/backtrace.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2021-05-20 15:53:50 +02:00
|
|
|
#if HAVE_BACKTRACE_SYMBOLS
|
2021-04-27 16:20:03 +02:00
|
|
|
int
|
|
|
|
isc_backtrace(void **addrs, int maxaddrs) {
|
|
|
|
int n;
|
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
/*
|
|
|
|
* Validate the arguments: intentionally avoid using REQUIRE().
|
|
|
|
* See notes in backtrace.h.
|
|
|
|
*/
|
2021-04-27 16:20:03 +02:00
|
|
|
if (addrs == NULL || maxaddrs <= 0) {
|
|
|
|
return (-1);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* backtrace(3) includes this function itself in the address array,
|
|
|
|
* which should be eliminated from the returned sequence.
|
|
|
|
*/
|
2021-04-27 16:20:03 +02:00
|
|
|
n = backtrace(addrs, maxaddrs);
|
2009-09-01 18:40:25 +00:00
|
|
|
if (n < 2) {
|
2021-04-27 16:20:03 +02:00
|
|
|
return (-1);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-09-01 18:40:25 +00:00
|
|
|
n--;
|
2020-03-11 09:55:48 +01:00
|
|
|
memmove(addrs, &addrs[1], sizeof(addrs[0]) * n);
|
2021-04-27 16:20:03 +02:00
|
|
|
|
|
|
|
return (n);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
isc_backtrace_symbols(void *const *buffer, int size) {
|
|
|
|
return (backtrace_symbols(buffer, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
isc_backtrace_symbols_fd(void *const *buffer, int size, int fd) {
|
|
|
|
backtrace_symbols_fd(buffer, size, fd);
|
2009-09-01 18:40:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 16:20:03 +02:00
|
|
|
#else /* HAVE_BACKTRACE_SYMBOLS */
|
|
|
|
|
|
|
|
int
|
|
|
|
isc_backtrace(void **addrs, int maxaddrs) {
|
2020-03-11 09:55:48 +01:00
|
|
|
UNUSED(addrs);
|
2009-09-01 18:40:25 +00:00
|
|
|
UNUSED(maxaddrs);
|
|
|
|
|
2021-04-27 16:20:03 +02:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
isc_backtrace_symbols(void *const *buffer, int size) {
|
|
|
|
UNUSED(buffer);
|
|
|
|
UNUSED(size);
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
isc_backtrace_symbols_fd(void *const *buffer, int size, int fd) {
|
|
|
|
UNUSED(buffer);
|
|
|
|
UNUSED(size);
|
|
|
|
UNUSED(fd);
|
2009-09-01 18:40:25 +00:00
|
|
|
}
|
2021-04-27 16:20:03 +02:00
|
|
|
|
|
|
|
#endif /* HAVE_BACKTRACE_SYMBOLS */
|