2009-09-01 18:40:25 +00:00
|
|
|
/*
|
2016-06-27 14:56:38 +10:00
|
|
|
* Copyright (C) 2009, 2013, 2015, 2016 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/.
|
2009-09-01 18:40:25 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-02 23:48:03 +00:00
|
|
|
/* $Id: backtrace_test.c,v 1.4 2009/09/02 23:48:01 tbox Exp $ */
|
2009-09-01 20:13:44 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2009-09-01 18:40:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <isc/backtrace.h>
|
2015-05-23 14:21:51 +02:00
|
|
|
#include <isc/print.h>
|
2009-09-01 18:40:25 +00:00
|
|
|
#include <isc/result.h>
|
|
|
|
|
|
|
|
const char *expected_symbols[] = {
|
|
|
|
"func3",
|
|
|
|
"func2",
|
|
|
|
"func1",
|
|
|
|
"main"
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
func3() {
|
|
|
|
void *tracebuf[16];
|
|
|
|
int i, nframes;
|
|
|
|
int error = 0;
|
|
|
|
const char *fname;
|
|
|
|
isc_result_t result;
|
|
|
|
unsigned long offset;
|
|
|
|
|
|
|
|
result = isc_backtrace_gettrace(tracebuf, 16, &nframes);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
printf("isc_backtrace_gettrace failed: %s\n",
|
|
|
|
isc_result_totext(result));
|
|
|
|
return (1);
|
|
|
|
}
|
2009-09-02 23:48:03 +00:00
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
if (nframes < 4)
|
|
|
|
error++;
|
2009-09-02 23:48:03 +00:00
|
|
|
|
2009-09-01 18:40:25 +00:00
|
|
|
for (i = 0; i < 4 && i < nframes; i++) {
|
|
|
|
fname = NULL;
|
|
|
|
result = isc_backtrace_getsymbol(tracebuf[i], &fname, &offset);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
error++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(fname, expected_symbols[i]) != 0)
|
|
|
|
error++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
printf("Unexpected result:\n");
|
|
|
|
printf(" # of frames: %d (expected: at least 4)\n", nframes);
|
|
|
|
printf(" symbols:\n");
|
|
|
|
for (i = 0; i < nframes; i++) {
|
|
|
|
fname = NULL;
|
|
|
|
result = isc_backtrace_getsymbol(tracebuf[i], &fname,
|
|
|
|
&offset);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
printf(" [%d] %s\n", i, fname);
|
|
|
|
else {
|
2013-12-04 12:47:23 +11:00
|
|
|
printf(" [%d] %p getsymbol failed: %s\n", i,
|
|
|
|
tracebuf[i], isc_result_totext(result));
|
2009-09-01 18:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
func2() {
|
|
|
|
return (func3());
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
func1() {
|
|
|
|
return (func2());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main() {
|
|
|
|
return (func1());
|
|
|
|
}
|