@@ -394,7 +394,7 @@ DWARFDebugLine::getOrParseLineTable(const DWARFDataExtractor &DebugLineData,
394
394
}
395
395
396
396
bool DWARFDebugLine::LineTable::parse (const DWARFDataExtractor &DebugLineData,
397
- uint32_t *OffsetPtr) {
397
+ uint32_t *OffsetPtr, raw_ostream *OS ) {
398
398
const uint32_t DebugLineOffset = *OffsetPtr;
399
399
400
400
clear ();
@@ -405,14 +405,23 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
405
405
return false ;
406
406
}
407
407
408
+ if (OS)
409
+ Prologue.dump (*OS);
410
+
408
411
const uint32_t EndOffset =
409
412
DebugLineOffset + Prologue.TotalLength + Prologue.sizeofTotalLength ();
410
413
411
414
ParsingState State (this );
412
415
413
416
while (*OffsetPtr < EndOffset) {
417
+ if (OS)
418
+ *OS << format (" 0x%08.08" PRIx32 " : " , *OffsetPtr);
419
+
414
420
uint8_t Opcode = DebugLineData.getU8 (OffsetPtr);
415
421
422
+ if (OS)
423
+ *OS << format (" %02.02" PRIx8 " " , Opcode);
424
+
416
425
if (Opcode == 0 ) {
417
426
// Extended Opcodes always start with a zero opcode followed by
418
427
// a uleb128 length so you can skip ones you don't know about
@@ -421,6 +430,8 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
421
430
uint32_t ArgSize = Len - (*OffsetPtr - ExtOffset);
422
431
423
432
uint8_t SubOpcode = DebugLineData.getU8 (OffsetPtr);
433
+ if (OS)
434
+ *OS << LNExtendedString (SubOpcode);
424
435
switch (SubOpcode) {
425
436
case DW_LNE_end_sequence:
426
437
// Set the end_sequence register of the state machine to true and
@@ -432,6 +443,11 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
432
443
// of the sequence.
433
444
State.Row .EndSequence = true ;
434
445
State.appendRowToMatrix (*OffsetPtr);
446
+ if (OS) {
447
+ *OS << " \n " ;
448
+ OS->indent (12 );
449
+ State.Row .dump (*OS);
450
+ }
435
451
State.resetRowAndSequence ();
436
452
break ;
437
453
@@ -443,6 +459,8 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
443
459
// that affect the address register add a delta to it. This instruction
444
460
// stores a relocatable value into it instead.
445
461
State.Row .Address = DebugLineData.getRelocatedAddress (OffsetPtr);
462
+ if (OS)
463
+ *OS << format (" (0x%16.16" PRIx64 " )" , State.Row .Address );
446
464
break ;
447
465
448
466
case DW_LNE_define_file:
@@ -473,11 +491,18 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
473
491
FileEntry.ModTime = DebugLineData.getULEB128 (OffsetPtr);
474
492
FileEntry.Length = DebugLineData.getULEB128 (OffsetPtr);
475
493
Prologue.FileNames .push_back (FileEntry);
494
+ if (OS)
495
+ *OS << " (" << FileEntry.Name .str ()
496
+ << " , dir=" << FileEntry.DirIdx << " , mod_time="
497
+ << format (" (0x%16.16" PRIx64 " )" , FileEntry.ModTime )
498
+ << " , length=" << FileEntry.Length << " )" ;
476
499
}
477
500
break ;
478
501
479
502
case DW_LNE_set_discriminator:
480
503
State.Row .Discriminator = DebugLineData.getULEB128 (OffsetPtr);
504
+ if (OS)
505
+ *OS << " (" << State.Row .Discriminator << " )" ;
481
506
break ;
482
507
483
508
default :
@@ -487,39 +512,58 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
487
512
break ;
488
513
}
489
514
} else if (Opcode < Prologue.OpcodeBase ) {
515
+ if (OS)
516
+ *OS << LNStandardString (Opcode);
490
517
switch (Opcode) {
491
518
// Standard Opcodes
492
519
case DW_LNS_copy:
493
520
// Takes no arguments. Append a row to the matrix using the
494
521
// current values of the state-machine registers. Then set
495
522
// the basic_block register to false.
496
523
State.appendRowToMatrix (*OffsetPtr);
524
+ if (OS) {
525
+ *OS << " \n " ;
526
+ OS->indent (12 );
527
+ State.Row .dump (*OS);
528
+ *OS << " \n " ;
529
+ }
497
530
break ;
498
531
499
532
case DW_LNS_advance_pc:
500
533
// Takes a single unsigned LEB128 operand, multiplies it by the
501
534
// min_inst_length field of the prologue, and adds the
502
535
// result to the address register of the state machine.
503
- State.Row .Address +=
504
- DebugLineData.getULEB128 (OffsetPtr) * Prologue.MinInstLength ;
536
+ {
537
+ uint64_t AddrOffset =
538
+ DebugLineData.getULEB128 (OffsetPtr) * Prologue.MinInstLength ;
539
+ State.Row .Address += AddrOffset;
540
+ if (OS)
541
+ *OS << " (" << AddrOffset << " )" ;
542
+ }
505
543
break ;
506
544
507
545
case DW_LNS_advance_line:
508
546
// Takes a single signed LEB128 operand and adds that value to
509
547
// the line register of the state machine.
510
548
State.Row .Line += DebugLineData.getSLEB128 (OffsetPtr);
549
+ if (OS)
550
+ *OS << " (" << State.Row .Line << " )" ;
511
551
break ;
512
552
513
553
case DW_LNS_set_file:
514
554
// Takes a single unsigned LEB128 operand and stores it in the file
515
555
// register of the state machine.
516
556
State.Row .File = DebugLineData.getULEB128 (OffsetPtr);
557
+ if (OS)
558
+ *OS << " (" << State.Row .File << " )" ;
517
559
break ;
518
560
519
561
case DW_LNS_set_column:
520
562
// Takes a single unsigned LEB128 operand and stores it in the
521
563
// column register of the state machine.
522
564
State.Row .Column = DebugLineData.getULEB128 (OffsetPtr);
565
+ if (OS)
566
+ *OS << " (" << State.Row .Column << " )" ;
523
567
break ;
524
568
525
569
case DW_LNS_negate_stmt:
@@ -551,6 +595,9 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
551
595
uint64_t AddrOffset =
552
596
(AdjustOpcode / Prologue.LineRange ) * Prologue.MinInstLength ;
553
597
State.Row .Address += AddrOffset;
598
+ if (OS)
599
+ *OS
600
+ << format (" (0x%16.16" PRIx64 " )" , AddrOffset);
554
601
}
555
602
break ;
556
603
@@ -564,7 +611,13 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
564
611
// judge when the computation of a special opcode overflows and
565
612
// requires the use of DW_LNS_advance_pc. Such assemblers, however,
566
613
// can use DW_LNS_fixed_advance_pc instead, sacrificing compression.
567
- State.Row .Address += DebugLineData.getU16 (OffsetPtr);
614
+ {
615
+ uint16_t PCOffset = DebugLineData.getU16 (OffsetPtr);
616
+ State.Row .Address += PCOffset;
617
+ if (OS)
618
+ *OS
619
+ << format (" (0x%16.16" PRIx64 " )" , PCOffset);
620
+ }
568
621
break ;
569
622
570
623
case DW_LNS_set_prologue_end:
@@ -583,6 +636,8 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
583
636
// Takes a single unsigned LEB128 operand and stores it in the
584
637
// column register of the state machine.
585
638
State.Row .Isa = DebugLineData.getULEB128 (OffsetPtr);
639
+ if (OS)
640
+ *OS << " (" << State.Row .Isa << " )" ;
586
641
break ;
587
642
588
643
default :
@@ -592,8 +647,12 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
592
647
{
593
648
assert (Opcode - 1U < Prologue.StandardOpcodeLengths .size ());
594
649
uint8_t OpcodeLength = Prologue.StandardOpcodeLengths [Opcode - 1 ];
595
- for (uint8_t I = 0 ; I < OpcodeLength; ++I)
596
- DebugLineData.getULEB128 (OffsetPtr);
650
+ for (uint8_t I = 0 ; I < OpcodeLength; ++I) {
651
+ uint64_t Value = DebugLineData.getULEB128 (OffsetPtr);
652
+ if (OS)
653
+ *OS << format (" Skipping ULEB128 value: 0x%16.16" PRIx64 " )\n " ,
654
+ Value);
655
+ }
597
656
}
598
657
break ;
599
658
}
@@ -638,10 +697,20 @@ bool DWARFDebugLine::LineTable::parse(const DWARFDataExtractor &DebugLineData,
638
697
Prologue.LineBase + (AdjustOpcode % Prologue.LineRange );
639
698
State.Row .Line += LineOffset;
640
699
State.Row .Address += AddrOffset;
700
+
701
+ if (OS) {
702
+ *OS << " address += " << ((uint32_t )AdjustOpcode)
703
+ << " , line += " << LineOffset << " \n " ;
704
+ OS->indent (12 );
705
+ State.Row .dump (*OS);
706
+ }
707
+
641
708
State.appendRowToMatrix (*OffsetPtr);
642
709
// Reset discriminator to 0.
643
710
State.Row .Discriminator = 0 ;
644
711
}
712
+ if (OS)
713
+ *OS << " \n " ;
645
714
}
646
715
647
716
if (!State.Sequence .Empty ) {
0 commit comments