Move jdwpspy into C++ now that jdwp itself is in C++.
git cherry-pick --no-commit 73cfba122a4ae1c6162fe1c5112e77d8c8430dd9
Change-Id: Id0c6188ece19f6eade18ba8725384d94465aa197
diff --git a/tools/jdwpspy/Android.mk b/tools/jdwpspy/Android.mk
index eca3e22..2201aab 100644
--- a/tools/jdwpspy/Android.mk
+++ b/tools/jdwpspy/Android.mk
@@ -4,9 +4,9 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
- Main.c \
- Net.c \
- find_JdwpConstants.c
+ Main.cpp \
+ Net.cpp \
+ find_JdwpConstants.cpp
LOCAL_C_INCLUDES += \
dalvik/vm
diff --git a/tools/jdwpspy/Common.h b/tools/jdwpspy/Common.h
index c42d183..ddaba9c 100644
--- a/tools/jdwpspy/Common.h
+++ b/tools/jdwpspy/Common.h
@@ -14,11 +14,6 @@
typedef unsigned int u4;
typedef unsigned long long u8;
-#ifndef __bool_true_false_are_defined
-typedef enum { false=0, true=!false } bool;
-#define __bool_true_false_are_defined 1
-#endif
-
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
#ifndef _JDWP_MISC_INLINE
diff --git a/tools/jdwpspy/Main.c b/tools/jdwpspy/Main.cpp
similarity index 87%
rename from tools/jdwpspy/Main.c
rename to tools/jdwpspy/Main.cpp
index 62a0007..0f68d52 100644
--- a/tools/jdwpspy/Main.c
+++ b/tools/jdwpspy/Main.cpp
@@ -33,7 +33,7 @@
void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
HexDumpMode mode, const char* prefix)
{
- const unsigned char* addr = vaddr;
+ const unsigned char* addr = reinterpret_cast<const unsigned char*>(vaddr);
char out[77]; /* exact fit */
unsigned int offset; /* offset to show while printing */
char* hex;
@@ -53,19 +53,17 @@
gap = (int) offset & 0x0f;
while (length) {
unsigned int lineOffset = offset & ~0x0f;
- int i, count;
-
- hex = out;
- asc = out + 59;
+ char* hex = out;
+ char* asc = out + 59;
- for (i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++) {
*hex++ = gHexDigit[lineOffset >> 28];
lineOffset <<= 4;
}
hex++;
hex++;
- count = ((int)length > 16-gap) ? 16-gap : (int) length; /* cap length */
+ int count = ((int)length > 16-gap) ? 16-gap : (int) length; /* cap length */
assert(count != 0);
assert(count+gap <= 16);
@@ -75,6 +73,7 @@
asc += gap;
}
+ int i;
for (i = gap ; i < count+gap; i++) {
*hex++ = gHexDigit[*addr >> 4];
*hex++ = gHexDigit[*addr & 0x0f];
@@ -118,9 +117,6 @@
*/
int main(int argc, char* argv[])
{
- int connectPort, listenPort;
- int cc;
-
if (argc < 2 || argc > 3) {
usage("jdwpspy");
return 2;
@@ -129,15 +125,15 @@
setvbuf(stdout, NULL, _IONBF, 0);
/* may want this to be host:port */
- connectPort = atoi(argv[1]);
+ int connectPort = atoi(argv[1]);
+ int listenPort;
if (argc > 2)
listenPort = atoi(argv[2]);
else
listenPort = connectPort + 1;
- cc = run("localhost", connectPort, listenPort);
+ int cc = run("localhost", connectPort, listenPort);
return (cc != 0);
}
-
diff --git a/tools/jdwpspy/Net.c b/tools/jdwpspy/Net.cpp
similarity index 97%
rename from tools/jdwpspy/Net.c
rename to tools/jdwpspy/Net.cpp
index 555fe49..b923006 100644
--- a/tools/jdwpspy/Net.c
+++ b/tools/jdwpspy/Net.cpp
@@ -7,9 +7,9 @@
#include "jdwp/JdwpConstants.h"
#include <stdlib.h>
-#include <unistd.h>
+#include <unistd.h>
#include <stdio.h>
-#include <string.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -205,9 +205,7 @@
*/
static const char* getCommandName(int cmdSet, int cmd)
{
- int i;
-
- for (i = 0; i < (int) NELEM(gHandlerMap); i++) {
+ for (int i = 0; i < (int) NELEM(gHandlerMap); i++) {
if (gHandlerMap[i].cmdSet == cmdSet &&
gHandlerMap[i].cmd == cmd)
{
@@ -229,10 +227,7 @@
NetState* jdwpNetStartup(unsigned short listenPort, const char* connectHost,
unsigned short connectPort)
{
- NetState* netState;
- int one = 1;
-
- netState = (NetState*) malloc(sizeof(*netState));
+ NetState* netState = (NetState*) malloc(sizeof(*netState));
memset(netState, 0, sizeof(*netState));
netState->listenSock = -1;
netState->dbg.sock = netState->vm.sock = -1;
@@ -251,12 +246,15 @@
}
/* allow immediate re-use if we die */
- if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one,
- sizeof(one)) < 0)
{
- fprintf(stderr, "setsockopt(SO_REUSEADDR) failed: %s\n",
- strerror(errno));
- goto fail;
+ int one = 1;
+ if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one,
+ sizeof(one)) < 0)
+ {
+ fprintf(stderr, "setsockopt(SO_REUSEADDR) failed: %s\n",
+ strerror(errno));
+ goto fail;
+ }
}
struct sockaddr_in addr;
@@ -474,7 +472,7 @@
char prefix[3];
u4 length, id;
u1 flags, cmdSet=0, cmd=0;
- u2 error=0;
+ JdwpError error = ERR_NONE;
bool reply;
int dataLen;
@@ -483,7 +481,7 @@
flags = get1(buf+8);
if ((flags & kJDWPFlagReply) != 0) {
reply = true;
- error = get2BE(buf+9);
+ error = static_cast<JdwpError>(get2BE(buf+9));
} else {
reply = false;
cmdSet = get1(buf+9);
@@ -748,4 +746,3 @@
return 0;
}
-
diff --git a/tools/jdwpspy/find_JdwpConstants.c b/tools/jdwpspy/find_JdwpConstants.c
deleted file mode 100644
index 8ff8186..0000000
--- a/tools/jdwpspy/find_JdwpConstants.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "jdwp/JdwpConstants.c"
diff --git a/tools/jdwpspy/find_JdwpConstants.cpp b/tools/jdwpspy/find_JdwpConstants.cpp
new file mode 100644
index 0000000..57b7dbb
--- /dev/null
+++ b/tools/jdwpspy/find_JdwpConstants.cpp
@@ -0,0 +1 @@
+#include "jdwp/JdwpConstants.cpp"