<div dir="ltr"><div><div><div>This could get a little bit tricky due to Address Space Layout Randomization (ASLR). llvm-symbolizer is able to map an address to file:line:offset, but only if the address given to it matches what is in the ELF file to begin with.<br><br></div>ASLR introduces randomness into the upper address bits, which makes this impossible unless you can filter it out.<br><br></div>If you are using the Linux dladdr function in the process of getting a backtrace, then it provides the base address of whatever segment the queried function is in. (This is true at least for shared libraries; I'm not sure if it is also true for those parts of the program that are not in a shared library.) Subtracting the base address of the library from the address in question will give you the offset into the library, which is the address that llvm-symbolizer really wants.<br><br>    if (dladdr(addr, &info)) {<br>        // addr - info.dli_fbase is address that must be passed to llvm-symbolizer<br>        string          so_name = info.dli_fname;<br>        intptr_t        offset = (char*)addr - (char*)info.dli_fbase;<br><br></div>        // invoke llvm-symbolizer with so_name and offset<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 9:34 AM, Nathan Schagen via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi LLVM people,<div><br></div><div>I would like the llvm-symbolizer to resolve both function names and line/column numbers for me. The latter does not seem to work. </div><div><br></div><div> I'm using the Memory Sanitizer example with LLVM 3.3. This is what I did:</div><div><br></div><div><div>➜  msan_test cat test.c</div><div>#include <stdio.h></div><div><br></div><div>int main(int argc, char** argv) {</div><div>  int a[10];</div><div>  a[5] = 0;</div><div>  if (a[argc])</div><div>    printf("xx\n");</div><div>  return 0;</div><div>}</div><div>➜  msan_test clang -fsanitize=memory -fno-omit-frame-pointer -g -O2 -o test test.c</div><div>➜  msan_test ./test</div><div>==9547== WARNING: Use of uninitialized value</div><div>    #0 0x55ea59c9c476 (/home/nathan/test/c/msan_test/test+0x25476)</div><div>    #1 0x7fbdfc187a3f (/lib/x86_64-linux-gnu/libc.so.6+0x20a3f)</div><div>    #2 0x55ea59c9c2a8 (/home/nathan/test/c/msan_test/test+0x252a8)</div><div>Exiting</div><div><br></div><div>Copied file/offset pairs into report.txt. I am aware of MSAN_SYMBOLIZER_PATH.</div><div><br></div><div>➜  msan_test cat report.txt </div><div>/home/nathan/test/c/msan_test/test 0x25476</div><div>/lib/x86_64-linux-gnu/libc.so.6 0x20a3f</div><div>/home/nathan/test/c/msan_test/test 0x252a8</div><div>➜  msan_test llvm-symbolizer < report.txt</div><div>main</div><div>??:0:0</div><div><br></div><div>??</div><div>??:0:0</div><div><br></div><div>_start</div><div>??:0:0</div><div><br></div><div>➜  msan_test</div></div><div><br></div><div>It's unclear to me why no line numbers show up. This is what readelf has to say:</div><div><br></div><div><div>➜  msan_test readelf -WS test | egrep '\.(stab|debug)'</div><div>  [28] .debug_info       PROGBITS        0000000000000000 02ec10 040d9e 00      0   0  1</div><div>  [29] .debug_abbrev     PROGBITS        0000000000000000 06f9ae 006943 00      0   0  1</div><div>  [30] .debug_loc        PROGBITS        0000000000000000 0762f1 0637d3 00      0   0  1</div><div>  [31] .debug_aranges    PROGBITS        0000000000000000 0d9ac4 000570 00      0   0  1</div><div>  [32] .debug_ranges     PROGBITS        0000000000000000 0da034 014fe0 00      0   0  1</div><div>  [33] .debug_line       PROGBITS        0000000000000000 0ef014 0091de 00      0   0  1</div><div>  [34] .debug_str        PROGBITS        0000000000000000 0f81f2 010e90 01  MS  0   0  1</div><div>  [36] .debug_macinfo    PROGBITS        0000000000000000 1090cd 000000 00      0   0  1</div><div>  [37] .debug_pubtypes   PROGBITS        0000000000000000 1090cd 000000 00      0   0  1</div></div><div><br></div><div>Can someone point me in the right direction?</div><div><br></div><div>Thanks in advance!</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>