ReactOS 0.4.15-dev-7842-g558ab78
source.c File Reference
#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 207 of file source.c.

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}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define WideCharToMultiByte
Definition: compat.h:111
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
static PVOID ptr
Definition: dispmode.c:27
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

Referenced by SymEnumSourceFiles().

◆ source_find()

static unsigned source_find ( const char name)
static

Definition at line 52 of file source.c.

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}
static struct module * rb_module
Definition: source.c:33
uint32_t entry
Definition: isohybrid.c:63
#define e
Definition: ke_i.h:82
#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
Definition: name.c:39
Definition: rbtree.h:36

Referenced by source_new().

◆ source_get()

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

Definition at line 130 of file source.c.

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

Referenced by coff_process_info(), dwarf2_set_line_number(), elf_lookup_symtab(), 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 66 of file source.c.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
void * pool_alloc(struct pool *a, size_t len) DECLSPEC_HIDDEN
Definition: storage.c:89
#define HeapFree(x, y, z)
Definition: compat.h:735
static unsigned source_find(const char *name)
Definition: source.c:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static int wine_rb_put(struct wine_rb_tree *tree, const void *key, struct wine_rb_entry *entry)
Definition: rbtree.h:215
struct wine_rb_tree sources_offsets_tree
unsigned sources_used
unsigned sources_alloc
struct pool pool
unsigned source
Definition: source.c:37
struct wine_rb_entry entry
Definition: source.c:36
#define max(a, b)
Definition: svc.c:63
int ret

Referenced by codeview_snarf(), codeview_snarf_linetab(), codeview_snarf_linetab2(), coff_add_file(), dwarf2_parse_compilation_unit(), dwarf2_parse_line_numbers(), elf_hash_symtab(), 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 40 of file source.c.

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}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLdouble GLdouble t
Definition: gl.h:2047
Definition: copy.c:22

Referenced by module_new().

◆ SymEnumSourceFiles()

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

Definition at line 240 of file source.c.

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}
#define SetLastError(x)
Definition: compat.h:752
BOOL(CALLBACK * PSYM_ENUMSOURCEFILES_CALLBACKW)(PSOURCEFILEW, PVOID)
Definition: compat.h:1454
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI SymEnumSourceFilesW(HANDLE hProcess, ULONG64 ModBase, PCWSTR Mask, PSYM_ENUMSOURCEFILES_CALLBACKW cbSrcFiles, PVOID UserContext)
Definition: source.c:141
static BOOL CALLBACK enum_source_files_W_to_A(PSOURCEFILEW source_file, PVOID context)
Definition: source.c:207
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int Mask
Definition: fpcontrol.c:82
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:71
static BOOL CALLBACK callbackW(PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_W_DATA data, LPVOID context)
Definition: propset.c:144
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ SymEnumSourceFilesW()

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

Definition at line 141 of file source.c.

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}
#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
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 TRUE
Definition: types.h:120
struct process * process_find_by_handle(HANDLE hProcess)
Definition: dbghelp.c:99
Definition: _pair.h:47

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 293 of file source.c.

297{
298 FIXME("%p %s %s %s %u %u %p %p: stub!\n",
300 line, flags, EnumLinesCallback, UserContext);
302 return FALSE;
303}
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
GLbitfield flags
Definition: glext.h:7161
#define debugstr_a
Definition: kernel32.h:31
Definition: fci.c:127
Definition: parser.c:49

◆ 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 309 of file source.c.

313{
314 FIXME("%p %s %s %s %u %u %p %p: stub!\n",
316 line, flags, EnumLinesCallback, UserContext);
318 return FALSE;
319}
#define debugstr_w
Definition: kernel32.h:32

◆ SymGetSourceFileToken()

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

Definition at line 325 of file source.c.

327{
328 FIXME("%p %s %s %p %p: stub!\n",
331 return FALSE;
332}
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
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

◆ SymGetSourceFileTokenW()

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

Definition at line 338 of file source.c.

340{
341 FIXME("%p %s %s %p %p: stub!\n",
344 return FALSE;
345}

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dbghelp  )

Variable Documentation

◆ rb_module

struct module* rb_module
static

Definition at line 33 of file source.c.

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