2005-05-17 16:32:55 +02:00
|
|
|
/*
|
|
|
|
* File dwarf.c - read dwarf2 information from the ELF modules
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005, Raphael Junqueira
|
2011-03-08 21:31:26 +01:00
|
|
|
* Copyright (C) 2006-2011, Eric Pouech
|
2010-03-27 09:08:11 +01:00
|
|
|
* Copyright (C) 2010, Alexandre Julliard
|
2005-05-17 16:32:55 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-17 16:32:55 +02:00
|
|
|
*/
|
|
|
|
|
2008-02-27 20:02:39 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2005-05-17 16:32:55 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2006-12-05 22:13:30 +01:00
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "oleauto.h"
|
2005-05-17 16:32:55 +02:00
|
|
|
|
|
|
|
#include "dbghelp_private.h"
|
2010-03-18 21:30:47 +01:00
|
|
|
#include "image_private.h"
|
2005-05-17 16:32:55 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_dwarf);
|
|
|
|
|
2006-06-18 21:31:43 +02:00
|
|
|
/* FIXME:
|
|
|
|
* - Functions:
|
|
|
|
* o unspecified parameters
|
|
|
|
* o inlined functions
|
2006-06-18 21:32:00 +02:00
|
|
|
* o Debug{Start|End}Point
|
2006-06-18 21:32:03 +02:00
|
|
|
* o CFA
|
2006-06-18 21:31:46 +02:00
|
|
|
* - Udt
|
2006-06-18 21:32:06 +02:00
|
|
|
* o proper types loading (nesting)
|
2006-06-18 21:31:43 +02:00
|
|
|
*/
|
2006-06-18 21:31:46 +02:00
|
|
|
|
2005-05-19 13:14:39 +02:00
|
|
|
#if 0
|
2005-05-18 11:46:12 +02:00
|
|
|
static void dump(const void* ptr, unsigned len)
|
|
|
|
{
|
2006-06-18 21:32:30 +02:00
|
|
|
int i, j;
|
|
|
|
BYTE msg[128];
|
|
|
|
static const char hexof[] = "0123456789abcdef";
|
2009-01-19 10:24:06 +01:00
|
|
|
const BYTE* x = ptr;
|
2006-06-18 21:32:30 +02:00
|
|
|
|
|
|
|
for (i = 0; i < len; i += 16)
|
2005-05-18 11:46:12 +02:00
|
|
|
{
|
2006-06-18 21:32:30 +02:00
|
|
|
sprintf(msg, "%08x: ", i);
|
|
|
|
memset(msg + 10, ' ', 3 * 16 + 1 + 16);
|
|
|
|
for (j = 0; j < min(16, len - i); j++)
|
|
|
|
{
|
|
|
|
msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
|
|
|
|
msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
|
|
|
|
msg[10 + 3 * j + 2] = ' ';
|
|
|
|
msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
|
|
|
|
x[i + j] : '.';
|
|
|
|
}
|
|
|
|
msg[10 + 3 * 16] = ' ';
|
|
|
|
msg[10 + 3 * 16 + 1 + 16] = '\0';
|
|
|
|
TRACE("%s\n", msg);
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
2005-05-19 13:14:39 +02:00
|
|
|
#endif
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2005-05-17 16:32:55 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Main Specs:
|
|
|
|
* http://www.eagercon.com/dwarf/dwarf3std.htm
|
|
|
|
* http://www.eagercon.com/dwarf/dwarf-2.0.0.pdf
|
|
|
|
*
|
|
|
|
* dwarf2.h: http://www.hakpetzna.com/b/binutils/dwarf2_8h-source.html
|
|
|
|
*
|
|
|
|
* example of projects who do dwarf2 parsing:
|
|
|
|
* http://www.x86-64.org/cgi-bin/cvsweb.cgi/binutils.dead/binutils/readelf.c?rev=1.1.1.2
|
|
|
|
* http://elis.ugent.be/diota/log/ltrace_elf.c
|
|
|
|
*/
|
2006-06-18 21:30:59 +02:00
|
|
|
#include "dwarf.h"
|
2005-12-19 18:22:54 +01:00
|
|
|
|
2005-05-18 11:46:12 +02:00
|
|
|
/**
|
|
|
|
* Parsers
|
|
|
|
*/
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
typedef struct dwarf2_abbrev_entry_attr_s
|
|
|
|
{
|
2005-05-20 11:41:10 +02:00
|
|
|
unsigned long attribute;
|
|
|
|
unsigned long form;
|
|
|
|
struct dwarf2_abbrev_entry_attr_s* next;
|
|
|
|
} dwarf2_abbrev_entry_attr_t;
|
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
typedef struct dwarf2_abbrev_entry_s
|
|
|
|
{
|
|
|
|
unsigned long entry_code;
|
|
|
|
unsigned long tag;
|
|
|
|
unsigned char have_child;
|
|
|
|
unsigned num_attr;
|
|
|
|
dwarf2_abbrev_entry_attr_t* attrs;
|
2005-05-20 11:41:10 +02:00
|
|
|
} dwarf2_abbrev_entry_t;
|
|
|
|
|
2006-06-18 21:31:39 +02:00
|
|
|
struct dwarf2_block
|
|
|
|
{
|
|
|
|
unsigned size;
|
|
|
|
const unsigned char* ptr;
|
|
|
|
};
|
|
|
|
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute
|
2006-06-18 21:31:17 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned long form;
|
2011-03-08 21:31:02 +01:00
|
|
|
enum {attr_direct, attr_abstract_origin, attr_specification} gotten_from;
|
2006-09-25 22:40:58 +02:00
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned long uvalue;
|
2010-03-15 21:12:22 +01:00
|
|
|
ULONGLONG lluvalue;
|
2006-09-25 22:40:58 +02:00
|
|
|
long svalue;
|
|
|
|
const char* string;
|
2006-09-25 22:41:10 +02:00
|
|
|
struct dwarf2_block block;
|
2006-09-25 22:40:58 +02:00
|
|
|
} u;
|
2006-06-18 21:31:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct dwarf2_debug_info_s
|
|
|
|
{
|
|
|
|
const dwarf2_abbrev_entry_t*abbrev;
|
|
|
|
struct symt* symt;
|
2006-09-25 22:41:10 +02:00
|
|
|
const unsigned char** data;
|
2006-06-18 21:31:17 +02:00
|
|
|
struct vector children;
|
2011-03-08 21:30:47 +01:00
|
|
|
struct dwarf2_debug_info_s* parent;
|
2006-06-18 21:31:17 +02:00
|
|
|
} dwarf2_debug_info_t;
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
typedef struct dwarf2_section_s
|
|
|
|
{
|
|
|
|
const unsigned char* address;
|
|
|
|
unsigned size;
|
2010-03-18 21:31:26 +01:00
|
|
|
DWORD_PTR rva;
|
2006-06-18 21:32:09 +02:00
|
|
|
} dwarf2_section_t;
|
|
|
|
|
2011-01-18 21:49:05 +01:00
|
|
|
enum dwarf2_sections {section_debug, section_string, section_abbrev, section_line, section_ranges, section_max};
|
2006-06-18 21:32:09 +02:00
|
|
|
|
|
|
|
typedef struct dwarf2_traverse_context_s
|
|
|
|
{
|
|
|
|
const unsigned char* data;
|
|
|
|
const unsigned char* end_data;
|
|
|
|
unsigned char word_size;
|
|
|
|
} dwarf2_traverse_context_t;
|
|
|
|
|
2008-02-06 21:56:06 +01:00
|
|
|
/* symt_cache indexes */
|
|
|
|
#define sc_void 0
|
|
|
|
#define sc_int1 1
|
|
|
|
#define sc_int2 2
|
|
|
|
#define sc_int4 3
|
|
|
|
#define sc_num 4
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
typedef struct dwarf2_parse_context_s
|
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
const dwarf2_section_t* sections;
|
|
|
|
unsigned section;
|
2006-06-18 21:32:09 +02:00
|
|
|
struct pool pool;
|
|
|
|
struct module* module;
|
2011-03-08 21:31:14 +01:00
|
|
|
struct symt_compiland* compiland;
|
2006-06-24 09:50:10 +02:00
|
|
|
const struct elf_thunk_area*thunks;
|
2006-06-18 21:32:09 +02:00
|
|
|
struct sparse_array abbrev_table;
|
|
|
|
struct sparse_array debug_info_table;
|
2007-03-15 22:01:06 +01:00
|
|
|
unsigned long load_offset;
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned long ref_offset;
|
2008-02-06 21:56:06 +01:00
|
|
|
struct symt* symt_cache[sc_num]; /* void, int1, int2, int4 */
|
2011-03-08 21:30:56 +01:00
|
|
|
char* cpp_name;
|
2005-05-17 16:32:55 +02:00
|
|
|
} dwarf2_parse_context_t;
|
|
|
|
|
2006-11-24 22:17:26 +01:00
|
|
|
/* stored in the dbghelp's module internal structure for later reuse */
|
|
|
|
struct dwarf2_module_info_s
|
|
|
|
{
|
|
|
|
dwarf2_section_t debug_loc;
|
2010-03-27 09:07:50 +01:00
|
|
|
dwarf2_section_t debug_frame;
|
|
|
|
dwarf2_section_t eh_frame;
|
2010-03-24 22:04:06 +01:00
|
|
|
unsigned char word_size;
|
2006-11-24 22:17:26 +01:00
|
|
|
};
|
|
|
|
|
2006-11-24 22:17:31 +01:00
|
|
|
#define loc_dwarf2_location_list (loc_user + 0)
|
|
|
|
#define loc_dwarf2_block (loc_user + 1)
|
|
|
|
|
2006-06-18 21:30:49 +02:00
|
|
|
/* forward declarations */
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx, dwarf2_debug_info_t* entry);
|
2006-06-18 21:30:49 +02:00
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned char dwarf2_get_byte(const unsigned char* ptr)
|
|
|
|
{
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static unsigned char dwarf2_parse_byte(dwarf2_traverse_context_t* ctx)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned char uvalue = dwarf2_get_byte(ctx->data);
|
2006-06-18 21:32:30 +02:00
|
|
|
ctx->data += 1;
|
|
|
|
return uvalue;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned short dwarf2_get_u2(const unsigned char* ptr)
|
|
|
|
{
|
2009-12-12 12:19:02 +01:00
|
|
|
return *(const UINT16*)ptr;
|
2006-09-25 22:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static unsigned short dwarf2_parse_u2(dwarf2_traverse_context_t* ctx)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned short uvalue = dwarf2_get_u2(ctx->data);
|
2006-06-18 21:32:30 +02:00
|
|
|
ctx->data += 2;
|
|
|
|
return uvalue;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned long dwarf2_get_u4(const unsigned char* ptr)
|
|
|
|
{
|
2009-12-12 12:19:02 +01:00
|
|
|
return *(const UINT32*)ptr;
|
2006-09-25 22:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static unsigned long dwarf2_parse_u4(dwarf2_traverse_context_t* ctx)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned long uvalue = dwarf2_get_u4(ctx->data);
|
2006-06-18 21:32:30 +02:00
|
|
|
ctx->data += 4;
|
|
|
|
return uvalue;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2009-12-12 12:19:02 +01:00
|
|
|
static DWORD64 dwarf2_get_u8(const unsigned char* ptr)
|
|
|
|
{
|
|
|
|
return *(const UINT64*)ptr;
|
|
|
|
}
|
|
|
|
|
2010-02-08 22:33:19 +01:00
|
|
|
static DWORD64 dwarf2_parse_u8(dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
|
|
|
DWORD64 uvalue = dwarf2_get_u8(ctx->data);
|
|
|
|
ctx->data += 8;
|
|
|
|
return uvalue;
|
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned long dwarf2_get_leb128_as_unsigned(const unsigned char* ptr, const unsigned char** end)
|
2005-05-17 16:32:55 +02:00
|
|
|
{
|
2006-06-18 21:32:30 +02:00
|
|
|
unsigned long ret = 0;
|
|
|
|
unsigned char byte;
|
|
|
|
unsigned shift = 0;
|
2005-05-17 16:32:55 +02:00
|
|
|
|
2006-06-18 21:32:33 +02:00
|
|
|
do
|
2006-06-18 21:32:30 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
byte = dwarf2_get_byte(ptr++);
|
2006-06-18 21:32:30 +02:00
|
|
|
ret |= (byte & 0x7f) << shift;
|
|
|
|
shift += 7;
|
2006-06-18 21:32:33 +02:00
|
|
|
} while (byte & 0x80);
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
if (end) *end = ptr;
|
2006-06-18 21:32:30 +02:00
|
|
|
return ret;
|
2005-05-17 16:32:55 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned long dwarf2_leb128_as_unsigned(dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
|
|
|
|
assert(ctx);
|
|
|
|
|
|
|
|
ret = dwarf2_get_leb128_as_unsigned(ctx->data, &ctx->data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long dwarf2_get_leb128_as_signed(const unsigned char* ptr, const unsigned char** end)
|
2005-05-17 16:32:55 +02:00
|
|
|
{
|
2006-06-18 21:32:30 +02:00
|
|
|
long ret = 0;
|
|
|
|
unsigned char byte;
|
|
|
|
unsigned shift = 0;
|
|
|
|
const unsigned size = sizeof(int) * 8;
|
|
|
|
|
2006-06-18 21:32:33 +02:00
|
|
|
do
|
2006-06-18 21:32:30 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
byte = dwarf2_get_byte(ptr++);
|
2006-06-18 21:32:30 +02:00
|
|
|
ret |= (byte & 0x7f) << shift;
|
|
|
|
shift += 7;
|
2006-06-18 21:32:33 +02:00
|
|
|
} while (byte & 0x80);
|
2006-09-25 22:41:10 +02:00
|
|
|
if (end) *end = ptr;
|
2006-06-18 21:32:33 +02:00
|
|
|
|
2006-06-18 21:32:30 +02:00
|
|
|
/* as spec: sign bit of byte is 2nd high order bit (80x40)
|
|
|
|
* -> 0x80 is used as flag.
|
|
|
|
*/
|
|
|
|
if ((shift < size) && (byte & 0x40))
|
|
|
|
{
|
|
|
|
ret |= - (1 << shift);
|
|
|
|
}
|
|
|
|
return ret;
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static long dwarf2_leb128_as_signed(dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
|
|
|
long ret = 0;
|
|
|
|
|
|
|
|
assert(ctx);
|
|
|
|
|
|
|
|
ret = dwarf2_get_leb128_as_signed(ctx->data, &ctx->data);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned dwarf2_leb128_length(const dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
|
|
|
unsigned ret;
|
|
|
|
for (ret = 0; ctx->data[ret] & 0x80; ret++);
|
|
|
|
return ret + 1;
|
|
|
|
}
|
|
|
|
|
2009-12-12 12:19:02 +01:00
|
|
|
/******************************************************************
|
|
|
|
* dwarf2_get_addr
|
|
|
|
*
|
|
|
|
* Returns an address.
|
|
|
|
* We assume that in all cases word size from Dwarf matches the size of
|
|
|
|
* addresses in platform where the exec is compiled.
|
|
|
|
*/
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned long dwarf2_get_addr(const unsigned char* ptr, unsigned word_size)
|
2006-06-18 21:31:17 +02:00
|
|
|
{
|
|
|
|
unsigned long ret;
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
switch (word_size)
|
2006-06-18 21:31:17 +02:00
|
|
|
{
|
|
|
|
case 4:
|
2006-09-25 22:41:10 +02:00
|
|
|
ret = dwarf2_get_u4(ptr);
|
2006-06-18 21:31:17 +02:00
|
|
|
break;
|
2009-12-12 12:19:02 +01:00
|
|
|
case 8:
|
|
|
|
ret = dwarf2_get_u8(ptr);
|
|
|
|
break;
|
2006-06-18 21:31:17 +02:00
|
|
|
default:
|
2006-09-25 22:41:10 +02:00
|
|
|
FIXME("Unsupported Word Size %u\n", word_size);
|
2006-06-18 21:31:17 +02:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static unsigned long dwarf2_parse_addr(dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
|
|
|
unsigned long ret = dwarf2_get_addr(ctx->data, ctx->word_size);
|
|
|
|
ctx->data += ctx->word_size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static const char* dwarf2_debug_traverse_ctx(const dwarf2_traverse_context_t* ctx)
|
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
return wine_dbg_sprintf("ctx(%p)", ctx->data);
|
2006-06-18 21:32:09 +02:00
|
|
|
}
|
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
static const char* dwarf2_debug_ctx(const dwarf2_parse_context_t* ctx)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2007-03-13 17:26:33 +01:00
|
|
|
return wine_dbg_sprintf("ctx(%p,%s)",
|
|
|
|
ctx, debugstr_w(ctx->module->module.ModuleName));
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2007-02-21 21:54:39 +01:00
|
|
|
static const char* dwarf2_debug_di(const dwarf2_debug_info_t* di)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
return wine_dbg_sprintf("debug_info(abbrev:%p,symt:%p)",
|
|
|
|
di->abbrev, di->symt);
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
static dwarf2_abbrev_entry_t*
|
2007-04-18 00:19:45 +02:00
|
|
|
dwarf2_abbrev_table_find_entry(const struct sparse_array* abbrev_table,
|
2006-06-18 21:31:13 +02:00
|
|
|
unsigned long entry_code)
|
2005-05-18 11:46:12 +02:00
|
|
|
{
|
2006-06-18 21:31:13 +02:00
|
|
|
assert( NULL != abbrev_table );
|
|
|
|
return sparse_array_find(abbrev_table, entry_code);
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static void dwarf2_parse_abbrev_set(dwarf2_traverse_context_t* abbrev_ctx,
|
2006-06-18 21:31:13 +02:00
|
|
|
struct sparse_array* abbrev_table,
|
|
|
|
struct pool* pool)
|
2005-05-18 11:46:12 +02:00
|
|
|
{
|
2006-06-18 21:31:13 +02:00
|
|
|
unsigned long entry_code;
|
|
|
|
dwarf2_abbrev_entry_t* abbrev_entry;
|
|
|
|
dwarf2_abbrev_entry_attr_t* new = NULL;
|
|
|
|
dwarf2_abbrev_entry_attr_t* last = NULL;
|
|
|
|
unsigned long attribute;
|
|
|
|
unsigned long form;
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
assert( NULL != abbrev_ctx );
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
TRACE("%s, end at %p\n",
|
|
|
|
dwarf2_debug_traverse_ctx(abbrev_ctx), abbrev_ctx->end_data);
|
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
sparse_array_init(abbrev_table, sizeof(dwarf2_abbrev_entry_t), 32);
|
|
|
|
while (abbrev_ctx->data < abbrev_ctx->end_data)
|
|
|
|
{
|
2006-06-18 21:32:09 +02:00
|
|
|
TRACE("now at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx));
|
2006-06-18 21:31:13 +02:00
|
|
|
entry_code = dwarf2_leb128_as_unsigned(abbrev_ctx);
|
|
|
|
TRACE("found entry_code %lu\n", entry_code);
|
|
|
|
if (!entry_code)
|
|
|
|
{
|
2006-06-18 21:32:09 +02:00
|
|
|
TRACE("NULL entry code at %s\n", dwarf2_debug_traverse_ctx(abbrev_ctx));
|
2006-06-18 21:31:13 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
abbrev_entry = sparse_array_add(abbrev_table, entry_code, pool);
|
|
|
|
assert( NULL != abbrev_entry );
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
abbrev_entry->entry_code = entry_code;
|
|
|
|
abbrev_entry->tag = dwarf2_leb128_as_unsigned(abbrev_ctx);
|
|
|
|
abbrev_entry->have_child = dwarf2_parse_byte(abbrev_ctx);
|
|
|
|
abbrev_entry->attrs = NULL;
|
|
|
|
abbrev_entry->num_attr = 0;
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
TRACE("table:(%p,#%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n",
|
|
|
|
abbrev_table, sparse_array_length(abbrev_table),
|
|
|
|
entry_code, abbrev_entry->tag, abbrev_entry->have_child, abbrev_entry);
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
last = NULL;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
attribute = dwarf2_leb128_as_unsigned(abbrev_ctx);
|
|
|
|
form = dwarf2_leb128_as_unsigned(abbrev_ctx);
|
|
|
|
if (!attribute) break;
|
|
|
|
|
|
|
|
new = pool_alloc(pool, sizeof(dwarf2_abbrev_entry_attr_t));
|
|
|
|
assert(new);
|
|
|
|
|
|
|
|
new->attribute = attribute;
|
|
|
|
new->form = form;
|
|
|
|
new->next = NULL;
|
|
|
|
if (abbrev_entry->attrs) last->next = new;
|
|
|
|
else abbrev_entry->attrs = new;
|
|
|
|
last = new;
|
|
|
|
abbrev_entry->num_attr++;
|
|
|
|
}
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
2006-06-18 21:31:13 +02:00
|
|
|
TRACE("found %u entries\n", sparse_array_length(abbrev_table));
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
static void dwarf2_swallow_attribute(dwarf2_traverse_context_t* ctx,
|
|
|
|
const dwarf2_abbrev_entry_attr_t* abbrev_attr)
|
2006-06-18 21:31:17 +02:00
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
unsigned step;
|
|
|
|
|
2006-06-18 21:31:17 +02:00
|
|
|
TRACE("(attr:0x%lx,form:0x%lx)\n", abbrev_attr->attribute, abbrev_attr->form);
|
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
switch (abbrev_attr->form)
|
|
|
|
{
|
2006-06-18 21:31:17 +02:00
|
|
|
case DW_FORM_ref_addr:
|
2006-09-25 22:41:10 +02:00
|
|
|
case DW_FORM_addr: step = ctx->word_size; break;
|
2006-06-18 21:31:17 +02:00
|
|
|
case DW_FORM_flag:
|
|
|
|
case DW_FORM_data1:
|
2006-09-25 22:41:10 +02:00
|
|
|
case DW_FORM_ref1: step = 1; break;
|
2006-06-18 21:31:17 +02:00
|
|
|
case DW_FORM_data2:
|
2006-09-25 22:41:10 +02:00
|
|
|
case DW_FORM_ref2: step = 2; break;
|
2006-06-18 21:31:17 +02:00
|
|
|
case DW_FORM_data4:
|
|
|
|
case DW_FORM_ref4:
|
2006-09-25 22:41:10 +02:00
|
|
|
case DW_FORM_strp: step = 4; break;
|
|
|
|
case DW_FORM_data8:
|
|
|
|
case DW_FORM_ref8: step = 8; break;
|
2006-06-18 21:31:17 +02:00
|
|
|
case DW_FORM_sdata:
|
|
|
|
case DW_FORM_ref_udata:
|
2006-09-25 22:41:10 +02:00
|
|
|
case DW_FORM_udata: step = dwarf2_leb128_length(ctx); break;
|
|
|
|
case DW_FORM_string: step = strlen((const char*)ctx->data) + 1; break;
|
|
|
|
case DW_FORM_block: step = dwarf2_leb128_as_unsigned(ctx); break;
|
|
|
|
case DW_FORM_block1: step = dwarf2_parse_byte(ctx); break;
|
|
|
|
case DW_FORM_block2: step = dwarf2_parse_u2(ctx); break;
|
|
|
|
case DW_FORM_block4: step = dwarf2_parse_u4(ctx); break;
|
2006-06-18 21:31:17 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled attribute form %lx\n", abbrev_attr->form);
|
2006-09-25 22:41:10 +02:00
|
|
|
return;
|
2006-06-18 21:31:17 +02:00
|
|
|
}
|
2006-09-25 22:41:10 +02:00
|
|
|
ctx->data += step;
|
2006-06-18 21:31:17 +02:00
|
|
|
}
|
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
static void dwarf2_fill_attr(const dwarf2_parse_context_t* ctx,
|
|
|
|
const dwarf2_abbrev_entry_attr_t* abbrev_attr,
|
|
|
|
const unsigned char* data,
|
|
|
|
struct attribute* attr)
|
2006-06-18 21:31:27 +02:00
|
|
|
{
|
2006-11-24 22:18:20 +01:00
|
|
|
attr->form = abbrev_attr->form;
|
|
|
|
switch (attr->form)
|
2006-06-18 21:31:27 +02:00
|
|
|
{
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref_addr:
|
|
|
|
case DW_FORM_addr:
|
2010-03-24 22:04:06 +01:00
|
|
|
attr->u.uvalue = dwarf2_get_addr(data,
|
|
|
|
ctx->module->format_info[DFI_DWARF]->u.dwarf2_info->word_size);
|
2006-11-24 22:18:20 +01:00
|
|
|
TRACE("addr<0x%lx>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_flag:
|
|
|
|
attr->u.uvalue = dwarf2_get_byte(data);
|
|
|
|
TRACE("flag<0x%lx>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_data1:
|
|
|
|
attr->u.uvalue = dwarf2_get_byte(data);
|
|
|
|
TRACE("data1<%lu>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_data2:
|
|
|
|
attr->u.uvalue = dwarf2_get_u2(data);
|
|
|
|
TRACE("data2<%lu>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_data4:
|
|
|
|
attr->u.uvalue = dwarf2_get_u4(data);
|
|
|
|
TRACE("data4<%lu>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_data8:
|
2010-03-15 21:12:22 +01:00
|
|
|
attr->u.lluvalue = dwarf2_get_u8(data);
|
|
|
|
TRACE("data8<%s>\n", wine_dbgstr_longlong(attr->u.uvalue));
|
2006-11-24 22:18:20 +01:00
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref1:
|
|
|
|
attr->u.uvalue = ctx->ref_offset + dwarf2_get_byte(data);
|
|
|
|
TRACE("ref1<0x%lx>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref2:
|
|
|
|
attr->u.uvalue = ctx->ref_offset + dwarf2_get_u2(data);
|
|
|
|
TRACE("ref2<0x%lx>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref4:
|
|
|
|
attr->u.uvalue = ctx->ref_offset + dwarf2_get_u4(data);
|
|
|
|
TRACE("ref4<0x%lx>\n", attr->u.uvalue);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref8:
|
|
|
|
FIXME("Unhandled 64 bit support\n");
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_sdata:
|
|
|
|
attr->u.svalue = dwarf2_get_leb128_as_signed(data, NULL);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_ref_udata:
|
|
|
|
attr->u.uvalue = dwarf2_get_leb128_as_unsigned(data, NULL);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_udata:
|
|
|
|
attr->u.uvalue = dwarf2_get_leb128_as_unsigned(data, NULL);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_string:
|
|
|
|
attr->u.string = (const char *)data;
|
|
|
|
TRACE("string<%s>\n", attr->u.string);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_strp:
|
|
|
|
{
|
|
|
|
unsigned long offset = dwarf2_get_u4(data);
|
|
|
|
attr->u.string = (const char*)ctx->sections[section_string].address + offset;
|
|
|
|
}
|
|
|
|
TRACE("strp<%s>\n", attr->u.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_FORM_block:
|
|
|
|
attr->u.block.size = dwarf2_get_leb128_as_unsigned(data, &attr->u.block.ptr);
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_block1:
|
|
|
|
attr->u.block.size = dwarf2_get_byte(data);
|
|
|
|
attr->u.block.ptr = data + 1;
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_block2:
|
|
|
|
attr->u.block.size = dwarf2_get_u2(data);
|
|
|
|
attr->u.block.ptr = data + 2;
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
case DW_FORM_block4:
|
|
|
|
attr->u.block.size = dwarf2_get_u4(data);
|
|
|
|
attr->u.block.ptr = data + 4;
|
|
|
|
break;
|
2006-09-25 22:41:10 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled attribute form %lx\n", abbrev_attr->form);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL dwarf2_find_attribute(const dwarf2_parse_context_t* ctx,
|
|
|
|
const dwarf2_debug_info_t* di,
|
|
|
|
unsigned at, struct attribute* attr)
|
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
unsigned i, refidx = 0;
|
2006-11-24 22:18:20 +01:00
|
|
|
dwarf2_abbrev_entry_attr_t* abbrev_attr;
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_abbrev_entry_attr_t* ref_abbrev_attr = NULL;
|
2006-11-24 22:18:20 +01:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
attr->gotten_from = attr_direct;
|
2006-11-24 22:18:20 +01:00
|
|
|
while (di)
|
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
ref_abbrev_attr = NULL;
|
2006-11-24 22:18:20 +01:00
|
|
|
for (i = 0, abbrev_attr = di->abbrev->attrs; abbrev_attr; i++, abbrev_attr = abbrev_attr->next)
|
|
|
|
{
|
|
|
|
if (abbrev_attr->attribute == at)
|
|
|
|
{
|
|
|
|
dwarf2_fill_attr(ctx, abbrev_attr, di->data[i], attr);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-03-08 21:31:02 +01:00
|
|
|
if ((abbrev_attr->attribute == DW_AT_abstract_origin ||
|
|
|
|
abbrev_attr->attribute == DW_AT_specification) &&
|
2006-11-24 22:18:20 +01:00
|
|
|
at != DW_AT_sibling)
|
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
if (ref_abbrev_attr)
|
|
|
|
FIXME("two references %lx and %lx\n", ref_abbrev_attr->attribute, abbrev_attr->attribute);
|
|
|
|
ref_abbrev_attr = abbrev_attr;
|
|
|
|
refidx = i;
|
|
|
|
attr->gotten_from = (abbrev_attr->attribute == DW_AT_abstract_origin) ?
|
|
|
|
attr_abstract_origin : attr_specification;
|
2006-09-25 22:41:10 +02:00
|
|
|
}
|
2006-06-18 21:31:27 +02:00
|
|
|
}
|
2011-03-08 21:31:02 +01:00
|
|
|
/* do we have either an abstract origin or a specification debug entry to look into ? */
|
|
|
|
if (!ref_abbrev_attr) break;
|
|
|
|
dwarf2_fill_attr(ctx, ref_abbrev_attr, di->data[refidx], attr);
|
2006-11-24 22:18:20 +01:00
|
|
|
if (!(di = sparse_array_find(&ctx->debug_info_table, attr->u.uvalue)))
|
|
|
|
FIXME("Should have found the debug info entry\n");
|
2006-06-18 21:31:27 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:31:14 +01:00
|
|
|
static void dwarf2_load_one_entry(dwarf2_parse_context_t*, dwarf2_debug_info_t*);
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2006-09-25 22:40:41 +02:00
|
|
|
#define Wine_DW_no_register 0x7FFFFFFF
|
2006-06-18 21:31:39 +02:00
|
|
|
|
2006-11-24 22:17:31 +01:00
|
|
|
static unsigned dwarf2_map_register(int regno)
|
2006-06-18 21:31:39 +02:00
|
|
|
{
|
2010-03-24 22:04:18 +01:00
|
|
|
if (regno == Wine_DW_no_register)
|
2006-11-24 22:17:31 +01:00
|
|
|
{
|
2010-03-24 22:04:18 +01:00
|
|
|
FIXME("What the heck map reg 0x%x\n",regno);
|
2006-11-24 22:17:31 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2010-03-24 22:04:18 +01:00
|
|
|
return dbghelp_current_cpu->map_dwarf_register(regno);
|
2006-11-24 22:17:31 +01:00
|
|
|
}
|
|
|
|
|
2006-11-24 22:17:59 +01:00
|
|
|
static enum location_error
|
|
|
|
compute_location(dwarf2_traverse_context_t* ctx, struct location* loc,
|
2006-11-24 22:18:04 +01:00
|
|
|
HANDLE hproc, const struct location* frame)
|
2006-11-24 22:17:31 +01:00
|
|
|
{
|
2010-02-08 22:33:19 +01:00
|
|
|
DWORD_PTR tmp, stack[64];
|
2006-06-18 21:31:39 +02:00
|
|
|
unsigned stk;
|
2006-11-24 22:17:31 +01:00
|
|
|
unsigned char op;
|
|
|
|
BOOL piece_found = FALSE;
|
|
|
|
|
|
|
|
stack[stk = 0] = 0;
|
|
|
|
|
|
|
|
loc->kind = loc_absolute;
|
|
|
|
loc->reg = Wine_DW_no_register;
|
|
|
|
|
|
|
|
while (ctx->data < ctx->end_data)
|
|
|
|
{
|
|
|
|
op = dwarf2_parse_byte(ctx);
|
2010-02-08 22:33:19 +01:00
|
|
|
|
|
|
|
if (op >= DW_OP_lit0 && op <= DW_OP_lit31)
|
|
|
|
stack[++stk] = op - DW_OP_lit0;
|
|
|
|
else if (op >= DW_OP_reg0 && op <= DW_OP_reg31)
|
2006-11-24 22:17:31 +01:00
|
|
|
{
|
2006-12-02 17:43:20 +01:00
|
|
|
/* dbghelp APIs don't know how to cope with this anyway
|
|
|
|
* (for example 'long long' stored in two registers)
|
|
|
|
* FIXME: We should tell winedbg how to deal with it (sigh)
|
|
|
|
*/
|
|
|
|
if (!piece_found)
|
|
|
|
{
|
2011-03-13 21:31:17 +01:00
|
|
|
DWORD cvreg = dwarf2_map_register(op - DW_OP_reg0);
|
2006-12-02 17:43:20 +01:00
|
|
|
if (loc->reg != Wine_DW_no_register)
|
2011-03-13 21:31:17 +01:00
|
|
|
FIXME("Only supporting one reg (%s/%d -> %s/%d)\n",
|
|
|
|
dbghelp_current_cpu->fetch_regname(loc->reg), loc->reg,
|
|
|
|
dbghelp_current_cpu->fetch_regname(cvreg), cvreg);
|
|
|
|
loc->reg = cvreg;
|
2006-12-02 17:43:20 +01:00
|
|
|
}
|
|
|
|
loc->kind = loc_register;
|
2010-02-08 22:33:19 +01:00
|
|
|
}
|
|
|
|
else if (op >= DW_OP_breg0 && op <= DW_OP_breg31)
|
|
|
|
{
|
2006-11-24 22:17:31 +01:00
|
|
|
/* dbghelp APIs don't know how to cope with this anyway
|
|
|
|
* (for example 'long long' stored in two registers)
|
|
|
|
* FIXME: We should tell winedbg how to deal with it (sigh)
|
|
|
|
*/
|
2006-11-24 22:18:08 +01:00
|
|
|
if (!piece_found)
|
2006-11-24 22:17:31 +01:00
|
|
|
{
|
2011-03-13 21:31:17 +01:00
|
|
|
DWORD cvreg = dwarf2_map_register(op - DW_OP_breg0);
|
2006-11-24 22:17:31 +01:00
|
|
|
if (loc->reg != Wine_DW_no_register)
|
2011-03-13 21:31:17 +01:00
|
|
|
FIXME("Only supporting one breg (%s/%d -> %s/%d)\n",
|
|
|
|
dbghelp_current_cpu->fetch_regname(loc->reg), loc->reg,
|
|
|
|
dbghelp_current_cpu->fetch_regname(cvreg), cvreg);
|
|
|
|
loc->reg = cvreg;
|
2006-11-24 22:17:31 +01:00
|
|
|
}
|
2006-12-02 17:43:20 +01:00
|
|
|
stack[++stk] = dwarf2_leb128_as_signed(ctx);
|
|
|
|
loc->kind = loc_regrel;
|
2010-02-08 22:33:19 +01:00
|
|
|
}
|
|
|
|
else switch (op)
|
|
|
|
{
|
|
|
|
case DW_OP_nop: break;
|
|
|
|
case DW_OP_addr: stack[++stk] = dwarf2_parse_addr(ctx); break;
|
|
|
|
case DW_OP_const1u: stack[++stk] = dwarf2_parse_byte(ctx); break;
|
|
|
|
case DW_OP_const1s: stack[++stk] = dwarf2_parse_byte(ctx); break;
|
|
|
|
case DW_OP_const2u: stack[++stk] = dwarf2_parse_u2(ctx); break;
|
|
|
|
case DW_OP_const2s: stack[++stk] = dwarf2_parse_u2(ctx); break;
|
|
|
|
case DW_OP_const4u: stack[++stk] = dwarf2_parse_u4(ctx); break;
|
|
|
|
case DW_OP_const4s: stack[++stk] = dwarf2_parse_u4(ctx); break;
|
|
|
|
case DW_OP_const8u: stack[++stk] = dwarf2_parse_u8(ctx); break;
|
|
|
|
case DW_OP_const8s: stack[++stk] = dwarf2_parse_u8(ctx); break;
|
|
|
|
case DW_OP_constu: stack[++stk] = dwarf2_leb128_as_unsigned(ctx); break;
|
|
|
|
case DW_OP_consts: stack[++stk] = dwarf2_leb128_as_signed(ctx); break;
|
|
|
|
case DW_OP_dup: stack[stk + 1] = stack[stk]; stk++; break;
|
|
|
|
case DW_OP_drop: stk--; break;
|
|
|
|
case DW_OP_over: stack[stk + 1] = stack[stk - 1]; stk++; break;
|
|
|
|
case DW_OP_pick: stack[stk + 1] = stack[stk - dwarf2_parse_byte(ctx)]; stk++; break;
|
|
|
|
case DW_OP_swap: tmp = stack[stk]; stack[stk] = stack[stk-1]; stack[stk-1] = tmp; break;
|
|
|
|
case DW_OP_rot: tmp = stack[stk]; stack[stk] = stack[stk-1]; stack[stk-1] = stack[stk-2]; stack[stk-2] = tmp; break;
|
|
|
|
case DW_OP_abs: stack[stk] = labs(stack[stk]); break;
|
|
|
|
case DW_OP_neg: stack[stk] = -stack[stk]; break;
|
|
|
|
case DW_OP_not: stack[stk] = ~stack[stk]; break;
|
|
|
|
case DW_OP_and: stack[stk-1] &= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_or: stack[stk-1] |= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_minus: stack[stk-1] -= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_mul: stack[stk-1] *= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_plus: stack[stk-1] += stack[stk]; stk--; break;
|
|
|
|
case DW_OP_xor: stack[stk-1] ^= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_shl: stack[stk-1] <<= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_shr: stack[stk-1] >>= stack[stk]; stk--; break;
|
|
|
|
case DW_OP_plus_uconst: stack[stk] += dwarf2_leb128_as_unsigned(ctx); break;
|
|
|
|
case DW_OP_shra: stack[stk-1] = stack[stk-1] / (1 << stack[stk]); stk--; break;
|
|
|
|
case DW_OP_div: stack[stk-1] = stack[stk-1] / stack[stk]; stk--; break;
|
|
|
|
case DW_OP_mod: stack[stk-1] = stack[stk-1] % stack[stk]; stk--; break;
|
|
|
|
case DW_OP_ge: stack[stk-1] = (stack[stk-1] >= stack[stk]); stk--; break;
|
|
|
|
case DW_OP_gt: stack[stk-1] = (stack[stk-1] > stack[stk]); stk--; break;
|
|
|
|
case DW_OP_le: stack[stk-1] = (stack[stk-1] <= stack[stk]); stk--; break;
|
|
|
|
case DW_OP_lt: stack[stk-1] = (stack[stk-1] < stack[stk]); stk--; break;
|
|
|
|
case DW_OP_eq: stack[stk-1] = (stack[stk-1] == stack[stk]); stk--; break;
|
|
|
|
case DW_OP_ne: stack[stk-1] = (stack[stk-1] != stack[stk]); stk--; break;
|
|
|
|
case DW_OP_skip: tmp = dwarf2_parse_u2(ctx); ctx->data += tmp; break;
|
|
|
|
case DW_OP_bra: tmp = dwarf2_parse_u2(ctx); if (!stack[stk--]) ctx->data += tmp; break;
|
|
|
|
case DW_OP_regx:
|
2010-03-27 09:08:55 +01:00
|
|
|
tmp = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!piece_found)
|
|
|
|
{
|
|
|
|
if (loc->reg != Wine_DW_no_register)
|
|
|
|
FIXME("Only supporting one reg\n");
|
|
|
|
loc->reg = dwarf2_map_register(tmp);
|
|
|
|
}
|
2010-02-08 22:33:19 +01:00
|
|
|
loc->kind = loc_register;
|
|
|
|
break;
|
|
|
|
case DW_OP_bregx:
|
|
|
|
tmp = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (loc->reg != Wine_DW_no_register)
|
|
|
|
FIXME("Only supporting one regx\n");
|
2010-03-27 09:08:55 +01:00
|
|
|
loc->reg = dwarf2_map_register(tmp);
|
|
|
|
stack[++stk] = dwarf2_leb128_as_signed(ctx);
|
|
|
|
loc->kind = loc_regrel;
|
2010-02-08 22:33:19 +01:00
|
|
|
break;
|
2006-11-24 22:17:31 +01:00
|
|
|
case DW_OP_fbreg:
|
|
|
|
if (loc->reg != Wine_DW_no_register)
|
2011-03-13 21:31:17 +01:00
|
|
|
FIXME("Only supporting one reg (%s/%d -> -2)\n",
|
|
|
|
dbghelp_current_cpu->fetch_regname(loc->reg), loc->reg);
|
2006-11-24 22:17:31 +01:00
|
|
|
if (frame && frame->kind == loc_register)
|
|
|
|
{
|
|
|
|
loc->kind = loc_regrel;
|
|
|
|
loc->reg = frame->reg;
|
|
|
|
stack[++stk] = dwarf2_leb128_as_signed(ctx);
|
|
|
|
}
|
|
|
|
else if (frame && frame->kind == loc_regrel)
|
|
|
|
{
|
|
|
|
loc->kind = loc_regrel;
|
|
|
|
loc->reg = frame->reg;
|
|
|
|
stack[++stk] = dwarf2_leb128_as_signed(ctx) + frame->offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: this could be later optimized by not recomputing
|
|
|
|
* this very location expression
|
|
|
|
*/
|
|
|
|
loc->kind = loc_dwarf2_block;
|
|
|
|
stack[++stk] = dwarf2_leb128_as_signed(ctx);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DW_OP_piece:
|
|
|
|
{
|
|
|
|
unsigned sz = dwarf2_leb128_as_unsigned(ctx);
|
2006-11-24 22:18:08 +01:00
|
|
|
WARN("Not handling OP_piece (size=%d)\n", sz);
|
2006-11-24 22:17:31 +01:00
|
|
|
piece_found = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-24 22:18:04 +01:00
|
|
|
case DW_OP_deref:
|
|
|
|
if (!stk)
|
|
|
|
{
|
|
|
|
FIXME("Unexpected empty stack\n");
|
|
|
|
return loc_err_internal;
|
|
|
|
}
|
|
|
|
if (loc->reg != Wine_DW_no_register)
|
|
|
|
{
|
|
|
|
WARN("Too complex expression for deref\n");
|
|
|
|
return loc_err_too_complex;
|
|
|
|
}
|
|
|
|
if (hproc)
|
|
|
|
{
|
2009-12-12 12:18:28 +01:00
|
|
|
DWORD_PTR addr = stack[stk--];
|
|
|
|
DWORD_PTR deref;
|
2006-11-24 22:18:04 +01:00
|
|
|
|
|
|
|
if (!ReadProcessMemory(hproc, (void*)addr, &deref, sizeof(deref), NULL))
|
|
|
|
{
|
2009-12-12 12:18:28 +01:00
|
|
|
WARN("Couldn't read memory at %lx\n", addr);
|
2006-11-24 22:18:04 +01:00
|
|
|
return loc_err_cant_read;
|
|
|
|
}
|
|
|
|
stack[++stk] = deref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loc->kind = loc_dwarf2_block;
|
|
|
|
}
|
|
|
|
break;
|
2010-02-08 22:33:19 +01:00
|
|
|
case DW_OP_deref_size:
|
|
|
|
if (!stk)
|
|
|
|
{
|
|
|
|
FIXME("Unexpected empty stack\n");
|
|
|
|
return loc_err_internal;
|
|
|
|
}
|
|
|
|
if (loc->reg != Wine_DW_no_register)
|
|
|
|
{
|
|
|
|
WARN("Too complex expression for deref\n");
|
|
|
|
return loc_err_too_complex;
|
|
|
|
}
|
|
|
|
if (hproc)
|
|
|
|
{
|
|
|
|
DWORD_PTR addr = stack[stk--];
|
|
|
|
BYTE derefsize = dwarf2_parse_byte(ctx);
|
|
|
|
DWORD64 deref;
|
|
|
|
|
|
|
|
if (!ReadProcessMemory(hproc, (void*)addr, &deref, derefsize, NULL))
|
|
|
|
{
|
|
|
|
WARN("Couldn't read memory at %lx\n", addr);
|
|
|
|
return loc_err_cant_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (derefsize)
|
|
|
|
{
|
|
|
|
case 1: stack[++stk] = *(unsigned char*)&deref; break;
|
|
|
|
case 2: stack[++stk] = *(unsigned short*)&deref; break;
|
|
|
|
case 4: stack[++stk] = *(DWORD*)&deref; break;
|
|
|
|
case 8: if (ctx->word_size >= derefsize) stack[++stk] = deref; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-13 21:31:11 +01:00
|
|
|
dwarf2_parse_byte(ctx);
|
|
|
|
loc->kind = loc_dwarf2_block;
|
2010-02-08 22:33:19 +01:00
|
|
|
}
|
|
|
|
break;
|
2010-05-31 22:08:28 +02:00
|
|
|
case DW_OP_stack_value:
|
|
|
|
/* Expected behaviour is that this is the last instruction of this
|
|
|
|
* expression and just the "top of stack" value should be put to loc->offset. */
|
|
|
|
break;
|
2006-11-24 22:17:31 +01:00
|
|
|
default:
|
2009-06-28 14:04:27 +02:00
|
|
|
if (op < DW_OP_lo_user) /* as DW_OP_hi_user is 0xFF, we don't need to test against it */
|
|
|
|
FIXME("Unhandled attr op: %x\n", op);
|
|
|
|
/* FIXME else unhandled extension */
|
2006-11-24 22:17:59 +01:00
|
|
|
return loc_err_internal;
|
2006-11-24 22:17:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
loc->offset = stack[stk];
|
2006-11-24 22:17:59 +01:00
|
|
|
return 0;
|
2006-11-24 22:17:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL dwarf2_compute_location_attr(dwarf2_parse_context_t* ctx,
|
2007-04-18 00:19:45 +02:00
|
|
|
const dwarf2_debug_info_t* di,
|
2006-11-24 22:17:31 +01:00
|
|
|
unsigned long dw,
|
|
|
|
struct location* loc,
|
|
|
|
const struct location* frame)
|
|
|
|
{
|
2006-09-25 22:41:27 +02:00
|
|
|
struct attribute xloc;
|
|
|
|
|
|
|
|
if (!dwarf2_find_attribute(ctx, di, dw, &xloc)) return FALSE;
|
2006-06-18 21:31:39 +02:00
|
|
|
|
2006-09-25 22:41:27 +02:00
|
|
|
switch (xloc.form)
|
|
|
|
{
|
|
|
|
case DW_FORM_data1: case DW_FORM_data2:
|
|
|
|
case DW_FORM_udata: case DW_FORM_sdata:
|
2006-11-24 22:17:31 +01:00
|
|
|
loc->kind = loc_absolute;
|
|
|
|
loc->reg = 0;
|
|
|
|
loc->offset = xloc.u.uvalue;
|
|
|
|
return TRUE;
|
|
|
|
case DW_FORM_data4: case DW_FORM_data8:
|
|
|
|
loc->kind = loc_dwarf2_location_list;
|
|
|
|
loc->reg = Wine_DW_no_register;
|
|
|
|
loc->offset = xloc.u.uvalue;
|
2006-09-25 22:41:27 +02:00
|
|
|
return TRUE;
|
2010-03-27 09:08:44 +01:00
|
|
|
case DW_FORM_block:
|
|
|
|
case DW_FORM_block1:
|
|
|
|
case DW_FORM_block2:
|
|
|
|
case DW_FORM_block4:
|
|
|
|
break;
|
|
|
|
default: FIXME("Unsupported yet form %lx\n", xloc.form);
|
|
|
|
return FALSE;
|
2006-09-25 22:41:27 +02:00
|
|
|
}
|
2006-11-24 22:17:31 +01:00
|
|
|
|
2006-09-25 22:41:27 +02:00
|
|
|
/* assume we have a block form */
|
2006-06-18 21:31:39 +02:00
|
|
|
|
2006-09-25 22:41:27 +02:00
|
|
|
if (xloc.u.block.size)
|
2006-06-18 21:31:39 +02:00
|
|
|
{
|
2006-11-24 22:17:59 +01:00
|
|
|
dwarf2_traverse_context_t lctx;
|
|
|
|
enum location_error err;
|
2006-06-18 21:31:39 +02:00
|
|
|
|
2006-09-25 22:41:27 +02:00
|
|
|
lctx.data = xloc.u.block.ptr;
|
|
|
|
lctx.end_data = xloc.u.block.ptr + xloc.u.block.size;
|
2010-03-24 22:04:06 +01:00
|
|
|
lctx.word_size = ctx->module->format_info[DFI_DWARF]->u.dwarf2_info->word_size;
|
2006-06-18 21:31:39 +02:00
|
|
|
|
2006-11-24 22:18:04 +01:00
|
|
|
err = compute_location(&lctx, loc, NULL, frame);
|
2006-11-24 22:17:59 +01:00
|
|
|
if (err < 0)
|
2006-11-24 22:17:47 +01:00
|
|
|
{
|
|
|
|
loc->kind = loc_error;
|
2006-11-24 22:17:59 +01:00
|
|
|
loc->reg = err;
|
2006-11-24 22:17:47 +01:00
|
|
|
}
|
|
|
|
else if (loc->kind == loc_dwarf2_block)
|
|
|
|
{
|
|
|
|
unsigned* ptr = pool_alloc(&ctx->module->pool,
|
|
|
|
sizeof(unsigned) + xloc.u.block.size);
|
|
|
|
*ptr = xloc.u.block.size;
|
|
|
|
memcpy(ptr + 1, xloc.u.block.ptr, xloc.u.block.size);
|
|
|
|
loc->offset = (unsigned long)ptr;
|
|
|
|
}
|
2006-06-18 21:31:39 +02:00
|
|
|
}
|
2006-09-25 22:41:27 +02:00
|
|
|
return TRUE;
|
2006-06-18 21:31:39 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_lookup_type(dwarf2_parse_context_t* ctx,
|
|
|
|
const dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2011-03-26 12:16:39 +01:00
|
|
|
struct attribute attr;
|
|
|
|
dwarf2_debug_info_t* type;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-26 12:16:39 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_type, &attr))
|
|
|
|
return NULL;
|
|
|
|
if (!(type = sparse_array_find(&ctx->debug_info_table, attr.u.uvalue)))
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-26 12:16:39 +01:00
|
|
|
FIXME("Unable to find back reference to type %lx\n", attr.u.uvalue);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!type->symt)
|
|
|
|
{
|
|
|
|
/* load the debug info entity */
|
|
|
|
dwarf2_load_one_entry(ctx, type);
|
2006-06-18 21:31:32 +02:00
|
|
|
if (!type->symt)
|
2011-03-26 12:16:39 +01:00
|
|
|
FIXME("Unable to load forward reference for tag %lx\n", type->abbrev->tag);
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2011-03-26 12:16:39 +01:00
|
|
|
return type->symt;
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:30:56 +01:00
|
|
|
static const char* dwarf2_get_cpp_name(dwarf2_parse_context_t* ctx, dwarf2_debug_info_t* di, const char* name)
|
|
|
|
{
|
|
|
|
char* last;
|
|
|
|
struct attribute diname;
|
2011-03-08 21:31:26 +01:00
|
|
|
struct attribute spec;
|
2011-03-08 21:30:56 +01:00
|
|
|
|
|
|
|
if (di->abbrev->tag == DW_TAG_compile_unit) return name;
|
|
|
|
if (!ctx->cpp_name)
|
|
|
|
ctx->cpp_name = pool_alloc(&ctx->pool, MAX_SYM_NAME);
|
2011-03-09 22:57:19 +01:00
|
|
|
last = ctx->cpp_name + MAX_SYM_NAME - strlen(name) - 1;
|
2011-03-08 21:30:56 +01:00
|
|
|
strcpy(last, name);
|
2011-03-08 21:31:26 +01:00
|
|
|
|
|
|
|
/* if the di is a definition, but has also a (previous) declaration, then scope must
|
|
|
|
* be gotten from declaration not definition
|
|
|
|
*/
|
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_specification, &spec) && spec.gotten_from == attr_direct)
|
|
|
|
{
|
|
|
|
di = sparse_array_find(&ctx->debug_info_table, spec.u.uvalue);
|
|
|
|
if (!di)
|
|
|
|
{
|
|
|
|
FIXME("Should have found the debug info entry\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:30:56 +01:00
|
|
|
for (di = di->parent; di; di = di->parent)
|
|
|
|
{
|
|
|
|
switch (di->abbrev->tag)
|
|
|
|
{
|
|
|
|
case DW_TAG_namespace:
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_class_type:
|
|
|
|
case DW_TAG_interface_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_name, &diname))
|
|
|
|
{
|
|
|
|
size_t len = strlen(diname.u.string);
|
|
|
|
last -= 2 + len;
|
|
|
|
if (last < ctx->cpp_name) return NULL;
|
|
|
|
memcpy(last, diname.u.string, len);
|
|
|
|
last[len] = last[len + 1] = ':';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2011-01-18 21:49:05 +01:00
|
|
|
/******************************************************************
|
|
|
|
* dwarf2_read_range
|
|
|
|
*
|
|
|
|
* read a range for a given debug_info (either using AT_range attribute, in which
|
|
|
|
* case we don't return all the details, or using AT_low_pc & AT_high_pc attributes)
|
|
|
|
* in all cases, range is relative to beginning of compilation unit
|
|
|
|
*/
|
|
|
|
static BOOL dwarf2_read_range(dwarf2_parse_context_t* ctx, const dwarf2_debug_info_t* di,
|
|
|
|
unsigned long* plow, unsigned long* phigh)
|
|
|
|
{
|
|
|
|
struct attribute range;
|
|
|
|
|
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_ranges, &range))
|
|
|
|
{
|
|
|
|
dwarf2_traverse_context_t traverse;
|
|
|
|
unsigned long low, high;
|
|
|
|
|
|
|
|
traverse.data = ctx->sections[section_ranges].address + range.u.uvalue;
|
|
|
|
traverse.end_data = ctx->sections[section_ranges].address +
|
|
|
|
ctx->sections[section_ranges].size;
|
|
|
|
traverse.word_size = ctx->module->format_info[DFI_DWARF]->u.dwarf2_info->word_size;
|
|
|
|
|
|
|
|
*plow = ULONG_MAX;
|
|
|
|
*phigh = 0;
|
|
|
|
while (traverse.data + 2 * traverse.word_size < traverse.end_data)
|
|
|
|
{
|
|
|
|
low = dwarf2_parse_addr(&traverse);
|
|
|
|
high = dwarf2_parse_addr(&traverse);
|
|
|
|
if (low == 0 && high == 0) break;
|
|
|
|
if (low == ULONG_MAX) FIXME("unsupported yet (base address selection)\n");
|
|
|
|
if (low < *plow) *plow = low;
|
|
|
|
if (high > *phigh) *phigh = high;
|
|
|
|
}
|
|
|
|
if (*plow == ULONG_MAX || *phigh == 0) {FIXME("no entry found\n"); return FALSE;}
|
|
|
|
if (*plow == *phigh) {FIXME("entry found, but low=high\n"); return FALSE;}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct attribute low_pc;
|
|
|
|
struct attribute high_pc;
|
|
|
|
|
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_low_pc, &low_pc) ||
|
|
|
|
!dwarf2_find_attribute(ctx, di, DW_AT_high_pc, &high_pc))
|
|
|
|
return FALSE;
|
|
|
|
*plow = low_pc.u.uvalue;
|
|
|
|
*phigh = high_pc.u.uvalue;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:17 +02:00
|
|
|
/******************************************************************
|
|
|
|
* dwarf2_read_one_debug_info
|
|
|
|
*
|
|
|
|
* Loads into memory one debug info entry, and recursively its children (if any)
|
|
|
|
*/
|
|
|
|
static BOOL dwarf2_read_one_debug_info(dwarf2_parse_context_t* ctx,
|
2006-06-18 21:32:09 +02:00
|
|
|
dwarf2_traverse_context_t* traverse,
|
2011-03-08 21:30:47 +01:00
|
|
|
dwarf2_debug_info_t* parent_di,
|
2006-06-18 21:31:17 +02:00
|
|
|
dwarf2_debug_info_t** pdi)
|
|
|
|
{
|
|
|
|
const dwarf2_abbrev_entry_t*abbrev;
|
|
|
|
unsigned long entry_code;
|
|
|
|
unsigned long offset;
|
|
|
|
dwarf2_debug_info_t* di;
|
|
|
|
dwarf2_debug_info_t* child;
|
|
|
|
dwarf2_debug_info_t** where;
|
|
|
|
dwarf2_abbrev_entry_attr_t* attr;
|
|
|
|
unsigned i;
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute sibling;
|
2006-06-18 21:31:17 +02:00
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
offset = traverse->data - ctx->sections[ctx->section].address;
|
2006-06-18 21:32:09 +02:00
|
|
|
entry_code = dwarf2_leb128_as_unsigned(traverse);
|
2006-06-18 21:31:17 +02:00
|
|
|
TRACE("found entry_code %lu at 0x%lx\n", entry_code, offset);
|
|
|
|
if (!entry_code)
|
|
|
|
{
|
|
|
|
*pdi = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
abbrev = dwarf2_abbrev_table_find_entry(&ctx->abbrev_table, entry_code);
|
|
|
|
if (!abbrev)
|
|
|
|
{
|
|
|
|
WARN("Cannot find abbrev entry for %lu at 0x%lx\n", entry_code, offset);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
di = sparse_array_add(&ctx->debug_info_table, offset, &ctx->pool);
|
|
|
|
if (!di) return FALSE;
|
|
|
|
di->abbrev = abbrev;
|
|
|
|
di->symt = NULL;
|
2011-03-08 21:30:47 +01:00
|
|
|
di->parent = parent_di;
|
2006-06-18 21:31:17 +02:00
|
|
|
|
|
|
|
if (abbrev->num_attr)
|
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
di->data = pool_alloc(&ctx->pool, abbrev->num_attr * sizeof(const char*));
|
2006-06-18 21:31:17 +02:00
|
|
|
for (i = 0, attr = abbrev->attrs; attr; i++, attr = attr->next)
|
|
|
|
{
|
2006-09-25 22:41:10 +02:00
|
|
|
di->data[i] = traverse->data;
|
|
|
|
dwarf2_swallow_attribute(traverse, attr);
|
2006-06-18 21:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
2006-09-25 22:41:10 +02:00
|
|
|
else di->data = NULL;
|
2006-06-18 21:31:17 +02:00
|
|
|
if (abbrev->have_child)
|
|
|
|
{
|
|
|
|
vector_init(&di->children, sizeof(dwarf2_debug_info_t*), 16);
|
2006-06-18 21:32:09 +02:00
|
|
|
while (traverse->data < traverse->end_data)
|
2006-06-18 21:31:17 +02:00
|
|
|
{
|
2011-03-08 21:30:47 +01:00
|
|
|
if (!dwarf2_read_one_debug_info(ctx, traverse, di, &child)) return FALSE;
|
2006-06-18 21:31:17 +02:00
|
|
|
if (!child) break;
|
|
|
|
where = vector_add(&di->children, &ctx->pool);
|
|
|
|
if (!where) return FALSE;
|
|
|
|
*where = child;
|
|
|
|
}
|
|
|
|
}
|
2006-09-25 22:41:10 +02:00
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_sibling, &sibling) &&
|
|
|
|
traverse->data != ctx->sections[ctx->section].address + sibling.u.uvalue)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
|
|
|
WARN("setting cursor for %s to next sibling <0x%lx>\n",
|
2006-09-25 22:40:58 +02:00
|
|
|
dwarf2_debug_traverse_ctx(traverse), sibling.u.uvalue);
|
2006-09-25 22:41:10 +02:00
|
|
|
traverse->data = ctx->sections[ctx->section].address + sibling.u.uvalue;
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2006-06-18 21:31:17 +02:00
|
|
|
*pdi = di;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
static struct vector* dwarf2_get_di_children(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
|
|
|
{
|
|
|
|
struct attribute spec;
|
|
|
|
|
|
|
|
while (di)
|
|
|
|
{
|
|
|
|
if (di->abbrev->have_child)
|
|
|
|
return &di->children;
|
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_specification, &spec)) break;
|
|
|
|
if (!(di = sparse_array_find(&ctx->debug_info_table, spec.u.uvalue)))
|
|
|
|
FIXME("Should have found the debug info entry\n");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-18 11:46:12 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute size;
|
|
|
|
struct attribute encoding;
|
2006-06-18 21:31:32 +02:00
|
|
|
enum BasicType bt;
|
2008-02-06 21:56:06 +01:00
|
|
|
int cache_idx = -1;
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
2005-05-19 13:14:39 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name))
|
|
|
|
name.u.string = NULL;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
|
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_encoding, &encoding)) encoding.u.uvalue = DW_ATE_void;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2006-09-25 22:40:58 +02:00
|
|
|
switch (encoding.u.uvalue)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
|
|
|
case DW_ATE_void: bt = btVoid; break;
|
|
|
|
case DW_ATE_address: bt = btULong; break;
|
|
|
|
case DW_ATE_boolean: bt = btBool; break;
|
|
|
|
case DW_ATE_complex_float: bt = btComplex; break;
|
|
|
|
case DW_ATE_float: bt = btFloat; break;
|
|
|
|
case DW_ATE_signed: bt = btInt; break;
|
|
|
|
case DW_ATE_unsigned: bt = btUInt; break;
|
|
|
|
case DW_ATE_signed_char: bt = btChar; break;
|
|
|
|
case DW_ATE_unsigned_char: bt = btChar; break;
|
|
|
|
default: bt = btNoType; break;
|
|
|
|
}
|
2006-09-25 22:40:58 +02:00
|
|
|
di->symt = &symt_new_basic(ctx->module, bt, name.u.string, size.u.uvalue)->symt;
|
2008-02-06 21:56:06 +01:00
|
|
|
switch (bt)
|
|
|
|
{
|
|
|
|
case btVoid:
|
|
|
|
assert(size.u.uvalue == 0);
|
|
|
|
cache_idx = sc_void;
|
|
|
|
break;
|
|
|
|
case btInt:
|
|
|
|
switch (size.u.uvalue)
|
|
|
|
{
|
|
|
|
case 1: cache_idx = sc_int1; break;
|
|
|
|
case 2: cache_idx = sc_int2; break;
|
|
|
|
case 4: cache_idx = sc_int4; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2008-02-12 21:25:33 +01:00
|
|
|
if (cache_idx != -1 && !ctx->symt_cache[cache_idx])
|
2008-02-06 21:56:06 +01:00
|
|
|
ctx->symt_cache[cache_idx] = di->symt;
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-06-18 21:31:32 +02:00
|
|
|
return di->symt;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_typedef(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct symt* ref_type;
|
|
|
|
struct attribute name;
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), di->abbrev->entry_code);
|
|
|
|
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
|
2006-06-18 21:31:32 +02:00
|
|
|
ref_type = dwarf2_lookup_type(ctx, di);
|
|
|
|
|
2006-09-25 22:40:58 +02:00
|
|
|
if (name.u.string)
|
|
|
|
di->symt = &symt_new_typedef(ctx->module, ref_type, name.u.string)->symt;
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-06-18 21:31:32 +02:00
|
|
|
return di->symt;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_pointer_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct symt* ref_type;
|
|
|
|
struct attribute size;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-19 13:14:39 +02:00
|
|
|
|
2011-01-13 20:09:44 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = sizeof(void *);
|
2006-11-24 22:18:31 +01:00
|
|
|
if (!(ref_type = dwarf2_lookup_type(ctx, di)))
|
2008-02-06 21:56:06 +01:00
|
|
|
{
|
|
|
|
ref_type = ctx->symt_cache[sc_void];
|
|
|
|
assert(ref_type);
|
|
|
|
}
|
2011-01-13 20:09:44 +01:00
|
|
|
di->symt = &symt_new_pointer(ctx->module, ref_type, size.u.uvalue)->symt;
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-06-18 21:31:32 +02:00
|
|
|
return di->symt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt* ref_type;
|
|
|
|
struct symt* idx_type = NULL;
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute min, max, cnt;
|
2006-06-18 21:31:32 +02:00
|
|
|
dwarf2_debug_info_t* child;
|
2011-03-08 21:31:02 +01:00
|
|
|
unsigned int i;
|
|
|
|
const struct vector* children;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2010-06-07 21:48:36 +02:00
|
|
|
ref_type = dwarf2_lookup_type(ctx, di);
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (!(children = dwarf2_get_di_children(ctx, di)))
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2010-06-07 21:48:36 +02:00
|
|
|
/* fake an array with unknown size */
|
|
|
|
/* FIXME: int4 even on 64bit machines??? */
|
|
|
|
idx_type = ctx->symt_cache[sc_int4];
|
|
|
|
min.u.uvalue = 0;
|
|
|
|
max.u.uvalue = -1;
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2011-03-08 21:31:02 +01:00
|
|
|
else for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2006-06-18 21:31:32 +02:00
|
|
|
switch (child->abbrev->tag)
|
|
|
|
{
|
|
|
|
case DW_TAG_subrange_type:
|
|
|
|
idx_type = dwarf2_lookup_type(ctx, child);
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, child, DW_AT_lower_bound, &min))
|
2006-09-25 22:40:58 +02:00
|
|
|
min.u.uvalue = 0;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, child, DW_AT_upper_bound, &max))
|
2006-09-25 22:40:58 +02:00
|
|
|
max.u.uvalue = 0;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (dwarf2_find_attribute(ctx, child, DW_AT_count, &cnt))
|
2006-09-25 22:40:58 +02:00
|
|
|
max.u.uvalue = min.u.uvalue + cnt.u.uvalue;
|
2006-06-18 21:31:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-09-25 22:40:58 +02:00
|
|
|
di->symt = &symt_new_array(ctx->module, min.u.uvalue, max.u.uvalue, ref_type, idx_type)->symt;
|
2006-06-18 21:31:32 +02:00
|
|
|
return di->symt;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_const_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt* ref_type;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
2011-04-11 20:47:05 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2011-04-11 20:47:05 +02:00
|
|
|
if (!(ref_type = dwarf2_lookup_type(ctx, di)))
|
|
|
|
{
|
|
|
|
ref_type = ctx->symt_cache[sc_void];
|
|
|
|
assert(ref_type);
|
|
|
|
}
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-06-18 21:31:32 +02:00
|
|
|
di->symt = ref_type;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
return ref_type;
|
2005-05-19 13:14:39 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:42 +02:00
|
|
|
static struct symt* dwarf2_parse_volatile_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
|
|
|
{
|
|
|
|
struct symt* ref_type;
|
|
|
|
|
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
2011-03-26 12:16:45 +01:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2006-09-25 22:41:42 +02:00
|
|
|
|
2011-03-26 12:16:45 +01:00
|
|
|
if (!(ref_type = dwarf2_lookup_type(ctx, di)))
|
|
|
|
{
|
|
|
|
ref_type = ctx->symt_cache[sc_void];
|
|
|
|
assert(ref_type);
|
|
|
|
}
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-09-25 22:41:42 +02:00
|
|
|
di->symt = ref_type;
|
|
|
|
|
|
|
|
return ref_type;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_reference_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-19 13:14:39 +02:00
|
|
|
{
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt* ref_type = NULL;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
ref_type = dwarf2_lookup_type(ctx, di);
|
|
|
|
/* FIXME: for now, we hard-wire C++ references to pointers */
|
2011-01-13 20:09:44 +01:00
|
|
|
di->symt = &symt_new_pointer(ctx->module, ref_type, sizeof(void *))->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
return di->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static void dwarf2_parse_udt_member(dwarf2_parse_context_t* ctx,
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_debug_info_t* di,
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt_udt* parent)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt* elt_type;
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute bit_size;
|
|
|
|
struct attribute bit_offset;
|
2006-11-24 22:17:31 +01:00
|
|
|
struct location loc;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
assert(parent);
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
|
2006-06-18 21:31:32 +02:00
|
|
|
elt_type = dwarf2_lookup_type(ctx, di);
|
2006-11-24 22:17:31 +01:00
|
|
|
if (dwarf2_compute_location_attr(ctx, di, DW_AT_data_member_location, &loc, NULL))
|
|
|
|
{
|
|
|
|
if (loc.kind != loc_absolute)
|
|
|
|
{
|
|
|
|
FIXME("Found register, while not expecting it\n");
|
|
|
|
loc.offset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("found member_location at %s -> %lu\n",
|
|
|
|
dwarf2_debug_ctx(ctx), loc.offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loc.offset = 0;
|
2006-11-24 22:18:20 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_bit_size, &bit_size))
|
|
|
|
bit_size.u.uvalue = 0;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_bit_offset, &bit_offset))
|
2006-06-18 21:32:06 +02:00
|
|
|
{
|
|
|
|
/* FIXME: we should only do this when implementation is LSB (which is
|
|
|
|
* the case on i386 processors)
|
|
|
|
*/
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute nbytes;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &nbytes))
|
2006-06-18 21:32:06 +02:00
|
|
|
{
|
|
|
|
DWORD64 size;
|
2009-12-14 22:05:46 +01:00
|
|
|
nbytes.u.uvalue = symt_get_info(ctx->module, elt_type, TI_GET_LENGTH, &size) ?
|
|
|
|
(unsigned long)size : 0;
|
2006-06-18 21:32:06 +02:00
|
|
|
}
|
2006-09-25 22:40:58 +02:00
|
|
|
bit_offset.u.uvalue = nbytes.u.uvalue * 8 - bit_offset.u.uvalue - bit_size.u.uvalue;
|
2006-06-18 21:32:06 +02:00
|
|
|
}
|
2006-09-25 22:40:58 +02:00
|
|
|
else bit_offset.u.uvalue = 0;
|
|
|
|
symt_add_udt_element(ctx->module, parent, name.u.string, elt_type,
|
2006-11-24 22:17:31 +01:00
|
|
|
(loc.offset << 3) + bit_offset.u.uvalue,
|
|
|
|
bit_size.u.uvalue);
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
|
|
|
|
2011-03-08 21:31:20 +01:00
|
|
|
static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di);
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_udt_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di,
|
|
|
|
enum UdtKind udt)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute size;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t*child;
|
|
|
|
unsigned int i;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
|
2011-03-08 21:31:32 +01:00
|
|
|
/* quirk... FIXME provide real support for anonymous UDTs */
|
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name))
|
|
|
|
name.u.string = "zz_anon_zz";
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:30:56 +01:00
|
|
|
di->symt = &symt_new_udt(ctx->module, dwarf2_get_cpp_name(ctx, di, name.u.string),
|
|
|
|
size.u.uvalue, udt)->symt;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_member:
|
|
|
|
/* FIXME: should I follow the sibling stuff ?? */
|
|
|
|
dwarf2_parse_udt_member(ctx, child, (struct symt_udt*)di->symt);
|
|
|
|
break;
|
|
|
|
case DW_TAG_enumeration_type:
|
|
|
|
dwarf2_parse_enumeration_type(ctx, child);
|
|
|
|
break;
|
2011-03-08 21:31:20 +01:00
|
|
|
case DW_TAG_subprogram:
|
|
|
|
dwarf2_parse_subprogram(ctx, child);
|
|
|
|
break;
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_class_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
case DW_TAG_typedef:
|
|
|
|
/* FIXME: we need to handle nested udt definitions */
|
|
|
|
case DW_TAG_inheritance:
|
|
|
|
case DW_TAG_template_type_param:
|
|
|
|
case DW_TAG_template_value_param:
|
|
|
|
case DW_TAG_variable:
|
|
|
|
case DW_TAG_imported_declaration:
|
|
|
|
case DW_TAG_ptr_to_member_type:
|
|
|
|
/* FIXME: some C++ related stuff */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
break;
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
return di->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static void dwarf2_parse_enumerator(dwarf2_parse_context_t* ctx,
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_debug_info_t* di,
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt_enum* parent)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute value;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2007-02-18 12:15:37 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) return;
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_const_value, &value)) value.u.svalue = 0;
|
2006-09-25 22:40:58 +02:00
|
|
|
symt_add_enum_element(ctx->module, parent, name.u.string, value.u.svalue);
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(ctx, di)) FIXME("Unsupported children\n");
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_enumeration_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute size;
|
2008-02-06 21:55:59 +01:00
|
|
|
struct symt_basic* basetype;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t*child;
|
|
|
|
unsigned int i;
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->symt) return di->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name)) name.u.string = NULL;
|
2008-02-06 21:55:59 +01:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 4;
|
|
|
|
|
|
|
|
switch (size.u.uvalue) /* FIXME: that's wrong */
|
|
|
|
{
|
|
|
|
case 1: basetype = symt_new_basic(ctx->module, btInt, "char", 1); break;
|
|
|
|
case 2: basetype = symt_new_basic(ctx->module, btInt, "short", 2); break;
|
|
|
|
default:
|
|
|
|
case 4: basetype = symt_new_basic(ctx->module, btInt, "int", 4); break;
|
|
|
|
}
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2008-02-06 21:55:59 +01:00
|
|
|
di->symt = &symt_new_enum(ctx->module, name.u.string, &basetype->symt)->symt;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(ctx, di);
|
|
|
|
/* FIXME: should we use the sibling stuff ?? */
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_enumerator:
|
|
|
|
dwarf2_parse_enumerator(ctx, child, (struct symt_enum*)di->symt);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
di->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return di->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
/* structure used to pass information around when parsing a subprogram */
|
|
|
|
typedef struct dwarf2_subprogram_s
|
|
|
|
{
|
|
|
|
dwarf2_parse_context_t* ctx;
|
|
|
|
struct symt_function* func;
|
2006-11-24 22:17:59 +01:00
|
|
|
BOOL non_computed_variable;
|
2006-11-24 22:17:31 +01:00
|
|
|
struct location frame;
|
2006-06-18 21:32:03 +02:00
|
|
|
} dwarf2_subprogram_t;
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* dwarf2_parse_variable
|
|
|
|
*
|
|
|
|
* Parses any variable (parameter, local/global variable)
|
|
|
|
*/
|
|
|
|
static void dwarf2_parse_variable(dwarf2_subprogram_t* subpgm,
|
|
|
|
struct symt_block* block,
|
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-11-24 22:18:20 +01:00
|
|
|
struct symt* param_type;
|
|
|
|
struct attribute name, value;
|
|
|
|
struct location loc;
|
|
|
|
BOOL is_pmt;
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-11-24 22:18:20 +01:00
|
|
|
is_pmt = !block && di->abbrev->tag == DW_TAG_formal_parameter;
|
2006-06-18 21:32:03 +02:00
|
|
|
param_type = dwarf2_lookup_type(subpgm->ctx, di);
|
2006-11-24 22:18:20 +01:00
|
|
|
|
2007-02-18 12:15:37 +01:00
|
|
|
if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_name, &name)) {
|
|
|
|
/* cannot do much without the name, the functions below won't like it. */
|
|
|
|
return;
|
|
|
|
}
|
2006-11-24 22:17:31 +01:00
|
|
|
if (dwarf2_compute_location_attr(subpgm->ctx, di, DW_AT_location,
|
|
|
|
&loc, &subpgm->frame))
|
2006-06-18 21:32:00 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute ext;
|
2006-06-18 21:32:00 +02:00
|
|
|
|
2006-11-24 22:17:47 +01:00
|
|
|
TRACE("found parameter %s (kind=%d, offset=%ld, reg=%d) at %s\n",
|
|
|
|
name.u.string, loc.kind, loc.offset, loc.reg,
|
2006-11-24 22:17:31 +01:00
|
|
|
dwarf2_debug_ctx(subpgm->ctx));
|
2006-11-24 22:17:47 +01:00
|
|
|
|
2006-11-24 22:17:31 +01:00
|
|
|
switch (loc.kind)
|
2006-06-18 21:32:03 +02:00
|
|
|
{
|
2009-05-29 12:30:28 +02:00
|
|
|
case loc_error:
|
|
|
|
break;
|
2006-11-24 22:17:31 +01:00
|
|
|
case loc_absolute:
|
2006-06-18 21:32:03 +02:00
|
|
|
/* it's a global variable */
|
2006-11-24 22:17:59 +01:00
|
|
|
/* FIXME: we don't handle its scope yet */
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_external, &ext))
|
2006-09-25 22:40:58 +02:00
|
|
|
ext.u.uvalue = 0;
|
2011-01-29 20:38:04 +01:00
|
|
|
loc.offset += subpgm->ctx->load_offset;
|
2011-03-08 21:31:14 +01:00
|
|
|
symt_new_global_variable(subpgm->ctx->module, subpgm->ctx->compiland,
|
2011-03-08 21:30:56 +01:00
|
|
|
dwarf2_get_cpp_name(subpgm->ctx, di, name.u.string), !ext.u.uvalue,
|
2011-01-29 20:38:04 +01:00
|
|
|
loc, 0, param_type);
|
2006-06-18 21:32:03 +02:00
|
|
|
break;
|
2006-11-24 22:17:47 +01:00
|
|
|
default:
|
2006-11-24 22:17:59 +01:00
|
|
|
subpgm->non_computed_variable = TRUE;
|
2006-11-24 22:17:47 +01:00
|
|
|
/* fall through */
|
2006-11-24 22:17:31 +01:00
|
|
|
case loc_register:
|
|
|
|
case loc_regrel:
|
2006-06-18 21:32:03 +02:00
|
|
|
/* either a pmt/variable relative to frame pointer or
|
|
|
|
* pmt/variable in a register
|
|
|
|
*/
|
2006-09-25 22:41:42 +02:00
|
|
|
assert(subpgm->func);
|
2006-06-18 21:32:03 +02:00
|
|
|
symt_add_func_local(subpgm->ctx->module, subpgm->func,
|
|
|
|
is_pmt ? DataIsParam : DataIsLocal,
|
2006-11-24 22:17:38 +01:00
|
|
|
&loc, block, param_type, name.u.string);
|
2006-06-18 21:32:03 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-06-18 21:32:00 +02:00
|
|
|
}
|
2006-12-05 22:13:30 +01:00
|
|
|
else if (dwarf2_find_attribute(subpgm->ctx, di, DW_AT_const_value, &value))
|
2006-08-03 19:36:10 +02:00
|
|
|
{
|
2006-12-05 22:13:30 +01:00
|
|
|
VARIANT v;
|
2007-02-05 07:20:23 +01:00
|
|
|
if (subpgm->func) WARN("Unsupported constant %s in function\n", name.u.string);
|
2006-12-05 22:13:30 +01:00
|
|
|
if (is_pmt) FIXME("Unsupported constant (parameter) %s in function\n", name.u.string);
|
|
|
|
switch (value.form)
|
|
|
|
{
|
|
|
|
case DW_FORM_data1:
|
|
|
|
case DW_FORM_data2:
|
|
|
|
case DW_FORM_data4:
|
|
|
|
case DW_FORM_udata:
|
2007-12-26 09:51:18 +01:00
|
|
|
case DW_FORM_addr:
|
2006-12-05 22:13:30 +01:00
|
|
|
v.n1.n2.vt = VT_UI4;
|
|
|
|
v.n1.n2.n3.lVal = value.u.uvalue;
|
|
|
|
break;
|
|
|
|
|
2010-03-15 21:12:22 +01:00
|
|
|
case DW_FORM_data8:
|
|
|
|
v.n1.n2.vt = VT_UI8;
|
|
|
|
v.n1.n2.n3.llVal = value.u.lluvalue;
|
|
|
|
break;
|
|
|
|
|
2006-12-05 22:13:30 +01:00
|
|
|
case DW_FORM_sdata:
|
|
|
|
v.n1.n2.vt = VT_I4;
|
|
|
|
v.n1.n2.n3.lVal = value.u.svalue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_FORM_strp:
|
|
|
|
case DW_FORM_string:
|
|
|
|
/* FIXME: native doesn't report const strings from here !!
|
|
|
|
* however, the value of the string is in the code somewhere
|
|
|
|
*/
|
|
|
|
v.n1.n2.vt = VT_I1 | VT_BYREF;
|
|
|
|
v.n1.n2.n3.byref = pool_strdup(&subpgm->ctx->module->pool, value.u.string);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DW_FORM_block:
|
|
|
|
case DW_FORM_block1:
|
|
|
|
case DW_FORM_block2:
|
|
|
|
case DW_FORM_block4:
|
2009-10-03 13:15:43 +02:00
|
|
|
v.n1.n2.vt = VT_I4;
|
|
|
|
switch (value.u.block.size)
|
|
|
|
{
|
|
|
|
case 1: v.n1.n2.n3.lVal = *(BYTE*)value.u.block.ptr; break;
|
|
|
|
case 2: v.n1.n2.n3.lVal = *(USHORT*)value.u.block.ptr; break;
|
|
|
|
case 4: v.n1.n2.n3.lVal = *(DWORD*)value.u.block.ptr; break;
|
|
|
|
default:
|
|
|
|
v.n1.n2.vt = VT_I1 | VT_BYREF;
|
|
|
|
v.n1.n2.n3.byref = pool_alloc(&subpgm->ctx->module->pool, value.u.block.size);
|
|
|
|
memcpy(v.n1.n2.n3.byref, value.u.block.ptr, value.u.block.size);
|
|
|
|
}
|
|
|
|
break;
|
2006-12-05 22:13:30 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported form for const value %s (%lx)\n",
|
|
|
|
name.u.string, value.form);
|
|
|
|
v.n1.n2.vt = VT_EMPTY;
|
|
|
|
}
|
2011-03-08 21:31:14 +01:00
|
|
|
di->symt = &symt_new_constant(subpgm->ctx->module, subpgm->ctx->compiland,
|
2006-12-05 22:13:30 +01:00
|
|
|
name.u.string, param_type, &v)->symt;
|
2006-08-03 19:36:10 +02:00
|
|
|
}
|
2010-08-25 21:43:46 +02:00
|
|
|
else
|
|
|
|
{
|
2011-07-30 12:03:08 +02:00
|
|
|
/* variable has been optimized away... report anyway */
|
2010-08-25 21:43:46 +02:00
|
|
|
loc.kind = loc_error;
|
|
|
|
loc.reg = loc_err_no_location;
|
|
|
|
if (subpgm->func)
|
|
|
|
{
|
|
|
|
symt_add_func_local(subpgm->ctx->module, subpgm->func,
|
|
|
|
is_pmt ? DataIsParam : DataIsLocal,
|
|
|
|
&loc, block, param_type, name.u.string);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("dropping global variable %s which has been optimized away\n", name.u.string);
|
|
|
|
}
|
|
|
|
}
|
2006-06-18 21:32:03 +02:00
|
|
|
if (is_pmt && subpgm->func && subpgm->func->type)
|
|
|
|
symt_add_function_signature_parameter(subpgm->ctx->module,
|
|
|
|
(struct symt_function_signature*)subpgm->func->type,
|
2006-06-18 21:32:00 +02:00
|
|
|
param_type);
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
if (dwarf2_get_di_children(subpgm->ctx, di)) FIXME("Unsupported children\n");
|
2005-05-23 11:50:15 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
static void dwarf2_parse_subprogram_label(dwarf2_subprogram_t* subpgm,
|
2007-04-18 00:19:45 +02:00
|
|
|
const dwarf2_debug_info_t* di)
|
2006-06-18 21:31:49 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
|
|
|
struct attribute low_pc;
|
2006-11-24 22:17:54 +01:00
|
|
|
struct location loc;
|
2006-06-18 21:31:49 +02:00
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
|
2006-06-18 21:31:49 +02:00
|
|
|
|
2006-09-25 22:41:10 +02:00
|
|
|
if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_low_pc, &low_pc)) low_pc.u.uvalue = 0;
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(subpgm->ctx, di, DW_AT_name, &name))
|
|
|
|
name.u.string = NULL;
|
2006-06-18 21:31:49 +02:00
|
|
|
|
2006-11-24 22:17:54 +01:00
|
|
|
loc.kind = loc_absolute;
|
2007-03-15 22:01:06 +01:00
|
|
|
loc.offset = subpgm->ctx->load_offset + low_pc.u.uvalue;
|
2006-06-18 21:32:03 +02:00
|
|
|
symt_add_function_point(subpgm->ctx->module, subpgm->func, SymTagLabel,
|
2006-11-24 22:17:54 +01:00
|
|
|
&loc, name.u.string);
|
2006-06-18 21:31:49 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t* subpgm,
|
2006-11-24 22:18:20 +01:00
|
|
|
struct symt_block* parent_block,
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_debug_info_t* di);
|
2006-06-18 21:31:43 +02:00
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
static void dwarf2_parse_inlined_subroutine(dwarf2_subprogram_t* subpgm,
|
2006-11-24 22:18:20 +01:00
|
|
|
struct symt_block* parent_block,
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-23 11:50:15 +02:00
|
|
|
{
|
2006-11-24 22:18:20 +01:00
|
|
|
struct symt_block* block;
|
2011-01-18 21:49:05 +01:00
|
|
|
unsigned long low_pc, high_pc;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t*child;
|
|
|
|
unsigned int i;
|
2006-11-24 22:18:20 +01:00
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2011-01-18 21:49:05 +01:00
|
|
|
if (!dwarf2_read_range(subpgm->ctx, di, &low_pc, &high_pc))
|
|
|
|
{
|
|
|
|
FIXME("cannot read range\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-11-24 22:18:20 +01:00
|
|
|
|
|
|
|
block = symt_open_func_block(subpgm->ctx->module, subpgm->func, parent_block,
|
2011-01-18 21:49:05 +01:00
|
|
|
subpgm->ctx->load_offset + low_pc - subpgm->func->address,
|
|
|
|
high_pc - low_pc);
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(subpgm->ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_formal_parameter:
|
|
|
|
case DW_TAG_variable:
|
|
|
|
dwarf2_parse_variable(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_lexical_block:
|
|
|
|
dwarf2_parse_subprogram_block(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_inlined_subroutine:
|
|
|
|
dwarf2_parse_inlined_subroutine(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_label:
|
|
|
|
dwarf2_parse_subprogram_label(subpgm, child);
|
|
|
|
break;
|
2011-04-14 21:27:59 +02:00
|
|
|
case DW_TAG_GNU_call_site:
|
|
|
|
/* this isn't properly supported by dbghelp interface. skip it for now */
|
|
|
|
break;
|
2011-03-08 21:31:02 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
child->abbrev->tag, dwarf2_debug_ctx(subpgm->ctx),
|
|
|
|
dwarf2_debug_di(di));
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
|
|
|
}
|
2006-11-24 22:18:20 +01:00
|
|
|
symt_close_func_block(subpgm->ctx->module, subpgm->func, block, 0);
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
static void dwarf2_parse_subprogram_block(dwarf2_subprogram_t* subpgm,
|
2006-06-18 21:32:03 +02:00
|
|
|
struct symt_block* parent_block,
|
2011-03-08 21:31:02 +01:00
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-06-18 21:32:03 +02:00
|
|
|
struct symt_block* block;
|
2011-01-18 21:49:05 +01:00
|
|
|
unsigned long low_pc, high_pc;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t*child;
|
|
|
|
unsigned int i;
|
2005-05-23 11:50:15 +02:00
|
|
|
|
2006-06-18 21:32:03 +02:00
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
|
|
|
|
|
2011-01-18 21:49:05 +01:00
|
|
|
if (!dwarf2_read_range(subpgm->ctx, di, &low_pc, &high_pc))
|
|
|
|
{
|
|
|
|
FIXME("no range\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-06-18 21:32:03 +02:00
|
|
|
|
|
|
|
block = symt_open_func_block(subpgm->ctx->module, subpgm->func, parent_block,
|
2011-01-18 21:49:05 +01:00
|
|
|
subpgm->ctx->load_offset + low_pc - subpgm->func->address,
|
|
|
|
high_pc - low_pc);
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(subpgm->ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2005-12-19 18:22:54 +01:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_inlined_subroutine:
|
|
|
|
dwarf2_parse_inlined_subroutine(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_variable:
|
|
|
|
dwarf2_parse_variable(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_lexical_block:
|
|
|
|
dwarf2_parse_subprogram_block(subpgm, block, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_subprogram:
|
|
|
|
/* FIXME: likely a declaration (to be checked)
|
|
|
|
* skip it for now
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case DW_TAG_formal_parameter:
|
|
|
|
/* FIXME: likely elements for exception handling (GCC flavor)
|
|
|
|
* Skip it for now
|
|
|
|
*/
|
|
|
|
break;
|
2011-04-14 21:27:59 +02:00
|
|
|
case DW_TAG_imported_module:
|
|
|
|
/* C++ stuff to be silenced (for now) */
|
|
|
|
break;
|
|
|
|
case DW_TAG_GNU_call_site:
|
|
|
|
/* this isn't properly supported by dbghelp interface. skip it for now */
|
|
|
|
break;
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_label:
|
|
|
|
dwarf2_parse_subprogram_label(subpgm, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_class_type:
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
case DW_TAG_enumeration_type:
|
|
|
|
case DW_TAG_typedef:
|
|
|
|
/* the type referred to will be loaded when we need it, so skip it */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
child->abbrev->tag, dwarf2_debug_ctx(subpgm->ctx), dwarf2_debug_di(di));
|
2005-12-19 18:22:54 +01:00
|
|
|
}
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
2006-06-18 21:32:03 +02:00
|
|
|
|
|
|
|
symt_close_func_block(subpgm->ctx->module, subpgm->func, block, 0);
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx,
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
2011-01-18 21:49:05 +01:00
|
|
|
unsigned long low_pc, high_pc;
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute is_decl;
|
|
|
|
struct attribute inline_flags;
|
2006-06-18 21:31:32 +02:00
|
|
|
struct symt* ret_type;
|
|
|
|
struct symt_function_signature* sig_type;
|
2006-06-18 21:32:03 +02:00
|
|
|
dwarf2_subprogram_t subpgm;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t* child;
|
|
|
|
unsigned int i;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
|
2008-05-18 09:43:39 +02:00
|
|
|
if (!dwarf2_find_attribute(ctx, di, DW_AT_name, &name))
|
|
|
|
{
|
|
|
|
WARN("No name for function... dropping function\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-24 22:18:20 +01:00
|
|
|
/* if it's an abstract representation of an inline function, there should be
|
|
|
|
* a concrete object that we'll handle
|
|
|
|
*/
|
2011-03-08 21:30:42 +01:00
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_inline, &inline_flags) &&
|
|
|
|
inline_flags.u.uvalue != DW_INL_not_inlined)
|
2006-11-24 22:18:20 +01:00
|
|
|
{
|
|
|
|
TRACE("Function %s declared as inlined (%ld)... skipping\n",
|
2006-11-24 22:18:26 +01:00
|
|
|
name.u.string ? name.u.string : "(null)", inline_flags.u.uvalue);
|
2006-11-24 22:18:20 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:31:26 +01:00
|
|
|
if (dwarf2_find_attribute(ctx, di, DW_AT_declaration, &is_decl) &&
|
|
|
|
is_decl.u.uvalue && is_decl.gotten_from == attr_direct)
|
|
|
|
{
|
|
|
|
/* it's a real declaration, skip it */
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-18 21:49:05 +01:00
|
|
|
if (!dwarf2_read_range(ctx, di, &low_pc, &high_pc))
|
|
|
|
{
|
2011-03-08 21:31:26 +01:00
|
|
|
WARN("cannot get range for %s\n", name.u.string);
|
2011-01-18 21:49:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-06-24 09:50:10 +02:00
|
|
|
/* As functions (defined as inline assembly) get debug info with dwarf
|
|
|
|
* (not the case for stabs), we just drop Wine's thunks here...
|
|
|
|
* Actual thunks will be created in elf_module from the symbol table
|
|
|
|
*/
|
2011-01-18 21:49:05 +01:00
|
|
|
if (elf_is_in_thunk_area(ctx->load_offset + low_pc, ctx->thunks) >= 0)
|
2006-06-24 09:50:10 +02:00
|
|
|
return NULL;
|
2006-11-24 22:18:31 +01:00
|
|
|
if (!(ret_type = dwarf2_lookup_type(ctx, di)))
|
2008-02-06 21:56:06 +01:00
|
|
|
{
|
|
|
|
ret_type = ctx->symt_cache[sc_void];
|
|
|
|
assert(ret_type);
|
|
|
|
}
|
2006-06-18 21:31:32 +02:00
|
|
|
/* FIXME: assuming C source code */
|
|
|
|
sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
|
2011-03-08 21:31:26 +01:00
|
|
|
subpgm.func = symt_new_function(ctx->module, ctx->compiland,
|
|
|
|
dwarf2_get_cpp_name(ctx, di, name.u.string),
|
|
|
|
ctx->load_offset + low_pc, high_pc - low_pc,
|
|
|
|
&sig_type->symt);
|
|
|
|
di->symt = &subpgm.func->symt;
|
2006-06-18 21:32:03 +02:00
|
|
|
subpgm.ctx = ctx;
|
2006-11-24 22:17:31 +01:00
|
|
|
if (!dwarf2_compute_location_attr(ctx, di, DW_AT_frame_base,
|
|
|
|
&subpgm.frame, NULL))
|
2006-06-18 21:32:03 +02:00
|
|
|
{
|
2006-11-24 22:17:31 +01:00
|
|
|
/* on stack !! */
|
|
|
|
subpgm.frame.kind = loc_regrel;
|
2011-04-11 20:47:19 +02:00
|
|
|
subpgm.frame.reg = dbghelp_current_cpu->frame_regno;
|
2006-11-24 22:17:31 +01:00
|
|
|
subpgm.frame.offset = 0;
|
2006-06-18 21:32:03 +02:00
|
|
|
}
|
2006-11-24 22:17:59 +01:00
|
|
|
subpgm.non_computed_variable = FALSE;
|
2006-06-18 21:32:03 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_variable:
|
|
|
|
case DW_TAG_formal_parameter:
|
|
|
|
dwarf2_parse_variable(&subpgm, NULL, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_lexical_block:
|
|
|
|
dwarf2_parse_subprogram_block(&subpgm, NULL, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_inlined_subroutine:
|
|
|
|
dwarf2_parse_inlined_subroutine(&subpgm, NULL, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_subprogram:
|
|
|
|
/* FIXME: likely a declaration (to be checked)
|
|
|
|
* skip it for now
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case DW_TAG_label:
|
|
|
|
dwarf2_parse_subprogram_label(&subpgm, child);
|
|
|
|
break;
|
|
|
|
case DW_TAG_class_type:
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
case DW_TAG_enumeration_type:
|
|
|
|
case DW_TAG_typedef:
|
|
|
|
/* the type referred to will be loaded when we need it, so skip it */
|
|
|
|
break;
|
|
|
|
case DW_TAG_unspecified_parameters:
|
|
|
|
case DW_TAG_template_type_param:
|
|
|
|
case DW_TAG_template_value_param:
|
2011-04-14 21:27:59 +02:00
|
|
|
case DW_TAG_GNU_call_site:
|
2011-03-08 21:31:02 +01:00
|
|
|
/* FIXME: no support in dbghelp's internals so far */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
|
|
|
|
child->abbrev->tag, dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2006-11-24 22:17:59 +01:00
|
|
|
if (subpgm.non_computed_variable || subpgm.frame.kind >= loc_user)
|
|
|
|
{
|
|
|
|
symt_add_function_point(ctx->module, subpgm.func, SymTagCustom,
|
|
|
|
&subpgm.frame, NULL);
|
|
|
|
}
|
2008-05-25 19:29:58 +02:00
|
|
|
if (subpgm.func) symt_normalize_function(subpgm.ctx->module, subpgm.func);
|
2006-06-18 21:31:32 +02:00
|
|
|
|
|
|
|
return di->symt;
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 22:41:42 +02:00
|
|
|
static struct symt* dwarf2_parse_subroutine_type(dwarf2_parse_context_t* ctx,
|
|
|
|
dwarf2_debug_info_t* di)
|
|
|
|
{
|
|
|
|
struct symt* ret_type;
|
|
|
|
struct symt_function_signature* sig_type;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t* child;
|
|
|
|
unsigned int i;
|
2006-09-25 22:41:42 +02:00
|
|
|
|
|
|
|
if (di->symt) return di->symt;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
|
2006-11-24 22:18:31 +01:00
|
|
|
if (!(ret_type = dwarf2_lookup_type(ctx, di)))
|
2008-02-06 21:56:06 +01:00
|
|
|
{
|
|
|
|
ret_type = ctx->symt_cache[sc_void];
|
|
|
|
assert(ret_type);
|
|
|
|
}
|
2006-09-25 22:41:42 +02:00
|
|
|
|
|
|
|
/* FIXME: assuming C source code */
|
|
|
|
sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-09-25 22:41:42 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2006-09-25 22:41:42 +02:00
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
switch (child->abbrev->tag)
|
2006-09-25 22:41:42 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
case DW_TAG_formal_parameter:
|
|
|
|
symt_add_function_signature_parameter(ctx->module, sig_type,
|
|
|
|
dwarf2_lookup_type(ctx, child));
|
|
|
|
break;
|
|
|
|
case DW_TAG_unspecified_parameters:
|
|
|
|
WARN("Unsupported unspecified parameters\n");
|
|
|
|
break;
|
2006-09-25 22:41:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return di->symt = &sig_type->symt;
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:30:56 +01:00
|
|
|
static void dwarf2_parse_namespace(dwarf2_parse_context_t* ctx,
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_debug_info_t* di)
|
2011-03-08 21:30:56 +01:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t* child;
|
|
|
|
unsigned int i;
|
|
|
|
|
2011-03-08 21:30:56 +01:00
|
|
|
if (di->symt) return;
|
|
|
|
|
|
|
|
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
|
|
|
|
|
|
|
|
di->symt = ctx->symt_cache[sc_void];
|
|
|
|
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
|
|
|
{
|
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_load_one_entry(ctx, child);
|
2011-03-08 21:30:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
static void dwarf2_load_one_entry(dwarf2_parse_context_t* ctx,
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_debug_info_t* di)
|
2005-05-20 11:41:10 +02:00
|
|
|
{
|
2006-06-18 21:31:32 +02:00
|
|
|
switch (di->abbrev->tag)
|
|
|
|
{
|
|
|
|
case DW_TAG_typedef:
|
|
|
|
dwarf2_parse_typedef(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_base_type:
|
|
|
|
dwarf2_parse_base_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_pointer_type:
|
|
|
|
dwarf2_parse_pointer_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_class_type:
|
|
|
|
dwarf2_parse_udt_type(ctx, di, UdtClass);
|
|
|
|
break;
|
|
|
|
case DW_TAG_structure_type:
|
|
|
|
dwarf2_parse_udt_type(ctx, di, UdtStruct);
|
|
|
|
break;
|
|
|
|
case DW_TAG_union_type:
|
|
|
|
dwarf2_parse_udt_type(ctx, di, UdtUnion);
|
|
|
|
break;
|
|
|
|
case DW_TAG_array_type:
|
|
|
|
dwarf2_parse_array_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_const_type:
|
|
|
|
dwarf2_parse_const_type(ctx, di);
|
|
|
|
break;
|
2006-09-25 22:41:42 +02:00
|
|
|
case DW_TAG_volatile_type:
|
|
|
|
dwarf2_parse_volatile_type(ctx, di);
|
|
|
|
break;
|
2006-06-18 21:31:32 +02:00
|
|
|
case DW_TAG_reference_type:
|
|
|
|
dwarf2_parse_reference_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_enumeration_type:
|
|
|
|
dwarf2_parse_enumeration_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_subprogram:
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_parse_subprogram(ctx, di);
|
2006-06-18 21:31:32 +02:00
|
|
|
break;
|
2006-09-25 22:41:42 +02:00
|
|
|
case DW_TAG_subroutine_type:
|
|
|
|
dwarf2_parse_subroutine_type(ctx, di);
|
|
|
|
break;
|
|
|
|
case DW_TAG_variable:
|
|
|
|
{
|
|
|
|
dwarf2_subprogram_t subpgm;
|
|
|
|
|
|
|
|
subpgm.ctx = ctx;
|
|
|
|
subpgm.func = NULL;
|
2006-11-24 22:17:31 +01:00
|
|
|
subpgm.frame.kind = loc_absolute;
|
|
|
|
subpgm.frame.offset = 0;
|
|
|
|
subpgm.frame.reg = Wine_DW_no_register;
|
2006-09-25 22:41:42 +02:00
|
|
|
dwarf2_parse_variable(&subpgm, NULL, di);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-29 13:02:39 +01:00
|
|
|
case DW_TAG_namespace:
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_parse_namespace(ctx, di);
|
2011-03-08 21:30:56 +01:00
|
|
|
break;
|
|
|
|
/* silence a couple of C++ defines */
|
2009-12-29 13:02:39 +01:00
|
|
|
case DW_TAG_imported_module:
|
|
|
|
case DW_TAG_imported_declaration:
|
2011-03-08 21:30:36 +01:00
|
|
|
case DW_TAG_ptr_to_member_type:
|
2009-12-29 13:02:39 +01:00
|
|
|
break;
|
2005-05-20 11:41:10 +02:00
|
|
|
default:
|
2006-09-25 22:41:42 +02:00
|
|
|
FIXME("Unhandled Tag type 0x%lx at %s, for %lu\n",
|
|
|
|
di->abbrev->tag, dwarf2_debug_ctx(ctx), di->abbrev->entry_code);
|
2005-05-20 11:41:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:24 +02:00
|
|
|
static void dwarf2_set_line_number(struct module* module, unsigned long address,
|
2007-04-18 00:19:45 +02:00
|
|
|
const struct vector* v, unsigned file, unsigned line)
|
2006-06-18 21:32:24 +02:00
|
|
|
{
|
|
|
|
struct symt_function* func;
|
2006-12-05 22:13:23 +01:00
|
|
|
struct symt_ht* symt;
|
2006-06-18 21:32:24 +02:00
|
|
|
unsigned* psrc;
|
|
|
|
|
|
|
|
if (!file || !(psrc = vector_at(v, file - 1))) return;
|
|
|
|
|
2007-03-13 17:26:33 +01:00
|
|
|
TRACE("%s %lx %s %u\n",
|
|
|
|
debugstr_w(module->module.ModuleName), address, source_get(module, *psrc), line);
|
2006-12-05 22:13:23 +01:00
|
|
|
if (!(symt = symt_find_nearest(module, address)) ||
|
|
|
|
symt->symt.tag != SymTagFunction) return;
|
|
|
|
func = (struct symt_function*)symt;
|
2006-06-18 21:32:24 +02:00
|
|
|
symt_add_func_line(module, func, *psrc, line, address - func->address);
|
|
|
|
}
|
|
|
|
|
2006-11-06 20:05:34 +01:00
|
|
|
static BOOL dwarf2_parse_line_numbers(const dwarf2_section_t* sections,
|
2006-06-18 21:32:17 +02:00
|
|
|
dwarf2_parse_context_t* ctx,
|
2006-11-05 23:30:52 +01:00
|
|
|
const char* compile_dir,
|
2006-06-18 21:32:17 +02:00
|
|
|
unsigned long offset)
|
|
|
|
{
|
|
|
|
dwarf2_traverse_context_t traverse;
|
|
|
|
unsigned long length;
|
2011-04-18 21:57:33 +02:00
|
|
|
unsigned insn_size, default_stmt;
|
2006-06-18 21:32:17 +02:00
|
|
|
unsigned line_range, opcode_base;
|
|
|
|
int line_base;
|
|
|
|
const unsigned char* opcode_len;
|
2006-06-18 21:32:24 +02:00
|
|
|
struct vector dirs;
|
|
|
|
struct vector files;
|
|
|
|
const char** p;
|
2006-06-18 21:32:17 +02:00
|
|
|
|
2006-11-06 20:05:28 +01:00
|
|
|
/* section with line numbers stripped */
|
2010-03-18 21:30:47 +01:00
|
|
|
if (sections[section_line].address == IMAGE_NO_MAP)
|
2006-11-06 20:05:34 +01:00
|
|
|
return FALSE;
|
2006-11-06 20:05:28 +01:00
|
|
|
|
2011-03-19 16:58:27 +01:00
|
|
|
if (offset + 4 > sections[section_line].size)
|
|
|
|
{
|
|
|
|
WARN("out of bounds offset\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-06-18 21:32:17 +02:00
|
|
|
traverse.data = sections[section_line].address + offset;
|
|
|
|
traverse.end_data = traverse.data + 4;
|
2010-03-24 22:04:06 +01:00
|
|
|
traverse.word_size = ctx->module->format_info[DFI_DWARF]->u.dwarf2_info->word_size;
|
2006-06-18 21:32:17 +02:00
|
|
|
|
|
|
|
length = dwarf2_parse_u4(&traverse);
|
2010-03-20 09:47:54 +01:00
|
|
|
traverse.end_data = sections[section_line].address + offset + length;
|
2006-06-18 21:32:17 +02:00
|
|
|
|
2011-03-19 16:58:27 +01:00
|
|
|
if (offset + 4 + length > sections[section_line].size)
|
|
|
|
{
|
|
|
|
WARN("out of bounds header\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-04-18 21:57:33 +02:00
|
|
|
dwarf2_parse_u2(&traverse); /* version */
|
|
|
|
dwarf2_parse_u4(&traverse); /* header_len */
|
2006-06-18 21:32:17 +02:00
|
|
|
insn_size = dwarf2_parse_byte(&traverse);
|
|
|
|
default_stmt = dwarf2_parse_byte(&traverse);
|
2006-06-18 21:32:24 +02:00
|
|
|
line_base = (signed char)dwarf2_parse_byte(&traverse);
|
2006-06-18 21:32:17 +02:00
|
|
|
line_range = dwarf2_parse_byte(&traverse);
|
|
|
|
opcode_base = dwarf2_parse_byte(&traverse);
|
|
|
|
|
|
|
|
opcode_len = traverse.data;
|
2006-06-18 21:32:24 +02:00
|
|
|
traverse.data += opcode_base - 1;
|
2006-06-18 21:32:17 +02:00
|
|
|
|
2006-06-18 21:32:24 +02:00
|
|
|
vector_init(&dirs, sizeof(const char*), 4);
|
|
|
|
p = vector_add(&dirs, &ctx->pool);
|
2006-11-05 23:30:52 +01:00
|
|
|
*p = compile_dir ? compile_dir : ".";
|
2006-06-18 21:32:17 +02:00
|
|
|
while (*traverse.data)
|
|
|
|
{
|
2006-11-05 23:30:52 +01:00
|
|
|
const char* rel = (const char*)traverse.data;
|
|
|
|
unsigned rellen = strlen(rel);
|
|
|
|
TRACE("Got include %s\n", rel);
|
|
|
|
traverse.data += rellen + 1;
|
2006-06-18 21:32:24 +02:00
|
|
|
p = vector_add(&dirs, &ctx->pool);
|
2006-11-05 23:30:52 +01:00
|
|
|
|
|
|
|
if (*rel == '/' || !compile_dir)
|
|
|
|
*p = rel;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* include directory relative to compile directory */
|
|
|
|
unsigned baselen = strlen(compile_dir);
|
|
|
|
char* tmp = pool_alloc(&ctx->pool, baselen + 1 + rellen + 1);
|
|
|
|
strcpy(tmp, compile_dir);
|
|
|
|
if (tmp[baselen - 1] != '/') tmp[baselen++] = '/';
|
|
|
|
strcpy(&tmp[baselen], rel);
|
|
|
|
*p = tmp;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:17 +02:00
|
|
|
}
|
|
|
|
traverse.data++;
|
2006-06-18 21:32:24 +02:00
|
|
|
|
|
|
|
vector_init(&files, sizeof(unsigned), 16);
|
2006-06-18 21:32:17 +02:00
|
|
|
while (*traverse.data)
|
|
|
|
{
|
2006-06-18 21:32:24 +02:00
|
|
|
unsigned int dir_index, mod_time, length;
|
|
|
|
const char* name;
|
|
|
|
const char* dir;
|
|
|
|
unsigned* psrc;
|
2006-06-18 21:32:17 +02:00
|
|
|
|
|
|
|
name = (const char*)traverse.data;
|
|
|
|
traverse.data += strlen(name) + 1;
|
|
|
|
dir_index = dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
mod_time = dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
length = dwarf2_leb128_as_unsigned(&traverse);
|
2006-06-18 21:32:24 +02:00
|
|
|
dir = *(const char**)vector_at(&dirs, dir_index);
|
|
|
|
TRACE("Got file %s/%s (%u,%u)\n", dir, name, mod_time, length);
|
|
|
|
psrc = vector_add(&files, &ctx->pool);
|
|
|
|
*psrc = source_new(ctx->module, dir, name);
|
2006-06-18 21:32:17 +02:00
|
|
|
}
|
|
|
|
traverse.data++;
|
|
|
|
|
|
|
|
while (traverse.data < traverse.end_data)
|
|
|
|
{
|
2006-06-18 21:32:20 +02:00
|
|
|
unsigned long address = 0;
|
2006-06-18 21:32:17 +02:00
|
|
|
unsigned file = 1;
|
|
|
|
unsigned line = 1;
|
|
|
|
unsigned is_stmt = default_stmt;
|
2010-05-24 22:15:41 +02:00
|
|
|
BOOL end_sequence = FALSE;
|
2006-06-18 21:32:17 +02:00
|
|
|
unsigned opcode, extopcode, i;
|
|
|
|
|
|
|
|
while (!end_sequence)
|
|
|
|
{
|
|
|
|
opcode = dwarf2_parse_byte(&traverse);
|
|
|
|
TRACE("Got opcode %x\n", opcode);
|
|
|
|
|
|
|
|
if (opcode >= opcode_base)
|
|
|
|
{
|
|
|
|
unsigned delta = opcode - opcode_base;
|
|
|
|
|
|
|
|
address += (delta / line_range) * insn_size;
|
|
|
|
line += line_base + (delta % line_range);
|
2006-06-18 21:32:24 +02:00
|
|
|
dwarf2_set_line_number(ctx->module, address, &files, file, line);
|
2006-06-18 21:32:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case DW_LNS_copy:
|
2006-06-18 21:32:24 +02:00
|
|
|
dwarf2_set_line_number(ctx->module, address, &files, file, line);
|
2006-06-18 21:32:17 +02:00
|
|
|
break;
|
|
|
|
case DW_LNS_advance_pc:
|
|
|
|
address += insn_size * dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
break;
|
|
|
|
case DW_LNS_advance_line:
|
2006-06-18 21:32:20 +02:00
|
|
|
line += dwarf2_leb128_as_signed(&traverse);
|
2006-06-18 21:32:17 +02:00
|
|
|
break;
|
|
|
|
case DW_LNS_set_file:
|
2006-06-18 21:32:20 +02:00
|
|
|
file = dwarf2_leb128_as_unsigned(&traverse);
|
2006-06-18 21:32:17 +02:00
|
|
|
break;
|
|
|
|
case DW_LNS_set_column:
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
break;
|
|
|
|
case DW_LNS_negate_stmt:
|
|
|
|
is_stmt = !is_stmt;
|
|
|
|
break;
|
|
|
|
case DW_LNS_set_basic_block:
|
|
|
|
break;
|
|
|
|
case DW_LNS_const_add_pc:
|
|
|
|
address += ((255 - opcode_base) / line_range) * insn_size;
|
|
|
|
break;
|
|
|
|
case DW_LNS_fixed_advance_pc:
|
|
|
|
address += dwarf2_parse_u2(&traverse);
|
|
|
|
break;
|
|
|
|
case DW_LNS_extended_op:
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
extopcode = dwarf2_parse_byte(&traverse);
|
|
|
|
switch (extopcode)
|
|
|
|
{
|
|
|
|
case DW_LNE_end_sequence:
|
2006-06-18 21:32:24 +02:00
|
|
|
dwarf2_set_line_number(ctx->module, address, &files, file, line);
|
2006-06-18 21:32:17 +02:00
|
|
|
end_sequence = TRUE;
|
|
|
|
break;
|
|
|
|
case DW_LNE_set_address:
|
2007-03-15 22:01:06 +01:00
|
|
|
address = ctx->load_offset + dwarf2_parse_addr(&traverse);
|
2006-06-18 21:32:17 +02:00
|
|
|
break;
|
|
|
|
case DW_LNE_define_file:
|
2006-06-18 21:32:24 +02:00
|
|
|
FIXME("not handled %s\n", traverse.data);
|
2006-06-18 21:32:17 +02:00
|
|
|
traverse.data += strlen((const char *)traverse.data) + 1;
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
break;
|
2010-06-27 22:57:33 +02:00
|
|
|
case DW_LNE_set_discriminator:
|
|
|
|
WARN("not handled %s\n", traverse.data);
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
break;
|
2006-06-18 21:32:17 +02:00
|
|
|
default:
|
|
|
|
FIXME("Unsupported extended opcode %x\n", extopcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unsupported opcode %x\n", opcode);
|
|
|
|
for (i = 0; i < opcode_len[opcode]; i++)
|
|
|
|
dwarf2_leb128_as_unsigned(&traverse);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-06 20:05:34 +01:00
|
|
|
return TRUE;
|
2006-06-18 21:32:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections,
|
|
|
|
struct module* module,
|
2006-06-24 09:50:10 +02:00
|
|
|
const struct elf_thunk_area* thunks,
|
2008-04-30 21:27:49 +02:00
|
|
|
dwarf2_traverse_context_t* mod_ctx,
|
2007-03-15 22:01:06 +01:00
|
|
|
unsigned long load_offset)
|
2005-05-18 11:46:12 +02:00
|
|
|
{
|
|
|
|
dwarf2_parse_context_t ctx;
|
2006-06-18 21:32:09 +02:00
|
|
|
dwarf2_traverse_context_t abbrev_ctx;
|
2006-06-18 21:31:17 +02:00
|
|
|
dwarf2_debug_info_t* di;
|
2008-04-30 21:27:49 +02:00
|
|
|
dwarf2_traverse_context_t cu_ctx;
|
|
|
|
const unsigned char* comp_unit_start = mod_ctx->data;
|
|
|
|
unsigned long cu_length;
|
|
|
|
unsigned short cu_version;
|
|
|
|
unsigned long cu_abbrev_offset;
|
2006-06-18 21:32:09 +02:00
|
|
|
BOOL ret = FALSE;
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2008-04-30 21:27:49 +02:00
|
|
|
cu_length = dwarf2_parse_u4(mod_ctx);
|
2010-03-20 09:47:54 +01:00
|
|
|
cu_ctx.data = mod_ctx->data;
|
2008-04-30 21:27:49 +02:00
|
|
|
cu_ctx.end_data = mod_ctx->data + cu_length;
|
|
|
|
mod_ctx->data += cu_length;
|
|
|
|
cu_version = dwarf2_parse_u2(&cu_ctx);
|
|
|
|
cu_abbrev_offset = dwarf2_parse_u4(&cu_ctx);
|
|
|
|
cu_ctx.word_size = dwarf2_parse_byte(&cu_ctx);
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
TRACE("Compilation Unit Header found at 0x%x:\n",
|
2009-12-12 12:19:02 +01:00
|
|
|
(int)(comp_unit_start - sections[section_debug].address));
|
2008-04-30 21:27:49 +02:00
|
|
|
TRACE("- length: %lu\n", cu_length);
|
|
|
|
TRACE("- version: %u\n", cu_version);
|
|
|
|
TRACE("- abbrev_offset: %lu\n", cu_abbrev_offset);
|
|
|
|
TRACE("- word_size: %u\n", cu_ctx.word_size);
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2008-04-30 21:27:49 +02:00
|
|
|
if (cu_version != 2)
|
2006-06-18 21:32:09 +02:00
|
|
|
{
|
|
|
|
WARN("%u DWARF version unsupported. Wine dbghelp only support DWARF 2.\n",
|
2008-04-30 21:27:49 +02:00
|
|
|
cu_version);
|
2006-06-18 21:32:09 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-18 11:46:12 +02:00
|
|
|
|
2010-03-24 22:04:06 +01:00
|
|
|
module->format_info[DFI_DWARF]->u.dwarf2_info->word_size = cu_ctx.word_size;
|
|
|
|
mod_ctx->word_size = cu_ctx.word_size;
|
|
|
|
|
2006-06-18 21:31:13 +02:00
|
|
|
pool_init(&ctx.pool, 65536);
|
2006-09-25 22:41:10 +02:00
|
|
|
ctx.sections = sections;
|
|
|
|
ctx.section = section_debug;
|
2006-06-18 21:31:27 +02:00
|
|
|
ctx.module = module;
|
2006-06-24 09:50:10 +02:00
|
|
|
ctx.thunks = thunks;
|
2007-03-15 22:01:06 +01:00
|
|
|
ctx.load_offset = load_offset;
|
2008-04-30 21:27:49 +02:00
|
|
|
ctx.ref_offset = comp_unit_start - sections[section_debug].address;
|
2008-02-06 21:56:06 +01:00
|
|
|
memset(ctx.symt_cache, 0, sizeof(ctx.symt_cache));
|
|
|
|
ctx.symt_cache[sc_void] = &symt_new_basic(module, btVoid, "void", 0)->symt;
|
2011-03-08 21:30:56 +01:00
|
|
|
ctx.cpp_name = NULL;
|
2006-06-18 21:32:09 +02:00
|
|
|
|
2010-03-20 09:47:54 +01:00
|
|
|
abbrev_ctx.data = sections[section_abbrev].address + cu_abbrev_offset;
|
2006-06-18 21:32:09 +02:00
|
|
|
abbrev_ctx.end_data = sections[section_abbrev].address + sections[section_abbrev].size;
|
2008-04-30 21:27:49 +02:00
|
|
|
abbrev_ctx.word_size = cu_ctx.word_size;
|
2006-06-18 21:31:13 +02:00
|
|
|
dwarf2_parse_abbrev_set(&abbrev_ctx, &ctx.abbrev_table, &ctx.pool);
|
2005-05-20 11:41:10 +02:00
|
|
|
|
2006-06-18 21:31:17 +02:00
|
|
|
sparse_array_init(&ctx.debug_info_table, sizeof(dwarf2_debug_info_t), 128);
|
2011-03-08 21:30:47 +01:00
|
|
|
dwarf2_read_one_debug_info(&ctx, &cu_ctx, NULL, &di);
|
2006-06-18 21:31:17 +02:00
|
|
|
|
2006-06-18 21:31:32 +02:00
|
|
|
if (di->abbrev->tag == DW_TAG_compile_unit)
|
|
|
|
{
|
2006-09-25 22:40:58 +02:00
|
|
|
struct attribute name;
|
2011-03-08 21:31:02 +01:00
|
|
|
struct vector* children;
|
|
|
|
dwarf2_debug_info_t* child = NULL;
|
|
|
|
unsigned int i;
|
2006-11-24 22:17:21 +01:00
|
|
|
struct attribute stmt_list, low_pc;
|
2006-11-05 23:30:52 +01:00
|
|
|
struct attribute comp_dir;
|
2006-06-18 21:31:32 +02:00
|
|
|
|
2006-11-24 22:18:26 +01:00
|
|
|
if (!dwarf2_find_attribute(&ctx, di, DW_AT_name, &name))
|
|
|
|
name.u.string = NULL;
|
2006-11-05 23:30:52 +01:00
|
|
|
|
|
|
|
/* get working directory of current compilation unit */
|
|
|
|
if (!dwarf2_find_attribute(&ctx, di, DW_AT_comp_dir, &comp_dir))
|
|
|
|
comp_dir.u.string = NULL;
|
|
|
|
|
2006-11-24 22:17:21 +01:00
|
|
|
if (!dwarf2_find_attribute(&ctx, di, DW_AT_low_pc, &low_pc))
|
|
|
|
low_pc.u.uvalue = 0;
|
2011-03-08 21:31:14 +01:00
|
|
|
ctx.compiland = symt_new_compiland(module, ctx.load_offset + low_pc.u.uvalue,
|
|
|
|
source_new(module, comp_dir.u.string, name.u.string));
|
|
|
|
di->symt = &ctx.compiland->symt;
|
2011-03-08 21:31:02 +01:00
|
|
|
children = dwarf2_get_di_children(&ctx, di);
|
|
|
|
if (children) for (i = 0; i < vector_length(children); i++)
|
2006-06-18 21:31:32 +02:00
|
|
|
{
|
2011-03-08 21:31:02 +01:00
|
|
|
child = *(dwarf2_debug_info_t**)vector_at(children, i);
|
2011-03-08 21:31:14 +01:00
|
|
|
dwarf2_load_one_entry(&ctx, child);
|
2006-06-18 21:31:32 +02:00
|
|
|
}
|
2006-09-25 22:41:10 +02:00
|
|
|
if (dwarf2_find_attribute(&ctx, di, DW_AT_stmt_list, &stmt_list))
|
2006-06-18 21:32:17 +02:00
|
|
|
{
|
2006-11-06 20:05:34 +01:00
|
|
|
if (dwarf2_parse_line_numbers(sections, &ctx, comp_dir.u.string, stmt_list.u.uvalue))
|
|
|
|
module->module.LineNumbers = TRUE;
|
2006-06-18 21:32:17 +02:00
|
|
|
}
|
2006-06-18 21:32:09 +02:00
|
|
|
ret = TRUE;
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|
2006-06-18 21:31:32 +02:00
|
|
|
else FIXME("Should have a compilation unit here\n");
|
2006-06-18 21:31:13 +02:00
|
|
|
pool_destroy(&ctx.pool);
|
2006-06-18 21:32:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 21:31:43 +01:00
|
|
|
static BOOL dwarf2_lookup_loclist(const struct module_format* modfmt, const BYTE* start,
|
2010-03-24 22:04:12 +01:00
|
|
|
unsigned long ip, dwarf2_traverse_context_t* lctx)
|
2006-11-24 22:17:59 +01:00
|
|
|
{
|
2010-03-24 22:04:00 +01:00
|
|
|
DWORD_PTR beg, end;
|
2006-11-24 22:17:59 +01:00
|
|
|
const BYTE* ptr = start;
|
|
|
|
DWORD len;
|
|
|
|
|
2010-03-18 21:31:43 +01:00
|
|
|
while (ptr < modfmt->u.dwarf2_info->debug_loc.address + modfmt->u.dwarf2_info->debug_loc.size)
|
2006-11-24 22:17:59 +01:00
|
|
|
{
|
2010-03-24 22:04:12 +01:00
|
|
|
beg = dwarf2_get_addr(ptr, modfmt->u.dwarf2_info->word_size); ptr += modfmt->u.dwarf2_info->word_size;
|
|
|
|
end = dwarf2_get_addr(ptr, modfmt->u.dwarf2_info->word_size); ptr += modfmt->u.dwarf2_info->word_size;
|
2006-11-24 22:17:59 +01:00
|
|
|
if (!beg && !end) break;
|
|
|
|
len = dwarf2_get_u2(ptr); ptr += 2;
|
|
|
|
|
|
|
|
if (beg <= ip && ip < end)
|
|
|
|
{
|
|
|
|
lctx->data = ptr;
|
|
|
|
lctx->end_data = ptr + len;
|
2010-03-24 22:04:06 +01:00
|
|
|
lctx->word_size = modfmt->u.dwarf2_info->word_size;
|
2006-11-24 22:17:59 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
ptr += len;
|
|
|
|
}
|
|
|
|
WARN("Couldn't find ip in location list\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-11-24 22:18:04 +01:00
|
|
|
static enum location_error loc_compute_frame(struct process* pcs,
|
2010-03-18 21:31:43 +01:00
|
|
|
const struct module_format* modfmt,
|
2006-11-24 22:17:59 +01:00
|
|
|
const struct symt_function* func,
|
2010-03-24 22:04:00 +01:00
|
|
|
DWORD_PTR ip, struct location* frame)
|
2006-11-24 22:17:59 +01:00
|
|
|
{
|
|
|
|
struct symt** psym = NULL;
|
|
|
|
struct location* pframe;
|
|
|
|
dwarf2_traverse_context_t lctx;
|
|
|
|
enum location_error err;
|
2008-09-24 21:50:00 +02:00
|
|
|
unsigned int i;
|
2006-11-24 22:17:59 +01:00
|
|
|
|
2007-05-15 02:05:12 +02:00
|
|
|
for (i=0; i<vector_length(&func->vchildren); i++)
|
2006-11-24 22:17:59 +01:00
|
|
|
{
|
2007-05-15 02:05:12 +02:00
|
|
|
psym = vector_at(&func->vchildren, i);
|
2006-11-24 22:17:59 +01:00
|
|
|
if ((*psym)->tag == SymTagCustom)
|
|
|
|
{
|
2008-02-06 21:55:47 +01:00
|
|
|
pframe = &((struct symt_hierarchy_point*)*psym)->loc;
|
2006-11-24 22:17:59 +01:00
|
|
|
|
|
|
|
/* First, recompute the frame information, if needed */
|
|
|
|
switch (pframe->kind)
|
|
|
|
{
|
|
|
|
case loc_regrel:
|
|
|
|
case loc_register:
|
|
|
|
*frame = *pframe;
|
|
|
|
break;
|
|
|
|
case loc_dwarf2_location_list:
|
|
|
|
WARN("Searching loclist for %s\n", func->hash_elt.name);
|
2010-03-18 21:31:43 +01:00
|
|
|
if (!dwarf2_lookup_loclist(modfmt,
|
|
|
|
modfmt->u.dwarf2_info->debug_loc.address + pframe->offset,
|
2006-11-24 22:17:59 +01:00
|
|
|
ip, &lctx))
|
|
|
|
return loc_err_out_of_scope;
|
2006-11-24 22:18:04 +01:00
|
|
|
if ((err = compute_location(&lctx, frame, pcs->handle, NULL)) < 0) return err;
|
2006-11-24 22:17:59 +01:00
|
|
|
if (frame->kind >= loc_user)
|
|
|
|
{
|
|
|
|
WARN("Couldn't compute runtime frame location\n");
|
|
|
|
return loc_err_too_complex;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unsupported frame kind %d\n", pframe->kind);
|
|
|
|
return loc_err_internal;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WARN("Couldn't find Custom function point, whilst location list offset is searched\n");
|
|
|
|
return loc_err_internal;
|
|
|
|
}
|
|
|
|
|
2010-03-27 09:08:11 +01:00
|
|
|
enum reg_rule
|
|
|
|
{
|
|
|
|
RULE_UNSET, /* not set at all */
|
|
|
|
RULE_UNDEFINED, /* undefined value */
|
|
|
|
RULE_SAME, /* same value as previous frame */
|
|
|
|
RULE_CFA_OFFSET, /* stored at cfa offset */
|
|
|
|
RULE_OTHER_REG, /* stored in other register */
|
|
|
|
RULE_EXPRESSION, /* address specified by expression */
|
|
|
|
RULE_VAL_EXPRESSION /* value specified by expression */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* make it large enough for all CPUs */
|
|
|
|
#define NB_FRAME_REGS 64
|
2010-07-03 22:22:09 +02:00
|
|
|
#define MAX_SAVED_STATES 16
|
|
|
|
|
|
|
|
struct frame_state
|
|
|
|
{
|
|
|
|
ULONG_PTR cfa_offset;
|
|
|
|
unsigned char cfa_reg;
|
|
|
|
enum reg_rule cfa_rule;
|
|
|
|
enum reg_rule rules[NB_FRAME_REGS];
|
|
|
|
ULONG_PTR regs[NB_FRAME_REGS];
|
|
|
|
};
|
2010-03-27 09:08:11 +01:00
|
|
|
|
|
|
|
struct frame_info
|
|
|
|
{
|
|
|
|
ULONG_PTR ip;
|
|
|
|
ULONG_PTR code_align;
|
|
|
|
LONG_PTR data_align;
|
|
|
|
unsigned char retaddr_reg;
|
|
|
|
unsigned char fde_encoding;
|
|
|
|
unsigned char lsda_encoding;
|
|
|
|
unsigned char signal_frame;
|
|
|
|
unsigned char aug_z_format;
|
2010-07-03 22:22:09 +02:00
|
|
|
unsigned char state_sp;
|
|
|
|
struct frame_state state;
|
|
|
|
struct frame_state state_stack[MAX_SAVED_STATES];
|
2010-03-27 09:08:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static ULONG_PTR dwarf2_parse_augmentation_ptr(dwarf2_traverse_context_t* ctx, unsigned char encoding)
|
|
|
|
{
|
|
|
|
ULONG_PTR base;
|
|
|
|
|
|
|
|
if (encoding == DW_EH_PE_omit) return 0;
|
|
|
|
|
|
|
|
switch (encoding & 0xf0)
|
|
|
|
{
|
|
|
|
case DW_EH_PE_abs:
|
|
|
|
base = 0;
|
|
|
|
break;
|
|
|
|
case DW_EH_PE_pcrel:
|
|
|
|
base = (ULONG_PTR)ctx->data;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unsupported encoding %02x\n", encoding);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (encoding & 0x0f)
|
|
|
|
{
|
|
|
|
case DW_EH_PE_native:
|
|
|
|
return base + dwarf2_parse_addr(ctx);
|
|
|
|
case DW_EH_PE_leb128:
|
|
|
|
return base + dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
case DW_EH_PE_data2:
|
|
|
|
return base + dwarf2_parse_u2(ctx);
|
|
|
|
case DW_EH_PE_data4:
|
|
|
|
return base + dwarf2_parse_u4(ctx);
|
|
|
|
case DW_EH_PE_data8:
|
|
|
|
return base + dwarf2_parse_u8(ctx);
|
|
|
|
case DW_EH_PE_signed|DW_EH_PE_leb128:
|
|
|
|
return base + dwarf2_leb128_as_signed(ctx);
|
|
|
|
case DW_EH_PE_signed|DW_EH_PE_data2:
|
|
|
|
return base + (signed short)dwarf2_parse_u2(ctx);
|
|
|
|
case DW_EH_PE_signed|DW_EH_PE_data4:
|
|
|
|
return base + (signed int)dwarf2_parse_u4(ctx);
|
|
|
|
case DW_EH_PE_signed|DW_EH_PE_data8:
|
|
|
|
return base + (LONG64)dwarf2_parse_u8(ctx);
|
|
|
|
default:
|
|
|
|
FIXME("unsupported encoding %02x\n", encoding);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL parse_cie_details(dwarf2_traverse_context_t* ctx, struct frame_info* info)
|
|
|
|
{
|
|
|
|
unsigned char version;
|
|
|
|
const char* augmentation;
|
|
|
|
const unsigned char* end;
|
|
|
|
ULONG_PTR len;
|
|
|
|
|
|
|
|
memset(info, 0, sizeof(*info));
|
|
|
|
info->lsda_encoding = DW_EH_PE_omit;
|
|
|
|
info->aug_z_format = 0;
|
|
|
|
|
|
|
|
/* parse the CIE first */
|
|
|
|
version = dwarf2_parse_byte(ctx);
|
|
|
|
if (version != 1)
|
|
|
|
{
|
|
|
|
FIXME("unknown CIE version %u at %p\n", version, ctx->data - 1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
augmentation = (const char*)ctx->data;
|
|
|
|
ctx->data += strlen(augmentation) + 1;
|
|
|
|
|
|
|
|
info->code_align = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
info->data_align = dwarf2_leb128_as_signed(ctx);
|
|
|
|
info->retaddr_reg = dwarf2_parse_byte(ctx);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.cfa_rule = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
|
|
|
|
end = NULL;
|
|
|
|
TRACE("\tparsing augmentation %s\n", augmentation);
|
|
|
|
if (*augmentation) do
|
|
|
|
{
|
|
|
|
switch (*augmentation)
|
|
|
|
{
|
|
|
|
case 'z':
|
|
|
|
len = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
end = ctx->data + len;
|
|
|
|
info->aug_z_format = 1;
|
|
|
|
continue;
|
|
|
|
case 'L':
|
|
|
|
info->lsda_encoding = dwarf2_parse_byte(ctx);
|
|
|
|
continue;
|
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
unsigned char encoding = dwarf2_parse_byte(ctx);
|
2010-04-01 21:24:26 +02:00
|
|
|
/* throw away the indirect bit, as we don't care for the result */
|
|
|
|
encoding &= ~DW_EH_PE_indirect;
|
2010-03-27 09:08:11 +01:00
|
|
|
dwarf2_parse_augmentation_ptr(ctx, encoding); /* handler */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case 'R':
|
|
|
|
info->fde_encoding = dwarf2_parse_byte(ctx);
|
|
|
|
continue;
|
|
|
|
case 'S':
|
|
|
|
info->signal_frame = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FIXME("unknown augmentation '%c'\n", *augmentation);
|
|
|
|
if (!end) return FALSE;
|
|
|
|
break;
|
|
|
|
} while (*++augmentation);
|
|
|
|
if (end) ctx->data = end;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL dwarf2_get_cie(unsigned long addr, struct module* module, DWORD_PTR delta,
|
|
|
|
dwarf2_traverse_context_t* fde_ctx, dwarf2_traverse_context_t* cie_ctx,
|
2010-04-01 21:24:20 +02:00
|
|
|
struct frame_info* info, BOOL in_eh_frame)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
const unsigned char* ptr_blk;
|
|
|
|
const unsigned char* cie_ptr;
|
|
|
|
const unsigned char* last_cie_ptr = (const unsigned char*)~0;
|
|
|
|
unsigned len, id;
|
|
|
|
unsigned long start, range;
|
2010-04-01 21:24:20 +02:00
|
|
|
unsigned cie_id;
|
|
|
|
const BYTE* start_data = fde_ctx->data;
|
2010-03-27 09:08:11 +01:00
|
|
|
|
2010-04-01 21:24:20 +02:00
|
|
|
cie_id = in_eh_frame ? 0 : DW_CIE_ID;
|
2010-03-27 09:08:11 +01:00
|
|
|
for (; fde_ctx->data + 2 * 4 < fde_ctx->end_data; fde_ctx->data = ptr_blk)
|
|
|
|
{
|
|
|
|
/* find the FDE for address addr (skip CIE) */
|
|
|
|
len = dwarf2_parse_u4(fde_ctx);
|
|
|
|
if (len == 0xffffffff) FIXME("Unsupported yet 64-bit CIEs\n");
|
|
|
|
ptr_blk = fde_ctx->data + len;
|
|
|
|
id = dwarf2_parse_u4(fde_ctx);
|
2010-04-01 21:24:20 +02:00
|
|
|
if (id == cie_id)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
last_cie_ptr = fde_ctx->data - 8;
|
|
|
|
/* we need some bits out of the CIE in order to parse all contents */
|
|
|
|
if (!parse_cie_details(fde_ctx, info)) return FALSE;
|
|
|
|
cie_ctx->data = fde_ctx->data;
|
|
|
|
cie_ctx->end_data = ptr_blk;
|
|
|
|
cie_ctx->word_size = fde_ctx->word_size;
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-01 21:24:20 +02:00
|
|
|
cie_ptr = (in_eh_frame) ? fde_ctx->data - id - 4 : start_data + id;
|
2010-03-27 09:08:11 +01:00
|
|
|
if (cie_ptr != last_cie_ptr)
|
|
|
|
{
|
|
|
|
last_cie_ptr = cie_ptr;
|
|
|
|
cie_ctx->data = cie_ptr;
|
|
|
|
cie_ctx->word_size = fde_ctx->word_size;
|
|
|
|
cie_ctx->end_data = cie_ptr + 4;
|
|
|
|
cie_ctx->end_data = cie_ptr + 4 + dwarf2_parse_u4(cie_ctx);
|
2010-04-01 21:24:20 +02:00
|
|
|
if (dwarf2_parse_u4(cie_ctx) != cie_id)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
FIXME("wrong CIE pointer\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!parse_cie_details(cie_ctx, info)) return FALSE;
|
|
|
|
}
|
|
|
|
start = delta + dwarf2_parse_augmentation_ptr(fde_ctx, info->fde_encoding);
|
|
|
|
range = dwarf2_parse_augmentation_ptr(fde_ctx, info->fde_encoding & 0x0F);
|
|
|
|
|
|
|
|
if (addr >= start && addr < start + range)
|
|
|
|
{
|
|
|
|
/* reset the FDE context */
|
|
|
|
fde_ctx->end_data = ptr_blk;
|
|
|
|
|
|
|
|
info->ip = start;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int valid_reg(ULONG_PTR reg)
|
|
|
|
{
|
|
|
|
if (reg >= NB_FRAME_REGS) FIXME("unsupported reg %lx\n", reg);
|
|
|
|
return (reg < NB_FRAME_REGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void execute_cfa_instructions(dwarf2_traverse_context_t* ctx,
|
|
|
|
ULONG_PTR last_ip, struct frame_info *info)
|
|
|
|
{
|
2011-03-13 21:30:34 +01:00
|
|
|
while (ctx->data < ctx->end_data && info->ip <= last_ip + info->signal_frame)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
enum dwarf_call_frame_info op = dwarf2_parse_byte(ctx);
|
|
|
|
|
|
|
|
if (op & 0xc0)
|
|
|
|
{
|
|
|
|
switch (op & 0xc0)
|
|
|
|
{
|
|
|
|
case DW_CFA_advance_loc:
|
|
|
|
{
|
|
|
|
ULONG_PTR offset = (op & 0x3f) * info->code_align;
|
|
|
|
TRACE("%lx: DW_CFA_advance_loc %lu\n", info->ip, offset);
|
|
|
|
info->ip += offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_offset:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = op & 0x3f;
|
|
|
|
LONG_PTR offset = dwarf2_leb128_as_unsigned(ctx) * info->data_align;
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_offset %s, %ld\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)),
|
|
|
|
offset);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.regs[reg] = offset;
|
|
|
|
info->state.rules[reg] = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_restore:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = op & 0x3f;
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_restore %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.rules[reg] = RULE_UNSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else switch (op)
|
|
|
|
{
|
|
|
|
case DW_CFA_nop:
|
|
|
|
break;
|
|
|
|
case DW_CFA_set_loc:
|
|
|
|
{
|
|
|
|
ULONG_PTR loc = dwarf2_parse_augmentation_ptr(ctx, info->fde_encoding);
|
|
|
|
TRACE("%lx: DW_CFA_set_loc %lx\n", info->ip, loc);
|
|
|
|
info->ip = loc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_advance_loc1:
|
|
|
|
{
|
|
|
|
ULONG_PTR offset = dwarf2_parse_byte(ctx) * info->code_align;
|
|
|
|
TRACE("%lx: DW_CFA_advance_loc1 %lu\n", info->ip, offset);
|
|
|
|
info->ip += offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_advance_loc2:
|
|
|
|
{
|
|
|
|
ULONG_PTR offset = dwarf2_parse_u2(ctx) * info->code_align;
|
|
|
|
TRACE("%lx: DW_CFA_advance_loc2 %lu\n", info->ip, offset);
|
|
|
|
info->ip += offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_advance_loc4:
|
|
|
|
{
|
|
|
|
ULONG_PTR offset = dwarf2_parse_u4(ctx) * info->code_align;
|
|
|
|
TRACE("%lx: DW_CFA_advance_loc4 %lu\n", info->ip, offset);
|
|
|
|
info->ip += offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_offset_extended:
|
|
|
|
case DW_CFA_offset_extended_sf:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
LONG_PTR offset = (op == DW_CFA_offset_extended) ? dwarf2_leb128_as_unsigned(ctx) * info->data_align
|
|
|
|
: dwarf2_leb128_as_signed(ctx) * info->data_align;
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_offset_extended %s, %ld\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)),
|
|
|
|
offset);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.regs[reg] = offset;
|
|
|
|
info->state.rules[reg] = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_restore_extended:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_restore_extended %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.rules[reg] = RULE_UNSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_undefined:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_undefined %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.rules[reg] = RULE_UNDEFINED;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_same_value:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_same_value %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.regs[reg] = reg;
|
|
|
|
info->state.rules[reg] = RULE_SAME;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_register:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
ULONG_PTR reg2 = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg) || !valid_reg(reg2)) break;
|
|
|
|
TRACE("%lx: DW_CFA_register %s == %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)),
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg2)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.regs[reg] = reg2;
|
|
|
|
info->state.rules[reg] = RULE_OTHER_REG;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_remember_state:
|
2010-07-03 22:22:09 +02:00
|
|
|
TRACE("%lx: DW_CFA_remember_state\n", info->ip);
|
|
|
|
if (info->state_sp >= MAX_SAVED_STATES)
|
|
|
|
FIXME("%lx: DW_CFA_remember_state too many nested saves\n", info->ip);
|
|
|
|
else
|
|
|
|
info->state_stack[info->state_sp++] = info->state;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
case DW_CFA_restore_state:
|
2010-07-03 22:22:09 +02:00
|
|
|
TRACE("%lx: DW_CFA_restore_state\n", info->ip);
|
|
|
|
if (!info->state_sp)
|
|
|
|
FIXME("%lx: DW_CFA_restore_state without corresponding save\n", info->ip);
|
|
|
|
else
|
|
|
|
info->state = info->state_stack[--info->state_sp];
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
case DW_CFA_def_cfa:
|
|
|
|
case DW_CFA_def_cfa_sf:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
ULONG_PTR offset = (op == DW_CFA_def_cfa) ? dwarf2_leb128_as_unsigned(ctx)
|
|
|
|
: dwarf2_leb128_as_signed(ctx) * info->data_align;
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_def_cfa %s, %lu\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)),
|
|
|
|
offset);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.cfa_reg = reg;
|
|
|
|
info->state.cfa_offset = offset;
|
|
|
|
info->state.cfa_rule = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_def_cfa_register:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_def_cfa_register %s\n",
|
|
|
|
info->ip,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)));
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.cfa_reg = reg;
|
|
|
|
info->state.cfa_rule = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_def_cfa_offset:
|
|
|
|
case DW_CFA_def_cfa_offset_sf:
|
|
|
|
{
|
|
|
|
ULONG_PTR offset = (op == DW_CFA_def_cfa_offset) ? dwarf2_leb128_as_unsigned(ctx)
|
|
|
|
: dwarf2_leb128_as_signed(ctx) * info->data_align;
|
|
|
|
TRACE("%lx: DW_CFA_def_cfa_offset %lu\n", info->ip, offset);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.cfa_offset = offset;
|
|
|
|
info->state.cfa_rule = RULE_CFA_OFFSET;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_def_cfa_expression:
|
|
|
|
{
|
|
|
|
ULONG_PTR expr = (ULONG_PTR)ctx->data;
|
|
|
|
ULONG_PTR len = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
TRACE("%lx: DW_CFA_def_cfa_expression %lx-%lx\n", info->ip, expr, expr+len);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.cfa_offset = expr;
|
|
|
|
info->state.cfa_rule = RULE_VAL_EXPRESSION;
|
2010-03-27 09:08:11 +01:00
|
|
|
ctx->data += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DW_CFA_expression:
|
|
|
|
case DW_CFA_val_expression:
|
|
|
|
{
|
|
|
|
ULONG_PTR reg = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
ULONG_PTR expr = (ULONG_PTR)ctx->data;
|
|
|
|
ULONG_PTR len = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
if (!valid_reg(reg)) break;
|
|
|
|
TRACE("%lx: DW_CFA_%sexpression %s %lx-%lx\n",
|
|
|
|
info->ip, (op == DW_CFA_expression) ? "" : "val_",
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(reg)),
|
|
|
|
expr, expr + len);
|
2010-07-03 22:22:09 +02:00
|
|
|
info->state.regs[reg] = expr;
|
|
|
|
info->state.rules[reg] = (op == DW_CFA_expression) ? RULE_EXPRESSION : RULE_VAL_EXPRESSION;
|
2010-03-27 09:08:11 +01:00
|
|
|
ctx->data += len;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-06 22:28:24 +02:00
|
|
|
case DW_CFA_GNU_args_size:
|
|
|
|
/* FIXME: should check that GCC is the compiler for this CU */
|
|
|
|
{
|
|
|
|
ULONG_PTR args = dwarf2_leb128_as_unsigned(ctx);
|
|
|
|
TRACE("%lx: DW_CFA_GNU_args_size %lu\n", info->ip, args);
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
}
|
2010-03-27 09:08:11 +01:00
|
|
|
default:
|
|
|
|
FIXME("%lx: unknown CFA opcode %02x\n", info->ip, op);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve a context register from its dwarf number */
|
|
|
|
static ULONG_PTR get_context_reg(CONTEXT *context, ULONG_PTR dw_reg)
|
|
|
|
{
|
|
|
|
unsigned regno = dbghelp_current_cpu->map_dwarf_register(dw_reg), sz;
|
|
|
|
ULONG_PTR* ptr = dbghelp_current_cpu->fetch_context_reg(context, regno, &sz);
|
|
|
|
|
|
|
|
if (sz != sizeof(ULONG_PTR))
|
|
|
|
{
|
|
|
|
FIXME("reading register %lu/%u of wrong size %u\n", dw_reg, regno, sz);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set a context register from its dwarf number */
|
|
|
|
static void set_context_reg(struct cpu_stack_walk* csw, CONTEXT *context, ULONG_PTR dw_reg,
|
|
|
|
ULONG_PTR val, BOOL isdebuggee)
|
|
|
|
{
|
|
|
|
unsigned regno = dbghelp_current_cpu->map_dwarf_register(dw_reg), sz;
|
|
|
|
ULONG_PTR* ptr = dbghelp_current_cpu->fetch_context_reg(context, regno, &sz);
|
|
|
|
|
|
|
|
if (isdebuggee)
|
|
|
|
{
|
|
|
|
char tmp[16];
|
|
|
|
|
|
|
|
if (sz > sizeof(tmp))
|
|
|
|
{
|
|
|
|
FIXME("register %lu/%u size is too wide: %u\n", dw_reg, regno, sz);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!sw_read_mem(csw, val, tmp, sz))
|
|
|
|
{
|
|
|
|
WARN("Couldn't read memory at %p\n", (void*)val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(ptr, tmp, sz);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (sz != sizeof(ULONG_PTR))
|
|
|
|
{
|
|
|
|
FIXME("assigning to register %lu/%u of wrong size %u\n", dw_reg, regno, sz);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*ptr = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy a register from one context to another using dwarf number */
|
|
|
|
static void copy_context_reg(CONTEXT *dstcontext, ULONG_PTR dwregdst, CONTEXT* srccontext, ULONG_PTR dwregsrc)
|
|
|
|
{
|
|
|
|
unsigned regdstno = dbghelp_current_cpu->map_dwarf_register(dwregdst), szdst;
|
|
|
|
unsigned regsrcno = dbghelp_current_cpu->map_dwarf_register(dwregsrc), szsrc;
|
|
|
|
ULONG_PTR* ptrdst = dbghelp_current_cpu->fetch_context_reg(dstcontext, regdstno, &szdst);
|
|
|
|
ULONG_PTR* ptrsrc = dbghelp_current_cpu->fetch_context_reg(srccontext, regsrcno, &szsrc);
|
|
|
|
|
|
|
|
if (szdst != szsrc)
|
|
|
|
{
|
|
|
|
FIXME("Cannot copy register %lu/%u => %lu/%u because of size mismatch (%u => %u)\n",
|
|
|
|
dwregsrc, regsrcno, dwregdst, regdstno, szsrc, szdst);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(ptrdst, ptrsrc, szdst);
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:43:10 +02:00
|
|
|
static ULONG_PTR eval_expression(const struct module* module, struct cpu_stack_walk* csw,
|
2010-06-27 18:55:09 +02:00
|
|
|
const unsigned char* zp, CONTEXT *context)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
dwarf2_traverse_context_t ctx;
|
|
|
|
ULONG_PTR reg, sz, tmp, stack[64];
|
|
|
|
int sp = -1;
|
|
|
|
ULONG_PTR len;
|
|
|
|
|
|
|
|
ctx.data = zp;
|
|
|
|
ctx.end_data = zp + 4;
|
|
|
|
len = dwarf2_leb128_as_unsigned(&ctx);
|
|
|
|
ctx.end_data = ctx.data + len;
|
2010-06-27 18:55:09 +02:00
|
|
|
ctx.word_size = module->format_info[DFI_DWARF]->u.dwarf2_info->word_size;
|
2010-03-27 09:08:11 +01:00
|
|
|
|
|
|
|
while (ctx.data < ctx.end_data)
|
|
|
|
{
|
|
|
|
unsigned char opcode = dwarf2_parse_byte(&ctx);
|
|
|
|
|
|
|
|
if (opcode >= DW_OP_lit0 && opcode <= DW_OP_lit31)
|
|
|
|
stack[++sp] = opcode - DW_OP_lit0;
|
|
|
|
else if (opcode >= DW_OP_reg0 && opcode <= DW_OP_reg31)
|
|
|
|
stack[++sp] = get_context_reg(context, opcode - DW_OP_reg0);
|
|
|
|
else if (opcode >= DW_OP_breg0 && opcode <= DW_OP_breg31)
|
|
|
|
stack[++sp] = get_context_reg(context, opcode - DW_OP_breg0) + dwarf2_leb128_as_signed(&ctx);
|
|
|
|
else switch (opcode)
|
|
|
|
{
|
|
|
|
case DW_OP_nop: break;
|
|
|
|
case DW_OP_addr: stack[++sp] = dwarf2_parse_addr(&ctx); break;
|
|
|
|
case DW_OP_const1u: stack[++sp] = dwarf2_parse_byte(&ctx); break;
|
|
|
|
case DW_OP_const1s: stack[++sp] = (signed char)dwarf2_parse_byte(&ctx); break;
|
|
|
|
case DW_OP_const2u: stack[++sp] = dwarf2_parse_u2(&ctx); break;
|
|
|
|
case DW_OP_const2s: stack[++sp] = (short)dwarf2_parse_u2(&ctx); break;
|
|
|
|
case DW_OP_const4u: stack[++sp] = dwarf2_parse_u4(&ctx); break;
|
|
|
|
case DW_OP_const4s: stack[++sp] = (signed int)dwarf2_parse_u4(&ctx); break;
|
|
|
|
case DW_OP_const8u: stack[++sp] = dwarf2_parse_u8(&ctx); break;
|
|
|
|
case DW_OP_const8s: stack[++sp] = (LONG_PTR)dwarf2_parse_u8(&ctx); break;
|
|
|
|
case DW_OP_constu: stack[++sp] = dwarf2_leb128_as_unsigned(&ctx); break;
|
|
|
|
case DW_OP_consts: stack[++sp] = dwarf2_leb128_as_signed(&ctx); break;
|
|
|
|
case DW_OP_deref:
|
|
|
|
if (!sw_read_mem(csw, stack[sp], &tmp, sizeof(tmp)))
|
|
|
|
{
|
|
|
|
ERR("Couldn't read memory at %lx\n", stack[sp]);
|
|
|
|
tmp = 0;
|
|
|
|
}
|
|
|
|
stack[sp] = tmp;
|
|
|
|
break;
|
|
|
|
case DW_OP_dup: stack[sp + 1] = stack[sp]; sp++; break;
|
|
|
|
case DW_OP_drop: sp--; break;
|
|
|
|
case DW_OP_over: stack[sp + 1] = stack[sp - 1]; sp++; break;
|
|
|
|
case DW_OP_pick: stack[sp + 1] = stack[sp - dwarf2_parse_byte(&ctx)]; sp++; break;
|
|
|
|
case DW_OP_swap: tmp = stack[sp]; stack[sp] = stack[sp-1]; stack[sp-1] = tmp; break;
|
|
|
|
case DW_OP_rot: tmp = stack[sp]; stack[sp] = stack[sp-1]; stack[sp-1] = stack[sp-2]; stack[sp-2] = tmp; break;
|
|
|
|
case DW_OP_abs: stack[sp] = labs(stack[sp]); break;
|
|
|
|
case DW_OP_neg: stack[sp] = -stack[sp]; break;
|
|
|
|
case DW_OP_not: stack[sp] = ~stack[sp]; break;
|
|
|
|
case DW_OP_and: stack[sp-1] &= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_or: stack[sp-1] |= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_minus: stack[sp-1] -= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_mul: stack[sp-1] *= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_plus: stack[sp-1] += stack[sp]; sp--; break;
|
|
|
|
case DW_OP_xor: stack[sp-1] ^= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_shl: stack[sp-1] <<= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_shr: stack[sp-1] >>= stack[sp]; sp--; break;
|
|
|
|
case DW_OP_plus_uconst: stack[sp] += dwarf2_leb128_as_unsigned(&ctx); break;
|
|
|
|
case DW_OP_shra: stack[sp-1] = (LONG_PTR)stack[sp-1] / (1 << stack[sp]); sp--; break;
|
|
|
|
case DW_OP_div: stack[sp-1] = (LONG_PTR)stack[sp-1] / (LONG_PTR)stack[sp]; sp--; break;
|
|
|
|
case DW_OP_mod: stack[sp-1] = (LONG_PTR)stack[sp-1] % (LONG_PTR)stack[sp]; sp--; break;
|
|
|
|
case DW_OP_ge: stack[sp-1] = ((LONG_PTR)stack[sp-1] >= (LONG_PTR)stack[sp]); sp--; break;
|
|
|
|
case DW_OP_gt: stack[sp-1] = ((LONG_PTR)stack[sp-1] > (LONG_PTR)stack[sp]); sp--; break;
|
|
|
|
case DW_OP_le: stack[sp-1] = ((LONG_PTR)stack[sp-1] <= (LONG_PTR)stack[sp]); sp--; break;
|
|
|
|
case DW_OP_lt: stack[sp-1] = ((LONG_PTR)stack[sp-1] < (LONG_PTR)stack[sp]); sp--; break;
|
|
|
|
case DW_OP_eq: stack[sp-1] = (stack[sp-1] == stack[sp]); sp--; break;
|
|
|
|
case DW_OP_ne: stack[sp-1] = (stack[sp-1] != stack[sp]); sp--; break;
|
|
|
|
case DW_OP_skip: tmp = (short)dwarf2_parse_u2(&ctx); ctx.data += tmp; break;
|
|
|
|
case DW_OP_bra: tmp = (short)dwarf2_parse_u2(&ctx); if (!stack[sp--]) ctx.data += tmp; break;
|
|
|
|
case DW_OP_GNU_encoded_addr:
|
|
|
|
tmp = dwarf2_parse_byte(&ctx);
|
|
|
|
stack[++sp] = dwarf2_parse_augmentation_ptr(&ctx, tmp);
|
|
|
|
break;
|
|
|
|
case DW_OP_regx:
|
|
|
|
stack[++sp] = get_context_reg(context, dwarf2_leb128_as_unsigned(&ctx));
|
|
|
|
break;
|
|
|
|
case DW_OP_bregx:
|
|
|
|
reg = dwarf2_leb128_as_unsigned(&ctx);
|
|
|
|
tmp = dwarf2_leb128_as_signed(&ctx);
|
|
|
|
stack[++sp] = get_context_reg(context, reg) + tmp;
|
|
|
|
break;
|
|
|
|
case DW_OP_deref_size:
|
|
|
|
sz = dwarf2_parse_byte(&ctx);
|
|
|
|
if (!sw_read_mem(csw, stack[sp], &tmp, sz))
|
|
|
|
{
|
|
|
|
ERR("Couldn't read memory at %lx\n", stack[sp]);
|
|
|
|
tmp = 0;
|
|
|
|
}
|
|
|
|
/* do integral promotion */
|
|
|
|
switch (sz)
|
|
|
|
{
|
|
|
|
case 1: stack[sp] = *(unsigned char*)&tmp; break;
|
|
|
|
case 2: stack[sp] = *(unsigned short*)&tmp; break;
|
|
|
|
case 4: stack[sp] = *(unsigned int*)&tmp; break;
|
|
|
|
case 8: stack[sp] = *(ULONG_PTR*)&tmp; break; /* FIXME: won't work on 32bit platform */
|
|
|
|
default: FIXME("Unknown size for deref 0x%lx\n", sz);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unhandled opcode %02x\n", opcode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stack[sp];
|
|
|
|
}
|
|
|
|
|
2010-08-28 17:43:10 +02:00
|
|
|
static void apply_frame_state(const struct module* module, struct cpu_stack_walk* csw,
|
2010-07-03 22:22:09 +02:00
|
|
|
CONTEXT *context, struct frame_state *state, ULONG_PTR* cfa)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
ULONG_PTR value;
|
|
|
|
CONTEXT new_context = *context;
|
|
|
|
|
2010-07-03 22:22:09 +02:00
|
|
|
switch (state->cfa_rule)
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
case RULE_EXPRESSION:
|
2010-07-03 22:22:09 +02:00
|
|
|
*cfa = eval_expression(module, csw, (const unsigned char*)state->cfa_offset, context);
|
2010-06-27 18:55:15 +02:00
|
|
|
if (!sw_read_mem(csw, *cfa, cfa, sizeof(*cfa)))
|
|
|
|
{
|
|
|
|
WARN("Couldn't read memory at %p\n", (void*)*cfa);
|
|
|
|
return;
|
|
|
|
}
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
case RULE_VAL_EXPRESSION:
|
2010-07-03 22:22:09 +02:00
|
|
|
*cfa = eval_expression(module, csw, (const unsigned char*)state->cfa_offset, context);
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-03 22:22:09 +02:00
|
|
|
*cfa = get_context_reg(context, state->cfa_reg) + state->cfa_offset;
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!*cfa) return;
|
|
|
|
|
|
|
|
for (i = 0; i < NB_FRAME_REGS; i++)
|
|
|
|
{
|
2010-07-03 22:22:09 +02:00
|
|
|
switch (state->rules[i])
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
|
|
|
case RULE_UNSET:
|
|
|
|
case RULE_UNDEFINED:
|
|
|
|
case RULE_SAME:
|
|
|
|
break;
|
|
|
|
case RULE_CFA_OFFSET:
|
2010-07-03 22:22:09 +02:00
|
|
|
set_context_reg(csw, &new_context, i, *cfa + state->regs[i], TRUE);
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
case RULE_OTHER_REG:
|
2010-07-03 22:22:09 +02:00
|
|
|
copy_context_reg(&new_context, i, context, state->regs[i]);
|
2010-03-27 09:08:11 +01:00
|
|
|
break;
|
|
|
|
case RULE_EXPRESSION:
|
2010-07-03 22:22:09 +02:00
|
|
|
value = eval_expression(module, csw, (const unsigned char*)state->regs[i], context);
|
2010-03-27 09:08:11 +01:00
|
|
|
set_context_reg(csw, &new_context, i, value, TRUE);
|
|
|
|
break;
|
|
|
|
case RULE_VAL_EXPRESSION:
|
2010-07-03 22:22:09 +02:00
|
|
|
value = eval_expression(module, csw, (const unsigned char*)state->regs[i], context);
|
2010-03-27 09:08:11 +01:00
|
|
|
set_context_reg(csw, &new_context, i, value, FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*context = new_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dwarf2_virtual_unwind
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL dwarf2_virtual_unwind(struct cpu_stack_walk* csw, ULONG_PTR ip, CONTEXT* context, ULONG_PTR* cfa)
|
|
|
|
{
|
|
|
|
struct module_pair pair;
|
|
|
|
struct frame_info info;
|
|
|
|
dwarf2_traverse_context_t cie_ctx, fde_ctx;
|
|
|
|
struct module_format* modfmt;
|
|
|
|
const unsigned char* end;
|
|
|
|
DWORD_PTR delta;
|
|
|
|
|
|
|
|
if (!(pair.pcs = process_find_by_handle(csw->hProcess)) ||
|
|
|
|
!(pair.requested = module_find_by_addr(pair.pcs, ip, DMT_UNKNOWN)) ||
|
|
|
|
!module_get_debug(&pair))
|
|
|
|
return FALSE;
|
|
|
|
modfmt = pair.effective->format_info[DFI_DWARF];
|
|
|
|
if (!modfmt) return FALSE;
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
fde_ctx.data = modfmt->u.dwarf2_info->eh_frame.address;
|
|
|
|
fde_ctx.end_data = fde_ctx.data + modfmt->u.dwarf2_info->eh_frame.size;
|
|
|
|
fde_ctx.word_size = modfmt->u.dwarf2_info->word_size;
|
|
|
|
/* let offsets relative to the eh_frame sections be correctly computed, as we'll map
|
|
|
|
* in this process the IMAGE section at a different address as the one expected by
|
|
|
|
* the image
|
|
|
|
*/
|
|
|
|
delta = pair.effective->module.BaseOfImage + modfmt->u.dwarf2_info->eh_frame.rva -
|
|
|
|
(DWORD_PTR)modfmt->u.dwarf2_info->eh_frame.address;
|
2010-04-01 21:24:20 +02:00
|
|
|
if (!dwarf2_get_cie(ip, pair.effective, delta, &fde_ctx, &cie_ctx, &info, TRUE))
|
2010-03-27 09:08:11 +01:00
|
|
|
{
|
2010-04-01 21:24:20 +02:00
|
|
|
fde_ctx.data = modfmt->u.dwarf2_info->debug_frame.address;
|
|
|
|
fde_ctx.end_data = fde_ctx.data + modfmt->u.dwarf2_info->debug_frame.size;
|
|
|
|
fde_ctx.word_size = modfmt->u.dwarf2_info->word_size;
|
|
|
|
delta = pair.effective->reloc_delta;
|
|
|
|
if (!dwarf2_get_cie(ip, pair.effective, delta, &fde_ctx, &cie_ctx, &info, FALSE))
|
|
|
|
{
|
|
|
|
TRACE("Couldn't find information for %lx\n", ip);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-27 09:08:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("function %lx/%lx code_align %lu data_align %ld retaddr %s\n",
|
|
|
|
ip, info.ip, info.code_align, info.data_align,
|
|
|
|
dbghelp_current_cpu->fetch_regname(dbghelp_current_cpu->map_dwarf_register(info.retaddr_reg)));
|
|
|
|
|
|
|
|
/* if at very beginning of function, return and use default unwinder */
|
|
|
|
if (ip == info.ip) return FALSE;
|
|
|
|
execute_cfa_instructions(&cie_ctx, ip, &info);
|
|
|
|
|
|
|
|
if (info.aug_z_format) /* get length of augmentation data */
|
|
|
|
{
|
|
|
|
ULONG_PTR len = dwarf2_leb128_as_unsigned(&fde_ctx);
|
|
|
|
end = fde_ctx.data + len;
|
|
|
|
}
|
|
|
|
else end = NULL;
|
|
|
|
dwarf2_parse_augmentation_ptr(&fde_ctx, info.lsda_encoding); /* handler_data */
|
|
|
|
if (end) fde_ctx.data = end;
|
|
|
|
|
|
|
|
execute_cfa_instructions(&fde_ctx, ip, &info);
|
2010-07-03 22:22:09 +02:00
|
|
|
apply_frame_state(pair.effective, csw, context, &info.state, cfa);
|
2010-03-27 09:08:11 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-24 22:17:47 +01:00
|
|
|
static void dwarf2_location_compute(struct process* pcs,
|
2010-03-18 21:31:43 +01:00
|
|
|
const struct module_format* modfmt,
|
2006-11-24 22:17:47 +01:00
|
|
|
const struct symt_function* func,
|
|
|
|
struct location* loc)
|
|
|
|
{
|
2006-11-24 22:17:59 +01:00
|
|
|
struct location frame;
|
2010-03-24 22:04:00 +01:00
|
|
|
DWORD_PTR ip;
|
2006-11-24 22:17:59 +01:00
|
|
|
int err;
|
|
|
|
dwarf2_traverse_context_t lctx;
|
|
|
|
|
|
|
|
if (!func->container || func->container->tag != SymTagCompiland)
|
|
|
|
{
|
|
|
|
WARN("We'd expect function %s's container to exist and be a compiland\n", func->hash_elt.name);
|
|
|
|
err = loc_err_internal;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* instruction pointer relative to compiland's start */
|
|
|
|
ip = pcs->ctx_frame.InstructionOffset - ((struct symt_compiland*)func->container)->address;
|
|
|
|
|
2010-03-18 21:31:43 +01:00
|
|
|
if ((err = loc_compute_frame(pcs, modfmt, func, ip, &frame)) == 0)
|
2006-11-24 22:17:59 +01:00
|
|
|
{
|
|
|
|
switch (loc->kind)
|
|
|
|
{
|
|
|
|
case loc_dwarf2_location_list:
|
|
|
|
/* Then, if the variable has a location list, find it !! */
|
2010-03-18 21:31:43 +01:00
|
|
|
if (dwarf2_lookup_loclist(modfmt,
|
|
|
|
modfmt->u.dwarf2_info->debug_loc.address + loc->offset,
|
2006-11-24 22:17:59 +01:00
|
|
|
ip, &lctx))
|
|
|
|
goto do_compute;
|
|
|
|
err = loc_err_out_of_scope;
|
|
|
|
break;
|
|
|
|
case loc_dwarf2_block:
|
|
|
|
/* or if we have a copy of an existing block, get ready for it */
|
|
|
|
{
|
|
|
|
unsigned* ptr = (unsigned*)loc->offset;
|
|
|
|
|
|
|
|
lctx.data = (const BYTE*)(ptr + 1);
|
|
|
|
lctx.end_data = lctx.data + *ptr;
|
2010-03-24 22:04:06 +01:00
|
|
|
lctx.word_size = modfmt->u.dwarf2_info->word_size;
|
2006-11-24 22:17:59 +01:00
|
|
|
}
|
|
|
|
do_compute:
|
|
|
|
/* now get the variable */
|
2006-11-24 22:18:04 +01:00
|
|
|
err = compute_location(&lctx, loc, pcs->handle, &frame);
|
2006-11-24 22:17:59 +01:00
|
|
|
break;
|
|
|
|
case loc_register:
|
|
|
|
case loc_regrel:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN("Unsupported local kind %d\n", loc->kind);
|
|
|
|
err = loc_err_internal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err < 0)
|
|
|
|
{
|
|
|
|
loc->kind = loc_register;
|
|
|
|
loc->reg = err;
|
|
|
|
}
|
2006-11-24 22:17:47 +01:00
|
|
|
}
|
|
|
|
|
2010-03-18 21:31:43 +01:00
|
|
|
static void dwarf2_module_remove(struct process* pcs, struct module_format* modfmt)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, modfmt);
|
|
|
|
}
|
|
|
|
|
2010-03-18 21:31:26 +01:00
|
|
|
static inline BOOL dwarf2_init_section(dwarf2_section_t* section, struct image_file_map* fmap,
|
|
|
|
const char* sectname, struct image_section_map* ism)
|
|
|
|
{
|
|
|
|
struct image_section_map local_ism;
|
|
|
|
|
|
|
|
if (!ism) ism = &local_ism;
|
|
|
|
if (!image_find_section(fmap, sectname, ism))
|
|
|
|
{
|
|
|
|
section->address = NULL;
|
|
|
|
section->size = 0;
|
|
|
|
section->rva = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
section->address = (const BYTE*)image_map_section(ism);
|
|
|
|
section->size = image_get_map_size(ism);
|
|
|
|
section->rva = image_get_map_rva(ism);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-06-18 21:32:09 +02:00
|
|
|
BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
|
2006-06-24 09:50:10 +02:00
|
|
|
const struct elf_thunk_area* thunks,
|
2010-03-18 21:31:26 +01:00
|
|
|
struct image_file_map* fmap)
|
2006-06-18 21:32:09 +02:00
|
|
|
{
|
2011-01-24 15:52:42 +01:00
|
|
|
dwarf2_section_t eh_frame, section[section_max];
|
2008-04-30 21:27:49 +02:00
|
|
|
dwarf2_traverse_context_t mod_ctx;
|
2010-03-18 21:31:26 +01:00
|
|
|
struct image_section_map debug_sect, debug_str_sect, debug_abbrev_sect,
|
2011-01-24 15:52:42 +01:00
|
|
|
debug_line_sect, debug_ranges_sect, eh_frame_sect;
|
2010-03-18 21:31:26 +01:00
|
|
|
BOOL ret = TRUE;
|
2010-03-18 21:31:43 +01:00
|
|
|
struct module_format* dwarf2_modfmt;
|
2010-03-18 21:31:26 +01:00
|
|
|
|
2011-01-24 15:52:42 +01:00
|
|
|
dwarf2_init_section(&eh_frame, fmap, ".eh_frame", &eh_frame_sect);
|
|
|
|
dwarf2_init_section(§ion[section_debug], fmap, ".debug_info", &debug_sect);
|
2010-03-18 21:31:26 +01:00
|
|
|
dwarf2_init_section(§ion[section_abbrev], fmap, ".debug_abbrev", &debug_abbrev_sect);
|
|
|
|
dwarf2_init_section(§ion[section_string], fmap, ".debug_str", &debug_str_sect);
|
|
|
|
dwarf2_init_section(§ion[section_line], fmap, ".debug_line", &debug_line_sect);
|
2011-01-18 21:49:05 +01:00
|
|
|
dwarf2_init_section(§ion[section_ranges], fmap, ".debug_ranges", &debug_ranges_sect);
|
2010-03-18 21:31:26 +01:00
|
|
|
|
2011-01-24 15:52:42 +01:00
|
|
|
/* to do anything useful we need either .eh_frame or .debug_info */
|
|
|
|
if ((!eh_frame.address || eh_frame.address == IMAGE_NO_MAP) &&
|
|
|
|
(!section[section_debug].address || section[section_debug].address == IMAGE_NO_MAP))
|
2010-03-18 21:31:26 +01:00
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
|
2011-01-24 15:52:42 +01:00
|
|
|
if (fmap->modtype == DMT_ELF && debug_sect.fmap)
|
2010-03-18 21:31:26 +01:00
|
|
|
{
|
|
|
|
/* debug info might have a different base address than .so file
|
|
|
|
* when elf file is prelinked after splitting off debug info
|
|
|
|
* adjust symbol base addresses accordingly
|
|
|
|
*/
|
|
|
|
load_offset += fmap->u.elf.elf_start - debug_sect.fmap->u.elf.elf_start;
|
|
|
|
}
|
2008-04-30 21:27:49 +02:00
|
|
|
|
2010-03-18 21:31:26 +01:00
|
|
|
TRACE("Loading Dwarf2 information for %s\n", debugstr_w(module->module.ModuleName));
|
2006-06-18 21:32:09 +02:00
|
|
|
|
2010-03-20 09:47:54 +01:00
|
|
|
mod_ctx.data = section[section_debug].address;
|
2010-03-18 21:31:26 +01:00
|
|
|
mod_ctx.end_data = mod_ctx.data + section[section_debug].size;
|
2010-03-24 22:04:06 +01:00
|
|
|
mod_ctx.word_size = 0; /* will be correctly set later on */
|
2006-11-24 22:17:47 +01:00
|
|
|
|
2010-03-24 22:04:06 +01:00
|
|
|
dwarf2_modfmt = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(*dwarf2_modfmt) + sizeof(*dwarf2_modfmt->u.dwarf2_info));
|
|
|
|
if (!dwarf2_modfmt)
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
goto leave;
|
|
|
|
}
|
2010-03-18 21:31:43 +01:00
|
|
|
dwarf2_modfmt->module = module;
|
|
|
|
dwarf2_modfmt->remove = dwarf2_module_remove;
|
|
|
|
dwarf2_modfmt->loc_compute = dwarf2_location_compute;
|
2010-03-24 22:04:06 +01:00
|
|
|
dwarf2_modfmt->u.dwarf2_info = (struct dwarf2_module_info_s*)(dwarf2_modfmt + 1);
|
|
|
|
dwarf2_modfmt->u.dwarf2_info->word_size = 0; /* will be correctly set later on */
|
2010-03-18 21:31:43 +01:00
|
|
|
dwarf2_modfmt->module->format_info[DFI_DWARF] = dwarf2_modfmt;
|
|
|
|
|
2010-03-27 09:08:11 +01:00
|
|
|
/* As we'll need later some sections' content, we won't unmap these
|
|
|
|
* sections upon existing this function
|
|
|
|
*/
|
2010-03-24 22:04:06 +01:00
|
|
|
dwarf2_init_section(&dwarf2_modfmt->u.dwarf2_info->debug_loc, fmap, ".debug_loc", NULL);
|
2010-03-27 09:07:50 +01:00
|
|
|
dwarf2_init_section(&dwarf2_modfmt->u.dwarf2_info->debug_frame, fmap, ".debug_frame", NULL);
|
2011-01-24 15:52:42 +01:00
|
|
|
dwarf2_modfmt->u.dwarf2_info->eh_frame = eh_frame;
|
2006-11-24 22:17:26 +01:00
|
|
|
|
2008-04-30 21:27:49 +02:00
|
|
|
while (mod_ctx.data < mod_ctx.end_data)
|
2006-06-18 21:32:09 +02:00
|
|
|
{
|
2010-03-18 21:31:43 +01:00
|
|
|
dwarf2_parse_compilation_unit(section, dwarf2_modfmt->module, thunks, &mod_ctx, load_offset);
|
2006-06-18 21:32:09 +02:00
|
|
|
}
|
2010-03-18 21:31:43 +01:00
|
|
|
dwarf2_modfmt->module->module.SymType = SymDia;
|
|
|
|
dwarf2_modfmt->module->module.CVSig = 'D' | ('W' << 8) | ('A' << 16) | ('R' << 24);
|
2006-06-26 21:37:32 +02:00
|
|
|
/* FIXME: we could have a finer grain here */
|
2010-03-18 21:31:43 +01:00
|
|
|
dwarf2_modfmt->module->module.GlobalSymbols = TRUE;
|
|
|
|
dwarf2_modfmt->module->module.TypeInfo = TRUE;
|
|
|
|
dwarf2_modfmt->module->module.SourceIndexed = TRUE;
|
|
|
|
dwarf2_modfmt->module->module.Publics = TRUE;
|
2010-03-18 21:31:26 +01:00
|
|
|
|
|
|
|
leave:
|
|
|
|
image_unmap_section(&debug_sect);
|
|
|
|
image_unmap_section(&debug_abbrev_sect);
|
|
|
|
image_unmap_section(&debug_str_sect);
|
|
|
|
image_unmap_section(&debug_line_sect);
|
2011-01-18 21:49:05 +01:00
|
|
|
image_unmap_section(&debug_ranges_sect);
|
2011-01-24 15:52:42 +01:00
|
|
|
if (!ret) image_unmap_section(&eh_frame_sect);
|
2010-03-18 21:31:36 +01:00
|
|
|
|
2010-03-18 21:31:26 +01:00
|
|
|
return ret;
|
2005-05-18 11:46:12 +02:00
|
|
|
}
|