Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ typedef struct Srcpos
#define srcpos_name(p) (srcpos_sfile(p).SFname)
#endif
#if MARS
char *Sfilename;
const char *Sfilename;
#define srcpos_name(p) ((p).SFname)
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -4645,7 +4645,7 @@ elem *doptelem(elem *e,HINT goal)
void postoptelem(elem *e)
{
int linnum = 0;
char *filename = NULL;
const char *filename = NULL;

elem_debug(e);
while (1)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ typedef unsigned int IDXSYM;

struct linnum_data
{
char *filename;
const char *filename;
unsigned filenumber; // corresponding file number for DW_LNS_set_file

unsigned linoff_count;
Expand Down
179 changes: 142 additions & 37 deletions src/backend/dwarf.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,80 @@ static int hasModname; // 1 if has DW_TAG_module
// .debug_info
static IDXSEC infoseg;
static Outbuffer *infobuf;
static AArray *infoFileName_table;

static AArray *type_table;
static AArray *functype_table; // not sure why this cannot be combined with type_table
static Outbuffer *functypebuf;

// typeinfo declarations for hash of char*

struct Abuf
{
const unsigned char *buf;
size_t length;
};

struct TypeInfo_Abuf : TypeInfo
{
const char* toString();
hash_t getHash(void *p);
int equals(void *p1, void *p2);
int compare(void *p1, void *p2);
size_t tsize();
void swap(void *p1, void *p2);
};

TypeInfo_Abuf ti_abuf;

const char* TypeInfo_Abuf::toString()
{
return "Abuf";
}

hash_t TypeInfo_Abuf::getHash(void *p)
{
Abuf a = *(Abuf *)p;

hash_t hash = 0;
for (size_t i = 0; i < a.length; i++)
hash = hash * 11 + a.buf[i];

return hash;
}

int TypeInfo_Abuf::equals(void *p1, void *p2)
{
Abuf a1 = *(Abuf*)p1;
Abuf a2 = *(Abuf*)p2;

return a1.length == a2.length &&
memcmp(a1.buf, a2.buf, a1.length) == 0;
}

int TypeInfo_Abuf::compare(void *p1, void *p2)
{
Abuf a1 = *(Abuf*)p1;
Abuf a2 = *(Abuf*)p2;

if (a1.length == a2.length)
return memcmp(a1.buf, a2.buf, a1.length);
else if (a1.length < a2.length)
return -1;
else
return 1;
}

size_t TypeInfo_Abuf::tsize()
{
return sizeof(Abuf);
}

void TypeInfo_Abuf::swap(void *p1, void *p2)
{
assert(0);
}

#pragma pack(1)
struct DebugInfoHeader
{ unsigned total_length;
Expand Down Expand Up @@ -387,6 +456,11 @@ void dwarf_initfile(const char *filename)

/* ======================================== */

if (infoFileName_table)
{ delete infoFileName_table;
infoFileName_table = NULL;
}

lineseg = dwarf_getsegment(".debug_line", 0);
linebuf = SegData[lineseg]->SDbuf;

Expand Down Expand Up @@ -552,6 +626,46 @@ void dwarf_initfile(const char *filename)
debug_aranges_buf->write32(0); // pad to 16
}

/*************************************
* Add a file to the .debug_line header
*/
int dwarf_line_addfile(const char* filename)
{
if (!infoFileName_table)
infoFileName_table = new AArray(&ti_abuf, sizeof(unsigned));

Abuf abuf;
abuf.buf = (const unsigned char*)filename;
abuf.length = strlen(filename)-1;

unsigned *pidx = (unsigned *)infoFileName_table->get(&abuf);
if (!*pidx) // if no idx assigned yet
{
*pidx = infoFileName_table->length(); // assign newly computed idx

linebuf->writeString(filename);
linebuf->writeByte(0); // index
linebuf->writeByte(0); // mtime
linebuf->writeByte(0); // length
}

return *pidx;
}

int dwarf_line_getfile(const char* filename)
{
assert(infoFileName_table);

Abuf abuf;
abuf.buf = (const unsigned char*)filename;
abuf.length = strlen(filename)-1;

unsigned *pidx = (unsigned *)infoFileName_table->get(&abuf);
assert(pidx);

return *pidx;
}

void dwarf_initmodule(const char *filename, const char *modname)
{
if (modname)
Expand All @@ -573,6 +687,8 @@ void dwarf_initmodule(const char *filename, const char *modname)
}
else
hasModname = 0;

dwarf_line_addfile(filename);
}

void dwarf_termmodule()
Expand All @@ -594,13 +710,14 @@ void dwarf_termfile()
// Put out line number info

// file_names
unsigned filenumber = 0;
unsigned last_filenumber = 0;
const char* last_filename = NULL;
for (unsigned seg = 1; seg <= seg_count; seg++)
{
for (unsigned i = 0; i < SegData[seg]->SDlinnum_count; i++)
{
linnum_data *ld = &SegData[seg]->SDlinnum_data[i];
char *filename;
const char *filename;
#if MARS
filename = ld->filename;
#else
Expand All @@ -610,39 +727,17 @@ void dwarf_termfile()
else
filename = ::filename;
#endif
/* Look to see if filename has already been output
*/
for (unsigned s = 1; s < seg; s++)
if (last_filename == filename)
{
for (unsigned j = 0; j < SegData[s]->SDlinnum_count; j++)
{
char *f2;
linnum_data *ld2 = &SegData[s]->SDlinnum_data[j];

#if MARS
f2 = ld2->filename;
#else
Sfile *sf = ld2->filptr;
if (sf)
f2 = sf->SFname;
else
f2 = ::filename;
#endif
if (filename == f2)
{ ld->filenumber = ld2->filenumber;
goto L1;
}
}
ld->filenumber = last_filenumber;
}
else
{
ld->filenumber = dwarf_line_getfile(filename);

linebuf->writeString(filename);
ld->filenumber = ++filenumber;

linebuf->writeByte(0); // index
linebuf->writeByte(0); // mtime
linebuf->writeByte(0); // length
L1:
;
last_filenumber = ld->filenumber;
last_filename = filename;
}
}
}
linebuf->writeByte(0); // end of file_names
Expand Down Expand Up @@ -736,6 +831,10 @@ void dwarf_termfile()
linebuf->writeByte(DW_LNS_copy);
}

