1 /* -*- tab-width: 8; c-basic-offset: 2 -*- */
4 * File stabs.c - read stabs information from the wine executable itself.
6 * Copyright (C) 1996, Eric Youngdale.
7 * 1999, 2000 Eric Pouech
12 #include <sys/types.h>
15 #ifdef HAVE_SYS_MMAN_H
24 #define PATH_MAX _MAX_PATH
29 #if defined(__svr4__) || defined(__sun)
40 #elif defined(__EMX__)
77 struct stab_nlist *n_next;
83 unsigned long n_value;
87 * This is used to keep track of known datatypes so that we don't redefine
88 * them over and over again. It sucks up lots of memory otherwise.
92 struct known_typedef * next;
95 struct datatype * types[1];
98 #define NR_STAB_HASH 521
100 struct known_typedef * ktd_head[NR_STAB_HASH] = {NULL,};
102 static unsigned int stab_hash( const char * name )
104 unsigned int hash = 0;
112 hash = (hash << 4) + *p++;
114 if( (tmp = (hash & 0xf0000000)) )
120 return hash % NR_STAB_HASH;
124 static void stab_strcpy(char * dest, const char * source)
127 * A strcpy routine that stops when we hit the ':' character.
128 * Faster than copying the whole thing, and then nuking the
131 while(*source != '\0' && *source != ':')
140 struct datatype** vector;
144 #define MAX_INCLUDES 256
146 static include_def* include_defs = NULL;
147 static int num_include_def = 0;
148 static int num_alloc_include_def = 0;
149 static int cu_include_stack[MAX_INCLUDES];
150 static int cu_include_stk_idx = 0;
151 static struct datatype** cu_vector = NULL;
152 static int cu_nrofentries = 0;
156 DEBUG_CreateInclude(const char* file, unsigned long val)
158 if (num_include_def == num_alloc_include_def)
160 num_alloc_include_def += 256;
161 include_defs = DBG_realloc(include_defs, sizeof(include_defs[0])*num_alloc_include_def);
162 memset(include_defs+num_include_def, 0, sizeof(include_defs[0])*256);
164 include_defs[num_include_def].name = DBG_strdup(file);
165 include_defs[num_include_def].value = val;
166 include_defs[num_include_def].vector = NULL;
167 include_defs[num_include_def].nrofentries = 0;
169 return num_include_def++;
174 DEBUG_FindInclude(const char* file, unsigned long val)
178 for (i = 0; i < num_include_def; i++)
180 if (val == include_defs[i].value &&
181 strcmp(file, include_defs[i].name) == 0)
189 DEBUG_AddInclude(int idx)
191 ++cu_include_stk_idx;
193 /* is this happen, just bump MAX_INCLUDES */
194 /* we could also handle this as another dynarray */
195 assert(cu_include_stk_idx < MAX_INCLUDES);
197 cu_include_stack[cu_include_stk_idx] = idx;
198 return cu_include_stk_idx;
203 DEBUG_ResetIncludes(void)
206 * The datatypes that we would need to use are reset when
207 * we start a new file. (at least the ones in filenr == 0
209 cu_include_stk_idx = 0;/* keep 0 as index for the .c file itself */
210 memset(cu_vector, 0, sizeof(cu_vector[0]) * cu_nrofentries);
215 DEBUG_FreeIncludes(void)
219 DEBUG_ResetIncludes();
221 for (i = 0; i < num_include_def; i++)
223 DBG_free(include_defs[i].name);
224 DBG_free(include_defs[i].vector);
226 DBG_free(include_defs);
229 num_alloc_include_def = 0;
235 #define MAX_TD_NESTING 128
239 DEBUG_FileSubNr2StabEnum(int filenr, int subnr)
241 struct datatype** ret;
243 /* DEBUG_Printf(DBG_CHN_MESG, "creating type id for (%d,%d)\n", filenr, subnr); */
245 /* FIXME: I could perhaps create a dummy include_def for each compilation
246 * unit which would allow not to handle those two cases separately
250 if (cu_nrofentries <= subnr)
252 cu_vector = DBG_realloc(cu_vector, sizeof(cu_vector[0])*(subnr+1));
253 memset(cu_vector+cu_nrofentries, 0, sizeof(cu_vector[0])*(subnr+1-cu_nrofentries));
254 cu_nrofentries = subnr + 1;
256 ret = &cu_vector[subnr];
262 assert(filenr <= cu_include_stk_idx);
264 idef = &include_defs[cu_include_stack[filenr]];
266 if (idef->nrofentries <= subnr)
268 idef->vector = DBG_realloc(idef->vector, sizeof(idef->vector[0])*(subnr+1));
269 memset(idef->vector + idef->nrofentries, 0, sizeof(idef->vector[0])*(subnr+1-idef->nrofentries));
270 idef->nrofentries = subnr + 1;
272 ret = &idef->vector[subnr];
274 /* DEBUG_Printf(DBG_CHN_MESG,"(%d,%d) is %d\n",filenr,subnr,ret); */
280 DEBUG_ReadTypeEnumBackwards(char*x) {
287 filenr=strtol(x,&x,10); /* <int> */
289 subnr=strtol(x,&x,10); /* <int> */
292 while ((*x>='0') && (*x<='9'))
297 return DEBUG_FileSubNr2StabEnum(filenr,subnr);
302 DEBUG_ReadTypeEnum(char **x) {
307 filenr=strtol(*x,x,10); /* <int> */
309 subnr=strtol(*x,x,10); /* <int> */
313 subnr = strtol(*x,x,10); /* <int> */
315 return DEBUG_FileSubNr2StabEnum(filenr,subnr);
320 DEBUG_RegisterTypedef(const char * name, struct datatype ** types, int ndef)
323 struct known_typedef * ktd;
328 ktd = (struct known_typedef *) DBG_alloc(sizeof(struct known_typedef)
329 + (ndef - 1) * sizeof(struct datatype *));
331 hash = stab_hash(name);
333 ktd->name = DBG_strdup(name);
335 memcpy(&ktd->types[0], types, ndef * sizeof(struct datatype *));
336 ktd->next = ktd_head[hash];
337 ktd_head[hash] = ktd;
344 DEBUG_HandlePreviousTypedef(const char * name, const char * stab)
347 enum debug_type expect;
349 struct known_typedef * ktd;
352 hash = stab_hash(name);
354 for(ktd = ktd_head[hash]; ktd; ktd = ktd->next)
355 if ((ktd->name[0] == name[0]) && (strcmp(name, ktd->name) == 0) )
359 * Didn't find it. This must be a new one.
365 * Examine the stab to make sure it has the same number of definitions.
368 for(ptr = strchr(stab, '='); ptr; ptr = strchr(ptr+1, '='))
370 if( count >= ktd->ndefs )
374 * Make sure the types of all of the objects is consistent with
375 * what we have already parsed.
389 case '(': /* it's mainly a ref to another typedef, skip it */
406 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%c).\n",ptr[1]);
409 if( expect != -1 && expect != DEBUG_GetType(ktd->types[count]) )
414 if( ktd->ndefs != count )
418 * Go through, dig out all of the type numbers, and substitute the
419 * appropriate things.
422 for(ptr = strchr(stab, '='); ptr; ptr = strchr(ptr+1, '='))
423 *DEBUG_ReadTypeEnumBackwards(ptr-1) = ktd->types[count++];
428 static int DEBUG_FreeRegisteredTypedefs(void)
432 struct known_typedef * ktd;
433 struct known_typedef * next;
436 for(j=0; j < NR_STAB_HASH; j++ )
438 for(ktd = ktd_head[j]; ktd; ktd = next)
454 DEBUG_ParseTypedefStab(char * ptr, const char * typename)
459 struct datatype * curr_type;
460 struct datatype * datatype;
461 struct datatype * curr_types[MAX_TD_NESTING];
462 char element_name[1024];
465 const char * orig_typename;
471 orig_typename = typename;
473 if( DEBUG_HandlePreviousTypedef(typename, ptr) )
477 * Go from back to front. First we go through and figure out what
478 * type numbers we need, and register those types. Then we go in
479 * and fill the details.
482 for( c = strchr(ptr, '='); c != NULL; c = strchr(c + 1, '=') )
485 * Back up until we get to a non-numeric character, to get datatype
487 struct datatype** dt = DEBUG_ReadTypeEnumBackwards(c-1);
489 if( ntypes >= MAX_TD_NESTING )
492 * If this ever happens, just bump the counter.
494 DEBUG_Printf(DBG_CHN_MESG, "Typedef nesting overflow\n");
501 *dt = DEBUG_NewDataType(DT_POINTER, NULL);
502 curr_types[ntypes++] = *dt;
506 *dt = DEBUG_NewDataType(DT_STRUCT, typename);
507 curr_types[ntypes++] = *dt;
510 *dt = DEBUG_NewDataType(DT_ARRAY, NULL);
511 curr_types[ntypes++] = *dt;
514 /* will be handled in next loop,
515 * just a ref to another type
517 curr_types[ntypes++] = NULL;
521 *dt = DEBUG_NewDataType(DT_BASIC, typename);
522 curr_types[ntypes++] = *dt;
525 stab_strcpy(element_name, c + 3);
526 *dt = DEBUG_NewDataType(DT_STRUCT, element_name);
527 curr_types[ntypes++] = *dt;
530 *dt = DEBUG_NewDataType(DT_ENUM, NULL);
531 curr_types[ntypes++] = *dt;
534 *dt = DEBUG_NewDataType(DT_FUNC, NULL);
535 curr_types[ntypes++] = *dt;
538 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%c).\n",c[1]);
546 * OK, now take a second sweep through. Now we will be digging
547 * out the definitions of the various components, and storing
548 * them in the skeletons that we have already allocated. We take
549 * a right-to left search as this is much easier to parse.
551 for( c = strrchr(ptr, '='); c != NULL; c = strrchr(ptr, '=') )
553 struct datatype** dt = DEBUG_ReadTypeEnumBackwards(c-1);
554 struct datatype** dt2;
575 datatype = *DEBUG_ReadTypeEnum(&tc);
576 DEBUG_SetPointerType(curr_type, datatype);
584 dt2 = DEBUG_ReadTypeEnum(&tc);
590 else if (!*dt && !*dt2)
592 /* this should be a basic type, define it */
593 *dt2 = *dt = DEBUG_NewDataType(DT_BASIC, typename);
597 DEBUG_Printf(DBG_CHN_MESG, "Unknown condition %p %p (%s)\n", *dt, *dt2, ptr);
603 curr_types[ntp--] = *dt;
609 * We have already handled these above.
615 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo>,<int>,<int>;; */
619 DEBUG_ReadTypeEnum(&tc);
621 arrmin = strtol(tc, &tc, 10); /* <int> */
623 arrmax = strtol(tc, &tc, 10); /* <int> */
625 datatype = *DEBUG_ReadTypeEnum(&tc); /* <typeinfo> */
630 DEBUG_SetArrayParams(curr_type, arrmin, arrmax, datatype);
638 if( DEBUG_SetStructSize(curr_type, strtol(tc, &tc, 10)) == FALSE )
641 * We have already filled out this structure. Nothing to do,
642 * so just skip forward to the end of the definition.
644 while( tc[0] != ';' && tc[1] != ';' )
657 * Now parse the individual elements of the structure/union.
668 datatype = *DEBUG_ReadTypeEnum(&tc);
671 offset = strtol(tc, &tc, 10);
673 size = strtol(tc, &tc, 10);
676 DEBUG_AddStructElement(curr_type, element_name, datatype,
681 /* ... but proceed parsing to the end of the stab */
682 DEBUG_Printf(DBG_CHN_MESG, "failure on %s %s\n", ptr, ti);
689 /* if we had a undeclared value this one is undeclared too.
690 * remove it from the stab_types.
691 * I just set it to NULL to detect bugs in my thoughtprocess.
692 * FIXME: leaks the memory for the structure elements.
693 * FIXME: such structures should have been optimized away
707 * Now parse the individual elements of the structure/union.
716 offset = strtol(tc, &tc, 10);
718 DEBUG_AddStructElement(curr_type, element_name, NULL, offset, 0);
726 DEBUG_Printf(DBG_CHN_MESG, "Unknown type (%c).\n",c[1]);
731 * Now register the type so that if we encounter it again, we will know
734 DEBUG_RegisterTypedef(orig_typename, curr_types, ntypes);
739 static struct datatype *
740 DEBUG_ParseStabType(const char * stab)
745 * Look through the stab definition, and figure out what datatype
746 * this represents. If we have something we know about, assign the
749 c = strchr(stab, ':');
755 * The next character says more about the type (i.e. data, function, etc)
756 * of symbol. Skip it.
761 * The next is either an integer or a (integer,integer).
762 * The DEBUG_ReadTypeEnum takes care that stab_types is large enough.
764 return *DEBUG_ReadTypeEnum(&c);
768 DEBUG_ParseStabs(char * addr, unsigned int load_offset,
769 unsigned int staboff, int stablen,
770 unsigned int strtaboff, int strtablen)
772 struct name_hash * curr_func = NULL;
773 struct wine_locals * curr_loc = NULL;
774 struct name_hash * curr_sym = NULL;
775 char currpath[PATH_MAX];
777 int in_external_file = FALSE;
785 struct stab_nlist * stab_ptr;
788 char * subpath = NULL;
791 nstab = stablen / sizeof(struct stab_nlist);
792 stab_ptr = (struct stab_nlist *) (addr + staboff);
793 strs = (char *) (addr + strtaboff);
795 memset(currpath, 0, sizeof(currpath));
798 * Allocate a buffer into which we can build stab strings for cases
799 * where the stab is continued over multiple lines.
802 stabbuff = (char *) DBG_alloc(stabbufflen);
806 for(i=0; i < nstab; i++, stab_ptr++ )
808 ptr = strs + (unsigned int) stab_ptr->n_un.n_name;
809 if( ptr[strlen(ptr) - 1] == '\\' )
812 * Indicates continuation. Append this to the buffer, and go onto the
813 * next record. Repeat the process until we find a stab without the
814 * '/' character, as this indicates we have the whole thing.
817 if( strlen(stabbuff) + len > stabbufflen )
819 stabbufflen += 65536;
820 stabbuff = (char *) DBG_realloc(stabbuff, stabbufflen);
822 strncat(stabbuff, ptr, len - 1);
825 else if( stabbuff[0] != '\0' )
827 strcat( stabbuff, ptr);
831 if( strchr(ptr, '=') != NULL )
834 * The stabs aren't in writable memory, so copy it over so we are
835 * sure we can scribble on it.
837 if( ptr != stabbuff )
839 strcpy(stabbuff, ptr);
842 stab_strcpy(symname, ptr);
843 DEBUG_ParseTypedefStab(ptr, symname);
846 switch(stab_ptr->n_type)
850 * These are useless with ELF. They have no value, and you have to
851 * read the normal symbol table to get the address. Thus we
852 * ignore them, and when we process the normal symbol table
853 * we should do the right thing.
855 * With a.out or mingw, they actually do make some amount of sense.
857 new_value.addr.seg = 0;
858 new_value.type = DEBUG_ParseStabType(ptr);
859 new_value.addr.off = load_offset + stab_ptr->n_value;
860 new_value.cookie = DV_TARGET;
862 stab_strcpy(symname, ptr);
864 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
865 SYM_WINE | SYM_DATA | SYM_INVALID );
867 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
868 SYM_WINE | SYM_DATA );
874 * We need to keep track of these so we get symbol scoping
875 * right for local variables. For now, we just ignore them.
876 * The hooks are already there for dealing with this however,
877 * so all we need to do is to keep count of the nesting level,
878 * and find the RBRAC for each matching LBRAC.
884 * These are static symbols and BSS symbols.
886 new_value.addr.seg = 0;
887 new_value.type = DEBUG_ParseStabType(ptr);
888 new_value.addr.off = load_offset + stab_ptr->n_value;
889 new_value.cookie = DV_TARGET;
891 stab_strcpy(symname, ptr);
892 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
893 SYM_WINE | SYM_DATA );
897 * These are function parameters.
899 if( curr_func != NULL && !in_external_file )
901 stab_strcpy(symname, ptr);
902 curr_loc = DEBUG_AddLocal( curr_func, 0,
903 stab_ptr->n_value, 0, 0, symname );
904 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
908 if( curr_func != NULL && !in_external_file )
910 stab_strcpy(symname, ptr);
911 curr_loc = DEBUG_AddLocal( curr_func, stab_ptr->n_value + 1,
913 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
917 if( curr_func != NULL && !in_external_file )
919 stab_strcpy(symname, ptr);
920 curr_loc = DEBUG_AddLocal( curr_func, 0,
921 stab_ptr->n_value, 0, 0, symname );
922 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
927 * This is a line number. These are always relative to the start
928 * of the function (N_FUN), and this makes the lookup easier.
930 if( curr_func != NULL && !in_external_file )
933 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
938 * This isn't right. The order of the stabs is different under
939 * a.out, and as a result we would end up attaching the line
940 * number to the wrong function.
942 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
943 stab_ptr->n_value - curr_func->addr.off);
950 * First, clean up the previous function we were working on.
952 DEBUG_Normalize(curr_func);
955 * For now, just declare the various functions. Later
956 * on, we will add the line number information and the
959 if( !in_external_file)
961 stab_strcpy(symname, ptr);
964 new_value.addr.seg = 0;
965 new_value.type = DEBUG_ParseStabType(ptr);
966 new_value.addr.off = load_offset + stab_ptr->n_value;
967 new_value.cookie = DV_TARGET;
969 * Copy the string to a temp buffer so we
970 * can kill everything after the ':'. We do
971 * it this way because otherwise we end up dirtying
972 * all of the pages related to the stabs, and that
973 * sucks up swap space like crazy.
975 curr_func = DEBUG_AddSymbol( symname, &new_value, currpath,
976 SYM_WINE | SYM_FUNC);
980 /* some GCC seem to use a N_FUN "" to mark the end of a function */
987 * Don't add line number information for this function
995 * This indicates a new source file. Append the records
996 * together, to build the correct path name.
1000 * With a.out, there is no NULL string N_SO entry at the end of
1001 * the file. Thus when we find non-consecutive entries,
1002 * we consider that a new file is started.
1004 if( last_nso < i-1 )
1007 DEBUG_Normalize(curr_func);
1018 DEBUG_Normalize(curr_func);
1024 strcat(currpath, ptr);
1026 strcpy(currpath, ptr);
1028 DEBUG_ResetIncludes();
1034 * This indicates we are including stuff from an include file.
1035 * If this is the main source, enable the debug stuff, otherwise
1038 in_external_file = !(subpath == NULL || strcmp(ptr, subpath) == 0);
1042 strtabinc = stab_ptr->n_value;
1043 DEBUG_Normalize(curr_func);
1048 * Ignore this. We don't care what it points to.
1052 DEBUG_AddInclude(DEBUG_CreateInclude(ptr, stab_ptr->n_value));
1057 DEBUG_AddInclude(DEBUG_FindInclude(ptr, stab_ptr->n_value));
1061 * Always ignore these. GCC doesn't even generate them.
1065 DEBUG_Printf(DBG_CHN_MESG, "Unkown stab type 0x%02x\n", stab_ptr->n_type);
1072 DEBUG_Printf(DBG_CHN_MESG, "%d %x %s\n", stab_ptr->n_type,
1073 (unsigned int) stab_ptr->n_value,
1074 strs + (unsigned int) stab_ptr->n_un.n_name);
1078 DEBUG_FreeRegisteredTypedefs();
1079 DEBUG_FreeIncludes();
1087 * Walk through the entire symbol table and add any symbols we find there.
1088 * This can be used in cases where we have stripped ELF shared libraries,
1089 * or it can be used in cases where we have data symbols for which the address
1090 * isn't encoded in the stabs.
1092 * This is all really quite easy, since we don't have to worry about line
1093 * numbers or local data variables.
1097 DEBUG_ProcessElfSymtab(char * addr, unsigned int load_offset,
1098 Elf32_Shdr * symtab, Elf32_Shdr * strtab)
1100 char * curfile = NULL;
1101 struct name_hash * curr_sym = NULL;
1104 DBG_VALUE new_value;
1111 symp = (Elf32_Sym *) (addr + symtab->sh_offset);
1112 nsym = symtab->sh_size / sizeof(*symp);
1113 strp = (char *) (addr + strtab->sh_offset);
1115 for(i=0; i < nsym; i++, symp++)
1118 * Ignore certain types of entries which really aren't of that much
1121 if( ELF32_ST_TYPE(symp->st_info) == STT_SECTION ||
1122 symp->st_shndx == STN_UNDEF )
1127 symname = strp + symp->st_name;
1130 * Save the name of the current file, so we have a way of tracking
1131 * static functions/data.
1133 if( ELF32_ST_TYPE(symp->st_info) == STT_FILE )
1140 * See if we already have something for this symbol.
1141 * If so, ignore this entry, because it would have come from the
1142 * stabs or from a previous symbol. If the value is different,
1143 * we will have to keep the darned thing, because there can be
1144 * multiple local symbols by the same name.
1146 if( (DEBUG_GetSymbolValue(symname, -1, &new_value, FALSE ) == TRUE)
1147 && (new_value.addr.off == (load_offset + symp->st_value)) )
1150 new_value.addr.seg = 0;
1151 new_value.type = NULL;
1152 new_value.addr.off = load_offset + symp->st_value;
1153 new_value.cookie = DV_TARGET;
1154 flags = SYM_WINE | (ELF32_ST_BIND(symp->st_info) == STT_FUNC
1155 ? SYM_FUNC : SYM_DATA);
1156 if( ELF32_ST_BIND(symp->st_info) == STB_GLOBAL )
1157 curr_sym = DEBUG_AddSymbol( symname, &new_value, NULL, flags );
1159 curr_sym = DEBUG_AddSymbol( symname, &new_value, curfile, flags );
1162 * Record the size of the symbol. This can come in handy in
1163 * some cases. Not really used yet, however.
1165 if( symp->st_size != 0 )
1166 DEBUG_SetSymbolSize(curr_sym, symp->st_size);
1173 DEBUG_ProcessElfObject(const char * filename, unsigned int load_offset)
1176 char * addr = (char*)0xffffffff;
1178 struct stat statbuf;
1188 * Make sure we can stat and open this file.
1190 if( filename == NULL )
1193 if (stat(filename, &statbuf) == -1)
1195 char *s,*t,*fn,*paths;
1196 if (strchr(filename,'/'))
1198 paths = DBG_strdup(getenv("PATH"));
1203 fn = (char*)DBG_alloc(strlen(filename)+1+strlen(s)+1);
1206 strcat(fn,filename);
1207 if ((rtn = DEBUG_ProcessElfObject(fn,load_offset))) {
1213 if (t) s = t+1; else break;
1215 if (!s || !*s) DEBUG_Printf(DBG_CHN_MESG," not found");
1220 if (DEBUG_FindModuleByName(filename, DM_TYPE_ELF))
1223 DEBUG_Printf(DBG_CHN_MESG, "Loading stabs debug symbols from %s (0x%08lx)\n",
1224 filename, load_offset);
1227 * Now open the file, so that we can mmap() it.
1229 if ((fd = open(filename, O_RDONLY)) == -1)
1233 * Now mmap() the file.
1235 addr = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
1236 if (addr == (char*)0xffffffff)
1240 * Next, we need to find a few of the internal ELF headers within
1241 * this thing. We need the main executable header, and the section
1244 ehptr = (Elf32_Ehdr *) addr;
1246 if( load_offset == 0 )
1247 DEBUG_RegisterELFModule(ehptr->e_entry, filename);
1249 DEBUG_RegisterELFModule(load_offset, filename);
1251 spnt = (Elf32_Shdr *) (addr + ehptr->e_shoff);
1252 nsect = ehptr->e_shnum;
1253 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
1255 stabsect = stabstrsect = -1;
1257 for(i=0; i < nsect; i++)
1259 if( strcmp(shstrtab + spnt[i].sh_name, ".stab") == 0 )
1262 if( strcmp(shstrtab + spnt[i].sh_name, ".stabstr") == 0 )
1266 if( stabsect == -1 || stabstrsect == -1 ) {
1267 DEBUG_Printf(DBG_CHN_WARN, "no .stab section\n");
1272 * OK, now just parse all of the stabs.
1274 if (!(rtn = DEBUG_ParseStabs(addr, load_offset,
1275 spnt[stabsect].sh_offset,
1276 spnt[stabsect].sh_size,
1277 spnt[stabstrsect].sh_offset,
1278 spnt[stabstrsect].sh_size))) {
1279 DEBUG_Printf(DBG_CHN_WARN, "bad stabs\n");
1283 for(i=0; i < nsect; i++)
1285 if( (strcmp(shstrtab + spnt[i].sh_name, ".symtab") == 0)
1286 && (spnt[i].sh_type == SHT_SYMTAB) )
1287 DEBUG_ProcessElfSymtab(addr, load_offset,
1288 spnt + i, spnt + spnt[i].sh_link);
1290 if( (strcmp(shstrtab + spnt[i].sh_name, ".dynsym") == 0)
1291 && (spnt[i].sh_type == SHT_DYNSYM) )
1292 DEBUG_ProcessElfSymtab(addr, load_offset,
1293 spnt + i, spnt + spnt[i].sh_link);
1298 if (addr != (char*)0xffffffff)
1299 munmap(addr, statbuf.st_size);
1301 if (fd != -1) close(fd);
1307 DEBUG_ReadExecutableDbgInfo(const char* exe_name)
1310 struct r_debug dbg_hdr;
1319 * Make sure we can stat and open this file.
1321 if( exe_name == NULL )
1324 fprintf( stderr, "Loading symbols: %s", exe_name );
1325 DEBUG_ProcessElfObject(exe_name, 0);
1327 /* previous step should have loaded symbol _DYNAMIC if it exists inside
1328 * the main executable
1330 if (!DEBUG_GetSymbolValue("_DYNAMIC", -1, &val, FALSE)) {
1331 fprintf(stderr, "Can't find symbol _DYNAMIC\n");
1336 if (!DEBUG_READ_MEM_VERBOSE((void*)val.addr.off, &dyn, sizeof(dyn)))
1338 val.addr.off += sizeof(dyn);
1339 } while (dyn.d_tag != DT_DEBUG && dyn.d_tag != DT_NULL);
1340 if (dyn.d_tag == DT_NULL) goto leave;
1343 * OK, now dig into the actual tables themselves.
1345 if (!DEBUG_READ_MEM_VERBOSE((void*)dyn.d_un.d_ptr, &dbg_hdr, sizeof(dbg_hdr)))
1349 * Now walk the linked list. In all known ELF implementations,
1350 * the dynamic loader maintains this linked list for us. In some
1351 * cases the first entry doesn't appear with a name, in other cases it
1354 for (lm_addr = (u_long)dbg_hdr.r_map; lm_addr; lm_addr = (u_long)lm.l_next)
1356 if (!DEBUG_READ_MEM_VERBOSE((void*)lm_addr, &lm, sizeof(lm)))
1358 if (lm.l_addr != 0 &&
1359 DEBUG_READ_MEM_VERBOSE((void*)lm.l_addr, &ehdr, sizeof(ehdr)) &&
1360 ehdr.e_type == ET_DYN && /* only look at dynamic modules */
1361 lm.l_name != NULL &&
1362 DEBUG_READ_MEM_VERBOSE(lm.l_name, bufstr, sizeof(bufstr))) {
1363 bufstr[sizeof(bufstr) - 1] = '\0';
1364 DEBUG_ProcessElfObject(bufstr, lm.l_addr);
1374 #else /* !__ELF__ */
1377 DEBUG_ProcessElfObject(const char * filename, unsigned int load_offset)
1383 DEBUG_ReadExecutableDbgInfo(void)
1388 #endif /* __ELF__ */