Mercurial > hg > CbC > CbC_gcc
comparison libbacktrace/xcoff.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* xcoff.c -- Get debug data from an XCOFF file for backtraces. | 1 /* xcoff.c -- Get debug data from an XCOFF file for backtraces. |
2 Copyright (C) 2012-2018 Free Software Foundation, Inc. | 2 Copyright (C) 2012-2020 Free Software Foundation, Inc. |
3 Adapted from elf.c. | 3 Adapted from elf.c. |
4 | 4 |
5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are | 6 modification, are permitted provided that the following conditions are |
7 met: | 7 met: |
385 uint64_t lnnoptr0; | 385 uint64_t lnnoptr0; |
386 /* Loader address. */ | 386 /* Loader address. */ |
387 uintptr_t base_address; | 387 uintptr_t base_address; |
388 }; | 388 }; |
389 | 389 |
390 /* An index of DWARF sections we care about. */ | |
391 | |
392 enum dwarf_section | |
393 { | |
394 DWSECT_INFO, | |
395 DWSECT_LINE, | |
396 DWSECT_ABBREV, | |
397 DWSECT_RANGES, | |
398 DWSECT_STR, | |
399 DWSECT_MAX | |
400 }; | |
401 | |
402 /* Information we gather for the DWARF sections we care about. */ | 390 /* Information we gather for the DWARF sections we care about. */ |
403 | 391 |
404 struct dwsect_info | 392 struct dwsect_info |
405 { | 393 { |
406 /* Section file offset. */ | 394 /* Section file offset. */ |
1098 uint64_t lnnoptr; | 1086 uint64_t lnnoptr; |
1099 uint32_t nlnno; | 1087 uint32_t nlnno; |
1100 off_t str_off; | 1088 off_t str_off; |
1101 off_t min_offset; | 1089 off_t min_offset; |
1102 off_t max_offset; | 1090 off_t max_offset; |
1103 struct dwsect_info dwsect[DWSECT_MAX]; | 1091 struct dwsect_info dwsect[DEBUG_MAX]; |
1104 size_t sects_size; | 1092 size_t sects_size; |
1105 size_t syms_size; | 1093 size_t syms_size; |
1106 int32_t str_size; | 1094 int32_t str_size; |
1107 int sects_view_valid; | 1095 int sects_view_valid; |
1108 int linenos_view_valid; | 1096 int linenos_view_valid; |
1109 int syms_view_valid; | 1097 int syms_view_valid; |
1110 int str_view_valid; | 1098 int str_view_valid; |
1111 int dwarf_view_valid; | 1099 int dwarf_view_valid; |
1112 int magic_ok; | 1100 int magic_ok; |
1113 int i; | 1101 int i; |
1102 struct dwarf_sections dwarf_sections; | |
1114 | 1103 |
1115 *found_sym = 0; | 1104 *found_sym = 0; |
1116 | 1105 |
1117 sects_view_valid = 0; | 1106 sects_view_valid = 0; |
1118 linenos_view_valid = 0; | 1107 linenos_view_valid = 0; |
1253 continue; | 1242 continue; |
1254 /* Map DWARF section to array index. */ | 1243 /* Map DWARF section to array index. */ |
1255 switch (sects[i].s_flags & 0xffff0000) | 1244 switch (sects[i].s_flags & 0xffff0000) |
1256 { | 1245 { |
1257 case SSUBTYP_DWINFO: | 1246 case SSUBTYP_DWINFO: |
1258 idx = DWSECT_INFO; | 1247 idx = DEBUG_INFO; |
1259 break; | 1248 break; |
1260 case SSUBTYP_DWLINE: | 1249 case SSUBTYP_DWLINE: |
1261 idx = DWSECT_LINE; | 1250 idx = DEBUG_LINE; |
1262 break; | 1251 break; |
1263 case SSUBTYP_DWABREV: | 1252 case SSUBTYP_DWABREV: |
1264 idx = DWSECT_ABBREV; | 1253 idx = DEBUG_ABBREV; |
1265 break; | 1254 break; |
1266 case SSUBTYP_DWARNGE: | 1255 case SSUBTYP_DWARNGE: |
1267 idx = DWSECT_RANGES; | 1256 idx = DEBUG_RANGES; |
1268 break; | 1257 break; |
1269 case SSUBTYP_DWSTR: | 1258 case SSUBTYP_DWSTR: |
1270 idx = DWSECT_STR; | 1259 idx = DEBUG_STR; |
1271 break; | 1260 break; |
1272 default: | 1261 default: |
1273 continue; | 1262 continue; |
1274 } | 1263 } |
1275 if (min_offset == 0 || (off_t) sects[i].s_scnptr < min_offset) | 1264 if (min_offset == 0 || (off_t) sects[i].s_scnptr < min_offset) |
1286 max_offset - min_offset, | 1275 max_offset - min_offset, |
1287 error_callback, data, &dwarf_view)) | 1276 error_callback, data, &dwarf_view)) |
1288 goto fail; | 1277 goto fail; |
1289 dwarf_view_valid = 1; | 1278 dwarf_view_valid = 1; |
1290 | 1279 |
1291 for (i = 0; i < (int) DWSECT_MAX; ++i) | 1280 for (i = 0; i < (int) DEBUG_MAX; ++i) |
1292 { | 1281 { |
1293 if (dwsect[i].offset == 0) | 1282 if (dwsect[i].offset == 0) |
1294 dwsect[i].data = NULL; | 1283 dwsect[i].data = NULL; |
1295 else | 1284 else |
1296 dwsect[i].data = ((const unsigned char *) dwarf_view.data | 1285 dwsect[i].data = ((const unsigned char *) dwarf_view.data |
1297 + (dwsect[i].offset - min_offset)); | 1286 + (dwsect[i].offset - min_offset)); |
1298 } | 1287 } |
1299 | 1288 |
1300 if (!backtrace_dwarf_add (state, 0, | 1289 memset (&dwarf_sections, 0, sizeof dwarf_sections); |
1301 dwsect[DWSECT_INFO].data, | 1290 |
1302 dwsect[DWSECT_INFO].size, | 1291 dwarf_sections.data[DEBUG_INFO] = dwsect[DEBUG_INFO].data; |
1292 dwarf_sections.size[DEBUG_INFO] = dwsect[DEBUG_INFO].size; | |
1303 #if BACKTRACE_XCOFF_SIZE == 32 | 1293 #if BACKTRACE_XCOFF_SIZE == 32 |
1304 /* XXX workaround for broken lineoff */ | 1294 /* XXX workaround for broken lineoff */ |
1305 dwsect[DWSECT_LINE].data - 4, | 1295 dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 4; |
1306 #else | 1296 #else |
1307 /* XXX workaround for broken lineoff */ | 1297 /* XXX workaround for broken lineoff */ |
1308 dwsect[DWSECT_LINE].data - 12, | 1298 dwarf_sections.data[DEBUG_LINE] = dwsect[DEBUG_LINE].data - 12; |
1309 #endif | 1299 #endif |
1310 dwsect[DWSECT_LINE].size, | 1300 dwarf_sections.size[DEBUG_LINE] = dwsect[DEBUG_LINE].size; |
1311 dwsect[DWSECT_ABBREV].data, | 1301 dwarf_sections.data[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].data; |
1312 dwsect[DWSECT_ABBREV].size, | 1302 dwarf_sections.size[DEBUG_ABBREV] = dwsect[DEBUG_ABBREV].size; |
1313 dwsect[DWSECT_RANGES].data, | 1303 dwarf_sections.data[DEBUG_RANGES] = dwsect[DEBUG_RANGES].data; |
1314 dwsect[DWSECT_RANGES].size, | 1304 dwarf_sections.size[DEBUG_RANGES] = dwsect[DEBUG_RANGES].size; |
1315 dwsect[DWSECT_STR].data, | 1305 dwarf_sections.data[DEBUG_STR] = dwsect[DEBUG_STR].data; |
1316 dwsect[DWSECT_STR].size, | 1306 dwarf_sections.size[DEBUG_STR] = dwsect[DEBUG_STR].size; |
1307 | |
1308 if (!backtrace_dwarf_add (state, 0, &dwarf_sections, | |
1317 1, /* big endian */ | 1309 1, /* big endian */ |
1318 error_callback, data, fileline_fn)) | 1310 NULL, /* altlink */ |
1311 error_callback, data, fileline_fn, | |
1312 NULL /* returned fileline_entry */)) | |
1319 goto fail; | 1313 goto fail; |
1320 } | 1314 } |
1321 | 1315 |
1322 /* Read the XCOFF line number entries if DWARF sections not found. */ | 1316 /* Read the XCOFF line number entries if DWARF sections not found. */ |
1323 | 1317 |
1588 else | 1582 else |
1589 { | 1583 { |
1590 if (found_sym) | 1584 if (found_sym) |
1591 backtrace_atomic_store_pointer (&state->syminfo_fn, xcoff_syminfo); | 1585 backtrace_atomic_store_pointer (&state->syminfo_fn, xcoff_syminfo); |
1592 else | 1586 else |
1593 __sync_bool_compare_and_swap (&state->syminfo_fn, NULL, xcoff_nosyms); | 1587 (void) __sync_bool_compare_and_swap (&state->syminfo_fn, NULL, |
1588 xcoff_nosyms); | |
1594 } | 1589 } |
1595 | 1590 |
1596 if (!state->threaded) | 1591 if (!state->threaded) |
1597 { | 1592 { |
1598 if (state->fileline_fn == NULL || state->fileline_fn == xcoff_nodebug) | 1593 if (state->fileline_fn == NULL || state->fileline_fn == xcoff_nodebug) |