summaryrefslogtreecommitdiffstats
path: root/private/sdktools/ntsdsapi/sl.c
blob: 4fafcb51b2328a6dfc86a940329718986240ec6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#include <string.h>

#include "ntsdp.h"
#include "types.h"
#include "cvtypes.h"
#include "shapi.h"
#include "cvproto.h"
#include "cvinfo.h"
#include "sapi.h"
#include "shiproto.h"
#include "ntempd.h"
#include "ntimage.h"
#include "ntsapi.h"

/*
 *  Function Prototypes
 */

PIMAGE_INFO pImageFromIndex( UCHAR);			// NTSYM.C

/*
 *  Global Memory (File)
 */


static char chName[512];


/*
 *  Da Code
 */


/***    SL_GetBytesGenerated
**
**  Synopsis:
**      SHOFF SL_GetBytesGenerated( PSYMFILE pSymfile, PLINENO pLineno);
**
**  Entry:
**      pSymfile - Pointer to the Symfile entry.
**      pLineno  - Pointer to the Line number entry
**
**  Returns:
**      Returns the number of bytes generated.
**
**  Description:
**      Given a pointer to a Symfile and a corresponding linenumber, return
**	the number of bytes generated.
**
*/

SHOFF SL_GetBytesGenerated( PSYMFILE pSymfile, PLINENO pLineno )
{
    ULONG MemoryLow;
    ULONG MemoryHigh;
    
    MemoryLow = pLineno->memoryOffset;

    if (pLineno == (pSymfile->pLineno + pSymfile->cLineno))
	MemoryHigh = pSymfile->endOffset;
    else
	MemoryHigh = (pLineno + 1)->memoryOffset;
    
    return (SHOFF)(MemoryHigh-MemoryLow-1);
}


/***    SL_GetLineAbove
**
**  Synopsis:
**      WORD SL_GetLineAbove( PSYMFILE pSymfile, PLINENO pLineno);
**
**  Entry:
**      pSymfile - Pointer to the Symfile entry.
**      pLineno  - Pointer to the Line number entry
**
**  Returns:
**      Returns next line number for the given file, or zero if at the
**	last line of the file.
**
**  Description:
**      Given a pointer to a Symfile and a corresponding linenumber entry,
**	return the line number for the next line that generated code.
**	Returns zero if at the last line of the file.
**
*/

WORD SL_GetLineAbove( PSYMFILE pSymfile, PLINENO pLineno )
{
    if (pLineno == (pSymfile->pLineno + pSymfile->cLineno))
	return 0;
    else
	return (pLineno + 1)->breakLineNumber;
}


/***    SL_GetLineBelow
**
**  Synopsis:
**      WORD SL_GetLineBelow( PSYMFILE pSymfile, PLINENO pLineno);
**
**  Entry:
**      pSymfile - Pointer to the Symfile entry.
**      pLineno  - Pointer to the Line number entry
**
**  Returns:
**      Returns previous line number for the given file, or zero if at the
**	first line of the file.
**
**  Description:
**      Given a pointer to a Symfile and a corresponding linenumber entry,
**	return the line number for the previous line that generated code.
**	Returns zero if at the first line of the file.
**
*/

WORD SL_GetLineBelow( PSYMFILE pSymfile, PLINENO pLineno )
{
    if ( pLineno == pSymfile->pLineno )
	return 0;
    else
	return (pLineno - 1)->breakLineNumber;
}



/***    SLFLineToAddr
**
**  Synopsis:
**	BOOLEAN SLFLineToAddr (HSF hsf, WORD line, LPADDR lpaddr,
**				SHOFF FAR * lpcbLn, WORD FAR *lpNear);
**  Entry:
**	hsf	- handle to the source file.
**	line	- Source line (One-based).
**	*lpaddr - Address for this source line.
**	*lpcbLn - Bytes of code that were generated for this source line.
**	*lpNear - The nearest line below ([0]) and above ([1]) which
**		  generated code.
**
**  Returns:
**	TRUE for success, FALSE for failure.
**
**  Description:
**      Given an filename and a line number, return the address for the line.
**	Returns TRUE or FALSE, and when successful the address and the number
**	of bytes of code generated for the line.
**
*/

BOOL LOADDS PASCAL SLFLineToAddr (HSF hsf, WORD line, LPADDR lpaddr,
				SHOFF FAR * lpcb, WORD FAR * lpNearest)
{
    PLINENO  pLineno;
    PSYMFILE pSymfile = (PSYMFILE)hsf;
    PIMAGE_INFO pImage = pImageFromIndex( pSymfile->modIndex);
		
    pLineno = GetLinenoFromFilename( pSymfile->pchName, &pSymfile,
						   line, pImage->index);

    if ( pLineno && pLineno->breakLineNumber == line) {
	SH_SetAddr(lpaddr,pLineno->memoryOffset,(HEXE)pImage);
	*lpcb = SL_GetBytesGenerated(pSymfile,pLineno);

	if ( lpNearest ) {
	    *lpNearest++ = SL_GetLineBelow(pSymfile,pLineno);  
	    *lpNearest   = SL_GetLineAbove(pSymfile,pLineno);
        }

	if ( line == 1 && pLineno->memoryOffset == 0)
	    return(FALSE);
	else
	    return(TRUE);

    }	

    else {
//	dprintf("KD: SLFLineToAddr(), %s!%d is unknown\n",
//						pSymfile->pchName,line);
	return(FALSE);
    }
}


