Backend Development 7 min read

Debug MySQL Source with VS Code and LLDB on macOS – A Complete Guide

Learn how to efficiently debug MySQL source code on macOS using Visual Studio Code and LLDB, covering installation of LLDB via Homebrew, configuring VS Code extensions, setting up local and remote debugging parameters, breakpoint management, and essential command-line steps for seamless development.

Efficient Ops
Efficient Ops
Efficient Ops
Debug MySQL Source with VS Code and LLDB on macOS – A Complete Guide

Introduction

MySQL debugging is a fundamental skill for exploring the MySQL source code. Previously we introduced how to use LLDB to debug MySQL, but command‑line operation is inconvenient. This article shows how to use Visual Studio Code on macOS for local and remote debugging, greatly improving efficiency.

Visual Studio Code

Visual Studio Code (VS Code) is an open‑source editor from Microsoft that runs on Windows, Linux and macOS. It supports debugging, has built‑in Git, code completion, snippets, refactoring, and can be customized with themes, shortcuts, settings, and extensions.

Install LLDB

LLDB is part of the LLVM toolchain. It is recommended to install the LLVM suite via Homebrew rather than using the system‑provided LLDB. Before installing, create a certificate as required.

Install LLVM with:

brew install llvm --with-python@2 --with-lldb

Install Plugin

VS Code includes built‑in debug capabilities; we recommend installing the “LLDB Debugger” extension.

Configure Debug Parameters

Open the MySQL source directory in VS Code, go to the Debug pane, and add a configuration. Set

program

to the path of the compiled

mysqld

binary and

args

to the required startup arguments, typically the MySQL configuration file.

Start Debugging

Press the launch button. If no breakpoint is set,

mysqld

runs normally; if a breakpoint is hit, the debugger stops and shows the state as illustrated.

The debug window is divided into six parts:

1: Variable view 2: Watch variables 3: Call stack 4: Breakpoints (can also set by clicking line numbers) 5: Code view with debug controls (continue, step over, step in, step out, restart, stop) 6: Debug console I/O

Breakpoint Settings

Click the gutter before a line to set a breakpoint, or create conditional breakpoints. A conditional breakpoint triggers only when a specified expression evaluates true, allowing you to skip irrelevant executions.

Conditional breakpoints are useful for stopping execution when a target variable reaches a certain value, reducing manual stepping.

Remote Debugging

To debug MySQL running on a remote Linux server, use LLDB’s remote debugging support. Install LLDB on the remote host via yum:

yum install -y llvm-toolset-7

Then start the remote lldb‑server:

/opt/rh/llvm-toolset-7/root/usr/bin/lldb-server platform --listen "*:9191" --server

Add a remote attach configuration in

launch.json

:

<code>{
  "type": "lldb",
  "request": "attach",
  "name": "Remote attach",
  "program": "~/mysql5626/usr/local/mysql/bin/mysqld",
  "pid": "<target_pid>",
  "initCommands": [
    "platform select remote-linux",
    "platform connect connect://<remote_host>:9191"
  ],
  "sourceMap": {
    "/export/home/pb2/build/sb_0-15908961-1436910670.17/mysql-5.6.26": "/Users/hongbin/workbench/mysql-server"
  }
}
</code>

Make sure the local source tree matches the remote binary version and set the appropriate

sourceMap

entries.

References

http://lldb.llvm.org/remote.html

https://github.com/vadimcn/vscode-lldb

debuggingmysqlremote debuggingVS CodeLLDB
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.