Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO/NICETOHAVE: | 5 // TODO/NICETOHAVE: |
6 // - eliminate DW_CLS_ if not used | 6 // - eliminate DW_CLS_ if not used |
7 // - package info in compilation units | 7 // - package info in compilation units |
8 // - assign global variables and types to their packages | 8 // - assign global variables and types to their packages |
9 // - (upstream) type info for C parts of runtime | 9 // - (upstream) type info for C parts of runtime |
10 // - gdb uses c syntax, meaning clumsy quoting is needed for go identifiers. e g | 10 // - gdb uses c syntax, meaning clumsy quoting is needed for go identifiers. e g |
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 // Fake attributes for slices, maps and channel | 983 // Fake attributes for slices, maps and channel |
984 enum { | 984 enum { |
985 DW_AT_internal_elem_type = 250, // channels and slices | 985 DW_AT_internal_elem_type = 250, // channels and slices |
986 DW_AT_internal_key_type = 251, // maps | 986 DW_AT_internal_key_type = 251, // maps |
987 DW_AT_internal_val_type = 252, // maps | 987 DW_AT_internal_val_type = 252, // maps |
988 DW_AT_internal_location = 253, // params and locals | 988 DW_AT_internal_location = 253, // params and locals |
989 }; | 989 }; |
990 | 990 |
991 static DWDie* defptrto(DWDie *dwtype); // below | 991 static DWDie* defptrto(DWDie *dwtype); // below |
992 | 992 |
993 // Lookup predefined types | |
994 static Sym* | |
995 lookup_or_diag(char *n) { | |
rsc
2011/01/26 17:11:26
\n before {
| |
996 Sym *s; | |
997 | |
998 s = lookup(n,0); | |
rsc
2011/01/26 17:11:26
s/,/, /
| |
999 if (s->size == 0) | |
1000 diag("missing type:%s", n); | |
rsc
2011/01/26 17:11:26
s/:/: /
s/missing/dwarf: missing
if the caller is
| |
1001 return s; | |
1002 } | |
1003 | |
993 // Define gotype, for composite ones recurse into constituents. | 1004 // Define gotype, for composite ones recurse into constituents. |
994 static DWDie* | 1005 static DWDie* |
995 defgotype(Sym *gotype) | 1006 defgotype(Sym *gotype) |
996 { | 1007 { |
997 DWDie *die, *fld; | 1008 DWDie *die, *fld; |
998 Sym *s; | 1009 Sym *s; |
999 char *name, *f; | 1010 char *name, *f; |
1000 uint8 kind; | 1011 uint8 kind; |
1001 vlong bytesize; | 1012 vlong bytesize; |
1002 int i, nfields; | 1013 int i, nfields; |
1003 | 1014 |
1004 if (gotype == nil) | 1015 if (gotype == nil) |
1005 return find_or_diag(&dwtypes, "<unspecified>"); | 1016 return find_or_diag(&dwtypes, "<unspecified>"); |
1006 | 1017 |
1007 if (strncmp("type.", gotype->name, 5) != 0) { | 1018 if (strncmp("type.", gotype->name, 5) != 0) { |
1008 diag("Type name doesn't start with \".type\": %s", gotype->name) ; | 1019 diag("Type name doesn't start with \".type\": %s", gotype->name) ; |
1009 return find_or_diag(&dwtypes, "<unspecified>"); | 1020 return find_or_diag(&dwtypes, "<unspecified>"); |
1010 } | 1021 } |
1011 » name = gotype->name + 5; // Altenatively decode from Type.string | 1022 » name = gotype->name + 5; // Alternatively decode from Type.string |
rsc
2011/01/26 17:11:26
s/Alternatively/could also/
| |
1012 | 1023 |
1013 die = find(&dwtypes, name); | 1024 die = find(&dwtypes, name); |
1014 if (die != nil) | 1025 if (die != nil) |
1015 return die; | 1026 return die; |
1016 | 1027 |
1017 » if (0 && debug['v'] > 2) { | 1028 » if (1 && debug['v'] > 2) { |
rsc
2011/01/26 17:11:26
s/1/0/
| |
1018 print("new type: %s @0x%08x [%d]", gotype->name, gotype->value, gotype->size); | 1029 print("new type: %s @0x%08x [%d]", gotype->name, gotype->value, gotype->size); |
1019 for (i = 0; i < gotype->size; i++) { | 1030 for (i = 0; i < gotype->size; i++) { |
1020 if (!(i%8)) print("\n\t%04x ", i); | 1031 if (!(i%8)) print("\n\t%04x ", i); |
1021 print("%02x ", gotype->p[i]); | 1032 print("%02x ", gotype->p[i]); |
1022 } | 1033 } |
1023 print("\n"); | 1034 print("\n"); |
1024 for (i = 0; i < gotype->nr; i++) { | 1035 for (i = 0; i < gotype->nr; i++) { |
1025 print("\t0x%02x[%x] %d %s[%llx]\n", | 1036 print("\t0x%02x[%x] %d %s[%llx]\n", |
1026 gotype->r[i].off, | 1037 gotype->r[i].off, |
1027 gotype->r[i].siz, | 1038 gotype->r[i].siz, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 newrefattr(fld, DW_AT_type, defptrto(defgotype(s))); | 1122 newrefattr(fld, DW_AT_type, defptrto(defgotype(s))); |
1112 } | 1123 } |
1113 die = defptrto(die); | 1124 die = defptrto(die); |
1114 break; | 1125 break; |
1115 | 1126 |
1116 case KindInterface: | 1127 case KindInterface: |
1117 die = newdie(&dwtypes, DW_ABRV_IFACETYPE, name); | 1128 die = newdie(&dwtypes, DW_ABRV_IFACETYPE, name); |
1118 newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, bytesize, 0); | 1129 newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, bytesize, 0); |
1119 nfields = decodetype_ifacemethodcount(gotype); | 1130 nfields = decodetype_ifacemethodcount(gotype); |
1120 if (nfields == 0) | 1131 if (nfields == 0) |
1121 » » » s = lookup("type.runtime.eface", 0); | 1132 » » » s = lookup_or_diag("type.runtime.eface"); |
1122 else | 1133 else |
1123 » » » s = lookup("type.runtime.iface", 0); | 1134 » » » s = lookup_or_diag("type.runtime.iface"); |
1124 newrefattr(die, DW_AT_type, defgotype(s)); | 1135 newrefattr(die, DW_AT_type, defgotype(s)); |
1125 break; | 1136 break; |
1126 | 1137 |
1127 case KindMap: | 1138 case KindMap: |
1128 die = newdie(&dwtypes, DW_ABRV_MAPTYPE, name); | 1139 die = newdie(&dwtypes, DW_ABRV_MAPTYPE, name); |
1129 s = decodetype_mapkey(gotype); | 1140 s = decodetype_mapkey(gotype); |
1130 newrefattr(die, DW_AT_internal_key_type, defgotype(s)); | 1141 newrefattr(die, DW_AT_internal_key_type, defgotype(s)); |
1131 s = decodetype_mapvalue(gotype); | 1142 s = decodetype_mapvalue(gotype); |
1132 newrefattr(die, DW_AT_internal_val_type, defgotype(s)); | 1143 newrefattr(die, DW_AT_internal_val_type, defgotype(s)); |
1133 break; | 1144 break; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 a->data = (char*) dwtype; | 1241 a->data = (char*) dwtype; |
1231 else | 1242 else |
1232 newrefattr(child, DW_AT_type, dwtype); | 1243 newrefattr(child, DW_AT_type, dwtype); |
1233 } | 1244 } |
1234 | 1245 |
1235 static void | 1246 static void |
1236 synthesizestringtypes(DWDie* die) | 1247 synthesizestringtypes(DWDie* die) |
1237 { | 1248 { |
1238 DWDie *prototype; | 1249 DWDie *prototype; |
1239 | 1250 |
1240 » prototype = defgotype(lookup("type.runtime.string_", 0)); | 1251 » prototype = defgotype(lookup_or_diag("type.string")); |
1241 if (prototype == nil) | 1252 if (prototype == nil) |
1242 » » return; | 1253 return; |
1243 | 1254 |
1244 for (; die != nil; die = die->link) { | 1255 for (; die != nil; die = die->link) { |
1245 if (die->abbrev != DW_ABRV_STRINGTYPE) | 1256 if (die->abbrev != DW_ABRV_STRINGTYPE) |
1246 continue; | 1257 continue; |
1247 copychildren(die, prototype); | 1258 copychildren(die, prototype); |
1248 } | 1259 } |
1249 } | 1260 } |
1250 | 1261 |
1251 static void | 1262 static void |
1252 synthesizeslicetypes(DWDie *die) | 1263 synthesizeslicetypes(DWDie *die) |
1253 { | 1264 { |
1254 DWDie *prototype, *elem; | 1265 DWDie *prototype, *elem; |
1255 | 1266 |
1256 » prototype = defgotype(lookup("type.runtime.slice",0)); | 1267 » prototype = defgotype(lookup_or_diag("type.runtime.slice")); |
1257 if (prototype == nil) | 1268 if (prototype == nil) |
1258 return; | 1269 return; |
1259 | 1270 |
1260 for (; die != nil; die = die->link) { | 1271 for (; die != nil; die = die->link) { |
1261 if (die->abbrev != DW_ABRV_SLICETYPE) | 1272 if (die->abbrev != DW_ABRV_SLICETYPE) |
1262 continue; | 1273 continue; |
1263 copychildren(die, prototype); | 1274 copychildren(die, prototype); |
1264 elem = (DWDie*) getattr(die, DW_AT_internal_elem_type)->data; | 1275 elem = (DWDie*) getattr(die, DW_AT_internal_elem_type)->data; |
1265 substitutetype(die, "array", defptrto(elem)); | 1276 substitutetype(die, "array", defptrto(elem)); |
1266 } | 1277 } |
(...skipping 18 matching lines...) Expand all Loading... | |
1285 // synthesizemaptypes is way too closely married to runtime/hashmap.c | 1296 // synthesizemaptypes is way too closely married to runtime/hashmap.c |
1286 enum { | 1297 enum { |
1287 MaxValsize = 256 - 64 | 1298 MaxValsize = 256 - 64 |
1288 }; | 1299 }; |
1289 | 1300 |
1290 static void | 1301 static void |
1291 synthesizemaptypes(DWDie *die) | 1302 synthesizemaptypes(DWDie *die) |
1292 { | 1303 { |
1293 | 1304 |
1294 DWDie *hash, *hash_subtable, *hash_entry, | 1305 DWDie *hash, *hash_subtable, *hash_entry, |
1295 » » *dwh, *dwhs, *dwhe, *keytype, *valtype, *fld; | 1306 » » *dwh, *dwhs, *dwhe, *dwhash, *keytype, *valtype, *fld; |
1296 int hashsize, keysize, valsize, datsize, valsize_in_hash, datavo; | 1307 int hashsize, keysize, valsize, datsize, valsize_in_hash, datavo; |
1297 DWAttr *a; | 1308 DWAttr *a; |
1298 | 1309 |
1299 » hash» » = defgotype(lookup("type.runtime.hash",0)); | 1310 » hash» » = defgotype(lookup_or_diag("type.runtime.hmap")); |
1300 » hash_subtable» = defgotype(lookup("type.runtime.hash_subtable",0)); | 1311 » hash_subtable» = defgotype(lookup_or_diag("type.runtime.hash_subtable") ); |
1301 » hash_entry» = defgotype(lookup("type.runtime.hash_entry",0)); | 1312 » hash_entry» = defgotype(lookup_or_diag("type.runtime.hash_entry")); |
1302 | 1313 |
1303 if (hash == nil || hash_subtable == nil || hash_entry == nil) | 1314 if (hash == nil || hash_subtable == nil || hash_entry == nil) |
1304 return; | 1315 return; |
1305 | 1316 |
1306 » dwh = (DWDie*)getattr(find_or_diag(hash_entry, "hash"), DW_AT_type)->dat a; | 1317 » dwhash = (DWDie*)getattr(find_or_diag(hash_entry, "hash"), DW_AT_type)-> data; |
1307 » if (dwh == nil) | 1318 » if (dwhash == nil) |
1308 return; | 1319 return; |
1309 | 1320 |
1310 » hashsize = getattr(dwh, DW_AT_byte_size)->value; | 1321 » hashsize = getattr(dwhash, DW_AT_byte_size)->value; |
1311 | 1322 |
1312 for (; die != nil; die = die->link) { | 1323 for (; die != nil; die = die->link) { |
1313 if (die->abbrev != DW_ABRV_MAPTYPE) | 1324 if (die->abbrev != DW_ABRV_MAPTYPE) |
1314 continue; | 1325 continue; |
1315 | 1326 |
1316 keytype = (DWDie*) getattr(die, DW_AT_internal_key_type)->data; | 1327 keytype = (DWDie*) getattr(die, DW_AT_internal_key_type)->data; |
1317 valtype = (DWDie*) getattr(die, DW_AT_internal_val_type)->data; | 1328 valtype = (DWDie*) getattr(die, DW_AT_internal_val_type)->data; |
1318 | 1329 |
1319 a = getattr(keytype, DW_AT_byte_size); | 1330 a = getattr(keytype, DW_AT_byte_size); |
1320 keysize = a ? a->value : PtrSize; // We don't store size with P ointers | 1331 keysize = a ? a->value : PtrSize; // We don't store size with P ointers |
(...skipping 11 matching lines...) Expand all Loading... | |
1332 datsize = datavo + valsize_in_hash; | 1343 datsize = datavo + valsize_in_hash; |
1333 if (datsize < PtrSize) | 1344 if (datsize < PtrSize) |
1334 datsize = PtrSize; | 1345 datsize = PtrSize; |
1335 datsize = rnd(datsize, PtrSize); | 1346 datsize = rnd(datsize, PtrSize); |
1336 | 1347 |
1337 // Construct struct hash_entry<K,V> | 1348 // Construct struct hash_entry<K,V> |
1338 dwhe = newdie(&dwtypes, DW_ABRV_STRUCTTYPE, | 1349 dwhe = newdie(&dwtypes, DW_ABRV_STRUCTTYPE, |
1339 mkinternaltypename("hash_entry", | 1350 mkinternaltypename("hash_entry", |
1340 getattr(keytype, DW_AT_name)->data, | 1351 getattr(keytype, DW_AT_name)->data, |
1341 getattr(valtype, DW_AT_name)->data)); | 1352 getattr(valtype, DW_AT_name)->data)); |
1342 » » copychildren(dwhe, hash_entry); | 1353 |
1343 » » substitutetype(dwhe, "key", keytype); | 1354 fld = newdie(dwhe, DW_ABRV_STRUCTFIELD, "hash"); |
1355 newrefattr(fld, DW_AT_type, dwhash); | |
1356 newmemberoffsetattr(fld, 0); | |
1357 | |
1358 fld = newdie(dwhe, DW_ABRV_STRUCTFIELD, "key"); | |
1359 newrefattr(fld, DW_AT_type, keytype); | |
1360 newmemberoffsetattr(fld, hashsize); | |
1361 | |
1362 fld = newdie(dwhe, DW_ABRV_STRUCTFIELD, "val"); | |
1344 if (valsize > MaxValsize) | 1363 if (valsize > MaxValsize) |
1345 valtype = defptrto(valtype); | 1364 valtype = defptrto(valtype); |
1346 » » substitutetype(dwhe, "val", valtype); | 1365 newrefattr(fld, DW_AT_type, valtype); |
1347 » » fld = find_or_diag(dwhe, "val"); | |
1348 » » delattr(fld, DW_AT_data_member_location); | |
1349 newmemberoffsetattr(fld, hashsize + datavo); | 1366 newmemberoffsetattr(fld, hashsize + datavo); |
1350 newattr(dwhe, DW_AT_byte_size, DW_CLS_CONSTANT, hashsize + datsi ze, NULL); | 1367 newattr(dwhe, DW_AT_byte_size, DW_CLS_CONSTANT, hashsize + datsi ze, NULL); |
1351 | 1368 |
1352 // Construct hash_subtable<hash_entry<K,V>> | 1369 // Construct hash_subtable<hash_entry<K,V>> |
1353 dwhs = newdie(&dwtypes, DW_ABRV_STRUCTTYPE, | 1370 dwhs = newdie(&dwtypes, DW_ABRV_STRUCTTYPE, |
1354 mkinternaltypename("hash_subtable", | 1371 mkinternaltypename("hash_subtable", |
1355 getattr(keytype, DW_AT_name)->data, | 1372 getattr(keytype, DW_AT_name)->data, |
1356 getattr(valtype, DW_AT_name)->data)); | 1373 getattr(valtype, DW_AT_name)->data)); |
1357 copychildren(dwhs, hash_subtable); | 1374 copychildren(dwhs, hash_subtable); |
1358 substitutetype(dwhs, "end", defptrto(dwhe)); | 1375 substitutetype(dwhs, "end", defptrto(dwhe)); |
(...skipping 16 matching lines...) Expand all Loading... | |
1375 } | 1392 } |
1376 | 1393 |
1377 static void | 1394 static void |
1378 synthesizechantypes(DWDie *die) | 1395 synthesizechantypes(DWDie *die) |
1379 { | 1396 { |
1380 DWDie *sudog, *waitq, *link, *hchan, | 1397 DWDie *sudog, *waitq, *link, *hchan, |
1381 *dws, *dww, *dwl, *dwh, *elemtype; | 1398 *dws, *dww, *dwl, *dwh, *elemtype; |
1382 DWAttr *a; | 1399 DWAttr *a; |
1383 int elemsize, linksize, sudogsize; | 1400 int elemsize, linksize, sudogsize; |
1384 | 1401 |
1385 » sudog = defgotype(lookup("type.runtime.sudoG",0)); | 1402 » sudog = defgotype(lookup_or_diag("type.runtime.sudog")); |
1386 » waitq = defgotype(lookup("type.runtime.waitQ",0)); | 1403 » waitq = defgotype(lookup_or_diag("type.runtime.waitq")); |
1387 » link = defgotype(lookup("type.runtime.link",0)); | 1404 » link = defgotype(lookup_or_diag("type.runtime.link")); |
1388 » hchan = defgotype(lookup("type.runtime.hChan",0)); | 1405 » hchan = defgotype(lookup_or_diag("type.runtime.hchan")); |
1389 if (sudog == nil || waitq == nil || link == nil || hchan == nil) | 1406 if (sudog == nil || waitq == nil || link == nil || hchan == nil) |
1390 return; | 1407 return; |
1391 | 1408 |
1392 sudogsize = getattr(sudog, DW_AT_byte_size)->value; | 1409 sudogsize = getattr(sudog, DW_AT_byte_size)->value; |
1393 linksize = getattr(link, DW_AT_byte_size)->value; | 1410 linksize = getattr(link, DW_AT_byte_size)->value; |
1394 | 1411 |
1395 for (; die != nil; die = die->link) { | 1412 for (; die != nil; die = die->link) { |
1396 if (die->abbrev != DW_ABRV_CHANTYPE) | 1413 if (die->abbrev != DW_ABRV_CHANTYPE) |
1397 continue; | 1414 continue; |
1398 elemtype = (DWDie*) getattr(die, DW_AT_internal_elem_type)->data ; | 1415 elemtype = (DWDie*) getattr(die, DW_AT_internal_elem_type)->data ; |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2324 // Some types that must exist to define other ones. | 2341 // Some types that must exist to define other ones. |
2325 newdie(&dwtypes, DW_ABRV_NULLTYPE, "<unspecified>"); | 2342 newdie(&dwtypes, DW_ABRV_NULLTYPE, "<unspecified>"); |
2326 newdie(&dwtypes, DW_ABRV_NULLTYPE, "void"); | 2343 newdie(&dwtypes, DW_ABRV_NULLTYPE, "void"); |
2327 newrefattr(newdie(&dwtypes, DW_ABRV_PTRTYPE, "unsafe.Pointer"), | 2344 newrefattr(newdie(&dwtypes, DW_ABRV_PTRTYPE, "unsafe.Pointer"), |
2328 DW_AT_type, find(&dwtypes, "void")); | 2345 DW_AT_type, find(&dwtypes, "void")); |
2329 die = newdie(&dwtypes, DW_ABRV_BASETYPE, "uintptr"); // needed for arra y size | 2346 die = newdie(&dwtypes, DW_ABRV_BASETYPE, "uintptr"); // needed for arra y size |
2330 newattr(die, DW_AT_encoding, DW_CLS_CONSTANT, DW_ATE_unsigned, 0); | 2347 newattr(die, DW_AT_encoding, DW_CLS_CONSTANT, DW_ATE_unsigned, 0); |
2331 newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, PtrSize, 0); | 2348 newattr(die, DW_AT_byte_size, DW_CLS_CONSTANT, PtrSize, 0); |
2332 | 2349 |
2333 // Needed by the prettyprinter code for interface inspection. | 2350 // Needed by the prettyprinter code for interface inspection. |
2334 » defgotype(lookup("type.runtime.commonType",0)); | 2351 » defgotype(lookup_or_diag("type.runtime.commonType")); |
2335 » defgotype(lookup("type.runtime.InterfaceType",0)); | 2352 » defgotype(lookup_or_diag("type.runtime.InterfaceType")); |
2336 » defgotype(lookup("type.runtime.itab",0)); | 2353 » defgotype(lookup_or_diag("type.runtime.itab")); |
2337 | 2354 |
2338 genasmsym(defdwsymb); | 2355 genasmsym(defdwsymb); |
2339 | 2356 |
2340 writeabbrev(); | 2357 writeabbrev(); |
2341 align(abbrevsize); | 2358 align(abbrevsize); |
2342 writelines(); | 2359 writelines(); |
2343 align(linesize); | 2360 align(linesize); |
2344 writeframes(); | 2361 writeframes(); |
2345 align(framesize); | 2362 align(framesize); |
2346 | 2363 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2587 newPEDWARFSection(".debug_info", infosize); | 2604 newPEDWARFSection(".debug_info", infosize); |
2588 if (pubnamessize > 0) | 2605 if (pubnamessize > 0) |
2589 newPEDWARFSection(".debug_pubnames", pubnamessize); | 2606 newPEDWARFSection(".debug_pubnames", pubnamessize); |
2590 if (pubtypessize > 0) | 2607 if (pubtypessize > 0) |
2591 newPEDWARFSection(".debug_pubtypes", pubtypessize); | 2608 newPEDWARFSection(".debug_pubtypes", pubtypessize); |
2592 if (arangessize > 0) | 2609 if (arangessize > 0) |
2593 newPEDWARFSection(".debug_aranges", arangessize); | 2610 newPEDWARFSection(".debug_aranges", arangessize); |
2594 if (gdbscriptsize > 0) | 2611 if (gdbscriptsize > 0) |
2595 newPEDWARFSection(".debug_gdb_scripts", gdbscriptsize); | 2612 newPEDWARFSection(".debug_gdb_scripts", gdbscriptsize); |
2596 } | 2613 } |
OLD | NEW |