diff --git a/src/arch/registers.h b/src/arch/registers.h index 045cb0c..7982667 100644 --- a/src/arch/registers.h +++ b/src/arch/registers.h @@ -1,4 +1,16 @@ -#pragma once +#ifndef __PST_REGISTERS_H__ +#define __PST_REGISTERS_H__ + +/* + * registers.cpp + * + * x86_64 registers mapping to DWARF registers + * + * Created on: Jan 27, 2020 + * Author: nnosov + */ + + #include #include @@ -22,3 +34,5 @@ typedef enum { } pst_reg_error; pst_reg_error pst_get_reg(pst_context* ctx, int regno, uint64_t& regval); + +#endif /* __PST_REGISTERS_H__ */ diff --git a/src/common.h b/src/common.h index 48abdbd..8196255 100644 --- a/src/common.h +++ b/src/common.h @@ -1,5 +1,12 @@ #ifndef __PST_COMMON_H__ #define __PST_COMMON_H__ +/* + * common.h + * + * Created on: Jan 8, 2020 + * Author: nnosov + */ + #include diff --git a/src/context.cpp b/src/context.cpp index 1423df9..f8076c8 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -10,8 +10,8 @@ #include "context.h" -#include "../src/dwarf/dwarf_operations.h" -#include "registers.h" +#include "dwarf/dwarf_operations.h" +#include "arch/registers.h" extern dwarf_reg_map reg_map[]; diff --git a/src/context.h b/src/context.h index 68bc0a3..5cc6c88 100644 --- a/src/context.h +++ b/src/context.h @@ -14,8 +14,8 @@ #include #include -#include "../src/utils/allocator.h" -#include "../src/utils/log.h" +#include "utils/allocator.h" +#include "utils/log.h" extern pst_log logger; // logger for whole PST library extern pst_allocator allocator; // custom allocator for PST library diff --git a/src/dwarf/dwarf_call_site.cpp b/src/dwarf/dwarf_call_site.cpp index 08e5909..457f0bc 100644 --- a/src/dwarf/dwarf_call_site.cpp +++ b/src/dwarf/dwarf_call_site.cpp @@ -5,15 +5,15 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_call_site.h" #include #include -#include "../src/dwarf/dwarf_function.h" -#include "../src/dwarf/dwarf_utils.h" -#include "../src/dwarf/dwarf_utils.h" -#include "../utils/hash_multimap.h" +#include "dwarf_call_site.h" +#include "dwarf_function.h" +#include "dwarf_utils.h" +#include "dwarf_utils.h" +#include "utils/hash_multimap.h" // ----------------------------------------------------------------------------------- // pst_call_site_param diff --git a/src/dwarf/dwarf_call_site.h b/src/dwarf/dwarf_call_site.h index f908256..1c1430c 100644 --- a/src/dwarf/dwarf_call_site.h +++ b/src/dwarf/dwarf_call_site.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_CALL_SITE_H_ -#define SRC_DWARF_DWARF_CALL_SITE_H_ +#ifndef __PST_DWARF_CALL_SITE_H__ +#define __PST_DWARF_CALL_SITE_H__ #include #include @@ -87,4 +87,4 @@ void pst_call_site_storage_del(pst_call_site_storage* storage, pst_call_site* st void pst_call_site_storage_del(pst_call_site_storage* storage, pst_call_site* st); -#endif /* SRC_DWARF_DWARF_CALL_SITE_H_ */ +#endif /* __PST_DWARF_CALL_SITE_H__ */ diff --git a/src/dwarf/dwarf_expression.cpp b/src/dwarf/dwarf_expression.cpp index d58e200..4b6f53a 100644 --- a/src/dwarf/dwarf_expression.cpp +++ b/src/dwarf/dwarf_expression.cpp @@ -5,13 +5,13 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_expression.h" #include -#include "../utils/allocator.h" +#include "utils/allocator.h" #include "common.h" #include "context.h" +#include "dwarf_expression.h" // // DWARF operation diff --git a/src/dwarf/dwarf_expression.h b/src/dwarf/dwarf_expression.h index 69fc600..e57d565 100644 --- a/src/dwarf/dwarf_expression.h +++ b/src/dwarf/dwarf_expression.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_EXPRESSION_H_ -#define SRC_DWARF_DWARF_EXPRESSION_H_ +#ifndef __PST_DWARF_EXPRESSION_H__ +#define __PST_DWARF_EXPRESSION_H__ #include #include @@ -46,4 +46,4 @@ bool pst_dwarf_expr_equal(pst_dwarf_expr* lhs, pst_dwarf_expr* rhs); bool pst_dwarf_expr_print_op(pst_dwarf_expr* expr, const char* fmt, ...); void pst_dwarf_expr_set_value(pst_dwarf_expr* expr, uint64_t v); -#endif /* SRC_DWARF_DWARF_EXPRESSION_H_ */ +#endif /* __PST_DWARF_EXPRESSION_H__ */ diff --git a/src/dwarf/dwarf_function.cpp b/src/dwarf/dwarf_function.cpp index ba93c77..6774672 100644 --- a/src/dwarf/dwarf_function.cpp +++ b/src/dwarf/dwarf_function.cpp @@ -5,14 +5,14 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_function.h" #include #include #include -#include "../src/dwarf/dwarf_stack.h" -#include "../src/dwarf/dwarf_utils.h" +#include "dwarf_stack.h" +#include "dwarf_utils.h" +#include "dwarf_function.h" // ----------------------------------------------------------------------------------- // pst_function diff --git a/src/dwarf/dwarf_function.h b/src/dwarf/dwarf_function.h index 3337a26..e07fb34 100644 --- a/src/dwarf/dwarf_function.h +++ b/src/dwarf/dwarf_function.h @@ -5,14 +5,17 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_FUNCTION_H_ -#define SRC_DWARF_DWARF_FUNCTION_H_ +#ifndef __PST_DWARF_FUNCTION_H__ +#define __PST_DWARF_FUNCTION_H__ -#include "../src/dwarf/dwarf_call_site.h" -#include "../src/dwarf/dwarf_expression.h" -#include "../src/dwarf/dwarf_parameter.h" -#include "../utils/list_head.h" +#include +#include + +#include "utils/list_head.h" #include "context.h" +#include "dwarf_call_site.h" +#include "dwarf_expression.h" +#include "dwarf_parameter.h" // ----------------------------------------------------------------------------------- // pst_function @@ -46,4 +49,4 @@ bool pst_function_unwind(pst_function* fn, Dwarf_Addr addr); bool pst_function_handle_dwarf(pst_function * fn, Dwarf_Die* d); bool pst_function_print_dwarf(pst_function* fn); -#endif /* SRC_DWARF_DWARF_FUNCTION_H_ */ +#endif /* __PST_DWARF_FUNCTION_H__ */ diff --git a/src/dwarf/dwarf_handler.h b/src/dwarf/dwarf_handler.h index 9107194..36ddd18 100644 --- a/src/dwarf/dwarf_handler.h +++ b/src/dwarf/dwarf_handler.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef PST_HANDLER_H_ -#define PST_HANDLER_H_ +#ifndef __PST_DWARF_HANDLER_H__ +#define __PST_DWARF_HANDLER_H__ //system #include @@ -29,4 +29,4 @@ bool pst_handler_handle_dwarf(pst_handler* h); void pst_handler_print_dwarf(pst_handler* h); bool pst_handler_unwind(pst_handler* h); -#endif /* PST_HANDLER_H_ */ +#endif /* __PST_DWARF_HANDLER_H__ */ diff --git a/src/dwarf/dwarf_operations.cpp b/src/dwarf/dwarf_operations.cpp index 7167cb3..5f6c531 100644 --- a/src/dwarf/dwarf_operations.cpp +++ b/src/dwarf/dwarf_operations.cpp @@ -5,13 +5,13 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_operations.h" #include #include #include "common.h" #include "registers.h" +#include "dwarf_operations.h" // not implemented operations bool dw_op_notimpl(pst_dwarf_stack* stack, const dwarf_op_map* map, Dwarf_Word op1, Dwarf_Word op2) diff --git a/src/dwarf/dwarf_operations.h b/src/dwarf/dwarf_operations.h index 3967437..6ca0c60 100644 --- a/src/dwarf/dwarf_operations.h +++ b/src/dwarf/dwarf_operations.h @@ -1,4 +1,13 @@ -#pragma once +#ifndef __PST_DWARF_OPERATIONS_H__ +#define __PST_DWARF_OPERATIONS_H__ + +/* + * dwarf_operations.cpp + * + * Created on: Jan 11, 2020 + * Author: nnosov + */ + #include @@ -20,3 +29,5 @@ typedef struct __dwarf_op_map { } dwarf_op_map; const dwarf_op_map* find_op_map(int op); + +#endif /* __PST_DWARF_OPERATIONS_H__ */ diff --git a/src/dwarf/dwarf_parameter.cpp b/src/dwarf/dwarf_parameter.cpp index caaf49b..8ae658c 100644 --- a/src/dwarf/dwarf_parameter.cpp +++ b/src/dwarf/dwarf_parameter.cpp @@ -5,13 +5,13 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_parameter.h" #include #include -#include "../src/dwarf/dwarf_utils.h" +#include "dwarf_utils.h" #include "context.h" +#include "dwarf_parameter.h" // // pst_type diff --git a/src/dwarf/dwarf_parameter.h b/src/dwarf/dwarf_parameter.h index 9b70afa..702b6b3 100644 --- a/src/dwarf/dwarf_parameter.h +++ b/src/dwarf/dwarf_parameter.h @@ -5,14 +5,14 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_PARAMETER_H_ -#define SRC_DWARF_DWARF_PARAMETER_H_ +#ifndef __PST_DWARF_PARAMETER_H__ +#define __PST_DWARF_PARAMETER_H__ #include #include -#include "../src/dwarf/dwarf_expression.h" -#include "../utils/list_head.h" +#include "dwarf_expression.h" +#include "utils/list_head.h" #include "context.h" typedef struct __pst_type { @@ -56,4 +56,4 @@ bool pst_parameter_print_dwarf(pst_parameter* param); bool pst_parameter_handle_type(pst_parameter* param, Dwarf_Attribute* base); pst_type* pst_parameter_add_type(pst_parameter* param, const char* name, int type); -#endif /* SRC_DWARF_DWARF_PARAMETER_H_ */ +#endif /* __PST_DWARF_PARAMETER_H__ */ diff --git a/src/dwarf/dwarf_stack.cpp b/src/dwarf/dwarf_stack.cpp index bd83c7e..2558177 100644 --- a/src/dwarf/dwarf_stack.cpp +++ b/src/dwarf/dwarf_stack.cpp @@ -5,16 +5,16 @@ * Author: nnosov */ -#include "../src/dwarf/dwarf_stack.h" #include #include #include -#include "../src/dwarf/dwarf_operations.h" -#include "../utils/allocator.h" -#include "../utils/list_head.h" +#include "utils/allocator.h" +#include "utils/list_head.h" +#include "dwarf_operations.h" #include "dwarf_handler.h" +#include "dwarf_stack.h" // ----------------------------------------------------------------------------------- // DWARF Stack value diff --git a/src/dwarf/dwarf_stack.h b/src/dwarf/dwarf_stack.h index d523cd3..3a32ce2 100644 --- a/src/dwarf/dwarf_stack.h +++ b/src/dwarf/dwarf_stack.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_STACK_H_ -#define SRC_DWARF_DWARF_STACK_H_ +#ifndef __PST_DWARF_STACK_H__ +#define __PST_DWARF_STACK_H__ #include @@ -94,4 +94,4 @@ 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); -#endif /* SRC_DWARF_DWARF_STACK_H_ */ +#endif /* __PST_DWARF_STACK_H__ */ diff --git a/src/dwarf/dwarf_utils.h b/src/dwarf/dwarf_utils.h index 511c8c1..0d1fde2 100644 --- a/src/dwarf/dwarf_utils.h +++ b/src/dwarf/dwarf_utils.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef SRC_DWARF_DWARF_UTILS_H_ -#define SRC_DWARF_DWARF_UTILS_H_ +#ifndef __PST_DWARF_UTILS_H__ +#define __PST_DWARF_UTILS_H__ #include @@ -27,4 +27,4 @@ int regname_callback (void *arg, int regno, const char *setname, const char *pre bool handle_location(pst_context* ctx, Dwarf_Attribute* attr, pst_dwarf_expr* loc, Dwarf_Addr pc, pst_function* fun); bool is_location_form(int form); -#endif /* SRC_DWARF_DWARF_UTILS_H_ */ +#endif /* __PST_DWARF_UTILS_H__ */ diff --git a/src/utils/allocator.cpp b/src/utils/allocator.cpp index df855cb..c4ca93d 100644 --- a/src/utils/allocator.cpp +++ b/src/utils/allocator.cpp @@ -5,12 +5,12 @@ * Author: nnosov */ -#include "../src/utils/allocator.h" #include #include #include +#include "allocator.h" #include "common.h" void heap_free(pst_allocator* alloc, void* buff) diff --git a/src/utils/allocator.h b/src/utils/allocator.h index cda0e1d..078fd36 100644 --- a/src/utils/allocator.h +++ b/src/utils/allocator.h @@ -5,8 +5,8 @@ * Author: nnosov */ -#ifndef PST_ALLOCATOR_H_ -#define PST_ALLOCATOR_H_ +#ifndef __PST_ALLOCATOR_H__ +#define __PST_ALLOCATOR_H__ #include #include @@ -56,4 +56,4 @@ void pst_alloc_init(pst_allocator* alloc); void pst_alloc_init_custom(pst_allocator* alloc, void* buff, uint32_t size); void pst_alloc_fini(pst_allocator* alloc); -#endif /* PST_ALLOCATOR_H_ */ +#endif /* __PST_ALLOCATOR_H__ */ diff --git a/src/utils/list_head.h b/src/utils/list_head.h index f793a58..e4e9aed 100644 --- a/src/utils/list_head.h +++ b/src/utils/list_head.h @@ -1,5 +1,5 @@ /******************************************************************************* -Copyright (c) 2006, Nikolay Nosov +Copyright (c) 2006, Nikolai Nosov All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/src/utils/log.cpp b/src/utils/log.cpp index 8a44483..fce3752 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.cpp @@ -1,8 +1,9 @@ -#include "../../src/utils/log.h" #include #include +#include "log.h" + const char * const severity_map[] = { " [DEBUG] : ", " [INFO] : ", diff --git a/src/utils/log.h b/src/utils/log.h index ce46118..790540e 100644 --- a/src/utils/log.h +++ b/src/utils/log.h @@ -1,5 +1,5 @@ -#ifndef PST_LOG_H_ -#define PST_LOG_H_ +#ifndef __PST_LOG_H_ +#define __PST_LOG_H_ #include #include @@ -20,9 +20,7 @@ enum SC_LogSeverity { #define LOG_BUFF_SIZE (1024*1024) -typedef struct __pst_log pst_log; - -typedef struct __pst_log { +typedef struct pst_log { // methods void (*close) (pst_log* log); bool (*open) (pst_log* log); @@ -47,4 +45,4 @@ 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_fini(pst_log* log); -#endif /* PST_LOG_H_ */ +#endif /* __PST_LOG_H_ */ diff --git a/tests/simple.cpp b/tests/simple.cpp index 9df250a..291c3e1 100644 --- a/tests/simple.cpp +++ b/tests/simple.cpp @@ -1,6 +1,5 @@ #include - void do_stuff(int my_arg) { int my_local = my_arg + 2; @@ -10,7 +9,6 @@ void do_stuff(int my_arg) printf("i = %d\n", i); } - int main() { do_stuff(2);