Fix some DDMS stuff I'd broken, and fix HexDump's double-spacing.
Change-Id: I6583458a818406197744cc640b0993f73cfd5384
diff --git a/src/debugger.cc b/src/debugger.cc
index 51e43c1..6d3f80c 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -851,11 +851,11 @@
size_t char_count = (name.get() != NULL) ? name->GetLength() : 0;
const jchar* chars = name->GetCharArray()->GetData();
- size_t byte_count = char_count*2 + sizeof(uint32_t)*2;
- std::vector<uint8_t> bytes(byte_count);
+ std::vector<uint8_t> bytes;
JDWP::Append4BE(bytes, t->GetThinLockId());
JDWP::AppendUtf16BE(bytes, chars, char_count);
- Dbg::DdmSendChunk(type, bytes.size(), &bytes[0]);
+ CHECK_EQ(bytes.size(), char_count*2 + sizeof(uint32_t)*2);
+ Dbg::DdmSendChunk(type, bytes);
}
}
@@ -899,6 +899,10 @@
Dbg::DdmSendChunkV(type, vec, 1);
}
+void Dbg::DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes) {
+ DdmSendChunk(type, bytes.size(), &bytes[0]);
+}
+
void Dbg::DdmSendChunkV(uint32_t type, const struct iovec* iov, int iovcnt) {
if (gJdwpState == NULL) {
LOG(VERBOSE) << "Debugger thread not active, ignoring DDM send: " << type;
@@ -969,7 +973,7 @@
* [u4]: current number of objects allocated
*/
uint8_t heap_count = 1;
- std::vector<uint8_t> bytes(4 + (heap_count * (4 + 8 + 1 + 4 + 4 + 4 + 4)));
+ std::vector<uint8_t> bytes;
JDWP::Append4BE(bytes, heap_count);
JDWP::Append4BE(bytes, 1); // Heap id (bogus; we only have one heap).
JDWP::Append8BE(bytes, MilliTime());
@@ -978,7 +982,8 @@
JDWP::Append4BE(bytes, Heap::GetTotalMemory()); // Current heap size in bytes.
JDWP::Append4BE(bytes, Heap::GetBytesAllocated());
JDWP::Append4BE(bytes, Heap::GetObjectsAllocated());
- Dbg::DdmSendChunk(CHUNK_TYPE("HPIF"), bytes.size(), &bytes[0]);
+ CHECK_EQ(bytes.size(), 4U + (heap_count * (4 + 8 + 1 + 4 + 4 + 4 + 4)));
+ Dbg::DdmSendChunk(CHUNK_TYPE("HPIF"), bytes);
}
enum HpsgSolidity {
diff --git a/src/debugger.h b/src/debugger.h
index 0aa2c83..35ef619 100644
--- a/src/debugger.h
+++ b/src/debugger.h
@@ -238,6 +238,7 @@
static bool DdmHandlePacket(const uint8_t* buf, int dataLen, uint8_t** pReplyBuf, int* pReplyLen);
static void DdmConnected();
static void DdmDisconnected();
+ static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes);
static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf);
static void DdmSendChunkV(uint32_t type, const struct iovec* iov, int iovcnt);
diff --git a/src/jdwp/jdwp_bits.h b/src/jdwp/jdwp_bits.h
index 5e5b120..faa3960 100644
--- a/src/jdwp/jdwp_bits.h
+++ b/src/jdwp/jdwp_bits.h
@@ -159,13 +159,6 @@
*dst += sizeof(value);
}
-// @deprecated
-static inline void SetUtf8String(uint8_t* buf, const uint8_t* str) {
- uint32_t strLen = strlen((const char*)str);
- Set4BE(buf, strLen);
- memcpy(buf + sizeof(uint32_t), str, strLen);
-}
-
} // namespace JDWP
} // namespace art
diff --git a/src/jdwp/jdwp_expand_buf.cc b/src/jdwp/jdwp_expand_buf.cc
index 71931e1..f5e24b2 100644
--- a/src/jdwp/jdwp_expand_buf.cc
+++ b/src/jdwp/jdwp_expand_buf.cc
@@ -153,6 +153,12 @@
pBuf->curLen += sizeof(val);
}
+static void SetUtf8String(uint8_t* buf, const uint8_t* str) {
+ uint32_t strLen = strlen((const char*)str);
+ Set4BE(buf, strLen);
+ memcpy(buf + sizeof(uint32_t), str, strLen);
+}
+
/*
* Add a UTF8 string as a 4-byte length followed by a non-NULL-terminated
* string.
diff --git a/src/logging.cc b/src/logging.cc
index bb68442..34e5e8d 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -66,14 +66,14 @@
/*
* Print a hex dump in this format:
*
- * 01234567: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef\n
+ * 01234567: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef
*
* Does not use printf() or other string-formatting calls.
*/
void HexDump(const void* address, size_t byte_count, bool show_actual_address) {
static const char gHexDigit[] = "0123456789abcdef";
const unsigned char* addr = reinterpret_cast<const unsigned char*>(address);
- char out[77]; /* exact fit */
+ char out[76]; /* exact fit */
unsigned int offset; /* offset to show while printing */
if (show_actual_address) {
@@ -83,7 +83,6 @@
}
memset(out, ' ', sizeof(out)-1);
out[8] = ':';
- out[sizeof(out)-2] = '\n';
out[sizeof(out)-1] = '\0';
int gap = (int) offset & 0x0f;
diff --git a/src/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/src/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index 5ea3729..4d20a85 100644
--- a/src/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/src/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -81,9 +81,6 @@
static const int kThstHeaderLen = 4;
static void ThreadStatsGetterCallback(Thread* t, void* context) {
- uint8_t** ptr = reinterpret_cast<uint8_t**>(context);
- uint8_t* buf = *ptr;
-
/*
* Generate the contents of a THST chunk. The data encompasses all known
* threads.
@@ -93,7 +90,7 @@
* (1b) bytes per entry
* (2b) thread count
* Then, for each thread:
- * (4b) threadId
+ * (4b) thread id
* (1b) thread status
* (4b) tid
* (4b) utime
@@ -108,14 +105,13 @@
int utime, stime, task_cpu;
GetTaskStats(t->GetTid(), utime, stime, task_cpu);
- JDWP::Set4BE(buf+0, t->GetThinLockId());
- JDWP::Set1(buf+4, t->GetState());
- JDWP::Set4BE(buf+5, t->GetTid());
- JDWP::Set4BE(buf+9, utime);
- JDWP::Set4BE(buf+13, stime);
- JDWP::Set1(buf+17, t->IsDaemon());
-
- *ptr += kThstBytesPerEntry;
+ std::vector<uint8_t>& bytes = *reinterpret_cast<std::vector<uint8_t>*>(context);
+ JDWP::Append4BE(bytes, t->GetThinLockId());
+ JDWP::Append1BE(bytes, t->GetState());
+ JDWP::Append4BE(bytes, t->GetTid());
+ JDWP::Append4BE(bytes, utime);
+ JDWP::Append4BE(bytes, stime);
+ JDWP::Append1BE(bytes, t->IsDaemon());
}
static jbyteArray DdmVmInternal_getThreadStats(JNIEnv* env, jclass) {
@@ -124,17 +120,14 @@
ScopedThreadListLock thread_list_lock;
ThreadList* thread_list = Runtime::Current()->GetThreadList();
- uint16_t thread_count;
+ uint16_t thread_count = 0;
thread_list->ForEach(ThreadCountCallback, &thread_count);
- bytes.resize(kThstHeaderLen + thread_count * kThstBytesPerEntry);
+ JDWP::Append1BE(bytes, kThstHeaderLen);
+ JDWP::Append1BE(bytes, kThstBytesPerEntry);
+ JDWP::Append2BE(bytes, thread_count);
- JDWP::Set1(&bytes[0], kThstHeaderLen);
- JDWP::Set1(&bytes[1], kThstBytesPerEntry);
- JDWP::Set2BE(&bytes[2], thread_count);
-
- uint8_t* ptr = &bytes[kThstHeaderLen];
- thread_list->ForEach(ThreadStatsGetterCallback, &ptr);
+ thread_list->ForEach(ThreadStatsGetterCallback, &bytes);
}
jbyteArray result = env->NewByteArray(bytes.size());