cryptui: Implement CryptUIDlgSelectCertificateFromStore.
[wine.git] / programs / winedbg / symbol.c
blobaa88ffcbc74d2471949de0a2e44c32e825280fe7
1 /*
2 * Generate hash tables for Wine debugger symbols
4 * Copyright (C) 1993, Eric Youngdale.
5 * 2004-2005, Eric Pouech.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
27 #include "debugger.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
32 static BOOL symbol_get_debug_start(const struct dbg_type* func, ULONG64* start)
34 DWORD count, tag;
35 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
36 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
37 int i;
38 struct dbg_type child;
40 if (!func->id) return FALSE; /* native dbghelp not always fills the info field */
42 if (!types_get_info(func, TI_GET_CHILDRENCOUNT, &count)) return FALSE;
43 fcp->Start = 0;
44 while (count)
46 fcp->Count = min(count, 256);
47 if (types_get_info(func, TI_FINDCHILDREN, fcp))
49 for (i = 0; i < min(fcp->Count, count); i++)
51 child.module = func->module;
52 child.id = fcp->ChildId[i];
53 types_get_info(&child, TI_GET_SYMTAG, &tag);
54 if (tag != SymTagFuncDebugStart) continue;
55 return types_get_info(&child, TI_GET_ADDRESS, start);
57 count -= min(count, 256);
58 fcp->Start += 256;
59 fcp->Start += 256;
62 return FALSE;
65 static BOOL fill_sym_lvalue(const SYMBOL_INFO* sym, ULONG_PTR base,
66 struct dbg_lvalue* lvalue, char* buffer, size_t sz)
68 if (buffer) buffer[0] = '\0';
69 if (sym->Flags & SYMFLAG_REGISTER)
71 DWORD_PTR* pval;
73 if (!memory_get_register(sym->Register, &pval, buffer, sz))
74 return FALSE;
75 lvalue->cookie = DLV_HOST;
76 lvalue->addr.Offset = (DWORD_PTR)pval;
78 else if (sym->Flags & SYMFLAG_REGREL)
80 DWORD_PTR* pval;
81 size_t l;
83 *buffer++ = '['; sz--;
84 if (!memory_get_register(sym->Register, &pval, buffer, sz))
85 return FALSE;
86 l = strlen(buffer);
87 sz -= l;
88 buffer += l;
89 lvalue->cookie = DLV_TARGET;
90 lvalue->addr.Offset = (ULONG64)*pval + sym->Address;
91 if ((LONG_PTR)sym->Address >= 0)
92 snprintf(buffer, sz, "+%ld]", (ULONG_PTR)sym->Address);
93 else
94 snprintf(buffer, sz, "-%ld]", -(LONG_PTR)sym->Address);
96 else if (sym->Flags & SYMFLAG_VALUEPRESENT)
98 struct dbg_type type;
99 VARIANT v;
101 type.module = sym->ModBase;
102 type.id = sym->Index;
104 if (!types_get_info(&type, TI_GET_VALUE, &v))
106 if (buffer) snprintf(buffer, sz, "Couldn't get full value information for %s", sym->Name);
107 return FALSE;
109 else if (v.n1.n2.vt & VT_BYREF)
111 /* FIXME: this won't work for pointers or arrays, as we don't always
112 * know, if the value to be dereferenced lies in debuggee or
113 * debugger address space.
115 if (sym->Tag == SymTagPointerType || sym->Tag == SymTagArrayType)
117 if (buffer) snprintf(buffer, sz, "Couldn't dereference pointer for const value for %s", sym->Name);
118 return FALSE;
120 /* this is likely Wine's dbghelp which passes const values by reference
121 * (object is managed by dbghelp, hence in debugger address space)
123 lvalue->cookie = DLV_HOST;
124 lvalue->addr.Offset = (DWORD_PTR)sym->Value;
126 else
128 DWORD* pdw = (DWORD*)lexeme_alloc_size(sizeof(*pdw));
129 lvalue->cookie = DLV_HOST;
130 lvalue->addr.Offset = (DWORD_PTR)pdw;
131 *pdw = sym->Value;
134 else if (sym->Flags & SYMFLAG_LOCAL)
136 lvalue->cookie = DLV_TARGET;
137 lvalue->addr.Offset = base + sym->Address;
139 else if (sym->Flags & SYMFLAG_TLSREL)
141 PROCESS_BASIC_INFORMATION pbi;
142 THREAD_BASIC_INFORMATION tbi;
143 DWORD_PTR addr;
144 PEB peb;
145 PEB_LDR_DATA ldr_data;
146 PLIST_ENTRY head, current;
147 LDR_MODULE ldr_module;
148 unsigned tlsindex = -1;
150 if (NtQueryInformationProcess(dbg_curr_process->handle, ProcessBasicInformation,
151 &pbi, sizeof(pbi), NULL) ||
152 NtQueryInformationThread(dbg_curr_thread->handle, ThreadBasicInformation,
153 &tbi, sizeof(tbi), NULL))
155 tls_error:
156 if (buffer) snprintf(buffer, sz, "Cannot read TLS address\n");
157 return FALSE;
159 addr = (DWORD_PTR)&(((TEB*)tbi.TebBaseAddress)->ThreadLocalStoragePointer);
160 if (!dbg_read_memory((void*)addr, &addr, sizeof(addr)) ||
161 !dbg_read_memory(pbi.PebBaseAddress, &peb, sizeof(peb)) ||
162 !dbg_read_memory(peb.LdrData, &ldr_data, sizeof(ldr_data)))
163 goto tls_error;
164 current = ldr_data.InLoadOrderModuleList.Flink;
165 head = &((PEB_LDR_DATA*)peb.LdrData)->InLoadOrderModuleList;
168 if (!dbg_read_memory(CONTAINING_RECORD(current, LDR_MODULE, InLoadOrderModuleList),
169 &ldr_module, sizeof(ldr_module))) goto tls_error;
170 if ((DWORD_PTR)ldr_module.BaseAddress == sym->ModBase)
172 tlsindex = ldr_module.TlsIndex;
173 break;
175 current = ldr_module.InLoadOrderModuleList.Flink;
176 } while (current != head);
178 addr += tlsindex * sizeof(DWORD_PTR);
179 if (!dbg_read_memory((void*)addr, &addr, sizeof(addr))) goto tls_error;
180 lvalue->cookie = DLV_TARGET;
181 lvalue->addr.Offset = addr + sym->Address;
183 else
185 lvalue->cookie = DLV_TARGET;
186 lvalue->addr.Offset = sym->Address;
188 lvalue->addr.Mode = AddrModeFlat;
189 lvalue->type.module = sym->ModBase;
190 lvalue->type.id = sym->TypeIndex;
192 return TRUE;
195 struct sgv_data
197 #define NUMDBGV 100
198 struct
200 /* FIXME: NUMDBGV should be made variable */
201 struct dbg_lvalue lvalue;
202 DWORD flags;
203 DWORD sym_info;
204 } syms[NUMDBGV]; /* out : will be filled in with various found symbols */
205 int num; /* out : number of found symbols */
206 int num_thunks; /* out : number of thunks found */
207 const char* name; /* in : name of symbol to look up */
208 unsigned do_thunks : 1; /* in : whether we return thunks tags */
209 ULONG64 frame_offset; /* in : frame for local & parameter variables look up */
212 static BOOL CALLBACK sgv_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
214 struct sgv_data* sgv = ctx;
215 unsigned insp;
216 char tmp[64];
218 if (sym->Flags & SYMFLAG_THUNK)
220 if (!sgv->do_thunks) return TRUE;
221 sgv->num_thunks++;
224 if (sgv->num >= NUMDBGV)
226 dbg_printf("Too many addresses for symbol '%s', limiting the first %d\n",
227 sgv->name, NUMDBGV);
228 return FALSE;
230 WINE_TRACE("==> %s %s%s%s%s%s%s%s%s\n",
231 sym->Name,
232 (sym->Flags & SYMFLAG_FUNCTION) ? "func " : "",
233 (sym->Flags & SYMFLAG_FRAMEREL) ? "framerel " : "",
234 (sym->Flags & SYMFLAG_TLSREL) ? "tlsrel " : "",
235 (sym->Flags & SYMFLAG_REGISTER) ? "register " : "",
236 (sym->Flags & SYMFLAG_REGREL) ? "regrel " : "",
237 (sym->Flags & SYMFLAG_PARAMETER) ? "param " : "",
238 (sym->Flags & SYMFLAG_LOCAL) ? "local " : "",
239 (sym->Flags & SYMFLAG_THUNK) ? "thunk " : "");
241 /* always keep the thunks at end of the array */
242 insp = sgv->num;
243 if (sgv->num_thunks && !(sym->Flags & SYMFLAG_THUNK))
245 insp -= sgv->num_thunks;
246 memmove(&sgv->syms[insp + 1], &sgv->syms[insp],
247 sizeof(sgv->syms[0]) * sgv->num_thunks);
249 if (!fill_sym_lvalue(sym, sgv->frame_offset, &sgv->syms[insp].lvalue, tmp, sizeof(tmp)))
251 dbg_printf("%s: %s\n", sym->Name, tmp);
252 return TRUE;
254 sgv->syms[insp].flags = sym->Flags;
255 sgv->syms[insp].sym_info = sym->Index;
256 sgv->num++;
258 return TRUE;
261 enum sym_get_lval symbol_picker_interactive(const char* name, const struct sgv_data* sgv,
262 struct dbg_lvalue* rtn)
264 char buffer[512];
265 unsigned i;
267 if (!dbg_interactiveP)
269 dbg_printf("More than one symbol named %s, picking the first one\n", name);
270 *rtn = sgv->syms[0].lvalue;
271 return sglv_found;
274 dbg_printf("Many symbols with name '%s', "
275 "choose the one you want (<cr> to abort):\n", name);
276 for (i = 0; i < sgv->num; i++)
278 if (sgv->num - sgv->num_thunks > 1 && (sgv->syms[i].flags & SYMFLAG_THUNK) && !DBG_IVAR(AlwaysShowThunks))
279 continue;
280 dbg_printf("[%d]: ", i + 1);
281 if (sgv->syms[i].flags & (SYMFLAG_LOCAL | SYMFLAG_PARAMETER))
283 dbg_printf("%s %sof %s\n",
284 sgv->syms[i].flags & SYMFLAG_PARAMETER ? "Parameter" : "Local variable",
285 sgv->syms[i].flags & (SYMFLAG_REGISTER|SYMFLAG_REGREL) ? "(in a register) " : "",
286 name);
288 else if (sgv->syms[i].flags & SYMFLAG_THUNK)
290 print_address(&sgv->syms[i].lvalue.addr, TRUE);
291 /* FIXME: should display where the thunks points to */
292 dbg_printf(" thunk %s\n", name);
294 else
296 print_address(&sgv->syms[i].lvalue.addr, TRUE);
297 dbg_printf("\n");
302 if (input_read_line("=> ", buffer, sizeof(buffer)))
304 if (buffer[0] == '\0') return sglv_aborted;
305 i = atoi(buffer);
306 if (i < 1 || i > sgv->num)
307 dbg_printf("Invalid choice %d\n", i);
309 else return sglv_aborted;
310 } while (i < 1 || i > sgv->num);
312 /* The array is 0-based, but the choices are 1..n,
313 * so we have to subtract one before returning.
315 *rtn = sgv->syms[i - 1].lvalue;
316 return sglv_found;
319 enum sym_get_lval symbol_picker_scoped(const char* name, const struct sgv_data* sgv,
320 struct dbg_lvalue* rtn)
322 unsigned i;
323 int local = -1;
325 for (i = 0; i < sgv->num; i++)
327 if (sgv->num - sgv->num_thunks > 1 && (sgv->syms[i].flags & SYMFLAG_THUNK) && !DBG_IVAR(AlwaysShowThunks))
328 continue;
329 if (sgv->syms[i].flags & (SYMFLAG_LOCAL | SYMFLAG_PARAMETER))
331 if (local == -1)
332 local = i;
333 else
335 /* FIXME: several locals with same name... which one to pick ?? */
336 dbg_printf("Several local variables/parameters for %s, aborting\n", name);
337 return sglv_aborted;
341 if (local != -1)
343 *rtn = sgv->syms[local].lvalue;
344 return sglv_found;
346 /* no locals found, multiple globals... abort for now */
347 dbg_printf("Several global variables for %s, aborting\n", name);
348 return sglv_aborted;
351 symbol_picker_t symbol_current_picker = symbol_picker_interactive;
353 /***********************************************************************
354 * symbol_get_lvalue
356 * Get the address of a named symbol.
357 * Return values:
358 * sglv_found: if the symbol is found
359 * sglv_unknown: if the symbol isn't found
360 * sglv_aborted: some error occurred (likely, many symbols of same name exist,
361 * and user didn't pick one of them)
363 enum sym_get_lval symbol_get_lvalue(const char* name, const int lineno,
364 struct dbg_lvalue* rtn, BOOL bp_disp)
366 struct sgv_data sgv;
367 int i;
368 char buffer[512];
369 DWORD opt;
370 IMAGEHLP_STACK_FRAME ihsf;
372 if (strlen(name) + 4 > sizeof(buffer))
374 WINE_WARN("Too long symbol (%s)\n", name);
375 return sglv_unknown;
378 sgv.num = 0;
379 sgv.num_thunks = 0;
380 sgv.name = &buffer[2];
381 sgv.do_thunks = DBG_IVAR(AlwaysShowThunks);
383 if (strchr(name, '!'))
385 strcpy(buffer, name);
387 else
389 buffer[0] = '*';
390 buffer[1] = '!';
391 strcpy(&buffer[2], name);
394 /* this is a wine specific options to return also ELF modules in the
395 * enumeration
397 SymSetOptions((opt = SymGetOptions()) | 0x40000000);
398 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);
400 if (!sgv.num)
402 const char* ptr = strchr(name, '!');
403 if ((ptr && ptr[1] != '_') || (!ptr && *name != '_'))
405 if (ptr)
407 int offset = ptr - name;
408 memcpy(buffer, name, offset + 1);
409 buffer[offset + 1] = '_';
410 strcpy(&buffer[offset + 2], ptr + 1);
412 else
414 buffer[0] = '*';
415 buffer[1] = '!';
416 buffer[2] = '_';
417 strcpy(&buffer[3], name);
419 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);
422 SymSetOptions(opt);
424 /* now grab local symbols */
425 if (stack_get_current_frame(&ihsf) && sgv.num < NUMDBGV)
427 sgv.frame_offset = ihsf.FrameOffset;
428 SymEnumSymbols(dbg_curr_process->handle, 0, name, sgv_cb, (void*)&sgv);
431 if (!sgv.num)
433 dbg_printf("No symbols found for %s\n", name);
434 return sglv_unknown;
437 /* recompute potential offsets for functions (linenumber, skip prolog) */
438 for (i = 0; i < sgv.num; i++)
440 if (sgv.syms[i].flags & (SYMFLAG_REGISTER|SYMFLAG_REGREL|SYMFLAG_LOCAL|SYMFLAG_THUNK))
441 continue;
443 if (lineno == -1)
445 struct dbg_type type;
446 ULONG64 addr;
448 type.module = sgv.syms[i].lvalue.type.module;
449 type.id = sgv.syms[i].sym_info;
450 if (bp_disp && symbol_get_debug_start(&type, &addr))
451 sgv.syms[i].lvalue.addr.Offset = addr;
453 else
455 DWORD disp;
456 IMAGEHLP_LINE64 il;
457 BOOL found = FALSE;
459 il.SizeOfStruct = sizeof(il);
460 SymGetLineFromAddr64(dbg_curr_process->handle,
461 (DWORD_PTR)memory_to_linear_addr(&sgv.syms[i].lvalue.addr),
462 &disp, &il);
465 if (lineno == il.LineNumber)
467 sgv.syms[i].lvalue.addr.Offset = il.Address;
468 found = TRUE;
469 break;
471 } while (SymGetLineNext64(dbg_curr_process->handle, &il));
472 if (!found)
473 WINE_FIXME("No line (%d) found for %s (setting to symbol start)\n",
474 lineno, name);
478 if (sgv.num - sgv.num_thunks > 1 || /* many symbols non thunks (and showing only non thunks) */
479 (sgv.num > 1 && DBG_IVAR(AlwaysShowThunks)) || /* many symbols (showing symbols & thunks) */
480 (sgv.num == sgv.num_thunks && sgv.num_thunks > 1))
482 return symbol_current_picker(name, &sgv, rtn);
484 /* first symbol is the one we want:
485 * - only one symbol found,
486 * - or many symbols but only one non thunk when AlwaysShowThunks is FALSE
488 *rtn = sgv.syms[0].lvalue;
489 return sglv_found;
492 BOOL symbol_is_local(const char* name)
494 struct sgv_data sgv;
495 IMAGEHLP_STACK_FRAME ihsf;
497 sgv.num = 0;
498 sgv.num_thunks = 0;
499 sgv.name = name;
500 sgv.do_thunks = FALSE;
502 if (stack_get_current_frame(&ihsf))
504 sgv.frame_offset = ihsf.FrameOffset;
505 SymEnumSymbols(dbg_curr_process->handle, 0, name, sgv_cb, (void*)&sgv);
507 return sgv.num > 0;
510 /***********************************************************************
511 * symbol_read_symtable
513 * Read a symbol file into the hash table.
515 void symbol_read_symtable(const char* filename, unsigned long offset)
517 dbg_printf("No longer supported\n");
519 #if 0
520 /* FIXME: have to implement SymAddSymbol in dbghelp, but likely we'll need to link
521 * this with an already loaded module !!
523 FILE* symbolfile;
524 unsigned addr;
525 char type;
526 char* cpnt;
527 char buffer[256];
528 char name[256];
530 if (!(symbolfile = fopen(filename, "r")))
532 WINE_WARN("Unable to open symbol table %s\n", filename);
533 return;
536 dbg_printf("Reading symbols from file %s\n", filename);
538 while (1)
540 fgets(buffer, sizeof(buffer), symbolfile);
541 if (feof(symbolfile)) break;
543 /* Strip any text after a # sign (i.e. comments) */
544 cpnt = strchr(buffer, '#');
545 if (cpnt) *cpnt = '\0';
547 /* Quietly ignore any lines that have just whitespace */
548 for (cpnt = buffer; *cpnt; cpnt++)
550 if (*cpnt != ' ' && *cpnt != '\t') break;
552 if (!*cpnt || *cpnt == '\n') continue;
554 if (sscanf(buffer, "%lx %c %s", &addr, &type, name) == 3)
556 if (value.addr.off + offset < value.addr.off)
557 WINE_WARN("Address wrap around\n");
558 value.addr.off += offset;
559 SymAddSymbol(current_process->handle, BaseOfDll,
560 name, addr, 0, 0);
563 fclose(symbolfile);
564 #endif
567 /***********************************************************************
568 * symbol_get_function_line_status
570 * Find the symbol nearest to a given address.
572 enum dbg_line_status symbol_get_function_line_status(const ADDRESS64* addr)
574 IMAGEHLP_LINE64 il;
575 DWORD disp;
576 ULONG64 disp64, start;
577 DWORD_PTR lin = (DWORD_PTR)memory_to_linear_addr(addr);
578 char buffer[sizeof(SYMBOL_INFO) + 256];
579 SYMBOL_INFO* sym = (SYMBOL_INFO*)buffer;
580 struct dbg_type func;
582 il.SizeOfStruct = sizeof(il);
583 sym->SizeOfStruct = sizeof(SYMBOL_INFO);
584 sym->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
586 /* do we have some info for lin address ? */
587 if (!SymFromAddr(dbg_curr_process->handle, lin, &disp64, sym))
589 ADDRESS64 jumpee;
590 /* some compilers insert thunks in their code without debug info associated
591 * take care of this situation
593 if (dbg_curr_process->be_cpu->is_jump((void*)lin, &jumpee))
594 return symbol_get_function_line_status(&jumpee);
595 return dbg_no_line_info;
598 switch (sym->Tag)
600 case SymTagThunk:
601 /* FIXME: so far dbghelp doesn't return the 16 <=> 32 thunks
602 * and furthermore, we no longer take care of them !!!
604 return dbg_in_a_thunk;
605 case SymTagFunction:
606 case SymTagPublicSymbol: break;
607 default:
608 WINE_FIXME("Unexpected sym-tag 0x%08x\n", sym->Tag);
609 case SymTagData:
610 return dbg_no_line_info;
612 /* we should have a function now */
613 if (!SymGetLineFromAddr64(dbg_curr_process->handle, lin, &disp, &il))
614 return dbg_no_line_info;
616 func.module = sym->ModBase;
617 func.id = sym->Index;
619 if (symbol_get_debug_start(&func, &start) && lin < start)
620 return dbg_not_on_a_line_number;
622 if (!sym->Size) sym->Size = 0x100000;
623 if (il.FileName && il.FileName[0] && disp < sym->Size)
624 return (disp == 0) ? dbg_on_a_line_number : dbg_not_on_a_line_number;
626 return dbg_no_line_info;
629 /***********************************************************************
630 * symbol_get_line
632 * Find the symbol nearest to a given address.
633 * Returns sourcefile name and line number in a format that the listing
634 * handler can deal with.
636 BOOL symbol_get_line(const char* filename, const char* name,
637 IMAGEHLP_LINE64* line)
639 struct sgv_data sgv;
640 char buffer[512];
641 DWORD opt, disp;
642 unsigned i;
643 BOOL found = FALSE;
644 IMAGEHLP_LINE64 il;
646 sgv.num = 0;
647 sgv.num_thunks = 0;
648 sgv.name = &buffer[2];
649 sgv.do_thunks = FALSE;
651 buffer[0] = '*';
652 buffer[1] = '!';
653 strcpy(&buffer[2], name);
655 /* this is a wine specific options to return also ELF modules in the
656 * enumeration
658 SymSetOptions((opt = SymGetOptions()) | 0x40000000);
659 if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
661 SymSetOptions(opt);
662 return FALSE;
665 if (!sgv.num && (name[0] != '_'))
667 buffer[2] = '_';
668 strcpy(&buffer[3], name);
669 if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
671 SymSetOptions(opt);
672 return FALSE;
675 SymSetOptions(opt);
677 for (i = 0; i < sgv.num; i++)
679 DWORD_PTR linear = (DWORD_PTR)memory_to_linear_addr(&sgv.syms[i].lvalue.addr);
681 il.SizeOfStruct = sizeof(il);
682 if (!SymGetLineFromAddr64(dbg_curr_process->handle, linear, &disp, &il))
683 continue;
684 if (filename && strcmp(il.FileName, filename)) continue;
685 if (found)
687 WINE_FIXME("Several found, returning first (may not be what you want)...\n");
688 break;
690 found = TRUE;
691 *line = il;
693 if (!found)
695 if (filename) dbg_printf("No such function %s in %s\n", name, filename);
696 else dbg_printf("No such function %s\n", name);
697 return FALSE;
699 return TRUE;
702 /******************************************************************
703 * symbol_print_local
705 * Overall format is:
706 * <name>=<value> in non detailed form
707 * <name>=<value> (local|pmt <where>) in detailed form
708 * Note <value> can be an error message in case of error
710 void symbol_print_local(const SYMBOL_INFO* sym, DWORD_PTR base, BOOL detailed)
712 struct dbg_lvalue lvalue;
713 char buffer[64];
715 dbg_printf("%s=", sym->Name);
717 if (fill_sym_lvalue(sym, base, &lvalue, buffer, sizeof(buffer)))
719 print_value(&lvalue, 0, 1);
720 if (detailed)
721 dbg_printf(" (%s %s)",
722 (sym->Flags & SYMFLAG_PARAMETER) ? "parameter" : "local",
723 buffer);
725 else
727 dbg_printf("%s", buffer);
728 if (detailed)
729 dbg_printf(" (%s)",
730 (sym->Flags & SYMFLAG_PARAMETER) ? "parameter" : "local");
734 static BOOL CALLBACK info_locals_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
736 struct dbg_type type;
738 dbg_printf("\t");
739 type.module = sym->ModBase;
740 type.id = sym->TypeIndex;
741 types_print_type(&type, FALSE);
743 dbg_printf(" ");
744 symbol_print_local(sym, (DWORD_PTR)ctx, TRUE);
745 dbg_printf("\n");
747 return TRUE;
750 BOOL symbol_info_locals(void)
752 IMAGEHLP_STACK_FRAME ihsf;
753 ADDRESS64 addr;
755 stack_get_current_frame(&ihsf);
756 addr.Mode = AddrModeFlat;
757 addr.Offset = ihsf.InstructionOffset;
758 print_address(&addr, FALSE);
759 dbg_printf(": (%08lx)\n", (DWORD_PTR)ihsf.FrameOffset);
760 SymEnumSymbols(dbg_curr_process->handle, 0, NULL, info_locals_cb, (void*)(DWORD_PTR)ihsf.FrameOffset);
762 return TRUE;
766 static BOOL CALLBACK symbols_info_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
768 struct dbg_type type;
769 IMAGEHLP_MODULE mi;
771 mi.SizeOfStruct = sizeof(mi);
773 if (!SymGetModuleInfo(dbg_curr_process->handle, sym->ModBase, &mi))
774 mi.ModuleName[0] = '\0';
775 else
777 size_t len = strlen(mi.ModuleName);
778 if (len > 5 && !strcmp(mi.ModuleName + len - 5, "<elf>"))
779 mi.ModuleName[len - 5] = '\0';
782 dbg_printf("%08lx: %s!%s", (ULONG_PTR)sym->Address, mi.ModuleName, sym->Name);
783 type.id = sym->TypeIndex;
784 type.module = sym->ModBase;
786 if (sym->TypeIndex != dbg_itype_none && sym->TypeIndex != 0)
788 dbg_printf(" ");
789 types_print_type(&type, FALSE);
791 dbg_printf("\n");
792 return TRUE;
795 void symbol_info(const char* str)
797 char buffer[512];
798 DWORD opt;
800 if (strlen(str) + 3 >= sizeof(buffer))
802 dbg_printf("Symbol too long (%s)\n", str);
803 return;
805 buffer[0] = '*';
806 buffer[1] = '!';
807 strcpy(&buffer[2], str);
808 /* this is a wine specific options to return also ELF modules in the
809 * enumeration
811 SymSetOptions((opt = SymGetOptions()) | 0x40000000);
812 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, symbols_info_cb, NULL);
813 SymSetOptions(opt);