Commit 9f6d9093 authored by Lubomir Bulej's avatar Lubomir Bulej
Browse files

Share protobuf-c implementation between the two agents

The make files of both agents were unified and the generated
protobuf-c implementation of the protocol has been put to
separate directory.
parent f14ff567
# Protocol buffers definition
This folder contains protocol buffers definitions and generated
code for the C agent and Java server. To regenerate the source
files, e.g., after updating protocol buffers, use the provided
script.
## Requirements
To generate the protocol buffer source code, you need to have
`protoc-c` for the C files, and normal `protoc` for the Java
files. For example, on a Fedora system, you need the
`protobuf-c-compiler` package for the former, and the
`protobuf-compiler` for the latter.
The `protobuf-c` library for C is included in source form and
comes from the [protobuf-c](https://github.com/protobuf-c/protobuf-c)
project.
......@@ -4,22 +4,22 @@
#ifndef PROTOBUF_C_disl_2eproto__INCLUDED
#define PROTOBUF_C_disl_2eproto__INCLUDED
#include "protobuf-c.h"
#include <protobuf-c/protobuf-c.h>
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _InstrumentationDelivery InstrumentationDelivery;
typedef struct _InstrumentationAcceptConfirmation InstrumentationAcceptConfirmation;
typedef struct _InstrClassInfo InstrClassInfo;
typedef struct _InstrumentClassRequest InstrumentClassRequest;
typedef struct _InstrumentClassResponse InstrumentClassResponse;
typedef struct InstrumentationDelivery InstrumentationDelivery;
typedef struct InstrumentationAcceptConfirmation InstrumentationAcceptConfirmation;
typedef struct InstrClassInfo InstrClassInfo;
typedef struct InstrumentClassRequest InstrumentClassRequest;
typedef struct InstrumentClassResponse InstrumentClassResponse;
/* --- enums --- */
......@@ -37,7 +37,7 @@ typedef enum _InstrumentClassResponse__InstrumentClassResult {
* When the client obtains the session_id, next step should be sending
* the instrumentation jar (or more of them) to the instrumentation server.
*/
struct _InstrumentationDelivery
struct InstrumentationDelivery
{
ProtobufCMessage base;
size_t n_sizes;
......@@ -52,7 +52,7 @@ struct _InstrumentationDelivery
/*
* This is server response to InstrumentationDelivery message
*/
struct _InstrumentationAcceptConfirmation
struct InstrumentationAcceptConfirmation
{
ProtobufCMessage base;
protobuf_c_boolean instrumentation_accepted;
......@@ -62,7 +62,7 @@ struct _InstrumentationAcceptConfirmation
, 0 }
struct _InstrClassInfo
struct InstrClassInfo
{
ProtobufCMessage base;
char *classname;
......@@ -76,7 +76,7 @@ struct _InstrClassInfo
/*
* This is the request to the instrumentaion server to instrument attached class.
*/
struct _InstrumentClassRequest
struct InstrumentClassRequest
{
ProtobufCMessage base;
int32_t flags;
......@@ -93,7 +93,7 @@ struct _InstrumentClassRequest
/*
* Server response containing either the instrumented classbytes or error message
*/
struct _InstrumentClassResponse
struct InstrumentClassResponse
{
ProtobufCMessage base;
InstrumentClassResponse__InstrumentClassResult result;
......
......@@ -4,25 +4,25 @@
#ifndef PROTOBUF_C_main_2eproto__INCLUDED
#define PROTOBUF_C_main_2eproto__INCLUDED
#include "protobuf-c.h"
#include <protobuf-c/protobuf-c.h>
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
#include "disl.pb-c.h"
#include "shvm.pb-c.h"
typedef struct _Error Error;
typedef struct _SessionInitRequest SessionInitRequest;
typedef struct _SessionInitResponse SessionInitResponse;
typedef struct _CloseConnection CloseConnection;
typedef struct _ClientMessage ClientMessage;
typedef struct _ServerMessage ServerMessage;
typedef struct Error Error;
typedef struct SessionInitRequest SessionInitRequest;
typedef struct SessionInitResponse SessionInitResponse;
typedef struct CloseConnection CloseConnection;
typedef struct ClientMessage ClientMessage;
typedef struct ServerMessage ServerMessage;
/* --- enums --- */
......@@ -37,7 +37,7 @@ typedef enum _CloseConnection__CloseReason {
/*
* Common type to send errors
*/
struct _Error
struct Error
{
ProtobufCMessage base;
char *message;
......@@ -52,7 +52,7 @@ struct _Error
* This is sent as the clients first message
* May contain some additional data to describe the client (JVM version etc.)
*/
struct _SessionInitRequest
struct SessionInitRequest
{
ProtobufCMessage base;
/*
......@@ -74,7 +74,7 @@ struct _SessionInitRequest
* The request could either be ACCEPTed or DENYed
* In the case of positive answer, there is also a session_id present
*/
struct _SessionInitResponse
struct SessionInitResponse
{
ProtobufCMessage base;
protobuf_c_boolean accepted;
......@@ -91,7 +91,7 @@ struct _SessionInitResponse
**
* Notify server about closing connection
*/
struct _CloseConnection
struct CloseConnection
{
ProtobufCMessage base;
CloseConnection__CloseReason reason;
......@@ -117,13 +117,13 @@ typedef enum {
CLIENT_MESSAGE__REQUEST_THREAD_END = 17,
CLIENT_MESSAGE__REQUEST_THREAD_INFO = 18,
CLIENT_MESSAGE__REQUEST_ERROR = 30
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__REQUEST)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__REQUEST__CASE)
} ClientMessage__RequestCase;
/*
* Pack together messages from client to simply distinguish them at the server side.
*/
struct _ClientMessage
struct ClientMessage
{
ProtobufCMessage base;
int32_t session_id;
......@@ -163,13 +163,13 @@ typedef enum {
SERVER_MESSAGE__RESPONSE_INSTRUMENTATION_ACCEPT_CONFIRMATION = 2,
SERVER_MESSAGE__RESPONSE_INSTRUMENT_CLASS_RESPONSE = 3,
SERVER_MESSAGE__RESPONSE_ERROR = 30
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SERVER_MESSAGE__RESPONSE)
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(SERVER_MESSAGE__RESPONSE__CASE)
} ServerMessage__ResponseCase;
/*
* Pack together messages from server to simply distinguish them at the client side.
*/
struct _ServerMessage
struct ServerMessage
{
ProtobufCMessage base;
int32_t response_id;
......
......@@ -4,25 +4,25 @@
#ifndef PROTOBUF_C_shvm_2eproto__INCLUDED
#define PROTOBUF_C_shvm_2eproto__INCLUDED
#include "protobuf-c.h"
#include <protobuf-c/protobuf-c.h>
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION
#elif 1004000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _Analyze Analyze;
typedef struct _ClassInfo ClassInfo;
typedef struct _NewClass NewClass;
typedef struct _ObjectFree ObjectFree;
typedef struct _RegisterAnalysis RegisterAnalysis;
typedef struct _StringInfo StringInfo;
typedef struct _ThreadEnd ThreadEnd;
typedef struct _ThreadInfo ThreadInfo;
typedef struct Analyze Analyze;
typedef struct ClassInfo ClassInfo;
typedef struct NewClass NewClass;
typedef struct ObjectFree ObjectFree;
typedef struct RegisterAnalysis RegisterAnalysis;
typedef struct StringInfo StringInfo;
typedef struct ThreadEnd ThreadEnd;
typedef struct ThreadInfo ThreadInfo;
/* --- enums --- */
......@@ -30,7 +30,7 @@ typedef struct _ThreadInfo ThreadInfo;
/* --- messages --- */
struct _Analyze
struct Analyze
{
ProtobufCMessage base;
int64_t orderingid;
......@@ -42,7 +42,7 @@ struct _Analyze
, 0, 0, {0,NULL} }
struct _ClassInfo
struct ClassInfo
{
ProtobufCMessage base;
int64_t classtag;
......@@ -56,7 +56,7 @@ struct _ClassInfo
, 0, (char *)protobuf_c_empty_string, (char *)protobuf_c_empty_string, 0, 0 }
struct _NewClass
struct NewClass
{
ProtobufCMessage base;
char *classname;
......@@ -68,7 +68,7 @@ struct _NewClass
, (char *)protobuf_c_empty_string, 0, {0,NULL} }
struct _ObjectFree
struct ObjectFree
{
ProtobufCMessage base;
int32_t count;
......@@ -79,7 +79,7 @@ struct _ObjectFree
, 0, {0,NULL} }
struct _RegisterAnalysis
struct RegisterAnalysis
{
ProtobufCMessage base;
int32_t analysisid;
......@@ -90,7 +90,7 @@ struct _RegisterAnalysis
, 0, (char *)protobuf_c_empty_string }
struct _StringInfo
struct StringInfo
{
ProtobufCMessage base;
int64_t stringtag;
......@@ -101,7 +101,7 @@ struct _StringInfo
, 0, (char *)protobuf_c_empty_string }
struct _ThreadEnd
struct ThreadEnd
{
ProtobufCMessage base;
int64_t threadid;
......@@ -111,7 +111,7 @@ struct _ThreadEnd
, 0 }
struct _ThreadInfo
struct ThreadInfo
{
ProtobufCMessage base;
int64_t threadtag;
......
SRC=src/proto
DST=gen
for target in agent server; do
mkdir -p $DST/$target
rm -rf $DST/$target/*
done
for part in disl shvm main; do
protoc-c -I$SRC $SRC/$part.proto --c_out=$DST/agent
protoc -I$SRC $SRC/$part.proto --java_out=lite:$DST/server
done
# Import local variable definitions
-include Makefile.local
INCLUDE_DIR ?= ../src-jdk-include
JDK_DIR ?= ../src-jdk-include
PROTO_DIR ?= ../protocol
LIBRARY_BASE ?= dislagent
ifeq ($(OS),Windows_NT)
......@@ -100,22 +101,51 @@ endif
#
TARGET_DIR ?= $(BUILD_DIR)
LIBRARY_NAME := $(LIB_PREFIX)$(LIBRARY_BASE)$(LIB_SUFFIX)
LIBRARY := $(TARGET_DIR)/$(LIBRARY_NAME)
#
# Source files and directories.
#
PROTO_GEN_DIR := $(PROTO_DIR)/gen
PROTO_GEN_AGENT := $(PROTO_DIR)/gen/agent
PROTO_GEN_SOURCES := $(wildcard $(PROTO_GEN_AGENT)/*.pb-c.c)
PROTO_GEN_OBJECTS := $(addprefix $(BUILD_DIR)/,$(notdir $(PROTO_GEN_SOURCES:%.c=%.o)))
PROTO_GEN_HEADERS := $(PROTO_GEN_SOURCES:%.c=%.h)
PROTO_LIB_DIR := $(PROTO_DIR)/src
PROTO_LIB_PROTO_C := $(PROTO_DIR)/src/protobuf-c
PROTO_LIB_SOURCES := $(wildcard $(PROTO_LIB_PROTO_C)/*.c)
PROTO_LIB_OBJECTS := $(addprefix $(BUILD_DIR)/,$(notdir $(PROTO_LIB_SOURCES:%.c=%.o)))
PROTO_LIB_HEADERS := $(PROTO_LIB_SOURCES:%.c=%.h)
PROTO_SOURCES := $(PROTO_GEN_SOURCES) $(PROTO_LIB_SOURCES)
PROTO_OBJECTS := $(PROTO_GEN_OBJECTS) $(PROTO_LIB_OBJECTS)
PROTO_HEADERS := $(PROTO_GEN_HEADERS) $(PROTO_LIB_HEADERS)
AGENT_GENSRCS := bytecode.c codeflags.h
# Source and object files needed to create the library
SOURCES = bytecode.c common.c jvmtiutil.c connection.c \
AGENT_SOURCES := \
bytecode.c common.c jvmtiutil.c connection.c \
connpool.c msgchannel.c network.c classparser.c \
dislagent.c sessions.c \
protocol/protobuf-c.c protocol/main.pb-c.c protocol/disl.pb-c.c protocol/shvm.pb-c.c
dislagent.c sessions.c
HEADERS = $(wildcard *.h) codeflags.h $(wildcard protocol/*.h)
GENSRCS = bytecode.c codeflags.h
AGENT_OBJECTS = $(addprefix $(BUILD_DIR)/,$(AGENT_SOURCES:%.c=%.o))
AGENT_SRCDEPS = $(addprefix $(BUILD_DIR)/,$(AGENT_SOURCES:%.c=%.d))
AGENT_HEADERS = $(wildcard *.h)
OBJECTS = $(addprefix $(BUILD_DIR)/,$(SOURCES:%.c=%.o))
SRCDEPS = $(SOURCES:%.c=%.d)
SOURCES = $(AGENT_SOURCES) $(PROTO_SOURCES)
OBJECTS = $(AGENT_OBJECTS) $(PROTO_OBJECTS)
HEADERS = $(AGENT_HEADERS) $(PROTO_HEADERS)
SRCDEPS = $(AGENT_SRCDEPS)
GENSRCS = $(AGENT_GENSRCS)
# Generic and platform-specific JNI and JVMTI headers
JDK_INCLUDES := $(addprefix -I,$(JDK_DIR) $(JDK_DIR)/$(JDK_TARGET))
# Base options depending on the build
......@@ -128,16 +158,12 @@ endif
# Generate position independent code
CFLAGS += -fPIC
# Path to JNI and JVMTI includes
CFLAGS += -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/$(JDK_TARGET)
# Use GNU extensions and warn on most things
CFLAGS += -std=gnu99 -W -Wall -Wextra -Wno-unused-parameter
# Hide most symbols except those exported
CFLAGS_PARTS += -fvisibility=hidden
# Derive GCC flags for linker from LDFLAGS
COMMA := ,
CFLAGS_LD := $(CFLAGS_LD) $(addprefix -Wl$(COMMA),$(LDFLAGS))
......@@ -173,15 +199,14 @@ debug:
# Generated files
bytecode.c codeflags.h:
$(AGENT_GENSRCS):
ant -f ../build.xml prepare-disl-agent
# Output directory for compiled object files
# Build output directory for object and dependency files
$(BUILD_DIR):
mkdir $@
mkdir $@/protocol
# Compilation and linking targets
......@@ -191,7 +216,7 @@ ifneq (,$(WHOLE))
CFLAGS += $(CFLAGS_WHOLE) -DWHOLE
$(LIBRARY): $(HEADERS) $(SOURCES)
$(CC) $(CC_SHARED) $(CFLAGS) $(TARGET_ARCH) $(CFLAGS_LD) $(SOURCES) $(LIBS) $(OUTPUT_OPTION)
$(CC) $(CC_SHARED) $(CFLAGS) -I$(PROTO_LIB_DIR) -I$(PROTO_GEN_DIR) $(JDK_INCLUDES) $(TARGET_ARCH) $(CFLAGS_LD) $(SOURCES) $(LIBS) $(OUTPUT_OPTION)
else
......@@ -201,9 +226,15 @@ $(LIBRARY): $(OBJECTS)
$(LD) $(LD_SHARED) $(LDFLAGS) $(TARGET_ARCH) $(LIBDIRS) $(OBJECTS) $(LIBS) $(OUTPUT_OPTION)
$(BUILD_DIR)/%.o: %.c
$(CC) $(CFLAGS) -I$(PROTO_LIB_DIR) -I$(PROTO_GEN_DIR) $(JDK_INCLUDES) $(TARGET_ARCH) -c $? $(OUTPUT_OPTION)
$(BUILD_DIR)/%.o: $(PROTO_GEN_AGENT)/%.c
$(CC) $(CFLAGS) -I$(PROTO_LIB_DIR) $(TARGET_ARCH) -c $? $(OUTPUT_OPTION)
$(BUILD_DIR)/%.o: $(PROTO_LIB_PROTO_C)/%.c
$(CC) $(CFLAGS) $(TARGET_ARCH) -c $? $(OUTPUT_OPTION)
%.d: %.c
$(BUILD_DIR)/%.d: %.c
@$(CC) -MM $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
-include $(SRCDEPS)
......
......@@ -5,13 +5,14 @@
#include "connection.h"
#include "network.h"
#include "msgchannel.h"
#include "protocol/main.pb-c.h"
#include "sessions.h"
#include "bytecode.h"
#include "classparser.h"
#include "codeflags.h"
#include <agent/main.pb-c.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: main.proto */
#ifndef PROTOBUF_C_main_2eproto__INCLUDED
#define PROTOBUF_C_main_2eproto__INCLUDED
#include "protobuf-c.h"
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003002 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
#include "disl.pb-c.h"
#include "shvm.pb-c.h"
typedef struct _Error Error;
typedef struct _SessionInitRequest SessionInitRequest;
typedef struct _SessionInitResponse SessionInitResponse;
typedef struct _CloseConnection CloseConnection;
typedef struct _ClientMessage ClientMessage;
typedef struct _ServerMessage ServerMessage;
/* --- enums --- */
typedef enum _CloseConnection__CloseReason {
CLOSE_CONNECTION__CLOSE_REASON__FINISHED = 0
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLOSE_CONNECTION__CLOSE_REASON)
} CloseConnection__CloseReason;
/* --- messages --- */
/*
* Common type to send errors
*/
struct _Error
{
ProtobufCMessage base;
char *message;
};
#define ERROR__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&error__descriptor) \
, (char *)protobuf_c_empty_string }
/*
* Request server to initialize session
* This is sent as the clients first message
* May contain some additional data to describe the client (JVM version etc.)
*/
struct _SessionInitRequest
{
ProtobufCMessage base;
/*
* Request the instrumentation functionality from the server
*/
protobuf_c_boolean require_disl;
/*
* Request the ShadowVM functionality from the server
*/
protobuf_c_boolean require_shvm;
};
#define SESSION_INIT_REQUEST__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&session_init_request__descriptor) \
, 0, 0 }
/*
* This is the response to SessionInitRequest message
* The request could either be ACCEPTed or DENYed
* In the case of positive answer, there is also a session_id present
*/
struct _SessionInitResponse
{
ProtobufCMessage base;
protobuf_c_boolean accepted;
int32_t session_id;
size_t n_errors;
Error **errors;
};
#define SESSION_INIT_RESPONSE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&session_init_response__descriptor) \
, 0, 0, 0,NULL }
/*
**
* Notify server about closing connection
*/
struct _CloseConnection
{
ProtobufCMessage base;
CloseConnection__CloseReason reason;
};
#define CLOSE_CONNECTION__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&close_connection__descriptor) \
, CLOSE_CONNECTION__CLOSE_REASON__FINISHED }
typedef enum {
CLIENT_MESSAGE__REQUEST__NOT_SET = 0,
CLIENT_MESSAGE__REQUEST_SESSION_INIT_REQUEST = 2,
CLIENT_MESSAGE__REQUEST_INSTRUMENTATION_DELIVERY = 3,
CLIENT_MESSAGE__REQUEST_INSTRUMENT_CLASS_REQUEST = 4,
CLIENT_MESSAGE__REQUEST_CLOSE_CONNECTION = 5,
CLIENT_MESSAGE__REQUEST_ANALYZE = 10,
CLIENT_MESSAGE__REQUEST_CLOSE = 11,
CLIENT_MESSAGE__REQUEST_CLASS_INFO = 12,
CLIENT_MESSAGE__REQUEST_NEW_CLASS = 13,
CLIENT_MESSAGE__REQUEST_OBJECT_FREE = 14,
CLIENT_MESSAGE__REQUEST_REGISTER_ANALYSIS = 15,
CLIENT_MESSAGE__REQUEST_STRING_INFO = 16,
CLIENT_MESSAGE__REQUEST_THREAD_END = 17,
CLIENT_MESSAGE__REQUEST_THREAD_INFO = 18,
CLIENT_MESSAGE__REQUEST_ERROR = 30
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(CLIENT_MESSAGE__REQUEST)
} ClientMessage__RequestCase;
/*
* Pack together messages from client to simply distinguish them at the server side.
*/
struct _ClientMessage
{
ProtobufCMessage base;
int32_t session_id;
int32_t request_id;
ClientMessage__RequestCase request_case;
union {
/*
* / Instrumentation messages
*/
SessionInitRequest *session_init_request;
InstrumentationDelivery *instrumentation_delivery;
InstrumentClassRequest *instrument_class_request;
CloseConnection *close_connection;
/*
* / Analysis messages
*/
Analyze *analyze;
CloseConnection *close;
ClassInfo *class_info;
NewClass *new_class;
ObjectFree *object_free;
RegisterAnalysis *register_analysis;
StringInfo *string_info;
ThreadEnd *thread_end;
ThreadInfo *thread_info;
Error *error;
};
};
#define CLIENT_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&client_message__descriptor) \
, 0, 0, CLIENT_MESSAGE__REQUEST__NOT_SET, {0} }
typedef enum {
SERVER_MESSAGE__RESPONSE__NOT_SET = 0,
SERVER_MESSAGE__RESPONSE_SESSION_INIT_RESPONSE = 1,
SERVER_MESSAGE__RESPONSE_INSTRUMENTATION_ACCEPT_CONFIRMATION = 2,