Skip to content

Commit

Permalink
add extern "C" to use pstrace in C++ applications. renamed global logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nnosov committed Nov 19, 2020
1 parent 154c8e2 commit 4a3dbda
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/libpst.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <ucontext.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "libpst-types.h"

typedef struct pst_handler pst_handler;
Expand Down Expand Up @@ -133,4 +137,8 @@ int pst_unwind_pretty(pst_handler* handler);
*/
const char* pst_print_pretty(pst_handler* handler);

#ifdef __cplusplus
}
#endif

#endif /* __LIBPST_EXTERNAL_H_ */
2 changes: 1 addition & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
extern dwarf_reg_map reg_map[];
extern int regnum;

pst_logger logger; // logger for library
pst_logger pstlogger; // logger for library
pst_allocator allocator; // custom allocator for PST library

static void clean_print(pst_context* ctx)
Expand Down
4 changes: 2 additions & 2 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
// uncomment line below to enable debug output to stdout
//#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

#define pst_alloc(TYPE) (TYPE*)allocator.alloc(&allocator, sizeof(TYPE))
#define pst_free(NAME) allocator.free(&allocator, NAME)

#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
#define pst_log(SEVERITY, FORMAT, ...)
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/libpst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_log_init_console(&logger);
pst_log_init_console(&pstlogger);

pst_new(pst_handler, handler, hctx);

Expand All @@ -37,7 +37,7 @@ void pst_lib_fini(pst_handler* h)
pst_free(h);

// global
pst_log_fini(&logger);
pst_log_fini(&pstlogger);
pst_alloc_fini(&allocator);
}

Expand Down

0 comments on commit 4a3dbda

Please sign in to comment.