OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/eh-frame.h" | 5 #include "src/eh-frame.h" |
6 #include "test/unittests/test-utils.h" | 6 #include "test/unittests/test-utils.h" |
7 | 7 |
8 // Test enabled only on supported architectures. | 8 // Test enabled only on supported architectures. |
9 #if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM) || \ | 9 #if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_ARM) || \ |
10 defined(V8_TARGET_ARCH_ARM64) | 10 defined(V8_TARGET_ARCH_ARM64) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 int procedure_address_offset = iterator.GetCurrentOffset(); | 68 int procedure_address_offset = iterator.GetCurrentOffset(); |
69 int procedure_address = iterator.GetNextUInt32(); | 69 int procedure_address = iterator.GetNextUInt32(); |
70 EXPECT_EQ(-(procedure_address_offset + RoundUp(kProcedureSize, 8)), | 70 EXPECT_EQ(-(procedure_address_offset + RoundUp(kProcedureSize, 8)), |
71 procedure_address); | 71 procedure_address); |
72 | 72 |
73 int procedure_size = iterator.GetNextUInt32(); | 73 int procedure_size = iterator.GetNextUInt32(); |
74 EXPECT_EQ(kProcedureSize, procedure_size); | 74 EXPECT_EQ(kProcedureSize, procedure_size); |
75 } | 75 } |
76 | 76 |
77 TEST_F(EhFrameWriterTest, SetOffset) { | 77 TEST_F(EhFrameWriterTest, SetOffset) { |
78 static const int kOffset = 0x0badc0de; | 78 static const uint32_t kOffset = 0x0badc0de; |
79 | 79 |
80 EhFrameWriter writer(zone()); | 80 EhFrameWriter writer(zone()); |
81 writer.Initialize(); | 81 writer.Initialize(); |
82 writer.SetBaseAddressOffset(kOffset); | 82 writer.SetBaseAddressOffset(kOffset); |
83 writer.Finish(100); | 83 writer.Finish(100); |
84 | 84 |
85 EhFrameIterator iterator = MakeIterator(&writer); | 85 EhFrameIterator iterator = MakeIterator(&writer); |
86 iterator.SkipToFdeDirectives(); | 86 iterator.SkipToFdeDirectives(); |
87 | 87 |
88 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfaOffset, | 88 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfaOffset, |
89 iterator.GetNextOpcode()); | 89 iterator.GetNextOpcode()); |
90 EXPECT_EQ(kOffset, iterator.GetNextULeb128()); | 90 EXPECT_EQ(kOffset, iterator.GetNextULeb128()); |
91 } | 91 } |
92 | 92 |
93 TEST_F(EhFrameWriterTest, IncreaseOffset) { | 93 TEST_F(EhFrameWriterTest, IncreaseOffset) { |
94 static const int kFirstOffset = 121; | 94 static const uint32_t kFirstOffset = 121; |
95 static const int kSecondOffset = 16; | 95 static const uint32_t kSecondOffset = 16; |
96 | 96 |
97 EhFrameWriter writer(zone()); | 97 EhFrameWriter writer(zone()); |
98 writer.Initialize(); | 98 writer.Initialize(); |
99 writer.SetBaseAddressOffset(kFirstOffset); | 99 writer.SetBaseAddressOffset(kFirstOffset); |
100 writer.IncreaseBaseAddressOffset(kSecondOffset); | 100 writer.IncreaseBaseAddressOffset(kSecondOffset); |
101 writer.Finish(100); | 101 writer.Finish(100); |
102 | 102 |
103 EhFrameIterator iterator = MakeIterator(&writer); | 103 EhFrameIterator iterator = MakeIterator(&writer); |
104 iterator.SkipToFdeDirectives(); | 104 iterator.SkipToFdeDirectives(); |
105 | 105 |
(...skipping 12 matching lines...) Expand all Loading... |
118 EhFrameWriter writer(zone()); | 118 EhFrameWriter writer(zone()); |
119 writer.Initialize(); | 119 writer.Initialize(); |
120 writer.SetBaseAddressRegister(test_register); | 120 writer.SetBaseAddressRegister(test_register); |
121 writer.Finish(100); | 121 writer.Finish(100); |
122 | 122 |
123 EhFrameIterator iterator = MakeIterator(&writer); | 123 EhFrameIterator iterator = MakeIterator(&writer); |
124 iterator.SkipToFdeDirectives(); | 124 iterator.SkipToFdeDirectives(); |
125 | 125 |
126 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfaRegister, | 126 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfaRegister, |
127 iterator.GetNextOpcode()); | 127 iterator.GetNextOpcode()); |
128 EXPECT_EQ(kTestRegisterCode, iterator.GetNextULeb128()); | 128 EXPECT_EQ(static_cast<uint32_t>(kTestRegisterCode), |
| 129 iterator.GetNextULeb128()); |
129 } | 130 } |
130 | 131 |
131 TEST_F(EhFrameWriterTest, SetRegisterAndOffset) { | 132 TEST_F(EhFrameWriterTest, SetRegisterAndOffset) { |
132 Register test_register = Register::from_code(kTestRegisterCode); | 133 Register test_register = Register::from_code(kTestRegisterCode); |
133 static const int kOffset = 0x0badc0de; | 134 static const uint32_t kOffset = 0x0badc0de; |
134 | 135 |
135 EhFrameWriter writer(zone()); | 136 EhFrameWriter writer(zone()); |
136 writer.Initialize(); | 137 writer.Initialize(); |
137 writer.SetBaseAddressRegisterAndOffset(test_register, kOffset); | 138 writer.SetBaseAddressRegisterAndOffset(test_register, kOffset); |
138 writer.Finish(100); | 139 writer.Finish(100); |
139 | 140 |
140 EhFrameIterator iterator = MakeIterator(&writer); | 141 EhFrameIterator iterator = MakeIterator(&writer); |
141 iterator.SkipToFdeDirectives(); | 142 iterator.SkipToFdeDirectives(); |
142 | 143 |
143 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfa, iterator.GetNextOpcode()); | 144 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kDefCfa, iterator.GetNextOpcode()); |
144 EXPECT_EQ(kTestRegisterCode, iterator.GetNextULeb128()); | 145 EXPECT_EQ(static_cast<uint32_t>(kTestRegisterCode), |
| 146 iterator.GetNextULeb128()); |
145 EXPECT_EQ(kOffset, iterator.GetNextULeb128()); | 147 EXPECT_EQ(kOffset, iterator.GetNextULeb128()); |
146 } | 148 } |
147 | 149 |
148 TEST_F(EhFrameWriterTest, PcOffsetEncoding6bit) { | 150 TEST_F(EhFrameWriterTest, PcOffsetEncoding6bit) { |
149 static const int kOffset = 42; | 151 static const int kOffset = 42; |
150 | 152 |
151 EhFrameWriter writer(zone()); | 153 EhFrameWriter writer(zone()); |
152 writer.Initialize(); | 154 writer.Initialize(); |
153 writer.AdvanceLocation(kOffset * EhFrameConstants::kCodeAlignmentFactor); | 155 writer.AdvanceLocation(kOffset * EhFrameConstants::kCodeAlignmentFactor); |
154 writer.Finish(100); | 156 writer.Finish(100); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc1, | 256 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc1, |
255 iterator.GetNextOpcode()); | 257 iterator.GetNextOpcode()); |
256 EXPECT_EQ(kFirstOffset, iterator.GetNextByte()); | 258 EXPECT_EQ(kFirstOffset, iterator.GetNextByte()); |
257 | 259 |
258 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc2, | 260 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc2, |
259 iterator.GetNextOpcode()); | 261 iterator.GetNextOpcode()); |
260 EXPECT_EQ(kSecondOffset - kFirstOffset, iterator.GetNextUInt16()); | 262 EXPECT_EQ(kSecondOffset - kFirstOffset, iterator.GetNextUInt16()); |
261 } | 263 } |
262 | 264 |
263 TEST_F(EhFrameWriterTest, PcOffsetEncoding32bit) { | 265 TEST_F(EhFrameWriterTest, PcOffsetEncoding32bit) { |
264 static const int kOffset = kMaxUInt16 + 42; | 266 static const uint32_t kOffset = kMaxUInt16 + 42; |
265 | 267 |
266 EhFrameWriter writer(zone()); | 268 EhFrameWriter writer(zone()); |
267 writer.Initialize(); | 269 writer.Initialize(); |
268 writer.AdvanceLocation(kOffset * EhFrameConstants::kCodeAlignmentFactor); | 270 writer.AdvanceLocation(kOffset * EhFrameConstants::kCodeAlignmentFactor); |
269 writer.Finish(100); | 271 writer.Finish(100); |
270 | 272 |
271 EhFrameIterator iterator = MakeIterator(&writer); | 273 EhFrameIterator iterator = MakeIterator(&writer); |
272 iterator.SkipToFdeDirectives(); | 274 iterator.SkipToFdeDirectives(); |
273 | 275 |
274 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc4, | 276 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kAdvanceLoc4, |
275 iterator.GetNextOpcode()); | 277 iterator.GetNextOpcode()); |
276 EXPECT_EQ(kOffset, iterator.GetNextUInt32()); | 278 EXPECT_EQ(kOffset, iterator.GetNextUInt32()); |
277 } | 279 } |
278 | 280 |
279 TEST_F(EhFrameWriterTest, PcOffsetEncoding32bitDelta) { | 281 TEST_F(EhFrameWriterTest, PcOffsetEncoding32bitDelta) { |
280 static const int kFirstOffset = kMaxUInt16 + 0x42; | 282 static const uint32_t kFirstOffset = kMaxUInt16 + 0x42; |
281 static const int kSecondOffset = kMaxUInt16 + 0x67; | 283 static const uint32_t kSecondOffset = kMaxUInt16 + 0x67; |
282 | 284 |
283 EhFrameWriter writer(zone()); | 285 EhFrameWriter writer(zone()); |
284 writer.Initialize(); | 286 writer.Initialize(); |
285 writer.AdvanceLocation(kFirstOffset * EhFrameConstants::kCodeAlignmentFactor); | 287 writer.AdvanceLocation(kFirstOffset * EhFrameConstants::kCodeAlignmentFactor); |
286 writer.AdvanceLocation(kSecondOffset * | 288 writer.AdvanceLocation(kSecondOffset * |
287 EhFrameConstants::kCodeAlignmentFactor); | 289 EhFrameConstants::kCodeAlignmentFactor); |
288 writer.Finish(100); | 290 writer.Finish(100); |
289 | 291 |
290 EhFrameIterator iterator = MakeIterator(&writer); | 292 EhFrameIterator iterator = MakeIterator(&writer); |
291 iterator.SkipToFdeDirectives(); | 293 iterator.SkipToFdeDirectives(); |
(...skipping 12 matching lines...) Expand all Loading... |
304 | 306 |
305 EhFrameWriter writer(zone()); | 307 EhFrameWriter writer(zone()); |
306 writer.Initialize(); | 308 writer.Initialize(); |
307 writer.RecordRegisterSavedToStack(test_register, kOffset); | 309 writer.RecordRegisterSavedToStack(test_register, kOffset); |
308 writer.Finish(100); | 310 writer.Finish(100); |
309 | 311 |
310 EhFrameIterator iterator = MakeIterator(&writer); | 312 EhFrameIterator iterator = MakeIterator(&writer); |
311 iterator.SkipToFdeDirectives(); | 313 iterator.SkipToFdeDirectives(); |
312 | 314 |
313 EXPECT_EQ((2 << 6) | kTestRegisterCode, iterator.GetNextByte()); | 315 EXPECT_EQ((2 << 6) | kTestRegisterCode, iterator.GetNextByte()); |
314 EXPECT_EQ(kOffset / EhFrameConstants::kDataAlignmentFactor, | 316 EXPECT_EQ( |
315 iterator.GetNextULeb128()); | 317 static_cast<uint32_t>(kOffset / EhFrameConstants::kDataAlignmentFactor), |
| 318 iterator.GetNextULeb128()); |
316 } | 319 } |
317 | 320 |
318 TEST_F(EhFrameWriterTest, SaveRegisterSignedOffset) { | 321 TEST_F(EhFrameWriterTest, SaveRegisterSignedOffset) { |
319 Register test_register = Register::from_code(kTestRegisterCode); | 322 Register test_register = Register::from_code(kTestRegisterCode); |
320 static const int kOffset = | 323 static const int kOffset = |
321 EhFrameConstants::kDataAlignmentFactor < 0 ? 12344 : -12344; | 324 EhFrameConstants::kDataAlignmentFactor < 0 ? 12344 : -12344; |
322 | 325 |
323 ASSERT_EQ(kOffset % EhFrameConstants::kDataAlignmentFactor, 0); | 326 ASSERT_EQ(kOffset % EhFrameConstants::kDataAlignmentFactor, 0); |
324 | 327 |
325 EhFrameWriter writer(zone()); | 328 EhFrameWriter writer(zone()); |
326 writer.Initialize(); | 329 writer.Initialize(); |
327 writer.RecordRegisterSavedToStack(test_register, kOffset); | 330 writer.RecordRegisterSavedToStack(test_register, kOffset); |
328 writer.Finish(100); | 331 writer.Finish(100); |
329 | 332 |
330 EhFrameIterator iterator = MakeIterator(&writer); | 333 EhFrameIterator iterator = MakeIterator(&writer); |
331 iterator.SkipToFdeDirectives(); | 334 iterator.SkipToFdeDirectives(); |
332 | 335 |
333 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kOffsetExtendedSf, | 336 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kOffsetExtendedSf, |
334 iterator.GetNextOpcode()); | 337 iterator.GetNextOpcode()); |
335 EXPECT_EQ(kTestRegisterCode, iterator.GetNextULeb128()); | 338 EXPECT_EQ(static_cast<uint32_t>(kTestRegisterCode), |
| 339 iterator.GetNextULeb128()); |
336 EXPECT_EQ(kOffset / EhFrameConstants::kDataAlignmentFactor, | 340 EXPECT_EQ(kOffset / EhFrameConstants::kDataAlignmentFactor, |
337 iterator.GetNextSLeb128()); | 341 iterator.GetNextSLeb128()); |
338 } | 342 } |
339 | 343 |
340 TEST_F(EhFrameWriterTest, RegisterNotModified) { | 344 TEST_F(EhFrameWriterTest, RegisterNotModified) { |
341 Register test_register = Register::from_code(kTestRegisterCode); | 345 Register test_register = Register::from_code(kTestRegisterCode); |
342 | 346 |
343 EhFrameWriter writer(zone()); | 347 EhFrameWriter writer(zone()); |
344 writer.Initialize(); | 348 writer.Initialize(); |
345 writer.RecordRegisterNotModified(test_register); | 349 writer.RecordRegisterNotModified(test_register); |
346 writer.Finish(100); | 350 writer.Finish(100); |
347 | 351 |
348 EhFrameIterator iterator = MakeIterator(&writer); | 352 EhFrameIterator iterator = MakeIterator(&writer); |
349 iterator.SkipToFdeDirectives(); | 353 iterator.SkipToFdeDirectives(); |
350 | 354 |
351 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kSameValue, | 355 EXPECT_EQ(EhFrameConstants::DwarfOpcodes::kSameValue, |
352 iterator.GetNextOpcode()); | 356 iterator.GetNextOpcode()); |
353 EXPECT_EQ(kTestRegisterCode, iterator.GetNextULeb128()); | 357 EXPECT_EQ(static_cast<uint32_t>(kTestRegisterCode), |
| 358 iterator.GetNextULeb128()); |
354 } | 359 } |
355 | 360 |
356 TEST_F(EhFrameWriterTest, RegisterFollowsInitialRule) { | 361 TEST_F(EhFrameWriterTest, RegisterFollowsInitialRule) { |
357 Register test_register = Register::from_code(kTestRegisterCode); | 362 Register test_register = Register::from_code(kTestRegisterCode); |
358 | 363 |
359 EhFrameWriter writer(zone()); | 364 EhFrameWriter writer(zone()); |
360 writer.Initialize(); | 365 writer.Initialize(); |
361 writer.RecordRegisterFollowsInitialRule(test_register); | 366 writer.RecordRegisterFollowsInitialRule(test_register); |
362 writer.Finish(100); | 367 writer.Finish(100); |
363 | 368 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 int offset_to_procedure = iterator.GetNextUInt32(); | 460 int offset_to_procedure = iterator.GetNextUInt32(); |
456 EXPECT_EQ(-(eh_frame_size + kPaddingSize + kCodeSize), offset_to_procedure); | 461 EXPECT_EQ(-(eh_frame_size + kPaddingSize + kCodeSize), offset_to_procedure); |
457 | 462 |
458 // B -> C | 463 // B -> C |
459 int offset_to_fde = iterator.GetNextUInt32(); | 464 int offset_to_fde = iterator.GetNextUInt32(); |
460 EXPECT_EQ(-(fde_size + EhFrameConstants::kEhFrameTerminatorSize), | 465 EXPECT_EQ(-(fde_size + EhFrameConstants::kEhFrameTerminatorSize), |
461 offset_to_fde); | 466 offset_to_fde); |
462 } | 467 } |
463 | 468 |
464 #endif | 469 #endif |
OLD | NEW |