blob: 2808a0d18aeb7700417fd62ca77959f4569db1b2 [file] [log] [blame]
yuezonghec78e2ef2025-02-13 17:57:46 -08001/*******************************************************************************
2 * Copyright (c) 2014 IBM Corp.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and Eclipse Distribution License v1.0 which accompany this distribution.
7 *
8 * The Eclipse Public License is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 * and the Eclipse Distribution License is available at
11 * http://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * Contributors:
14 * Ian Craggs - initial API and implementation and/or initial documentation
15 * Ian Craggs - fix for bug #434081
16 *******************************************************************************/
17
18#ifndef STACKTRACE_H_
19#define STACKTRACE_H_
20
21#include <stdio.h>
22#define NOSTACKTRACE 1
23
24#if defined(NOSTACKTRACE)
25#define FUNC_ENTRY
26#define FUNC_ENTRY_NOLOG
27#define FUNC_ENTRY_MED
28#define FUNC_ENTRY_MAX
29#define FUNC_EXIT
30#define FUNC_EXIT_NOLOG
31#define FUNC_EXIT_MED
32#define FUNC_EXIT_MAX
33#define FUNC_EXIT_RC(x)
34#define FUNC_EXIT_MED_RC(x)
35#define FUNC_EXIT_MAX_RC(x)
36
37#else
38
39#if defined(WIN32)
40#define inline __inline
41#define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM)
42#define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1)
43#define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM)
44#define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM)
45#define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM)
46#define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1)
47#define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM)
48#define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM)
49#define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM)
50#define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM)
51#define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM)
52#else
53#define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM)
54#define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1)
55#define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM)
56#define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM)
57#define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM)
58#define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1)
59#define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM)
60#define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM)
61#define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM)
62#define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM)
63#define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM)
64
65void StackTrace_entry(const char* name, int line, int trace);
66void StackTrace_exit(const char* name, int line, void* return_value, int trace);
67
68void StackTrace_printStack(FILE* dest);
69char* StackTrace_get(unsigned long);
70
71#endif
72
73#endif
74
75
76
77
78#endif /* STACKTRACE_H_ */