• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


Commit MetaInfo

修訂4a6483923cb3bea2af714ee7916fbc08f590cc42 (tree)
時間2019-04-05 06:47:42
作者Christopher Ferris <cferris@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge "Fix off by one reading build id." into qt-dev

Change Summary

差異

--- a/libunwindstack/ElfInterface.cpp
+++ b/libunwindstack/ElfInterface.cpp
@@ -285,7 +285,7 @@ std::string ElfInterface::ReadBuildID() {
285285 if (gnu_build_id_size_ - offset < hdr.n_descsz || hdr.n_descsz == 0) {
286286 return "";
287287 }
288- std::string build_id(hdr.n_descsz - 1, '\0');
288+ std::string build_id(hdr.n_descsz, '\0');
289289 if (memory_->ReadFully(gnu_build_id_offset_ + offset, &build_id[0], hdr.n_descsz)) {
290290 return build_id;
291291 }
--- a/libunwindstack/tests/ElfInterfaceTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceTest.cpp
@@ -1192,14 +1192,16 @@ void ElfInterfaceTest::BuildID() {
11921192 char note_section[128];
11931193 Nhdr note_header = {};
11941194 note_header.n_namesz = 4; // "GNU"
1195- note_header.n_descsz = 8; // "BUILDID"
1195+ note_header.n_descsz = 7; // "BUILDID"
11961196 note_header.n_type = NT_GNU_BUILD_ID;
11971197 memcpy(&note_section, &note_header, sizeof(note_header));
11981198 size_t note_offset = sizeof(note_header);
1199+ // The note information contains the GNU and trailing '\0'.
11991200 memcpy(&note_section[note_offset], "GNU", sizeof("GNU"));
12001201 note_offset += sizeof("GNU");
1201- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1204+ note_offset += 8;
12031205
12041206 Shdr shdr = {};
12051207 shdr.sh_type = SHT_NOTE;
@@ -1244,24 +1246,27 @@ void ElfInterfaceTest::BuildIDTwoNotes() {
12441246 char note_section[128];
12451247 Nhdr note_header = {};
12461248 note_header.n_namesz = 8; // "WRONG" aligned to 4
1247- note_header.n_descsz = 8; // "BUILDID"
1249+ note_header.n_descsz = 7; // "BUILDID"
12481250 note_header.n_type = NT_GNU_BUILD_ID;
12491251 memcpy(&note_section, &note_header, sizeof(note_header));
12501252 size_t note_offset = sizeof(note_header);
12511253 memcpy(&note_section[note_offset], "WRONG", sizeof("WRONG"));
12521254 note_offset += 8;
1253- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1257+ note_offset += 8;
12551258
12561259 note_header.n_namesz = 4; // "GNU"
1257- note_header.n_descsz = 8; // "BUILDID"
1260+ note_header.n_descsz = 7; // "BUILDID"
12581261 note_header.n_type = NT_GNU_BUILD_ID;
12591262 memcpy(&note_section[note_offset], &note_header, sizeof(note_header));
12601263 note_offset += sizeof(note_header);
1264+ // The note information contains the GNU and trailing '\0'.
12611265 memcpy(&note_section[note_offset], "GNU", sizeof("GNU"));
12621266 note_offset += sizeof("GNU");
1263- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1269+ note_offset += 8;
12651270
12661271 Shdr shdr = {};
12671272 shdr.sh_type = SHT_NOTE;
@@ -1306,14 +1311,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForName () {
13061311 char note_section[128];
13071312 Nhdr note_header = {};
13081313 note_header.n_namesz = 4; // "GNU"
1309- note_header.n_descsz = 8; // "BUILDID"
1314+ note_header.n_descsz = 7; // "BUILDID"
13101315 note_header.n_type = NT_GNU_BUILD_ID;
13111316 memcpy(&note_section, &note_header, sizeof(note_header));
13121317 size_t note_offset = sizeof(note_header);
1318+ // The note information contains the GNU and trailing '\0'.
13131319 memcpy(&note_section[note_offset], "GNU", sizeof("GNU"));
13141320 note_offset += sizeof("GNU");
1315- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1323+ note_offset += 8;
13171324
13181325 Shdr shdr = {};
13191326 shdr.sh_type = SHT_NOTE;
@@ -1358,14 +1365,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForDesc () {
13581365 char note_section[128];
13591366 Nhdr note_header = {};
13601367 note_header.n_namesz = 4; // "GNU"
1361- note_header.n_descsz = 8; // "BUILDID"
1368+ note_header.n_descsz = 7; // "BUILDID"
13621369 note_header.n_type = NT_GNU_BUILD_ID;
13631370 memcpy(&note_section, &note_header, sizeof(note_header));
13641371 size_t note_offset = sizeof(note_header);
1372+ // The note information contains the GNU and trailing '\0'.
13651373 memcpy(&note_section[note_offset], "GNU", sizeof("GNU"));
13661374 note_offset += sizeof("GNU");
1367- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1377+ note_offset += 8;
13691378
13701379 Shdr shdr = {};
13711380 shdr.sh_type = SHT_NOTE;
@@ -1410,14 +1419,16 @@ void ElfInterfaceTest::BuildIDSectionTooSmallForHeader () {
14101419 char note_section[128];
14111420 Nhdr note_header = {};
14121421 note_header.n_namesz = 4; // "GNU"
1413- note_header.n_descsz = 8; // "BUILDID"
1422+ note_header.n_descsz = 7; // "BUILDID"
14141423 note_header.n_type = NT_GNU_BUILD_ID;
14151424 memcpy(&note_section, &note_header, sizeof(note_header));
14161425 size_t note_offset = sizeof(note_header);
1426+ // The note information contains the GNU and trailing '\0'.
14171427 memcpy(&note_section[note_offset], "GNU", sizeof("GNU"));
14181428 note_offset += sizeof("GNU");
1419- memcpy(&note_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(&note_section[note_offset], "BUILDID", 7);
1431+ note_offset += 8;
14211432
14221433 Shdr shdr = {};
14231434 shdr.sh_type = SHT_NOTE;
--- a/libunwindstack/tests/UnwindOfflineTest.cpp
+++ b/libunwindstack/tests/UnwindOfflineTest.cpp
@@ -204,6 +204,7 @@ static std::string DumpFrames(Unwinder& unwinder) {
204204 TEST_F(UnwindOfflineTest, pc_straddle_arm) {
205205 ASSERT_NO_FATAL_FAILURE(Init("straddle_arm/", ARCH_ARM));
206206
207+ std::unique_ptr<Regs> regs_copy(regs_->Clone());
207208 Unwinder unwinder(128, maps_.get(), regs_.get(), process_memory_);
208209 unwinder.Unwind();
209210
@@ -223,6 +224,22 @@ TEST_F(UnwindOfflineTest, pc_straddle_arm) {
223224 EXPECT_EQ(0xe9c86730U, unwinder.frames()[2].sp);
224225 EXPECT_EQ(0xf3367147U, unwinder.frames()[3].pc);
225226 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);
226243 }
227244
228245 TEST_F(UnwindOfflineTest, pc_in_gnu_debugdata_arm) {