Fix a bunch more lint.
(If you ignore the compilers, we've got relatively little lint now. Fits on
a single screen.)
Change-Id: I51389002894d4fd8cf46f79d2bac57079322a030
diff --git a/src/jdwp/jdwp.h b/src/jdwp/jdwp.h
index 7940566..8534c8e 100644
--- a/src/jdwp/jdwp.h
+++ b/src/jdwp/jdwp.h
@@ -214,6 +214,9 @@
*/
bool PostVMDeath();
+ // Called if/when we realize we're talking to DDMS.
+ void NotifyDdmsActive();
+
/*
* Send up a chunk of DDM data.
*/
@@ -276,59 +279,50 @@
public: // TODO: fix privacy
const JdwpOptions* options_;
- private:
+ private:
/* wait for creation of the JDWP thread */
Mutex thread_start_lock_;
ConditionVariable thread_start_cond_;
- volatile int32_t debug_thread_started_;
pthread_t pthread_;
Thread* thread_;
- public: // TODO: fix privacy
- ObjectId debugThreadId;
+
+ volatile int32_t debug_thread_started_;
+ ObjectId debug_thread_id_;
+
private:
bool run;
+ const JdwpTransport* transport_;
- const JdwpTransport* transport;
public: // TODO: fix privacy
JdwpNetState* netState;
- private:
- /* for wait-for-debugger */
+ private:
+ // For wait-for-debugger.
Mutex attach_lock_;
ConditionVariable attach_cond_;
- /* time of last debugger activity, in milliseconds */
- int64_t lastActivityWhen;
+ // Time of last debugger activity, in milliseconds.
+ int64_t last_activity_time_ms_;
- /* global counters and a mutex to protect them */
+ // Global counters and a mutex to protect them.
Mutex serial_lock_;
uint32_t request_serial_ GUARDED_BY(serial_lock_);
uint32_t event_serial_ GUARDED_BY(serial_lock_);
- /*
- * Events requested by the debugger (breakpoints, class prep, etc).
- */
- public: // TODO: fix privacy
+ // Linked list of events requested by the debugger (breakpoints, class prep, etc).
Mutex event_list_lock_;
- JdwpEvent* event_list_ GUARDED_BY(event_list_lock_); // Linked list of events.
+ JdwpEvent* event_list_ GUARDED_BY(event_list_lock_);
int event_list_size_ GUARDED_BY(event_list_lock_); // Number of elements in event_list_.
- private:
- /*
- * Synchronize suspension of event thread (to avoid receiving "resume"
- * events before the thread has finished suspending itself).
- */
+ // Used to synchronize suspension of the event thread (to avoid receiving "resume"
+ // events before the thread has finished suspending itself).
Mutex event_thread_lock_;
ConditionVariable event_thread_cond_;
- ObjectId eventThreadId;
+ ObjectId event_thread_id_;
- /*
- * DDM support.
- */
- public: // TODO: fix privacy
- bool ddmActive;
+ bool ddm_is_active_;
};
} // namespace JDWP
diff --git a/src/jdwp/jdwp_adb.cc b/src/jdwp/jdwp_adb.cc
index 4577b59..6bc7820 100644
--- a/src/jdwp/jdwp_adb.cc
+++ b/src/jdwp/jdwp_adb.cc
@@ -190,7 +190,7 @@
/* first, ensure that we get a connection to the ADB daemon */
-retry:
+ retry:
if (netState->shuttingDown) {
return false;
}
@@ -240,10 +240,7 @@
#endif
/* now try to send our pid to the ADB daemon */
- do {
- ret = send( netState->controlSock, buff, 4, 0 );
- } while (ret < 0 && errno == EINTR);
-
+ ret = TEMP_FAILURE_RETRY(send(netState->controlSock, buff, 4, 0));
if (ret >= 0) {
VLOG(jdwp) << StringPrintf("PID sent as '%.*s' to ADB", 4, buff);
break;
@@ -256,7 +253,7 @@
PLOG(ERROR) << "Can't connect to ADB control socket";
}
- usleep( sleep_ms*1000 );
+ usleep(sleep_ms * 1000);
sleep_ms += (sleep_ms >> 1);
if (sleep_ms > sleep_max_ms) {
@@ -291,7 +288,7 @@
/*
* Connect out to a debugger (for server=n). Not required.
*/
-static bool establishConnection(JdwpState*) {
+static bool establishConnection(JdwpState*, const JdwpOptions*) {
return false;
}
@@ -627,7 +624,7 @@
*/
return handlePacket(state);
-fail:
+ fail:
closeConnection(state);
return false;
}
diff --git a/src/jdwp/jdwp_event.cc b/src/jdwp/jdwp_event.cc
index f398066..841ee8c 100644
--- a/src/jdwp/jdwp_event.cc
+++ b/src/jdwp/jdwp_event.cc
@@ -503,7 +503,7 @@
}
/* this is rare but possible -- see CLASS_PREPARE handling */
- if (Dbg::GetThreadSelfId() == debugThreadId) {
+ if (Dbg::GetThreadSelfId() == debug_thread_id_) {
LOG(INFO) << "NOTE: SuspendByPolicy not suspending JDWP thread";
return;
}
@@ -572,8 +572,8 @@
* If another thread is already doing stuff, wait for it. This can
* go to sleep indefinitely.
*/
- while (eventThreadId != 0) {
- VLOG(jdwp) << StringPrintf("event in progress (%#llx), %#llx sleeping", eventThreadId, threadId);
+ while (event_thread_id_ != 0) {
+ VLOG(jdwp) << StringPrintf("event in progress (%#llx), %#llx sleeping", event_thread_id_, threadId);
waited = true;
event_thread_cond_.Wait(event_thread_lock_);
}
@@ -582,7 +582,7 @@
VLOG(jdwp) << StringPrintf("event token grabbed (%#llx)", threadId);
}
if (threadId != 0) {
- eventThreadId = threadId;
+ event_thread_id_ = threadId;
}
}
@@ -597,10 +597,10 @@
*/
MutexLock mu(event_thread_lock_);
- CHECK_NE(eventThreadId, 0U);
- VLOG(jdwp) << StringPrintf("cleared event token (%#llx)", eventThreadId);
+ CHECK_NE(event_thread_id_, 0U);
+ VLOG(jdwp) << StringPrintf("cleared event token (%#llx)", event_thread_id_);
- eventThreadId = 0;
+ event_thread_id_ = 0;
event_thread_cond_.Signal();
}
@@ -722,7 +722,7 @@
* while doing so. (I don't think we currently do this at all, so
* this is mostly paranoia.)
*/
- if (basket.threadId == debugThreadId) {
+ if (basket.threadId == debug_thread_id_) {
VLOG(jdwp) << "Ignoring location event in JDWP thread";
return false;
}
@@ -1018,7 +1018,7 @@
suspend_policy = scanSuspendPolicy(match_list, match_count);
VLOG(jdwp) << " suspend_policy=" << suspend_policy;
- if (basket.threadId == debugThreadId) {
+ if (basket.threadId == debug_thread_id_) {
/*
* JDWP says that, for a class prep in the debugger thread, we
* should set threadId to null and if any threads were supposed
@@ -1106,7 +1106,7 @@
* Make sure we're in VMWAIT in case the write blocks.
*/
int old_state = Dbg::ThreadWaiting();
- (*transport->sendBufferedRequest)(this, wrapiov, iov_count + 1);
+ (*transport_->sendBufferedRequest)(this, wrapiov, iov_count + 1);
Dbg::ThreadContinuing(old_state);
}
diff --git a/src/jdwp/jdwp_expand_buf.cc b/src/jdwp/jdwp_expand_buf.cc
index 307167e..523c9d7 100644
--- a/src/jdwp/jdwp_expand_buf.cc
+++ b/src/jdwp/jdwp_expand_buf.cc
@@ -44,13 +44,10 @@
* Allocate a JdwpBuf and some initial storage.
*/
ExpandBuf* expandBufAlloc() {
- ExpandBuf* newBuf;
-
- newBuf = (ExpandBuf*) malloc(sizeof(*newBuf));
- newBuf->storage = (uint8_t*) malloc(kInitialStorage);
+ ExpandBuf* newBuf = new ExpandBuf;
+ newBuf->storage = reinterpret_cast<uint8_t*>(malloc(kInitialStorage));
newBuf->curLen = 0;
newBuf->maxLen = kInitialStorage;
-
return newBuf;
}
@@ -63,7 +60,7 @@
}
free(pBuf->storage);
- free(pBuf);
+ delete pBuf;
}
/*
@@ -80,7 +77,6 @@
return pBuf->curLen;
}
-
/*
* Ensure that the buffer has enough space to hold incoming data. If it
* doesn't, resize the buffer.
@@ -94,7 +90,7 @@
pBuf->maxLen *= 2;
}
- uint8_t* newPtr = (uint8_t*) realloc(pBuf->storage, pBuf->maxLen);
+ uint8_t* newPtr = reinterpret_cast<uint8_t*>(realloc(pBuf->storage, pBuf->maxLen));
if (newPtr == NULL) {
LOG(FATAL) << "realloc(" << pBuf->maxLen << ") failed";
}
diff --git a/src/jdwp/jdwp_handler.cc b/src/jdwp/jdwp_handler.cc
index f873da2..95d4c09 100644
--- a/src/jdwp/jdwp_handler.cc
+++ b/src/jdwp/jdwp_handler.cc
@@ -1425,13 +1425,7 @@
VLOG(jdwp) << StringPrintf(" Handling DDM packet (%.4s)", buf);
- /*
- * On first DDM packet, notify all handlers that DDM is running.
- */
- if (!state->ddmActive) {
- state->ddmActive = true;
- Dbg::DdmConnected();
- }
+ state->NotifyDdmsActive();
/*
* If they want to send something back, we copy it into the buffer.
@@ -1628,7 +1622,7 @@
* so waitForDebugger() doesn't return if we stall for a bit here.
*/
Dbg::GoActive();
- QuasiAtomic::Swap64(0, &lastActivityWhen);
+ QuasiAtomic::Swap64(0, &last_activity_time_ms_);
}
/*
@@ -1697,7 +1691,7 @@
* the initial setup. Only update if this is a non-DDMS packet.
*/
if (pHeader->cmdSet != kJDWPDdmCmdSet) {
- QuasiAtomic::Swap64(MilliTime(), &lastActivityWhen);
+ QuasiAtomic::Swap64(MilliTime(), &last_activity_time_ms_);
}
/* tell the VM that GC is okay again */
diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc
index 20b770f..3a4d398 100644
--- a/src/jdwp/jdwp_main.cc
+++ b/src/jdwp/jdwp_main.cc
@@ -59,11 +59,11 @@
}
bool JdwpState::IsConnected() {
- return (*transport->isConnected)(this);
+ return (*transport_->isConnected)(this);
}
bool JdwpState::SendRequest(ExpandBuf* pReq) {
- return (*transport->sendRequest)(this, pReq);
+ return (*transport_->sendRequest)(this, pReq);
}
/*
@@ -89,13 +89,13 @@
thread_start_lock_("JDWP thread start lock"),
thread_start_cond_("JDWP thread start condition variable"),
debug_thread_started_(false),
- debugThreadId(0),
+ debug_thread_id_(0),
run(false),
- transport(NULL),
+ transport_(NULL),
netState(NULL),
attach_lock_("JDWP attach lock"),
attach_cond_("JDWP attach condition variable"),
- lastActivityWhen(0),
+ last_activity_time_ms_(0),
serial_lock_("JDWP serial lock"),
request_serial_(0x10000000),
event_serial_(0x20000000),
@@ -104,8 +104,8 @@
event_list_size_(0),
event_thread_lock_("JDWP event thread lock"),
event_thread_cond_("JDWP event thread condition variable"),
- eventThreadId(0),
- ddmActive(false) {
+ event_thread_id_(0),
+ ddm_is_active_(false) {
}
/*
@@ -119,19 +119,19 @@
switch (options->transport) {
case kJdwpTransportSocket:
// LOGD("prepping for JDWP over TCP");
- state->transport = SocketTransport();
+ state->transport_ = SocketTransport();
break;
#ifdef HAVE_ANDROID_OS
case kJdwpTransportAndroidAdb:
// LOGD("prepping for JDWP over ADB");
- state->transport = AndroidAdbTransport();
+ state->transport_ = AndroidAdbTransport();
break;
#endif
default:
LOG(FATAL) << "Unknown transport: " << options->transport;
}
- if (!(*state->transport->startup)(state.get(), options)) {
+ if (!(*state->transport_->startup)(state.get(), options)) {
return NULL;
}
@@ -211,7 +211,7 @@
* Should not have one of these in progress. If the debugger went away
* mid-request, though, we could see this.
*/
- if (eventThreadId != 0) {
+ if (event_thread_id_ != 0) {
LOG(WARNING) << "Resetting state while event in progress";
DCHECK(false);
}
@@ -221,7 +221,7 @@
* Tell the JDWP thread to shut down. Frees "state".
*/
JdwpState::~JdwpState() {
- if (transport != NULL) {
+ if (transport_ != NULL) {
if (IsConnected()) {
PostVMDeath();
}
@@ -230,7 +230,7 @@
* Close down the network to inspire the thread to halt.
*/
VLOG(jdwp) << "JDWP shutting down net...";
- (*transport->shutdown)(this);
+ (*transport_->shutdown)(this);
if (debug_thread_started_) {
run = false;
@@ -241,7 +241,7 @@
}
VLOG(jdwp) << "JDWP freeing netstate...";
- (*transport->free)(this);
+ (*transport_->free)(this);
netState = NULL;
}
CHECK(netState == NULL);
@@ -303,7 +303,7 @@
* Block forever, waiting for a connection. To support the
* "timeout=xxx" option we'll need to tweak this.
*/
- if (!(*transport->accept)(this)) {
+ if (!(*transport_->accept)(this)) {
break;
}
} else {
@@ -313,7 +313,7 @@
* have a timeout if the handshake reply isn't received in a
* reasonable amount of time.
*/
- if (!(*transport->establish)(this)) {
+ if (!(*transport_->establish)(this, options_)) {
/* wake anybody who was waiting for us to succeed */
MutexLock mu(attach_lock_);
attach_cond_.Broadcast();
@@ -333,17 +333,17 @@
Dbg::ThreadWaiting();
}
- if (!(*transport->processIncoming)(this)) {
+ if (!(*transport_->processIncoming)(this)) {
/* blocking read */
break;
}
- if (first && !(*transport->awaitingHandshake)(this)) {
+ if (first && !(*transport_->awaitingHandshake)(this)) {
/* handshake worked, tell the interpreter that we're active */
first = false;
/* set thread ID; requires object registry to be active */
- debugThreadId = Dbg::GetThreadSelfId();
+ debug_thread_id_ = Dbg::GetThreadSelfId();
/* wake anybody who's waiting for us */
MutexLock mu(attach_lock_);
@@ -351,10 +351,10 @@
}
}
- (*transport->close)(this);
+ (*transport_->close)(this);
- if (ddmActive) {
- ddmActive = false;
+ if (ddm_is_active_) {
+ ddm_is_active_ = false;
/* broadcast the disconnect; must be in RUNNING state */
Dbg::ThreadRunning();
@@ -384,6 +384,13 @@
runtime->DetachCurrentThread();
}
+void JdwpState::NotifyDdmsActive() {
+ if (!ddm_is_active_) {
+ ddm_is_active_ = true;
+ Dbg::DdmConnected();
+ }
+}
+
Thread* JdwpState::GetDebugThread() {
return thread_;
}
@@ -420,7 +427,7 @@
return -1;
}
- int64_t last = QuasiAtomic::Read64(&lastActivityWhen);
+ int64_t last = QuasiAtomic::Read64(&last_activity_time_ms_);
/* initializing or in the middle of something? */
if (last == 0) {
diff --git a/src/jdwp/jdwp_priv.h b/src/jdwp/jdwp_priv.h
index 98ae3b9..cead61a 100644
--- a/src/jdwp/jdwp_priv.h
+++ b/src/jdwp/jdwp_priv.h
@@ -55,7 +55,7 @@
struct JdwpTransport {
bool (*startup)(JdwpState* state, const JdwpOptions* options);
bool (*accept)(JdwpState* state);
- bool (*establish)(JdwpState* state);
+ bool (*establish)(JdwpState* state, const JdwpOptions* options);
void (*close)(JdwpState* state);
void (*shutdown)(JdwpState* state);
void (*free)(JdwpState* state);
diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc
index 4424e7b..1cd610b 100644
--- a/src/jdwp/jdwp_socket.cc
+++ b/src/jdwp/jdwp_socket.cc
@@ -177,7 +177,7 @@
return netState;
-fail:
+ fail:
netShutdown(netState);
netFree(netState);
return NULL;
@@ -332,7 +332,7 @@
/*
* Create a connection to a waiting debugger.
*/
-static bool establishConnection(JdwpState* state) {
+static bool establishConnection(JdwpState* state, const JdwpOptions* options) {
union {
sockaddr_in addrInet;
sockaddr addrPlain;
@@ -340,9 +340,9 @@
hostent* pEntry;
CHECK(state != NULL && state->netState != NULL);
- CHECK(!state->options_->server);
- CHECK(!state->options_->host.empty());
- CHECK_NE(state->options_->port, 0);
+ CHECK(!options->server);
+ CHECK(!options->host.empty());
+ CHECK_NE(options->port, 0);
/*
* Start by resolving the host name.
@@ -353,16 +353,16 @@
hostent he;
char auxBuf[128];
int error;
- int cc = gethostbyname_r(state->options_->host.c_str(), &he, auxBuf, sizeof(auxBuf), &pEntry, &error);
+ int cc = gethostbyname_r(options->host.c_str(), &he, auxBuf, sizeof(auxBuf), &pEntry, &error);
if (cc != 0) {
- LOG(WARNING) << "gethostbyname_r('" << state->options_->host << "') failed: " << hstrerror(error);
+ LOG(WARNING) << "gethostbyname_r('" << options->host << "') failed: " << hstrerror(error);
return false;
}
#else
h_errno = 0;
- pEntry = gethostbyname(state->options_->host.c_str());
+ pEntry = gethostbyname(options->host.c_str());
if (pEntry == NULL) {
- PLOG(WARNING) << "gethostbyname('" << state->options_->host << "') failed";
+ PLOG(WARNING) << "gethostbyname('" << options->host << "') failed";
return false;
}
#endif
@@ -371,7 +371,7 @@
memcpy(&addr.addrInet.sin_addr, pEntry->h_addr, pEntry->h_length);
addr.addrInet.sin_family = pEntry->h_addrtype;
- addr.addrInet.sin_port = htons(state->options_->port);
+ addr.addrInet.sin_port = htons(options->port);
LOG(INFO) << "Connecting out to " << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port);
@@ -396,7 +396,7 @@
return false;
}
- LOG(INFO) << "Connection established to " << state->options_->host << " (" << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port) << ")";
+ LOG(INFO) << "Connection established to " << options->host << " (" << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port) << ")";
netState->awaitingHandshake = true;
netState->inputCount = 0;
@@ -686,7 +686,7 @@
*/
return handlePacket(state);
-fail:
+ fail:
closeConnection(state);
return false;
}