2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999, 2000, Ulrich Weigand.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Note - this handles reading debug information for 32 bit applications
23 * that run under Windows-NT for example. I doubt that this would work well
24 * for 16 bit applications, but I don't think it really matters since the
25 * file format is different, and we should never get in here in such cases.
28 * Get 16 bit CV stuff working.
29 * Add symbol size to internal symbol table.
40 #define PATH_MAX MAX_PATH
42 #include "wine/exception.h"
46 #define MAX_PATHNAME_LEN 1024
55 typedef struct tagMSC_DBG_INFO
58 PIMAGE_SECTION_HEADER sectp;
65 /*========================================================================
66 * Debug file access helper routines
69 static WINE_EXCEPTION_FILTER(page_fault)
71 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
72 return EXCEPTION_EXECUTE_HANDLER;
73 return EXCEPTION_CONTINUE_SEARCH;
76 /***********************************************************************
77 * DEBUG_LocateDebugInfoFile
79 * NOTE: dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
81 static void DEBUG_LocateDebugInfoFile(const char *filename, char *dbg_filename)
83 char *str1 = DBG_alloc(MAX_PATHNAME_LEN);
84 char *str2 = DBG_alloc(MAX_PATHNAME_LEN*10);
88 file = strrchr(filename, '\\');
89 if( file == NULL ) file = filename; else file++;
91 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
92 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
93 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
94 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
95 (SearchPath(NULL, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part)))
96 lstrcpyn(dbg_filename, str2, MAX_PATHNAME_LEN);
98 lstrcpyn(dbg_filename, filename, MAX_PATHNAME_LEN);
103 /***********************************************************************
104 * DEBUG_MapDebugInfoFile
106 static void* DEBUG_MapDebugInfoFile(const char* name, DWORD offset, DWORD size,
107 HANDLE* hFile, HANDLE* hMap)
109 DWORD g_offset; /* offset aligned on map granuality */
110 DWORD g_size; /* size to map, with offset aligned */
116 char filename[MAX_PATHNAME_LEN];
118 DEBUG_LocateDebugInfoFile(name, filename);
119 if ((*hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
124 DWORD file_size = GetFileSize(*hFile, NULL);
125 if (file_size == (DWORD)-1) return NULL;
126 size = file_size - offset;
129 g_offset = offset & ~0xFFFF; /* FIXME: is granularity portable ? */
130 g_size = offset + size - g_offset;
132 if ((*hMap = CreateFileMapping(*hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == 0)
135 if ((ret = MapViewOfFile(*hMap, FILE_MAP_READ, 0, g_offset, g_size)) != NULL)
136 ret += offset - g_offset;
141 /***********************************************************************
142 * DEBUG_UnmapDebugInfoFile
144 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile, HANDLE hMap, void* addr)
146 if (addr) UnmapViewOfFile(addr);
147 if (hMap) CloseHandle(hMap);
148 if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile);
153 /*========================================================================
154 * Process COFF debug information.
159 unsigned int startaddr;
160 unsigned int endaddr;
161 const char *filename;
164 struct name_hash **entries;
171 struct CoffFile *files;
176 static const char* DEBUG_GetCoffName( PIMAGE_SYMBOL coff_sym, const char* coff_strtab )
178 static char namebuff[9];
181 if( coff_sym->N.Name.Short )
183 memcpy(namebuff, coff_sym->N.ShortName, 8);
185 nampnt = &namebuff[0];
189 nampnt = coff_strtab + coff_sym->N.Name.Long;
192 if( nampnt[0] == '_' )
197 static int DEBUG_AddCoffFile( struct CoffFileSet* coff_files, const char* filename )
199 struct CoffFile* file;
201 if( coff_files->nfiles + 1 >= coff_files->nfiles_alloc )
203 coff_files->nfiles_alloc += 10;
204 coff_files->files = (struct CoffFile *) DBG_realloc(coff_files->files,
205 coff_files->nfiles_alloc * sizeof(struct CoffFile));
207 file = coff_files->files + coff_files->nfiles;
208 file->startaddr = 0xffffffff;
210 file->filename = filename;
211 file->linetab_offset = -1;
213 file->entries = NULL;
214 file->neps = file->neps_alloc = 0;
216 return coff_files->nfiles++;
219 static void DEBUG_AddCoffSymbol( struct CoffFile* coff_file, struct name_hash* sym )
221 if( coff_file->neps + 1 >= coff_file->neps_alloc )
223 coff_file->neps_alloc += 10;
224 coff_file->entries = (struct name_hash **)
225 DBG_realloc(coff_file->entries,
226 coff_file->neps_alloc * sizeof(struct name_hash *));
228 coff_file->entries[coff_file->neps++] = sym;
231 static enum DbgInfoLoad DEBUG_ProcessCoff( DBG_MODULE *module, LPBYTE root )
233 PIMAGE_AUX_SYMBOL aux;
234 PIMAGE_COFF_SYMBOLS_HEADER coff;
235 PIMAGE_LINENUMBER coff_linetab;
236 PIMAGE_LINENUMBER linepnt;
238 PIMAGE_SYMBOL coff_sym;
239 PIMAGE_SYMBOL coff_symbols;
240 struct CoffFileSet coff_files;
241 int curr_file_idx = -1;
250 enum DbgInfoLoad dil = DIL_ERROR;
252 DEBUG_Printf(DBG_CHN_TRACE, "Processing COFF symbols...\n");
254 assert(sizeof(IMAGE_SYMBOL) == IMAGE_SIZEOF_SYMBOL);
255 assert(sizeof(IMAGE_LINENUMBER) == IMAGE_SIZEOF_LINENUMBER);
257 coff_files.files = NULL;
258 coff_files.nfiles = coff_files.nfiles_alloc = 0;
260 coff = (PIMAGE_COFF_SYMBOLS_HEADER) root;
262 coff_symbols = (PIMAGE_SYMBOL) ((unsigned int) coff + coff->LvaToFirstSymbol);
263 coff_linetab = (PIMAGE_LINENUMBER) ((unsigned int) coff + coff->LvaToFirstLinenumber);
264 coff_strtab = (char *) (coff_symbols + coff->NumberOfSymbols);
268 new_value.cookie = DV_TARGET;
269 new_value.type = NULL;
271 for(i=0; i < coff->NumberOfSymbols; i++ )
273 coff_sym = coff_symbols + i;
274 naux = coff_sym->NumberOfAuxSymbols;
276 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
278 curr_file_idx = DEBUG_AddCoffFile( &coff_files, (char *) (coff_sym + 1) );
279 DEBUG_Printf(DBG_CHN_TRACE,"New file %s\n", coff_files.files[curr_file_idx].filename);
284 if (curr_file_idx < 0) {
285 assert(coff_files.nfiles == 0 && coff_files.nfiles_alloc == 0);
286 curr_file_idx = DEBUG_AddCoffFile( &coff_files, "<none>" );
287 DEBUG_Printf(DBG_CHN_TRACE,"New file %s\n", coff_files.files[curr_file_idx].filename);
291 * This guy marks the size and location of the text section
292 * for the current file. We need to keep track of this so
293 * we can figure out what file the different global functions
296 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
298 && (coff_sym->Type == 0)
299 && (coff_sym->SectionNumber == 1) )
301 aux = (PIMAGE_AUX_SYMBOL) (coff_sym + 1);
303 if( coff_files.files[curr_file_idx].linetab_offset != -1 )
306 * Save this so we can still get the old name.
308 const char* fn = coff_files.files[curr_file_idx].filename;
311 DEBUG_Printf(DBG_CHN_TRACE, "Duplicating sect from %s: %lx %x %x %d %d\n",
312 coff_files.files[curr_file_idx].filename,
314 aux->Section.NumberOfRelocations,
315 aux->Section.NumberOfLinenumbers,
317 aux->Section.Selection);
318 DEBUG_Printf(DBG_CHN_TRACE, "More sect %d %s %08lx %d %d %d\n",
319 coff_sym->SectionNumber,
320 DEBUG_GetCoffName( coff_sym, coff_strtab ),
323 coff_sym->StorageClass,
324 coff_sym->NumberOfAuxSymbols);
328 * Duplicate the file entry. We have no way to describe
329 * multiple text sections in our current way of handling things.
331 DEBUG_AddCoffFile( &coff_files, fn );
336 DEBUG_Printf(DBG_CHN_TRACE, "New text sect from %s: %lx %x %x %d %d\n",
337 coff_files.files[curr_file_idx].filename,
339 aux->Section.NumberOfRelocations,
340 aux->Section.NumberOfLinenumbers,
342 aux->Section.Selection);
346 if( coff_files.files[curr_file_idx].startaddr > coff_sym->Value )
348 coff_files.files[curr_file_idx].startaddr = coff_sym->Value;
351 if( coff_files.files[curr_file_idx].endaddr < coff_sym->Value + aux->Section.Length )
353 coff_files.files[curr_file_idx].endaddr = coff_sym->Value + aux->Section.Length;
356 coff_files.files[curr_file_idx].linetab_offset = linetab_indx;
357 coff_files.files[curr_file_idx].linecnt = aux->Section.NumberOfLinenumbers;
358 linetab_indx += aux->Section.NumberOfLinenumbers;
363 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
365 && (coff_sym->SectionNumber == 1) )
367 DWORD base = module->msc_info->sectp[coff_sym->SectionNumber - 1].VirtualAddress;
369 * This is a normal static function when naux == 0.
370 * Just register it. The current file is the correct
371 * one in this instance.
373 nampnt = DEBUG_GetCoffName( coff_sym, coff_strtab );
375 new_value.addr.seg = 0;
376 new_value.addr.off = (int) ((char *)module->load_addr + base + coff_sym->Value);
379 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding static symbol %s\n", nampnt);
382 /* FIXME: was adding symbol to this_file ??? */
383 DEBUG_AddCoffSymbol( &coff_files.files[curr_file_idx],
384 DEBUG_AddSymbol( nampnt, &new_value,
385 coff_files.files[curr_file_idx].filename,
386 SYM_WIN32 | SYM_FUNC ) );
391 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
392 && ISFCN(coff_sym->Type)
393 && (coff_sym->SectionNumber > 0) )
395 const char* this_file = NULL;
396 DWORD base = module->msc_info->sectp[coff_sym->SectionNumber - 1].VirtualAddress;
397 nampnt = DEBUG_GetCoffName( coff_sym, coff_strtab );
399 new_value.addr.seg = 0;
400 new_value.addr.off = (int) ((char *)module->load_addr + base + coff_sym->Value);
403 DEBUG_Printf(DBG_CHN_TRACE, "%d: %lx %s\n", i, new_value.addr.off, nampnt);
405 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global symbol %s (sect=%s)\n",
406 nampnt, MSC_INFO(module)->sectp[coff_sym->SectionNumber - 1].Name);
410 * Now we need to figure out which file this guy belongs to.
412 for(j=0; j < coff_files.nfiles; j++)
414 if( coff_files.files[j].startaddr <= base + coff_sym->Value
415 && coff_files.files[j].endaddr > base + coff_sym->Value )
417 this_file = coff_files.files[j].filename;
421 if (j < coff_files.nfiles) {
422 DEBUG_AddCoffSymbol( &coff_files.files[j],
423 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 | SYM_FUNC ) );
425 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 | SYM_FUNC );
431 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
432 && (coff_sym->SectionNumber > 0) )
434 DWORD base = module->msc_info->sectp[coff_sym->SectionNumber - 1].VirtualAddress;
436 * Similar to above, but for the case of data symbols.
437 * These aren't treated as entrypoints.
439 nampnt = DEBUG_GetCoffName( coff_sym, coff_strtab );
441 new_value.addr.seg = 0;
442 new_value.addr.off = (int) ((char *)module->load_addr + base + coff_sym->Value);
445 DEBUG_Printf(DBG_CHN_TRACE, "%d: %lx %s\n", i, new_value.addr.off, nampnt);
447 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global data symbol %s\n", nampnt);
451 * Now we need to figure out which file this guy belongs to.
453 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 | SYM_DATA );
458 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
462 * Ignore these. They don't have anything to do with
470 DEBUG_Printf(DBG_CHN_TRACE,"Skipping unknown entry '%s' %d %d %d\n",
471 DEBUG_GetCoffName( coff_sym, coff_strtab ),
472 coff_sym->StorageClass, coff_sym->SectionNumber, naux);
476 * For now, skip past the aux entries.
483 * OK, we now should have a list of files, and we should have a list
484 * of entrypoints. We need to sort the entrypoints so that we are
485 * able to tie the line numbers with the given functions within the
488 if( coff_files.files != NULL )
490 for(j=0; j < coff_files.nfiles; j++)
492 if( coff_files.files[j].entries != NULL )
494 qsort(coff_files.files[j].entries, coff_files.files[j].neps,
495 sizeof(struct name_hash *), DEBUG_cmp_sym);
500 * Now pick apart the line number tables, and attach the entries
501 * to the given functions.
503 for(j=0; j < coff_files.nfiles; j++)
506 if( coff_files.files[j].neps != 0 )
507 for(k=0; k < coff_files.files[j].linecnt; k++)
509 linepnt = coff_linetab + coff_files.files[j].linetab_offset + k;
511 * If we have spilled onto the next entrypoint, then
516 if (l+1 >= coff_files.files[j].neps) break;
517 DEBUG_GetSymbolAddr(coff_files.files[j].entries[l+1], &new_value.addr);
518 if( (((unsigned int)module->load_addr +
519 linepnt->Type.VirtualAddress) >= new_value.addr.off) )
526 * Add the line number. This is always relative to the
527 * start of the function, so we need to subtract that offset
530 DEBUG_GetSymbolAddr(coff_files.files[j].entries[l], &new_value.addr);
531 DEBUG_AddLineNumber(coff_files.files[j].entries[l],
533 (unsigned int) module->load_addr
534 + linepnt->Type.VirtualAddress
535 - new_value.addr.off);
542 if( coff_files.files != NULL )
544 for(j=0; j < coff_files.nfiles; j++)
546 if( coff_files.files[j].entries != NULL )
548 DBG_free(coff_files.files[j].entries);
551 DBG_free(coff_files.files);
560 /*========================================================================
561 * Process CodeView type information.
568 unsigned short int len;
574 unsigned short int len;
578 unsigned char variant[1];
583 unsigned short int len;
585 unsigned int datatype;
586 unsigned int attribute;
587 unsigned char variant[1];
592 unsigned short int len;
595 unsigned char bitoff;
601 unsigned short int len;
605 unsigned char bitoff;
610 unsigned short int len;
614 unsigned short int arrlen; /* numeric leaf */
616 unsigned char name[1];
622 unsigned short int len;
624 unsigned int elemtype;
625 unsigned int idxtype;
626 unsigned short int arrlen; /* numeric leaf */
628 unsigned char name[1];
634 unsigned short int len;
641 unsigned short int structlen; /* numeric leaf */
643 unsigned char name[1];
649 unsigned short int len;
653 unsigned int fieldlist;
654 unsigned int derived;
656 unsigned short int structlen; /* numeric leaf */
658 unsigned char name[1];
664 unsigned short int len;
669 unsigned short int un_len; /* numeric leaf */
671 unsigned char name[1];
677 unsigned short int len;
681 unsigned int fieldlist;
682 unsigned short int un_len; /* numeric leaf */
684 unsigned char name[1];
690 unsigned short int len;
696 unsigned char name[1];
701 unsigned short int len;
707 unsigned char name[1];
712 unsigned short int len;
714 unsigned char list[1];
718 union codeview_fieldtype
730 unsigned short int offset; /* numeric leaf */
738 unsigned short int offset; /* numeric leaf */
747 unsigned short int vbpoff; /* numeric leaf */
749 unsigned short int vboff; /* numeric leaf */
759 unsigned short int vbpoff; /* numeric leaf */
761 unsigned short int vboff; /* numeric leaf */
769 unsigned short int value; /* numeric leaf */
771 unsigned char name[1];
779 unsigned char name[1];
787 unsigned char name[1];
795 unsigned short int offset; /* numeric leaf */
797 unsigned char name[1];
806 unsigned short int offset; /* numeric leaf */
808 unsigned char name[1];
817 unsigned char name[1];
825 unsigned char name[1];
833 unsigned char name[1];
841 unsigned char name[1];
848 unsigned char name[1];
856 unsigned char name[1];
891 unsigned char name[1];
898 unsigned int vtab_offset;
899 unsigned char name[1];
907 unsigned char name[1];
914 unsigned int vtab_offset;
915 unsigned char name[1];
938 unsigned char name[1];
946 unsigned char name[1];
954 unsigned char name[1];
960 * This covers the basic datatypes that VC++ seems to be using these days.
961 * 32 bit mode only. There are additional numbers for the pointers in 16
962 * bit mode. There are many other types listed in the documents, but these
963 * are apparently not used by the compiler, or represent pointer types
966 #define T_NOTYPE 0x0000 /* Notype */
967 #define T_ABS 0x0001 /* Abs */
968 #define T_VOID 0x0003 /* Void */
969 #define T_CHAR 0x0010 /* signed char */
970 #define T_SHORT 0x0011 /* short */
971 #define T_LONG 0x0012 /* long */
972 #define T_QUAD 0x0013 /* long long */
973 #define T_UCHAR 0x0020 /* unsigned char */
974 #define T_USHORT 0x0021 /* unsigned short */
975 #define T_ULONG 0x0022 /* unsigned long */
976 #define T_UQUAD 0x0023 /* unsigned long long */
977 #define T_REAL32 0x0040 /* float */
978 #define T_REAL64 0x0041 /* double */
979 #define T_RCHAR 0x0070 /* real char */
980 #define T_WCHAR 0x0071 /* wide char */
981 #define T_INT4 0x0074 /* int */
982 #define T_UINT4 0x0075 /* unsigned int */
984 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
985 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
986 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
987 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
988 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
989 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
990 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
991 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
992 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
993 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
994 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
995 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
996 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
997 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
998 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
1001 #define LF_MODIFIER 0x0001
1002 #define LF_POINTER 0x0002
1003 #define LF_ARRAY 0x0003
1004 #define LF_CLASS 0x0004
1005 #define LF_STRUCTURE 0x0005
1006 #define LF_UNION 0x0006
1007 #define LF_ENUM 0x0007
1008 #define LF_PROCEDURE 0x0008
1009 #define LF_MFUNCTION 0x0009
1010 #define LF_VTSHAPE 0x000a
1011 #define LF_COBOL0 0x000b
1012 #define LF_COBOL1 0x000c
1013 #define LF_BARRAY 0x000d
1014 #define LF_LABEL 0x000e
1015 #define LF_NULL 0x000f
1016 #define LF_NOTTRAN 0x0010
1017 #define LF_DIMARRAY 0x0011
1018 #define LF_VFTPATH 0x0012
1019 #define LF_PRECOMP 0x0013
1020 #define LF_ENDPRECOMP 0x0014
1021 #define LF_OEM 0x0015
1022 #define LF_TYPESERVER 0x0016
1024 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
1025 #define LF_POINTER_32 0x1002
1026 #define LF_ARRAY_32 0x1003
1027 #define LF_CLASS_32 0x1004
1028 #define LF_STRUCTURE_32 0x1005
1029 #define LF_UNION_32 0x1006
1030 #define LF_ENUM_32 0x1007
1031 #define LF_PROCEDURE_32 0x1008
1032 #define LF_MFUNCTION_32 0x1009
1033 #define LF_COBOL0_32 0x100a
1034 #define LF_BARRAY_32 0x100b
1035 #define LF_DIMARRAY_32 0x100c
1036 #define LF_VFTPATH_32 0x100d
1037 #define LF_PRECOMP_32 0x100e
1038 #define LF_OEM_32 0x100f
1040 #define LF_SKIP 0x0200
1041 #define LF_ARGLIST 0x0201
1042 #define LF_DEFARG 0x0202
1043 #define LF_LIST 0x0203
1044 #define LF_FIELDLIST 0x0204
1045 #define LF_DERIVED 0x0205
1046 #define LF_BITFIELD 0x0206
1047 #define LF_METHODLIST 0x0207
1048 #define LF_DIMCONU 0x0208
1049 #define LF_DIMCONLU 0x0209
1050 #define LF_DIMVARU 0x020a
1051 #define LF_DIMVARLU 0x020b
1052 #define LF_REFSYM 0x020c
1054 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
1055 #define LF_ARGLIST_32 0x1201
1056 #define LF_DEFARG_32 0x1202
1057 #define LF_FIELDLIST_32 0x1203
1058 #define LF_DERIVED_32 0x1204
1059 #define LF_BITFIELD_32 0x1205
1060 #define LF_METHODLIST_32 0x1206
1061 #define LF_DIMCONU_32 0x1207
1062 #define LF_DIMCONLU_32 0x1208
1063 #define LF_DIMVARU_32 0x1209
1064 #define LF_DIMVARLU_32 0x120a
1066 #define LF_BCLASS 0x0400
1067 #define LF_VBCLASS 0x0401
1068 #define LF_IVBCLASS 0x0402
1069 #define LF_ENUMERATE 0x0403
1070 #define LF_FRIENDFCN 0x0404
1071 #define LF_INDEX 0x0405
1072 #define LF_MEMBER 0x0406
1073 #define LF_STMEMBER 0x0407
1074 #define LF_METHOD 0x0408
1075 #define LF_NESTTYPE 0x0409
1076 #define LF_VFUNCTAB 0x040a
1077 #define LF_FRIENDCLS 0x040b
1078 #define LF_ONEMETHOD 0x040c
1079 #define LF_VFUNCOFF 0x040d
1080 #define LF_NESTTYPEEX 0x040e
1081 #define LF_MEMBERMODIFY 0x040f
1083 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
1084 #define LF_VBCLASS_32 0x1401
1085 #define LF_IVBCLASS_32 0x1402
1086 #define LF_FRIENDFCN_32 0x1403
1087 #define LF_INDEX_32 0x1404
1088 #define LF_MEMBER_32 0x1405
1089 #define LF_STMEMBER_32 0x1406
1090 #define LF_METHOD_32 0x1407
1091 #define LF_NESTTYPE_32 0x1408
1092 #define LF_VFUNCTAB_32 0x1409
1093 #define LF_FRIENDCLS_32 0x140a
1094 #define LF_ONEMETHOD_32 0x140b
1095 #define LF_VFUNCOFF_32 0x140c
1096 #define LF_NESTTYPEEX_32 0x140d
1098 #define LF_NUMERIC 0x8000 /* numeric leaf types */
1099 #define LF_CHAR 0x8000
1100 #define LF_SHORT 0x8001
1101 #define LF_USHORT 0x8002
1102 #define LF_LONG 0x8003
1103 #define LF_ULONG 0x8004
1104 #define LF_REAL32 0x8005
1105 #define LF_REAL64 0x8006
1106 #define LF_REAL80 0x8007
1107 #define LF_REAL128 0x8008
1108 #define LF_QUADWORD 0x8009
1109 #define LF_UQUADWORD 0x800a
1110 #define LF_REAL48 0x800b
1111 #define LF_COMPLEX32 0x800c
1112 #define LF_COMPLEX64 0x800d
1113 #define LF_COMPLEX80 0x800e
1114 #define LF_COMPLEX128 0x800f
1115 #define LF_VARSTRING 0x8010
1119 #define MAX_BUILTIN_TYPES 0x480
1120 static struct datatype * cv_basic_types[MAX_BUILTIN_TYPES];
1121 static unsigned int num_cv_defined_types = 0;
1122 static struct datatype **cv_defined_types = NULL;
1125 DEBUG_InitCVDataTypes(void)
1128 * These are the common builtin types that are used by VC++.
1130 cv_basic_types[T_NOTYPE] = NULL;
1131 cv_basic_types[T_ABS] = NULL;
1132 cv_basic_types[T_VOID] = DEBUG_GetBasicType(DT_BASIC_VOID);
1133 cv_basic_types[T_CHAR] = DEBUG_GetBasicType(DT_BASIC_CHAR);
1134 cv_basic_types[T_SHORT] = DEBUG_GetBasicType(DT_BASIC_SHORTINT);
1135 cv_basic_types[T_LONG] = DEBUG_GetBasicType(DT_BASIC_LONGINT);
1136 cv_basic_types[T_QUAD] = DEBUG_GetBasicType(DT_BASIC_LONGLONGINT);
1137 cv_basic_types[T_UCHAR] = DEBUG_GetBasicType(DT_BASIC_UCHAR);
1138 cv_basic_types[T_USHORT] = DEBUG_GetBasicType(DT_BASIC_USHORTINT);
1139 cv_basic_types[T_ULONG] = DEBUG_GetBasicType(DT_BASIC_ULONGINT);
1140 cv_basic_types[T_UQUAD] = DEBUG_GetBasicType(DT_BASIC_ULONGLONGINT);
1141 cv_basic_types[T_REAL32] = DEBUG_GetBasicType(DT_BASIC_FLOAT);
1142 cv_basic_types[T_REAL64] = DEBUG_GetBasicType(DT_BASIC_DOUBLE);
1143 cv_basic_types[T_RCHAR] = DEBUG_GetBasicType(DT_BASIC_CHAR);
1144 cv_basic_types[T_WCHAR] = DEBUG_GetBasicType(DT_BASIC_SHORTINT);
1145 cv_basic_types[T_INT4] = DEBUG_GetBasicType(DT_BASIC_INT);
1146 cv_basic_types[T_UINT4] = DEBUG_GetBasicType(DT_BASIC_UINT);
1148 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
1149 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
1150 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
1151 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
1152 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
1153 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
1154 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
1155 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
1156 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
1157 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
1158 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
1159 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
1160 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
1161 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
1162 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
1167 numeric_leaf( int *value, unsigned short int *leaf )
1169 unsigned short int type = *leaf++;
1172 if ( type < LF_NUMERIC )
1182 *value = *(char *)leaf;
1187 *value = *(short *)leaf;
1192 *value = *(unsigned short *)leaf;
1197 *value = *(int *)leaf;
1202 *value = *(unsigned int *)leaf;
1208 *value = 0; /* FIXME */
1213 *value = 0; /* FIXME */
1218 *value = 0; /* FIXME */
1223 *value = 0; /* FIXME */
1228 *value = 0; /* FIXME */
1233 *value = 0; /* FIXME */
1238 *value = 0; /* FIXME */
1243 *value = 0; /* FIXME */
1248 *value = 0; /* FIXME */
1253 *value = 0; /* FIXME */
1257 length += 2 + *leaf;
1258 *value = 0; /* FIXME */
1262 DEBUG_Printf( DBG_CHN_MESG, "Unknown numeric leaf type %04x\n", type );
1272 terminate_string( unsigned char *name )
1274 static char symname[256];
1276 int namelen = name[0];
1277 assert( namelen >= 0 && namelen < 256 );
1279 memcpy( symname, name+1, namelen );
1280 symname[namelen] = '\0';
1282 if ( !*symname || strcmp( symname, "__unnamed" ) == 0 )
1289 struct datatype * DEBUG_GetCVType(unsigned int typeno)
1291 struct datatype * dt = NULL;
1294 * Convert Codeview type numbers into something we can grok internally.
1295 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
1296 * up are all user defined (structs, etc).
1298 if ( typeno < 0x1000 )
1300 if ( typeno < MAX_BUILTIN_TYPES )
1301 dt = cv_basic_types[typeno];
1305 if ( typeno - 0x1000 < num_cv_defined_types )
1306 dt = cv_defined_types[typeno - 0x1000];
1313 DEBUG_AddCVType( unsigned int typeno, struct datatype *dt )
1315 while ( typeno - 0x1000 >= num_cv_defined_types )
1317 num_cv_defined_types += 0x100;
1318 cv_defined_types = (struct datatype **)
1319 DBG_realloc( cv_defined_types,
1320 num_cv_defined_types * sizeof(struct datatype *) );
1322 memset( cv_defined_types + num_cv_defined_types - 0x100,
1324 0x100 * sizeof(struct datatype *) );
1326 if ( cv_defined_types == NULL )
1330 cv_defined_types[ typeno - 0x1000 ] = dt;
1335 DEBUG_ClearTypeTable( void )
1337 if ( cv_defined_types )
1338 DBG_free( cv_defined_types );
1340 cv_defined_types = NULL;
1341 num_cv_defined_types = 0;
1345 DEBUG_AddCVType_Pointer( unsigned int typeno, unsigned int datatype )
1347 struct datatype *dt =
1348 DEBUG_FindOrMakePointerType( DEBUG_GetCVType( datatype ) );
1350 return DEBUG_AddCVType( typeno, dt );
1354 DEBUG_AddCVType_Array( unsigned int typeno, char *name,
1355 unsigned int elemtype, unsigned int arr_len )
1357 struct datatype *dt = DEBUG_NewDataType( DT_ARRAY, name );
1358 struct datatype *elem = DEBUG_GetCVType( elemtype );
1359 unsigned int elem_size = elem? DEBUG_GetObjectSize( elem ) : 0;
1360 unsigned int arr_max = elem_size? arr_len / elem_size : 0;
1362 DEBUG_SetArrayParams( dt, 0, arr_max, elem );
1363 return DEBUG_AddCVType( typeno, dt );
1367 DEBUG_AddCVType_Bitfield( unsigned int typeno,
1368 unsigned int bitoff, unsigned int nbits,
1369 unsigned int basetype )
1371 struct datatype *dt = DEBUG_NewDataType( DT_BITFIELD, NULL );
1372 struct datatype *base = DEBUG_GetCVType( basetype );
1374 DEBUG_SetBitfieldParams( dt, bitoff, nbits, base );
1375 return DEBUG_AddCVType( typeno, dt );
1379 DEBUG_AddCVType_EnumFieldList( unsigned int typeno, unsigned char *list, int len )
1381 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, NULL );
1382 unsigned char *ptr = list;
1384 while ( ptr - list < len )
1386 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1388 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1394 switch ( type->generic.id )
1398 int value, vlen = numeric_leaf( &value, &type->enumerate.value );
1399 unsigned char *name = (unsigned char *)&type->enumerate.value + vlen;
1401 DEBUG_AddStructElement( dt, terminate_string( name ),
1404 ptr += 2 + 2 + vlen + (1 + name[0]);
1409 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in ENUM field list\n",
1415 return DEBUG_AddCVType( typeno, dt );
1419 DEBUG_AddCVType_StructFieldList( unsigned int typeno, unsigned char *list, int len )
1421 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, NULL );
1422 unsigned char *ptr = list;
1424 while ( ptr - list < len )
1426 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1428 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1434 switch ( type->generic.id )
1438 int offset, olen = numeric_leaf( &offset, &type->bclass.offset );
1440 /* FIXME: ignored for now */
1442 ptr += 2 + 2 + 2 + olen;
1448 int offset, olen = numeric_leaf( &offset, &type->bclass32.offset );
1450 /* FIXME: ignored for now */
1452 ptr += 2 + 2 + 4 + olen;
1459 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass.vbpoff );
1460 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass.vbpoff + vbpoff);
1461 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1463 /* FIXME: ignored for now */
1465 ptr += 2 + 2 + 2 + 2 + vbplen + vplen;
1470 case LF_IVBCLASS_32:
1472 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass32.vbpoff );
1473 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass32.vbpoff + vbpoff);
1474 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1476 /* FIXME: ignored for now */
1478 ptr += 2 + 2 + 4 + 4 + vbplen + vplen;
1484 int offset, olen = numeric_leaf( &offset, &type->member.offset );
1485 unsigned char *name = (unsigned char *)&type->member.offset + olen;
1487 struct datatype *subtype = DEBUG_GetCVType( type->member.type );
1488 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1490 DEBUG_AddStructElement( dt, terminate_string( name ),
1491 subtype, offset << 3, elem_size << 3 );
1493 ptr += 2 + 2 + 2 + olen + (1 + name[0]);
1499 int offset, olen = numeric_leaf( &offset, &type->member32.offset );
1500 unsigned char *name = (unsigned char *)&type->member32.offset + olen;
1502 struct datatype *subtype = DEBUG_GetCVType( type->member32.type );
1503 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1505 DEBUG_AddStructElement( dt, terminate_string( name ),
1506 subtype, offset << 3, elem_size << 3 );
1508 ptr += 2 + 2 + 4 + olen + (1 + name[0]);
1513 /* FIXME: ignored for now */
1514 ptr += 2 + 2 + 2 + (1 + type->stmember.name[0]);
1517 case LF_STMEMBER_32:
1518 /* FIXME: ignored for now */
1519 ptr += 2 + 4 + 2 + (1 + type->stmember32.name[0]);
1523 /* FIXME: ignored for now */
1524 ptr += 2 + 2 + 2 + (1 + type->method.name[0]);
1528 /* FIXME: ignored for now */
1529 ptr += 2 + 2 + 4 + (1 + type->method32.name[0]);
1533 /* FIXME: ignored for now */
1534 ptr += 2 + 2 + (1 + type->nesttype.name[0]);
1537 case LF_NESTTYPE_32:
1538 /* FIXME: ignored for now */
1539 ptr += 2 + 2 + 4 + (1 + type->nesttype32.name[0]);
1543 /* FIXME: ignored for now */
1547 case LF_VFUNCTAB_32:
1548 /* FIXME: ignored for now */
1553 /* FIXME: ignored for now */
1554 switch ( (type->onemethod.attribute >> 2) & 7 )
1556 case 4: case 6: /* (pure) introducing virtual method */
1557 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt.name[0]);
1561 ptr += 2 + 2 + 2 + (1 + type->onemethod.name[0]);
1566 case LF_ONEMETHOD_32:
1567 /* FIXME: ignored for now */
1568 switch ( (type->onemethod32.attribute >> 2) & 7 )
1570 case 4: case 6: /* (pure) introducing virtual method */
1571 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod32_virt.name[0]);
1575 ptr += 2 + 2 + 4 + (1 + type->onemethod32.name[0]);
1581 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in STRUCT field list\n",
1587 return DEBUG_AddCVType( typeno, dt );
1591 DEBUG_AddCVType_Enum( unsigned int typeno, char *name, unsigned int fieldlist )
1593 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, name );
1594 struct datatype *list = DEBUG_GetCVType( fieldlist );
1597 if(DEBUG_CopyFieldlist( dt, list ) == FALSE)
1600 return DEBUG_AddCVType( typeno, dt );
1604 DEBUG_AddCVType_Struct( unsigned int typeno, char *name, int structlen, unsigned int fieldlist )
1606 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, name );
1607 struct datatype *list = DEBUG_GetCVType( fieldlist );
1611 DEBUG_SetStructSize( dt, structlen );
1612 if(DEBUG_CopyFieldlist( dt, list ) == FALSE)
1616 return DEBUG_AddCVType( typeno, dt );
1620 DEBUG_ParseTypeTable( char *table, int len )
1622 unsigned int curr_type = 0x1000;
1625 while ( ptr - table < len )
1627 union codeview_type *type = (union codeview_type *) ptr;
1630 switch ( type->generic.id )
1633 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer.datatype );
1636 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer32.datatype );
1641 int arrlen, alen = numeric_leaf( &arrlen, &type->array.arrlen );
1642 unsigned char *name = (unsigned char *)&type->array.arrlen + alen;
1644 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1645 type->array.elemtype, arrlen );
1650 int arrlen, alen = numeric_leaf( &arrlen, &type->array32.arrlen );
1651 unsigned char *name = (unsigned char *)&type->array32.arrlen + alen;
1653 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1654 type->array32.elemtype, type->array32.arrlen );
1659 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield.bitoff,
1660 type->bitfield.nbits,
1661 type->bitfield.type );
1663 case LF_BITFIELD_32:
1664 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield32.bitoff,
1665 type->bitfield32.nbits,
1666 type->bitfield32.type );
1670 case LF_FIELDLIST_32:
1673 * A 'field list' is a CodeView-specific data type which doesn't
1674 * directly correspond to any high-level data type. It is used
1675 * to hold the collection of members of a struct, class, union
1676 * or enum type. The actual definition of that type will follow
1677 * later, and refer to the field list definition record.
1679 * As we don't have a field list type ourselves, we look ahead
1680 * in the field list to try to find out whether this field list
1681 * will be used for an enum or struct type, and create a dummy
1682 * type of the corresponding sort. Later on, the definition of
1683 * the 'real' type will copy the member / enumeration data.
1686 char *list = type->fieldlist.list;
1687 int len = (ptr + type->generic.len + 2) - list;
1689 if ( ((union codeview_fieldtype *)list)->generic.id == LF_ENUMERATE )
1690 retv = DEBUG_AddCVType_EnumFieldList( curr_type, list, len );
1692 retv = DEBUG_AddCVType_StructFieldList( curr_type, list, len );
1699 int structlen, slen = numeric_leaf( &structlen, &type->structure.structlen );
1700 unsigned char *name = (unsigned char *)&type->structure.structlen + slen;
1702 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1703 structlen, type->structure.fieldlist );
1706 case LF_STRUCTURE_32:
1709 int structlen, slen = numeric_leaf( &structlen, &type->structure32.structlen );
1710 unsigned char *name = (unsigned char *)&type->structure32.structlen + slen;
1712 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1713 structlen, type->structure32.fieldlist );
1719 int un_len, ulen = numeric_leaf( &un_len, &type->t_union.un_len );
1720 unsigned char *name = (unsigned char *)&type->t_union.un_len + ulen;
1722 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1723 un_len, type->t_union.fieldlist );
1728 int un_len, ulen = numeric_leaf( &un_len, &type->t_union32.un_len );
1729 unsigned char *name = (unsigned char *)&type->t_union32.un_len + ulen;
1731 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1732 un_len, type->t_union32.fieldlist );
1737 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration.name ),
1738 type->enumeration.field );
1741 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration32.name ),
1742 type->enumeration32.field );
1753 ptr += type->generic.len + 2;
1760 /*========================================================================
1761 * Process CodeView line number information.
1778 struct codeview_linetab_hdr
1785 unsigned short * linetab;
1786 unsigned int * offtab;
1789 static struct codeview_linetab_hdr *
1790 DEBUG_SnarfLinetab(char * linetab,
1794 char filename[PATH_MAX];
1795 unsigned int * filetab;
1799 struct codeview_linetab_hdr * lt_hdr;
1800 unsigned int * lt_ptr;
1804 union any_size pnt2;
1805 struct startend * start;
1809 * Now get the important bits.
1815 filetab = (unsigned int *) pnt.c;
1818 * Now count up the number of segments in the file.
1821 for(i=0; i<nfile; i++)
1823 pnt2.c = linetab + filetab[i];
1828 * Next allocate the header we will be returning.
1829 * There is one header for each segment, so that we can reach in
1830 * and pull bits as required.
1832 lt_hdr = (struct codeview_linetab_hdr *)
1833 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
1834 if( lt_hdr == NULL )
1839 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
1842 * Now fill the header we will be returning, one for each segment.
1843 * Note that this will basically just contain pointers into the existing
1844 * line table, and we do not actually copy any additional information
1845 * or allocate any additional memory.
1849 for(i=0; i<nfile; i++)
1852 * Get the pointer into the segment information.
1854 pnt2.c = linetab + filetab[i];
1855 file_segcount = *pnt2.s;
1858 lt_ptr = (unsigned int *) pnt2.c;
1859 start = (struct startend *) (lt_ptr + file_segcount);
1862 * Now snarf the filename for all of the segments for this file.
1864 fn = (unsigned char *) (start + file_segcount);
1865 memset(filename, 0, sizeof(filename));
1866 memcpy(filename, fn + 1, *fn);
1867 fn = DBG_strdup(filename);
1869 for(k = 0; k < file_segcount; k++, this_seg++)
1871 pnt2.c = linetab + lt_ptr[k];
1872 lt_hdr[this_seg].start = start[k].start;
1873 lt_hdr[this_seg].end = start[k].end;
1874 lt_hdr[this_seg].sourcefile = fn;
1875 lt_hdr[this_seg].segno = *pnt2.s++;
1876 lt_hdr[this_seg].nline = *pnt2.s++;
1877 lt_hdr[this_seg].offtab = pnt2.ui;
1878 lt_hdr[this_seg].linetab = (unsigned short *)
1879 (pnt2.ui + lt_hdr[this_seg].nline);
1890 /*========================================================================
1891 * Process CodeView symbol information.
1894 union codeview_symbol
1906 unsigned int offset;
1908 unsigned short symtype;
1909 unsigned char namelen;
1910 unsigned char name[1];
1917 unsigned int symtype;
1918 unsigned int offset;
1920 unsigned char namelen;
1921 unsigned char name[1];
1928 unsigned int pparent;
1931 unsigned int offset;
1932 unsigned short segment;
1933 unsigned short thunk_len;
1934 unsigned char thtype;
1935 unsigned char namelen;
1936 unsigned char name[1];
1943 unsigned int pparent;
1946 unsigned int proc_len;
1947 unsigned int debug_start;
1948 unsigned int debug_end;
1949 unsigned int offset;
1950 unsigned short segment;
1951 unsigned short proctype;
1952 unsigned char flags;
1953 unsigned char namelen;
1954 unsigned char name[1];
1961 unsigned int pparent;
1964 unsigned int proc_len;
1965 unsigned int debug_start;
1966 unsigned int debug_end;
1967 unsigned int proctype;
1968 unsigned int offset;
1969 unsigned short segment;
1970 unsigned char flags;
1971 unsigned char namelen;
1972 unsigned char name[1];
1977 short int len; /* Total length of this entry */
1978 short int id; /* Always S_BPREL32 */
1979 unsigned int offset; /* Stack offset relative to BP */
1980 unsigned short symtype;
1981 unsigned char namelen;
1982 unsigned char name[1];
1987 short int len; /* Total length of this entry */
1988 short int id; /* Always S_BPREL32 */
1989 unsigned int offset; /* Stack offset relative to BP */
1990 unsigned int symtype;
1991 unsigned char namelen;
1992 unsigned char name[1];
1997 #define S_COMPILE 0x0001
1998 #define S_REGISTER 0x0002
1999 #define S_CONSTANT 0x0003
2000 #define S_UDT 0x0004
2001 #define S_SSEARCH 0x0005
2002 #define S_END 0x0006
2003 #define S_SKIP 0x0007
2004 #define S_CVRESERVE 0x0008
2005 #define S_OBJNAME 0x0009
2006 #define S_ENDARG 0x000a
2007 #define S_COBOLUDT 0x000b
2008 #define S_MANYREG 0x000c
2009 #define S_RETURN 0x000d
2010 #define S_ENTRYTHIS 0x000e
2012 #define S_BPREL 0x0200
2013 #define S_LDATA 0x0201
2014 #define S_GDATA 0x0202
2015 #define S_PUB 0x0203
2016 #define S_LPROC 0x0204
2017 #define S_GPROC 0x0205
2018 #define S_THUNK 0x0206
2019 #define S_BLOCK 0x0207
2020 #define S_WITH 0x0208
2021 #define S_LABEL 0x0209
2022 #define S_CEXMODEL 0x020a
2023 #define S_VFTPATH 0x020b
2024 #define S_REGREL 0x020c
2025 #define S_LTHREAD 0x020d
2026 #define S_GTHREAD 0x020e
2028 #define S_PROCREF 0x0400
2029 #define S_DATAREF 0x0401
2030 #define S_ALIGN 0x0402
2031 #define S_LPROCREF 0x0403
2033 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
2034 #define S_CONSTANT_32 0x1002
2035 #define S_UDT_32 0x1003
2036 #define S_COBOLUDT_32 0x1004
2037 #define S_MANYREG_32 0x1005
2039 #define S_BPREL_32 0x1006
2040 #define S_LDATA_32 0x1007
2041 #define S_GDATA_32 0x1008
2042 #define S_PUB_32 0x1009
2043 #define S_LPROC_32 0x100a
2044 #define S_GPROC_32 0x100b
2045 #define S_VFTTABLE_32 0x100c
2046 #define S_REGREL_32 0x100d
2047 #define S_LTHREAD_32 0x100e
2048 #define S_GTHREAD_32 0x100f
2053 DEBUG_MapCVOffset( DBG_MODULE *module, unsigned int offset )
2055 int nomap = module->msc_info->nomap;
2056 OMAP_DATA *omapp = module->msc_info->omapp;
2059 if ( !nomap || !omapp )
2062 /* FIXME: use binary search */
2063 for ( i = 0; i < nomap-1; i++ )
2064 if ( omapp[i].from <= offset && omapp[i+1].from > offset )
2065 return !omapp[i].to? 0 : omapp[i].to + (offset - omapp[i].from);
2070 static struct name_hash *
2071 DEBUG_AddCVSymbol( DBG_MODULE *module, char *name, int namelen,
2072 int type, unsigned int seg, unsigned int offset,
2073 int size, int cookie, int flags,
2074 struct codeview_linetab_hdr *linetab )
2076 int nsect = module->msc_info->nsect;
2077 PIMAGE_SECTION_HEADER sectp = module->msc_info->sectp;
2079 struct name_hash *symbol;
2080 char symname[PATH_MAX];
2084 * Some sanity checks
2087 if ( !name || !namelen )
2090 if ( !seg || seg > nsect )
2094 * Convert type, address, and symbol name
2096 value.type = type? DEBUG_GetCVType( type ) : NULL;
2097 value.cookie = cookie;
2100 value.addr.off = (unsigned int) module->load_addr +
2101 DEBUG_MapCVOffset( module, sectp[seg-1].VirtualAddress + offset );
2103 memcpy( symname, name, namelen );
2104 symname[namelen] = '\0';
2108 * Check whether we have line number information
2112 for ( ; linetab->linetab; linetab++ )
2113 if ( linetab->segno == seg
2114 && linetab->start <= offset
2115 && linetab->end > offset )
2118 if ( !linetab->linetab )
2124 * Create Wine symbol record
2126 symbol = DEBUG_AddSymbol( symname, &value,
2127 linetab? linetab->sourcefile : NULL, flags );
2130 DEBUG_SetSymbolSize( symbol, size );
2134 * Add line numbers if found
2139 for ( i = 0; i < linetab->nline; i++ )
2140 if ( linetab->offtab[i] >= offset
2141 && linetab->offtab[i] < offset + size )
2143 DEBUG_AddLineNumber( symbol, linetab->linetab[i],
2144 linetab->offtab[i] - offset );
2151 static struct wine_locals *
2152 DEBUG_AddCVLocal( struct name_hash *func, char *name, int namelen,
2153 int type, int offset )
2155 struct wine_locals *local;
2156 char symname[PATH_MAX];
2158 memcpy( symname, name, namelen );
2159 symname[namelen] = '\0';
2161 local = DEBUG_AddLocal( func, 0, offset, 0, 0, symname );
2162 DEBUG_SetLocalSymbolType( local, DEBUG_GetCVType( type ) );
2168 DEBUG_SnarfCodeView( DBG_MODULE *module, LPBYTE root, int offset, int size,
2169 struct codeview_linetab_hdr *linetab )
2171 struct name_hash *curr_func = NULL;
2176 * Loop over the different types of records and whenever we
2177 * find something we are interested in, record it and move on.
2179 for ( i = offset; i < size; i += length )
2181 union codeview_symbol *sym = (union codeview_symbol *)(root + i);
2182 length = sym->generic.len + 2;
2184 switch ( sym->generic.id )
2187 * Global and local data symbols. We don't associate these
2188 * with any given source file.
2193 DEBUG_AddCVSymbol( module, sym->data.name, sym->data.namelen,
2194 sym->data.symtype, sym->data.seg,
2195 sym->data.offset, 0,
2196 DV_TARGET, SYM_WIN32 | SYM_DATA, NULL );
2201 DEBUG_AddCVSymbol( module, sym->data32.name, sym->data32.namelen,
2202 sym->data32.symtype, sym->data32.seg,
2203 sym->data32.offset, 0,
2204 DV_TARGET, SYM_WIN32 | SYM_DATA, NULL );
2208 * Sort of like a global function, but it just points
2209 * to a thunk, which is a stupid name for what amounts to
2210 * a PLT slot in the normal jargon that everyone else uses.
2213 DEBUG_AddCVSymbol( module, sym->thunk.name, sym->thunk.namelen,
2214 0, sym->thunk.segment,
2215 sym->thunk.offset, sym->thunk.thunk_len,
2216 DV_TARGET, SYM_WIN32 | SYM_FUNC, NULL );
2220 * Global and static functions.
2224 DEBUG_Normalize( curr_func );
2226 curr_func = DEBUG_AddCVSymbol( module, sym->proc.name, sym->proc.namelen,
2227 sym->proc.proctype, sym->proc.segment,
2228 sym->proc.offset, sym->proc.proc_len,
2229 DV_TARGET, SYM_WIN32 | SYM_FUNC, linetab );
2231 DEBUG_SetSymbolBPOff( curr_func, sym->proc.debug_start );
2235 DEBUG_Normalize( curr_func );
2237 curr_func = DEBUG_AddCVSymbol( module, sym->proc32.name, sym->proc32.namelen,
2238 sym->proc32.proctype, sym->proc32.segment,
2239 sym->proc32.offset, sym->proc32.proc_len,
2240 DV_TARGET, SYM_WIN32 | SYM_FUNC, linetab );
2242 DEBUG_SetSymbolBPOff( curr_func, sym->proc32.debug_start );
2247 * Function parameters and stack variables.
2250 DEBUG_AddCVLocal( curr_func, sym->stack.name, sym->stack.namelen,
2251 sym->stack.symtype, sym->stack.offset );
2254 DEBUG_AddCVLocal( curr_func, sym->stack32.name, sym->stack32.namelen,
2255 sym->stack32.symtype, sym->stack32.offset );
2260 * These are special, in that they are always followed by an
2261 * additional length-prefixed string which is *not* included
2262 * into the symbol length count. We need to skip it.
2268 LPBYTE name = (LPBYTE)sym + length;
2269 length += (*name + 1 + 3) & ~3;
2275 DEBUG_Normalize( curr_func );
2277 if ( linetab ) DBG_free(linetab);
2283 /*========================================================================
2288 typedef struct _PDB_FILE
2293 } PDB_FILE, *PPDB_FILE;
2295 typedef struct _PDB_HEADER
2303 WORD toc_block[ 1 ];
2305 } PDB_HEADER, *PPDB_HEADER;
2307 typedef struct _PDB_TOC
2312 } PDB_TOC, *PPDB_TOC;
2314 typedef struct _PDB_ROOT
2317 DWORD TimeDateStamp;
2322 } PDB_ROOT, *PPDB_ROOT;
2324 typedef struct _PDB_TYPES_OLD
2333 } PDB_TYPES_OLD, *PPDB_TYPES_OLD;
2335 typedef struct _PDB_TYPES
2348 DWORD search_offset;
2350 DWORD unknown_offset;
2353 } PDB_TYPES, *PPDB_TYPES;
2355 typedef struct _PDB_SYMBOL_RANGE
2361 DWORD characteristics;
2365 } PDB_SYMBOL_RANGE, *PPDB_SYMBOL_RANGE;
2367 typedef struct _PDB_SYMBOL_RANGE_EX
2373 DWORD characteristics;
2379 } PDB_SYMBOL_RANGE_EX, *PPDB_SYMBOL_RANGE_EX;
2381 typedef struct _PDB_SYMBOL_FILE
2384 PDB_SYMBOL_RANGE range;
2394 } PDB_SYMBOL_FILE, *PPDB_SYMBOL_FILE;
2396 typedef struct _PDB_SYMBOL_FILE_EX
2399 PDB_SYMBOL_RANGE_EX range;
2407 DWORD reserved[ 2 ];
2410 } PDB_SYMBOL_FILE_EX, *PPDB_SYMBOL_FILE_EX;
2412 typedef struct _PDB_SYMBOL_SOURCE
2418 } PDB_SYMBOL_SOURCE, *PPDB_SYMBOL_SOURCE;
2420 typedef struct _PDB_SYMBOL_IMPORT
2424 DWORD TimeDateStamp;
2428 } PDB_SYMBOL_IMPORT, *PPDB_SYMBOL_IMPORT;
2430 typedef struct _PDB_SYMBOLS_OLD
2439 DWORD srcmodule_size;
2441 } PDB_SYMBOLS_OLD, *PPDB_SYMBOLS_OLD;
2443 typedef struct _PDB_SYMBOLS
2454 DWORD srcmodule_size;
2455 DWORD pdbimport_size;
2458 } PDB_SYMBOLS, *PPDB_SYMBOLS;
2462 static void *pdb_read( LPBYTE image, WORD *block_list, int size )
2464 PPDB_HEADER pdb = (PPDB_HEADER)image;
2468 if ( !size ) return NULL;
2470 nBlocks = (size + pdb->blocksize-1) / pdb->blocksize;
2471 buffer = DBG_alloc( nBlocks * pdb->blocksize );
2473 for ( i = 0; i < nBlocks; i++ )
2474 memcpy( buffer + i*pdb->blocksize,
2475 image + block_list[i]*pdb->blocksize, pdb->blocksize );
2480 static void *pdb_read_file( LPBYTE image, PPDB_TOC toc, DWORD fileNr )
2482 PPDB_HEADER pdb = (PPDB_HEADER)image;
2486 if ( !toc || fileNr >= toc->nFiles )
2489 block_list = (WORD *) &toc->file[ toc->nFiles ];
2490 for ( i = 0; i < fileNr; i++ )
2491 block_list += (toc->file[i].size + pdb->blocksize-1) / pdb->blocksize;
2493 return pdb_read( image, block_list, toc->file[fileNr].size );
2496 static void pdb_free( void *buffer )
2501 static void pdb_convert_types_header( PDB_TYPES *types, char *image )
2503 memset( types, 0, sizeof(PDB_TYPES) );
2504 if ( !image ) return;
2506 if ( *(DWORD *)image < 19960000 ) /* FIXME: correct version? */
2508 /* Old version of the types record header */
2509 PDB_TYPES_OLD *old = (PDB_TYPES_OLD *)image;
2510 types->version = old->version;
2511 types->type_offset = sizeof(PDB_TYPES_OLD);
2512 types->type_size = old->type_size;
2513 types->first_index = old->first_index;
2514 types->last_index = old->last_index;
2515 types->file = old->file;
2519 /* New version of the types record header */
2520 *types = *(PDB_TYPES *)image;
2524 static void pdb_convert_symbols_header( PDB_SYMBOLS *symbols,
2525 int *header_size, char *image )
2527 memset( symbols, 0, sizeof(PDB_SYMBOLS) );
2528 if ( !image ) return;
2530 if ( *(DWORD *)image != 0xffffffff )
2532 /* Old version of the symbols record header */
2533 PDB_SYMBOLS_OLD *old = (PDB_SYMBOLS_OLD *)image;
2534 symbols->version = 0;
2535 symbols->module_size = old->module_size;
2536 symbols->offset_size = old->offset_size;
2537 symbols->hash_size = old->hash_size;
2538 symbols->srcmodule_size = old->srcmodule_size;
2539 symbols->pdbimport_size = 0;
2540 symbols->hash1_file = old->hash1_file;
2541 symbols->hash2_file = old->hash2_file;
2542 symbols->gsym_file = old->gsym_file;
2544 *header_size = sizeof(PDB_SYMBOLS_OLD);
2548 /* New version of the symbols record header */
2549 *symbols = *(PDB_SYMBOLS *)image;
2551 *header_size = sizeof(PDB_SYMBOLS);
2555 static enum DbgInfoLoad DEBUG_ProcessPDBFile( DBG_MODULE *module,
2556 const char *filename, DWORD timestamp )
2558 enum DbgInfoLoad dil = DIL_ERROR;
2561 PDB_HEADER *pdb = NULL;
2562 PDB_TOC *toc = NULL;
2563 PDB_ROOT *root = NULL;
2564 char *types_image = NULL;
2565 char *symbols_image = NULL;
2567 PDB_SYMBOLS symbols;
2568 int header_size = 0;
2569 char *modimage, *file;
2571 DEBUG_Printf( DBG_CHN_TRACE, "Processing PDB file %s\n", filename );
2574 * Open and map() .PDB file
2576 image = DEBUG_MapDebugInfoFile( filename, 0, 0, &hFile, &hMap );
2579 DEBUG_Printf( DBG_CHN_ERR, "-Unable to peruse .PDB file %s\n", filename );
2584 * Read in TOC and well-known files
2587 pdb = (PPDB_HEADER)image;
2588 toc = pdb_read( image, pdb->toc_block, pdb->toc.size );
2589 root = pdb_read_file( image, toc, 1 );
2590 types_image = pdb_read_file( image, toc, 2 );
2591 symbols_image = pdb_read_file( image, toc, 3 );
2593 pdb_convert_types_header( &types, types_image );
2594 pdb_convert_symbols_header( &symbols, &header_size, symbols_image );
2598 DEBUG_Printf( DBG_CHN_ERR,
2599 "-Unable to get root from .PDB file %s\n",
2605 * Check for unknown versions
2608 switch ( root->version )
2610 case 19950623: /* VC 4.0 */
2612 case 19960307: /* VC 5.0 */
2613 case 19970604: /* VC 6.0 */
2616 DEBUG_Printf( DBG_CHN_ERR, "-Unknown root block version %ld\n", root->version );
2619 switch ( types.version )
2621 case 19950410: /* VC 4.0 */
2623 case 19961031: /* VC 5.0 / 6.0 */
2626 DEBUG_Printf( DBG_CHN_ERR, "-Unknown type info version %ld\n", types.version );
2629 switch ( symbols.version )
2631 case 0: /* VC 4.0 */
2632 case 19960307: /* VC 5.0 */
2633 case 19970606: /* VC 6.0 */
2636 DEBUG_Printf( DBG_CHN_ERR, "-Unknown symbol info version %ld\n", symbols.version );
2641 * Check .PDB time stamp
2644 if ( root->TimeDateStamp != timestamp )
2646 DEBUG_Printf( DBG_CHN_ERR, "-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
2647 filename, root->TimeDateStamp, timestamp );
2654 DEBUG_ParseTypeTable( types_image + types.type_offset, types.type_size );
2657 * Read type-server .PDB imports
2660 if ( symbols.pdbimport_size )
2663 DEBUG_Printf(DBG_CHN_ERR, "-Type server .PDB imports ignored!\n" );
2667 * Read global symbol table
2670 modimage = pdb_read_file( image, toc, symbols.gsym_file );
2673 DEBUG_SnarfCodeView( module, modimage, 0,
2674 toc->file[symbols.gsym_file].size, NULL );
2675 pdb_free( modimage );
2679 * Read per-module symbol / linenumber tables
2682 file = symbols_image + header_size;
2683 while ( file - symbols_image < header_size + symbols.module_size )
2685 int file_nr, file_index, symbol_size, lineno_size;
2688 if ( symbols.version < 19970000 )
2690 PDB_SYMBOL_FILE *sym_file = (PDB_SYMBOL_FILE *) file;
2691 file_nr = sym_file->file;
2692 file_name = sym_file->filename;
2693 file_index = sym_file->range.index;
2694 symbol_size = sym_file->symbol_size;
2695 lineno_size = sym_file->lineno_size;
2699 PDB_SYMBOL_FILE_EX *sym_file = (PDB_SYMBOL_FILE_EX *) file;
2700 file_nr = sym_file->file;
2701 file_name = sym_file->filename;
2702 file_index = sym_file->range.index;
2703 symbol_size = sym_file->symbol_size;
2704 lineno_size = sym_file->lineno_size;
2707 modimage = pdb_read_file( image, toc, file_nr );
2710 struct codeview_linetab_hdr *linetab = NULL;
2713 linetab = DEBUG_SnarfLinetab( modimage + symbol_size, lineno_size );
2716 DEBUG_SnarfCodeView( module, modimage, sizeof(DWORD),
2717 symbol_size, linetab );
2719 pdb_free( modimage );
2722 file_name += strlen(file_name) + 1;
2723 file = (char *)( (DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3 );
2734 DEBUG_ClearTypeTable();
2736 if ( symbols_image ) pdb_free( symbols_image );
2737 if ( types_image ) pdb_free( types_image );
2738 if ( root ) pdb_free( root );
2739 if ( toc ) pdb_free( toc );
2741 DEBUG_UnmapDebugInfoFile(hFile, hMap, image);
2749 /*========================================================================
2750 * Process CodeView debug information.
2753 #define CODEVIEW_NB09_SIG ( 'N' | ('B' << 8) | ('0' << 16) | ('9' << 24) )
2754 #define CODEVIEW_NB10_SIG ( 'N' | ('B' << 8) | ('1' << 16) | ('0' << 24) )
2755 #define CODEVIEW_NB11_SIG ( 'N' | ('B' << 8) | ('1' << 16) | ('1' << 24) )
2757 typedef struct _CODEVIEW_HEADER
2762 } CODEVIEW_HEADER, *PCODEVIEW_HEADER;
2764 typedef struct _CODEVIEW_PDB_DATA
2770 } CODEVIEW_PDB_DATA, *PCODEVIEW_PDB_DATA;
2772 typedef struct _CV_DIRECTORY_HEADER
2780 } CV_DIRECTORY_HEADER, *PCV_DIRECTORY_HEADER;
2782 typedef struct _CV_DIRECTORY_ENTRY
2789 } CV_DIRECTORY_ENTRY, *PCV_DIRECTORY_ENTRY;
2792 #define sstAlignSym 0x125
2793 #define sstSrcModule 0x127
2796 static enum DbgInfoLoad DEBUG_ProcessCodeView( DBG_MODULE *module, LPBYTE root )
2798 PCODEVIEW_HEADER cv = (PCODEVIEW_HEADER)root;
2799 enum DbgInfoLoad dil = DIL_ERROR;
2801 switch ( cv->dwSignature )
2803 case CODEVIEW_NB09_SIG:
2804 case CODEVIEW_NB11_SIG:
2806 PCV_DIRECTORY_HEADER hdr = (PCV_DIRECTORY_HEADER)(root + cv->lfoDirectory);
2807 PCV_DIRECTORY_ENTRY ent, prev, next;
2810 ent = (PCV_DIRECTORY_ENTRY)((LPBYTE)hdr + hdr->cbDirHeader);
2811 for ( i = 0; i < hdr->cDir; i++, ent = next )
2813 next = (i == hdr->cDir-1)? NULL :
2814 (PCV_DIRECTORY_ENTRY)((LPBYTE)ent + hdr->cbDirEntry);
2815 prev = (i == 0)? NULL :
2816 (PCV_DIRECTORY_ENTRY)((LPBYTE)ent - hdr->cbDirEntry);
2818 if ( ent->subsection == sstAlignSym )
2821 * Check the next and previous entry. If either is a
2822 * sstSrcModule, it contains the line number info for
2825 * FIXME: This is not a general solution!
2827 struct codeview_linetab_hdr *linetab = NULL;
2829 if ( next && next->iMod == ent->iMod
2830 && next->subsection == sstSrcModule )
2831 linetab = DEBUG_SnarfLinetab( root + next->lfo, next->cb );
2833 if ( prev && prev->iMod == ent->iMod
2834 && prev->subsection == sstSrcModule )
2835 linetab = DEBUG_SnarfLinetab( root + prev->lfo, prev->cb );
2838 DEBUG_SnarfCodeView( module, root + ent->lfo, sizeof(DWORD),
2847 case CODEVIEW_NB10_SIG:
2849 PCODEVIEW_PDB_DATA pdb = (PCODEVIEW_PDB_DATA)(cv + 1);
2851 dil = DEBUG_ProcessPDBFile( module, pdb->name, pdb->timestamp );
2856 DEBUG_Printf( DBG_CHN_ERR, "Unknown CODEVIEW signature %08lX in module %s\n",
2857 cv->dwSignature, module->module_name );
2865 /*========================================================================
2866 * Process debug directory.
2868 static enum DbgInfoLoad DEBUG_ProcessDebugDirectory( DBG_MODULE *module,
2870 PIMAGE_DEBUG_DIRECTORY dbg,
2873 enum DbgInfoLoad dil;
2877 /* First, watch out for OMAP data */
2878 for ( i = 0; i < nDbg; i++ )
2880 if ( dbg[i].Type == IMAGE_DEBUG_TYPE_OMAP_FROM_SRC )
2882 module->msc_info->nomap = dbg[i].SizeOfData / sizeof(OMAP_DATA);
2883 module->msc_info->omapp = (OMAP_DATA *)(file_map + dbg[i].PointerToRawData);
2888 /* Now, try to parse CodeView debug info */
2889 for ( i = 0; dil != DIL_LOADED && i < nDbg; i++ )
2891 if ( dbg[i].Type == IMAGE_DEBUG_TYPE_CODEVIEW )
2893 dil = DEBUG_ProcessCodeView( module, file_map + dbg[i].PointerToRawData );
2897 /* If not found, try to parse COFF debug info */
2898 for ( i = 0; dil != DIL_LOADED && i < nDbg; i++ )
2900 if ( dbg[i].Type == IMAGE_DEBUG_TYPE_COFF )
2901 dil = DEBUG_ProcessCoff( module, file_map + dbg[i].PointerToRawData );
2904 /* FIXME: this should be supported... this is the debug information for
2905 * functions compiled without a frame pointer (FPO = frame pointer omission)
2906 * the associated data helps finding out the relevant information
2908 for ( i = 0; i < nDbg; i++ )
2909 if ( dbg[i].Type == IMAGE_DEBUG_TYPE_FPO )
2910 DEBUG_Printf(DBG_CHN_MESG, "This guy has FPO information\n");
2913 #define FRAME_TRAP 1
2916 typedef struct _FPO_DATA {
2917 DWORD ulOffStart; /* offset 1st byte of function code */
2918 DWORD cbProcSize; /* # bytes in function */
2919 DWORD cdwLocals; /* # bytes in locals/4 */
2920 WORD cdwParams; /* # bytes in params/4 */
2922 WORD cbProlog : 8; /* # bytes in prolog */
2923 WORD cbRegs : 3; /* # regs saved */
2924 WORD fHasSEH : 1; /* TRUE if SEH in func */
2925 WORD fUseBP : 1; /* TRUE if EBP has been allocated */
2926 WORD reserved : 1; /* reserved for future use */
2927 WORD cbFrame : 2; /* frame type */
2931 __EXCEPT(page_fault)
2940 /*========================================================================
2943 static enum DbgInfoLoad DEBUG_ProcessDBGFile( DBG_MODULE *module,
2944 const char *filename, DWORD timestamp )
2946 enum DbgInfoLoad dil = DIL_ERROR;
2947 HANDLE hFile = INVALID_HANDLE_VALUE, hMap = 0;
2948 LPBYTE file_map = NULL;
2949 PIMAGE_SEPARATE_DEBUG_HEADER hdr;
2950 PIMAGE_DEBUG_DIRECTORY dbg;
2954 DEBUG_Printf( DBG_CHN_TRACE, "Processing DBG file %s\n", filename );
2956 file_map = DEBUG_MapDebugInfoFile( filename, 0, 0, &hFile, &hMap );
2959 DEBUG_Printf( DBG_CHN_ERR, "-Unable to peruse .DBG file %s\n", filename );
2963 hdr = (PIMAGE_SEPARATE_DEBUG_HEADER) file_map;
2965 if ( hdr->TimeDateStamp != timestamp )
2967 DEBUG_Printf( DBG_CHN_ERR, "Warning - %s has incorrect internal timestamp\n",
2970 * Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2971 * files but nonetheless this check fails. Anyway, WINDBG (debugger for
2972 * Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2977 dbg = (PIMAGE_DEBUG_DIRECTORY) ( file_map + sizeof(*hdr)
2978 + hdr->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
2979 + hdr->ExportedNamesSize );
2981 nDbg = hdr->DebugDirectorySize / sizeof(*dbg);
2983 dil = DEBUG_ProcessDebugDirectory( module, file_map, dbg, nDbg );
2987 DEBUG_UnmapDebugInfoFile( hFile, hMap, file_map );
2992 /*========================================================================
2993 * Process MSC debug information in PE file.
2995 enum DbgInfoLoad DEBUG_RegisterMSCDebugInfo( DBG_MODULE *module, HANDLE hFile,
2996 void *_nth, unsigned long nth_ofs )
2998 enum DbgInfoLoad dil = DIL_ERROR;
2999 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
3000 PIMAGE_DATA_DIRECTORY dir = nth->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_DEBUG;
3001 PIMAGE_DEBUG_DIRECTORY dbg = NULL;
3003 MSC_DBG_INFO extra_info = { 0, NULL, 0, NULL };
3005 LPBYTE file_map = NULL;
3008 /* Read in section data */
3010 module->msc_info = &extra_info;
3011 extra_info.nsect = nth->FileHeader.NumberOfSections;
3012 extra_info.sectp = DBG_alloc( extra_info.nsect * sizeof(IMAGE_SECTION_HEADER) );
3013 if ( !extra_info.sectp )
3016 if ( !DEBUG_READ_MEM_VERBOSE( (char *)module->load_addr +
3017 nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
3018 nth->FileHeader.SizeOfOptionalHeader,
3020 extra_info.nsect * sizeof(IMAGE_SECTION_HEADER) ) )
3023 /* Read in debug directory */
3025 nDbg = dir->Size / sizeof(IMAGE_DEBUG_DIRECTORY);
3029 dbg = (PIMAGE_DEBUG_DIRECTORY) DBG_alloc( nDbg * sizeof(IMAGE_DEBUG_DIRECTORY) );
3033 if ( !DEBUG_READ_MEM_VERBOSE( (char *)module->load_addr + dir->VirtualAddress,
3034 dbg, nDbg * sizeof(IMAGE_DEBUG_DIRECTORY) ) )
3038 /* Map in PE file */
3039 file_map = DEBUG_MapDebugInfoFile( NULL, 0, 0, &hFile, &hMap );
3044 /* Parse debug directory */
3046 if ( nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED )
3048 /* Debug info is stripped to .DBG file */
3050 PIMAGE_DEBUG_MISC misc = (PIMAGE_DEBUG_MISC)(file_map + dbg->PointerToRawData);
3052 if ( nDbg != 1 || dbg->Type != IMAGE_DEBUG_TYPE_MISC
3053 || misc->DataType != IMAGE_DEBUG_MISC_EXENAME )
3055 DEBUG_Printf( DBG_CHN_ERR, "-Debug info stripped, but no .DBG file in module %s\n",
3056 module->module_name );
3060 dil = DEBUG_ProcessDBGFile( module, misc->Data, nth->FileHeader.TimeDateStamp );
3064 /* Debug info is embedded into PE module */
3065 /* FIXME: the nDBG information we're manipulating comes from the debuggee
3066 * address space. However, the following code will be made against the
3067 * version mapped in the debugger address space. There are cases (for example
3068 * when the PE sections are compressed in the file and become decompressed
3069 * in the debuggee address space) where the two don't match.
3070 * Therefore, redo the DBG information lookup with the mapped data
3072 PIMAGE_NT_HEADERS mpd_nth = (PIMAGE_NT_HEADERS)(file_map + nth_ofs);
3073 PIMAGE_DATA_DIRECTORY mpd_dir;
3074 PIMAGE_DEBUG_DIRECTORY mpd_dbg = NULL;
3077 if ( mpd_nth->Signature != IMAGE_NT_SIGNATURE ||
3078 mpd_nth->FileHeader.NumberOfSections != nth->FileHeader.NumberOfSections ||
3079 (mpd_nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0)
3081 mpd_dir = mpd_nth->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_DEBUG;
3083 if ((mpd_dir->Size / sizeof(IMAGE_DEBUG_DIRECTORY)) != nDbg)
3086 mpd_dbg = (PIMAGE_DEBUG_DIRECTORY)(file_map + mpd_dir->VirtualAddress);
3088 dil = DEBUG_ProcessDebugDirectory( module, file_map, mpd_dbg, nDbg );
3093 module->msc_info = NULL;
3095 DEBUG_UnmapDebugInfoFile( 0, hMap, file_map );
3096 if ( extra_info.sectp ) DBG_free( extra_info.sectp );
3097 if ( dbg ) DBG_free( dbg );
3102 /*========================================================================
3103 * look for stabs information in PE header (it's how mingw compiler provides its
3104 * debugging information), and also wine PE <-> ELF linking through .wsolnk sections
3106 enum DbgInfoLoad DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile,
3107 void* _nth, unsigned long nth_ofs)
3109 IMAGE_SECTION_HEADER pe_seg;
3110 unsigned long pe_seg_ofs;
3111 int i, stabsize = 0, stabstrsize = 0;
3112 unsigned int stabs = 0, stabstr = 0;
3113 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
3114 enum DbgInfoLoad dil = DIL_ERROR;
3116 pe_seg_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
3117 nth->FileHeader.SizeOfOptionalHeader;
3119 for (i = 0; i < nth->FileHeader.NumberOfSections; i++, pe_seg_ofs += sizeof(pe_seg)) {
3120 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + pe_seg_ofs),
3121 &pe_seg, sizeof(pe_seg)))
3124 if (!strcasecmp(pe_seg.Name, ".stab")) {
3125 stabs = pe_seg.VirtualAddress;
3126 stabsize = pe_seg.SizeOfRawData;
3127 } else if (!strncasecmp(pe_seg.Name, ".stabstr", 8)) {
3128 stabstr = pe_seg.VirtualAddress;
3129 stabstrsize = pe_seg.SizeOfRawData;
3133 if (stabstrsize && stabsize) {
3134 char* s1 = DBG_alloc(stabsize+stabstrsize);
3137 if (DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabs, s1, stabsize) &&
3138 DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabstr,
3139 s1 + stabsize, stabstrsize)) {
3140 dil = DEBUG_ParseStabs(s1, 0, 0, stabsize, stabsize, stabstrsize);
3142 DEBUG_Printf(DBG_CHN_MESG, "couldn't read data block\n");
3146 DEBUG_Printf(DBG_CHN_MESG, "couldn't alloc %d bytes\n",
3147 stabsize + stabstrsize);