To run inside MacOS under gdb you need:
set dont-handle-bad-access 1
handle SIGBUS nostop noprint
+
+To run in Linux under gdb, use:
+handle SIGSEGV nostop noprint
-CC=gcc
-CXX=g++
-
-BIN=model
-LIB_NAME=model
-LIB_SO=lib$(LIB_NAME).so
-
-USER_O=userprog.o
-USER_H=libthreads.h
+include common.mk
MODEL_CC=libthreads.cc schedule.cc model.cc threads.cc librace.cc action.cc nodestack.cc clockvector.cc main.cc snapshot-interface.cc cyclegraph.cc datarace.cc impatomic.cc cmodelint.cc promise.cc
MODEL_O=libthreads.o schedule.o model.o threads.o librace.o action.o nodestack.o clockvector.o main.o snapshot-interface.o cyclegraph.o datarace.o impatomic.o cmodelint.o promise.o
SHMEM_O=snapshot.o malloc.o mymemory.o
SHMEM_H=snapshot.h snapshotimp.h mymemory.h
-CPPFLAGS=-Wall -g -O0 -Iinclude -I.
+CPPFLAGS += -Iinclude -I.
LDFLAGS=-ldl -lrt
SHARED=-shared
-all: $(BIN)
+TESTS=test
+
+all: $(LIB_SO) tests
debug: CPPFLAGS += -DCONFIG_DEBUG
debug: all
docs: *.c *.cc *.h
doxygen
-$(BIN): $(USER_O) $(LIB_SO)
- $(CXX) -o $(BIN) $(USER_O) -L. -l$(LIB_NAME)
-
-# note: implicit rule for generating $(USER_O) (i.e., userprog.c -> userprog.o)
-
$(LIB_SO): $(MODEL_O) $(MODEL_H) $(SHMEM_O) $(SHMEM_H)
$(CXX) $(SHARED) -o $(LIB_SO) $(MODEL_O) $(SHMEM_O) $(LDFLAGS)
$(CXX) -fPIC -c $< $(CPPFLAGS)
clean:
- rm -f $(BIN) *.o *.so
+ rm -f *.o *.so
+ $(MAKE) -C $(TESTS) clean
mrclean: clean
rm -rf docs
tags::
ctags -R
+
+tests:: $(LIB_SO)
+ $(MAKE) -C $(TESTS)
--- /dev/null
+# A few common Makefile items
+
+CC=gcc
+CXX=g++
+
+LIB_NAME=model
+LIB_SO=lib$(LIB_NAME).so
+
+CPPFLAGS=-Wall -g -O0
#!/bin/sh
+#
+# Runs a simple test (default: ./test/userprog.o)
+# Syntax:
+# ./run.sh [gdb]
+# ./run.sh [test program] [gdb]
+#
+# If you include a 'gdb' argument, the your program will be launched with gdb.
+# You can also supply a test program argument to run something besides the
+# default program.
+#
+
+BIN=./test/userprog.o
+
export LD_LIBRARY_PATH=.
+[ $# -gt 0 ] && [ "$1" != "gdb" ] && BIN=$1 && shift
+
if [ $# -gt 0 ]; then
if [ "$1" = "gdb" ]; then
- gdb ./model
+ gdb $BIN
else
echo "Invalid argument(s)"
exit 1
fi
else
- ./model
+ $BIN
fi
--- /dev/null
+include ../common.mk
+
+CPPFLAGS += -I.. -I../include
+TESTS=userprog
+
+SRCS = $(wildcard *.c)
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
+all: $(OBJS)
+
+%.o: %.c
+ $(CC) -o $@ $< $(CPPFLAGS) -L.. -l$(LIB_NAME)
+
+clean::
+ rm -f *.o $(TESTS)
--- /dev/null
+#include <stdio.h>
+
+#include "libthreads.h"
+#include "librace.h"
+#include "stdatomic.h"
+
+atomic_int x;
+atomic_int y;
+
+static void a(void *obj)
+{
+ int r1=atomic_load_explicit(&y, memory_order_relaxed);
+ atomic_store_explicit(&x, r1, memory_order_relaxed);
+ printf("r1=%u\n",r1);
+}
+
+static void b(void *obj)
+{
+ int r2=atomic_load_explicit(&x, memory_order_relaxed);
+ atomic_store_explicit(&y, 42, memory_order_relaxed);
+ printf("r2=%u\n",r2);
+}
+
+void user_main()
+{
+ thrd_t t1, t2;
+
+ atomic_init(&x, 0);
+ atomic_init(&y, 0);
+
+ printf("Thread %d: creating 2 threads\n", thrd_current());
+ thrd_create(&t1, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
+
+ thrd_join(t1);
+ thrd_join(t2);
+ printf("Thread %d is finished\n", thrd_current());
+}
+++ /dev/null
-#include <stdio.h>
-
-#include "libthreads.h"
-#include "librace.h"
-#include "stdatomic.h"
-
-atomic_int x;
-atomic_int y;
-
-static void a(void *obj)
-{
- int r1=atomic_load_explicit(&y, memory_order_relaxed);
- atomic_store_explicit(&x, r1, memory_order_relaxed);
- printf("r1=%u\n",r1);
-}
-
-static void b(void *obj)
-{
- int r2=atomic_load_explicit(&x, memory_order_relaxed);
- atomic_store_explicit(&y, 42, memory_order_relaxed);
- printf("r2=%u\n",r2);
-}
-
-void user_main()
-{
- thrd_t t1, t2;
-
- atomic_init(&x, 0);
- atomic_init(&y, 0);
-
- printf("Thread %d: creating 2 threads\n", thrd_current());
- thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&b, NULL);
-
- thrd_join(t1);
- thrd_join(t2);
- printf("Thread %d is finished\n", thrd_current());
-}