2 * File dwarf.c - read dwarf2 information from the ELF modules
4 * Copyright (C) 2005, Raphael Junqueira
5 * Copyright (C) 2006, 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 #define NONAMELESSUNION
26 #include <sys/types.h>
28 #ifdef HAVE_SYS_STAT_H
29 # include <sys/stat.h>
31 #ifdef HAVE_SYS_MMAN_H
42 #define PATH_MAX MAX_PATH
53 #include "dbghelp_private.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_dwarf);
61 * o unspecified parameters
63 * o Debug{Start|End}Point
66 * o proper types loading (nesting)
70 static void dump(const void* ptr, unsigned len)
74 static const char hexof[] = "0123456789abcdef";
77 for (i = 0; i < len; i += 16)
79 sprintf(msg, "%08x: ", i);
80 memset(msg + 10, ' ', 3 * 16 + 1 + 16);
81 for (j = 0; j < min(16, len - i); j++)
83 msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
84 msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
85 msg[10 + 3 * j + 2] = ' ';
86 msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
89 msg[10 + 3 * 16] = ' ';
90 msg[10 + 3 * 16 + 1 + 16] = '\0';
99 * http://www.eagercon.com/dwarf/dwarf3std.htm
100 * http://www.eagercon.com/dwarf/dwarf-2.0.0.pdf
102 * dwarf2.h: http://www.hakpetzna.com/b/binutils/dwarf2_8h-source.html
104 * example of projects who do dwarf2 parsing:
105 * http://www.x86-64.org/cgi-bin/cvsweb.cgi/binutils.dead/binutils/readelf.c?rev=1.1.1.2
106 * http://elis.ugent.be/diota/log/ltrace_elf.c
114 typedef struct dwarf2_abbrev_entry_attr_s
116 unsigned long attribute;
118 struct dwarf2_abbrev_entry_attr_s* next;
119 } dwarf2_abbrev_entry_attr_t;
121 typedef struct dwarf2_abbrev_entry_s
123 unsigned long entry_code;
125 unsigned char have_child;
127 dwarf2_abbrev_entry_attr_t* attrs;
128 } dwarf2_abbrev_entry_t;
133 const unsigned char* ptr;
141 unsigned long uvalue;
144 struct dwarf2_block block;
148 typedef struct dwarf2_debug_info_s
150 const dwarf2_abbrev_entry_t*abbrev;
152 const unsigned char** data;
153 struct vector children;
154 } dwarf2_debug_info_t;
156 typedef struct dwarf2_section_s
158 const unsigned char* address;
162 enum dwarf2_sections {section_debug, section_string, section_abbrev, section_line, section_max};
164 typedef struct dwarf2_traverse_context_s
166 const unsigned char* data;
167 const unsigned char* start_data;
168 const unsigned char* end_data;
169 unsigned char word_size;
170 } dwarf2_traverse_context_t;
172 /* symt_cache indexes */
179 typedef struct dwarf2_parse_context_s
181 const dwarf2_section_t* sections;
184 struct module* module;
185 const struct elf_thunk_area*thunks;
186 struct sparse_array abbrev_table;
187 struct sparse_array debug_info_table;
188 unsigned long load_offset;
189 unsigned long ref_offset;
190 unsigned char word_size;
191 struct symt* symt_cache[sc_num]; /* void, int1, int2, int4 */
192 } dwarf2_parse_context_t;
194 /* stored in the dbghelp's module internal structure for later reuse */
195 struct dwarf2_module_info_s
197 dwarf2_section_t debug_loc;
200 #define loc_dwarf2_location_list (loc_user + 0)
201 #define loc_dwarf2_block (loc_user + 1)
203 /* forward declarations */
204 static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx, dwarf2_debug_info_t* entry);
206 static unsigned char dwarf2_get_byte(const unsigned char* ptr)
211 static unsigned char dwarf2_parse_byte(dwarf2_traverse_context_t* ctx)
213 unsigned char uvalue = dwarf2_get_byte(ctx->data);
218 static unsigned short dwarf2_get_u2(const unsigned char* ptr)
220 return *(const UINT16*)ptr;
223 static unsigned short dwarf2_parse_u2(dwarf2_traverse_context_t* ctx)
225 unsigned short uvalue = dwarf2_get_u2(ctx->data);
230 static unsigned long dwarf2_get_u4(const unsigned char* ptr)
232 return *(const UINT32*)ptr;
235 static unsigned long dwarf2_parse_u4(dwarf2_traverse_context_t* ctx)
237 unsigned long uvalue = dwarf2_get_u4(ctx->data);
242 static DWORD64 dwarf2_get_u8(const unsigned char* ptr)
244 return *(const UINT64*)ptr;
247 static unsigned long dwarf2_get_leb128_as_unsigned(const unsigned char* ptr, const unsigned char** end)
249 unsigned long ret = 0;
255 byte = dwarf2_get_byte(ptr++);
256 ret |= (byte & 0x7f) << shift;
258 } while (byte & 0x80);
264 static unsigned long dwarf2_leb128_as_unsigned(dwarf2_traverse_context_t* ctx)
270 ret = dwarf2_get_leb128_as_unsigned(ctx->data, &ctx->data);
275 static long dwarf2_get_leb128_as_signed(const unsigned char* ptr, const unsigned char** end)
280 const unsigned size = sizeof(int) * 8;
284 byte = dwarf2_get_byte(ptr++);
285 ret |= (byte & 0x7f) << shift;
287 } while (byte & 0x80);
290 /* as spec: sign bit of byte is 2nd high order bit (80x40)
291 * -> 0x80 is used as flag.
293 if ((shift < size) && (byte & 0x40))
295 ret |= - (1 << shift);
300 static long dwarf2_leb128_as_signed(dwarf2_traverse_context_t* ctx)
306 ret = dwarf2_get_leb128_as_signed(ctx->data, &ctx->data);
310 static unsigned dwarf2_leb128_length(const dwarf2_traverse_context_t* ctx)
313 for (ret = 0; ctx->data[ret] & 0x80; ret++);
317 /******************************************************************
320 * Returns an address.
321 * We assume that in all cases word size from Dwarf matches the size of
322 * addresses in platform where the exec is compiled.
324 static unsigned long dwarf2_get_addr(const unsigned char* ptr, unsigned word_size)
331 ret = dwarf2_get_u4(ptr);
334 ret = dwarf2_get_u8(ptr);
337 FIXME("Unsupported Word Size %u\n", word_size);
343 static unsigned long dwarf2_parse_addr(dwarf2_traverse_context_t* ctx)
345 unsigned long ret = dwarf2_get_addr(ctx->data, ctx->word_size);
346 ctx->data += ctx->word_size;
350 static const char* dwarf2_debug_traverse_ctx(const dwarf2_traverse_context_t* ctx)
352 return wine_dbg_sprintf("ctx(%p)", ctx->data);
355 static const char* dwarf2_debug_ctx(const dwarf2_parse_context_t* ctx)
357 return wine_dbg_sprintf("ctx(%p,%s)",
358 ctx, debugstr_w(ctx->module->module.ModuleName));
361 static const char* dwarf2_debug_di(const dwarf2_debug_info_t* di)
363 return wine_dbg_sprintf("debug_info(abbrev:%p,symt:%p)",
364 di->abbrev, di->symt);
367 static dwarf2_abbrev_entry_t*
368 dwarf2_abbrev_table_find_entry(const struct sparse_array* abbrev_table,
369 unsigned long entry_code)
371 assert( NULL != abbrev_table );
372 return sparse_array_find(abbrev_table, entry_code);
375 static void dwarf2_parse_abbrev_set(dwarf2_traverse_context_t* abbrev_ctx,
376 struct sparse_array* abbrev_table,
379 unsigned long entry_code;
380 dwarf2_abbrev_entry_t* abbrev_entry;
381 dwarf2_abbrev_entry_attr_t* new = NULL;
382 dwarf2_abbrev_entry_attr_t* last = NULL;
383 unsigned long attribute;
386 assert( NULL != abbrev_ctx );
388 TRACE("%s, end at %p\n",
389 dwarf2_debug_traverse_ctx(abbrev_ctx), abbrev_ctx->end_data);
391 sparse_array_init(abbrev_table, sizeof(dwarf2_abbrev_entry_t), 32);
392 while (abbrev_ctx->data < abbrev_ctx->end_data)
394 TRACE("now at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx));
395 entry_code = dwarf2_leb128_as_unsigned(abbrev_ctx);
396 TRACE("found entry_code %lu\n", entry_code);
399 TRACE("NULL entry code at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx));
402 abbrev_entry = sparse_array_add(abbrev_table, entry_code, pool);
403 assert( NULL != abbrev_entry );
405 abbrev_entry->entry_code = entry_code;
406 abbrev_entry->tag = dwarf2_leb128_as_unsigned(abbrev_ctx);
407 abbrev_entry->have_child = dwarf2_parse_byte(abbrev_ctx);
408 abbrev_entry->attrs = NULL;
409 abbrev_entry->num_attr = 0;
411 TRACE("table:(%p,#%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n",
412 abbrev_table, sparse_array_length(abbrev_table),
413 entry_code, abbrev_entry->tag, abbrev_entry->have_child, abbrev_entry);
418 attribute = dwarf2_leb128_as_unsigned(abbrev_ctx);
419 form = dwarf2_leb128_as_unsigned(abbrev_ctx);
420 if (!attribute) break;
422 new = pool_alloc(pool, sizeof(dwarf2_abbrev_entry_attr_t));
425 new->attribute = attribute;
428 if (abbrev_entry->attrs) last->next = new;
429 else abbrev_entry->attrs = new;
431 abbrev_entry->num_attr++;
434 TRACE("found %u entries\n", sparse_array_length(abbrev_table));
437 static void dwarf2_swallow_attribute(dwarf2_traverse_context_t* ctx,
438 const dwarf2_abbrev_entry_attr_t* abbrev_attr)
442 TRACE("(attr:0x%lx,form:0x%lx)\n", abbrev_attr->attribute, abbrev_attr->form);
444 switch (abbrev_attr->form)
446 case DW_FORM_ref_addr:
447 case DW_FORM_addr: step = ctx->word_size; break;
450 case DW_FORM_ref1: step = 1; break;
452 case DW_FORM_ref2: step = 2; break;
455 case DW_FORM_strp: step = 4; break;
457 case DW_FORM_ref8: step = 8; break;
459 case DW_FORM_ref_udata:
460 case DW_FORM_udata: step = dwarf2_leb128_length(ctx); break;
461 case DW_FORM_string: step = strlen((const char*)ctx->data) + 1; break;
462 case DW_FORM_block: step = dwarf2_leb128_as_unsigned(ctx); break;
463 case DW_FORM_block1: step = dwarf2_parse_byte(ctx); break;
464 case DW_FORM_block2: step = dwarf2_parse_u2(ctx); break;
465 case DW_FORM_block4: step = dwarf2_parse_u4(ctx); break;
467 FIXME("Unhandled attribute form %lx\n", abbrev_attr->form);
473 static void dwarf2_fill_attr(const dwarf2_parse_context_t* ctx,
474 const dwarf2_abbrev_entry_attr_t* abbrev_attr,
475 const unsigned char* data,
476 struct attribute* attr)
478 attr->form = abbrev_attr->form;
481 case DW_FORM_ref_addr:
483 attr->u.uvalue = dwarf2_get_addr(data, ctx->word_size);
484 TRACE("addr<0x%lx>\n", attr->u.uvalue);
488 attr->u.uvalue = dwarf2_get_byte(data);
489 TRACE("flag<0x%lx>\n", attr->u.uvalue);
493 attr->u.uvalue = dwarf2_get_byte(data);
494 TRACE("data1<%lu>\n", attr->u.uvalue);
498 attr->u.uvalue = dwarf2_get_u2(data);
499 TRACE("data2<%lu>\n", attr->u.uvalue);
503 attr->u.uvalue = dwarf2_get_u4(data);
504 TRACE("data4<%lu>\n", attr->u.uvalue);
508 attr->u.block.size = 8;
509 attr->u.block.ptr = data;
514 attr->u.uvalue = ctx->ref_offset + dwarf2_get_byte(data);
515 TRACE("ref1<0x%lx>\n", attr->u.uvalue);
519 attr->u.uvalue = ctx->ref_offset + dwarf2_get_u2(data);
520 TRACE("ref2<0x%lx>\n", attr->u.uvalue);
524 attr->u.uvalue = ctx->ref_offset + dwarf2_get_u4(data);
525 TRACE("ref4<0x%lx>\n", attr->u.uvalue);
529 FIXME("Unhandled 64 bit support\n");
533 attr->u.svalue = dwarf2_get_leb128_as_signed(data, NULL);
536 case DW_FORM_ref_udata:
537 attr->u.uvalue = dwarf2_get_leb128_as_unsigned(data, NULL);
541 attr->u.uvalue = dwarf2_get_leb128_as_unsigned(data, NULL);
545 attr->u.string = (const char *)data;
546 TRACE("string<%s>\n", attr->u.string);
551 unsigned long offset = dwarf2_get_u4(data);
552 attr->u.string = (const char*)ctx->sections[section_string].address + offset;
554 TRACE("strp<%s>\n", attr->u.string);
558 attr->u.block.size = dwarf2_get_leb128_as_unsigned(data, &attr->u.block.ptr);
562 attr->u.block.size = dwarf2_get_byte(data);
563 attr->u.block.ptr = data + 1;
567 attr->u.block.size = dwarf2_get_u2(data);
568 attr->u.block.ptr = data + 2;
572 attr->u.block.size = dwarf2_get_u4(data);
573 attr->u.block.ptr = data + 4;
577 FIXME("Unhandled attribute form %lx\n", abbrev_attr->form);
582 static BOOL dwarf2_find_attribute(const dwarf2_parse_context_t* ctx,
583 const dwarf2_debug_info_t* di,
584 unsigned at, struct attribute* attr)
587 dwarf2_abbrev_entry_attr_t* abbrev_attr;
588 dwarf2_abbrev_entry_attr_t* abstract_abbrev_attr;
592 abstract_abbrev_attr = NULL;
593 for (i = 0, abbrev_attr = di->abbrev->attrs; abbrev_attr; i++, abbrev_attr = abbrev_attr->next)
595 if (abbrev_attr->attribute == at)
597 dwarf2_fill_attr(ctx, abbrev_attr, di->data[i], attr);
600 if (abbrev_attr->attribute == DW_AT_abstract_origin &&
603 abstract_abbrev_attr = abbrev_attr;
607 /* do we have an abstract origin debug entry to look into ? */
608 if (!abstract_abbrev_attr) break;
609 dwarf2_fill_attr(ctx, abstract_abbrev_attr, di->data[ai], attr);
610 if (!(di = sparse_array_find(&ctx->debug_info_table, attr->u.uvalue)))
611 FIXME("Should have found the debug info entry\n");
616 static void dwarf2_load_one_entry(dwarf2_parse_context_t*, dwarf2_debug_info_t*,
617 struct symt_compiland*);
619 #define Wine_DW_no_register 0x7FFFFFFF
621 static unsigned dwarf2_map_register(int regno)
627 case Wine_DW_no_register: FIXME("What the heck map reg 0x%x\n",regno); reg = 0; break;
628 case 0: reg = CV_REG_EAX; break;
629 case 1: reg = CV_REG_ECX; break;
630 case 2: reg = CV_REG_EDX; break;
631 case 3: reg = CV_REG_EBX; break;
632 case 4: reg = CV_REG_ESP; break;
633 case 5: reg = CV_REG_EBP; break;
634 case 6: reg = CV_REG_ESI; break;
635 case 7: reg = CV_REG_EDI; break;
636 case 8: reg = CV_REG_EIP; break;
637 case 9: reg = CV_REG_EFLAGS; break;
638 case 10: reg = CV_REG_CS; break;
639 case 11: reg = CV_REG_SS; break;
640 case 12: reg = CV_REG_DS; break;
641 case 13: reg = CV_REG_ES; break;
642 case 14: reg = CV_REG_FS; break;
643 case 15: reg = CV_REG_GS; break;
644 case 16: case 17: case 18: case 19:
645 case 20: case 21: case 22: case 23:
646 reg = CV_REG_ST0 + regno - 16; break;
647 case 24: reg = CV_REG_CTRL; break;
648 case 25: reg = CV_REG_STAT; break;
649 case 26: reg = CV_REG_TAG; break;
657 case 32: case 33: case 34: case 35:
658 case 36: case 37: case 38: case 39:
659 reg = CV_REG_XMM0 + regno - 32; break;
660 case 40: reg = CV_REG_MXCSR; break;
662 FIXME("Don't know how to map register %d\n", regno);
668 static enum location_error
669 compute_location(dwarf2_traverse_context_t* ctx, struct location* loc,
670 HANDLE hproc, const struct location* frame)
675 BOOL piece_found = FALSE;
679 loc->kind = loc_absolute;
680 loc->reg = Wine_DW_no_register;
682 while (ctx->data < ctx->end_data)
684 op = dwarf2_parse_byte(ctx);
687 case DW_OP_lit0: case DW_OP_lit1: case DW_OP_lit2: case DW_OP_lit3:
688 case DW_OP_lit4: case DW_OP_lit5: case DW_OP_lit6: case DW_OP_lit7:
689 case DW_OP_lit8: case DW_OP_lit9: case DW_OP_lit10: case DW_OP_lit11:
690 case DW_OP_lit12: case DW_OP_lit13: case DW_OP_lit14: case DW_OP_lit15:
691 case DW_OP_lit16: case DW_OP_lit17: case DW_OP_lit18: case DW_OP_lit19:
692 case DW_OP_lit20: case DW_OP_lit21: case DW_OP_lit22: case DW_OP_lit23:
693 case DW_OP_lit24: case DW_OP_lit25: case DW_OP_lit26: case DW_OP_lit27:
694 case DW_OP_lit28: case DW_OP_lit29: case DW_OP_lit30: case DW_OP_lit31:
695 stack[++stk] = op - DW_OP_lit0; break;
696 case DW_OP_addr: stack[++stk] = dwarf2_parse_addr(ctx); break;
697 case DW_OP_const1u: stack[++stk] = dwarf2_parse_byte(ctx); break;
698 case DW_OP_const1s: stack[++stk] = (long)(signed char)dwarf2_parse_byte(ctx); break;
699 case DW_OP_const2u: stack[++stk] = dwarf2_parse_u2(ctx); break;
700 case DW_OP_const2s: stack[++stk] = (long)(short)dwarf2_parse_u2(ctx); break;
701 case DW_OP_const4u: stack[++stk] = dwarf2_parse_u4(ctx); break;
702 case DW_OP_const4s: stack[++stk] = dwarf2_parse_u4(ctx); break;
703 case DW_OP_constu: stack[++stk] = dwarf2_leb128_as_unsigned(ctx); break;
704 case DW_OP_consts: stack[++stk] = dwarf2_leb128_as_signed(ctx); break;
705 case DW_OP_plus_uconst:
706 stack[stk] += dwarf2_leb128_as_unsigned(ctx); break;
707 case DW_OP_reg0: case DW_OP_reg1: case DW_OP_reg2: case DW_OP_reg3:
708 case DW_OP_reg4: case DW_OP_reg5: case DW_OP_reg6: case DW_OP_reg7:
709 case DW_OP_reg8: case DW_OP_reg9: case DW_OP_reg10: case DW_OP_reg11:
710 case DW_OP_reg12: case DW_OP_reg13: case DW_OP_reg14: case DW_OP_reg15:
711 case DW_OP_reg16: case DW_OP_reg17: case DW_OP_reg18: case DW_OP_reg19:
712 case DW_OP_reg20: case DW_OP_reg21: case DW_OP_reg22: case DW_OP_reg23:
713 case DW_OP_reg24: case DW_OP_reg25: case DW_OP_reg26: case DW_OP_reg27:
714 case DW_OP_reg28: case DW_OP_reg29: case DW_OP_reg30: case DW_OP_reg31:
715 /* dbghelp APIs don't know how to cope with this anyway
716 * (for example 'long long' stored in two registers)
717 * FIXME: We should tell winedbg how to deal with it (sigh)
721 if (loc->reg != Wine_DW_no_register)
722 FIXME("Only supporting one reg (%d -> %d)\n",
723 loc->reg, dwarf2_map_register(op - DW_OP_reg0));
724 loc->reg = dwarf2_map_register(op - DW_OP_reg0);
726 loc->kind = loc_register;
728 case DW_OP_breg0: case DW_OP_breg1: case DW_OP_breg2: case DW_OP_breg3:
729 case DW_OP_breg4: case DW_OP_breg5: case DW_OP_breg6: case DW_OP_breg7:
730 case DW_OP_breg8: case DW_OP_breg9: case DW_OP_breg10: case DW_OP_breg11:
731 case DW_OP_breg12: case DW_OP_breg13: case DW_OP_breg14: case DW_OP_breg15:
732 case DW_OP_breg16: case DW_OP_breg17: case DW_OP_breg18: case DW_OP_breg19:
733 case DW_OP_breg20: case DW_OP_breg21: case DW_OP_breg22: case DW_OP_breg23:
734 case DW_OP_breg24: case DW_OP_breg25: case DW_OP_breg26: case DW_OP_breg27:
735 case DW_OP_breg28: case DW_OP_breg29: case DW_OP_breg30: case DW_OP_breg31:
736 /* dbghelp APIs don't know how to cope with this anyway
737 * (for example 'long long' stored in two registers)
738 * FIXME: We should tell winedbg how to deal with it (sigh)
742 if (loc->reg != Wine_DW_no_register)
743 FIXME("Only supporting one reg (%d -> %d)\n",
744 loc->reg, dwarf2_map_register(op - DW_OP_breg0));
745 loc->reg = dwarf2_map_register(op - DW_OP_breg0);
747 stack[++stk] = dwarf2_leb128_as_signed(ctx);
748 loc->kind = loc_regrel;
751 if (loc->reg != Wine_DW_no_register)
752 FIXME("Only supporting one reg (%d -> -2)\n", loc->reg);
753 if (frame && frame->kind == loc_register)
755 loc->kind = loc_regrel;
756 loc->reg = frame->reg;
757 stack[++stk] = dwarf2_leb128_as_signed(ctx);
759 else if (frame && frame->kind == loc_regrel)
761 loc->kind = loc_regrel;
762 loc->reg = frame->reg;
763 stack[++stk] = dwarf2_leb128_as_signed(ctx) + frame->offset;
767 /* FIXME: this could be later optimized by not recomputing
768 * this very location expression
770 loc->kind = loc_dwarf2_block;
771 stack[++stk] = dwarf2_leb128_as_signed(ctx);
776 unsigned sz = dwarf2_leb128_as_unsigned(ctx);
777 WARN("Not handling OP_piece (size=%d)\n", sz);
784 FIXME("Unexpected empty stack\n");
785 return loc_err_internal;
787 if (loc->reg != Wine_DW_no_register)
789 WARN("Too complex expression for deref\n");
790 return loc_err_too_complex;
794 DWORD_PTR addr = stack[stk--];
797 if (!ReadProcessMemory(hproc, (void*)addr, &deref, sizeof(deref), NULL))
799 WARN("Couldn't read memory at %lx\n", addr);
800 return loc_err_cant_read;
802 stack[++stk] = deref;
806 loc->kind = loc_dwarf2_block;
810 if (op < DW_OP_lo_user) /* as DW_OP_hi_user is 0xFF, we don't need to test against it */
811 FIXME("Unhandled attr op: %x\n", op);
812 /* FIXME else unhandled extension */
813 return loc_err_internal;
816 loc->offset = stack[stk];
820 static BOOL dwarf2_compute_location_attr(dwarf2_parse_context_t* ctx,
821 const dwarf2_debug_info_t* di,
823 struct location* loc,
824 const struct location* frame)
826 struct attribute xloc;
828 if (!dwarf2_find_attribute(ctx, di, dw, &xloc)) return FALSE;
832 case DW_FORM_data1: case DW_FORM_data2:
833 case DW_FORM_udata: case DW_FORM_sdata:
834 loc->kind = loc_absolute;
836 loc->offset = xloc.u.uvalue;
838 case DW_FORM_data4: case DW_FORM_data8:
839 loc->kind = loc_dwarf2_location_list;
840 loc->reg = Wine_DW_no_register;
841 loc->offset = xloc.u.uvalue;
845 /* assume we have a block form */
847 if (xloc.u.block.size)
849 dwarf2_traverse_context_t lctx;
850 enum location_error err;
852 lctx.data = xloc.u.block.ptr;
853 lctx.end_data = xloc.u.block.ptr + xloc.u.block.size;
854 lctx.word_size = ctx->word_size;
856 err = compute_location(&lctx, loc, NULL, frame);
859 loc->kind = loc_error;
862 else if (loc->kind == loc_dwarf2_block)
864 unsigned* ptr = pool_alloc(&ctx->module->pool,
865 sizeof(unsigned) + xloc.u.block.size);
866 *ptr = xloc.u.block.size;
867 memcpy(ptr + 1, xloc.u.block.ptr, xloc.u.block.size);
868 loc->offset = (unsigned long)ptr;
874 static struct symt* dwarf2_lookup_type(dwarf2_parse_context_t* ctx,
875 const dwarf2_debug_info_t* di)
877 struct attribute attr;
879 if (dwarf2_find_attribute(ctx, di, DW_AT_type, &attr))
881 dwarf2_debug_info_t* type;
883 type = sparse_array_find(&ctx->debug_info_table, attr.u.uvalue);
884 if (!type) FIXME("Unable to find back reference to type %lx\n", attr.u.uvalue);
887 /* load the debug info entity */
888 dwarf2_load_one_entry(ctx, type, NULL);
895 /******************************************************************
896 * dwarf2_read_one_debug_info
898 * Loads into memory one debug info entry, and recursively its children (if any)
900 static BOOL dwarf2_read_one_debug_info(dwarf2_parse_context_t* ctx,
901 dwarf2_traverse_context_t* traverse,
902 dwarf2_debug_info_t** pdi)
904 const dwarf2_abbrev_entry_t*abbrev;
905 unsigned long entry_code;
906 unsigned long offset;
907 dwarf2_debug_info_t* di;
908 dwarf2_debug_info_t* child;
909 dwarf2_debug_info_t** where;
910 dwarf2_abbrev_entry_attr_t* attr;
912 struct attribute sibling;
914 offset = traverse->data - ctx->sections[ctx->section].address;
915 entry_code = dwarf2_leb128_as_unsigned(traverse);
916 TRACE("found entry_code %lu at 0x%lx\n", entry_code, offset);
922 abbrev = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
925 WARN("Cannot find abbrev entry for %lu at 0x%lx\n", entry_code, offset);
928 di = sparse_array_add(&ctx->debug_info_table, offset, &ctx->pool);
929 if (!di) return FALSE;
933 if (abbrev->num_attr)
935 di->data = pool_alloc(&ctx->pool, abbrev->num_attr * sizeof(const char*));
936 for (i = 0, attr = abbrev->attrs; attr; i++, attr = attr->next)
938 di->data[i] = traverse->data;
939 dwarf2_swallow_attribute(traverse, attr);
942 else di->data = NULL;
943 if (abbrev->have_child)
945 vector_init(&di->children, sizeof(dwarf2_debug_info_t*), 16);
946 while (traverse->data < traverse->end_data)
948 if (!dwarf2_read_one_debug_info(ctx, traverse, &child)) return FALSE;
950 where = vector_add(&di->children, &ctx->pool);
951 if (!where) return FALSE;
955 if (dwarf2_find_attribute(ctx, di, DW_AT_sibling, &sibling) &&
956 traverse->data != ctx->sections[ctx->section].address + sibling.u.uvalue)
958 WARN("setting cursor for %s to next sibling <0x%lx>\n",
959 dwarf2_debug_traverse_ctx(traverse), sibling.u.uvalue);
960 traverse->data = ctx->sections[ctx->section].address + sibling.u.uvalue;
966 static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx,
967 dwarf2_debug_info_t* di)
969 struct attribute name;
970 struct attribute size;
971 struct attribute encoding;
974 if (di->symt) return di->symt;
976 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
978 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name))
979 name.u.string = NULL;
980 if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
981 if (!dwarf2_find_attribute(ctx, di, DW_AT_encoding, &encoding)) encoding.u.uvalue = DW_ATE_void;
983 switch (encoding.u.uvalue)
985 case DW_ATE_void: bt = btVoid; break;
986 case DW_ATE_address: bt = btULong; break;
987 case DW_ATE_boolean: bt = btBool; break;
988 case DW_ATE_complex_float: bt = btComplex; break;
989 case DW_ATE_float: bt = btFloat; break;
990 case DW_ATE_signed: bt = btInt; break;
991 case DW_ATE_unsigned: bt = btUInt; break;
992 case DW_ATE_signed_char: bt = btChar; break;
993 case DW_ATE_unsigned_char: bt = btChar; break;
994 default: bt = btNoType; break;
996 di->symt = &symt_new_basic(ctx->module, bt, name.u.string, size.u.uvalue)->symt;
1000 assert(size.u.uvalue == 0);
1001 cache_idx = sc_void;
1004 switch (size.u.uvalue)
1006 case 1: cache_idx = sc_int1; break;
1007 case 2: cache_idx = sc_int2; break;
1008 case 4: cache_idx = sc_int4; break;
1013 if (cache_idx != -1 && !ctx->symt_cache[cache_idx])
1014 ctx->symt_cache[cache_idx] = di->symt;
1016 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1020 static struct symt* dwarf2_parse_typedef(dwarf2_parse_context_t* ctx,
1021 dwarf2_debug_info_t* di)
1023 struct symt* ref_type;
1024 struct attribute name;
1026 if (di->symt) return di->symt;
1028 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), di->abbrev->entry_code);
1030 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
1031 ref_type = dwarf2_lookup_type(ctx, di);
1034 di->symt = &symt_new_typedef(ctx->module, ref_type, name.u.string)->symt;
1035 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1039 static struct symt* dwarf2_parse_pointer_type(dwarf2_parse_context_t* ctx,
1040 dwarf2_debug_info_t* di)
1042 struct symt* ref_type;
1043 struct attribute size;
1045 if (di->symt) return di->symt;
1047 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1049 if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
1050 if (!(ref_type = dwarf2_lookup_type(ctx, di)))
1052 ref_type = ctx->symt_cache[sc_void];
1055 di->symt = &symt_new_pointer(ctx->module, ref_type)->symt;
1056 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1060 static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
1061 dwarf2_debug_info_t* di)
1063 struct symt* ref_type;
1064 struct symt* idx_type = NULL;
1065 struct attribute min, max, cnt;
1066 dwarf2_debug_info_t* child;
1069 if (di->symt) return di->symt;
1071 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1073 if (!di->abbrev->have_child)
1075 FIXME("array without range information\n");
1078 ref_type = dwarf2_lookup_type(ctx, di);
1080 for (i=0; i<vector_length(&di->children); i++)
1082 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1083 switch (child->abbrev->tag)
1085 case DW_TAG_subrange_type:
1086 idx_type = dwarf2_lookup_type(ctx, child);
1087 if (!dwarf2_find_attribute(ctx, child, DW_AT_lower_bound, &min))
1089 if (!dwarf2_find_attribute(ctx, child, DW_AT_upper_bound, &max))
1091 if (dwarf2_find_attribute(ctx, child, DW_AT_count, &cnt))
1092 max.u.uvalue = min.u.uvalue + cnt.u.uvalue;
1095 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1096 child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1100 di->symt = &symt_new_array(ctx->module, min.u.uvalue, max.u.uvalue, ref_type, idx_type)->symt;
1104 static struct symt* dwarf2_parse_const_type(dwarf2_parse_context_t* ctx,
1105 dwarf2_debug_info_t* di)
1107 struct symt* ref_type;
1109 if (di->symt) return di->symt;
1111 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1113 ref_type = dwarf2_lookup_type(ctx, di);
1114 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1115 di->symt = ref_type;
1120 static struct symt* dwarf2_parse_volatile_type(dwarf2_parse_context_t* ctx,
1121 dwarf2_debug_info_t* di)
1123 struct symt* ref_type;
1125 if (di->symt) return di->symt;
1127 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1129 ref_type = dwarf2_lookup_type(ctx, di);
1130 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1131 di->symt = ref_type;
1136 static struct symt* dwarf2_parse_reference_type(dwarf2_parse_context_t* ctx,
1137 dwarf2_debug_info_t* di)
1139 struct symt* ref_type = NULL;
1141 if (di->symt) return di->symt;
1143 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1145 ref_type = dwarf2_lookup_type(ctx, di);
1146 /* FIXME: for now, we hard-wire C++ references to pointers */
1147 di->symt = &symt_new_pointer(ctx->module, ref_type)->symt;
1149 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1154 static void dwarf2_parse_udt_member(dwarf2_parse_context_t* ctx,
1155 const dwarf2_debug_info_t* di,
1156 struct symt_udt* parent)
1158 struct symt* elt_type;
1159 struct attribute name;
1160 struct attribute bit_size;
1161 struct attribute bit_offset;
1162 struct location loc;
1166 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1168 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
1169 elt_type = dwarf2_lookup_type(ctx, di);
1170 if (dwarf2_compute_location_attr(ctx, di, DW_AT_data_member_location, &loc, NULL))
1172 if (loc.kind != loc_absolute)
1174 FIXME("Found register, while not expecting it\n");
1178 TRACE("found member_location at %s -> %lu\n",
1179 dwarf2_debug_ctx(ctx), loc.offset);
1183 if (!dwarf2_find_attribute(ctx, di, DW_AT_bit_size, &bit_size))
1184 bit_size.u.uvalue = 0;
1185 if (dwarf2_find_attribute(ctx, di, DW_AT_bit_offset, &bit_offset))
1187 /* FIXME: we should only do this when implementation is LSB (which is
1188 * the case on i386 processors)
1190 struct attribute nbytes;
1191 if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &nbytes))
1194 nbytes.u.uvalue = symt_get_info(ctx->module, elt_type, TI_GET_LENGTH, &size) ?
1195 (unsigned long)size : 0;
1197 bit_offset.u.uvalue = nbytes.u.uvalue * 8 - bit_offset.u.uvalue - bit_size.u.uvalue;
1199 else bit_offset.u.uvalue = 0;
1200 symt_add_udt_element(ctx->module, parent, name.u.string, elt_type,
1201 (loc.offset << 3) + bit_offset.u.uvalue,
1204 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1207 static struct symt* dwarf2_parse_udt_type(dwarf2_parse_context_t* ctx,
1208 dwarf2_debug_info_t* di,
1211 struct attribute name;
1212 struct attribute size;
1214 if (di->symt) return di->symt;
1216 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1218 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
1219 if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
1221 di->symt = &symt_new_udt(ctx->module, name.u.string, size.u.uvalue, udt)->symt;
1223 if (di->abbrev->have_child) /** any interest to not have child ? */
1225 dwarf2_debug_info_t* child;
1228 for (i=0; i<vector_length(&di->children); i++)
1230 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1232 switch (child->abbrev->tag)
1235 /* FIXME: should I follow the sibling stuff ?? */
1236 dwarf2_parse_udt_member(ctx, child, (struct symt_udt*)di->symt);
1238 case DW_TAG_enumeration_type:
1239 dwarf2_parse_enumeration_type(ctx, child);
1241 case DW_TAG_structure_type:
1242 case DW_TAG_class_type:
1243 case DW_TAG_union_type:
1244 case DW_TAG_typedef:
1245 /* FIXME: we need to handle nested udt definitions */
1248 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1249 child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1258 static void dwarf2_parse_enumerator(dwarf2_parse_context_t* ctx,
1259 const dwarf2_debug_info_t* di,
1260 struct symt_enum* parent)
1262 struct attribute name;
1263 struct attribute value;
1265 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1267 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) return;
1268 if (!dwarf2_find_attribute(ctx, di, DW_AT_const_value, &value)) value.u.svalue = 0;
1269 symt_add_enum_element(ctx->module, parent, name.u.string, value.u.svalue);
1271 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1274 static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx,
1275 dwarf2_debug_info_t* di)
1277 struct attribute name;
1278 struct attribute size;
1279 struct symt_basic* basetype;
1281 if (di->symt) return di->symt;
1283 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1285 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
1286 if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 4;
1288 switch (size.u.uvalue) /* FIXME: that's wrong */
1290 case 1: basetype = symt_new_basic(ctx->module, btInt, "char", 1); break;
1291 case 2: basetype = symt_new_basic(ctx->module, btInt, "short", 2); break;
1293 case 4: basetype = symt_new_basic(ctx->module, btInt, "int", 4); break;
1296 di->symt = &symt_new_enum(ctx->module, name.u.string, &basetype->symt)->symt;
1298 if (di->abbrev->have_child) /* any interest to not have child ? */
1300 dwarf2_debug_info_t* child;
1303 /* FIXME: should we use the sibling stuff ?? */
1304 for (i=0; i<vector_length(&di->children); i++)
1306 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1308 switch (child->abbrev->tag)
1310 case DW_TAG_enumerator:
1311 dwarf2_parse_enumerator(ctx, child, (struct symt_enum*)di->symt);
1314 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1315 di->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1322 /* structure used to pass information around when parsing a subprogram */
1323 typedef struct dwarf2_subprogram_s
1325 dwarf2_parse_context_t* ctx;
1326 struct symt_compiland* compiland;
1327 struct symt_function* func;
1328 BOOL non_computed_variable;
1329 struct location frame;
1330 } dwarf2_subprogram_t;
1332 /******************************************************************
1333 * dwarf2_parse_variable
1335 * Parses any variable (parameter, local/global variable)
1337 static void dwarf2_parse_variable(dwarf2_subprogram_t* subpgm,
1338 struct symt_block* block,
1339 dwarf2_debug_info_t* di)
1341 struct symt* param_type;
1342 struct attribute name, value;
1343 struct location loc;
1346 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
1348 is_pmt = !block && di->abbrev->tag == DW_TAG_formal_parameter;
1349 param_type = dwarf2_lookup_type(subpgm->ctx, di);
1351 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_name, &name)) {
1352 /* cannot do much without the name, the functions below won't like it. */
1355 if (dwarf2_compute_location_attr(subpgm->ctx, di, DW_AT_location,
1356 &loc, &subpgm->frame))
1358 struct attribute ext;
1360 TRACE("found parameter %s (kind=%d, offset=%ld, reg=%d) at %s\n",
1361 name.u.string, loc.kind, loc.offset, loc.reg,
1362 dwarf2_debug_ctx(subpgm->ctx));
1369 /* it's a global variable */
1370 /* FIXME: we don't handle its scope yet */
1371 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_external, &ext))
1373 symt_new_global_variable(subpgm->ctx->module, subpgm->compiland,
1374 name.u.string, !ext.u.uvalue,
1375 subpgm->ctx->load_offset + loc.offset,
1379 subpgm->non_computed_variable = TRUE;
1383 /* either a pmt/variable relative to frame pointer or
1384 * pmt/variable in a register
1386 assert(subpgm->func);
1387 symt_add_func_local(subpgm->ctx->module, subpgm->func,
1388 is_pmt ? DataIsParam : DataIsLocal,
1389 &loc, block, param_type, name.u.string);
1393 else if (dwarf2_find_attribute(subpgm->ctx, di, DW_AT_const_value, &value))
1396 if (subpgm->func) WARN("Unsupported constant %s in function\n", name.u.string);
1397 if (is_pmt) FIXME("Unsupported constant (parameter) %s in function\n", name.u.string);
1405 v.n1.n2.vt = VT_UI4;
1406 v.n1.n2.n3.lVal = value.u.uvalue;
1411 v.n1.n2.n3.lVal = value.u.svalue;
1415 case DW_FORM_string:
1416 /* FIXME: native doesn't report const strings from here !!
1417 * however, the value of the string is in the code somewhere
1419 v.n1.n2.vt = VT_I1 | VT_BYREF;
1420 v.n1.n2.n3.byref = pool_strdup(&subpgm->ctx->module->pool, value.u.string);
1424 case DW_FORM_block1:
1425 case DW_FORM_block2:
1426 case DW_FORM_block4:
1428 switch (value.u.block.size)
1430 case 1: v.n1.n2.n3.lVal = *(BYTE*)value.u.block.ptr; break;
1431 case 2: v.n1.n2.n3.lVal = *(USHORT*)value.u.block.ptr; break;
1432 case 4: v.n1.n2.n3.lVal = *(DWORD*)value.u.block.ptr; break;
1434 v.n1.n2.vt = VT_I1 | VT_BYREF;
1435 v.n1.n2.n3.byref = pool_alloc(&subpgm->ctx->module->pool, value.u.block.size);
1436 memcpy(v.n1.n2.n3.byref, value.u.block.ptr, value.u.block.size);
1441 v.n1.n2.vt = VT_I1 | VT_BYREF;
1442 v.n1.n2.n3.byref = pool_alloc(&subpgm->ctx->module->pool, value.u.block.size);
1443 memcpy(v.n1.n2.n3.byref, value.u.block.ptr, value.u.block.size);
1447 FIXME("Unsupported form for const value %s (%lx)\n",
1448 name.u.string, value.form);
1449 v.n1.n2.vt = VT_EMPTY;
1451 di->symt = &symt_new_constant(subpgm->ctx->module, subpgm->compiland,
1452 name.u.string, param_type, &v)->symt;
1454 if (is_pmt && subpgm->func && subpgm->func->type)
1455 symt_add_function_signature_parameter(subpgm->ctx->module,
1456 (struct symt_function_signature*)subpgm->func->type,
1459 if (di->abbrev->have_child) FIXME("Unsupported children\n");
1462 static void dwarf2_parse_subprogram_label(dwarf2_subprogram_t* subpgm,
1463 const dwarf2_debug_info_t* di)
1465 struct attribute name;
1466 struct attribute low_pc;
1467 struct location loc;
1469 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
1471 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_low_pc, &low_pc)) low_pc.u.uvalue = 0;
1472 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_name, &name))
1473 name.u.string = NULL;
1475 loc.kind = loc_absolute;
1476 loc.offset = subpgm->ctx->load_offset + low_pc.u.uvalue;
1477 symt_add_function_point(subpgm->ctx->module, subpgm->func, SymTagLabel,
1478 &loc, name.u.string);
1481 static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t* subpgm,
1482 struct symt_block* parent_block,
1483 const dwarf2_debug_info_t* di);
1485 static void dwarf2_parse_inlined_subroutine(dwarf2_subprogram_t* subpgm,
1486 struct symt_block* parent_block,
1487 const dwarf2_debug_info_t* di)
1489 struct symt_block* block;
1490 struct attribute low_pc;
1491 struct attribute high_pc;
1493 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
1495 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_low_pc, &low_pc)) low_pc.u.uvalue = 0;
1496 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_high_pc, &high_pc)) high_pc.u.uvalue = 0;
1498 block = symt_open_func_block(subpgm->ctx->module, subpgm->func, parent_block,
1499 subpgm->ctx->load_offset + low_pc.u.uvalue - subpgm->func->address,
1500 high_pc.u.uvalue - low_pc.u.uvalue);
1502 if (di->abbrev->have_child) /** any interest to not have child ? */
1504 dwarf2_debug_info_t* child;
1507 for (i=0; i<vector_length(&di->children); i++)
1509 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1511 switch (child->abbrev->tag)
1513 case DW_TAG_formal_parameter:
1514 case DW_TAG_variable:
1515 dwarf2_parse_variable(subpgm, block, child);
1517 case DW_TAG_lexical_block:
1518 dwarf2_parse_subprogram_block(subpgm, block, child);
1520 case DW_TAG_inlined_subroutine:
1521 dwarf2_parse_inlined_subroutine(subpgm, block, child);
1524 dwarf2_parse_subprogram_label(subpgm, child);
1527 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1528 child->abbrev->tag, dwarf2_debug_ctx(subpgm->ctx),
1529 dwarf2_debug_di(di));
1533 symt_close_func_block(subpgm->ctx->module, subpgm->func, block, 0);
1536 static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t* subpgm,
1537 struct symt_block* parent_block,
1538 const dwarf2_debug_info_t* di)
1540 struct symt_block* block;
1541 struct attribute low_pc;
1542 struct attribute high_pc;
1544 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
1546 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_low_pc, &low_pc))
1547 low_pc.u.uvalue = 0;
1548 if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_high_pc, &high_pc))
1549 high_pc.u.uvalue = 0;
1551 block = symt_open_func_block(subpgm->ctx->module, subpgm->func, parent_block,
1552 subpgm->ctx->load_offset + low_pc.u.uvalue - subpgm->func->address,
1553 high_pc.u.uvalue - low_pc.u.uvalue);
1555 if (di->abbrev->have_child) /** any interest to not have child ? */
1557 dwarf2_debug_info_t* child;
1560 for (i=0; i<vector_length(&di->children); i++)
1562 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1564 switch (child->abbrev->tag)
1566 case DW_TAG_inlined_subroutine:
1567 dwarf2_parse_inlined_subroutine(subpgm, block, child);
1569 case DW_TAG_variable:
1570 dwarf2_parse_variable(subpgm, block, child);
1572 case DW_TAG_lexical_block:
1573 dwarf2_parse_subprogram_block(subpgm, block, child);
1575 case DW_TAG_subprogram:
1576 /* FIXME: likely a declaration (to be checked)
1580 case DW_TAG_formal_parameter:
1581 /* FIXME: likely elements for exception handling (GCC flavor)
1586 dwarf2_parse_subprogram_label(subpgm, child);
1588 case DW_TAG_class_type:
1589 case DW_TAG_structure_type:
1590 case DW_TAG_union_type:
1591 case DW_TAG_enumeration_type:
1592 case DW_TAG_typedef:
1593 /* the type referred to will be loaded when we need it, so skip it */
1596 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1597 child->abbrev->tag, dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
1602 symt_close_func_block(subpgm->ctx->module, subpgm->func, block, 0);
1605 static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx,
1606 dwarf2_debug_info_t* di,
1607 struct symt_compiland* compiland)
1609 struct attribute name;
1610 struct attribute low_pc;
1611 struct attribute high_pc;
1612 struct attribute is_decl;
1613 struct attribute inline_flags;
1614 struct symt* ret_type;
1615 struct symt_function_signature* sig_type;
1616 dwarf2_subprogram_t subpgm;
1618 if (di->symt) return di->symt;
1620 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1622 if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name))
1624 WARN("No name for function... dropping function\n");
1627 /* if it's an abstract representation of an inline function, there should be
1628 * a concrete object that we'll handle
1630 if (dwarf2_find_attribute(ctx, di, DW_AT_inline, &inline_flags))
1632 TRACE("Function %s declared as inlined (%ld)... skipping\n",
1633 name.u.string ? name.u.string : "(null)", inline_flags.u.uvalue);
1637 if (!dwarf2_find_attribute(ctx, di, DW_AT_low_pc, &low_pc)) low_pc.u.uvalue = 0;
1638 if (!dwarf2_find_attribute(ctx, di, DW_AT_high_pc, &high_pc)) high_pc.u.uvalue = 0;
1639 /* As functions (defined as inline assembly) get debug info with dwarf
1640 * (not the case for stabs), we just drop Wine's thunks here...
1641 * Actual thunks will be created in elf_module from the symbol table
1643 if (elf_is_in_thunk_area(ctx->load_offset + low_pc.u.uvalue,
1646 if (!dwarf2_find_attribute(ctx, di, DW_AT_declaration, &is_decl))
1647 is_decl.u.uvalue = 0;
1649 if (!(ret_type = dwarf2_lookup_type(ctx, di)))
1651 ret_type = ctx->symt_cache[sc_void];
1655 /* FIXME: assuming C source code */
1656 sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
1657 if (!is_decl.u.uvalue)
1659 subpgm.func = symt_new_function(ctx->module, compiland, name.u.string,
1660 ctx->load_offset + low_pc.u.uvalue,
1661 high_pc.u.uvalue - low_pc.u.uvalue,
1663 di->symt = &subpgm.func->symt;
1665 else subpgm.func = NULL;
1668 subpgm.compiland = compiland;
1669 if (!dwarf2_compute_location_attr(ctx, di, DW_AT_frame_base,
1670 &subpgm.frame, NULL))
1673 subpgm.frame.kind = loc_regrel;
1674 subpgm.frame.reg = 0;
1675 subpgm.frame.offset = 0;
1677 subpgm.non_computed_variable = FALSE;
1679 if (di->abbrev->have_child) /** any interest to not have child ? */
1681 dwarf2_debug_info_t* child;
1684 for (i=0; i<vector_length(&di->children); i++)
1686 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1688 switch (child->abbrev->tag)
1690 case DW_TAG_variable:
1691 case DW_TAG_formal_parameter:
1692 dwarf2_parse_variable(&subpgm, NULL, child);
1694 case DW_TAG_lexical_block:
1695 dwarf2_parse_subprogram_block(&subpgm, NULL, child);
1697 case DW_TAG_inlined_subroutine:
1698 dwarf2_parse_inlined_subroutine(&subpgm, NULL, child);
1700 case DW_TAG_subprogram:
1701 /* FIXME: likely a declaration (to be checked)
1706 dwarf2_parse_subprogram_label(&subpgm, child);
1708 case DW_TAG_class_type:
1709 case DW_TAG_structure_type:
1710 case DW_TAG_union_type:
1711 case DW_TAG_enumeration_type:
1712 case DW_TAG_typedef:
1713 /* the type referred to will be loaded when we need it, so skip it */
1715 case DW_TAG_unspecified_parameters:
1716 /* FIXME: no support in dbghelp's internals so far */
1719 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1720 child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1725 if (subpgm.non_computed_variable || subpgm.frame.kind >= loc_user)
1727 symt_add_function_point(ctx->module, subpgm.func, SymTagCustom,
1728 &subpgm.frame, NULL);
1730 if (subpgm.func) symt_normalize_function(subpgm.ctx->module, subpgm.func);
1735 static struct symt* dwarf2_parse_subroutine_type(dwarf2_parse_context_t* ctx,
1736 dwarf2_debug_info_t* di)
1738 struct symt* ret_type;
1739 struct symt_function_signature* sig_type;
1741 if (di->symt) return di->symt;
1743 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
1745 if (!(ret_type = dwarf2_lookup_type(ctx, di)))
1747 ret_type = ctx->symt_cache[sc_void];
1751 /* FIXME: assuming C source code */
1752 sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
1754 if (di->abbrev->have_child) /** any interest to not have child ? */
1756 dwarf2_debug_info_t* child;
1759 for (i=0; i<vector_length(&di->children); i++)
1761 child = *(dwarf2_debug_info_t**)vector_at(&di->children, i);
1763 switch (child->abbrev->tag)
1765 case DW_TAG_formal_parameter:
1766 symt_add_function_signature_parameter(ctx->module, sig_type,
1767 dwarf2_lookup_type(ctx, child));
1769 case DW_TAG_unspecified_parameters:
1770 WARN("Unsupported unspecified parameters\n");
1776 return di->symt = &sig_type->symt;
1779 static void dwarf2_load_one_entry(dwarf2_parse_context_t* ctx,
1780 dwarf2_debug_info_t* di,
1781 struct symt_compiland* compiland)
1783 switch (di->abbrev->tag)
1785 case DW_TAG_typedef:
1786 dwarf2_parse_typedef(ctx, di);
1788 case DW_TAG_base_type:
1789 dwarf2_parse_base_type(ctx, di);
1791 case DW_TAG_pointer_type:
1792 dwarf2_parse_pointer_type(ctx, di);
1794 case DW_TAG_class_type:
1795 dwarf2_parse_udt_type(ctx, di, UdtClass);
1797 case DW_TAG_structure_type:
1798 dwarf2_parse_udt_type(ctx, di, UdtStruct);
1800 case DW_TAG_union_type:
1801 dwarf2_parse_udt_type(ctx, di, UdtUnion);
1803 case DW_TAG_array_type:
1804 dwarf2_parse_array_type(ctx, di);
1806 case DW_TAG_const_type:
1807 dwarf2_parse_const_type(ctx, di);
1809 case DW_TAG_volatile_type:
1810 dwarf2_parse_volatile_type(ctx, di);
1812 case DW_TAG_reference_type:
1813 dwarf2_parse_reference_type(ctx, di);
1815 case DW_TAG_enumeration_type:
1816 dwarf2_parse_enumeration_type(ctx, di);
1818 case DW_TAG_subprogram:
1819 dwarf2_parse_subprogram(ctx, di, compiland);
1821 case DW_TAG_subroutine_type:
1822 dwarf2_parse_subroutine_type(ctx, di);
1824 case DW_TAG_variable:
1826 dwarf2_subprogram_t subpgm;
1829 subpgm.compiland = compiland;
1831 subpgm.frame.kind = loc_absolute;
1832 subpgm.frame.offset = 0;
1833 subpgm.frame.reg = Wine_DW_no_register;
1834 dwarf2_parse_variable(&subpgm, NULL, di);
1838 FIXME("Unhandled Tag type 0x%lx at %s, for %lu\n",
1839 di->abbrev->tag, dwarf2_debug_ctx(ctx), di->abbrev->entry_code);
1843 static void dwarf2_set_line_number(struct module* module, unsigned long address,
1844 const struct vector* v, unsigned file, unsigned line)
1846 struct symt_function* func;
1847 struct symt_ht* symt;
1850 if (!file || !(psrc = vector_at(v, file - 1))) return;
1852 TRACE("%s %lx %s %u\n",
1853 debugstr_w(module->module.ModuleName), address, source_get(module, *psrc), line);
1854 if (!(symt = symt_find_nearest(module, address)) ||
1855 symt->symt.tag != SymTagFunction) return;
1856 func = (struct symt_function*)symt;
1857 symt_add_func_line(module, func, *psrc, line, address - func->address);
1860 static BOOL dwarf2_parse_line_numbers(const dwarf2_section_t* sections,
1861 dwarf2_parse_context_t* ctx,
1862 const char* compile_dir,
1863 unsigned long offset)
1865 dwarf2_traverse_context_t traverse;
1866 unsigned long length;
1867 unsigned version, header_len, insn_size, default_stmt;
1868 unsigned line_range, opcode_base;
1870 const unsigned char* opcode_len;
1872 struct vector files;
1875 /* section with line numbers stripped */
1876 if (sections[section_line].address == ELF_NO_MAP)
1879 traverse.data = sections[section_line].address + offset;
1880 traverse.start_data = traverse.data;
1881 traverse.end_data = traverse.data + 4;
1882 traverse.word_size = ctx->word_size;
1884 length = dwarf2_parse_u4(&traverse);
1885 traverse.end_data = traverse.start_data + length;
1887 version = dwarf2_parse_u2(&traverse);
1888 header_len = dwarf2_parse_u4(&traverse);
1889 insn_size = dwarf2_parse_byte(&traverse);
1890 default_stmt = dwarf2_parse_byte(&traverse);
1891 line_base = (signed char)dwarf2_parse_byte(&traverse);
1892 line_range = dwarf2_parse_byte(&traverse);
1893 opcode_base = dwarf2_parse_byte(&traverse);
1895 opcode_len = traverse.data;
1896 traverse.data += opcode_base - 1;
1898 vector_init(&dirs, sizeof(const char*), 4);
1899 p = vector_add(&dirs, &ctx->pool);
1900 *p = compile_dir ? compile_dir : ".";
1901 while (*traverse.data)
1903 const char* rel = (const char*)traverse.data;
1904 unsigned rellen = strlen(rel);
1905 TRACE("Got include %s\n", rel);
1906 traverse.data += rellen + 1;
1907 p = vector_add(&dirs, &ctx->pool);
1909 if (*rel == '/' || !compile_dir)
1913 /* include directory relative to compile directory */
1914 unsigned baselen = strlen(compile_dir);
1915 char* tmp = pool_alloc(&ctx->pool, baselen + 1 + rellen + 1);
1916 strcpy(tmp, compile_dir);
1917 if (tmp[baselen - 1] != '/') tmp[baselen++] = '/';
1918 strcpy(&tmp[baselen], rel);
1925 vector_init(&files, sizeof(unsigned), 16);
1926 while (*traverse.data)
1928 unsigned int dir_index, mod_time, length;
1933 name = (const char*)traverse.data;
1934 traverse.data += strlen(name) + 1;
1935 dir_index = dwarf2_leb128_as_unsigned(&traverse);
1936 mod_time = dwarf2_leb128_as_unsigned(&traverse);
1937 length = dwarf2_leb128_as_unsigned(&traverse);
1938 dir = *(const char**)vector_at(&dirs, dir_index);
1939 TRACE("Got file %s/%s (%u,%u)\n", dir, name, mod_time, length);
1940 psrc = vector_add(&files, &ctx->pool);
1941 *psrc = source_new(ctx->module, dir, name);
1945 while (traverse.data < traverse.end_data)
1947 unsigned long address = 0;
1950 unsigned is_stmt = default_stmt;
1951 BOOL basic_block = FALSE, end_sequence = FALSE;
1952 unsigned opcode, extopcode, i;
1954 while (!end_sequence)
1956 opcode = dwarf2_parse_byte(&traverse);
1957 TRACE("Got opcode %x\n", opcode);
1959 if (opcode >= opcode_base)
1961 unsigned delta = opcode - opcode_base;
1963 address += (delta / line_range) * insn_size;
1964 line += line_base + (delta % line_range);
1966 dwarf2_set_line_number(ctx->module, address, &files, file, line);
1973 basic_block = FALSE;
1974 dwarf2_set_line_number(ctx->module, address, &files, file, line);
1976 case DW_LNS_advance_pc:
1977 address += insn_size * dwarf2_leb128_as_unsigned(&traverse);
1979 case DW_LNS_advance_line:
1980 line += dwarf2_leb128_as_signed(&traverse);
1982 case DW_LNS_set_file:
1983 file = dwarf2_leb128_as_unsigned(&traverse);
1985 case DW_LNS_set_column:
1986 dwarf2_leb128_as_unsigned(&traverse);
1988 case DW_LNS_negate_stmt:
1991 case DW_LNS_set_basic_block:
1994 case DW_LNS_const_add_pc:
1995 address += ((255 - opcode_base) / line_range) * insn_size;
1997 case DW_LNS_fixed_advance_pc:
1998 address += dwarf2_parse_u2(&traverse);
2000 case DW_LNS_extended_op:
2001 dwarf2_leb128_as_unsigned(&traverse);
2002 extopcode = dwarf2_parse_byte(&traverse);
2005 case DW_LNE_end_sequence:
2006 dwarf2_set_line_number(ctx->module, address, &files, file, line);
2007 end_sequence = TRUE;
2009 case DW_LNE_set_address:
2010 address = ctx->load_offset + dwarf2_parse_addr(&traverse);
2012 case DW_LNE_define_file:
2013 FIXME("not handled %s\n", traverse.data);
2014 traverse.data += strlen((const char *)traverse.data) + 1;
2015 dwarf2_leb128_as_unsigned(&traverse);
2016 dwarf2_leb128_as_unsigned(&traverse);
2017 dwarf2_leb128_as_unsigned(&traverse);
2020 FIXME("Unsupported extended opcode %x\n", extopcode);
2025 WARN("Unsupported opcode %x\n", opcode);
2026 for (i = 0; i < opcode_len[opcode]; i++)
2027 dwarf2_leb128_as_unsigned(&traverse);
2036 static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections,
2037 struct module* module,
2038 const struct elf_thunk_area* thunks,
2039 dwarf2_traverse_context_t* mod_ctx,
2040 unsigned long load_offset)
2042 dwarf2_parse_context_t ctx;
2043 dwarf2_traverse_context_t abbrev_ctx;
2044 dwarf2_debug_info_t* di;
2045 dwarf2_traverse_context_t cu_ctx;
2046 const unsigned char* comp_unit_start = mod_ctx->data;
2047 unsigned long cu_length;
2048 unsigned short cu_version;
2049 unsigned long cu_abbrev_offset;
2052 cu_length = dwarf2_parse_u4(mod_ctx);
2053 cu_ctx.data = cu_ctx.start_data = mod_ctx->data;
2054 cu_ctx.end_data = mod_ctx->data + cu_length;
2055 mod_ctx->data += cu_length;
2056 cu_version = dwarf2_parse_u2(&cu_ctx);
2057 cu_abbrev_offset = dwarf2_parse_u4(&cu_ctx);
2058 cu_ctx.word_size = dwarf2_parse_byte(&cu_ctx);
2060 TRACE("Compilation Unit Header found at 0x%x:\n",
2061 (int)(comp_unit_start - sections[section_debug].address));
2062 TRACE("- length: %lu\n", cu_length);
2063 TRACE("- version: %u\n", cu_version);
2064 TRACE("- abbrev_offset: %lu\n", cu_abbrev_offset);
2065 TRACE("- word_size: %u\n", cu_ctx.word_size);
2067 if (cu_version != 2)
2069 WARN("%u DWARF version unsupported. Wine dbghelp only support DWARF 2.\n",
2074 pool_init(&ctx.pool, 65536);
2075 ctx.sections = sections;
2076 ctx.section = section_debug;
2077 ctx.module = module;
2078 ctx.word_size = cu_ctx.word_size;
2079 ctx.thunks = thunks;
2080 ctx.load_offset = load_offset;
2081 ctx.ref_offset = comp_unit_start - sections[section_debug].address;
2082 memset(ctx.symt_cache, 0, sizeof(ctx.symt_cache));
2083 ctx.symt_cache[sc_void] = &symt_new_basic(module, btVoid, "void", 0)->symt;
2085 abbrev_ctx.start_data = sections[section_abbrev].address + cu_abbrev_offset;
2086 abbrev_ctx.data = abbrev_ctx.start_data;
2087 abbrev_ctx.end_data = sections[section_abbrev].address + sections[section_abbrev].size;
2088 abbrev_ctx.word_size = cu_ctx.word_size;
2089 dwarf2_parse_abbrev_set(&abbrev_ctx, &ctx.abbrev_table, &ctx.pool);
2091 sparse_array_init(&ctx.debug_info_table, sizeof(dwarf2_debug_info_t), 128);
2092 dwarf2_read_one_debug_info(&ctx, &cu_ctx, &di);
2094 if (di->abbrev->tag == DW_TAG_compile_unit)
2096 struct attribute name;
2097 dwarf2_debug_info_t** pdi = NULL;
2098 struct attribute stmt_list, low_pc;
2099 struct attribute comp_dir;
2101 if (!dwarf2_find_attribute(&ctx, di, DW_AT_name, &name))
2102 name.u.string = NULL;
2104 /* get working directory of current compilation unit */
2105 if (!dwarf2_find_attribute(&ctx, di, DW_AT_comp_dir, &comp_dir))
2106 comp_dir.u.string = NULL;
2108 if (!dwarf2_find_attribute(&ctx, di, DW_AT_low_pc, &low_pc))
2109 low_pc.u.uvalue = 0;
2110 di->symt = &symt_new_compiland(module,
2111 ctx.load_offset + low_pc.u.uvalue,
2112 source_new(module, comp_dir.u.string, name.u.string))->symt;
2114 if (di->abbrev->have_child)
2117 for (i=0; i<vector_length(&di->children); i++)
2119 pdi = vector_at(&di->children, i);
2120 dwarf2_load_one_entry(&ctx, *pdi, (struct symt_compiland*)di->symt);
2123 if (dwarf2_find_attribute(&ctx, di, DW_AT_stmt_list, &stmt_list))
2125 if (dwarf2_parse_line_numbers(sections, &ctx, comp_dir.u.string, stmt_list.u.uvalue))
2126 module->module.LineNumbers = TRUE;
2130 else FIXME("Should have a compilation unit here\n");
2131 pool_destroy(&ctx.pool);
2135 static BOOL dwarf2_lookup_loclist(const struct module* module, const BYTE* start,
2137 dwarf2_traverse_context_t* lctx)
2140 const BYTE* ptr = start;
2143 while (ptr < module->dwarf2_info->debug_loc.address + module->dwarf2_info->debug_loc.size)
2145 beg = dwarf2_get_u4(ptr); ptr += 4;
2146 end = dwarf2_get_u4(ptr); ptr += 4;
2147 if (!beg && !end) break;
2148 len = dwarf2_get_u2(ptr); ptr += 2;
2150 if (beg <= ip && ip < end)
2153 lctx->end_data = ptr + len;
2154 lctx->word_size = 4; /* FIXME word size !!! */
2159 WARN("Couldn't find ip in location list\n");
2163 static enum location_error loc_compute_frame(struct process* pcs,
2164 const struct module* module,
2165 const struct symt_function* func,
2166 DWORD ip, struct location* frame)
2168 struct symt** psym = NULL;
2169 struct location* pframe;
2170 dwarf2_traverse_context_t lctx;
2171 enum location_error err;
2174 for (i=0; i<vector_length(&func->vchildren); i++)
2176 psym = vector_at(&func->vchildren, i);
2177 if ((*psym)->tag == SymTagCustom)
2179 pframe = &((struct symt_hierarchy_point*)*psym)->loc;
2181 /* First, recompute the frame information, if needed */
2182 switch (pframe->kind)
2188 case loc_dwarf2_location_list:
2189 WARN("Searching loclist for %s\n", func->hash_elt.name);
2190 if (!dwarf2_lookup_loclist(module,
2191 module->dwarf2_info->debug_loc.address + pframe->offset,
2193 return loc_err_out_of_scope;
2194 if ((err = compute_location(&lctx, frame, pcs->handle, NULL)) < 0) return err;
2195 if (frame->kind >= loc_user)
2197 WARN("Couldn't compute runtime frame location\n");
2198 return loc_err_too_complex;
2202 WARN("Unsupported frame kind %d\n", pframe->kind);
2203 return loc_err_internal;
2208 WARN("Couldn't find Custom function point, whilst location list offset is searched\n");
2209 return loc_err_internal;
2212 static void dwarf2_location_compute(struct process* pcs,
2213 const struct module* module,
2214 const struct symt_function* func,
2215 struct location* loc)
2217 struct location frame;
2220 dwarf2_traverse_context_t lctx;
2222 if (!func->container || func->container->tag != SymTagCompiland)
2224 WARN("We'd expect function %s's container to exist and be a compiland\n", func->hash_elt.name);
2225 err = loc_err_internal;
2229 /* instruction pointer relative to compiland's start */
2230 ip = pcs->ctx_frame.InstructionOffset - ((struct symt_compiland*)func->container)->address;
2232 if ((err = loc_compute_frame(pcs, module, func, ip, &frame)) == 0)
2236 case loc_dwarf2_location_list:
2237 /* Then, if the variable has a location list, find it !! */
2238 if (dwarf2_lookup_loclist(module,
2239 module->dwarf2_info->debug_loc.address + loc->offset,
2242 err = loc_err_out_of_scope;
2244 case loc_dwarf2_block:
2245 /* or if we have a copy of an existing block, get ready for it */
2247 unsigned* ptr = (unsigned*)loc->offset;
2249 lctx.data = (const BYTE*)(ptr + 1);
2250 lctx.end_data = lctx.data + *ptr;
2251 lctx.word_size = 4; /* FIXME !! */
2254 /* now get the variable */
2255 err = compute_location(&lctx, loc, pcs->handle, &frame);
2262 WARN("Unsupported local kind %d\n", loc->kind);
2263 err = loc_err_internal;
2269 loc->kind = loc_register;
2274 BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
2275 const struct elf_thunk_area* thunks,
2276 const unsigned char* debug, unsigned int debug_size,
2277 const unsigned char* abbrev, unsigned int abbrev_size,
2278 const unsigned char* str, unsigned int str_size,
2279 const unsigned char* line, unsigned int line_size,
2280 const unsigned char* loclist, unsigned int loclist_size)
2282 dwarf2_section_t section[section_max];
2284 dwarf2_traverse_context_t mod_ctx;
2286 mod_ctx.start_data = mod_ctx.data = debug;
2287 mod_ctx.end_data = debug + debug_size;
2289 module->loc_compute = dwarf2_location_compute;
2291 section[section_debug].address = debug;
2292 section[section_debug].size = debug_size;
2293 section[section_abbrev].address = abbrev;
2294 section[section_abbrev].size = abbrev_size;
2295 section[section_string].address = str;
2296 section[section_string].size = str_size;
2297 section[section_line].address = line;
2298 section[section_line].size = line_size;
2302 /* initialize the dwarf2 specific info block for this module.
2303 * As we'll need later on the .debug_loc section content, we copy it in
2304 * the module structure for later reuse
2306 module->dwarf2_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*module->dwarf2_info) + loclist_size);
2307 if (!module->dwarf2_info) return FALSE;
2308 ptr = (unsigned char*)(module->dwarf2_info + 1);
2309 memcpy(ptr, loclist, loclist_size);
2310 module->dwarf2_info->debug_loc.address = ptr;
2311 module->dwarf2_info->debug_loc.size = loclist_size;
2314 while (mod_ctx.data < mod_ctx.end_data)
2316 dwarf2_parse_compilation_unit(section, module, thunks, &mod_ctx, load_offset);
2318 module->module.SymType = SymDia;
2319 module->module.CVSig = 'D' | ('W' << 8) | ('A' << 16) | ('R' << 24);
2320 /* FIXME: we could have a finer grain here */
2321 module->module.GlobalSymbols = TRUE;
2322 module->module.TypeInfo = TRUE;
2323 module->module.SourceIndexed = TRUE;
2324 module->module.Publics = TRUE;