llvm::DIInstruction getFilename returns filename with a directory, I just want the filename

I'm trying to get debugging metadata from an llvm Instruction using the DILocation class.

However, when I query the DILocation for the filename where the instruction came from, I get a filename with a directory tagged onto the front.

I though it would return just the file and the entire directory path should be retrieved via a call to getDirectory().

For example, instead of XMain_0.c I end up with pbg/XMain_0.c

I compiled my bitcode like this:

XMain_0.o: pbg/XMain_0.c $(CC) <snip> -c pbg/XMain_0.c

Does the fact that I passed in my source with a directory on it mean that the metadata saves the source filename as the input?

Here's a cut down example:

const llvm::Instruction* inst //passed in MDNode *n = inst->getMetadata("dbg"); DILocation loc(n); file = loc.getFilename().str(); // => pbg/XMain_0.c dir = loc.getDirectory().str(); // => /projects/pbg/pbg-m/DIR

Are there calls I can make to "normalize" this data or do I need to do it by hand?

Clang 3.1 if that matters.


I think it depends on the invocation of the compiler. If you run:

clang -c somedir/somefile.c

Then the full somedir/somefile.c will be the filename.

How does your invocation look like?


There is nothing weird about it. The debugger will look for source files relative to some project root, and if you compile files likes this, it's the way they are going to be found. gcc does the same thing:

/tmp$ pwd /tmp /tmp$ cat subdir/test.c int foo() { return 42; } /tmp$ gcc -g -O0 -c subdir/test.c -o test.o /tmp$ readelf --debug-dump=info test.o | grep -A4 compile_unit <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) <c> DW_AT_producer : (indirect string, offset: 0x0): GNU C 4.6.3 <10> DW_AT_language : 1 (ANSI C) <11> DW_AT_name : (indirect string, offset: 0xc): subdir/test.c <15> DW_AT_comp_dir : (indirect string, offset: 0x1a): /tmp


  • jquery datepicker onselect not working
  • Chrome extension file upload browse window position off screen
  • Programmatically center text output in for loop
  • Prevent floating DIVs from overlapping footer
  • Tests with generic classes crash since swift 2.2
  • C++ NetBeans Run-Configuration passing arguments-issue
  • objective-c MPMoviePlayerViewController done button language
  • Save pictures to custom folder in media library
  • Use function defined in one cpp file in function defined in another cpp file in Rcpp
  • Will jQuery ever leverage HTML5 technologies?
  • Binding ContextMenu Tag to Owner
  • Changing Entity's State in Entity Framework 4.1
  • How can I get process name of specific PID with ps command in alpine
  • Keep Sql Connection open for iterating many requests? Or close each step?
  • Connection pooling with URLConnection?
  • richtextbox to string
  • C: Incompatible pointer type initializing
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Counter field in MS Access, how to generate?
  • AES padding and writing the ciphertext to a disk file
  • VS2008 Enable C++ Exception with SEH
  • Javascript + PHP Encryption with pidCrypt
  • what is the difference between the asp.net mvc application and asp.net web application
  • Websockets service method fails during R startup
  • Apache 2.4 - remove | delete | uninstall
  • Matrix multiplication with MKL
  • Proper way to use connect-multiparty with express.js?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Trying to get generic when generic is not available
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal