fix compilation errors related to C specifics

This commit is contained in:
2020-02-05 16:14:52 +04:00
parent ef055f0324
commit cdacdce8e5
29 changed files with 93 additions and 92 deletions
+4 -4
View File
@@ -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); \
+2 -2
View File
@@ -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);
+4 -4
View File
@@ -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); \
@@ -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, &regval);
+1 -1
View File
@@ -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__ */
+4 -4
View File
@@ -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;
View File
+7 -6
View File
@@ -13,6 +13,7 @@
#include <execinfo.h>
#include <libunwind.h>
#include <elfutils/libdwfl.h>
#include <stdbool.h>
#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
@@ -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, &param->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;
}
+4 -4
View File
@@ -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
@@ -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;
@@ -8,7 +8,9 @@
#include <dwarf.h>
#include <stdlib.h>
#include <cxxabi.h>
#include <libiberty/demangle.h>
#include <stdio.h>
#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) {
+3 -3
View File
@@ -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);
@@ -4,15 +4,16 @@
* Created on: Dec 28, 2019
* Author: nnosov
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <ucontext.h>
#include <dwarf.h>
#include <elfutils/libdwfl.h>
#include <cxxabi.h>
#include <execinfo.h>
#include <inttypes.h>
#include <dlfcn.h>
@@ -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) {
@@ -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(&param->types) : list_next(&t->node);
pst_type* ret = NULL;
+3 -2
View File
@@ -9,6 +9,7 @@
#define __PST_DWARF_STACK_H__
#include <stdint.h>
#include <stdbool.h>
#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);
@@ -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;
-4
View File
@@ -15,10 +15,6 @@
#include "dwarf_function.h"
typedef struct __reginfo {
__reginfo() {
regname[0] = 0;
regno = -1;
}
char regname[32];
int regno;
} reginfo;
+2 -2
View File
@@ -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) {
+4 -4
View File
@@ -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;
+5 -5
View File
@@ -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);
+3 -2
View File
@@ -1,6 +1,7 @@
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#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);
}
+10 -9
View File
@@ -7,26 +7,27 @@
#include <string.h>
#include <pthread.h>
#include <limits.h>
#include <stdbool.h>
// 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_ */
+4 -5
View File
@@ -29,7 +29,6 @@ uint32_t Fun1(const int arg1, my_int arg2, uint32_t arg3)
#include <ucontext.h>
#include <execinfo.h>
#include <cxxabi.h>
#include <signal.h>
#include <limits.h>
#include <sys/types.h>
@@ -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 <sys/time.h>
View File