|
From: <sv...@va...> - 2005-06-26 02:19:21
|
Author: njn
Date: 2005-06-26 03:19:17 +0100 (Sun, 26 Jun 2005)
New Revision: 4027
Log:
If read_lib_symbols() fails, once again discard the SegInfo.
And some other minor cleanups.
Modified:
trunk/coregrind/m_debuginfo/priv_symtab.h
trunk/coregrind/m_debuginfo/symtab.c
Modified: trunk/coregrind/m_debuginfo/priv_symtab.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/priv_symtab.h 2005-06-26 00:44:21 UTC (re=
v 4026)
+++ trunk/coregrind/m_debuginfo/priv_symtab.h 2005-06-26 02:19:17 UTC (re=
v 4027)
@@ -171,7 +171,7 @@
struct _SegInfo {
struct _SegInfo* next; /* list of SegInfos */
=20
- Int ref;
+ Int ref;
=20
/* Description of the mapped segment. */
Addr start;
Modified: trunk/coregrind/m_debuginfo/symtab.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_debuginfo/symtab.c 2005-06-26 00:44:21 UTC (rev 402=
6)
+++ trunk/coregrind/m_debuginfo/symtab.c 2005-06-26 02:19:17 UTC (rev 402=
7)
@@ -48,6 +48,12 @@
=20
#include <elf.h> /* ELF defns */
=20
+/* The root structure for the entire symbol table system. It is a
+ linked list of SegInfos. Note that this entire mechanism assumes
+ that what we read from /proc/self/maps doesn't contain overlapping
+ address ranges, and as a result the SegInfos in this list describe
+ disjoint address ranges.=20
+*/
static SegInfo* segInfo_list =3D NULL;
=20
/*------------------------------------------------------------*/
@@ -1290,12 +1296,15 @@
=20
si->offset =3D 0;
=20
+ vg_assert(si->soname =3D=3D NULL);
+
for (i =3D 0; i < ehdr->e_phnum; i++) {
ElfXX_Phdr *o_phdr;
ElfXX_Addr mapped, mapped_end;
=20
o_phdr =3D &((ElfXX_Phdr *)(oimage + ehdr->e_phoff))[i];
=20
+ // Try to get the soname.
if (o_phdr->p_type =3D=3D PT_DYNAMIC && si->soname =3D=3D NULL) {
const ElfXX_Dyn *dyn =3D (const ElfXX_Dyn *)(oimage + o_phdr->p_off=
set);
Int stroff =3D -1;
@@ -1329,15 +1338,16 @@
baseaddr =3D o_phdr->p_vaddr;
}
=20
+ // Make sure the Phdrs are in order
if (o_phdr->p_vaddr < prev_addr) {
ML_(symerr)("ELF Phdrs are out of order!?");
goto out;
}
prev_addr =3D o_phdr->p_vaddr;
=20
+ // Get the data and bss start/size if appropriate
mapped =3D o_phdr->p_vaddr + si->offset;
mapped_end =3D mapped + o_phdr->p_memsz;
-
if (si->data_start =3D=3D 0 &&
(o_phdr->p_flags & (PF_R|PF_W|PF_X)) =3D=3D (PF_R|PF_W)) {
si->data_start =3D mapped;
@@ -1348,14 +1358,13 @@
else
si->bss_size =3D 0;
}
-
- mapped =3D mapped & ~(VKI_PAGE_SIZE-1);
- mapped_end =3D (mapped_end + VKI_PAGE_SIZE - 1) & ~(VKI_PAGE_SIZE-1);
-
#if 0
/* 20050228: disabled this until VG_(next_segment) can be
reinstated in some clean incarnation of the low level
memory manager. */
+ mapped =3D mapped & ~(VKI_PAGE_SIZE-1);
+ mapped_end =3D (mapped_end + VKI_PAGE_SIZE - 1) & ~(VKI_PAGE_SIZE-1);
+
if (VG_(needs).data_syms &&
(mapped >=3D si->start && mapped <=3D (si->start+si->size)) &&
(mapped_end > (si->start+si->size))) {
@@ -1444,8 +1453,6 @@
Addr dummy_addr =3D 0;
Addr ehframe_addr =3D 0;
=20
- Bool has_debuginfo =3D False;
-
/* Find all interesting sections */
for (i =3D 0; i < ehdr->e_shnum; i++) {
# define FIND(sec_name, sec_data, sec_size, sec_addr, in_exec, ty=
pe) \
@@ -1567,14 +1574,12 @@
appears reading stabs stuff on amd64-linux doesn't work, so
we ignore it. */
# if !defined(VGP_amd64_linux)
- if (stab !=3D NULL && stabstr !=3D NULL) {
- has_debuginfo =3D True;
+ if (stab && stabstr) {
ML_(read_debuginfo_stabs) ( si, stab, stab_sz,=20
stabstr, stabstr_sz );
}
# endif
if (debug_line) {
- has_debuginfo =3D True;
ML_(read_debuginfo_dwarf2) ( si,=20
debug_info, debug_info_sz,
debug_abbv,
@@ -1582,13 +1587,8 @@
debug_str );
}
if (dwarf1d && dwarf1l) {
- has_debuginfo =3D True;
ML_(read_debuginfo_dwarf1) ( si, dwarf1d, dwarf1d_sz,=20
dwarf1l, dwarf1l_sz );
- }=20
- if (!has_debuginfo) {
- ML_(symerr)(" object doesn't have any line number info");
- goto out;
}
}
res =3D True;
@@ -1610,61 +1610,35 @@
/*--- Main entry point for symbols table reading. ---*/
/*------------------------------------------------------------*/
=20
-/* The root structure for the entire symbol table system. It is a
- linked list of SegInfos. Note that this entire mechanism assumes
- that what we read from /proc/self/maps doesn't contain overlapping
- address ranges, and as a result the SegInfos in this list describe
- disjoint address ranges.=20
-*/
-SegInfo *VG_(read_seg_symbols) ( Addr seg_addr, SizeT seg_len,
- OffT seg_offset, const Char* seg_filena=
me)
+static SegInfo*
+alloc_SegInfo(Addr start, SizeT size, OffT foffset, const Char* filename=
)
{
- SegInfo* si;
+ SegInfo* si =3D VG_(arena_calloc)(VG_AR_SYMTAB, 1, sizeof(SegInfo));
=20
- VGP_PUSHCC(VgpReadSyms);
+ si->start =3D start;
+ si->size =3D size;
+ si->foffset =3D foffset;
+ si->filename =3D VG_(arena_strdup)(VG_AR_SYMTAB, filename);
=20
- /* Get the record initialised right. */
- si =3D VG_(arena_malloc)(VG_AR_SYMTAB, sizeof(SegInfo));
-
- VG_(memset)(si, 0, sizeof(*si));
- si->start =3D seg_addr;
- si->size =3D seg_len;
- si->foffset =3D seg_offset;
- si->filename =3D VG_(arena_strdup)(VG_AR_SYMTAB, seg_filename);
-
si->ref =3D 1;
=20
- si->symtab =3D NULL;
- si->symtab_size =3D si->symtab_used =3D 0;
- si->loctab =3D NULL;
- si->loctab_size =3D si->loctab_used =3D 0;
- si->strchunks =3D NULL;
- si->scopetab =3D NULL;
- si->scopetab_size =3D si->scopetab_used =3D 0;
- si->cfisi =3D NULL;
- si->cfisi_size =3D si->cfisi_used =3D 0;
- si->cfisi_minaddr =3D si->cfisi_maxaddr =3D 0;
+ // Everything else -- pointers, sizes, arrays -- is zeroed by calloc.
=20
- si->stab_typetab =3D NULL;
+ return si;
+}
=20
- si->plt_start =3D si->plt_size =3D 0;
- si->got_start =3D si->got_size =3D 0;
- si->data_start =3D si->data_size =3D 0;
- si->bss_start =3D si->bss_size =3D 0;
+SegInfo *VG_(read_seg_symbols) ( Addr seg_addr, SizeT seg_len,
+ OffT seg_offset, const Char* seg_filena=
me)
+{
+ SegInfo* si =3D alloc_SegInfo(seg_addr, seg_len, seg_offset, seg_file=
name);
=20
- /* And actually fill it up. */
- if (!read_lib_symbols ( si ) && 0) {
- /* XXX this interacts badly with the prevN optimization in
- addStr(). Since this frees the si, the si pointer value can
- be recycled, which confuses the curr_si =3D=3D si test. For no=
w,
- this code is disabled, and everything is included in the
- segment list, even if it is a bad ELF file. Ironically,
- running this under valgrind itself hides the problem, because
- it doesn't recycle pointers... */
- // [Nb: the prevN optimization has now been removed from addStr().
- // However, when I try reactivating this path of the branch I get
- // seg faults... --njn 13-Jun-2005]
+ VGP_PUSHCC(VgpReadSyms);
+
+ if (!read_lib_symbols ( si )) {
+ // Something went wrong (eg. bad ELF file).
freeSegInfo( si );
+ si =3D NULL;
+
} else {
// Prepend si to segInfo_list
si->next =3D segInfo_list;
|