ReactOS  0.4.14-dev-55-g2da92ac
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 "config.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
26 
27 #include "dbghelp_private.h"
28 #ifndef DBGHELP_STATIC_LIB
29 #include "wine/debug.h"
30 #endif
31 
33 
34 static struct module* rb_module;
35 struct source_rb
36 {
38  unsigned source;
39 };
40 
41 int source_rb_compare(const void *key, const struct wine_rb_entry *entry)
42 {
43  const struct source_rb *t = WINE_RB_ENTRY_VALUE(entry, const struct source_rb, entry);
44 
45  return strcmp((const char*)key, rb_module->sources + t->source);
46 }
47 
48 /******************************************************************
49  * source_find
50  *
51  * check whether a source file has already been stored
52  */
53 static unsigned source_find(const char* name)
54 {
55  struct wine_rb_entry* e;
56 
57  e = wine_rb_get(&rb_module->sources_offsets_tree, name);
58  if (!e) return -1;
59  return WINE_RB_ENTRY_VALUE(e, struct source_rb, entry)->source;
60 }
61 
62 /******************************************************************
63  * source_new
64  *
65  * checks if source exists. if not, add it
66  */
67 unsigned source_new(struct module* module, const char* base, const char* name)
68 {
69  unsigned ret = -1;
70  const char* full;
71  char* tmp = NULL;
72 
73  if (!name) return ret;
74  if (!base || *name == '/')
75  full = name;
76  else
77  {
78  unsigned bsz = strlen(base);
79 
80  tmp = HeapAlloc(GetProcessHeap(), 0, bsz + 1 + strlen(name) + 1);
81  if (!tmp) return ret;
82  full = tmp;
83  strcpy(tmp, base);
84  if (tmp[bsz - 1] != '/') tmp[bsz++] = '/';
85  strcpy(&tmp[bsz], name);
86  }
87  rb_module = module;
88  if (!module->sources || (ret = source_find(full)) == (unsigned)-1)
89  {
90  char* new;
91  int len = strlen(full) + 1;
92  struct source_rb* rb;
93 
95  {
96  if (!module->sources)
97  {
98  module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
100  }
101  else
102  {
104  (module->sources_used + len + 1 + 255) & ~255 );
107  }
108  if (!new) goto done;
109  module->sources = new;
110  }
113  module->sources_used += len;
114  module->sources[module->sources_used] = '\0';
115  if ((rb = pool_alloc(&module->pool, sizeof(*rb))))
116  {
117  rb->source = ret;
119  }
120  }
121 done:
122  HeapFree(GetProcessHeap(), 0, tmp);
123  return ret;
124 }
125 
126 /******************************************************************
127  * source_get
128  *
129  * returns a stored source file name
130  */
131 const char* source_get(const struct module* module, unsigned idx)
132 {
133  if (idx == -1) return "";
135  return module->sources + idx;
136 }
137 
138 /******************************************************************
139  * SymEnumSourceFilesW (DBGHELP.@)
140  *
141  */
144  PVOID UserContext)
145 {
146  struct module_pair pair;
147  SOURCEFILEW sf;
148  char* ptr;
149  WCHAR* conversion_buffer = NULL;
150  DWORD conversion_buffer_len = 0;
151 
152  if (!cbSrcFiles) return FALSE;
154  if (!pair.pcs) return FALSE;
155 
156  if (ModBase)
157  {
158  pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
159  if (!module_get_debug(&pair)) return FALSE;
160  }
161  else
162  {
163  if (Mask[0] == '!')
164  {
165  pair.requested = module_find_by_nameW(pair.pcs, Mask + 1);
166  if (!module_get_debug(&pair)) return FALSE;
167  }
168  else
169  {
170  FIXME("Unsupported yet (should get info from current context)\n");
171  return FALSE;
172  }
173  }
174  if (!pair.effective->sources) return FALSE;
175  for (ptr = pair.effective->sources; *ptr; ptr += strlen(ptr) + 1)
176  {
177  DWORD len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0);
178 
179  if (len > conversion_buffer_len)
180  {
181  HeapFree(GetProcessHeap(), 0, conversion_buffer);
182  conversion_buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
183  if (!conversion_buffer) return FALSE;
184  conversion_buffer_len = len;
185  }
186 
187  MultiByteToWideChar(CP_ACP, 0, ptr, -1, conversion_buffer, len);
188 
189  /* FIXME: not using Mask */
190  sf.ModBase = ModBase;
191  sf.FileName = conversion_buffer;
192  if (!cbSrcFiles(&sf, UserContext)) break;
193  }
194 
195  HeapFree(GetProcessHeap(), 0, conversion_buffer);
196  return TRUE;
197 }
198 
200 {
206 };
207 
209 {
210  struct enum_sources_files_context *ctx = context;
211  SOURCEFILE source_fileA;
212  DWORD len;
213 
214  len = WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, NULL, 0, NULL, NULL);
215  if (len > ctx->conversion_buffer_len)
216  {
219 
220  if (!ptr)
221  {
223  return FALSE;
224  }
225 
226  ctx->conversion_buffer = ptr;
227  ctx->conversion_buffer_len = len;
228  }
229 
230  WideCharToMultiByte(CP_ACP, 0, source_file->FileName, -1, ctx->conversion_buffer, len, NULL, NULL);
231 
232  source_fileA.ModBase = source_file->ModBase;
233  source_fileA.FileName = ctx->conversion_buffer;
234  return ctx->callbackA(&source_fileA, ctx->caller_context);
235 }
236 
237 /******************************************************************
238  * SymEnumSourceFiles (DBGHELP.@)
239  *
240  */
243  PVOID UserContext)
244 {
245  WCHAR *maskW = NULL;
247  PVOID context;
248  struct enum_sources_files_context callback_context = {cbSrcFiles, UserContext};
249  BOOL ret;
250 
251  if (Mask)
252  {
253  DWORD len = MultiByteToWideChar(CP_ACP, 0, Mask, -1, NULL, 0);
254 
255  maskW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
256  if (!maskW)
257  {
259  return FALSE;
260  }
261 
262  MultiByteToWideChar(CP_ACP, 0, Mask, -1, maskW, len);
263  }
264 
265  if (cbSrcFiles)
266  {
269  }
270  else
271  {
272  callbackW = NULL;
273  context = UserContext;
274  }
275 
276  ret = SymEnumSourceFilesW(hProcess, ModBase, maskW, callbackW, context);
277 
278  if (callback_context.callback_error)
279  {
280  SetLastError(callback_context.callback_error);
281  ret = FALSE;
282  }
283 
284  HeapFree(GetProcessHeap(), 0, callback_context.conversion_buffer);
285  HeapFree(GetProcessHeap(), 0, maskW);
286 
287  return ret;
288 }
289 
290 /******************************************************************
291  * SymEnumSourceLines (DBGHELP.@)
292  *
293  */
296  PSYM_ENUMLINES_CALLBACK EnumLinesCallback,
297  PVOID UserContext)
298 {
299  FIXME("%p %s %s %s %u %u %p %p: stub!\n",
301  line, flags, EnumLinesCallback, UserContext);
303  return FALSE;
304 }
305 
306 /******************************************************************
307  * SymEnumSourceLinesW(DBGHELP.@)
308  *
309  */
312  PSYM_ENUMLINES_CALLBACKW EnumLinesCallback,
313  PVOID UserContext)
314 {
315  FIXME("%p %s %s %s %u %u %p %p: stub!\n",
317  line, flags, EnumLinesCallback, UserContext);
319  return FALSE;
320 }
321 
322 /******************************************************************
323  * SymGetSourceFileToken (DBGHELP.@)
324  *
325  */
328 {
329  FIXME("%p %s %s %p %p: stub!\n",
332  return FALSE;
333 }
334 
335 /******************************************************************
336  * SymGetSourceFileTokenW (DBGHELP.@)
337  *
338  */
341 {
342  FIXME("%p %s %s %p %p: stub!\n",
345  return FALSE;
346 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
HMODULE module
Definition: main.cpp:47
struct process * process_find_by_handle(HANDLE hProcess)
Definition: dbghelp.c:80
unsigned sources_alloc
#define WideCharToMultiByte
Definition: compat.h:101
unsigned source_new(struct module *module, const char *base, const char *name)
Definition: source.c:67
Definition: http.c:6587
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned sources_used
#define CP_ACP
Definition: compat.h:99
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI SymEnumSourceLines(HANDLE hProcess, ULONG64 base, PCSTR obj, PCSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACK EnumLinesCallback, PVOID UserContext)
Definition: source.c:294
BOOL(CALLBACK * PSYM_ENUMLINES_CALLBACKW)(PSRCCODEINFOW, PVOID)
Definition: compat.h:1106
GLdouble GLdouble t
Definition: gl.h:2047
struct wine_rb_entry entry
Definition: source.c:37
#define assert(x)
Definition: debug.h:53
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
const char * source_get(const struct module *module, unsigned idx)
Definition: source.c:131
static BOOL CALLBACK enum_source_files_W_to_A(PSOURCEFILEW source_file, PVOID context)
Definition: source.c:208
struct wine_rb_tree sources_offsets_tree
char * sources
PSYM_ENUMSOURCEFILES_CALLBACK callbackA
Definition: source.c:201
DWORD64 ModBase
Definition: compat.h:1091
void * pool_alloc(struct pool *a, size_t len) DECLSPEC_HIDDEN
Definition: storage.c:90
unsigned int BOOL
Definition: ntddk_ex.h:94
#define e
Definition: ke_i.h:82
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
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp)
static PVOID ptr
Definition: dispmode.c:27
unsigned int idx
Definition: utils.c:41
smooth NULL
Definition: ftsmooth.c:416
PCHAR FileName
Definition: compat.h:1087
Definition: parser.c:48
BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles, PVOID UserContext)
Definition: source.c:241
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
BOOL module_get_debug(struct module_pair *) DECLSPEC_HIDDEN
Definition: module.c:340
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACKW)(PSOURCEFILEW, PVOID)
Definition: compat.h:1095
#define debugstr_a
Definition: kernel32.h:31
#define WINE_RB_ENTRY_VALUE(element, type, field)
Definition: rbtree.h:31
#define WINAPI
Definition: msvc.h:8
unsigned source
Definition: source.c:38
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACK)(PSOURCEFILE, PVOID)
Definition: compat.h:1094
GLbitfield flags
Definition: glext.h:7161
unsigned __int64 ULONG64
Definition: imports.h:198
int ret
BOOL(CALLBACK * PSYM_ENUMLINES_CALLBACK)(PSRCCODEINFO, PVOID)
Definition: compat.h:760
uint32_t entry
Definition: isohybrid.c:63
struct module * module_find_by_addr(const struct process *pcs, DWORD64 addr, enum module_type type) DECLSPEC_HIDDEN
Definition: module.c:399
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLenum src
Definition: glext.h:6340
struct pool pool
static struct module * rb_module
Definition: source.c:34
BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles, PVOID UserContext)
Definition: source.c:142
static unsigned source_find(const char *name)
Definition: source.c:53
Definition: rbtree.h:35
#define HeapReAlloc
Definition: compat.h:393
static int wine_rb_put(struct wine_rb_tree *tree, const void *key, struct wine_rb_entry *entry)
Definition: rbtree.h:215
Definition: _pair.h:47
BOOL WINAPI SymGetSourceFileToken(HANDLE hProcess, ULONG64 base, PCSTR src, PVOID *token, DWORD *size)
Definition: source.c:326
BOOL WINAPI SymGetSourceFileTokenW(HANDLE hProcess, ULONG64 base, PCWSTR src, PVOID *token, DWORD *size)
Definition: source.c:339
#define MultiByteToWideChar
Definition: compat.h:100
static BOOL CALLBACK callbackW(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data, LPVOID context)
Definition: propset.c:144
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
Definition: name.c:36
static struct wine_rb_entry * wine_rb_get(const struct wine_rb_tree *tree, const void *key)
Definition: rbtree.h:203
PWSTR FileName
Definition: compat.h:1092
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int source_rb_compare(const void *key, const struct wine_rb_entry *entry)
Definition: source.c:41
const char * PCSTR
Definition: typedefs.h:51
BOOL WINAPI SymEnumSourceLinesW(HANDLE hProcess, ULONG64 base, PCWSTR obj, PCWSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACKW EnumLinesCallback, PVOID UserContext)
Definition: source.c:310
#define HeapFree(x, y, z)
Definition: compat.h:394
DWORD64 ModBase
Definition: compat.h:1086
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
Definition: path.c:42
struct module * module_find_by_nameW(const struct process *pcs, const WCHAR *name) DECLSPEC_HIDDEN
Definition: module.c:244
Definition: fci.c:126
GLuint const GLchar * name
Definition: glext.h:6031