// Write DW_LNS_advance_pc to cover the function prologue
linebuf->writeByte(DW_LNS_advance_pc);
linebuf->writeByte(sd->SDbuf->size() - address);

// Write DW_LNE_end_sequence
linebuf->writeByte(0);
linebuf->writeByte(1);
Expand Down Expand Up @@ -908,6 +1007,13 @@ void dwarf_func_term(Symbol *sfunc)
IDXSEC seg = sfunc->Sseg;
seg_data *sd = SegData[seg];

#if MARS
const char* filename = sfunc->Sfunc->Fstartline.Sfilename;
int filenum = dwarf_line_getfile(filename);
#else
int filenum = 1;
#endif

unsigned ret_type = dwarf_typidx(sfunc->Stype->Tnext);
if (tybasic(sfunc->Stype->Tnext->Tty) == TYvoid)
ret_type = 0;
Expand Down Expand Up @@ -999,7 +1105,7 @@ void dwarf_func_term(Symbol *sfunc)
#endif
infobuf->writeString(name); // DW_AT_name
infobuf->writeString(sfunc->Sident); // DW_AT_MIPS_linkage_name
infobuf->writeByte(1); // DW_AT_decl_file
infobuf->writeByte(filenum); // DW_AT_decl_file
infobuf->writeWord(sfunc->Sfunc->Fstartline.Slinnum); // DW_AT_decl_line
if (ret_type)
infobuf->write32(ret_type); // DW_AT_type
Expand Down Expand Up @@ -1177,8 +1283,7 @@ void dwarf_func_term(Symbol *sfunc)
debug_loc_buf->write32(funcoffset + 3);
dwarf_addrel(debug_loc_seg, debug_loc_buf->size(), seg);
debug_loc_buf->write32(funcoffset + sfunc->Ssize);
//debug_loc_buf->write32(0x08750002);
debug_loc_buf->write32(0x00750002);
debug_loc_buf->write32(0x08750002);

