socsvn commit: r240424 - in soc2012/gmiller/locking-head: . include
lib/libwitness tools/regression/lib/libwitness
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Thu Aug 16 03:36:35 UTC 2012
Author: gmiller
Date: Thu Aug 16 03:36:33 2012
New Revision: 240424
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240424
Log:
r240389 at FreeBSD-dev: root | 2012-08-15 00:20:46 -0500
If USE_LIBUNWIND is present in src.conf, attempt to use devel/libunwind to
generate backtraces for the lock acquisitions that resulted in a LoR.
Added:
soc2012/gmiller/locking-head/lib/libwitness/unwind.c
Modified:
soc2012/gmiller/locking-head/ (props changed)
soc2012/gmiller/locking-head/include/pthread_np.h
soc2012/gmiller/locking-head/lib/libwitness/Makefile
soc2012/gmiller/locking-head/lib/libwitness/lists.c
soc2012/gmiller/locking-head/lib/libwitness/logs.c
soc2012/gmiller/locking-head/lib/libwitness/witness.h
soc2012/gmiller/locking-head/lib/libwitness/xml.c
soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile
Modified: soc2012/gmiller/locking-head/include/pthread_np.h
==============================================================================
Modified: soc2012/gmiller/locking-head/lib/libwitness/Makefile
==============================================================================
Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c
==============================================================================
Added: soc2012/gmiller/locking-head/lib/libwitness/unwind.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/lib/libwitness/unwind.c Thu Aug 16 03:36:33 2012 (r240424)
@@ -0,0 +1,101 @@
+/*-
+ * Copyright (c) 2012 Greg Miller <gmiller at freebsd.org>..
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include "witness.h"
+
+char *
+trace_str(struct backtrace *trace)
+{
+ char *buffer;
+ int length = 1;
+ struct stack_frame *frame;
+ int count = 0;
+ char line_buf[MAX_FRAME_ID_LENGTH + 4];
+
+ buffer = malloc(1);
+ if (buffer != NULL) {
+ buffer[0] = '\0';
+
+ SLIST_FOREACH(frame, trace, frame_next) {
+ if (strncmp(frame->id, "pthread_", 8) == 0) {
+ break;
+ }
+
+ sprintf(line_buf, "%d: %s\n", count, frame->id);
+
+ length += strlen(line_buf);
+ buffer = reallocf(buffer, length);
+
+ strcat(buffer, line_buf);
+
+ if (++count == 10) {
+ break;
+ }
+ }
+ }
+
+ return (buffer);
+}
+
+#ifdef USE_LIBUNWIND
+
+#include <libunwind.h>
+
+void
+record_backtrace(struct backtrace *trace)
+{
+ unw_context_t context;
+ unw_cursor_t cursor;
+ struct stack_frame *frame;
+ unw_word_t offset;
+
+ free_frame(trace);
+
+ unw_getcontext(&context);
+ unw_init_local(&cursor, &context);
+ while (unw_step(&cursor) > 0) {
+ frame = malloc(sizeof(struct stack_frame));
+ if (frame == NULL) {
+ return;
+ }
+
+ unw_get_proc_name(&cursor, frame->id, MAX_FRAME_ID_LENGTH,
+ &offset);
+
+ SLIST_INSERT_HEAD(trace, frame, frame_next);
+ }
+}
+
+#else
+
+void
+record_backtrace(struct backtrace *trace)
+{
+ trace = trace;
+}
+
+#endif
Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h
==============================================================================
Modified: soc2012/gmiller/locking-head/lib/libwitness/xml.c
==============================================================================
Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/Makefile
==============================================================================
More information about the svn-soc-all
mailing list