<div class="gmail_quote">On Tue, Jul 3, 2012 at 1:40 PM, Alexander Potapenko <span dir="ltr"><<a href="mailto:glider@google.com" target="_blank">glider@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I believe this broke the ASan buildbot:<br></blockquote><div><br></div><div>Yeah, r159655 should fix that.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
  COMPILE:   clang_darwin/asan_osx/i386:<br>
/Users/buildbot/src/llvm-buildbot/slave/mac10.6/build/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc<br>
/Users/buildbot/src/llvm-buildbot/slave/mac10.6/build/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc:119:1:<br>
error: control may reach end of non-void function<br>
[-Werror,-Wreturn-type]<br>
};<br>
<br>
On Tue, Jul 3, 2012 at 12:24 PM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br>
> Author: samsonov<br>
> Date: Tue Jul  3 03:24:14 2012<br>
> New Revision: 159652<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=159652&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=159652&view=rev</a><br>
> Log:<br>
> [Sanitizer] Extend a symbolizer code. Implemented for Linux only. Use dl_iterate_phdr to get virtual addresses of mapped module sections. To symbolize an address from a module, map this module to memory and obtain pointers to debug info sections. Later these pointers can be passed to constructor of DWARF context-in-memory from LLVM DebugInfo lib.<br>

><br>
> Modified:<br>
>     compiler-rt/trunk/lib/asan/asan_stack.cc<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
>     compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/asan_stack.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/asan_stack.cc (original)<br>
> +++ compiler-rt/trunk/lib/asan/asan_stack.cc Tue Jul  3 03:24:14 2012<br>
> @@ -46,14 +46,20 @@<br>
>      AddressInfo addr_frames[64];<br>
>      uptr addr_frames_num = 0;<br>
>      if (FLAG_symbolize) {<br>
> -      addr_frames_num = SymbolizeCode(pc, addr_frames,<br>
> +      bool last_frame = (i == size - 1) || !addr[i + 1];<br>
> +      addr_frames_num = SymbolizeCode(pc - !last_frame, addr_frames,<br>
>                                        ASAN_ARRAY_SIZE(addr_frames));<br>
>      }<br>
>      if (addr_frames_num > 0) {<br>
>        for (uptr j = 0; j < addr_frames_num; j++) {<br>
>          AddressInfo &info = addr_frames[j];<br>
>          AsanPrintf("    #%zu 0x%zx", frame_num, pc);<br>
> -        if (info.module) {<br>
> +        if (info.function) {<br>
> +          AsanPrintf(" %s", info.function);<br>
> +        }<br>
> +        if (info.file) {<br>
> +          AsanPrintf(" %s:%d:%d", info.file, info.line, info.column);<br>
> +        } else if (info.module) {<br>
>            AsanPrintf(" (%s+0x%zx)", info.module, info.module_offset);<br>
>          }<br>
>          AsanPrintf("\n");<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Jul  3 03:24:14 2012<br>
> @@ -64,6 +64,11 @@<br>
>  // Returns the number of read bytes or 0 if file can not be opened.<br>
>  uptr ReadFileToBuffer(const char *file_name, char **buff,<br>
>                        uptr *buff_size, uptr max_len);<br>
> +// Maps given file to virtual memory, and returns pointer to it<br>
> +// (or NULL if the mapping failes). Stores the size of mmaped region<br>
> +// in '*buff_size'.<br>
> +void *MapFileToMemory(const char *file_name, uptr *buff_size);<br>
> +<br>
>  const char *GetEnv(const char *name);<br>
>  const char *GetPwd();<br>
><br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Tue Jul  3 03:24:14 2012<br>
> @@ -16,9 +16,13 @@<br>
>  #include "sanitizer_common.h"<br>
>  #include "sanitizer_internal_defs.h"<br>
>  #include "sanitizer_libc.h"<br>
> +#include "sanitizer_placement_new.h"<br>
>  #include "sanitizer_procmaps.h"<br>
> +#include "sanitizer_symbolizer.h"<br>
><br>
> +#include <elf.h><br>
>  #include <fcntl.h><br>
> +#include <link.h><br>
>  #include <pthread.h><br>
>  #include <sched.h><br>
>  #include <sys/mman.h><br>
> @@ -63,9 +67,15 @@<br>
>  }<br>
><br>
>  uptr internal_filesize(fd_t fd) {<br>
> -  struct stat st = {};<br>
> +#if __WORDSIZE == 64<br>
> +  struct stat st;<br>
>    if (syscall(__NR_fstat, fd, &st))<br>
>      return -1;<br>
> +#else<br>
> +  struct stat64 st;<br>
> +  if (syscall(__NR_fstat64, fd, &st))<br>
> +    return -1;<br>
> +#endif<br>
>    return (uptr)st.st_size;<br>
>  }<br>
><br>
> @@ -153,6 +163,81 @@<br>
>    return 0;  // Not found.<br>
>  }<br>
><br>
> +// ------------------ sanitizer_symbolizer.h<br>
> +typedef ElfW(Ehdr) Elf_Ehdr;<br>
> +typedef ElfW(Shdr) Elf_Shdr;<br>
> +<br>
> +bool FindDWARFSection(uptr object_file_addr, const char *section_name,<br>
> +                      DWARFSection *section) {<br>
> +  Elf_Ehdr *exe = (Elf_Ehdr*)object_file_addr;<br>
> +  Elf_Shdr *sections = (Elf_Shdr*)(object_file_addr + exe->e_shoff);<br>
> +  uptr section_names = object_file_addr +<br>
> +                       sections[exe->e_shstrndx].sh_offset;<br>
> +  for (int i = 0; i < exe->e_shnum; i++) {<br>
> +    Elf_Shdr *current_section = &sections[i];<br>
> +    const char *current_name = (const char*)section_names +<br>
> +                               current_section->sh_name;<br>
> +    if (IsFullNameOfDWARFSection(current_name, section_name)) {<br>
> +      section->data = (const char*)object_file_addr +<br>
> +                      current_section->sh_offset;<br>
> +      section->size = current_section->sh_size;<br>
> +      return true;<br>
> +    }<br>
> +  }<br>
> +  return false;<br>
> +}<br>
> +<br>
> +#ifdef ANDROID<br>
> +uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {<br>
> +  UNIMPLEMENTED();<br>
> +}<br>
> +#else  // ANDROID<br>
> +struct DlIteratePhdrData {<br>
> +  ModuleDIContext *modules;<br>
> +  uptr current_n;<br>
> +  uptr max_n;<br>
> +};<br>
> +<br>
> +static const uptr kMaxPathLength = 512;<br>
> +<br>
> +static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {<br>
> +  DlIteratePhdrData *data = (DlIteratePhdrData*)arg;<br>
> +  if (data->current_n == data->max_n)<br>
> +    return 0;<br>
> +  char *module_name = 0;<br>
> +  if (data->current_n == 0) {<br>
> +    // First module is the binary itself.<br>
> +    module_name = (char*)InternalAlloc(kMaxPathLength);<br>
> +    uptr module_name_len = readlink("/proc/self/exe",<br>
> +                                    module_name, kMaxPathLength);<br>
> +    CHECK_NE(module_name_len, (uptr)-1);<br>
> +    CHECK_LT(module_name_len, kMaxPathLength);<br>
> +    module_name[module_name_len] = '\0';<br>
> +  } else if (info->dlpi_name) {<br>
> +    module_name = internal_strdup(info->dlpi_name);<br>
> +  }<br>
> +  if (module_name == 0 || module_name[0] == '\0')<br>
> +    return 0;<br>
> +  void *mem = &data->modules[data->current_n];<br>
> +  ModuleDIContext *cur_module = new(mem) ModuleDIContext(module_name);<br>
> +  data->current_n++;<br>
> +  for (int i = 0; i < info->dlpi_phnum; i++) {<br>
> +    uptr cur_beg = info->dlpi_addr + info->dlpi_phdr[i].p_vaddr;<br>
> +    uptr cur_end = cur_beg + info->dlpi_phdr[i].p_memsz;<br>
> +    cur_module->addAddressRange(cur_beg, cur_end);<br>
> +  }<br>
> +  InternalFree(module_name);<br>
> +  return 0;<br>
> +}<br>
> +<br>
> +uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {<br>
> +  CHECK(modules);<br>
> +  DlIteratePhdrData data = {modules, 0, max_modules};<br>
> +  dl_iterate_phdr(dl_iterate_phdr_cb, &data);<br>
> +  return data.current_n;<br>
> +}<br>
> +#endif  // ANDROID<br>
> +<br>
>  // ----------------- sanitizer_procmaps.h<br>
>  ProcessMaps::ProcessMaps() {<br>
>    proc_self_maps_buff_len_ =<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Tue Jul  3 03:24:14 2012<br>
> @@ -18,6 +18,7 @@<br>
>  #include "sanitizer_internal_defs.h"<br>
>  #include "sanitizer_libc.h"<br>
>  #include "sanitizer_procmaps.h"<br>
> +#include "sanitizer_symbolizer.h"<br>
><br>
>  #include <crt_externs.h>  // for _NSGetEnviron<br>
>  #include <fcntl.h><br>
> @@ -106,6 +107,17 @@<br>
>    return 0;<br>
>  }<br>
><br>
> +// ------------------ sanitizer_symbolizer.h<br>
> +bool FindDWARFSection(uptr object_file_addr, const char *section_name,<br>
> +                      DWARFSection *section) {<br>
> +  UNIMPLEMENTED();<br>
> +  return false;<br>
> +}<br>
> +<br>
> +uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {<br>
> +  UNIMPLEMENTED();<br>
> +};<br>
> +<br>
>  // ----------------- sanitizer_procmaps.h<br>
><br>
>  ProcessMaps::ProcessMaps() {<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Tue Jul  3 03:24:14 2012<br>
> @@ -76,6 +76,18 @@<br>
>                         -1, 0);<br>
>  }<br>
><br>
> +void *MapFileToMemory(const char *file_name, uptr *buff_size) {<br>
> +  fd_t fd = internal_open(file_name, false);<br>
> +  CHECK_NE(fd, kInvalidFd);<br>
> +  uptr fsize = internal_filesize(fd);<br>
> +  CHECK_NE(fsize, (uptr)-1);<br>
> +  CHECK_GT(fsize, 0);<br>
> +  *buff_size = RoundUpTo(fsize, kPageSize);<br>
> +  void *map = internal_mmap(0, *buff_size, PROT_READ, MAP_PRIVATE, fd, 0);<br>
> +  return (map == MAP_FAILED) ? 0 : map;<br>
> +}<br>
> +<br>
> +<br>
>  static inline bool IntervalsAreSeparate(uptr start1, uptr end1,<br>
>                                          uptr start2, uptr end2) {<br>
>    CHECK(start1 <= end1);<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_procmaps.h Tue Jul  3 03:24:14 2012<br>
> @@ -41,7 +41,17 @@<br>
>      for (int i = 0; Next(&start, &end, &file_offset, filename, filename_size);<br>
>           i++) {<br>
>        if (addr >= start && addr < end) {<br>
> -        // Don't subtract 'start' for the first entry. Don't ask me why.<br>
> +        // Don't subtract 'start' for the first entry:<br>
> +        // * If a binary is compiled w/o -pie, then the first entry in<br>
> +        //   process maps is likely the binary itself (all dynamic libs<br>
> +        //   are mapped higher in address space). For such a binary,<br>
> +        //   instruction offset in binary coincides with the actual<br>
> +        //   instruction address in virtual memory (as code section<br>
> +        //   is mapped to a fixed memory range).<br>
> +        // * If a binary is compiled with -pie, all the modules are<br>
> +        //   mapped high at address space (in particular, higher than<br>
> +        //   shadow memory of the tool), so the module can't be the<br>
> +        //   first entry.<br>
>          *offset = (addr - (i ? start : 0)) + file_offset;<br>
>          return true;<br>
>        }<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.cc Tue Jul  3 03:24:14 2012<br>
> @@ -19,6 +19,18 @@<br>
><br>
>  namespace __sanitizer {<br>
><br>
> +bool IsFullNameOfDWARFSection(const char *full_name, const char *short_name) {<br>
> +  // Skip "__DWARF," prefix.<br>
> +  if (0 == internal_strncmp(full_name, "__DWARF,", 8)) {<br>
> +    full_name += 8;<br>
> +  }<br>
> +  // Skip . and _ prefices.<br>
> +  while (*full_name == '.' || *full_name == '_') {<br>
> +    full_name++;<br>
> +  }<br>
> +  return 0 == internal_strcmp(full_name, short_name);<br>
> +}<br>
> +<br>
>  void AddressInfo::Clear() {<br>
>    InternalFree(module);<br>
>    InternalFree(function);<br>
> @@ -26,97 +38,105 @@<br>
>    internal_memset(this, 0, sizeof(AddressInfo));<br>
>  }<br>
><br>
> -static const int kMaxModuleNameLength = 4096;<br>
> +ModuleDIContext::ModuleDIContext(const char *module_name) {<br>
> +  full_name_ = internal_strdup(module_name);<br>
> +  short_name_ = internal_strrchr(module_name, '/');<br>
> +  if (short_name_ == 0) {<br>
> +    short_name_ = full_name_;<br>
> +  } else {<br>
> +    short_name_++;<br>
> +  }<br>
> +  base_address_ = (uptr)-1;<br>
> +  n_ranges_ = 0;<br>
> +  mapped_addr_ = 0;<br>
> +  mapped_size_ = 0;<br>
> +}<br>
><br>
> -struct ModuleDesc {<br>
> -  ModuleDesc *next;<br>
> -  uptr start;<br>
> -  uptr end;<br>
> -  uptr offset;<br>
> -  char *full_name;<br>
> -  char *name;<br>
> -<br>
> -  ModuleDesc(uptr _start, uptr _end, uptr _offset, const char *module_name) {<br>
> -    next = 0;<br>
> -    start = _start;<br>
> -    end = _end;<br>
> -    offset = _offset;<br>
> -    full_name = internal_strdup(module_name);<br>
> -    name = internal_strrchr(module_name, '/');<br>
> -    if (name == 0) {<br>
> -      name = full_name;<br>
> -    } else {<br>
> -      name++;<br>
> -    }<br>
> +void ModuleDIContext::addAddressRange(uptr beg, uptr end) {<br>
> +  CHECK_LT(n_ranges_, kMaxNumberOfAddressRanges);<br>
> +  ranges_[n_ranges_].beg = beg;<br>
> +  ranges_[n_ranges_].end = end;<br>
> +  base_address_ = Min(base_address_, beg);<br>
> +  n_ranges_++;<br>
> +}<br>
> +<br>
> +bool ModuleDIContext::containsAddress(uptr address) const {<br>
> +  for (uptr i = 0; i < n_ranges_; i++) {<br>
> +    if (ranges_[i].beg <= address && address < ranges_[i].end)<br>
> +      return true;<br>
>    }<br>
> -};<br>
> +  return false;<br>
> +}<br>
> +<br>
> +void ModuleDIContext::getAddressInfo(AddressInfo *info) {<br>
> +  info->module = internal_strdup(full_name_);<br>
> +  info->module_offset = info->address - base_address_;<br>
> +  if (mapped_addr_ == 0)<br>
> +    CreateDIContext();<br>
> +  // FIXME: Use the actual debug info context here.<br>
> +  info->function = 0;<br>
> +  info->file = 0;<br>
> +  info->line = 0;<br>
> +  info->column = 0;<br>
> +}<br>
> +<br>
> +void ModuleDIContext::CreateDIContext() {<br>
> +  mapped_addr_ = (uptr)MapFileToMemory(full_name_, &mapped_size_);<br>
> +  CHECK(mapped_addr_);<br>
> +  DWARFSection debug_info;<br>
> +  DWARFSection debug_abbrev;<br>
> +  DWARFSection debug_line;<br>
> +  DWARFSection debug_aranges;<br>
> +  DWARFSection debug_str;<br>
> +  FindDWARFSection(mapped_addr_, "debug_info", &debug_info);<br>
> +  FindDWARFSection(mapped_addr_, "debug_abbrev", &debug_abbrev);<br>
> +  FindDWARFSection(mapped_addr_, "debug_line", &debug_line);<br>
> +  FindDWARFSection(mapped_addr_, "debug_aranges", &debug_aranges);<br>
> +  FindDWARFSection(mapped_addr_, "debug_str", &debug_str);<br>
> +  // FIXME: Construct actual debug info context using mapped_addr,<br>
> +  // mapped_size and pointers to DWARF sections in memory.<br>
> +}<br>
><br>
>  class Symbolizer {<br>
>   public:<br>
> -  void GetModuleDescriptions() {<br>
> -    ProcessMaps proc_maps;<br>
> -    uptr start, end, offset;<br>
> -    char *module_name = (char*)InternalAlloc(kMaxModuleNameLength);<br>
> -    ModuleDesc *prev_module = 0;<br>
> -    while (proc_maps.Next(&start, &end, &offset, module_name,<br>
> -                          kMaxModuleNameLength)) {<br>
> -      void *mem = InternalAlloc(sizeof(ModuleDesc));<br>
> -      ModuleDesc *cur_module = new(mem) ModuleDesc(start, end, offset,<br>
> -                                                   module_name);<br>
> -      if (!prev_module) {<br>
> -        modules_ = cur_module;<br>
> -      } else {<br>
> -        prev_module->next = cur_module;<br>
> -      }<br>
> -      prev_module = cur_module;<br>
> -    }<br>
> -    InternalFree(module_name);<br>
> -  }<br>
> -<br>
>    uptr SymbolizeCode(uptr addr, AddressInfo *frames, uptr max_frames) {<br>
>      if (max_frames == 0)<br>
>        return 0;<br>
>      AddressInfo *info = &frames[0];<br>
>      info->Clear();<br>
>      info->address = addr;<br>
> +    ModuleDIContext *module = FindModuleForAddress(addr);<br>
> +    if (module) {<br>
> +      module->getAddressInfo(info);<br>
> +      return 1;<br>
> +    }<br>
> +    return 0;<br>
> +  }<br>
> +<br>
> + private:<br>
> +  ModuleDIContext *FindModuleForAddress(uptr address) {<br>
>      if (modules_ == 0) {<br>
> -      GetModuleDescriptions();<br>
> +      modules_ = (ModuleDIContext*)InternalAlloc(<br>
> +          kMaxNumberOfModuleContexts * sizeof(ModuleDIContext));<br>
> +      CHECK(modules_);<br>
> +      n_modules_ = GetListOfModules(modules_, kMaxNumberOfModuleContexts);<br>
> +      CHECK_GT(n_modules_, 0);<br>
> +      CHECK_LT(n_modules_, kMaxNumberOfModuleContexts);<br>
>      }<br>
> -    bool first = true;<br>
> -    for (ModuleDesc *module = modules_; module; module = module->next) {<br>
> -      if (addr >= module->start && addr < module->end) {<br>
> -        info->module = internal_strdup(module->full_name);<br>
> -        // Don't subtract 'start' for the first entry:<br>
> -        // * If a binary is compiled w/o -pie, then the first entry in<br>
> -        //   process maps is likely the binary itself (all dynamic libs<br>
> -        //   are mapped higher in address space). For such a binary,<br>
> -        //   instruction offset in binary coincides with the actual<br>
> -        //   instruction address in virtual memory (as code section<br>
> -        //   is mapped to a fixed memory range).<br>
> -        // * If a binary is compiled with -pie, all the modules are<br>
> -        //   mapped high at address space (in particular, higher than<br>
> -        //   shadow memory of the tool), so the module can't be the<br>
> -        //   first entry.<br>
> -        info->module_offset = (addr - (first ? 0 : module->start)) +<br>
> -                              module->offset;<br>
> -        // FIXME: Fill other fields here as well: create debug<br>
> -        // context for a given module and fetch file/line info from it.<br>
> -        info->function = 0;<br>
> -        info->file = 0;<br>
> -        info->line = 0;<br>
> -        info->column = 0;<br>
> -        return 1;<br>
> +    for (uptr i = 0; i < n_modules_; i++) {<br>
> +      if (modules_[i].containsAddress(address)) {<br>
> +        return &modules_[i];<br>
>        }<br>
> -      first = false;<br>
>      }<br>
>      return 0;<br>
>    }<br>
> -<br>
> - private:<br>
> -  ModuleDesc *modules_;  // List of module descriptions is leaked.<br>
> +  static const uptr kMaxNumberOfModuleContexts = 256;<br>
> +  // Array of module debug info contexts is leaked.<br>
> +  ModuleDIContext *modules_;<br>
> +  uptr n_modules_;<br>
>  };<br>
><br>
> -static Symbolizer symbolizer;<br>
> +static Symbolizer symbolizer;  // Linker initialized.<br>
><br>
>  uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames) {<br>
>    return symbolizer.SymbolizeCode(address, frames, max_frames);<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer.h Tue Jul  3 03:24:14 2012<br>
> @@ -52,6 +52,45 @@<br>
>  // This function should NOT be called from two threads simultaneously.<br>
>  uptr SymbolizeCode(uptr address, AddressInfo *frames, uptr max_frames);<br>
><br>
> +// Debug info routines<br>
> +struct DWARFSection {<br>
> +  const char *data;<br>
> +  uptr size;<br>
> +};<br>
> +// Returns true on success.<br>
> +bool FindDWARFSection(uptr object_file_addr, const char *section_name,<br>
> +                      DWARFSection *section);<br>
> +bool IsFullNameOfDWARFSection(const char *full_name, const char *short_name);<br>
> +<br>
> +class ModuleDIContext {<br>
> + public:<br>
> +  explicit ModuleDIContext(const char *module_name);<br>
> +  void addAddressRange(uptr beg, uptr end);<br>
> +  bool containsAddress(uptr address) const;<br>
> +  void getAddressInfo(AddressInfo *info);<br>
> +<br>
> +  const char *full_name() const { return full_name_; }<br>
> +<br>
> + private:<br>
> +  void CreateDIContext();<br>
> +<br>
> +  struct AddressRange {<br>
> +    uptr beg;<br>
> +    uptr end;<br>
> +  };<br>
> +  char *full_name_;<br>
> +  char *short_name_;<br>
> +  uptr base_address_;<br>
> +  static const uptr kMaxNumberOfAddressRanges = 16;<br>
> +  AddressRange ranges_[kMaxNumberOfAddressRanges];<br>
> +  uptr n_ranges_;<br>
> +  uptr mapped_addr_;<br>
> +  uptr mapped_size_;<br>
> +};<br>
> +<br>
> +// OS-dependent function that gets the linked list of all loaded modules.<br>
> +uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules);<br>
> +<br>
>  }  // namespace __sanitizer<br>
><br>
>  #endif  // SANITIZER_SYMBOLIZER_H<br>
><br>
> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=159652&r1=159651&r2=159652&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=159652&r1=159651&r2=159652&view=diff</a><br>

> ==============================================================================<br>
> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)<br>
> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Tue Jul  3 03:24:14 2012<br>
> @@ -16,6 +16,7 @@<br>
><br>
>  #include "sanitizer_common.h"<br>
>  #include "sanitizer_libc.h"<br>
> +#include "sanitizer_symbolizer.h"<br>
><br>
>  namespace __sanitizer {<br>
><br>
> @@ -75,6 +76,10 @@<br>
>    return true;<br>
>  }<br>
><br>
> +void *MapFileToMemory(const char *file_name, uptr *buff_size) {<br>
> +  UNIMPLEMENTED();<br>
> +}<br>
> +<br>
>  const char *GetEnv(const char *name) {<br>
>    static char env_buffer[32767] = {};<br>
><br>
> @@ -125,6 +130,17 @@<br>
>    return atexit(function);<br>
>  }<br>
><br>
> +// ------------------ sanitizer_symbolizer.h<br>
> +bool FindDWARFSection(uptr object_file_addr, const char *section_name,<br>
> +                      DWARFSection *section) {<br>
> +  UNIMPLEMENTED();<br>
> +  return false;<br>
> +}<br>
> +<br>
> +uptr GetListOfModules(ModuleDIContext *modules, uptr max_modules) {<br>
> +  UNIMPLEMENTED();<br>
> +};<br>
> +<br>
>  // ------------------ sanitizer_libc.h<br>
>  void *internal_mmap(void *addr, uptr length, int prot, int flags,<br>
>                      int fd, u64 offset) {<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Alexander Potapenko<br>
Software Engineer<br>
Google Moscow<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>