Commit 2aa6cf3e authored by Luuk van Dijk's avatar Luuk van Dijk

[68]l: more robust decoding of reflection type info in generating dwarf.

R=rsc
CC=golang-dev, golang-dev
https://golang.org/cl/4106041
parent 59a63952
...@@ -798,6 +798,17 @@ decode_reloc(Sym *s, int32 off) ...@@ -798,6 +798,17 @@ decode_reloc(Sym *s, int32 off)
return nil; return nil;
} }
static Sym*
decode_reloc_sym(Sym *s, int32 off)
{
Reloc *r;
r = decode_reloc(s,off);
if (r == nil)
return nil;
return r->sym;
}
static uvlong static uvlong
decode_inuxi(uchar* p, int sz) decode_inuxi(uchar* p, int sz)
{ {
...@@ -851,7 +862,7 @@ decodetype_size(Sym *s) ...@@ -851,7 +862,7 @@ decodetype_size(Sym *s)
static Sym* static Sym*
decodetype_arrayelem(Sym *s) decodetype_arrayelem(Sym *s)
{ {
return decode_reloc(s, 5*PtrSize + 8)->sym; // 0x1c / 0x30 return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30
} }
static vlong static vlong
...@@ -864,26 +875,26 @@ decodetype_arraylen(Sym *s) ...@@ -864,26 +875,26 @@ decodetype_arraylen(Sym *s)
static Sym* static Sym*
decodetype_ptrelem(Sym *s) decodetype_ptrelem(Sym *s)
{ {
return decode_reloc(s, 5*PtrSize + 8)->sym; // 0x1c / 0x30 return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30
} }
// Type.MapType.key, elem // Type.MapType.key, elem
static Sym* static Sym*
decodetype_mapkey(Sym *s) decodetype_mapkey(Sym *s)
{ {
return decode_reloc(s, 5*PtrSize + 8)->sym; // 0x1c / 0x30 return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30
} }
static Sym* static Sym*
decodetype_mapvalue(Sym *s) decodetype_mapvalue(Sym *s)
{ {
return decode_reloc(s, 6*PtrSize + 8)->sym; // 0x20 / 0x38 return decode_reloc_sym(s, 6*PtrSize + 8); // 0x20 / 0x38
} }
// Type.ChanType.elem // Type.ChanType.elem
static Sym* static Sym*
decodetype_chanelem(Sym *s) decodetype_chanelem(Sym *s)
{ {
return decode_reloc(s, 5*PtrSize + 8)->sym; // 0x1c / 0x30 return decode_reloc_sym(s, 5*PtrSize + 8); // 0x1c / 0x30
} }
// Type.FuncType.dotdotdot // Type.FuncType.dotdotdot
...@@ -912,7 +923,9 @@ decodetype_funcintype(Sym *s, int i) ...@@ -912,7 +923,9 @@ decodetype_funcintype(Sym *s, int i)
Reloc *r; Reloc *r;
r = decode_reloc(s, 6*PtrSize + 8); r = decode_reloc(s, 6*PtrSize + 8);
return decode_reloc(r->sym, r->add + i * PtrSize)->sym; if (r == nil)
return nil;
return decode_reloc_sym(r->sym, r->add + i * PtrSize);
} }
static Sym* static Sym*
...@@ -921,7 +934,9 @@ decodetype_funcouttype(Sym *s, int i) ...@@ -921,7 +934,9 @@ decodetype_funcouttype(Sym *s, int i)
Reloc *r; Reloc *r;
r = decode_reloc(s, 7*PtrSize + 16); r = decode_reloc(s, 7*PtrSize + 16);
return decode_reloc(r->sym, r->add + i * PtrSize)->sym; if (r == nil)
return nil;
return decode_reloc_sym(r->sym, r->add + i * PtrSize);
} }
// Type.StructType.fields.Slice::len // Type.StructType.fields.Slice::len
...@@ -935,21 +950,20 @@ decodetype_structfieldcount(Sym *s) ...@@ -935,21 +950,20 @@ decodetype_structfieldcount(Sym *s)
static char* static char*
decodetype_structfieldname(Sym *s, int i) decodetype_structfieldname(Sym *s, int i)
{ {
Reloc* r; // go.string."foo" 0x28 / 0x40
s = decode_reloc_sym(s, 6*PtrSize + 0x10 + i*5*PtrSize);
r = decode_reloc(s, 6*PtrSize + 0x10 + i*5*PtrSize); // go.string."foo" 0x28 / 0x40 if (s == nil) // embedded structs have a nil name.
if (r == nil) // embedded structs have a nil name.
return nil; return nil;
r = decode_reloc(r->sym, 0); // string."foo" s = decode_reloc_sym(s, 0); // string."foo"
if (r == nil) // shouldn't happen. if (s == nil) // shouldn't happen.
return nil; return nil;
return (char*)r->sym->p; // the c-string return (char*)s->p; // the c-string
} }
static Sym* static Sym*
decodetype_structfieldtype(Sym *s, int i) decodetype_structfieldtype(Sym *s, int i)
{ {
return decode_reloc(s, 8*PtrSize + 0x10 + i*5*PtrSize)->sym; // 0x30 / 0x50 return decode_reloc_sym(s, 8*PtrSize + 0x10 + i*5*PtrSize); // 0x30 / 0x50
} }
static vlong static vlong
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment