OLD | NEW |
| (Empty) |
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 | |
30 // Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com> | |
31 | |
32 // dump_stabs_unittest.cc: Unit tests for DumpStabsHandler. | |
33 | |
34 #include <vector> | |
35 | |
36 #include "breakpad_googletest_includes.h" | |
37 #include "common/dump_stabs.h" | |
38 | |
39 using google_breakpad::DumpStabsHandler; | |
40 using google_breakpad::Module; | |
41 using std::vector; | |
42 | |
43 TEST(DumpStabsHandler, SimpleCU) { | |
44 Module m("name", "os", "arch", "id"); | |
45 DumpStabsHandler h(&m); | |
46 | |
47 // Feed in a simple compilation unit that defines a function with | |
48 // one line. | |
49 EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0x9f4d1271e50db93bLL, | |
50 "build-directory")); | |
51 EXPECT_TRUE(h.StartFunction("function", 0xfde4abbed390c394LL)); | |
52 EXPECT_TRUE(h.Line(0xfde4abbed390c394LL, "source-file-name", 174823314)); | |
53 EXPECT_TRUE(h.EndFunction(0xfde4abbed390c3a4LL)); | |
54 EXPECT_TRUE(h.EndCompilationUnit(0xfee4abbed390c3a4LL)); | |
55 h.Finalize(); | |
56 | |
57 // Now check to see what has been added to the Module. | |
58 Module::File *file = m.FindExistingFile("source-file-name"); | |
59 ASSERT_TRUE(file != NULL); | |
60 | |
61 vector<Module::Function *> functions; | |
62 m.GetFunctions(&functions, functions.end()); | |
63 ASSERT_EQ((size_t) 1, functions.size()); | |
64 Module::Function *function = functions[0]; | |
65 EXPECT_STREQ("function", function->name.c_str()); | |
66 EXPECT_EQ(0xfde4abbed390c394LL, function->address); | |
67 EXPECT_EQ(0x10U, function->size); | |
68 EXPECT_EQ(0U, function->parameter_size); | |
69 ASSERT_EQ((size_t) 1, function->lines.size()); | |
70 Module::Line *line = &function->lines[0]; | |
71 EXPECT_EQ(0xfde4abbed390c394LL, line->address); | |
72 EXPECT_EQ(0x10U, line->size); // derived from EndFunction | |
73 EXPECT_TRUE(line->file == file); | |
74 EXPECT_EQ(174823314, line->number); | |
75 } | |
76 | |
77 TEST(InferSizes, LineSize) { | |
78 Module m("name", "os", "arch", "id"); | |
79 DumpStabsHandler h(&m); | |
80 | |
81 // Feed in a simple compilation unit that defines a function with | |
82 // one line. | |
83 EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xb4513962eff94e92LL, | |
84 "build-directory")); | |
85 EXPECT_TRUE(h.StartFunction("function", 0xb4513962eff94e92LL)); | |
86 EXPECT_TRUE(h.Line(0xb4513962eff94e92LL, "source-file-name-1", 77396614)); | |
87 EXPECT_TRUE(h.Line(0xb4513963eff94e92LL, "source-file-name-2", 87660088)); | |
88 EXPECT_TRUE(h.EndFunction(0)); // unknown function end address | |
89 EXPECT_TRUE(h.EndCompilationUnit(0)); // unknown CU end address | |
90 EXPECT_TRUE(h.StartCompilationUnit("compilation-unit-2", 0xb4523963eff94e92LL, | |
91 "build-directory-2")); // next boundary | |
92 EXPECT_TRUE(h.EndCompilationUnit(0)); | |
93 h.Finalize(); | |
94 | |
95 // Now check to see what has been added to the Module. | |
96 Module::File *file1 = m.FindExistingFile("source-file-name-1"); | |
97 ASSERT_TRUE(file1 != NULL); | |
98 Module::File *file2 = m.FindExistingFile("source-file-name-2"); | |
99 ASSERT_TRUE(file2 != NULL); | |
100 | |
101 vector<Module::Function *> functions; | |
102 m.GetFunctions(&functions, functions.end()); | |
103 ASSERT_EQ((size_t) 1, functions.size()); | |
104 | |
105 Module::Function *function = functions[0]; | |
106 EXPECT_STREQ("function", function->name.c_str()); | |
107 EXPECT_EQ(0xb4513962eff94e92LL, function->address); | |
108 EXPECT_EQ(0x1000100000000ULL, function->size); // inferred from CU end | |
109 EXPECT_EQ(0U, function->parameter_size); | |
110 ASSERT_EQ((size_t) 2, function->lines.size()); | |
111 | |
112 Module::Line *line1 = &function->lines[0]; | |
113 EXPECT_EQ(0xb4513962eff94e92LL, line1->address); | |
114 EXPECT_EQ(0x100000000ULL, line1->size); // derived from EndFunction | |
115 EXPECT_TRUE(line1->file == file1); | |
116 EXPECT_EQ(77396614, line1->number); | |
117 | |
118 Module::Line *line2 = &function->lines[1]; | |
119 EXPECT_EQ(0xb4513963eff94e92LL, line2->address); | |
120 EXPECT_EQ(0x1000000000000ULL, line2->size); // derived from EndFunction | |
121 EXPECT_TRUE(line2->file == file2); | |
122 EXPECT_EQ(87660088, line2->number); | |
123 } | |
124 | |
125 TEST(FunctionNames, Mangled) { | |
126 Module m("name", "os", "arch", "id"); | |
127 DumpStabsHandler h(&m); | |
128 | |
129 // Compilation unit with one function, mangled name. | |
130 EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0xf2cfda63cef7f46cLL, | |
131 "build-directory")); | |
132 EXPECT_TRUE(h.StartFunction("_ZNSt6vectorIySaIyEE9push_backERKy", | |
133 0xf2cfda63cef7f46dLL)); | |
134 EXPECT_TRUE(h.EndFunction(0)); | |
135 EXPECT_TRUE(h.EndCompilationUnit(0)); | |
136 | |
137 h.Finalize(); | |
138 | |
139 // Now check to see what has been added to the Module. | |
140 Module::File *file = m.FindExistingFile("compilation-unit"); | |
141 ASSERT_TRUE(file != NULL); | |
142 | |
143 vector<Module::Function *> functions; | |
144 m.GetFunctions(&functions, functions.end()); | |
145 ASSERT_EQ(1U, functions.size()); | |
146 | |
147 Module::Function *function = functions[0]; | |
148 // This is GCC-specific, but we shouldn't be seeing STABS data anywhere | |
149 // but Linux. | |
150 EXPECT_STREQ("std::vector<unsigned long long, " | |
151 "std::allocator<unsigned long long> >::" | |
152 "push_back(unsigned long long const&)", | |
153 function->name.c_str()); | |
154 EXPECT_EQ(0xf2cfda63cef7f46dLL, function->address); | |
155 EXPECT_LT(0U, function->size); // should have used dummy size | |
156 EXPECT_EQ(0U, function->parameter_size); | |
157 ASSERT_EQ(0U, function->lines.size()); | |
158 } | |
159 | |
160 // The GNU toolchain can omit functions that are not used; however, | |
161 // when it does so, it doesn't clean up the debugging information that | |
162 // refers to them. In STABS, this results in compilation units whose | |
163 // SO addresses are zero. | |
164 TEST(Omitted, Function) { | |
165 Module m("name", "os", "arch", "id"); | |
166 DumpStabsHandler h(&m); | |
167 | |
168 // The StartCompilationUnit and EndCompilationUnit calls may both have an | |
169 // address of zero if the compilation unit has had sections removed. | |
170 EXPECT_TRUE(h.StartCompilationUnit("compilation-unit", 0, "build-directory")); | |
171 EXPECT_TRUE(h.StartFunction("function", 0x2a133596)); | |
172 EXPECT_TRUE(h.EndFunction(0)); | |
173 EXPECT_TRUE(h.EndCompilationUnit(0)); | |
174 } | |
175 | |
176 // TODO --- if we actually cared about STABS. Even without these we've | |
177 // got full coverage of non-failure source lines in dump_stabs.cc. | |
178 | |
179 // Line size from next line | |
180 // Line size from function end | |
181 // Line size from next function start | |
182 // line size from cu end | |
183 // line size from next cu start | |
184 // fallback size is something plausible | |
185 | |
186 // function size from function end | |
187 // function size from next function start | |
188 // function size from cu end | |
189 // function size from next cu start | |
190 // fallback size is something plausible | |
191 | |
192 // omitting functions outside the compilation unit's address range | |
193 // zero-line, one-line, many-line functions | |
OLD | NEW |