2 * Copyright 2006 The Android Open Source Project
6 #define _JDWP_MISC_INLINE
15 static const char gHexDigit[] = "0123456789abcdef";
18 * Print a hex dump. Just hands control off to the fancy version.
20 void printHexDump(const void* vaddr, size_t length)
22 printHexDumpEx(stdout, vaddr, length, kHexDumpLocal, "");
24 void printHexDump2(const void* vaddr, size_t length, const char* prefix)
26 printHexDumpEx(stdout, vaddr, length, kHexDumpLocal, prefix);
30 * Print a hex dump in this format:
32 01234567: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef\n
34 void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
35 HexDumpMode mode, const char* prefix)
37 const unsigned char* addr = reinterpret_cast<const unsigned char*>(vaddr);
38 char out[77]; /* exact fit */
39 uintptr_t offset; /* offset to show while printing */
44 if (mode == kHexDumpLocal)
47 offset = (uintptr_t) addr;
49 memset(out, ' ', sizeof(out)-1);
51 out[sizeof(out)-2] = '\n';
52 out[sizeof(out)-1] = '\0';
54 gap = (int) offset & 0x0f;
56 unsigned int lineOffset = offset & ~0x0f;
60 for (int i = 0; i < 8; i++) {
61 *hex++ = gHexDigit[lineOffset >> 28];
67 int count = ((int)length > 16-gap) ? 16-gap : (int) length; /* cap length */
69 assert(count+gap <= 16);
72 /* only on first line */
78 for (i = gap ; i < count+gap; i++) {
79 *hex++ = gHexDigit[*addr >> 4];
80 *hex++ = gHexDigit[*addr & 0x0f];
88 for ( ; i < 16; i++) {
89 /* erase extra stuff; only happens on last line */
96 fprintf(fp, "%s%s", prefix, out);
108 static void usage(const char* progName)
110 fprintf(stderr, "Usage: %s VM-port [debugger-listen-port]\n\n", progName);
112 "When a debugger connects to the debugger-listen-port, jdwpspy will connect\n");
113 fprintf(stderr, "to the VM on the VM-port.\n");
119 int main(int argc, char* argv[])
121 if (argc < 2 || argc > 3) {
126 setvbuf(stdout, NULL, _IONBF, 0);
128 /* may want this to be host:port */
129 int connectPort = atoi(argv[1]);
133 listenPort = atoi(argv[2]);
135 listenPort = connectPort + 1;
137 int cc = run("localhost", connectPort, listenPort);