Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * jdwpspy common stuff. |
| 5 | */ |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 6 | #ifndef ART_JDWPSPY_COMMON_H_ |
| 7 | #define ART_JDWPSPY_COMMON_H_ |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 8 | |
Elliott Hughes | 6d8dd47 | 2012-01-17 18:27:41 -0800 | [diff] [blame] | 9 | #include <stdint.h> |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 10 | #include <stdio.h> |
| 11 | #include <sys/types.h> |
| 12 | |
Elliott Hughes | 6d8dd47 | 2012-01-17 18:27:41 -0800 | [diff] [blame] | 13 | typedef uint8_t u1; |
| 14 | typedef uint16_t u2; |
| 15 | typedef uint32_t u4; |
| 16 | typedef uint64_t u8; |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 17 | |
| 18 | #define NELEM(x) (sizeof(x) / sizeof((x)[0])) |
| 19 | |
| 20 | #ifndef _JDWP_MISC_INLINE |
| 21 | # define INLINE extern inline |
| 22 | #else |
| 23 | # define INLINE |
| 24 | #endif |
| 25 | |
| 26 | /* |
| 27 | * Get 1 byte. (Included to make the code more legible.) |
| 28 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 29 | INLINE u1 get1(unsigned const char* pSrc) { |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 30 | return *pSrc; |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Get 2 big-endian bytes. |
| 35 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 36 | INLINE u2 get2BE(unsigned char const* pSrc) { |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 37 | u2 result; |
| 38 | |
| 39 | result = *pSrc++ << 8; |
| 40 | result |= *pSrc++; |
| 41 | |
| 42 | return result; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * Get 4 big-endian bytes. |
| 47 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 48 | INLINE u4 get4BE(unsigned char const* pSrc) { |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 49 | u4 result; |
| 50 | |
| 51 | result = *pSrc++ << 24; |
| 52 | result |= *pSrc++ << 16; |
| 53 | result |= *pSrc++ << 8; |
| 54 | result |= *pSrc++; |
| 55 | |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Get 8 big-endian bytes. |
| 61 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 62 | INLINE u8 get8BE(unsigned char const* pSrc) { |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 63 | u8 result; |
| 64 | |
| 65 | result = (u8) *pSrc++ << 56; |
| 66 | result |= (u8) *pSrc++ << 48; |
| 67 | result |= (u8) *pSrc++ << 40; |
| 68 | result |= (u8) *pSrc++ << 32; |
| 69 | result |= (u8) *pSrc++ << 24; |
| 70 | result |= (u8) *pSrc++ << 16; |
| 71 | result |= (u8) *pSrc++ << 8; |
| 72 | result |= (u8) *pSrc++; |
| 73 | |
| 74 | return result; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * Start here. |
| 80 | */ |
| 81 | int run(const char* connectHost, int connectPort, int listenPort); |
| 82 | |
| 83 | /* |
| 84 | * Print a hex dump to the specified file pointer. |
| 85 | * |
| 86 | * "local" mode prints a hex dump starting from offset 0 (roughly equivalent |
| 87 | * to "xxd -g1"). |
| 88 | * |
| 89 | * "mem" mode shows the actual memory address, and will offset the start |
| 90 | * so that the low nibble of the address is always zero. |
| 91 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 92 | enum HexDumpMode { kHexDumpLocal, kHexDumpMem }; |
Brian Carlstrom | 34c0631 | 2011-12-05 09:38:27 -0800 | [diff] [blame] | 93 | void printHexDump(const void* vaddr, size_t length); |
| 94 | void printHexDump2(const void* vaddr, size_t length, const char* prefix); |
| 95 | void printHexDumpEx(FILE* fp, const void* vaddr, size_t length, |
| 96 | HexDumpMode mode, const char* prefix); |
| 97 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 98 | #endif // ART_JDWPSPY_COMMON_H_ |