X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fbacktrace.h;h=2527243f7718672c4d47991cd6890eb4b40bee9d;hb=003ce655b7116d18c86a74c50391e54990346931;hp=49b250c7f127efbf35a8c0029a50a6e6b53157d5;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=sliver-openvswitch.git diff --git a/lib/backtrace.h b/lib/backtrace.h index 49b250c7f..2527243f7 100644 --- a/lib/backtrace.h +++ b/lib/backtrace.h @@ -1,23 +1,65 @@ /* - * Copyright (c) 2009 Nicira Networks. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * Copyright (c) 2009 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef BACKTRACE_H #define BACKTRACE_H 1 #include +#include "dynamic-string.h" + +/* log_backtrace() will save the backtrace of a running program + * into the log at the DEBUG level. + * + * To use it, insert the following code to where backtrace is + * desired: + * #include "backtrace.h" + * + * log_backtrace(); + * // A message can be added with log_backtrace_msg("your message") + * + * + * A typical log will look like the following. The hex numbers listed after + * "backtrace" are the addresses of the backtrace. + * + * 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) + * + * The following bash command can be used to view backtrace in + * a more readable form. + * addr2line -p -e vswitchd/ovs-vswitchd + * + * An typical run and output will look like: + * addr2line -p -e vswitchd/ovs-vswitchd 0x00521f57 0x00460365 0x00463ea4 + * 0x0046470b 0x0043b32d 0x0043bac3 0x0043bae2 0x0043943b 0x004c22b3 + * 0x2b5b3ac94e9a 0x2b5b3b4a33fd + * + * openvswitch/lib/backtrace.c:33 + * openvswitch/lib/dpif-netdev.c:1312 + * openvswitch/lib/dpif.c:937 + * openvswitch/lib/dpif.c:1258 + * openvswitch/ofproto/ofproto-dpif-upcall.c:1440 + * openvswitch/ofproto/ofproto-dpif-upcall.c:1595 + * openvswitch/ofproto/ofproto-dpif-upcall.c:160 + * openvswitch/ofproto/ofproto-dpif-upcall.c:717 + * openvswitch/lib/ovs-thread.c:268 + * ??:0 + * ??:0 + */ + +#define log_backtrace() log_backtrace_at(NULL, SOURCE_LOCATOR); +#define log_backtrace_msg(msg) log_backtrace_at(msg, SOURCE_LOCATOR); #define BACKTRACE_MAX_FRAMES 31 @@ -27,5 +69,6 @@ struct backtrace { }; void backtrace_capture(struct backtrace *); +void log_backtrace_at(const char *msg, const char *where); #endif /* backtrace.h */