configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / dbghelp / source.c
blobc8ecf26c9fc44b2767738177f2cc9058bebd1368
1 /*
2 * File source.c - source files management
4 * Copyright (C) 2004, Eric Pouech.
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.
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.
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
21 #include "config.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
27 #include "dbghelp_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
32 /******************************************************************
33 * source_find
35 * check whether a source file has already been stored
37 static unsigned source_find(const struct module* module, const char* name)
39 char* ptr = module->sources;
41 while (*ptr)
43 if (strcmp(ptr, name) == 0) return ptr - module->sources;
44 ptr += strlen(ptr) + 1;
46 return (unsigned)-1;
49 /******************************************************************
50 * source_new
52 * checks if source exists. if not, add it
54 unsigned source_new(struct module* module, const char* base, const char* name)
56 unsigned ret;
57 const char* full;
58 char* tmp = NULL;
60 if (!name) return (unsigned)-1;
61 if (!base || *name == '/')
62 full = name;
63 else
65 unsigned bsz = strlen(base);
67 tmp = HeapAlloc(GetProcessHeap(), 0, bsz + 1 + strlen(name) + 1);
68 if (!tmp) return (unsigned)-1;
69 full = tmp;
70 strcpy(tmp, base);
71 if (tmp[bsz - 1] != '/') tmp[bsz++] = '/';
72 strcpy(&tmp[bsz], name);
74 if (!module->sources || (ret = source_find(module, full)) == (unsigned)-1)
76 int len = strlen(full) + 1;
77 if (module->sources_used + len + 1 > module->sources_alloc)
79 if (!module->sources)
81 module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255;
82 module->sources = HeapAlloc(GetProcessHeap(), 0, module->sources_alloc);
84 else
86 module->sources_alloc = max( module->sources_alloc * 2,
87 (module->sources_used + len + 1 + 255) & ~255 );
88 module->sources = HeapReAlloc(GetProcessHeap(), 0, module->sources,
89 module->sources_alloc);
92 ret = module->sources_used;
93 memcpy(module->sources + module->sources_used, full, len);
94 module->sources_used += len;
95 module->sources[module->sources_used] = '\0';
97 HeapFree(GetProcessHeap(), 0, tmp);
98 return ret;
101 /******************************************************************
102 * source_get
104 * returns a stored source file name
106 const char* source_get(const struct module* module, unsigned idx)
108 if (idx == -1) return "";
109 assert(module->sources);
110 return module->sources + idx;
113 /******************************************************************
114 * SymEnumSourceFiles (DBGHELP.@)
117 BOOL WINAPI SymEnumSourceFiles(HANDLE hProcess, ULONG64 ModBase, PCSTR Mask,
118 PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles,
119 PVOID UserContext)
121 struct module_pair pair;
122 SOURCEFILE sf;
123 char* ptr;
125 if (!cbSrcFiles) return FALSE;
126 pair.pcs = process_find_by_handle(hProcess);
127 if (!pair.pcs) return FALSE;
129 if (ModBase)
131 pair.requested = module_find_by_addr(pair.pcs, ModBase, DMT_UNKNOWN);
132 if (!module_get_debug(&pair)) return FALSE;
134 else
136 if (Mask[0] == '!')
138 pair.requested = module_find_by_nameA(pair.pcs, Mask + 1);
139 if (!module_get_debug(&pair)) return FALSE;
141 else
143 FIXME("Unsupported yet (should get info from current context)\n");
144 return FALSE;
147 if (!pair.effective->sources) return FALSE;
148 for (ptr = pair.effective->sources; *ptr; ptr += strlen(ptr) + 1)
150 /* FIXME: not using Mask */
151 sf.ModBase = ModBase;
152 sf.FileName = ptr;
153 if (!cbSrcFiles(&sf, UserContext)) break;
156 return TRUE;
159 /******************************************************************
160 * SymGetSourceFileToken (DBGHELP.@)
163 BOOL WINAPI SymGetSourceFileToken(HANDLE hProcess, ULONG64 base,
164 PCSTR src, PVOID* token, DWORD* size)
166 FIXME("%p %s %s %p %p: stub!\n",
167 hProcess, wine_dbgstr_longlong(base), debugstr_a(src), token, size);
168 SetLastError(ERROR_NOT_SUPPORTED);
169 return FALSE;
172 /******************************************************************
173 * SymGetSourceFileTokenW (DBGHELP.@)
176 BOOL WINAPI SymGetSourceFileTokenW(HANDLE hProcess, ULONG64 base,
177 PCWSTR src, PVOID* token, DWORD* size)
179 FIXME("%p %s %s %p %p: stub!\n",
180 hProcess, wine_dbgstr_longlong(base), debugstr_w(src), token, size);
181 SetLastError(ERROR_NOT_SUPPORTED);
182 return FALSE;