ReactOS  0.4.14-dev-98-gb0d4763
source.c File Reference
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "dbghelp_private.h"
#include "wine/debug.h"
Include dependency graph for source.c:

Go to the source code of this file.

Classes

struct  source_rb
 
struct  enum_sources_files_context
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dbghelp)
 
int source_rb_compare (const void *key, const struct wine_rb_entry *entry)
 
static unsigned source_find (const char *name)
 
unsigned source_new (struct module *module, const char *base, const char *name)
 
const charsource_get (const struct module *module, unsigned idx)
 
BOOL WINAPI SymEnumSourceFilesW (HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles, PVOID UserContext)
 
static BOOL CALLBACK enum_source_files_W_to_A (PSOURCEFILEW source_file, PVOID context)
 
BOOL WINAPI SymEnumSourceFiles (HANDLE hProcess, ULONG64 ModBase, PCSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles, PVOID UserContext)
 
BOOL WINAPI SymEnumSourceLines (HANDLE hProcess, ULONG64 base, PCSTR obj, PCSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACK EnumLinesCallback, PVOID UserContext)
 
BOOL WINAPI SymEnumSourceLinesW (HANDLE hProcess, ULONG64 base, PCWSTR obj, PCWSTR file, DWORD line, DWORD flags, PSYM_ENUMLINES_CALLBACKW EnumLinesCallback, PVOID UserContext)
 
BOOL WINAPI SymGetSourceFileToken (HANDLE hProcess, ULONG64 base, PCSTR src, PVOID *token, DWORD *size)
 
BOOL WINAPI SymGetSourceFileTokenW (HANDLE hProcess, ULONG64 base, PCWSTR src, PVOID *token, DWORD *size)
 

Variables

static struct modulerb_module
 

Function Documentation

◆ enum_source_files_W_to_A()

static BOOL CALLBACK enum_source_files_W_to_A ( PSOURCEFILEW  source_file,
PVOID  context 
)
static

Definition at line 208 of file source.c.

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 }
#define WideCharToMultiByte
Definition: compat.h:101
Definition: http.c:6587
#define CP_ACP
Definition: compat.h:99
PSYM_ENUMSOURCEFILES_CALLBACK callbackA
Definition: source.c:201
DWORD64 ModBase
Definition: compat.h:1091
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
PCHAR FileName
Definition: compat.h:1087
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
#define HeapReAlloc
Definition: compat.h:393
PWSTR FileName
Definition: compat.h:1092
DWORD64 ModBase
Definition: compat.h:1086
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by SymEnumSourceFiles().

◆ source_find()

static unsigned source_find ( const char name)
static

Definition at line 53 of file source.c.

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 }
#define e
Definition: ke_i.h:82
#define WINE_RB_ENTRY_VALUE(element, type, field)
Definition: rbtree.h:31
uint32_t entry
Definition: isohybrid.c:63
static struct module * rb_module
Definition: source.c:34
Definition: rbtree.h:35
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

Referenced by source_new().

◆ source_get()

const char* source_get ( const struct module module,
unsigned  idx 
)

Definition at line 131 of file source.c.

132 {
133  if (idx == -1) return "";
135  return module->sources + idx;
136 }
#define assert(x)
Definition: debug.h:53
char * sources
unsigned int idx
Definition: utils.c:41

Referenced by coff_process_info(), dwarf2_set_line_number(), SymEnumLines(), SymGetLinePrev64(), symt_add_func_line(), symt_fill_func_line_info(), symt_get_func_line_next(), and symt_new_compiland().

◆ source_new()

unsigned source_new ( struct module module,
const char base,
const char name 
)

Definition at line 67 of file source.c.

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 }
#define max(a, b)
Definition: svc.c:63
HMODULE module
Definition: main.cpp:47
unsigned sources_alloc
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned sources_used
struct wine_rb_entry entry
Definition: source.c:37
struct wine_rb_tree sources_offsets_tree
char * sources
void * pool_alloc(struct pool *a, size_t len) DECLSPEC_HIDDEN
Definition: storage.c:90
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned source
Definition: source.c:38
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
struct pool pool
static struct module * rb_module
Definition: source.c:34
static unsigned source_find(const char *name)
Definition: source.c:53
#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: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define HeapFree(x, y, z)
Definition: compat.h:394
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by codeview_snarf(), codeview_snarf_linetab(), codeview_snarf_linetab2(), coff_add_file(), dwarf2_parse_compilation_unit(), dwarf2_parse_line_numbers(), pe_load_coff_symbol_table(), rsym_parse(), and stabs_parse().

◆ source_rb_compare()

int source_rb_compare ( const void key,
const struct wine_rb_entry entry 
)

Definition at line 41 of file source.c.

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 }
GLdouble GLdouble t
Definition: gl.h:2047
#define WINE_RB_ENTRY_VALUE(element, type, field)
Definition: rbtree.h:31
uint32_t entry
Definition: isohybrid.c:63
static struct module * rb_module
Definition: source.c:34
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
Definition: path.c:42

