I have a cursor that's pointing to a function call for which the prototype is declared inside an included header file. I want to get the location for such declaration, but as can be seen in the gdb output bellow, after getting the type for the function call, getting the cursor for the declaration type is failing, how to get it right?

(gdb) n
66      CXType mickey_type = clang_getCursorType(mickey_cursor);
(gdb) n
67      CXCursor mickey_decl_cursor = clang_getTypeDeclaration(mickey_type);
(gdb) n
68      CXSourceLocation mickey_decl_location = clang_getCursorLocation(mickey_decl_cursor);
(gdb) p mickey_type 
$1 = {
  kind = CXType_FunctionProto, 
  data = {0x102826cb0, 0x100a03d90}
}
(gdb) print mickey_decl_cursor 
$2 = {
  kind = CXCursor_NoDeclFound, 
  xdata = 0, 
  data = {0x0, 0x0, 0x0}
}
(gdb) q

Here's all the relevant source code:

有帮助吗?

解决方案

bah, my bad, I should have used clang_getCursorReferenced instead... there's no location for the declaration of the function's type! I must look for the function declaration.

Fixed Code

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top