From 0e0b286447318b6909f3f32452ebf92434a18ee6 Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 6 Sep 2025 01:56:39 +0800 Subject: [PATCH 01/12] fix frame_protobuf library --- contrib/plugins/bap-tracing/meson.build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/bap-tracing/meson.build b/contrib/plugins/bap-tracing/meson.build index 08ddca168141b..743282e703b3f 100644 --- a/contrib/plugins/bap-tracing/meson.build +++ b/contrib/plugins/bap-tracing/meson.build @@ -31,7 +31,11 @@ frame_proto_src = custom_target( ) libprotobuf = dependency('libprotobuf-c') -frame_protobuf = static_library('protobuf', [frame_proto_src], pic: true) +frame_protobuf = static_library( + 'protobuf', + [frame_proto_src], + dependencies: [libprotobuf], + pic: true) dep_libprotobuf = declare_dependency( sources : [frame_proto_src, frame_arch_h], link_with : [frame_protobuf], From fe13983586d7488eb91ebd3c55a5e319d02722bf Mon Sep 17 00:00:00 2001 From: billow Date: Sat, 6 Sep 2025 01:57:36 +0800 Subject: [PATCH 02/12] add tricore-core.xml fix bap-frames url x x --- .gitmodules | 3 +- configs/targets/tricore-softmmu.mak | 1 + contrib/plugins/bap-tracing/bap-frames | 2 +- contrib/plugins/bap-tracing/tracing.h | 1 + gdb-xml/tricore-core.xml | 72 ++++++++++++++++++++++++++ target/tricore/cpu.c | 1 + 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 gdb-xml/tricore-core.xml diff --git a/.gitmodules b/.gitmodules index 439b531cfbdda..ab35905da9460 100644 --- a/.gitmodules +++ b/.gitmodules @@ -45,4 +45,5 @@ url = https://gitlab.com/libvirt/libvirt-ci.git [submodule "contrib/plugins/bap-tracing/bap-frames"] path = contrib/plugins/bap-tracing/bap-frames - url = git@github.com:BinaryAnalysisPlatform/bap-frames.git + url = https://github.com/b1llow/bap-frames.git + branch = tricore-support diff --git a/configs/targets/tricore-softmmu.mak b/configs/targets/tricore-softmmu.mak index 781ce49a62fe0..37357e1374949 100644 --- a/configs/targets/tricore-softmmu.mak +++ b/configs/targets/tricore-softmmu.mak @@ -1,2 +1,3 @@ TARGET_ARCH=tricore TARGET_LONG_BITS=32 +TARGET_XML_FILES= gdb-xml/tricore-core.xml diff --git a/contrib/plugins/bap-tracing/bap-frames b/contrib/plugins/bap-tracing/bap-frames index 75878683e9fef..821c2b6cd044c 160000 --- a/contrib/plugins/bap-tracing/bap-frames +++ b/contrib/plugins/bap-tracing/bap-frames @@ -1 +1 @@ -Subproject commit 75878683e9fef27bb3053e2237ea098de81ff267 +Subproject commit 821c2b6cd044c5dff72077bc6812e8bd16491465 diff --git a/contrib/plugins/bap-tracing/tracing.h b/contrib/plugins/bap-tracing/tracing.h index 131ac73a27b2b..f39509e2fc3f8 100644 --- a/contrib/plugins/bap-tracing/tracing.h +++ b/contrib/plugins/bap-tracing/tracing.h @@ -104,6 +104,7 @@ static struct arch_enum_entry arch_map[] = { {.name = "8051", .arch = frame_arch_8051, .machine = 0}, {.name = "sm83", .arch = frame_arch_sm83, .machine = 0}, {.name = "hexagon", .arch = frame_arch_hexagon, .machine = 0}, + {.name = "tricore", .arch = frame_arch_tricore, .machine = frame_mach_tricore_162}, {.name = NULL, .arch = frame_arch_last, .machine = 0}, }; diff --git a/gdb-xml/tricore-core.xml b/gdb-xml/tricore-core.xml new file mode 100644 index 0000000000000..67f25c17204a7 --- /dev/null +++ b/gdb-xml/tricore-core.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 16acc4ecb92ec..68b2cd84cf4c8 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -199,6 +199,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) cc->gdb_read_register = tricore_cpu_gdb_read_register; cc->gdb_write_register = tricore_cpu_gdb_write_register; cc->gdb_num_core_regs = 44; + cc->gdb_core_xml_file = "tricore-core.xml"; cc->gdb_arch_name = tricore_gdb_arch_name; cc->dump_state = tricore_cpu_dump_state; From eb87d3dc325be1ca5dd903524fd1b03aa940447a Mon Sep 17 00:00:00 2001 From: billow Date: Mon, 8 Sep 2025 06:32:09 +0800 Subject: [PATCH 03/12] try fix bap-tracing --- contrib/plugins/bap-tracing/tracing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/bap-tracing/tracing.c b/contrib/plugins/bap-tracing/tracing.c index fbb7161f0e5ce..1a5398d3a2360 100644 --- a/contrib/plugins/bap-tracing/tracing.c +++ b/contrib/plugins/bap-tracing/tracing.c @@ -339,7 +339,8 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { } static void plugin_exit(qemu_plugin_id_t id, void *udata) { - flush_all_frame_bufs(); + qemu_plugin_outs("Exiting plugin, flushing data...\n"); + // flush_all_frame_bufs(); g_rw_lock_writer_lock(&state.file_lock); g_rw_lock_reader_lock(&state.toc_entries_offsets_lock); From 51d736bdc5f7434fee66ed7c52be2c08464e9c3c Mon Sep 17 00:00:00 2001 From: billow Date: Sun, 14 Sep 2025 04:29:15 +0800 Subject: [PATCH 04/12] add tricore xml --- gdb-xml/tricore-core.xml | 5 +++++ gdb-xml/tricore-fpu.xml | 17 +++++++++++++++++ gdb-xml/tricore.xml | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 gdb-xml/tricore-fpu.xml create mode 100644 gdb-xml/tricore.xml diff --git a/gdb-xml/tricore-core.xml b/gdb-xml/tricore-core.xml index 67f25c17204a7..48f2a54324d1d 100644 --- a/gdb-xml/tricore-core.xml +++ b/gdb-xml/tricore-core.xml @@ -59,6 +59,7 @@ + @@ -69,4 +70,8 @@ + + + + diff --git a/gdb-xml/tricore-fpu.xml b/gdb-xml/tricore-fpu.xml new file mode 100644 index 0000000000000..d2dbe4da117ff --- /dev/null +++ b/gdb-xml/tricore-fpu.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + diff --git a/gdb-xml/tricore.xml b/gdb-xml/tricore.xml new file mode 100644 index 0000000000000..1b0a3a561feac --- /dev/null +++ b/gdb-xml/tricore.xml @@ -0,0 +1,13 @@ + + + + + + tricore + + + From 727f9b9792e21a0fc7aa041514379543c336d8d3 Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 23 Oct 2025 16:33:16 +0800 Subject: [PATCH 05/12] update bap-frames submodule URL and commit reference --- .gitmodules | 2 +- contrib/plugins/bap-tracing/bap-frames | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index ab35905da9460..f86c1e687d2d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -45,5 +45,5 @@ url = https://gitlab.com/libvirt/libvirt-ci.git [submodule "contrib/plugins/bap-tracing/bap-frames"] path = contrib/plugins/bap-tracing/bap-frames - url = https://github.com/b1llow/bap-frames.git + url = https://github.com/BinaryAnalysisPlatform/bap-frames.git branch = tricore-support diff --git a/contrib/plugins/bap-tracing/bap-frames b/contrib/plugins/bap-tracing/bap-frames index 821c2b6cd044c..de612ffce48cb 160000 --- a/contrib/plugins/bap-tracing/bap-frames +++ b/contrib/plugins/bap-tracing/bap-frames @@ -1 +1 @@ -Subproject commit 821c2b6cd044c5dff72077bc6812e8bd16491465 +Subproject commit de612ffce48cb93f7a462f8b0ab28f2884adec0b From b8fcd61ab27a845c14df054bfbbe310316f392be Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 23 Oct 2025 16:34:49 +0800 Subject: [PATCH 06/12] remove branch specification for bap-frames submodule --- .gitmodules | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index f86c1e687d2d1..5998c94376a00 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,4 +46,3 @@ [submodule "contrib/plugins/bap-tracing/bap-frames"] path = contrib/plugins/bap-tracing/bap-frames url = https://github.com/BinaryAnalysisPlatform/bap-frames.git - branch = tricore-support From 4788cb60c9ab69a3fd2d2cf5394a3a05c7c23e06 Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 23 Oct 2025 22:40:01 +0800 Subject: [PATCH 07/12] Update configs/targets/tricore-softmmu.mak Co-authored-by: Rot127 <45763064+Rot127@users.noreply.github.com> --- configs/targets/tricore-softmmu.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/targets/tricore-softmmu.mak b/configs/targets/tricore-softmmu.mak index 37357e1374949..dee80251e43f4 100644 --- a/configs/targets/tricore-softmmu.mak +++ b/configs/targets/tricore-softmmu.mak @@ -1,3 +1,3 @@ TARGET_ARCH=tricore TARGET_LONG_BITS=32 -TARGET_XML_FILES= gdb-xml/tricore-core.xml +TARGET_XML_FILES=gdb-xml/tricore-core.xml From 967f2cd3d71c4c687915502fa56a7f9b0a042c04 Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 23 Oct 2025 23:02:53 +0800 Subject: [PATCH 08/12] Fix plugin exit message and document flush_all_frame_bufs() issue --- contrib/plugins/bap-tracing/tracing.c | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/contrib/plugins/bap-tracing/tracing.c b/contrib/plugins/bap-tracing/tracing.c index 1a5398d3a2360..a14956a708c33 100644 --- a/contrib/plugins/bap-tracing/tracing.c +++ b/contrib/plugins/bap-tracing/tracing.c @@ -339,7 +339,36 @@ static void cb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { } static void plugin_exit(qemu_plugin_id_t id, void *udata) { - qemu_plugin_outs("Exiting plugin, flushing data...\n"); + qemu_plugin_outs("Exiting bap-tracing plugin\n"); + /** + * FIXME: flush_all_frame_bufs() is currently commented out due to an + * assertion failure in qemu_plugin_get_registers when used in the plugin + * exit callback. + * + * Root cause: When the plugin exits, current_cpu has already been set to + * NULL by QEMU's shutdown sequence. However, flush_all_frame_bufs() calls + * qemu_plugin_get_registers() (via add_post_reg_state()) to capture the + * final register state, which internally asserts that current_cpu is + * non-NULL. This causes the assertion to fail. + * + * This issue is specific to the TriCore architecture tracing but may affect + * other architectures as well. + * + * Potential drawbacks of commenting out this call: + * 1. The last few instruction frames in each vCPU's buffer may not be + * written to the trace file, resulting in incomplete traces. + * 2. Post-execution register states for the final instructions will not + * be captured, potentially losing important state information. + * 3. If the frame buffers have accumulated data that hasn't reached the + * flush threshold, that data will be lost entirely. + * + * Possible solutions: + * - Modify QEMU to allow qemu_plugin_get_registers() to gracefully handle + * NULL current_cpu during shutdown + * - Add a pre-exit flush mechanism that runs before current_cpu is cleared + * - Skip register state capture in flush_all_frame_bufs() when called from + * plugin_exit, flushing only the instruction frames without post-state + */ // flush_all_frame_bufs(); g_rw_lock_writer_lock(&state.file_lock); From 73b327fef70fcdfe36a084fb9d12f7c058609a0b Mon Sep 17 00:00:00 2001 From: billow Date: Thu, 23 Oct 2025 23:07:04 +0800 Subject: [PATCH 09/12] Update tricore-core.xml to include additional special registers and enhance documentation --- gdb-xml/tricore-core.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gdb-xml/tricore-core.xml b/gdb-xml/tricore-core.xml index 48f2a54324d1d..1ce0276d5d33a 100644 --- a/gdb-xml/tricore-core.xml +++ b/gdb-xml/tricore-core.xml @@ -1,4 +1,10 @@ + + +