Referenced by module_new().

◆ SymEnumSourceFiles()

BOOL WINAPI SymEnumSourceFiles ( HANDLE  hProcess,
ULONG64  ModBase,
PCSTR  Mask,
PSYM_ENUMSOURCEFILES_CALLBACK  cbSrcFiles,
PVOID  UserContext 
)

Definition at line 241 of file source.c.

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 }
Definition: http.c:6587
#define CP_ACP
Definition: compat.h:99
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
static BOOL CALLBACK enum_source_files_W_to_A(PSOURCEFILEW source_file, PVOID context)
Definition: source.c:208
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACKW)(PSOURCEFILEW, PVOID)
Definition: compat.h:1095
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
int ret
GLenum GLsizei len
Definition: glext.h:6722
BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles, PVOID UserContext)
Definition: source.c:142
#define MultiByteToWideChar
Definition: compat.h:100
static BOOL CALLBACK callbackW(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data, LPVOID context)
Definition: propset.c:144
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ SymEnumSourceFilesW()

BOOL WINAPI SymEnumSourceFilesW ( HANDLE  hProcess,
ULONG64  ModBase,
PCWSTR  Mask,
PSYM_ENUMSOURCEFILES_CALLBACKW  cbSrcFiles,
PVOID  UserContext 
)

Definition at line 142 of file source.c.

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 }
#define TRUE
Definition: types.h:120
struct process * process_find_by_handle(HANDLE hProcess)
Definition: dbghelp.c:80
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define CP_ACP
Definition: compat.h:99
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define FIXME(fmt,...)
Definition: debug.h:110
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
struct module * module_find_by_addr(const struct process *pcs, DWORD64 addr, enum module_type type) DECLSPEC_HIDDEN
Definition: module.c:399
GLenum GLsizei len
Definition: glext.h:6722
Definition: _pair.h:47
#define MultiByteToWideChar
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:394
struct module * module_find_by_nameW(const struct process *pcs, const WCHAR *name) DECLSPEC_HIDDEN
Definition: module.c:244

Referenced by SymEnumSourceFiles().

◆ SymEnumSourceLines()

BOOL WINAPI SymEnumSourceLines ( HANDLE  hProcess,
ULONG64  base,
PCSTR  obj,
PCSTR  file,
DWORD  line,
DWORD  flags,
PSYM_ENUMLINES_CALLBACK  EnumLinesCallback,
PVOID  UserContext 
)

Definition at line 294 of file source.c.

298 {
299  FIXME("%p %s %s %s %u %u %p %p: stub!\n",
301  line, flags, EnumLinesCallback, UserContext);
303  return FALSE;
304 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define FIXME(fmt,...)
Definition: debug.h:110
Definition: parser.c:48
#define debugstr_a
Definition: kernel32.h:31
#define SetLastError(x)
Definition: compat.h:409
GLbitfield flags
Definition: glext.h:7161
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
Definition: fci.c:126

◆ SymEnumSourceLinesW()

BOOL WINAPI SymEnumSourceLinesW ( HANDLE  hProcess,
ULONG64  base,
PCWSTR  obj,
PCWSTR  file,
DWORD  line,
DWORD  flags,
PSYM_ENUMLINES_CALLBACKW  EnumLinesCallback,
PVOID  UserContext 
)

Definition at line 310 of file source.c.

314 {
315  FIXME("%p %s %s %s %u %u %p %p: stub!\n",
317  line, flags, EnumLinesCallback, UserContext);
319  return FALSE;
320 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
Definition: parser.c:48
#define SetLastError(x)
Definition: compat.h:409
GLbitfield flags
Definition: glext.h:7161
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
Definition: fci.c:126

◆ SymGetSourceFileToken()

BOOL WINAPI SymGetSourceFileToken ( HANDLE  hProcess,
ULONG64  base,
PCSTR  src,
PVOID token,
DWORD size 
)

Definition at line 326 of file source.c.

328 {
329  FIXME("%p %s %s %p %p: stub!\n",
332  return FALSE;
333 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
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 FIXME(fmt,...)
Definition: debug.h:110
GLsizeiptr size
Definition: glext.h:5919
#define debugstr_a
Definition: kernel32.h:31
#define SetLastError(x)
Definition: compat.h:409
GLenum src
Definition: glext.h:6340
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41

◆ SymGetSourceFileTokenW()

BOOL WINAPI SymGetSourceFileTokenW ( HANDLE  hProcess,
ULONG64  base,
PCWSTR  src,
PVOID token,
DWORD size 
)

Definition at line 339 of file source.c.

341 {
342  FIXME("%p %s %s %p %p: stub!\n",
345  return FALSE;
346 }
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
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
GLsizeiptr size
Definition: glext.h:5919
#define SetLastError(x)
Definition: compat.h:409
GLenum src
Definition: glext.h:6340
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dbghelp  )

Variable Documentation

◆ rb_module

struct module* rb_module
static

Definition at line 34 of file source.c.

Referenced by source_find(), source_new(), and source_rb_compare().