blob: f942dee9a88693a1ae91aa91a4e75e25c89b21b3 [file] [log] [blame]
Brian Carlstrom34c06312011-12-05 09:38:27 -08001/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * jdwpspy common stuff.
5 */
6#ifndef _JDWPSPY_COMMON
7#define _JDWPSPY_COMMON
8
Elliott Hughes6d8dd472012-01-17 18:27:41 -08009#include <stdint.h>
Brian Carlstrom34c06312011-12-05 09:38:27 -080010#include <stdio.h>
11#include <sys/types.h>
12
Elliott Hughes6d8dd472012-01-17 18:27:41 -080013typedef uint8_t u1;
14typedef uint16_t u2;
15typedef uint32_t u4;
16typedef uint64_t u8;
Brian Carlstrom34c06312011-12-05 09:38:27 -080017
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 */
29INLINE u1 get1(unsigned const char* pSrc)
30{
31 return *pSrc;
32}
33
34/*
35 * Get 2 big-endian bytes.
36 */
37INLINE u2 get2BE(unsigned char const* pSrc)
38{
39 u2 result;
40
41 result = *pSrc++ << 8;
42 result |= *pSrc++;
43
44 return result;
45}
46
47/*
48 * Get 4 big-endian bytes.
49 */
50INLINE u4 get4BE(unsigned char const* pSrc)
51{
52 u4 result;
53
54 result = *pSrc++ << 24;
55 result |= *pSrc++ << 16;
56 result |= *pSrc++ << 8;
57 result |= *pSrc++;
58
59 return result;
60}
61
62/*
63 * Get 8 big-endian bytes.
64 */
65INLINE u8 get8BE(unsigned char const* pSrc)
66{
67 u8 result;
68
69 result = (u8) *pSrc++ << 56;
70 result |= (u8) *pSrc++ << 48;
71 result |= (u8) *pSrc++ << 40;
72 result |= (u8) *pSrc++ << 32;
73 result |= (u8) *pSrc++ << 24;
74 result |= (u8) *pSrc++ << 16;
75 result |= (u8) *pSrc++ << 8;
76 result |= (u8) *pSrc++;
77
78 return result;
79}
80
81
82/*
83 * Start here.
84 */
85int run(const char* connectHost, int connectPort, int listenPort);
86
87/*
88 * Print a hex dump to the specified file pointer.
89 *
90 * "local" mode prints a hex dump starting from offset 0 (roughly equivalent
91 * to "xxd -g1").
92 *
93 * "mem" mode shows the actual memory address, and will offset the start
94 * so that the low nibble of the address is always zero.
95 */
96typedef enum { kHexDumpLocal, kHexDumpMem } HexDumpMode;
97void printHexDump(const void* vaddr, size_t length);
98void printHexDump2(const void* vaddr, size_t length, const char* prefix);
99void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
100 HexDumpMode mode, const char* prefix);
101
102#endif /*_JDWPSPY_COMMON*/