Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ddwarf #526

Merged
merged 4 commits into from Jan 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
169 changes: 169 additions & 0 deletions src/backend/dwarf.c
Expand Up @@ -1504,6 +1504,7 @@ unsigned dwarf_typidx(type *t)
DW_AT_byte_size, DW_FORM_data1, DW_AT_byte_size, DW_FORM_data1,
0, 0, 0, 0,
}; };
#ifdef USE_DWARF_D_EXTENSIONS
static unsigned char abbrevTypeDArray[] = static unsigned char abbrevTypeDArray[] =
{ {
DW_TAG_darray_type, DW_TAG_darray_type,
Expand Down Expand Up @@ -1537,6 +1538,7 @@ unsigned dwarf_typidx(type *t)
DW_AT_type, DW_FORM_ref4, // function type DW_AT_type, DW_FORM_ref4, // function type
0, 0, 0, 0,
}; };
#endif // USE_DWARF_D_EXTENSIONS
static unsigned char abbrevTypeConst[] = static unsigned char abbrevTypeConst[] =
{ {
DW_TAG_const_type, DW_TAG_const_type,
Expand Down Expand Up @@ -1622,9 +1624,33 @@ unsigned dwarf_typidx(type *t)
{ p = (tybasic(t->Tty) == TYullong) ? "unsigned long long" : "ucent"; { p = (tybasic(t->Tty) == TYullong) ? "unsigned long long" : "ucent";
goto Lsigned; goto Lsigned;
} }

#ifndef USE_DWARF_D_EXTENSIONS
static unsigned char abbrevTypeStruct[] =
{
DW_TAG_structure_type,
1, // children
DW_AT_sibling, DW_FORM_ref4,
DW_AT_name, DW_FORM_string,
DW_AT_byte_size, DW_FORM_data1,
0, 0,
};

static unsigned char abbrevTypeMember[] =
{
DW_TAG_member,
0, // no children
DW_AT_name, DW_FORM_string,
DW_AT_type, DW_FORM_ref4,
DW_AT_data_member_location, DW_FORM_block1,
0, 0,
};
#endif

/* It's really TYdarray, and Tnext is the /* It's really TYdarray, and Tnext is the
* element type * element type
*/ */
#ifdef USE_DWARF_D_EXTENSIONS
nextidx = dwarf_typidx(t->Tnext); nextidx = dwarf_typidx(t->Tnext);
code = nextidx code = nextidx
? dwarf_abbrev_code(abbrevTypeDArray, sizeof(abbrevTypeDArray)) ? dwarf_abbrev_code(abbrevTypeDArray, sizeof(abbrevTypeDArray))
Expand All @@ -1634,6 +1660,56 @@ unsigned dwarf_typidx(type *t)
infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size
if (nextidx) if (nextidx)
infobuf->write32(nextidx); // DW_AT_type infobuf->write32(nextidx); // DW_AT_type
#else
{
unsigned lenidx = I64 ? dwarf_typidx(tsulong) : dwarf_typidx(tsuns);

{
type *tdata = type_alloc(TYnptr);
tdata->Tnext = t->Tnext;
t->Tnext->Tcount++;
tdata->Tcount++;
nextidx = dwarf_typidx(tdata);
type_free(tdata);
}

code = dwarf_abbrev_code(abbrevTypeStruct, sizeof(abbrevTypeStruct));
idx = infobuf->size();
infobuf->writeuLEB128(code); // abbreviation code
unsigned siblingoffset = infobuf->size();
unsigned idxsibling = 0;
infobuf->write32(idxsibling); // DW_AT_sibling
infobuf->write("_Array_", 7); // DW_AT_name
if (tybasic(t->Tnext->Tty))
infobuf->writeString(tystring[tybasic(t->Tnext->Tty)]);
else
infobuf->writeByte(0);
infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size

// length
code = dwarf_abbrev_code(abbrevTypeMember, sizeof(abbrevTypeMember));
infobuf->writeuLEB128(code); // abbreviation code
infobuf->writeString("length"); // DW_AT_name
infobuf->write32(lenidx); // DW_AT_type

infobuf->writeByte(2); // DW_AT_data_member_location
infobuf->writeByte(DW_OP_plus_uconst);
infobuf->writeByte(0);

// ptr
infobuf->writeuLEB128(code); // abbreviation code
infobuf->writeString("ptr"); // DW_AT_name
infobuf->write32(nextidx); // DW_AT_type

infobuf->writeByte(2); // DW_AT_data_member_location
infobuf->writeByte(DW_OP_plus_uconst);
infobuf->writeByte(I64 ? 8 : 4);

infobuf->writeByte(0); // no more siblings
idxsibling = infobuf->size();
*(unsigned *)(infobuf->buf + siblingoffset) = idxsibling;
}
#endif
break; break;


case TYllong: case TYllong:
Expand All @@ -1645,6 +1721,7 @@ unsigned dwarf_typidx(type *t)
/* It's really TYdelegate, and Tnext is the /* It's really TYdelegate, and Tnext is the
* function type * function type
*/ */
#ifdef USE_DWARF_D_EXTENSIONS
{ type *tv = type_fake(TYnptr); { type *tv = type_fake(TYnptr);
tv->Tcount++; tv->Tcount++;
pvoididx = dwarf_typidx(tv); // void* is the 'this' type pvoididx = dwarf_typidx(tv); // void* is the 'this' type
Expand All @@ -1657,6 +1734,52 @@ unsigned dwarf_typidx(type *t)
infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size
infobuf->write32(pvoididx); // DW_AT_containing_type infobuf->write32(pvoididx); // DW_AT_containing_type
infobuf->write32(nextidx); // DW_AT_type infobuf->write32(nextidx); // DW_AT_type
#else
{
{
type *tp = type_fake(TYnptr);
tp->Tcount++;
pvoididx = dwarf_typidx(tp); // void*

tp->Tnext = t->Tnext; // fptr*
tp->Tnext->Tcount++;
nextidx = dwarf_typidx(tp);
type_free(tp);
}

code = dwarf_abbrev_code(abbrevTypeStruct, sizeof(abbrevTypeStruct));
idx = infobuf->size();
infobuf->writeuLEB128(code); // abbreviation code
unsigned siblingoffset = infobuf->size();
unsigned idxsibling = 0;
infobuf->write32(idxsibling); // DW_AT_sibling
infobuf->writeString("_Delegate"); // DW_AT_name
infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size

// ctxptr
code = dwarf_abbrev_code(abbrevTypeMember, sizeof(abbrevTypeMember));
infobuf->writeuLEB128(code); // abbreviation code
infobuf->writeString("ctxptr"); // DW_AT_name
infobuf->write32(pvoididx); // DW_AT_type

infobuf->writeByte(2); // DW_AT_data_member_location
infobuf->writeByte(DW_OP_plus_uconst);
infobuf->writeByte(0);

// funcptr
infobuf->writeuLEB128(code); // abbreviation code
infobuf->writeString("funcptr"); // DW_AT_name
infobuf->write32(nextidx); // DW_AT_type

infobuf->writeByte(2); // DW_AT_data_member_location
infobuf->writeByte(DW_OP_plus_uconst);
infobuf->writeByte(I64 ? 8 : 4);

infobuf->writeByte(0); // no more siblings
idxsibling = infobuf->size();
*(unsigned *)(infobuf->buf + siblingoffset) = idxsibling;
}
#endif
break; break;


case TYnref: case TYnref:
Expand All @@ -1668,6 +1791,7 @@ unsigned dwarf_typidx(type *t)
/* It's really TYaarray, and Tnext is the /* It's really TYaarray, and Tnext is the
* element type, Tkey is the key type * element type, Tkey is the key type
*/ */
#ifdef USE_DWARF_D_EXTENSIONS
keyidx = dwarf_typidx(t->Tkey); keyidx = dwarf_typidx(t->Tkey);
nextidx = dwarf_typidx(t->Tnext); nextidx = dwarf_typidx(t->Tnext);
code = dwarf_abbrev_code(abbrevTypeAArray, sizeof(abbrevTypeAArray)); code = dwarf_abbrev_code(abbrevTypeAArray, sizeof(abbrevTypeAArray));
Expand All @@ -1676,6 +1800,51 @@ unsigned dwarf_typidx(type *t)
infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size
infobuf->write32(nextidx); // DW_AT_type infobuf->write32(nextidx); // DW_AT_type
infobuf->write32(keyidx); // DW_AT_containing_type infobuf->write32(keyidx); // DW_AT_containing_type
#else
{
{
type *tp = type_fake(TYnptr);
tp->Tcount++;
pvoididx = dwarf_typidx(tp); // void*
}

code = dwarf_abbrev_code(abbrevTypeStruct, sizeof(abbrevTypeStruct));
idx = infobuf->size();
infobuf->writeuLEB128(code); // abbreviation code
unsigned siblingoffset = infobuf->size();
unsigned idxsibling = 0;
infobuf->write32(idxsibling); // DW_AT_sibling
infobuf->write("_AArray_", 8); // DW_AT_name
if (tybasic(t->Tkey->Tty))
p = tystring[tybasic(t->Tkey->Tty)];
else
p = "key";
infobuf->write(p, strlen(p));

infobuf->writeByte('_');
if (tybasic(t->Tnext->Tty))
p = tystring[tybasic(t->Tnext->Tty)];
else
p = "value";
infobuf->writeString(p);

infobuf->writeByte(tysize(t->Tty)); // DW_AT_byte_size

// ptr
code = dwarf_abbrev_code(abbrevTypeMember, sizeof(abbrevTypeMember));
infobuf->writeuLEB128(code); // abbreviation code
infobuf->writeString("ptr"); // DW_AT_name
infobuf->write32(pvoididx); // DW_AT_type

infobuf->writeByte(2); // DW_AT_data_member_location
infobuf->writeByte(DW_OP_plus_uconst);
infobuf->writeByte(0);

infobuf->writeByte(0); // no more siblings
idxsibling = infobuf->size();
*(unsigned *)(infobuf->buf + siblingoffset) = idxsibling;
}
#endif
break; break;


case TYvoid: return 0; case TYvoid: return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/dwarf.h
Expand Up @@ -4,6 +4,8 @@


/* ==================== Dwarf debug ======================= */ /* ==================== Dwarf debug ======================= */


// #define USE_DWARF_D_EXTENSIONS

void dwarf_initfile(const char *filename); void dwarf_initfile(const char *filename);
void dwarf_termfile(); void dwarf_termfile();
void dwarf_initmodule(const char *filename, const char *modulename); void dwarf_initmodule(const char *filename, const char *modulename);
Expand Down
2 changes: 2 additions & 0 deletions src/backend/dwarf2.h
Expand Up @@ -65,9 +65,11 @@ enum
DW_TAG_shared_type = 0x40, DW_TAG_shared_type = 0x40,


// D programming language extensions // D programming language extensions
#ifdef USE_DWARF_D_EXTENSIONS
DW_TAG_darray_type = 0x41, DW_TAG_darray_type = 0x41,
DW_TAG_aarray_type = 0x42, DW_TAG_aarray_type = 0x42,
DW_TAG_delegate_type = 0x43, DW_TAG_delegate_type = 0x43,
#endif


DW_TAG_lo_user = 0x4080, DW_TAG_lo_user = 0x4080,
DW_TAG_hi_user = 0xFFFF, DW_TAG_hi_user = 0xFFFF,
Expand Down