/thirdparty/breakpad/processor/stackwalker_amd64_unittest.cc

http://github.com/tomahawk-player/tomahawk · C++ · 561 lines · 390 code · 69 blank · 102 comment · 1 complexity · 5ae29351e4a3f5210a1af33738b3eade MD5 · raw file

  1. // Copyright (c) 2010, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
  30. // stackwalker_amd64_unittest.cc: Unit tests for StackwalkerAMD64 class.
  31. #include <string>
  32. #include <string.h>
  33. #include <vector>
  34. #include "breakpad_googletest_includes.h"
  35. #include "common/test_assembler.h"
  36. #include "google_breakpad/common/minidump_format.h"
  37. #include "google_breakpad/processor/basic_source_line_resolver.h"
  38. #include "google_breakpad/processor/call_stack.h"
  39. #include "google_breakpad/processor/source_line_resolver_interface.h"
  40. #include "google_breakpad/processor/stack_frame_cpu.h"
  41. #include "processor/stackwalker_unittest_utils.h"
  42. #include "processor/stackwalker_amd64.h"
  43. using google_breakpad::BasicSourceLineResolver;
  44. using google_breakpad::CallStack;
  45. using google_breakpad::StackFrame;
  46. using google_breakpad::StackFrameAMD64;
  47. using google_breakpad::StackwalkerAMD64;
  48. using google_breakpad::SystemInfo;
  49. using google_breakpad::test_assembler::kLittleEndian;
  50. using google_breakpad::test_assembler::Label;
  51. using google_breakpad::test_assembler::Section;
  52. using std::string;
  53. using std::vector;
  54. using testing::_;
  55. using testing::Return;
  56. using testing::SetArgumentPointee;
  57. using testing::Test;
  58. class StackwalkerAMD64Fixture {
  59. public:
  60. StackwalkerAMD64Fixture()
  61. : stack_section(kLittleEndian),
  62. // Give the two modules reasonable standard locations and names
  63. // for tests to play with.
  64. module1(0x40000000c0000000ULL, 0x10000, "module1", "version1"),
  65. module2(0x50000000b0000000ULL, 0x10000, "module2", "version2") {
  66. // Identify the system as a Linux system.
  67. system_info.os = "Linux";
  68. system_info.os_short = "linux";
  69. system_info.os_version = "Horrendous Hippo";
  70. system_info.cpu = "x86";
  71. system_info.cpu_info = "";
  72. // Put distinctive values in the raw CPU context.
  73. BrandContext(&raw_context);
  74. // Create some modules with some stock debugging information.
  75. modules.Add(&module1);
  76. modules.Add(&module2);
  77. // By default, none of the modules have symbol info; call
  78. // SetModuleSymbols to override this.
  79. EXPECT_CALL(supplier, GetCStringSymbolData(_, _, _, _))
  80. .WillRepeatedly(Return(MockSymbolSupplier::NOT_FOUND));
  81. }
  82. // Set the Breakpad symbol information that supplier should return for
  83. // MODULE to INFO.
  84. void SetModuleSymbols(MockCodeModule *module, const string &info) {
  85. unsigned int buffer_size = info.size() + 1;
  86. char *buffer = reinterpret_cast<char*>(operator new(buffer_size));
  87. strcpy(buffer, info.c_str());
  88. EXPECT_CALL(supplier, GetCStringSymbolData(module, &system_info, _, _))
  89. .WillRepeatedly(DoAll(SetArgumentPointee<3>(buffer),
  90. Return(MockSymbolSupplier::FOUND)));
  91. }
  92. // Populate stack_region with the contents of stack_section. Use
  93. // stack_section.start() as the region's starting address.
  94. void RegionFromSection() {
  95. string contents;
  96. ASSERT_TRUE(stack_section.GetContents(&contents));
  97. stack_region.Init(stack_section.start().Value(), contents);
  98. }
  99. // Fill RAW_CONTEXT with pseudo-random data, for round-trip checking.
  100. void BrandContext(MDRawContextAMD64 *raw_context) {
  101. u_int8_t x = 173;
  102. for (size_t i = 0; i < sizeof(*raw_context); i++)
  103. reinterpret_cast<u_int8_t *>(raw_context)[i] = (x += 17);
  104. }
  105. SystemInfo system_info;
  106. MDRawContextAMD64 raw_context;
  107. Section stack_section;
  108. MockMemoryRegion stack_region;
  109. MockCodeModule module1;
  110. MockCodeModule module2;
  111. MockCodeModules modules;
  112. MockSymbolSupplier supplier;
  113. BasicSourceLineResolver resolver;
  114. CallStack call_stack;
  115. const vector<StackFrame *> *frames;
  116. };
  117. class GetContextFrame: public StackwalkerAMD64Fixture, public Test { };
  118. class SanityCheck: public StackwalkerAMD64Fixture, public Test { };
  119. TEST_F(SanityCheck, NoResolver) {
  120. // There should be no references to the stack in this walk: we don't
  121. // provide any call frame information, so trying to reconstruct the
  122. // context frame's caller should fail. So there's no need for us to
  123. // provide stack contents.
  124. raw_context.rip = 0x40000000c0000200ULL;
  125. raw_context.rbp = 0x8000000080000000ULL;
  126. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  127. NULL, NULL);
  128. // This should succeed even without a resolver or supplier.
  129. ASSERT_TRUE(walker.Walk(&call_stack));
  130. frames = call_stack.frames();
  131. ASSERT_GE(1U, frames->size());
  132. StackFrameAMD64 *frame = static_cast<StackFrameAMD64 *>(frames->at(0));
  133. // Check that the values from the original raw context made it
  134. // through to the context in the stack frame.
  135. EXPECT_EQ(0, memcmp(&raw_context, &frame->context, sizeof(raw_context)));
  136. }
  137. TEST_F(GetContextFrame, Simple) {
  138. // There should be no references to the stack in this walk: we don't
  139. // provide any call frame information, so trying to reconstruct the
  140. // context frame's caller should fail. So there's no need for us to
  141. // provide stack contents.
  142. raw_context.rip = 0x40000000c0000200ULL;
  143. raw_context.rbp = 0x8000000080000000ULL;
  144. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  145. &supplier, &resolver);
  146. ASSERT_TRUE(walker.Walk(&call_stack));
  147. frames = call_stack.frames();
  148. ASSERT_GE(1U, frames->size());
  149. StackFrameAMD64 *frame = static_cast<StackFrameAMD64 *>(frames->at(0));
  150. // Check that the values from the original raw context made it
  151. // through to the context in the stack frame.
  152. EXPECT_EQ(0, memcmp(&raw_context, &frame->context, sizeof(raw_context)));
  153. }
  154. class GetCallerFrame: public StackwalkerAMD64Fixture, public Test { };
  155. TEST_F(GetCallerFrame, ScanWithoutSymbols) {
  156. // When the stack walker resorts to scanning the stack,
  157. // only addresses located within loaded modules are
  158. // considered valid return addresses.
  159. // Force scanning through three frames to ensure that the
  160. // stack pointer is set properly in scan-recovered frames.
  161. stack_section.start() = 0x8000000080000000ULL;
  162. u_int64_t return_address1 = 0x50000000b0000100ULL;
  163. u_int64_t return_address2 = 0x50000000b0000900ULL;
  164. Label frame1_sp, frame2_sp, frame1_rbp;
  165. stack_section
  166. // frame 0
  167. .Append(16, 0) // space
  168. .D64(0x40000000b0000000ULL) // junk that's not
  169. .D64(0x50000000d0000000ULL) // a return address
  170. .D64(return_address1) // actual return address
  171. // frame 1
  172. .Mark(&frame1_sp)
  173. .Append(16, 0) // space
  174. .D64(0x40000000b0000000ULL) // more junk
  175. .D64(0x50000000d0000000ULL)
  176. .Mark(&frame1_rbp)
  177. .D64(stack_section.start()) // This is in the right place to be
  178. // a saved rbp, but it's bogus, so
  179. // we shouldn't report it.
  180. .D64(return_address2) // actual return address
  181. // frame 2
  182. .Mark(&frame2_sp)
  183. .Append(32, 0); // end of stack
  184. RegionFromSection();
  185. raw_context.rip = 0x40000000c0000200ULL;
  186. raw_context.rbp = frame1_rbp.Value();
  187. raw_context.rsp = stack_section.start().Value();
  188. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  189. &supplier, &resolver);
  190. ASSERT_TRUE(walker.Walk(&call_stack));
  191. frames = call_stack.frames();
  192. ASSERT_EQ(3U, frames->size());
  193. StackFrameAMD64 *frame0 = static_cast<StackFrameAMD64 *>(frames->at(0));
  194. EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust);
  195. ASSERT_EQ(StackFrameAMD64::CONTEXT_VALID_ALL, frame0->context_validity);
  196. EXPECT_EQ(0, memcmp(&raw_context, &frame0->context, sizeof(raw_context)));
  197. StackFrameAMD64 *frame1 = static_cast<StackFrameAMD64 *>(frames->at(1));
  198. EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust);
  199. ASSERT_EQ((StackFrameAMD64::CONTEXT_VALID_RIP |
  200. StackFrameAMD64::CONTEXT_VALID_RSP |
  201. StackFrameAMD64::CONTEXT_VALID_RBP),
  202. frame1->context_validity);
  203. EXPECT_EQ(return_address1, frame1->context.rip);
  204. EXPECT_EQ(frame1_sp.Value(), frame1->context.rsp);
  205. EXPECT_EQ(frame1_rbp.Value(), frame1->context.rbp);
  206. StackFrameAMD64 *frame2 = static_cast<StackFrameAMD64 *>(frames->at(2));
  207. EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame2->trust);
  208. ASSERT_EQ((StackFrameAMD64::CONTEXT_VALID_RIP |
  209. StackFrameAMD64::CONTEXT_VALID_RSP),
  210. frame2->context_validity);
  211. EXPECT_EQ(return_address2, frame2->context.rip);
  212. EXPECT_EQ(frame2_sp.Value(), frame2->context.rsp);
  213. }
  214. TEST_F(GetCallerFrame, ScanWithFunctionSymbols) {
  215. // During stack scanning, if a potential return address
  216. // is located within a loaded module that has symbols,
  217. // it is only considered a valid return address if it
  218. // lies within a function's bounds.
  219. stack_section.start() = 0x8000000080000000ULL;
  220. u_int64_t return_address = 0x50000000b0000110ULL;
  221. Label frame1_sp, frame1_rbp;
  222. stack_section
  223. // frame 0
  224. .Append(16, 0) // space
  225. .D64(0x40000000b0000000ULL) // junk that's not
  226. .D64(0x50000000b0000000ULL) // a return address
  227. .D64(0x40000000c0001000ULL) // a couple of plausible addresses
  228. .D64(0x50000000b000aaaaULL) // that are not within functions
  229. .D64(return_address) // actual return address
  230. // frame 1
  231. .Mark(&frame1_sp)
  232. .Append(32, 0) // end of stack
  233. .Mark(&frame1_rbp);
  234. RegionFromSection();
  235. raw_context.rip = 0x40000000c0000200ULL;
  236. raw_context.rbp = frame1_rbp.Value();
  237. raw_context.rsp = stack_section.start().Value();
  238. SetModuleSymbols(&module1,
  239. // The youngest frame's function.
  240. "FUNC 100 400 10 platypus\n");
  241. SetModuleSymbols(&module2,
  242. // The calling frame's function.
  243. "FUNC 100 400 10 echidna\n");
  244. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  245. &supplier, &resolver);
  246. ASSERT_TRUE(walker.Walk(&call_stack));
  247. frames = call_stack.frames();
  248. ASSERT_EQ(2U, frames->size());
  249. StackFrameAMD64 *frame0 = static_cast<StackFrameAMD64 *>(frames->at(0));
  250. EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust);
  251. ASSERT_EQ(StackFrameAMD64::CONTEXT_VALID_ALL, frame0->context_validity);
  252. EXPECT_EQ("platypus", frame0->function_name);
  253. EXPECT_EQ(0x40000000c0000100ULL, frame0->function_base);
  254. StackFrameAMD64 *frame1 = static_cast<StackFrameAMD64 *>(frames->at(1));
  255. EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust);
  256. ASSERT_EQ((StackFrameAMD64::CONTEXT_VALID_RIP |
  257. StackFrameAMD64::CONTEXT_VALID_RSP |
  258. StackFrameAMD64::CONTEXT_VALID_RBP),
  259. frame1->context_validity);
  260. EXPECT_EQ(return_address, frame1->context.rip);
  261. EXPECT_EQ(frame1_sp.Value(), frame1->context.rsp);
  262. EXPECT_EQ(frame1_rbp.Value(), frame1->context.rbp);
  263. EXPECT_EQ("echidna", frame1->function_name);
  264. EXPECT_EQ(0x50000000b0000100ULL, frame1->function_base);
  265. }
  266. TEST_F(GetCallerFrame, CallerPushedRBP) {
  267. // Functions typically push their %rbp upon entry and set %rbp pointing
  268. // there. If stackwalking finds a plausible address for the next frame's
  269. // %rbp directly below the return address, assume that it is indeed the
  270. // next frame's %rbp.
  271. stack_section.start() = 0x8000000080000000ULL;
  272. u_int64_t return_address = 0x50000000b0000110ULL;
  273. Label frame0_rbp, frame1_sp, frame1_rbp;
  274. stack_section
  275. // frame 0
  276. .Append(16, 0) // space
  277. .D64(0x40000000b0000000ULL) // junk that's not
  278. .D64(0x50000000b0000000ULL) // a return address
  279. .D64(0x40000000c0001000ULL) // a couple of plausible addresses
  280. .D64(0x50000000b000aaaaULL) // that are not within functions
  281. .Mark(&frame0_rbp)
  282. .D64(frame1_rbp) // caller-pushed %rbp
  283. .D64(return_address) // actual return address
  284. // frame 1
  285. .Mark(&frame1_sp)
  286. .Append(32, 0) // body of frame1
  287. .Mark(&frame1_rbp); // end of stack
  288. RegionFromSection();
  289. raw_context.rip = 0x40000000c0000200ULL;
  290. raw_context.rbp = frame0_rbp.Value();
  291. raw_context.rsp = stack_section.start().Value();
  292. SetModuleSymbols(&module1,
  293. // The youngest frame's function.
  294. "FUNC 100 400 10 sasquatch\n");
  295. SetModuleSymbols(&module2,
  296. // The calling frame's function.
  297. "FUNC 100 400 10 yeti\n");
  298. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  299. &supplier, &resolver);
  300. ASSERT_TRUE(walker.Walk(&call_stack));
  301. frames = call_stack.frames();
  302. ASSERT_EQ(2U, frames->size());
  303. StackFrameAMD64 *frame0 = static_cast<StackFrameAMD64 *>(frames->at(0));
  304. EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust);
  305. ASSERT_EQ(StackFrameAMD64::CONTEXT_VALID_ALL, frame0->context_validity);
  306. EXPECT_EQ(frame0_rbp.Value(), frame0->context.rbp);
  307. EXPECT_EQ("sasquatch", frame0->function_name);
  308. EXPECT_EQ(0x40000000c0000100ULL, frame0->function_base);
  309. StackFrameAMD64 *frame1 = static_cast<StackFrameAMD64 *>(frames->at(1));
  310. EXPECT_EQ(StackFrame::FRAME_TRUST_SCAN, frame1->trust);
  311. ASSERT_EQ((StackFrameAMD64::CONTEXT_VALID_RIP |
  312. StackFrameAMD64::CONTEXT_VALID_RSP |
  313. StackFrameAMD64::CONTEXT_VALID_RBP),
  314. frame1->context_validity);
  315. EXPECT_EQ(return_address, frame1->context.rip);
  316. EXPECT_EQ(frame1_sp.Value(), frame1->context.rsp);
  317. EXPECT_EQ(frame1_rbp.Value(), frame1->context.rbp);
  318. EXPECT_EQ("yeti", frame1->function_name);
  319. EXPECT_EQ(0x50000000b0000100ULL, frame1->function_base);
  320. }
  321. struct CFIFixture: public StackwalkerAMD64Fixture {
  322. CFIFixture() {
  323. // Provide a bunch of STACK CFI records; we'll walk to the caller
  324. // from every point in this series, expecting to find the same set
  325. // of register values.
  326. SetModuleSymbols(&module1,
  327. // The youngest frame's function.
  328. "FUNC 4000 1000 10 enchiridion\n"
  329. // Initially, just a return address.
  330. "STACK CFI INIT 4000 100 .cfa: $rsp 8 + .ra: .cfa 8 - ^\n"
  331. // Push %rbx.
  332. "STACK CFI 4001 .cfa: $rsp 16 + $rbx: .cfa 16 - ^\n"
  333. // Save %r12 in %rbx. Weird, but permitted.
  334. "STACK CFI 4002 $r12: $rbx\n"
  335. // Allocate frame space, and save %r13.
  336. "STACK CFI 4003 .cfa: $rsp 40 + $r13: .cfa 32 - ^\n"
  337. // Put the return address in %r13.
  338. "STACK CFI 4005 .ra: $r13\n"
  339. // Save %rbp, and use it as a frame pointer.
  340. "STACK CFI 4006 .cfa: $rbp 16 + $rbp: .cfa 24 - ^\n"
  341. // The calling function.
  342. "FUNC 5000 1000 10 epictetus\n"
  343. // Mark it as end of stack.
  344. "STACK CFI INIT 5000 1000 .cfa: $rsp .ra 0\n");
  345. // Provide some distinctive values for the caller's registers.
  346. expected.rsp = 0x8000000080000000ULL;
  347. expected.rip = 0x40000000c0005510ULL;
  348. expected.rbp = 0x68995b1de4700266ULL;
  349. expected.rbx = 0x5a5beeb38de23be8ULL;
  350. expected.r12 = 0xed1b02e8cc0fc79cULL;
  351. expected.r13 = 0x1d20ad8acacbe930ULL;
  352. expected.r14 = 0xe94cffc2f7adaa28ULL;
  353. expected.r15 = 0xb638d17d8da413b5ULL;
  354. // By default, registers are unchanged.
  355. raw_context = expected;
  356. }
  357. // Walk the stack, using stack_section as the contents of the stack
  358. // and raw_context as the current register values. (Set
  359. // raw_context.rsp to the stack's starting address.) Expect two
  360. // stack frames; in the older frame, expect the callee-saves
  361. // registers to have values matching those in 'expected'.
  362. void CheckWalk() {
  363. RegionFromSection();
  364. raw_context.rsp = stack_section.start().Value();
  365. StackwalkerAMD64 walker(&system_info, &raw_context, &stack_region, &modules,
  366. &supplier, &resolver);
  367. ASSERT_TRUE(walker.Walk(&call_stack));
  368. frames = call_stack.frames();
  369. ASSERT_EQ(2U, frames->size());
  370. StackFrameAMD64 *frame0 = static_cast<StackFrameAMD64 *>(frames->at(0));
  371. EXPECT_EQ(StackFrame::FRAME_TRUST_CONTEXT, frame0->trust);
  372. ASSERT_EQ(StackFrameAMD64::CONTEXT_VALID_ALL, frame0->context_validity);
  373. EXPECT_EQ("enchiridion", frame0->function_name);
  374. EXPECT_EQ(0x40000000c0004000ULL, frame0->function_base);
  375. StackFrameAMD64 *frame1 = static_cast<StackFrameAMD64 *>(frames->at(1));
  376. EXPECT_EQ(StackFrame::FRAME_TRUST_CFI, frame1->trust);
  377. ASSERT_EQ((StackFrameAMD64::CONTEXT_VALID_RIP |
  378. StackFrameAMD64::CONTEXT_VALID_RSP |
  379. StackFrameAMD64::CONTEXT_VALID_RBP |
  380. StackFrameAMD64::CONTEXT_VALID_RBX |
  381. StackFrameAMD64::CONTEXT_VALID_R12 |
  382. StackFrameAMD64::CONTEXT_VALID_R13 |
  383. StackFrameAMD64::CONTEXT_VALID_R14 |
  384. StackFrameAMD64::CONTEXT_VALID_R15),
  385. frame1->context_validity);
  386. EXPECT_EQ(expected.rip, frame1->context.rip);
  387. EXPECT_EQ(expected.rsp, frame1->context.rsp);
  388. EXPECT_EQ(expected.rbp, frame1->context.rbp);
  389. EXPECT_EQ(expected.rbx, frame1->context.rbx);
  390. EXPECT_EQ(expected.r12, frame1->context.r12);
  391. EXPECT_EQ(expected.r13, frame1->context.r13);
  392. EXPECT_EQ(expected.r14, frame1->context.r14);
  393. EXPECT_EQ(expected.r15, frame1->context.r15);
  394. EXPECT_EQ("epictetus", frame1->function_name);
  395. }
  396. // The values we expect to find for the caller's registers.
  397. MDRawContextAMD64 expected;
  398. };
  399. class CFI: public CFIFixture, public Test { };
  400. TEST_F(CFI, At4000) {
  401. Label frame1_rsp = expected.rsp;
  402. stack_section
  403. .D64(0x40000000c0005510ULL) // return address
  404. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  405. raw_context.rip = 0x40000000c0004000ULL;
  406. CheckWalk();
  407. }
  408. TEST_F(CFI, At4001) {
  409. Label frame1_rsp = expected.rsp;
  410. stack_section
  411. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  412. .D64(0x40000000c0005510ULL) // return address
  413. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  414. raw_context.rip = 0x40000000c0004001ULL;
  415. raw_context.rbx = 0xbe0487d2f9eafe29ULL; // callee's (distinct) %rbx value
  416. CheckWalk();
  417. }
  418. TEST_F(CFI, At4002) {
  419. Label frame1_rsp = expected.rsp;
  420. stack_section
  421. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  422. .D64(0x40000000c0005510ULL) // return address
  423. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  424. raw_context.rip = 0x40000000c0004002ULL;
  425. raw_context.rbx = 0xed1b02e8cc0fc79cULL; // saved %r12
  426. raw_context.r12 = 0xb0118de918a4bceaULL; // callee's (distinct) %r12 value
  427. CheckWalk();
  428. }
  429. TEST_F(CFI, At4003) {
  430. Label frame1_rsp = expected.rsp;
  431. stack_section
  432. .D64(0x0e023828dffd4d81ULL) // garbage
  433. .D64(0x1d20ad8acacbe930ULL) // saved %r13
  434. .D64(0x319e68b49e3ace0fULL) // garbage
  435. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  436. .D64(0x40000000c0005510ULL) // return address
  437. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  438. raw_context.rip = 0x40000000c0004003ULL;
  439. raw_context.rbx = 0xed1b02e8cc0fc79cULL; // saved %r12
  440. raw_context.r12 = 0x89d04fa804c87a43ULL; // callee's (distinct) %r12
  441. raw_context.r13 = 0x5118e02cbdb24b03ULL; // callee's (distinct) %r13
  442. CheckWalk();
  443. }
  444. // The results here should be the same as those at module offset 0x4003.
  445. TEST_F(CFI, At4004) {
  446. Label frame1_rsp = expected.rsp;
  447. stack_section
  448. .D64(0x0e023828dffd4d81ULL) // garbage
  449. .D64(0x1d20ad8acacbe930ULL) // saved %r13
  450. .D64(0x319e68b49e3ace0fULL) // garbage
  451. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  452. .D64(0x40000000c0005510ULL) // return address
  453. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  454. raw_context.rip = 0x40000000c0004004ULL;
  455. raw_context.rbx = 0xed1b02e8cc0fc79cULL; // saved %r12
  456. raw_context.r12 = 0x89d04fa804c87a43ULL; // callee's (distinct) %r12
  457. raw_context.r13 = 0x5118e02cbdb24b03ULL; // callee's (distinct) %r13
  458. CheckWalk();
  459. }
  460. TEST_F(CFI, At4005) {
  461. Label frame1_rsp = expected.rsp;
  462. stack_section
  463. .D64(0x4b516dd035745953ULL) // garbage
  464. .D64(0x1d20ad8acacbe930ULL) // saved %r13
  465. .D64(0xa6d445e16ae3d872ULL) // garbage
  466. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  467. .D64(0xaa95fa054aedfbaeULL) // garbage
  468. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  469. raw_context.rip = 0x40000000c0004005ULL;
  470. raw_context.rbx = 0xed1b02e8cc0fc79cULL; // saved %r12
  471. raw_context.r12 = 0x46b1b8868891b34aULL; // callee's %r12
  472. raw_context.r13 = 0x40000000c0005510ULL; // return address
  473. CheckWalk();
  474. }
  475. TEST_F(CFI, At4006) {
  476. Label frame0_rbp;
  477. Label frame1_rsp = expected.rsp;
  478. stack_section
  479. .D64(0x043c6dfceb91aa34ULL) // garbage
  480. .D64(0x1d20ad8acacbe930ULL) // saved %r13
  481. .D64(0x68995b1de4700266ULL) // saved %rbp
  482. .Mark(&frame0_rbp) // frame pointer points here
  483. .D64(0x5a5beeb38de23be8ULL) // saved %rbx
  484. .D64(0xf015ee516ad89eabULL) // garbage
  485. .Mark(&frame1_rsp); // This effectively sets stack_section.start().
  486. raw_context.rip = 0x40000000c0004006ULL;
  487. raw_context.rbp = frame0_rbp.Value();
  488. raw_context.rbx = 0xed1b02e8cc0fc79cULL; // saved %r12
  489. raw_context.r12 = 0x26e007b341acfebdULL; // callee's %r12
  490. raw_context.r13 = 0x40000000c0005510ULL; // return address
  491. CheckWalk();
  492. }