Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ class ValueBuffer: public Value
};


#ifdef DBUG_OFF
static inline const char *dbug_print_item(Item *item) { return NULL; }
#else
const char *dbug_print_item(Item *item);
#endif

class Virtual_tmp_table;
class sp_head;
class Protocol;
Expand Down
3 changes: 3 additions & 0 deletions sql/sql_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/


/*
Used in mtr tests to check index flags and key part flags and datatypes.
*/
class Debug_key: public String
{
public:
Expand Down
44 changes: 44 additions & 0 deletions sql/sql_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,47 @@ void print_keyuse_array_for_trace(THD *thd, DYNAMIC_ARRAY *keyuse_array)
keyuse_elem.add("null_rejecting",keyuse->null_rejecting);
}
}


#ifndef DBUG_OFF

/* Check if ptr points to memory on the mem_root */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing this blank line to have the function immediately follow the comment (consistent with dbug_which_mem_root below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought most functions actually do the reverse - have a blank line between the comment and function.
Do I change it in dbug_which_mem_root instead?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever way, only be consistent.

bool dbug_is_mem_on_mem_root(const MEM_ROOT *mem_root, void *ptr)
{
const USED_MEM *ptrs[]= {mem_root->free, mem_root->used};
for (const USED_MEM **p= ptrs; p!=ptrs + 2; p++)
{
for (const USED_MEM *block= *p; block; block= block->next)
{
const char *start= (const char*)block;
const char *end= start + block->size - block->left;
DBUG_ASSERT(end >= start);
if (ptr >= start && ptr < end)
return true;
}
}
return false;
}


/*
Check whether ptr has been allocated on a statement mem_root
or transient mem_root or somewhere else.
*/
const char *dbug_which_mem_root(THD *thd, void *ptr)
{
if (dbug_is_mem_on_mem_root(thd->mem_root, ptr))
{
if (thd->mem_root == thd->stmt_arena->mem_root)
return "thd->mem_root, same as stmt_arena->mem_root";
return "thd->mem_root";
}

if (dbug_is_mem_on_mem_root(thd->stmt_arena->mem_root, ptr))
return "thd->stmt_arena->mem_root";

return "Unknown";
}

#endif
33 changes: 33 additions & 0 deletions sql/sql_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,42 @@ class JOIN;
struct TABLE_LIST;
typedef class Item COND;
typedef class st_select_lex SELECT_LEX;
typedef class st_select_lex_unit SELECT_LEX_UNIT;
struct SORT_FIELD;
class SEL_ARG;


#ifndef DBUG_OFF
/*
Functions intended for manual use in debugger. NOT thread-safe.
*/

/* Print various data structures */
const char *dbug_print_item(Item *item);
const char *dbug_print_select(SELECT_LEX *sl);
const char *dbug_print_unit(SELECT_LEX_UNIT *un);
const char *dbug_print_sel_arg(SEL_ARG *sel_arg);

/* A single overloaded function (not inline so debugger sees them): */
const char *dbug_print(Item *x);
const char *dbug_print(SELECT_LEX *x);
const char *dbug_print(SELECT_LEX_UNIT *x);

/* Print current table row */
const char* dbug_print_table_row(TABLE *table);
const char *dbug_print_row(TABLE *table, const uchar *rec);

/* Check which MEM_ROOT the data is on */
bool dbug_is_mem_on_mem_root(const MEM_ROOT *mem_root, void *ptr);
const char *dbug_which_mem_root(THD *thd, void *ptr);

#else
// A dummy implementation is used in release builds
inline const char *dbug_print_item(Item *item) { return NULL; }
#endif

#ifndef DBUG_OFF
/* Functions that print into DBUG_FILE (/tmp/mariadb.trace by default) */
void print_where(COND *cond,const char *info, enum_query_type query_type);
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
void TEST_join(JOIN *join);
Expand Down