2 * File stabs.c - read stabs information from the wine executable itself.
4 * Copyright (C) 1996, Eric Youngdale.
17 #define PATH_MAX _MAX_PATH
32 #elif defined(__EMX__)
62 * This is how we translate stab types into our internal representations
65 static struct datatype ** stab_types = NULL;
66 static int num_stab_types = 0;
69 * Set so that we know the main executable name and path.
76 struct stab_nlist *n_next;
82 unsigned long n_value;
86 * This is used to keep track of known datatypes so that we don't redefine
87 * them over and over again. It sucks up lots of memory otherwise.
91 struct known_typedef * next;
94 struct datatype * types[0];
97 #define NR_STAB_HASH 521
99 struct known_typedef * ktd_head[NR_STAB_HASH] = {NULL,};
101 static unsigned int stab_hash( const char * name )
103 unsigned int hash = 0;
111 hash = (hash << 4) + *p++;
113 if( (tmp = (hash & 0xf0000000)) )
119 return hash % NR_STAB_HASH;
123 static void stab_strcpy(char * dest, const char * source)
126 * A strcpy routine that stops when we hit the ':' character.
127 * Faster than copying the whole thing, and then nuking the
130 while(*source != '\0' && *source != ':')
135 #define MAX_TD_NESTING 128
137 static int **typenums;
138 static int *nroftypenums=NULL;
139 static int nrofnroftypenums=0;
140 static int curtypenum = 0;
144 DEBUG_FileSubNr2StabEnum(int filenr,int subnr) {
145 if (nrofnroftypenums<=filenr) {
146 nroftypenums = xrealloc(nroftypenums,sizeof(nroftypenums[0])*(filenr+1));
147 memset(nroftypenums+nrofnroftypenums,0,(filenr+1-nrofnroftypenums)*sizeof(nroftypenums[0]));
148 typenums = xrealloc(typenums,sizeof(typenums[0])*(filenr+1));
149 memset(typenums+nrofnroftypenums,0,sizeof(typenums[0])*(filenr+1-nrofnroftypenums));
150 nrofnroftypenums=filenr+1;
152 if (nroftypenums[filenr]<=subnr) {
153 typenums[filenr] = xrealloc(typenums[filenr],sizeof(typenums[0][0])*(subnr+1));
154 memset(typenums[filenr]+nroftypenums[filenr],0,sizeof(typenums[0][0])*(subnr+1-nroftypenums[filenr]));
155 nroftypenums[filenr] = subnr+1;
157 if (!typenums[filenr][subnr])
158 typenums[filenr][subnr]=++curtypenum;
160 if( num_stab_types <= curtypenum ) {
161 num_stab_types = curtypenum + 256;
162 stab_types = (struct datatype **) xrealloc(stab_types,
163 num_stab_types * sizeof(struct datatype *)
165 memset( stab_types + curtypenum, 0, sizeof(struct datatype *) * (num_stab_types - curtypenum) );
167 //fprintf(stderr,"(%d,%d) is %d\n",filenr,subnr,typenums[filenr][subnr]);
168 return typenums[filenr][subnr];
173 DEBUG_ReadTypeEnumBackwards(char*x) {
180 filenr=strtol(x,&x,10); /* <int> */
182 subnr=strtol(x,&x,10); /* <int> */
185 while ((*x>='0') && (*x<='9'))
190 return DEBUG_FileSubNr2StabEnum(filenr,subnr);
195 DEBUG_ReadTypeEnum(char **x) {
200 filenr=strtol(*x,x,10); /* <int> */
202 subnr=strtol(*x,x,10); /* <int> */
206 subnr = strtol(*x,x,10); /* <int> */
208 return DEBUG_FileSubNr2StabEnum(filenr,subnr);
213 DEBUG_RegisterTypedef(const char * name, struct datatype ** types, int ndef)
216 struct known_typedef * ktd;
221 ktd = (struct known_typedef *) xmalloc(sizeof(struct known_typedef)
222 + ndef * sizeof(struct datatype *));
224 hash = stab_hash(name);
226 ktd->name = xstrdup(name);
228 memcpy(&ktd->types[0], types, ndef * sizeof(struct datatype *));
229 ktd->next = ktd_head[hash];
230 ktd_head[hash] = ktd;
237 DEBUG_HandlePreviousTypedef(const char * name, const char * stab)
240 enum debug_type expect;
242 struct known_typedef * ktd;
245 hash = stab_hash(name);
247 for(ktd = ktd_head[hash]; ktd; ktd = ktd->next)
248 if ((ktd->name[0] == name[0]) && (strcmp(name, ktd->name) == 0) )
252 * Didn't find it. This must be a new one.
258 * Examine the stab to make sure it has the same number of definitions.
261 for(ptr = strchr(stab, '='); ptr; ptr = strchr(ptr+1, '='))
263 if( count >= ktd->ndefs )
267 * Make sure the types of all of the objects is consistent with
268 * what we have already parsed.
297 fprintf(stderr, "Unknown type (%c).\n",ptr[1]);
300 if( expect != DEBUG_GetType(ktd->types[count]) )
305 if( ktd->ndefs != count )
309 * Go through, dig out all of the type numbers, and substitute the
310 * appropriate things.
313 for(ptr = strchr(stab, '='); ptr; ptr = strchr(ptr+1, '='))
314 stab_types[DEBUG_ReadTypeEnumBackwards(ptr-1)] = ktd->types[count++];
319 static int DEBUG_FreeRegisteredTypedefs()
323 struct known_typedef * ktd;
324 struct known_typedef * next;
327 for(j=0; j < NR_STAB_HASH; j++ )
329 for(ktd = ktd_head[j]; ktd; ktd = next)
345 DEBUG_ParseTypedefStab(char * ptr, const char * typename)
350 struct datatype * curr_type;
351 struct datatype * datatype;
352 struct datatype * curr_types[MAX_TD_NESTING];
353 char element_name[1024];
356 const char * orig_typename;
362 orig_typename = typename;
364 if( DEBUG_HandlePreviousTypedef(typename, ptr) )
368 * Go from back to front. First we go through and figure out what
369 * type numbers we need, and register those types. Then we go in
370 * and fill the details.
373 for( c = strchr(ptr, '='); c != NULL; c = strchr(c + 1, '=') )
376 * Back up until we get to a non-numeric character. This is the type
379 typenum = DEBUG_ReadTypeEnumBackwards(c-1);
381 if( ntypes >= MAX_TD_NESTING )
384 * If this ever happens, just bump the counter.
386 fprintf(stderr, "Typedef nesting overflow\n");
393 stab_types[typenum] = DEBUG_NewDataType(POINTER, NULL);
394 curr_types[ntypes++] = stab_types[typenum];
398 stab_types[typenum] = DEBUG_NewDataType(STRUCT, typename);
399 curr_types[ntypes++] = stab_types[typenum];
402 stab_types[typenum] = DEBUG_NewDataType(ARRAY, NULL);
403 curr_types[ntypes++] = stab_types[typenum];
408 stab_types[typenum] = DEBUG_NewDataType(BASIC, typename);
409 curr_types[ntypes++] = stab_types[typenum];
412 stab_strcpy(element_name, c + 3);
413 stab_types[typenum] = DEBUG_NewDataType(STRUCT, element_name);
414 curr_types[ntypes++] = stab_types[typenum];
417 stab_types[typenum] = DEBUG_NewDataType(ENUM, NULL);
418 curr_types[ntypes++] = stab_types[typenum];
421 stab_types[typenum] = DEBUG_NewDataType(FUNC, NULL);
422 curr_types[ntypes++] = stab_types[typenum];
425 fprintf(stderr, "Unknown type (%c).\n",c[1]);
431 * Now register the type so that if we encounter it again, we will know
434 DEBUG_RegisterTypedef(orig_typename, curr_types, ntypes);
437 * OK, now take a second sweep through. Now we will be digging
438 * out the definitions of the various components, and storing
439 * them in the skeletons that we have already allocated. We take
440 * a right-to left search as this is much easier to parse.
442 for( c = strrchr(ptr, '='); c != NULL; c = strrchr(ptr, '=') )
444 int typenum = DEBUG_ReadTypeEnumBackwards(c-1);
445 curr_type = stab_types[typenum];
462 datatype = stab_types[DEBUG_ReadTypeEnum(&tc)];
463 DEBUG_SetPointerType(curr_type, datatype);
473 * We have already handled these above.
478 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo>,<int>,<int>;; */
482 DEBUG_ReadTypeEnum(&tc);
484 arrmin = strtol(tc, &tc, 10); /* <int> */
486 arrmax = strtol(tc, &tc, 10); /* <int> */
488 datatype = stab_types[DEBUG_ReadTypeEnum(&tc)]; /* <typeinfo> */
493 DEBUG_SetArrayParams(curr_type, arrmin, arrmax, datatype);
500 if( DEBUG_SetStructSize(curr_type, strtol(tc, &tc, 10)) == FALSE )
503 * We have already filled out this structure. Nothing to do,
504 * so just skip forward to the end of the definition.
506 while( tc[0] != ';' && tc[1] != ';' )
519 * Now parse the individual elements of the structure/union.
530 datatype = stab_types[DEBUG_ReadTypeEnum(&tc)];
533 offset = strtol(tc, &tc, 10);
535 size = strtol(tc, &tc, 10);
538 DEBUG_AddStructElement(curr_type, element_name, datatype, offset, size);
541 /* ... but proceed parsing to the end of the stab */
546 /* if we had a undeclared value this one is undeclared too.
547 * remove it from the stab_types.
548 * I just set it to NULL to detect bugs in my thoughtprocess.
549 * FIXME: leaks the memory for the structure elements.
550 * FIXME: such structures should have been optimized away
553 stab_types[typenum] = NULL;
564 * Now parse the individual elements of the structure/union.
573 offset = strtol(tc, &tc, 10);
575 DEBUG_AddStructElement(curr_type, element_name, NULL, offset, 0);
583 fprintf(stderr, "Unknown type (%c).\n",c[1]);
592 static struct datatype *
593 DEBUG_ParseStabType(const char * stab)
598 * Look through the stab definition, and figure out what datatype
599 * this represents. If we have something we know about, assign the
602 c = strchr(stab, ':');
608 * The next character says more about the type (i.e. data, function, etc)
609 * of symbol. Skip it.
613 * The next is either an integer or a (integer,integer).
614 * The DEBUG_ReadTypeEnum takes care that stab_types is large enough.
616 return stab_types[DEBUG_ReadTypeEnum(&c)];
621 DEBUG_ParseStabs(char * addr, unsigned int load_offset,
622 unsigned int staboff, int stablen,
623 unsigned int strtaboff, int strtablen)
625 struct name_hash * curr_func = NULL;
626 struct wine_locals * curr_loc = NULL;
627 struct name_hash * curr_sym = NULL;
628 char currpath[PATH_MAX];
638 struct stab_nlist * stab_ptr;
641 char * subpath = NULL;
644 nstab = stablen / sizeof(struct stab_nlist);
645 stab_ptr = (struct stab_nlist *) (addr + staboff);
646 strs = (char *) (addr + strtaboff);
648 memset(currpath, 0, sizeof(currpath));
651 * Allocate a buffer into which we can build stab strings for cases
652 * where the stab is continued over multiple lines.
655 stabbuff = (char *) xmalloc(stabbufflen);
659 for(i=0; i < nstab; i++, stab_ptr++ )
661 ptr = strs + (unsigned int) stab_ptr->n_un.n_name;
662 if( ptr[strlen(ptr) - 1] == '\\' )
665 * Indicates continuation. Append this to the buffer, and go onto the
666 * next record. Repeat the process until we find a stab without the
667 * '/' character, as this indicates we have the whole thing.
670 if( strlen(stabbuff) + len > stabbufflen )
672 stabbufflen += 65536;
673 stabbuff = (char *) xrealloc(stabbuff, stabbufflen);
675 strncat(stabbuff, ptr, len - 1);
678 else if( stabbuff[0] != '\0' )
680 strcat( stabbuff, ptr);
684 if( strchr(ptr, '=') != NULL )
687 * The stabs aren't in writable memory, so copy it over so we are
688 * sure we can scribble on it.
690 if( ptr != stabbuff )
692 strcpy(stabbuff, ptr);
695 stab_strcpy(symname, ptr);
696 DEBUG_ParseTypedefStab(ptr, symname);
699 switch(stab_ptr->n_type)
703 * These are useless with ELF. They have no value, and you have to
704 * read the normal symbol table to get the address. Thus we
705 * ignore them, and when we process the normal symbol table
706 * we should do the right thing.
708 * With a.out, they actually do make some amount of sense.
711 new_addr.type = DEBUG_ParseStabType(ptr);
712 new_addr.off = load_offset + stab_ptr->n_value;
714 stab_strcpy(symname, ptr);
716 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
717 SYM_WINE | SYM_DATA | SYM_INVALID);
719 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
720 SYM_WINE | SYM_DATA );
726 * We need to keep track of these so we get symbol scoping
727 * right for local variables. For now, we just ignore them.
728 * The hooks are already there for dealing with this however,
729 * so all we need to do is to keep count of the nesting level,
730 * and find the RBRAC for each matching LBRAC.
736 * These are static symbols and BSS symbols.
739 new_addr.type = DEBUG_ParseStabType(ptr);
740 new_addr.off = load_offset + stab_ptr->n_value;
742 stab_strcpy(symname, ptr);
743 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
744 SYM_WINE | SYM_DATA );
748 * These are function parameters.
750 if( (curr_func != NULL)
751 && (stab_ptr->n_value != 0) )
753 stab_strcpy(symname, ptr);
754 curr_loc = DEBUG_AddLocal(curr_func, 0,
755 stab_ptr->n_value, 0, 0, symname);
756 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr));
760 if( curr_func != NULL )
762 stab_strcpy(symname, ptr);
763 curr_loc = DEBUG_AddLocal(curr_func, stab_ptr->n_value, 0, 0, 0, symname);
764 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr));
768 if( (curr_func != NULL)
769 && (stab_ptr->n_value != 0) )
771 stab_strcpy(symname, ptr);
772 DEBUG_AddLocal(curr_func, 0,
773 stab_ptr->n_value, 0, 0, symname);
775 else if (curr_func == NULL)
777 stab_strcpy(symname, ptr);
782 * This is a line number. These are always relative to the start
783 * of the function (N_FUN), and this makes the lookup easier.
785 if( curr_func != NULL )
788 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
793 * This isn't right. The order of the stabs is different under
794 * a.out, and as a result we would end up attaching the line
795 * number to the wrong function.
797 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
798 stab_ptr->n_value - curr_func->addr.off);
805 * First, clean up the previous function we were working on.
807 DEBUG_Normalize(curr_func);
810 * For now, just declare the various functions. Later
811 * on, we will add the line number information and the
817 new_addr.type = DEBUG_ParseStabType(ptr);
818 new_addr.off = load_offset + stab_ptr->n_value;
820 * Copy the string to a temp buffer so we
821 * can kill everything after the ':'. We do
822 * it this way because otherwise we end up dirtying
823 * all of the pages related to the stabs, and that
824 * sucks up swap space like crazy.
826 stab_strcpy(symname, ptr);
827 curr_func = DEBUG_AddSymbol( symname, &new_addr, currpath,
828 SYM_WINE | SYM_FUNC);
833 * Don't add line number information for this function
841 * This indicates a new source file. Append the records
842 * together, to build the correct path name.
846 * With a.out, there is no NULL string N_SO entry at the end of
847 * the file. Thus when we find non-consecutive entries,
848 * we consider that a new file is started.
853 DEBUG_Normalize(curr_func);
864 DEBUG_Normalize(curr_func);
867 * The datatypes that we would need to use are reset when
868 * we start a new file.
870 memset(stab_types, 0, num_stab_types * sizeof(stab_types[0]));
872 for (i=0;i<nrofnroftypenums;i++)
873 memset(typenums[i],0,sizeof(typenums[i][0])*nroftypenums[i]);
879 strcat(currpath, ptr);
881 strcpy(currpath, ptr);
888 * This indicates we are including stuff from an include file.
889 * If this is the main source, enable the debug stuff, otherwise
892 if( subpath == NULL || strcmp(ptr, subpath) == 0 )
899 DEBUG_Normalize(curr_func);
905 strtabinc = stab_ptr->n_value;
906 DEBUG_Normalize(curr_func);
911 * Ignore this. We don't care what it points to.
918 * Always ignore these. GCC doesn't even generate them.
928 fprintf(stderr, "%d %x %s\n", stab_ptr->n_type,
929 (unsigned int) stab_ptr->n_value,
930 strs + (unsigned int) stab_ptr->n_un.n_name);
934 if( stab_types != NULL )
942 DEBUG_FreeRegisteredTypedefs();
950 * Walk through the entire symbol table and add any symbols we find there.
951 * This can be used in cases where we have stripped ELF shared libraries,
952 * or it can be used in cases where we have data symbols for which the address
953 * isn't encoded in the stabs.
955 * This is all really quite easy, since we don't have to worry about line
956 * numbers or local data variables.
960 DEBUG_ProcessElfSymtab(char * addr, unsigned int load_offset,
961 Elf32_Shdr * symtab, Elf32_Shdr * strtab)
963 char * curfile = NULL;
964 struct name_hash * curr_sym = NULL;
974 symp = (Elf32_Sym *) (addr + symtab->sh_offset);
975 nsym = symtab->sh_size / sizeof(*symp);
976 strp = (char *) (addr + strtab->sh_offset);
978 for(i=0; i < nsym; i++, symp++)
981 * Ignore certain types of entries which really aren't of that much
984 if( ELF32_ST_TYPE(symp->st_info) == STT_SECTION )
989 symname = strp + symp->st_name;
992 * Save the name of the current file, so we have a way of tracking
993 * static functions/data.
995 if( ELF32_ST_TYPE(symp->st_info) == STT_FILE )
1003 * See if we already have something for this symbol.
1004 * If so, ignore this entry, because it would have come from the
1005 * stabs or from a previous symbol. If the value is different,
1006 * we will have to keep the darned thing, because there can be
1007 * multiple local symbols by the same name.
1009 if( (DEBUG_GetSymbolValue(symname, -1, &new_addr, FALSE ) == TRUE)
1010 && (new_addr.off == (load_offset + symp->st_value)) )
1014 new_addr.type = NULL;
1015 new_addr.off = load_offset + symp->st_value;
1016 flags = SYM_WINE | (ELF32_ST_BIND(symp->st_info) == STT_FUNC
1017 ? SYM_FUNC : SYM_DATA);
1018 if( ELF32_ST_BIND(symp->st_info) == STB_GLOBAL )
1019 curr_sym = DEBUG_AddSymbol( symname, &new_addr, NULL, flags );
1021 curr_sym = DEBUG_AddSymbol( symname, &new_addr, curfile, flags );
1024 * Record the size of the symbol. This can come in handy in
1025 * some cases. Not really used yet, however.
1027 if( symp->st_size != 0 )
1028 DEBUG_SetSymbolSize(curr_sym, symp->st_size);
1036 DEBUG_ProcessElfObject(char * filename, unsigned int load_offset)
1039 struct stat statbuf;
1042 char * addr = (char *) 0xffffffff;
1053 * Make sure we can stat and open this file.
1055 if( filename == NULL )
1058 status = stat(filename, &statbuf);
1061 char *s,*t,*fn,*paths;
1062 if (strchr(filename,'/'))
1064 paths = xstrdup(getenv("PATH"));
1069 fn = (char*)xmalloc(strlen(filename)+1+strlen(s)+1);
1072 strcat(fn,filename);
1073 if ((rtn = DEBUG_ProcessElfObject(fn,load_offset))) {
1079 if (t) s = t+1; else break;
1081 if (!s || !*s) fprintf(stderr," not found");
1087 * Now open the file, so that we can mmap() it.
1089 fd = open(filename, O_RDONLY);
1095 * Now mmap() the file.
1097 addr = mmap(0, statbuf.st_size, PROT_READ,
1098 MAP_PRIVATE, fd, 0);
1099 if( addr == (char *) 0xffffffff )
1103 * Next, we need to find a few of the internal ELF headers within
1104 * this thing. We need the main executable header, and the section
1107 ehptr = (Elf32_Ehdr *) addr;
1109 if( load_offset == 0 )
1110 DEBUG_RegisterELFDebugInfo(ehptr->e_entry, statbuf.st_size, filename);
1112 DEBUG_RegisterELFDebugInfo(load_offset, statbuf.st_size, filename);
1114 spnt = (Elf32_Shdr *) (addr + ehptr->e_shoff);
1115 nsect = ehptr->e_shnum;
1116 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
1118 stabsect = stabstrsect = -1;
1120 for(i=0; i < nsect; i++)
1122 if( strcmp(shstrtab + spnt[i].sh_name, ".stab") == 0 )
1125 if( strcmp(shstrtab + spnt[i].sh_name, ".stabstr") == 0 )
1129 if( stabsect == -1 || stabstrsect == -1 )
1133 * OK, now just parse all of the stabs.
1135 rtn = DEBUG_ParseStabs(addr, load_offset,
1136 spnt[stabsect].sh_offset,
1137 spnt[stabsect].sh_size,
1138 spnt[stabstrsect].sh_offset,
1139 spnt[stabstrsect].sh_size);
1144 for(i=0; i < nsect; i++)
1146 if( (strcmp(shstrtab + spnt[i].sh_name, ".symtab") == 0)
1147 && (spnt[i].sh_type == SHT_SYMTAB) )
1148 DEBUG_ProcessElfSymtab(addr, load_offset,
1149 spnt + i, spnt + spnt[i].sh_link);
1151 if( (strcmp(shstrtab + spnt[i].sh_name, ".dynsym") == 0)
1152 && (spnt[i].sh_type == SHT_DYNSYM) )
1153 DEBUG_ProcessElfSymtab(addr, load_offset,
1154 spnt + i, spnt + spnt[i].sh_link);
1159 if( addr != (char *) 0xffffffff )
1160 munmap(addr, statbuf.st_size);
1170 DEBUG_ReadExecutableDbgInfo(void)
1175 struct r_debug * dbg_hdr;
1176 struct link_map * lpnt = NULL;
1177 extern Elf32_Dyn _DYNAMIC[];
1181 exe_name = DEBUG_argv0;
1184 * Make sure we can stat and open this file.
1186 if( exe_name == NULL )
1189 fprintf( stderr, "Loading symbols: %s", exe_name );
1190 rowcount = 17 + strlen(exe_name);
1191 DEBUG_ProcessElfObject(exe_name, 0);
1194 * Finally walk the tables that the dynamic loader maintains to find all
1195 * of the other shared libraries which might be loaded. Perform the
1196 * same step for all of these.
1199 if( dynpnt == NULL )
1203 * Now walk the dynamic section (of the executable, looking for a DT_DEBUG
1206 for(; dynpnt->d_tag != DT_NULL; dynpnt++)
1207 if( dynpnt->d_tag == DT_DEBUG )
1210 if( (dynpnt->d_tag != DT_DEBUG)
1211 || (dynpnt->d_un.d_ptr == 0) )
1215 * OK, now dig into the actual tables themselves.
1217 dbg_hdr = (struct r_debug *) dynpnt->d_un.d_ptr;
1218 lpnt = dbg_hdr->r_map;
1221 * Now walk the linked list. In all known ELF implementations,
1222 * the dynamic loader maintains this linked list for us. In some
1223 * cases the first entry doesn't appear with a name, in other cases it
1226 for(; lpnt; lpnt = lpnt->l_next )
1229 * We already got the stuff for the executable using the
1230 * argv[0] entry above. Here we only need to concentrate on any
1231 * shared libraries which may be loaded.
1233 ehdr = (Elf32_Ehdr *) lpnt->l_addr;
1234 if( (lpnt->l_addr == 0) || (ehdr->e_type != ET_DYN) )
1237 if( lpnt->l_name != NULL )
1239 if (rowcount + strlen(lpnt->l_name) > 76)
1241 fprintf( stderr, "\n " );
1244 fprintf( stderr, " %s", lpnt->l_name );
1245 rowcount += strlen(lpnt->l_name) + 1;
1246 DEBUG_ProcessElfObject(lpnt->l_name, lpnt->l_addr);
1253 fprintf( stderr, "\n" );
1258 #else /* !__ELF__ */
1265 DEBUG_ReadExecutableDbgInfo(void)
1267 char * addr = (char *) 0xffffffff;
1272 unsigned int staboff;
1273 struct stat statbuf;
1275 unsigned int stroff;
1277 exe_name = DEBUG_argv0;
1280 * Make sure we can stat and open this file.
1282 if( exe_name == NULL )
1285 status = stat(exe_name, &statbuf);
1290 * Now open the file, so that we can mmap() it.
1292 fd = open(exe_name, O_RDONLY);
1298 * Now mmap() the file.
1300 addr = mmap(0, statbuf.st_size, PROT_READ,
1301 MAP_PRIVATE, fd, 0);
1302 if( addr == (char *) 0xffffffff )
1305 ahdr = (struct exec *) addr;
1307 staboff = N_SYMOFF(*ahdr);
1308 stroff = N_STROFF(*ahdr);
1309 rtn = DEBUG_ParseStabs(addr, 0,
1313 statbuf.st_size - stroff);
1316 * Give a nice status message here...
1318 fprintf( stderr, "Loading symbols: %s", exe_name );
1324 if( addr != (char *) 0xffffffff )
1325 munmap(addr, statbuf.st_size);
1335 * Non-linux, non-ELF platforms.
1338 DEBUG_ReadExecutableDbgInfo(void)
1344 #endif /* __ELF__ */