Skip to content

Commit 3246b97

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Log the cmd when the binder driver fails to consume buffer" into main
2 parents 91a1058 + 0272a5d commit 3246b97

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

libs/binder/IPCThreadState.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ static const void* printReturnCommand(std::ostream& out, const void* _cmd) {
232232
return cmd;
233233
}
234234

235+
static void printReturnCommandParcel(std::ostream& out, const Parcel& parcel) {
236+
const void* cmds = parcel.data();
237+
out << "\t" << HexDump(cmds, parcel.dataSize()) << "\n";
238+
IF_LOG_COMMANDS() {
239+
const void* end = parcel.data() + parcel.dataSize();
240+
while (cmds < end) cmds = printReturnCommand(out, cmds);
241+
}
242+
}
243+
235244
static const void* printCommand(std::ostream& out, const void* _cmd) {
236245
static const size_t N = sizeof(kCommandStrings)/sizeof(kCommandStrings[0]);
237246
const int32_t* cmd = (const int32_t*)_cmd;
@@ -1235,13 +1244,15 @@ status_t IPCThreadState::talkWithDriver(bool doReceive)
12351244

12361245
if (err >= NO_ERROR) {
12371246
if (bwr.write_consumed > 0) {
1238-
if (bwr.write_consumed < mOut.dataSize())
1247+
if (bwr.write_consumed < mOut.dataSize()) {
1248+
std::ostringstream logStream;
1249+
printReturnCommandParcel(logStream, mIn);
12391250
LOG_ALWAYS_FATAL("Driver did not consume write buffer. "
1240-
"err: %s consumed: %zu of %zu",
1241-
statusToString(err).c_str(),
1242-
(size_t)bwr.write_consumed,
1243-
mOut.dataSize());
1244-
else {
1251+
"err: %s consumed: %zu of %zu.\n"
1252+
"Return command: %s",
1253+
statusToString(err).c_str(), (size_t)bwr.write_consumed,
1254+
mOut.dataSize(), logStream.str().c_str());
1255+
} else {
12451256
mOut.setDataSize(0);
12461257
processPostWriteDerefs();
12471258
}
@@ -1252,14 +1263,8 @@ status_t IPCThreadState::talkWithDriver(bool doReceive)
12521263
}
12531264
IF_LOG_COMMANDS() {
12541265
std::ostringstream logStream;
1255-
logStream << "Remaining data size: " << mOut.dataSize() << "\n";
1256-
logStream << "Received commands from driver: ";
1257-
const void* cmds = mIn.data();
1258-
const void* end = mIn.data() + mIn.dataSize();
1259-
logStream << "\t" << HexDump(cmds, mIn.dataSize()) << "\n";
1260-
while (cmds < end) cmds = printReturnCommand(logStream, cmds);
1261-
std::string message = logStream.str();
1262-
ALOGI("%s", message.c_str());
1266+
printReturnCommandParcel(logStream, mIn);
1267+
ALOGI("%s", logStream.str().c_str());
12631268
}
12641269
return NO_ERROR;
12651270
}

0 commit comments

Comments
 (0)