1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * File stabs.c - read stabs information from the wine executable itself.
6 * Copyright (C) 1996, Eric Youngdale.
7 * 1999-2003 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Maintenance Information
25 * -----------------------
27 * For documentation on the stabs format see for example
28 * The "stabs" debug format
29 * by Julia Menapace, Jim Kingdon, David Mackenzie
31 * available (hopefully) from http:\\sources.redhat.com\gdb\onlinedocs
36 #include <sys/types.h>
39 #ifdef HAVE_SYS_MMAN_H
48 #define PATH_MAX MAX_PATH
53 #if defined(__svr4__) || defined(__sun)
64 #ifdef HAVE_SYS_LINK_H
65 # include <sys/link.h>
96 typedef struct tagELF_DBG_INFO
104 struct stab_nlist *n_next;
107 unsigned char n_type;
110 unsigned long n_value;
113 static void stab_strcpy(char * dest, int sz, const char * source)
116 * A strcpy routine that stops when we hit the ':' character.
117 * Faster than copying the whole thing, and then nuking the
120 while(*source != '\0' && *source != ':' && sz-- > 0)
130 struct datatype** vector;
134 #define MAX_INCLUDES 5120
136 static include_def* include_defs = NULL;
137 static int num_include_def = 0;
138 static int num_alloc_include_def = 0;
139 static int cu_include_stack[MAX_INCLUDES];
140 static int cu_include_stk_idx = 0;
141 static struct datatype** cu_vector = NULL;
142 static int cu_nrofentries = 0;
146 DEBUG_CreateInclude(const char* file, unsigned long val)
148 if (num_include_def == num_alloc_include_def)
150 num_alloc_include_def += 256;
151 include_defs = DBG_realloc(include_defs, sizeof(include_defs[0])*num_alloc_include_def);
152 memset(include_defs+num_include_def, 0, sizeof(include_defs[0])*256);
154 include_defs[num_include_def].name = DBG_strdup(file);
155 include_defs[num_include_def].value = val;
156 include_defs[num_include_def].vector = NULL;
157 include_defs[num_include_def].nrofentries = 0;
159 return num_include_def++;
164 DEBUG_FindInclude(const char* file, unsigned long val)
168 for (i = 0; i < num_include_def; i++)
170 if (val == include_defs[i].value &&
171 strcmp(file, include_defs[i].name) == 0)
179 DEBUG_AddInclude(int idx)
181 ++cu_include_stk_idx;
183 /* is this happen, just bump MAX_INCLUDES */
184 /* we could also handle this as another dynarray */
185 assert(cu_include_stk_idx < MAX_INCLUDES);
187 cu_include_stack[cu_include_stk_idx] = idx;
188 return cu_include_stk_idx;
193 DEBUG_ResetIncludes(void)
196 * The datatypes that we would need to use are reset when
197 * we start a new file. (at least the ones in filenr == 0
199 cu_include_stk_idx = 0;/* keep 0 as index for the .c file itself */
200 memset(cu_vector, 0, sizeof(cu_vector[0]) * cu_nrofentries);
205 DEBUG_FreeIncludes(void)
209 DEBUG_ResetIncludes();
211 for (i = 0; i < num_include_def; i++)
213 DBG_free(include_defs[i].name);
214 DBG_free(include_defs[i].vector);
216 DBG_free(include_defs);
219 num_alloc_include_def = 0;
227 DEBUG_FileSubNr2StabEnum(int filenr, int subnr)
229 struct datatype** ret;
231 /* DEBUG_Printf(DBG_CHN_MESG, "creating type id for (%d,%d)\n", filenr, subnr); */
233 /* FIXME: I could perhaps create a dummy include_def for each compilation
234 * unit which would allow not to handle those two cases separately
238 if (cu_nrofentries <= subnr)
240 cu_vector = DBG_realloc(cu_vector, sizeof(cu_vector[0])*(subnr+1));
241 memset(cu_vector+cu_nrofentries, 0, sizeof(cu_vector[0])*(subnr+1-cu_nrofentries));
242 cu_nrofentries = subnr + 1;
244 ret = &cu_vector[subnr];
250 assert(filenr <= cu_include_stk_idx);
252 idef = &include_defs[cu_include_stack[filenr]];
254 if (idef->nrofentries <= subnr)
256 idef->vector = DBG_realloc(idef->vector, sizeof(idef->vector[0])*(subnr+1));
257 memset(idef->vector + idef->nrofentries, 0, sizeof(idef->vector[0])*(subnr+1-idef->nrofentries));
258 idef->nrofentries = subnr + 1;
260 ret = &idef->vector[subnr];
262 /* DEBUG_Printf(DBG_CHN_MESG,"(%d,%d) is %d\n",filenr,subnr,ret); */
268 DEBUG_ReadTypeEnum(char **x) {
273 filenr=strtol(*x,x,10); /* <int> */
275 subnr=strtol(*x,x,10); /* <int> */
279 subnr = strtol(*x,x,10); /* <int> */
281 return DEBUG_FileSubNr2StabEnum(filenr,subnr);
284 /*#define PTS_DEBUG*/
285 struct ParseTypedefData
301 static void PTS_Push(struct ParseTypedefData* ptd, unsigned line)
303 assert(ptd->err_idx < sizeof(ptd->errors) / sizeof(ptd->errors[0]));
304 ptd->errors[ptd->err_idx].line = line;
305 ptd->errors[ptd->err_idx].ptr = ptd->ptr;
308 #define PTS_ABORTIF(ptd, t) do { if (t) { PTS_Push((ptd), __LINE__); return -1;} } while (0)
310 #define PTS_ABORTIF(ptd, t) do { if (t) return -1; } while (0)
313 static int DEBUG_PTS_ReadTypedef(struct ParseTypedefData* ptd, const char* typename,
314 struct datatype** dt);
316 static int DEBUG_PTS_ReadID(struct ParseTypedefData* ptd)
318 char* first = ptd->ptr;
321 PTS_ABORTIF(ptd, (ptd->ptr = strchr(ptd->ptr, ':')) == NULL);
322 len = ptd->ptr - first;
323 PTS_ABORTIF(ptd, len >= sizeof(ptd->buf) - ptd->idx);
324 memcpy(ptd->buf + ptd->idx, first, len);
325 ptd->buf[ptd->idx + len] = '\0';
327 ptd->ptr++; /* ':' */
331 static int DEBUG_PTS_ReadNum(struct ParseTypedefData* ptd, int* v)
335 *v = strtol(ptd->ptr, &last, 10);
336 PTS_ABORTIF(ptd, last == ptd->ptr);
341 static int DEBUG_PTS_ReadTypeReference(struct ParseTypedefData* ptd,
342 int* filenr, int* subnr)
344 if (*ptd->ptr == '(') {
345 /* '(' <int> ',' <int> ')' */
347 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, filenr) == -1);
348 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
349 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, subnr) == -1);
350 PTS_ABORTIF(ptd, *ptd->ptr++ != ')');
353 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, subnr) == -1);
358 static int DEBUG_PTS_ReadRange(struct ParseTypedefData* ptd, struct datatype** dt,
361 /* type ';' <int> ';' <int> ';' */
362 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, dt) == -1);
363 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
364 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, lo) == -1);
365 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
366 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, hi) == -1);
367 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
371 static inline int DEBUG_PTS_ReadMethodInfo(struct ParseTypedefData* ptd)
379 /* get type of return value */
380 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
381 if (*ptd->ptr == ';') ptd->ptr++;
383 /* get types of parameters */
384 if (*ptd->ptr == ':')
386 PTS_ABORTIF(ptd, !(tmp = strchr(ptd->ptr + 1, ';')));
389 PTS_ABORTIF(ptd, !(*ptd->ptr >= '0' && *ptd->ptr <= '9'));
391 PTS_ABORTIF(ptd, !(ptd->ptr[0] >= 'A' && *ptd->ptr <= 'D'));
393 PTS_ABORTIF(ptd, mthd != '.' && mthd != '?' && mthd != '*');
400 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &ofs) == -1);
401 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
402 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
403 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
405 } while (*ptd->ptr != ';');
411 static inline int DEBUG_PTS_ReadAggregate(struct ParseTypedefData* ptd,
412 struct datatype* sdt)
415 struct datatype* adt;
416 struct datatype* dt = NULL;
420 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &sz) == -1);
422 doadd = DEBUG_SetStructSize(sdt, sz);
423 if (*ptd->ptr == '!') /* C++ inheritence */
429 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &num_classes) == -1);
430 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
431 while (--num_classes >= 0)
433 ptd->ptr += 2; /* skip visibility and inheritence */
434 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &ofs) == -1);
435 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
437 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &adt) == -1);
439 snprintf(tmp, sizeof(tmp), "__inherited_class_%s", DEBUG_GetName(adt));
440 /* FIXME: DEBUG_GetObjectSize will not always work, especially when adt
441 * has just been seen as a forward definition and not the real stuff yet.
442 * As we don't use much the size of members in structs, this may not
443 * be much of a problem
445 if (doadd) DEBUG_AddStructElement(sdt, tmp, adt, ofs, DEBUG_GetObjectSize(adt) * 8);
446 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
450 /* if the structure has already been filled, just redo the parsing
451 * but don't store results into the struct
452 * FIXME: there's a quite ugly memory leak in there...
455 /* Now parse the individual elements of the structure/union. */
456 while (*ptd->ptr != ';')
458 /* agg_name : type ',' <int:offset> ',' <int:size> */
461 if (ptd->ptr[0] == '$' && ptd->ptr[1] == 'v')
465 if (ptd->ptr[2] == 'f')
467 /* C++ virtual method table */
469 DEBUG_ReadTypeEnum(&ptd->ptr);
470 PTS_ABORTIF(ptd, *ptd->ptr++ != ':');
471 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
472 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
473 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &x) == -1);
474 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
478 else if (ptd->ptr[2] == 'b')
481 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
482 PTS_ABORTIF(ptd, *ptd->ptr++ != ':');
483 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
484 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
485 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &x) == -1);
486 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
492 PTS_ABORTIF(ptd, DEBUG_PTS_ReadID(ptd) == -1);
493 /* Ref. TSDF R2.130 Section 7.4. When the field name is a method name
494 * it is followed by two colons rather than one.
496 if (*ptd->ptr == ':')
499 DEBUG_PTS_ReadMethodInfo(ptd);
505 /* skip C++ member protection /0 /1 or /2 */
506 if (*ptd->ptr == '/') ptd->ptr += 2;
508 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &adt) == -1);
513 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &ofs) == -1);
514 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
515 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &sz) == -1);
516 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
518 if (doadd) DEBUG_AddStructElement(sdt, ptd->buf + idx, adt, ofs, sz);
523 /* method parameters... terminated by ';' */
524 PTS_ABORTIF(ptd, !(tmp = strchr(ptd->ptr, ';')));
529 PTS_ABORTIF(ptd, TRUE);
533 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
534 if (*ptd->ptr == '~')
537 PTS_ABORTIF(ptd, *ptd->ptr++ != '%');
538 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &dt) == -1);
539 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
544 static inline int DEBUG_PTS_ReadEnum(struct ParseTypedefData* ptd,
545 struct datatype* edt)
550 while (*ptd->ptr != ';') {
552 PTS_ABORTIF(ptd, DEBUG_PTS_ReadID(ptd) == -1);
553 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &ofs) == -1);
554 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
555 DEBUG_AddStructElement(edt, ptd->buf + idx, NULL, ofs, 0);
562 static inline int DEBUG_PTS_ReadArray(struct ParseTypedefData* ptd,
563 struct datatype* adt)
566 struct datatype* rdt;
568 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo> */
570 PTS_ABORTIF(ptd, *ptd->ptr++ != 'r');
571 /* FIXME: range type is lost, always assume int */
572 PTS_ABORTIF(ptd, DEBUG_PTS_ReadRange(ptd, &rdt, &lo, &hi) == -1);
573 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &rdt) == -1);
575 DEBUG_SetArrayParams(adt, lo, hi, rdt);
579 static int DEBUG_PTS_ReadTypedef(struct ParseTypedefData* ptd, const char* typename,
580 struct datatype** ret_dt)
582 int idx, lo, hi, sz = -1;
583 struct datatype* new_dt = NULL; /* newly created data type */
584 struct datatype* ref_dt; /* referenced data type (pointer...) */
585 struct datatype* dt1; /* intermediate data type (scope is limited) */
586 struct datatype* dt2; /* intermediate data type: t1=t2=new_dt */
589 /* things are a bit complicated because of the way the typedefs are stored inside
590 * the file (we cannot keep the struct datatype** around, because address can
591 * change when realloc is done, so we must call over and over
592 * DEBUG_FileSubNr2StabEnum to keep the correct values around
593 * (however, keeping struct datatype* is valid))
595 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypeReference(ptd, &filenr1, &subnr1) == -1);
597 while (*ptd->ptr == '=') {
599 PTS_ABORTIF(ptd, new_dt != NULL);
601 /* first handle attribute if any */
604 if (*++ptd->ptr == 's') {
606 if (DEBUG_PTS_ReadNum(ptd, &sz) == -1) {
607 DEBUG_Printf(DBG_CHN_MESG, "Not an attribute... NIY\n");
611 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
615 /* then the real definitions */
616 switch (*ptd->ptr++) {
619 new_dt = DEBUG_NewDataType(DT_POINTER, NULL);
620 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &ref_dt) == -1);
621 DEBUG_SetPointerType(new_dt, ref_dt);
623 case 'k': /* 'const' modifier */
624 case 'B': /* 'volatile' modifier */
625 /* just kinda ignore the modifier, I guess -gmt */
626 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, typename, &new_dt) == -1);
630 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, typename, &new_dt) == -1);
633 new_dt = DEBUG_NewDataType(DT_ARRAY, NULL);
634 PTS_ABORTIF(ptd, DEBUG_PTS_ReadArray(ptd, new_dt) == -1);
637 new_dt = DEBUG_NewDataType(DT_BASIC, typename);
638 assert(!*DEBUG_FileSubNr2StabEnum(filenr1, subnr1));
639 *DEBUG_FileSubNr2StabEnum(filenr1, subnr1) = new_dt;
640 PTS_ABORTIF(ptd, DEBUG_PTS_ReadRange(ptd, &ref_dt, &lo, &hi) == -1);
641 /* should perhaps do more here... */
644 new_dt = DEBUG_NewDataType(DT_FUNC, NULL);
645 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &ref_dt) == -1);
646 DEBUG_SetPointerType(new_dt, ref_dt);
649 new_dt = DEBUG_NewDataType(DT_ENUM, NULL);
650 PTS_ABORTIF(ptd, DEBUG_PTS_ReadEnum(ptd, new_dt) == -1);
654 /* dt1 can have been already defined in a forward definition */
655 dt1 = *DEBUG_FileSubNr2StabEnum(filenr1, subnr1);
656 dt2 = DEBUG_TypeCast(DT_STRUCT, typename);
658 new_dt = DEBUG_NewDataType(DT_STRUCT, typename);
659 /* we need to set it here, because a struct can hold a pointer
662 *DEBUG_FileSubNr2StabEnum(filenr1, subnr1) = new_dt;
664 if (DEBUG_GetType(dt1) != DT_STRUCT) {
665 DEBUG_Printf(DBG_CHN_MESG,
666 "Forward declaration is not an aggregate\n");
670 /* should check typename is the same too */
673 PTS_ABORTIF(ptd, DEBUG_PTS_ReadAggregate(ptd, new_dt) == -1);
676 switch (*ptd->ptr++) {
677 case 'e': lo = DT_ENUM; break;
678 case 's': case 'u': lo = DT_STRUCT; break;
683 PTS_ABORTIF(ptd, DEBUG_PTS_ReadID(ptd) == -1);
684 new_dt = DEBUG_NewDataType(lo, ptd->buf + idx);
689 enum debug_type_basic basic = DT_BASIC_LAST;
691 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &lo) == -1);
695 case 1: basic = DT_BASIC_INT; break;
696 case 2: basic = DT_BASIC_CHAR; break;
697 case 3: basic = DT_BASIC_SHORTINT; break;
698 case 4: basic = DT_BASIC_LONGINT; break;
699 case 5: basic = DT_BASIC_UCHAR; break;
700 case 6: basic = DT_BASIC_SCHAR; break;
701 case 7: basic = DT_BASIC_USHORTINT; break;
702 case 8: basic = DT_BASIC_UINT; break;
703 /* case 9: basic = DT_BASIC_UINT"; */
704 case 10: basic = DT_BASIC_ULONGINT; break;
705 case 11: basic = DT_BASIC_VOID; break;
706 case 12: basic = DT_BASIC_FLOAT; break;
707 case 13: basic = DT_BASIC_DOUBLE; break;
708 case 14: basic = DT_BASIC_LONGDOUBLE; break;
709 /* case 15: basic = DT_BASIC_INT; break; */
712 case 32: basic = DT_BASIC_BOOL1; break;
713 case 16: basic = DT_BASIC_BOOL2; break;
714 case 8: basic = DT_BASIC_BOOL4; break;
717 /* case 17: basic = DT_BASIC_SHORT real; break; */
718 /* case 18: basic = DT_BASIC_REAL; break; */
719 case 25: basic = DT_BASIC_CMPLX_FLOAT; break;
720 case 26: basic = DT_BASIC_CMPLX_DOUBLE; break;
721 /* case 30: basic = DT_BASIC_wchar"; break; */
722 case 31: basic = DT_BASIC_LONGLONGINT; break;
723 case 32: basic = DT_BASIC_ULONGLONGINT; break;
727 PTS_ABORTIF(ptd, !(new_dt = DEBUG_GetBasicType(basic)));
728 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
732 new_dt = DEBUG_NewDataType(DT_FUNC, NULL);
733 if (*ptd->ptr == '#')
736 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &ref_dt) == -1);
737 DEBUG_SetPointerType(new_dt, ref_dt);
741 struct datatype* cls_dt;
742 struct datatype* pmt_dt;
744 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &cls_dt) == -1);
745 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
746 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &ref_dt) == -1);
747 DEBUG_SetPointerType(new_dt, ref_dt);
748 while (*ptd->ptr == ',')
751 PTS_ABORTIF(ptd, DEBUG_PTS_ReadTypedef(ptd, NULL, &pmt_dt) == -1);
757 enum debug_type_basic basic = DT_BASIC_LAST;
760 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &type) == -1);
761 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
762 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &len) == -1);
763 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
764 PTS_ABORTIF(ptd, DEBUG_PTS_ReadNum(ptd, &unk) == -1);
765 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
769 case 1: basic = DT_BASIC_FLOAT; break;
770 case 2: basic = DT_BASIC_DOUBLE; break;
771 case 3: basic = DT_BASIC_CMPLX_FLOAT; break;
772 case 4: basic = DT_BASIC_CMPLX_DOUBLE; break;
773 case 5: basic = DT_BASIC_CMPLX_LONGDOUBLE; break;
774 case 6: basic = DT_BASIC_LONGDOUBLE; break;
775 default: PTS_ABORTIF(ptd, 1);
777 PTS_ABORTIF(ptd, !(new_dt = DEBUG_GetBasicType(basic)));
781 DEBUG_Printf(DBG_CHN_MESG, "Unknown type '%c'\n", ptd->ptr[-1]);
788 /* is it a forward declaration that has been filled ? */
789 new_dt = *DEBUG_FileSubNr2StabEnum(filenr1, subnr1);
790 /* if not, this should then be a basic type: define it, or even void */
792 new_dt = DEBUG_NewDataType(DT_BASIC, typename);
795 *DEBUG_FileSubNr2StabEnum(filenr1, subnr1) = *ret_dt = new_dt;
799 DEBUG_Printf(DBG_CHN_MESG, "Adding (%d,%d) %s => ", filenr1, subnr1, typename);
800 DEBUG_PrintTypeCast(new_dt);
801 DEBUG_Printf(DBG_CHN_MESG, "\n");
808 static int DEBUG_ParseTypedefStab(char* ptr, const char* typename)
810 struct ParseTypedefData ptd;
814 /* check for already existing definition */
820 for (ptd.ptr = ptr - 1; ;)
822 ptd.ptr = strchr(ptd.ptr + 1, ':');
823 if (ptd.ptr == NULL || *++ptd.ptr != ':') break;
828 if (*ptd.ptr != '(') ptd.ptr++;
829 /* most of type definitions take one char, except Tt */
830 if (*ptd.ptr != '(') ptd.ptr++;
831 ret = DEBUG_PTS_ReadTypedef(&ptd, typename, &dt);
834 if (ret == -1 || *ptd.ptr) {
837 DEBUG_Printf(DBG_CHN_MESG, "Failure on %s\n", ptr);
840 for (i = 0; i < ptd.err_idx; i++)
842 DEBUG_Printf(DBG_CHN_MESG, "[%d]: line %d => %s\n",
843 i, ptd.errors[i].line, ptd.errors[i].ptr);
847 DEBUG_Printf(DBG_CHN_MESG, "[0]: => %s\n", ptd.ptr);
850 DEBUG_Printf(DBG_CHN_MESG, "Failure on %s at %s\n", ptr, ptd.ptr);
858 static struct datatype *
859 DEBUG_ParseStabType(const char * stab)
861 const char* c = stab - 1;
864 * Look through the stab definition, and figure out what datatype
865 * this represents. If we have something we know about, assign the
867 * According to "The \"stabs\" debug format" (Rev 2.130) the name may be
868 * a C++ name and contain double colons e.g. foo::bar::baz:t5=*6.
872 if ((c = strchr(c + 1, ':')) == NULL) return NULL;
873 } while (*++c == ':');
876 * The next characters say more about the type (i.e. data, function, etc)
877 * of symbol. Skip them. (C++ for example may have Tt).
878 * Actually this is a very weak description; I think Tt is the only
879 * multiple combination we should see.
881 while (*c && *c != '(' && !isdigit(*c))
884 * The next is either an integer or a (integer,integer).
885 * The DEBUG_ReadTypeEnum takes care that stab_types is large enough.
887 return *DEBUG_ReadTypeEnum((char**)&c);
890 enum DbgInfoLoad DEBUG_ParseStabs(char * addr, void *load_offset,
891 unsigned int staboff, int stablen,
892 unsigned int strtaboff, int strtablen)
894 struct name_hash * curr_func = NULL;
895 struct wine_locals * curr_loc = NULL;
896 struct name_hash * curr_sym = NULL;
897 char currpath[PATH_MAX];
899 int in_external_file = FALSE;
906 unsigned int stabbufflen;
907 struct stab_nlist * stab_ptr;
910 char * subpath = NULL;
913 nstab = stablen / sizeof(struct stab_nlist);
914 stab_ptr = (struct stab_nlist *) (addr + staboff);
915 strs = (char *) (addr + strtaboff);
917 memset(currpath, 0, sizeof(currpath));
920 * Allocate a buffer into which we can build stab strings for cases
921 * where the stab is continued over multiple lines.
924 stabbuff = (char *) DBG_alloc(stabbufflen);
928 for (i = 0; i < nstab; i++, stab_ptr++)
930 ptr = strs + (unsigned int) stab_ptr->n_un.n_name;
931 if( ptr[strlen(ptr) - 1] == '\\' )
934 * Indicates continuation. Append this to the buffer, and go onto the
935 * next record. Repeat the process until we find a stab without the
936 * '/' character, as this indicates we have the whole thing.
939 if( strlen(stabbuff) + len > stabbufflen )
941 stabbufflen += 65536;
942 stabbuff = (char *) DBG_realloc(stabbuff, stabbufflen);
944 strncat(stabbuff, ptr, len - 1);
947 else if( stabbuff[0] != '\0' )
949 strcat( stabbuff, ptr);
953 if( strchr(ptr, '=') != NULL )
956 * The stabs aren't in writable memory, so copy it over so we are
957 * sure we can scribble on it.
959 if( ptr != stabbuff )
961 strcpy(stabbuff, ptr);
964 stab_strcpy(symname, sizeof(symname), ptr);
965 if (!DEBUG_ParseTypedefStab(ptr, symname)) {
966 /* skip this definition */
972 switch(stab_ptr->n_type)
976 * These are useless with ELF. They have no value, and you have to
977 * read the normal symbol table to get the address. Thus we
978 * ignore them, and when we process the normal symbol table
979 * we should do the right thing.
981 * With a.out or mingw, they actually do make some amount of sense.
983 new_value.addr.seg = 0;
984 new_value.type = DEBUG_ParseStabType(ptr);
985 new_value.addr.off = (unsigned long)load_offset + stab_ptr->n_value;
986 new_value.cookie = DV_TARGET;
988 stab_strcpy(symname, sizeof(symname), ptr);
990 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
991 SYM_WINE | SYM_DATA | SYM_INVALID );
993 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
994 SYM_WINE | SYM_DATA );
1000 * We need to keep track of these so we get symbol scoping
1001 * right for local variables. For now, we just ignore them.
1002 * The hooks are already there for dealing with this however,
1003 * so all we need to do is to keep count of the nesting level,
1004 * and find the RBRAC for each matching LBRAC.
1010 * These are static symbols and BSS symbols.
1012 new_value.addr.seg = 0;
1013 new_value.type = DEBUG_ParseStabType(ptr);
1014 new_value.addr.off = (unsigned long)load_offset + stab_ptr->n_value;
1015 new_value.cookie = DV_TARGET;
1017 stab_strcpy(symname, sizeof(symname), ptr);
1018 curr_sym = DEBUG_AddSymbol( symname, &new_value, currpath,
1019 SYM_WINE | SYM_DATA );
1023 * These are function parameters.
1025 if( curr_func != NULL && !in_external_file )
1027 stab_strcpy(symname, sizeof(symname), ptr);
1028 curr_loc = DEBUG_AddLocal( curr_func, 0,
1029 stab_ptr->n_value, 0, 0, symname );
1030 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
1034 if( curr_func != NULL && !in_external_file )
1036 stab_strcpy(symname, sizeof(symname), ptr);
1037 curr_loc = DEBUG_AddLocal( curr_func, stab_ptr->n_value + 1,
1039 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
1043 if( curr_func != NULL && !in_external_file )
1045 stab_strcpy(symname, sizeof(symname), ptr);
1046 curr_loc = DEBUG_AddLocal( curr_func, 0,
1047 stab_ptr->n_value, 0, 0, symname );
1048 DEBUG_SetLocalSymbolType( curr_loc, DEBUG_ParseStabType(ptr) );
1053 * This is a line number. These are always relative to the start
1054 * of the function (N_FUN), and this makes the lookup easier.
1056 if( curr_func != NULL && !in_external_file )
1059 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
1064 * This isn't right. The order of the stabs is different under
1065 * a.out, and as a result we would end up attaching the line
1066 * number to the wrong function.
1068 DEBUG_AddLineNumber(curr_func, stab_ptr->n_desc,
1069 stab_ptr->n_value - curr_func->addr.off);
1076 * First, clean up the previous function we were working on.
1078 DEBUG_Normalize(curr_func);
1081 * For now, just declare the various functions. Later
1082 * on, we will add the line number information and the
1085 if( !in_external_file)
1087 stab_strcpy(symname, sizeof(symname), ptr);
1090 new_value.addr.seg = 0;
1091 new_value.type = DEBUG_ParseStabType(ptr);
1092 new_value.addr.off = (unsigned long)load_offset + stab_ptr->n_value;
1093 new_value.cookie = DV_TARGET;
1095 * Copy the string to a temp buffer so we
1096 * can kill everything after the ':'. We do
1097 * it this way because otherwise we end up dirtying
1098 * all of the pages related to the stabs, and that
1099 * sucks up swap space like crazy.
1102 curr_func = DEBUG_AddSymbol( symname, &new_value, currpath,
1103 SYM_WINE | SYM_FUNC | SYM_INVALID );
1105 curr_func = DEBUG_AddSymbol( symname, &new_value, currpath,
1106 SYM_WINE | SYM_FUNC );
1111 /* some GCC seem to use a N_FUN "" to mark the end of a function */
1118 * Don't add line number information for this function
1126 * This indicates a new source file. Append the records
1127 * together, to build the correct path name.
1131 * With a.out, there is no NULL string N_SO entry at the end of
1132 * the file. Thus when we find non-consecutive entries,
1133 * we consider that a new file is started.
1135 if( last_nso < i-1 )
1138 DEBUG_Normalize(curr_func);
1143 if( *ptr == '\0' ) /* end of N_SO file */
1149 DEBUG_Normalize(curr_func);
1155 strcat(currpath, ptr);
1157 strcpy(currpath, ptr);
1159 DEBUG_ResetIncludes();
1165 * This indicates we are including stuff from an include file.
1166 * If this is the main source, enable the debug stuff, otherwise
1169 in_external_file = !(subpath == NULL || strcmp(ptr, subpath) == 0);
1170 in_external_file = FALSE; /* FIXME EPP hack FIXME */;
1174 strtabinc = stab_ptr->n_value;
1175 DEBUG_Normalize(curr_func);
1180 * Ignore this. We don't care what it points to.
1184 DEBUG_AddInclude(DEBUG_CreateInclude(ptr, stab_ptr->n_value));
1189 DEBUG_AddInclude(DEBUG_FindInclude(ptr, stab_ptr->n_value));
1193 * Always ignore these. GCC doesn't even generate them.
1197 DEBUG_Printf(DBG_CHN_MESG, "Unknown stab type 0x%02x\n", stab_ptr->n_type);
1204 DEBUG_Printf(DBG_CHN_MESG, "0x%02x %x %s\n", stab_ptr->n_type,
1205 (unsigned int) stab_ptr->n_value,
1206 strs + (unsigned int) stab_ptr->n_un.n_name);
1210 DEBUG_FreeIncludes();
1218 * Walk through the entire symbol table and add any symbols we find there.
1219 * This can be used in cases where we have stripped ELF shared libraries,
1220 * or it can be used in cases where we have data symbols for which the address
1221 * isn't encoded in the stabs.
1223 * This is all really quite easy, since we don't have to worry about line
1224 * numbers or local data variables.
1226 static int DEBUG_ProcessElfSymtab(DBG_MODULE* module, char* addr,
1227 void *load_addr, Elf32_Shdr* symtab,
1230 char * curfile = NULL;
1231 struct name_hash * curr_sym = NULL;
1234 DBG_VALUE new_value;
1240 symp = (Elf32_Sym *) (addr + symtab->sh_offset);
1241 nsym = symtab->sh_size / sizeof(*symp);
1242 strp = (char *) (addr + strtab->sh_offset);
1244 for (i = 0; i < nsym; i++, symp++)
1247 * Ignore certain types of entries which really aren't of that much
1250 if( ELF32_ST_TYPE(symp->st_info) == STT_SECTION ||
1251 symp->st_shndx == STN_UNDEF )
1256 symname = strp + symp->st_name;
1259 * Save the name of the current file, so we have a way of tracking
1260 * static functions/data.
1262 if( ELF32_ST_TYPE(symp->st_info) == STT_FILE )
1268 new_value.type = NULL;
1269 new_value.addr.seg = 0;
1270 new_value.addr.off = (unsigned long)load_addr + symp->st_value;
1271 new_value.cookie = DV_TARGET;
1272 flags = SYM_WINE | ((ELF32_ST_TYPE(symp->st_info) == STT_FUNC)
1273 ? SYM_FUNC : SYM_DATA);
1274 if( ELF32_ST_BIND(symp->st_info) == STB_GLOBAL )
1275 curr_sym = DEBUG_AddSymbol( symname, &new_value, NULL, flags );
1277 curr_sym = DEBUG_AddSymbol( symname, &new_value, curfile, flags );
1280 * Record the size of the symbol. This can come in handy in
1281 * some cases. Not really used yet, however.
1283 if( symp->st_size != 0 )
1284 DEBUG_SetSymbolSize(curr_sym, symp->st_size);
1291 * Loads the symbolic information from ELF module stored in 'filename'
1292 * the module has been loaded at 'load_offset' address, so symbols' address
1293 * relocation is performed
1295 * -1 if the file cannot be found/opened
1296 * 0 if the file doesn't contain symbolic info (or this info cannot be
1300 enum DbgInfoLoad DEBUG_LoadElfStabs(DBG_MODULE* module)
1302 enum DbgInfoLoad dil = DIL_ERROR;
1303 char* addr = (char*)0xffffffff;
1305 struct stat statbuf;
1313 if (module->type != DMT_ELF || !module->elf_info) {
1314 DEBUG_Printf(DBG_CHN_ERR, "Bad elf module '%s'\n", module->module_name);
1318 /* check that the file exists, and that the module hasn't been loaded yet */
1319 if (stat(module->module_name, &statbuf) == -1) goto leave;
1320 if (S_ISDIR(statbuf.st_mode)) goto leave;
1323 * Now open the file, so that we can mmap() it.
1325 if ((fd = open(module->module_name, O_RDONLY)) == -1) goto leave;
1329 * Now mmap() the file.
1331 addr = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
1332 if (addr == (char*)0xffffffff) goto leave;
1335 * Next, we need to find a few of the internal ELF headers within
1336 * this thing. We need the main executable header, and the section
1339 ehptr = (Elf32_Ehdr*) addr;
1340 spnt = (Elf32_Shdr*) (addr + ehptr->e_shoff);
1341 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
1343 stabsect = stabstrsect = -1;
1345 for (i = 0; i < ehptr->e_shnum; i++) {
1346 if (strcmp(shstrtab + spnt[i].sh_name, ".stab") == 0)
1349 if (strcmp(shstrtab + spnt[i].sh_name, ".stabstr") == 0)
1353 if (stabsect == -1 || stabstrsect == -1) {
1354 DEBUG_Printf(DBG_CHN_WARN, "No .stab section\n");
1359 * OK, now just parse all of the stabs.
1361 if (DEBUG_ParseStabs(addr,
1362 module->elf_info->elf_addr,
1363 spnt[stabsect].sh_offset,
1364 spnt[stabsect].sh_size,
1365 spnt[stabstrsect].sh_offset,
1366 spnt[stabstrsect].sh_size)) {
1370 DEBUG_Printf(DBG_CHN_WARN, "Couldn't read correctly read stabs\n");
1374 for (i = 0; i < ehptr->e_shnum; i++) {
1375 if ( (strcmp(shstrtab + spnt[i].sh_name, ".symtab") == 0)
1376 && (spnt[i].sh_type == SHT_SYMTAB))
1377 DEBUG_ProcessElfSymtab(module, addr, module->elf_info->elf_addr,
1378 spnt + i, spnt + spnt[i].sh_link);
1380 if ( (strcmp(shstrtab + spnt[i].sh_name, ".dynsym") == 0)
1381 && (spnt[i].sh_type == SHT_DYNSYM))
1382 DEBUG_ProcessElfSymtab(module, addr, module->elf_info->elf_addr,
1383 spnt + i, spnt + spnt[i].sh_link);
1387 if (addr != (char*)0xffffffff) munmap(addr, statbuf.st_size);
1388 if (fd != -1) close(fd);
1394 * Loads the information for ELF module stored in 'filename'
1395 * the module has been loaded at 'load_offset' address
1397 * -1 if the file cannot be found/opened
1398 * 0 if the file doesn't contain symbolic info (or this info cannot be
1402 static enum DbgInfoLoad DEBUG_ProcessElfFile(const char* filename,
1404 unsigned int* dyn_addr)
1406 static const unsigned char elf_signature[4] = { ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3 };
1407 enum DbgInfoLoad dil = DIL_ERROR;
1408 char* addr = (char*)0xffffffff;
1410 struct stat statbuf;
1416 DBG_MODULE* module = NULL;
1420 DEBUG_Printf(DBG_CHN_TRACE, "Processing elf file '%s'\n", filename);
1422 /* check that the file exists, and that the module hasn't been loaded yet */
1423 if (stat(filename, &statbuf) == -1) goto leave;
1426 * Now open the file, so that we can mmap() it.
1428 if ((fd = open(filename, O_RDONLY)) == -1) goto leave;
1431 * Now mmap() the file.
1433 addr = mmap(0, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
1434 if (addr == (char*)-1) goto leave;
1439 * Next, we need to find a few of the internal ELF headers within
1440 * this thing. We need the main executable header, and the section
1443 ehptr = (Elf32_Ehdr*) addr;
1444 if (memcmp( ehptr->e_ident, elf_signature, sizeof(elf_signature) )) goto leave;
1446 spnt = (Elf32_Shdr*) (addr + ehptr->e_shoff);
1447 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
1449 /* if non relocatable ELF, then remove fixed address from computation
1450 * otherwise, all addresses are zero based
1452 delta = (load_offset == 0) ? ehptr->e_entry : 0;
1454 /* grab size of module once loaded in memory */
1455 ppnt = (Elf32_Phdr*) (addr + ehptr->e_phoff);
1457 for (i = 0; i < ehptr->e_phnum; i++) {
1458 if (ppnt[i].p_type != PT_LOAD) continue;
1459 if (size < ppnt[i].p_vaddr - delta + ppnt[i].p_memsz)
1460 size = ppnt[i].p_vaddr - delta + ppnt[i].p_memsz;
1463 for (i = 0; i < ehptr->e_shnum; i++)
1465 if (strcmp(shstrtab + spnt[i].sh_name, ".bss") == 0 &&
1466 spnt[i].sh_type == SHT_NOBITS)
1468 if (size < spnt[i].sh_addr - delta + spnt[i].sh_size)
1469 size = spnt[i].sh_addr - delta + spnt[i].sh_size;
1471 if (strcmp(shstrtab + spnt[i].sh_name, ".dynamic") == 0 &&
1472 spnt[i].sh_type == SHT_DYNAMIC)
1474 if (dyn_addr) *dyn_addr = spnt[i].sh_addr;
1478 module = DEBUG_RegisterELFModule((load_offset == 0) ? (void *)ehptr->e_entry : load_offset,
1485 if ((module->elf_info = DBG_alloc(sizeof(ELF_DBG_INFO))) == NULL) {
1486 DEBUG_Printf(DBG_CHN_ERR, "OOM\n");
1490 module->elf_info->elf_addr = load_offset;
1491 dil = DEBUG_LoadElfStabs(module);
1494 if (addr != (char*)0xffffffff) munmap(addr, statbuf.st_size);
1495 if (fd != -1) close(fd);
1496 if (module) module->dil = dil;
1501 static enum DbgInfoLoad DEBUG_ProcessElfFileFromPath(const char * filename,
1503 unsigned int* dyn_addr,
1506 enum DbgInfoLoad dil = DIL_ERROR;
1510 if (!path) return -1;
1512 for (s = paths = DBG_strdup(path); s && *s; s = (t) ? (t+1) : NULL) {
1515 fn = (char*)DBG_alloc(strlen(filename) + 1 + strlen(s) + 1);
1519 strcat(fn, filename);
1520 dil = DEBUG_ProcessElfFile(fn, load_offset, dyn_addr);
1522 if (dil != DIL_ERROR) break;
1523 s = (t) ? (t+1) : NULL;
1530 static enum DbgInfoLoad DEBUG_ProcessElfObject(const char* filename,
1532 unsigned int* dyn_addr)
1534 enum DbgInfoLoad dil = DIL_ERROR;
1536 if (filename == NULL) return DIL_ERROR;
1537 if (DEBUG_FindModuleByName(filename, DMT_ELF)) return DIL_LOADED;
1539 if (strstr (filename, "libstdc++")) return DIL_ERROR; /* We know we can't do it */
1540 dil = DEBUG_ProcessElfFile(filename, load_offset, dyn_addr);
1542 /* if relative pathname, try some absolute base dirs */
1543 if (dil == DIL_ERROR && !strchr(filename, '/')) {
1544 dil = DEBUG_ProcessElfFileFromPath(filename, load_offset, dyn_addr, getenv("PATH"));
1545 if (dil == DIL_ERROR)
1546 dil = DEBUG_ProcessElfFileFromPath(filename, load_offset, dyn_addr, getenv("LD_LIBRARY_PATH"));
1547 if (dil == DIL_ERROR)
1548 dil = DEBUG_ProcessElfFileFromPath(filename, load_offset, dyn_addr, getenv("WINEDLLPATH"));
1551 DEBUG_ReportDIL(dil, "ELF", filename, load_offset);
1556 static BOOL DEBUG_WalkList(struct r_debug* dbg_hdr)
1564 * Now walk the linked list. In all known ELF implementations,
1565 * the dynamic loader maintains this linked list for us. In some
1566 * cases the first entry doesn't appear with a name, in other cases it
1569 for (lm_addr = (void *)dbg_hdr->r_map; lm_addr; lm_addr = (void *)lm.l_next) {
1570 if (!DEBUG_READ_MEM_VERBOSE(lm_addr, &lm, sizeof(lm)))
1573 if (lm.l_addr != 0 &&
1574 DEBUG_READ_MEM_VERBOSE((void*)lm.l_addr, &ehdr, sizeof(ehdr)) &&
1575 ehdr.e_type == ET_DYN && /* only look at dynamic modules */
1576 lm.l_name != NULL &&
1577 DEBUG_READ_MEM_VERBOSE((void*)lm.l_name, bufstr, sizeof(bufstr))) {
1578 bufstr[sizeof(bufstr) - 1] = '\0';
1579 DEBUG_ProcessElfObject(bufstr, (void *)lm.l_addr, NULL);
1586 static BOOL DEBUG_RescanElf(void)
1588 struct r_debug dbg_hdr;
1590 if (!DEBUG_CurrProcess ||
1591 !DEBUG_READ_MEM_VERBOSE((void*)DEBUG_CurrProcess->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)))
1594 switch (dbg_hdr.r_state) {
1596 DEBUG_WalkList(&dbg_hdr);
1597 DEBUG_CheckDelayedBP();
1602 /* FIXME: this is not currently handled, would need some kind of mark&sweep algo */
1608 enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name)
1611 struct r_debug dbg_hdr;
1612 enum DbgInfoLoad dil = DIL_NOINFO;
1613 unsigned int dyn_addr;
1616 * Make sure we can stat and open this file.
1618 if (exe_name == NULL) goto leave;
1619 DEBUG_ProcessElfObject(exe_name, 0, &dyn_addr);
1622 if (!DEBUG_READ_MEM_VERBOSE((void*)dyn_addr, &dyn, sizeof(dyn)))
1624 dyn_addr += sizeof(dyn);
1625 } while (dyn.d_tag != DT_DEBUG && dyn.d_tag != DT_NULL);
1626 if (dyn.d_tag == DT_NULL) goto leave;
1629 * OK, now dig into the actual tables themselves.
1631 if (!DEBUG_READ_MEM_VERBOSE((void*)dyn.d_un.d_ptr, &dbg_hdr, sizeof(dbg_hdr)))
1634 assert(!DEBUG_CurrProcess->dbg_hdr_addr);
1635 DEBUG_CurrProcess->dbg_hdr_addr = (unsigned long)dyn.d_un.d_ptr;
1637 if (dbg_hdr.r_brk) {
1640 DEBUG_Printf(DBG_CHN_TRACE, "Setting up a breakpoint on r_brk(%lx)\n",
1641 (unsigned long)dbg_hdr.r_brk);
1643 DEBUG_SetBreakpoints(FALSE);
1645 value.cookie = DV_TARGET;
1647 value.addr.off = (DWORD)dbg_hdr.r_brk;
1648 DEBUG_AddBreakpoint(&value, DEBUG_RescanElf, TRUE);
1649 DEBUG_SetBreakpoints(TRUE);
1652 dil = DEBUG_WalkList(&dbg_hdr);
1658 /* FIXME: merge with some of the routines above */
1659 int read_elf_info(const char* filename, unsigned long tab[])
1661 static const unsigned char elf_signature[4] = { ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3 };
1672 hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
1673 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1674 if (hFile == INVALID_HANDLE_VALUE) goto leave;
1675 hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
1676 if (hMap == 0) goto leave;
1677 addr = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
1678 if (addr == NULL) goto leave;
1680 ehptr = (Elf32_Ehdr*) addr;
1681 if (memcmp(ehptr->e_ident, elf_signature, sizeof(elf_signature))) goto leave;
1683 spnt = (Elf32_Shdr*) (addr + ehptr->e_shoff);
1684 shstrtab = (addr + spnt[ehptr->e_shstrndx].sh_offset);
1686 tab[0] = tab[1] = tab[2] = 0;
1687 for (i = 0; i < ehptr->e_shnum; i++)
1692 if (addr != NULL) UnmapViewOfFile(addr);
1693 if (hMap != 0) CloseHandle(hMap);
1694 if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
1698 #else /* !__ELF__ */
1700 enum DbgInfoLoad DEBUG_ReadExecutableDbgInfo(const char* exe_name)
1705 #endif /* __ELF__ */