2009-09-01 18:40:25 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2009-09-01 18:40:25 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10: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 http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2009-09-01 18:40:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <string.h>
|
2020-03-11 09:55:48 +01:00
|
|
|
#ifdef HAVE_BACKTRACE
|
2009-09-01 18:40:25 +00:00
|
|
|
#include <execinfo.h>
|
2020-03-11 09:55:48 +01:00
|
|
|
#endif /* HAVE_BACKTRACE */
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
#include <isc/backtrace.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
2020-03-11 09:55:48 +01:00
|
|
|
#ifdef HAVE_BACKTRACE
|
2009-09-01 18:40:25 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) {
|
2009-09-01 18:40:25 +00:00
|
|
|
/*
|
|
|
|
* Validate the arguments: intentionally avoid using REQUIRE().
|
|
|
|
* See notes in backtrace.h.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (addrs == NULL || nframes == NULL) {
|
2009-09-01 18:40:25 +00:00
|
|
|
return (ISC_R_FAILURE);
|
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.
|
|
|
|
*/
|
2020-03-11 09:55:48 +01:00
|
|
|
int n = backtrace(addrs, maxaddrs);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (n < 2) {
|
2009-09-01 18:40:25 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
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);
|
2009-09-01 18:40:25 +00:00
|
|
|
*nframes = n;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2020-03-11 09:55:48 +01:00
|
|
|
#else /* HAVE_BACKTRACE */
|
2009-09-01 18:40:25 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) {
|
2020-03-11 09:55:48 +01:00
|
|
|
UNUSED(addrs);
|
2009-09-01 18:40:25 +00:00
|
|
|
UNUSED(maxaddrs);
|
2020-03-11 09:55:48 +01:00
|
|
|
UNUSED(nframes);
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
}
|
2020-03-11 09:55:48 +01:00
|
|
|
#endif /* HAVE_BACKTRACE */
|