Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ enum {
*/
typedef unsigned LLVMGEPNoWrapFlags;

typedef enum {
LLVMDbgRecordLabel,
LLVMDbgRecordDeclare,
LLVMDbgRecordValue,
LLVMDbgRecordAssign,
} LLVMDbgRecordKind;

/**
* @}
*/
Expand Down Expand Up @@ -3896,6 +3903,37 @@ LLVM_C_ABI LLVMDbgRecordRef LLVMGetNextDbgRecord(LLVMDbgRecordRef DbgRecord);
LLVM_C_ABI LLVMDbgRecordRef
LLVMGetPreviousDbgRecord(LLVMDbgRecordRef DbgRecord);

/**
* Get the debug location attached to the debug record.
*
* @see llvm::DbgRecord::getDebugLoc()
*/
LLVMMetadataRef LLVMDbgRecordGetDebugLoc(LLVMDbgRecordRef Rec);

LLVMDbgRecordKind LLVMDbgRecordGetKind(LLVMDbgRecordRef Rec);

/**
* Get the value of the DbgVariableRecord.
*
* @see llvm::DbgVariableRecord::getValue()
*/
LLVMValueRef LLVMDbgVariableRecordGetValue(LLVMDbgRecordRef Rec,
unsigned OpIdx);

/**
* Get the debug info variable of the DbgVariableRecord.
*
* @see llvm::DbgVariableRecord::getVariable()
*/
LLVMMetadataRef LLVMDbgVariableRecordGetVariable(LLVMDbgRecordRef Rec);

/**
* Get the debug info expression of the DbgVariableRecord.
*
* @see llvm::DbgVariableRecord::getExpression()
*/
LLVMMetadataRef LLVMDbgVariableRecordGetExpression(LLVMDbgRecordRef Rec);

/**
* @defgroup LLVMCCoreValueInstructionCall Call Sites and Invocations
*
Expand Down
31 changes: 31 additions & 0 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,37 @@ LLVMDbgRecordRef LLVMGetPreviousDbgRecord(LLVMDbgRecordRef Rec) {
return wrap(&*--I);
}

LLVMMetadataRef LLVMDbgRecordGetDebugLoc(LLVMDbgRecordRef Rec) {
return wrap(unwrap<DbgRecord>(Rec)->getDebugLoc().getAsMDNode());
}

LLVMDbgRecordKind LLVMDbgRecordGetKind(LLVMDbgRecordRef Rec) {
DbgRecord *Record = unwrap<DbgRecord>(Rec);
if (isa<DbgLabelRecord>(Record))
return LLVMDbgRecordLabel;
DbgVariableRecord *VariableRecord = dyn_cast<DbgVariableRecord>(Record);
assert(VariableRecord && "unexpected record");
if (VariableRecord->isDbgDeclare())
return LLVMDbgRecordDeclare;
if (VariableRecord->isDbgValue())
return LLVMDbgRecordValue;
assert(VariableRecord->isDbgAssign() && "unexpected record");
return LLVMDbgRecordAssign;
}

LLVMValueRef LLVMDbgVariableRecordGetValue(LLVMDbgRecordRef Rec,
unsigned OpIdx) {
return wrap(unwrap<DbgVariableRecord>(Rec)->getValue(OpIdx));
}

LLVMMetadataRef LLVMDbgVariableRecordGetVariable(LLVMDbgRecordRef Rec) {
return wrap(unwrap<DbgVariableRecord>(Rec)->getRawVariable());
}

LLVMMetadataRef LLVMDbgVariableRecordGetExpression(LLVMDbgRecordRef Rec) {
return wrap(unwrap<DbgVariableRecord>(Rec)->getRawExpression());
}

unsigned LLVMGetNumArgOperands(LLVMValueRef Instr) {
if (FuncletPadInst *FPI = dyn_cast<FuncletPadInst>(unwrap(Instr))) {
return FPI->arg_size();
Expand Down
30 changes: 30 additions & 0 deletions llvm/tools/llvm-c-test/debuginfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,36 @@ int llvm_test_dibuilder(void) {
assert(AddDbgRecordUnderTheRange == NULL);
(void)AddDbgRecordUnderTheRange;

// Test that we can read the first debug record.
LLVMMetadataRef AddDbgRecordFirstDebugLoc =
LLVMDbgRecordGetDebugLoc(AddDbgRecordFirst);
assert(LLVMDILocationGetLine(AddDbgRecordFirstDebugLoc) == 43);
assert(LLVMDbgRecordGetKind(AddDbgRecordFirst) == LLVMDbgRecordValue);
LLVMValueRef AddDbgRecordFirstValue =
LLVMDbgVariableRecordGetValue(AddDbgRecordFirst, 0);
assert(LLVMGetValueKind(AddDbgRecordFirstValue) == LLVMConstantIntValueKind);
assert(LLVMConstIntGetZExtValue(AddDbgRecordFirstValue) == 0);
LLVMMetadataRef AddDbgRecordFirstVariable =
LLVMDbgVariableRecordGetVariable(AddDbgRecordFirst);
assert(LLVMGetMetadataKind(AddDbgRecordFirstVariable) ==
LLVMDILocalVariableMetadataKind);
// TODO: For now, there is no way to get the name.
LLVMMetadataRef AddDbgRecordFirstVariableScope =
LLVMDIVariableGetScope(AddDbgRecordFirstVariable);
assert(LLVMGetMetadataKind(AddDbgRecordFirstVariableScope) ==
LLVMDILexicalBlockMetadataKind);
LLVMMetadataRef AddDbgRecordFirstVariableFile =
LLVMDIScopeGetFile(AddDbgRecordFirstVariableScope);
assert(LLVMGetMetadataKind(AddDbgRecordFirstVariableFile) ==
LLVMDIFileMetadataKind);
unsigned FileLen = 0;
assert(strcmp(LLVMDIFileGetFilename(AddDbgRecordFirstVariableFile, &FileLen),
"debuginfo.c") == 0);
LLVMMetadataRef AddDbgRecordFirstExpr =
LLVMDbgVariableRecordGetExpression(AddDbgRecordFirst);
assert(LLVMGetMetadataKind(AddDbgRecordFirstExpr) ==
LLVMDIExpressionMetadataKind);

char *MStr = LLVMPrintModuleToString(M);
puts(MStr);
LLVMDisposeMessage(MStr);
Expand Down