MySQL 8.0.39
Source Code Documentation
test_trace_plugin.cc File Reference
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "my_byteorder.h"
#include "mysql.h"
#include "mysql_trace.h"

Classes

struct  test_trace::st_trace_data
 State information maintained by the test trace plugin for each traced connection. More...
 
class  test_trace::Logger
 

Namespaces

namespace  test_trace
 

Macros

#define LOGGER(M)   ::test_trace::Logger logger(M);
 
#define LOG(ARGS)
 
#define DUMP(KEY, DATA, LEN)
 
#define OK_PACKET(PKT)   (*((const byte *)PKT) == 0x00)
 
#define ERR_PACKET(PKT)   (*((const byte *)PKT) == 0xFF)
 
#define EOF_PACKET(PKT)   (*((const byte *)PKT) == 0xFE)
 
#define FILE_REQUEST(PKT)   (*((const byte *)PKT) == 0xFB)
 
#define protocol_stage_chk_ev_declare(S)
 
#define protocol_stage_check(S)
 
#define NEXT_STAGE(S)
 

Typedefs

typedef unsigned char test_trace::byte
 

Functions

static int test_trace::plugin_init (char *a, size_t b, int argc, va_list args)
 
static int test_trace::plugin_deinit ()
 
void * test_trace::trace_start (struct st_mysql_client_plugin_TRACE *, MYSQL *conn, enum protocol_stage stage)
 
void test_trace::trace_stop (struct st_mysql_client_plugin_TRACE *, MYSQL *conn, void *data)
 
int test_trace::trace_event (struct st_mysql_client_plugin_TRACE *, void *data_ptr, MYSQL *conn, enum protocol_stage stage, enum trace_event ev, struct st_trace_event_args args)
 
int test_trace::check_event_CONNECTING (MYSQL *, struct st_trace_data *, enum trace_event ev, struct st_trace_event_args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_INIT_PACKET (MYSQL *, struct st_trace_data *, enum trace_event ev, struct st_trace_event_args, enum protocol_stage *next_stage)
 
int test_trace::check_event_AUTHENTICATE (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_SSL_NEGOTIATION (MYSQL *conn, struct st_trace_data *, enum trace_event ev, struct st_trace_event_args, enum protocol_stage *next_stage)
 
int test_trace::check_event_READY_FOR_COMMAND (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_PACKET (MYSQL *conn, struct st_trace_data *, enum trace_event ev, struct st_trace_event_args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_RESULT (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_FIELD_DEF (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_ROW (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_PS_DESCRIPTION (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_WAIT_FOR_PARAM_DEF (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_FILE_REQUEST (MYSQL *conn, struct st_trace_data *data, enum trace_event ev, struct st_trace_event_args args, enum protocol_stage *next_stage)
 
int test_trace::check_event_DISCONNECTED (MYSQL *, struct st_trace_data *, enum trace_event, struct st_trace_event_args, enum protocol_stage *)
 

Variables

static tracing_start_callback test_trace::trace_start
 
static tracing_stop_callback test_trace::trace_stop
 
static trace_event_handler test_trace::trace_event
 
struct st_mysql_client_plugin_TRACE test_trace_plugin
 
static bool test_trace::logger_enabled = false
 
static Logger test_trace::logger
 The "top-level" logger used when no connection context is given. More...
 
static bool test_trace::opt_crash = false
 Global flag telling if test trace plugin should crash if it detects incorrect protocol flow (unexpected stage or invalid event for the current stage). More...
 

Detailed Description


Test trace plugin

If WITH_TEST_TRACE_PLUGIN build option was checked when building libmysql then this plugin is built into client library (no plugin loading required).

The plugin follows the protocol flow based on the trace events reported to it. If MYSQL_TEST_TRACE_DEBUG environment variable is non-zero then it logs information about received trace events and reports if a particular event is invalid.

If MYSQL_TEST_TRACE_CRASH environment variable is set to something else than 0 then the plugin will crash if an invalid trace event was reported to it.

Macro Definition Documentation

◆ DUMP

#define DUMP (   KEY,
  DATA,
  LEN 
)
Value:
do { \
logger.dump((KEY), (DATA), (LEN)); \
} while (0)
Definition: key.h:113

◆ EOF_PACKET

#define EOF_PACKET (   PKT)    (*((const byte *)PKT) == 0xFE)

◆ ERR_PACKET

#define ERR_PACKET (   PKT)    (*((const byte *)PKT) == 0xFF)

◆ FILE_REQUEST

#define FILE_REQUEST (   PKT)    (*((const byte *)PKT) == 0xFB)

◆ LOG

#define LOG (   ARGS)
Value:
do { \
logger.log ARGS; \
} while (0)

◆ LOGGER

#define LOGGER (   M)    ::test_trace::Logger logger(M);

◆ NEXT_STAGE

#define NEXT_STAGE (   S)
Value:
do { \
if (next_stage) *next_stage = PROTOCOL_STAGE_##S; \
} while (0)

◆ OK_PACKET

#define OK_PACKET (   PKT)    (*((const byte *)PKT) == 0x00)

◆ protocol_stage_check

#define protocol_stage_check (   S)
Value:
case PROTOCOL_STAGE_##S: \
check = check_event_##S(conn, data, ev, args, &(data->next_stage)); \
break;

◆ protocol_stage_chk_ev_declare

#define protocol_stage_chk_ev_declare (   S)
Value:
static int check_event_##S( \
MYSQL *conn, struct st_trace_data *data, enum trace_event ev, \
struct st_trace_event_args args, enum protocol_stage *next_stage);
trace_event
Definition: plugin_trace.h:230
protocol_stage
Definition: plugin_trace.h:226
Definition: mysql.h:299
Some trace events have additional arguments.
Definition: plugin_trace.h:213

Variable Documentation

◆ test_trace_plugin

struct st_mysql_client_plugin_TRACE test_trace_plugin
Initial value:
= {
"test_trace_plugin",
"Rafal Somla",
"A plugin for testing protocol tracing infrastructure",
{0, 1, 0},
"GPL",
NULL,
#define MYSQL_CLIENT_TRACE_PLUGIN
Definition: client_plugin.h:81
#define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION
Definition: client_plugin.h:84
static tracing_stop_callback trace_stop
Definition: test_trace_plugin.cc:74
static trace_event_handler trace_event
Definition: test_trace_plugin.cc:75
static int plugin_init(char *a, size_t b, int argc, va_list args)
Definition: test_trace_plugin.cc:315
static int plugin_deinit()
Definition: test_trace_plugin.cc:328
static tracing_start_callback trace_start
Definition: test_trace_plugin.cc:73
#define NULL
Definition: types.h:55