blob: 30a49fba76e75048a64be73744a5eb2234d3f1b3 [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 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -07006#ifndef ART_JDWPSPY_COMMON_H_
7#define ART_JDWPSPY_COMMON_H_
Brian Carlstrom34c06312011-12-05 09:38:27 -08008
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 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070029INLINE u1 get1(unsigned const char* pSrc) {
Brian Carlstrom34c06312011-12-05 09:38:27 -080030 return *pSrc;
31}
32
33/*
34 * Get 2 big-endian bytes.
35 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070036INLINE u2 get2BE(unsigned char const* pSrc) {
Brian Carlstrom34c06312011-12-05 09:38:27 -080037 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 Carlstrom2ce745c2013-07-17 17:44:30 -070048INLINE u4 get4BE(unsigned char const* pSrc) {
Brian Carlstrom34c06312011-12-05 09:38:27 -080049 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 Carlstrom2ce745c2013-07-17 17:44:30 -070062INLINE u8 get8BE(unsigned char const* pSrc) {
Brian Carlstrom34c06312011-12-05 09:38:27 -080063 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 */
81int 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 Hughes719ace42012-03-09 18:06:03 -080092enum HexDumpMode { kHexDumpLocal, kHexDumpMem };
Brian Carlstrom34c06312011-12-05 09:38:27 -080093void printHexDump(const void* vaddr, size_t length);
94void printHexDump2(const void* vaddr, size_t length, const char* prefix);
95void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
96 HexDumpMode mode, const char* prefix);
97
Brian Carlstromfc0e3212013-07-17 14:40:12 -070098#endif // ART_JDWPSPY_COMMON_H_