Mysql Debug mode implementation _ MySQL

Source: Internet
Author: User
Tags connect socket
Mysql Debug mode implementation bitsCN.com

Mysql Debug mode implementation

The previous section led the development of a kernel module. during the test, it was found that the MYSQL client could not connect to the server.

After querying the document and tracing, I finally found the code for MYSQL to connect to the client. the CLI_MYSQL_REAL_CONNECT function in the source file SQL-common/client. c.

However, the code is very long and cannot be understood at half past one. At this time, we found that the code contains many such codes:

[Cpp]

DBUG_ENTER ("mysql_real_connect ");

This means that you only need to start MYSQL in debug mode to track code execution.

After the query documents and tests, you only need to add the cmake-WITH_DEBUG = 1 parameter during cmake.

Before starting a MYSQL client, change an environment variable:

[Plain]

Export MYSQL_DEBUG = d: t: O,/tmp/client. trace

Open/tmp/client. trace in the editor and you will get the following Debug information:

[Cpp]

| Info: Connect socket

|> Vio_socket_connect

|> Viow_set_blocking

|

|> Vie_io_wait

|

|> Viow_set_blocking

|

|

| Info: No success, close socket, try next address.

| Info: End of connect attempts, sock: 4 status: 1 error: 0

| Error: Got error 0 on connect to 'localhost'

|> Set_mysql_extended_error

| Enter: error: 2003 'can't connect to MySQL server on '%-. 100s' (% d )'

|

| Error: message: 2003/HY000 (Can't connect to MySQL server on 'localhost' (0 ))

The following number is the row number. The execution of the program can be tracked from this file!

Awesome! We can't help but sigh. In addition, I learned the specific implementation of this debugging mode:

In CMakeList.txt, there is such a piece of code:

[Plain]

IF (WITH_DEBUG)

SET (CMAKE_BUILD_TYPE "Debug" cache string $ {BUILDTYPE_DOCSTRING} FORCE)

[Plain]

IF (NOT CMAKE_BUILD_TYPE

And not CMAKE_GENERATOR MATCHES "Visual Studio"

And not CMAKE_GENERATOR MATCHES "Xcode ")

# This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode

# Or if custom C flags are set. In VS and Xcode for non-Debug deployments

# DBUG_OFF is already correctly set. Use DBUG_OFF for Makefile based projects

# Without build type too, unless user specifically requests DBUG.

IF (NOT CMAKE_C_FLAGS MATCHES "-DDBUG_ON ")

ADD_DEFINITIONS (-DDBUG_OFF)

ENDIF ()

ENDIF ()

If CMAKE_BUILD_TYPE is not set, the following code is executed. If a CFLAGS environment variable named-DDBUG_ON is not set at this time, a CFLAGS:-DDBUG_OFF will be added.

Later, when the compiler compiles, it determines how to define functions such as DBUG_ENTER as null code or the actual error code based on the macros added by the compiler parameters.

[Cpp]

/*

* These macros provide a user interface into functions in

* Dbug runtime support library. They isolate users from changes

* In the MACROS and/or runtime support.

*

* The symbols "_ LINE _" and "_ FILE _" are expanded by

* Preprocessor to the current source file line number and file

* Name respectively.

*

* WARNING --- Because the DBUG_ENTER macro allocates space on

* The user function's stack, it must precede any executable

* Statements in the user function.

*

*/

# Ifdef DBUG_OFF

# Define DBUG_ENTER (a1)

# Define DBUG_RETURN (a1) return (a1)

# Define DBUG_VOID_RETURN return

# Define DBUG_EXECUTE (keyword, a1)

# Define DBUG_PRINT (keyword, arglist)

# Define DBUG_2 (keyword, format)/* Obsolete */

# Define DBUG_3 (keyword, format, a1)/* Obsolete */

# Define DBUG_4 (keyword, format, a1, a2)/* Obsolete */

# Define DBUG_5 (keyword, format, a1, a2, a3)/* Obsolete */

# Define DBUG_PUSH (a1)

# Define DBUG_POP ()

# Define DBUG_PROCESS (a1)

# Define DBUG_FILE (stderr)

# Define DBUG_SETJMP setjmp

# Define DBUG_LONGJMP longjmp

# Define DBUG_DUMP (keyword, a1)

# Else

# Define DBUG_ENTER ()/

Auto char * _ db_func _; auto char * _ db_file _; auto int _ db_level _;/

Auto char ** _ db_framep _;/

_ Db_enter _ (a ,__ FILE __,__ LINE __, & _ db_func _, & _ db_file _, & _ db_level _,/

& _ Db_framep _)

# Define DBUG_LEAVE/

(_ Db_return _ (_ LINE __, & _ db_func _, & _ db_file _, & _ db_level _))

# Define DBUG_RETURN (a1) return (DBUG_LEAVE, (a1 ))

# Define DBUG_VOID_RETURN {DBUG_LEAVE; return ;}

# Define DBUG_EXECUTE (keyword, a1 )/

{If (_ db_on _) {if (_ db_keyword _ (keyword) {a1 }}}

# Define DBUG_PRINT (keyword, arglist )/

{If (_ db_on _) {_ db_pargs _ (_ LINE __, keyword); _ db_doprnt _ arglist ;}}

# Define DBUG_2 (keyword, format )/

DBUG_PRINT (keyword, (format)/* Obsolete */

# Define DBUG_3 (keyword, format, a1 )/

DBUG_PRINT (keyword, (format, a1)/* Obsolete */

# Define DBUG_4 (keyword, format, a1, a2 )/

DBUG_PRINT (keyword, (format, a1, a2)/* Obsolete */

# Define DBUG_5 (keyword, format, a1, a2, a3 )/

DBUG_PRINT (keyword, (format, a1, a2, a3)/* Obsolete */

# Define DBUG_PUSH (a1) _ db_push _ (a1)

# Define DBUG_POP () _ db_pop _()

# Define DBUG_PROCESS (a1) (_ db_process _ = a1)

# Define DBUG_FILE (_ db_fp _)

# Define DBUG_SETJMP (a1) (_ db_setjmp _ (), setjmp (a1 ))

# Define DBUG_LONGJMP (a1, a2) (_ db_longjmp _ (), longjmp (a1, a2 ))

# Define DBUG_DUMP (keyword, a1, a2) _ db_dump _ (_ LINE __, keyword, a1, a2)

# Endif

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.