From 32bc5f858ac8b1bae23d319706db2952b4ff8d4e Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 15:51:40 -0300 Subject: [PATCH 1/6] New makefile 1. A single root makefile for everything: library, examples, tests 2. Introduce makefile variables for all compilation flags 3. Add comments to explain the -Wl,-E 4. Use "install" instead of "cp", to set correct permissions. 5. Can run tests without "make install", using local ptracer.h and pt-run. Fixes #11 ps.: The new filenames changed all the tracebacks. Can we change the tests so that they don't break so easily? --- .gitignore | 3 +- Makefile | 90 +++++++++++++++++------- examples/fibonacci/Makefile | 18 ----- {lib => include}/ptracer.h | 32 ++++----- spec/tracebacks/anon_lua/Makefile | 12 ---- spec/tracebacks/depth_recursion/Makefile | 12 ---- spec/tracebacks/dispatch/Makefile | 12 ---- spec/tracebacks/ellipsis/Makefile | 12 ---- spec/tracebacks/multimod/Makefile | 14 ---- spec/tracebacks/singular/Makefile | 12 ---- spec/tracebacks_spec.lua | 56 +++++++-------- src/{pt-run/main.c => pt-run.c} | 18 ++--- 12 files changed, 121 insertions(+), 170 deletions(-) delete mode 100644 examples/fibonacci/Makefile rename {lib => include}/ptracer.h (95%) delete mode 100644 spec/tracebacks/anon_lua/Makefile delete mode 100644 spec/tracebacks/depth_recursion/Makefile delete mode 100644 spec/tracebacks/dispatch/Makefile delete mode 100644 spec/tracebacks/ellipsis/Makefile delete mode 100644 spec/tracebacks/multimod/Makefile delete mode 100644 spec/tracebacks/singular/Makefile rename src/{pt-run/main.c => pt-run.c} (97%) diff --git a/.gitignore b/.gitignore index 4e2aede..49627b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o *.a *.so -/pt-run + +pt-run diff --git a/Makefile b/Makefile index ba5ed33..9f83253 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,79 @@ # Copyright (c) 2024, The Pallene Developers # Pallene Tracer is licensed under the MIT license. # Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: MIT -CC := gcc -CFLAGS := -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra +# Where to install our things +PREFIX = /usr/local +BINDIR = $(PREFIX)/bin +INCDIR = $(PREFIX)/include -LUA_DIR := /usr +# Where to find Lua libraries +LUA_PREFIX = /usr/local +LUA_BINDIR = $(LUA_PREFIX)/bin +LUA_INCDIR = $(LUA_PREFIX)/include +LUA_LIBDIR = $(LUA_PREFIX)/lib -INSTALL_DIR := /usr/local -INSTALL_INCDIR := $(INSTALL_DIR)/include -INSTALL_LIBDIR := $(INSTALL_DIR)/lib -INSTALL_BINDIR := $(INSTALL_DIR)/bin +# How to install files +INSTALL= install -p +INSTALL_EXEC= $(INSTALL) -m 0755 +INSTALL_DATA= $(INSTALL) -m 0644 -.PHONY: install ptracer_header pt-run libptracer uninstall clean +# C compilation flags +CFLAGS = -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra +CPPFLAGS = -I$(LUA_INCDIR) -Iinclude +LIBFLAG = -fPIC -shared -install: ptracer_header pt-run - cp pt-run $(INSTALL_BINDIR) +# The -Wl,-E tells the linker to not throw away unused Lua API symbols. +# We need them for Lua modules that are dynamically linked via require +PTRUN_LDFLAGS = -L$(LUA_LIBDIR) -Wl,-E +PTRUN_LDLIBS = -llua -lm -# We need the `ptracer.h` header to be installed first. -ptracer_header: - cp lib/ptracer.h $(INSTALL_INCDIR) +# =================== +# Compilation targets +# =================== -pt-run: - $(CC) $(CFLAGS) src/pt-run/main.c -o pt-run -llua -lm -Wl,-E -L$(LUA_DIR)/lib +.PHONY: library examples tests all install uninstall clean -uninstall: - rm -rf $(INSTALL_INCDIR)/ptracer.h - rm -rf $(INSTALL_BINDIR)/pt-run +library: \ + src/pt-run -clean: - rm -rf examples/*/*.so - rm -rf spec/tracebacks/*/*.so - rm -rf *.so - rm -rf pt-run +examples: library \ + examples/fibonacci/fibonacci.so +tests: library \ + spec/tracebacks/anon_lua/module.so \ + spec/tracebacks/depth_recursion/module.so \ + spec/tracebacks/dispatch/module.so \ + spec/tracebacks/ellipsis/module.so \ + spec/tracebacks/multimod/module_a.so \ + spec/tracebacks/multimod/module_b.so \ + spec/tracebacks/singular/module.so + +all: library examples specs + +install: src/pt-run include/ptracer.h + $(INSTALL_EXEC) src/pt-run $(BINDIR) + $(INSTALL_DATA) include/ptracer.h $(INCDIR) + +uninstall: + rm -rf $(INCDIR)/ptracer.h + rm -rf $(BINDIR)/pt-run + +clean: + rm -rf src/pt-run examples/*/*.so spec/tracebacks/*/*.so + +%.so: %.c + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBFLAG) $< -o $@ + +src/pt-run: src/pt-run.c include/ptracer.h + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(PTRUN_LDFLAGS) $< -o $@ $(PTRUN_LDLIBS) + +examples/fibonacci/fibonacci.so: examples/fibonacci/fibonacci.c include/ptracer.h +spec/tracebacks/anon_lua/module.so: spec/tracebacks/anon_lua/module.c include/ptracer.h +spec/tracebacks/depth_recursion/module.so: spec/tracebacks/depth_recursion/module.c include/ptracer.h +spec/tracebacks/dispatch/module.so: spec/tracebacks/dispatch/module.c include/ptracer.h +spec/tracebacks/ellipsis/module.so: spec/tracebacks/ellipsis/module.c include/ptracer.h +spec/tracebacks/multimod/module_a.so: spec/tracebacks/multimod/module_a.c include/ptracer.h +spec/tracebacks/multimod/module_b.so: spec/tracebacks/multimod/module_b.c include/ptracer.h +spec/tracebacks/singular/module.so: spec/tracebacks/singular/module.c include/ptracer.h diff --git a/examples/fibonacci/Makefile b/examples/fibonacci/Makefile deleted file mode 100644 index 948af4d..0000000 --- a/examples/fibonacci/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all debug clean -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -O2 -shared fibonacci.c -o fibonacci.so - -debug: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -O2 -DPT_DEBUG -shared fibonacci.c -o fibonacci.so - -clean: - rm -rf fibonacci.so diff --git a/lib/ptracer.h b/include/ptracer.h similarity index 95% rename from lib/ptracer.h rename to include/ptracer.h index fc98009..1373f7b 100644 --- a/lib/ptracer.h +++ b/include/ptracer.h @@ -1,8 +1,8 @@ -/* +/* * Copyright (c) 2024, The Pallene Developers * Pallene Tracer is licensed under the MIT license. * Please refer to the LICENSE and AUTHORS files for details - * SPDX-License-Identifier: MIT + * SPDX-License-Identifier: MIT */ #ifndef PALLENE_TRACER_H @@ -50,16 +50,16 @@ #define PALLENE_TRACER_SETLINE(fnstack, line) pallene_tracer_setline(fnstack, line) #define PALLENE_TRACER_FRAMEEXIT(fnstack) pallene_tracer_frameexit(fnstack) -#else -#define PALLENE_TRACER_FRAMEENTER(fnstack, frame) -#define PALLENE_TRACER_SETLINE(fnstack, line) -#define PALLENE_TRACER_FRAMEEXIT(fnstack) +#else +#define PALLENE_TRACER_FRAMEENTER(fnstack, frame) +#define PALLENE_TRACER_SETLINE(fnstack, line) +#define PALLENE_TRACER_FRAMEEXIT(fnstack) #endif // PT_DEBUG /* Not part of the API. */ #ifdef PT_DEBUG -#define _PALLENE_TRACER_PREPARE_C_FRAME(fn_name, filename, var_name) \ -pt_fn_details_t var_name##_details = \ +#define _PALLENE_TRACER_PREPARE_C_FRAME(fn_name, filename, var_name) \ +pt_fn_details_t var_name##_details = \ PALLENE_TRACER_FN_DETAILS(fn_name, filename); \ pt_frame_t var_name = PALLENE_TRACER_C_FRAME(var_name##_details) @@ -70,21 +70,21 @@ pt_frame_t var_name = PALLENE_TRACER_LUA_FRAME(fnptr) lua_toclose(L, -1) #else -#define _PALLENE_TRACER_PREPARE_LUA_FRAME(fnptr, var_name) -#define _PALLENE_TRACER_PREPARE_C_FRAME(fn_name, filename, var_name) -#define _PALLENE_TRACER_FINALIZER(L, location) +#define _PALLENE_TRACER_PREPARE_LUA_FRAME(fnptr, var_name) +#define _PALLENE_TRACER_PREPARE_C_FRAME(fn_name, filename, var_name) +#define _PALLENE_TRACER_FINALIZER(L, location) #endif // PT_DEBUG /* ---- DATA-STRUCTURE HELPER MACROS ---- */ /* Use this macro to fill in the details structure. */ -/* E.U.: +/* E.U.: pt_fn_details_t det = PALLENE_TRACER_FN_DETAILS("fn_name", "some_mod.c"); */ #define PALLENE_TRACER_FN_DETAILS(name, fname) \ { .fn_name = name, .filename = fname } -/* Use this macro to fill in the frame structure as a +/* Use this macro to fill in the frame structure as a Lua interface frame. */ /* E.U.: `pt_frame_t frame = PALLENE_TRACER_LUA_FRAME(lua_fn);` */ #define PALLENE_TRACER_LUA_FRAME(fnptr) \ @@ -103,9 +103,9 @@ pt_frame_t var_name = PALLENE_TRACER_LUA_FRAME(fnptr) /* ---- API HELPER MACROS ---- */ /* Use this macro the bypass some frameenter boilerplates for Lua interface frames. */ -/* Note: `location` is where the finalizer object is in the stack, acquired from +/* Note: `location` is where the finalizer object is in the stack, acquired from `pallene_tracer_init()` function. If the object is passed to Lua C functions as an - upvalue, this should be `lua_upvalueindex(n)`. Otherwise, it should just be a number + upvalue, this should be `lua_upvalueindex(n)`. Otherwise, it should just be a number denoting the parameter index where the object is found if passed as a plain parameter to the functon. */ /* The `var_name` indicates the name of the `pt_frame_t` structure variable. */ @@ -185,7 +185,7 @@ PT_API pt_fnstack_t *pallene_tracer_init(lua_State *L); /* Pushes a frame to the stack. The frame structure is self-managed for every function. */ static inline void pallene_tracer_frameenter(pt_fnstack_t *fnstack, pt_frame_t *restrict frame) { /* Have we ran out of stack entries? If we do, stop pushing frames. */ - if(luai_likely(fnstack->count < PALLENE_TRACER_MAX_CALLSTACK)) + if(luai_likely(fnstack->count < PALLENE_TRACER_MAX_CALLSTACK)) fnstack->stack[fnstack->count] = *frame; fnstack->count++; diff --git a/spec/tracebacks/anon_lua/Makefile b/spec/tracebacks/anon_lua/Makefile deleted file mode 100644 index 15fb481..0000000 --- a/spec/tracebacks/anon_lua/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module.c -o module.so diff --git a/spec/tracebacks/depth_recursion/Makefile b/spec/tracebacks/depth_recursion/Makefile deleted file mode 100644 index 15fb481..0000000 --- a/spec/tracebacks/depth_recursion/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module.c -o module.so diff --git a/spec/tracebacks/dispatch/Makefile b/spec/tracebacks/dispatch/Makefile deleted file mode 100644 index fb0fceb..0000000 --- a/spec/tracebacks/dispatch/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wextra -Wall -fPIC -DPT_DEBUG -shared module.c -o module.so diff --git a/spec/tracebacks/ellipsis/Makefile b/spec/tracebacks/ellipsis/Makefile deleted file mode 100644 index 15fb481..0000000 --- a/spec/tracebacks/ellipsis/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module.c -o module.so diff --git a/spec/tracebacks/multimod/Makefile b/spec/tracebacks/multimod/Makefile deleted file mode 100644 index 5669961..0000000 --- a/spec/tracebacks/multimod/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc -LIB_DIR := /usr/local/lib - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module_a.c -o module_a.so - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module_b.c -o module_b.so diff --git a/spec/tracebacks/singular/Makefile b/spec/tracebacks/singular/Makefile deleted file mode 100644 index 15fb481..0000000 --- a/spec/tracebacks/singular/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) 2024, The Pallene Developers -# Pallene Tracer is licensed under the MIT license. -# Please refer to the LICENSE and AUTHORS files for details -# SPDX-License-Identifier: MIT - -CC := gcc - -.PHONY : all -.SILENT: - -all: - $(CC) -std=c99 -pedantic -Wall -Wextra -fPIC -DPT_DEBUG -shared module.c -o module.so diff --git a/spec/tracebacks_spec.lua b/spec/tracebacks_spec.lua index 8ad5ced..b861ea1 100644 --- a/spec/tracebacks_spec.lua +++ b/spec/tracebacks_spec.lua @@ -6,12 +6,12 @@ local util = require "spec.util" local function assert_test(example, expected_content) - local cdir = util.shell_quote("spec/tracebacks/"..example) - local ok, err = util.execute(string.format("cd %s && make", cdir)) - assert(ok, err) + assert(util.execute("make --quiet tests")) + local cdir = util.shell_quote("spec/tracebacks/"..example) + local ptrun = util.shell_quote("../../../src/pt-run") local ok, _, output_content, err_content = - util.outputs_of_execute(string.format("cd %s && pt-run main.lua", cdir)) + util.outputs_of_execute(string.format("cd %s && %s main.lua", cdir, ptrun)) assert(not ok, output_content) assert.are.same(expected_content, err_content) end @@ -20,10 +20,10 @@ it("Dispatch", function() assert_test("dispatch", [[ Runtime error: main.lua:9: Error from a C function, which has no trace in Lua callstack! Stack traceback: - module.c:48: in function 'some_oblivious_c_function' - module.c:92: in function 'module_fn_2' + spec/tracebacks/dispatch/module.c:48: in function 'some_oblivious_c_function' + spec/tracebacks/dispatch/module.c:92: in function 'module_fn_2' main.lua:9: in function 'lua_callee_1' - module.c:61: in function 'module_fn_1' + spec/tracebacks/dispatch/module.c:61: in function 'module_fn_1' main.lua:12: in
]]) end) @@ -32,8 +32,8 @@ it("Singular", function() assert_test("singular", [[ Runtime error: main.lua:9: Life's !good Stack traceback: - module.c:49: in function 'lifes_good_fn' - module.c:59: in function 'singular_fn' + spec/tracebacks/singular/module.c:49: in function 'lifes_good_fn' + spec/tracebacks/singular/module.c:59: in function 'singular_fn' main.lua:9: in function 'some_lua_fn' main.lua:12: in
]]) @@ -44,9 +44,9 @@ it("Multi-module", function() assert_test("multimod", [[ Runtime error: main.lua:10: Error from another module! Stack traceback: - module_b.c:19: in function 'another_mod_fn' + spec/tracebacks/multimod/module_b.c:19: in function 'another_mod_fn' main.lua:10: in function 'some_lua_fn' - module_a.c:20: in function 'some_mod_fn' + spec/tracebacks/multimod/module_a.c:20: in function 'some_mod_fn' main.lua:13: in
]]) end) @@ -57,15 +57,15 @@ Runtime error: main.lua:10: Depth reached 0! Stack traceback: C: in function 'error' main.lua:10: in function 'lua_fn' - module.c:56: in function 'module_fn' + spec/tracebacks/depth_recursion/module.c:56: in function 'module_fn' main.lua:13: in function 'lua_fn' - module.c:56: in function 'module_fn' + spec/tracebacks/depth_recursion/module.c:56: in function 'module_fn' main.lua:13: in function 'lua_fn' - module.c:56: in function 'module_fn' + spec/tracebacks/depth_recursion/module.c:56: in function 'module_fn' main.lua:13: in function 'lua_fn' - module.c:56: in function 'module_fn' + spec/tracebacks/depth_recursion/module.c:56: in function 'module_fn' main.lua:13: in function 'lua_fn' - module.c:56: in function 'module_fn' + spec/tracebacks/depth_recursion/module.c:56: in function 'module_fn' main.lua:13: in function 'lua_fn' main.lua:16: in
]]) @@ -75,10 +75,10 @@ it("Anonymous Lua Fn", function() assert_test("anon_lua", [[ Runtime error: main.lua:9: Error from a C function, which has no trace in Lua callstack! Stack traceback: - module.c:48: in function 'some_oblivious_c_function' - module.c:92: in function 'module_fn_2' + spec/tracebacks/anon_lua/module.c:48: in function 'some_oblivious_c_function' + spec/tracebacks/anon_lua/module.c:92: in function 'module_fn_2' main.lua:9: in function '' - module.c:61: in function 'module_fn_1' + spec/tracebacks/anon_lua/module.c:61: in function 'module_fn_1' main.lua:12: in
]]) end) @@ -87,27 +87,27 @@ it("Traceback Ellipsis", function() assert_test("ellipsis", [[ Runtime error: C stack overflow Stack traceback: - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' ... (Skipped 380 frames) ... main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' - module.c:52: in function 'module_fn' + spec/tracebacks/ellipsis/module.c:52: in function 'module_fn' main.lua:9: in function 'lua_fn' main.lua:12: in
]]) diff --git a/src/pt-run/main.c b/src/pt-run.c similarity index 97% rename from src/pt-run/main.c rename to src/pt-run.c index 824ad37..64edf87 100644 --- a/src/pt-run/main.c +++ b/src/pt-run.c @@ -2,7 +2,7 @@ * Copyright (c) 2024, The Pallene Developers * Pallene Tracer is licensed under the MIT license. * Please refer to the LICENSE and AUTHORS files for details - * SPDX-License-Identifier: MIT + * SPDX-License-Identifier: MIT */ #include @@ -13,7 +13,7 @@ #include #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Traceback ellipsis top threshold. How many frames should we print first to trigger ellipsis? */ @@ -23,7 +23,7 @@ /* This should always be 2 fewer than top threshold, for symmetry. Becuase we will always have 2 tail frames lingering around at - at the end which is not captured by '_countlevels'. Lua also + at the end which is not captured by '_countlevels'. Lua also do it like this. */ #ifndef PT_RUN_TRACEBACK_BOTTOM_THRESHOLD #define PT_RUN_TRACEBACK_BOTTOM_THRESHOLD 8 @@ -38,7 +38,7 @@ static void pt_run_help() { printf("Pallene Tracer runner for call-stack backtrace\n\n"); printf("Arguments:\n" " lua_script Lua file to debug\n" - " args ... Arguments passed to Lua script\n\n"); + " args ... Arguments passed to Lua script\n\n"); printf("Options:\n" " -h, --help Show this help message and exit\n"); } @@ -279,7 +279,7 @@ int main(int argc, char **argv) { if(!strncmp(argv[1], "-", 1)) { char *match = argv[1] + 1; - if(!strcmp(match, "h") || !strcmp(match, "-help")) + if(!strcmp(match, "h") || !strcmp(match, "-help")) pt_run_help(); else { pt_run_usage(stderr); @@ -314,17 +314,17 @@ int main(int argc, char **argv) { } /* Push arguments to Lua stack. */ - for(int i = 2; i < argc; i++) + for(int i = 2; i < argc; i++) lua_pushstring(L, argv[i]); /* Moment of truth. */ status = lua_pcall(L, argc - 2, LUA_MULTRET, traceback_fn); - if(status != LUA_OK) + if(status != LUA_OK) res = EXIT_FAILURE; -finalize: +finalize: /* Cleanup. */ lua_close(L); -out: +out: return res; } From 7cec24ab3b320bc9789892b9ac86788b95700ebf Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 19:37:09 -0300 Subject: [PATCH 2/6] Compile things before running tests If there is a compilation error, then there's no point in running the tests. --- run-tests | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/run-tests b/run-tests index 2427a93..5e9f89c 100755 --- a/run-tests +++ b/run-tests @@ -6,5 +6,4 @@ # ./run-tests # ./run-tests -k # ./run-tests spec/traceback_spec.lua - -busted --verbose --no-keep-going "$@" +make tests && busted --verbose --no-keep-going "$@" From 17ab1866ee3bfcbecd2f740fc623c71cf4fb4e4a Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 19:50:34 -0300 Subject: [PATCH 3/6] Get rid of include and src directories This way do do not need a -I compilation flag to find the ptracer.h and we don't need to discuss what is the name of the include directory. --- Makefile | 32 ++++++++++++------------ examples/fibonacci/fibonacci.c | 6 ++--- src/pt-run.c => pt-run.c | 0 include/ptracer.h => ptracer.h | 0 spec/tracebacks/anon_lua/module.c | 2 +- spec/tracebacks/depth_recursion/module.c | 2 +- spec/tracebacks/dispatch/module.c | 2 +- spec/tracebacks/ellipsis/module.c | 2 +- spec/tracebacks/multimod/module_a.c | 2 +- spec/tracebacks/multimod/module_b.c | 2 +- spec/tracebacks/singular/module.c | 2 +- spec/tracebacks_spec.lua | 2 +- 12 files changed, 27 insertions(+), 27 deletions(-) rename src/pt-run.c => pt-run.c (100%) rename include/ptracer.h => ptracer.h (100%) diff --git a/Makefile b/Makefile index 9f83253..01b25e1 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ INSTALL_DATA= $(INSTALL) -m 0644 # C compilation flags CFLAGS = -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra -CPPFLAGS = -I$(LUA_INCDIR) -Iinclude +CPPFLAGS = -I$(LUA_INCDIR) LIBFLAG = -fPIC -shared # The -Wl,-E tells the linker to not throw away unused Lua API symbols. @@ -36,7 +36,7 @@ PTRUN_LDLIBS = -llua -lm .PHONY: library examples tests all install uninstall clean library: \ - src/pt-run + pt-run examples: library \ examples/fibonacci/fibonacci.so @@ -50,30 +50,30 @@ tests: library \ spec/tracebacks/multimod/module_b.so \ spec/tracebacks/singular/module.so -all: library examples specs +all: library examples tests -install: src/pt-run include/ptracer.h - $(INSTALL_EXEC) src/pt-run $(BINDIR) - $(INSTALL_DATA) include/ptracer.h $(INCDIR) +install: pt-run ptracer.h + $(INSTALL_EXEC) pt-run $(BINDIR) + $(INSTALL_DATA) ptracer.h $(INCDIR) uninstall: rm -rf $(INCDIR)/ptracer.h rm -rf $(BINDIR)/pt-run clean: - rm -rf src/pt-run examples/*/*.so spec/tracebacks/*/*.so + rm -rf pt-run examples/*/*.so spec/tracebacks/*/*.so %.so: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(LIBFLAG) $< -o $@ -src/pt-run: src/pt-run.c include/ptracer.h +pt-run: pt-run.c ptracer.h $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(PTRUN_LDFLAGS) $< -o $@ $(PTRUN_LDLIBS) -examples/fibonacci/fibonacci.so: examples/fibonacci/fibonacci.c include/ptracer.h -spec/tracebacks/anon_lua/module.so: spec/tracebacks/anon_lua/module.c include/ptracer.h -spec/tracebacks/depth_recursion/module.so: spec/tracebacks/depth_recursion/module.c include/ptracer.h -spec/tracebacks/dispatch/module.so: spec/tracebacks/dispatch/module.c include/ptracer.h -spec/tracebacks/ellipsis/module.so: spec/tracebacks/ellipsis/module.c include/ptracer.h -spec/tracebacks/multimod/module_a.so: spec/tracebacks/multimod/module_a.c include/ptracer.h -spec/tracebacks/multimod/module_b.so: spec/tracebacks/multimod/module_b.c include/ptracer.h -spec/tracebacks/singular/module.so: spec/tracebacks/singular/module.c include/ptracer.h +examples/fibonacci/fibonacci.so: examples/fibonacci/fibonacci.c ptracer.h +spec/tracebacks/anon_lua/module.so: spec/tracebacks/anon_lua/module.c ptracer.h +spec/tracebacks/depth_recursion/module.so: spec/tracebacks/depth_recursion/module.c ptracer.h +spec/tracebacks/dispatch/module.so: spec/tracebacks/dispatch/module.c ptracer.h +spec/tracebacks/ellipsis/module.so: spec/tracebacks/ellipsis/module.c ptracer.h +spec/tracebacks/multimod/module_a.so: spec/tracebacks/multimod/module_a.c ptracer.h +spec/tracebacks/multimod/module_b.so: spec/tracebacks/multimod/module_b.c ptracer.h +spec/tracebacks/singular/module.so: spec/tracebacks/singular/module.c ptracer.h diff --git a/examples/fibonacci/fibonacci.c b/examples/fibonacci/fibonacci.c index b31e406..8baf167 100644 --- a/examples/fibonacci/fibonacci.c +++ b/examples/fibonacci/fibonacci.c @@ -1,12 +1,12 @@ -/* +/* * Copyright (c) 2024, The Pallene Developers * Pallene Tracer is licensed under the MIT license. * Please refer to the LICENSE and AUTHORS files for details - * SPDX-License-Identifier: MIT + * SPDX-License-Identifier: MIT */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* User specific macros when Pallene Tracer debug mode is enabled. */ #ifdef PT_DEBUG diff --git a/src/pt-run.c b/pt-run.c similarity index 100% rename from src/pt-run.c rename to pt-run.c diff --git a/include/ptracer.h b/ptracer.h similarity index 100% rename from include/ptracer.h rename to ptracer.h diff --git a/spec/tracebacks/anon_lua/module.c b/spec/tracebacks/anon_lua/module.c index 6f952f9..75d0a37 100644 --- a/spec/tracebacks/anon_lua/module.c +++ b/spec/tracebacks/anon_lua/module.c @@ -7,7 +7,7 @@ /* Static use of the library would suffice. */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Here goes user specifc macros when Pallene Tracer debug mode is active. */ #ifdef PT_DEBUG diff --git a/spec/tracebacks/depth_recursion/module.c b/spec/tracebacks/depth_recursion/module.c index dcb3da0..73901cb 100644 --- a/spec/tracebacks/depth_recursion/module.c +++ b/spec/tracebacks/depth_recursion/module.c @@ -7,7 +7,7 @@ /* Static use of the library would suffice. */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Here goes user specific macros when Pallene Tracer debug mode is active. */ #ifdef PT_DEBUG diff --git a/spec/tracebacks/dispatch/module.c b/spec/tracebacks/dispatch/module.c index 368c649..c14317b 100644 --- a/spec/tracebacks/dispatch/module.c +++ b/spec/tracebacks/dispatch/module.c @@ -7,7 +7,7 @@ /* Static use of the library would suffice. */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Here goes user specific macros when Pallene Tracer debug mode is active. */ #ifdef PT_DEBUG diff --git a/spec/tracebacks/ellipsis/module.c b/spec/tracebacks/ellipsis/module.c index 2b9ab6c..6dcbcf5 100644 --- a/spec/tracebacks/ellipsis/module.c +++ b/spec/tracebacks/ellipsis/module.c @@ -7,7 +7,7 @@ /* Static use of the library would suffice. */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Here goes user specific macros when Pallene Tracer debug mode is active. */ #ifdef PT_DEBUG diff --git a/spec/tracebacks/multimod/module_a.c b/spec/tracebacks/multimod/module_a.c index cfa910e..7b09776 100644 --- a/spec/tracebacks/multimod/module_a.c +++ b/spec/tracebacks/multimod/module_a.c @@ -6,7 +6,7 @@ */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" #include "module_include.h" diff --git a/spec/tracebacks/multimod/module_b.c b/spec/tracebacks/multimod/module_b.c index 2e63519..cdbd15f 100644 --- a/spec/tracebacks/multimod/module_b.c +++ b/spec/tracebacks/multimod/module_b.c @@ -6,7 +6,7 @@ */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" #include "module_include.h" diff --git a/spec/tracebacks/singular/module.c b/spec/tracebacks/singular/module.c index 46f5d04..164e374 100644 --- a/spec/tracebacks/singular/module.c +++ b/spec/tracebacks/singular/module.c @@ -7,7 +7,7 @@ /* Static use of the library would suffice. */ #define PT_IMPLEMENTATION -#include +#include "ptracer.h" /* Here goes user specific macros when Pallene Tracer debug mode is active. */ #ifdef PT_DEBUG diff --git a/spec/tracebacks_spec.lua b/spec/tracebacks_spec.lua index b861ea1..55b942f 100644 --- a/spec/tracebacks_spec.lua +++ b/spec/tracebacks_spec.lua @@ -9,7 +9,7 @@ local function assert_test(example, expected_content) assert(util.execute("make --quiet tests")) local cdir = util.shell_quote("spec/tracebacks/"..example) - local ptrun = util.shell_quote("../../../src/pt-run") + local ptrun = util.shell_quote("../../../pt-run") local ok, _, output_content, err_content = util.outputs_of_execute(string.format("cd %s && %s main.lua", cdir, ptrun)) assert(not ok, output_content) From a04d767b576bae203201b7fad287b30741ae5a27 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 20:04:33 -0300 Subject: [PATCH 4/6] "make install" should never compile things It's a bad idea to run the compiler with sudo, and it's not what people expect. --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbb6607..55f5bf2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: - name: Build run: | - sudo make install + make all && sudo make install - name: Install Busted run: luarocks --local install busted diff --git a/Makefile b/Makefile index 01b25e1..0f58f03 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ tests: library \ all: library examples tests -install: pt-run ptracer.h +install: $(INSTALL_EXEC) pt-run $(BINDIR) $(INSTALL_DATA) ptracer.h $(INCDIR) From 1ecac9211415ee1981bf2cce10db9977358208c0 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 20:10:30 -0300 Subject: [PATCH 5/6] Fix -Wformat-security warning It was causing the CI to fail, because that's part of -Wextra for them? Fixes #18 --- Makefile | 2 +- pt-run.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0f58f03..3b668c7 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ INSTALL_EXEC= $(INSTALL) -m 0755 INSTALL_DATA= $(INSTALL) -m 0644 # C compilation flags -CFLAGS = -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra +CFLAGS = -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra -Wformat-security CPPFLAGS = -I$(LUA_INCDIR) LIBFLAG = -fPIC -shared diff --git a/pt-run.c b/pt-run.c index 64edf87..2cbb1ff 100644 --- a/pt-run.c +++ b/pt-run.c @@ -149,7 +149,7 @@ static void pt_run_dbg_print(const char *buf, bool *ellipsis, int *pframes, int || ((nframes - *pframes) <= PT_RUN_TRACEBACK_BOTTOM_THRESHOLD); if(luai_likely(should_print)) - fprintf(stderr, buf); + fprintf(stderr, "%s", buf); else if(*ellipsis) { fprintf(stderr, "\n ... (Skipped %d frames) ...\n\n", nframes - (PT_RUN_TRACEBACK_TOP_THRESHOLD From 5f0c41d495934c551060b550de035e4671070f15 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 9 Aug 2024 20:14:21 -0300 Subject: [PATCH 6/6] Actually, we do need -I. Oops! --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3b668c7..2bc4cf3 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ INSTALL_DATA= $(INSTALL) -m 0644 # C compilation flags CFLAGS = -DPT_DEBUG -O2 -std=c99 -pedantic -Wall -Wextra -Wformat-security -CPPFLAGS = -I$(LUA_INCDIR) +CPPFLAGS = -I$(LUA_INCDIR) -I. LIBFLAG = -fPIC -shared # The -Wl,-E tells the linker to not throw away unused Lua API symbols.