Open an3l opened 5 years ago
In mysql invoking SIGINT
output is going in the next row (in his patch we have to press enter again)
mysql> use test;^C
mysql> ^C
mysql> ^C
MariaDB [(none)]> (SIGINT), (ENTER) # not good
MariaDB [(none)]> ^C
Reasong is that mysql is using cmd-line-utils/libedit/readline.c
while we are using extra/readline.h
which are different.
# Enable SIGINT
gdb -> handle SIGINT pass
b handle_ctrlc_signal
mysql>
Program received signal SIGINT, Interrupt.
0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
(gdb) bt
#0 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#1 0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#2 0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#3 0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\b ", ch=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#4 0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#5 0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#6 0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#7 0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#8 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x000055555558c0d3 in handle_ctrlc_signal(int) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1534
breakpoint already hit 1 time
(gdb) n
sig_handler (signo=2) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/sig.c:69
(gdb) bt
#0 sig_handler (signo=32767) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/sig.c:69
#1 <signal handler called>
#2 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3 0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4 0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5 0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\bt", ch=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6 0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7 0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8 0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9 0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
(gdb) c
Continuing.
Program received signal SIGINT, Interrupt.
0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
(gdb) bt
#0 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#1 0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#2 0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#3 0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "", ch=0x7fffffffd97c L"缀\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#4 0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#5 0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#6 0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#7 0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#8 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
(gdb) n
handle_ctrlc_signal (sig=-737690969) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1533
(gdb) bt
#0 handle_ctrlc_signal (sig=-737690969) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1533
#1 <signal handler called>
#2 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3 0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4 0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5 0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\b ", ch=0x7fffffffd97c L" \001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6 0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7 0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8 0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9 0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
c
n
#0 handle_ctrlc_signal (sig=2) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1537
#1 <signal handler called>
#2 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd8b0, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3 0x000055555568cedd in read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:315
#4 0x000055555568d13e in el_wgetc (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:433
#5 0x000055555568cca5 in read_getcmd (el=0x555555c58110, cmdnum=0x7fffffffd97b "\bt", ch=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:246
#6 0x000055555568d534 in el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:578
#7 0x0000555555682e81 in el_gets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/eln.c:74
#8 0x0000555555677b65 in readline (p=0x555555c85400 "mysql> ") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/readline.c:441
#9 0x000055555558d14f in read_and_execute (interactive=true) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:2315
#10 0x000055555558bd9e in main (argc=5, argv=0x555555c4a060) at /home/anel/workspace/mariadb/mysql-server/client/mysql.cc:1447
execute_query is not invoked !
read_char (el=0x555555c58110, cp=0x7fffffffd97c L"t\001\xffffffff") at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:316
case SIGINT: │
│325 goto end; end: return (int)num_read; │ │373 }
el_wgets (el=0x555555c58110, nread=0x7fffffffda00) at /home/anel/workspace/mariadb/mysql-server/cmd-line-utils/libedit/read.c:585
terminal__flush(el); /* flush any buffered output */ │
│705 /* make sure the tty is set up correctly */
(gdb) n
rl_signal_handler (sig=0) at extra/readline/signals.c:118
(gdb) bt
#0 rl_signal_handler (sig=0) at extra/readline/signals.c:118
#1 <signal handler called>
#2 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#3 0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#4 0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#5 0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#6 0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#7 0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#8 0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#9 0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#10 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291
(gdb) n
Program received signal SIGINT, Interrupt.
0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
(gdb) bt
#0 0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
#1 0x0000555555626854 in rl_signal_handler (sig=2) at extra/readline/signals.c:184
#2 <signal handler called>
#3 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#4 0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#5 0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#6 0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#7 0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#8 0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#9 0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#10 0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#11 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291
(gdb) n
handle_ctrlc_signal (sig=32767) at client/mysql.cc:1310
(gdb) bt
#0 handle_ctrlc_signal (sig=32767) at client/mysql.cc:1310
#1 <signal handler called>
#2 0x00007ffff62f214d in __GI___sigprocmask (how=2, set=0x7fffffffd370, oset=0x0)
at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
#3 0x0000555555626854 in rl_signal_handler (sig=2) at extra/readline/signals.c:184
#4 <signal handler called>
#5 0x00007ffff7bc734e in __libc_read (fd=0, buf=0x7fffffffd9cb, nbytes=1) at ../sysdeps/unix/sysv/linux/read.c:27
#6 0x00005555556299c0 in rl_getc (stream=0x7ffff669ea00 <_IO_2_1_stdin_>) at extra/readline/input.c:466
#7 0x000055555562998b in rl_read_key () at extra/readline/input.c:446
#8 0x000055555561268c in readline_internal_char () at extra/readline/readline.c:482
#9 0x00005555556127c4 in readline_internal_charloop () at extra/readline/readline.c:543
#10 0x00005555556127f0 in readline_internal () at extra/readline/readline.c:557
#11 0x0000555555612253 in readline (prompt=0x555555bf76a8 "MariaDB [(none)]> ") at extra/readline/readline.c:320
#12 0x00005555555b5040 in read_and_execute (interactive=true) at client/mysql.cc:2154
#13 0x00005555555b3ad4 in main (argc=1, argv=0x555555bee2b0) at client/mysql.cc:1291
Write own patch with handling signal(SIGINT)
and in signal handler (longjump or better readline library support)
readline library functions
passing sigint
Playing with readline:
Create ~/.inputrc
.
There is global inputrc
in /etc/inputrc
.
See info rluserman
and man readline
(3-library calls(functions within program libraries)
locate readline.so
Incremental C-r, non-incremental M(meta-Alt)-p search
List symbols from dynamic object files nm -D /bin/bash |grep readline
in general list conente of library (.so) with nm filename
Install readline development libraries sudo apt-get install libreadline-dev
Compiler(header-> -Idir
or CPATH
environment variables "include-paths", in /usr/include/
there is a readline/readline.h
and 'math.h', since header filename is know only directory is needed).
Include paths of "Gnu preprocessor " cpp -v
Linker(libraries are needed to resolve external dependencies, "libraries-path", -Ldir
or LIBRARY_PATH
and library name -lmath
-> linker needs to know directory and library name)
GCC uses the following environment variables:
/usr/lib
for example)
Compiling:
gcc -c readline_anel.c
Linking:
gcc -o read readline_anel.o -lreadline -g -v
or:
gcc readline_anel.c -o read -lreadline -g -v
$file readline_anel.c
readline_anel.c: C source, ASCII text
$ file read
read: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=2b16e494bef187efefeaa865f7b56873ec9202b2, with debug_info, not stripped
$file readline_anel.o
readline_anel.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
List symbol table of object files:
$ nm readline_anel.o
U add_history
U free
U _GLOBAL_OFFSET_TABLE_
0000000000000000 b line_read
000000000000006f T main
U printf
U readline
0000000000000000 T rl_gets
Object dump dissablem: objdump --disassemble readline_anel.o
or : objdump --disassemble read
, readelf: readelf --sections readline_anel.o
List dynamic-ink libraries utility ldd read
examines exectuable and list of shared libraries it needs.
make --help
Make consists of target, list of pre-requisites and commands
<stdio.h>
should be included before readline.h
RL_READLINE_VERSION in hex format
new object types, all pointers to functions.
gcc manual
readline library
global offset table -got
Raised PR #1308 in mariadb server
This issue is analysis of PR#703. Short notes:
Inspection:
No support for windows yet
New signal and signal handler
signal(SIGINT, handle_ctrlc_signal);
Added functions
void handle_ctrlc_signal(int sig)
:static void kill_query(const char *reason)
->new functionstatic void init_connection_options(MYSQL *mysql)
:sql_real_connect()
sql_real_connect()
:opt_plugin_dir(MYSQL_PLUGIN_DIR)
,opt_protocol(MYSQL_OPT_PROTOCOL)
,opt_default_auth(MYSQL_DEFAULT_AUTH)
,shared_mememory_base_name (for win32-MYSQL_SHARED_MEMORY_BASE_NAME)
,MYSQL_OPT_CONNECT_ATTR_RESET
,MYSQL_OPT_CONNECT_ATTR_ADD
.static inline void reset_prompt(char *in_string, bool *ml_comment);
Variable
size_t nread;
-> unused variable