2 * File stabs.c - read stabs information from the wine executable itself.
4 * Copyright (C) 1996, Eric Youngdale.
19 #define PATH_MAX _MAX_PATH
36 #elif defined(__EMX__)
66 * This is how we translate stab types into our internal representations
69 static struct datatype
** stab_types
= NULL
;
70 static int num_stab_types
= 0;
73 * Set so that we know the main executable name and path.
80 struct stab_nlist
*n_next
;
86 unsigned long n_value
;
90 * This is used to keep track of known datatypes so that we don't redefine
91 * them over and over again. It sucks up lots of memory otherwise.
95 struct known_typedef
* next
;
98 struct datatype
* types
[0];
101 #define NR_STAB_HASH 521
103 struct known_typedef
* ktd_head
[NR_STAB_HASH
] = {NULL
,};
105 static unsigned int stab_hash( const char * name
)
107 unsigned int hash
= 0;
115 hash
= (hash
<< 4) + *p
++;
117 if( (tmp
= (hash
& 0xf0000000)) )
123 return hash
% NR_STAB_HASH
;
127 static void stab_strcpy(char * dest
, const char * source
)
130 * A strcpy routine that stops when we hit the ':' character.
131 * Faster than copying the whole thing, and then nuking the
134 while(*source
!= '\0' && *source
!= ':')
139 #define MAX_TD_NESTING 128
141 static int **typenums
;
142 static int *nroftypenums
=NULL
;
143 static int nrofnroftypenums
=0;
144 static int curtypenum
= 0;
148 DEBUG_FileSubNr2StabEnum(int filenr
,int subnr
) {
149 if (nrofnroftypenums
<=filenr
) {
150 nroftypenums
= xrealloc(nroftypenums
,sizeof(nroftypenums
[0])*(filenr
+1));
151 memset(nroftypenums
+nrofnroftypenums
,0,(filenr
+1-nrofnroftypenums
)*sizeof(nroftypenums
[0]));
152 typenums
= xrealloc(typenums
,sizeof(typenums
[0])*(filenr
+1));
153 memset(typenums
+nrofnroftypenums
,0,sizeof(typenums
[0])*(filenr
+1-nrofnroftypenums
));
154 nrofnroftypenums
=filenr
+1;
156 if (nroftypenums
[filenr
]<=subnr
) {
157 typenums
[filenr
] = xrealloc(typenums
[filenr
],sizeof(typenums
[0][0])*(subnr
+1));
158 memset(typenums
[filenr
]+nroftypenums
[filenr
],0,sizeof(typenums
[0][0])*(subnr
+1-nroftypenums
[filenr
]));
159 nroftypenums
[filenr
] = subnr
+1;
161 if (!typenums
[filenr
][subnr
])
162 typenums
[filenr
][subnr
]=++curtypenum
;
164 if( num_stab_types
<= curtypenum
) {
165 num_stab_types
= curtypenum
+ 256;
166 stab_types
= (struct datatype
**) xrealloc(stab_types
,
167 num_stab_types
* sizeof(struct datatype
*)
169 memset( stab_types
+ curtypenum
, 0, sizeof(struct datatype
*) * (num_stab_types
- curtypenum
) );
171 /*fprintf(stderr,"(%d,%d) is %d\n",filenr,subnr,typenums[filenr][subnr]); */
172 return typenums
[filenr
][subnr
];
177 DEBUG_ReadTypeEnumBackwards(char*x
) {
184 filenr
=strtol(x
,&x
,10); /* <int> */
186 subnr
=strtol(x
,&x
,10); /* <int> */
189 while ((*x
>='0') && (*x
<='9'))
194 return DEBUG_FileSubNr2StabEnum(filenr
,subnr
);
199 DEBUG_ReadTypeEnum(char **x
) {
204 filenr
=strtol(*x
,x
,10); /* <int> */
206 subnr
=strtol(*x
,x
,10); /* <int> */
210 subnr
= strtol(*x
,x
,10); /* <int> */
212 return DEBUG_FileSubNr2StabEnum(filenr
,subnr
);
217 DEBUG_RegisterTypedef(const char * name
, struct datatype
** types
, int ndef
)
220 struct known_typedef
* ktd
;
225 ktd
= (struct known_typedef
*) xmalloc(sizeof(struct known_typedef
)
226 + ndef
* sizeof(struct datatype
*));
228 hash
= stab_hash(name
);
230 ktd
->name
= xstrdup(name
);
232 memcpy(&ktd
->types
[0], types
, ndef
* sizeof(struct datatype
*));
233 ktd
->next
= ktd_head
[hash
];
234 ktd_head
[hash
] = ktd
;
241 DEBUG_HandlePreviousTypedef(const char * name
, const char * stab
)
244 enum debug_type expect
;
246 struct known_typedef
* ktd
;
249 hash
= stab_hash(name
);
251 for(ktd
= ktd_head
[hash
]; ktd
; ktd
= ktd
->next
)
252 if ((ktd
->name
[0] == name
[0]) && (strcmp(name
, ktd
->name
) == 0) )
256 * Didn't find it. This must be a new one.
262 * Examine the stab to make sure it has the same number of definitions.
265 for(ptr
= strchr(stab
, '='); ptr
; ptr
= strchr(ptr
+1, '='))
267 if( count
>= ktd
->ndefs
)
271 * Make sure the types of all of the objects is consistent with
272 * what we have already parsed.
301 fprintf(stderr
, "Unknown type (%c).\n",ptr
[1]);
304 if( expect
!= DEBUG_GetType(ktd
->types
[count
]) )
309 if( ktd
->ndefs
!= count
)
313 * Go through, dig out all of the type numbers, and substitute the
314 * appropriate things.
317 for(ptr
= strchr(stab
, '='); ptr
; ptr
= strchr(ptr
+1, '='))
318 stab_types
[DEBUG_ReadTypeEnumBackwards(ptr
-1)] = ktd
->types
[count
++];
323 static int DEBUG_FreeRegisteredTypedefs()
327 struct known_typedef
* ktd
;
328 struct known_typedef
* next
;
331 for(j
=0; j
< NR_STAB_HASH
; j
++ )
333 for(ktd
= ktd_head
[j
]; ktd
; ktd
= next
)
349 DEBUG_ParseTypedefStab(char * ptr
, const char * typename
)
354 struct datatype
* curr_type
;
355 struct datatype
* datatype
;
356 struct datatype
* curr_types
[MAX_TD_NESTING
];
357 char element_name
[1024];
360 const char * orig_typename
;
366 orig_typename
= typename
;
368 if( DEBUG_HandlePreviousTypedef(typename
, ptr
) )
372 * Go from back to front. First we go through and figure out what
373 * type numbers we need, and register those types. Then we go in
374 * and fill the details.
377 for( c
= strchr(ptr
, '='); c
!= NULL
; c
= strchr(c
+ 1, '=') )
380 * Back up until we get to a non-numeric character. This is the type
383 typenum
= DEBUG_ReadTypeEnumBackwards(c
-1);
385 if( ntypes
>= MAX_TD_NESTING
)
388 * If this ever happens, just bump the counter.
390 fprintf(stderr
, "Typedef nesting overflow\n");
397 stab_types
[typenum
] = DEBUG_NewDataType(DT_POINTER
, NULL
);
398 curr_types
[ntypes
++] = stab_types
[typenum
];
402 stab_types
[typenum
] = DEBUG_NewDataType(DT_STRUCT
, typename
);
403 curr_types
[ntypes
++] = stab_types
[typenum
];
406 stab_types
[typenum
] = DEBUG_NewDataType(DT_ARRAY
, NULL
);
407 curr_types
[ntypes
++] = stab_types
[typenum
];
412 stab_types
[typenum
] = DEBUG_NewDataType(DT_BASIC
, typename
);
413 curr_types
[ntypes
++] = stab_types
[typenum
];
416 stab_strcpy(element_name
, c
+ 3);
417 stab_types
[typenum
] = DEBUG_NewDataType(DT_STRUCT
, element_name
);
418 curr_types
[ntypes
++] = stab_types
[typenum
];
421 stab_types
[typenum
] = DEBUG_NewDataType(DT_ENUM
, NULL
);
422 curr_types
[ntypes
++] = stab_types
[typenum
];
425 stab_types
[typenum
] = DEBUG_NewDataType(DT_FUNC
, NULL
);
426 curr_types
[ntypes
++] = stab_types
[typenum
];
429 fprintf(stderr
, "Unknown type (%c).\n",c
[1]);
435 * Now register the type so that if we encounter it again, we will know
438 DEBUG_RegisterTypedef(orig_typename
, curr_types
, ntypes
);
441 * OK, now take a second sweep through. Now we will be digging
442 * out the definitions of the various components, and storing
443 * them in the skeletons that we have already allocated. We take
444 * a right-to left search as this is much easier to parse.
446 for( c
= strrchr(ptr
, '='); c
!= NULL
; c
= strrchr(ptr
, '=') )
448 int typenum
= DEBUG_ReadTypeEnumBackwards(c
-1);
449 curr_type
= stab_types
[typenum
];
466 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)];
467 DEBUG_SetPointerType(curr_type
, datatype
);
477 * We have already handled these above.
482 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo>,<int>,<int>;; */
486 DEBUG_ReadTypeEnum(&tc
);
488 arrmin
= strtol(tc
, &tc
, 10); /* <int> */
490 arrmax
= strtol(tc
, &tc
, 10); /* <int> */
492 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)]; /* <typeinfo> */
497 DEBUG_SetArrayParams(curr_type
, arrmin
, arrmax
, datatype
);
504 if( DEBUG_SetStructSize(curr_type
, strtol(tc
, &tc
, 10)) == FALSE
)
507 * We have already filled out this structure. Nothing to do,
508 * so just skip forward to the end of the definition.
510 while( tc
[0] != ';' && tc
[1] != ';' )
523 * Now parse the individual elements of the structure/union.
534 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)];
537 offset
= strtol(tc
, &tc
, 10);
539 size
= strtol(tc
, &tc
, 10);
542 DEBUG_AddStructElement(curr_type
, element_name
, datatype
, offset
, size
);
545 /* ... but proceed parsing to the end of the stab */
550 /* if we had a undeclared value this one is undeclared too.
551 * remove it from the stab_types.
552 * I just set it to NULL to detect bugs in my thoughtprocess.
553 * FIXME: leaks the memory for the structure elements.
554 * FIXME: such structures should have been optimized away
557 stab_types
[typenum
] = NULL
;
568 * Now parse the individual elements of the structure/union.
577 offset
= strtol(tc
, &tc
, 10);
579 DEBUG_AddStructElement(curr_type
, element_name
, NULL
, offset
, 0);
587 fprintf(stderr
, "Unknown type (%c).\n",c
[1]);
596 static struct datatype
*
597 DEBUG_ParseStabType(const char * stab
)
602 * Look through the stab definition, and figure out what datatype
603 * this represents. If we have something we know about, assign the
606 c
= strchr(stab
, ':');
612 * The next character says more about the type (i.e. data, function, etc)
613 * of symbol. Skip it.
617 * The next is either an integer or a (integer,integer).
618 * The DEBUG_ReadTypeEnum takes care that stab_types is large enough.
620 return stab_types
[DEBUG_ReadTypeEnum(&c
)];
625 DEBUG_ParseStabs(char * addr
, unsigned int load_offset
,
626 unsigned int staboff
, int stablen
,
627 unsigned int strtaboff
, int strtablen
)
629 struct name_hash
* curr_func
= NULL
;
630 struct wine_locals
* curr_loc
= NULL
;
631 struct name_hash
* curr_sym
= NULL
;
632 char currpath
[PATH_MAX
];
642 struct stab_nlist
* stab_ptr
;
645 char * subpath
= NULL
;
648 nstab
= stablen
/ sizeof(struct stab_nlist
);
649 stab_ptr
= (struct stab_nlist
*) (addr
+ staboff
);
650 strs
= (char *) (addr
+ strtaboff
);
652 memset(currpath
, 0, sizeof(currpath
));
655 * Allocate a buffer into which we can build stab strings for cases
656 * where the stab is continued over multiple lines.
659 stabbuff
= (char *) xmalloc(stabbufflen
);
663 for(i
=0; i
< nstab
; i
++, stab_ptr
++ )
665 ptr
= strs
+ (unsigned int) stab_ptr
->n_un
.n_name
;
666 if( ptr
[strlen(ptr
) - 1] == '\\' )
669 * Indicates continuation. Append this to the buffer, and go onto the
670 * next record. Repeat the process until we find a stab without the
671 * '/' character, as this indicates we have the whole thing.
674 if( strlen(stabbuff
) + len
> stabbufflen
)
676 stabbufflen
+= 65536;
677 stabbuff
= (char *) xrealloc(stabbuff
, stabbufflen
);
679 strncat(stabbuff
, ptr
, len
- 1);
682 else if( stabbuff
[0] != '\0' )
684 strcat( stabbuff
, ptr
);
688 if( strchr(ptr
, '=') != NULL
)
691 * The stabs aren't in writable memory, so copy it over so we are
692 * sure we can scribble on it.
694 if( ptr
!= stabbuff
)
696 strcpy(stabbuff
, ptr
);
699 stab_strcpy(symname
, ptr
);
700 DEBUG_ParseTypedefStab(ptr
, symname
);
703 switch(stab_ptr
->n_type
)
707 * These are useless with ELF. They have no value, and you have to
708 * read the normal symbol table to get the address. Thus we
709 * ignore them, and when we process the normal symbol table
710 * we should do the right thing.
712 * With a.out, they actually do make some amount of sense.
715 new_addr
.type
= DEBUG_ParseStabType(ptr
);
716 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
718 stab_strcpy(symname
, ptr
);
720 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
721 SYM_WINE
| SYM_DATA
| SYM_INVALID
);
723 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
724 SYM_WINE
| SYM_DATA
);
730 * We need to keep track of these so we get symbol scoping
731 * right for local variables. For now, we just ignore them.
732 * The hooks are already there for dealing with this however,
733 * so all we need to do is to keep count of the nesting level,
734 * and find the RBRAC for each matching LBRAC.
740 * These are static symbols and BSS symbols.
743 new_addr
.type
= DEBUG_ParseStabType(ptr
);
744 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
746 stab_strcpy(symname
, ptr
);
747 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
748 SYM_WINE
| SYM_DATA
);
752 * These are function parameters.
754 if( (curr_func
!= NULL
)
755 && (stab_ptr
->n_value
!= 0) )
757 stab_strcpy(symname
, ptr
);
758 curr_loc
= DEBUG_AddLocal(curr_func
, 0,
759 stab_ptr
->n_value
, 0, 0, symname
);
760 DEBUG_SetLocalSymbolType( curr_loc
, DEBUG_ParseStabType(ptr
));
764 if( curr_func
!= NULL
)
766 stab_strcpy(symname
, ptr
);
767 curr_loc
= DEBUG_AddLocal(curr_func
, stab_ptr
->n_value
, 0, 0, 0, symname
);
768 DEBUG_SetLocalSymbolType( curr_loc
, DEBUG_ParseStabType(ptr
));
772 if( (curr_func
!= NULL
)
773 && (stab_ptr
->n_value
!= 0) )
775 stab_strcpy(symname
, ptr
);
776 DEBUG_AddLocal(curr_func
, 0,
777 stab_ptr
->n_value
, 0, 0, symname
);
779 else if (curr_func
== NULL
)
781 stab_strcpy(symname
, ptr
);
786 * This is a line number. These are always relative to the start
787 * of the function (N_FUN), and this makes the lookup easier.
789 if( curr_func
!= NULL
)
792 DEBUG_AddLineNumber(curr_func
, stab_ptr
->n_desc
,
797 * This isn't right. The order of the stabs is different under
798 * a.out, and as a result we would end up attaching the line
799 * number to the wrong function.
801 DEBUG_AddLineNumber(curr_func
, stab_ptr
->n_desc
,
802 stab_ptr
->n_value
- curr_func
->addr
.off
);
809 * First, clean up the previous function we were working on.
811 DEBUG_Normalize(curr_func
);
814 * For now, just declare the various functions. Later
815 * on, we will add the line number information and the
821 new_addr
.type
= DEBUG_ParseStabType(ptr
);
822 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
824 * Copy the string to a temp buffer so we
825 * can kill everything after the ':'. We do
826 * it this way because otherwise we end up dirtying
827 * all of the pages related to the stabs, and that
828 * sucks up swap space like crazy.
830 stab_strcpy(symname
, ptr
);
831 curr_func
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
832 SYM_WINE
| SYM_FUNC
);
837 * Don't add line number information for this function
845 * This indicates a new source file. Append the records
846 * together, to build the correct path name.
850 * With a.out, there is no NULL string N_SO entry at the end of
851 * the file. Thus when we find non-consecutive entries,
852 * we consider that a new file is started.
857 DEBUG_Normalize(curr_func
);
868 DEBUG_Normalize(curr_func
);
871 * The datatypes that we would need to use are reset when
872 * we start a new file.
874 memset(stab_types
, 0, num_stab_types
* sizeof(stab_types
[0]));
876 for (i=0;i<nrofnroftypenums;i++)
877 memset(typenums[i],0,sizeof(typenums[i][0])*nroftypenums[i]);
883 strcat(currpath
, ptr
);
885 strcpy(currpath
, ptr
);
892 * This indicates we are including stuff from an include file.
893 * If this is the main source, enable the debug stuff, otherwise
896 if( subpath
== NULL
|| strcmp(ptr
, subpath
) == 0 )
903 DEBUG_Normalize(curr_func
);
909 strtabinc
= stab_ptr
->n_value
;
910 DEBUG_Normalize(curr_func
);
915 * Ignore this. We don't care what it points to.
922 * Always ignore these. GCC doesn't even generate them.
932 fprintf(stderr
, "%d %x %s\n", stab_ptr
->n_type
,
933 (unsigned int) stab_ptr
->n_value
,
934 strs
+ (unsigned int) stab_ptr
->n_un
.n_name
);
938 if( stab_types
!= NULL
)
946 DEBUG_FreeRegisteredTypedefs();
954 * Walk through the entire symbol table and add any symbols we find there.
955 * This can be used in cases where we have stripped ELF shared libraries,
956 * or it can be used in cases where we have data symbols for which the address
957 * isn't encoded in the stabs.
959 * This is all really quite easy, since we don't have to worry about line
960 * numbers or local data variables.
964 DEBUG_ProcessElfSymtab(char * addr
, unsigned int load_offset
,
965 Elf32_Shdr
* symtab
, Elf32_Shdr
* strtab
)
967 char * curfile
= NULL
;
968 struct name_hash
* curr_sym
= NULL
;
978 symp
= (Elf32_Sym
*) (addr
+ symtab
->sh_offset
);
979 nsym
= symtab
->sh_size
/ sizeof(*symp
);
980 strp
= (char *) (addr
+ strtab
->sh_offset
);
982 for(i
=0; i
< nsym
; i
++, symp
++)
985 * Ignore certain types of entries which really aren't of that much
988 if( ELF32_ST_TYPE(symp
->st_info
) == STT_SECTION
)
993 symname
= strp
+ symp
->st_name
;
996 * Save the name of the current file, so we have a way of tracking
997 * static functions/data.
999 if( ELF32_ST_TYPE(symp
->st_info
) == STT_FILE
)
1007 * See if we already have something for this symbol.
1008 * If so, ignore this entry, because it would have come from the
1009 * stabs or from a previous symbol. If the value is different,
1010 * we will have to keep the darned thing, because there can be
1011 * multiple local symbols by the same name.
1013 if( (DEBUG_GetSymbolValue(symname
, -1, &new_addr
, FALSE
) == TRUE
)
1014 && (new_addr
.off
== (load_offset
+ symp
->st_value
)) )
1018 new_addr
.type
= NULL
;
1019 new_addr
.off
= load_offset
+ symp
->st_value
;
1020 flags
= SYM_WINE
| (ELF32_ST_BIND(symp
->st_info
) == STT_FUNC
1021 ? SYM_FUNC
: SYM_DATA
);
1022 if( ELF32_ST_BIND(symp
->st_info
) == STB_GLOBAL
)
1023 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, NULL
, flags
);
1025 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, curfile
, flags
);
1028 * Record the size of the symbol. This can come in handy in
1029 * some cases. Not really used yet, however.
1031 if( symp
->st_size
!= 0 )
1032 DEBUG_SetSymbolSize(curr_sym
, symp
->st_size
);
1040 DEBUG_ProcessElfObject(char * filename
, unsigned int load_offset
)
1043 struct stat statbuf
;
1046 char * addr
= (char *) 0xffffffff;
1057 * Make sure we can stat and open this file.
1059 if( filename
== NULL
)
1062 status
= stat(filename
, &statbuf
);
1065 char *s
,*t
,*fn
,*paths
;
1066 if (strchr(filename
,'/'))
1068 paths
= xstrdup(getenv("PATH"));
1073 fn
= (char*)xmalloc(strlen(filename
)+1+strlen(s
)+1);
1076 strcat(fn
,filename
);
1077 if ((rtn
= DEBUG_ProcessElfObject(fn
,load_offset
))) {
1083 if (t
) s
= t
+1; else break;
1085 if (!s
|| !*s
) fprintf(stderr
," not found");
1091 * Now open the file, so that we can mmap() it.
1093 fd
= open(filename
, O_RDONLY
);
1099 * Now mmap() the file.
1101 addr
= mmap(0, statbuf
.st_size
, PROT_READ
,
1102 MAP_PRIVATE
, fd
, 0);
1103 if( addr
== (char *) 0xffffffff )
1107 * Next, we need to find a few of the internal ELF headers within
1108 * this thing. We need the main executable header, and the section
1111 ehptr
= (Elf32_Ehdr
*) addr
;
1113 if( load_offset
== 0 )
1114 DEBUG_RegisterELFDebugInfo(ehptr
->e_entry
, statbuf
.st_size
, filename
);
1116 DEBUG_RegisterELFDebugInfo(load_offset
, statbuf
.st_size
, filename
);
1118 spnt
= (Elf32_Shdr
*) (addr
+ ehptr
->e_shoff
);
1119 nsect
= ehptr
->e_shnum
;
1120 shstrtab
= (addr
+ spnt
[ehptr
->e_shstrndx
].sh_offset
);
1122 stabsect
= stabstrsect
= -1;
1124 for(i
=0; i
< nsect
; i
++)
1126 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stab") == 0 )
1129 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stabstr") == 0 )
1133 if( stabsect
== -1 || stabstrsect
== -1 )
1137 * OK, now just parse all of the stabs.
1139 rtn
= DEBUG_ParseStabs(addr
, load_offset
,
1140 spnt
[stabsect
].sh_offset
,
1141 spnt
[stabsect
].sh_size
,
1142 spnt
[stabstrsect
].sh_offset
,
1143 spnt
[stabstrsect
].sh_size
);
1148 for(i
=0; i
< nsect
; i
++)
1150 if( (strcmp(shstrtab
+ spnt
[i
].sh_name
, ".symtab") == 0)
1151 && (spnt
[i
].sh_type
== SHT_SYMTAB
) )
1152 DEBUG_ProcessElfSymtab(addr
, load_offset
,
1153 spnt
+ i
, spnt
+ spnt
[i
].sh_link
);
1155 if( (strcmp(shstrtab
+ spnt
[i
].sh_name
, ".dynsym") == 0)
1156 && (spnt
[i
].sh_type
== SHT_DYNSYM
) )
1157 DEBUG_ProcessElfSymtab(addr
, load_offset
,
1158 spnt
+ i
, spnt
+ spnt
[i
].sh_link
);
1163 if( addr
!= (char *) 0xffffffff )
1164 munmap(addr
, statbuf
.st_size
);
1174 DEBUG_ReadExecutableDbgInfo(void)
1179 struct r_debug
* dbg_hdr
;
1180 struct link_map
* lpnt
= NULL
;
1181 extern Elf32_Dyn _DYNAMIC
[];
1185 exe_name
= DEBUG_argv0
;
1188 * Make sure we can stat and open this file.
1190 if( exe_name
== NULL
)
1193 fprintf( stderr
, "Loading symbols: %s", exe_name
);
1194 rowcount
= 17 + strlen(exe_name
);
1195 DEBUG_ProcessElfObject(exe_name
, 0);
1198 * Finally walk the tables that the dynamic loader maintains to find all
1199 * of the other shared libraries which might be loaded. Perform the
1200 * same step for all of these.
1203 if( dynpnt
== NULL
)
1207 * Now walk the dynamic section (of the executable, looking for a DT_DEBUG
1210 for(; dynpnt
->d_tag
!= DT_NULL
; dynpnt
++)
1211 if( dynpnt
->d_tag
== DT_DEBUG
)
1214 if( (dynpnt
->d_tag
!= DT_DEBUG
)
1215 || (dynpnt
->d_un
.d_ptr
== 0) )
1219 * OK, now dig into the actual tables themselves.
1221 dbg_hdr
= (struct r_debug
*) dynpnt
->d_un
.d_ptr
;
1222 lpnt
= dbg_hdr
->r_map
;
1225 * Now walk the linked list. In all known ELF implementations,
1226 * the dynamic loader maintains this linked list for us. In some
1227 * cases the first entry doesn't appear with a name, in other cases it
1230 for(; lpnt
; lpnt
= lpnt
->l_next
)
1233 * We already got the stuff for the executable using the
1234 * argv[0] entry above. Here we only need to concentrate on any
1235 * shared libraries which may be loaded.
1237 ehdr
= (Elf32_Ehdr
*) lpnt
->l_addr
;
1238 if( (lpnt
->l_addr
== 0) || (ehdr
->e_type
!= ET_DYN
) )
1241 if( lpnt
->l_name
!= NULL
)
1243 if (rowcount
+ strlen(lpnt
->l_name
) > 76)
1245 fprintf( stderr
, "\n " );
1248 fprintf( stderr
, " %s", lpnt
->l_name
);
1249 rowcount
+= strlen(lpnt
->l_name
) + 1;
1250 DEBUG_ProcessElfObject(lpnt
->l_name
, lpnt
->l_addr
);
1257 fprintf( stderr
, "\n" );
1262 #else /* !__ELF__ */
1269 DEBUG_ReadExecutableDbgInfo(void)
1271 char * addr
= (char *) 0xffffffff;
1276 unsigned int staboff
;
1277 struct stat statbuf
;
1279 unsigned int stroff
;
1281 exe_name
= DEBUG_argv0
;
1284 * Make sure we can stat and open this file.
1286 if( exe_name
== NULL
)
1289 status
= stat(exe_name
, &statbuf
);
1294 * Now open the file, so that we can mmap() it.
1296 fd
= open(exe_name
, O_RDONLY
);
1302 * Now mmap() the file.
1304 addr
= mmap(0, statbuf
.st_size
, PROT_READ
,
1305 MAP_PRIVATE
, fd
, 0);
1306 if( addr
== (char *) 0xffffffff )
1309 ahdr
= (struct exec
*) addr
;
1311 staboff
= N_SYMOFF(*ahdr
);
1312 stroff
= N_STROFF(*ahdr
);
1313 rtn
= DEBUG_ParseStabs(addr
, 0,
1317 statbuf
.st_size
- stroff
);
1320 * Give a nice status message here...
1322 fprintf( stderr
, "Loading symbols: %s", exe_name
);
1328 if( addr
!= (char *) 0xffffffff )
1329 munmap(addr
, statbuf
.st_size
);
1339 * Non-linux, non-ELF platforms.
1342 DEBUG_ReadExecutableDbgInfo(void)
1348 #endif /* __ELF__ */