pstrace

Форк
0
/
libpst.c 
90 строк · 2.0 Кб
1
/*
2
 * libpst.c
3
 *
4
 *  Created on: Feb 5, 2020
5
 *      Author: nnosov
6
 */
7

8
#include <ucontext.h>
9
#include <stdio.h>
10
#include <stdint.h>
11

12
#include "utils/allocator.h"
13
#include "dwarf/dwarf_handler.h"
14
#include "dwarf/dwarf_parameter.h"
15

16
// allocate and initialize libpst library
17
pst_handler* pst_lib_init(ucontext_t* hctx, void* buff, uint32_t size)
18
{
19
    // global
20
    if(!buff || !size) {
21
        pst_alloc_init(&allocator);
22
    } else {
23
        pst_alloc_init_custom(&allocator, buff, size);
24
    }
25

26
    pst_log_init_console(&pstlogger);
27

28
    pst_new(pst_handler, handler, hctx);
29

30
    return handler;
31
}
32

33
// deallocate libpst handler and library
34
void pst_lib_fini(pst_handler* h)
35
{
36
    pst_handler_fini(h);
37
    pst_free(h);
38

39
    // global
40
    pst_log_fini(&pstlogger);
41
    pst_alloc_fini(&allocator);
42
}
43

44
// save stack trace information to provided buffer in RAM
45
int pst_unwind_simple(pst_handler* h)
46
{
47
    return pst_handler_unwind_simple(h);
48
}
49

50
// save stack trace information to provided buffer in RAM
51
int pst_unwind_pretty(pst_handler* h)
52
{
53
    return pst_handler_handle_dwarf(h);
54
}
55

56
pst_parameter_info* pst_get_parameter_info(pst_parameter* parameter)
57
{
58
    return &parameter->info;
59
}
60

61
pst_function_info* pst_get_function_info(pst_function* function)
62
{
63
    return &function->info;
64
}
65

66
pst_function* pst_function_next(pst_handler* handler, pst_function* current)
67
{
68
    return pst_handler_next_function(handler, current);
69
}
70

71
int pst_get_register(pst_function* fn, int regno, unw_word_t* val)
72
{
73
    if(regno == UNW_X86_64_CFA) {
74
        // intentionally return our own CFA obtained using libdw since libunwind returns wrong register value
75
        *val = fn->info.cfa;
76
        return 0;
77
    }
78

79
    return unw_get_reg(&fn->context, regno, val);
80
}
81

82
pst_parameter* pst_parameter_next(pst_function* function, pst_parameter* current)
83
{
84
    return function_next_parameter(function, current);
85
}
86

87
pst_parameter* pst_parameter_next_child(pst_parameter* parent, pst_parameter* current)
88
{
89
    return parameter_next_child(parent, current);
90
}
91

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.