How to debug mapD core and trace the excution of a SQL


#1

Hi! I’m a freshman to gdb, but I know the basic knowledge.

I wan’t to trace the mapD server, and I wonder how a SQL is excuted in mapD.
So I want to debug it. But the server got two child thread——bufThread && httpThread.

I followed the gdb tuturial to debug multi-threads code. But I always failed with the error below.And I can't see which code line the code executed.

Futher, I can’t set breakpoint. I must do something in a wrong way. Can anyone help me.Thanks

0x00007ffff62f198d in pthread_join (threadid=140736714430208, thread_return=0x0) at pthread_join.c:90
90      pthread_join.c: No such file or directory.
(gdb) q


#2

@pickou we would love to help, but the issues you describe seem to be specific to GDB rather than our products. I can ask around and see if we have anyone that’s familiar with GDB.


#3

hi @pickou,

You have to compile for debug using the `-DCMAKE_BUILD_TYPE=debug, but I guess you already did, then you have to be sure the built mapd_server is functional, starting the server then running some queries; after that debugging is as “easy” :wink: task, but following the various steps of such complex software with gdb in command line mode it’s a little awkward.

anyway here is a brief example

 gdb ./mapd_server
GNU gdb (Ubuntu 8.2-0ubuntu1~16.04.1) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
[CUT]
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./mapd_server...
set argsdone.
 (gdb)
(gdb) set args --config /opt/mapd_storage/mapd.conf
(gdb) start
Temporary breakpoint 1 at 0x14dd1a6: file /opt/github-mapd/mapd-core/MapDServer.cpp, line 204.
Starting program: /opt/github-mapd/mapd-core/build_profiling/bin/mapd_server --config /opt/mapd_storage/mapd.conf
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 1, main (argc=3, argv=0x7fffffffe5c8) at /opt/github-mapd/mapd-core/MapDServer.cpp:204
204     int main(int argc, char** argv) {
(gdb) break CompareIR.cpp:Executor::codegenCmp
Breakpoint 2 at 0x1d95853: CompareIR.cpp:Executor::codegenCmp. (2 locations)
(gdb) continue
Continuing.
E0107 17:25:24.999969  4173 MapDHandler.cpp:176] This build isn't CUDA enabled, will run on CPU
Thrift: Mon Jan  7 17:25:25 2019 TSocket::open() connect() <Host: localhost Port: 9093>Connection refused
[Detaching after fork from child process 4182]
E0107 17:25:25.217703  4173 MapDHandler.cpp:208] No GPUs detected, falling back to CPU mode
[New Thread 0x7fffdf5f1700 (LWP 4199)]
[CUT]
[Thread 0x7fffde4ee700 (LWP 4208) exited]
[Switching to Thread 0x7ffff7f94700 (LWP 4203)]

Thread 4 "mapd_server" hit Breakpoint 2, Executor::codegenCmp (this=0x4c5de10, bin_oper=0x5326f10, co=...)
    at /opt/github-mapd/mapd-core/QueryEngine/CompareIR.cpp:184
184                                       const CompilationOptions& co) {
(gdb) step
185       const auto qualifier = bin_oper->get_qualifier();

As you can see it’s not a problem setting breakpoints and seeing line codes; you cannot see the source of the pthread_join function because it’s a part of pthread lib. If you are getting this “error” every time you run the debug, is likely your executable has a problem.


#5

Thanks for your detailed reply. My confusion lies in break CompareIR.cpp:Executor::codegenCmp. I set as break mapDServer.cpp:13,but it failed with error can' find file mapDServer.cpp. So I’m confused. In addition,I got myself stuck in the two thread.
Anyway, I’m clear now. Thanks for your kindly help.


#6

Yes,this is a debugging issue of gdb rather than the mapD. I appreciate your help.


#7

Hi @pickou,

you should find which is the record source directory of the mapd_server file; so open mapd_server executable with gdb then run this command

info sources

You should get an output like that

(gdb) info sources
Source files for which symbols have been read in:

/opt/github-mapd/mapd-core/MapDServer.cpp, /usr/include/c++/6/exception, /usr/include/c++/6/bits/predefined_ops.h,
/usr/include/c++/6/bits/stl_algobase.h, /usr/include/c++/6/bits/char_traits.h, /usr/include/x86_64-linux-gnu/bits/byteswap.h,
[CUT] 

if the path of your mapd sources is wrong, you can try to set the right path with the gdb command

set directory $cdir:$cwd:/the/path/where/mapd/sources/reside

and retry.

it’s normal you are stuck with two thread because the server runs initially two threads