1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef _RECORD_BLOCK_H |
6 | #define _RECORD_BLOCK_H |
7 | |
8 | #include <linux/unistd.h> |
9 | #include <time.h> |
10 | #include <stdio.h> |
11 | #include <stdlib.h> |
12 | |
13 | #include <cstdint> |
14 | #include <string> |
15 | #include <vector> |
16 | |
17 | #include "cpu.h" |
18 | #include "zstd_writer.h" |
19 | |
20 | typedef struct tagVmSegment { |
21 | uintptr_t start; |
22 | uintptr_t end; |
23 | }VmSegment; |
24 | |
25 | typedef struct tagEventHead{ |
26 | struct timespec cur_time; |
27 | int16_t reason; |
28 | uint16_t thread_num; |
29 | uint16_t current_tid; /*thread trigger syscall*/ |
30 | uint16_t ; |
31 | }EventHead; |
32 | |
33 | typedef struct tagThreadContext{ |
34 | bool interrupted; |
35 | uint16_t tid; |
36 | USER_REGS regs; |
37 | USER_FPREGS fpregs; |
38 | VmSegment stack; |
39 | std::vector<char> tls; /*contain errno, ...*/ |
40 | }ThreadContext; |
41 | |
42 | class TraceStream { |
43 | public: |
44 | TraceStream(void); |
45 | ~TraceStream(void); |
46 | bool init(pid_t pid, int buffer_size, ZstdWriter* writer); |
47 | int write(ThreadContext* block); |
48 | int write(EventHead* head, void* ); |
49 | int write(void* buf, int size); |
50 | int write(VmSegment* segment); |
51 | int read(uintptr_t addr, void* buf, int size); |
52 | int get_pid(void) {return pid;}; |
53 | int error_count(void) {return pread_error;}; |
54 | |
55 | private: |
56 | int log_pread_error(int error, uintptr_t offset, int got, int req); |
57 | std::vector<char> buffer; |
58 | int pread_error; |
59 | int pid; |
60 | int mem_file; |
61 | ZstdWriter* zstd; |
62 | }; |
63 | |
64 | #endif /*end #ifndef _RECORD_BLOCK_H*/ |
65 | |