2 * File stabs.c - read stabs information from the wine executable itself.
4 * Copyright (C) 1996, Eric Youngdale.
43 * Set so that we know the main executable name and path.
50 struct stab_nlist
*n_next
;
56 unsigned long n_value
;
62 DEBUG_ParseStabs(char * addr
, Elf32_Shdr
* stabsect
, Elf32_Shdr
* stabstr
)
67 struct stab_nlist
* stab_ptr
;
71 char currpath
[PATH_MAX
];
73 char * subpath
= NULL
;
75 struct name_hash
* curr_func
= NULL
;
78 nstab
= stabsect
->sh_size
/ sizeof(struct stab_nlist
);
79 stab_ptr
= (struct stab_nlist
*) (addr
+ stabsect
->sh_offset
);
80 strs
= (char *) (addr
+ stabstr
->sh_offset
);
82 memset(currpath
, 0, sizeof(currpath
));
85 for(i
=0; i
< nstab
; i
++, stab_ptr
++ )
87 ptr
= strs
+ (unsigned int) stab_ptr
->n_un
.n_name
;
88 switch(stab_ptr
->n_type
)
92 * These are useless. They have no value, and you have to
93 * read the normal symbol table to get the address. Thus we
94 * ignore them, and when we process the normal symbol table
95 * we should do the right thing.
100 * We need to keep track of these so we get symbol scoping
101 * right for local variables. For now, we just ignore them.
102 * The hooks are already there for dealing with this however,
103 * so all we need to do is to keep count of the nesting level,
104 * and find the RBRAC for each matching LBRAC.
110 * These are static symbols and BSS symbols.
113 new_addr
.off
= stab_ptr
->n_value
;
115 strcpy(symname
, ptr
);
116 xptr
= strchr(symname
, ':');
121 DEBUG_AddSymbol( symname
, &new_addr
, currpath
);
125 * These are function parameters.
127 if( (curr_func
!= NULL
)
128 && (stab_ptr
->n_value
!= 0) )
130 strcpy(symname
, ptr
);
131 xptr
= strchr(symname
, ':');
136 DEBUG_AddLocal(curr_func
, 0,
137 stab_ptr
->n_value
, 0, 0, symname
);
141 if( curr_func
!= NULL
)
143 strcpy(symname
, ptr
);
144 xptr
= strchr(symname
, ':');
149 DEBUG_AddLocal(curr_func
, stab_ptr
->n_value
, 0, 0, 0, symname
);
153 if( (curr_func
!= NULL
)
154 && (stab_ptr
->n_value
!= 0) )
156 strcpy(symname
, ptr
);
157 xptr
= strchr(symname
, ':');
162 DEBUG_AddLocal(curr_func
, 0,
163 stab_ptr
->n_value
, 0, 0, symname
);
168 * This is a line number. These are always relative to the start
169 * of the function (N_FUN), and this makes the lookup easier.
171 if( curr_func
!= NULL
)
173 DEBUG_AddLineNumber(curr_func
, stab_ptr
->n_desc
,
179 * For now, just declare the various functions. Later
180 * on, we will add the line number information and the
186 new_addr
.off
= stab_ptr
->n_value
;
188 * Copy the string to a temp buffer so we
189 * can kill everything after the ':'. We do
190 * it this way because otherwise we end up dirtying
191 * all of the pages related to the stabs, and that
192 * sucks up swap space like crazy.
194 strcpy(symname
, ptr
);
195 xptr
= strchr(symname
, ':');
200 curr_func
= DEBUG_AddSymbol( symname
, &new_addr
, currpath
);
205 * Don't add line number information for this function
213 * This indicates a new source file. Append the records
214 * together, to build the correct path name.
226 strcat(currpath
, ptr
);
232 * This indicates we are including stuff from an include file.
233 * If this is the main source, enable the debug stuff, otherwise
236 if( subpath
== NULL
|| strcmp(ptr
, subpath
) == 0 )
248 strtabinc
= stab_ptr
->n_value
;
253 * Ignore this. We don't care what it points to.
260 * Always ignore these. GCC doesn't even generate them.
267 fprintf(stderr
, "%d %x %s\n", stab_ptr
->n_type
,
268 (unsigned int) stab_ptr
->n_value
,
269 strs
+ (unsigned int) stab_ptr
->n_un
.n_name
);
276 DEBUG_ReadExecutableDbgInfo(void)
283 char * addr
= (char *) 0xffffffff;
292 exe_name
= DEBUG_argv0
;
295 * Make sure we can stat and open this file.
297 if( exe_name
== NULL
)
302 status
= stat(exe_name
, &statbuf
);
309 * Now open the file, so that we can mmap() it.
311 fd
= open(exe_name
, O_RDONLY
);
319 * Now mmap() the file.
321 addr
= mmap(0, statbuf
.st_size
, PROT_READ
,
325 * Next, we need to find a few of the internal ELF headers within
326 * this thing. We need the main executable header, and the section
329 ehptr
= (Elf32_Ehdr
*) addr
;
330 spnt
= (Elf32_Shdr
*) (addr
+ ehptr
->e_shoff
);
331 nsect
= ehptr
->e_shnum
;
332 shstrtab
= (addr
+ spnt
[ehptr
->e_shstrndx
].sh_offset
);
334 stabsect
= stabstrsect
= -1;
336 for(i
=0; i
< nsect
; i
++)
338 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stab") == 0 )
343 if( strcmp(shstrtab
+ spnt
[i
].sh_name
, ".stabstr") == 0 )
349 if( stabsect
== -1 || stabstrsect
== -1 )
355 * OK, now just parse all of the stabs.
357 rtn
= DEBUG_ParseStabs(addr
, spnt
+ stabsect
, spnt
+ stabstrsect
);
361 if( addr
!= (char *) 0xffffffff )
363 munmap(addr
, statbuf
.st_size
);