获取LLVM-IR

时间:2017-03-14 15:46:06

标签: llvm llvm-ir

我想在IR中打印确切的调试信息号,我该怎么办?

例如,考虑如下的IR块,

call void @llvm.dbg.declare(metadata i32* %a, metadata !10, metadata !11), !dbg !12!
!12 = !DILocation(line: 19, column: 7, scope: !6)

我想将!12打印为字符串以进行调试。我可以通过

获取DILocation的对象
Instruction::getDebugLoc()->get()

但我得到的只是一个指针,没有这样的接口来获取数字。我可以假设LLVM在实际生成bitcode时给出了数字,因为转储DILocation会产生类似

的结果。
<0x7342628> = !DILocation(line: 23, column: 3, scope: <0x733e5f8>)

此。但是当我使用Instruction :: dump()时,它给了我一些看起来像

的东西
call void @llvm.dbg.declare(metadata i32* %a, metadata !10, metadata !11), !dbg !12

这个,所以我很困惑它是否在运行期间有调试信息的编号信息。

是否有编号信息?如果是这样,我如何获得该信息?如果没有,我应该在哪里检查以查找LLVM中bitcode的生成?

2 个答案:

答案 0 :(得分:2)

您在谈论行/列号吗?如果是这样,那么您可以直接从debugLoc

轻松访问它们
instruction->getDebugLoc()->getLine()
instruction->getDebugLoc()->getColumn()

请参阅DebugInfoMetadata的定义:

unsigned getLine() const { return SubclassData32; }
unsigned getColumn() const { return SubclassData16; }

答案 1 :(得分:2)

回答这个问题可能为时不晚。

Private Sub sendacdcsched_Click()
'sends an email with a calendar appointment for the facility schedule.

    DoCmd.Save 'saves the record first

    Dim OutlookApp As Object
    Dim Outlookmessage As Object
    Dim scheduleACDC As String
    Dim OLNamespace As Object
    Dim OLFolder As Object

    scheduleACDC = "Schedule for ACDC for " & Me.schedDate.Value

    'Create Instance of Outlook
    On Error Resume Next

    Set OutlookApp = GetObject(Class:="Outlook.Application") 'Handles if Outlook is already open
    Err.Clear
    If OutlookApp Is Nothing Then Set OutlookApp = CreateObject(Class:="Outlook.Application") 'If not, open Outlook
    On Error GoTo 0

    Set OLNamespace = OutlookApp.getnamespace("MAPI")
    Set OLFolder = OLNamespace.Folders.Item("name@address.office.com")

    'Create a new email message
    Set Outlookmessage = OLFolder.items.Add(1)

    'Create Outlook email with attachment
    On Error Resume Next
    With Outlookmessage
        .meetingstatus = 1 'makes it a meeting so you can add recipients
        .start = Me.schedDate & " 8:00:00 AM"
        .duration = 240 'in minutes
        .To = ""  'Insert all emails addresses to be sent to here'
        .subject = "ACDC"  'email subject line'
        .Body = scheduleACDC
        .Display 'displays email before you send it. If you wish to send without seeing it displayed use .send'
    End With

    On Error GoTo 0
End Sub

输出是:

if (instruction->hasMetadata()) {
  instruction->dump();

  // one way
  SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
  instruction->getAllMetadata(MDs);
  for (auto &MD : MDs) {
    if (MDNode *N = MD.second) {
      N->printAsOperand(errs(), instruction->getModule());
      errs() << "\n";
    }
  }

  // second way
  instruction->getDebugLoc()->printAsOperand(errs(), instruction->getModule());
  errs() << "\n";

  // third way
  int debugInfoKindID = 0;
  MDNode *debug = instruction->getMetadata(debugInfoKindID);
  debug->printAsOperand(errs(), instruction->getModule());
  errs() << "\n";
}

我通过查看%11 = add nsw i32 %9, %10, !dbg !29 !29 !29 !29 ,其测试llvm//unittests/IR/MetadataTest.cpp找到了这个。