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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "dbghelp_private.h"
28 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
35 /******************************************************************
38 * check whether a source file has already been stored
40 static unsigned source_find(const struct module
* module
, const char* name
)
42 char* ptr
= module
->sources
;
46 if (strcmp(ptr
, name
) == 0) return ptr
- module
->sources
;
47 ptr
+= strlen(ptr
) + 1;
52 /******************************************************************
55 * checks if source exists. if not, add it
57 unsigned source_new(struct module
* module
, const char* name
)
62 if (!name
) return (unsigned)-1;
63 if (module
->sources
&& (ret
= source_find(module
, name
)) != (unsigned)-1)
66 len
= strlen(name
) + 1;
67 if (module
->sources_used
+ len
+ 1 > module
->sources_alloc
)
69 /* Alloc by block of 256 bytes */
70 module
->sources_alloc
= (module
->sources_used
+ len
+ 1 + 255) & ~255;
72 module
->sources
= HeapAlloc(GetProcessHeap(), 0, module
->sources_alloc
);
74 module
->sources
= HeapReAlloc(GetProcessHeap(), 0, module
->sources
,
75 module
->sources_alloc
);
77 ret
= module
->sources_used
;
78 strcpy(module
->sources
+ module
->sources_used
, name
);
79 module
->sources_used
+= len
;
80 module
->sources
[module
->sources_used
] = '\0';
84 /******************************************************************
87 * returns a stored source file name
89 const char* source_get(const struct module
* module
, unsigned idx
)
91 if (idx
== -1) return "";
92 assert(module
->sources
);
93 return module
->sources
+ idx
;
96 /******************************************************************
97 * SymEnumSourceFiles (DBGHELP.@)
100 BOOL WINAPI
SymEnumSourceFiles(HANDLE hProcess
, ULONG64 ModBase
, PCSTR Mask
,
101 PSYM_ENUMSOURCEFILES_CALLBACK cbSrcFiles
,
105 struct module_pair pair
;
109 if (!cbSrcFiles
) return FALSE
;
110 pcs
= process_find_by_handle(hProcess
);
111 if (!pcs
) return FALSE
;
115 pair
.requested
= module_find_by_addr(pcs
, ModBase
, DMT_UNKNOWN
);
116 if (!module_get_debug(pcs
, &pair
)) return FALSE
;
122 pair
.requested
= module_find_by_name(pcs
, Mask
+ 1, DMT_UNKNOWN
);
123 if (!module_get_debug(pcs
, &pair
)) return FALSE
;
127 FIXME("Unsupported yet (should get info from current context)\n");
131 if (!pair
.effective
->sources
) return FALSE
;
132 for (ptr
= pair
.effective
->sources
; *ptr
; ptr
+= strlen(ptr
) + 1)
134 /* FIXME: not using Mask */
135 sf
.ModBase
= ModBase
;
137 if (!cbSrcFiles(&sf
, UserContext
)) break;
143 /******************************************************************
144 * SymEnumLines (DBGHELP.@)
147 BOOL WINAPI
SymEnumLines(HANDLE hProcess
, ULONG64 base
, PCSTR compiland
,
148 PCSTR srcfile
, PSYM_ENUMLINES_CALLBACK cb
, PVOID user
)
151 struct module_pair pair
;
152 struct hash_table_iter hti
;
155 struct line_info
* dli
;
160 if (!cb
) return FALSE
;
161 pcs
= process_find_by_handle(hProcess
);
162 if (!pcs
) return FALSE
;
163 if (!(dbghelp_options
& SYMOPT_LOAD_LINES
)) return TRUE
;
164 if (regcomp(&re
, srcfile
, REG_NOSUB
))
166 FIXME("Couldn't compile %s\n", srcfile
);
167 SetLastError(ERROR_INVALID_PARAMETER
);
170 if (compiland
) FIXME("Unsupported yet (filtering on compiland %s)\n", compiland
);
171 pair
.requested
= module_find_by_addr(pcs
, base
, DMT_UNKNOWN
);
172 if (!module_get_debug(pcs
, &pair
)) return FALSE
;
174 sci
.SizeOfStruct
= sizeof(sci
);
177 hash_table_iter_init(&pair
.effective
->ht_symbols
, &hti
, NULL
);
178 while ((ptr
= hash_table_iter_up(&hti
)))
180 sym
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
181 if (sym
->symt
.tag
!= SymTagFunction
) continue;
184 sci
.FileName
[0] = '\0';
185 while ((dli
= vector_iter_up(&((struct symt_function
*)sym
)->vlines
, dli
)))
187 if (dli
->is_source_file
)
189 file
= (char*)source_get(pair
.effective
, dli
->u
.source_file
);
190 if (regexec(&re
, file
, 0, NULL
, 0) != 0) file
= "";
191 strcpy(sci
.FileName
, file
);
193 else if (sci
.FileName
[0])
196 sci
.Obj
[0] = '\0'; /* FIXME */
197 sci
.LineNumber
= dli
->line_number
;
198 sci
.Address
= dli
->u
.pc_offset
;
199 if (!cb(&sci
, user
)) break;
206 /******************************************************************
207 * SymGetSourceFileToken (DBGHELP.@)
210 BOOL WINAPI
SymGetSourceFileToken(HANDLE hProcess
, ULONG64 base
,
211 PCSTR src
, PVOID
* token
, DWORD
* size
)
213 FIXME("%p %s %s %p %p: stub!\n",
214 hProcess
, wine_dbgstr_longlong(base
), debugstr_a(src
), token
, size
);
215 SetLastError(ERROR_NOT_SUPPORTED
);