gpt4 book ai didi

c - 如何通过 LLVM C 绑定(bind)发出调试信息?

转载 作者:行者123 更新时间:2023-11-29 07:42:53 25 4
gpt4 key购买 nike

我目前正在研究一个用 Rust 编写的简单 LLVM 前端。我现在正在尝试发出调试信息。

如何通过 C 绑定(bind)发出此调试信息(源位置和变量)?有可能吗?我需要编写 C++ 包装器吗?

似乎有一个用于插入源位置的函数 (LLVMSetCurrentDebugLocation; LLVM ; Rust ),但我不知道如何构造一个包含此信息的正确 LLVMValue。我想它需要某种元数据。

最佳答案

参见 DebugInfo.h用于从 C++ LLVM 调试信息 API 到 C 绑定(bind)的映射。您需要的示例是:

  • 新的 DIBuilder -> LLVMCreateDIBuilder()
  • DIBuilder::createFile() -> LLVMDIBuilderCreateFile()
  • DIBuilder::createCompileUnit() -> LLVMDIBuilderCreateCompileUnit()
  • DIBuilder::createBasicType() -> LLVMDIBuilderCreateBasicType()

(使用这些函数为您的编译器设置 dwarf 上下文)

您提到的 LLVMSetCurrentDebugLocation() 函数相当于 IRBuilder<>::SetCurrentDebugLocation()

对于每个调试表达式,您需要一个调试位置和表达式的 DWARF 元数据。这是像下面这样完成的(C++ 片段):

auto loc_glc = DebugLoc::get( line, column, dwFunc );
m_dwBuilder->insertDeclare( r, dwVar_gr, m_dwBuilder->createExpression(), loc_glc, fooBB );
m_builder.SetCurrentDebugLocation( loc_glc );

您需要将调试位置与 DWARF 表达式相关联,然后使用 LLVMSetCurrentDebugLocation() 将其“锚定”到您的 IRBuilder。

关于c - 如何通过 LLVM C 绑定(bind)发出调试信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47893551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com