Skip to content

Commit e3a5dc8

Browse files
committed
Move defs into header file and add Frame struct.
1 parent 48e0f40 commit e3a5dc8

File tree

3 files changed

+84
-14
lines changed

3 files changed

+84
-14
lines changed

contrib/plugins/bap-tracing/frame.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "tracing.h"
2+
3+
Frame *frame_new_std(uint64_t addr, int vcpu_id) {
4+
Frame *frame = g_new(Frame, 1);
5+
frame__init(frame);
6+
7+
StdFrame *sframe = g_new(StdFrame, 1);
8+
std_frame__init(sframe);
9+
frame->std_frame = sframe;
10+
11+
sframe->address = addr;
12+
sframe->thread_id = vcpu_id;
13+
14+
OperandValueList *ol_in = g_new(OperandValueList, 1);
15+
operand_value_list__init(ol_in);
16+
ol_in->n_elem = 0;
17+
sframe->operand_pre_list = ol_in;
18+
19+
OperandValueList *ol_out = g_new(OperandValueList, 1);
20+
operand_value_list__init(ol_out);
21+
ol_out->n_elem = 0;
22+
sframe->operand_post_list = ol_out;
23+
return frame;
24+
}

contrib/plugins/bap-tracing/tracing.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
// SPDX-FileCopyrightText: 2025 Rot127 <[email protected]>
22
// SPDX-License-Identifier: GPL-2.0-only
33

4-
#include <qemu-plugin.h>
4+
#include <glib.h>
55

6-
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
7-
8-
typedef struct {
9-
// Current instruction related things.
10-
} VCPU;
11-
12-
typedef struct {
13-
GRWLock vcpus_array_lock;
14-
GArray *vcpus;
15-
16-
GRWLock frame_buffer_lock;
17-
GPtrArray *frame_buffer;
18-
} TraceState;
6+
#include "tracing.h"
197

208
static TraceState state;
219

contrib/plugins/bap-tracing/tracing.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef BAP_TRACING_H
2+
#define BAP_TRACING_H
3+
4+
#include <qemu-plugin.h>
5+
#include <stdio.h>
6+
7+
#include "tracewrap.h"
8+
9+
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
10+
11+
#define FRAME_BUFFER_SIZE 1024
12+
13+
typedef struct {
14+
Frame **fbuf;
15+
size_t len;
16+
} FrameBuffer;
17+
18+
typedef struct {
19+
// Current instruction related things.
20+
} VCPU;
21+
22+
typedef struct {
23+
GRWLock vcpus_array_lock;
24+
GArray *vcpus;
25+
26+
GRWLock frame_buffer_lock;
27+
FrameBuffer *frame_buffer;
28+
29+
GRWLock file_lock;
30+
FILE *file;
31+
} TraceState;
32+
33+
VCPU *vcpu_new(void);
34+
35+
/**
36+
* \brief Initializes a frame buffer with space for \p size frames.
37+
* Returns the buffer or NULL in case of failure.
38+
*/
39+
FrameBuffer *frame_buffer_init(size_t size);
40+
41+
/**
42+
* \brief Push a frame into the buffer.
43+
* Returns true on success. False otherwise.
44+
*/
45+
bool frame_buffer_push(FrameBuffer *buf, Frame *frame);
46+
47+
/**
48+
* \brief Flusehs the buffer and returns it's content.
49+
* The size of the returned buffer is written to \p fbuf_size.
50+
*/
51+
Frame **frame_buffer_flush(FrameBuffer *buf, size_t *fbuf_size);
52+
53+
/**
54+
* \brief Create new std frame
55+
*/
56+
Frame *frame_new_std(uint64_t addr, int vcpu_id);
57+
58+
#endif

0 commit comments

Comments
 (0)