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
27 #include "dbghelp_private.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
32 static struct module
* rb_module
;
35 struct wine_rb_entry entry
;
39 static void *source_rb_alloc(size_t size
)
41 return HeapAlloc(GetProcessHeap(), 0, size
);
44 static void *source_rb_realloc(void *ptr
, size_t size
)
46 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
49 static void source_rb_free(void *ptr
)
51 HeapFree(GetProcessHeap(), 0, ptr
);
54 static int source_rb_compare(const void *key
, const struct wine_rb_entry
*entry
)
56 const struct source_rb
*t
= WINE_RB_ENTRY_VALUE(entry
, const struct source_rb
, entry
);
58 return strcmp((const char*)key
, rb_module
->sources
+ t
->source
);
61 const struct wine_rb_functions source_rb_functions
=
69 /******************************************************************
72 * check whether a source file has already been stored
74 static unsigned source_find(const char* name
)
76 struct wine_rb_entry
* e
;
78 e
= wine_rb_get(&rb_module
->sources_offsets_tree
, name
);
80 return WINE_RB_ENTRY_VALUE(e
, struct source_rb
, entry
)->source
;
83 /******************************************************************
86 * checks if source exists. if not, add it
88 unsigned source_new(struct module
* module
, const char* base
, const char* name
)
94 if (!name
) return ret
;
95 if (!base
|| *name
== '/')
99 unsigned bsz
= strlen(base
);
101 tmp
= HeapAlloc(GetProcessHeap(), 0, bsz
+ 1 + strlen(name
) + 1);
102 if (!tmp
) return ret
;
105 if (tmp
[bsz
- 1] != '/') tmp
[bsz
++] = '/';
106 strcpy(&tmp
[bsz
], name
);
109 if (!module
->sources
|| (ret
= source_find(full
)) == (unsigned)-1)
112 int len
= strlen(full
) + 1;
113 struct source_rb
* rb
;
115 if (module
->sources_used
+ len
+ 1 > module
->sources_alloc
)
117 if (!module
->sources
)
119 module
->sources_alloc
= (module
->sources_used
+ len
+ 1 + 255) & ~255;
120 new = HeapAlloc(GetProcessHeap(), 0, module
->sources_alloc
);
124 module
->sources_alloc
= max( module
->sources_alloc
* 2,
125 (module
->sources_used
+ len
+ 1 + 255) & ~255 );
126 new = HeapReAlloc(GetProcessHeap(), 0, module
->sources
,
127 module
->sources_alloc
);
130 module
->sources
= new;
132 ret
= module
->sources_used
;
133 memcpy(module
->sources
+ module
->sources_used
, full
, len
);
134 module
->sources_used
+= len
;
135 module
->sources
[module
->sources_used
] = '\0';
136 if ((rb
= pool_alloc(&module
->pool
, sizeof(*rb
))))
139 wine_rb_put(&module
->sources_offsets_tree
, full
, &rb
->entry
);
143 HeapFree(GetProcessHeap(), 0, tmp
);
147 /******************************************************************
150 * returns a stored source file name
152 const char* source_get(const struct module
* module
, unsigned idx
)
154 if (idx
== -1) return "";
155 assert(module
->sources
);
156 return module
->sources
+ idx
;
159 /******************************************************************
160 * SymEnumSourceFiles (DBGHELP.@)
163 BOOL WINAPI
SymEnumSourceFiles(HANDLE hProcess
, ULONG64 ModBase
, PCSTR Mask
,
164 PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles
,
167 struct module_pair pair
;
171 if (!cbSrcFiles
) return FALSE
;
172 pair
.pcs
= process_find_by_handle(hProcess
);
173 if (!pair
.pcs
) return FALSE
;
177 pair
.requested
= module_find_by_addr(pair
.pcs
, ModBase
, DMT_UNKNOWN
);
178 if (!module_get_debug(&pair
)) return FALSE
;
184 pair
.requested
= module_find_by_nameA(pair
.pcs
, Mask
+ 1);
185 if (!module_get_debug(&pair
)) return FALSE
;
189 FIXME("Unsupported yet (should get info from current context)\n");
193 if (!pair
.effective
->sources
) return FALSE
;
194 for (ptr
= pair
.effective
->sources
; *ptr
; ptr
+= strlen(ptr
) + 1)
196 /* FIXME: not using Mask */
197 sf
.ModBase
= ModBase
;
199 if (!cbSrcFiles(&sf
, UserContext
)) break;
205 /******************************************************************
206 * SymGetSourceFileToken (DBGHELP.@)
209 BOOL WINAPI
SymGetSourceFileToken(HANDLE hProcess
, ULONG64 base
,
210 PCSTR src
, PVOID
* token
, DWORD
* size
)
212 FIXME("%p %s %s %p %p: stub!\n",
213 hProcess
, wine_dbgstr_longlong(base
), debugstr_a(src
), token
, size
);
214 SetLastError(ERROR_NOT_SUPPORTED
);
218 /******************************************************************
219 * SymGetSourceFileTokenW (DBGHELP.@)
222 BOOL WINAPI
SymGetSourceFileTokenW(HANDLE hProcess
, ULONG64 base
,
223 PCWSTR src
, PVOID
* token
, DWORD
* size
)
225 FIXME("%p %s %s %p %p: stub!\n",
226 hProcess
, wine_dbgstr_longlong(base
), debugstr_w(src
), token
, size
);
227 SetLastError(ERROR_NOT_SUPPORTED
);