From cdacdce8e549fa142352125293fbf6d4e006f522 Mon Sep 17 00:00:00 2001 From: Nikolai Nosov Date: Wed, 5 Feb 2020 16:14:52 +0400 Subject: [PATCH] fix compilation errors related to C specifics --- Makefile | 8 +++---- include/libpst.h | 4 ++-- src/Makefile | 8 +++---- src/arch/{registers.cpp => registers.c} | 2 +- src/arch/registers.h | 2 +- src/{common.cpp => common.c} | 8 +++---- src/{context.cpp => context.c} | 0 src/context.h | 13 ++++++------ ...{dwarf_call_site.cpp => dwarf_call_site.c} | 14 ++++++------- src/dwarf/dwarf_call_site.h | 8 +++---- ...warf_expression.cpp => dwarf_expression.c} | 6 +++--- .../{dwarf_function.cpp => dwarf_function.c} | 21 ++++++++++--------- src/dwarf/dwarf_function.h | 6 +++--- .../{dwarf_handler.cpp => dwarf_handler.c} | 15 ++++++------- ...warf_operations.cpp => dwarf_operations.c} | 0 ...{dwarf_parameter.cpp => dwarf_parameter.c} | 4 ++-- src/dwarf/{dwarf_stack.cpp => dwarf_stack.c} | 0 src/dwarf/dwarf_stack.h | 5 +++-- src/dwarf/{dwarf_utils.cpp => dwarf_utils.c} | 2 +- src/dwarf/dwarf_utils.h | 4 ---- src/{libpst.cpp => libpst.c} | 4 ++-- src/utils/{allocator.cpp => allocator.c} | 0 src/utils/allocator.h | 8 +++---- .../{hash_multimap.cpp => hash_multimap.c} | 0 src/utils/hash_multimap.h | 10 ++++----- src/utils/{log.cpp => log.c} | 5 +++-- src/utils/log.h | 19 +++++++++-------- tests/{main.cpp => main.c} | 9 ++++---- tests/{simple.cpp => simple.c} | 0 29 files changed, 93 insertions(+), 92 deletions(-) rename src/arch/{registers.cpp => registers.c} (98%) rename src/{common.cpp => common.c} (94%) rename src/{context.cpp => context.c} (100%) rename src/dwarf/{dwarf_call_site.cpp => dwarf_call_site.c} (96%) rename src/dwarf/{dwarf_expression.cpp => dwarf_expression.c} (93%) rename src/dwarf/{dwarf_function.cpp => dwarf_function.c} (96%) rename src/dwarf/{dwarf_handler.cpp => dwarf_handler.c} (95%) rename src/dwarf/{dwarf_operations.cpp => dwarf_operations.c} (100%) rename src/dwarf/{dwarf_parameter.cpp => dwarf_parameter.c} (98%) rename src/dwarf/{dwarf_stack.cpp => dwarf_stack.c} (100%) rename src/dwarf/{dwarf_utils.cpp => dwarf_utils.c} (97%) rename src/{libpst.cpp => libpst.c} (94%) rename src/utils/{allocator.cpp => allocator.c} (100%) rename src/utils/{hash_multimap.cpp => hash_multimap.c} (100%) rename src/utils/{log.cpp => log.c} (98%) rename tests/{main.cpp => main.c} (95%) rename tests/{simple.cpp => simple.c} (100%) diff --git a/Makefile b/Makefile index dc19492..b5be6ef 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,11 @@ BIN = $(RESULT_DIR)/trace #source file search path. add here new directories which contains files specified for $(SRC) VPATH = ./tests -SRC = $(shell find . -name '*.cpp') +SRC = $(shell find . -name '*.c') #OBJ = $(patsubst %.cpp,%.o,$(addprefix $(BUILD_DIR)/,$(notdir $(SRC)))) OBJ = $(BUILD_DIR)/main.o -LIBS = -L./ -lpthread -ldl -ldw -lunwind -lunwind-x86_64 -lstdc++ +LIBS = -L./ -lpthread -ldl -ldw -lunwind -lunwind-x86_64 -lstdc++ -liberty PST_LIBS = ./build/libpst.a INCS = -I./include -I./src @@ -78,7 +78,7 @@ $(RESULT_DIR)/prepare.res: @touch $@ $(BIN): $(BUILD_DIR)/prepare.bld $(RESULT_DIR)/prepare.res $(OBJ) $(PST_LIBS) - gcc -ggdb -O3 -o $(BUILD_DIR)/simple ./tests/simple.cpp + gcc -ggdb -O3 -o $(BUILD_DIR)/simple ./tests/simple.c @make -C ./src @printf "Create %-60s" $@ @OUT=$$($(CXX) $(COLOR) -o $@ $(OBJ) $(PST_LIBS) $(LIBS) 2>&1); \ @@ -92,7 +92,7 @@ $(BIN): $(BUILD_DIR)/prepare.bld $(RESULT_DIR)/prepare.res $(OBJ) $(PST_LIBS) fi; \ fi -$(BUILD_DIR)/%.o: %.cpp +$(BUILD_DIR)/%.o: %.c #compile source code directly to $BUILD_DIR directory @printf "Building %-60s" $@ @OUT=$$($(CXX) $(COLOR) -o $@ -c $< $(FLAGS) $(INCS) 2>&1); \ diff --git a/include/libpst.h b/include/libpst.h index f53eb55..27402b1 100644 --- a/include/libpst.h +++ b/include/libpst.h @@ -30,7 +30,7 @@ void pst_del_handler(pst_handler* h); // // write stack trace information to provided file descriptor -int pst_unwind_simple(pst_handler* h, FILE* fd); +int pst_unwind_simple_fd(pst_handler* h, FILE* fd); // save stack trace information to provided buffer in RAM int pst_unwind_simple(pst_handler* h, char* buff, uint32_t buff_size); @@ -42,7 +42,7 @@ int pst_unwind_simple(pst_handler* h, char* buff, uint32_t buff_size); // // write stack trace information to provided file descriptor -int pst_unwind_pretty(pst_handler* h, FILE* fd); +int pst_unwind_pretty_fd(pst_handler* h, FILE* fd); // save stack trace information to provided buffer in RAM int pst_unwind_pretty(pst_handler* h, char* buff, uint32_t buff_size); diff --git a/src/Makefile b/src/Makefile index 6b95495..5d79e43 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,11 +34,11 @@ DATE_BUILD = $(shell date +"%D %T") #source and header files search path. add here new directories which contains files specified for $(SRC) VPATH = ./ ./dwarf ./arch ./utils -SRC = $(wildcard $(addsuffix /*.cpp,${VPATH})) -OBJ = $(patsubst %.cpp,%.o,$(addprefix $(BUILD_DIR)/,$(notdir $(SRC)))) +SRC = $(wildcard $(addsuffix /*.c,${VPATH})) +OBJ = $(patsubst %.c,%.o,$(addprefix $(BUILD_DIR)/,$(notdir $(SRC)))) INCS = -I"./dwarf" -I"./" -I"./utils" -I"./arch" -FLAGS = -Wall -ggdb -fPIC -O3 -rdynamic -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DSOFT_BUILD=$(SOFT_BUILD) -DUSER_BUILD=$(USER) -DDATE_BUILD="$(DATE_BUILD)" +FLAGS = -Wall -ggdb -fPIC -O3 -rdynamic -D_GNU_SOURCE -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DSOFT_BUILD=$(SOFT_BUILD) -DUSER_BUILD=$(USER) -DDATE_BUILD="$(DATE_BUILD)" .PHONY: all clean @@ -57,7 +57,7 @@ $(RESULT_DIR)/prepare.res: @if [ ! -e $(RESULT_DIR) ]; then mkdir -vp $(RESULT_DIR); fi @touch $@ -$(BUILD_DIR)/%.o: %.cpp +$(BUILD_DIR)/%.o: %.c #compile source code directly to $BUILD_DIR directory @printf "Building %-60s" $@ @OUT=$$($(CXX) $(COLOR) -o $@ -c $< $(FLAGS) $(INCS) 2>&1); \ diff --git a/src/arch/registers.cpp b/src/arch/registers.c similarity index 98% rename from src/arch/registers.cpp rename to src/arch/registers.c index a7650fd..08c6ae1 100644 --- a/src/arch/registers.cpp +++ b/src/arch/registers.c @@ -99,7 +99,7 @@ int find_regnum(uint32_t op) return -1; } -pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t& regval) +pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t* regval) { #ifdef USE_LIBUNWIND int ret = unw_get_reg(ctx->curr_frame, regno, ®val); diff --git a/src/arch/registers.h b/src/arch/registers.h index 7982667..fc9e9b1 100644 --- a/src/arch/registers.h +++ b/src/arch/registers.h @@ -33,6 +33,6 @@ typedef enum { REG_EXPR_ERROR } pst_reg_error; -pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t& regval); +pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t* regval); #endif /* __PST_REGISTERS_H__ */ diff --git a/src/common.cpp b/src/common.c similarity index 94% rename from src/common.cpp rename to src/common.c index f3c46a9..f345a71 100644 --- a/src/common.cpp +++ b/src/common.c @@ -45,8 +45,8 @@ uint32_t decode_uleb128(uint8_t *uleb128) } // Utility function to encode a ULEB128 value to a buffer. Returns -// the length in bytes of the encoded value. -inline unsigned encode_uleb128(uint64_t value, uint8_t *p, unsigned PadTo = 0) +// the length in bytes of the encoded value. by default PadTo = 0 +inline unsigned encode_uleb128(uint64_t value, uint8_t *p, unsigned PadTo) { uint8_t *orig_p = p; unsigned count = 0; @@ -70,8 +70,8 @@ inline unsigned encode_uleb128(uint64_t value, uint8_t *p, unsigned PadTo = 0) } // Utility function to encode a SLEB128 value to a buffer. Returns -// the length in bytes of the encoded value. -inline unsigned encode_sleb128(int64_t value, uint8_t *p, unsigned PadTo = 0) +// the length in bytes of the encoded value. by default PadTo = 0 +inline unsigned encode_sleb128(int64_t value, uint8_t *p, unsigned PadTo) { uint8_t *orig_p = p; unsigned count = 0; diff --git a/src/context.cpp b/src/context.c similarity index 100% rename from src/context.cpp rename to src/context.c diff --git a/src/context.h b/src/context.h index 5cc6c88..326dbe1 100644 --- a/src/context.h +++ b/src/context.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "utils/allocator.h" #include "utils/log.h" @@ -27,13 +28,13 @@ extern pst_allocator allocator; // custom allocator for PST library char* pst_strdup(const char* str); -typedef struct pst_context { +typedef struct __pst_context { // methods - void (*clean_print) (pst_context* ctx); - bool (*print) (pst_context* ctx, const char* fmt, ...); - bool (*print_expr) (pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Attribute* attr); - void (*print_registers) (pst_context* ctx, int from, int to); - void (*print_stack) (pst_context* ctx, int max, uint64_t next_cfa); + void (*clean_print) (struct __pst_context* ctx); + bool (*print) (struct __pst_context* ctx, const char* fmt, ...); + bool (*print_expr) (struct __pst_context* ctx, Dwarf_Op *exprs, int exprlen, Dwarf_Attribute* attr); + void (*print_registers) (struct __pst_context* ctx, int from, int to); + void (*print_stack) (struct __pst_context* ctx, int max, uint64_t next_cfa); // fields ucontext_t* hcontext; // context of signal handler diff --git a/src/dwarf/dwarf_call_site.cpp b/src/dwarf/dwarf_call_site.c similarity index 96% rename from src/dwarf/dwarf_call_site.cpp rename to src/dwarf/dwarf_call_site.c index 457f0bc..7a7cbd7 100644 --- a/src/dwarf/dwarf_call_site.cpp +++ b/src/dwarf/dwarf_call_site.c @@ -54,7 +54,7 @@ void pst_call_site_param_fini(pst_call_site_param* param) // ----------------------------------------------------------------------------------- // pst_call_site // ----------------------------------------------------------------------------------- -pst_call_site_param* add_param(pst_call_site* site) +static pst_call_site_param* add_param(pst_call_site* site) { pst_call_site_param* p = pst_call_site_param_new(); pst_call_site_param_init(p); @@ -63,13 +63,13 @@ pst_call_site_param* add_param(pst_call_site* site) return p; } -void del_param(pst_call_site*, pst_call_site_param* p) +static void del_param(pst_call_site_param* p) { list_del(&p->node); pst_call_site_param_fini(p); } -pst_call_site_param* next_param(pst_call_site* site, pst_call_site_param* p) +static pst_call_site_param* next_param(pst_call_site* site, pst_call_site_param* p) { list_node* n = (p == NULL) ? list_first(&site->params) : list_next(&p->node); pst_call_site_param* ret = NULL; @@ -109,7 +109,7 @@ bool call_site_handle_dwarf(pst_call_site* site, Dwarf_Die* child) attr = dwarf_attr(child, DW_AT_location, &attr_mem); if(!handle_location(site->ctx, attr, ¶m->location, pc, NULL)) { pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff); - del_param(site, param); + del_param(param); return false; } pst_log(SEVERITY_DEBUG, " DW_AT_location: %s", site->ctx->buff); @@ -126,7 +126,7 @@ bool call_site_handle_dwarf(pst_call_site* site, Dwarf_Die* child) pst_log(SEVERITY_DEBUG, " DW_AT_GNU_call_site_value:\"%s\" ==> 0x%lX", site->ctx->buff, param->value); } else { pst_log(SEVERITY_ERROR, "Failed to calculate DW_AT_location expression: %s", site->ctx->buff); - del_param(site, param); + del_param(param); pst_dwarf_expr_fini(&loc); return false; } @@ -320,8 +320,8 @@ void pst_call_site_storage_init(pst_call_site_storage* storage, pst_context* ctx { storage->ctx = ctx; list_head_init(&storage->call_sites); - hash_head_init(&storage->cs_to_target); - hash_head_init(&storage->cs_to_origin); + hash_head_init(&storage->cs_to_target, HASH_MIN_SHIFT, 0, 0); + hash_head_init(&storage->cs_to_origin, HASH_MIN_SHIFT, 0 ,0); storage->allocated = false; } diff --git a/src/dwarf/dwarf_call_site.h b/src/dwarf/dwarf_call_site.h index 1c1430c..e14547c 100644 --- a/src/dwarf/dwarf_call_site.h +++ b/src/dwarf/dwarf_call_site.h @@ -16,7 +16,7 @@ #include "../utils/list_head.h" #include "context.h" -typedef struct pst_callee_info { +typedef struct __pst_callee_info { Dwarf_Addr target; char* origin; } pst_callee_info; @@ -25,7 +25,7 @@ typedef struct pst_callee_info { // ----------------------------------------------------------------------------------- // DW_TAG_call_site_parameter // ----------------------------------------------------------------------------------- -typedef struct pst_call_site_param { +typedef struct __pst_call_site_param { list_node node; // uplink. !!! must be first !!! Dwarf_Die* param; // reference to parameter DIE in callee (DW_AT_call_parameter) @@ -43,7 +43,7 @@ void pst_call_site_param_fini(pst_call_site_param* param); // ----------------------------------------------------------------------------------- // DW_TAG_call_site // ----------------------------------------------------------------------------------- -typedef struct pst_call_site { +typedef struct __pst_call_site { list_node node; // uplink to list of call-sites hash_node tgt_node; // uplink to call-site by node dictionary hash_node org_node; // uplink to call-site by origin dictionary @@ -68,7 +68,7 @@ typedef struct __pst_function pst_function; // ----------------------------------------------------------------------------------- // storage for all of function's call sites // ----------------------------------------------------------------------------------- -typedef struct pst_call_site_storage { +typedef struct __pst_call_site_storage { pst_context* ctx; list_head call_sites; // Call-Site definitions hash_head cs_to_target; // map pointer to caller to call-site diff --git a/src/dwarf/dwarf_expression.cpp b/src/dwarf/dwarf_expression.c similarity index 93% rename from src/dwarf/dwarf_expression.cpp rename to src/dwarf/dwarf_expression.c index 4b6f53a..a0964b3 100644 --- a/src/dwarf/dwarf_expression.cpp +++ b/src/dwarf/dwarf_expression.c @@ -54,7 +54,7 @@ void pst_dwarf_op_fini(pst_dwarf_op* dwop) // // pst_dwarf_expr // -pst_dwarf_op* add_op(pst_dwarf_expr* expr, uint8_t operation, uint64_t arg1, uint64_t arg2) +static pst_dwarf_op* add_op(pst_dwarf_expr* expr, uint8_t operation, uint64_t arg1, uint64_t arg2) { pst_new(pst_dwarf_op, op, operation, arg1, arg2); list_add_bottom(&expr->operations, &op->node); @@ -62,7 +62,7 @@ pst_dwarf_op* add_op(pst_dwarf_expr* expr, uint8_t operation, uint64_t arg1, uin return op; } -pst_dwarf_op* next_op(pst_dwarf_expr* expr, pst_dwarf_op* op) +static pst_dwarf_op* next_op(pst_dwarf_expr* expr, pst_dwarf_op* op) { struct list_node* n = (op == NULL) ? list_first(&expr->operations) : list_next(&op->node); @@ -74,7 +74,7 @@ pst_dwarf_op* next_op(pst_dwarf_expr* expr, pst_dwarf_op* op) return ret; } -void clean(pst_dwarf_expr* expr) +static void clean(pst_dwarf_expr* expr) { pst_dwarf_op* op = NULL; struct list_node *pos, *tn; diff --git a/src/dwarf/dwarf_function.cpp b/src/dwarf/dwarf_function.c similarity index 96% rename from src/dwarf/dwarf_function.cpp rename to src/dwarf/dwarf_function.c index 6774672..043d474 100644 --- a/src/dwarf/dwarf_function.cpp +++ b/src/dwarf/dwarf_function.c @@ -8,7 +8,9 @@ #include #include -#include +#include +#include + #include "dwarf_stack.h" #include "dwarf_utils.h" @@ -17,7 +19,7 @@ // ----------------------------------------------------------------------------------- // pst_function // ----------------------------------------------------------------------------------- -bool get_frame(pst_function* fn) +static bool get_frame(pst_function* fn) { // get CFI (Call Frame Information) for current module // from handle_cfi() @@ -85,7 +87,7 @@ bool get_frame(pst_function* fn) return true; } -pst_parameter* add_param(pst_function* fn) +static pst_parameter* add_param(pst_function* fn) { pst_new(pst_parameter, p, fn->ctx); list_add_bottom(&fn->params, &p->node); @@ -93,13 +95,13 @@ pst_parameter* add_param(pst_function* fn) return p; } -void del_param(pst_parameter* p) +static void del_param(pst_parameter* p) { list_del(&p->node); pst_free(p); } -void clear(pst_function* fn) +static void clear(pst_function* fn) { pst_parameter* param = NULL; struct list_node *pos, *tn; @@ -111,7 +113,7 @@ void clear(pst_function* fn) pst_call_site_storage_fini(&fn->call_sites); } -pst_parameter* next_param(pst_function* fn, pst_parameter* p) +static pst_parameter* next_param(pst_function* fn, pst_parameter* p) { struct list_node* n = (p == NULL) ? list_first(&fn->params) : list_next(&p->node); @@ -400,8 +402,7 @@ bool pst_function_unwind(pst_function* fn, Dwarf_Addr addr) const char* addrname = dwfl_module_addrname(fn->ctx->module, addr); char* demangle_name = NULL; if(addrname) { - int status; - demangle_name = abi::__cxa_demangle(addrname, NULL, NULL, &status); + demangle_name = cplus_demangle(addrname, 0); char* function_name = NULL; if(asprintf(&function_name, "%s%s", demangle_name ? demangle_name : addrname, demangle_name ? "" : "()") == -1) { pst_log(SEVERITY_ERROR, "Failed to allocate memory"); @@ -424,7 +425,7 @@ bool pst_function_unwind(pst_function* fn, Dwarf_Addr addr) return true; } -void pst_function_init(pst_function* fn, pst_context* _ctx, __pst_function* _parent) +void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _parent) { list_node_init(&fn->node); @@ -448,7 +449,7 @@ void pst_function_init(pst_function* fn, pst_context* _ctx, __pst_function* _par fn->allocated = false; } -pst_function* pst_function_new(pst_context* _ctx, __pst_function* _parent) +pst_function* pst_function_new(pst_context* _ctx, pst_function* _parent) { pst_function* fn = pst_alloc(pst_function); if(fn) { diff --git a/src/dwarf/dwarf_function.h b/src/dwarf/dwarf_function.h index e07fb34..0b31ad2 100644 --- a/src/dwarf/dwarf_function.h +++ b/src/dwarf/dwarf_function.h @@ -36,13 +36,13 @@ typedef struct __pst_function { unw_cursor_t cursor; // copy of stack state of the function int line; // line in code where function is defined char* file; // file name (DWARF Compilation Unit) where function is defined - __pst_function* parent; // parent function in call trace (caller) + struct __pst_function* parent; // parent function in call trace (caller) Dwarf_Frame* frame; // function's stack frame pst_context* ctx; // context of unwinding bool allocated; // whether this object was allocated or not } pst_function; -void pst_function_init(pst_function* fn, pst_context* _ctx, __pst_function* _parent); -pst_function* pst_function_new(pst_context* _ctx, __pst_function* _parent); +void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _parent); +pst_function* pst_function_new(pst_context* _ctx, pst_function* _parent); void pst_function_fini(pst_function* fn); bool pst_function_unwind(pst_function* fn, Dwarf_Addr addr); diff --git a/src/dwarf/dwarf_handler.cpp b/src/dwarf/dwarf_handler.c similarity index 95% rename from src/dwarf/dwarf_handler.cpp rename to src/dwarf/dwarf_handler.c index c806248..12887d6 100644 --- a/src/dwarf/dwarf_handler.cpp +++ b/src/dwarf/dwarf_handler.c @@ -4,15 +4,16 @@ * Created on: Dec 28, 2019 * Author: nnosov */ + #include #include #include #include #include +#include #include #include -#include #include #include #include @@ -75,7 +76,7 @@ bool get_dwarf_function(pst_handler* h, pst_function* fun) return nret; } -pst_function* add_function(pst_handler* h, pst_function* parent) +static pst_function* add_function(pst_handler* h, pst_function* parent) { pst_new(pst_function, fn, &h->ctx, parent); list_add_bottom(&h->functions, &fn->node); @@ -83,13 +84,13 @@ pst_function* add_function(pst_handler* h, pst_function* parent) return fn; } -void del_function(pst_function* fn) +static void del_function(pst_function* fn) { list_del(&fn->node); pst_function_fini(fn); } -void clear(pst_handler* h) +static void clear(pst_handler* h) { pst_function* fn = NULL; struct list_node *pos, *tn; @@ -99,7 +100,7 @@ void clear(pst_handler* h) } } -pst_function* next_function(pst_handler* h, pst_function* fn) +static pst_function* next_function(pst_handler* h, pst_function* fn) { list_node* n = (fn == NULL) ? list_first(&h->functions) : list_next(&fn->node); pst_function* ret = NULL; @@ -110,7 +111,7 @@ pst_function* next_function(pst_handler* h, pst_function* fn) return ret; } -pst_function* prev_function(pst_handler* h, pst_function* fn) +static pst_function* prev_function(pst_handler* h, pst_function* fn) { list_node* n = (fn == NULL) ? list_last(&h->functions) : list_prev(&fn->node); pst_function* ret = NULL; @@ -121,7 +122,7 @@ pst_function* prev_function(pst_handler* h, pst_function* fn) return ret; } -pst_function* last_function(pst_handler* h) +static pst_function* last_function(pst_handler* h) { list_node* n = list_last(&h->functions); if(n) { diff --git a/src/dwarf/dwarf_operations.cpp b/src/dwarf/dwarf_operations.c similarity index 100% rename from src/dwarf/dwarf_operations.cpp rename to src/dwarf/dwarf_operations.c diff --git a/src/dwarf/dwarf_parameter.cpp b/src/dwarf/dwarf_parameter.c similarity index 98% rename from src/dwarf/dwarf_parameter.cpp rename to src/dwarf/dwarf_parameter.c index 8ae658c..a39c530 100644 --- a/src/dwarf/dwarf_parameter.cpp +++ b/src/dwarf/dwarf_parameter.c @@ -46,7 +46,7 @@ void pst_type_fini(pst_type* t) // // pst_parameter // -void clear(pst_parameter* param) +static void clear(pst_parameter* param) { pst_type* t = NULL; struct list_node *pos, *tn; @@ -56,7 +56,7 @@ void clear(pst_parameter* param) } } -pst_type* next_type(pst_parameter* param, pst_type* t) +static pst_type* next_type(pst_parameter* param, pst_type* t) { list_node* n = (t == NULL) ? list_first(¶m->types) : list_next(&t->node); pst_type* ret = NULL; diff --git a/src/dwarf/dwarf_stack.cpp b/src/dwarf/dwarf_stack.c similarity index 100% rename from src/dwarf/dwarf_stack.cpp rename to src/dwarf/dwarf_stack.c diff --git a/src/dwarf/dwarf_stack.h b/src/dwarf/dwarf_stack.h index 3a32ce2..566b4b6 100644 --- a/src/dwarf/dwarf_stack.h +++ b/src/dwarf/dwarf_stack.h @@ -9,6 +9,7 @@ #define __PST_DWARF_STACK_H__ #include +#include #include "common.h" #include "context.h" @@ -86,10 +87,10 @@ void pst_dwarf_stack_init(pst_dwarf_stack* st, pst_context* ctx); pst_dwarf_stack* pst_dwarf_stack_new(pst_context* ctx); void pst_dwarf_stack_fini(pst_dwarf_stack* st); -bool pst_dwarf_stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attribute* attr, pst_function* fun = NULL); +bool pst_dwarf_stack_calc(pst_dwarf_stack* st, Dwarf_Op *exprs, int expr_len, Dwarf_Attribute* attr, pst_function* fun); void pst_dwarf_stack_clear(pst_dwarf_stack* st); bool pst_dwarf_stack_get_value(pst_dwarf_stack* st, uint64_t* value); -pst_dwarf_value* pst_dwarf_stack_get(pst_dwarf_stack* st, uint32_t idx = 0); +pst_dwarf_value* pst_dwarf_stack_get(pst_dwarf_stack* st, uint32_t idx); pst_dwarf_value* pst_dwarf_stack_pop(pst_dwarf_stack* st); void pst_dwarf_stack_push_value(pst_dwarf_stack* st, pst_dwarf_value* value); void pst_dwarf_stack_push(pst_dwarf_stack* st, void* v, uint32_t s, int t); diff --git a/src/dwarf/dwarf_utils.cpp b/src/dwarf/dwarf_utils.c similarity index 97% rename from src/dwarf/dwarf_utils.cpp rename to src/dwarf/dwarf_utils.c index 11663bc..9b36137 100644 --- a/src/dwarf/dwarf_utils.cpp +++ b/src/dwarf/dwarf_utils.c @@ -31,7 +31,7 @@ int regname_callback (void *arg, int regno, const char *setname, const char *pre return 0; } -bool handle_location(pst_context* ctx, Dwarf_Attribute* attr, pst_dwarf_expr* loc, Dwarf_Addr pc, pst_function* fun = NULL) +bool handle_location(pst_context* ctx, Dwarf_Attribute* attr, pst_dwarf_expr* loc, Dwarf_Addr pc, pst_function* fun) { ctx->clean_print(ctx); Dwarf_Addr offset = pc - ctx->base_addr; diff --git a/src/dwarf/dwarf_utils.h b/src/dwarf/dwarf_utils.h index 0d1fde2..3cbc395 100644 --- a/src/dwarf/dwarf_utils.h +++ b/src/dwarf/dwarf_utils.h @@ -15,10 +15,6 @@ #include "dwarf_function.h" typedef struct __reginfo { - __reginfo() { - regname[0] = 0; - regno = -1; - } char regname[32]; int regno; } reginfo; diff --git a/src/libpst.cpp b/src/libpst.c similarity index 94% rename from src/libpst.cpp rename to src/libpst.c index 4f9b32e..ab81986 100644 --- a/src/libpst.cpp +++ b/src/libpst.c @@ -34,7 +34,7 @@ void pst_del_handler(pst_handler* h) } // write stack trace information to provided file descriptor -int pst_unwind_simple(pst_handler* h, FILE* fd) +int pst_unwind_simple_fd(pst_handler* h, FILE* fd) { int ret = pst_handler_unwind(h); if(ret) { @@ -62,7 +62,7 @@ int pst_unwind_simple(pst_handler* h, char* buff, uint32_t buff_size) // write stack trace information to provided file descriptor -int pst_unwind_pretty(pst_handler* h, FILE* fd) +int pst_unwind_pretty_fd(pst_handler* h, FILE* fd) { int ret = pst_handler_handle_dwarf(h); if(ret) { diff --git a/src/utils/allocator.cpp b/src/utils/allocator.c similarity index 100% rename from src/utils/allocator.cpp rename to src/utils/allocator.c diff --git a/src/utils/allocator.h b/src/utils/allocator.h index 078fd36..774bf43 100644 --- a/src/utils/allocator.h +++ b/src/utils/allocator.h @@ -38,11 +38,11 @@ typedef enum { ALLOC_CUSTOM = 2 // use custom allocator in predefined range of memory } pst_alloc_type; -typedef struct pst_allocator { +typedef struct __pst_allocator { // methods - void* (*alloc)(pst_allocator* alloc, uint32_t size); - void (*free)(pst_allocator* alloc, void* buff); - void* (*realloc)(pst_allocator* alloc, void* buff, uint32_t new_size); + void* (*alloc)(struct __pst_allocator* alloc, uint32_t size); + void (*free)(struct __pst_allocator* alloc, void* buff); + void* (*realloc)(struct __pst_allocator* alloc, void* buff, uint32_t new_size); // fields int type; diff --git a/src/utils/hash_multimap.cpp b/src/utils/hash_multimap.c similarity index 100% rename from src/utils/hash_multimap.cpp rename to src/utils/hash_multimap.c diff --git a/src/utils/hash_multimap.h b/src/utils/hash_multimap.h index 43259a6..d9afcda 100644 --- a/src/utils/hash_multimap.h +++ b/src/utils/hash_multimap.h @@ -14,12 +14,12 @@ @param key_size hash key size in bytes @param node uplink to hash multimap table */ -struct hash_node +typedef struct hash_node { char *key; int key_size; struct list_node node; -}; +} hash_node; /** Hash function prototype @@ -48,7 +48,7 @@ typedef int (*_compare_fn)(const void *key1, const void *key2, int size); hash multimap table @param count count of the nodes in the hash table */ -struct hash_head +typedef struct hash_head { unsigned char hash_shift; unsigned short hash_size; @@ -58,7 +58,7 @@ struct hash_head _hash_fn hash_fn; _compare_fn compare_fn; -}; +} hash_head; /** Hash table iterator @@ -76,7 +76,7 @@ struct hash_iterator void hash_node_init(struct hash_node *node); void hash_node_cleanup(struct hash_node *node); -int hash_head_init(struct hash_head *map, unsigned int hash_shift = HASH_MIN_SHIFT, _hash_fn hf = 0, _compare_fn cf = 0); +int hash_head_init(struct hash_head *map, unsigned int hash_shift, _hash_fn hf, _compare_fn cf); void hash_head_cleanup(struct hash_head *map); struct hash_node* hash_find(struct hash_head *map, const void *key, int key_size); diff --git a/src/utils/log.cpp b/src/utils/log.c similarity index 98% rename from src/utils/log.cpp rename to src/utils/log.c index fce3752..74edc59 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.c @@ -1,6 +1,7 @@ #include #include +#include #include "log.h" @@ -202,12 +203,12 @@ void close_file(pst_log* log) fsp->max_bytes = 0; } -bool is_file_opened(pst_log* log) +int is_file_opened(pst_log* log) { file_spec* fsp = (file_spec*)log->child; if(!fsp) { fprintf(stderr, "Wrong initialization of File-based logger while check open\n"); - return false; + return 0; } return (fsp->fd != 0); } diff --git a/src/utils/log.h b/src/utils/log.h index 790540e..e258edd 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -7,26 +7,27 @@ #include #include #include +#include // Log message severity -enum SC_LogSeverity { +typedef enum { SEVERITY_DEBUG = 0, SEVERITY_INFO, SEVERITY_WARNING, SEVERITY_ERROR, //---------------- SEVERITY_MAX -}; +} SC_LogSeverity; #define LOG_BUFF_SIZE (1024*1024) -typedef struct pst_log { +typedef struct __pst_log { // methods - void (*close) (pst_log* log); - bool (*open) (pst_log* log); - bool (*is_opened) (pst_log* log); - void (*log) (pst_log* log, SC_LogSeverity severity, const char* fmt, ...); - void (*send_message) (pst_log* log, SC_LogSeverity severity); + void (*close) (struct __pst_log* log); + bool (*open) (struct __pst_log* log); + bool (*is_opened) (struct __pst_log* log); + void (*log) (struct __pst_log* log, SC_LogSeverity severity, const char* fmt, ...); + void (*send_message) (struct __pst_log* log, SC_LogSeverity severity); // fields char* mpSource; // source for store log messages (file, IP:port or something else) @@ -42,7 +43,7 @@ typedef struct pst_log { } pst_log; void pst_log_init_console(pst_log* log); -void pst_log_init_file(pst_log* log, const char* path, uint64_t max_bytes = 64 * 1024 * 1024/* 64Mb */); +void pst_log_init_file(pst_log* log, const char* path, uint64_t max_bytes); void pst_log_fini(pst_log* log); #endif /* __PST_LOG_H_ */ diff --git a/tests/main.cpp b/tests/main.c similarity index 95% rename from tests/main.cpp rename to tests/main.c index ae4542b..69eb2f8 100644 --- a/tests/main.cpp +++ b/tests/main.c @@ -29,7 +29,6 @@ uint32_t Fun1(const int arg1, my_int arg2, uint32_t arg3) #include #include -#include #include #include #include @@ -39,7 +38,7 @@ uint32_t Fun1(const int arg1, my_int arg2, uint32_t arg3) typedef void (*sig_handler_t)(int sig); -void SetSignalHandler(sig_handler_t handler = 0); +void SetSignalHandler(sig_handler_t handler); void SigusrHandler(int sig) { @@ -69,9 +68,9 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context) return; } - int ret = pst_unwind_simple(handler, stdout); + int ret = pst_unwind_simple_fd(handler, stdout); if(!ret) { - pst_unwind_pretty(handler, stdout); + pst_unwind_pretty_fd(handler, stdout); } else { printf("No stack trace obtained\n"); } @@ -94,7 +93,7 @@ void FatalSignalHandler(int sig, siginfo_t* info, void* context) void SignalHandler(int sig) { // do nothing and reset to our handler back - SetSignalHandler(); + SetSignalHandler(0); } #include diff --git a/tests/simple.cpp b/tests/simple.c similarity index 100% rename from tests/simple.cpp rename to tests/simple.c