SQLite source code compilation and debugging

1. Compile on msys

This article introduces the windows platform, so you must first install the msys2 environment. I won’t go into details here. For details, please refer to the following article:
https://blog.csdn.net/qiuzhiqian1990/article/details/56671839

To download the source code at first, the official website address is as follows:
https://www.sqlite.org/download.html
Select the version that contains all the source files, the 11.93M one, unzip the
Insert picture description here
downloaded package, and then open msys2 to enter sqlite-src- 3310100 folder and execute the ./configure command to generate a makefile.

Next, run the make command, you can see an error, prompting "/bin/sh: tclsh: command not found".
Insert picture description here
This is caused by not installing tcl. The compilation of sqlite depends on the tcl script, so tcl must be installed first. ActiveTcl 8.6 is installed, which can be downloaded from the following address:
https://www.cr173.com/soft/46330.html
I installed it in the F:/Tcl directory. After installation, enter the command tclsh in cmd, and the% description appears The installation is successful, and then re-enter the make command in msys, and found a lot of strange errors, which are caused by the last compilation error, so make clean up first, and then make to compile successfully.
Insert picture description here
The compiled version is the shell version of sqlite. At the same time, you can see that a large number of compiled target files are generated in the project directory to affect reading. At this time, you can create a new folder in it, such as
mkdir bld
cd bld
…/configure
make,
and then the compiled files are all placed in the bld folder .

The default compilation will only generate the shell version and not the tcl version. To compile the tcl version, you need to specify the target
make tclsqlite3.exe during make

2. Compile on eclipse

Previously, I mainly did some verification of the compilation environment. In order to improve the development efficiency, the compilation was done on eclipse. First, create a new project, select cygwin gcc, and
Insert picture description here
then right-click on the project to create a new folder, select the external association method, and import The folder where the source code is located
Insert picture description here
By default, SQLite uses built-in automatic compilation. Now we can’t use automatic compilation. Instead, use the makefile in the newly created bld folder to compile. Right-click the project name on the left and click Properties to select the
Insert picture description here
Insert picture description here
compilation target as follows Select tclsqlite3.exe, after compiling, set breakpoint debugging now:
Insert picture description here
create a debug configuration
Insert picture description here
according to the following configuration, find tclsqlite3.exe and
Insert picture description here
then set the path mapping, otherwise the source file will not be found during dubug, and the set e disk is where the project is located After the directory
Insert picture description here
debug, enter the puts command and find that there is no print,
Insert picture description here
but it can be printed by running the program directly.
Insert picture description here
After debugging, it is confirmed that there is a problem with the current gdb. Open msys2 to view the gdb version.
Insert picture description here
I used gdb 7.11.1-1 before. This is a problem. It is recommended to install mingw-w64-i686-gdb 8.1-1 and use the command to pacman -S mingw-w64-i686-gdbinstall. After installation, replace the debug default gdb with the gdb
Insert picture description here
path in the mingw32 directory and modify it according to the installed msys2 path. For the sake of safety, enter F:\msys32\mingw32\bin\gdb.exe -vit in cmd to confirm this The version of gdb
Insert picture description here
You can see that this version is indeed what we need. Once again debug input puts command, you can see that the gdb can output normally.
Insert picture description here
Next, set a breakpoint in the sqlite3PagerOpen function in pager.c under the src directory, and run The following commandsqlite3 db example1.db, It is found that the breakpoint cannot be stopped, but the example1.db database file has been generated in the sqlite_build folder, indicating that the program has executed the instruction, but the corresponding source code file is wrong. After some exploration, I know that sqlite will save all sources. The file is synthesized into a sqlite3.c file, you can modify the makefile so that it is not merged.
Insert picture description here
Change USE_AMALGAMATION = 1 to USE_AMALGAMATION = 0.

When I encountered the above problem, I compiled the makefile in the main directory of the project. Now I created a new bld folder and compiled it, and I can single-step debugging during debugging, but setting any breakpoints is invalid. The reason for this phenomenon is Eclipse does not support setting breakpoints based on relative paths, and the compiled source files are compiled according to relative paths

Insert picture description here
As shown in the figure above, setting a breakpoint on line 4005 according to an absolute path will not stop, and setting a breakpoint on line 4006 according to a relative path can stop, and eclipse sets a breakpoint according to the absolute path.

The solution is to change the original relative path:
Insert picture description here
to an absolute path TOP = /e/qxqb/open_source/sqlite-src-3310100.

The sqlite source code uses some macros to control the compilation options. If you want to learn through debugging and want to compile the debug version of the code, you can make the following changes in the makefile:
Insert picture description here
Because you are currently using an external makefile to compile, eclipse does not know the compilation options. The code controlled by these macros is grayed out in comment state, so add it in the right-click Properties of the project, this is mainly for the convenience of reading the code, and it does not have a compiling effect.
Insert picture description here
Now re-set a breakpoint in the sqlite3PagerOpen function in pager.c, enter it sqlite3 db example1.db, and the code does stop there when it runs
Insert picture description here

Guess you like

Origin blog.csdn.net/pfysw/article/details/104716815