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
);
58 * o unspecified parameters
60 * o Debug{Start|End}Point
63 * o proper types loading (nesting)
67 static void dump(const void* ptr
, unsigned len
)
71 static const char hexof
[] = "0123456789abcdef";
72 const BYTE
* x
= (const BYTE
*)ptr
;
74 for (i
= 0; i
< len
; i
+= 16)
76 sprintf(msg
, "%08x: ", i
);
77 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
78 for (j
= 0; j
< min(16, len
- i
); j
++)
80 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
81 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
82 msg
[10 + 3 * j
+ 2] = ' ';
83 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
86 msg
[10 + 3 * 16] = ' ';
87 msg
[10 + 3 * 16 + 1 + 16] = '\0';
96 * http://www.eagercon.com/dwarf/dwarf3std.htm
97 * http://www.eagercon.com/dwarf/dwarf-2.0.0.pdf
99 * dwarf2.h: http://www.hakpetzna.com/b/binutils/dwarf2_8h-source.html
101 * example of projects who do dwarf2 parsing:
102 * http://www.x86-64.org/cgi-bin/cvsweb.cgi/binutils.dead/binutils/readelf.c?rev=1.1.1.2
103 * http://elis.ugent.be/diota/log/ltrace_elf.c
111 typedef struct dwarf2_abbrev_entry_attr_s
113 unsigned long attribute
;
115 struct dwarf2_abbrev_entry_attr_s
* next
;
116 } dwarf2_abbrev_entry_attr_t
;
118 typedef struct dwarf2_abbrev_entry_s
120 unsigned long entry_code
;
122 unsigned char have_child
;
124 dwarf2_abbrev_entry_attr_t
* attrs
;
125 } dwarf2_abbrev_entry_t
;
130 const unsigned char* ptr
;
138 unsigned long uvalue
;
141 struct dwarf2_block block
;
145 typedef struct dwarf2_debug_info_s
147 const dwarf2_abbrev_entry_t
*abbrev
;
149 const unsigned char** data
;
150 struct vector children
;
151 } dwarf2_debug_info_t
;
153 typedef struct dwarf2_section_s
155 const unsigned char* address
;
159 enum dwarf2_sections
{section_debug
, section_string
, section_abbrev
, section_line
, section_max
};
161 typedef struct dwarf2_traverse_context_s
163 const unsigned char* data
;
164 const unsigned char* start_data
;
165 const unsigned char* end_data
;
166 unsigned char word_size
;
167 } dwarf2_traverse_context_t
;
169 typedef struct dwarf2_parse_context_s
171 const dwarf2_section_t
* sections
;
174 struct module
* module
;
175 const struct elf_thunk_area
*thunks
;
176 struct sparse_array abbrev_table
;
177 struct sparse_array debug_info_table
;
178 unsigned long ref_offset
;
179 unsigned char word_size
;
180 } dwarf2_parse_context_t
;
182 /* stored in the dbghelp's module internal structure for later reuse */
183 struct dwarf2_module_info_s
185 dwarf2_section_t debug_loc
;
188 #define loc_dwarf2_location_list (loc_user + 0)
189 #define loc_dwarf2_block (loc_user + 1)
191 /* forward declarations */
192 static struct symt
* dwarf2_parse_enumeration_type(dwarf2_parse_context_t
* ctx
, dwarf2_debug_info_t
* entry
);
194 static unsigned char dwarf2_get_byte(const unsigned char* ptr
)
199 static unsigned char dwarf2_parse_byte(dwarf2_traverse_context_t
* ctx
)
201 unsigned char uvalue
= dwarf2_get_byte(ctx
->data
);
206 static unsigned short dwarf2_get_u2(const unsigned char* ptr
)
208 return *(const unsigned short*)ptr
;
211 static unsigned short dwarf2_parse_u2(dwarf2_traverse_context_t
* ctx
)
213 unsigned short uvalue
= dwarf2_get_u2(ctx
->data
);
218 static unsigned long dwarf2_get_u4(const unsigned char* ptr
)
220 return *(const unsigned long*)ptr
;
223 static unsigned long dwarf2_parse_u4(dwarf2_traverse_context_t
* ctx
)
225 unsigned long uvalue
= dwarf2_get_u4(ctx
->data
);
230 static unsigned long dwarf2_get_leb128_as_unsigned(const unsigned char* ptr
, const unsigned char** end
)
232 unsigned long ret
= 0;
238 byte
= dwarf2_get_byte(ptr
++);
239 ret
|= (byte
& 0x7f) << shift
;
241 } while (byte
& 0x80);
247 static unsigned long dwarf2_leb128_as_unsigned(dwarf2_traverse_context_t
* ctx
)
253 ret
= dwarf2_get_leb128_as_unsigned(ctx
->data
, &ctx
->data
);
258 static long dwarf2_get_leb128_as_signed(const unsigned char* ptr
, const unsigned char** end
)
263 const unsigned size
= sizeof(int) * 8;
267 byte
= dwarf2_get_byte(ptr
++);
268 ret
|= (byte
& 0x7f) << shift
;
270 } while (byte
& 0x80);
273 /* as spec: sign bit of byte is 2nd high order bit (80x40)
274 * -> 0x80 is used as flag.
276 if ((shift
< size
) && (byte
& 0x40))
278 ret
|= - (1 << shift
);
283 static long dwarf2_leb128_as_signed(dwarf2_traverse_context_t
* ctx
)
289 ret
= dwarf2_get_leb128_as_signed(ctx
->data
, &ctx
->data
);
293 static unsigned dwarf2_leb128_length(const dwarf2_traverse_context_t
* ctx
)
296 for (ret
= 0; ctx
->data
[ret
] & 0x80; ret
++);
300 static unsigned long dwarf2_get_addr(const unsigned char* ptr
, unsigned word_size
)
307 ret
= dwarf2_get_u4(ptr
);
310 FIXME("Unsupported Word Size %u\n", word_size
);
316 static unsigned long dwarf2_parse_addr(dwarf2_traverse_context_t
* ctx
)
318 unsigned long ret
= dwarf2_get_addr(ctx
->data
, ctx
->word_size
);
319 ctx
->data
+= ctx
->word_size
;
323 static const char* dwarf2_debug_traverse_ctx(const dwarf2_traverse_context_t
* ctx
)
325 return wine_dbg_sprintf("ctx(%p)", ctx
->data
);
328 static const char* dwarf2_debug_ctx(const dwarf2_parse_context_t
* ctx
)
330 return wine_dbg_sprintf("ctx(%p,%s)", ctx
, ctx
->module
->module
.ModuleName
);
333 static const char* dwarf2_debug_di(const dwarf2_debug_info_t
* di
)
335 return wine_dbg_sprintf("debug_info(abbrev:%p,symt:%p)",
336 di
->abbrev
, di
->symt
);
339 static dwarf2_abbrev_entry_t
*
340 dwarf2_abbrev_table_find_entry(struct sparse_array
* abbrev_table
,
341 unsigned long entry_code
)
343 assert( NULL
!= abbrev_table
);
344 return sparse_array_find(abbrev_table
, entry_code
);
347 static void dwarf2_parse_abbrev_set(dwarf2_traverse_context_t
* abbrev_ctx
,
348 struct sparse_array
* abbrev_table
,
351 unsigned long entry_code
;
352 dwarf2_abbrev_entry_t
* abbrev_entry
;
353 dwarf2_abbrev_entry_attr_t
* new = NULL
;
354 dwarf2_abbrev_entry_attr_t
* last
= NULL
;
355 unsigned long attribute
;
358 assert( NULL
!= abbrev_ctx
);
360 TRACE("%s, end at %p\n",
361 dwarf2_debug_traverse_ctx(abbrev_ctx
), abbrev_ctx
->end_data
);
363 sparse_array_init(abbrev_table
, sizeof(dwarf2_abbrev_entry_t
), 32);
364 while (abbrev_ctx
->data
< abbrev_ctx
->end_data
)
366 TRACE("now at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx
));
367 entry_code
= dwarf2_leb128_as_unsigned(abbrev_ctx
);
368 TRACE("found entry_code %lu\n", entry_code
);
371 TRACE("NULL entry code at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx
));
374 abbrev_entry
= sparse_array_add(abbrev_table
, entry_code
, pool
);
375 assert( NULL
!= abbrev_entry
);
377 abbrev_entry
->entry_code
= entry_code
;
378 abbrev_entry
->tag
= dwarf2_leb128_as_unsigned(abbrev_ctx
);
379 abbrev_entry
->have_child
= dwarf2_parse_byte(abbrev_ctx
);
380 abbrev_entry
->attrs
= NULL
;
381 abbrev_entry
->num_attr
= 0;
383 TRACE("table:(%p,#%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n",
384 abbrev_table
, sparse_array_length(abbrev_table
),
385 entry_code
, abbrev_entry
->tag
, abbrev_entry
->have_child
, abbrev_entry
);
390 attribute
= dwarf2_leb128_as_unsigned(abbrev_ctx
);
391 form
= dwarf2_leb128_as_unsigned(abbrev_ctx
);
392 if (!attribute
) break;
394 new = pool_alloc(pool
, sizeof(dwarf2_abbrev_entry_attr_t
));
397 new->attribute
= attribute
;
400 if (abbrev_entry
->attrs
) last
->next
= new;
401 else abbrev_entry
->attrs
= new;
403 abbrev_entry
->num_attr
++;
406 TRACE("found %u entries\n", sparse_array_length(abbrev_table
));
409 static void dwarf2_swallow_attribute(dwarf2_traverse_context_t
* ctx
,
410 const dwarf2_abbrev_entry_attr_t
* abbrev_attr
)
414 TRACE("(attr:0x%lx,form:0x%lx)\n", abbrev_attr
->attribute
, abbrev_attr
->form
);
416 switch (abbrev_attr
->form
)
418 case DW_FORM_ref_addr
:
419 case DW_FORM_addr
: step
= ctx
->word_size
; break;
422 case DW_FORM_ref1
: step
= 1; break;
424 case DW_FORM_ref2
: step
= 2; break;
427 case DW_FORM_strp
: step
= 4; break;
429 case DW_FORM_ref8
: step
= 8; break;
431 case DW_FORM_ref_udata
:
432 case DW_FORM_udata
: step
= dwarf2_leb128_length(ctx
); break;
433 case DW_FORM_string
: step
= strlen((const char*)ctx
->data
) + 1; break;
434 case DW_FORM_block
: step
= dwarf2_leb128_as_unsigned(ctx
); break;
435 case DW_FORM_block1
: step
= dwarf2_parse_byte(ctx
); break;
436 case DW_FORM_block2
: step
= dwarf2_parse_u2(ctx
); break;
437 case DW_FORM_block4
: step
= dwarf2_parse_u4(ctx
); break;
439 FIXME("Unhandled attribute form %lx\n", abbrev_attr
->form
);
445 static void dwarf2_fill_attr(const dwarf2_parse_context_t
* ctx
,
446 const dwarf2_abbrev_entry_attr_t
* abbrev_attr
,
447 const unsigned char* data
,
448 struct attribute
* attr
)
450 attr
->form
= abbrev_attr
->form
;
453 case DW_FORM_ref_addr
:
455 attr
->u
.uvalue
= dwarf2_get_addr(data
, ctx
->word_size
);
456 TRACE("addr<0x%lx>\n", attr
->u
.uvalue
);
460 attr
->u
.uvalue
= dwarf2_get_byte(data
);
461 TRACE("flag<0x%lx>\n", attr
->u
.uvalue
);
465 attr
->u
.uvalue
= dwarf2_get_byte(data
);
466 TRACE("data1<%lu>\n", attr
->u
.uvalue
);
470 attr
->u
.uvalue
= dwarf2_get_u2(data
);
471 TRACE("data2<%lu>\n", attr
->u
.uvalue
);
475 attr
->u
.uvalue
= dwarf2_get_u4(data
);
476 TRACE("data4<%lu>\n", attr
->u
.uvalue
);
480 FIXME("Unhandled 64bits support\n");
484 attr
->u
.uvalue
= ctx
->ref_offset
+ dwarf2_get_byte(data
);
485 TRACE("ref1<0x%lx>\n", attr
->u
.uvalue
);
489 attr
->u
.uvalue
= ctx
->ref_offset
+ dwarf2_get_u2(data
);
490 TRACE("ref2<0x%lx>\n", attr
->u
.uvalue
);
494 attr
->u
.uvalue
= ctx
->ref_offset
+ dwarf2_get_u4(data
);
495 TRACE("ref4<0x%lx>\n", attr
->u
.uvalue
);
499 FIXME("Unhandled 64 bit support\n");
503 attr
->u
.svalue
= dwarf2_get_leb128_as_signed(data
, NULL
);
506 case DW_FORM_ref_udata
:
507 attr
->u
.uvalue
= dwarf2_get_leb128_as_unsigned(data
, NULL
);
511 attr
->u
.uvalue
= dwarf2_get_leb128_as_unsigned(data
, NULL
);
515 attr
->u
.string
= (const char *)data
;
516 TRACE("string<%s>\n", attr
->u
.string
);
521 unsigned long offset
= dwarf2_get_u4(data
);
522 attr
->u
.string
= (const char*)ctx
->sections
[section_string
].address
+ offset
;
524 TRACE("strp<%s>\n", attr
->u
.string
);
528 attr
->u
.block
.size
= dwarf2_get_leb128_as_unsigned(data
, &attr
->u
.block
.ptr
);
532 attr
->u
.block
.size
= dwarf2_get_byte(data
);
533 attr
->u
.block
.ptr
= data
+ 1;
537 attr
->u
.block
.size
= dwarf2_get_u2(data
);
538 attr
->u
.block
.ptr
= data
+ 2;
542 attr
->u
.block
.size
= dwarf2_get_u4(data
);
543 attr
->u
.block
.ptr
= data
+ 4;
547 FIXME("Unhandled attribute form %lx\n", abbrev_attr
->form
);
552 static BOOL
dwarf2_find_attribute(const dwarf2_parse_context_t
* ctx
,
553 const dwarf2_debug_info_t
* di
,
554 unsigned at
, struct attribute
* attr
)
557 dwarf2_abbrev_entry_attr_t
* abbrev_attr
;
558 dwarf2_abbrev_entry_attr_t
* abstract_abbrev_attr
;
562 abstract_abbrev_attr
= NULL
;
563 for (i
= 0, abbrev_attr
= di
->abbrev
->attrs
; abbrev_attr
; i
++, abbrev_attr
= abbrev_attr
->next
)
565 if (abbrev_attr
->attribute
== at
)
567 dwarf2_fill_attr(ctx
, abbrev_attr
, di
->data
[i
], attr
);
570 if (abbrev_attr
->attribute
== DW_AT_abstract_origin
&&
573 abstract_abbrev_attr
= abbrev_attr
;
577 /* do we have an abstract origin debug entry to look into ? */
578 if (!abstract_abbrev_attr
) break;
579 dwarf2_fill_attr(ctx
, abstract_abbrev_attr
, di
->data
[ai
], attr
);
580 if (!(di
= sparse_array_find(&ctx
->debug_info_table
, attr
->u
.uvalue
)))
581 FIXME("Should have found the debug info entry\n");
586 static void dwarf2_load_one_entry(dwarf2_parse_context_t
*, dwarf2_debug_info_t
*,
587 struct symt_compiland
*);
589 #define Wine_DW_no_register 0x7FFFFFFF
591 static unsigned dwarf2_map_register(int regno
)
597 case Wine_DW_no_register
: FIXME("What the heck map reg 0x%x\n",regno
); reg
= 0; break;
598 case 0: reg
= CV_REG_EAX
; break;
599 case 1: reg
= CV_REG_ECX
; break;
600 case 2: reg
= CV_REG_EDX
; break;
601 case 3: reg
= CV_REG_EBX
; break;
602 case 4: reg
= CV_REG_ESP
; break;
603 case 5: reg
= CV_REG_EBP
; break;
604 case 6: reg
= CV_REG_ESI
; break;
605 case 7: reg
= CV_REG_EDI
; break;
606 case 8: reg
= CV_REG_EIP
; break;
607 case 9: reg
= CV_REG_EFLAGS
; break;
608 case 10: reg
= CV_REG_CS
; break;
609 case 11: reg
= CV_REG_SS
; break;
610 case 12: reg
= CV_REG_DS
; break;
611 case 13: reg
= CV_REG_ES
; break;
612 case 14: reg
= CV_REG_FS
; break;
613 case 15: reg
= CV_REG_GS
; break;
614 case 16: case 17: case 18: case 19:
615 case 20: case 21: case 22: case 23:
616 reg
= CV_REG_ST0
+ regno
- 16; break;
617 case 24: reg
= CV_REG_CTRL
; break;
618 case 25: reg
= CV_REG_STAT
; break;
619 case 26: reg
= CV_REG_TAG
; break;
627 case 32: case 33: case 34: case 35:
628 case 36: case 37: case 38: case 39:
629 reg
= CV_REG_XMM0
+ regno
- 32; break;
630 case 40: reg
= CV_REG_MXCSR
; break;
632 FIXME("Don't know how to map register %d\n", regno
);
638 static enum location_error
639 compute_location(dwarf2_traverse_context_t
* ctx
, struct location
* loc
,
640 HANDLE hproc
, const struct location
* frame
)
642 unsigned long stack
[64];
645 BOOL piece_found
= FALSE
;
649 loc
->kind
= loc_absolute
;
650 loc
->reg
= Wine_DW_no_register
;
652 while (ctx
->data
< ctx
->end_data
)
654 op
= dwarf2_parse_byte(ctx
);
657 case DW_OP_addr
: stack
[++stk
] = dwarf2_parse_addr(ctx
); break;
658 case DW_OP_const1u
: stack
[++stk
] = dwarf2_parse_byte(ctx
); break;
659 case DW_OP_const1s
: stack
[++stk
] = (long)(signed char)dwarf2_parse_byte(ctx
); break;
660 case DW_OP_const2u
: stack
[++stk
] = dwarf2_parse_u2(ctx
); break;
661 case DW_OP_const2s
: stack
[++stk
] = (long)(short)dwarf2_parse_u2(ctx
); break;
662 case DW_OP_const4u
: stack
[++stk
] = dwarf2_parse_u4(ctx
); break;
663 case DW_OP_const4s
: stack
[++stk
] = dwarf2_parse_u4(ctx
); break;
664 case DW_OP_constu
: stack
[++stk
] = dwarf2_leb128_as_unsigned(ctx
); break;
665 case DW_OP_consts
: stack
[++stk
] = dwarf2_leb128_as_signed(ctx
); break;
666 case DW_OP_plus_uconst
:
667 stack
[stk
] += dwarf2_leb128_as_unsigned(ctx
); break;
668 case DW_OP_reg0
: case DW_OP_reg1
: case DW_OP_reg2
: case DW_OP_reg3
:
669 case DW_OP_reg4
: case DW_OP_reg5
: case DW_OP_reg6
: case DW_OP_reg7
:
670 case DW_OP_reg8
: case DW_OP_reg9
: case DW_OP_reg10
: case DW_OP_reg11
:
671 case DW_OP_reg12
: case DW_OP_reg13
: case DW_OP_reg14
: case DW_OP_reg15
:
672 case DW_OP_reg16
: case DW_OP_reg17
: case DW_OP_reg18
: case DW_OP_reg19
:
673 case DW_OP_reg20
: case DW_OP_reg21
: case DW_OP_reg22
: case DW_OP_reg23
:
674 case DW_OP_reg24
: case DW_OP_reg25
: case DW_OP_reg26
: case DW_OP_reg27
:
675 case DW_OP_reg28
: case DW_OP_reg29
: case DW_OP_reg30
: case DW_OP_reg31
:
676 case DW_OP_breg0
: case DW_OP_breg1
: case DW_OP_breg2
: case DW_OP_breg3
:
677 case DW_OP_breg4
: case DW_OP_breg5
: case DW_OP_breg6
: case DW_OP_breg7
:
678 case DW_OP_breg8
: case DW_OP_breg9
: case DW_OP_breg10
: case DW_OP_breg11
:
679 case DW_OP_breg12
: case DW_OP_breg13
: case DW_OP_breg14
: case DW_OP_breg15
:
680 case DW_OP_breg16
: case DW_OP_breg17
: case DW_OP_breg18
: case DW_OP_breg19
:
681 case DW_OP_breg20
: case DW_OP_breg21
: case DW_OP_breg22
: case DW_OP_breg23
:
682 case DW_OP_breg24
: case DW_OP_breg25
: case DW_OP_breg26
: case DW_OP_breg27
:
683 case DW_OP_breg28
: case DW_OP_breg29
: case DW_OP_breg30
: case DW_OP_breg31
:
684 /* dbghelp APIs don't know how to cope with this anyway
685 * (for example 'long long' stored in two registers)
686 * FIXME: We should tell winedbg how to deal with it (sigh)
690 if (loc
->reg
!= Wine_DW_no_register
)
691 FIXME("Only supporting one reg (%d -> %d)\n",
692 loc
->reg
, op
- DW_OP_reg0
);
693 loc
->reg
= dwarf2_map_register(op
- DW_OP_reg0
);
695 if (op
>= DW_OP_breg0
&& op
<= DW_OP_breg31
)
697 stack
[++stk
] = dwarf2_leb128_as_signed(ctx
);
698 loc
->kind
= loc_regrel
;
701 loc
->kind
= loc_register
;
704 if (loc
->reg
!= Wine_DW_no_register
)
705 FIXME("Only supporting one reg (%d -> -2)\n", loc
->reg
);
706 if (frame
&& frame
->kind
== loc_register
)
708 loc
->kind
= loc_regrel
;
709 loc
->reg
= frame
->reg
;
710 stack
[++stk
] = dwarf2_leb128_as_signed(ctx
);
712 else if (frame
&& frame
->kind
== loc_regrel
)
714 loc
->kind
= loc_regrel
;
715 loc
->reg
= frame
->reg
;
716 stack
[++stk
] = dwarf2_leb128_as_signed(ctx
) + frame
->offset
;
720 /* FIXME: this could be later optimized by not recomputing
721 * this very location expression
723 loc
->kind
= loc_dwarf2_block
;
724 stack
[++stk
] = dwarf2_leb128_as_signed(ctx
);
729 unsigned sz
= dwarf2_leb128_as_unsigned(ctx
);
730 WARN("Not handling OP_piece (size=%d)\n", sz
);
737 FIXME("Unexpected empty stack\n");
738 return loc_err_internal
;
740 if (loc
->reg
!= Wine_DW_no_register
)
742 WARN("Too complex expression for deref\n");
743 return loc_err_too_complex
;
747 DWORD addr
= stack
[stk
--];
750 if (!ReadProcessMemory(hproc
, (void*)addr
, &deref
, sizeof(deref
), NULL
))
752 WARN("Couldn't read memory at %lx\n", addr
);
753 return loc_err_cant_read
;
755 stack
[++stk
] = deref
;
759 loc
->kind
= loc_dwarf2_block
;
763 FIXME("Unhandled attr op: %x\n", op
);
764 return loc_err_internal
;
767 loc
->offset
= stack
[stk
];
771 static BOOL
dwarf2_compute_location_attr(dwarf2_parse_context_t
* ctx
,
772 dwarf2_debug_info_t
* di
,
774 struct location
* loc
,
775 const struct location
* frame
)
777 struct attribute xloc
;
779 if (!dwarf2_find_attribute(ctx
, di
, dw
, &xloc
)) return FALSE
;
783 case DW_FORM_data1
: case DW_FORM_data2
:
784 case DW_FORM_udata
: case DW_FORM_sdata
:
785 loc
->kind
= loc_absolute
;
787 loc
->offset
= xloc
.u
.uvalue
;
789 case DW_FORM_data4
: case DW_FORM_data8
:
790 loc
->kind
= loc_dwarf2_location_list
;
791 loc
->reg
= Wine_DW_no_register
;
792 loc
->offset
= xloc
.u
.uvalue
;
796 /* assume we have a block form */
798 if (xloc
.u
.block
.size
)
800 dwarf2_traverse_context_t lctx
;
801 enum location_error err
;
803 lctx
.data
= xloc
.u
.block
.ptr
;
804 lctx
.end_data
= xloc
.u
.block
.ptr
+ xloc
.u
.block
.size
;
805 lctx
.word_size
= ctx
->word_size
;
807 err
= compute_location(&lctx
, loc
, NULL
, frame
);
810 loc
->kind
= loc_error
;
813 else if (loc
->kind
== loc_dwarf2_block
)
815 unsigned* ptr
= pool_alloc(&ctx
->module
->pool
,
816 sizeof(unsigned) + xloc
.u
.block
.size
);
817 *ptr
= xloc
.u
.block
.size
;
818 memcpy(ptr
+ 1, xloc
.u
.block
.ptr
, xloc
.u
.block
.size
);
819 loc
->offset
= (unsigned long)ptr
;
825 static struct symt
* dwarf2_lookup_type(dwarf2_parse_context_t
* ctx
,
826 const dwarf2_debug_info_t
* di
)
828 struct attribute attr
;
830 if (dwarf2_find_attribute(ctx
, di
, DW_AT_type
, &attr
))
832 dwarf2_debug_info_t
* type
;
834 type
= sparse_array_find(&ctx
->debug_info_table
, attr
.u
.uvalue
);
835 if (!type
) FIXME("Unable to find back reference to type %lx\n", attr
.u
.uvalue
);
838 /* load the debug info entity */
839 dwarf2_load_one_entry(ctx
, type
, NULL
);
846 /******************************************************************
847 * dwarf2_read_one_debug_info
849 * Loads into memory one debug info entry, and recursively its children (if any)
851 static BOOL
dwarf2_read_one_debug_info(dwarf2_parse_context_t
* ctx
,
852 dwarf2_traverse_context_t
* traverse
,
853 dwarf2_debug_info_t
** pdi
)
855 const dwarf2_abbrev_entry_t
*abbrev
;
856 unsigned long entry_code
;
857 unsigned long offset
;
858 dwarf2_debug_info_t
* di
;
859 dwarf2_debug_info_t
* child
;
860 dwarf2_debug_info_t
** where
;
861 dwarf2_abbrev_entry_attr_t
* attr
;
863 struct attribute sibling
;
865 offset
= traverse
->data
- ctx
->sections
[ctx
->section
].address
;
866 entry_code
= dwarf2_leb128_as_unsigned(traverse
);
867 TRACE("found entry_code %lu at 0x%lx\n", entry_code
, offset
);
873 abbrev
= dwarf2_abbrev_table_find_entry(&ctx
->abbrev_table
, entry_code
);
876 WARN("Cannot find abbrev entry for %lu at 0x%lx\n", entry_code
, offset
);
879 di
= sparse_array_add(&ctx
->debug_info_table
, offset
, &ctx
->pool
);
880 if (!di
) return FALSE
;
884 if (abbrev
->num_attr
)
886 di
->data
= pool_alloc(&ctx
->pool
, abbrev
->num_attr
* sizeof(const char*));
887 for (i
= 0, attr
= abbrev
->attrs
; attr
; i
++, attr
= attr
->next
)
889 di
->data
[i
] = traverse
->data
;
890 dwarf2_swallow_attribute(traverse
, attr
);
893 else di
->data
= NULL
;
894 if (abbrev
->have_child
)
896 vector_init(&di
->children
, sizeof(dwarf2_debug_info_t
*), 16);
897 while (traverse
->data
< traverse
->end_data
)
899 if (!dwarf2_read_one_debug_info(ctx
, traverse
, &child
)) return FALSE
;
901 where
= vector_add(&di
->children
, &ctx
->pool
);
902 if (!where
) return FALSE
;
906 if (dwarf2_find_attribute(ctx
, di
, DW_AT_sibling
, &sibling
) &&
907 traverse
->data
!= ctx
->sections
[ctx
->section
].address
+ sibling
.u
.uvalue
)
909 WARN("setting cursor for %s to next sibling <0x%lx>\n",
910 dwarf2_debug_traverse_ctx(traverse
), sibling
.u
.uvalue
);
911 traverse
->data
= ctx
->sections
[ctx
->section
].address
+ sibling
.u
.uvalue
;
917 static struct symt
* dwarf2_parse_base_type(dwarf2_parse_context_t
* ctx
,
918 dwarf2_debug_info_t
* di
)
920 struct attribute name
;
921 struct attribute size
;
922 struct attribute encoding
;
925 if (di
->symt
) return di
->symt
;
927 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
929 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
))
930 name
.u
.string
= NULL
;
931 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_byte_size
, &size
)) size
.u
.uvalue
= 0;
932 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_encoding
, &encoding
)) encoding
.u
.uvalue
= DW_ATE_void
;
934 switch (encoding
.u
.uvalue
)
936 case DW_ATE_void
: bt
= btVoid
; break;
937 case DW_ATE_address
: bt
= btULong
; break;
938 case DW_ATE_boolean
: bt
= btBool
; break;
939 case DW_ATE_complex_float
: bt
= btComplex
; break;
940 case DW_ATE_float
: bt
= btFloat
; break;
941 case DW_ATE_signed
: bt
= btInt
; break;
942 case DW_ATE_unsigned
: bt
= btUInt
; break;
943 case DW_ATE_signed_char
: bt
= btChar
; break;
944 case DW_ATE_unsigned_char
: bt
= btChar
; break;
945 default: bt
= btNoType
; break;
947 di
->symt
= &symt_new_basic(ctx
->module
, bt
, name
.u
.string
, size
.u
.uvalue
)->symt
;
948 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
952 static struct symt
* dwarf2_parse_typedef(dwarf2_parse_context_t
* ctx
,
953 dwarf2_debug_info_t
* di
)
955 struct symt
* ref_type
;
956 struct attribute name
;
958 if (di
->symt
) return di
->symt
;
960 TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx
), di
->abbrev
->entry_code
);
962 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
963 ref_type
= dwarf2_lookup_type(ctx
, di
);
966 di
->symt
= &symt_new_typedef(ctx
->module
, ref_type
, name
.u
.string
)->symt
;
967 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
971 static struct symt
* dwarf2_parse_pointer_type(dwarf2_parse_context_t
* ctx
,
972 dwarf2_debug_info_t
* di
)
974 struct symt
* ref_type
;
975 struct attribute size
;
977 if (di
->symt
) return di
->symt
;
979 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
981 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_byte_size
, &size
)) size
.u
.uvalue
= 0;
982 if (!(ref_type
= dwarf2_lookup_type(ctx
, di
)))
983 ref_type
= &symt_new_basic(ctx
->module
, btVoid
, "void", 0)->symt
;
985 di
->symt
= &symt_new_pointer(ctx
->module
, ref_type
)->symt
;
986 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
990 static struct symt
* dwarf2_parse_array_type(dwarf2_parse_context_t
* ctx
,
991 dwarf2_debug_info_t
* di
)
993 struct symt
* ref_type
;
994 struct symt
* idx_type
= NULL
;
995 struct attribute min
, max
, cnt
;
996 dwarf2_debug_info_t
** pchild
= NULL
;
997 dwarf2_debug_info_t
* child
;
999 if (di
->symt
) return di
->symt
;
1001 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1003 if (!di
->abbrev
->have_child
)
1005 FIXME("array without range information\n");
1008 ref_type
= dwarf2_lookup_type(ctx
, di
);
1010 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1013 switch (child
->abbrev
->tag
)
1015 case DW_TAG_subrange_type
:
1016 idx_type
= dwarf2_lookup_type(ctx
, child
);
1017 if (!dwarf2_find_attribute(ctx
, child
, DW_AT_lower_bound
, &min
))
1019 if (!dwarf2_find_attribute(ctx
, child
, DW_AT_upper_bound
, &max
))
1021 if (dwarf2_find_attribute(ctx
, child
, DW_AT_count
, &cnt
))
1022 max
.u
.uvalue
= min
.u
.uvalue
+ cnt
.u
.uvalue
;
1025 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1026 child
->abbrev
->tag
, dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1030 di
->symt
= &symt_new_array(ctx
->module
, min
.u
.uvalue
, max
.u
.uvalue
, ref_type
, idx_type
)->symt
;
1034 static struct symt
* dwarf2_parse_const_type(dwarf2_parse_context_t
* ctx
,
1035 dwarf2_debug_info_t
* di
)
1037 struct symt
* ref_type
;
1039 if (di
->symt
) return di
->symt
;
1041 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1043 ref_type
= dwarf2_lookup_type(ctx
, di
);
1044 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1045 di
->symt
= ref_type
;
1050 static struct symt
* dwarf2_parse_volatile_type(dwarf2_parse_context_t
* ctx
,
1051 dwarf2_debug_info_t
* di
)
1053 struct symt
* ref_type
;
1055 if (di
->symt
) return di
->symt
;
1057 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1059 ref_type
= dwarf2_lookup_type(ctx
, di
);
1060 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1061 di
->symt
= ref_type
;
1066 static struct symt
* dwarf2_parse_reference_type(dwarf2_parse_context_t
* ctx
,
1067 dwarf2_debug_info_t
* di
)
1069 struct symt
* ref_type
= NULL
;
1071 if (di
->symt
) return di
->symt
;
1073 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1075 ref_type
= dwarf2_lookup_type(ctx
, di
);
1076 /* FIXME: for now, we hard-wire C++ references to pointers */
1077 di
->symt
= &symt_new_pointer(ctx
->module
, ref_type
)->symt
;
1079 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1084 static void dwarf2_parse_udt_member(dwarf2_parse_context_t
* ctx
,
1085 dwarf2_debug_info_t
* di
,
1086 struct symt_udt
* parent
)
1088 struct symt
* elt_type
;
1089 struct attribute name
;
1090 struct attribute bit_size
;
1091 struct attribute bit_offset
;
1092 struct location loc
;
1096 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1098 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
1099 elt_type
= dwarf2_lookup_type(ctx
, di
);
1100 if (dwarf2_compute_location_attr(ctx
, di
, DW_AT_data_member_location
, &loc
, NULL
))
1102 if (loc
.kind
!= loc_absolute
)
1104 FIXME("Found register, while not expecting it\n");
1108 TRACE("found member_location at %s -> %lu\n",
1109 dwarf2_debug_ctx(ctx
), loc
.offset
);
1113 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_bit_size
, &bit_size
))
1114 bit_size
.u
.uvalue
= 0;
1115 if (dwarf2_find_attribute(ctx
, di
, DW_AT_bit_offset
, &bit_offset
))
1117 /* FIXME: we should only do this when implementation is LSB (which is
1118 * the case on i386 processors)
1120 struct attribute nbytes
;
1121 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_byte_size
, &nbytes
))
1124 nbytes
.u
.uvalue
= symt_get_info(elt_type
, TI_GET_LENGTH
, &size
) ? (unsigned long)size
: 0;
1126 bit_offset
.u
.uvalue
= nbytes
.u
.uvalue
* 8 - bit_offset
.u
.uvalue
- bit_size
.u
.uvalue
;
1128 else bit_offset
.u
.uvalue
= 0;
1129 symt_add_udt_element(ctx
->module
, parent
, name
.u
.string
, elt_type
,
1130 (loc
.offset
<< 3) + bit_offset
.u
.uvalue
,
1133 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1136 static struct symt
* dwarf2_parse_udt_type(dwarf2_parse_context_t
* ctx
,
1137 dwarf2_debug_info_t
* di
,
1140 struct attribute name
;
1141 struct attribute size
;
1143 if (di
->symt
) return di
->symt
;
1145 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1147 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
1148 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_byte_size
, &size
)) size
.u
.uvalue
= 0;
1150 di
->symt
= &symt_new_udt(ctx
->module
, name
.u
.string
, size
.u
.uvalue
, udt
)->symt
;
1152 if (di
->abbrev
->have_child
) /** any interest to not have child ? */
1154 dwarf2_debug_info_t
** pchild
= NULL
;
1155 dwarf2_debug_info_t
* child
;
1157 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1161 switch (child
->abbrev
->tag
)
1164 /* FIXME: should I follow the sibling stuff ?? */
1165 dwarf2_parse_udt_member(ctx
, child
, (struct symt_udt
*)di
->symt
);
1167 case DW_TAG_enumeration_type
:
1168 dwarf2_parse_enumeration_type(ctx
, child
);
1170 case DW_TAG_structure_type
:
1171 case DW_TAG_class_type
:
1172 case DW_TAG_union_type
:
1173 /* FIXME: we need to handle nested udt definitions */
1176 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1177 child
->abbrev
->tag
, dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1186 static void dwarf2_parse_enumerator(dwarf2_parse_context_t
* ctx
,
1187 dwarf2_debug_info_t
* di
,
1188 struct symt_enum
* parent
)
1190 struct attribute name
;
1191 struct attribute value
;
1193 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1195 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
1196 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_const_value
, &value
)) value
.u
.svalue
= 0;
1197 symt_add_enum_element(ctx
->module
, parent
, name
.u
.string
, value
.u
.svalue
);
1199 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1202 static struct symt
* dwarf2_parse_enumeration_type(dwarf2_parse_context_t
* ctx
,
1203 dwarf2_debug_info_t
* di
)
1205 struct attribute name
;
1206 struct attribute size
;
1208 if (di
->symt
) return di
->symt
;
1210 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1212 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
1213 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_byte_size
, &size
)) size
.u
.uvalue
= 0;
1215 di
->symt
= &symt_new_enum(ctx
->module
, name
.u
.string
)->symt
;
1217 if (di
->abbrev
->have_child
) /* any interest to not have child ? */
1219 dwarf2_debug_info_t
** pchild
= NULL
;
1220 dwarf2_debug_info_t
* child
;
1222 /* FIXME: should we use the sibling stuff ?? */
1223 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1227 switch (child
->abbrev
->tag
)
1229 case DW_TAG_enumerator
:
1230 dwarf2_parse_enumerator(ctx
, child
, (struct symt_enum
*)di
->symt
);
1233 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1234 di
->abbrev
->tag
, dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1241 /* structure used to pass information around when parsing a subprogram */
1242 typedef struct dwarf2_subprogram_s
1244 dwarf2_parse_context_t
* ctx
;
1245 struct symt_compiland
* compiland
;
1246 struct symt_function
* func
;
1247 BOOL non_computed_variable
;
1248 struct location frame
;
1249 } dwarf2_subprogram_t
;
1251 /******************************************************************
1252 * dwarf2_parse_variable
1254 * Parses any variable (parameter, local/global variable)
1256 static void dwarf2_parse_variable(dwarf2_subprogram_t
* subpgm
,
1257 struct symt_block
* block
,
1258 dwarf2_debug_info_t
* di
)
1260 struct symt
* param_type
;
1261 struct attribute name
, value
;
1262 struct location loc
;
1265 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm
->ctx
), dwarf2_debug_di(di
));
1267 is_pmt
= !block
&& di
->abbrev
->tag
== DW_TAG_formal_parameter
;
1268 param_type
= dwarf2_lookup_type(subpgm
->ctx
, di
);
1270 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_name
, &name
))
1271 name
.u
.string
= NULL
;
1272 if (dwarf2_compute_location_attr(subpgm
->ctx
, di
, DW_AT_location
,
1273 &loc
, &subpgm
->frame
))
1275 struct attribute ext
;
1277 TRACE("found parameter %s (kind=%d, offset=%ld, reg=%d) at %s\n",
1278 name
.u
.string
, loc
.kind
, loc
.offset
, loc
.reg
,
1279 dwarf2_debug_ctx(subpgm
->ctx
));
1284 /* it's a global variable */
1285 /* FIXME: we don't handle its scope yet */
1286 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_external
, &ext
))
1288 symt_new_global_variable(subpgm
->ctx
->module
, subpgm
->compiland
,
1289 name
.u
.string
, !ext
.u
.uvalue
,
1290 subpgm
->ctx
->module
->module
.BaseOfImage
+ loc
.offset
,
1294 subpgm
->non_computed_variable
= TRUE
;
1298 /* either a pmt/variable relative to frame pointer or
1299 * pmt/variable in a register
1301 assert(subpgm
->func
);
1302 symt_add_func_local(subpgm
->ctx
->module
, subpgm
->func
,
1303 is_pmt
? DataIsParam
: DataIsLocal
,
1304 &loc
, block
, param_type
, name
.u
.string
);
1308 if (dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_const_value
, &value
))
1310 FIXME("NIY: const value %08lx for %s\n", value
.u
.uvalue
, name
.u
.string
);
1312 if (is_pmt
&& subpgm
->func
&& subpgm
->func
->type
)
1313 symt_add_function_signature_parameter(subpgm
->ctx
->module
,
1314 (struct symt_function_signature
*)subpgm
->func
->type
,
1317 if (di
->abbrev
->have_child
) FIXME("Unsupported children\n");
1320 static void dwarf2_parse_subprogram_label(dwarf2_subprogram_t
* subpgm
,
1321 dwarf2_debug_info_t
* di
)
1323 struct attribute name
;
1324 struct attribute low_pc
;
1325 struct location loc
;
1327 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm
->ctx
), dwarf2_debug_di(di
));
1329 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_low_pc
, &low_pc
)) low_pc
.u
.uvalue
= 0;
1330 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_name
, &name
))
1331 name
.u
.string
= NULL
;
1333 loc
.kind
= loc_absolute
;
1334 loc
.offset
= subpgm
->ctx
->module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
,
1335 symt_add_function_point(subpgm
->ctx
->module
, subpgm
->func
, SymTagLabel
,
1336 &loc
, name
.u
.string
);
1339 static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t
* subpgm
,
1340 struct symt_block
* parent_block
,
1341 dwarf2_debug_info_t
* di
);
1343 static void dwarf2_parse_inlined_subroutine(dwarf2_subprogram_t
* subpgm
,
1344 struct symt_block
* parent_block
,
1345 dwarf2_debug_info_t
* di
)
1347 struct symt_block
* block
;
1348 struct attribute low_pc
;
1349 struct attribute high_pc
;
1351 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm
->ctx
), dwarf2_debug_di(di
));
1353 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_low_pc
, &low_pc
)) low_pc
.u
.uvalue
= 0;
1354 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_high_pc
, &high_pc
)) high_pc
.u
.uvalue
= 0;
1356 block
= symt_open_func_block(subpgm
->ctx
->module
, subpgm
->func
, parent_block
,
1357 subpgm
->ctx
->module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
- subpgm
->func
->address
,
1358 high_pc
.u
.uvalue
- low_pc
.u
.uvalue
);
1360 if (di
->abbrev
->have_child
) /** any interest to not have child ? */
1362 dwarf2_debug_info_t
** pchild
= NULL
;
1363 dwarf2_debug_info_t
* child
;
1365 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1369 switch (child
->abbrev
->tag
)
1371 case DW_TAG_formal_parameter
:
1372 case DW_TAG_variable
:
1373 dwarf2_parse_variable(subpgm
, block
, child
);
1375 case DW_TAG_lexical_block
:
1376 dwarf2_parse_subprogram_block(subpgm
, block
, child
);
1378 case DW_TAG_inlined_subroutine
:
1379 dwarf2_parse_inlined_subroutine(subpgm
, block
, child
);
1382 dwarf2_parse_subprogram_label(subpgm
, child
);
1385 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1386 child
->abbrev
->tag
, dwarf2_debug_ctx(subpgm
->ctx
),
1387 dwarf2_debug_di(di
));
1391 symt_close_func_block(subpgm
->ctx
->module
, subpgm
->func
, block
, 0);
1394 static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t
* subpgm
,
1395 struct symt_block
* parent_block
,
1396 dwarf2_debug_info_t
* di
)
1398 struct symt_block
* block
;
1399 struct attribute low_pc
;
1400 struct attribute high_pc
;
1402 TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm
->ctx
), dwarf2_debug_di(di
));
1404 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_low_pc
, &low_pc
))
1405 low_pc
.u
.uvalue
= 0;
1406 if (!dwarf2_find_attribute(subpgm
->ctx
, di
, DW_AT_high_pc
, &high_pc
))
1407 high_pc
.u
.uvalue
= 0;
1409 block
= symt_open_func_block(subpgm
->ctx
->module
, subpgm
->func
, parent_block
,
1410 subpgm
->ctx
->module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
- subpgm
->func
->address
,
1411 high_pc
.u
.uvalue
- low_pc
.u
.uvalue
);
1413 if (di
->abbrev
->have_child
) /** any interest to not have child ? */
1415 dwarf2_debug_info_t
** pchild
= NULL
;
1416 dwarf2_debug_info_t
* child
;
1418 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1422 switch (child
->abbrev
->tag
)
1424 case DW_TAG_inlined_subroutine
:
1425 dwarf2_parse_inlined_subroutine(subpgm
, block
, child
);
1427 case DW_TAG_variable
:
1428 dwarf2_parse_variable(subpgm
, block
, child
);
1430 case DW_TAG_lexical_block
:
1431 dwarf2_parse_subprogram_block(subpgm
, block
, child
);
1433 case DW_TAG_subprogram
:
1434 /* FIXME: likely a declaration (to be checked)
1438 case DW_TAG_formal_parameter
:
1439 /* FIXME: likely elements for exception handling (GCC flavor)
1444 dwarf2_parse_subprogram_label(subpgm
, child
);
1446 case DW_TAG_class_type
:
1447 case DW_TAG_structure_type
:
1448 case DW_TAG_union_type
:
1449 case DW_TAG_enumeration_type
:
1450 case DW_TAG_typedef
:
1451 /* the type referred to will be loaded when we need it, so skip it */
1454 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1455 child
->abbrev
->tag
, dwarf2_debug_ctx(subpgm
->ctx
), dwarf2_debug_di(di
));
1460 symt_close_func_block(subpgm
->ctx
->module
, subpgm
->func
, block
, 0);
1463 static struct symt
* dwarf2_parse_subprogram(dwarf2_parse_context_t
* ctx
,
1464 dwarf2_debug_info_t
* di
,
1465 struct symt_compiland
* compiland
)
1467 struct attribute name
;
1468 struct attribute low_pc
;
1469 struct attribute high_pc
;
1470 struct attribute is_decl
;
1471 struct attribute inline_flags
;
1472 struct symt
* ret_type
;
1473 struct symt_function_signature
* sig_type
;
1474 dwarf2_subprogram_t subpgm
;
1476 if (di
->symt
) return di
->symt
;
1478 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1480 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_name
, &name
)) name
.u
.string
= NULL
;
1481 /* if it's an abstract representation of an inline function, there should be
1482 * a concrete object that we'll handle
1484 if (dwarf2_find_attribute(ctx
, di
, DW_AT_inline
, &inline_flags
))
1486 TRACE("Function %s declared as inlined (%ld)... skipping\n",
1487 name
.u
.string
? name
.u
.string
: "(null)", inline_flags
.u
.uvalue
);
1491 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_low_pc
, &low_pc
)) low_pc
.u
.uvalue
= 0;
1492 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_high_pc
, &high_pc
)) high_pc
.u
.uvalue
= 0;
1493 /* As functions (defined as inline assembly) get debug info with dwarf
1494 * (not the case for stabs), we just drop Wine's thunks here...
1495 * Actual thunks will be created in elf_module from the symbol table
1497 if (elf_is_in_thunk_area(ctx
->module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
,
1500 if (!dwarf2_find_attribute(ctx
, di
, DW_AT_declaration
, &is_decl
))
1501 is_decl
.u
.uvalue
= 0;
1503 if (!(ret_type
= dwarf2_lookup_type(ctx
, di
)))
1504 ret_type
= &symt_new_basic(ctx
->module
, btVoid
, "void", 0)->symt
;
1506 /* FIXME: assuming C source code */
1507 sig_type
= symt_new_function_signature(ctx
->module
, ret_type
, CV_CALL_FAR_C
);
1508 if (!is_decl
.u
.uvalue
)
1510 subpgm
.func
= symt_new_function(ctx
->module
, compiland
, name
.u
.string
,
1511 ctx
->module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
,
1512 high_pc
.u
.uvalue
- low_pc
.u
.uvalue
,
1514 di
->symt
= &subpgm
.func
->symt
;
1516 else subpgm
.func
= NULL
;
1519 subpgm
.compiland
= compiland
;
1520 if (!dwarf2_compute_location_attr(ctx
, di
, DW_AT_frame_base
,
1521 &subpgm
.frame
, NULL
))
1524 subpgm
.frame
.kind
= loc_regrel
;
1525 subpgm
.frame
.reg
= 0;
1526 subpgm
.frame
.offset
= 0;
1528 subpgm
.non_computed_variable
= FALSE
;
1530 if (di
->abbrev
->have_child
) /** any interest to not have child ? */
1532 dwarf2_debug_info_t
** pchild
= NULL
;
1533 dwarf2_debug_info_t
* child
;
1535 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1539 switch (child
->abbrev
->tag
)
1541 case DW_TAG_variable
:
1542 case DW_TAG_formal_parameter
:
1543 dwarf2_parse_variable(&subpgm
, NULL
, child
);
1545 case DW_TAG_lexical_block
:
1546 dwarf2_parse_subprogram_block(&subpgm
, NULL
, child
);
1548 case DW_TAG_inlined_subroutine
:
1549 dwarf2_parse_inlined_subroutine(&subpgm
, NULL
, child
);
1551 case DW_TAG_subprogram
:
1552 /* FIXME: likely a declaration (to be checked)
1557 dwarf2_parse_subprogram_label(&subpgm
, child
);
1559 case DW_TAG_class_type
:
1560 case DW_TAG_structure_type
:
1561 case DW_TAG_union_type
:
1562 case DW_TAG_enumeration_type
:
1563 case DW_TAG_typedef
:
1564 /* the type referred to will be loaded when we need it, so skip it */
1566 case DW_TAG_unspecified_parameters
:
1567 /* FIXME: no support in dbghelp's internals so far */
1570 FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
1571 child
->abbrev
->tag
, dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1576 if (subpgm
.non_computed_variable
|| subpgm
.frame
.kind
>= loc_user
)
1578 symt_add_function_point(ctx
->module
, subpgm
.func
, SymTagCustom
,
1579 &subpgm
.frame
, NULL
);
1581 symt_normalize_function(subpgm
.ctx
->module
, subpgm
.func
);
1586 static struct symt
* dwarf2_parse_subroutine_type(dwarf2_parse_context_t
* ctx
,
1587 dwarf2_debug_info_t
* di
)
1589 struct symt
* ret_type
;
1590 struct symt_function_signature
* sig_type
;
1592 if (di
->symt
) return di
->symt
;
1594 TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx
), dwarf2_debug_di(di
));
1596 if (!(ret_type
= dwarf2_lookup_type(ctx
, di
)))
1597 ret_type
= &symt_new_basic(ctx
->module
, btVoid
, "void", 0)->symt
;
1599 /* FIXME: assuming C source code */
1600 sig_type
= symt_new_function_signature(ctx
->module
, ret_type
, CV_CALL_FAR_C
);
1602 if (di
->abbrev
->have_child
) /** any interest to not have child ? */
1604 dwarf2_debug_info_t
** pchild
= NULL
;
1605 dwarf2_debug_info_t
* child
;
1607 while ((pchild
= vector_iter_up(&di
->children
, pchild
)))
1611 switch (child
->abbrev
->tag
)
1613 case DW_TAG_formal_parameter
:
1614 symt_add_function_signature_parameter(ctx
->module
, sig_type
,
1615 dwarf2_lookup_type(ctx
, child
));
1617 case DW_TAG_unspecified_parameters
:
1618 WARN("Unsupported unspecified parameters\n");
1624 return di
->symt
= &sig_type
->symt
;
1627 static void dwarf2_load_one_entry(dwarf2_parse_context_t
* ctx
,
1628 dwarf2_debug_info_t
* di
,
1629 struct symt_compiland
* compiland
)
1631 switch (di
->abbrev
->tag
)
1633 case DW_TAG_typedef
:
1634 dwarf2_parse_typedef(ctx
, di
);
1636 case DW_TAG_base_type
:
1637 dwarf2_parse_base_type(ctx
, di
);
1639 case DW_TAG_pointer_type
:
1640 dwarf2_parse_pointer_type(ctx
, di
);
1642 case DW_TAG_class_type
:
1643 dwarf2_parse_udt_type(ctx
, di
, UdtClass
);
1645 case DW_TAG_structure_type
:
1646 dwarf2_parse_udt_type(ctx
, di
, UdtStruct
);
1648 case DW_TAG_union_type
:
1649 dwarf2_parse_udt_type(ctx
, di
, UdtUnion
);
1651 case DW_TAG_array_type
:
1652 dwarf2_parse_array_type(ctx
, di
);
1654 case DW_TAG_const_type
:
1655 dwarf2_parse_const_type(ctx
, di
);
1657 case DW_TAG_volatile_type
:
1658 dwarf2_parse_volatile_type(ctx
, di
);
1660 case DW_TAG_reference_type
:
1661 dwarf2_parse_reference_type(ctx
, di
);
1663 case DW_TAG_enumeration_type
:
1664 dwarf2_parse_enumeration_type(ctx
, di
);
1666 case DW_TAG_subprogram
:
1667 dwarf2_parse_subprogram(ctx
, di
, compiland
);
1669 case DW_TAG_subroutine_type
:
1670 dwarf2_parse_subroutine_type(ctx
, di
);
1672 case DW_TAG_variable
:
1674 dwarf2_subprogram_t subpgm
;
1677 subpgm
.compiland
= compiland
;
1679 subpgm
.frame
.kind
= loc_absolute
;
1680 subpgm
.frame
.offset
= 0;
1681 subpgm
.frame
.reg
= Wine_DW_no_register
;
1682 dwarf2_parse_variable(&subpgm
, NULL
, di
);
1686 FIXME("Unhandled Tag type 0x%lx at %s, for %lu\n",
1687 di
->abbrev
->tag
, dwarf2_debug_ctx(ctx
), di
->abbrev
->entry_code
);
1691 static void dwarf2_set_line_number(struct module
* module
, unsigned long address
,
1692 struct vector
* v
, unsigned file
, unsigned line
)
1694 struct symt_function
* func
;
1698 if (!file
|| !(psrc
= vector_at(v
, file
- 1))) return;
1700 TRACE("%s %lx %s %u\n", module
->module
.ModuleName
, address
, source_get(module
, *psrc
), line
);
1701 if ((idx
= symt_find_nearest(module
, address
)) == -1 ||
1702 module
->addr_sorttab
[idx
]->symt
.tag
!= SymTagFunction
) return;
1703 func
= (struct symt_function
*)module
->addr_sorttab
[idx
];
1704 symt_add_func_line(module
, func
, *psrc
, line
, address
- func
->address
);
1707 static BOOL
dwarf2_parse_line_numbers(const dwarf2_section_t
* sections
,
1708 dwarf2_parse_context_t
* ctx
,
1709 const char* compile_dir
,
1710 unsigned long offset
)
1712 dwarf2_traverse_context_t traverse
;
1713 unsigned long length
;
1714 unsigned version
, header_len
, insn_size
, default_stmt
;
1715 unsigned line_range
, opcode_base
;
1717 const unsigned char* opcode_len
;
1719 struct vector files
;
1722 /* section with line numbers stripped */
1723 if (sections
[section_line
].address
== ELF_NO_MAP
)
1726 traverse
.data
= sections
[section_line
].address
+ offset
;
1727 traverse
.start_data
= traverse
.data
;
1728 traverse
.end_data
= traverse
.data
+ 4;
1729 traverse
.word_size
= ctx
->word_size
;
1731 length
= dwarf2_parse_u4(&traverse
);
1732 traverse
.end_data
= traverse
.start_data
+ length
;
1734 version
= dwarf2_parse_u2(&traverse
);
1735 header_len
= dwarf2_parse_u4(&traverse
);
1736 insn_size
= dwarf2_parse_byte(&traverse
);
1737 default_stmt
= dwarf2_parse_byte(&traverse
);
1738 line_base
= (signed char)dwarf2_parse_byte(&traverse
);
1739 line_range
= dwarf2_parse_byte(&traverse
);
1740 opcode_base
= dwarf2_parse_byte(&traverse
);
1742 opcode_len
= traverse
.data
;
1743 traverse
.data
+= opcode_base
- 1;
1745 vector_init(&dirs
, sizeof(const char*), 4);
1746 p
= vector_add(&dirs
, &ctx
->pool
);
1747 *p
= compile_dir
? compile_dir
: ".";
1748 while (*traverse
.data
)
1750 const char* rel
= (const char*)traverse
.data
;
1751 unsigned rellen
= strlen(rel
);
1752 TRACE("Got include %s\n", rel
);
1753 traverse
.data
+= rellen
+ 1;
1754 p
= vector_add(&dirs
, &ctx
->pool
);
1756 if (*rel
== '/' || !compile_dir
)
1760 /* include directory relative to compile directory */
1761 unsigned baselen
= strlen(compile_dir
);
1762 char* tmp
= pool_alloc(&ctx
->pool
, baselen
+ 1 + rellen
+ 1);
1763 strcpy(tmp
, compile_dir
);
1764 if (tmp
[baselen
- 1] != '/') tmp
[baselen
++] = '/';
1765 strcpy(&tmp
[baselen
], rel
);
1772 vector_init(&files
, sizeof(unsigned), 16);
1773 while (*traverse
.data
)
1775 unsigned int dir_index
, mod_time
, length
;
1780 name
= (const char*)traverse
.data
;
1781 traverse
.data
+= strlen(name
) + 1;
1782 dir_index
= dwarf2_leb128_as_unsigned(&traverse
);
1783 mod_time
= dwarf2_leb128_as_unsigned(&traverse
);
1784 length
= dwarf2_leb128_as_unsigned(&traverse
);
1785 dir
= *(const char**)vector_at(&dirs
, dir_index
);
1786 TRACE("Got file %s/%s (%u,%u)\n", dir
, name
, mod_time
, length
);
1787 psrc
= vector_add(&files
, &ctx
->pool
);
1788 *psrc
= source_new(ctx
->module
, dir
, name
);
1792 while (traverse
.data
< traverse
.end_data
)
1794 unsigned long address
= 0;
1797 unsigned is_stmt
= default_stmt
;
1798 BOOL basic_block
= FALSE
, end_sequence
= FALSE
;
1799 unsigned opcode
, extopcode
, i
;
1801 while (!end_sequence
)
1803 opcode
= dwarf2_parse_byte(&traverse
);
1804 TRACE("Got opcode %x\n", opcode
);
1806 if (opcode
>= opcode_base
)
1808 unsigned delta
= opcode
- opcode_base
;
1810 address
+= (delta
/ line_range
) * insn_size
;
1811 line
+= line_base
+ (delta
% line_range
);
1813 dwarf2_set_line_number(ctx
->module
, address
, &files
, file
, line
);
1820 basic_block
= FALSE
;
1821 dwarf2_set_line_number(ctx
->module
, address
, &files
, file
, line
);
1823 case DW_LNS_advance_pc
:
1824 address
+= insn_size
* dwarf2_leb128_as_unsigned(&traverse
);
1826 case DW_LNS_advance_line
:
1827 line
+= dwarf2_leb128_as_signed(&traverse
);
1829 case DW_LNS_set_file
:
1830 file
= dwarf2_leb128_as_unsigned(&traverse
);
1832 case DW_LNS_set_column
:
1833 dwarf2_leb128_as_unsigned(&traverse
);
1835 case DW_LNS_negate_stmt
:
1838 case DW_LNS_set_basic_block
:
1841 case DW_LNS_const_add_pc
:
1842 address
+= ((255 - opcode_base
) / line_range
) * insn_size
;
1844 case DW_LNS_fixed_advance_pc
:
1845 address
+= dwarf2_parse_u2(&traverse
);
1847 case DW_LNS_extended_op
:
1848 dwarf2_leb128_as_unsigned(&traverse
);
1849 extopcode
= dwarf2_parse_byte(&traverse
);
1852 case DW_LNE_end_sequence
:
1853 dwarf2_set_line_number(ctx
->module
, address
, &files
, file
, line
);
1854 end_sequence
= TRUE
;
1856 case DW_LNE_set_address
:
1857 address
= ctx
->module
->module
.BaseOfImage
+ dwarf2_parse_addr(&traverse
);
1859 case DW_LNE_define_file
:
1860 FIXME("not handled %s\n", traverse
.data
);
1861 traverse
.data
+= strlen((const char *)traverse
.data
) + 1;
1862 dwarf2_leb128_as_unsigned(&traverse
);
1863 dwarf2_leb128_as_unsigned(&traverse
);
1864 dwarf2_leb128_as_unsigned(&traverse
);
1867 FIXME("Unsupported extended opcode %x\n", extopcode
);
1872 WARN("Unsupported opcode %x\n", opcode
);
1873 for (i
= 0; i
< opcode_len
[opcode
]; i
++)
1874 dwarf2_leb128_as_unsigned(&traverse
);
1883 static BOOL
dwarf2_parse_compilation_unit(const dwarf2_section_t
* sections
,
1884 const dwarf2_comp_unit_t
* comp_unit
,
1885 struct module
* module
,
1886 const struct elf_thunk_area
* thunks
,
1887 const unsigned char* comp_unit_cursor
)
1889 dwarf2_parse_context_t ctx
;
1890 dwarf2_traverse_context_t traverse
;
1891 dwarf2_traverse_context_t abbrev_ctx
;
1892 dwarf2_debug_info_t
* di
;
1895 TRACE("Compilation Unit Header found at 0x%x:\n",
1896 comp_unit_cursor
- sections
[section_debug
].address
);
1897 TRACE("- length: %lu\n", comp_unit
->length
);
1898 TRACE("- version: %u\n", comp_unit
->version
);
1899 TRACE("- abbrev_offset: %lu\n", comp_unit
->abbrev_offset
);
1900 TRACE("- word_size: %u\n", comp_unit
->word_size
);
1902 if (comp_unit
->version
!= 2)
1904 WARN("%u DWARF version unsupported. Wine dbghelp only support DWARF 2.\n",
1905 comp_unit
->version
);
1909 pool_init(&ctx
.pool
, 65536);
1910 ctx
.sections
= sections
;
1911 ctx
.section
= section_debug
;
1912 ctx
.module
= module
;
1913 ctx
.word_size
= comp_unit
->word_size
;
1914 ctx
.thunks
= thunks
;
1915 ctx
.ref_offset
= comp_unit_cursor
- sections
[section_debug
].address
;
1917 traverse
.start_data
= comp_unit_cursor
+ sizeof(dwarf2_comp_unit_stream_t
);
1918 traverse
.data
= traverse
.start_data
;
1919 traverse
.word_size
= comp_unit
->word_size
;
1920 traverse
.end_data
= comp_unit_cursor
+ comp_unit
->length
+ sizeof(unsigned);
1922 abbrev_ctx
.start_data
= sections
[section_abbrev
].address
+ comp_unit
->abbrev_offset
;
1923 abbrev_ctx
.data
= abbrev_ctx
.start_data
;
1924 abbrev_ctx
.end_data
= sections
[section_abbrev
].address
+ sections
[section_abbrev
].size
;
1925 abbrev_ctx
.word_size
= comp_unit
->word_size
;
1926 dwarf2_parse_abbrev_set(&abbrev_ctx
, &ctx
.abbrev_table
, &ctx
.pool
);
1928 sparse_array_init(&ctx
.debug_info_table
, sizeof(dwarf2_debug_info_t
), 128);
1929 dwarf2_read_one_debug_info(&ctx
, &traverse
, &di
);
1931 if (di
->abbrev
->tag
== DW_TAG_compile_unit
)
1933 struct attribute name
;
1934 dwarf2_debug_info_t
** pdi
= NULL
;
1935 struct attribute stmt_list
, low_pc
;
1936 struct attribute comp_dir
;
1938 if (!dwarf2_find_attribute(&ctx
, di
, DW_AT_name
, &name
))
1939 name
.u
.string
= NULL
;
1941 /* get working directory of current compilation unit */
1942 if (!dwarf2_find_attribute(&ctx
, di
, DW_AT_comp_dir
, &comp_dir
))
1943 comp_dir
.u
.string
= NULL
;
1945 if (!dwarf2_find_attribute(&ctx
, di
, DW_AT_low_pc
, &low_pc
))
1946 low_pc
.u
.uvalue
= 0;
1947 di
->symt
= &symt_new_compiland(module
,
1948 module
->module
.BaseOfImage
+ low_pc
.u
.uvalue
,
1949 source_new(module
, comp_dir
.u
.string
, name
.u
.string
))->symt
;
1951 if (di
->abbrev
->have_child
)
1953 while ((pdi
= vector_iter_up(&di
->children
, pdi
)))
1955 dwarf2_load_one_entry(&ctx
, *pdi
, (struct symt_compiland
*)di
->symt
);
1958 if (dwarf2_find_attribute(&ctx
, di
, DW_AT_stmt_list
, &stmt_list
))
1960 if (dwarf2_parse_line_numbers(sections
, &ctx
, comp_dir
.u
.string
, stmt_list
.u
.uvalue
))
1961 module
->module
.LineNumbers
= TRUE
;
1965 else FIXME("Should have a compilation unit here\n");
1966 pool_destroy(&ctx
.pool
);
1970 static BOOL
dwarf2_lookup_loclist(const struct module
* module
, const BYTE
* start
,
1972 dwarf2_traverse_context_t
* lctx
)
1975 const BYTE
* ptr
= start
;
1978 while (ptr
< module
->dwarf2_info
->debug_loc
.address
+ module
->dwarf2_info
->debug_loc
.size
)
1980 beg
= dwarf2_get_u4(ptr
); ptr
+= 4;
1981 end
= dwarf2_get_u4(ptr
); ptr
+= 4;
1982 if (!beg
&& !end
) break;
1983 len
= dwarf2_get_u2(ptr
); ptr
+= 2;
1985 if (beg
<= ip
&& ip
< end
)
1988 lctx
->end_data
= ptr
+ len
;
1989 lctx
->word_size
= 4; /* FIXME word size !!! */
1994 WARN("Couldn't find ip in location list\n");
1998 static enum location_error
loc_compute_frame(struct process
* pcs
,
1999 const struct module
* module
,
2000 const struct symt_function
* func
,
2001 DWORD ip
, struct location
* frame
)
2003 struct symt
** psym
= NULL
;
2004 struct location
* pframe
;
2005 dwarf2_traverse_context_t lctx
;
2006 enum location_error err
;
2008 while ((psym
= vector_iter_up(&func
->vchildren
, psym
)))
2010 if ((*psym
)->tag
== SymTagCustom
)
2012 pframe
= &((struct symt_function_point
*)*psym
)->loc
;
2014 /* First, recompute the frame information, if needed */
2015 switch (pframe
->kind
)
2021 case loc_dwarf2_location_list
:
2022 WARN("Searching loclist for %s\n", func
->hash_elt
.name
);
2023 if (!dwarf2_lookup_loclist(module
,
2024 module
->dwarf2_info
->debug_loc
.address
+ pframe
->offset
,
2026 return loc_err_out_of_scope
;
2027 if ((err
= compute_location(&lctx
, frame
, pcs
->handle
, NULL
)) < 0) return err
;
2028 if (frame
->kind
>= loc_user
)
2030 WARN("Couldn't compute runtime frame location\n");
2031 return loc_err_too_complex
;
2035 WARN("Unsupported frame kind %d\n", pframe
->kind
);
2036 return loc_err_internal
;
2041 WARN("Couldn't find Custom function point, whilst location list offset is searched\n");
2042 return loc_err_internal
;
2045 static void dwarf2_location_compute(struct process
* pcs
,
2046 const struct module
* module
,
2047 const struct symt_function
* func
,
2048 struct location
* loc
)
2050 struct location frame
;
2053 dwarf2_traverse_context_t lctx
;
2055 if (!func
->container
|| func
->container
->tag
!= SymTagCompiland
)
2057 WARN("We'd expect function %s's container to exist and be a compiland\n", func
->hash_elt
.name
);
2058 err
= loc_err_internal
;
2062 /* instruction pointer relative to compiland's start */
2063 ip
= pcs
->ctx_frame
.InstructionOffset
- ((struct symt_compiland
*)func
->container
)->address
;
2065 if ((err
= loc_compute_frame(pcs
, module
, func
, ip
, &frame
)) == 0)
2069 case loc_dwarf2_location_list
:
2070 /* Then, if the variable has a location list, find it !! */
2071 if (dwarf2_lookup_loclist(module
,
2072 module
->dwarf2_info
->debug_loc
.address
+ loc
->offset
,
2075 err
= loc_err_out_of_scope
;
2077 case loc_dwarf2_block
:
2078 /* or if we have a copy of an existing block, get ready for it */
2080 unsigned* ptr
= (unsigned*)loc
->offset
;
2082 lctx
.data
= (const BYTE
*)(ptr
+ 1);
2083 lctx
.end_data
= lctx
.data
+ *ptr
;
2084 lctx
.word_size
= 4; /* FIXME !! */
2087 /* now get the variable */
2088 err
= compute_location(&lctx
, loc
, pcs
->handle
, &frame
);
2095 WARN("Unsupported local kind %d\n", loc
->kind
);
2096 err
= loc_err_internal
;
2102 loc
->kind
= loc_register
;
2107 BOOL
dwarf2_parse(struct module
* module
, unsigned long load_offset
,
2108 const struct elf_thunk_area
* thunks
,
2109 const unsigned char* debug
, unsigned int debug_size
,
2110 const unsigned char* abbrev
, unsigned int abbrev_size
,
2111 const unsigned char* str
, unsigned int str_size
,
2112 const unsigned char* line
, unsigned int line_size
,
2113 const unsigned char* loclist
, unsigned int loclist_size
)
2115 dwarf2_section_t section
[section_max
];
2117 const unsigned char*comp_unit_cursor
= debug
;
2118 const unsigned char*end_debug
= debug
+ debug_size
;
2120 module
->loc_compute
= dwarf2_location_compute
;
2122 section
[section_debug
].address
= debug
;
2123 section
[section_debug
].size
= debug_size
;
2124 section
[section_abbrev
].address
= abbrev
;
2125 section
[section_abbrev
].size
= abbrev_size
;
2126 section
[section_string
].address
= str
;
2127 section
[section_string
].size
= str_size
;
2128 section
[section_line
].address
= line
;
2129 section
[section_line
].size
= line_size
;
2133 /* initialize the dwarf2 specific info block for this module.
2134 * As we'll need later on the .debug_loc section content, we copy it in
2135 * the module structure for later reuse
2137 module
->dwarf2_info
= HeapAlloc(GetProcessHeap(), 0, sizeof(*module
->dwarf2_info
) + loclist_size
);
2138 if (!module
->dwarf2_info
) return FALSE
;
2139 ptr
= (unsigned char*)(module
->dwarf2_info
+ 1);
2140 memcpy(ptr
, loclist
, loclist_size
);
2141 module
->dwarf2_info
->debug_loc
.address
= ptr
;
2142 module
->dwarf2_info
->debug_loc
.size
= loclist_size
;
2145 while (comp_unit_cursor
< end_debug
)
2147 const dwarf2_comp_unit_stream_t
* comp_unit_stream
;
2148 dwarf2_comp_unit_t comp_unit
;
2150 comp_unit_stream
= (const dwarf2_comp_unit_stream_t
*) comp_unit_cursor
;
2151 comp_unit
.length
= *(unsigned long*) comp_unit_stream
->length
;
2152 comp_unit
.version
= *(unsigned short*) comp_unit_stream
->version
;
2153 comp_unit
.abbrev_offset
= *(unsigned long*) comp_unit_stream
->abbrev_offset
;
2154 comp_unit
.word_size
= *(unsigned char*) comp_unit_stream
->word_size
;
2156 dwarf2_parse_compilation_unit(section
, &comp_unit
, module
,
2157 thunks
, comp_unit_cursor
);
2158 comp_unit_cursor
+= comp_unit
.length
+ sizeof(unsigned);
2160 module
->module
.SymType
= SymDia
;
2161 module
->module
.CVSig
= 'D' | ('W' << 8) | ('A' << 16) | ('R' << 24);
2162 /* FIXME: we could have a finer grain here */
2163 module
->module
.GlobalSymbols
= TRUE
;
2164 module
->module
.TypeInfo
= TRUE
;
2165 module
->module
.SourceIndexed
= TRUE
;
2166 module
->module
.Publics
= TRUE
;