add extern "C" to use pstrace in C++ applications. renamed global logger

This commit is contained in:
2020-11-19 13:10:23 +04:00
parent 154c8e2f18
commit 4a3dbdae4a
4 changed files with 13 additions and 5 deletions
+8
View File
@@ -14,6 +14,10 @@
#include <ucontext.h> #include <ucontext.h>
#include <stdint.h> #include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "libpst-types.h" #include "libpst-types.h"
typedef struct pst_handler pst_handler; typedef struct pst_handler pst_handler;
@@ -133,4 +137,8 @@ int pst_unwind_pretty(pst_handler* handler);
*/ */
const char* pst_print_pretty(pst_handler* handler); const char* pst_print_pretty(pst_handler* handler);
#ifdef __cplusplus
}
#endif
#endif /* __LIBPST_EXTERNAL_H_ */ #endif /* __LIBPST_EXTERNAL_H_ */
+1 -1
View File
@@ -17,7 +17,7 @@
extern dwarf_reg_map reg_map[]; extern dwarf_reg_map reg_map[];
extern int regnum; extern int regnum;
pst_logger logger; // logger for library pst_logger pstlogger; // logger for library
pst_allocator allocator; // custom allocator for PST library pst_allocator allocator; // custom allocator for PST library
static void clean_print(pst_context* ctx) static void clean_print(pst_context* ctx)
+2 -2
View File
@@ -21,14 +21,14 @@
// uncomment line below to enable debug output to stdout // uncomment line below to enable debug output to stdout
//#define PST_DEBUG //#define PST_DEBUG
extern pst_logger logger; // logger for whole PST library extern pst_logger pstlogger; // logger for whole PST library
extern pst_allocator allocator; // custom allocator for PST library extern pst_allocator allocator; // custom allocator for PST library
#define pst_alloc(TYPE) (TYPE*)allocator.alloc(&allocator, sizeof(TYPE)) #define pst_alloc(TYPE) (TYPE*)allocator.alloc(&allocator, sizeof(TYPE))
#define pst_free(NAME) allocator.free(&allocator, NAME) #define pst_free(NAME) allocator.free(&allocator, NAME)
#ifdef PST_DEBUG #ifdef PST_DEBUG
#define pst_log(SEVERITY, FORMAT, ...) logger.log(&logger, SEVERITY, FORMAT, ##__VA_ARGS__) #define pst_log(SEVERITY, FORMAT, ...) pstlogger.log(&logger, SEVERITY, FORMAT, ##__VA_ARGS__)
#else #else
#define pst_log(SEVERITY, FORMAT, ...) #define pst_log(SEVERITY, FORMAT, ...)
#endif #endif
+2 -2
View File
@@ -23,7 +23,7 @@ pst_handler* pst_lib_init(ucontext_t* hctx, void* buff, uint32_t size)
pst_alloc_init_custom(&allocator, buff, size); pst_alloc_init_custom(&allocator, buff, size);
} }
pst_log_init_console(&logger); pst_log_init_console(&pstlogger);
pst_new(pst_handler, handler, hctx); pst_new(pst_handler, handler, hctx);
@@ -37,7 +37,7 @@ void pst_lib_fini(pst_handler* h)
pst_free(h); pst_free(h);
// global // global
pst_log_fini(&logger); pst_log_fini(&pstlogger);
pst_alloc_fini(&allocator); pst_alloc_fini(&allocator);
} }