/***    SLHsfFromFile
**
**  Synopsis:
**	HSF SLHsfFromFile ( HMOD hmod, LSZ File );
**
**  Entry:
**      hmod	- Module to check for this filename
**	File	- Filename
**
**  Returns:
**      Handle to the Source File or NULL if not found.
**
**  Description:
**      Given a module and a source filename, return the HSF
**	that corresponds.  The path and extension on the file
**	name will be ignored.
**
**
*/

HSF LOADDS PASCAL SLHsfFromFile ( HMOD hmod, LSZ  lszFile )
{
    PIMAGE_INFO pImage;
    PSYMFILE pSymfile;
    char	rgch[_MAX_CVFNAME];
    
    if ( hmod )
	pImage = (PIMAGE_INFO)SHHexeFromHmod(hmod);
    else
	pImage = (PIMAGE_INFO)SHGetNextExe( (HEXE)NULL);
    
    _splitpath(lszFile, NULL, NULL, rgch, NULL);
    _strlwr(rgch);
    if ( GetLinenoFromFilename( rgch, &pSymfile, 1, pImage->index) )
	return (HSF) (((HMOD) pSymfile == hmod) ? pSymfile : NULL);
    else
	return (HSF)NULL;
}


/***    SLHsfFromPcxt
**
**  Synopsis:
**      HSF SLHsfFromPcxt( PCXT pcxt);
**
**  Entry:
**      pcxt - pointer to a context block.
**
**  Returns:
**      Returns a handle to the source file or NULL if not found.
**
**  Description:
**      Given a pointer to a CXT return a handle to the source file.
**
*/

HSF LOADDS PASCAL SLHsfFromPcxt(PCXT pcxt)
{
    ULONG    offset;
    PLINENO  pLineno;
    PSYMFILE pSymfile;

    offset = SH_OffsetFromAddr( &pcxt->addr );
    pLineno = GetLinenoFromOffset( &pSymfile, offset);
    if ( pLineno ) 
	return (HSF)pSymfile;
    else
	return (HSF)0;
}



/***    SLLineFromAddr
**
**  Synopsis:
**	BOOL SLLineFromAddr( LPADDR lpaddr,
**			     LPW lpwLine,
**			     SHOFF FAR * lpcb,
**			     SHOFF FAR * lpdb );
**  Entry:
** 	lpaddr	 - address for which we want source line info
** 	*lpwLine - Line (one-based) for this address
**	*lpcb	 - Bytes of code that were generated for this source line.
**	*lpdb	 - Delta to start of the line.
**
**  Returns:
** 	TRUE if source was found, FALSE if not
**
**  Description:
** 	Given an address return the line number that corresponds.
**	Also return count bytes for the given line, and the delta
**	between the address that was passed in and the first byte
**	corresponding to this source line.
**
*/

BOOL LOADDS PASCAL SLLineFromAddr ( LPADDR lpaddr, LPW lpwLine, 
				    SHOFF FAR * lpcb, SHOFF FAR * lpdb)
{
    ULONG    offset;
    PLINENO  pLineno;
    PSYMFILE pSymfile;
    
    offset = SH_OffsetFromAddr( lpaddr );
    
    pLineno = GetLinenoFromOffset( &pSymfile, offset);
    if ( pLineno ) {
	*lpwLine = (WORD)pLineno->breakLineNumber;
	*lpcb = SL_GetBytesGenerated(pSymfile,pLineno);
	*lpdb = (SHOFF)(offset - pLineno->memoryOffset);
	return(TRUE);
    }	

    else {
//	dprintf("KD: SLLineFromAddr() failed for offset %x\n",offset);
	return(FALSE);
    }
}



/***    SLNameFromHsf
**
**  Synopsis:
**      LPCH SLNameFromHsf( HSF hsf);
**
**  Entry:
**      hsf - Handle to a source file.
**
**  Returns:
**      Returns the Address of a length-prefixed string containing the
**	path/filename.
**
**  Description:
**      Returns length-prefixed pointer to the filename associated with 
**	source file.  Each call to this function overwrites any previous
**	calls.  NOTE: Length-prefixed pointer, it's NOT quaranteed to be
**	null terminated!
**
*/

LPCH LOADDS PASCAL SLNameFromHsf(HSF hsf)
{
    PSYMFILE pSymfile = (PSYMFILE)hsf;
    
    strncpy(&chName[1],pSymfile->pchPath, 512);
    strncat(&chName[1],pSymfile->pchName, 512);
    strncat(&chName[1],pSymfile->pchExtension, 512);
    chName[0] = (char)strlen(&chName[1]);
    return &chName[0];
}