Mysql Debug mode implementation

Source: Internet
Author: User
Tags connect socket
Welcome to the Linux community forum and interact with 2 million technical staff. 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, tracing, and finally found the MYSQL implementation link client code, in the source file sql-commonclient.c CLI_MYSQL _

Welcome to the Linux community forum, and interact with 2 million technical staff> go to the previous section and lead the development of a kernel module. During the test, we 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. In the source file SQL-common/client. c, the CLI_MYSQL _

Welcome to the Linux community forum and interact with 2 million technicians>

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.

*

*/

[1] [2]

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.