ReactOS 0.4.15-dev-5669-g09dde2c
source.c
Go to the documentation of this file.
1/*
2 * File source.c - source files management
3 *
4 * Copyright (C) 2004, Eric Pouech.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <assert.h>
25
26#include "dbghelp_private.h"
27#ifndef DBGHELP_STATIC_LIB
28#include "wine/debug.h"
29#endif
30
32
33static struct module* rb_module;
35{
37 unsigned source;
38};
39
40int source_rb_compare(const void *key, const struct wine_rb_entry *entry)
41{
42 const struct source_rb *t = WINE_RB_ENTRY_VALUE(entry, const struct source_rb, entry);
43
44 return strcmp((const char*)key, rb_module->sources + t->source);
45}
46
47/******************************************************************
48 * source_find
49 *
50 * check whether a source file has already been stored
51 */
52static unsigned source_find(const char* name)
53{
54 struct wine_rb_entry* e;
55
56 e = wine_rb_get(&rb_module->sources_offsets_tree, name);
57 if (!e) return -1;
58 return WINE_RB_ENTRY_VALUE(e, struct source_rb, entry)->source;
59}
60
61/******************************************************************
62 * source_new
63 *
64 * checks if source exists. if not, add it
65 */
66unsigned source_new(struct module* module, const char* base, const char* name)
67{
68 unsigned ret = -1;
69 const char* full;
70 char* tmp = NULL;
71
72 if (!name) return ret;
73 if (!base || *name == '/')
74 full = name;
75 else
76 {
77 unsigned bsz = strlen(base);
78
79 tmp = HeapAlloc(GetProcessHeap(), 0, bsz + 1 + strlen(name) + 1);
80 if (!tmp) return ret;
81 full = tmp;
82 strcpy(tmp, base);
83 if (tmp[bsz - 1] != '/') tmp[bsz++] = '/';
84 strcpy(&tmp[bsz], name);
85 }
87 if (!module->sources || (ret = source_find(full)) == (unsigned)-1)
88 {
89 char* new;
90 int len = strlen(full) + 1;
91 struct source_rb* rb;
92
94 {
95 if (!module->sources)
96 {
97 module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
99 }
100 else
101 {
103 (module->sources_used + len + 1 + 255) & ~255 );
106 }
107 if (!new) goto done;
108 module->sources = new;
109 }
114 if ((rb = pool_alloc(&module->pool, sizeof(*rb))))
115 {
116 rb->source = ret;
118 }
119 }
120done:
121 HeapFree(GetProcessHeap(), 0, tmp);
122 return ret;
123}
124
125/******************************************************************
126 * source_get
127 *
128 * returns a stored source file name
129 */
130const char* source_get(const struct module* module, unsigned idx)
131{
132 if (idx == -1) return "";
134 return module->sources + idx;
135}
136
137/******************************************************************
138 * SymEnumSourceFilesW (DBGHELP.@)
139 *
140 */
143 PVOID UserContext)
144{
145 struct module_pair pair;
146 SOURCEFILEW sf;
147 char* ptr;
148 WCHAR* conversion_buffer = NULL;
149 DWORD conversion_buffer_len = 0;
150
151 if (!cbSrcFiles) return FALSE;
153 if (!pair.pcs) return FALSE;
154
155 if (ModBase)
156 {
157 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
158 if (!module_get_debug(&pair)) return FALSE;
159 }
160 else
161 {
162 if (Mask[0] == '!')
163 {
164 pair.requested = module_find_by_nameW(pair.pcs, Mask + 1);
165 if (!module_get_debug(&pair)) return FALSE;
166 }
167 else
168 {
169 FIXME("Unsupported yet (should get info from current context)\n");
170 return FALSE;
171 }
172 }
173 if (!pair.effective->sources) return FALSE;
174 for (ptr = pair.effective->sources; *ptr; ptr += strlen(ptr) + 1)
175 {
177
178 if (len > conversion_buffer_len)
179 {
180 HeapFree(GetProcessHeap(), 0, conversion_buffer);
181 conversion_buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
182 if (!conversion_buffer) return FALSE;
183 conversion_buffer_len = len;
184 }
185
186 MultiByteToWideChar(CP_ACP, 0, ptr, -1, conversion_buffer, len);
187
188 /* FIXME: not using Mask */
189 sf.ModBase = ModBase;
190 sf.FileName = conversion_buffer;
191 if (!cbSrcFiles(&sf, UserContext)) break;
192 }
193
194 HeapFree(GetProcessHeap(), 0, conversion_buffer);
195 return TRUE;
196}
197
199{
205};
206
208{
210 SOURCEFILE source_fileA;
211 DWORD len;
212
213 len = WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, NULL, 0, NULL, NULL);
214 if (len > ctx->conversion_buffer_len)
215 {
216 char *ptr = ctx->conversion_buffer ? HeapReAlloc(GetProcessHeap(), 0, ctx->conversion_buffer, len) :
218
219 if (!ptr)
220 {
221 ctx->callback_error = ERROR_OUTOFMEMORY;
222 return FALSE;
223 }
224
225 ctx->conversion_buffer = ptr;
226 ctx->conversion_buffer_len = len;
227 }
228
229 WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, ctx->conversion_buffer, len, NULL, NULL);
230
231 source_fileA.ModBase = source_file->ModBase;
232 source_fileA.FileName = ctx->conversion_buffer;
233 return ctx->callbackA(&source_fileA, ctx->caller_context);
234}
235
236/******************************************************************
237 * SymEnumSourceFiles (DBGHELP.@)
238 *
239 */
242 PVOID UserContext)
243{
244 WCHAR *maskW = NULL;
247 struct enum_sources_files_context callback_context = {cbSrcFiles, UserContext};
248 BOOL ret;
249
250 if (Mask)
251 {
253
254 maskW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
255 if (!maskW)
256 {
258 return FALSE;
259 }
260
261 MultiByteToWideChar(CP_ACP, 0, Mask, -1, maskW, len);
262 }
263
264 if (cbSrcFiles)
265 {
268 }
269 else
270 {
271 callbackW = NULL;
272 context = UserContext;
273 }
274
275 ret = SymEnumSourceFilesW(hProcess, ModBase, maskW, callbackW, context);
276
277 if (callback_context.callback_error)
278 {
279 SetLastError(callback_context.callback_error);
280 ret = FALSE;
281 }
282
283 HeapFree(GetProcessHeap(), 0, callback_context.conversion_buffer);
284 HeapFree(GetProcessHeap(), 0, maskW);
285
286 return ret;
287}
288
289/******************************************************************
290 * SymEnumSourceLines (DBGHELP.@)
291 *
292 */
295 PSYM_ENUMLINES_CALLBACK EnumLinesCallback,
296 PVOID UserContext)
297{
298 FIXME("%p %s %s %s %u %u %p %p: stub!\n",
300 line, flags, EnumLinesCallback, UserContext);
302 return FALSE;
303}
304
305/******************************************************************
306 * SymEnumSourceLinesW(DBGHELP.@)
307 *
308 */
311 PSYM_ENUMLINES_CALLBACKW EnumLinesCallback,
312 PVOID UserContext)
313{
314 FIXME("%p %s %s %s %u %u %p %p: stub!\n",
316 line, flags, EnumLinesCallback, UserContext);
318 return FALSE;
319}
320
321/******************************************************************
322 * SymGetSourceFileToken (DBGHELP.@)
323 *
324 */
327{
328 FIXME("%p %s %s %p %p: stub!\n",
331 return FALSE;
332}
333
334/******************************************************************
335 * SymGetSourceFileTokenW (DBGHELP.@)
336 *
337 */
340{
341 FIXME("%p %s %s %p %p: stub!\n",
344 return FALSE;
345}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: debug.h:111
struct module * module_find_by_nameW(const struct process *pcs, const WCHAR *name) DECLSPEC_HIDDEN
Definition: module.c:279
void * pool_alloc(struct pool *a, size_t len) DECLSPEC_HIDDEN
Definition: storage.c:89
struct module * module_find_by_addr(const struct process *pcs, DWORD64 addr, enum module_type type) DECLSPEC_HIDDEN
Definition: module.c:420
BOOL module_get_debug(struct module_pair *) DECLSPEC_HIDDEN
Definition: module.c:374
@ DMT_UNKNOWN
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define SetLastError(x)
Definition: compat.h:752
BOOL(CALLBACK * PSYM_ENUMLINES_CALLBACKW)(PSRCCODEINFOW, PVOID)
Definition: compat.h:1465
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACKW)(PSOURCEFILEW, PVOID)
Definition: compat.h:1454
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACK)(PSOURCEFILE, PVOID)
Definition: compat.h:1453
BOOL(CALLBACK * PSYM_ENUMLINES_CALLBACK)(PSRCCODEINFO, PVOID)
Definition: compat.h:1118
struct process * process_find_by_handle(HANDLE hProcess)
Definition: dbghelp.c:99
BOOL WINAPI SymGetSourceFileTokenW(HANDLE hProcess, ULONG64 base, PCWSTR src, PVOID *token, DWORD *size)
Definition: source.c:338
const char * source_get(const struct module *module, unsigned idx)
Definition: source.c:130
static struct module * rb_module
Definition: source.c:33
BOOL WINAPI SymEnumSourceLines(HANDLE hProcess, ULONG64 base, PCSTR obj, PCSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACK EnumLinesCallback, PVOID UserContext)
Definition: source.c:293
BOOL WINAPI SymEnumSourceLinesW(HANDLE hProcess, ULONG64 base, PCWSTR obj, PCWSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACKW EnumLinesCallback, PVOID UserContext)
Definition: source.c:309
unsigned source_new(struct module *module, const char *base, const char *name)
Definition: source.c:66
BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles, PVOID UserContext)
Definition: source.c:141
BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles, PVOID UserContext)
Definition: source.c:240
static unsigned source_find(const char *name)
Definition: source.c:52
int source_rb_compare(const void *key, const struct wine_rb_entry *entry)
Definition: source.c:40
BOOL WINAPI SymGetSourceFileToken(HANDLE hProcess, ULONG64 base, PCSTR src, PVOID *token, DWORD *size)
Definition: source.c:325
static BOOL CALLBACK enum_source_files_W_to_A(PSOURCEFILEW source_file, PVOID context)
Definition: source.c:207
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned int Mask
Definition: fpcontrol.c:82
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
uint32_t entry
Definition: isohybrid.c:63
#define e
Definition: ke_i.h:82
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned __int64 ULONG64
Definition: imports.h:198
static PVOID ptr
Definition: dispmode.c:27
static BOOL CALLBACK callbackW(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data, LPVOID context)
Definition: propset.c:144
#define WINE_RB_ENTRY_VALUE(element, type, field)
Definition: rbtree.h:31
static struct wine_rb_entry * wine_rb_get(const struct wine_rb_tree *tree, const void *key)
Definition: rbtree.h:203
static int wine_rb_put(struct wine_rb_tree *tree, const void *key, struct wine_rb_entry *entry)
Definition: rbtree.h:215
PWSTR FileName
Definition: compat.h:1451
DWORD64 ModBase
Definition: compat.h:1450
DWORD64 ModBase
Definition: compat.h:1445
PCHAR FileName
Definition: compat.h:1446
Definition: http.c:7252
PSYM_ENUMSOURCEFILES_CALLBACK callbackA
Definition: source.c:200
Definition: fci.c:127
Definition: copy.c:22
Definition: parser.c:49
struct wine_rb_tree sources_offsets_tree
unsigned sources_used
char * sources
unsigned sources_alloc
struct pool pool
Definition: name.c:39
Definition: _pair.h:47
unsigned source
Definition: source.c:37
struct wine_rb_entry entry
Definition: source.c:36
Definition: rbtree.h:36
#define max(a, b)
Definition: svc.c:63
const uint16_t * PCWSTR
Definition: typedefs.h:57
const char * PCSTR
Definition: typedefs.h:52
int ret
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180