⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mipsread.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
{    int			 f_idx, s_idx;    HDRR		*hdr = cur_hdr;    /* Running pointers */    FDR			*fh;    register EXTR	*esh;    register SYMR	*sh;    struct partial_symtab *pst;    int past_first_source_file = 0;    /* List of current psymtab's include files */    char **psymtab_include_list;    int includes_allocated;    int includes_used;    EXTR **extern_tab;    struct pst_map * fdr_to_pst;    /* Index within current psymtab dependency list */    struct partial_symtab **dependency_list;    int dependencies_used, dependencies_allocated;    struct cleanup *old_chain;    extern_tab = (EXTR**)obstack_alloc (&objfile->psymbol_obstack,					sizeof(EXTR *) * hdr->iextMax);    includes_allocated = 30;    includes_used = 0;    psymtab_include_list = (char **) alloca (includes_allocated *					     sizeof (char *));    next_symbol_text_func = mips_next_symbol_text;    dependencies_allocated = 30;    dependencies_used = 0;    dependency_list =	(struct partial_symtab **) alloca (dependencies_allocated *					   sizeof (struct partial_symtab *));    last_source_file = NULL;    /*     * Big plan:     *     * Only parse the Local and External symbols, and the Relative FDR.     * Fixup enough of the loader symtab to be able to use it.     * Allocate space only for the file's portions we need to     * look at. (XXX)     */    max_gdbinfo = 0;    max_glevel = MIN_GLEVEL;    /* Allocate the map FDR -> PST.       Minor hack: -O3 images might claim some global data belongs       to FDR -1. We`ll go along with that */    fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);    old_chain = make_cleanup (free, fdr_to_pst);    fdr_to_pst++;    {	struct partial_symtab * pst = new_psymtab("", objfile);	fdr_to_pst[-1].pst = pst;	FDR_IDX(pst) = -1;    }    /* Pass 1 over external syms: Presize and partition the list */    for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {	esh = (EXTR *) (hdr->cbExtOffset) + s_idx;	fdr_to_pst[esh->ifd].n_globals++;    }    /* Pass 1.5 over files:  partition out global symbol space */    s_idx = 0;    for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {	fdr_to_pst[f_idx].globals_offset = s_idx;	s_idx += fdr_to_pst[f_idx].n_globals;	fdr_to_pst[f_idx].n_globals = 0;    }    /* Pass 2 over external syms: fill in external symbols */    for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {	enum minimal_symbol_type ms_type = mst_text;	esh = (EXTR *) (hdr->cbExtOffset) + s_idx;	extern_tab[fdr_to_pst[esh->ifd].globals_offset		   + fdr_to_pst[esh->ifd].n_globals++] = esh;	if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)		continue;	switch (esh->asym.st) {	case stProc:		break;	case stGlobal:		ms_type = mst_data;		break;	case stLabel:		break;	default:		ms_type = mst_unknown;		complain (&unknown_ext_complaint, (char *)esh->asym.iss);	}	prim_record_minimal_symbol ((char *)esh->asym.iss,				    esh->asym.value,				    ms_type);    }    /* Pass 3 over files, over local syms: fill in static symbols */    for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {	struct partial_symtab *save_pst;	EXTR **ext_ptr;	cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);	if (fh->csym == 0) {	    fdr_to_pst[f_idx].pst = NULL;	    continue;	}	pst = start_psymtab_common (objfile, section_offsets, (char*)fh->rss,				    fh->cpd ? fh->adr : 0,				    objfile->global_psymbols.next,				    objfile->static_psymbols.next);	pst->read_symtab_private = (char *)	    obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));	save_pst = pst;	/* Make everything point to everything. */	FDR_IDX(pst) = f_idx;	fdr_to_pst[f_idx].pst = pst;	fh->ioptBase = (int)pst;	CUR_HDR(pst) = cur_hdr;	/* The way to turn this into a symtab is to call... */	pst->read_symtab = mipscoff_psymtab_to_symtab;	pst->texthigh = pst->textlow;	/* For stabs-in-ecoff files, the second symbol must be @stab.	   This symbol is emitted by mips-tfile to signal	   that the current object file uses encapsulated stabs	   instead of mips ecoff for local symbols.	   (It is the second symbol because the first symbol is	   the stFile used to signal the start of a file). */	if (fh->csym >= 2	    && strcmp((char *)(((SYMR *)fh->isymBase)[1].iss),		      stabs_symbol) == 0) {	    processing_gcc_compilation = 2;	    for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {		int type_code;		char *namestring;		sh = cur_sdx + (SYMR *) fh->isymBase;		type_code = MIPS_UNMARK_STAB(sh->index);		if (!MIPS_IS_STAB(sh)) {		    if (sh->st == stProc || sh->st == stStaticProc) {			long procaddr = sh->value;			sh = AUX_GET_ISYM (fh->fBigendian,			       sh->index + (union aux_ext *)(fh->iauxBase))			    + (SYMR *) fh->isymBase - 1;			if (sh->st == stEnd) {			    long high = procaddr + sh->value;			    if (high > pst->texthigh)				pst->texthigh = high;			}		    }		    continue;		}#define SET_NAMESTRING() namestring = (char*)sh->iss#define CUR_SYMBOL_TYPE type_code#define CUR_SYMBOL_VALUE sh->value#define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\  pst = save_pst#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0#define HANDLE_RBRAC(val) \  if ((val) > save_pst->texthigh) save_pst->texthigh = (val);#include "partial-stab.h"	    }	}	else {	    processing_gcc_compilation = 0;	    for (cur_sdx = 0; cur_sdx < fh->csym; ) {		char *name;		enum address_class class;		sh = cur_sdx + (SYMR *) fh->isymBase;		if (MIPS_IS_STAB(sh)) {		    cur_sdx++;		    continue;		}		if (sh->sc == scUndefined || sh->sc == scNil ||		    sh->index == 0xfffff) {		    /* FIXME, premature? */		    cur_sdx++;		    continue;		}		name = (char *)(sh->iss);		switch (sh->st) {		    long high;		    long procaddr;		    int new_sdx;		  case stProc:		/* Asm labels apparently */		  case stStaticProc:		/* Function */		    ADD_PSYMBOL_TO_LIST(name, strlen(name),					VAR_NAMESPACE, LOC_BLOCK,					objfile->static_psymbols, sh->value);		    /* Skip over procedure to next one. */		    if (sh->index >= hdr->iauxMax)		      {			/* Should not happen, but does when cross-compiling			   with the MIPS compiler.  FIXME -- pull later.  */			complain (&index_complaint, name);			new_sdx = cur_sdx+1;	/* Don't skip at all */		      }		    else		      new_sdx = AUX_GET_ISYM (fh->fBigendian,				sh->index + (union aux_ext *)fh->iauxBase);		    procaddr = sh->value;		    if (new_sdx <= cur_sdx)		      {			/* This should not happen either... FIXME.  */			complain (&aux_index_complaint, name);			new_sdx = cur_sdx + 1;	/* Don't skip backward */		      }		    cur_sdx = new_sdx;		    sh = cur_sdx + (SYMR *) fh->isymBase - 1;		    if (sh->st != stEnd)			continue;		    high = procaddr + sh->value;		    if (high > pst->texthigh)			pst->texthigh = high;		    continue;		  case stStatic:			/* Variable */		    class = LOC_STATIC;		    break;		  case stTypedef:			/* Typedef */		    class = LOC_TYPEDEF;		    break;		  case stConstant:		/* Constant decl */		    class = LOC_CONST;		    break;		  case stUnion:		  case stStruct:		  case stEnum:		  case stBlock:			/* { }, str, un, enum*/		    if (sh->sc == scInfo) {			ADD_PSYMBOL_TO_LIST(name, strlen(name),					    STRUCT_NAMESPACE, LOC_TYPEDEF,					    objfile->static_psymbols, sh->value);		    }		    /* Skip over the block */		    cur_sdx = sh->index;		    continue;		  case stFile:			/* File headers */		  case stLabel:			/* Labels */		  case stEnd:			/* Ends of files */		    goto skip;		  case stLocal:			/* Local variables */		    /* Normally these are skipped because we skip over		       all blocks we see.  However, these can occur		       as visible symbols in a .h file that contains code. */		    goto skip;		  default:		    /* Both complaints are valid:  one gives symbol name,		       the other the offending symbol type.  */		    complain (&unknown_sym_complaint, (char *)sh->iss);		    complain (&unknown_st_complaint, (char *)sh->st);		    cur_sdx++;		    continue;		}		/* Use this gdb symbol */		ADD_PSYMBOL_TO_LIST(name, strlen(name),				    VAR_NAMESPACE, class,				    objfile->static_psymbols, sh->value);	      skip:		cur_sdx++;		/* Go to next file symbol */	    }	    /* Now do enter the external symbols. */	    ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];	    cur_sdx = fdr_to_pst[f_idx].n_globals;	    PST_PRIVATE(save_pst)->extern_count = cur_sdx;	    PST_PRIVATE(save_pst)->extern_tab = ext_ptr;	    for (; --cur_sdx >= 0; ext_ptr++) {		register struct partial_symbol *psym;		enum address_class class;		if ((*ext_ptr)->ifd != f_idx)		    abort();		sh = &(*ext_ptr)->asym;		switch (sh->st) {		  case stProc:		    class = LOC_BLOCK;		    break;		  case stLabel:		    class = LOC_LABEL;		    break;		  default:		    complain (&unknown_ext_complaint, (char *)sh->iss);		    /* Fall through, pretend it's global.  */		  case stGlobal:		    class = LOC_STATIC;		    break;		}		if (objfile->global_psymbols.next >=		    objfile->global_psymbols.list + objfile->global_psymbols.size)		    extend_psymbol_list (&objfile->global_psymbols, objfile);		psym = objfile->global_psymbols.next++;		SYMBOL_NAME (psym) = (char*)sh->iss;		SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;		SYMBOL_CLASS (psym) = class;		SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;	    }	}	end_psymtab (save_pst, psymtab_include_list, includes_used,		     -1, save_pst->texthigh,		     dependency_list, dependencies_used);	if (objfile -> ei.entry_point >= save_pst->textlow &&	    objfile -> ei.entry_point <  save_pst->texthigh)	  {	    objfile -> ei.entry_file_lowpc = save_pst->textlow;	    objfile -> ei.entry_file_highpc = save_pst->texthigh;	  }    }    /* Mark the last code address, and remember it for later */    hdr->cbDnOffset = end_of_text_seg;    /* Now scan the FDRs for dependencies */    for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {	int s_id0 = 0;	fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);	pst = fdr_to_pst[f_idx].pst;	/* This should catch stabs-in-ecoff. */	if (fh->crfd <= 1)		continue;	if (fh->cpd == 0) {  /* If there are no functions defined here ... */		/* ...then presumably a .h file: drop reverse depends .h->.c */		for (; s_id0 < fh->crfd; s_id0++) {			RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;			if (*rh == f_idx) {				s_id0++;	/* Skip self-dependency */				break;			}		}	}	pst->number_of_dependencies = fh->crfd - s_id0;	pst->dependencies = (struct partial_symtab **)		obstack_alloc (&objfile->psymbol_obstack,			       pst->number_of_dependencies *			       sizeof (struct partial_symtab *));	for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {	    RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;	    if (*rh < 0 || *rh >= hdr->ifdMax)		complain(&bad_file_number_complaint, (char *)*rh);	    else		pst->dependencies[s_idx-s_id0] = fdr_to_pst[*rh].pst;	}    }    do_cleanups (old_chain);}#if 0/* Do the initial analisys of the F_IDX-th file descriptor.   Allocates a partial symtab for it, and builds the list   of dependent files by recursion. LEV says at which level   of recursion we are called (to pretty up debug traces) */static struct partial_symtab *parse_fdr(f_idx, lev, objfile)	int f_idx;	int lev;	struct objfile *objfile;{	register FDR *fh;	register struct partial_symtab *pst;	int s_idx, s_id0;	fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;	/* Use this to indicate into which symtab this file was parsed */	if (fh->ioptBase)		return (struct partial_symtab *) fh->ioptBase;	/* Debuggability level */	if (compare_glevel(max_glevel, fh->glevel) < 0)		max_glevel = fh->glevel;	/* Make a new partial_symtab */	pst = new_psymtab(fh->rss, objfile);	if (fh->cpd == 0){		pst->textlow = 0;		pst->texthigh = 0;	} else {		pst->textlow = fh->adr;		pst->texthigh = fh->cpd;	/* To be fixed later */	}	/* Make everything point to everything. */	FDR_IDX(pst) = f_idx;	fdr_to_pst[f_idx].pst = pst;	fh->ioptBase = (int)pst;	/* Analyze its dependencies */	if (fh->crfd <= 1)		return pst;	s_id0 = 0;	if (fh->cpd == 0) {  /* If there are no functions defined here ... */		/* ...then presumably a .h file: drop reverse depends .h->.c */		for (; s_id0 < fh->crfd; s_id0++) {			RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;			if (*rh == f_idx) {				s_id0++;	/* Skip self-dependency */				break;			}		}	}	pst->number_of_dependencies = fh->crfd - s_id0;	pst->dependencies = (struct partial_symtab **)		obstack_alloc (&objfile->psymbol_obstack,				 pst->number_of_dependencies *				   sizeof (struct partial_symtab *));	for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {		RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;		pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);	}	return pst;}#endifstatic char*mips_next_symbol_text (){    cur_sdx++;    return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;}/* Ancillary function to psymtab_to_symtab().  Does all the work   for turning the partial symtab PST into a symtab, recurring   first on all dependent psymtabs.  The argument F

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -