]> git.proxmox.com Git - mirror_ovs.git/blame - lib/backtrace.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / backtrace.h
CommitLineData
064af421 1/*
e0edde6f 2 * Copyright (c) 2009 Nicira, Inc.
064af421 3 *
a14bc59f
BP
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
064af421 7 *
a14bc59f
BP
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
064af421
BP
15 */
16
17#ifndef BACKTRACE_H
18#define BACKTRACE_H 1
19
20#include <stdint.h>
3e8a2ad1 21#include "openvswitch/dynamic-string.h"
d0b99d38 22
e2ed6fbe
WT
23#ifdef HAVE_UNWIND
24#define UNW_LOCAL_ONLY
25#include <libunwind.h>
26#endif
27
d0b99d38
AZ
28/* log_backtrace() will save the backtrace of a running program
29 * into the log at the DEBUG level.
30 *
31 * To use it, insert the following code to where backtrace is
32 * desired:
33 * #include "backtrace.h"
34 *
b5343307
BP
35 * log_backtrace(); <-- plain
36 * log_backtrace_msg("your message"); <-- with a message
d0b99d38
AZ
37 *
38 *
39 * A typical log will look like the following. The hex numbers listed after
40 * "backtrace" are the addresses of the backtrace.
41 *
42 * 2014-03-13T23:18:11.979Z|00002|backtrace(revalidator_6)|ERR|lib/dpif-netdev.c:1312: (backtrace: 0x00521f57 0x00460365 0x00463ea4 0x0046470b 0x0043b32d 0x0043bac3 0x0043bae2 0x0043943b 0x004c22b3 0x2b5b3ac94e9a 0x2b5b3b4a33fd)
43 *
44 * The following bash command can be used to view backtrace in
45 * a more readable form.
46 * addr2line -p -e vswitchd/ovs-vswitchd <cut-and-paste back traces>
47 *
48 * An typical run and output will look like:
49 * addr2line -p -e vswitchd/ovs-vswitchd 0x00521f57 0x00460365 0x00463ea4
50 * 0x0046470b 0x0043b32d 0x0043bac3 0x0043bae2 0x0043943b 0x004c22b3
51 * 0x2b5b3ac94e9a 0x2b5b3b4a33fd
52 *
53 * openvswitch/lib/backtrace.c:33
54 * openvswitch/lib/dpif-netdev.c:1312
55 * openvswitch/lib/dpif.c:937
56 * openvswitch/lib/dpif.c:1258
57 * openvswitch/ofproto/ofproto-dpif-upcall.c:1440
58 * openvswitch/ofproto/ofproto-dpif-upcall.c:1595
59 * openvswitch/ofproto/ofproto-dpif-upcall.c:160
60 * openvswitch/ofproto/ofproto-dpif-upcall.c:717
61 * openvswitch/lib/ovs-thread.c:268
62 * ??:0
63 * ??:0
64 */
65
8f3676cf
TG
66#define log_backtrace() log_backtrace_at(NULL, OVS_SOURCE_LOCATOR);
67#define log_backtrace_msg(msg) log_backtrace_at(msg, OVS_SOURCE_LOCATOR);
064af421
BP
68
69#define BACKTRACE_MAX_FRAMES 31
70
71struct backtrace {
72 int n_frames;
73 uintptr_t frames[BACKTRACE_MAX_FRAMES];
74};
75
e2ed6fbe
WT
76#ifdef HAVE_UNWIND
77#define UNW_MAX_DEPTH 32
78#define UNW_MAX_FUNCN 32
79#define UNW_MAX_BUF \
80 (UNW_MAX_DEPTH * sizeof(struct unw_backtrace))
81
82struct unw_backtrace {
83 char func[UNW_MAX_FUNCN];
84 unw_word_t ip;
85 unw_word_t offset;
86};
87#endif
88
064af421 89void backtrace_capture(struct backtrace *);
d0b99d38 90void log_backtrace_at(const char *msg, const char *where);
e2ed6fbe 91void log_received_backtrace(int fd);
064af421
BP
92
93#endif /* backtrace.h */