netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / lib / backtrace.h
1 /*
2  * Copyright (c) 2009 Nicira, Inc.
3  *
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:
7  *
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.
15  */
16
17 #ifndef BACKTRACE_H
18 #define BACKTRACE_H 1
19
20 #include <stdint.h>
21 #include "dynamic-string.h"
22
23 /* log_backtrace() will save the backtrace of a running program
24  * into the log at the DEBUG level.
25  *
26  * To use it, insert the following code to where backtrace is
27  * desired:
28  *       #include "backtrace.h"
29  *
30  *       log_backtrace();
31  *       // A message can be added with log_backtrace_msg("your message")
32  *
33  *
34  * A typical log will look like the following. The hex numbers listed after
35  * "backtrace" are the addresses of the backtrace.
36  *
37  * 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)
38  *
39  * The following bash command can be used to  view backtrace in
40  * a more readable form.
41  * addr2line -p -e vswitchd/ovs-vswitchd <cut-and-paste back traces>
42  *
43  * An typical run and output will look like:
44  * addr2line -p -e vswitchd/ovs-vswitchd  0x00521f57 0x00460365 0x00463ea4
45  * 0x0046470b 0x0043b32d 0x0043bac3 0x0043bae2 0x0043943b 0x004c22b3
46  * 0x2b5b3ac94e9a 0x2b5b3b4a33fd
47  *
48  * openvswitch/lib/backtrace.c:33
49  * openvswitch/lib/dpif-netdev.c:1312
50  * openvswitch/lib/dpif.c:937
51  * openvswitch/lib/dpif.c:1258
52  * openvswitch/ofproto/ofproto-dpif-upcall.c:1440
53  * openvswitch/ofproto/ofproto-dpif-upcall.c:1595
54  * openvswitch/ofproto/ofproto-dpif-upcall.c:160
55  * openvswitch/ofproto/ofproto-dpif-upcall.c:717
56  * openvswitch/lib/ovs-thread.c:268
57  * ??:0
58  * ??:0
59  */
60
61 #define log_backtrace() log_backtrace_at(NULL, OVS_SOURCE_LOCATOR);
62 #define log_backtrace_msg(msg) log_backtrace_at(msg, OVS_SOURCE_LOCATOR);
63
64 #define BACKTRACE_MAX_FRAMES 31
65
66 struct backtrace {
67     int n_frames;
68     uintptr_t frames[BACKTRACE_MAX_FRAMES];
69 };
70
71 void backtrace_capture(struct backtrace *);
72 void log_backtrace_at(const char *msg, const char *where);
73
74 #endif /* backtrace.h */