• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * jdwpspy common stuff.
5  */
6 #ifndef ART_JDWPSPY_COMMON_H_
7 #define ART_JDWPSPY_COMMON_H_
8 
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <sys/types.h>
12 
13 typedef uint8_t u1;
14 typedef uint16_t u2;
15 typedef uint32_t u4;
16 typedef uint64_t u8;
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  */
get1(unsigned const char * pSrc)29 INLINE u1 get1(unsigned const char* pSrc) {
30     return *pSrc;
31 }
32 
33 /*
34  * Get 2 big-endian bytes.
35  */
get2BE(unsigned char const * pSrc)36 INLINE u2 get2BE(unsigned char const* pSrc) {
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  */
get4BE(unsigned char const * pSrc)48 INLINE u4 get4BE(unsigned char const* pSrc) {
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  */
get8BE(unsigned char const * pSrc)62 INLINE u8 get8BE(unsigned char const* pSrc) {
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  */
92 enum HexDumpMode { kHexDumpLocal, kHexDumpMem };
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 
98 #endif  // ART_JDWPSPY_COMMON_H_
99