Removed obsolete TOOLSUBDIRS dependency.
[wine/multimedia.git] / debugger / msc.c
blob9ff2964c1d27c426076818ba65792c434c6d2b69
1 /*
2 * File msc.c - read VC++ debug information from COFF and eventually
3 * from PDB files.
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.
13 * TODO:
14 * Get 16 bit CV stuff working.
15 * Add symbol size to internal symbol table.
18 #include "config.h"
19 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #ifndef PATH_MAX
24 #define PATH_MAX _MAX_PATH
25 #endif
26 #include "debugger.h"
27 #include "neexe.h"
28 #include "file.h"
30 typedef struct {
31 IMAGE_DEBUG_DIRECTORY dbgdir;
32 u_long sect_ofs;
33 int nsect;
34 char* dbg_info;
35 int dbg_size;
36 } MSC_DBG_INFO;
38 #define MSC_INFO(module) ((MSC_DBG_INFO*)((module)->extra_info))
40 static int DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module);
43 * dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
45 static void DEBUG_LocateDebugInfoFile(const char *filename, char *dbg_filename)
47 char *str1 = DBG_alloc(MAX_PATHNAME_LEN);
48 char *str2 = DBG_alloc(MAX_PATHNAME_LEN*10);
49 const char *file;
50 char *name_part;
52 file = strrchr(filename, '\\');
53 if( file == NULL ) file = filename; else file++;
55 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
56 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
57 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
58 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
59 (SearchPath(NULL, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part)))
60 lstrcpyn(dbg_filename, str2, MAX_PATHNAME_LEN);
61 else
62 lstrcpyn(dbg_filename, filename, MAX_PATHNAME_LEN);
63 DBG_free(str1);
64 DBG_free(str2);
67 /***********************************************************************
68 * DEBUG_MapDebugInfoFile
70 static void* DEBUG_MapDebugInfoFile(const char* name, DWORD offset, DWORD size,
71 HANDLE* hFile, HANDLE* hMap)
73 OFSTRUCT ofs;
74 DWORD g_offset; /* offset aligned on map granuality */
75 DWORD g_size; /* size to map, with offset aligned */
76 char* ret;
78 *hMap = 0;
80 if (name != NULL) {
81 char filename[MAX_PATHNAME_LEN];
83 DEBUG_LocateDebugInfoFile(name, filename);
84 if ((*hFile = OpenFile(filename, &ofs, OF_READ)) == HFILE_ERROR)
85 return NULL;
88 if (!size) {
89 DWORD file_size = GetFileSize(*hFile, NULL);
90 if (file_size == (DWORD)-1) return NULL;
91 size = file_size - offset;
94 g_offset = offset & ~0xFFFF; /* FIXME: is granularity portable ? */
95 g_size = offset + size - g_offset;
97 if ((*hMap = CreateFileMapping(*hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == 0)
98 return NULL;
100 if ((ret = MapViewOfFile(*hMap, FILE_MAP_READ, 0, g_offset, g_size)) != NULL)
101 ret += offset - g_offset;
102 return ret;
105 /***********************************************************************
106 * DEBUG_UnmapDebugInfoFile
108 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile, HANDLE hMap, void* addr)
110 if (addr) UnmapViewOfFile(addr);
111 if (hMap) CloseHandle(hMap);
112 if (hFile) CloseHandle(hFile);
115 union any_size
117 char * c;
118 short * s;
119 int * i;
120 unsigned int * ui;
124 * This is a convenience structure used to map portions of the
125 * line number table.
127 struct startend
129 unsigned int start;
130 unsigned int end;
134 * This is how we reference the various record types.
136 union codeview_symbol
138 struct
140 short int len;
141 short int id;
142 } generic;
144 struct
146 short int len;
147 short int id;
148 unsigned int offset;
149 unsigned short seg;
150 unsigned short symtype;
151 unsigned char namelen;
152 unsigned char name[1];
153 } data;
155 struct
157 short int len;
158 short int id;
159 unsigned int symtype;
160 unsigned int offset;
161 unsigned short seg;
162 unsigned char namelen;
163 unsigned char name[1];
164 } data32;
166 struct
168 short int len;
169 short int id;
170 unsigned int pparent;
171 unsigned int pend;
172 unsigned int next;
173 unsigned int offset;
174 unsigned short segment;
175 unsigned short thunk_len;
176 unsigned char thtype;
177 unsigned char namelen;
178 unsigned char name[1];
179 } thunk;
181 struct
183 short int len;
184 short int id;
185 unsigned int pparent;
186 unsigned int pend;
187 unsigned int next;
188 unsigned int proc_len;
189 unsigned int debug_start;
190 unsigned int debug_end;
191 unsigned int offset;
192 unsigned short segment;
193 unsigned short proctype;
194 unsigned char flags;
195 unsigned char namelen;
196 unsigned char name[1];
197 } proc;
199 struct
201 short int len;
202 short int id;
203 unsigned int pparent;
204 unsigned int pend;
205 unsigned int next;
206 unsigned int proc_len;
207 unsigned int debug_start;
208 unsigned int debug_end;
209 unsigned int proctype;
210 unsigned int offset;
211 unsigned short segment;
212 unsigned char flags;
213 unsigned char namelen;
214 unsigned char name[1];
215 } proc32;
217 struct
219 short int len; /* Total length of this entry */
220 short int id; /* Always S_BPREL32 */
221 unsigned int offset; /* Stack offset relative to BP */
222 unsigned short symtype;
223 unsigned char namelen;
224 unsigned char name[1];
225 } stack;
227 struct
229 short int len; /* Total length of this entry */
230 short int id; /* Always S_BPREL32 */
231 unsigned int offset; /* Stack offset relative to BP */
232 unsigned int symtype;
233 unsigned char namelen;
234 unsigned char name[1];
235 } stack32;
239 union codeview_type
241 struct
243 short int len;
244 short int id;
245 } generic;
247 struct
249 short int len;
250 short int id;
251 short int attribute;
252 short int datatype;
253 unsigned char variant[1];
254 } pointer;
256 struct
258 short int len;
259 short int id;
260 unsigned int datatype;
261 unsigned int attribute;
262 unsigned char variant[1];
263 } pointer32;
265 struct
267 short int len;
268 short int id;
269 unsigned char nbits;
270 unsigned char bitoff;
271 unsigned short type;
272 } bitfield;
274 struct
276 short int len;
277 short int id;
278 unsigned int type;
279 unsigned char nbits;
280 unsigned char bitoff;
281 } bitfield32;
283 struct
285 short int len;
286 short int id;
287 short int elemtype;
288 short int idxtype;
289 unsigned short int arrlen; /* numeric leaf */
290 #if 0
291 unsigned char name[1];
292 #endif
293 } array;
295 struct
297 short int len;
298 short int id;
299 unsigned int elemtype;
300 unsigned int idxtype;
301 unsigned short int arrlen; /* numeric leaf */
302 #if 0
303 unsigned char name[1];
304 #endif
305 } array32;
307 struct
309 short int len;
310 short int id;
311 short int n_element;
312 short int fieldlist;
313 short int property;
314 short int derived;
315 short int vshape;
316 unsigned short int structlen; /* numeric leaf */
317 #if 0
318 unsigned char name[1];
319 #endif
320 } structure;
322 struct
324 short int len;
325 short int id;
326 short int n_element;
327 short int property;
328 unsigned int fieldlist;
329 unsigned int derived;
330 unsigned int vshape;
331 unsigned short int structlen; /* numeric leaf */
332 #if 0
333 unsigned char name[1];
334 #endif
335 } structure32;
337 struct
339 short int len;
340 short int id;
341 short int count;
342 short int fieldlist;
343 short int property;
344 unsigned short int un_len; /* numeric leaf */
345 #if 0
346 unsigned char name[1];
347 #endif
348 } t_union;
350 struct
352 short int len;
353 short int id;
354 short int count;
355 short int property;
356 unsigned int fieldlist;
357 unsigned short int un_len; /* numeric leaf */
358 #if 0
359 unsigned char name[1];
360 #endif
361 } t_union32;
363 struct
365 short int len;
366 short int id;
367 short int count;
368 short int type;
369 short int field;
370 short int property;
371 unsigned char name[1];
372 } enumeration;
374 struct
376 short int len;
377 short int id;
378 short int count;
379 short int property;
380 unsigned int type;
381 unsigned int field;
382 unsigned char name[1];
383 } enumeration32;
385 struct
387 short int len;
388 short int id;
389 unsigned char list[1];
390 } fieldlist;
393 union codeview_fieldtype
395 struct
397 short int id;
398 } generic;
400 struct
402 short int id;
403 short int type;
404 short int attribute;
405 unsigned short int offset; /* numeric leaf */
406 } bclass;
408 struct
410 short int id;
411 short int attribute;
412 unsigned int type;
413 unsigned short int offset; /* numeric leaf */
414 } bclass32;
416 struct
418 short int id;
419 short int btype;
420 short int vbtype;
421 short int attribute;
422 unsigned short int vbpoff; /* numeric leaf */
423 #if 0
424 unsigned short int vboff; /* numeric leaf */
425 #endif
426 } vbclass;
428 struct
430 short int id;
431 short int attribute;
432 unsigned int btype;
433 unsigned int vbtype;
434 unsigned short int vbpoff; /* numeric leaf */
435 #if 0
436 unsigned short int vboff; /* numeric leaf */
437 #endif
438 } vbclass32;
440 struct
442 short int id;
443 short int attribute;
444 unsigned short int value; /* numeric leaf */
445 #if 0
446 unsigned char name[1];
447 #endif
448 } enumerate;
450 struct
452 short int id;
453 short int type;
454 unsigned char name[1];
455 } friendfcn;
457 struct
459 short int id;
460 short int _pad0;
461 unsigned int type;
462 unsigned char name[1];
463 } friendfcn32;
465 struct
467 short int id;
468 short int type;
469 short int attribute;
470 unsigned short int offset; /* numeric leaf */
471 #if 0
472 unsigned char name[1];
473 #endif
474 } member;
476 struct
478 short int id;
479 short int attribute;
480 unsigned int type;
481 unsigned short int offset; /* numeric leaf */
482 #if 0
483 unsigned char name[1];
484 #endif
485 } member32;
487 struct
489 short int id;
490 short int type;
491 short int attribute;
492 unsigned char name[1];
493 } stmember;
495 struct
497 short int id;
498 short int attribute;
499 unsigned int type;
500 unsigned char name[1];
501 } stmember32;
503 struct
505 short int id;
506 short int count;
507 short int mlist;
508 unsigned char name[1];
509 } method;
511 struct
513 short int id;
514 short int count;
515 unsigned int mlist;
516 unsigned char name[1];
517 } method32;
519 struct
521 short int id;
522 short int index;
523 unsigned char name[1];
524 } nesttype;
526 struct
528 short int id;
529 short int _pad0;
530 unsigned int index;
531 unsigned char name[1];
532 } nesttype32;
534 struct
536 short int id;
537 short int type;
538 } vfunctab;
540 struct
542 short int id;
543 short int _pad0;
544 unsigned int type;
545 } vfunctab32;
547 struct
549 short int id;
550 short int type;
551 } friendcls;
553 struct
555 short int id;
556 short int _pad0;
557 unsigned int type;
558 } friendcls32;
561 struct
563 short int id;
564 short int attribute;
565 short int type;
566 unsigned char name[1];
567 } onemethod;
568 struct
570 short int id;
571 short int attribute;
572 short int type;
573 unsigned int vtab_offset;
574 unsigned char name[1];
575 } onemethod_virt;
577 struct
579 short int id;
580 short int attribute;
581 unsigned int type;
582 unsigned char name[1];
583 } onemethod32;
584 struct
586 short int id;
587 short int attribute;
588 unsigned int type;
589 unsigned int vtab_offset;
590 unsigned char name[1];
591 } onemethod32_virt;
593 struct
595 short int id;
596 short int type;
597 unsigned int offset;
598 } vfuncoff;
600 struct
602 short int id;
603 short int _pad0;
604 unsigned int type;
605 unsigned int offset;
606 } vfuncoff32;
608 struct
610 short int id;
611 short int attribute;
612 short int index;
613 unsigned char name[1];
614 } nesttypeex;
616 struct
618 short int id;
619 short int attribute;
620 unsigned int index;
621 unsigned char name[1];
622 } nesttypeex32;
624 struct
626 short int id;
627 short int attribute;
628 unsigned int type;
629 unsigned char name[1];
630 } membermodify;
633 #define S_COMPILE 0x0001
634 #define S_REGISTER 0x0002
635 #define S_CONSTANT 0x0003
636 #define S_UDT 0x0004
637 #define S_SSEARCH 0x0005
638 #define S_END 0x0006
639 #define S_SKIP 0x0007
640 #define S_CVRESERVE 0x0008
641 #define S_OBJNAME 0x0009
642 #define S_ENDARG 0x000a
643 #define S_COBOLUDT 0x000b
644 #define S_MANYREG 0x000c
645 #define S_RETURN 0x000d
646 #define S_ENTRYTHIS 0x000e
648 #define S_BPREL 0x0200
649 #define S_LDATA 0x0201
650 #define S_GDATA 0x0202
651 #define S_PUB 0x0203
652 #define S_LPROC 0x0204
653 #define S_GPROC 0x0205
654 #define S_THUNK 0x0206
655 #define S_BLOCK 0x0207
656 #define S_WITH 0x0208
657 #define S_LABEL 0x0209
658 #define S_CEXMODEL 0x020a
659 #define S_VFTPATH 0x020b
660 #define S_REGREL 0x020c
661 #define S_LTHREAD 0x020d
662 #define S_GTHREAD 0x020e
664 #define S_PROCREF 0x0400
665 #define S_DATAREF 0x0401
666 #define S_ALIGN 0x0402
667 #define S_LPROCREF 0x0403
669 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
670 #define S_CONSTANT_32 0x1002
671 #define S_UDT_32 0x1003
672 #define S_COBOLUDT_32 0x1004
673 #define S_MANYREG_32 0x1005
675 #define S_BPREL_32 0x1006
676 #define S_LDATA_32 0x1007
677 #define S_GDATA_32 0x1008
678 #define S_PUB_32 0x1009
679 #define S_LPROC_32 0x100a
680 #define S_GPROC_32 0x100b
681 #define S_VFTTABLE_32 0x100c
682 #define S_REGREL_32 0x100d
683 #define S_LTHREAD_32 0x100e
684 #define S_GTHREAD_32 0x100f
688 * This covers the basic datatypes that VC++ seems to be using these days.
689 * 32 bit mode only. There are additional numbers for the pointers in 16
690 * bit mode. There are many other types listed in the documents, but these
691 * are apparently not used by the compiler, or represent pointer types
692 * that are not used.
694 #define T_NOTYPE 0x0000 /* Notype */
695 #define T_ABS 0x0001 /* Abs */
696 #define T_VOID 0x0003 /* Void */
697 #define T_CHAR 0x0010 /* signed char */
698 #define T_SHORT 0x0011 /* short */
699 #define T_LONG 0x0012 /* long */
700 #define T_QUAD 0x0013 /* long long */
701 #define T_UCHAR 0x0020 /* unsigned char */
702 #define T_USHORT 0x0021 /* unsigned short */
703 #define T_ULONG 0x0022 /* unsigned long */
704 #define T_UQUAD 0x0023 /* unsigned long long */
705 #define T_REAL32 0x0040 /* float */
706 #define T_REAL64 0x0041 /* double */
707 #define T_RCHAR 0x0070 /* real char */
708 #define T_WCHAR 0x0071 /* wide char */
709 #define T_INT4 0x0074 /* int */
710 #define T_UINT4 0x0075 /* unsigned int */
712 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
713 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
714 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
715 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
716 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
717 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
718 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
719 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
720 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
721 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
722 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
723 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
724 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
725 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
726 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
728 #define LF_MODIFIER 0x0001
729 #define LF_POINTER 0x0002
730 #define LF_ARRAY 0x0003
731 #define LF_CLASS 0x0004
732 #define LF_STRUCTURE 0x0005
733 #define LF_UNION 0x0006
734 #define LF_ENUM 0x0007
735 #define LF_PROCEDURE 0x0008
736 #define LF_MFUNCTION 0x0009
737 #define LF_VTSHAPE 0x000a
738 #define LF_COBOL0 0x000b
739 #define LF_COBOL1 0x000c
740 #define LF_BARRAY 0x000d
741 #define LF_LABEL 0x000e
742 #define LF_NULL 0x000f
743 #define LF_NOTTRAN 0x0010
744 #define LF_DIMARRAY 0x0011
745 #define LF_VFTPATH 0x0012
746 #define LF_PRECOMP 0x0013
747 #define LF_ENDPRECOMP 0x0014
748 #define LF_OEM 0x0015
749 #define LF_TYPESERVER 0x0016
751 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
752 #define LF_POINTER_32 0x1002
753 #define LF_ARRAY_32 0x1003
754 #define LF_CLASS_32 0x1004
755 #define LF_STRUCTURE_32 0x1005
756 #define LF_UNION_32 0x1006
757 #define LF_ENUM_32 0x1007
758 #define LF_PROCEDURE_32 0x1008
759 #define LF_MFUNCTION_32 0x1009
760 #define LF_COBOL0_32 0x100a
761 #define LF_BARRAY_32 0x100b
762 #define LF_DIMARRAY_32 0x100c
763 #define LF_VFTPATH_32 0x100d
764 #define LF_PRECOMP_32 0x100e
765 #define LF_OEM_32 0x100f
767 #define LF_SKIP 0x0200
768 #define LF_ARGLIST 0x0201
769 #define LF_DEFARG 0x0202
770 #define LF_LIST 0x0203
771 #define LF_FIELDLIST 0x0204
772 #define LF_DERIVED 0x0205
773 #define LF_BITFIELD 0x0206
774 #define LF_METHODLIST 0x0207
775 #define LF_DIMCONU 0x0208
776 #define LF_DIMCONLU 0x0209
777 #define LF_DIMVARU 0x020a
778 #define LF_DIMVARLU 0x020b
779 #define LF_REFSYM 0x020c
781 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
782 #define LF_ARGLIST_32 0x1201
783 #define LF_DEFARG_32 0x1202
784 #define LF_FIELDLIST_32 0x1203
785 #define LF_DERIVED_32 0x1204
786 #define LF_BITFIELD_32 0x1205
787 #define LF_METHODLIST_32 0x1206
788 #define LF_DIMCONU_32 0x1207
789 #define LF_DIMCONLU_32 0x1208
790 #define LF_DIMVARU_32 0x1209
791 #define LF_DIMVARLU_32 0x120a
793 #define LF_BCLASS 0x0400
794 #define LF_VBCLASS 0x0401
795 #define LF_IVBCLASS 0x0402
796 #define LF_ENUMERATE 0x0403
797 #define LF_FRIENDFCN 0x0404
798 #define LF_INDEX 0x0405
799 #define LF_MEMBER 0x0406
800 #define LF_STMEMBER 0x0407
801 #define LF_METHOD 0x0408
802 #define LF_NESTTYPE 0x0409
803 #define LF_VFUNCTAB 0x040a
804 #define LF_FRIENDCLS 0x040b
805 #define LF_ONEMETHOD 0x040c
806 #define LF_VFUNCOFF 0x040d
807 #define LF_NESTTYPEEX 0x040e
808 #define LF_MEMBERMODIFY 0x040f
810 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
811 #define LF_VBCLASS_32 0x1401
812 #define LF_IVBCLASS_32 0x1402
813 #define LF_FRIENDFCN_32 0x1403
814 #define LF_INDEX_32 0x1404
815 #define LF_MEMBER_32 0x1405
816 #define LF_STMEMBER_32 0x1406
817 #define LF_METHOD_32 0x1407
818 #define LF_NESTTYPE_32 0x1408
819 #define LF_VFUNCTAB_32 0x1409
820 #define LF_FRIENDCLS_32 0x140a
821 #define LF_ONEMETHOD_32 0x140b
822 #define LF_VFUNCOFF_32 0x140c
823 #define LF_NESTTYPEEX_32 0x140d
825 #define LF_NUMERIC 0x8000 /* numeric leaf types */
826 #define LF_CHAR 0x8000
827 #define LF_SHORT 0x8001
828 #define LF_USHORT 0x8002
829 #define LF_LONG 0x8003
830 #define LF_ULONG 0x8004
831 #define LF_REAL32 0x8005
832 #define LF_REAL64 0x8006
833 #define LF_REAL80 0x8007
834 #define LF_REAL128 0x8008
835 #define LF_QUADWORD 0x8009
836 #define LF_UQUADWORD 0x800a
837 #define LF_REAL48 0x800b
838 #define LF_COMPLEX32 0x800c
839 #define LF_COMPLEX64 0x800d
840 #define LF_COMPLEX80 0x800e
841 #define LF_COMPLEX128 0x800f
842 #define LF_VARSTRING 0x8010
846 #define MAX_BUILTIN_TYPES 0x480
847 static struct datatype * cv_basic_types[MAX_BUILTIN_TYPES];
848 static int num_cv_defined_types = 0;
849 static struct datatype **cv_defined_types = NULL;
852 * For the type CODEVIEW debug directory entries, the debug directory
853 * points to a structure like this. The cv_name field is the name
854 * of an external .PDB file.
856 struct CodeViewDebug
858 char cv_nbtype[8];
859 unsigned int cv_timestamp;
860 char cv_unknown[4];
861 char cv_name[1];
864 struct MiscDebug {
865 unsigned int DataType;
866 unsigned int Length;
867 char Unicode;
868 char Reserved[3];
869 char Data[1];
873 * This is the header that the COFF variety of debug header points to.
875 struct CoffDebug {
876 unsigned int N_Sym;
877 unsigned int SymbolOffset;
878 unsigned int N_Linenum;
879 unsigned int LinenumberOffset;
880 unsigned int Unused[4];
883 struct CoffLinenum {
884 unsigned int VirtualAddr;
885 unsigned short int Linenum;
888 struct CoffFiles {
889 unsigned int startaddr;
890 unsigned int endaddr;
891 char * filename;
892 int linetab_offset;
893 int linecnt;
894 struct name_hash **entries;
895 int neps;
896 int neps_alloc;
900 struct CoffSymbol {
901 union {
902 char ShortName[8];
903 struct {
904 unsigned int NotLong;
905 unsigned int StrTaboff;
906 } Name;
907 } N;
908 unsigned int Value;
909 short SectionNumber;
910 short Type;
911 char StorageClass;
912 unsigned char NumberOfAuxSymbols;
915 struct CoffAuxSection{
916 unsigned int Length;
917 unsigned short NumberOfRelocations;
918 unsigned short NumberOfLinenumbers;
919 unsigned int CheckSum;
920 short Number;
921 char Selection;
922 } Section;
925 * These two structures are used in the directory within a .DBG file
926 * to locate the individual important bits that we might want to see.
928 struct CV4_DirHead {
929 short unsigned int dhsize;
930 short unsigned int desize;
931 unsigned int ndir;
932 unsigned int next_offset;
933 unsigned int flags;
936 struct CV4_DirEnt {
937 short unsigned int subsect_number;
938 short unsigned int module_number;
939 unsigned int offset;
940 unsigned int size;
944 * These are the values of interest that the subsect_number field takes.
946 #define sstAlignSym 0x125
947 #define sstSrcModule 0x127
949 struct codeview_linetab_hdr
951 unsigned int nline;
952 unsigned int segno;
953 unsigned int start;
954 unsigned int end;
955 char * sourcefile;
956 unsigned short * linetab;
957 unsigned int * offtab;
963 * CodeView type information parsing
966 static int
967 numeric_leaf( int *value, unsigned short int *leaf )
969 unsigned short int type = *leaf++;
970 int length = 2;
972 if ( type < LF_NUMERIC )
974 *value = type;
976 else
978 switch ( type )
980 case LF_CHAR:
981 length += 1;
982 *value = *(char *)leaf;
983 break;
985 case LF_SHORT:
986 length += 2;
987 *value = *(short *)leaf;
988 break;
990 case LF_USHORT:
991 length += 2;
992 *value = *(unsigned short *)leaf;
993 break;
995 case LF_LONG:
996 length += 4;
997 *value = *(int *)leaf;
998 break;
1000 case LF_ULONG:
1001 length += 4;
1002 *value = *(unsigned int *)leaf;
1003 break;
1005 case LF_QUADWORD:
1006 case LF_UQUADWORD:
1007 length += 8;
1008 *value = 0; /* FIXME */
1009 break;
1011 case LF_REAL32:
1012 length += 4;
1013 *value = 0; /* FIXME */
1014 break;
1016 case LF_REAL48:
1017 length += 6;
1018 *value = 0; /* FIXME */
1019 break;
1021 case LF_REAL64:
1022 length += 8;
1023 *value = 0; /* FIXME */
1024 break;
1026 case LF_REAL80:
1027 length += 10;
1028 *value = 0; /* FIXME */
1029 break;
1031 case LF_REAL128:
1032 length += 16;
1033 *value = 0; /* FIXME */
1034 break;
1036 case LF_COMPLEX32:
1037 length += 4;
1038 *value = 0; /* FIXME */
1039 break;
1041 case LF_COMPLEX64:
1042 length += 8;
1043 *value = 0; /* FIXME */
1044 break;
1046 case LF_COMPLEX80:
1047 length += 10;
1048 *value = 0; /* FIXME */
1049 break;
1051 case LF_COMPLEX128:
1052 length += 16;
1053 *value = 0; /* FIXME */
1054 break;
1056 case LF_VARSTRING:
1057 length += 2 + *leaf;
1058 *value = 0; /* FIXME */
1059 break;
1061 default:
1062 DEBUG_Printf( DBG_CHN_MESG, "Unknown numeric leaf type %04x\n", type );
1063 *value = 0;
1064 break;
1068 return length;
1071 static char *
1072 terminate_string( unsigned char *name )
1074 static char symname[256];
1076 int namelen = name[0];
1077 assert( namelen >= 0 && namelen < 256 );
1079 memcpy( symname, name+1, namelen );
1080 symname[namelen] = '\0';
1082 if ( !*symname || strcmp( symname, "__unnamed" ) == 0 )
1083 return NULL;
1084 else
1085 return symname;
1088 static
1089 struct datatype * DEBUG_GetCVType(unsigned int typeno)
1091 struct datatype * dt = NULL;
1094 * Convert Codeview type numbers into something we can grok internally.
1095 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
1096 * up are all user defined (structs, etc).
1098 if ( typeno < 0x1000 )
1100 if ( typeno < MAX_BUILTIN_TYPES )
1101 dt = cv_basic_types[typeno];
1103 else
1105 if ( typeno - 0x1000 < num_cv_defined_types )
1106 dt = cv_defined_types[typeno - 0x1000];
1109 return dt;
1112 static int
1113 DEBUG_AddCVType( unsigned int typeno, struct datatype *dt )
1115 while ( typeno - 0x1000 >= num_cv_defined_types )
1117 num_cv_defined_types += 0x100;
1118 cv_defined_types = (struct datatype **)
1119 DBG_realloc( cv_defined_types,
1120 num_cv_defined_types * sizeof(struct datatype *) );
1122 memset( cv_defined_types + num_cv_defined_types - 0x100,
1124 0x100 * sizeof(struct datatype *) );
1126 if ( cv_defined_types == NULL )
1127 return FALSE;
1130 cv_defined_types[ typeno - 0x1000 ] = dt;
1131 return TRUE;
1134 static void
1135 DEBUG_ClearTypeTable( void )
1137 if ( cv_defined_types )
1138 DBG_free( cv_defined_types );
1140 cv_defined_types = NULL;
1141 num_cv_defined_types = 0;
1144 static int
1145 DEBUG_AddCVType_Pointer( unsigned int typeno, unsigned int datatype )
1147 struct datatype *dt =
1148 DEBUG_FindOrMakePointerType( DEBUG_GetCVType( datatype ) );
1150 return DEBUG_AddCVType( typeno, dt );
1153 static int
1154 DEBUG_AddCVType_Array( unsigned int typeno, char *name,
1155 unsigned int elemtype, unsigned int arr_len )
1157 struct datatype *dt = DEBUG_NewDataType( DT_ARRAY, name );
1158 struct datatype *elem = DEBUG_GetCVType( elemtype );
1159 unsigned int elem_size = elem? DEBUG_GetObjectSize( elem ) : 0;
1160 unsigned int arr_max = elem_size? arr_len / elem_size : 0;
1162 DEBUG_SetArrayParams( dt, 0, arr_max, elem );
1163 return DEBUG_AddCVType( typeno, dt );
1166 static int
1167 DEBUG_AddCVType_Bitfield( unsigned int typeno,
1168 unsigned int bitoff, unsigned int nbits,
1169 unsigned int basetype )
1171 struct datatype *dt = DEBUG_NewDataType( DT_BITFIELD, NULL );
1172 struct datatype *base = DEBUG_GetCVType( basetype );
1174 DEBUG_SetBitfieldParams( dt, bitoff, nbits, base );
1175 return DEBUG_AddCVType( typeno, dt );
1178 static int
1179 DEBUG_AddCVType_EnumFieldList( unsigned int typeno, unsigned char *list, int len )
1181 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, NULL );
1182 unsigned char *ptr = list;
1184 while ( ptr - list < len )
1186 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1188 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1190 ptr += *ptr & 0x0f;
1191 continue;
1194 switch ( type->generic.id )
1196 case LF_ENUMERATE:
1198 int value, vlen = numeric_leaf( &value, &type->enumerate.value );
1199 unsigned char *name = (unsigned char *)&type->enumerate.value + vlen;
1201 DEBUG_AddStructElement( dt, terminate_string( name ),
1202 NULL, value, 0 );
1204 ptr += 2 + 2 + vlen + (1 + name[0]);
1205 break;
1208 default:
1209 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in ENUM field list\n",
1210 type->generic.id );
1211 return FALSE;
1215 return DEBUG_AddCVType( typeno, dt );
1218 static int
1219 DEBUG_AddCVType_StructFieldList( unsigned int typeno, unsigned char *list, int len )
1221 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, NULL );
1222 unsigned char *ptr = list;
1224 while ( ptr - list < len )
1226 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1228 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1230 ptr += *ptr & 0x0f;
1231 continue;
1234 switch ( type->generic.id )
1236 case LF_BCLASS:
1238 int offset, olen = numeric_leaf( &offset, &type->bclass.offset );
1240 /* FIXME: ignored for now */
1242 ptr += 2 + 2 + 2 + olen;
1243 break;
1246 case LF_BCLASS_32:
1248 int offset, olen = numeric_leaf( &offset, &type->bclass32.offset );
1250 /* FIXME: ignored for now */
1252 ptr += 2 + 2 + 4 + olen;
1253 break;
1256 case LF_VBCLASS:
1257 case LF_IVBCLASS:
1259 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass.vbpoff );
1260 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass.vbpoff + vbpoff);
1261 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1263 /* FIXME: ignored for now */
1265 ptr += 2 + 2 + 2 + 2 + vbplen + vplen;
1266 break;
1269 case LF_VBCLASS_32:
1270 case LF_IVBCLASS_32:
1272 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass32.vbpoff );
1273 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass32.vbpoff + vbpoff);
1274 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1276 /* FIXME: ignored for now */
1278 ptr += 2 + 2 + 4 + 4 + vbplen + vplen;
1279 break;
1282 case LF_MEMBER:
1284 int offset, olen = numeric_leaf( &offset, &type->member.offset );
1285 unsigned char *name = (unsigned char *)&type->member.offset + olen;
1287 struct datatype *subtype = DEBUG_GetCVType( type->member.type );
1288 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1290 DEBUG_AddStructElement( dt, terminate_string( name ),
1291 subtype, offset << 3, elem_size << 3 );
1293 ptr += 2 + 2 + 2 + olen + (1 + name[0]);
1294 break;
1297 case LF_MEMBER_32:
1299 int offset, olen = numeric_leaf( &offset, &type->member32.offset );
1300 unsigned char *name = (unsigned char *)&type->member32.offset + olen;
1302 struct datatype *subtype = DEBUG_GetCVType( type->member32.type );
1303 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1305 DEBUG_AddStructElement( dt, terminate_string( name ),
1306 subtype, offset << 3, elem_size << 3 );
1308 ptr += 2 + 2 + 4 + olen + (1 + name[0]);
1309 break;
1312 case LF_STMEMBER:
1313 /* FIXME: ignored for now */
1314 ptr += 2 + 2 + 2 + (1 + type->stmember.name[0]);
1315 break;
1317 case LF_STMEMBER_32:
1318 /* FIXME: ignored for now */
1319 ptr += 2 + 4 + 2 + (1 + type->stmember32.name[0]);
1320 break;
1322 case LF_METHOD:
1323 /* FIXME: ignored for now */
1324 ptr += 2 + 2 + 2 + (1 + type->method.name[0]);
1325 break;
1327 case LF_METHOD_32:
1328 /* FIXME: ignored for now */
1329 ptr += 2 + 2 + 4 + (1 + type->method32.name[0]);
1330 break;
1332 case LF_NESTTYPE:
1333 /* FIXME: ignored for now */
1334 ptr += 2 + 2 + (1 + type->nesttype.name[0]);
1335 break;
1337 case LF_NESTTYPE_32:
1338 /* FIXME: ignored for now */
1339 ptr += 2 + 2 + 4 + (1 + type->nesttype32.name[0]);
1340 break;
1342 case LF_VFUNCTAB:
1343 /* FIXME: ignored for now */
1344 ptr += 2 + 2;
1345 break;
1347 case LF_VFUNCTAB_32:
1348 /* FIXME: ignored for now */
1349 ptr += 2 + 2 + 4;
1350 break;
1352 case LF_ONEMETHOD:
1353 /* FIXME: ignored for now */
1354 switch ( (type->onemethod.attribute >> 2) & 7 )
1356 case 4: case 6: /* (pure) introducing virtual method */
1357 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt.name[0]);
1358 break;
1360 default:
1361 ptr += 2 + 2 + 2 + (1 + type->onemethod.name[0]);
1362 break;
1364 break;
1366 case LF_ONEMETHOD_32:
1367 /* FIXME: ignored for now */
1368 switch ( (type->onemethod32.attribute >> 2) & 7 )
1370 case 4: case 6: /* (pure) introducing virtual method */
1371 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod32_virt.name[0]);
1372 break;
1374 default:
1375 ptr += 2 + 2 + 4 + (1 + type->onemethod32.name[0]);
1376 break;
1378 break;
1380 default:
1381 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in STRUCT field list\n",
1382 type->generic.id );
1383 return FALSE;
1387 return DEBUG_AddCVType( typeno, dt );
1390 static int
1391 DEBUG_AddCVType_Enum( unsigned int typeno, char *name, unsigned int fieldlist )
1393 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, name );
1394 struct datatype *list = DEBUG_GetCVType( fieldlist );
1396 if ( list )
1397 DEBUG_CopyFieldlist( dt, list );
1399 return DEBUG_AddCVType( typeno, dt );
1402 static int
1403 DEBUG_AddCVType_Struct( unsigned int typeno, char *name, int structlen, unsigned int fieldlist )
1405 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, name );
1406 struct datatype *list = DEBUG_GetCVType( fieldlist );
1408 if ( list )
1410 DEBUG_SetStructSize( dt, structlen );
1411 DEBUG_CopyFieldlist( dt, list );
1414 return DEBUG_AddCVType( typeno, dt );
1417 static int
1418 DEBUG_ParseTypeTable( char *table, int len )
1420 unsigned int curr_type = 0x1000;
1421 char *ptr = table;
1423 while ( ptr - table < len )
1425 union codeview_type *type = (union codeview_type *) ptr;
1426 int retv = TRUE;
1428 switch ( type->generic.id )
1430 case LF_POINTER:
1431 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer.datatype );
1432 break;
1433 case LF_POINTER_32:
1434 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer32.datatype );
1435 break;
1437 case LF_ARRAY:
1439 int arrlen, alen = numeric_leaf( &arrlen, &type->array.arrlen );
1440 unsigned char *name = (unsigned char *)&type->array.arrlen + alen;
1442 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1443 type->array.elemtype, arrlen );
1444 break;
1446 case LF_ARRAY_32:
1448 int arrlen, alen = numeric_leaf( &arrlen, &type->array32.arrlen );
1449 unsigned char *name = (unsigned char *)&type->array32.arrlen + alen;
1451 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1452 type->array32.elemtype, type->array32.arrlen );
1453 break;
1456 case LF_BITFIELD:
1457 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield.bitoff,
1458 type->bitfield.nbits,
1459 type->bitfield.type );
1460 break;
1461 case LF_BITFIELD_32:
1462 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield32.bitoff,
1463 type->bitfield32.nbits,
1464 type->bitfield32.type );
1465 break;
1467 case LF_FIELDLIST:
1468 case LF_FIELDLIST_32:
1471 * A 'field list' is a CodeView-specific data type which doesn't
1472 * directly correspond to any high-level data type. It is used
1473 * to hold the collection of members of a struct, class, union
1474 * or enum type. The actual definition of that type will follow
1475 * later, and refer to the field list definition record.
1477 * As we don't have a field list type ourselves, we look ahead
1478 * in the field list to try to find out whether this field list
1479 * will be used for an enum or struct type, and create a dummy
1480 * type of the corresponding sort. Later on, the definition of
1481 * the 'real' type will copy the member / enumeration data.
1484 char *list = type->fieldlist.list;
1485 int len = (ptr + type->generic.len + 2) - list;
1487 if ( ((union codeview_fieldtype *)list)->generic.id == LF_ENUMERATE )
1488 retv = DEBUG_AddCVType_EnumFieldList( curr_type, list, len );
1489 else
1490 retv = DEBUG_AddCVType_StructFieldList( curr_type, list, len );
1491 break;
1494 case LF_STRUCTURE:
1495 case LF_CLASS:
1497 int structlen, slen = numeric_leaf( &structlen, &type->structure.structlen );
1498 unsigned char *name = (unsigned char *)&type->structure.structlen + slen;
1500 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1501 structlen, type->structure.fieldlist );
1502 break;
1504 case LF_STRUCTURE_32:
1505 case LF_CLASS_32:
1507 int structlen, slen = numeric_leaf( &structlen, &type->structure32.structlen );
1508 unsigned char *name = (unsigned char *)&type->structure32.structlen + slen;
1510 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1511 structlen, type->structure32.fieldlist );
1512 break;
1515 case LF_UNION:
1517 int un_len, ulen = numeric_leaf( &un_len, &type->t_union.un_len );
1518 unsigned char *name = (unsigned char *)&type->t_union.un_len + ulen;
1520 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1521 un_len, type->t_union.fieldlist );
1522 break;
1524 case LF_UNION_32:
1526 int un_len, ulen = numeric_leaf( &un_len, &type->t_union32.un_len );
1527 unsigned char *name = (unsigned char *)&type->t_union32.un_len + ulen;
1529 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1530 un_len, type->t_union32.fieldlist );
1531 break;
1534 case LF_ENUM:
1535 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration.name ),
1536 type->enumeration.field );
1537 break;
1538 case LF_ENUM_32:
1539 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration32.name ),
1540 type->enumeration32.field );
1541 break;
1543 default:
1544 break;
1547 if ( !retv )
1548 return FALSE;
1550 curr_type++;
1551 ptr += type->generic.len + 2;
1554 return TRUE;
1558 void
1559 DEBUG_InitCVDataTypes(void)
1562 * These are the common builtin types that are used by VC++.
1564 cv_basic_types[T_NOTYPE] = NULL;
1565 cv_basic_types[T_ABS] = NULL;
1566 cv_basic_types[T_VOID] = DEBUG_NewDataType(DT_BASIC, "void");
1567 cv_basic_types[T_CHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1568 cv_basic_types[T_SHORT] = DEBUG_NewDataType(DT_BASIC, "short int");
1569 cv_basic_types[T_LONG] = DEBUG_NewDataType(DT_BASIC, "long int");
1570 cv_basic_types[T_QUAD] = DEBUG_NewDataType(DT_BASIC, "long long int");
1571 cv_basic_types[T_UCHAR] = DEBUG_NewDataType(DT_BASIC, "unsigned char");
1572 cv_basic_types[T_USHORT] = DEBUG_NewDataType(DT_BASIC, "short unsigned int");
1573 cv_basic_types[T_ULONG] = DEBUG_NewDataType(DT_BASIC, "long unsigned int");
1574 cv_basic_types[T_UQUAD] = DEBUG_NewDataType(DT_BASIC, "long long unsigned int");
1575 cv_basic_types[T_REAL32] = DEBUG_NewDataType(DT_BASIC, "float");
1576 cv_basic_types[T_REAL64] = DEBUG_NewDataType(DT_BASIC, "double");
1577 cv_basic_types[T_RCHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1578 cv_basic_types[T_WCHAR] = DEBUG_NewDataType(DT_BASIC, "short");
1579 cv_basic_types[T_INT4] = DEBUG_NewDataType(DT_BASIC, "int");
1580 cv_basic_types[T_UINT4] = DEBUG_NewDataType(DT_BASIC, "unsigned int");
1582 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
1583 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
1584 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
1585 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
1586 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
1587 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
1588 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
1589 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
1590 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
1591 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
1592 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
1593 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
1594 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
1595 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
1596 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
1600 * In this function, we keep track of deferred debugging information
1601 * that we may need later if we were to need to use the internal debugger.
1602 * We don't fully process it here for performance reasons.
1605 DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth, unsigned long nth_ofs)
1607 int has_codeview = FALSE;
1608 int rtn = FALSE;
1609 IMAGE_DEBUG_DIRECTORY dbg;
1610 u_long v_addr, size, orig_size;
1611 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1613 orig_size = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
1614 if (orig_size) {
1615 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1616 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1618 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *) module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1620 switch(dbg.Type)
1622 case IMAGE_DEBUG_TYPE_CODEVIEW:
1623 case IMAGE_DEBUG_TYPE_MISC:
1624 has_codeview = TRUE;
1625 break;
1627 v_addr += sizeof(dbg);
1630 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1631 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1633 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1635 switch(dbg.Type)
1637 case IMAGE_DEBUG_TYPE_COFF:
1639 * If we have both codeview and COFF debug info, ignore the
1640 * coff debug info as it would just confuse us, and it is
1641 * less complete.
1643 * FIXME - this is broken - if we cannot find the PDB file, then
1644 * we end up with no debugging info at all. In this case, we
1645 * should use the COFF info as a backup.
1647 if( has_codeview )
1649 break;
1651 case IMAGE_DEBUG_TYPE_CODEVIEW:
1652 case IMAGE_DEBUG_TYPE_MISC:
1654 * This is usually an indirection to a .DBG file.
1655 * This is similar to (but a slightly older format) from the
1656 * PDB file.
1658 * First check to see if the image was 'stripped'. If so, it
1659 * means that this entry points to a .DBG file. Otherwise,
1660 * it just points to itself, and we can ignore this.
1663 if( (dbg.Type != IMAGE_DEBUG_TYPE_MISC) ||
1664 (nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0 )
1667 * Read the important bits. What we do after this depends
1668 * upon the type, but this is always enough so we are able
1669 * to proceed if we know what we need to do next.
1671 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1672 * the DataDirectory array's content. One its entry contains the *beloved*
1673 * debug information. (Note the DataDirectory is mapped, not its content)
1675 HANDLE hMap;
1676 char* dbg_info;
1678 DEBUG_Printf(DBG_CHN_TRACE, "PE debugging info at %ld<%ld>\n", dbg.PointerToRawData, dbg.SizeOfData);
1679 dbg_info = DEBUG_MapDebugInfoFile(NULL, dbg.PointerToRawData, dbg.SizeOfData,
1680 &hFile, &hMap);
1682 if (dbg_info != NULL &&
1683 (module->extra_info = DBG_alloc(sizeof(MSC_DBG_INFO))) != NULL) {
1684 MSC_INFO(module)->dbg_info = dbg_info;
1685 MSC_INFO(module)->dbg_size = dbg.SizeOfData;
1686 MSC_INFO(module)->dbgdir = dbg;
1687 MSC_INFO(module)->sect_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1688 nth->FileHeader.SizeOfOptionalHeader;
1689 MSC_INFO(module)->nsect = nth->FileHeader.NumberOfSections;
1690 DEBUG_ProcessMSCDebugInfo(module);
1691 DBG_free(MSC_INFO(module));
1692 MSC_INFO(module) = NULL;
1694 DEBUG_UnmapDebugInfoFile(0, hMap, dbg_info);
1696 break;
1697 #if 0
1698 default:
1699 #endif
1701 v_addr += sizeof(dbg);
1703 DEBUG_CurrProcess->next_index++;
1706 return rtn;
1709 /* look for stabs information in PE header (it's how mingw compiler provides its
1710 * debugging information), and also wine PE <-> ELF linking thru .wsolnk sections
1712 int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth,
1713 unsigned long nth_ofs)
1715 IMAGE_SECTION_HEADER pe_seg;
1716 unsigned long pe_seg_ofs;
1717 int i, stabsize = 0, stabstrsize = 0;
1718 unsigned int stabs = 0, stabstr = 0;
1719 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1721 pe_seg_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1722 nth->FileHeader.SizeOfOptionalHeader;
1724 for (i = 0; i < nth->FileHeader.NumberOfSections; i++, pe_seg_ofs += sizeof(pe_seg)) {
1725 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + pe_seg_ofs),
1726 &pe_seg, sizeof(pe_seg)))
1727 continue;
1729 if (!strcasecmp(pe_seg.Name, ".stab")) {
1730 stabs = pe_seg.VirtualAddress;
1731 stabsize = pe_seg.SizeOfRawData;
1732 } else if (!strncasecmp(pe_seg.Name, ".stabstr", 8)) {
1733 stabstr = pe_seg.VirtualAddress;
1734 stabstrsize = pe_seg.SizeOfRawData;
1738 if (stabstrsize && stabsize) {
1739 char* s1 = DBG_alloc(stabsize+stabstrsize);
1741 if (s1) {
1742 if (DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabs, s1, stabsize) &&
1743 DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabstr,
1744 s1 + stabsize, stabstrsize)) {
1745 DEBUG_ParseStabs(s1, 0, 0, stabsize, stabsize, stabstrsize);
1746 } else {
1747 DEBUG_Printf(DBG_CHN_MESG, "couldn't read data block\n");
1749 DBG_free(s1);
1750 } else {
1751 DEBUG_Printf(DBG_CHN_MESG, "couldn't alloc %d bytes\n",
1752 stabsize + stabstrsize);
1755 return TRUE;
1759 * Process COFF debugging information embedded in a Win32 application.
1762 static
1764 DEBUG_ProcessCoff(DBG_MODULE* module)
1766 struct CoffAuxSection * aux;
1767 struct CoffDebug * coff;
1768 struct CoffFiles * coff_files = NULL;
1769 struct CoffLinenum * coff_linetab;
1770 char * coff_strtab;
1771 struct CoffSymbol * coff_sym;
1772 struct CoffSymbol * coff_symbol;
1773 struct CoffFiles * curr_file = NULL;
1774 int i;
1775 int j;
1776 int k;
1777 struct CoffLinenum * linepnt;
1778 int linetab_indx;
1779 char namebuff[9];
1780 char * nampnt;
1781 int naux;
1782 DBG_VALUE new_value;
1783 int nfiles = 0;
1784 int nfiles_alloc = 0;
1785 struct CoffFiles orig_file;
1786 int rtn = FALSE;
1787 char * this_file = NULL;
1789 coff = (struct CoffDebug *) MSC_INFO(module)->dbg_info;
1791 coff_symbol = (struct CoffSymbol *) ((unsigned int) coff + coff->SymbolOffset);
1792 coff_linetab = (struct CoffLinenum *) ((unsigned int) coff + coff->LinenumberOffset);
1793 coff_strtab = (char *) ((unsigned int) coff_symbol + 18*coff->N_Sym);
1795 linetab_indx = 0;
1797 new_value.cookie = DV_TARGET;
1798 new_value.type = NULL;
1800 for(i=0; i < coff->N_Sym; i++ )
1803 * We do this because some compilers (i.e. gcc) incorrectly
1804 * pad the structure up to a 4 byte boundary. The structure
1805 * is really only 18 bytes long, so we have to manually make sure
1806 * we get it right.
1808 * FIXME - there must be a way to have autoconf figure out the
1809 * correct compiler option for this. If it is always gcc, that
1810 * makes life simpler, but I don't want to force this.
1812 coff_sym = (struct CoffSymbol *) ((unsigned int) coff_symbol + 18*i);
1813 naux = coff_sym->NumberOfAuxSymbols;
1815 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
1817 if( nfiles + 1 >= nfiles_alloc )
1819 nfiles_alloc += 10;
1820 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1821 nfiles_alloc * sizeof(struct CoffFiles));
1823 curr_file = coff_files + nfiles;
1824 nfiles++;
1825 curr_file->startaddr = 0xffffffff;
1826 curr_file->endaddr = 0;
1827 curr_file->filename = ((char *) coff_sym) + 18;
1828 curr_file->linetab_offset = -1;
1829 curr_file->linecnt = 0;
1830 curr_file->entries = NULL;
1831 curr_file->neps = curr_file->neps_alloc = 0;
1832 DEBUG_Printf(DBG_CHN_TRACE,"New file %s\n", curr_file->filename);
1833 i += naux;
1834 continue;
1838 * This guy marks the size and location of the text section
1839 * for the current file. We need to keep track of this so
1840 * we can figure out what file the different global functions
1841 * go with.
1843 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1844 && (naux != 0)
1845 && (coff_sym->Type == 0)
1846 && (coff_sym->SectionNumber == 1) )
1848 aux = (struct CoffAuxSection *) ((unsigned int) coff_sym + 18);
1850 if( curr_file->linetab_offset != -1 )
1852 #if 0
1853 DEBUG_Printf(DBG_CHN_TRACE, "Duplicating sect from %s: %x %x %x %d %d\n",
1854 curr_file->filename,
1855 aux->Length,
1856 aux->NumberOfRelocations,
1857 aux->NumberOfLinenumbers,
1858 aux->Number,
1859 aux->Selection);
1860 DEBUG_Printf(DBG_CHN_TRACE, "More sect %d %x %d %d %d\n",
1861 coff_sym->SectionNumber,
1862 coff_sym->Value,
1863 coff_sym->Type,
1864 coff_sym->StorageClass,
1865 coff_sym->NumberOfAuxSymbols);
1866 #endif
1869 * Save this so we can copy bits from it.
1871 orig_file = *curr_file;
1874 * Duplicate the file entry. We have no way to describe
1875 * multiple text sections in our current way of handling things.
1877 if( nfiles + 1 >= nfiles_alloc )
1879 nfiles_alloc += 10;
1880 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1881 nfiles_alloc * sizeof(struct CoffFiles));
1883 curr_file = coff_files + nfiles;
1884 nfiles++;
1885 curr_file->startaddr = 0xffffffff;
1886 curr_file->endaddr = 0;
1887 curr_file->filename = orig_file.filename;
1888 curr_file->linetab_offset = -1;
1889 curr_file->linecnt = 0;
1890 curr_file->entries = NULL;
1891 curr_file->neps = curr_file->neps_alloc = 0;
1893 #if 0
1894 else
1896 DEBUG_Printf(DBG_CHN_TRACE, "New text sect from %s: %x %x %x %d %d\n",
1897 curr_file->filename,
1898 aux->Length,
1899 aux->NumberOfRelocations,
1900 aux->NumberOfLinenumbers,
1901 aux->Number,
1902 aux->Selection);
1904 #endif
1906 if( curr_file->startaddr > coff_sym->Value )
1908 curr_file->startaddr = coff_sym->Value;
1911 if( curr_file->startaddr > coff_sym->Value )
1913 curr_file->startaddr = coff_sym->Value;
1916 if( curr_file->endaddr < coff_sym->Value + aux->Length )
1918 curr_file->endaddr = coff_sym->Value + aux->Length;
1921 curr_file->linetab_offset = linetab_indx;
1922 curr_file->linecnt = aux->NumberOfLinenumbers;
1923 linetab_indx += aux->NumberOfLinenumbers;
1924 i += naux;
1925 continue;
1928 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1929 && (naux == 0)
1930 && (coff_sym->SectionNumber == 1) )
1933 * This is a normal static function when naux == 0.
1934 * Just register it. The current file is the correct
1935 * one in this instance.
1937 if( coff_sym->N.Name.NotLong )
1939 memcpy(namebuff, coff_sym->N.ShortName, 8);
1940 namebuff[8] = '\0';
1941 nampnt = &namebuff[0];
1943 else
1945 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1948 if( nampnt[0] == '_' )
1950 nampnt++;
1953 new_value.addr.seg = 0;
1954 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1956 if( curr_file->neps + 1 >= curr_file->neps_alloc )
1958 curr_file->neps_alloc += 10;
1959 curr_file->entries = (struct name_hash **)
1960 DBG_realloc(curr_file->entries,
1961 curr_file->neps_alloc * sizeof(struct name_hash *));
1963 #if 0
1964 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding static symbol %s\n", nampnt);
1965 #endif
1966 curr_file->entries[curr_file->neps++] =
1967 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
1968 i += naux;
1969 continue;
1972 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1973 && ISFCN(coff_sym->Type)
1974 && (coff_sym->SectionNumber > 0) )
1976 if( coff_sym->N.Name.NotLong )
1978 memcpy(namebuff, coff_sym->N.ShortName, 8);
1979 namebuff[8] = '\0';
1980 nampnt = &namebuff[0];
1982 else
1984 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1988 if( nampnt[0] == '_' )
1990 nampnt++;
1993 new_value.addr.seg = 0;
1994 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1996 #if 0
1997 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
1999 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global symbol %s\n", nampnt);
2000 #endif
2003 * Now we need to figure out which file this guy belongs to.
2005 this_file = NULL;
2006 for(j=0; j < nfiles; j++)
2008 if( coff_files[j].startaddr <= coff_sym->Value
2009 && coff_files[j].endaddr > coff_sym->Value )
2011 this_file = coff_files[j].filename;
2012 break;
2015 if( coff_files[j].neps + 1 >= coff_files[j].neps_alloc )
2017 coff_files[j].neps_alloc += 10;
2018 coff_files[j].entries = (struct name_hash **)
2019 DBG_realloc(coff_files[j].entries,
2020 coff_files[j].neps_alloc * sizeof(struct name_hash *));
2022 coff_files[j].entries[coff_files[j].neps++] =
2023 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
2024 i += naux;
2025 continue;
2028 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
2029 && (coff_sym->SectionNumber > 0) )
2032 * Similar to above, but for the case of data symbols.
2033 * These aren't treated as entrypoints.
2035 if( coff_sym->N.Name.NotLong )
2037 memcpy(namebuff, coff_sym->N.ShortName, 8);
2038 namebuff[8] = '\0';
2039 nampnt = &namebuff[0];
2041 else
2043 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
2047 if( nampnt[0] == '_' )
2049 nampnt++;
2052 new_value.addr.seg = 0;
2053 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
2055 #if 0
2056 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
2058 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global data symbol %s\n", nampnt);
2059 #endif
2062 * Now we need to figure out which file this guy belongs to.
2064 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 );
2065 i += naux;
2066 continue;
2069 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
2070 && (naux == 0) )
2073 * Ignore these. They don't have anything to do with
2074 * reality.
2076 i += naux;
2077 continue;
2080 #if 0
2081 DEBUG_Printf(DBG_CHN_TRACE,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
2082 coff_sym->SectionNumber, naux);
2083 #endif
2086 * For now, skip past the aux entries.
2088 i += naux;
2093 * OK, we now should have a list of files, and we should have a list
2094 * of entrypoints. We need to sort the entrypoints so that we are
2095 * able to tie the line numbers with the given functions within the
2096 * file.
2098 if( coff_files != NULL )
2100 for(j=0; j < nfiles; j++)
2102 if( coff_files[j].entries != NULL )
2104 qsort(coff_files[j].entries, coff_files[j].neps,
2105 sizeof(struct name_hash *), DEBUG_cmp_sym);
2110 * Now pick apart the line number tables, and attach the entries
2111 * to the given functions.
2113 for(j=0; j < nfiles; j++)
2115 i = 0;
2116 if( coff_files[j].neps != 0 )
2117 for(k=0; k < coff_files[j].linecnt; k++)
2120 * Another monstrosity caused by the fact that we are using
2121 * a 6 byte structure, and gcc wants to pad structures to 4 byte
2122 * boundaries. Otherwise we could just index into an array.
2124 linepnt = (struct CoffLinenum *)
2125 ((unsigned int) coff_linetab +
2126 6*(coff_files[j].linetab_offset + k));
2128 * If we have spilled onto the next entrypoint, then
2129 * bump the counter..
2131 while(TRUE)
2133 if (i+1 >= coff_files[j].neps) break;
2134 DEBUG_GetSymbolAddr(coff_files[j].entries[i+1], &new_value.addr);
2135 if( (((unsigned int)module->load_addr +
2136 linepnt->VirtualAddr) >= new_value.addr.off) )
2138 i++;
2139 } else break;
2143 * Add the line number. This is always relative to the
2144 * start of the function, so we need to subtract that offset
2145 * first.
2147 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_value.addr);
2148 DEBUG_AddLineNumber(coff_files[j].entries[i],
2149 linepnt->Linenum,
2150 (unsigned int) module->load_addr
2151 + linepnt->VirtualAddr
2152 - new_value.addr.off);
2157 rtn = TRUE;
2159 if( coff_files != NULL )
2161 for(j=0; j < nfiles; j++)
2163 if( coff_files[j].entries != NULL )
2165 DBG_free(coff_files[j].entries);
2168 DBG_free(coff_files);
2171 return (rtn);
2176 * Process a codeview line number table. Digestify the thing so that
2177 * we can easily reference the thing when we process the rest of
2178 * the information.
2180 static struct codeview_linetab_hdr *
2181 DEBUG_SnarfLinetab(char * linetab,
2182 int size)
2184 int file_segcount;
2185 char filename[PATH_MAX];
2186 unsigned int * filetab;
2187 char * fn;
2188 int i;
2189 int k;
2190 struct codeview_linetab_hdr * lt_hdr;
2191 unsigned int * lt_ptr;
2192 int nfile;
2193 int nseg;
2194 union any_size pnt;
2195 union any_size pnt2;
2196 struct startend * start;
2197 int this_seg;
2200 * Now get the important bits.
2202 pnt.c = linetab;
2203 nfile = *pnt.s++;
2204 nseg = *pnt.s++;
2206 filetab = (unsigned int *) pnt.c;
2209 * Now count up the number of segments in the file.
2211 nseg = 0;
2212 for(i=0; i<nfile; i++)
2214 pnt2.c = linetab + filetab[i];
2215 nseg += *pnt2.s;
2219 * Next allocate the header we will be returning.
2220 * There is one header for each segment, so that we can reach in
2221 * and pull bits as required.
2223 lt_hdr = (struct codeview_linetab_hdr *)
2224 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
2225 if( lt_hdr == NULL )
2227 goto leave;
2230 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
2233 * Now fill the header we will be returning, one for each segment.
2234 * Note that this will basically just contain pointers into the existing
2235 * line table, and we do not actually copy any additional information
2236 * or allocate any additional memory.
2239 this_seg = 0;
2240 for(i=0; i<nfile; i++)
2243 * Get the pointer into the segment information.
2245 pnt2.c = linetab + filetab[i];
2246 file_segcount = *pnt2.s;
2248 pnt2.ui++;
2249 lt_ptr = (unsigned int *) pnt2.c;
2250 start = (struct startend *) (lt_ptr + file_segcount);
2253 * Now snarf the filename for all of the segments for this file.
2255 fn = (unsigned char *) (start + file_segcount);
2256 memset(filename, 0, sizeof(filename));
2257 memcpy(filename, fn + 1, *fn);
2258 fn = DBG_strdup(filename);
2260 for(k = 0; k < file_segcount; k++, this_seg++)
2262 pnt2.c = linetab + lt_ptr[k];
2263 lt_hdr[this_seg].start = start[k].start;
2264 lt_hdr[this_seg].end = start[k].end;
2265 lt_hdr[this_seg].sourcefile = fn;
2266 lt_hdr[this_seg].segno = *pnt2.s++;
2267 lt_hdr[this_seg].nline = *pnt2.s++;
2268 lt_hdr[this_seg].offtab = pnt2.ui;
2269 lt_hdr[this_seg].linetab = (unsigned short *)
2270 (pnt2.ui + lt_hdr[this_seg].nline);
2274 leave:
2276 return lt_hdr;
2280 static int
2281 DEBUG_SnarfCodeView( DBG_MODULE * module,
2282 char * cv_data,
2283 int size,
2284 struct codeview_linetab_hdr * linetab)
2286 struct name_hash * curr_func = NULL;
2287 struct wine_locals * curr_sym = NULL;
2288 int i;
2289 int j;
2290 int len;
2291 DBG_VALUE new_value;
2292 int nsect;
2293 union any_size ptr;
2294 IMAGE_SECTION_HEADER * sectp;
2295 union codeview_symbol * sym;
2296 char symname[PATH_MAX];
2297 struct name_hash * thunk_sym = NULL;
2299 ptr.c = cv_data;
2300 nsect = MSC_INFO(module)->nsect;
2301 sectp = DBG_alloc(sizeof(*sectp) * nsect);
2302 if (!sectp ||
2303 !DEBUG_READ_MEM_VERBOSE((char *)module->load_addr + MSC_INFO(module)->sect_ofs,
2304 sectp, sizeof(*sectp) * nsect))
2305 return FALSE;
2308 * Loop over the different types of records and whenever we
2309 * find something we are interested in, record it and move on.
2311 while( ptr.c - cv_data < size )
2313 sym = (union codeview_symbol *) ptr.c;
2315 if( sym->generic.len - sizeof(int) == (ptr.c - cv_data) )
2318 * This happens when we have indirect symbols that VC++ 4.2
2319 * sometimes uses when there isn't a line number table.
2320 * We ignore it - we will process and enter all of the
2321 * symbols in the global symbol table anyways, so there
2322 * isn't much point in keeping track of all of this crap.
2324 break;
2327 memset(symname, 0, sizeof(symname));
2328 switch(sym->generic.id)
2330 case S_GDATA:
2331 case S_LDATA:
2332 case S_PUB:
2334 * First, a couple of sanity checks.
2336 if( sym->data.namelen == 0 )
2338 break;
2341 if( sym->data.seg == 0 || sym->data.seg > nsect )
2343 break;
2347 * Global and local data symbols. We don't associate these
2348 * with any given source file.
2351 memcpy(symname, sym->data.name, sym->data.namelen);
2352 new_value.addr.seg = 0;
2353 new_value.type = DEBUG_GetCVType(sym->data.symtype);
2354 new_value.addr.off = (unsigned int) module->load_addr +
2355 sectp[sym->data.seg - 1].VirtualAddress +
2356 sym->data.offset;
2357 new_value.cookie = DV_TARGET;
2358 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2359 break;
2360 case S_GDATA_32:
2361 case S_LDATA_32:
2362 case S_PUB_32:
2364 * First, a couple of sanity checks.
2366 if( sym->data32.namelen == 0 )
2368 break;
2371 if( sym->data32.seg == 0 || sym->data32.seg > nsect )
2373 break;
2377 * Global and local data symbols. We don't associate these
2378 * with any given source file.
2381 memcpy(symname, sym->data32.name, sym->data32.namelen);
2382 new_value.addr.seg = 0;
2383 new_value.type = DEBUG_GetCVType(sym->data32.symtype);
2384 new_value.addr.off = (unsigned int) module->load_addr +
2385 sectp[sym->data32.seg - 1].VirtualAddress +
2386 sym->data32.offset;
2387 new_value.cookie = DV_TARGET;
2388 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2389 break;
2390 case S_THUNK:
2392 * Sort of like a global function, but it just points
2393 * to a thunk, which is a stupid name for what amounts to
2394 * a PLT slot in the normal jargon that everyone else uses.
2396 memcpy(symname, sym->thunk.name, sym->thunk.namelen);
2397 new_value.addr.seg = 0;
2398 new_value.type = NULL;
2399 new_value.addr.off = (unsigned int) module->load_addr +
2400 sectp[sym->thunk.segment - 1].VirtualAddress +
2401 sym->thunk.offset;
2402 new_value.cookie = DV_TARGET;
2403 thunk_sym = DEBUG_AddSymbol( symname, &new_value, NULL,
2404 SYM_WIN32 | SYM_FUNC);
2405 DEBUG_SetSymbolSize(thunk_sym, sym->thunk.thunk_len);
2406 break;
2407 case S_GPROC:
2408 case S_LPROC:
2410 * Global and static functions.
2412 memcpy(symname, sym->proc.name, sym->proc.namelen);
2413 new_value.addr.seg = 0;
2414 new_value.type = DEBUG_GetCVType(sym->proc.proctype);
2415 new_value.addr.off = (unsigned int) module->load_addr +
2416 sectp[sym->proc.segment - 1].VirtualAddress +
2417 sym->proc.offset;
2418 new_value.cookie = DV_TARGET;
2420 * See if we can find a segment that this goes with. If so,
2421 * it means that we also may have line number information
2422 * for this function.
2424 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2426 if( ((unsigned int) module->load_addr
2427 + sectp[linetab[i].segno - 1].VirtualAddress
2428 + linetab[i].start <= new_value.addr.off)
2429 && ((unsigned int) module->load_addr
2430 + sectp[linetab[i].segno - 1].VirtualAddress
2431 + linetab[i].end > new_value.addr.off) )
2433 break;
2437 DEBUG_Normalize(curr_func);
2438 if( !linetab || linetab[i].linetab == NULL )
2440 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2441 SYM_WIN32 | SYM_FUNC);
2443 else
2446 * First, create the entry. Then dig through the linetab
2447 * and add whatever line numbers are appropriate for this
2448 * function.
2450 curr_func = DEBUG_AddSymbol( symname, &new_value,
2451 linetab[i].sourcefile,
2452 SYM_WIN32 | SYM_FUNC);
2453 for(j=0; j < linetab[i].nline; j++)
2455 if( linetab[i].offtab[j] >= sym->proc.offset
2456 && linetab[i].offtab[j] < sym->proc.offset
2457 + sym->proc.proc_len )
2459 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2460 linetab[i].offtab[j] - sym->proc.offset);
2467 * Add information about where we should set breakpoints
2468 * in this function.
2470 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
2471 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
2472 break;
2473 case S_GPROC_32:
2474 case S_LPROC_32:
2476 * Global and static functions.
2478 memcpy(symname, sym->proc32.name, sym->proc32.namelen);
2479 new_value.addr.seg = 0;
2480 new_value.type = DEBUG_GetCVType(sym->proc32.proctype);
2481 new_value.addr.off = (unsigned int) module->load_addr +
2482 sectp[sym->proc32.segment - 1].VirtualAddress +
2483 sym->proc32.offset;
2484 new_value.cookie = DV_TARGET;
2486 * See if we can find a segment that this goes with. If so,
2487 * it means that we also may have line number information
2488 * for this function.
2490 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2492 if( ((unsigned int) module->load_addr
2493 + sectp[linetab[i].segno - 1].VirtualAddress
2494 + linetab[i].start <= new_value.addr.off)
2495 && ((unsigned int) module->load_addr
2496 + sectp[linetab[i].segno - 1].VirtualAddress
2497 + linetab[i].end > new_value.addr.off) )
2499 break;
2503 DEBUG_Normalize(curr_func);
2504 if( !linetab || linetab[i].linetab == NULL )
2506 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2507 SYM_WIN32 | SYM_FUNC);
2509 else
2512 * First, create the entry. Then dig through the linetab
2513 * and add whatever line numbers are appropriate for this
2514 * function.
2516 curr_func = DEBUG_AddSymbol( symname, &new_value,
2517 linetab[i].sourcefile,
2518 SYM_WIN32 | SYM_FUNC);
2519 for(j=0; j < linetab[i].nline; j++)
2521 if( linetab[i].offtab[j] >= sym->proc32.offset
2522 && linetab[i].offtab[j] < sym->proc32.offset
2523 + sym->proc32.proc_len )
2525 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2526 linetab[i].offtab[j] - sym->proc32.offset);
2533 * Add information about where we should set breakpoints
2534 * in this function.
2536 DEBUG_SetSymbolBPOff(curr_func, sym->proc32.debug_start);
2537 DEBUG_SetSymbolSize(curr_func, sym->proc32.proc_len);
2538 break;
2539 case S_BPREL:
2541 * Function parameters and stack variables.
2543 memcpy(symname, sym->stack.name, sym->stack.namelen);
2544 curr_sym = DEBUG_AddLocal(curr_func,
2546 sym->stack.offset,
2549 symname);
2550 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
2552 break;
2553 case S_BPREL_32:
2555 * Function parameters and stack variables.
2557 memcpy(symname, sym->stack32.name, sym->stack32.namelen);
2558 curr_sym = DEBUG_AddLocal(curr_func,
2560 sym->stack32.offset,
2563 symname);
2564 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack32.symtype));
2566 break;
2567 default:
2568 break;
2572 * Adjust pointer to point to next entry, rounding up to a word
2573 * boundary. MS preserving alignment? Stranger things have
2574 * happened.
2576 if( sym->generic.id == S_PROCREF
2577 || sym->generic.id == S_DATAREF
2578 || sym->generic.id == S_LPROCREF )
2580 len = (sym->generic.len + 3) & ~3;
2581 len += ptr.c[16] + 1;
2582 ptr.c += (len + 3) & ~3;
2584 else
2586 ptr.c += (sym->generic.len + 3) & ~3;
2590 if( linetab != NULL )
2592 DBG_free(linetab);
2595 DBG_free(sectp);
2596 return TRUE;
2601 * Process PDB file which contains debug information.
2604 #pragma pack(1)
2605 typedef struct _PDB_FILE
2607 DWORD size;
2608 DWORD unknown;
2610 } PDB_FILE, *PPDB_FILE;
2612 typedef struct _PDB_HEADER
2614 CHAR ident[40];
2615 DWORD signature;
2616 DWORD blocksize;
2617 WORD freelist;
2618 WORD total_alloc;
2619 PDB_FILE toc;
2620 WORD toc_block[ 1 ];
2622 } PDB_HEADER, *PPDB_HEADER;
2624 typedef struct _PDB_TOC
2626 DWORD nFiles;
2627 PDB_FILE file[ 1 ];
2629 } PDB_TOC, *PPDB_TOC;
2631 typedef struct _PDB_ROOT
2633 DWORD version;
2634 DWORD TimeDateStamp;
2635 DWORD unknown;
2636 DWORD cbNames;
2637 CHAR names[ 1 ];
2639 } PDB_ROOT, *PPDB_ROOT;
2641 typedef struct _PDB_TYPES_OLD
2643 DWORD version;
2644 WORD first_index;
2645 WORD last_index;
2646 DWORD type_size;
2647 WORD file;
2648 WORD pad;
2650 } PDB_TYPES_OLD, *PPDB_TYPES_OLD;
2652 typedef struct _PDB_TYPES
2654 DWORD version;
2655 DWORD type_offset;
2656 DWORD first_index;
2657 DWORD last_index;
2658 DWORD type_size;
2659 WORD file;
2660 WORD pad;
2661 DWORD hash_size;
2662 DWORD hash_base;
2663 DWORD hash_offset;
2664 DWORD hash_len;
2665 DWORD search_offset;
2666 DWORD search_len;
2667 DWORD unknown_offset;
2668 DWORD unknown_len;
2670 } PDB_TYPES, *PPDB_TYPES;
2672 typedef struct _PDB_SYMBOL_RANGE
2674 WORD segment;
2675 WORD pad1;
2676 DWORD offset;
2677 DWORD size;
2678 DWORD characteristics;
2679 WORD index;
2680 WORD pad2;
2682 } PDB_SYMBOL_RANGE, *PPDB_SYMBOL_RANGE;
2684 typedef struct _PDB_SYMBOL_RANGE_EX
2686 WORD segment;
2687 WORD pad1;
2688 DWORD offset;
2689 DWORD size;
2690 DWORD characteristics;
2691 WORD index;
2692 WORD pad2;
2693 DWORD timestamp;
2694 DWORD unknown;
2696 } PDB_SYMBOL_RANGE_EX, *PPDB_SYMBOL_RANGE_EX;
2698 typedef struct _PDB_SYMBOL_FILE
2700 DWORD unknown1;
2701 PDB_SYMBOL_RANGE range;
2702 WORD flag;
2703 WORD file;
2704 DWORD symbol_size;
2705 DWORD lineno_size;
2706 DWORD unknown2;
2707 DWORD nSrcFiles;
2708 DWORD attribute;
2709 CHAR filename[ 1 ];
2711 } PDB_SYMBOL_FILE, *PPDB_SYMBOL_FILE;
2713 typedef struct _PDB_SYMBOL_FILE_EX
2715 DWORD unknown1;
2716 PDB_SYMBOL_RANGE_EX range;
2717 WORD flag;
2718 WORD file;
2719 DWORD symbol_size;
2720 DWORD lineno_size;
2721 DWORD unknown2;
2722 DWORD nSrcFiles;
2723 DWORD attribute;
2724 DWORD reserved[ 2 ];
2725 CHAR filename[ 1 ];
2727 } PDB_SYMBOL_FILE_EX, *PPDB_SYMBOL_FILE_EX;
2729 typedef struct _PDB_SYMBOL_SOURCE
2731 WORD nModules;
2732 WORD nSrcFiles;
2733 WORD table[ 1 ];
2735 } PDB_SYMBOL_SOURCE, *PPDB_SYMBOL_SOURCE;
2737 typedef struct _PDB_SYMBOL_IMPORT
2739 DWORD unknown1;
2740 DWORD unknown2;
2741 DWORD TimeDateStamp;
2742 DWORD nRequests;
2743 CHAR filename[ 1 ];
2745 } PDB_SYMBOL_IMPORT, *PPDB_SYMBOL_IMPORT;
2747 typedef struct _PDB_SYMBOLS_OLD
2749 WORD hash1_file;
2750 WORD hash2_file;
2751 WORD gsym_file;
2752 WORD pad;
2753 DWORD module_size;
2754 DWORD offset_size;
2755 DWORD hash_size;
2756 DWORD srcmodule_size;
2758 } PDB_SYMBOLS_OLD, *PPDB_SYMBOLS_OLD;
2760 typedef struct _PDB_SYMBOLS
2762 DWORD signature;
2763 DWORD version;
2764 DWORD unknown;
2765 DWORD hash1_file;
2766 DWORD hash2_file;
2767 DWORD gsym_file;
2768 DWORD module_size;
2769 DWORD offset_size;
2770 DWORD hash_size;
2771 DWORD srcmodule_size;
2772 DWORD pdbimport_size;
2773 DWORD resvd[ 5 ];
2775 } PDB_SYMBOLS, *PPDB_SYMBOLS;
2776 #pragma pack()
2779 static void *pdb_read( LPBYTE image, WORD *block_list, int size )
2781 PPDB_HEADER pdb = (PPDB_HEADER)image;
2782 int i, nBlocks;
2783 LPBYTE buffer;
2785 if ( !size ) return NULL;
2787 nBlocks = (size + pdb->blocksize-1) / pdb->blocksize;
2788 buffer = DBG_alloc( nBlocks * pdb->blocksize );
2790 for ( i = 0; i < nBlocks; i++ )
2791 memcpy( buffer + i*pdb->blocksize,
2792 image + block_list[i]*pdb->blocksize, pdb->blocksize );
2794 return buffer;
2797 static void *pdb_read_file( LPBYTE image, PPDB_TOC toc, int fileNr )
2799 PPDB_HEADER pdb = (PPDB_HEADER)image;
2800 WORD *block_list;
2801 int i;
2803 if ( !toc || fileNr >= toc->nFiles )
2804 return NULL;
2806 block_list = (WORD *) &toc->file[ toc->nFiles ];
2807 for ( i = 0; i < fileNr; i++ )
2808 block_list += (toc->file[i].size + pdb->blocksize-1) / pdb->blocksize;
2810 return pdb_read( image, block_list, toc->file[fileNr].size );
2813 static void pdb_free( void *buffer )
2815 DBG_free( buffer );
2818 static void pdb_convert_types_header( PDB_TYPES *types, char *image )
2820 memset( types, 0, sizeof(PDB_TYPES) );
2821 if ( !image ) return;
2823 if ( *(DWORD *)image < 19960000 ) /* FIXME: correct version? */
2825 /* Old version of the types record header */
2826 PDB_TYPES_OLD *old = (PDB_TYPES_OLD *)image;
2827 types->version = old->version;
2828 types->type_offset = sizeof(PDB_TYPES_OLD);
2829 types->type_size = old->type_size;
2830 types->first_index = old->first_index;
2831 types->last_index = old->last_index;
2832 types->file = old->file;
2834 else
2836 /* New version of the types record header */
2837 *types = *(PDB_TYPES *)image;
2841 static void pdb_convert_symbols_header( PDB_SYMBOLS *symbols,
2842 int *header_size, char *image )
2844 memset( symbols, 0, sizeof(PDB_SYMBOLS) );
2845 if ( !image ) return;
2847 if ( *(DWORD *)image != 0xffffffff )
2849 /* Old version of the symbols record header */
2850 PDB_SYMBOLS_OLD *old = (PDB_SYMBOLS_OLD *)image;
2851 symbols->version = 0;
2852 symbols->module_size = old->module_size;
2853 symbols->offset_size = old->offset_size;
2854 symbols->hash_size = old->hash_size;
2855 symbols->srcmodule_size = old->srcmodule_size;
2856 symbols->pdbimport_size = 0;
2857 symbols->hash1_file = old->hash1_file;
2858 symbols->hash2_file = old->hash2_file;
2859 symbols->gsym_file = old->gsym_file;
2861 *header_size = sizeof(PDB_SYMBOLS_OLD);
2863 else
2865 /* New version of the symbols record header */
2866 *symbols = *(PDB_SYMBOLS *)image;
2868 *header_size = sizeof(PDB_SYMBOLS);
2872 static int DEBUG_ProcessPDBFile( DBG_MODULE* module, const char *full_filename )
2874 HANDLE hFile, hMap;
2875 char *image = NULL;
2876 PDB_HEADER *pdb = NULL;
2877 PDB_TOC *toc = NULL;
2878 PDB_ROOT *root = NULL;
2879 char *types_image = NULL;
2880 char *symbols_image = NULL;
2881 PDB_TYPES types;
2882 PDB_SYMBOLS symbols;
2883 int header_size = 0;
2884 char *modimage, *file;
2886 DEBUG_Printf(DBG_CHN_TRACE, "Processing PDB file %s\n", full_filename);
2889 * Open and map() .PDB file
2891 if ((image = DEBUG_MapDebugInfoFile(full_filename, 0, 0, &hFile, &hMap)) == NULL) {
2892 DEBUG_Printf( DBG_CHN_ERR, "-Unable to peruse .PDB file %s\n", full_filename );
2893 goto leave;
2897 * Read in TOC and well-known files
2900 pdb = (PPDB_HEADER)image;
2901 toc = pdb_read( image, pdb->toc_block, pdb->toc.size );
2902 root = pdb_read_file( image, toc, 1 );
2903 types_image = pdb_read_file( image, toc, 2 );
2904 symbols_image = pdb_read_file( image, toc, 3 );
2906 pdb_convert_types_header( &types, types_image );
2907 pdb_convert_symbols_header( &symbols, &header_size, symbols_image );
2910 * Check for unknown versions
2913 switch ( root->version )
2915 case 19950623: /* VC 4.0 */
2916 case 19950814:
2917 case 19960307: /* VC 5.0 */
2918 case 19970604: /* VC 6.0 */
2919 break;
2920 default:
2921 DEBUG_Printf( DBG_CHN_ERR, "-Unknown root block version %ld\n", root->version );
2924 switch ( types.version )
2926 case 19950410: /* VC 4.0 */
2927 case 19951122:
2928 case 19961031: /* VC 5.0 / 6.0 */
2929 break;
2930 default:
2931 DEBUG_Printf( DBG_CHN_ERR, "-Unknown type info version %ld\n", types.version );
2934 switch ( symbols.version )
2936 case 0: /* VC 4.0 */
2937 case 19960307: /* VC 5.0 */
2938 case 19970606: /* VC 6.0 */
2939 break;
2940 default:
2941 DEBUG_Printf( DBG_CHN_ERR, "-Unknown symbol info version %ld\n", symbols.version );
2946 * Check .PDB time stamp
2949 if ( root->TimeDateStamp
2950 != ((struct CodeViewDebug *)MSC_INFO(module)->dbg_info)->cv_timestamp )
2952 /* the timestamp seems to be wrong often (we may read the file wrong)*/
2953 DEBUG_Printf(DBG_CHN_MESG, "-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08x)\n",
2954 full_filename, root->TimeDateStamp,
2955 ((struct CodeViewDebug *)MSC_INFO(module)->dbg_info)->cv_timestamp);
2959 * Read type table
2962 DEBUG_ParseTypeTable( types_image + types.type_offset, types.type_size );
2965 * Read type-server .PDB imports
2968 if ( symbols.pdbimport_size )
2970 /* FIXME */
2971 DEBUG_Printf(DBG_CHN_ERR, "-Type server .PDB imports ignored!\n" );
2975 * Read global symbol table
2978 modimage = pdb_read_file( image, toc, symbols.gsym_file );
2979 if ( modimage )
2981 DEBUG_SnarfCodeView( module, modimage,
2982 toc->file[symbols.gsym_file].size, NULL );
2983 pdb_free( modimage );
2987 * Read per-module symbol / linenumber tables
2990 file = symbols_image + header_size;
2991 while ( file - symbols_image < header_size + symbols.module_size )
2993 int file_nr, file_index, symbol_size, lineno_size;
2994 char *file_name;
2996 if ( symbols.version < 19970000 )
2998 PDB_SYMBOL_FILE *sym_file = (PDB_SYMBOL_FILE *) file;
2999 file_nr = sym_file->file;
3000 file_name = sym_file->filename;
3001 file_index = sym_file->range.index;
3002 symbol_size = sym_file->symbol_size;
3003 lineno_size = sym_file->lineno_size;
3005 else
3007 PDB_SYMBOL_FILE_EX *sym_file = (PDB_SYMBOL_FILE_EX *) file;
3008 file_nr = sym_file->file;
3009 file_name = sym_file->filename;
3010 file_index = sym_file->range.index;
3011 symbol_size = sym_file->symbol_size;
3012 lineno_size = sym_file->lineno_size;
3015 modimage = pdb_read_file( image, toc, file_nr );
3016 if ( modimage )
3018 struct codeview_linetab_hdr *linetab = NULL;
3020 if ( lineno_size )
3021 linetab = DEBUG_SnarfLinetab( modimage + symbol_size, lineno_size );
3023 if ( symbol_size )
3024 DEBUG_SnarfCodeView( module, modimage + sizeof(DWORD),
3025 symbol_size - sizeof(DWORD), linetab );
3027 pdb_free( modimage );
3030 file_name += strlen(file_name) + 1;
3031 file = (char *)( (DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3 );
3035 leave:
3038 * Cleanup
3041 DEBUG_ClearTypeTable();
3043 if ( symbols_image ) pdb_free( symbols_image );
3044 if ( types_image ) pdb_free( types_image );
3045 if ( root ) pdb_free( root );
3046 if ( toc ) pdb_free( toc );
3048 DEBUG_UnmapDebugInfoFile(hFile, hMap, image);
3050 return TRUE;
3055 * Process DBG file which contains debug information.
3057 static
3059 DEBUG_ProcessDBGFile(DBG_MODULE* module, const char* filename)
3061 HANDLE hFile, hMap;
3062 char * addr;
3063 PIMAGE_DEBUG_DIRECTORY dbghdr;
3064 DBG_MODULE module2;
3065 MSC_DBG_INFO extra_info2;
3066 int i;
3067 int j;
3068 int nsect;
3069 PIMAGE_SEPARATE_DEBUG_HEADER pdbg = NULL;
3070 IMAGE_SECTION_HEADER * sectp;
3072 if ((addr = DEBUG_MapDebugInfoFile(filename, 0, 0, &hFile, &hMap)) == NULL) {
3073 DEBUG_Printf(DBG_CHN_ERR, "-Unable to peruse .DBG file %s\n", filename);
3074 goto leave;
3077 pdbg = (PIMAGE_SEPARATE_DEBUG_HEADER) addr;
3079 if( pdbg->TimeDateStamp != MSC_INFO(module)->dbgdir.TimeDateStamp )
3081 DEBUG_Printf(DBG_CHN_ERR, "Warning - %s has incorrect internal timestamp\n",
3082 filename);
3083 /* goto leave; */
3085 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
3086 files but nonetheless this check fails. Anyway, WINDBG (debugger for
3087 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
3091 DEBUG_Printf(DBG_CHN_MESG, "Processing symbols from %s...\n", filename);
3093 dbghdr = (PIMAGE_DEBUG_DIRECTORY) ( addr + sizeof(*pdbg)
3094 + pdbg->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
3095 + pdbg->ExportedNamesSize);
3097 sectp = (PIMAGE_SECTION_HEADER) ((char *) pdbg + sizeof(*pdbg));
3098 nsect = pdbg->NumberOfSections;
3100 for( i=0; i < pdbg->DebugDirectorySize / sizeof(*pdbg); i++, dbghdr++ )
3102 switch(dbghdr->Type)
3104 case IMAGE_DEBUG_TYPE_COFF:
3106 * Dummy up a deferred debug header to handle the
3107 * COFF stuff embedded within the DBG file.
3109 memset((char *) &module2, 0, sizeof(module2));
3110 module2.extra_info = &extra_info2;
3111 MSC_INFO(&module2)->dbg_info = (addr + dbghdr->PointerToRawData);
3112 MSC_INFO(&module2)->dbg_size = dbghdr->SizeOfData;
3113 module2.load_addr = module->load_addr;
3115 DEBUG_ProcessCoff(&module2);
3116 break;
3117 case IMAGE_DEBUG_TYPE_CODEVIEW:
3119 char * codeview;
3120 struct CV4_DirHead * codeview_dir;
3121 struct CV4_DirEnt * codeview_dent;
3122 struct codeview_linetab_hdr * linetab;
3123 struct CodeViewDebug * cvd;
3125 cvd = (struct CodeViewDebug *) (addr + dbghdr->PointerToRawData);
3128 * see msdn.microsoft.com/library/specs/S66EA.HTM
3129 * for desriptions of more NBxx formats
3131 if( strcmp(cvd->cv_nbtype, "NB10") == 0 )
3134 * The debug information resides in a seperate pdb file.
3135 * This section contains only a filename.
3137 DEBUG_ProcessPDBFile(module, cvd->cv_name);
3139 else if (strcmp(cvd->cv_nbtype, "NB09") == 0 )
3142 * CodeView 4.10
3143 * This is the older format by which codeview stuff is
3144 * stored, known as the 'NB09' format. Newer executables
3145 * and dlls created by VC++ use PDB files instead, which
3146 * have lots of internal similarities, but the overall
3147 * format and structure is quite different.
3149 codeview = (addr + dbghdr->PointerToRawData);
3153 * We need to find the directory. This is easy too.
3155 codeview_dir = (struct CV4_DirHead *)
3156 (codeview + ((unsigned int*) codeview)[1]);
3159 * Some more sanity checks. Make sure that everything
3160 * is as we expect it.
3162 if( codeview_dir->next_offset != 0
3163 || codeview_dir->dhsize != sizeof(*codeview_dir)
3164 || codeview_dir->desize != sizeof(*codeview_dent) )
3166 break;
3168 codeview_dent = (struct CV4_DirEnt *) (codeview_dir + 1);
3170 for(j=0; j < codeview_dir->ndir; j++, codeview_dent++)
3172 if( codeview_dent->subsect_number == sstAlignSym )
3175 * Check the previous entry. If it is a
3176 * sstSrcModule, it contains the line number
3177 * info for this file.
3179 linetab = NULL;
3180 if( codeview_dent[1].module_number == codeview_dent[0].module_number
3181 && codeview_dent[1].subsect_number == sstSrcModule )
3183 linetab = DEBUG_SnarfLinetab(
3184 codeview + codeview_dent[1].offset,
3185 codeview_dent[1].size);
3188 if( codeview_dent[-1].module_number == codeview_dent[0].module_number
3189 && codeview_dent[-1].subsect_number == sstSrcModule )
3191 linetab = DEBUG_SnarfLinetab(
3192 codeview + codeview_dent[-1].offset,
3193 codeview_dent[-1].size);
3196 * Now process the CV stuff.
3198 DEBUG_SnarfCodeView(module,
3199 codeview + codeview_dent->offset + sizeof(DWORD),
3200 codeview_dent->size - sizeof(DWORD),
3201 linetab);
3205 else
3207 DEBUG_Printf(DBG_CHN_ERR, "Unknown CODEVIEW type %s in module %s\n",
3208 cvd->cv_nbtype, module->module_name);
3211 break;
3212 default:
3213 break;
3216 leave:
3218 DEBUG_UnmapDebugInfoFile(hFile, hMap, addr);
3220 return TRUE;
3223 static int
3224 DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module)
3226 struct CodeViewDebug * cvd;
3227 struct MiscDebug * misc;
3228 char * filename;
3229 int sts;
3231 switch (MSC_INFO(module)->dbgdir.Type)
3233 case IMAGE_DEBUG_TYPE_COFF:
3235 * Standard COFF debug information that VC++ adds when you
3236 * use /debugtype:both with the linker.
3238 DEBUG_Printf(DBG_CHN_TRACE, "Processing COFF symbols...\n");
3239 sts = DEBUG_ProcessCoff(module);
3240 break;
3241 case IMAGE_DEBUG_TYPE_CODEVIEW:
3243 * This is a pointer to a PDB file of some sort.
3245 cvd = (struct CodeViewDebug *) MSC_INFO(module)->dbg_info;
3247 if( strcmp(cvd->cv_nbtype, "NB10") != 0 )
3250 * Whatever this is, we don't know how to deal with
3251 * it yet.
3253 sts = FALSE;
3254 DEBUG_Printf(DBG_CHN_ERR, "Unknown CODEVIEW type %s in module %s\n",
3255 cvd->cv_nbtype, module->module_name);
3256 break;
3258 sts = DEBUG_ProcessPDBFile(module, cvd->cv_name);
3259 break;
3260 case IMAGE_DEBUG_TYPE_MISC:
3262 * A pointer to a .DBG file of some sort. These files
3263 * can contain either CV4 or COFF information. Open
3264 * the file, and try to do the right thing with it.
3266 misc = (struct MiscDebug *) MSC_INFO(module)->dbg_info;
3268 filename = strrchr((char *) &misc->Data, '.');
3271 * Ignore the file if it doesn't have a .DBG extension.
3273 if( (filename == NULL)
3274 || ( (strcmp(filename, ".dbg") != 0)
3275 && (strcmp(filename, ".DBG") != 0)) )
3277 sts = FALSE;
3278 break;
3281 filename = (char *) &misc->Data;
3284 * Do the dirty deed...
3286 sts = DEBUG_ProcessDBGFile(module, filename);
3288 break;
3289 default:
3291 * We should never get here...
3293 sts = FALSE;
3294 break;
3296 module->status = (sts) ? DM_STATUS_LOADED : DM_STATUS_ERROR;
3297 return sts;