]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/backtrace.c
2 * Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include "backtrace.h"
25 #include "openvswitch/vlog.h"
28 VLOG_DEFINE_THIS_MODULE(backtrace
);
33 backtrace_capture(struct backtrace
*b
)
35 void *frames
[BACKTRACE_MAX_FRAMES
];
38 b
->n_frames
= backtrace(frames
, BACKTRACE_MAX_FRAMES
);
39 for (i
= 0; i
< b
->n_frames
; i
++) {
40 b
->frames
[i
] = (uintptr_t) frames
[i
];
46 backtrace_capture(struct backtrace
*backtrace
)
48 backtrace
->n_frames
= 0;
53 backtrace_format(const struct backtrace
*b
, struct ds
*ds
)
58 ds_put_cstr(ds
, " (backtrace:");
59 for (i
= 0; i
< b
->n_frames
; i
++) {
60 ds_put_format(ds
, " 0x%08"PRIxPTR
, b
->frames
[i
]);
69 log_backtrace_at(const char *msg
, const char *where
)
72 struct ds ds
= DS_EMPTY_INITIALIZER
;
74 backtrace_capture(&b
);
76 ds_put_format(&ds
, "%s ", msg
);
79 ds_put_cstr(&ds
, where
);
80 VLOG_ERR("%s", backtrace_format(&b
, &ds
));
87 log_received_backtrace(int fd
) {
89 struct unw_backtrace backtrace
[UNW_MAX_DEPTH
];
91 VLOG_WARN("%s fd %d", __func__
, fd
);
92 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
93 memset(backtrace
, 0, UNW_MAX_BUF
);
95 byte_read
= read(fd
, backtrace
, UNW_MAX_BUF
);
97 VLOG_ERR("Read fd %d failed: %s", fd
,
99 } else if (byte_read
> 0) {
100 VLOG_WARN("SIGSEGV detected, backtrace:");
101 for (int i
= 0; i
< UNW_MAX_DEPTH
; i
++) {
102 if (backtrace
[i
].func
[0] == 0) {
105 VLOG_WARN("0x%016"PRIxPTR
" <%s+0x%"PRIxPTR
">\n",
108 backtrace
[i
].offset
);
112 #else /* !HAVE_UNWIND */
114 log_received_backtrace(int daemonize_fd OVS_UNUSED
) {
115 VLOG_WARN("Backtrace using libunwind not supported.");
117 #endif /* HAVE_UNWIND */