[PATCH] D60489: [LLVM-C] Add DIFile Field Accesssors
Josh Berdine via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 14 14:00:06 PDT 2019
jberdine added a comment.
@CodaFi thanks! For Instructions, I have modified my client to use these functions and tested. For reference, the callers look like:
CAMLprim value llvm_instr_get_debug_loc_filename(LLVMValueRef Instr) {
CAMLparam0();
CAMLlocal2(Option, String);
LLVMMetadataRef Loc = LLVMInstructionGetDebugLoc(Instr);
if (!Loc) CAMLreturn(Val_int(0));
LLVMMetadataRef Scope = LLVMDILocationGetScope(Loc);
if (!Scope) CAMLreturn(Val_int(0));
LLVMMetadataRef File = LLVMDIScopeGetFile(Scope);
if (!File) CAMLreturn(Val_int(0));
unsigned Length;
const char *Chars;
if ((Chars = LLVMDIFileGetFilename(File, &Length))) {
String = caml_alloc_string(Length);
memcpy(String_val(String), Chars, Length);
Option = caml_alloc_small(1, 0);
Store_field(Option, 0, String);
CAMLreturn(Option);
}
CAMLreturn(Val_int(0));
}
So for instructions, it seems to work well to use LLVMInstructionGetDebugLoc and then LLVMDILocationGetLine, LLVMDILocationGetColumn, LLVMDILocationGetScope and this diff's functions.
But so far I have not found analogues of LLVMInstructionGetDebugLoc for GlobalVariables and Functions. To be concrete, the function extracting the line number I'm using is:
unsigned LLVMGetDebugLocLine(LLVMValueRef Val) {
unsigned L = 0;
if (const auto *I = dyn_cast<Instruction>(unwrap(Val))) {
if (const auto &DL = I->getDebugLoc()) {
L = DL->getLine();
}
} else if (const auto *GV = dyn_cast<GlobalVariable>(unwrap(Val))) {
SmallVector<DIGlobalVariableExpression *, 1> GVEs;
GV->getDebugInfo(GVEs);
if (GVEs.size())
if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
L = DGV->getLine();
} else if (const auto *F = dyn_cast<Function>(unwrap(Val))) {
if (const DISubprogram *DSP = F->getSubprogram())
L = DSP->getLine();
} else {
assert(0 && "Expected Instruction, GlobalVariable or Function");
return -1;
}
return L;
}
Am I overlooking something, or is exposing more needed to cover what the above is doing on GlobalVariables and Functions?
================
Comment at: llvm/include/llvm-c/DebugInfo.h:464
+ * Get the directory of a given file.
+ * \param Scope The file object.
+ * \param Len The length of the returned string.
----------------
s/Scope/File ?
================
Comment at: llvm/include/llvm-c/DebugInfo.h:473
+ * Get the name of a given file.
+ * \param Scope The file object.
+ * \param Len The length of the returned string.
----------------
s/Scope/File ?
================
Comment at: llvm/include/llvm-c/DebugInfo.h:482
+ * Get the source of a given file.
+ * \param Scope The file object.
+ * \param Len The length of the returned string.
----------------
s/Scope/File ?
================
Comment at: llvm/lib/IR/DebugInfo.cpp:913
+const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
+ auto Dir = unwrapDI<DIFile>(File)->getFilename();
+ *Len = Dir.size();
----------------
Dir ?
================
Comment at: llvm/lib/IR/DebugInfo.cpp:919
+const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
+ if (auto Dir = unwrapDI<DIFile>(File)->getSource()) {
+ *Len = Dir->size();
----------------
Dir ?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60489/new/
https://reviews.llvm.org/D60489
More information about the llvm-commits
mailing list