Skip to content

Commit

Permalink
lib: introduce debug library
Browse files Browse the repository at this point in the history
Introduce a new debug library which provides introspection facilities
for debugging ucode scripts.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Aug 8, 2023
1 parent be07107 commit 6940c28
Show file tree
Hide file tree
Showing 6 changed files with 1,652 additions and 6 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ IF(NOT COMPILE_SUPPORT)
ADD_DEFINITIONS(-DNO_COMPILE)
ENDIF()

OPTION(DEBUG_SUPPORT "Debug plugin support" ON)
OPTION(FS_SUPPORT "Filesystem plugin support" ON)
OPTION(MATH_SUPPORT "Math plugin support" ON)
OPTION(UBUS_SUPPORT "Ubus plugin support" ON)
Expand Down Expand Up @@ -89,6 +90,20 @@ UNSET(CMAKE_REQUIRED_LIBRARIES)

SET(LIBRARIES "")

IF(DEBUG_SUPPORT)
SET(LIBRARIES ${LIBRARIES} debug_lib)
ADD_LIBRARY(debug_lib MODULE lib/debug.c)
SET_TARGET_PROPERTIES(debug_lib PROPERTIES OUTPUT_NAME debug PREFIX "")
TARGET_LINK_OPTIONS(debug_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS})
FIND_LIBRARY(ubox NAMES ubox)
IF(ubox)
FIND_PATH(uloop_include_dir NAMES libubox/uloop.h)
INCLUDE_DIRECTORIES(${uloop_include_dir})
TARGET_LINK_LIBRARIES(debug_lib ${ubox} ${libucode})
SET_TARGET_PROPERTIES(debug_lib PROPERTIES COMPILE_DEFINITIONS HAVE_ULOOP)
ENDIF()
ENDIF()

IF(FS_SUPPORT)
SET(LIBRARIES ${LIBRARIES} fs_lib)
ADD_LIBRARY(fs_lib MODULE lib/fs.c)
Expand Down
4 changes: 2 additions & 2 deletions include/ucode/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ __hidden size_t uc_chunk_add(uc_chunk_t *chunk, uint8_t byte, size_t line);

__hidden void uc_chunk_pop(uc_chunk_t *chunk);

__hidden size_t uc_chunk_debug_get_srcpos(uc_chunk_t *chunk, size_t off);
size_t uc_chunk_debug_get_srcpos(uc_chunk_t *chunk, size_t offset);
__hidden void uc_chunk_debug_add_variable(uc_chunk_t *chunk, size_t from, size_t to, size_t slot, bool upval, uc_value_t *name);
__hidden uc_value_t *uc_chunk_debug_get_variable(uc_chunk_t *chunk, size_t off, size_t slot, bool upval);
uc_value_t *uc_chunk_debug_get_variable(uc_chunk_t *chunk, size_t offset, size_t slot, bool upval);

#endif /* UCODE_CHUNK_H */
2 changes: 1 addition & 1 deletion include/ucode/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern const uc_function_list_t uc_stdlib_functions[];
void uc_stdlib_load(uc_value_t *scope);
uc_cfn_ptr_t uc_stdlib_function(const char *name);

__hidden bool uc_source_context_format(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact);
bool uc_source_context_format(uc_stringbuf_t *buf, uc_source_t *src, size_t off, bool compact);
__hidden bool uc_error_context_format(uc_stringbuf_t *buf, uc_source_t *src, uc_value_t *stacktrace, size_t off);
__hidden void uc_error_message_indent(char **msg);

Expand Down
4 changes: 2 additions & 2 deletions include/ucode/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ uc_program_put(uc_program_t *prog) {
__hidden uc_function_t *uc_program_function_new(uc_program_t *, const char *, uc_source_t *, size_t);
__hidden size_t uc_program_function_id(uc_program_t *, uc_function_t *);
__hidden uc_function_t *uc_program_function_load(uc_program_t *, size_t);
__hidden uc_source_t *uc_program_function_source(uc_function_t *);
__hidden size_t uc_program_function_srcpos(uc_function_t *, size_t);
uc_source_t *uc_program_function_source(uc_function_t *);
size_t uc_program_function_srcpos(uc_function_t *, size_t);
__hidden void uc_program_function_free(uc_function_t *);

__hidden uc_value_t *uc_program_get_constant(uc_program_t *, size_t);
Expand Down
2 changes: 1 addition & 1 deletion include/ucode/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef enum {
uc_source_t *uc_source_new_file(const char *path);
uc_source_t *uc_source_new_buffer(const char *name, char *buf, size_t len);

__hidden size_t uc_source_get_line(uc_source_t *source, size_t *offset);
size_t uc_source_get_line(uc_source_t *source, size_t *offset);

static inline uc_source_t *
uc_source_get(uc_source_t *source) {
Expand Down
Loading

0 comments on commit 6940c28

Please sign in to comment.