Skip to content

Commit 62c5235

Browse files
authored
Merge pull request #42 from Starforge-Atelier/trace-10-tricore
gdb-xml: add tricore.xml
2 parents f78db2c + 0b343c5 commit 62c5235

File tree

12 files changed

+161
-5
lines changed

12 files changed

+161
-5
lines changed

.github/workflows/build.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jobs:
1111
uses: actions/setup-python@v4
1212
with:
1313
python-version: '3.x'
14+
- name: Install Python dependencies
15+
run: |
16+
pip install --upgrade pip
17+
pip install distlib setuptools wheel
1418
- name: Install deps
1519
run: |
1620
sudo apt-get -y update
@@ -32,5 +36,5 @@ jobs:
3236
cd qemu
3337
mkdir build
3438
cd build
35-
../configure --enable-plugins --target-list=sparc-linux-user,sparc64-linux-user
39+
../configure --enable-plugins --target-list=sparc-linux-user,sparc64-linux-user,tricore-softmmu
3640
ninja

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
url = https://gitlab.com/libvirt/libvirt-ci.git
4646
[submodule "contrib/plugins/bap-tracing/bap-frames"]
4747
path = contrib/plugins/bap-tracing/bap-frames
48-
url = git@github.com:BinaryAnalysisPlatform/bap-frames.git
48+
url = https://github.com/BinaryAnalysisPlatform/bap-frames.git

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Known to work:
1111
- Sparc
1212
- Hexagon
1313
- PPC
14+
- TriCore
1415

1516
Needs fixes:
1617

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
TARGET_ARCH=tricore
22
TARGET_LONG_BITS=32
3+
TARGET_XML_FILES=gdb-xml/tricore-core.xml

contrib/plugins/bap-tracing/meson.build

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ frame_proto_src = custom_target(
3131
)
3232

