I have an LLVM pass that iterates over LLVM IR code and I would like to get a directory and a filename for both the functions and basic blocks for the original code. I know that when I have an Instruction Pointer, I can easily get the information using the code below: Thanks to @hailinzeng 
([How to get the filename and directory from a LLVM Instruction?](https://stackoverflow.com/questions/43503804/how-to-get-the-filename-and-directory-from-a-llvm-instruction))

```
const llvm::DebugLoc &location = i_iter->getDebugLoc();

if (location && debugLocationInfoOn) {
  std::string dbgInfo;
  llvm::raw_string_ostream rso(dbgInfo);
  location.print(rso);
  std::cout << rso.str();
}

```

However, since the class `Function` and `BasicBlock` do not have a member function `getDebugLoc()`, this doesn't work. I saw another post [here](https://stackoverflow.com/questions/14166004/llvmdiinstruction-getfilename-returns-filename-with-a-directory-i-just-want-t) using the metadata but I do not know how to get to the `DILocation` or `DIScope` from the metadata. Using 

```
MDNode *n = inst->getMetadata("dbg");
DILocation loc(n);   `

```

Gives the error below

> 
> /usr/lib/llvm-3.9/include/llvm/IR/Metadata.def:83:42: note: forward declaration of 'llvm::DILocation'
>  HANDLE\_SPECIALIZED\_MDNODE\_LEAF\_UNIQUABLE(DILocation)
> 
> 
> 

I'm using llvm 3.9. 

UPDATE ::
Thanks Stanislav Pankevich. I wasn't including the right headers but now I have a new issue. DILocation requires LLVMContext, StorageType, and unsigned Line. How do I get the line number and and storage type from a function pointer?
 `DILocation(LLVMContext &C, StorageType Storage, unsigned Line,`

For those working with a similar issue, you can get LLVMContext using

```
llvm::MDNode * testmd = F.getMetadata("dbg");
F.getContext ()

```