2 * Functions to process in-memory arrays of CodeView data sections
3 * (currently only contains sstSrcModule).
5 * Copyright 2000 John R. Sheets
8 /* FIXME - Change to cvprint.c */
16 #include "cvinclude.h"
18 /************************ sstSrcModule ************************/
20 /* Print out stuff in OMFSourceModule block. Rather than using the supplied
21 * OMFSourceModule struct, we'll extract each piece of data separately from
22 * the block of memory (rawdata). This struct (and the others used in
23 * sstSrcModule sections) is pretty useless. We can't use sizeof() on it
24 * because it contains the first element of the file offset array (i.e. baseSrcFile),
25 * which we need to parse separately anyway. See below for problems with the
28 * The contents of this section look like this (the first two fields are
29 * already extracted and passed in as parameters):
31 * unsigned short cFile
33 * unsigned long baseSrcFile[cFile]
34 * unsigned long segarray[cSeg * 2]
35 * unsigned short segindexarray[cSeg]
37 int PrintSrcModuleInfo (BYTE
* rawdata
, short *filecount
, short *segcount
)
44 unsigned long *baseSrcFile
;
45 unsigned long *segarray
;
46 unsigned short *segindexarray
;
48 /* Get all our pointers straightened out
50 cFile
= *(short*)rawdata
;
51 cSeg
= *(short*)(rawdata
+ 2);
52 baseSrcFile
= (long*)(rawdata
+ 4);
53 segarray
= &baseSrcFile
[cFile
];
54 segindexarray
= (short*)(&segarray
[cSeg
* 2]);
56 /* Pass # of segments and files back to calling function
61 printf ("\n Module table: Found %d file(s) and %d segment(s)\n", cFile
, cSeg
);
62 for (i
= 0; i
< cFile
; i
++)
64 printf (" File #%d begins at an offset of 0x%lx in this section\n",
65 i
+ 1, baseSrcFile
[i
]);
68 for (i
= 0; i
< cSeg
; i
++)
70 printf (" Segment #%d start = 0x%lx, end = 0x%lx, seg index = %d\n",
71 i
+ 1, segarray
[i
* 2], segarray
[(i
* 2) + 1], segindexarray
[i
]);
74 /* Return the total length of the data (in bytes) that we used, so
75 * we'll know how far to jump ahead for the next part of the sstSrcModule.
77 datalen
= ((BYTE
*)(&segindexarray
[cSeg
]) - rawdata
);
78 /* printf ("datalen before padding = %d\n", datalen); */
80 datalen
+= 4 - (datalen
% 4);
81 /* printf ("datalen after padding = %d\n", datalen); */
86 /* Print out the contents of a OMFSourceFile block. Unfortunately, the official
87 * version of this struct (probably quite outdated) claims that the 'cFName' field
88 * is a short. Based on experimentation with MSVC 5.0 .DBG files, this field is
89 * quite clearly only a single byte. Yet another reason to do it all by hand
90 * and avoid the "official" structs.
92 * The contents of this section look like this (the first field is
93 * pre-extracted, and 'pad' is ignored):
97 * unsigned long baseSrcLn[cSeg]
98 * unsigned long segarray[cSeg * 2]
102 int PrintSrcModuleFileInfo (BYTE
* rawdata
)
108 unsigned long *baseSrcLn
;
109 unsigned long *segarray
;
110 unsigned char cFName
;
113 /* Get all our pointers straightened out
115 cSeg
= *(short*)(rawdata
);
116 /* Skip the 'pad' field */
117 baseSrcLn
= (long*)(rawdata
+ 4);
118 segarray
= &baseSrcLn
[cSeg
];
119 cFName
= *((char*)&segarray
[cSeg
* 2]);
120 snprintf (Name
, cFName
+ 1, "%s", (char*)&segarray
[cSeg
* 2] + 1);
122 /* printf ("cSeg = %d\n", cSeg); */
123 printf ("\n File table: '%s'\n", Name
);
125 for (i
= 0; i
< cSeg
; i
++)
127 printf (" Segment #%d start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
128 i
+ 1, segarray
[i
* 2], segarray
[(i
* 2) + 1], baseSrcLn
[i
]);
131 /* Return the total length of the data (in bytes) that we used, so
132 * we'll know how far to jump ahead for the next part of the sstSrcModule.
134 datalen
= ((BYTE
*)(&segarray
[cSeg
* 2]) + cFName
+ 1 - rawdata
);
135 /* printf ("datalen before padding = %d\n", datalen); */
137 datalen
+= 4 - (datalen
% 4);
138 /* printf ("datalen after padding = %d\n", datalen); */
143 /* Print out the contents of a OMFSourceLine block. The contents of this section
147 * unsigned short cPair
148 * unsigned long offset[cPair]
149 * unsigned long linenumber[cPair]
151 int PrintSrcModuleLineInfo (BYTE
* rawdata
, int tablecount
)
157 unsigned short cPair
;
158 unsigned long *offset
;
159 unsigned short *linenumber
;
161 Seg
= *(short*)rawdata
;
162 cPair
= *(short*)(rawdata
+ 2);
163 offset
= (long*)(rawdata
+ 4);
164 linenumber
= (short*)&offset
[cPair
];
166 printf ("\n Line table #%d: Found %d line numbers for segment index %d\n",
167 tablecount
, cPair
, Seg
);
169 for (i
= 0; i
< cPair
; i
++)
171 printf (" Pair #%2d: offset = [0x%8lx], linenumber = %d\n",
172 i
+ 1, offset
[i
], linenumber
[i
]);
175 /* Return the total length of the data (in bytes) that we used, so
176 * we'll know how far to jump ahead for the next part of the sstSrcModule.
178 datalen
= ((BYTE
*)(&linenumber
[cPair
]) - rawdata
);
179 /* printf ("datalen before padding = %d\n", datalen); */
181 datalen
+= 4 - (datalen
% 4);
182 /* printf ("datalen after padding = %d\n", datalen); */