Release 970112
[wine/multimedia.git] / debugger / stabs.c
blob0c1ddf1689be9a6c8a75255b0e6678e11774c7db
1 /*
2 * File stabs.c - read stabs information from the wine executable itself.
4 * Copyright (C) 1996, Eric Youngdale.
5 */
7 #include <fcntl.h>
8 #include <sys/stat.h>
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <sys/mman.h>
16 #include "win.h"
17 #include "debugger.h"
18 #include "xmalloc.h"
20 #ifdef __svr4__
21 #define __ELF__
22 #endif
24 #ifdef __ELF__
25 #include <elf.h>
26 #include <link.h>
27 #else
28 #include <a.out.h>
29 #endif
31 #ifndef N_UNDF
32 #define N_UNDF 0x00
33 #endif
35 #define N_GSYM 0x20
36 #define N_FUN 0x24
37 #define N_STSYM 0x26
38 #define N_LCSYM 0x28
39 #define N_MAIN 0x2a
40 #define N_ROSYM 0x2c
41 #define N_OPT 0x3c
42 #define N_RSYM 0x40
43 #define N_SLINE 0x44
44 #define N_SO 0x64
45 #define N_LSYM 0x80
46 #define N_BINCL 0x82
47 #define N_SOL 0x84
48 #define N_PSYM 0xa0
49 #define N_EINCL 0xa2
50 #define N_LBRAC 0xc0
51 #define N_RBRAC 0xe0
55 * This is how we translate stab types into our internal representations
56 * of datatypes.
58 static struct datatype ** stab_types = NULL;
59 static int num_stab_types = 0;
62 * Set so that we know the main executable name and path.
64 char * DEBUG_argv0;
66 struct stab_nlist {
67 union {
68 char *n_name;
69 struct stab_nlist *n_next;
70 long n_strx;
71 } n_un;
72 unsigned char n_type;
73 char n_other;
74 short n_desc;
75 unsigned long n_value;
78 static void stab_strcpy(char * dest, const char * source)
81 * A strcpy routine that stops when we hit the ':' character.
82 * Faster than copying the whole thing, and then nuking the
83 * ':'.
85 while(*source != '\0' && *source != ':')
87 *dest++ = *source++;
89 *dest++ = '\0';
93 static
94 int
95 DEBUG_ParseTypedefStab(char * ptr, const char * typename)
97 int arrmax;
98 int arrmin;
99 char * c;
100 struct datatype * curr_type;
101 struct datatype * datatype;
102 char element_name[1024];
103 int offset;
104 int rtn = FALSE;
105 int size;
106 char * tc;
107 char * tc2;
108 int typenum;
111 * Go from back to front. First we go through and figure out what type numbers
112 * we need, and register those types. Then we go in and fill the details.
114 for( c = strchr(ptr, '='); c != NULL; c = strchr(c + 1, '=') )
117 * Back up until we get to a non-numeric character. This is the type
118 * number.
120 tc = c - 1;
121 while( *tc >= '0' && *tc <= '9' )
123 tc--;
125 typenum = atol(tc + 1);
126 if( num_stab_types <= typenum )
128 num_stab_types = typenum + 32;
129 stab_types = (struct datatype **) xrealloc(stab_types,
130 num_stab_types * sizeof(struct datatype *));
131 if( stab_types == NULL )
133 goto leave;
137 switch(c[1])
139 case '*':
140 stab_types[typenum] = DEBUG_NewDataType(POINTER, NULL);
141 break;
142 case 's':
143 case 'u':
144 stab_types[typenum] = DEBUG_NewDataType(STRUCT, typename);
145 break;
146 case 'a':
147 stab_types[typenum] = DEBUG_NewDataType(ARRAY, NULL);
148 break;
149 case '1':
150 case 'r':
151 stab_types[typenum] = DEBUG_NewDataType(BASIC, typename);
152 break;
153 case 'x':
154 stab_strcpy(element_name, c + 3);
155 stab_types[typenum] = DEBUG_NewDataType(STRUCT, element_name);
156 break;
157 case 'e':
158 stab_types[typenum] = DEBUG_NewDataType(ENUM, NULL);
159 break;
160 case 'f':
161 stab_types[typenum] = DEBUG_NewDataType(FUNC, NULL);
162 break;
163 default:
164 fprintf(stderr, "Unknown type.\n");
166 typename = NULL;
170 * OK, now take a second sweep through. Now we will be digging out the definitions
171 * of the various components, and storing them in the skeletons that we have already
172 * allocated. We take a right-to left search as this is much easier to parse.
174 for( c = strrchr(ptr, '='); c != NULL; c = strrchr(ptr, '=') )
177 * Back up until we get to a non-numeric character. This is the type
178 * number.
180 tc = c - 1;
181 while( *tc >= '0' && *tc <= '9' )
183 tc--;
185 typenum = atol(tc + 1);
186 curr_type = stab_types[typenum];
188 switch(c[1])
190 case 'x':
191 tc = c + 3;
192 while( *tc != ':' )
194 tc ++;
196 tc++;
197 if( *tc == '\0' )
199 *c = '\0';
201 else
203 strcpy(c, tc);
206 break;
207 case '*':
208 case 'f':
209 tc = c + 2;
210 datatype = stab_types[strtol(tc, &tc, 10)];
211 DEBUG_SetPointerType(curr_type, datatype);
212 if( *tc == '\0' )
214 *c = '\0';
216 else
218 strcpy(c, tc);
220 break;
221 case '1':
222 case 'r':
224 * We have already handled these above.
226 *c = '\0';
227 break;
228 case 'a':
229 tc = c + 5;
230 arrmin = strtol(tc, &tc, 10);
231 tc++;
232 arrmax = strtol(tc, &tc, 10);
233 tc++;
234 datatype = stab_types[strtol(tc, &tc, 10)];
235 if( *tc == '\0' )
237 *c = '\0';
239 else
241 strcpy(c, tc);
244 DEBUG_SetArrayParams(curr_type, arrmin, arrmax, datatype);
245 break;
246 case 's':
247 case 'u':
248 tc = c + 2;
249 DEBUG_SetStructSize(curr_type, strtol(tc, &tc, 10));
251 * Now parse the individual elements of the structure/union.
253 while(*tc != ';')
255 tc2 = element_name;
256 while(*tc != ':')
258 *tc2++ = *tc++;
260 tc++;
261 *tc2++ = '\0';
262 datatype = stab_types[strtol(tc, &tc, 10)];
263 tc++;
264 offset = strtol(tc, &tc, 10);
265 tc++;
266 size = strtol(tc, &tc, 10);
267 tc++;
268 DEBUG_AddStructElement(curr_type, element_name, datatype, offset, size);
270 if( *tc == '\0' )
272 *c = '\0';
274 else
276 strcpy(c, tc + 1);
278 break;
279 case 'e':
280 tc = c + 2;
282 * Now parse the individual elements of the structure/union.
284 while(*tc != ';')
286 tc2 = element_name;
287 while(*tc != ':')
289 *tc2++ = *tc++;
291 tc++;
292 *tc2++ = '\0';
293 offset = strtol(tc, &tc, 10);
294 tc++;
295 DEBUG_AddStructElement(curr_type, element_name, NULL, offset, 0);
297 if( *tc == '\0' )
299 *c = '\0';
301 else
303 strcpy(c, tc + 1);
305 break;
306 default:
307 fprintf(stderr, "Unknown type.\n");
308 break;
312 rtn = TRUE;
314 leave:
316 return rtn;
320 static struct datatype *
321 DEBUG_ParseStabType(const char * stab)
323 char * c;
324 int typenum;
327 * Look through the stab definition, and figure out what datatype
328 * this represents. If we have something we know about, assign the
329 * type.
331 c = strchr(stab, ':');
332 if( c == NULL )
334 return NULL;
337 c++;
339 * The next character says more about the type (i.e. data, function, etc)
340 * of symbol. Skip it.
342 c++;
344 typenum = atol(c);
346 if( typenum < num_stab_types && stab_types[typenum] != NULL )
348 return stab_types[typenum];
351 return NULL;
354 static
356 DEBUG_ParseStabs(char * addr, unsigned int load_offset,
357 unsigned int staboff, int stablen,
358 unsigned int strtaboff, int strtablen)
360 struct name_hash * curr_func = NULL;
361 struct wine_locals * curr_loc = NULL;
362 struct name_hash * curr_sym = NULL;
363 char currpath[PATH_MAX];
364 int i;
365 int ignore = FALSE;
366 int last_nso = -1;
367 int len;
368 DBG_ADDR new_addr;
369 int nstab;
370 char * ptr;
371 char * stabbuff;
372 int stabbufflen;
373 struct stab_nlist * stab_ptr;
374 char * strs;
375 int strtabinc;
376 char * subpath = NULL;
377 char symname[4096];
379 nstab = stablen / sizeof(struct stab_nlist);
380 stab_ptr = (struct stab_nlist *) (addr + staboff);
381 strs = (char *) (addr + strtaboff);
383 memset(currpath, 0, sizeof(currpath));
386 * Allocate a buffer into which we can build stab strings for cases
387 * where the stab is continued over multiple lines.
389 stabbufflen = 65536;
390 stabbuff = (char *) xmalloc(stabbufflen);
391 if( stabbuff == NULL )
393 goto leave;
396 strtabinc = 0;
397 stabbuff[0] = '\0';
398 for(i=0; i < nstab; i++, stab_ptr++ )
400 ptr = strs + (unsigned int) stab_ptr->n_un.n_name;
401 if( ptr[strlen(ptr) - 1] == '\\' )
404 * Indicates continuation. Append this to the buffer, and go onto the
405 * next record. Repeat the process until we find a stab without the
406 * '/' character, as this indicates we have the whole thing.
408 len = strlen(ptr);
409 if( strlen(stabbuff) + len > stabbufflen )
411 stabbufflen += 65536;
412 stabbuff = (char *) xrealloc(stabbuff, stabbufflen);
413 if( stabbuff == NULL )
415 goto leave;
418 strncat(stabbuff, ptr, len - 1);
419 continue;
421 else if( stabbuff[0] != '\0' )
423 strcat( stabbuff, ptr);
424 ptr = stabbuff;
427 if( strchr(ptr, '=') != NULL )
430 * The stabs aren't in writable memory, so copy it over so we are
431 * sure we can scribble on it.
433 if( ptr != stabbuff )
435 strcpy(stabbuff, ptr);
436 ptr = stabbuff;
438 stab_strcpy(symname, ptr);
439 DEBUG_ParseTypedefStab(ptr, symname);
442 switch(stab_ptr->n_type)
444 case N_GSYM:
446 * These are useless with ELF. They have no value, and you have to
447 * read the normal symbol table to get the address. Thus we
448 * ignore them, and when we process the normal symbol table
449 * we should do the right thing.
451 * With a.out, they actually do make some amount of sense.
453 new_addr.seg = 0;
454 new_addr.type = DEBUG_ParseStabType(ptr);
455 new_addr.off = load_offset + stab_ptr->n_value;
457 stab_strcpy(symname, ptr);
458 #ifdef __ELF__
459 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
460 SYM_WINE | SYM_DATA | SYM_INVALID);
461 #else
462 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
463 SYM_WINE | SYM_DATA );
464 #endif
465 break;
466 case N_RBRAC:
467 case N_LBRAC:
469 * We need to keep track of these so we get symbol scoping
470 * right for local variables. For now, we just ignore them.
471 * The hooks are already there for dealing with this however,
472 * so all we need to do is to keep count of the nesting level,
473 * and find the RBRAC for each matching LBRAC.
475 break;
476 case N_LCSYM:
477 case N_STSYM:
479 * These are static symbols and BSS symbols.
481 new_addr.seg = 0;
482 new_addr.type = DEBUG_ParseStabType(ptr);
483 new_addr.off = load_offset + stab_ptr->n_value;
485 stab_strcpy(symname, ptr);
486 curr_sym = DEBUG_AddSymbol( symname, &new_addr, currpath,
487 SYM_WINE | SYM_DATA );
488 break;
489 case N_PSYM:
491 * These are function parameters.
493 if( (curr_func != NULL)
494 && (stab_ptr->n_value != 0) )
496 stab_strcpy(symname, ptr);
497 curr_loc = DEBUG_AddLocal(curr_func, 0,
498 stab_ptr->n_value, 0, 0, symname);
499 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr));
501 break;
502 case N_RSYM:
503 if( curr_func != NULL )
505 stab_strcpy(symname, ptr);
506 curr_loc = DEBUG_AddLocal(curr_func, stab_ptr->n_value, 0, 0, 0, symname);
507 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr));
509 break;
510 case N_LSYM:
511 if( (curr_func != NULL)
512 && (stab_ptr->n_value != 0) )
514 stab_strcpy(symname, ptr);
515 DEBUG_AddLocal(curr_func, 0,
516 stab_ptr->n_value, 0, 0, symname);
518 else if (curr_func == NULL)
520 stab_strcpy(symname, ptr);
522 break;
523 case N_SLINE:
525 * This is a line number. These are always relative to the start
526 * of the function (N_FUN), and this makes the lookup easier.
528 if( curr_func != NULL )
530 #ifdef __ELF__
531 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
532 stab_ptr->n_value);
533 #else
534 #if 0
536 * This isn't right. The order of the stabs is different under
537 * a.out, and as a result we would end up attaching the line
538 * number to the wrong function.
540 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
541 stab_ptr->n_value - curr_func->addr.off);
542 #endif
543 #endif
545 break;
546 case N_FUN:
548 * First, clean up the previous function we were working on.
550 DEBUG_Normalize(curr_func);
553 * For now, just declare the various functions. Later
554 * on, we will add the line number information and the
555 * local symbols.
557 if( !ignore )
559 new_addr.seg = 0;
560 new_addr.type = DEBUG_ParseStabType(ptr);
561 new_addr.off = load_offset + stab_ptr->n_value;
563 * Copy the string to a temp buffer so we
564 * can kill everything after the ':'. We do
565 * it this way because otherwise we end up dirtying
566 * all of the pages related to the stabs, and that
567 * sucks up swap space like crazy.
569 stab_strcpy(symname, ptr);
570 curr_func = DEBUG_AddSymbol( symname, &new_addr, currpath,
571 SYM_WINE | SYM_FUNC);
573 else
576 * Don't add line number information for this function
577 * any more.
579 curr_func = NULL;
581 break;
582 case N_SO:
584 * This indicates a new source file. Append the records
585 * together, to build the correct path name.
587 #ifndef __ELF__
589 * With a.out, there is no NULL string N_SO entry at the end of
590 * the file. Thus when we find non-consecutive entries,
591 * we consider that a new file is started.
593 if( last_nso < i-1 )
595 currpath[0] = '\0';
596 DEBUG_Normalize(curr_func);
597 curr_func = NULL;
599 #endif
601 if( *ptr == '\0' )
604 * Nuke old path.
606 currpath[0] = '\0';
607 DEBUG_Normalize(curr_func);
608 curr_func = NULL;
610 * The datatypes that we would need to use are reset when
611 * we start a new file.
613 memset(stab_types, 0, num_stab_types * sizeof(stab_types));
615 else
617 strcat(currpath, ptr);
618 subpath = ptr;
620 last_nso = i;
621 break;
622 case N_SOL:
624 * This indicates we are including stuff from an include file.
625 * If this is the main source, enable the debug stuff, otherwise
626 * ignore it.
628 if( subpath == NULL || strcmp(ptr, subpath) == 0 )
630 ignore = FALSE;
632 else
634 ignore = TRUE;
635 DEBUG_Normalize(curr_func);
636 curr_func = NULL;
638 break;
639 case N_UNDF:
640 strs += strtabinc;
641 strtabinc = stab_ptr->n_value;
642 DEBUG_Normalize(curr_func);
643 curr_func = NULL;
644 break;
645 case N_OPT:
647 * Ignore this. We don't care what it points to.
649 break;
650 case N_BINCL:
651 case N_EINCL:
652 case N_MAIN:
654 * Always ignore these. GCC doesn't even generate them.
656 break;
657 default:
658 break;
661 stabbuff[0] = '\0';
663 #if 0
664 fprintf(stderr, "%d %x %s\n", stab_ptr->n_type,
665 (unsigned int) stab_ptr->n_value,
666 strs + (unsigned int) stab_ptr->n_un.n_name);
667 #endif
670 leave:
672 if( stab_types != NULL )
674 free(stab_types);
675 stab_types = NULL;
676 num_stab_types = 0;
679 return TRUE;
682 #ifdef __ELF__
685 * Walk through the entire symbol table and add any symbols we find there.
686 * This can be used in cases where we have stripped ELF shared libraries,
687 * or it can be used in cases where we have data symbols for which the address
688 * isn't encoded in the stabs.
690 * This is all really quite easy, since we don't have to worry about line
691 * numbers or local data variables.
693 static
695 DEBUG_ProcessElfSymtab(char * addr, unsigned int load_offset,
696 Elf32_Shdr * symtab, Elf32_Shdr * strtab)
698 char * curfile = NULL;
699 struct name_hash * curr_sym = NULL;
700 int flags;
701 int i;
702 DBG_ADDR new_addr;
703 int nsym;
704 char * strp;
705 char * symname;
706 Elf32_Sym * symp;
709 symp = (Elf32_Sym *) (addr + symtab->sh_offset);
710 nsym = symtab->sh_size / sizeof(*symp);
711 strp = (char *) (addr + strtab->sh_offset);
713 for(i=0; i < nsym; i++, symp++)
716 * Ignore certain types of entries which really aren't of that much
717 * interest.
719 if( ELF32_ST_TYPE(symp->st_info) == STT_SECTION )
721 continue;
724 symname = strp + symp->st_name;
727 * Save the name of the current file, so we have a way of tracking
728 * static functions/data.
730 if( ELF32_ST_TYPE(symp->st_info) == STT_FILE )
732 curfile = symname;
733 continue;
738 * See if we already have something for this symbol.
739 * If so, ignore this entry, because it would have come from the
740 * stabs or from a previous symbol. If the value is different,
741 * we will have to keep the darned thing, because there can be
742 * multiple local symbols by the same name.
744 if( (DEBUG_GetSymbolValue(symname, -1, &new_addr, FALSE ) == TRUE)
745 && (new_addr.off == (load_offset + symp->st_value)) )
747 continue;
750 new_addr.seg = 0;
751 new_addr.type = NULL;
752 new_addr.off = load_offset + symp->st_value;
753 flags = SYM_WINE | (ELF32_ST_BIND(symp->st_info) == STT_FUNC
754 ? SYM_FUNC : SYM_DATA);
755 if( ELF32_ST_BIND(symp->st_info) == STB_GLOBAL )
757 curr_sym = DEBUG_AddSymbol( symname, &new_addr, NULL, flags );
759 else
761 curr_sym = DEBUG_AddSymbol( symname, &new_addr, curfile, flags );
765 * Record the size of the symbol. This can come in handy in
766 * some cases. Not really used yet, however.
768 if( symp->st_size != 0 )
770 DEBUG_SetSymbolSize(curr_sym, symp->st_size);
774 return TRUE;
777 static
779 DEBUG_ProcessElfObject(char * filename, unsigned int load_offset)
781 int rtn = FALSE;
782 struct stat statbuf;
783 int fd = -1;
784 int status;
785 char * addr = (char *) 0xffffffff;
786 Elf32_Ehdr * ehptr;
787 Elf32_Shdr * spnt;
788 char * shstrtab;
789 int nsect;
790 int i;
791 int stabsect;
792 int stabstrsect;
796 * Make sure we can stat and open this file.
798 if( filename == NULL )
800 goto leave;
803 status = stat(filename, &statbuf);
804 if( status == -1 )
806 goto leave;
810 * Now open the file, so that we can mmap() it.
812 fd = open(filename, O_RDONLY);
813 if( fd == -1 )
815 goto leave;
820 * Now mmap() the file.
822 addr = mmap(0, statbuf.st_size, PROT_READ,
823 MAP_PRIVATE, fd, 0);
826 * Give a nice status message here...
828 fprintf(stderr, "Loading symbols from ELF file %s...\n", filename);
831 * Next, we need to find a few of the internal ELF headers within
832 * this thing. We need the main executable header, and the section
833 * table.
835 ehptr = (Elf32_Ehdr *) addr;
837 if( load_offset == NULL )
839 DEBUG_RegisterELFDebugInfo(ehptr->e_entry, statbuf.st_size, filename);
841 else
843 DEBUG_RegisterELFDebugInfo(load_offset, statbuf.st_size, filename);
846 spnt = (Elf32_Shdr *) (addr + ehptr->e_shoff);
847 nsect = ehptr->e_shnum;
848 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
850 stabsect = stabstrsect = -1;
852 for(i=0; i < nsect; i++)
854 if( strcmp(shstrtab + spnt[i].sh_name, ".stab") == 0 )
856 stabsect = i;
859 if( strcmp(shstrtab + spnt[i].sh_name, ".stabstr") == 0 )
861 stabstrsect = i;
865 if( stabsect == -1 || stabstrsect == -1 )
867 goto leave;
871 * OK, now just parse all of the stabs.
873 rtn = DEBUG_ParseStabs(addr, load_offset,
874 spnt[stabsect].sh_offset,
875 spnt[stabsect].sh_size,
876 spnt[stabstrsect].sh_offset,
877 spnt[stabstrsect].sh_size);
879 if( rtn != TRUE )
881 goto leave;
884 for(i=0; i < nsect; i++)
886 if( (strcmp(shstrtab + spnt[i].sh_name, ".symtab") == 0)
887 && (spnt[i].sh_type == SHT_SYMTAB) )
889 DEBUG_ProcessElfSymtab(addr, load_offset,
890 spnt + i, spnt + spnt[i].sh_link);
893 if( (strcmp(shstrtab + spnt[i].sh_name, ".dynsym") == 0)
894 && (spnt[i].sh_type == SHT_DYNSYM) )
896 DEBUG_ProcessElfSymtab(addr, load_offset,
897 spnt + i, spnt + spnt[i].sh_link);
901 leave:
903 if( addr != (char *) 0xffffffff )
905 munmap(addr, statbuf.st_size);
908 if( fd != -1 )
910 close(fd);
913 return (rtn);
918 DEBUG_ReadExecutableDbgInfo(void)
920 Elf32_Ehdr * ehdr;
921 char * exe_name;
922 Elf32_Dyn * dynpnt;
923 struct r_debug * dbg_hdr;
924 struct link_map * lpnt = NULL;
925 extern Elf32_Dyn _DYNAMIC[];
926 int rtn = FALSE;
928 exe_name = DEBUG_argv0;
931 * Make sure we can stat and open this file.
933 if( exe_name == NULL )
935 goto leave;
938 DEBUG_ProcessElfObject(exe_name, 0);
941 * Finally walk the tables that the dynamic loader maintains to find all
942 * of the other shared libraries which might be loaded. Perform the
943 * same step for all of these.
945 dynpnt = _DYNAMIC;
946 if( dynpnt == NULL )
948 goto leave;
952 * Now walk the dynamic section (of the executable, looking for a DT_DEBUG
953 * entry.
955 for(; dynpnt->d_tag != DT_NULL; dynpnt++)
957 if( dynpnt->d_tag == DT_DEBUG )
959 break;
963 if( (dynpnt->d_tag != DT_DEBUG)
964 || (dynpnt->d_un.d_ptr == NULL) )
966 goto leave;
970 * OK, now dig into the actual tables themselves.
972 dbg_hdr = (struct r_debug *) dynpnt->d_un.d_ptr;
973 lpnt = dbg_hdr->r_map;
976 * Now walk the linked list. In all known ELF implementations,
977 * the dynamic loader maintains this linked list for us. In some
978 * cases the first entry doesn't appear with a name, in other cases it
979 * does.
981 for(; lpnt; lpnt = lpnt->l_next )
984 * We already got the stuff for the executable using the
985 * argv[0] entry above. Here we only need to concentrate on any
986 * shared libraries which may be loaded.
988 ehdr = (Elf32_Ehdr *) lpnt->l_addr;
989 if( (lpnt->l_addr == NULL) || (ehdr->e_type != ET_DYN) )
991 continue;
994 if( lpnt->l_name != NULL )
996 DEBUG_ProcessElfObject(lpnt->l_name, lpnt->l_addr);
1000 rtn = TRUE;
1002 leave:
1004 return (rtn);
1008 #else /* !__ELF__ */
1010 #ifdef linux
1012 * a.out linux.
1015 DEBUG_ReadExecutableDbgInfo(void)
1017 char * addr = (char *) 0xffffffff;
1018 char * exe_name;
1019 struct exec * ahdr;
1020 int fd = -1;
1021 int rtn = FALSE;
1022 unsigned int staboff;
1023 struct stat statbuf;
1024 int status;
1025 unsigned int stroff;
1027 exe_name = DEBUG_argv0;
1030 * Make sure we can stat and open this file.
1032 if( exe_name == NULL )
1034 goto leave;
1037 status = stat(exe_name, &statbuf);
1038 if( status == -1 )
1040 goto leave;
1044 * Now open the file, so that we can mmap() it.
1046 fd = open(exe_name, O_RDONLY);
1047 if( fd == -1 )
1049 goto leave;
1054 * Now mmap() the file.
1056 addr = mmap(0, statbuf.st_size, PROT_READ,
1057 MAP_PRIVATE, fd, 0);
1059 ahdr = (struct exec *) addr;
1061 staboff = N_SYMOFF(*ahdr);
1062 stroff = N_STROFF(*ahdr);
1063 rtn = DEBUG_ParseStabs(addr, 0,
1064 staboff,
1065 ahdr->a_syms,
1066 stroff,
1067 statbuf.st_size - stroff);
1070 * Give a nice status message here...
1072 fprintf(stderr, "Loading symbols from a.out file %s...\n", exe_name);
1074 rtn = TRUE;
1076 leave:
1078 if( addr != (char *) 0xffffffff )
1080 munmap(addr, statbuf.st_size);
1083 if( fd != -1 )
1085 close(fd);
1088 return (rtn);
1091 #else
1093 * Non-linux, non-ELF platforms.
1096 DEBUG_ReadExecutableDbgInfo(void)
1098 return FALSE;
1100 #endif
1102 #endif /* __ELF__ */