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
24 #include <sys/types.h>
26 #ifdef HAVE_SYS_STAT_H
27 # include <sys/stat.h>
29 #ifdef HAVE_SYS_MMAN_H
40 #define PATH_MAX MAX_PATH
50 #include "dbghelp_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_dwarf);
57 static void dump(const void* ptr, unsigned len)
61 static const char hexof[] = "0123456789abcdef";
62 const BYTE* x = (const BYTE*)ptr;
64 for (i = 0; i < len; i += 16)
66 sprintf(msg, "%08x: ", i);
67 memset(msg + 10, ' ', 3 * 16 + 1 + 16);
68 for (j = 0; j < min(16, len - i); j++)
70 msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
71 msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
72 msg[10 + 3 * j + 2] = ' ';
73 msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
76 msg[10 + 3 * 16] = ' ';
77 msg[10 + 3 * 16 + 1 + 16] = '\0';
86 * http://www.eagercon.com/dwarf/dwarf3std.htm
87 * http://www.eagercon.com/dwarf/dwarf-2.0.0.pdf
89 * dwarf2.h: http://www.hakpetzna.com/b/binutils/dwarf2_8h-source.html
91 * example of projects who do dwarf2 parsing:
92 * http://www.x86-64.org/cgi-bin/cvsweb.cgi/binutils.dead/binutils/readelf.c?rev=1.1.1.2
93 * http://elis.ugent.be/diota/log/ltrace_elf.c
101 typedef struct dwarf2_abbrev_entry_attr_s {
102 unsigned long attribute;
104 struct dwarf2_abbrev_entry_attr_s* next;
105 } dwarf2_abbrev_entry_attr_t;
107 typedef struct dwarf2_abbrev_entry_s
109 unsigned long entry_code;
111 unsigned char have_child;
113 dwarf2_abbrev_entry_attr_t* attrs;
114 } dwarf2_abbrev_entry_t;
116 typedef struct dwarf2_parse_context_s {
118 struct sparse_array abbrev_table;
119 const unsigned char* data_stream;
120 const unsigned char* data;
121 const unsigned char* start_data;
122 const unsigned char* end_data;
123 const unsigned char* str_section;
124 unsigned long offset;
125 unsigned char word_size;
126 } dwarf2_parse_context_t;
128 /* forward declarations */
129 static struct symt_enum* dwarf2_parse_enumeration_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx);
131 static unsigned char dwarf2_parse_byte(dwarf2_parse_context_t* ctx)
133 unsigned char uvalue = *(const unsigned char*) ctx->data;
138 static unsigned short dwarf2_parse_u2(dwarf2_parse_context_t* ctx)
140 unsigned short uvalue = *(const unsigned short*) ctx->data;
145 static unsigned long dwarf2_parse_u4(dwarf2_parse_context_t* ctx)
147 unsigned long uvalue = *(const unsigned int*) ctx->data;
152 static unsigned long dwarf2_leb128_as_unsigned(dwarf2_parse_context_t* ctx)
154 unsigned long ret = 0;
158 assert( NULL != ctx );
161 byte = dwarf2_parse_byte(ctx);
162 ret |= (byte & 0x7f) << shift;
164 if (0 == (byte & 0x80)) { break ; }
170 static long dwarf2_leb128_as_signed(dwarf2_parse_context_t* ctx)
175 const unsigned size = sizeof(int) * 8;
177 assert( NULL != ctx );
180 byte = dwarf2_parse_byte(ctx);
181 ret |= (byte & 0x7f) << shift;
183 if (0 == (byte & 0x80)) { break ; }
185 /* as spec: sign bit of byte is 2nd high order bit (80x40)
186 * -> 0x80 is used as flag.
188 if ((shift < size) && (byte & 0x40)) {
189 ret |= - (1 << shift);
194 static const char* dwarf2_debug_ctx(dwarf2_parse_context_t* ctx)
196 /*return wine_dbg_sprintf("ctx(0x%x,%u)", ctx->data - ctx->start_data, ctx->level); */
197 return wine_dbg_sprintf("ctx(0x%x)", ctx->data - ctx->data_stream);
199 static const char* dwarf2_debug_attr(dwarf2_abbrev_entry_attr_t* attr)
201 return wine_dbg_sprintf("attr(attr:0x%lx,form:0x%lx)", attr->attribute, attr->form);
204 static void dwarf2_check_sibling(dwarf2_parse_context_t* ctx, unsigned long next_sibling)
206 if (0 < next_sibling && ctx->data != ctx->data_stream + next_sibling) {
207 if ((ctx->data + 1) != ctx->data_stream + next_sibling) {
209 WARN("cursor error for %s should be sibling<0x%lx>\n", dwarf2_debug_ctx(ctx), next_sibling);
211 ctx->data = ctx->data_stream + next_sibling;
216 static dwarf2_abbrev_entry_t*
217 dwarf2_abbrev_table_find_entry(struct sparse_array* abbrev_table,
218 unsigned long entry_code)
220 assert( NULL != abbrev_table );
221 return sparse_array_find(abbrev_table, entry_code);
224 static void dwarf2_parse_abbrev_set(dwarf2_parse_context_t* abbrev_ctx,
225 struct sparse_array* abbrev_table,
228 unsigned long entry_code;
229 dwarf2_abbrev_entry_t* abbrev_entry;
230 dwarf2_abbrev_entry_attr_t* new = NULL;
231 dwarf2_abbrev_entry_attr_t* last = NULL;
232 unsigned long attribute;
235 TRACE("%s, end at %p\n", dwarf2_debug_ctx(abbrev_ctx), abbrev_ctx->end_data);
237 assert( NULL != abbrev_ctx );
239 sparse_array_init(abbrev_table, sizeof(dwarf2_abbrev_entry_t), 32);
240 while (abbrev_ctx->data < abbrev_ctx->end_data)
242 TRACE("now at %s\n", dwarf2_debug_ctx(abbrev_ctx));
243 entry_code = dwarf2_leb128_as_unsigned(abbrev_ctx);
244 TRACE("found entry_code %lu\n", entry_code);
247 TRACE("NULL entry code at %s\n", dwarf2_debug_ctx(abbrev_ctx));
250 abbrev_entry = sparse_array_add(abbrev_table, entry_code, pool);
251 assert( NULL != abbrev_entry );
253 abbrev_entry->entry_code = entry_code;
254 abbrev_entry->tag = dwarf2_leb128_as_unsigned(abbrev_ctx);
255 abbrev_entry->have_child = dwarf2_parse_byte(abbrev_ctx);
256 abbrev_entry->attrs = NULL;
257 abbrev_entry->num_attr = 0;
259 TRACE("table:(%p,#%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n",
260 abbrev_table, sparse_array_length(abbrev_table),
261 entry_code, abbrev_entry->tag, abbrev_entry->have_child, abbrev_entry);
266 attribute = dwarf2_leb128_as_unsigned(abbrev_ctx);
267 form = dwarf2_leb128_as_unsigned(abbrev_ctx);
268 if (!attribute) break;
270 new = pool_alloc(pool, sizeof(dwarf2_abbrev_entry_attr_t));
273 new->attribute = attribute;
276 if (abbrev_entry->attrs) last->next = new;
277 else abbrev_entry->attrs = new;
279 abbrev_entry->num_attr++;
282 TRACE("found %u entries\n", sparse_array_length(abbrev_table));
285 static const char* dwarf2_parse_attr_as_string(dwarf2_abbrev_entry_attr_t* attr,
286 dwarf2_parse_context_t* ctx)
288 const char* ret = NULL;
289 switch (attr->form) {
291 ret = (const char*) ctx->data;
292 ctx->data += strlen(ret) + 1;
296 unsigned long offset = dwarf2_parse_u4(ctx);
297 ret = (const char*) ctx->str_section + offset;
298 /*FIXME("Unsupported indirect string format offset 0x%lx (in .debug_str)\n", offset);*/
302 ERR("Unsupported string format 0x%lx for attr 0x%lx\n", attr->form, attr->attribute);
307 static unsigned long dwarf2_parse_attr_as_addr(dwarf2_abbrev_entry_attr_t* attr,
308 dwarf2_parse_context_t* ctx)
310 unsigned long offset = 0;
311 switch (ctx->word_size) {
313 offset = *(const unsigned int*) ctx->data;
317 FIXME("Unsupported Word Size %u\n", ctx->word_size);
319 ctx->data += ctx->word_size;
323 static unsigned long dwarf2_parse_attr_as_ref(dwarf2_abbrev_entry_attr_t* attr,
324 dwarf2_parse_context_t* ctx)
326 unsigned long uvalue = 0;
327 switch (attr->form) {
329 uvalue = ctx->offset + dwarf2_parse_byte(ctx);
330 TRACE("ref1<0x%lx>\n", uvalue);
334 uvalue = ctx->offset + dwarf2_parse_u2(ctx);
335 TRACE("ref2<0x%lx>\n", uvalue);
339 uvalue = ctx->offset + dwarf2_parse_u4(ctx);
340 TRACE("ref4<0x%lx>\n", uvalue);
344 /* FIXME: 64bits support */
346 uvalue = ctx->offset + dwarf2_parse_u8(ctx);
347 TRACE("ref8<0x%lx>\n", uvalue);
356 static unsigned long dwarf2_parse_attr_as_data(dwarf2_abbrev_entry_attr_t* attr,
357 dwarf2_parse_context_t* ctx)
359 unsigned long uvalue = 0;
360 switch (attr->form) {
362 uvalue = dwarf2_parse_byte(ctx);
363 TRACE("data1<%lu>\n", uvalue);
367 uvalue = dwarf2_parse_u2(ctx);
368 TRACE("data2<%lu>\n", uvalue);
372 uvalue = dwarf2_parse_u4(ctx);
373 TRACE("data4<%lu>\n", uvalue);
377 FIXME("Unsupported 64bits support\n");
384 static void dwarf2_parse_attr(dwarf2_abbrev_entry_attr_t* attr,
385 dwarf2_parse_context_t* ctx)
387 const unsigned long attribute = attr->attribute;
388 const unsigned long form = attr->form;
389 unsigned long uvalue = 0;
391 const char* str = NULL;
393 TRACE("(attr:0x%lx,form:0x%lx)\n", attribute, form);
396 case DW_FORM_ref_addr:
398 uvalue = dwarf2_parse_attr_as_addr(attr, ctx);
402 uvalue = dwarf2_parse_byte(ctx);
403 TRACE("flag<0x%lx>\n", uvalue);
407 uvalue = dwarf2_parse_byte(ctx);
408 TRACE("data1<%lu>\n", uvalue);
412 uvalue = dwarf2_parse_u2(ctx);
413 TRACE("data2<%lu>\n", uvalue);
417 uvalue = dwarf2_parse_u4(ctx);
418 TRACE("data4<%lu>\n", uvalue);
425 uvalue = dwarf2_parse_attr_as_ref(attr, ctx);
426 /*TRACE("ref<0x%lx>\n", ctx->offset + uvalue);*/
430 FIXME("Unsupported 64bits support\n");
435 svalue = dwarf2_leb128_as_signed(ctx);
438 case DW_FORM_ref_udata:
440 uvalue = dwarf2_leb128_as_unsigned(ctx);
445 str = dwarf2_parse_attr_as_string(attr, ctx);
446 TRACE("string<%s>\n", str);
450 uvalue = dwarf2_leb128_as_unsigned(ctx);
455 uvalue = dwarf2_parse_byte(ctx);
460 uvalue = dwarf2_parse_u2(ctx);
465 uvalue = dwarf2_parse_u4(ctx);
474 static struct symt* dwarf2_find_symt_by_ref(struct module* module, unsigned long ref)
476 WARN("want ref<0x%lx>\n", ref);
480 static struct symt* dwarf2_add_symt_ref(struct module* module, unsigned long ref, struct symt* symt)
482 if (NULL != symt) return NULL;
486 static struct symt_basic* dwarf2_parse_base_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
488 struct symt_basic* symt = NULL;
489 const char* name = NULL;
491 unsigned encoding = 0;
493 dwarf2_abbrev_entry_attr_t* attr = NULL;
495 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
497 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
498 switch (attr->attribute) {
500 name = dwarf2_parse_attr_as_string(attr, ctx);
501 TRACE("found name %s\n", name);
503 case DW_AT_byte_size:
504 size = dwarf2_parse_attr_as_data(attr, ctx);
507 encoding = dwarf2_parse_byte(ctx);
510 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
511 dwarf2_parse_attr(attr, ctx);
515 case DW_ATE_void: bt = btVoid; break;
516 case DW_ATE_address: bt = btULong; break;
517 case DW_ATE_boolean: bt = btBool; break;
518 case DW_ATE_complex_float: bt = btComplex; break;
519 case DW_ATE_float: bt = btFloat; break;
520 case DW_ATE_signed: bt = btInt; break;
521 case DW_ATE_unsigned: bt = btUInt; break;
522 case DW_ATE_signed_char: bt = btChar; break;
523 case DW_ATE_unsigned_char: bt = btChar; break;
527 /*TRACE("symt_new_basic(%p, %u, %s, %u)", module, bt, name, size);*/
528 symt = symt_new_basic(module, bt, name, size);
530 if (entry->have_child) {
531 FIXME("Unsupported children\n");
536 static struct symt_typedef* dwarf2_parse_typedef(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
538 struct symt_typedef* symt = NULL;
539 struct symt* ref_type = NULL;
540 const char* name = NULL;
541 dwarf2_abbrev_entry_attr_t* attr = NULL;
543 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
545 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
546 switch (attr->attribute) {
548 name = dwarf2_parse_attr_as_string(attr, ctx);
549 TRACE("found name %s\n", name);
553 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
554 ref_type = dwarf2_find_symt_by_ref(module, ref);
557 case DW_AT_decl_file:
558 case DW_AT_decl_line:
559 dwarf2_parse_attr(attr, ctx);
562 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
563 dwarf2_parse_attr(attr, ctx);
567 symt = symt_new_typedef(module, ref_type, name);
570 if (entry->have_child) {
571 FIXME("Unsupported children\n");
576 static struct symt_pointer* dwarf2_parse_pointer_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
578 struct symt_pointer* symt = NULL;
579 struct symt* ref_type = NULL;
581 dwarf2_abbrev_entry_attr_t* attr = NULL;
583 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
585 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
586 switch (attr->attribute) {
587 case DW_AT_byte_size:
588 size = dwarf2_parse_attr_as_data(attr, ctx);
592 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
593 ref_type = dwarf2_find_symt_by_ref(module, ref);
597 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
598 dwarf2_parse_attr(attr, ctx);
601 symt = symt_new_pointer(module, ref_type);
603 if (entry->have_child) {
604 FIXME("Unsupported children\n");
609 static void dwarf2_parse_array_subrange_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_array* parent)
613 struct symt* idx_type = NULL;
614 dwarf2_abbrev_entry_attr_t* attr = NULL;
616 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
618 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
619 switch (attr->attribute) {
622 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
623 idx_type = dwarf2_find_symt_by_ref(module, ref);
624 /** check if idx_type is a basic_type integer */
627 case DW_AT_lower_bound:
628 TRACE("%s %s, lower_bound\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
629 min = dwarf2_parse_attr_as_data(attr, ctx);
631 case DW_AT_upper_bound:
632 TRACE("%s %s, upper_bound\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
633 max = dwarf2_parse_attr_as_data(attr, ctx);
636 TRACE("%s %s, count min:%u\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr), min);
637 max = min + dwarf2_parse_attr_as_data(attr, ctx);
640 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
641 dwarf2_parse_attr(attr, ctx);
646 parent->index_type = idx_type;
648 TRACE("found min:%u max:%u\n", min, max);
650 if (entry->have_child) {
651 FIXME("Unsupported children\n");
656 static struct symt_array* dwarf2_parse_array_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
658 struct symt_array* symt = NULL;
659 struct symt* ref_type = NULL;
662 dwarf2_abbrev_entry_attr_t* attr = NULL;
663 unsigned long next_sibling = 0;
665 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
667 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
668 switch (attr->attribute) {
670 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
674 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
675 ref_type = dwarf2_find_symt_by_ref(module, ref);
679 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
680 dwarf2_parse_attr(attr, ctx);
684 /* FIXME: ugly as hell */
685 symt = symt_new_array(module, min, max, ref_type, NULL);
687 if (entry->have_child) { /** any interest to not have child ? */
688 while (ctx->data < ctx->end_data) {
689 dwarf2_abbrev_entry_t* entry = NULL;
690 unsigned long entry_code;
691 unsigned long entry_ref = 0;
693 entry_ref = ctx->data - ctx->data_stream;
695 entry_code = dwarf2_leb128_as_unsigned(ctx);
696 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
697 if (0 == entry_code) {
701 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
702 assert( NULL != entry );
704 switch (entry->tag) {
705 case DW_TAG_subrange_type:
706 dwarf2_parse_array_subrange_type(module, entry, ctx, symt);
710 dwarf2_abbrev_entry_attr_t* attr;
711 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
712 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
713 dwarf2_parse_attr(attr, ctx);
721 /** set correct data cursor */
722 dwarf2_check_sibling(ctx, next_sibling);
727 static struct symt* dwarf2_parse_const_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
729 struct symt* ref_type = NULL;
730 dwarf2_abbrev_entry_attr_t* attr = NULL;
731 unsigned long next_sibling = 0;
733 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
735 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
736 switch (attr->attribute) {
739 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
740 ref_type = dwarf2_find_symt_by_ref(module, ref);
744 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
745 dwarf2_parse_attr(attr, ctx);
749 if (entry->have_child) {
750 FIXME("Unsupported children\n");
753 /** set correct data cursor */
754 dwarf2_check_sibling(ctx, next_sibling);
759 static struct symt* dwarf2_parse_reference_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
761 struct symt* symt = NULL;
762 struct symt* ref_type = NULL;
763 dwarf2_abbrev_entry_attr_t* attr = NULL;
764 unsigned long next_sibling = 0;
766 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
768 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
769 switch (attr->attribute) {
771 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
775 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
776 ref_type = dwarf2_find_symt_by_ref(module, ref);
780 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
781 dwarf2_parse_attr(attr, ctx);
784 /* FIXME: for now, we hard-wire C++ references to pointers */
785 symt = &symt_new_pointer(module, ref_type)->symt;
787 if (entry->have_child) {
788 FIXME("Unsupported children\n");
791 /** set correct data cursor */
792 dwarf2_check_sibling(ctx, next_sibling);
797 static void dwarf2_parse_udt_member(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_udt* parent)
799 struct symt* elt_type = NULL;
800 const char* name = NULL;
801 unsigned long offset = 0;
803 dwarf2_abbrev_entry_attr_t* attr = NULL;
804 unsigned long next_sibling = 0;
806 assert( NULL != parent );
808 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
810 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
811 switch (attr->attribute) {
813 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
816 name = dwarf2_parse_attr_as_string(attr, ctx);
817 TRACE("found name %s\n", name);
821 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
822 elt_type = dwarf2_find_symt_by_ref(module, ref);
825 case DW_AT_data_member_location:
827 unsigned long uvalue = 0;
828 TRACE("found member_location at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
829 /*offset = dwarf2_parse_attr_as_data(attr, ctx);*/
830 switch (attr->form) {
832 uvalue = dwarf2_leb128_as_unsigned(ctx);
835 uvalue = dwarf2_parse_byte(ctx);
838 uvalue = dwarf2_parse_u2(ctx);
841 uvalue = dwarf2_parse_u4(ctx);
844 WARN("Unhandled attr form at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
845 dwarf2_parse_attr(attr, ctx);
848 unsigned char op = dwarf2_parse_byte(ctx);
851 case DW_OP_plus_uconst:
852 offset = dwarf2_leb128_as_unsigned(ctx);
855 WARN("Unhandled attr op at %s, for %s, op:%u\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr), op);
858 TRACE("found offset:%lu\n", offset);
862 case DW_AT_decl_file:
863 case DW_AT_decl_line:
864 dwarf2_parse_attr(attr, ctx);
867 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
868 dwarf2_parse_attr(attr, ctx);
871 symt_add_udt_element(module, parent, name, elt_type, offset, size);
873 if (entry->have_child) {
874 FIXME("Unsupported children\n");
877 /** set correct data cursor */
878 dwarf2_check_sibling(ctx, next_sibling);
881 static void dwarf2_parse_udt_members(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_udt* symt)
883 if (entry->have_child) { /** any interest to not have child ? */
884 while (ctx->data < ctx->end_data) {
885 dwarf2_abbrev_entry_t* entry = NULL;
886 unsigned long entry_code;
887 unsigned long entry_ref = 0;
889 entry_ref = ctx->data - ctx->data_stream;
891 entry_code = dwarf2_leb128_as_unsigned(ctx);
892 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
893 if (0 == entry_code) {
897 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
898 assert( NULL != entry );
900 switch (entry->tag) {
902 dwarf2_parse_udt_member(module, entry, ctx, symt);
904 case DW_TAG_enumeration_type:
906 struct symt_enum* symt = dwarf2_parse_enumeration_type(module, entry, ctx);
907 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
912 dwarf2_abbrev_entry_attr_t* attr;
913 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
914 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
915 dwarf2_parse_attr(attr, ctx);
924 static struct symt_udt* dwarf2_parse_class_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
926 struct symt_udt* symt = NULL;
927 const char* name = NULL;
929 dwarf2_abbrev_entry_attr_t* attr = NULL;
930 unsigned long next_sibling = 0;
932 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
934 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
935 switch (attr->attribute) {
937 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
940 name = dwarf2_parse_attr_as_string(attr, ctx);
941 TRACE("found name %s\n", name);
943 case DW_AT_byte_size:
944 size = dwarf2_parse_attr_as_data(attr, ctx);
946 case DW_AT_decl_file:
947 case DW_AT_decl_line:
948 dwarf2_parse_attr(attr, ctx);
951 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
952 dwarf2_parse_attr(attr, ctx);
955 symt = symt_new_udt(module, name, size, UdtClass);
956 dwarf2_parse_udt_members(module, entry, ctx, symt);
958 /** set correct data cursor */
959 dwarf2_check_sibling(ctx, next_sibling);
964 static struct symt_udt* dwarf2_parse_struct_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
966 struct symt_udt* symt = NULL;
967 const char* name = NULL;
969 dwarf2_abbrev_entry_attr_t* attr = NULL;
970 unsigned long next_sibling = 0;
972 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
974 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
975 switch (attr->attribute) {
977 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
980 name = dwarf2_parse_attr_as_string(attr, ctx);
981 TRACE("found name %s\n", name);
983 case DW_AT_byte_size:
984 size = dwarf2_parse_attr_as_data(attr, ctx);
986 case DW_AT_decl_file:
987 case DW_AT_decl_line:
988 dwarf2_parse_attr(attr, ctx);
991 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
992 dwarf2_parse_attr(attr, ctx);
995 symt = symt_new_udt(module, name, size, UdtStruct);
996 dwarf2_parse_udt_members(module, entry, ctx, symt);
998 /** set correct data cursor */
999 dwarf2_check_sibling(ctx, next_sibling);
1004 static struct symt_udt* dwarf2_parse_union_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
1006 struct symt_udt* symt = NULL;
1007 const char* name = NULL;
1009 dwarf2_abbrev_entry_attr_t* attr = NULL;
1010 unsigned long next_sibling = 0;
1012 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1014 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1015 switch (attr->attribute) {
1017 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1020 name = dwarf2_parse_attr_as_string(attr, ctx);
1021 TRACE("found name %s\n", name);
1023 case DW_AT_byte_size:
1024 size = dwarf2_parse_attr_as_data(attr, ctx);
1026 case DW_AT_decl_file:
1027 case DW_AT_decl_line:
1028 dwarf2_parse_attr(attr, ctx);
1031 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1032 dwarf2_parse_attr(attr, ctx);
1035 symt = symt_new_udt(module, name, size, UdtUnion);
1036 dwarf2_parse_udt_members(module, entry, ctx, symt);
1038 /** set correct data cursor */
1039 dwarf2_check_sibling(ctx, next_sibling);
1044 static void dwarf2_parse_enumerator(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_enum* parent)
1046 const char* name = NULL;
1048 dwarf2_abbrev_entry_attr_t* attr = NULL;
1050 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1052 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1053 switch (attr->attribute) {
1055 name = dwarf2_parse_attr_as_string(attr, ctx);
1056 TRACE("found name %s\n", name);
1058 case DW_AT_const_value:
1059 switch (attr->form) {
1061 value = dwarf2_leb128_as_signed(ctx);
1062 TRACE("found value %ld\n", value);
1065 value = dwarf2_leb128_as_unsigned(ctx);
1066 TRACE("found value %ld\n", value);
1069 WARN("Unhandled attr form at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1070 dwarf2_parse_attr(attr, ctx);
1074 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1075 dwarf2_parse_attr(attr, ctx);
1078 symt_add_enum_element(module, parent, name, value);
1080 if (entry->have_child) {
1081 FIXME("Unsupported children\n");
1085 static struct symt_enum* dwarf2_parse_enumeration_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
1087 struct symt_enum* symt = NULL;
1088 const char* name = NULL;
1089 unsigned long size = 0;
1090 dwarf2_abbrev_entry_attr_t* attr = NULL;
1091 unsigned long next_sibling = 0;
1093 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1095 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1096 switch (attr->attribute) {
1098 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1101 name = dwarf2_parse_attr_as_string(attr, ctx);
1102 TRACE("found name %s\n", name);
1104 case DW_AT_byte_size:
1105 size = dwarf2_parse_attr_as_data(attr, ctx);
1107 case DW_AT_decl_file:
1108 case DW_AT_decl_line:
1109 dwarf2_parse_attr(attr, ctx);
1112 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1113 dwarf2_parse_attr(attr, ctx);
1116 symt = symt_new_enum(module, name);
1118 if (entry->have_child) { /** any interest to not have child ? */
1119 while (ctx->data < ctx->end_data) {
1120 dwarf2_abbrev_entry_t* entry = NULL;
1121 unsigned long entry_code;
1122 unsigned long entry_ref = 0;
1124 entry_ref = ctx->data - ctx->data_stream;
1126 entry_code = dwarf2_leb128_as_unsigned(ctx);
1127 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1128 if (0 == entry_code) {
1132 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
1133 assert( NULL != entry );
1135 switch (entry->tag) {
1136 case DW_TAG_enumerator:
1137 dwarf2_parse_enumerator(module, entry, ctx, symt);
1141 dwarf2_abbrev_entry_attr_t* attr;
1142 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
1143 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1144 dwarf2_parse_attr(attr, ctx);
1152 /** set correct data cursor */
1153 dwarf2_check_sibling(ctx, next_sibling);
1158 static void dwarf2_parse_variable(struct module* module,
1159 dwarf2_abbrev_entry_t* entry,
1160 dwarf2_parse_context_t* ctx)
1162 struct symt* var_type = NULL;
1163 dwarf2_abbrev_entry_attr_t* attr = NULL;
1164 const char* name = NULL;
1165 unsigned long next_sibling = 0;
1167 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1169 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1170 switch (attr->attribute) {
1172 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1176 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
1177 var_type = dwarf2_find_symt_by_ref(module, ref);
1181 name = dwarf2_parse_attr_as_string(attr, ctx);
1182 TRACE("found name %s\n", name);
1184 case DW_AT_decl_file:
1185 case DW_AT_decl_line:
1186 dwarf2_parse_attr(attr, ctx);
1189 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1190 dwarf2_parse_attr(attr, ctx);
1194 if (entry->have_child) {
1195 FIXME("Unsupported children\n");
1198 /** set correct data cursor */
1199 dwarf2_check_sibling(ctx, next_sibling);
1202 static void dwarf2_parse_subprogram_parameter(struct module* module,
1203 dwarf2_abbrev_entry_t* entry,
1204 dwarf2_parse_context_t* ctx,
1205 struct symt_function_signature* sig_type,
1206 struct symt_function* func_type)
1208 struct symt* param_type = NULL;
1209 const char* name = NULL;
1210 dwarf2_abbrev_entry_attr_t* attr = NULL;
1211 unsigned long next_sibling = 0;
1213 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1215 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1216 switch (attr->attribute) {
1218 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1222 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
1223 param_type = dwarf2_find_symt_by_ref(module, ref);
1227 name = dwarf2_parse_attr_as_string(attr, ctx);
1228 TRACE("found name %s\n", name);
1230 case DW_AT_decl_file:
1231 case DW_AT_decl_line:
1232 dwarf2_parse_attr(attr, ctx);
1234 case DW_AT_location:
1235 dwarf2_parse_attr(attr, ctx);
1238 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1239 dwarf2_parse_attr(attr, ctx);
1242 if (NULL != sig_type) {
1243 symt_add_function_signature_parameter(module, sig_type, param_type);
1246 if (entry->have_child) {
1247 FIXME("Unsupported children\n");
1250 /** set correct data cursor */
1251 dwarf2_check_sibling(ctx, next_sibling);
1254 static void dwarf2_parse_inlined_subroutine(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
1256 const char* name = NULL;
1257 unsigned long addr = 0;
1258 unsigned long low_pc = 0;
1259 unsigned long high_pc = 0;
1261 dwarf2_abbrev_entry_attr_t* attr = NULL;
1262 unsigned long next_sibling = 0;
1264 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1266 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1267 switch (attr->attribute) {
1269 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1272 low_pc = dwarf2_parse_attr_as_addr(attr, ctx);
1273 addr = module->module.BaseOfImage + low_pc;
1276 high_pc = dwarf2_parse_attr_as_addr(attr, ctx);
1277 size = high_pc - low_pc;
1280 name = dwarf2_parse_attr_as_string(attr, ctx);
1281 TRACE("found name %s\n", name);
1283 case DW_AT_decl_file:
1284 case DW_AT_decl_line:
1285 dwarf2_parse_attr(attr, ctx);
1288 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1289 dwarf2_parse_attr(attr, ctx);
1293 if (entry->have_child) { /** any interest to not have child ? */
1294 while (ctx->data < ctx->end_data) {
1295 dwarf2_abbrev_entry_t* entry = NULL;
1296 unsigned long entry_code;
1297 unsigned long entry_ref = 0;
1299 entry_ref = ctx->data - ctx->data_stream;
1301 entry_code = dwarf2_leb128_as_unsigned(ctx);
1302 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1303 if (0 == entry_code) {
1307 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
1308 assert( NULL != entry );
1310 switch (entry->tag) {
1311 case DW_TAG_formal_parameter:
1312 dwarf2_parse_subprogram_parameter(module, entry, ctx, NULL, NULL);
1314 case DW_TAG_variable:
1315 dwarf2_parse_variable(module, entry, ctx);
1320 dwarf2_abbrev_entry_attr_t* attr;
1321 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
1322 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1323 dwarf2_parse_attr(attr, ctx);
1331 /** set correct data cursor */
1332 dwarf2_check_sibling(ctx, next_sibling);
1336 static void dwarf2_parse_subprogram_block(struct module* module,
1337 dwarf2_abbrev_entry_t* entry,
1338 dwarf2_parse_context_t* ctx,
1339 struct symt_function_signature* sig_type,
1340 struct symt_function* func_type)
1342 dwarf2_abbrev_entry_attr_t* attr = NULL;
1343 const char* name = NULL;
1344 unsigned long next_sibling = 0;
1346 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1348 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1349 switch (attr->attribute) {
1351 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1354 name = dwarf2_parse_attr_as_string(attr, ctx);
1355 TRACE("found name %s\n", name);
1357 case DW_AT_decl_file:
1358 case DW_AT_decl_line:
1359 dwarf2_parse_attr(attr, ctx);
1361 case DW_AT_ranges: /** what to do ? */
1362 dwarf2_parse_attr(attr, ctx);
1365 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1366 dwarf2_parse_attr(attr, ctx);
1370 if (entry->have_child) { /** any interest to not have child ? */
1371 while (ctx->data < ctx->end_data) {
1372 dwarf2_abbrev_entry_t* entry = NULL;
1373 unsigned long entry_code;
1374 unsigned long entry_ref = 0;
1376 entry_ref = ctx->data - ctx->data_stream;
1378 entry_code = dwarf2_leb128_as_unsigned(ctx);
1379 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1380 if (0 == entry_code) {
1384 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
1385 assert( NULL != entry );
1387 switch (entry->tag) {
1388 case DW_TAG_inlined_subroutine:
1389 dwarf2_parse_inlined_subroutine(module, entry, ctx);
1391 case DW_TAG_variable:
1392 dwarf2_parse_variable(module, entry, ctx);
1397 dwarf2_abbrev_entry_attr_t* attr;
1398 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
1399 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1400 dwarf2_parse_attr(attr, ctx);
1408 /** set correct data cursor */
1409 dwarf2_check_sibling(ctx, next_sibling);
1412 static void dwarf2_parse_subprogram_content(struct module* module,
1413 dwarf2_abbrev_entry_t* entry,
1414 dwarf2_parse_context_t* ctx,
1415 struct symt_function_signature* sig_type,
1416 struct symt_function* func_type)
1418 if (entry->have_child) { /** any interest to not have child ? */
1419 while (ctx->data < ctx->end_data) {
1420 dwarf2_abbrev_entry_t* entry = NULL;
1421 unsigned long entry_code;
1422 unsigned long entry_ref = 0;
1424 entry_ref = ctx->data - ctx->data_stream;
1426 entry_code = dwarf2_leb128_as_unsigned(ctx);
1427 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1428 if (0 == entry_code) {
1432 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
1433 assert( NULL != entry );
1435 switch (entry->tag) {
1436 case DW_TAG_formal_parameter:
1437 dwarf2_parse_subprogram_parameter(module, entry, ctx, sig_type, func_type);
1439 case DW_TAG_lexical_block:
1440 dwarf2_parse_subprogram_block(module, entry, ctx, sig_type, func_type);
1442 case DW_TAG_variable:
1443 dwarf2_parse_variable(module, entry, ctx);
1448 dwarf2_abbrev_entry_attr_t* attr;
1449 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
1450 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1451 dwarf2_parse_attr(attr, ctx);
1460 static struct symt_function* dwarf2_parse_subprogram(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
1462 struct symt_function* func_type = NULL;
1463 const char* name = NULL;
1464 struct symt* ret_type = NULL;
1465 struct symt_function_signature* sig_type = NULL;
1466 unsigned long addr = 0;
1467 unsigned long low_pc = 0;
1468 unsigned long high_pc = 0;
1470 unsigned char is_decl = 0;
1471 unsigned char inl_flags = 0;
1472 unsigned char decl_file = 0;
1473 unsigned char decl_line = 0;
1474 dwarf2_abbrev_entry_attr_t* attr = NULL;
1475 unsigned long next_sibling = 0;
1476 enum CV_call_e call_conv = CV_CALL_FAR_C; /* FIXME: assuming C source code */
1479 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
1481 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1482 switch (attr->attribute) {
1484 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1487 low_pc = dwarf2_parse_attr_as_addr(attr, ctx);
1488 addr = module->module.BaseOfImage + low_pc;
1491 high_pc = dwarf2_parse_attr_as_addr(attr, ctx);
1492 size = high_pc - low_pc;
1495 name = dwarf2_parse_attr_as_string(attr, ctx);
1496 TRACE("found name %s\n", name);
1500 unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
1501 ret_type = dwarf2_find_symt_by_ref(module, ref);
1504 case DW_AT_declaration:
1505 is_decl = dwarf2_parse_byte(ctx);
1508 inl_flags = dwarf2_parse_byte(ctx);
1510 case DW_AT_calling_convention:
1511 switch (cc = dwarf2_parse_byte(ctx))
1513 case DW_CC_normal: break;
1514 case DW_CC_nocall: call_conv = -1;
1515 default: FIXME("Unsupported calling convention %d\n", cc);
1518 /* not work yet, need parsing .debug_line and using Compil Unit stmt_list
1519 case DW_AT_decl_file:
1520 decl_file = dwarf2_parse_byte(ctx);
1522 case DW_AT_decl_line:
1523 decl_line = dwarf2_parse_byte(ctx);
1527 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1528 dwarf2_parse_attr(attr, ctx);
1531 sig_type = symt_new_function_signature(module, ret_type, call_conv);
1533 func_type = symt_new_function(module, compiland, name, addr, size, &sig_type->symt);
1534 if (low_pc && high_pc) {
1535 symt_add_function_point(module, func_type, SymTagFuncDebugStart, low_pc, NULL);
1536 symt_add_function_point(module, func_type, SymTagFuncDebugEnd, high_pc, NULL);
1538 if (decl_file && decl_line) {
1539 symt_add_func_line(module, func_type, decl_file, decl_line, low_pc);
1542 dwarf2_parse_subprogram_content(module, entry, ctx, sig_type, func_type);
1543 symt_normalize_function(module, func_type);
1545 /** set correct data cursor */
1546 dwarf2_check_sibling(ctx, next_sibling);
1551 static void dwarf2_parse_compiland_content(struct module* module, const dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
1553 if (entry->have_child) { /** any interest to not have child ? */
1554 while (ctx->data < ctx->end_data) {
1555 dwarf2_abbrev_entry_t* entry = NULL;
1556 unsigned long entry_code;
1557 unsigned long entry_ref = 0;
1559 entry_ref = ctx->data - ctx->data_stream;
1561 entry_code = dwarf2_leb128_as_unsigned(ctx);
1562 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1563 if (0 == entry_code) {
1567 entry = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
1568 assert( NULL != entry );
1570 switch (entry->tag) {
1571 case DW_TAG_typedef:
1573 struct symt_typedef* symt = dwarf2_parse_typedef(module, entry, ctx);
1574 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1577 case DW_TAG_base_type:
1579 struct symt_basic* symt = dwarf2_parse_base_type(module, entry, ctx);
1580 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1583 case DW_TAG_pointer_type:
1585 struct symt_pointer* symt = dwarf2_parse_pointer_type(module, entry, ctx);
1586 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1589 case DW_TAG_class_type:
1591 struct symt_udt* symt = dwarf2_parse_class_type(module, entry, ctx);
1592 if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1595 case DW_TAG_structure_type:
1597 struct symt_udt* symt = dwarf2_parse_struct_type(module, entry, ctx);
1598 if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1601 case DW_TAG_union_type:
1603 struct symt_udt* symt = dwarf2_parse_union_type(module, entry, ctx);
1604 if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1607 case DW_TAG_array_type:
1609 struct symt_array* symt = dwarf2_parse_array_type(module, entry, ctx);
1610 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1613 case DW_TAG_const_type:
1615 struct symt* symt = dwarf2_parse_const_type(module, entry, ctx);
1616 dwarf2_add_symt_ref(module, entry_ref, symt);
1619 case DW_TAG_reference_type:
1621 struct symt* symt = dwarf2_parse_reference_type(module, entry, ctx);
1622 dwarf2_add_symt_ref(module, entry_ref, symt);
1625 case DW_TAG_enumeration_type:
1627 struct symt_enum* symt = dwarf2_parse_enumeration_type(module, entry, ctx);
1628 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1631 case DW_TAG_subprogram:
1633 struct symt_function* symt = dwarf2_parse_subprogram(module, entry, ctx, compiland);
1634 if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1640 dwarf2_abbrev_entry_attr_t* attr;
1641 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
1642 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1643 dwarf2_parse_attr(attr, ctx);
1652 static struct symt_compiland* dwarf2_parse_compiland(struct module* module, const dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
1654 struct symt_compiland* compiland = NULL;
1655 const char* name = NULL;
1656 unsigned long next_sibling = 0;
1657 dwarf2_abbrev_entry_attr_t* attr = NULL;
1659 TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
1661 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1662 switch (attr->attribute) {
1664 next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
1667 name = dwarf2_parse_attr_as_string(attr, ctx);
1668 TRACE("found name %s\n", name);
1671 WARN("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
1672 dwarf2_parse_attr(attr, ctx);
1675 compiland = symt_new_compiland(module, name);
1676 dwarf2_parse_compiland_content(module, entry, ctx, compiland);
1678 dwarf2_check_sibling(ctx, next_sibling);
1683 BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
1684 const unsigned char* debug, unsigned int debug_size,
1685 const unsigned char* abbrev, unsigned int abbrev_size,
1686 const unsigned char* str, unsigned int str_sz)
1688 const unsigned char* comp_unit_cursor = debug;
1689 const unsigned char* end_debug = debug + debug_size;
1691 while (comp_unit_cursor < end_debug) {
1692 const dwarf2_comp_unit_stream_t* comp_unit_stream;
1693 dwarf2_comp_unit_t comp_unit;
1694 dwarf2_parse_context_t ctx;
1695 dwarf2_parse_context_t abbrev_ctx;
1696 struct symt_compiland* compiland = NULL;
1698 comp_unit_stream = (const dwarf2_comp_unit_stream_t*) comp_unit_cursor;
1700 comp_unit.length = *(unsigned long*) comp_unit_stream->length;
1701 comp_unit.version = *(unsigned short*) comp_unit_stream->version;
1702 comp_unit.abbrev_offset = *(unsigned long*) comp_unit_stream->abbrev_offset;
1703 comp_unit.word_size = *(unsigned char*) comp_unit_stream->word_size;
1705 TRACE("Compilation Unit Herder found at 0x%x:\n", comp_unit_cursor - debug);
1706 TRACE("- length: %lu\n", comp_unit.length);
1707 TRACE("- version: %u\n", comp_unit.version);
1708 TRACE("- abbrev_offset: %lu\n", comp_unit.abbrev_offset);
1709 TRACE("- word_size: %u\n", comp_unit.word_size);
1711 pool_init(&ctx.pool, 65536);
1712 ctx.data_stream = debug;
1713 ctx.data = ctx.start_data = comp_unit_cursor + sizeof(dwarf2_comp_unit_stream_t);
1714 ctx.offset = comp_unit_cursor - debug;
1715 ctx.word_size = comp_unit.word_size;
1716 ctx.str_section = str;
1718 comp_unit_cursor += comp_unit.length + sizeof(unsigned);
1719 ctx.end_data = comp_unit_cursor;
1721 if (2 != comp_unit.version) {
1722 WARN("%u DWARF version unsupported. Wine dbghelp only support DWARF 2.\n", comp_unit.version);
1726 abbrev_ctx.data_stream = abbrev;
1727 abbrev_ctx.data = abbrev_ctx.start_data = abbrev + comp_unit.abbrev_offset;
1728 abbrev_ctx.end_data = abbrev + abbrev_size;
1729 abbrev_ctx.offset = comp_unit.abbrev_offset;
1730 abbrev_ctx.str_section = str;
1731 dwarf2_parse_abbrev_set(&abbrev_ctx, &ctx.abbrev_table, &ctx.pool);
1733 while (ctx.data < ctx.end_data) {
1734 const dwarf2_abbrev_entry_t* entry = NULL;
1735 unsigned long entry_code;
1736 unsigned long entry_ref = 0;
1738 entry_ref = ctx.data - ctx.data_stream;
1740 entry_code = dwarf2_leb128_as_unsigned(&ctx);
1741 TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
1742 if (0 == entry_code) {
1745 entry = dwarf2_abbrev_table_find_entry(&ctx.abbrev_table, entry_code);
1746 if (NULL == entry) {
1747 WARN("Cannot find abbrev entry for %lu at 0x%lx\n", entry_code, entry_ref);
1748 pool_destroy(&ctx.pool);
1752 switch (entry->tag) {
1753 case DW_TAG_compile_unit:
1755 struct symt_compiland* symt = dwarf2_parse_compiland(module, entry, &ctx);
1756 dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
1762 dwarf2_abbrev_entry_attr_t* attr;
1763 WARN("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(&ctx), entry->entry_code);
1764 for (attr = entry->attrs; NULL != attr; attr = attr->next) {
1765 dwarf2_parse_attr(attr, &ctx);
1771 pool_destroy(&ctx.pool);
1774 module->module.SymType = SymDia;