@@ -67,10 +67,8 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
67
67
(Op->getCode () >= DW_OP_reg0 && Op->getCode () <= DW_OP_reg31) ||
68
68
Op->getCode () == DW_OP_bregx || Op->getCode () == DW_OP_regx ||
69
69
Op->getCode () == DW_OP_regval_type ||
70
- Op->getCode () == DW_OP_LLVM_call_frame_entry_reg ||
71
- Op->getCode () == DW_OP_LLVM_aspace_bregx ||
72
- (SubOpcode && (*SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
73
- *SubOpcode == DW_OP_LLVM_aspace_bregx))) {
70
+ SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
71
+ SubOpcode == DW_OP_LLVM_aspace_bregx) {
74
72
if (prettyPrintRegisterOp (U, OS, DumpOpts, Op->getCode (),
75
73
Op->getRawOperands ()))
76
74
return true ;
@@ -100,22 +98,20 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
100
98
StringRef Name = OperationEncodingString (Op->getCode ());
101
99
assert (!Name.empty () && " DW_OP has no name!" );
102
100
OS << Name;
103
- }
104
101
105
- if (SubOpcode) {
106
- StringRef SubName = SubOperationEncodingString (Op->getCode (), *SubOpcode);
107
- assert (!SubName.empty () && " DW_OP SubOp has no name!" );
108
- OS << " " << SubName;
102
+ if (SubOpcode) {
103
+ StringRef SubName = SubOperationEncodingString (Op->getCode (), *SubOpcode);
104
+ assert (!SubName.empty () && " DW_OP SubOp has no name!" );
105
+ OS << ' ' << SubName;
106
+ }
109
107
}
110
108
111
109
if ((Op->getCode () >= DW_OP_breg0 && Op->getCode () <= DW_OP_breg31) ||
112
110
(Op->getCode () >= DW_OP_reg0 && Op->getCode () <= DW_OP_reg31) ||
113
111
Op->getCode () == DW_OP_bregx || Op->getCode () == DW_OP_regx ||
114
112
Op->getCode () == DW_OP_regval_type ||
115
- Op->getCode () == DW_OP_LLVM_call_frame_entry_reg ||
116
- Op->getCode () == DW_OP_LLVM_aspace_bregx ||
117
- (SubOpcode && (*SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
118
- *SubOpcode == DW_OP_LLVM_aspace_bregx)))
113
+ SubOpcode == DW_OP_LLVM_call_frame_entry_reg ||
114
+ SubOpcode == DW_OP_LLVM_aspace_bregx)
119
115
if (prettyPrintRegisterOp (U, OS, DumpOpts, Op->getCode (),
120
116
Op->getRawOperands ()))
121
117
return true ;
@@ -127,8 +123,8 @@ static bool printOp(const DWARFExpression::Operation *Op, raw_ostream &OS,
127
123
unsigned Signed = Size & DWARFExpression::Operation::SignBit;
128
124
129
125
if (Size == DWARFExpression::Operation::SizeSubOpLEB) {
130
- assert (Operand == 0 );
131
- assert (SubOpcode);
126
+ assert (Operand == 0 && " DW_OP SubOp must be the first operand " );
127
+ assert (SubOpcode && " DW_OP SubOp description is inconsistent " );
132
128
} else if (Size == DWARFExpression::Operation::BaseTypeRef && U) {
133
129
// For DW_OP_convert the operand may be 0 to indicate that conversion to
134
130
// the generic type should be done. The same holds for
@@ -225,6 +221,19 @@ static bool printCompactDWARFExpr(
225
221
nullptr) {
226
222
SmallVector<PrintedExpr, 4 > Stack;
227
223
224
+ auto UnknownOpcode = [](raw_ostream &OS, uint8_t Opcode,
225
+ std::optional<unsigned > SubOpcode) -> bool {
226
+ // If we hit an unknown operand, we don't know its effect on the stack,
227
+ // so bail out on the whole expression.
228
+ OS << " <unknown op " << dwarf::OperationEncodingString (Opcode) << " ("
229
+ << (int )Opcode;
230
+ if (SubOpcode)
231
+ OS << " ) subop " << dwarf::SubOperationEncodingString (Opcode, *SubOpcode)
232
+ << " (" << *SubOpcode;
233
+ OS << " )>" ;
234
+ return false ;
235
+ };
236
+
228
237
while (I != E) {
229
238
const DWARFExpression::Operation &Op = *I;
230
239
uint8_t Opcode = Op.getCode ();
@@ -277,8 +286,10 @@ static bool printCompactDWARFExpr(
277
286
break ;
278
287
}
279
288
case dwarf::DW_OP_LLVM_user: {
280
- assert (Op.getSubCode ());
281
- break ;
289
+ std::optional<unsigned > SubOpcode = Op.getSubCode ();
290
+ if (SubOpcode == dwarf::DW_OP_LLVM_nop)
291
+ break ;
292
+ return UnknownOpcode (OS, Opcode, SubOpcode);
282
293
}
283
294
default :
284
295
if (Opcode >= dwarf::DW_OP_reg0 && Opcode <= dwarf::DW_OP_reg31) {
@@ -302,11 +313,7 @@ static bool printCompactDWARFExpr(
302
313
if (Offset)
303
314
S << format (" %+" PRId64, Offset);
304
315
} else {
305
- // If we hit an unknown operand, we don't know its effect on the stack,
306
- // so bail out on the whole expression.
307
- OS << " <unknown op " << dwarf::OperationEncodingString (Opcode) << " ("
308
- << (int )Opcode << " )>" ;
309
- return false ;
316
+ return UnknownOpcode (OS, Opcode, std::nullopt );
310
317
}
311
318
break ;
312
319
}
@@ -346,8 +353,8 @@ bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
346
353
SubOpcode = Operands[OpNum++];
347
354
348
355
if (Opcode == DW_OP_bregx || Opcode == DW_OP_regx ||
349
- Opcode == DW_OP_regval_type ||
350
- ( SubOpcode && *SubOpcode == DW_OP_LLVM_aspace_bregx) )
356
+ Opcode == DW_OP_regval_type || SubOpcode == DW_OP_LLVM_aspace_bregx ||
357
+ SubOpcode == DW_OP_LLVM_call_frame_entry_reg )
351
358
DwarfRegNum = Operands[OpNum++];
352
359
else if (Opcode == DW_OP_LLVM_call_frame_entry_reg ||
353
360
(SubOpcode && *SubOpcode == DW_OP_LLVM_call_frame_entry_reg))
@@ -360,9 +367,7 @@ bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
360
367
auto RegName = DumpOpts.GetNameForDWARFReg (DwarfRegNum, DumpOpts.IsEH );
361
368
if (!RegName.empty ()) {
362
369
if ((Opcode >= DW_OP_breg0 && Opcode <= DW_OP_breg31) ||
363
- Opcode == DW_OP_bregx ||
364
- (Opcode == DW_OP_LLVM_aspace_bregx ||
365
- (SubOpcode && *SubOpcode == DW_OP_LLVM_aspace_bregx)))
370
+ Opcode == DW_OP_bregx || SubOpcode == DW_OP_LLVM_aspace_bregx)
366
371
OS << ' ' << RegName << format (" %+" PRId64, Operands[OpNum]);
367
372
else
368
373
OS << ' ' << RegName.data ();
0 commit comments