Intelligence without ambition is a bird without wings.

2016-09-02
gdb-指定源文件搜索

通过set substitute-path(优先使用)

set substitute-path from to

路径替换,适用于debug中的路径是绝对路径

通过directory命令

directory dirname ...

适用于debug中的路径是相对路径

参考

  1. https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Path.html#Source-Path
阅读此文

2016-09-02
gcc-生成可以宏调试信息

1
2
3
4
5
6
7
8
9
10
11
12
13
// Author: QianChenglong <qian_cheng_long@163.com>
// Create: 2016-09-01 17:51:59

#include <iostream>

#define STR "Hello world!\n"

int main(int argc, char* argv[])
{

std::cout << STR;

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
gcc main.cpp -ggdb3
gdb a.out
(gdb) list
1 // Author: QianChenglong <qian_cheng_long@163.com>
2 // Create: 2016-09-01 17:51:59
3
4 #include <iostream>
5
6 #define STR "Hello world!\n"
7
8 int main(int argc, char* argv[])
9 {
10 std::cout << STR;
(gdb) print STR
$1 = "Hello world!\n"
(gdb) macro expand STR
expands to: "Hello world!\n"

参考

  1. https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Debugging-Options.html#Debugging-Options
阅读此文

2016-09-01
source\_posts\判断库是否带有调试信息

通过查看符号表中是否带有调试信息

1
2
[I] wallace@centos:/m/s/W/p/B/p/B/t/m/lib64_debug-true (dev)> nm --debug-syms libmysqlclient.so|grep "\.debug_info"
0000000000000000 N .debug_info

通过file

not stripped => Debug
stripped => Release

动态库

1
2
[I] wallace@centos:/m/s/W/p/B/p/B/t/m/lib64_debug (dev)> file libmysqlclient.so
libmysqlclient.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xdb01cca2e0dba437512a3066296c995de3e2db72, not stripped

静态库

1
2
3
4
[I] wallace@centos:/m/s/W/p/B/p/B/t/m/lib64_debug (dev)> ar t libmysqlclient.a client.c.o
[I] wallace@centos:/m/s/W/p/B/p/B/t/m/lib64_debug (dev)> ar x libmysqlclient.a client.c.o
[I] wallace@centos:/m/s/W/p/B/p/B/t/m/lib64_debug (dev)> file client.c.o
client.c.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

参考

  1. http://unix.stackexchange.com/questions/2969/what-are-stripped-and-not-stripped-executables-in-unix
阅读此文

2016-08-31
hash为什么最好使用素数来作为桶大小

如何使用合数的的话?产生冲突的概率更大!如10=2*5(合数本身的性质)

阅读此文

2016-08-31
名人堂

Alan Jay Perlis(艾伦·杰·佩利)

  • ALGOL 60

  • 首届图灵奖

Charles Antony Richard Hoare(查尔斯·安东尼·理查德·霍尔)

关键字

Sir Maurice Vincent Wilkes(莫里斯·文森特·威尔克斯)

关键字

  • 世界上第一台存储程序式电子计算机EDSAC(第一台冯诺依曼体系结构计算机)

  • 变址,宏指令,微程序,子例程,高速缓冲存储器

参考

  1. https://en.wikipedia.org/wiki/Tony_Hoare
阅读此文

2016-08-26

产生原因之一

该连接超过空闲等待时间(wait_timeout,默认8小时),服务端主动关闭该连接,此时客户端再执行query,则mysql client返回该错误。

研究

  1. 设置mysql wait_timeout为5s,方便复现

    set global wait_timeout=5;
    
  2. 客户端首先建立好连接

    18:07:19.831124 IP localhost.46740 > localhost.mysql: Flags [S], seq 424450064, win 43690, options [mss 65495,sackOK,TS val 357860862 ecr 0,nop,wscale 7], length 0
    18:07:19.831158 IP localhost.mysql > localhost.46740: Flags [S.], seq 2970334829, ack 424450065, win 43690, options [mss 65495,sackOK,TS val 357860862 ecr 357860862,nop,wscale 7], length 0
    18:07:19.831179 IP localhost.46740 > localhost.mysql: Flags [.], ack 1, win 342, options [nop,nop,TS val 357860862 ecr 357860862], length 0
    ...
    
  3. 5s后,发现服务端主动断开连接(关闭了),服务端关闭了写通道

    18:07:24.902120 IP localhost.mysql > localhost.46740: Flags [F.], seq 233, ack 704, win 350, options [nop,nop,TS val 357865933 ecr 357860968], length 0
    18:07:24.943661 IP localhost.46740 > localhost.mysql: Flags [.], ack 234, win 342, options [nop,nop,TS val 357865974 ecr 357865933], length 0
    
    [I] wallace@centos:/m/s/W/p/B/p/b/B/judge_server> ss -aon|grep 3306
    tcp    CLOSE-WAIT 1      0      127.0.0.1:46739              127.0.0.1:3306                timer:(keepalive,120min,0)
    tcp    LISTEN     0      80       :::3306                 :::*                  
    tcp    FIN-WAIT-2 0      0      ::ffff:127.0.0.1:3306               ::ffff:127.0.0.1:46739               timer:(timewait,56sec,0)
    
    观看连接状态,发现服务端socket状态已变为`FIN-WAIT-2`,60s后超时关闭,服务端socket关闭连接后;
    此后客户端进入了半连接状态,若客户端继续发送数据,则会收到`RST`,客户端读返回-1,errno=ECONNRESET,
    `mysql connector c`会将该错误作为`CR_SERVER_LOST`
    
  4. 客户端发送数据

18:13:23.289923 IP localhost.46740 > localhost.mysql: Flags [P.], seq 704:737, ack 234, win 342, options [nop,nop,TS val 358224321 ecr 357865933], length 33
18:13:23.289935 IP localhost.mysql > localhost.46740: Flags [R], seq 2970335063, win 0, length 0
  1. gdb源码跟踪(mysql-connector-c-6.1.5-src)

    sql-common/client.c:957

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    ulong
    cli_safe_read_with_ok(MYSQL *mysql, my_bool read_ok)
    {

    NET *net= &mysql->net;
    ulong len=0;

    MYSQL_TRACE(READ_PACKET, mysql, ());

    if (net->vio != 0)
    len=my_net_read(net); // <= 此调用失败

    if (len == packet_error || len == 0) // len == packet_error 成立
    {
    DBUG_PRINT("error",("Wrong connection or packet. fd: %s len: %lu",
    vio_description(net->vio),len));
    #ifdef MYSQL_SERVER
    if (net->vio && (net->last_errno == ER_NET_READ_INTERRUPTED))
    return (packet_error);
    #endif /*MYSQL_SERVER*/
    end_server(mysql);
    set_mysql_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
    CR_NET_PACKET_TOO_LARGE: CR_SERVER_LOST, unknown_sqlstate); // 设置错误代码为:CR_SERVER_LOST
    return (packet_error);
    }
    Breakpoint 3, cli_safe_read_with_ok (mysql=0xb99e80, read_ok=0 '\000') at /media/sf_E_DRIVE/Soft/mysql-connector/mysql-connector-c-6.1.5-src/sql-common/client.c:976
    976     set_mysql_error(mysql, net->last_errno == ER_NET_PACKET_TOO_LARGE ?
    (gdb) bt
    #0  cli_safe_read_with_ok (mysql=0xb99e80, read_ok=0 '\000') at /media/sf_E_DRIVE/Soft/mysql-connector/mysql-connector-c-6.1.5-src/sql-common/client.c:976
    #1  0x00000000004183da in cli_safe_read (mysql=0xb99e80) at /media/sf_E_DRIVE/Soft/mysql-connector/mysql-connector-c-6.1.5-src/sql-common/client.c:1047
    #2  0x0000000000421f0b in cli_read_query_result (mysql=0xb99e80) at /media/sf_E_DRIVE/Soft/mysql-connector/mysql-connector-c-6.1.5-src/sql-common/client.c:4711
    #3  0x000000000042275c in mysql_real_query (mysql=0xb99e80, query=0x59c2db "SELECT age, name FROM test.a", length=28)
        at /media/sf_E_DRIVE/Soft/mysql-connector/mysql-connector-c-6.1.5-src/sql-common/client.c:4802
    #4  0x000000000040ad7b in mysql::Connection::Query (this=0xba01d0, sql=...) at Beme4wdServer/lily/mysql/connection.cpp:89
    

参考

  1. http://dev.mysql.com/doc/refman/5.6/en/mysql-real-query.html
  2. https://dev.mysql.com/doc/refman/5.6/en/gone-away.html
阅读此文

2016-08-26

  • 2016-08-26 stdarg.h

    在封装redisCommand中,传递va_list后,执行后,重试逻辑,再次传递va_list,内存崩溃。

阅读此文

2016-08-17
git

创建仓库

  • 从一个现有仓储建立纯仓库

    git clone --bare ssh://git@github.com:22/QianChenglong/home.git home.git
    
  • 从.git目录复制https://git.wiki.kernel.org/index.php/GitFaq#How_do_I_make_existing_non-bare_repository_bare.3F

    scp -rv .git dev2:~/git/Beme4wdServer.git
    cd Beme4wdServer.git/
    git config --bool core.bare true
    
  • 从本地目录

    git clone file:///path/to/repo.git/
    
  • 修改远程URL

    git remote set-url origin ssh://wallace@dev2:36000/~/git/home.git
    
  • 查看远程信息

    git remote -v
    git remote show origin
    
  • 从远程仓库取数据,不合并分支

    git fetch [remote-name]
    
  • push所有分支和tag,并跟踪

    git push --all origin -u
    

update-index

  • 添加可执行权限

    git update-index --chmod=+x config_server
    
  • 标识已纳入版本的文件不必跟踪变化

    git update-index --assume-unchanged <files>
    git update-index --no-assume-unchanged <files>(撤销)
    git ls-files -v(小写字母说明设置了该标志位)
    

分支

  • 查看所有分支

    git branch
    
  • 查看分支详情,最后一次commit

    git branch -v
    
  • 查看当前已经合并的分支

    git branch --merged
    
  • 查看当前没有合并的分支

    git branch --no-merged
    
  • 新建分支

    git branch testing
    
  • 切换分支

    git checkout testing
    
  • 新建分支并切换

    git checkout -b issue53
    
  • 删除分支

    git branch -d hotfix
    
  • 设置跟踪分支

    git branch --set-upstream-to=origin/master master
    

子模块

  • 添加模块

    git submodule add ssh://wallace@dev2.beme.com:36000/~/git/ssh.git .ssh
    
  • 修改url

    vim .gitmodule
    git submodule sync
    
  • 初始化

    git submodule init
    
  • 更新

    git submodule update
    

管理

  • 取消未暂存的修改

    git checkout -- <file>...
    

reset

功能:

  • 从HEAD拷贝到INDEX(重置暂存区),若指定PATH(文件名),则只操作指定文件(这种情况下,最好使用git checkout -- <paths>)

    git reset
    
  • 将HEAD指定到COMMIT

    git reset [<mode>] <commit>
    
    • –mixed [默认] INDEX同HEAD一起更新到<commit>,WORK不变

    • –soft INDEX,WORK保持不变,HEAD更新到<commit>

    • –hard INDEX,WORK同HEAD一起更新到<commit>

revert

恢复到指定commit,是复制指定commit并使HEAD指向它

commit

  • 重做上次提交,并使用上次提交信息

    git commit --amend --no-edit
    

rm

  • 从INDEX删除,但保留工作目录里面的

    git rm --cached <paths>
    
  • 强制删除已修改已暂存的文件(当前暂存区与上次提交的不一样)

    git rm -f <paths>
    
  • 从INDEX,WORK中删除

    git rm <paths>
    

diff

  • 查看当前版本与上一版本的差异

    git diff HEAD~1 HEAD functions/fish_prompt.fish
    
  • 查看暂存版本与工作目录中的差异

    git diff
    
  • 查看暂存与上一次提交的差异

    git diff --cached
    
  • 查看commit之间的差异

    git diff <commit1> <commit2> <path>
    

config

  • 配置解包内存

    git config --global pack.windowMemory 256m
    
  • 查看配置

    git config --list
    

实例

  • 同步home

    git init
    git remote add origin ssh://wallace@112.74.81.30:36000/~/git/home.git
    git fetch
    git reset --hard origin/master
    
  • 初始化并递归更新submodule

    git submodule update --init --recursive
    
阅读此文

2016-06-02
firewalld

  • 停止防火墙

    systemctl stop firewalld.service

  • 禁用防火墙

    systemctl disable firewalld.service

  • 放行端口

    firewall-cmd –permanent –add-port=80/tcp
    firewall-cmd –reload

阅读此文

2016-05-31
linux-时间片

查看时间片

[I] ~/p/B/p/c/s/time cat /proc/sys/kernel/sched_latency_ns
12000000
阅读此文