2 * File stabs.c - read stabs information from the wine executable itself.
4 * Copyright (C) 1996, Eric Youngdale.
19 #define PATH_MAX _MAX_PATH
35 #elif defined(__EMX__)
65 * This is how we translate stab types into our internal representations
68 static struct datatype
** stab_types
= NULL
;
69 static int num_stab_types
= 0;
72 * Set so that we know the main executable name and path.
79 struct stab_nlist
*n_next
;
85 unsigned long n_value
;
89 * This is used to keep track of known datatypes so that we don't redefine
90 * them over and over again. It sucks up lots of memory otherwise.
94 struct known_typedef
* next
;
97 struct datatype
* types
[0];
100 #define NR_STAB_HASH 521
102 struct known_typedef
* ktd_head
[NR_STAB_HASH
] = {NULL
,};
104 static unsigned int stab_hash( const char * name
)
106 unsigned int hash
= 0;
114 hash
= (hash
<< 4) + *p
++;
116 if( (tmp
= (hash
& 0xf0000000)) )
122 return hash
% NR_STAB_HASH
;
126 static void stab_strcpy(char * dest
, const char * source
)
129 * A strcpy routine that stops when we hit the ':' character.
130 * Faster than copying the whole thing, and then nuking the
133 while(*source
!= '\0' && *source
!= ':')
138 #define MAX_TD_NESTING 128
140 static int **typenums
;
141 static int *nroftypenums
=NULL
;
142 static int nrofnroftypenums
=0;
143 static int curtypenum
= 0;
147 DEBUG_FileSubNr2StabEnum(int filenr
,int subnr
) {
148 if (nrofnroftypenums
<=filenr
) {
149 nroftypenums
= xrealloc(nroftypenums
,sizeof(nroftypenums
[0])*(filenr
+1));
150 memset(nroftypenums
+nrofnroftypenums
,0,(filenr
+1-nrofnroftypenums
)*sizeof(nroftypenums
[0]));
151 typenums
= xrealloc(typenums
,sizeof(typenums
[0])*(filenr
+1));
152 memset(typenums
+nrofnroftypenums
,0,sizeof(typenums
[0])*(filenr
+1-nrofnroftypenums
));
153 nrofnroftypenums
=filenr
+1;
155 if (nroftypenums
[filenr
]<=subnr
) {
156 typenums
[filenr
] = xrealloc(typenums
[filenr
],sizeof(typenums
[0][0])*(subnr
+1));
157 memset(typenums
[filenr
]+nroftypenums
[filenr
],0,sizeof(typenums
[0][0])*(subnr
+1-nroftypenums
[filenr
]));
158 nroftypenums
[filenr
] = subnr
+1;
160 if (!typenums
[filenr
][subnr
])
161 typenums
[filenr
][subnr
]=++curtypenum
;
163 if( num_stab_types
<= curtypenum
) {
164 num_stab_types
= curtypenum
+ 256;
165 stab_types
= (struct datatype
**) xrealloc(stab_types
,
166 num_stab_types
* sizeof(struct datatype
*)
168 memset( stab_types
+ curtypenum
, 0, sizeof(struct datatype
*) * (num_stab_types
- curtypenum
) );
170 /*fprintf(stderr,"(%d,%d) is %d\n",filenr,subnr,typenums[filenr][subnr]); */
171 return typenums
[filenr
][subnr
];
176 DEBUG_ReadTypeEnumBackwards(char*x
) {
183 filenr
=strtol(x
,&x
,10); /* <int> */
185 subnr
=strtol(x
,&x
,10); /* <int> */
188 while ((*x
>='0') && (*x
<='9'))
193 return DEBUG_FileSubNr2StabEnum(filenr
,subnr
);
198 DEBUG_ReadTypeEnum(char **x
) {
203 filenr
=strtol(*x
,x
,10); /* <int> */
205 subnr
=strtol(*x
,x
,10); /* <int> */
209 subnr
= strtol(*x
,x
,10); /* <int> */
211 return DEBUG_FileSubNr2StabEnum(filenr
,subnr
);
216 DEBUG_RegisterTypedef(const char * name
, struct datatype
** types
, int ndef
)
219 struct known_typedef
* ktd
;
224 ktd
= (struct known_typedef
*) xmalloc(sizeof(struct known_typedef
)
225 + ndef
* sizeof(struct datatype
*));
227 hash
= stab_hash(name
);
229 ktd
->name
= xstrdup(name
);
231 memcpy(&ktd
->types
[0], types
, ndef
* sizeof(struct datatype
*));
232 ktd
->next
= ktd_head
[hash
];
233 ktd_head
[hash
] = ktd
;
240 DEBUG_HandlePreviousTypedef(const char * name
, const char * stab
)
243 enum debug_type expect
;
245 struct known_typedef
* ktd
;
248 hash
= stab_hash(name
);
250 for(ktd
= ktd_head
[hash
]; ktd
; ktd
= ktd
->next
)
251 if ((ktd
->name
[0] == name
[0]) && (strcmp(name
, ktd
->name
) == 0) )
255 * Didn't find it. This must be a new one.
261 * Examine the stab to make sure it has the same number of definitions.
264 for(ptr
= strchr(stab
, '='); ptr
; ptr
= strchr(ptr
+1, '='))
266 if( count
>= ktd
->ndefs
)
270 * Make sure the types of all of the objects is consistent with
271 * what we have already parsed.
300 fprintf(stderr
, "Unknown type (%c).\n",ptr
[1]);
303 if( expect
!= DEBUG_GetType(ktd
->types
[count
]) )
308 if( ktd
->ndefs
!= count
)
312 * Go through, dig out all of the type numbers, and substitute the
313 * appropriate things.
316 for(ptr
= strchr(stab
, '='); ptr
; ptr
= strchr(ptr
+1, '='))
317 stab_types
[DEBUG_ReadTypeEnumBackwards(ptr
-1)] = ktd
->types
[count
++];
322 static int DEBUG_FreeRegisteredTypedefs()
326 struct known_typedef
* ktd
;
327 struct known_typedef
* next
;
330 for(j
=0; j
< NR_STAB_HASH
; j
++ )
332 for(ktd
= ktd_head
[j
]; ktd
; ktd
= next
)
348 DEBUG_ParseTypedefStab(char * ptr
, const char * typename
)
353 struct datatype
* curr_type
;
354 struct datatype
* datatype
;
355 struct datatype
* curr_types
[MAX_TD_NESTING
];
356 char element_name
[1024];
359 const char * orig_typename
;
365 orig_typename
= typename
;
367 if( DEBUG_HandlePreviousTypedef(typename
, ptr
) )
371 * Go from back to front. First we go through and figure out what
372 * type numbers we need, and register those types. Then we go in
373 * and fill the details.
376 for( c
= strchr(ptr
, '='); c
!= NULL
; c
= strchr(c
+ 1, '=') )
379 * Back up until we get to a non-numeric character. This is the type
382 typenum
= DEBUG_ReadTypeEnumBackwards(c
-1);
384 if( ntypes
>= MAX_TD_NESTING
)
387 * If this ever happens, just bump the counter.
389 fprintf(stderr
, "Typedef nesting overflow\n");
396 stab_types
[typenum
] = DEBUG_NewDataType(DT_POINTER
, NULL
);
397 curr_types
[ntypes
++] = stab_types
[typenum
];
401 stab_types
[typenum
] = DEBUG_NewDataType(DT_STRUCT
, typename
);
402 curr_types
[ntypes
++] = stab_types
[typenum
];
405 stab_types
[typenum
] = DEBUG_NewDataType(DT_ARRAY
, NULL
);
406 curr_types
[ntypes
++] = stab_types
[typenum
];
411 stab_types
[typenum
] = DEBUG_NewDataType(DT_BASIC
, typename
);
412 curr_types
[ntypes
++] = stab_types
[typenum
];
415 stab_strcpy(element_name
, c
+ 3);
416 stab_types
[typenum
] = DEBUG_NewDataType(DT_STRUCT
, element_name
);
417 curr_types
[ntypes
++] = stab_types
[typenum
];
420 stab_types
[typenum
] = DEBUG_NewDataType(DT_ENUM
, NULL
);
421 curr_types
[ntypes
++] = stab_types
[typenum
];
424 stab_types
[typenum
] = DEBUG_NewDataType(DT_FUNC
, NULL
);
425 curr_types
[ntypes
++] = stab_types
[typenum
];
428 fprintf(stderr
, "Unknown type (%c).\n",c
[1]);
434 * Now register the type so that if we encounter it again, we will know
437 DEBUG_RegisterTypedef(orig_typename
, curr_types
, ntypes
);
440 * OK, now take a second sweep through. Now we will be digging
441 * out the definitions of the various components, and storing
442 * them in the skeletons that we have already allocated. We take
443 * a right-to left search as this is much easier to parse.
445 for( c
= strrchr(ptr
, '='); c
!= NULL
; c
= strrchr(ptr
, '=') )
447 int typenum
= DEBUG_ReadTypeEnumBackwards(c
-1);
448 curr_type
= stab_types
[typenum
];
465 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)];
466 DEBUG_SetPointerType(curr_type
, datatype
);
476 * We have already handled these above.
481 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo>,<int>,<int>;; */
485 DEBUG_ReadTypeEnum(&tc
);
487 arrmin
= strtol(tc
, &tc
, 10); /* <int> */
489 arrmax
= strtol(tc
, &tc
, 10); /* <int> */
491 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)]; /* <typeinfo> */
496 DEBUG_SetArrayParams(curr_type
, arrmin
, arrmax
, datatype
);
503 if( DEBUG_SetStructSize(curr_type
, strtol(tc
, &tc
, 10)) == FALSE
)
506 * We have already filled out this structure. Nothing to do,
507 * so just skip forward to the end of the definition.
509 while( tc
[0] != ';' && tc
[1] != ';' )
522 * Now parse the individual elements of the structure/union.
533 datatype
= stab_types
[DEBUG_ReadTypeEnum(&tc
)];
536 offset
= strtol(tc
, &tc
, 10);
538 size
= strtol(tc
, &tc
, 10);
541 DEBUG_AddStructElement(curr_type
, element_name
, datatype
, offset
, size
);
544 /* ... but proceed parsing to the end of the stab */
549 /* if we had a undeclared value this one is undeclared too.
550 * remove it from the stab_types.
551 * I just set it to NULL to detect bugs in my thoughtprocess.
552 * FIXME: leaks the memory for the structure elements.
553 * FIXME: such structures should have been optimized away
556 stab_types
[typenum
] = NULL
;
567 * Now parse the individual elements of the structure/union.
576 offset
= strtol(tc
, &tc
, 10);
578 DEBUG_AddStructElement(curr_type
, element_name
, NULL
, offset
, 0);
586 fprintf(stderr
, "Unknown type (%c).\n",c
[1]);
595 static struct datatype
*
596 DEBUG_ParseStabType(const char * stab
)
601 * Look through the stab definition, and figure out what datatype
602 * this represents. If we have something we know about, assign the
605 c
= strchr(stab
, ':');
611 * The next character says more about the type (i.e. data, function, etc)
612 * of symbol. Skip it.
616 * The next is either an integer or a (integer,integer).
617 * The DEBUG_ReadTypeEnum takes care that stab_types is large enough.
619 return stab_types
[DEBUG_ReadTypeEnum(&c
)];
623 DEBUG_ParseStabs(char * addr
, unsigned int load_offset
,
624 unsigned int staboff
, int stablen
,
625 unsigned int strtaboff
, int strtablen
)
627 struct name_hash
* curr_func
= NULL
;
628 struct wine_locals
* curr_loc
= NULL
;
629 struct name_hash
* curr_sym
= NULL
;
630 char currpath
[PATH_MAX
];
640 struct stab_nlist
* stab_ptr
;
643 char * subpath
= NULL
;
646 nstab
= stablen
/ sizeof(struct stab_nlist
);
647 stab_ptr
= (struct stab_nlist
*) (addr
+ staboff
);
648 strs
= (char *) (addr
+ strtaboff
);
650 memset(currpath
, 0, sizeof(currpath
));
653 * Allocate a buffer into which we can build stab strings for cases
654 * where the stab is continued over multiple lines.
657 stabbuff
= (char *) xmalloc(stabbufflen
);
661 for(i
=0; i
< nstab
; i
++, stab_ptr
++ )
663 ptr
= strs
+ (unsigned int) stab_ptr
->n_un
.n_name
;
664 if( ptr
[strlen(ptr
) - 1] == '\\' )
667 * Indicates continuation. Append this to the buffer, and go onto the
668 * next record. Repeat the process until we find a stab without the
669 * '/' character, as this indicates we have the whole thing.
672 if( strlen(stabbuff
) + len
> stabbufflen
)
674 stabbufflen
+= 65536;
675 stabbuff
= (char *) xrealloc(stabbuff
, stabbufflen
);
677 strncat(stabbuff
, ptr
, len
- 1);
680 else if( stabbuff
[0] != '\0' )
682 strcat( stabbuff
, ptr
);
686 if( strchr(ptr
, '=') != NULL
)
689 * The stabs aren't in writable memory, so copy it over so we are
690 * sure we can scribble on it.
692 if( ptr
!= stabbuff
)
694 strcpy(stabbuff
, ptr
);
697 stab_strcpy(symname
, ptr
);
698 DEBUG_ParseTypedefStab(ptr
, symname
);
701 switch(stab_ptr
->n_type
)
705 * These are useless with ELF. They have no value, and you have to
706 * read the normal symbol table to get the address. Thus we
707 * ignore them, and when we process the normal symbol table
708 * we should do the right thing.
710 * With a.out, they actually do make some amount of sense.
713 new_addr
.type
= DEBUG_ParseStabType(ptr
);
714 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
716 stab_strcpy(symname
, ptr
);
718 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
719 SYM_WINE
| SYM_DATA
| SYM_INVALID
);
721 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
722 SYM_WINE
| SYM_DATA
);
728 * We need to keep track of these so we get symbol scoping
729 * right for local variables. For now, we just ignore them.
730 * The hooks are already there for dealing with this however,
731 * so all we need to do is to keep count of the nesting level,
732 * and find the RBRAC for each matching LBRAC.
738 * These are static symbols and BSS symbols.
741 new_addr
.type
= DEBUG_ParseStabType(ptr
);
742 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
744 stab_strcpy(symname
, ptr
);
745 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
746 SYM_WINE
| SYM_DATA
);
750 * These are function parameters.
752 if( (curr_func
!= NULL
)
753 && (stab_ptr
->n_value
!= 0) )
755 stab_strcpy(symname
, ptr
);
756 curr_loc
= DEBUG_AddLocal(curr_func
, 0,
757 stab_ptr
->n_value
, 0, 0, symname
);
758 DEBUG_SetLocalSymbolType( curr_loc
, DEBUG_ParseStabType(ptr
));
762 if( curr_func
!= NULL
)
764 stab_strcpy(symname
, ptr
);
765 curr_loc
= DEBUG_AddLocal(curr_func
, stab_ptr
->n_value
, 0, 0, 0, symname
);
766 DEBUG_SetLocalSymbolType( curr_loc
, DEBUG_ParseStabType(ptr
));
770 if( (curr_func
!= NULL
)
771 && (stab_ptr
->n_value
!= 0) )
773 stab_strcpy(symname
, ptr
);
774 DEBUG_AddLocal(curr_func
, 0,
775 stab_ptr
->n_value
, 0, 0, symname
);
777 else if (curr_func
== NULL
)
779 stab_strcpy(symname
, ptr
);
784 * This is a line number. These are always relative to the start
785 * of the function (N_FUN), and this makes the lookup easier.
787 if( curr_func
!= NULL
)
790 DEBUG_AddLineNumber(curr_func
, stab_ptr
->n_desc
,
795 * This isn't right. The order of the stabs is different under
796 * a.out, and as a result we would end up attaching the line
797 * number to the wrong function.
799 DEBUG_AddLineNumber(curr_func
, stab_ptr
->n_desc
,
800 stab_ptr
->n_value
- curr_func
->addr
.off
);
807 * First, clean up the previous function we were working on.
809 DEBUG_Normalize(curr_func
);
812 * For now, just declare the various functions. Later
813 * on, we will add the line number information and the
819 new_addr
.type
= DEBUG_ParseStabType(ptr
);
820 new_addr
.off
= load_offset
+ stab_ptr
->n_value
;
822 * Copy the string to a temp buffer so we
823 * can kill everything after the ':'. We do
824 * it this way because otherwise we end up dirtying
825 * all of the pages related to the stabs, and that
826 * sucks up swap space like crazy.
828 stab_strcpy(symname
, ptr
);
829 curr_func
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
,
830 SYM_WINE
| SYM_FUNC
);
835 * Don't add line number information for this function
843 * This indicates a new source file. Append the records
844 * together, to build the correct path name.
848 * With a.out, there is no NULL string N_SO entry at the end of
849 * the file. Thus when we find non-consecutive entries,
850 * we consider that a new file is started.
855 DEBUG_Normalize(curr_func
);
866 DEBUG_Normalize(curr_func
);
869 * The datatypes that we would need to use are reset when
870 * we start a new file.
872 memset(stab_types
, 0, num_stab_types
* sizeof(stab_types
[0]));
874 for (i=0;i<nrofnroftypenums;i++)
875 memset(typenums[i],0,sizeof(typenums[i][0])*nroftypenums[i]);
881 strcat(currpath
, ptr
);
883 strcpy(currpath
, ptr
);
890 * This indicates we are including stuff from an include file.
891 * If this is the main source, enable the debug stuff, otherwise
894 if( subpath
== NULL
|| strcmp(ptr
, subpath
) == 0 )
901 DEBUG_Normalize(curr_func
);
907 strtabinc
= stab_ptr
->n_value
;
908 DEBUG_Normalize(curr_func
);
913 * Ignore this. We don't care what it points to.
920 * Always ignore these. GCC doesn't even generate them.
930 fprintf(stderr
, "%d %x %s\n", stab_ptr
->n_type
,
931 (unsigned int) stab_ptr
->n_value
,
932 strs
+ (unsigned int) stab_ptr
->n_un
.n_name
);
936 if( stab_types
!= NULL
)
944 DEBUG_FreeRegisteredTypedefs();
952 * Walk through the entire symbol table and add any symbols we find there.
953 * This can be used in cases where we have stripped ELF shared libraries,
954 * or it can be used in cases where we have data symbols for which the address
955 * isn't encoded in the stabs.
957 * This is all really quite easy, since we don't have to worry about line
958 * numbers or local data variables.
962 DEBUG_ProcessElfSymtab(char * addr
, unsigned int load_offset
,
963 Elf32_Shdr
* symtab
, Elf32_Shdr
* strtab
)
965 char * curfile
= NULL
;
966 struct name_hash
* curr_sym
= NULL
;
976 symp
= (Elf32_Sym
*) (addr
+ symtab
->sh_offset
);
977 nsym
= symtab
->sh_size
/ sizeof(*symp
);
978 strp
= (char *) (addr
+ strtab
->sh_offset
);
980 for(i
=0; i
< nsym
; i
++, symp
++)
983 * Ignore certain types of entries which really aren't of that much
986 if( ELF32_ST_TYPE(symp
->st_info
) == STT_SECTION
)
991 symname
= strp
+ symp
->st_name
;
994 * Save the name of the current file, so we have a way of tracking
995 * static functions/data.
997 if( ELF32_ST_TYPE(symp
->st_info
) == STT_FILE
)
1005 * See if we already have something for this symbol.
1006 * If so, ignore this entry, because it would have come from the
1007 * stabs or from a previous symbol. If the value is different,
1008 * we will have to keep the darned thing, because there can be
1009 * multiple local symbols by the same name.
1011 if( (DEBUG_GetSymbolValue(symname
, -1, &new_addr
, FALSE
) == TRUE
)
1012 && (new_addr
.off
== (load_offset
+ symp
->st_value
)) )
1016 new_addr
.type
= NULL
;
1017 new_addr
.off
= load_offset
+ symp
->st_value
;
1018 flags
= SYM_WINE
| (ELF32_ST_BIND(symp
->st_info
) == STT_FUNC
1019 ? SYM_FUNC
: SYM_DATA
);
1020 if( ELF32_ST_BIND(symp
->st_info
) == STB_GLOBAL
)
1021 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, NULL
, flags
);
1023 curr_sym
= DEBUG_AddSymbol( symname
, &new_addr
, curfile
, flags
);
1026 * Record the size of the symbol. This can come in handy in
1027 * some cases. Not really used yet, however.
1029 if( symp
->st_size
!= 0 )
1030 DEBUG_SetSymbolSize(curr_sym
, symp
->st_size
);
1038 DEBUG_ProcessElfObject(char * filename
, unsigned int load_offset
)
1041 struct stat statbuf
;
1044 char * addr
= (char *) 0xffffffff;
1055 * Make sure we can stat and open this file.
1057 if( filename
== NULL
)
1060 status
= stat(filename
, &statbuf
);
1063 char *s
,*t
,*fn
,*paths
;
1064 if (strchr(filename
,'/'))
1066 paths
= xstrdup(getenv("PATH"));
1071 fn
= (char*)xmalloc(strlen(filename
)+1+strlen(s
)+1);
1074 strcat(fn
,filename
);
1075 if ((rtn
= DEBUG_ProcessElfObject(fn
,load_offset
))) {
1081 if (t
) s
= t
+1; else break;
1083 if (!s
|| !*s
) fprintf(stderr
," not found");
1089 * Now open the file, so that we can mmap() it.
1091 fd
= open(filename
, O_RDONLY
);
1097 * Now mmap() the file.
1099 addr
= mmap(0, statbuf
.st_size
, PROT_READ
,
1100 MAP_PRIVATE
, fd
, 0);
1101 if( addr
== (char *) 0xffffffff )
1105 * Next, we need to find a few of the internal ELF headers within
1106 * this thing. We need the main executable header, and the section
1109 ehptr
= (Elf32_Ehdr
*) addr
;
1111 if( load_offset
== 0 )
1112 DEBUG_RegisterELFDebugInfo(ehptr
->e_entry
, statbuf
.st_size
, filename
);
1114 DEBUG_RegisterELFDebugInfo(load_offset
, statbuf
.st_size
, filename
);
1116 spnt
= (Elf32_Shdr
*) (addr
+ ehptr
->e_shoff
);
1117 nsect
= ehptr
->e_shnum
;
1118 shstrtab
= (addr
+ spnt
[ehptr
->e_shstrndx
].sh_offset
);
1120 stabsect
= stabstrsect
= -1;
1122 for(i
=0; i
< nsect
; i
++)
1124 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stab") == 0 )
1127 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stabstr") == 0 )
1131 if( stabsect
== -1 || stabstrsect
== -1 )
1135 * OK, now just parse all of the stabs.
1137 rtn
= DEBUG_ParseStabs(addr
, load_offset
,
1138 spnt
[stabsect
].sh_offset
,
1139 spnt
[stabsect
].sh_size
,
1140 spnt
[stabstrsect
].sh_offset
,
1141 spnt
[stabstrsect
].sh_size
);
1146 for(i
=0; i
< nsect
; i
++)
1148 if( (strcmp(shstrtab
+ spnt
[i
].sh_name
, ".symtab") == 0)
1149 && (spnt
[i
].sh_type
== SHT_SYMTAB
) )
1150 DEBUG_ProcessElfSymtab(addr
, load_offset
,
1151 spnt
+ i
, spnt
+ spnt
[i
].sh_link
);
1153 if( (strcmp(shstrtab
+ spnt
[i
].sh_name
, ".dynsym") == 0)
1154 && (spnt
[i
].sh_type
== SHT_DYNSYM
) )
1155 DEBUG_ProcessElfSymtab(addr
, load_offset
,
1156 spnt
+ i
, spnt
+ spnt
[i
].sh_link
);
1161 if( addr
!= (char *) 0xffffffff )
1162 munmap(addr
, statbuf
.st_size
);
1172 DEBUG_ReadExecutableDbgInfo(void)
1177 struct r_debug
* dbg_hdr
;
1178 struct link_map
* lpnt
= NULL
;
1179 extern Elf32_Dyn _DYNAMIC
[];
1183 exe_name
= DEBUG_argv0
;
1186 * Make sure we can stat and open this file.
1188 if( exe_name
== NULL
)
1191 fprintf( stderr
, "Loading symbols: %s", exe_name
);
1192 rowcount
= 17 + strlen(exe_name
);
1193 DEBUG_ProcessElfObject(exe_name
, 0);
1196 * Finally walk the tables that the dynamic loader maintains to find all
1197 * of the other shared libraries which might be loaded. Perform the
1198 * same step for all of these.
1201 if( dynpnt
== NULL
)
1205 * Now walk the dynamic section (of the executable, looking for a DT_DEBUG
1208 for(; dynpnt
->d_tag
!= DT_NULL
; dynpnt
++)
1209 if( dynpnt
->d_tag
== DT_DEBUG
)
1212 if( (dynpnt
->d_tag
!= DT_DEBUG
)
1213 || (dynpnt
->d_un
.d_ptr
== 0) )
1217 * OK, now dig into the actual tables themselves.
1219 dbg_hdr
= (struct r_debug
*) dynpnt
->d_un
.d_ptr
;
1220 lpnt
= dbg_hdr
->r_map
;
1223 * Now walk the linked list. In all known ELF implementations,
1224 * the dynamic loader maintains this linked list for us. In some
1225 * cases the first entry doesn't appear with a name, in other cases it
1228 for(; lpnt
; lpnt
= lpnt
->l_next
)
1231 * We already got the stuff for the executable using the
1232 * argv[0] entry above. Here we only need to concentrate on any
1233 * shared libraries which may be loaded.
1235 ehdr
= (Elf32_Ehdr
*) lpnt
->l_addr
;
1236 if( (lpnt
->l_addr
== 0) || (ehdr
->e_type
!= ET_DYN
) )
1239 if( lpnt
->l_name
!= NULL
)
1241 if (rowcount
+ strlen(lpnt
->l_name
) > 76)
1243 fprintf( stderr
, "\n " );
1246 fprintf( stderr
, " %s", lpnt
->l_name
);
1247 rowcount
+= strlen(lpnt
->l_name
) + 1;
1248 DEBUG_ProcessElfObject(lpnt
->l_name
, lpnt
->l_addr
);
1255 fprintf( stderr
, "\n" );
1260 #else /* !__ELF__ */
1267 DEBUG_ReadExecutableDbgInfo(void)
1269 char * addr
= (char *) 0xffffffff;
1274 unsigned int staboff
;
1275 struct stat statbuf
;
1277 unsigned int stroff
;
1279 exe_name
= DEBUG_argv0
;
1282 * Make sure we can stat and open this file.
1284 if( exe_name
== NULL
)
1287 status
= stat(exe_name
, &statbuf
);
1292 * Now open the file, so that we can mmap() it.
1294 fd
= open(exe_name
, O_RDONLY
);
1300 * Now mmap() the file.
1302 addr
= mmap(0, statbuf
.st_size
, PROT_READ
,
1303 MAP_PRIVATE
, fd
, 0);
1304 if( addr
== (char *) 0xffffffff )
1307 ahdr
= (struct exec
*) addr
;
1309 staboff
= N_SYMOFF(*ahdr
);
1310 stroff
= N_STROFF(*ahdr
);
1311 rtn
= DEBUG_ParseStabs(addr
, 0,
1315 statbuf
.st_size
- stroff
);
1318 * Give a nice status message here...
1320 fprintf( stderr
, "Loading symbols: %s", exe_name
);
1326 if( addr
!= (char *) 0xffffffff )
1327 munmap(addr
, statbuf
.st_size
);
1337 * Non-linux, non-ELF platforms.
1340 DEBUG_ReadExecutableDbgInfo(void)
1346 #endif /* __ELF__ */