3333
libprotobuf = dependency('libprotobuf-c')
34-
frame_protobuf = static_library('protobuf', [frame_proto_src], pic: true)
34+
frame_protobuf = static_library(
35+
'protobuf',
36+
[frame_proto_src],
37+
dependencies: [libprotobuf],
38+
pic: true)
3539
dep_libprotobuf = declare_dependency(
3640
sources : [frame_proto_src, frame_arch_h],
3741
link_with : [frame_protobuf],

contrib/plugins/bap-tracing/tracing.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static void flush_and_write_toc_entry(FrameBuffer *fbuf) {
184184
g_rw_lock_writer_unlock(&state.file_lock);
185185
}
186186

187+
static void flush_all_frame_bufs(void) __attribute__((unused));
187188
static void flush_all_frame_bufs(void) {
188189
g_rw_lock_writer_lock(&state.file_lock);
189190
g_rw_lock_writer_lock(&state.toc_entries_offsets_lock);
@@ -339,7 +340,37 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) {
339340
}
340341

341342
static void plugin_exit(qemu_plugin_id_t id, void *udata) {
342-
flush_all_frame_bufs();
343+
qemu_plugin_outs("Exiting bap-tracing plugin\n");
344+
/**
345+
* FIXME: flush_all_frame_bufs() is currently commented out due to an
346+
* assertion failure in qemu_plugin_get_registers when used in the plugin
347+
* exit callback.
348+
*
349+
* Root cause: When the plugin exits, current_cpu has already been set to
350+
* NULL by QEMU's shutdown sequence. However, flush_all_frame_bufs() calls
351+
* qemu_plugin_get_registers() (via add_post_reg_state()) to capture the
352+
* final register state, which internally asserts that current_cpu is
353+
* non-NULL. This causes the assertion to fail.
354+
*
355+
* This issue is specific to the TriCore architecture tracing but may affect
356+
* other architectures as well.
357+
*
358+
* Potential drawbacks of commenting out this call:
359+
* 1. The last few instruction frames in each vCPU's buffer may not be
360+
* written to the trace file, resulting in incomplete traces.
361+
* 2. Post-execution register states for the final instructions will not
362+
* be captured, potentially losing important state information.
363+
* 3. If the frame buffers have accumulated data that hasn't reached the
364+
* flush threshold, that data will be lost entirely.
365+
*
366+
* Possible solutions:
367+
* - Modify QEMU to allow qemu_plugin_get_registers() to gracefully handle
368+
* NULL current_cpu during shutdown
369+
* - Add a pre-exit flush mechanism that runs before current_cpu is cleared
370+
* - Skip register state capture in flush_all_frame_bufs() when called from
371+
* plugin_exit, flushing only the instruction frames without post-state
372+
*/
373+
// flush_all_frame_bufs();
343374

344375
g_rw_lock_writer_lock(&state.file_lock);
345376
g_rw_lock_reader_lock(&state.toc_entries_offsets_lock);

contrib/plugins/bap-tracing/tracing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static struct arch_enum_entry arch_map[] = {
104104
{.name = "8051", .arch = frame_arch_8051, .machine = 0},
105105
{.name = "sm83", .arch = frame_arch_sm83, .machine = 0},
106106
{.name = "hexagon", .arch = frame_arch_hexagon, .machine = 0},
107+
{.name = "tricore", .arch = frame_arch_tricore, .machine = frame_mach_tricore_162},
107108
{.name = NULL, .arch = frame_arch_last, .machine = 0},
108109
};
109110

gdb-xml/tricore-core.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0"?>
2+
3+
<!-- Based on https://github.com/Gigallith/gdb-tricore/blob/main/gdb/features/tricore-core.xml
4+
Modified according to rizin's TriCore plugin and QEMU's TriCore implementation.
5+
Added several special registers (syscon, cpu_id, core_id, biv, btv, isp, fcx, lcx, compat,
6+
pmucon0, cycles, instr, time). -->
7+
8+
<!-- Copyright (C) 2019 Free Software Foundation, Inc.
9+
10+
Copying and distribution of this file, with or without modification,
11+
are permitted in any medium without royalty provided the copyright
12+
notice and this notice are preserved. -->
13+
14+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
15+
<feature name="org.gnu.gdb.tricore.core">
16+
<reg name="a0" bitsize="32" type="data_ptr"/>
17+
<reg name="a1" bitsize="32" type="uint32"/>
18+
<reg name="a2" bitsize="32" type="uint32"/>
19+
<reg name="a3" bitsize="32" type="uint32"/>
20+
<reg name="a4" bitsize="32" type="uint32"/>
21+
<reg name="a5" bitsize="32" type="uint32"/>
22+
<reg name="a6" bitsize="32" type="uint32"/>
23+
<reg name="a7" bitsize="32" type="uint32"/>
24+
<reg name="a8" bitsize="32" type="uint32"/>
25+
<reg name="a9" bitsize="32" type="uint32"/>
26+
<reg name="a10" bitsize="32" type="uint32"/>
27+
<reg name="a11" bitsize="32" type="uint32"/>
28+
<reg name="a12" bitsize="32" type="uint32"/>
29+
<reg name="a13" bitsize="32" type="uint32"/>
30+
<reg name="a14" bitsize="32" type="uint32"/>
31+
<reg name="a15" bitsize="32" type="uint32"/>
32+
33+
<reg name="d0" bitsize="32" type="data_ptr"/>
34+
<reg name="d1" bitsize="32" type="uint32"/>
35+
<reg name="d2" bitsize="32" type="uint32"/>
36+
<reg name="d3" bitsize="32" type="uint32"/>
37+
<reg name="d4" bitsize="32" type="uint32"/>
38+
<reg name="d5" bitsize="32" type="uint32"/>
39+
<reg name="d6" bitsize="32" type="uint32"/>
40+
<reg name="d7" bitsize="32" type="uint32"/>
41+
<reg name="d8" bitsize="32" type="uint32"/>
42+
<reg name="d9" bitsize="32" type="uint32"/>
43+
<reg name="d10" bitsize="32" type="uint32"/>
44+
<reg name="d11" bitsize="32" type="uint32"/>
45+
<reg name="d12" bitsize="32" type="uint32"/>
46+
<reg name="d13" bitsize="32" type="uint32"/>
47+
<reg name="d14" bitsize="32" type="uint32"/>
48+
<reg name="d15" bitsize="32" type="uint32"/>
49+
50+
<flags id="psw_flags" size="4">
51+
<field name="CDC" start="0" end="6"/>
52+
<field name="CDE" start="7" end="8"/>
53+
<field name="C" start="31" end="31"/>
54+
<field name="V" start="30" end="30"/>
55+
<field name="SV" start="29" end="29"/>
56+
<field name="AV" start="28" end="28"/>
57+
<field name="SAV" start="27" end="27"/>
58+
<field name="RM" start="24" end="25"/>
59+
<field name="PRS" start="12" end="13"/>
60+
<field name="IO" start="10" end="11"/>
61+
<field name="IS" start="9" end="9"/>
62+
<field name="GW" start="8" end="8"/>
63+
</flags>
64+
65+
<reg name="pcxi" bitsize="32" type="data_ptr"/>
66+
<reg name="psw" bitsize="32" type="psw_flags"/>
67+
<reg name="pc" bitsize="32" type="code_ptr"/>
68+
<reg name="icr" bitsize="32" type="uint32"/>
69+
<reg name="syscon" bitsize="32" type="uint32"/>
70+
<reg name="cpu_id" bitsize="32" type="uint32"/>
71+
<reg name="core_id" bitsize="32" type="uint32"/>
72+
<reg name="biv" bitsize="32" type="uint32"/>
73+
<reg name="btv" bitsize="32" type="uint32"/>
74+
<reg name="isp" bitsize="32" type="uint32"/>
75+
<reg name="icr" bitsize="32" type="uint32"/>
76+
<reg name="fcx" bitsize="32" type="uint32"/>
77+
<reg name="lcx" bitsize="32" type="uint32"/>
78+
<reg name="compat" bitsize="32" type="uint32"/>
79+
<reg name="pmucon0" bitsize="32"/>
80+
<reg name="cycles" bitsize="32"/>
81+
<reg name="instr" bitsize="32"/>
82+
<reg name="time" bitsize="32"/>
83+
</feature>

gdb-xml/tricore-fpu.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2007-2020 Free Software Foundation, Inc.
3+
4+
Copying and distribution of this file, with or without modification,
5+
are permitted in any medium without royalty provided the copyright
6+
notice and this notice are preserved. -->
7+
8+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
9+
<feature name="org.gnu.gdb.tricore.fpu">
10+
<reg name="FPU_TRAP_CON" bitsize="32" type="ieee_single" regnum="0"/>
11+
<reg name="FPU_TRAP_PC" bitsize="32" type="ieee_single"/>
12+
<reg name="FPU_TRAP_OPC" bitsize="32" type="ieee_single"/>
13+
<reg name="FPU_TRAP_SRC1" bitsize="32" type="ieee_single"/>
14+
<reg name="FPU_TRAP_SRC2" bitsize="32" type="ieee_single"/>
15+
<reg name="FPU_TRAP_SRC3" bitsize="32" type="ieee_single"/>
16+
<reg name="FPU_ID" bitsize="32" type="ieee_single"/>
17+
</feature>

0 commit comments

Comments
 (0)