blob: 30a49fba76e75048a64be73744a5eb2234d3f1b3 [file] [log] [blame]
/*
* Copyright 2006 The Android Open Source Project
*
* jdwpspy common stuff.
*/
#ifndef ART_JDWPSPY_COMMON_H_
#define ART_JDWPSPY_COMMON_H_
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
typedef uint8_t u1;
typedef uint16_t u2;
typedef uint32_t u4;
typedef uint64_t u8;
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
#ifndef _JDWP_MISC_INLINE
# define INLINE extern inline
#else
# define INLINE
#endif
/*
* Get 1 byte. (Included to make the code more legible.)
*/
INLINE u1 get1(unsigned const char* pSrc) {
return *pSrc;
}
/*
* Get 2 big-endian bytes.
*/
INLINE u2 get2BE(unsigned char const* pSrc) {
u2 result;
result = *pSrc++ << 8;
result |= *pSrc++;
return result;
}
/*
* Get 4 big-endian bytes.
*/
INLINE u4 get4BE(unsigned char const* pSrc) {
u4 result;
result = *pSrc++ << 24;
result |= *pSrc++ << 16;
result |= *pSrc++ << 8;
result |= *pSrc++;
return result;
}
/*
* Get 8 big-endian bytes.
*/
INLINE u8 get8BE(unsigned char const* pSrc) {
u8 result;
result = (u8) *pSrc++ << 56;
result |= (u8) *pSrc++ << 48;
result |= (u8) *pSrc++ << 40;
result |= (u8) *pSrc++ << 32;
result |= (u8) *pSrc++ << 24;
result |= (u8) *pSrc++ << 16;
result |= (u8) *pSrc++ << 8;
result |= (u8) *pSrc++;
return result;
}
/*
* Start here.
*/
int run(const char* connectHost, int connectPort, int listenPort);
/*
* Print a hex dump to the specified file pointer.
*
* "local" mode prints a hex dump starting from offset 0 (roughly equivalent
* to "xxd -g1").
*
* "mem" mode shows the actual memory address, and will offset the start
* so that the low nibble of the address is always zero.
*/
enum HexDumpMode { kHexDumpLocal, kHexDumpMem };
void printHexDump(const void* vaddr, size_t length);
void printHexDump2(const void* vaddr, size_t length, const char* prefix);
void printHexDumpEx(FILE* fp, const void* vaddr, size_t length,
HexDumpMode mode, const char* prefix);
#endif // ART_JDWPSPY_COMMON_H_