debug_loc_buf->write32(0); // 2 words of 0 end it
debug_loc_buf->write32(0);
Expand Down Expand Up @@ -1305,7 +1410,7 @@ int TypeInfo_Atype::equals(void *p1, void *p2)
size_t len = a1.end - a1.start;

return len == a2.end - a2.start &&
memcmp(a1.buf->buf + a1.start, a1.buf->buf + a2.start, len) == 0;
memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len) == 0;
}

int TypeInfo_Atype::compare(void *p1, void *p2)
Expand All @@ -1314,7 +1419,7 @@ int TypeInfo_Atype::compare(void *p1, void *p2)
Atype a2 = *(Atype*)p2;
size_t len = a1.end - a1.start;
if (len == a2.end - a2.start)
return memcmp(a1.buf->buf + a1.start, a1.buf->buf + a2.start, len);
return memcmp(a1.buf->buf + a1.start, a2.buf->buf + a2.start, len);
else if (len < a2.end - a2.start)
return -1;
else
Expand Down
12 changes: 6 additions & 6 deletions src/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
((TypeFunction *)ftype)->isref = 1;
#endif

fop = new FuncDeclaration(0, 0, Id::assign, STCundefined, ftype);
fop = new FuncDeclaration(loc, 0, Id::assign, STCundefined, ftype);

Expression *e = NULL;
if (postblit)
Expand Down Expand Up @@ -335,7 +335,7 @@ FuncDeclaration *StructDeclaration::buildCpCtor(Scope *sc)
fparams->push(param);
Type *ftype = new TypeFunction(fparams, Type::tvoid, FALSE, LINKd);

fcp = new FuncDeclaration(0, 0, Id::cpctor, STCundefined, ftype);
fcp = new FuncDeclaration(loc, 0, Id::cpctor, STCundefined, ftype);
fcp->storage_class |= postblit->storage_class & STCdisable;

// Build *this = p;
Expand Down Expand Up @@ -434,7 +434,7 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
*/
if (e)
{ //printf("Building __fieldPostBlit()\n");
PostBlitDeclaration *dd = new PostBlitDeclaration(0, 0, Lexer::idPool("__fieldPostBlit"));
PostBlitDeclaration *dd = new PostBlitDeclaration(loc, 0, Lexer::idPool("__fieldPostBlit"));
dd->storage_class |= stc;
dd->fbody = new ExpStatement(0, e);
postblits.shift(dd);
Expand All @@ -460,7 +460,7 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
ex = new CallExp(0, ex);
e = Expression::combine(e, ex);
}
PostBlitDeclaration *dd = new PostBlitDeclaration(0, 0, Lexer::idPool("__aggrPostBlit"));
PostBlitDeclaration *dd = new PostBlitDeclaration(loc, 0, Lexer::idPool("__aggrPostBlit"));
dd->storage_class |= stc;
dd->fbody = new ExpStatement(0, e);
members->push(dd);
Expand Down Expand Up @@ -534,7 +534,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
*/
if (e)
{ //printf("Building __fieldDtor()\n");
DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__fieldDtor"));
DtorDeclaration *dd = new DtorDeclaration(loc, 0, Lexer::idPool("__fieldDtor"));
dd->fbody = new ExpStatement(0, e);
dtors.shift(dd);
members->push(dd);
Expand All @@ -559,7 +559,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
ex = new CallExp(0, ex);
e = Expression::combine(ex, e);
}
DtorDeclaration *dd = new DtorDeclaration(0, 0, Lexer::idPool("__aggrDtor"));
DtorDeclaration *dd = new DtorDeclaration(loc, 0, Lexer::idPool("__aggrDtor"));
dd->fbody = new ExpStatement(0, e);
members->push(dd);
dd->semantic(sc);
Expand Down
Loading