From: Julian Seward Date: Fri, 12 Jan 2007 22:03:14 +0000 (+0000) Subject: Merge r6506,7,8: Non-functional changes - partially rename X-Git-Tag: svn/VALGRIND_3_2_2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c1ab4ea28338672dd77172c655bdfb23a135606;p=thirdparty%2Fvalgrind.git Merge r6506,7,8: Non-functional changes - partially rename variables/fields used during debuginfo reading for greater clarity. git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_2_BRANCH@6511 --- diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index feff0967ee..6cebc8ba12 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -51,6 +51,35 @@ #include "priv_readelf.h" +/*------------------------------------------------------------*/ +/*--- The _svma / _avma / _image / _bias naming scheme ---*/ +/*------------------------------------------------------------*/ + +/* JRS 11 Jan 07: I find the different kinds of addresses involved in + debuginfo reading confusing. Recently I arrived at some + terminology which makes it clearer (to me, at least). There are 3 + kinds of address used in the debuginfo reading process: + + stated VMAs - the address where (eg) a .so says a symbol is, that + is, what it tells you if you consider the .so in + isolation + + actual VMAs - the address where (eg) said symbol really wound up + after the .so was mapped into memory + + image addresses - pointers into the copy of the .so (etc) + transiently mmaped aboard whilst we read its info + + Additionally I use the term 'bias' to denote the difference + between stated and actual VMAs for a given entity. + + This terminology is not used consistently, but a start has been + made. readelf.c and the call-frame info reader in readdwarf.c now + use it. Specifically, various variables and structure fields have + been annotated with _avma / _svma / _image / _bias. +*/ + + /*------------------------------------------------------------*/ /*--- Root structure ---*/ /*------------------------------------------------------------*/ @@ -75,10 +104,10 @@ SegInfo* alloc_SegInfo(Addr start, SizeT size, OffT foffset, { SegInfo* si = VG_(arena_calloc)(VG_AR_SYMTAB, 1, sizeof(SegInfo)); - si->start = start; - si->size = size; - si->foffset = foffset; - si->filename = VG_(arena_strdup)(VG_AR_SYMTAB, filename); + si->text_start_avma = start; + si->text_size = size; + si->foffset = foffset; + si->filename = VG_(arena_strdup)(VG_AR_SYMTAB, filename); // Everything else -- pointers, sizes, arrays -- is zeroed by calloc. return si; @@ -118,7 +147,8 @@ static void discard_SegInfo ( SegInfo* si ) if (VG_(clo_verbosity) > 1 || VG_(clo_trace_redir)) VG_(message)(Vg_DebugMsg, "Discarding syms at %p-%p in %s due to munmap()", - si->start, si->start + si->size, + si->text_start_avma, + si->text_start_avma + si->text_size, curr->filename ? curr->filename : (UChar*)"???"); vg_assert(*prev_next_ptr == curr); *prev_next_ptr = curr->next; @@ -150,8 +180,8 @@ static void discard_syms_in_range ( Addr start, SizeT length ) while (True) { if (curr == NULL) break; - if (start+length-1 < curr->start - || curr->start+curr->size-1 < start) { + if (start+length - 1 < curr->text_start_avma + || curr->text_start_avma + curr->text_size - 1 < start) { /* no overlap */ } else { found = True; @@ -336,7 +366,8 @@ static void search_all_symtabs ( Addr ptr, /*OUT*/SegInfo** psi, SegInfo* si; for (si = segInfo_list; si != NULL; si = si->next) { - if (si->start <= ptr && ptr < si->start+si->size) { + if (si->text_start_avma <= ptr + && ptr < si->text_start_avma + si->text_size) { sno = ML_(search_one_symtab) ( si, ptr, match_anywhere_in_fun ); if (sno == -1) goto not_found; *symno = sno; @@ -360,7 +391,8 @@ static void search_all_loctabs ( Addr ptr, /*OUT*/SegInfo** psi, SegInfo* si; for (si = segInfo_list; si != NULL; si = si->next) { - if (si->start <= ptr && ptr < si->start+si->size) { + if (si->text_start_avma <= ptr + && ptr < si->text_start_avma + si->text_size) { lno = ML_(search_one_loctab) ( si, ptr ); if (lno == -1) goto not_found; *locno = lno; @@ -501,7 +533,8 @@ Bool VG_(get_objname) ( Addr a, Char* buf, Int nbuf ) SegInfo* si; for (si = segInfo_list; si != NULL; si = si->next) { - if (si->start <= a && a < si->start+si->size) { + if (si->text_start_avma <= a + && a < si->text_start_avma + si->text_size) { VG_(strncpy_safely)(buf, si->filename, nbuf); return True; } @@ -516,7 +549,8 @@ SegInfo* VG_(find_seginfo) ( Addr a ) SegInfo* si; for (si = segInfo_list; si != NULL; si = si->next) { - if (si->start <= a && a < si->start+si->size) { + if (si->text_start_avma <= a + && a < si->text_start_avma + si->text_size) { return si; } } @@ -893,12 +927,12 @@ const SegInfo* VG_(next_seginfo)(const SegInfo* si) Addr VG_(seginfo_start)(const SegInfo* si) { - return si->start; + return si->text_start_avma; } SizeT VG_(seginfo_size)(const SegInfo* si) { - return si->size; + return si->text_size; } const UChar* VG_(seginfo_soname)(const SegInfo* si) @@ -913,7 +947,7 @@ const UChar* VG_(seginfo_filename)(const SegInfo* si) ULong VG_(seginfo_sym_offset)(const SegInfo* si) { - return si->offset; + return si->text_bias; } VgSectKind VG_(seginfo_sect_kind)(Addr a) @@ -922,29 +956,30 @@ VgSectKind VG_(seginfo_sect_kind)(Addr a) VgSectKind ret = Vg_SectUnknown; for(si = segInfo_list; si != NULL; si = si->next) { - if (a >= si->start && a < (si->start + si->size)) { + if (a >= si->text_start_avma + && a < si->text_start_avma + si->text_size) { if (0) VG_(printf)( "addr=%p si=%p %s got=%p %d plt=%p %d data=%p %d bss=%p %d\n", a, si, si->filename, - si->got_start_vma, si->got_size, - si->plt_start_vma, si->plt_size, - si->data_start_vma, si->data_size, - si->bss_start_vma, si->bss_size); + si->got_start_avma, si->got_size, + si->plt_start_avma, si->plt_size, + si->data_start_avma, si->data_size, + si->bss_start_avma, si->bss_size); ret = Vg_SectText; - if (a >= si->data_start_vma && a < (si->data_start_vma + si->data_size)) + if (a >= si->data_start_avma && a < si->data_start_avma + si->data_size) ret = Vg_SectData; else - if (a >= si->bss_start_vma && a < (si->bss_start_vma + si->bss_size)) + if (a >= si->bss_start_avma && a < si->bss_start_avma + si->bss_size) ret = Vg_SectBSS; else - if (a >= si->plt_start_vma && a < (si->plt_start_vma + si->plt_size)) + if (a >= si->plt_start_avma && a < si->plt_start_avma + si->plt_size) ret = Vg_SectPLT; else - if (a >= si->got_start_vma && a < (si->got_start_vma + si->got_size)) + if (a >= si->got_start_avma && a < si->got_start_avma + si->got_size) ret = Vg_SectGOT; } } diff --git a/coregrind/m_debuginfo/priv_storage.h b/coregrind/m_debuginfo/priv_storage.h index 2337461a68..99a3370a06 100644 --- a/coregrind/m_debuginfo/priv_storage.h +++ b/coregrind/m_debuginfo/priv_storage.h @@ -34,6 +34,9 @@ This module was also extensively hacked on by Jeremy Fitzhardinge and Tom Hughes. */ +/* See comment at top of debuginfo.c for explanation of + the _svma / _avma / _image / _bias naming scheme. +*/ #ifndef __PRIV_STORAGE_H #define __PRIV_STORAGE_H @@ -139,10 +142,10 @@ struct _SegInfo { struct _SegInfo* next; /* list of SegInfos */ /* Description of the mapped segment. */ - Addr start; - UInt size; + Addr text_start_avma; + UInt text_size; UChar* filename; /* in mallocville */ - OffT foffset; + OffT foffset; /* file offset for mapped text section - UNUSED */ UChar* soname; /* An expandable array of symbols. */ @@ -170,24 +173,25 @@ struct _SegInfo { UChar strtab[SEGINFO_STRCHUNKSIZE]; } *strchunks; - /* 'offset' is what needs to be added to an address in the address - space of the library as stored on disk (which is not 0-based for - executables or prelinked libraries) to get an address in memory - for the object loaded at 'start' */ - OffT offset; + /* 'text_bias' is what needs to be added to an address in the + address space of the library as stored on disk [a so-called + stated VMA] (which is not 0-based for executables or prelinked + libraries) to get an address in memory for the object loaded at + 'text_start_avma'. At least for text symbols. */ + OffT text_bias; /* Bounds of data, BSS, PLT, GOT and OPD (for ppc64-linux) so that tools can see what section an address is in. In the running image! */ - Addr plt_start_vma; + Addr plt_start_avma; UInt plt_size; - Addr got_start_vma; + Addr got_start_avma; UInt got_size; - Addr opd_start_vma; + Addr opd_start_avma; UInt opd_size; - Addr data_start_vma; + Addr data_start_avma; UInt data_size; - Addr bss_start_vma; + Addr bss_start_avma; UInt bss_size; }; diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c index c0aef1fb4b..4317777a11 100644 --- a/coregrind/m_debuginfo/readdwarf.c +++ b/coregrind/m_debuginfo/readdwarf.c @@ -1592,15 +1592,13 @@ static void initUnwindContext ( /*OUT*/UnwindContext* ctx ) } -/* A structure which holds information needed by read_encoded_Addr(). - Not sure what these address-like fields are -- really ought to - distinguish properly svma/avma/image addresses. +/* A structure which holds information needed by read_encoded_Addr(). */ typedef struct { UChar encoding; - UChar* ehframe; - Addr ehframe_addr; + UChar* ehframe_image; + Addr ehframe_avma; } AddressDecodingInfo; @@ -1839,10 +1837,10 @@ static Addr read_encoded_Addr ( /*OUT*/Int* nbytes, UChar* data ) { Addr base; - Int offset; - UChar encoding = adi->encoding; - UChar* ehframe = adi->ehframe; - Addr ehframe_addr = adi->ehframe_addr; + Word offset; + UChar encoding = adi->encoding; + UChar* ehframe_image = adi->ehframe_image; + Addr ehframe_avma = adi->ehframe_avma; vg_assert((encoding & DW_EH_PE_indirect) == 0); @@ -1853,7 +1851,7 @@ static Addr read_encoded_Addr ( /*OUT*/Int* nbytes, base = 0; break; case DW_EH_PE_pcrel: - base = ehframe_addr + ( data - ehframe ); + base = ehframe_avma + ( data - ehframe_image ); break; case DW_EH_PE_datarel: vg_assert(0); @@ -1868,7 +1866,7 @@ static Addr read_encoded_Addr ( /*OUT*/Int* nbytes, break; case DW_EH_PE_aligned: base = 0; - offset = data - ehframe; + offset = data - ehframe_image; if ((offset % sizeof(Addr)) != 0) { *nbytes = sizeof(Addr) - (offset % sizeof(Addr)); data += *nbytes; @@ -2477,12 +2475,12 @@ static CIE the_CIEs[N_CIEs]; void ML_(read_callframe_info_dwarf2) ( /*OUT*/struct _SegInfo* si, - UChar* ehframe, Int ehframe_sz, Addr ehframe_addr ) + UChar* ehframe_image, Int ehframe_sz, Addr ehframe_avma ) { Int nbytes; HChar* how = NULL; Int n_CIEs = 0; - UChar* data = ehframe; + UChar* data = ehframe_image; # if defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) /* These targets don't use CFI-based stack unwinding. */ @@ -2491,8 +2489,8 @@ void ML_(read_callframe_info_dwarf2) if (VG_(clo_trace_cfi)) { VG_(printf)("\n-----------------------------------------------\n"); - VG_(printf)("CFI info: ehframe %p, ehframe_sz %d\n", - ehframe, ehframe_sz ); + VG_(printf)("CFI info: szB %d, _avma %p, _image %p\n", + ehframe_sz, (void*)ehframe_avma, (void*)ehframe_image ); VG_(printf)("CFI info: name %s\n", si->filename ); } @@ -2524,11 +2522,11 @@ void ML_(read_callframe_info_dwarf2) UInt cie_pointer; /* Are we done? */ - if (data == ehframe + ehframe_sz) + if (data == ehframe_image + ehframe_sz) return; /* Overshot the end? Means something is wrong */ - if (data > ehframe + ehframe_sz) { + if (data > ehframe_image + ehframe_sz) { how = "overran the end of .eh_frame"; goto bad; } @@ -2538,8 +2536,8 @@ void ML_(read_callframe_info_dwarf2) ciefde_start = data; if (VG_(clo_trace_cfi)) - VG_(printf)("\ncie/fde.start = %p (ehframe + 0x%x)\n", - ciefde_start, ciefde_start - ehframe); + VG_(printf)("\ncie/fde.start = %p (ehframe_image + 0x%x)\n", + ciefde_start, ciefde_start - ehframe_image); ciefde_len = read_UInt(data); data += sizeof(UInt); if (VG_(clo_trace_cfi)) @@ -2549,7 +2547,7 @@ void ML_(read_callframe_info_dwarf2) of the sequence. ?? Neither the DWARF2 spec not the AMD64 ABI spec say this, though. */ if (ciefde_len == 0) { - if (data == ehframe + ehframe_sz) + if (data == ehframe_image + ehframe_sz) return; how = "zero-sized CIE/FDE but not at section end"; goto bad; @@ -2585,7 +2583,7 @@ void ML_(read_callframe_info_dwarf2) /* Record its offset. This is how we will find it again later when looking at an FDE. */ - the_CIEs[this_CIE].offset = ciefde_start - ehframe; + the_CIEs[this_CIE].offset = ciefde_start - ehframe_image; cie_version = read_UChar(data); data += sizeof(UChar); if (VG_(clo_trace_cfi)) @@ -2694,9 +2692,9 @@ void ML_(read_callframe_info_dwarf2) if (VG_(clo_trace_cfi)) { AddressDecodingInfo adi; - adi.encoding = the_CIEs[this_CIE].address_encoding; - adi.ehframe = ehframe; - adi.ehframe_addr = ehframe_addr; + adi.encoding = the_CIEs[this_CIE].address_encoding; + adi.ehframe_image = ehframe_image; + adi.ehframe_avma = ehframe_avma; show_CF_instructions(the_CIEs[this_CIE].instrs, the_CIEs[this_CIE].ilen, &adi ); } @@ -2720,7 +2718,7 @@ void ML_(read_callframe_info_dwarf2) /* re sizeof(UInt), matches XXX above. For 64-bit dwarf this will have to be a ULong instead. */ - look_for = (data - sizeof(UInt) - ehframe) - cie_pointer; + look_for = (data - sizeof(UInt) - ehframe_image) - cie_pointer; for (cie = 0; cie < n_CIEs; cie++) { if (0) VG_(printf)("look for %d %d\n", @@ -2734,17 +2732,17 @@ void ML_(read_callframe_info_dwarf2) goto bad; } - adi.encoding = the_CIEs[cie].address_encoding; - adi.ehframe = ehframe; - adi.ehframe_addr = ehframe_addr; + adi.encoding = the_CIEs[cie].address_encoding; + adi.ehframe_image = ehframe_image; + adi.ehframe_avma = ehframe_avma; fde_initloc = read_encoded_Addr(&nbytes, &adi, data); data += nbytes; if (VG_(clo_trace_cfi)) VG_(printf)("fde.initloc = %p\n", (void*)fde_initloc); - adi.encoding = the_CIEs[cie].address_encoding & 0xf; - adi.ehframe = ehframe; - adi.ehframe_addr = ehframe_addr; + adi.encoding = the_CIEs[cie].address_encoding & 0xf; + adi.ehframe_image = ehframe_image; + adi.ehframe_avma = ehframe_avma; fde_arange = read_encoded_Addr(&nbytes, &adi, data); data += nbytes; if (VG_(clo_trace_cfi)) @@ -2769,9 +2767,9 @@ void ML_(read_callframe_info_dwarf2) data += fde_ilen; - adi.encoding = the_CIEs[cie].address_encoding; - adi.ehframe = ehframe; - adi.ehframe_addr = ehframe_addr; + adi.encoding = the_CIEs[cie].address_encoding; + adi.ehframe_image = ehframe_image; + adi.ehframe_avma = ehframe_avma; if (VG_(clo_trace_cfi)) show_CF_instructions(fde_instrs, fde_ilen, &adi); diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index 90484523c6..e53f05b9b8 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -232,9 +232,9 @@ Bool get_elf_symbol_info ( if (!plausible && ELFXX_ST_TYPE(sym->st_info) == STT_NOTYPE && sym->st_size > 0 - && si->opd_start_vma != 0 - && sym_addr >= si->opd_start_vma - && sym_addr < si->opd_start_vma + si->opd_size) + && si->opd_start_avma != 0 + && sym_addr >= si->opd_start_avma + && sym_addr < si->opd_start_avma + si->opd_size) plausible = True; # endif @@ -261,15 +261,15 @@ Bool get_elf_symbol_info ( /* If it's apparently in a GOT or PLT, it's really a reference to a symbol defined elsewhere, so ignore it. */ - if (si->got_start_vma != 0 - && sym_addr >= si->got_start_vma - && sym_addr < si->got_start_vma + si->got_size) { + if (si->got_start_avma != 0 + && sym_addr >= si->got_start_avma + && sym_addr < si->got_start_avma + si->got_size) { TRACE_SYMTAB(" ignore -- in GOT: %s\n", sym_name); return False; } - if (si->plt_start_vma != 0 - && sym_addr >= si->plt_start_vma - && sym_addr < si->plt_start_vma + si->plt_size) { + if (si->plt_start_avma != 0 + && sym_addr >= si->plt_start_avma + && sym_addr < si->plt_start_avma + si->plt_size) { TRACE_SYMTAB(" ignore -- in PLT: %s\n", sym_name); return False; } @@ -284,9 +284,9 @@ Bool get_elf_symbol_info ( */ is_in_opd = False; - if (si->opd_start_vma != 0 - && sym_addr >= si->opd_start_vma - && sym_addr < si->opd_start_vma + si->opd_size) { + if (si->opd_start_avma != 0 + && sym_addr >= si->opd_start_avma + && sym_addr < si->opd_start_avma + si->opd_size) { # if !defined(VGP_ppc64_linux) TRACE_SYMTAB(" ignore -- in OPD: %s\n", sym_name); return False; @@ -306,7 +306,7 @@ Bool get_elf_symbol_info ( the vma of the opd section start, so we can figure out how far into the opd section this is. */ - offset_in_opd = (Addr)sym_addr - (Addr)(si->opd_start_vma); + offset_in_opd = (Addr)sym_addr - (Addr)(si->opd_start_avma); if (offset_in_opd < 0 || offset_in_opd >= si->opd_size) { TRACE_SYMTAB(" ignore -- invalid OPD offset: %s\n", sym_name); return False; @@ -345,7 +345,7 @@ Bool get_elf_symbol_info ( /* Here's yet another ppc64-linux hack. Get rid of leading dot if the symbol is outside .opd. */ # if defined(VGP_ppc64_linux) - if (si->opd_start_vma != 0 + if (si->opd_start_avma != 0 && !is_in_opd && sym_name[0] == '.') { vg_assert(!(*from_opd_out)); @@ -355,11 +355,12 @@ Bool get_elf_symbol_info ( /* If no part of the symbol falls within the mapped range, ignore it. */ - if (*sym_addr_out + *sym_size_out <= si->start - || *sym_addr_out >= si->start+si->size) { + if (*sym_addr_out + *sym_size_out <= si->text_start_avma + || *sym_addr_out >= si->text_start_avma + si->text_size) { TRACE_SYMTAB( "ignore -- %p .. %p outside mapped range %p .. %p\n", *sym_addr_out, *sym_addr_out + *sym_size_out, - si->start, si->start+si->size); + si->text_start_avma, + si->text_start_avma + si->text_size); return False; } @@ -368,9 +369,9 @@ Bool get_elf_symbol_info ( section. This would completely mess up function redirection and intercepting. This assert ensures that any symbols that make it into the symbol table on ppc64-linux don't point into .opd. */ - if (si->opd_start_vma != 0) { - vg_assert(*sym_addr_out + *sym_size_out <= si->opd_start_vma - || *sym_addr_out >= si->opd_start_vma + si->opd_size); + if (si->opd_start_avma != 0) { + vg_assert(*sym_addr_out + *sym_size_out <= si->opd_start_avma + || *sym_addr_out >= si->opd_start_avma + si->opd_size); } # endif @@ -825,7 +826,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) oimage = (Addr)NULL; if (VG_(clo_verbosity) > 1 || VG_(clo_trace_redir)) VG_(message)(Vg_DebugMsg, "Reading syms from %s (%p)", - si->filename, si->start ); + si->filename, si->text_start_avma ); /* mmap the object image aboard, so that we can read symbols and line number info out of it. It will be munmapped immediately @@ -857,6 +858,11 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) oimage = sres.val; + if (0) { + VG_(printf)("read_elf_debug_info: OIMAGE = %p - %p\n", + (void*)oimage, (void*)(oimage + (UWord)n_oimage)); + } + /* Ok, the object image is safely in oimage[0 .. n_oimage-1]. Now verify that it is a valid ELF .so or executable image. */ @@ -926,7 +932,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) if (!offset_set) { offset_set = True; - offset_oimage = si->start - o_phdr->p_vaddr; + offset_oimage = si->text_start_avma - o_phdr->p_vaddr; baseaddr = o_phdr->p_vaddr; } @@ -940,11 +946,11 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) // Get the data and bss start/size if appropriate mapped = o_phdr->p_vaddr + offset_oimage; mapped_end = mapped + o_phdr->p_memsz; - if (si->data_start_vma == 0 && + if (si->data_start_avma == 0 && (o_phdr->p_flags & (PF_R|PF_W|PF_X)) == (PF_R|PF_W)) { - si->data_start_vma = mapped; - si->data_size = o_phdr->p_filesz; - si->bss_start_vma = mapped + o_phdr->p_filesz; + si->data_start_avma = mapped; + si->data_size = o_phdr->p_filesz; + si->bss_start_avma = mapped + o_phdr->p_filesz; if (o_phdr->p_memsz > o_phdr->p_filesz) si->bss_size = o_phdr->p_memsz - o_phdr->p_filesz; else @@ -954,23 +960,31 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) mapped = mapped & ~(VKI_PAGE_SIZE-1); mapped_end = (mapped_end + VKI_PAGE_SIZE - 1) & ~(VKI_PAGE_SIZE-1); - if (VG_(needs).data_syms && - (mapped >= si->start && mapped <= (si->start+si->size)) && - (mapped_end > (si->start+si->size))) { - UInt newsz = mapped_end - si->start; - if (newsz > si->size) { + if (VG_(needs).data_syms + && mapped >= si->text_start_avma + && mapped <= (si->text_start_avma + si->text_size) + && mapped_end > (si->text_start_avma + si->text_size)) { + /* XXX jrs 2007 Jan 11: what's going on here? If data + syms are involved, surely we shouldn't be messing with + the segment's text_size unless there is an assumption + that the data segment has been mapped immediately after + the text segment. Which doesn't sound good to me. */ + UInt newsz = mapped_end - si->text_start_avma; + if (newsz > si->text_size) { if (0) VG_(printf)("extending mapping %p..%p %d -> ..%p %d\n", - si->start, si->start+si->size, si->size, - si->start+newsz, newsz); + si->text_start_avma, + si->text_start_avma + si->text_size, + si->text_size, + si->text_start_avma + newsz, newsz); - si->size = newsz; + si->text_size = newsz; } } } } - si->offset = offset_oimage; + si->text_bias = offset_oimage; /* If, after looking at all the program headers, we still didn't find a soname, add a fake one. */ @@ -994,7 +1008,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) information */ { /* Pointers to start of sections (in the oimage, not in the - running image) */ + running image) -- image addresses */ UChar* o_strtab = NULL; /* .strtab */ ElfXX_Sym* o_symtab = NULL; /* .symtab */ UChar* o_dynstr = NULL; /* .dynstr */ @@ -1033,9 +1047,9 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) UInt dwarf1l_sz = 0; UInt ehframe_sz = 0; - /* Section virtual addresses */ - Addr dummy_vma = 0; - Addr ehframe_vma = 0; + /* Section actual virtual addresses */ + Addr dummy_avma = 0; + Addr ehframe_avma = 0; /* Find all interesting sections */ @@ -1073,29 +1087,29 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) /* Nb: must find where .got and .plt sections will be in the * executable image, not in the object image transiently loaded. */ - /* NAME SIZE ADDR_IN_OIMAGE ADDR_WHEN_MAPPED */ - FIND(".dynsym", o_dynsym_sz, o_dynsym, dummy_vma) - FIND(".dynstr", o_dynstr_sz, o_dynstr, dummy_vma) - FIND(".symtab", o_symtab_sz, o_symtab, dummy_vma) - FIND(".strtab", o_strtab_sz, o_strtab, dummy_vma) + /* NAME SIZE ADDR_IN_OIMAGE ADDR_WHEN_MAPPED */ + FIND(".dynsym", o_dynsym_sz, o_dynsym, dummy_avma) + FIND(".dynstr", o_dynstr_sz, o_dynstr, dummy_avma) + FIND(".symtab", o_symtab_sz, o_symtab, dummy_avma) + FIND(".strtab", o_strtab_sz, o_strtab, dummy_avma) - FIND(".gnu_debuglink", debuglink_sz, debuglink, dummy_vma) + FIND(".gnu_debuglink", debuglink_sz, debuglink, dummy_avma) - FIND(".stab", stab_sz, stab, dummy_vma) - FIND(".stabstr", stabstr_sz, stabstr, dummy_vma) + FIND(".stab", stab_sz, stab, dummy_avma) + FIND(".stabstr", stabstr_sz, stabstr, dummy_avma) - FIND(".debug_line", debug_line_sz, debug_line, dummy_vma) - FIND(".debug_info", debug_info_sz, debug_info, dummy_vma) - FIND(".debug_abbrev", debug_abbv_sz, debug_abbv, dummy_vma) - FIND(".debug_str", debug_str_sz, debug_str, dummy_vma) + FIND(".debug_line", debug_line_sz, debug_line, dummy_avma) + FIND(".debug_info", debug_info_sz, debug_info, dummy_avma) + FIND(".debug_abbrev", debug_abbv_sz, debug_abbv, dummy_avma) + FIND(".debug_str", debug_str_sz, debug_str, dummy_avma) - FIND(".debug", dwarf1d_sz, dwarf1d, dummy_vma) - FIND(".line", dwarf1l_sz, dwarf1l, dummy_vma) - FIND(".eh_frame", ehframe_sz, ehframe, ehframe_vma) + FIND(".debug", dwarf1d_sz, dwarf1d, dummy_avma) + FIND(".line", dwarf1l_sz, dwarf1l, dummy_avma) + FIND(".eh_frame", ehframe_sz, ehframe, ehframe_avma) - FIND(".got", si->got_size, dummy_filea, si->got_start_vma) - FIND(".plt", si->plt_size, dummy_filea, si->plt_start_vma) - FIND(".opd", si->opd_size, opd_filea, si->opd_start_vma) + FIND(".got", si->got_size, dummy_filea, si->got_start_avma) + FIND(".plt", si->plt_size, dummy_filea, si->plt_start_avma) + FIND(".opd", si->opd_size, opd_filea, si->opd_start_avma) # undef FIND } @@ -1124,7 +1138,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) for (i = 0; i < ehdr->e_phnum; i++) { ElfXX_Phdr *o_phdr = &((ElfXX_Phdr *)(dimage + ehdr->e_phoff))[i]; if (o_phdr->p_type == PT_LOAD) { - offset_dimage = si->start - o_phdr->p_vaddr; + offset_dimage = si->text_start_avma - o_phdr->p_vaddr; break; } } @@ -1137,7 +1151,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) sh_strtab = (UChar*)(dimage + shdr[ehdr->e_shstrndx].sh_offset); /* Same deal as previous FIND, except simpler - doesn't - look for vma, only oimage address. */ + look for avma, only oimage address. */ /* Find all interesting sections */ for (i = 0; i < ehdr->e_shnum; i++) { @@ -1161,6 +1175,7 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) } \ } + /* ?? NAME SIZE ADDR_IN_OIMAGE */ FIND(need_symtab, ".symtab", o_symtab_sz, o_symtab) FIND(need_symtab, ".strtab", o_strtab_sz, o_strtab) FIND(1, ".stab", stab_sz, stab) @@ -1202,7 +1217,8 @@ Bool ML_(read_elf_debug_info) ( struct _SegInfo* si ) /* Read .eh_frame (call-frame-info) if any */ if (ehframe) { - ML_(read_callframe_info_dwarf2) ( si, ehframe, ehframe_sz, ehframe_vma ); + ML_(read_callframe_info_dwarf2) + ( si, ehframe/*image*/, ehframe_sz, ehframe_avma ); } /* Read the stabs and/or dwarf2 debug information, if any. It diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c index 2763ebb74e..f732f174da 100644 --- a/coregrind/m_debuginfo/storage.c +++ b/coregrind/m_debuginfo/storage.c @@ -253,13 +253,16 @@ void ML_(addLineInfo) ( struct _SegInfo* si, size = 1; } - /* vg_assert(this < si->start + si->size && next-1 >= si->start); */ - if (this >= si->start + si->size || next-1 < si->start) { + /* vg_assert(this < si->text_start_avma + si->size + && next-1 >= si->text_start_avma); */ + if (this >= si->text_start_avma + si->text_size + || next-1 < si->text_start_avma) { if (0) VG_(message)(Vg_DebugMsg, "warning: ignoring line info entry falling " "outside current SegInfo: %p %p %p %p", - si->start, si->start + si->size, + si->text_start_avma, + si->text_start_avma + si->text_size, this, next-1); return; } @@ -319,8 +322,8 @@ void ML_(addDiCfSI) ( struct _SegInfo* si, DiCfSI* cfsi ) /* Rule out ones which are completely outside the segment. These probably indicate some kind of bug, but for the meantime ignore them. */ - if ( cfsi->base + cfsi->len - 1 < si->start - || si->start + si->size - 1 < cfsi->base ) { + if ( cfsi->base + cfsi->len - 1 < si->text_start_avma + || si->text_start_avma + si->text_size - 1 < cfsi->base ) { static Int complaints = 3; if (VG_(clo_trace_cfi) || complaints > 0) { complaints--; @@ -330,8 +333,8 @@ void ML_(addDiCfSI) ( struct _SegInfo* si, DiCfSI* cfsi ) "warning: DiCfSI %p .. %p outside segment %p .. %p", cfsi->base, cfsi->base + cfsi->len - 1, - si->start, - si->start + si->size - 1 + si->text_start_avma, + si->text_start_avma + si->text_size - 1 ); } if (VG_(clo_trace_cfi))