2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999, Ulrich Weigand.
8 * Note - this handles reading debug information for 32 bit applications
9 * that run under Windows-NT for example. I doubt that this would work well
10 * for 16 bit applications, but I don't think it really matters since the
11 * file format is different, and we should never get in here in such cases.
14 * Get 16 bit CV stuff working.
15 * Add symbol size to internal symbol table.
24 #define PATH_MAX _MAX_PATH
32 IMAGE_DEBUG_DIRECTORY dbgdir;
39 #define MSC_INFO(module) ((MSC_DBG_INFO*)((module)->extra_info))
41 static int DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module);
44 * dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
46 static void DEBUG_LocateDebugInfoFile(const char *filename, char *dbg_filename)
48 char *str1 = DBG_alloc(MAX_PATHNAME_LEN);
49 char *str2 = DBG_alloc(MAX_PATHNAME_LEN*10);
53 file = strrchr(filename, '\\');
54 if( file == NULL ) file = filename; else file++;
56 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
57 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
58 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
59 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
60 (SearchPath(NULL, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part)))
61 lstrcpyn(dbg_filename, str2, MAX_PATHNAME_LEN);
63 lstrcpyn(dbg_filename, filename, MAX_PATHNAME_LEN);
68 /***********************************************************************
69 * DEBUG_MapDebugInfoFile
71 static void* DEBUG_MapDebugInfoFile(const char* name, DWORD offset, DWORD size,
72 HANDLE* hFile, HANDLE* hMap)
75 DWORD g_offset; /* offset aligned on map granuality */
76 DWORD g_size; /* size to map, with offset aligned */
82 char filename[MAX_PATHNAME_LEN];
84 DEBUG_LocateDebugInfoFile(name, filename);
85 if ((*hFile = OpenFile(filename, &ofs, OF_READ)) == HFILE_ERROR)
90 DWORD file_size = GetFileSize(*hFile, NULL);
91 if (file_size == (DWORD)-1) return NULL;
92 size = file_size - offset;
95 g_offset = offset & ~0xFFFF; /* FIXME: is granularity portable ? */
96 g_size = offset + size - g_offset;
98 if ((*hMap = CreateFileMapping(*hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == 0)
101 if ((ret = MapViewOfFile(*hMap, FILE_MAP_READ, 0, g_offset, g_size)) != NULL)
102 ret += offset - g_offset;
106 /***********************************************************************
107 * DEBUG_UnmapDebugInfoFile
109 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile, HANDLE hMap, void* addr)
111 if (addr) UnmapViewOfFile(addr);
112 if (hMap) CloseHandle(hMap);
113 if (hFile) CloseHandle(hFile);
125 * This is a convenience structure used to map portions of the
135 * This is how we reference the various record types.
137 union codeview_symbol
151 unsigned short symtype;
152 unsigned char namelen;
153 unsigned char name[1];
160 unsigned int symtype;
163 unsigned char namelen;
164 unsigned char name[1];
171 unsigned int pparent;
175 unsigned short segment;
176 unsigned short thunk_len;
177 unsigned char thtype;
178 unsigned char namelen;
179 unsigned char name[1];
186 unsigned int pparent;
189 unsigned int proc_len;
190 unsigned int debug_start;
191 unsigned int debug_end;
193 unsigned short segment;
194 unsigned short proctype;
196 unsigned char namelen;
197 unsigned char name[1];
204 unsigned int pparent;
207 unsigned int proc_len;
208 unsigned int debug_start;
209 unsigned int debug_end;
210 unsigned int proctype;
212 unsigned short segment;
214 unsigned char namelen;
215 unsigned char name[1];
220 short int len; /* Total length of this entry */
221 short int id; /* Always S_BPREL32 */
222 unsigned int offset; /* Stack offset relative to BP */
223 unsigned short symtype;
224 unsigned char namelen;
225 unsigned char name[1];
230 short int len; /* Total length of this entry */
231 short int id; /* Always S_BPREL32 */
232 unsigned int offset; /* Stack offset relative to BP */
233 unsigned int symtype;
234 unsigned char namelen;
235 unsigned char name[1];
254 unsigned char variant[1];
261 unsigned int datatype;
262 unsigned int attribute;
263 unsigned char variant[1];
271 unsigned char bitoff;
281 unsigned char bitoff;
290 unsigned char arrlen;
291 unsigned char namelen;
292 unsigned char name[1];
299 unsigned int elemtype;
300 unsigned int idxtype;
301 unsigned char arrlen;
302 unsigned char namelen;
303 unsigned char name[1];
315 unsigned short structlen;
316 unsigned char namelen;
317 unsigned char name[1];
326 unsigned int fieldlist;
327 unsigned int derived;
329 unsigned short structlen;
330 unsigned char namelen;
331 unsigned char name[1];
341 unsigned short un_len;
342 unsigned char namelen;
343 unsigned char name[1];
353 unsigned short un_len;
354 unsigned char namelen;
355 unsigned char name[1];
366 unsigned char namelen;
367 unsigned char name[1];
378 unsigned char namelen;
379 unsigned char name[1];
386 unsigned short int value;
387 unsigned char namelen;
388 unsigned char name[1];
396 unsigned short int offset;
397 unsigned char namelen;
398 unsigned char name[1];
406 unsigned short int offset;
407 unsigned char namelen;
408 unsigned char name[1];
412 #define S_COMPILE 0x0001
413 #define S_REGISTER 0x0002
414 #define S_CONSTANT 0x0003
416 #define S_SSEARCH 0x0005
418 #define S_SKIP 0x0007
419 #define S_CVRESERVE 0x0008
420 #define S_OBJNAME 0x0009
421 #define S_ENDARG 0x000a
422 #define S_COBOLUDT 0x000b
423 #define S_MANYREG 0x000c
424 #define S_RETURN 0x000d
425 #define S_ENTRYTHIS 0x000e
427 #define S_BPREL 0x0200
428 #define S_LDATA 0x0201
429 #define S_GDATA 0x0202
431 #define S_LPROC 0x0204
432 #define S_GPROC 0x0205
433 #define S_THUNK 0x0206
434 #define S_BLOCK 0x0207
435 #define S_WITH 0x0208
436 #define S_LABEL 0x0209
437 #define S_CEXMODEL 0x020a
438 #define S_VFTPATH 0x020b
439 #define S_REGREL 0x020c
440 #define S_LTHREAD 0x020d
441 #define S_GTHREAD 0x020e
443 #define S_PROCREF 0x0400
444 #define S_DATAREF 0x0401
445 #define S_ALIGN 0x0402
446 #define S_LPROCREF 0x0403
448 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
449 #define S_CONSTANT_32 0x1002
450 #define S_UDT_32 0x1003
451 #define S_COBOLUDT_32 0x1004
452 #define S_MANYREG_32 0x1005
454 #define S_BPREL_32 0x1006
455 #define S_LDATA_32 0x1007
456 #define S_GDATA_32 0x1008
457 #define S_PUB_32 0x1009
458 #define S_LPROC_32 0x100a
459 #define S_GPROC_32 0x100b
460 #define S_VFTTABLE_32 0x100c
461 #define S_REGREL_32 0x100d
462 #define S_LTHREAD_32 0x100e
463 #define S_GTHREAD_32 0x100f
467 * This covers the basic datatypes that VC++ seems to be using these days.
468 * 32 bit mode only. There are additional numbers for the pointers in 16
469 * bit mode. There are many other types listed in the documents, but these
470 * are apparently not used by the compiler, or represent pointer types
473 #define T_NOTYPE 0x0000 /* Notype */
474 #define T_ABS 0x0001 /* Abs */
475 #define T_VOID 0x0003 /* Void */
476 #define T_CHAR 0x0010 /* signed char */
477 #define T_SHORT 0x0011 /* short */
478 #define T_LONG 0x0012 /* long */
479 #define T_QUAD 0x0013 /* long long */
480 #define T_UCHAR 0x0020 /* unsigned char */
481 #define T_USHORT 0x0021 /* unsigned short */
482 #define T_ULONG 0x0022 /* unsigned long */
483 #define T_UQUAD 0x0023 /* unsigned long long */
484 #define T_REAL32 0x0040 /* float */
485 #define T_REAL64 0x0041 /* double */
486 #define T_RCHAR 0x0070 /* real char */
487 #define T_WCHAR 0x0071 /* wide char */
488 #define T_INT4 0x0074 /* int */
489 #define T_UINT4 0x0075 /* unsigned int */
491 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
492 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
493 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
494 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
495 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
496 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
497 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
498 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
499 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
500 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
501 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
502 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
503 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
504 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
505 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
507 #define LF_MODIFIER 0x0001
508 #define LF_POINTER 0x0002
509 #define LF_ARRAY 0x0003
510 #define LF_CLASS 0x0004
511 #define LF_STRUCTURE 0x0005
512 #define LF_UNION 0x0006
513 #define LF_ENUM 0x0007
514 #define LF_PROCEDURE 0x0008
515 #define LF_MFUNCTION 0x0009
516 #define LF_VTSHAPE 0x000a
517 #define LF_COBOL0 0x000b
518 #define LF_COBOL1 0x000c
519 #define LF_BARRAY 0x000d
520 #define LF_LABEL 0x000e
521 #define LF_NULL 0x000f
522 #define LF_NOTTRAN 0x0010
523 #define LF_DIMARRAY 0x0011
524 #define LF_VFTPATH 0x0012
525 #define LF_PRECOMP 0x0013
526 #define LF_ENDPRECOMP 0x0014
527 #define LF_OEM 0x0015
528 #define LF_TYPESERVER 0x0016
530 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
531 #define LF_POINTER_32 0x1002
532 #define LF_ARRAY_32 0x1003
533 #define LF_CLASS_32 0x1004
534 #define LF_STRUCTURE_32 0x1005
535 #define LF_UNION_32 0x1006
536 #define LF_ENUM_32 0x1007
537 #define LF_PROCEDURE_32 0x1008
538 #define LF_MFUNCTION_32 0x1009
539 #define LF_COBOL0_32 0x100a
540 #define LF_BARRAY_32 0x100b
541 #define LF_DIMARRAY_32 0x100c
542 #define LF_VFTPATH_32 0x100d
543 #define LF_PRECOMP_32 0x100e
544 #define LF_OEM_32 0x100f
546 #define LF_SKIP 0x0200
547 #define LF_ARGLIST 0x0201
548 #define LF_DEFARG 0x0202
549 #define LF_LIST 0x0203
550 #define LF_FIELDLIST 0x0204
551 #define LF_DERIVED 0x0205
552 #define LF_BITFIELD 0x0206
553 #define LF_METHODLIST 0x0207
554 #define LF_DIMCONU 0x0208
555 #define LF_DIMCONLU 0x0209
556 #define LF_DIMVARU 0x020a
557 #define LF_DIMVARLU 0x020b
558 #define LF_REFSYM 0x020c
560 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
561 #define LF_ARGLIST_32 0x1201
562 #define LF_DEFARG_32 0x1202
563 #define LF_FIELDLIST_32 0x1203
564 #define LF_DERIVED_32 0x1204
565 #define LF_BITFIELD_32 0x1205
566 #define LF_METHODLIST_32 0x1206
567 #define LF_DIMCONU_32 0x1207
568 #define LF_DIMCONLU_32 0x1208
569 #define LF_DIMVARU_32 0x1209
570 #define LF_DIMVARLU_32 0x120a
572 #define LF_BCLASS 0x0400
573 #define LF_VBCLASS 0x0401
574 #define LF_IVBCLASS 0x0402
575 #define LF_ENUMERATE 0x0403
576 #define LF_FRIENDFCN 0x0404
577 #define LF_INDEX 0x0405
578 #define LF_MEMBER 0x0406
579 #define LF_STMEMBER 0x0407
580 #define LF_METHOD 0x0408
581 #define LF_NESTTYPE 0x0409
582 #define LF_VFUNCTAB 0x040a
583 #define LF_FRIENDCLS 0x040b
584 #define LF_ONEMETHOD 0x040c
585 #define LF_VFUNCOFF 0x040d
586 #define LF_NESTTYPEEX 0x040e
587 #define LF_MEMBERMODIFY 0x040f
589 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
590 #define LF_VBCLASS_32 0x1401
591 #define LF_IVBCLASS_32 0x1402
592 #define LF_FRIENDFCN_32 0x1403
593 #define LF_INDEX_32 0x1404
594 #define LF_MEMBER_32 0x1405
595 #define LF_STMEMBER_32 0x1406
596 #define LF_METHOD_32 0x1407
597 #define LF_NESTTYPE_32 0x1408
598 #define LF_VFUNCTAB_32 0x1409
599 #define LF_FRIENDCLS_32 0x140a
600 #define LF_ONEMETHOD_32 0x140b
601 #define LF_VFUNCOFF_32 0x140c
602 #define LF_NESTTYPEEX_32 0x140d
607 #define MAX_BUILTIN_TYPES 0x480
608 static struct datatype * cv_basic_types[MAX_BUILTIN_TYPES];
609 static int num_cv_defined_types = 0;
610 static struct datatype **cv_defined_types = NULL;
613 * For the type CODEVIEW debug directory entries, the debug directory
614 * points to a structure like this. The cv_name field is the name
615 * of an external .PDB file.
620 unsigned int cv_timestamp;
626 unsigned int DataType;
634 * This is the header that the COFF variety of debug header points to.
638 unsigned int SymbolOffset;
639 unsigned int N_Linenum;
640 unsigned int LinenumberOffset;
641 unsigned int Unused[4];
645 unsigned int VirtualAddr;
646 unsigned short int Linenum;
650 unsigned int startaddr;
651 unsigned int endaddr;
655 struct name_hash **entries;
665 unsigned int NotLong;
666 unsigned int StrTaboff;
673 unsigned char NumberOfAuxSymbols;
676 struct CoffAuxSection{
678 unsigned short NumberOfRelocations;
679 unsigned short NumberOfLinenumbers;
680 unsigned int CheckSum;
686 * These two structures are used in the directory within a .DBG file
687 * to locate the individual important bits that we might want to see.
690 short unsigned int dhsize;
691 short unsigned int desize;
693 unsigned int next_offset;
698 short unsigned int subsect_number;
699 short unsigned int module_number;
705 * These are the values of interest that the subsect_number field takes.
707 #define sstAlignSym 0x125
708 #define sstSrcModule 0x127
710 struct codeview_linetab_hdr
717 unsigned short * linetab;
718 unsigned int * offtab;
723 * A simple macro that tells us whether a given COFF symbol is a
726 #define N_TMASK 0x0030
727 #define IMAGE_SYM_DTYPE_FUNCTION 2
729 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
733 * This is what we are looking for in the COFF symbols.
735 #define IMAGE_SYM_CLASS_EXTERNAL 0x2
736 #define IMAGE_SYM_CLASS_STATIC 0x3
737 #define IMAGE_SYM_CLASS_FILE 0x67
740 struct datatype * DEBUG_GetCVType(unsigned int typeno)
742 struct datatype * dt = NULL;
745 * Convert Codeview type numbers into something we can grok internally.
746 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
747 * up are all user defined (structs, etc).
749 if( typeno < 0x1000 )
751 if( typeno < MAX_BUILTIN_TYPES )
753 dt = cv_basic_types[typeno];
758 if( typeno - 0x1000 < num_cv_defined_types )
760 dt = cv_defined_types[typeno - 0x1000];
768 DEBUG_ParseTypeTable(char * table, int len)
772 enum debug_type fieldtype;
776 struct datatype * subtype;
778 union codeview_type * type;
779 union codeview_type * type2;
780 struct datatype * typeptr;
785 while( ptr.c - table < len )
787 type = (union codeview_type *) ptr.c;
789 if( curr_type - 0x1000 >= num_cv_defined_types )
791 num_cv_defined_types += 0x100;
792 cv_defined_types = (struct datatype **) DBG_realloc(cv_defined_types,
793 num_cv_defined_types * sizeof(struct datatype *));
794 memset(cv_defined_types + num_cv_defined_types - 0x100,
796 0x100 * sizeof(struct datatype *));
797 if( cv_defined_types == NULL )
803 switch(type->generic.id)
806 cv_defined_types[curr_type - 0x1000] =
807 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type->pointer.datatype));
810 cv_defined_types[curr_type - 0x1000] =
811 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type->pointer32.datatype));
814 if( type->array.arrlen >= 0x8000 )
817 * This is a numeric leaf, I am too lazy to handle this right
820 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
823 if( type->array.namelen != 0 )
825 memset(symname, 0, sizeof(symname));
826 memcpy(symname, type->array.name, type->array.namelen);
827 typeptr = DEBUG_NewDataType(DT_ARRAY, symname);
831 typeptr = DEBUG_NewDataType(DT_ARRAY, NULL);
833 cv_defined_types[curr_type - 0x1000] = typeptr;
835 subtype = DEBUG_GetCVType(type->array.elemtype);
836 if( (subtype == NULL)
837 || (elem_size = DEBUG_GetObjectSize(subtype)) == 0 )
843 arr_max = type->array.arrlen / DEBUG_GetObjectSize(subtype);
846 DEBUG_SetArrayParams(typeptr, 0, arr_max, subtype);
849 if( type->array32.arrlen >= 0x8000 )
852 * This is a numeric leaf, I am too lazy to handle this right
855 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
858 if( type->array32.namelen != 0 )
860 memset(symname, 0, sizeof(symname));
861 memcpy(symname, type->array32.name, type->array32.namelen);
862 typeptr = DEBUG_NewDataType(DT_ARRAY, symname);
866 typeptr = DEBUG_NewDataType(DT_ARRAY, NULL);
868 cv_defined_types[curr_type - 0x1000] = typeptr;
870 subtype = DEBUG_GetCVType(type->array32.elemtype);
871 if( (subtype == NULL)
872 || (elem_size = DEBUG_GetObjectSize(subtype)) == 0 )
878 arr_max = type->array32.arrlen / DEBUG_GetObjectSize(subtype);
881 DEBUG_SetArrayParams(typeptr, 0, arr_max, subtype);
885 * This is where the basic list of fields is defined for
886 * structures and classes.
888 * First, we need to look ahead and see whether we are building
889 * a fieldlist for an enum or a struct.
892 type2 = (union codeview_type *) ptr2.c;
893 if( type2->member.id == LF_MEMBER )
895 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
896 fieldtype = DT_STRUCT;
898 else if( type2->member.id == LF_ENUMERATE )
900 typeptr = DEBUG_NewDataType(DT_ENUM, NULL);
908 cv_defined_types[curr_type - 0x1000] = typeptr;
909 while( ptr2.c < (ptr.c + ((type->generic.len + 3) & ~3)) )
911 type2 = (union codeview_type *) ptr2.c;
912 if( type2->member.id == LF_MEMBER && fieldtype == DT_STRUCT )
914 memset(symname, 0, sizeof(symname));
915 memcpy(symname, type2->member.name, type2->member.namelen);
917 subtype = DEBUG_GetCVType(type2->member.type);
919 if( subtype != NULL )
921 elem_size = DEBUG_GetObjectSize(subtype);
924 if( type2->member.offset >= 0x8000 )
927 * This is a numeric leaf, I am too lazy to handle this right
930 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
934 DEBUG_AddStructElement(typeptr, symname, subtype,
935 type2->member.offset << 3,
939 else if( type2->member.id == LF_ENUMERATE && fieldtype == DT_ENUM )
941 memset(symname, 0, sizeof(symname));
942 memcpy(symname, type2->enumerate.name, type2->enumerate.namelen);
944 if( type2->enumerate.value >= 0x8000 )
947 * This is a numeric leaf, I am too lazy to handle this right
950 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
954 DEBUG_AddStructElement(typeptr, symname, NULL,
955 type2->enumerate.value, 0);
961 * Something else I have never seen before. Either wrong type of
962 * object in the fieldlist, or some other problem which I wouldn't
963 * really know how to handle until it came up.
965 DEBUG_Printf(DBG_CHN_MESG, "Unexpected entry in fieldlist\n");
970 ptr2.c += ((type2->member.namelen + 9 + 3) & ~3);
973 case LF_FIELDLIST_32:
975 * This is where the basic list of fields is defined for
976 * structures and classes.
978 * First, we need to look ahead and see whether we are building
979 * a fieldlist for an enum or a struct.
982 type2 = (union codeview_type *) ptr2.c;
983 if( type2->member32.id == LF_MEMBER_32 )
985 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
986 fieldtype = DT_STRUCT;
988 else if( type2->member32.id == LF_ENUMERATE )
990 typeptr = DEBUG_NewDataType(DT_ENUM, NULL);
998 cv_defined_types[curr_type - 0x1000] = typeptr;
999 while( ptr2.c < (ptr.c + ((type->generic.len + 3) & ~3)) )
1001 type2 = (union codeview_type *) ptr2.c;
1002 if( type2->member.id == LF_MEMBER_32 && fieldtype == DT_STRUCT )
1004 memset(symname, 0, sizeof(symname));
1005 memcpy(symname, type2->member32.name, type2->member32.namelen);
1007 subtype = DEBUG_GetCVType(type2->member32.type);
1009 if( subtype != NULL )
1011 elem_size = DEBUG_GetObjectSize(subtype);
1014 if( type2->member32.offset >= 0x8000 )
1017 * This is a numeric leaf, I am too lazy to handle this right
1020 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1024 DEBUG_AddStructElement(typeptr, symname, subtype,
1025 type2->member32.offset << 3,
1029 else if( type2->member32.id == LF_ENUMERATE && fieldtype == DT_ENUM )
1031 memset(symname, 0, sizeof(symname));
1032 memcpy(symname, type2->enumerate.name, type2->enumerate.namelen);
1034 if( type2->enumerate.value >= 0x8000 )
1037 * This is a numeric leaf, I am too lazy to handle this right
1040 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1044 DEBUG_AddStructElement(typeptr, symname, NULL,
1045 type2->enumerate.value, 0);
1051 * Something else I have never seen before. Either wrong type of
1052 * object in the fieldlist, or some other problem which I wouldn't
1053 * really know how to handle until it came up.
1055 DEBUG_Printf(DBG_CHN_MESG, "Unexpected entry in fieldlist\n");
1060 ptr2.c += ((type2->member32.namelen + 9 + 3) & ~3);
1065 if( type->structure.structlen >= 0x8000 )
1068 * This is a numeric leaf, I am too lazy to handle this right
1071 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1074 memset(symname, 0, sizeof(symname));
1075 memcpy(symname, type->structure.name, type->structure.namelen);
1076 if( strcmp(symname, "__unnamed") == 0 )
1078 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
1082 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
1084 cv_defined_types[curr_type - 0x1000] = typeptr;
1087 * Now copy the relevant bits from the fieldlist that we specified.
1089 subtype = DEBUG_GetCVType(type->structure.fieldlist);
1091 if( subtype != NULL )
1093 DEBUG_SetStructSize(typeptr, type->structure.structlen);
1094 DEBUG_CopyFieldlist(typeptr, subtype);
1097 case LF_STRUCTURE_32:
1099 if( type->structure32.structlen >= 0x8000 )
1102 * This is a numeric leaf, I am too lazy to handle this right
1105 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1108 memset(symname, 0, sizeof(symname));
1109 memcpy(symname, type->structure32.name, type->structure32.namelen);
1110 if( strcmp(symname, "__unnamed") == 0 )
1112 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
1116 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
1118 cv_defined_types[curr_type - 0x1000] = typeptr;
1121 * Now copy the relevant bits from the fieldlist that we specified.
1123 subtype = DEBUG_GetCVType(type->structure32.fieldlist);
1125 if( subtype != NULL )
1127 DEBUG_SetStructSize(typeptr, type->structure32.structlen);
1128 DEBUG_CopyFieldlist(typeptr, subtype);
1132 if( type->t_union.un_len >= 0x8000 )
1135 * This is a numeric leaf, I am too lazy to handle this right
1138 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1141 memset(symname, 0, sizeof(symname));
1142 memcpy(symname, type->t_union.name, type->t_union.namelen);
1144 if( strcmp(symname, "__unnamed") == 0 )
1146 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
1150 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
1153 cv_defined_types[curr_type - 0x1000] = typeptr;
1156 * Now copy the relevant bits from the fieldlist that we specified.
1158 subtype = DEBUG_GetCVType(type->t_union.field);
1160 if( subtype != NULL )
1162 DEBUG_SetStructSize(typeptr, type->t_union.un_len);
1163 DEBUG_CopyFieldlist(typeptr, subtype);
1167 if( type->t_union32.un_len >= 0x8000 )
1170 * This is a numeric leaf, I am too lazy to handle this right
1173 DEBUG_Printf(DBG_CHN_MESG, "Ignoring large numberic leaf.\n");
1176 memset(symname, 0, sizeof(symname));
1177 memcpy(symname, type->t_union32.name, type->t_union32.namelen);
1179 if( strcmp(symname, "__unnamed") == 0 )
1181 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
1185 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
1188 cv_defined_types[curr_type - 0x1000] = typeptr;
1191 * Now copy the relevant bits from the fieldlist that we specified.
1193 subtype = DEBUG_GetCVType(type->t_union32.field);
1195 if( subtype != NULL )
1197 DEBUG_SetStructSize(typeptr, type->t_union32.un_len);
1198 DEBUG_CopyFieldlist(typeptr, subtype);
1202 typeptr = DEBUG_NewDataType(DT_BITFIELD, NULL);
1203 cv_defined_types[curr_type - 0x1000] = typeptr;
1204 DEBUG_SetBitfieldParams(typeptr, type->bitfield.bitoff,
1205 type->bitfield.nbits,
1206 DEBUG_GetCVType(type->bitfield.type));
1208 case LF_BITFIELD_32:
1209 typeptr = DEBUG_NewDataType(DT_BITFIELD, NULL);
1210 cv_defined_types[curr_type - 0x1000] = typeptr;
1211 DEBUG_SetBitfieldParams(typeptr, type->bitfield32.bitoff,
1212 type->bitfield32.nbits,
1213 DEBUG_GetCVType(type->bitfield32.type));
1216 memset(symname, 0, sizeof(symname));
1217 memcpy(symname, type->enumeration.name, type->enumeration.namelen);
1218 typeptr = DEBUG_NewDataType(DT_ENUM, symname);
1219 cv_defined_types[curr_type - 0x1000] = typeptr;
1222 * Now copy the relevant bits from the fieldlist that we specified.
1224 subtype = DEBUG_GetCVType(type->enumeration.field);
1226 if( subtype != NULL )
1228 DEBUG_CopyFieldlist(typeptr, subtype);
1232 memset(symname, 0, sizeof(symname));
1233 memcpy(symname, type->enumeration32.name, type->enumeration32.namelen);
1234 typeptr = DEBUG_NewDataType(DT_ENUM, symname);
1235 cv_defined_types[curr_type - 0x1000] = typeptr;
1238 * Now copy the relevant bits from the fieldlist that we specified.
1240 subtype = DEBUG_GetCVType(type->enumeration32.field);
1242 if( subtype != NULL )
1244 DEBUG_CopyFieldlist(typeptr, subtype);
1251 ptr.c += (type->generic.len + 3) & ~3;
1258 DEBUG_InitCVDataTypes(void)
1261 * These are the common builtin types that are used by VC++.
1263 cv_basic_types[T_NOTYPE] = NULL;
1264 cv_basic_types[T_ABS] = NULL;
1265 cv_basic_types[T_VOID] = DEBUG_NewDataType(DT_BASIC, "void");
1266 cv_basic_types[T_CHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1267 cv_basic_types[T_SHORT] = DEBUG_NewDataType(DT_BASIC, "short int");
1268 cv_basic_types[T_LONG] = DEBUG_NewDataType(DT_BASIC, "long int");
1269 cv_basic_types[T_QUAD] = DEBUG_NewDataType(DT_BASIC, "long long int");
1270 cv_basic_types[T_UCHAR] = DEBUG_NewDataType(DT_BASIC, "unsigned char");
1271 cv_basic_types[T_USHORT] = DEBUG_NewDataType(DT_BASIC, "short unsigned int");
1272 cv_basic_types[T_ULONG] = DEBUG_NewDataType(DT_BASIC, "long unsigned int");
1273 cv_basic_types[T_UQUAD] = DEBUG_NewDataType(DT_BASIC, "long long unsigned int");
1274 cv_basic_types[T_REAL32] = DEBUG_NewDataType(DT_BASIC, "float");
1275 cv_basic_types[T_REAL64] = DEBUG_NewDataType(DT_BASIC, "double");
1276 cv_basic_types[T_RCHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1277 cv_basic_types[T_WCHAR] = DEBUG_NewDataType(DT_BASIC, "short");
1278 cv_basic_types[T_INT4] = DEBUG_NewDataType(DT_BASIC, "int");
1279 cv_basic_types[T_UINT4] = DEBUG_NewDataType(DT_BASIC, "unsigned int");
1281 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
1282 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
1283 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
1284 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
1285 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
1286 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
1287 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
1288 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
1289 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
1290 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
1291 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
1292 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
1293 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
1294 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
1295 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
1299 * In this function, we keep track of deferred debugging information
1300 * that we may need later if we were to need to use the internal debugger.
1301 * We don't fully process it here for performance reasons.
1304 DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth, unsigned long nth_ofs)
1306 int has_codeview = FALSE;
1308 IMAGE_DEBUG_DIRECTORY dbg;
1309 u_long v_addr, size, orig_size;
1310 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1312 orig_size = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
1314 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1315 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1317 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *) module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1321 case IMAGE_DEBUG_TYPE_CODEVIEW:
1322 case IMAGE_DEBUG_TYPE_MISC:
1323 has_codeview = TRUE;
1326 v_addr += sizeof(dbg);
1329 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1330 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1332 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1336 case IMAGE_DEBUG_TYPE_COFF:
1338 * If we have both codeview and COFF debug info, ignore the
1339 * coff debug info as it would just confuse us, and it is
1342 * FIXME - this is broken - if we cannot find the PDB file, then
1343 * we end up with no debugging info at all. In this case, we
1344 * should use the COFF info as a backup.
1350 case IMAGE_DEBUG_TYPE_CODEVIEW:
1351 case IMAGE_DEBUG_TYPE_MISC:
1353 * This is usually an indirection to a .DBG file.
1354 * This is similar to (but a slightly older format) from the
1357 * First check to see if the image was 'stripped'. If so, it
1358 * means that this entry points to a .DBG file. Otherwise,
1359 * it just points to itself, and we can ignore this.
1362 if( (dbg.Type != IMAGE_DEBUG_TYPE_MISC) ||
1363 (nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0 )
1366 * Read the important bits. What we do after this depends
1367 * upon the type, but this is always enough so we are able
1368 * to proceed if we know what we need to do next.
1370 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1371 * the DataDirectory array's content. One its entry contains the *beloved*
1372 * debug information. (Note the DataDirectory is mapped, not its content)
1377 DEBUG_Printf(DBG_CHN_TRACE, "PE debugging info at %ld<%ld>\n", dbg.PointerToRawData, dbg.SizeOfData);
1378 dbg_info = DEBUG_MapDebugInfoFile(NULL, dbg.PointerToRawData, dbg.SizeOfData,
1381 if (dbg_info != NULL &&
1382 (module->extra_info = DBG_alloc(sizeof(MSC_DBG_INFO))) != NULL) {
1383 MSC_INFO(module)->dbg_info = dbg_info;
1384 MSC_INFO(module)->dbg_size = dbg.SizeOfData;
1385 MSC_INFO(module)->dbgdir = dbg;
1386 MSC_INFO(module)->sect_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1387 nth->FileHeader.SizeOfOptionalHeader;
1388 MSC_INFO(module)->nsect = nth->FileHeader.NumberOfSections;
1389 DEBUG_ProcessMSCDebugInfo(module);
1390 DBG_free(MSC_INFO(module));
1391 MSC_INFO(module) = NULL;
1393 DEBUG_UnmapDebugInfoFile(0, hMap, dbg_info);
1400 v_addr += sizeof(dbg);
1402 DEBUG_CurrProcess->next_index++;
1408 /* look for stabs information in PE header (it's how mingw compiler provides its
1409 * debugging information), and also wine PE <-> ELF linking thru .wsolnk sections
1411 int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth,
1412 unsigned long nth_ofs)
1414 IMAGE_SECTION_HEADER pe_seg;
1415 unsigned long pe_seg_ofs;
1416 int i, stabsize = 0, stabstrsize = 0, xcnlnksize = 0;
1417 unsigned int stabs = 0, stabstr = 0, xcnlnk = 0;
1418 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1420 pe_seg_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1421 nth->FileHeader.SizeOfOptionalHeader;
1423 for (i = 0; i < nth->FileHeader.NumberOfSections; i++, pe_seg_ofs += sizeof(pe_seg)) {
1424 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + pe_seg_ofs),
1425 &pe_seg, sizeof(pe_seg)))
1428 if (!strcasecmp(pe_seg.Name, ".stab")) {
1429 stabs = pe_seg.VirtualAddress;
1430 stabsize = pe_seg.SizeOfRawData;
1431 } else if (!strncasecmp(pe_seg.Name, ".stabstr", 8)) {
1432 stabstr = pe_seg.VirtualAddress;
1433 stabstrsize = pe_seg.SizeOfRawData;
1434 } else if (!strncasecmp(pe_seg.Name, ".xcnlnk", 7)) {
1435 xcnlnk = pe_seg.VirtualAddress;
1436 xcnlnksize = pe_seg.SizeOfRawData;
1440 if (stabstrsize && stabsize) {
1441 char* s1 = DBG_alloc(stabsize+stabstrsize);
1444 if (DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabs, s1, stabsize) &&
1445 DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabstr,
1446 s1 + stabsize, stabstrsize)) {
1447 DEBUG_ParseStabs(s1, 0, 0, stabsize, stabsize, stabstrsize);
1449 DEBUG_Printf(DBG_CHN_MESG, "couldn't read data block\n");
1453 DEBUG_Printf(DBG_CHN_MESG, "couldn't alloc %d bytes\n",
1454 stabsize + stabstrsize);
1461 if (DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + xcnlnk, &addr,
1463 DEBUG_READ_MEM_VERBOSE((char*)addr, bufstr, sizeof(bufstr))) {
1464 bufstr[sizeof(bufstr) - 1] = 0;
1465 DEBUG_Printf(DBG_CHN_TRACE, "Got xcnlnk: argv0 '%s'\n", bufstr);
1466 DEBUG_ReadExecutableDbgInfo(bufstr);
1473 * Process COFF debugging information embedded in a Win32 application.
1478 DEBUG_ProcessCoff(DBG_MODULE* module)
1480 struct CoffAuxSection * aux;
1481 struct CoffDebug * coff;
1482 struct CoffFiles * coff_files = NULL;
1483 struct CoffLinenum * coff_linetab;
1485 struct CoffSymbol * coff_sym;
1486 struct CoffSymbol * coff_symbol;
1487 struct CoffFiles * curr_file = NULL;
1491 struct CoffLinenum * linepnt;
1496 DBG_VALUE new_value;
1498 int nfiles_alloc = 0;
1499 struct CoffFiles orig_file;
1501 char * this_file = NULL;
1503 coff = (struct CoffDebug *) MSC_INFO(module)->dbg_info;
1505 coff_symbol = (struct CoffSymbol *) ((unsigned int) coff + coff->SymbolOffset);
1506 coff_linetab = (struct CoffLinenum *) ((unsigned int) coff + coff->LinenumberOffset);
1507 coff_strtab = (char *) ((unsigned int) coff_symbol + 18*coff->N_Sym);
1511 new_value.cookie = DV_TARGET;
1512 new_value.type = NULL;
1514 for(i=0; i < coff->N_Sym; i++ )
1517 * We do this because some compilers (i.e. gcc) incorrectly
1518 * pad the structure up to a 4 byte boundary. The structure
1519 * is really only 18 bytes long, so we have to manually make sure
1522 * FIXME - there must be a way to have autoconf figure out the
1523 * correct compiler option for this. If it is always gcc, that
1524 * makes life simpler, but I don't want to force this.
1526 coff_sym = (struct CoffSymbol *) ((unsigned int) coff_symbol + 18*i);
1527 naux = coff_sym->NumberOfAuxSymbols;
1529 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
1531 if( nfiles + 1 >= nfiles_alloc )
1534 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1535 nfiles_alloc * sizeof(struct CoffFiles));
1537 curr_file = coff_files + nfiles;
1539 curr_file->startaddr = 0xffffffff;
1540 curr_file->endaddr = 0;
1541 curr_file->filename = ((char *) coff_sym) + 18;
1542 curr_file->linetab_offset = -1;
1543 curr_file->linecnt = 0;
1544 curr_file->entries = NULL;
1545 curr_file->neps = curr_file->neps_alloc = 0;
1546 DEBUG_Printf(DBG_CHN_TRACE,"New file %s\n", curr_file->filename);
1552 * This guy marks the size and location of the text section
1553 * for the current file. We need to keep track of this so
1554 * we can figure out what file the different global functions
1557 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1559 && (coff_sym->Type == 0)
1560 && (coff_sym->SectionNumber == 1) )
1562 aux = (struct CoffAuxSection *) ((unsigned int) coff_sym + 18);
1564 if( curr_file->linetab_offset != -1 )
1567 DEBUG_Printf(DBG_CHN_TRACE, "Duplicating sect from %s: %x %x %x %d %d\n",
1568 curr_file->filename,
1570 aux->NumberOfRelocations,
1571 aux->NumberOfLinenumbers,
1574 DEBUG_Printf(DBG_CHN_TRACE, "More sect %d %x %d %d %d\n",
1575 coff_sym->SectionNumber,
1578 coff_sym->StorageClass,
1579 coff_sym->NumberOfAuxSymbols);
1583 * Save this so we can copy bits from it.
1585 orig_file = *curr_file;
1588 * Duplicate the file entry. We have no way to describe
1589 * multiple text sections in our current way of handling things.
1591 if( nfiles + 1 >= nfiles_alloc )
1594 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1595 nfiles_alloc * sizeof(struct CoffFiles));
1597 curr_file = coff_files + nfiles;
1599 curr_file->startaddr = 0xffffffff;
1600 curr_file->endaddr = 0;
1601 curr_file->filename = orig_file.filename;
1602 curr_file->linetab_offset = -1;
1603 curr_file->linecnt = 0;
1604 curr_file->entries = NULL;
1605 curr_file->neps = curr_file->neps_alloc = 0;
1610 DEBUG_Printf(DBG_CHN_TRACE, "New text sect from %s: %x %x %x %d %d\n",
1611 curr_file->filename,
1613 aux->NumberOfRelocations,
1614 aux->NumberOfLinenumbers,
1620 if( curr_file->startaddr > coff_sym->Value )
1622 curr_file->startaddr = coff_sym->Value;
1625 if( curr_file->startaddr > coff_sym->Value )
1627 curr_file->startaddr = coff_sym->Value;
1630 if( curr_file->endaddr < coff_sym->Value + aux->Length )
1632 curr_file->endaddr = coff_sym->Value + aux->Length;
1635 curr_file->linetab_offset = linetab_indx;
1636 curr_file->linecnt = aux->NumberOfLinenumbers;
1637 linetab_indx += aux->NumberOfLinenumbers;
1642 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1644 && (coff_sym->SectionNumber == 1) )
1647 * This is a normal static function when naux == 0.
1648 * Just register it. The current file is the correct
1649 * one in this instance.
1651 if( coff_sym->N.Name.NotLong )
1653 memcpy(namebuff, coff_sym->N.ShortName, 8);
1655 nampnt = &namebuff[0];
1659 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1662 if( nampnt[0] == '_' )
1667 new_value.addr.seg = 0;
1668 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1670 if( curr_file->neps + 1 >= curr_file->neps_alloc )
1672 curr_file->neps_alloc += 10;
1673 curr_file->entries = (struct name_hash **)
1674 DBG_realloc(curr_file->entries,
1675 curr_file->neps_alloc * sizeof(struct name_hash *));
1678 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding static symbol %s\n", nampnt);
1680 curr_file->entries[curr_file->neps++] =
1681 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
1686 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1687 && ISFCN(coff_sym->Type)
1688 && (coff_sym->SectionNumber > 0) )
1690 if( coff_sym->N.Name.NotLong )
1692 memcpy(namebuff, coff_sym->N.ShortName, 8);
1694 nampnt = &namebuff[0];
1698 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1702 if( nampnt[0] == '_' )
1707 new_value.addr.seg = 0;
1708 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1711 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
1713 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global symbol %s\n", nampnt);
1717 * Now we need to figure out which file this guy belongs to.
1720 for(j=0; j < nfiles; j++)
1722 if( coff_files[j].startaddr <= coff_sym->Value
1723 && coff_files[j].endaddr > coff_sym->Value )
1725 this_file = coff_files[j].filename;
1729 if( coff_files[j].neps + 1 >= coff_files[j].neps_alloc )
1731 coff_files[j].neps_alloc += 10;
1732 coff_files[j].entries = (struct name_hash **)
1733 DBG_realloc(coff_files[j].entries,
1734 coff_files[j].neps_alloc * sizeof(struct name_hash *));
1736 coff_files[j].entries[coff_files[j].neps++] =
1737 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
1742 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1743 && (coff_sym->SectionNumber > 0) )
1746 * Similar to above, but for the case of data symbols.
1747 * These aren't treated as entrypoints.
1749 if( coff_sym->N.Name.NotLong )
1751 memcpy(namebuff, coff_sym->N.ShortName, 8);
1753 nampnt = &namebuff[0];
1757 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1761 if( nampnt[0] == '_' )
1766 new_value.addr.seg = 0;
1767 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1770 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
1772 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global data symbol %s\n", nampnt);
1776 * Now we need to figure out which file this guy belongs to.
1778 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 );
1783 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1787 * Ignore these. They don't have anything to do with
1795 DEBUG_Printf(DBG_CHN_TRACE,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
1796 coff_sym->SectionNumber, naux);
1800 * For now, skip past the aux entries.
1807 * OK, we now should have a list of files, and we should have a list
1808 * of entrypoints. We need to sort the entrypoints so that we are
1809 * able to tie the line numbers with the given functions within the
1812 if( coff_files != NULL )
1814 for(j=0; j < nfiles; j++)
1816 if( coff_files[j].entries != NULL )
1818 qsort(coff_files[j].entries, coff_files[j].neps,
1819 sizeof(struct name_hash *), DEBUG_cmp_sym);
1824 * Now pick apart the line number tables, and attach the entries
1825 * to the given functions.
1827 for(j=0; j < nfiles; j++)
1830 if( coff_files[j].neps != 0 )
1831 for(k=0; k < coff_files[j].linecnt; k++)
1834 * Another monstrosity caused by the fact that we are using
1835 * a 6 byte structure, and gcc wants to pad structures to 4 byte
1836 * boundaries. Otherwise we could just index into an array.
1838 linepnt = (struct CoffLinenum *)
1839 ((unsigned int) coff_linetab +
1840 6*(coff_files[j].linetab_offset + k));
1842 * If we have spilled onto the next entrypoint, then
1843 * bump the counter..
1847 if (i+1 >= coff_files[j].neps) break;
1848 DEBUG_GetSymbolAddr(coff_files[j].entries[i+1], &new_value.addr);
1849 if( (((unsigned int)module->load_addr +
1850 linepnt->VirtualAddr) >= new_value.addr.off) )
1857 * Add the line number. This is always relative to the
1858 * start of the function, so we need to subtract that offset
1861 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_value.addr);
1862 DEBUG_AddLineNumber(coff_files[j].entries[i],
1864 (unsigned int) module->load_addr
1865 + linepnt->VirtualAddr
1866 - new_value.addr.off);
1873 if( coff_files != NULL )
1875 for(j=0; j < nfiles; j++)
1877 if( coff_files[j].entries != NULL )
1879 DBG_free(coff_files[j].entries);
1882 DBG_free(coff_files);
1890 * Process a codeview line number table. Digestify the thing so that
1891 * we can easily reference the thing when we process the rest of
1894 static struct codeview_linetab_hdr *
1895 DEBUG_SnarfLinetab(char * linetab,
1899 char filename[PATH_MAX];
1900 unsigned int * filetab;
1904 struct codeview_linetab_hdr * lt_hdr;
1905 unsigned int * lt_ptr;
1909 union any_size pnt2;
1910 struct startend * start;
1914 * Now get the important bits.
1920 filetab = (unsigned int *) pnt.c;
1923 * Now count up the number of segments in the file.
1926 for(i=0; i<nfile; i++)
1928 pnt2.c = linetab + filetab[i];
1933 * Next allocate the header we will be returning.
1934 * There is one header for each segment, so that we can reach in
1935 * and pull bits as required.
1937 lt_hdr = (struct codeview_linetab_hdr *)
1938 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
1939 if( lt_hdr == NULL )
1944 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
1947 * Now fill the header we will be returning, one for each segment.
1948 * Note that this will basically just contain pointers into the existing
1949 * line table, and we do not actually copy any additional information
1950 * or allocate any additional memory.
1954 for(i=0; i<nfile; i++)
1957 * Get the pointer into the segment information.
1959 pnt2.c = linetab + filetab[i];
1960 file_segcount = *pnt2.s;
1963 lt_ptr = (unsigned int *) pnt2.c;
1964 start = (struct startend *) (lt_ptr + file_segcount);
1967 * Now snarf the filename for all of the segments for this file.
1969 fn = (unsigned char *) (start + file_segcount);
1970 memset(filename, 0, sizeof(filename));
1971 memcpy(filename, fn + 1, *fn);
1972 fn = DBG_strdup(filename);
1974 for(k = 0; k < file_segcount; k++, this_seg++)
1976 pnt2.c = linetab + lt_ptr[k];
1977 lt_hdr[this_seg].start = start[k].start;
1978 lt_hdr[this_seg].end = start[k].end;
1979 lt_hdr[this_seg].sourcefile = fn;
1980 lt_hdr[this_seg].segno = *pnt2.s++;
1981 lt_hdr[this_seg].nline = *pnt2.s++;
1982 lt_hdr[this_seg].offtab = pnt2.ui;
1983 lt_hdr[this_seg].linetab = (unsigned short *)
1984 (pnt2.ui + lt_hdr[this_seg].nline);
1995 DEBUG_SnarfCodeView( DBG_MODULE * module,
1998 struct codeview_linetab_hdr * linetab)
2000 struct name_hash * curr_func = NULL;
2001 struct wine_locals * curr_sym = NULL;
2005 DBG_VALUE new_value;
2008 IMAGE_SECTION_HEADER * sectp;
2009 union codeview_symbol * sym;
2010 char symname[PATH_MAX];
2011 struct name_hash * thunk_sym = NULL;
2014 nsect = MSC_INFO(module)->nsect;
2015 sectp = DBG_alloc(sizeof(*sectp) * nsect);
2017 !DEBUG_READ_MEM_VERBOSE((char *)module->load_addr + MSC_INFO(module)->sect_ofs,
2018 sectp, sizeof(*sectp) * nsect))
2022 * Loop over the different types of records and whenever we
2023 * find something we are interested in, record it and move on.
2025 while( ptr.c - cv_data < size )
2027 sym = (union codeview_symbol *) ptr.c;
2029 if( sym->generic.len - sizeof(int) == (ptr.c - cv_data) )
2032 * This happens when we have indirect symbols that VC++ 4.2
2033 * sometimes uses when there isn't a line number table.
2034 * We ignore it - we will process and enter all of the
2035 * symbols in the global symbol table anyways, so there
2036 * isn't much point in keeping track of all of this crap.
2041 memset(symname, 0, sizeof(symname));
2042 switch(sym->generic.id)
2048 * First, a couple of sanity checks.
2050 if( sym->data.namelen == 0 )
2055 if( sym->data.seg == 0 || sym->data.seg > nsect )
2061 * Global and local data symbols. We don't associate these
2062 * with any given source file.
2065 memcpy(symname, sym->data.name, sym->data.namelen);
2066 new_value.addr.seg = 0;
2067 new_value.type = DEBUG_GetCVType(sym->data.symtype);
2068 new_value.addr.off = (unsigned int) module->load_addr +
2069 sectp[sym->data.seg - 1].VirtualAddress +
2071 new_value.cookie = DV_TARGET;
2072 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2078 * First, a couple of sanity checks.
2080 if( sym->data32.namelen == 0 )
2085 if( sym->data32.seg == 0 || sym->data32.seg > nsect )
2091 * Global and local data symbols. We don't associate these
2092 * with any given source file.
2095 memcpy(symname, sym->data32.name, sym->data32.namelen);
2096 new_value.addr.seg = 0;
2097 new_value.type = DEBUG_GetCVType(sym->data32.symtype);
2098 new_value.addr.off = (unsigned int) module->load_addr +
2099 sectp[sym->data32.seg - 1].VirtualAddress +
2101 new_value.cookie = DV_TARGET;
2102 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2106 * Sort of like a global function, but it just points
2107 * to a thunk, which is a stupid name for what amounts to
2108 * a PLT slot in the normal jargon that everyone else uses.
2110 memcpy(symname, sym->thunk.name, sym->thunk.namelen);
2111 new_value.addr.seg = 0;
2112 new_value.type = NULL;
2113 new_value.addr.off = (unsigned int) module->load_addr +
2114 sectp[sym->thunk.segment - 1].VirtualAddress +
2116 new_value.cookie = DV_TARGET;
2117 thunk_sym = DEBUG_AddSymbol( symname, &new_value, NULL,
2118 SYM_WIN32 | SYM_FUNC);
2119 DEBUG_SetSymbolSize(thunk_sym, sym->thunk.thunk_len);
2124 * Global and static functions.
2126 memcpy(symname, sym->proc.name, sym->proc.namelen);
2127 new_value.addr.seg = 0;
2128 new_value.type = DEBUG_GetCVType(sym->proc.proctype);
2129 new_value.addr.off = (unsigned int) module->load_addr +
2130 sectp[sym->proc.segment - 1].VirtualAddress +
2132 new_value.cookie = DV_TARGET;
2134 * See if we can find a segment that this goes with. If so,
2135 * it means that we also may have line number information
2136 * for this function.
2138 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2140 if( ((unsigned int) module->load_addr
2141 + sectp[linetab[i].segno - 1].VirtualAddress
2142 + linetab[i].start <= new_value.addr.off)
2143 && ((unsigned int) module->load_addr
2144 + sectp[linetab[i].segno - 1].VirtualAddress
2145 + linetab[i].end > new_value.addr.off) )
2151 DEBUG_Normalize(curr_func);
2152 if( !linetab || linetab[i].linetab == NULL )
2154 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2155 SYM_WIN32 | SYM_FUNC);
2160 * First, create the entry. Then dig through the linetab
2161 * and add whatever line numbers are appropriate for this
2164 curr_func = DEBUG_AddSymbol( symname, &new_value,
2165 linetab[i].sourcefile,
2166 SYM_WIN32 | SYM_FUNC);
2167 for(j=0; j < linetab[i].nline; j++)
2169 if( linetab[i].offtab[j] >= sym->proc.offset
2170 && linetab[i].offtab[j] < sym->proc.offset
2171 + sym->proc.proc_len )
2173 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2174 linetab[i].offtab[j] - sym->proc.offset);
2181 * Add information about where we should set breakpoints
2184 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
2185 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
2190 * Global and static functions.
2192 memcpy(symname, sym->proc32.name, sym->proc32.namelen);
2193 new_value.addr.seg = 0;
2194 new_value.type = DEBUG_GetCVType(sym->proc32.proctype);
2195 new_value.addr.off = (unsigned int) module->load_addr +
2196 sectp[sym->proc32.segment - 1].VirtualAddress +
2198 new_value.cookie = DV_TARGET;
2200 * See if we can find a segment that this goes with. If so,
2201 * it means that we also may have line number information
2202 * for this function.
2204 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2206 if( ((unsigned int) module->load_addr
2207 + sectp[linetab[i].segno - 1].VirtualAddress
2208 + linetab[i].start <= new_value.addr.off)
2209 && ((unsigned int) module->load_addr
2210 + sectp[linetab[i].segno - 1].VirtualAddress
2211 + linetab[i].end > new_value.addr.off) )
2217 DEBUG_Normalize(curr_func);
2218 if( !linetab || linetab[i].linetab == NULL )
2220 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2221 SYM_WIN32 | SYM_FUNC);
2226 * First, create the entry. Then dig through the linetab
2227 * and add whatever line numbers are appropriate for this
2230 curr_func = DEBUG_AddSymbol( symname, &new_value,
2231 linetab[i].sourcefile,
2232 SYM_WIN32 | SYM_FUNC);
2233 for(j=0; j < linetab[i].nline; j++)
2235 if( linetab[i].offtab[j] >= sym->proc32.offset
2236 && linetab[i].offtab[j] < sym->proc32.offset
2237 + sym->proc32.proc_len )
2239 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2240 linetab[i].offtab[j] - sym->proc32.offset);
2247 * Add information about where we should set breakpoints
2250 DEBUG_SetSymbolBPOff(curr_func, sym->proc32.debug_start);
2251 DEBUG_SetSymbolSize(curr_func, sym->proc32.proc_len);
2255 * Function parameters and stack variables.
2257 memcpy(symname, sym->stack.name, sym->stack.namelen);
2258 curr_sym = DEBUG_AddLocal(curr_func,
2264 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
2269 * Function parameters and stack variables.
2271 memcpy(symname, sym->stack32.name, sym->stack32.namelen);
2272 curr_sym = DEBUG_AddLocal(curr_func,
2274 sym->stack32.offset,
2278 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack32.symtype));
2286 * Adjust pointer to point to next entry, rounding up to a word
2287 * boundary. MS preserving alignment? Stranger things have
2290 if( sym->generic.id == S_PROCREF
2291 || sym->generic.id == S_DATAREF
2292 || sym->generic.id == S_LPROCREF )
2294 len = (sym->generic.len + 3) & ~3;
2295 len += ptr.c[16] + 1;
2296 ptr.c += (len + 3) & ~3;
2300 ptr.c += (sym->generic.len + 3) & ~3;
2304 if( linetab != NULL )
2315 * Process PDB file which contains debug information.
2319 typedef struct _PDB_FILE
2324 } PDB_FILE, *PPDB_FILE;
2326 typedef struct _PDB_HEADER
2334 WORD toc_block[ 1 ];
2336 } PDB_HEADER, *PPDB_HEADER;
2338 typedef struct _PDB_TOC
2343 } PDB_TOC, *PPDB_TOC;
2345 typedef struct _PDB_ROOT
2348 DWORD TimeDateStamp;
2353 } PDB_ROOT, *PPDB_ROOT;
2355 typedef struct _PDB_TYPES_OLD
2364 } PDB_TYPES_OLD, *PPDB_TYPES_OLD;
2366 typedef struct _PDB_TYPES
2379 DWORD search_offset;
2381 DWORD unknown_offset;
2384 } PDB_TYPES, *PPDB_TYPES;
2386 typedef struct _PDB_SYMBOL_RANGE
2392 DWORD characteristics;
2396 } PDB_SYMBOL_RANGE, *PPDB_SYMBOL_RANGE;
2398 typedef struct _PDB_SYMBOL_RANGE_EX
2404 DWORD characteristics;
2410 } PDB_SYMBOL_RANGE_EX, *PPDB_SYMBOL_RANGE_EX;
2412 typedef struct _PDB_SYMBOL_FILE
2415 PDB_SYMBOL_RANGE range;
2425 } PDB_SYMBOL_FILE, *PPDB_SYMBOL_FILE;
2427 typedef struct _PDB_SYMBOL_FILE_EX
2430 PDB_SYMBOL_RANGE_EX range;
2438 DWORD reserved[ 2 ];
2441 } PDB_SYMBOL_FILE_EX, *PPDB_SYMBOL_FILE_EX;
2443 typedef struct _PDB_SYMBOL_SOURCE
2449 } PDB_SYMBOL_SOURCE, *PPDB_SYMBOL_SOURCE;
2451 typedef struct _PDB_SYMBOL_IMPORT
2455 DWORD TimeDateStamp;
2459 } PDB_SYMBOL_IMPORT, *PPDB_SYMBOL_IMPORT;
2461 typedef struct _PDB_SYMBOLS_OLD
2470 DWORD srcmodule_size;
2472 } PDB_SYMBOLS_OLD, *PPDB_SYMBOLS_OLD;
2474 typedef struct _PDB_SYMBOLS
2478 DWORD extended_format;
2485 DWORD srcmodule_size;
2486 DWORD pdbimport_size;
2489 } PDB_SYMBOLS, *PPDB_SYMBOLS;
2493 static void *pdb_read( LPBYTE image, WORD *block_list, int size )
2495 PPDB_HEADER pdb = (PPDB_HEADER)image;
2499 if ( !size ) return NULL;
2501 nBlocks = (size + pdb->blocksize-1) / pdb->blocksize;
2502 buffer = DBG_alloc( nBlocks * pdb->blocksize );
2504 for ( i = 0; i < nBlocks; i++ )
2505 memcpy( buffer + i*pdb->blocksize,
2506 image + block_list[i]*pdb->blocksize, pdb->blocksize );
2511 static void *pdb_read_file( LPBYTE image, PPDB_TOC toc, int fileNr )
2513 PPDB_HEADER pdb = (PPDB_HEADER)image;
2517 if ( !toc || fileNr >= toc->nFiles )
2520 block_list = (WORD *) &toc->file[ toc->nFiles ];
2521 for ( i = 0; i < fileNr; i++ )
2522 block_list += (toc->file[i].size + pdb->blocksize-1) / pdb->blocksize;
2524 return pdb_read( image, block_list, toc->file[fileNr].size );
2527 static void pdb_free( void *buffer )
2532 static void pdb_convert_types_header( PDB_TYPES *types, char *image )
2534 memset( types, 0, sizeof(PDB_TYPES) );
2535 if ( !image ) return;
2537 if ( *(DWORD *)image < 19960000 ) /* FIXME: correct version? */
2539 /* Old version of the types record header */
2540 PDB_TYPES_OLD *old = (PDB_TYPES_OLD *)image;
2541 types->version = old->version;
2542 types->type_offset = sizeof(PDB_TYPES_OLD);
2543 types->type_size = old->type_size;
2544 types->first_index = old->first_index;
2545 types->last_index = old->last_index;
2546 types->file = old->file;
2550 /* New version of the types record header */
2551 *types = *(PDB_TYPES *)image;
2555 static void pdb_convert_symbols_header( PDB_SYMBOLS *symbols,
2556 int *header_size, char *image )
2558 memset( symbols, 0, sizeof(PDB_SYMBOLS) );
2559 if ( !image ) return;
2561 if ( *(DWORD *)image != 0xffffffff )
2563 /* Old version of the symbols record header */
2564 PDB_SYMBOLS_OLD *old = (PDB_SYMBOLS_OLD *)image;
2565 symbols->version = 0;
2566 symbols->extended_format = 0;
2567 symbols->module_size = old->module_size;
2568 symbols->offset_size = old->offset_size;
2569 symbols->hash_size = old->hash_size;
2570 symbols->srcmodule_size = old->srcmodule_size;
2571 symbols->pdbimport_size = 0;
2572 symbols->hash1_file = old->hash1_file;
2573 symbols->hash2_file = old->hash2_file;
2574 symbols->gsym_file = old->gsym_file;
2576 *header_size = sizeof(PDB_SYMBOLS_OLD);
2580 /* New version of the symbols record header */
2581 *symbols = *(PDB_SYMBOLS *)image;
2583 *header_size = sizeof(PDB_SYMBOLS);
2587 static int DEBUG_ProcessPDBFile( DBG_MODULE* module, const char *full_filename )
2591 PDB_HEADER *pdb = NULL;
2592 PDB_TOC *toc = NULL;
2593 PDB_ROOT *root = NULL;
2594 char *types_image = NULL;
2595 char *symbols_image = NULL;
2597 PDB_SYMBOLS symbols;
2598 int header_size = 0;
2599 char *modimage, *file;
2603 * Open and map() .PDB file
2605 if ((image = DEBUG_MapDebugInfoFile(full_filename, 0, 0, &hFile, &hMap)) == NULL) {
2606 DEBUG_Printf( DBG_CHN_ERR, "-Unable to peruse .PDB file %s\n", full_filename );
2611 * Read in TOC and well-known files
2614 pdb = (PPDB_HEADER)image;
2615 toc = pdb_read( image, pdb->toc_block, pdb->toc.size );
2616 root = pdb_read_file( image, toc, 1 );
2617 types_image = pdb_read_file( image, toc, 2 );
2618 symbols_image = pdb_read_file( image, toc, 3 );
2620 pdb_convert_types_header( &types, types_image );
2621 pdb_convert_symbols_header( &symbols, &header_size, symbols_image );
2624 * Check for unknown versions
2627 switch ( root->version )
2629 case 19950623: /* VC 4.0 */
2631 case 19960307: /* VC 5.0 */
2632 case 19970604: /* VC 6.0 */
2635 DEBUG_Printf( DBG_CHN_ERR, "-Unknown root block version %ld\n", root->version );
2638 switch ( types.version )
2640 case 19950410: /* VC 4.0 */
2642 case 19961031: /* VC 5.0 / 6.0 */
2645 DEBUG_Printf( DBG_CHN_ERR, "-Unknown type info version %ld\n", types.version );
2648 switch ( symbols.version )
2650 case 0: /* VC 4.0 */
2651 case 19960307: /* VC 5.0 */
2652 case 19970606: /* VC 6.0 */
2655 DEBUG_Printf( DBG_CHN_ERR, "-Unknown symbol info version %ld\n", symbols.version );
2660 * Check .PDB time stamp
2663 if ( root->TimeDateStamp
2664 != ((struct CodeViewDebug *)MSC_INFO(module)->dbg_info)->cv_timestamp )
2666 DEBUG_Printf(DBG_CHN_ERR, "-Wrong time stamp of .PDB file %s\n", full_filename);
2674 DEBUG_ParseTypeTable( types_image + types.type_offset, types.type_size );
2677 * Read type-server .PDB imports
2680 if ( symbols.pdbimport_size )
2683 DEBUG_Printf(DBG_CHN_ERR, "-Type server .PDB imports ignored!\n" );
2687 * Read global symbol table
2690 modimage = pdb_read_file( image, toc, symbols.gsym_file );
2693 DEBUG_SnarfCodeView( module, modimage,
2694 toc->file[symbols.gsym_file].size, NULL );
2695 pdb_free( modimage );
2699 * Read per-module symbol / linenumber tables
2702 file = symbols_image + header_size;
2703 while ( file - symbols_image < header_size + symbols.module_size )
2705 int file_nr, file_index, symbol_size, lineno_size;
2708 if ( !symbols.extended_format )
2710 PDB_SYMBOL_FILE *sym_file = (PDB_SYMBOL_FILE *) file;
2711 file_nr = sym_file->file;
2712 file_name = sym_file->filename;
2713 file_index = sym_file->range.index;
2714 symbol_size = sym_file->symbol_size;
2715 lineno_size = sym_file->lineno_size;
2719 PDB_SYMBOL_FILE_EX *sym_file = (PDB_SYMBOL_FILE_EX *) file;
2720 file_nr = sym_file->file;
2721 file_name = sym_file->filename;
2722 file_index = sym_file->range.index;
2723 symbol_size = sym_file->symbol_size;
2724 lineno_size = sym_file->lineno_size;
2727 modimage = pdb_read_file( image, toc, file_nr );
2730 struct codeview_linetab_hdr *linetab = NULL;
2733 linetab = DEBUG_SnarfLinetab( modimage + symbol_size, lineno_size );
2736 DEBUG_SnarfCodeView( module, modimage + sizeof(DWORD),
2737 symbol_size - sizeof(DWORD), linetab );
2739 pdb_free( modimage );
2742 file_name += strlen(file_name) + 1;
2743 file = (char *)( (DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3 );
2753 if ( symbols_image ) pdb_free( symbols_image );
2754 if ( types_image ) pdb_free( types_image );
2755 if ( root ) pdb_free( root );
2756 if ( toc ) pdb_free( toc );
2758 DEBUG_UnmapDebugInfoFile(hFile, hMap, image);
2765 * Process DBG file which contains debug information.
2769 DEBUG_ProcessDBGFile(DBG_MODULE* module, const char* filename)
2774 struct CV4_DirHead * codeview_dir;
2775 struct CV4_DirEnt * codeview_dent;
2776 PIMAGE_DEBUG_DIRECTORY dbghdr;
2780 struct codeview_linetab_hdr * linetab;
2782 PIMAGE_SEPARATE_DEBUG_HEADER pdbg = NULL;
2783 IMAGE_SECTION_HEADER * sectp;
2785 if ((addr = DEBUG_MapDebugInfoFile(filename, 0, 0, &hFile, &hMap)) == NULL) {
2786 DEBUG_Printf(DBG_CHN_ERR, "-Unable to peruse .DBG file %s\n", filename);
2790 pdbg = (PIMAGE_SEPARATE_DEBUG_HEADER) addr;
2792 if( pdbg->TimeDateStamp != MSC_INFO(module)->dbgdir.TimeDateStamp )
2794 DEBUG_Printf(DBG_CHN_ERR, "Warning - %s has incorrect internal timestamp\n",
2798 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2799 files but nonetheless this check fails. Anyway, WINDBG (debugger for
2800 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2804 DEBUG_Printf(DBG_CHN_MESG, "Processing symbols from %s...\n", filename);
2806 dbghdr = (PIMAGE_DEBUG_DIRECTORY) ( addr + sizeof(*pdbg)
2807 + pdbg->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
2808 + pdbg->ExportedNamesSize);
2810 sectp = (PIMAGE_SECTION_HEADER) ((char *) pdbg + sizeof(*pdbg));
2811 nsect = pdbg->NumberOfSections;
2813 for( i=0; i < pdbg->DebugDirectorySize / sizeof(*pdbg); i++, dbghdr++ )
2815 switch(dbghdr->Type)
2817 case IMAGE_DEBUG_TYPE_COFF:
2819 * Dummy up a deferred debug header to handle the
2820 * COFF stuff embedded within the DBG file.
2822 memset((char *) &module2, 0, sizeof(module2));
2823 MSC_INFO(&module2)->dbg_info = (addr + dbghdr->PointerToRawData);
2824 MSC_INFO(&module2)->dbg_size = dbghdr->SizeOfData;
2825 module2.load_addr = module->load_addr;
2827 DEBUG_ProcessCoff(&module2);
2829 case IMAGE_DEBUG_TYPE_CODEVIEW:
2831 * This is the older format by which codeview stuff is
2832 * stored, known as the 'NB09' format. Newer executables
2833 * and dlls created by VC++ use PDB files instead, which
2834 * have lots of internal similarities, but the overall
2835 * format and structure is quite different.
2837 codeview = (addr + dbghdr->PointerToRawData);
2840 * The first thing in the codeview section should be
2841 * an 'NB09' identifier. As a sanity check, make sure
2844 if( *((unsigned int*) codeview) != 0x3930424e )
2850 * Next we need to find the directory. This is easy too.
2852 codeview_dir = (struct CV4_DirHead *)
2853 (codeview + ((unsigned int*) codeview)[1]);
2856 * Some more sanity checks. Make sure that everything
2857 * is as we expect it.
2859 if( codeview_dir->next_offset != 0
2860 || codeview_dir->dhsize != sizeof(*codeview_dir)
2861 || codeview_dir->desize != sizeof(*codeview_dent) )
2865 codeview_dent = (struct CV4_DirEnt *) (codeview_dir + 1);
2867 for(j=0; j < codeview_dir->ndir; j++, codeview_dent++)
2869 if( codeview_dent->subsect_number == sstAlignSym )
2872 * Check the previous entry. If it is a
2873 * sstSrcModule, it contains the line number
2874 * info for this file.
2877 if( codeview_dent[1].module_number == codeview_dent[0].module_number
2878 && codeview_dent[1].subsect_number == sstSrcModule )
2880 linetab = DEBUG_SnarfLinetab(
2881 codeview + codeview_dent[1].offset,
2882 codeview_dent[1].size);
2885 if( codeview_dent[-1].module_number == codeview_dent[0].module_number
2886 && codeview_dent[-1].subsect_number == sstSrcModule )
2888 linetab = DEBUG_SnarfLinetab(
2889 codeview + codeview_dent[-1].offset,
2890 codeview_dent[-1].size);
2893 * Now process the CV stuff.
2895 DEBUG_SnarfCodeView(module,
2896 codeview + codeview_dent->offset + sizeof(DWORD),
2897 codeview_dent->size - sizeof(DWORD),
2909 DEBUG_UnmapDebugInfoFile(hFile, hMap, addr);
2915 DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module)
2917 struct CodeViewDebug * cvd;
2918 struct MiscDebug * misc;
2922 switch (MSC_INFO(module)->dbgdir.Type)
2924 case IMAGE_DEBUG_TYPE_COFF:
2926 * Standard COFF debug information that VC++ adds when you
2927 * use /debugtype:both with the linker.
2929 DEBUG_Printf(DBG_CHN_TRACE, "Processing COFF symbols...\n");
2930 sts = DEBUG_ProcessCoff(module);
2932 case IMAGE_DEBUG_TYPE_CODEVIEW:
2934 * This is a pointer to a PDB file of some sort.
2936 cvd = (struct CodeViewDebug *) MSC_INFO(module)->dbg_info;
2938 if( strcmp(cvd->cv_nbtype, "NB10") != 0 )
2941 * Whatever this is, we don't know how to deal with
2947 sts = DEBUG_ProcessPDBFile(module, cvd->cv_name);
2948 DEBUG_Printf(DBG_CHN_TRACE, "Processing PDB file %s\n", cvd->cv_name);
2950 case IMAGE_DEBUG_TYPE_MISC:
2952 * A pointer to a .DBG file of some sort. These files
2953 * can contain either CV4 or COFF information. Open
2954 * the file, and try to do the right thing with it.
2956 misc = (struct MiscDebug *) MSC_INFO(module)->dbg_info;
2958 filename = strrchr((char *) &misc->Data, '.');
2961 * Ignore the file if it doesn't have a .DBG extension.
2963 if( (filename == NULL)
2964 || ( (strcmp(filename, ".dbg") != 0)
2965 && (strcmp(filename, ".DBG") != 0)) )
2971 filename = (char *) &misc->Data;
2974 * Do the dirty deed...
2976 sts = DEBUG_ProcessDBGFile(module, filename);
2981 * We should never get here...
2986 module->status = (sts) ? DM_STATUS_LOADED : DM_STATUS_ERROR;