wineoss: Fix missing break statement.
[wine.git] / programs / winedbg / symbol.c
blob4c4486ce5d86f0f5a994e3ac00953c84ac6eed90
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 <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "debugger.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
31 static BOOL symbol_get_debug_start(const struct dbg_type* func, ULONG64* start)
33 DWORD count, tag;
34 char buffer[sizeof(TI_FINDCHILDREN_PARAMS) + 256 * sizeof(DWORD)];
35 TI_FINDCHILDREN_PARAMS* fcp = (TI_FINDCHILDREN_PARAMS*)buffer;
36 int i;
37 struct dbg_type child;
39 if (!func->id) return FALSE; /* native dbghelp not always fills the info field */
41 if (!types_get_info(func, TI_GET_CHILDRENCOUNT, &count)) return FALSE;
42 fcp->Start = 0;
43 while (count)
45 fcp->Count = min(count, 256);
46 if (types_get_info(func, TI_FINDCHILDREN, fcp))
48 for (i = 0; i < min(fcp->Count, count); i++)
50 child.module = func->module;
51 child.id = fcp->ChildId[i];
52 types_get_info(&child, TI_GET_SYMTAG, &tag);
53 if (tag != SymTagFuncDebugStart) continue;
54 return types_get_info(&child, TI_GET_ADDRESS, start);
56 count -= min(count, 256);
57 fcp->Start += 256;
58 fcp->Start += 256;
61 return FALSE;
64 static BOOL fill_sym_lvalue(const SYMBOL_INFO* sym, ULONG_PTR base,
65 struct dbg_lvalue* lvalue, char* buffer, size_t sz)
67 if (buffer) buffer[0] = '\0';
68 if (sym->Flags & SYMFLAG_REGISTER)
70 if (!memory_get_register(sym->Register, lvalue, buffer, sz))
71 return FALSE;
73 else if (sym->Flags & SYMFLAG_REGREL)
75 size_t l;
77 *buffer++ = '['; sz--;
78 if (!memory_get_register(sym->Register, lvalue, buffer, sz))
79 return FALSE;
80 l = strlen(buffer);
81 sz -= l;
82 buffer += l;
83 init_lvalue(lvalue, TRUE, (void*)(DWORD_PTR)(types_extract_as_integer(lvalue) + sym->Address));
84 if ((LONG64)sym->Address >= 0)
85 snprintf(buffer, sz, "+%I64d]", sym->Address);
86 else
87 snprintf(buffer, sz, "-%I64d]", -(LONG64)sym->Address);
89 else if (sym->Flags & SYMFLAG_VALUEPRESENT)
91 struct dbg_type type;
92 VARIANT v;
94 type.module = sym->ModBase;
95 type.id = sym->Index;
97 if (!types_get_info(&type, TI_GET_VALUE, &v))
99 if (buffer) snprintf(buffer, sz, "Couldn't get full value information for %s", sym->Name);
100 return FALSE;
102 else if (V_ISBYREF(&v))
104 /* FIXME: this won't work for pointers or arrays, as we don't always
105 * know, if the value to be dereferenced lies in debuggee or
106 * debugger address space.
108 if (sym->Tag == SymTagPointerType || sym->Tag == SymTagArrayType)
110 if (buffer) snprintf(buffer, sz, "Couldn't dereference pointer for const value for %s", sym->Name);
111 return FALSE;
113 /* this is likely Wine's dbghelp which passes const values by reference
114 * (object is managed by dbghelp, hence in debugger address space)
116 init_lvalue(lvalue, FALSE, (void*)(DWORD_PTR)sym->Value);
118 else
120 DWORD* pdw = (DWORD*)lexeme_alloc_size(sizeof(*pdw));
121 init_lvalue(lvalue, FALSE, pdw);
122 *pdw = sym->Value;
125 else if (sym->Flags & SYMFLAG_LOCAL)
127 init_lvalue(lvalue, TRUE, (void*)(DWORD_PTR)(base + sym->Address));
129 else if (sym->Flags & SYMFLAG_TLSREL)
131 PROCESS_BASIC_INFORMATION pbi;
132 THREAD_BASIC_INFORMATION tbi;
133 DWORD_PTR addr;
134 PEB peb;
135 PEB_LDR_DATA ldr_data;
136 PLIST_ENTRY head, current;
137 LDR_DATA_TABLE_ENTRY ldr_module;
138 unsigned tlsindex = -1;
140 if (NtQueryInformationProcess(dbg_curr_process->handle, ProcessBasicInformation,
141 &pbi, sizeof(pbi), NULL) ||
142 NtQueryInformationThread(dbg_curr_thread->handle, ThreadBasicInformation,
143 &tbi, sizeof(tbi), NULL))
145 tls_error:
146 if (buffer) snprintf(buffer, sz, "Cannot read TLS address\n");
147 return FALSE;
149 addr = (DWORD_PTR)&(((TEB*)tbi.TebBaseAddress)->ThreadLocalStoragePointer);
150 if (!dbg_read_memory((void*)addr, &addr, sizeof(addr)) ||
151 !dbg_read_memory(pbi.PebBaseAddress, &peb, sizeof(peb)) ||
152 !dbg_read_memory(peb.LdrData, &ldr_data, sizeof(ldr_data)))
153 goto tls_error;
154 current = ldr_data.InLoadOrderModuleList.Flink;
155 head = &((PEB_LDR_DATA*)peb.LdrData)->InLoadOrderModuleList;
158 if (!dbg_read_memory(CONTAINING_RECORD(current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
159 &ldr_module, sizeof(ldr_module))) goto tls_error;
160 if ((DWORD_PTR)ldr_module.DllBase == sym->ModBase)
162 tlsindex = ldr_module.TlsIndex;
163 break;
165 current = ldr_module.InLoadOrderLinks.Flink;
166 } while (current != head);
168 addr += tlsindex * sizeof(DWORD_PTR);
169 if (!dbg_read_memory((void*)addr, &addr, sizeof(addr))) goto tls_error;
170 init_lvalue(lvalue, TRUE, (void*)(DWORD_PTR)(addr + sym->Address));
172 else
174 init_lvalue(lvalue, TRUE, (void*)(DWORD_PTR)sym->Address);
176 lvalue->addr.Mode = AddrModeFlat;
177 lvalue->type.module = sym->ModBase;
178 lvalue->type.id = sym->TypeIndex;
180 return TRUE;
183 struct sgv_data
185 #define NUMDBGV 100
186 struct
188 /* FIXME: NUMDBGV should be made variable */
189 struct dbg_lvalue lvalue;
190 DWORD flags;
191 DWORD sym_info;
192 } syms[NUMDBGV]; /* out : will be filled in with various found symbols */
193 int num; /* out : number of found symbols */
194 int num_thunks; /* out : number of thunks found */
195 const char* name; /* in : name of symbol to look up */
196 unsigned do_thunks : 1; /* in : whether we return thunks tags */
197 ULONG64 frame_offset; /* in : frame for local & parameter variables look up */
200 static BOOL CALLBACK sgv_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
202 struct sgv_data* sgv = ctx;
203 unsigned insp;
204 char tmp[64];
206 if (sym->Flags & SYMFLAG_THUNK)
208 if (!sgv->do_thunks) return TRUE;
209 sgv->num_thunks++;
212 if (sgv->num >= NUMDBGV)
214 dbg_printf("Too many addresses for symbol '%s', limiting the first %d\n",
215 sgv->name, NUMDBGV);
216 return FALSE;
218 WINE_TRACE("==> %s %s%s%s%s%s%s%s%s\n",
219 sym->Name,
220 (sym->Flags & SYMFLAG_FUNCTION) ? "func " : "",
221 (sym->Flags & SYMFLAG_FRAMEREL) ? "framerel " : "",
222 (sym->Flags & SYMFLAG_TLSREL) ? "tlsrel " : "",
223 (sym->Flags & SYMFLAG_REGISTER) ? "register " : "",
224 (sym->Flags & SYMFLAG_REGREL) ? "regrel " : "",
225 (sym->Flags & SYMFLAG_PARAMETER) ? "param " : "",
226 (sym->Flags & SYMFLAG_LOCAL) ? "local " : "",
227 (sym->Flags & SYMFLAG_THUNK) ? "thunk " : "");
229 /* always keep the thunks at end of the array */
230 insp = sgv->num;
231 if (sgv->num_thunks && !(sym->Flags & SYMFLAG_THUNK))
233 insp -= sgv->num_thunks;
234 memmove(&sgv->syms[insp + 1], &sgv->syms[insp],
235 sizeof(sgv->syms[0]) * sgv->num_thunks);
237 if (!fill_sym_lvalue(sym, sgv->frame_offset, &sgv->syms[insp].lvalue, tmp, sizeof(tmp)))
239 dbg_printf("%s: %s\n", sym->Name, tmp);
240 return TRUE;
242 sgv->syms[insp].flags = sym->Flags;
243 sgv->syms[insp].sym_info = sym->Index;
244 sgv->num++;
246 return TRUE;
249 enum sym_get_lval symbol_picker_interactive(const char* name, const struct sgv_data* sgv,
250 struct dbg_lvalue* rtn)
252 char buffer[512];
253 unsigned i;
255 if (!dbg_interactiveP)
257 dbg_printf("More than one symbol named %s, picking the first one\n", name);
258 *rtn = sgv->syms[0].lvalue;
259 return sglv_found;
262 dbg_printf("Many symbols with name '%s', "
263 "choose the one you want (<cr> to abort):\n", name);
264 for (i = 0; i < sgv->num; i++)
266 if (sgv->num - sgv->num_thunks > 1 && (sgv->syms[i].flags & SYMFLAG_THUNK) && !DBG_IVAR(AlwaysShowThunks))
267 continue;
268 dbg_printf("[%d]: ", i + 1);
269 if (sgv->syms[i].flags & (SYMFLAG_LOCAL | SYMFLAG_PARAMETER))
271 dbg_printf("%s %sof %s\n",
272 sgv->syms[i].flags & SYMFLAG_PARAMETER ? "Parameter" : "Local variable",
273 sgv->syms[i].flags & (SYMFLAG_REGISTER|SYMFLAG_REGREL) ? "(in a register) " : "",
274 name);
276 else if (sgv->syms[i].flags & SYMFLAG_THUNK)
278 print_address(&sgv->syms[i].lvalue.addr, TRUE);
279 /* FIXME: should display where the thunks points to */
280 dbg_printf(" thunk %s\n", name);
282 else
284 print_address(&sgv->syms[i].lvalue.addr, TRUE);
285 dbg_printf("\n");
290 if (input_read_line("=> ", buffer, sizeof(buffer)))
292 if (buffer[0] == '\0') return sglv_aborted;
293 i = atoi(buffer);
294 if (i < 1 || i > sgv->num)
295 dbg_printf("Invalid choice %d\n", i);
297 else return sglv_aborted;
298 } while (i < 1 || i > sgv->num);
300 /* The array is 0-based, but the choices are 1..n,
301 * so we have to subtract one before returning.
303 *rtn = sgv->syms[i - 1].lvalue;
304 return sglv_found;
307 enum sym_get_lval symbol_picker_scoped(const char* name, const struct sgv_data* sgv,
308 struct dbg_lvalue* rtn)
310 unsigned i;
311 int local = -1;
313 for (i = 0; i < sgv->num; i++)
315 if (sgv->num - sgv->num_thunks > 1 && (sgv->syms[i].flags & SYMFLAG_THUNK) && !DBG_IVAR(AlwaysShowThunks))
316 continue;
317 if (sgv->syms[i].flags & (SYMFLAG_LOCAL | SYMFLAG_PARAMETER))
319 if (local == -1)
320 local = i;
321 else
323 /* FIXME: several locals with same name... which one to pick ?? */
324 dbg_printf("Several local variables/parameters for %s, aborting\n", name);
325 return sglv_aborted;
329 if (local != -1)
331 *rtn = sgv->syms[local].lvalue;
332 return sglv_found;
334 /* no locals found, multiple globals... abort for now */
335 dbg_printf("Several global variables for %s, aborting\n", name);
336 return sglv_aborted;
339 symbol_picker_t symbol_current_picker = symbol_picker_interactive;
341 /***********************************************************************
342 * symbol_get_lvalue
344 * Get the address of a named symbol.
345 * Return values:
346 * sglv_found: if the symbol is found
347 * sglv_unknown: if the symbol isn't found
348 * sglv_aborted: some error occurred (likely, many symbols of same name exist,
349 * and user didn't pick one of them)
351 enum sym_get_lval symbol_get_lvalue(const char* name, const int lineno,
352 struct dbg_lvalue* rtn, BOOL bp_disp)
354 struct sgv_data sgv;
355 int i;
356 char buffer[512];
357 BOOL opt;
358 struct dbg_frame* frm;
360 if (strlen(name) + 4 > sizeof(buffer))
362 WINE_WARN("Too long symbol (%s)\n", name);
363 return sglv_unknown;
366 sgv.num = 0;
367 sgv.num_thunks = 0;
368 sgv.name = &buffer[2];
369 sgv.do_thunks = DBG_IVAR(AlwaysShowThunks);
371 if (strchr(name, '!'))
373 strcpy(buffer, name);
375 else
377 buffer[0] = '*';
378 buffer[1] = '!';
379 strcpy(&buffer[2], name);
382 /* this is a wine specific options to return also ELF modules in the
383 * enumeration
385 opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
386 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);
388 if (!sgv.num)
390 const char* ptr = strchr(name, '!');
391 if ((ptr && ptr[1] != '_') || (!ptr && *name != '_'))
393 if (ptr)
395 int offset = ptr - name;
396 memcpy(buffer, name, offset + 1);
397 buffer[offset + 1] = '_';
398 strcpy(&buffer[offset + 2], ptr + 1);
400 else
402 buffer[0] = '*';
403 buffer[1] = '!';
404 buffer[2] = '_';
405 strcpy(&buffer[3], name);
407 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv);
410 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
412 /* now grab local symbols */
413 if ((frm = stack_get_curr_frame()) && sgv.num < NUMDBGV && !strchr(name, '!'))
415 sgv.frame_offset = frm->linear_frame;
416 SymEnumSymbols(dbg_curr_process->handle, 0, name, sgv_cb, (void*)&sgv);
419 if (!sgv.num)
421 dbg_printf("No symbols found for %s\n", name);
422 return sglv_unknown;
425 /* recompute potential offsets for functions (linenumber, skip prolog) */
426 for (i = 0; i < sgv.num; i++)
428 if (sgv.syms[i].flags & (SYMFLAG_REGISTER|SYMFLAG_REGREL|SYMFLAG_LOCAL|SYMFLAG_THUNK))
429 continue;
431 if (lineno == -1)
433 struct dbg_type type;
434 ULONG64 addr;
436 type.module = sgv.syms[i].lvalue.type.module;
437 type.id = sgv.syms[i].sym_info;
438 if (bp_disp && symbol_get_debug_start(&type, &addr))
439 sgv.syms[i].lvalue.addr.Offset = addr;
441 else
443 DWORD disp;
444 IMAGEHLP_LINE64 il;
445 BOOL found = FALSE;
447 il.SizeOfStruct = sizeof(il);
448 SymGetLineFromAddr64(dbg_curr_process->handle,
449 (DWORD_PTR)memory_to_linear_addr(&sgv.syms[i].lvalue.addr),
450 &disp, &il);
453 if (lineno == il.LineNumber)
455 sgv.syms[i].lvalue.addr.Offset = il.Address;
456 found = TRUE;
457 break;
459 } while (SymGetLineNext64(dbg_curr_process->handle, &il));
460 if (!found)
461 WINE_FIXME("No line (%d) found for %s (setting to symbol start)\n",
462 lineno, name);
466 if (sgv.num - sgv.num_thunks > 1 || /* many symbols non thunks (and showing only non thunks) */
467 (sgv.num > 1 && DBG_IVAR(AlwaysShowThunks)) || /* many symbols (showing symbols & thunks) */
468 (sgv.num == sgv.num_thunks && sgv.num_thunks > 1))
470 return symbol_current_picker(name, &sgv, rtn);
472 /* first symbol is the one we want:
473 * - only one symbol found,
474 * - or many symbols but only one non thunk when AlwaysShowThunks is FALSE
476 *rtn = sgv.syms[0].lvalue;
477 return sglv_found;
480 BOOL symbol_is_local(const char* name)
482 struct sgv_data sgv;
483 struct dbg_frame* frm;
485 sgv.num = 0;
486 sgv.num_thunks = 0;
487 sgv.name = name;
488 sgv.do_thunks = FALSE;
490 if ((frm = stack_get_curr_frame()))
492 sgv.frame_offset = frm->linear_frame;
493 SymEnumSymbols(dbg_curr_process->handle, 0, name, sgv_cb, (void*)&sgv);
495 return sgv.num > 0;
498 /***********************************************************************
499 * symbol_read_symtable
501 * Read a symbol file into the hash table.
503 void symbol_read_symtable(const char* filename, ULONG_PTR offset)
505 dbg_printf("No longer supported\n");
507 #if 0
508 /* FIXME: have to implement SymAddSymbol in dbghelp, but likely we'll need to link
509 * this with an already loaded module !!
511 FILE* symbolfile;
512 unsigned addr;
513 char type;
514 char* cpnt;
515 char buffer[256];
516 char name[256];
518 if (!(symbolfile = fopen(filename, "r")))
520 WINE_WARN("Unable to open symbol table %s\n", filename);
521 return;
524 dbg_printf("Reading symbols from file %s\n", filename);
526 while (1)
528 fgets(buffer, sizeof(buffer), symbolfile);
529 if (feof(symbolfile)) break;
531 /* Strip any text after a # sign (i.e. comments) */
532 cpnt = strchr(buffer, '#');
533 if (cpnt) *cpnt = '\0';
535 /* Quietly ignore any lines that have just whitespace */
536 for (cpnt = buffer; *cpnt; cpnt++)
538 if (*cpnt != ' ' && *cpnt != '\t') break;
540 if (!*cpnt || *cpnt == '\n') continue;
542 if (sscanf(buffer, "%lx %c %s", &addr, &type, name) == 3)
544 if (value.addr.off + offset < value.addr.off)
545 WINE_WARN("Address wrap around\n");
546 value.addr.off += offset;
547 SymAddSymbol(current_process->handle, BaseOfDll,
548 name, addr, 0, 0);
551 fclose(symbolfile);
552 #endif
555 /***********************************************************************
556 * symbol_get_function_line_status
558 * Find the symbol nearest to a given address.
560 enum dbg_line_status symbol_get_function_line_status(const ADDRESS64* addr)
562 IMAGEHLP_LINE64 il;
563 DWORD disp;
564 ULONG64 disp64, start;
565 DWORD_PTR lin = (DWORD_PTR)memory_to_linear_addr(addr);
566 char buffer[sizeof(SYMBOL_INFO) + 256];
567 SYMBOL_INFO* sym = (SYMBOL_INFO*)buffer;
568 struct dbg_type func;
570 il.SizeOfStruct = sizeof(il);
571 sym->SizeOfStruct = sizeof(SYMBOL_INFO);
572 sym->MaxNameLen = sizeof(buffer) - sizeof(SYMBOL_INFO);
574 /* do we have some info for lin address ? */
575 if (!SymFromAddr(dbg_curr_process->handle, lin, &disp64, sym))
577 ADDRESS64 jumpee;
578 /* some compilers insert thunks in their code without debug info associated
579 * take care of this situation
581 if (dbg_curr_process->be_cpu->is_jump((void*)lin, &jumpee))
582 return symbol_get_function_line_status(&jumpee);
583 return dbg_no_line_info;
586 switch (sym->Tag)
588 case SymTagThunk:
589 /* FIXME: so far dbghelp doesn't return the 16 <=> 32 thunks
590 * and furthermore, we no longer take care of them !!!
592 return dbg_in_a_thunk;
593 case SymTagFunction:
594 case SymTagPublicSymbol: break;
595 default:
596 WINE_FIXME("Unexpected sym-tag 0x%08lx\n", sym->Tag);
597 case SymTagData:
598 return dbg_no_line_info;
600 /* we should have a function now */
601 if (!SymGetLineFromAddr64(dbg_curr_process->handle, lin, &disp, &il))
602 return dbg_no_line_info;
604 func.module = sym->ModBase;
605 func.id = sym->Index;
607 if (symbol_get_debug_start(&func, &start) && lin < start)
608 return dbg_not_on_a_line_number;
610 if (!sym->Size) sym->Size = 0x100000;
611 if (il.FileName && il.FileName[0] && disp < sym->Size)
612 return (disp == 0) ? dbg_on_a_line_number : dbg_not_on_a_line_number;
614 return dbg_no_line_info;
617 /***********************************************************************
618 * symbol_get_line
620 * Find the symbol nearest to a given address.
621 * Returns sourcefile name and line number in a format that the listing
622 * handler can deal with.
624 BOOL symbol_get_line(const char* filename, const char* name,
625 IMAGEHLP_LINE64* line)
627 struct sgv_data sgv;
628 char buffer[512];
629 DWORD opt, disp;
630 unsigned i;
631 BOOL found = FALSE;
632 IMAGEHLP_LINE64 il;
634 sgv.num = 0;
635 sgv.num_thunks = 0;
636 sgv.name = &buffer[2];
637 sgv.do_thunks = FALSE;
639 buffer[0] = '*';
640 buffer[1] = '!';
641 strcpy(&buffer[2], name);
643 /* this is a wine specific options to return also ELF modules in the
644 * enumeration
646 opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
647 if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
649 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
650 return FALSE;
653 if (!sgv.num && (name[0] != '_'))
655 buffer[2] = '_';
656 strcpy(&buffer[3], name);
657 if (!SymEnumSymbols(dbg_curr_process->handle, 0, buffer, sgv_cb, (void*)&sgv))
659 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
660 return FALSE;
663 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
665 for (i = 0; i < sgv.num; i++)
667 DWORD_PTR linear = (DWORD_PTR)memory_to_linear_addr(&sgv.syms[i].lvalue.addr);
669 il.SizeOfStruct = sizeof(il);
670 if (!SymGetLineFromAddr64(dbg_curr_process->handle, linear, &disp, &il))
671 continue;
672 if (filename && strcmp(il.FileName, filename)) continue;
673 if (found)
675 WINE_FIXME("Several found, returning first (may not be what you want)...\n");
676 break;
678 found = TRUE;
679 *line = il;
681 if (!found)
683 if (filename) dbg_printf("No such function %s in %s\n", name, filename);
684 else dbg_printf("No such function %s\n", name);
685 return FALSE;
687 return TRUE;
690 /******************************************************************
691 * symbol_print_local
693 * Overall format is:
694 * <name>=<value> in non detailed form
695 * <name>=<value> (local|pmt <where>) in detailed form
696 * Note <value> can be an error message in case of error
698 void symbol_print_local(const SYMBOL_INFO* sym, DWORD_PTR base, BOOL detailed)
700 struct dbg_lvalue lvalue;
701 char buffer[64];
703 dbg_printf("%s=", sym->Name);
705 if (fill_sym_lvalue(sym, base, &lvalue, buffer, sizeof(buffer)))
707 print_value(&lvalue, 0, 1);
708 if (detailed)
709 dbg_printf(" (%s %s)",
710 (sym->Flags & SYMFLAG_PARAMETER) ? "parameter" : "local",
711 buffer);
713 else
715 dbg_printf("%s", buffer);
716 if (detailed)
717 dbg_printf(" (%s)",
718 (sym->Flags & SYMFLAG_PARAMETER) ? "parameter" : "local");
722 static BOOL CALLBACK info_locals_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
724 struct dbg_type type;
726 dbg_printf("\t");
727 type.module = sym->ModBase;
728 type.id = sym->TypeIndex;
729 types_print_type(&type, FALSE);
731 dbg_printf(" ");
732 symbol_print_local(sym, (DWORD_PTR)ctx, TRUE);
733 dbg_printf("\n");
735 return TRUE;
738 BOOL symbol_info_locals(void)
740 ADDRESS64 addr;
741 struct dbg_frame* frm;
743 if (!(frm = stack_get_curr_frame())) return FALSE;
745 addr.Mode = AddrModeFlat;
746 addr.Offset = frm->linear_pc;
747 print_address(&addr, FALSE);
748 dbg_printf(": (%0*Ix)\n", ADDRWIDTH, frm->linear_frame);
749 SymEnumSymbols(dbg_curr_process->handle, 0, NULL, info_locals_cb, (void*)frm->linear_frame);
751 return TRUE;
754 static BOOL CALLBACK symbols_info_cb(PSYMBOL_INFO sym, ULONG size, PVOID ctx)
756 struct dbg_type type;
757 IMAGEHLP_MODULE mi;
759 mi.SizeOfStruct = sizeof(mi);
761 if (!SymGetModuleInfo(dbg_curr_process->handle, sym->ModBase, &mi))
762 mi.ModuleName[0] = '\0';
763 else
765 size_t len = strlen(mi.ModuleName);
766 if (len > 5 && !strcmp(mi.ModuleName + len - 5, "<elf>"))
767 mi.ModuleName[len - 5] = '\0';
770 dbg_printf("%0*I64x: %s!%s", ADDRWIDTH, sym->Address, mi.ModuleName, sym->Name);
771 type.id = sym->TypeIndex;
772 type.module = sym->ModBase;
774 if (sym->TypeIndex != dbg_itype_none && sym->TypeIndex != 0)
776 dbg_printf(" ");
777 types_print_type(&type, FALSE);
779 dbg_printf("\n");
780 return TRUE;
783 void symbol_info(const char* str)
785 char buffer[512];
786 BOOL opt;
788 if (strlen(str) + 3 >= sizeof(buffer))
790 dbg_printf("Symbol too long (%s)\n", str);
791 return;
793 buffer[0] = '*';
794 buffer[1] = '!';
795 strcpy(&buffer[2], str);
796 /* this is a wine specific options to return also ELF modules in the
797 * enumeration
799 opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
800 SymEnumSymbols(dbg_curr_process->handle, 0, buffer, symbols_info_cb, NULL);
801 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);