@@ -1244,391 +1244,12 @@ void MCAsmStreamer::Finish() {
1244
1244
if (!UseCFI)
1245
1245
EmitFrames (false );
1246
1246
}
1247
-
1248
- // ===----------------------------------------------------------------------===//
1249
- // / MCLSDADecoderAsmStreamer - This is identical to the MCAsmStreamer, but
1250
- // / outputs a description of the LSDA in a human readable format.
1251
- // /
1252
- namespace {
1253
-
1254
- class MCLSDADecoderAsmStreamer : public MCAsmStreamer {
1255
- const MCSymbol *PersonalitySymbol;
1256
- const MCSymbol *LSDASymbol;
1257
- bool InLSDA;
1258
- bool ReadingULEB128;
1259
-
1260
- uint64_t BytesRead;
1261
- uint64_t ActionTableBytes;
1262
- uint64_t LSDASize;
1263
-
1264
- SmallVector<char , 2 > ULEB128Value;
1265
- std::vector<int64_t > LSDAEncoding;
1266
- std::vector<const MCExpr*> Assignments;
1267
-
1268
- // / GetULEB128Value - A helper function to convert the value in the
1269
- // / ULEB128Value vector into a uint64_t.
1270
- uint64_t GetULEB128Value (SmallVectorImpl<char > &ULEB128Value) {
1271
- uint64_t Val = 0 ;
1272
- for (unsigned i = 0 , e = ULEB128Value.size (); i != e; ++i)
1273
- Val |= (ULEB128Value[i] & 0x7F ) << (7 * i);
1274
- return Val;
1275
- }
1276
-
1277
- // / ResetState - Reset the state variables.
1278
- void ResetState () {
1279
- PersonalitySymbol = 0 ;
1280
- LSDASymbol = 0 ;
1281
- LSDASize = 0 ;
1282
- BytesRead = 0 ;
1283
- ActionTableBytes = 0 ;
1284
- InLSDA = false ;
1285
- ReadingULEB128 = false ;
1286
- ULEB128Value.clear ();
1287
- LSDAEncoding.clear ();
1288
- Assignments.clear ();
1289
- }
1290
-
1291
- void EmitEHTableDescription ();
1292
-
1293
- const char *DecodeDWARFEncoding (unsigned Encoding) {
1294
- switch (Encoding) {
1295
- case dwarf::DW_EH_PE_absptr: return " absptr" ;
1296
- case dwarf::DW_EH_PE_omit: return " omit" ;
1297
- case dwarf::DW_EH_PE_pcrel: return " pcrel" ;
1298
- case dwarf::DW_EH_PE_udata4: return " udata4" ;
1299
- case dwarf::DW_EH_PE_udata8: return " udata8" ;
1300
- case dwarf::DW_EH_PE_sdata4: return " sdata4" ;
1301
- case dwarf::DW_EH_PE_sdata8: return " sdata8" ;
1302
- case dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4: return " pcrel udata4" ;
1303
- case dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4: return " pcrel sdata4" ;
1304
- case dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8: return " pcrel udata8" ;
1305
- case dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8: return " pcrel sdata8" ;
1306
- case dwarf::DW_EH_PE_indirect|dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata4:
1307
- return " indirect pcrel udata4" ;
1308
- case dwarf::DW_EH_PE_indirect|dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata4:
1309
- return " indirect pcrel sdata4" ;
1310
- case dwarf::DW_EH_PE_indirect|dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_udata8:
1311
- return " indirect pcrel udata8" ;
1312
- case dwarf::DW_EH_PE_indirect|dwarf::DW_EH_PE_pcrel|dwarf::DW_EH_PE_sdata8:
1313
- return " indirect pcrel sdata8" ;
1314
- }
1315
-
1316
- return " <unknown encoding>" ;
1317
- }
1318
- public:
1319
- MCLSDADecoderAsmStreamer (MCContext &Context, formatted_raw_ostream &os,
1320
- bool isVerboseAsm, bool useLoc, bool useCFI,
1321
- MCInstPrinter *printer, MCCodeEmitter *emitter,
1322
- TargetAsmBackend *asmbackend,
1323
- bool showInst)
1324
- : MCAsmStreamer(Context, os, isVerboseAsm, useLoc, useCFI,
1325
- printer, emitter, asmbackend, showInst) {
1326
- ResetState ();
1327
- }
1328
- ~MCLSDADecoderAsmStreamer () {}
1329
-
1330
- virtual void Finish () {
1331
- ResetState ();
1332
- MCAsmStreamer::Finish ();
1333
- }
1334
-
1335
- virtual void EmitLabel (MCSymbol *Symbol) {
1336
- if (Symbol == LSDASymbol)
1337
- InLSDA = true ;
1338
- MCAsmStreamer::EmitLabel (Symbol);
1339
- }
1340
- virtual void EmitAssignment (MCSymbol *Symbol, const MCExpr *Value) {
1341
- if (InLSDA)
1342
- Assignments.push_back (Value);
1343
- MCAsmStreamer::EmitAssignment (Symbol, Value);
1344
- }
1345
- virtual void EmitBytes (StringRef Data, unsigned AddrSpace);
1346
- virtual void EmitIntValue (uint64_t Value, unsigned Size,
1347
- unsigned AddrSpace = 0 );
1348
- virtual void EmitValueImpl (const MCExpr *Value, unsigned Size,
1349
- unsigned AddrSpace);
1350
- virtual void EmitFill (uint64_t NumBytes, uint8_t FillValue,
1351
- unsigned AddrSpace);
1352
- virtual void EmitCFIPersonality (const MCSymbol *Sym, unsigned Encoding) {
1353
- PersonalitySymbol = Sym;
1354
- MCAsmStreamer::EmitCFIPersonality (Sym, Encoding);
1355
- }
1356
- virtual void EmitCFILsda (const MCSymbol *Sym, unsigned Encoding) {
1357
- LSDASymbol = Sym;
1358
- MCAsmStreamer::EmitCFILsda (Sym, Encoding);
1359
- }
1360
- };
1361
-
1362
- } // end anonymous namespace
1363
-
1364
- void MCLSDADecoderAsmStreamer::EmitBytes (StringRef Data, unsigned AddrSpace) {
1365
- if (InLSDA && Data.size () == 1 ) {
1366
- LSDAEncoding.push_back ((unsigned )(unsigned char )Data[0 ]);
1367
- ++BytesRead;
1368
-
1369
- if (LSDAEncoding.size () == 4 )
1370
- // The fourth value tells us where the bottom of the type table is.
1371
- LSDASize = BytesRead + LSDAEncoding[3 ];
1372
- else if (LSDAEncoding.size () == 6 )
1373
- // The sixth value tells us where the start of the action table is.
1374
- ActionTableBytes = BytesRead;
1375
- }
1376
-
1377
- MCAsmStreamer::EmitBytes (Data, AddrSpace);
1378
- }
1379
-
1380
- void MCLSDADecoderAsmStreamer::EmitIntValue (uint64_t Value, unsigned Size,
1381
- unsigned AddrSpace) {
1382
- if (!InLSDA)
1383
- return MCAsmStreamer::EmitIntValue (Value, Size, AddrSpace);
1384
-
1385
- BytesRead += Size;
1386
-
1387
- // We place the LSDA into the LSDAEncoding vector for later analysis. If we
1388
- // have a ULEB128, we read that in separate iterations through here and then
1389
- // get its value.
1390
- if (!ReadingULEB128) {
1391
- LSDAEncoding.push_back (Value);
1392
- int EncodingSize = LSDAEncoding.size ();
1393
-
1394
- if (EncodingSize == 1 || EncodingSize == 3 ) {
1395
- // The LPStart and TType encodings.
1396
- if (Value != dwarf::DW_EH_PE_omit) {
1397
- // The encoding is next and is a ULEB128 value.
1398
- ReadingULEB128 = true ;
1399
- ULEB128Value.clear ();
1400
- } else {
1401
- // The encoding was omitted. Put a 0 here as a placeholder.
1402
- LSDAEncoding.push_back (0 );
1403
- }
1404
- } else if (EncodingSize == 5 ) {
1405
- // The next value is a ULEB128 value that tells us how long the call site
1406
- // table is -- where the start of the action tab
1407
- ReadingULEB128 = true ;
1408
- ULEB128Value.clear ();
1409
- }
1410
-
1411
- InLSDA = (LSDASize == 0 || BytesRead < LSDASize);
1412
- } else {
1413
- // We're reading a ULEB128. Make it so!
1414
- ULEB128Value.push_back (Value);
1415
-
1416
- if ((Value & 0x80 ) == 0 ) {
1417
- uint64_t Val = GetULEB128Value (ULEB128Value);
1418
- LSDAEncoding.push_back (Val);
1419
- ULEB128Value.clear ();
1420
- ReadingULEB128 = false ;
1421
-
1422
- if (LSDAEncoding.size () == 4 )
1423
- // The fourth value tells us where the bottom of the type table is.
1424
- LSDASize = BytesRead + LSDAEncoding[3 ];
1425
- else if (LSDAEncoding.size () == 6 )
1426
- // The sixth value tells us where the start of the action table is.
1427
- ActionTableBytes = BytesRead;
1428
- }
1429
- }
1430
-
1431
- MCAsmStreamer::EmitValueImpl (MCConstantExpr::Create (Value, getContext ()),
1432
- Size, AddrSpace);
1433
-
1434
- if (LSDASize != 0 && !InLSDA)
1435
- EmitEHTableDescription ();
1436
- }
1437
-
1438
- void MCLSDADecoderAsmStreamer::EmitValueImpl (const MCExpr *Value,
1439
- unsigned Size,
1440
- unsigned AddrSpace) {
1441
- if (InLSDA && LSDASize != 0 ) {
1442
- assert (BytesRead + Size <= LSDASize && " EH table too small!" );
1443
-
1444
- if (BytesRead > uint64_t (LSDAEncoding[5 ]) + ActionTableBytes)
1445
- // Insert the type values.
1446
- Assignments.push_back (Value);
1447
-
1448
- LSDAEncoding.push_back (Assignments.size ());
1449
- BytesRead += Size;
1450
- InLSDA = (LSDASize == 0 || BytesRead < LSDASize);
1451
- }
1452
-
1453
- MCAsmStreamer::EmitValueImpl (Value, Size, AddrSpace);
1454
-
1455
- if (LSDASize != 0 && !InLSDA)
1456
- EmitEHTableDescription ();
1457
- }
1458
-
1459
- void MCLSDADecoderAsmStreamer::EmitFill (uint64_t NumBytes, uint8_t FillValue,
1460
- unsigned AddrSpace) {
1461
- if (InLSDA && ReadingULEB128) {
1462
- for (uint64_t I = NumBytes; I != 0 ; --I)
1463
- ULEB128Value.push_back (FillValue);
1464
-
1465
- BytesRead += NumBytes;
1466
-
1467
- if ((FillValue & 0x80 ) == 0 ) {
1468
- uint64_t Val = GetULEB128Value (ULEB128Value);
1469
- LSDAEncoding.push_back (Val);
1470
- ULEB128Value.clear ();
1471
- ReadingULEB128 = false ;
1472
-
1473
- if (LSDAEncoding.size () == 4 )
1474
- // The fourth value tells us where the bottom of the type table is.
1475
- LSDASize = BytesRead + LSDAEncoding[3 ];
1476
- else if (LSDAEncoding.size () == 6 )
1477
- // The sixth value tells us where the start of the action table is.
1478
- ActionTableBytes = BytesRead;
1479
- }
1480
- }
1481
-
1482
- MCAsmStreamer::EmitFill (NumBytes, FillValue, AddrSpace);
1483
- }
1484
-
1485
- // / EmitEHTableDescription - Emit a human readable version of the LSDA.
1486
- void MCLSDADecoderAsmStreamer::EmitEHTableDescription () {
1487
- assert (LSDAEncoding.size () > 6 && " Invalid LSDA!" );
1488
-
1489
- // Emit header information.
1490
- StringRef C = MAI.getCommentString ();
1491
- #define CMT OS << C << ' '
1492
- CMT << " Exception Handling Table: " << LSDASymbol->getName () << " \n " ;
1493
- CMT << " @LPStart Encoding: " << DecodeDWARFEncoding (LSDAEncoding[0 ]) << " \n " ;
1494
- if (LSDAEncoding[1 ])
1495
- CMT << " @LPStart: 0x" << LSDAEncoding[1 ] << " \n " ;
1496
- CMT << " @TType Encoding: " << DecodeDWARFEncoding (LSDAEncoding[2 ]) << " \n " ;
1497
- CMT << " @TType Base: " << LSDAEncoding[3 ] << " bytes\n " ;
1498
- CMT << " @CallSite Encoding: " << DecodeDWARFEncoding (LSDAEncoding[4 ]) << " \n " ;
1499
- CMT << " @Action Table Size: " << LSDAEncoding[5 ] << " bytes\n\n " ;
1500
-
1501
- bool isSjLjEH = (MAI.getExceptionHandlingType () == ExceptionHandling::SjLj);
1502
-
1503
- int64_t CallSiteTableSize = LSDAEncoding[5 ];
1504
- unsigned CallSiteEntrySize;
1505
- if (!isSjLjEH)
1506
- CallSiteEntrySize = 4 + // Region start.
1507
- 4 + // Region end.
1508
- 4 + // Landing pad.
1509
- 1 ; // TType index.
1510
- else
1511
- CallSiteEntrySize = 1 + // Call index.
1512
- 1 ; // TType index.
1513
-
1514
- unsigned NumEntries = CallSiteTableSize / CallSiteEntrySize;
1515
- assert (CallSiteTableSize % CallSiteEntrySize == 0 &&
1516
- " The action table size is not a multiple of what it should be!" );
1517
- unsigned TTypeIdx = 5 + // Action table size index.
1518
- (isSjLjEH ? 2 : 4 ) * NumEntries + // Action table entries.
1519
- 1 ; // Just because.
1520
-
1521
- // Emit the action table.
1522
- unsigned Action = 1 ;
1523
- for (unsigned I = 6 ; I < TTypeIdx; ) {
1524
- CMT << " Action " << Action++ << " :\n " ;
1525
-
1526
- // The beginning of the throwing region.
1527
- uint64_t Idx = LSDAEncoding[I++];
1528
-
1529
- if (!isSjLjEH) {
1530
- CMT << " A throw between "
1531
- << *cast<MCBinaryExpr>(Assignments[Idx - 1 ])->getLHS () << " and " ;
1532
-
1533
- // The end of the throwing region.
1534
- Idx = LSDAEncoding[I++];
1535
- OS << *cast<MCBinaryExpr>(Assignments[Idx - 1 ])->getLHS ();
1536
-
1537
- // The landing pad.
1538
- Idx = LSDAEncoding[I++];
1539
- if (Idx) {
1540
- OS << " jumps to "
1541
- << *cast<MCBinaryExpr>(Assignments[Idx - 1 ])->getLHS ()
1542
- << " on an exception.\n " ;
1543
- } else {
1544
- OS << " does not have a landing pad.\n " ;
1545
- ++I;
1546
- continue ;
1547
- }
1548
- } else {
1549
- CMT << " A throw from call " << Idx << " \n " ;
1550
- }
1551
-
1552
- // The index into the action table.
1553
- Idx = LSDAEncoding[I++];
1554
- if (!Idx) {
1555
- CMT << " :cleanup:\n " ;
1556
- continue ;
1557
- }
1558
-
1559
- // A semi-graphical representation of what the different indexes are in the
1560
- // loop below.
1561
- //
1562
- // Idx - Index into the action table.
1563
- // Action - Index into the type table from the type table base.
1564
- // Next - Offset from Idx to the next action type.
1565
- //
1566
- // Idx---.
1567
- // |
1568
- // v
1569
- // [call site table] _1 _2 _3
1570
- // TTypeIdx--> .........................
1571
- // [action 1] _1 _2
1572
- // [action 2] _1 _2
1573
- // ...
1574
- // [action n] _1 _2
1575
- // [type m] ^
1576
- // ... |
1577
- // [type 1] `---Next
1578
- //
1579
-
1580
- int Action = LSDAEncoding[TTypeIdx + Idx - 1 ];
1581
- if ((Action & 0x40 ) != 0 )
1582
- // Ignore exception specifications.
1583
- continue ;
1584
-
1585
- // Emit the types that are caught by this exception.
1586
- CMT << " For type(s): " ;
1587
- for (;;) {
1588
- if ((Action & 0x40 ) != 0 )
1589
- // Ignore exception specifications.
1590
- break ;
1591
-
1592
- if (uint64_t Ty = LSDAEncoding[LSDAEncoding.size () - Action]) {
1593
- OS << " " << *Assignments[Ty - 1 ];
1594
-
1595
- // Types can be chained together. Typically, it's a negative offset from
1596
- // the current type to a different one in the type table.
1597
- int Next = LSDAEncoding[TTypeIdx + Idx];
1598
- if (Next == 0 )
1599
- break ;
1600
- if ((Next & 0x40 ) != 0 )
1601
- Next = (int )(signed char )(Next | 0x80 );
1602
- Idx += Next + 1 ;
1603
- Action = LSDAEncoding[TTypeIdx + Idx - 1 ];
1604
- continue ;
1605
- } else {
1606
- OS << " :catchall:" ;
1607
- }
1608
- break ;
1609
- }
1610
-
1611
- OS << " \n " ;
1612
- }
1613
-
1614
- OS << " \n " ;
1615
- ResetState ();
1616
- }
1617
-
1618
1247
MCStreamer *llvm::createAsmStreamer (MCContext &Context,
1619
1248
formatted_raw_ostream &OS,
1620
1249
bool isVerboseAsm, bool useLoc,
1621
1250
bool useCFI, MCInstPrinter *IP,
1622
1251
MCCodeEmitter *CE, TargetAsmBackend *TAB,
1623
1252
bool ShowInst) {
1624
- ExceptionHandling::ExceptionsType ET =
1625
- Context.getAsmInfo ().getExceptionHandlingType ();
1626
-
1627
- if (useCFI && isVerboseAsm &&
1628
- (ET == ExceptionHandling::SjLj || ET == ExceptionHandling::DwarfCFI))
1629
- return new MCLSDADecoderAsmStreamer (Context, OS, isVerboseAsm, useLoc,
1630
- useCFI, IP, CE, TAB, ShowInst);
1631
-
1632
1253
return new MCAsmStreamer (Context, OS, isVerboseAsm, useLoc, useCFI,
1633
1254
IP, CE, TAB, ShowInst);
1634
1255
}
0 commit comments