mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
MDEV-38347 Debugging functions
Extend current dbug_print* functions in such a way as to facilitate easy high level debugging. Introduce a single overloaded print function defined in dbp.h, DBUG_PRINT_FUNCTION, settable to your preference. Allow a shell environment variable DBUG_PRINT_FUNCTION to override this definition
This commit is contained in:
@@ -377,6 +377,11 @@ ELSEIF(TRASH_FREED_MEMORY MATCHES "AUTO" AND NOT WIN32 AND NOT WITH_VALGRIND AND
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DTRASH_FREED_MEMORY")
|
||||
ENDIF()
|
||||
|
||||
# override preferred overloaded debugging routine name
|
||||
IF(DEFINED ENV{DBUG_PRINT_FUNCTION})
|
||||
ADD_DEFINITIONS(-DDBUG_PRINT_FUNCTION=$ENV{DBUG_PRINT_FUNCTION})
|
||||
ENDIF()
|
||||
|
||||
INCLUDE(wsrep)
|
||||
|
||||
# Set commonly used variables
|
||||
|
||||
1866
sql/dbp.cc
Normal file
1866
sql/dbp.cc
Normal file
File diff suppressed because it is too large
Load Diff
48
sql/dbp.h
Normal file
48
sql/dbp.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Copyright (c) 2026, MariaDB
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
||||
|
||||
#ifndef __DBP_H__
|
||||
#define __DBP_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "my_global.h"
|
||||
#include "my_json_writer.h"
|
||||
|
||||
#ifndef DBUG_PRINT_FUNCTION
|
||||
# define DBUG_PRINT_FUNCTION dbug_print
|
||||
#endif
|
||||
#define DBUG_PRINT_ROW dbp_row
|
||||
#define DBUG_PRINT_TRACE dbp_trace
|
||||
#define DBUG_ITEM_BUFFER_SIZE 2048
|
||||
extern void dbug_strlcat( char *dest, uint dest_size, const char *src);
|
||||
|
||||
extern void dbug_sprintfcat(char *dest, uint dest_size, const char *format, ...);
|
||||
extern const char *dbug_add_print_field(Field *field);
|
||||
extern void dbug_add_print_field_value(Field *field);
|
||||
|
||||
#define DBUG_CAT(...) dbug_strlcat(dbug_big_buffer, DBUG_BIG_BUFFER_SIZE, \
|
||||
__VA_ARGS__)
|
||||
|
||||
#define DBUG_SPRINTF_CAT(...) dbug_sprintfcat(dbug_big_buffer,\
|
||||
DBUG_BIG_BUFFER_SIZE, __VA_ARGS__)
|
||||
|
||||
#define DBUG_TRASH_CHAR 0xa5
|
||||
|
||||
#define DBUG_BIG_BUFFER_SIZE 20480
|
||||
static char dbug_big_buffer[DBUG_BIG_BUFFER_SIZE];
|
||||
|
||||
#define DBUG_ROW_BUFFER_SIZE 1024
|
||||
|
||||
#endif
|
||||
@@ -11467,9 +11467,12 @@ const char *dbug_print_unit(SELECT_LEX_UNIT *un)
|
||||
return "Couldn't fit into buffer";
|
||||
}
|
||||
|
||||
#if 0
|
||||
// these overloads now defined in dbp.cc
|
||||
const char *dbug_print(Item *x) { return dbug_print_item(x); }
|
||||
const char *dbug_print(SELECT_LEX *x) { return dbug_print_select(x); }
|
||||
const char *dbug_print(SELECT_LEX_UNIT *x) { return dbug_print_unit(x); }
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@@ -11989,3 +11992,5 @@ bool ignored_list_includes_table(ignored_tables_list_t list, TABLE_LIST *tbl)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "dbp.cc"
|
||||
|
||||
@@ -298,6 +298,22 @@ public:
|
||||
|
||||
bool without_ranges() { return keys_map.is_clear_all(); }
|
||||
bool without_imerges() { return merges.is_empty(); }
|
||||
#ifndef DBUG_OFF
|
||||
key_map get_keys_map()
|
||||
{
|
||||
return keys_map;
|
||||
}
|
||||
|
||||
SEL_ARG *get_key(uint keyno)
|
||||
{
|
||||
return keys[keyno];
|
||||
}
|
||||
|
||||
uint get_type()
|
||||
{
|
||||
return (uint)type;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -17007,3 +17023,70 @@ void print_keyparts_name(String *out, const KEY_PART_INFO *key_part,
|
||||
}
|
||||
out->append(STRING_WITH_LEN(")"));
|
||||
}
|
||||
|
||||
#ifndef DBUG_OFF
|
||||
#include "dbp.h"
|
||||
|
||||
// "1 <= a < 'x'": a range as a string, values quoted SQL style
|
||||
void dbug_add_print_sel_arg(SEL_ARG *arg, KEY_PART *part)
|
||||
{
|
||||
DBUG_CAT("\"");
|
||||
if (!(arg->min_flag & NO_MIN_RANGE))
|
||||
{
|
||||
store_key_image_to_rec(part->field, arg->min_value, part->length);
|
||||
dbug_add_print_field_value(part->field);
|
||||
if (arg->min_flag & NEAR_MIN)
|
||||
DBUG_CAT(" < ");
|
||||
else
|
||||
DBUG_CAT(" <= ");
|
||||
}
|
||||
|
||||
DBUG_SPRINTF_CAT("%s", part->field->field_name.str);
|
||||
|
||||
if (!(arg->max_flag & NO_MAX_RANGE))
|
||||
{
|
||||
if (arg->max_flag & NEAR_MAX)
|
||||
DBUG_CAT(" < ");
|
||||
else
|
||||
DBUG_CAT(" <= ");
|
||||
store_key_image_to_rec(part->field, arg->max_value, part->length);
|
||||
dbug_add_print_field_value(part->field);
|
||||
}
|
||||
DBUG_CAT("\"");
|
||||
}
|
||||
|
||||
|
||||
const char *DBUG_PRINT_FUNCTION(SEL_ARG *arg, KEY_PART *part)
|
||||
{
|
||||
*dbug_big_buffer= (char)0;
|
||||
DBUG_SPRINTF_CAT("(SEL_ARG*)%p", arg);
|
||||
dbug_add_print_sel_arg(arg, part);
|
||||
return dbug_big_buffer;
|
||||
}
|
||||
|
||||
|
||||
const char *DBUG_PRINT_FUNCTION(SEL_TREE *arg, KEY_PART *parts)
|
||||
{
|
||||
static const char *type_names[]=
|
||||
{"IMPOSSIBLE", "ALWAYS", "MAYBE", "KEY", "KEY_SMALLER"};
|
||||
*dbug_big_buffer= (char)0;
|
||||
DBUG_SPRINTF_CAT("(SEL_TREE*)%p{type:%s, keys:[", arg,
|
||||
arg->type < array_elements(type_names) ?
|
||||
type_names[arg->type] : "UNKNOWN");
|
||||
key_map::Iterator it(arg->keys_map);
|
||||
int key_no;
|
||||
bool first= true;
|
||||
while ((key_no= it++) != key_map::Iterator::BITMAP_END)
|
||||
{
|
||||
SEL_ARG *key1= arg->get_key(key_no);
|
||||
if (!first)
|
||||
DBUG_CAT(", ");
|
||||
first= false;
|
||||
dbug_add_print_sel_arg( key1, parts+key1->part );
|
||||
}
|
||||
DBUG_CAT("]}");
|
||||
|
||||
return dbug_big_buffer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user