system/core
修訂 | 4a6483923cb3bea2af714ee7916fbc08f590cc42 (tree) |
---|---|
時間 | 2019-04-05 06:47:42 |
作者 | Christopher Ferris <cferris@goog...> |
Commiter | Android (Google) Code Review |
Merge "Fix off by one reading build id." into qt-dev
@@ -285,7 +285,7 @@ std::string ElfInterface::ReadBuildID() { | ||
285 | 285 | if (gnu_build_id_size_ - offset < hdr.n_descsz || hdr.n_descsz == 0) { |
286 | 286 | return ""; |
287 | 287 | } |
288 | - std::string build_id(hdr.n_descsz - 1, '\0'); | |
288 | + std::string build_id(hdr.n_descsz, '\0'); | |
289 | 289 | if (memory_->ReadFully(gnu_build_id_offset_ + offset, &build_id[0], hdr.n_descsz)) { |
290 | 290 | return build_id; |
291 | 291 | } |
@@ -1192,14 +1192,16 @@ void ElfInterfaceTest::BuildID() { | ||
1192 | 1192 | char note_section[128]; |
1193 | 1193 | Nhdr note_header = {}; |
1194 | 1194 | note_header.n_namesz = 4; // "GNU" |
1195 | - note_header.n_descsz = 8; // "BUILDID" | |
1195 | + note_header.n_descsz = 7; // "BUILDID" | |
1196 | 1196 | note_header.n_type = NT_GNU_BUILD_ID; |
1197 | 1197 | memcpy(¬e_section, ¬e_header, sizeof(note_header)); |
1198 | 1198 | size_t note_offset = sizeof(note_header); |
1199 | + // The note information contains the GNU and trailing '\0'. | |
1199 | 1200 | memcpy(¬e_section[note_offset], "GNU", sizeof("GNU")); |
1200 | 1201 | note_offset += sizeof("GNU"); |
1201 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1202 | - note_offset += sizeof("BUILDID"); | |
1202 | + // This part of the note does not contain any trailing '\0'. | |
1203 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1204 | + note_offset += 8; | |
1203 | 1205 | |
1204 | 1206 | Shdr shdr = {}; |
1205 | 1207 | shdr.sh_type = SHT_NOTE; |
@@ -1244,24 +1246,27 @@ void ElfInterfaceTest::BuildIDTwoNotes() { | ||
1244 | 1246 | char note_section[128]; |
1245 | 1247 | Nhdr note_header = {}; |
1246 | 1248 | note_header.n_namesz = 8; // "WRONG" aligned to 4 |
1247 | - note_header.n_descsz = 8; // "BUILDID" | |
1249 | + note_header.n_descsz = 7; // "BUILDID" | |
1248 | 1250 | note_header.n_type = NT_GNU_BUILD_ID; |
1249 | 1251 | memcpy(¬e_section, ¬e_header, sizeof(note_header)); |
1250 | 1252 | size_t note_offset = sizeof(note_header); |
1251 | 1253 | memcpy(¬e_section[note_offset], "WRONG", sizeof("WRONG")); |
1252 | 1254 | note_offset += 8; |
1253 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1254 | - note_offset += sizeof("BUILDID"); | |
1255 | + // This part of the note does not contain any trailing '\0'. | |
1256 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1257 | + note_offset += 8; | |
1255 | 1258 | |
1256 | 1259 | note_header.n_namesz = 4; // "GNU" |
1257 | - note_header.n_descsz = 8; // "BUILDID" | |
1260 | + note_header.n_descsz = 7; // "BUILDID" | |
1258 | 1261 | note_header.n_type = NT_GNU_BUILD_ID; |
1259 | 1262 | memcpy(¬e_section[note_offset], ¬e_header, sizeof(note_header)); |
1260 | 1263 | note_offset += sizeof(note_header); |
1264 | + // The note information contains the GNU and trailing '\0'. | |
1261 | 1265 | memcpy(¬e_section[note_offset], "GNU", sizeof("GNU")); |
1262 | 1266 | note_offset += sizeof("GNU"); |
1263 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1264 | - note_offset += sizeof("BUILDID"); | |
1267 | + // This part of the note does not contain any trailing '\0'. | |
1268 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1269 | + note_offset += 8; | |
1265 | 1270 | |
1266 | 1271 | Shdr shdr = {}; |
1267 | 1272 | shdr.sh_type = SHT_NOTE; |
@@ -1306,14 +1311,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForName () { | ||
1306 | 1311 | char note_section[128]; |
1307 | 1312 | Nhdr note_header = {}; |
1308 | 1313 | note_header.n_namesz = 4; // "GNU" |
1309 | - note_header.n_descsz = 8; // "BUILDID" | |
1314 | + note_header.n_descsz = 7; // "BUILDID" | |
1310 | 1315 | note_header.n_type = NT_GNU_BUILD_ID; |
1311 | 1316 | memcpy(¬e_section, ¬e_header, sizeof(note_header)); |
1312 | 1317 | size_t note_offset = sizeof(note_header); |
1318 | + // The note information contains the GNU and trailing '\0'. | |
1313 | 1319 | memcpy(¬e_section[note_offset], "GNU", sizeof("GNU")); |
1314 | 1320 | note_offset += sizeof("GNU"); |
1315 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1316 | - note_offset += sizeof("BUILDID"); | |
1321 | + // This part of the note does not contain any trailing '\0'. | |
1322 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1323 | + note_offset += 8; | |
1317 | 1324 | |
1318 | 1325 | Shdr shdr = {}; |
1319 | 1326 | shdr.sh_type = SHT_NOTE; |
@@ -1358,14 +1365,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () { | ||
1358 | 1365 | char note_section[128]; |
1359 | 1366 | Nhdr note_header = {}; |
1360 | 1367 | note_header.n_namesz = 4; // "GNU" |
1361 | - note_header.n_descsz = 8; // "BUILDID" | |
1368 | + note_header.n_descsz = 7; // "BUILDID" | |
1362 | 1369 | note_header.n_type = NT_GNU_BUILD_ID; |
1363 | 1370 | memcpy(¬e_section, ¬e_header, sizeof(note_header)); |
1364 | 1371 | size_t note_offset = sizeof(note_header); |
1372 | + // The note information contains the GNU and trailing '\0'. | |
1365 | 1373 | memcpy(¬e_section[note_offset], "GNU", sizeof("GNU")); |
1366 | 1374 | note_offset += sizeof("GNU"); |
1367 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1368 | - note_offset += sizeof("BUILDID"); | |
1375 | + // This part of the note does not contain any trailing '\0'. | |
1376 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1377 | + note_offset += 8; | |
1369 | 1378 | |
1370 | 1379 | Shdr shdr = {}; |
1371 | 1380 | shdr.sh_type = SHT_NOTE; |
@@ -1410,14 +1419,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () { | ||
1410 | 1419 | char note_section[128]; |
1411 | 1420 | Nhdr note_header = {}; |
1412 | 1421 | note_header.n_namesz = 4; // "GNU" |
1413 | - note_header.n_descsz = 8; // "BUILDID" | |
1422 | + note_header.n_descsz = 7; // "BUILDID" | |
1414 | 1423 | note_header.n_type = NT_GNU_BUILD_ID; |
1415 | 1424 | memcpy(¬e_section, ¬e_header, sizeof(note_header)); |
1416 | 1425 | size_t note_offset = sizeof(note_header); |
1426 | + // The note information contains the GNU and trailing '\0'. | |
1417 | 1427 | memcpy(¬e_section[note_offset], "GNU", sizeof("GNU")); |
1418 | 1428 | note_offset += sizeof("GNU"); |
1419 | - memcpy(¬e_section[note_offset], "BUILDID", sizeof("BUILDID")); | |
1420 | - note_offset += sizeof("BUILDID"); | |
1429 | + // This part of the note does not contain any trailing '\0'. | |
1430 | + memcpy(¬e_section[note_offset], "BUILDID", 7); | |
1431 | + note_offset += 8; | |
1421 | 1432 | |
1422 | 1433 | Shdr shdr = {}; |
1423 | 1434 | shdr.sh_type = SHT_NOTE; |
@@ -204,6 +204,7 @@ static std::string DumpFrames(Unwinder& unwinder) { | ||
204 | 204 | TEST_F(UnwindOfflineTest, pc_straddle_arm) { |
205 | 205 | ASSERT_NO_FATAL_FAILURE(Init("straddle_arm/", ARCH_ARM)); |
206 | 206 | |
207 | + std::unique_ptr<Regs> regs_copy(regs_->Clone()); | |
207 | 208 | Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_); |
208 | 209 | unwinder.Unwind(); |
209 | 210 |
@@ -223,6 +224,22 @@ TEST_F(UnwindOfflineTest, pc_straddle_arm) { | ||
223 | 224 | EXPECT_EQ(0xe9c86730U, unwinder.frames()[2].sp); |
224 | 225 | EXPECT_EQ(0xf3367147U, unwinder.frames()[3].pc); |
225 | 226 | EXPECT_EQ(0xe9c86778U, unwinder.frames()[3].sp); |
227 | + | |
228 | + // Display build ids now. | |
229 | + unwinder.SetRegs(regs_copy.get()); | |
230 | + unwinder.SetDisplayBuildID(true); | |
231 | + unwinder.Unwind(); | |
232 | + | |
233 | + frame_info = DumpFrames(unwinder); | |
234 | + ASSERT_EQ(4U, unwinder.NumFrames()) << "Unwind:\n" << frame_info; | |
235 | + EXPECT_EQ( | |
236 | + " #00 pc 0001a9f8 libc.so (abort+64) (BuildId: 2dd0d4ba881322a0edabeed94808048c)\n" | |
237 | + " #01 pc 00006a1b libbase.so (android::base::DefaultAborter(char const*)+6) (BuildId: " | |
238 | + "ed43842c239cac1a618e600ea91c4cbd)\n" | |
239 | + " #02 pc 00007441 libbase.so (android::base::LogMessage::~LogMessage()+748) (BuildId: " | |
240 | + "ed43842c239cac1a618e600ea91c4cbd)\n" | |
241 | + " #03 pc 00015147 /does/not/exist/libhidlbase.so\n", | |
242 | + frame_info); | |
226 | 243 | } |
227 | 244 | |
228 | 245 | TEST_F(UnwindOfflineTest, pc_in_gnu_debugdata_arm) { |