作者投稿和查稿 主编审稿 专家审稿 编委审稿 远程编辑

计算机工程 ›› 2026, Vol. 52 ›› Issue (8): 184-192. doi: 10.19678/j.issn.1000-3428.0070725

• 体系结构与先进计算 • 上一篇    下一篇

基于QEMU的龙架构平台插桩软件

高林萍1,*(), 徐伟2, 陈曦1, 穆奕博1, 张开1   

  1. 1. 中国科学技术大学先进技术研究院, 安徽 合肥 230026
    2. 中国科学技术大学计算机科学与技术学院, 安徽 合肥 230026
  • 收稿日期:2024-12-19 修回日期:2025-03-17 出版日期:2026-08-15 发布日期:2025-05-22
  • 通讯作者: 高林萍
  • 作者简介:

    高林萍, 女, 硕士, 主研方向为二进制翻译、编译优化

    徐伟, 高级实验师、博士

    陈曦, 硕士研究生

    穆奕博, 硕士研究生

    张开, 博士研究生

  • 基金资助:
    中国科学院基础与交叉前沿科研B类先导专项(XDB0660000)

An Instrumentation Software for LoongArch Based on QEMU

GAO Linping1,*(), XU Wei2, CHEN Xi1, MU Yibo1, ZHANG Kai1   

  1. 1. Institute of Advanced Technology, University of Science and Technology of China, Hefei 230026, Anhui, China
    2. School of Computer Science and Technology, University of Science and Technology of China, Hefei 230026, Anhui, China
  • Received:2024-12-19 Revised:2025-03-17 Online:2026-08-15 Published:2025-05-22
  • Contact: GAO Linping

摘要:

随着软件规模和复杂性指数级增长, 对程序运行时行为的监控和分析变得越来越困难, 动态二进制插桩(DBI)技术是解决这一问题的有效手段, 现有成熟的二进制插桩软件有Pin、Valgrind等, 主要支持x86、ARM等主流架构, 但在新兴的自主指令集架构上缺乏支持。龙架构(LoongArch)作为我国自主研制的指令集架构, 具有较好的自主性、先进性与兼容性, 但其发展时间较短, 生态环境尚不完善, 特别是在调试工具链方面存在明显短板。为了填补这一空白, 推动龙架构生态的成熟, 推出一款支持龙架构的DBI软件具有重要意义。本文旨在设计并实现一款基于QEMU(Quick Emulator)框架的DBI软件, 以支持龙架构的程序监控与分析。该软件对标Pin, 设计实现了5个基础插桩粒度及相关插桩应用程序编程接口(API), 并在此基础上开发了20多个插桩工具, 供用户直接使用或学习插桩工具的编写。为了提升框架性能, 通过优化条件跳转指令的翻译、基本块链接和插桩内联等方法对框架进行了改进。性能测试结果表明, 优化后的框架在指令级插桩效率上提升了100多倍, 基本块级插桩效率提高了近33倍。

关键词: 动态二进制插桩, Pin, 龙架构, QEMU框架, 插桩应用程序编程接口, 插桩工具

Abstract:

As software scale and complexity grow exponentially, monitoring and analyzing program runtime behavior has become increasingly challenging. Dynamic Binary Instrumentation (DBI) is an effective solution to this problem, with mature tools such as Pin and Valgrind supporting mainstream architectures such as x86 and ARM. However, these tools lack support for emerging domestic instruction set architectures such as LoongArch. LoongArch, a self-developed instruction-set architecture in China, exhibits high levels of autonomy, advancement, and compatibility. However, owing to its relatively short developmental history, the ecosystem remains incomplete, particularly in the debugging toolchain. Developing a dynamic binary instrumentation tool is important to address this gap and promote the maturation of the LoongArch ecosystem. This study aims to design and implement a dynamic binary instrumentation tool based on the Quick Emulator (QEMU) framework to support program monitoring and analysis in LoongArch. The tool, modeled after Pin, implements five fundamental instrumentation granularities and related Application Programming Interfaces (APIs), along with over 20 instrumentation tools for direct use or as learning resources for tool development. To enhance performance, the framework is optimized through improvements in conditional jump instruction translation, basic block linking, and instrumentation inlining. Performance tests demonstrate that the optimized framework achieves improvement of over 100 times in instruction-level instrumentation efficiency and nearly 33 times in basic block-level instrumentation efficiency.

Key words: Dynamic Binary Instrumentation (DBI), Pin, LoongArch, Quick Emulator (QEMU) framework, instrumentation Application Programming Interface (API), instrumentation tool