VoidStack


VoidStack

gdb常用命令

0 条评论 工具 gdb FairyFar

加载core

gdb oSan core.XXXX

调试带命令行参数程序

gdb --args ./prog arg1 arg2

使用源代码对照调试窗口

在有源代码的环境下,在gdb调试状态,使用ctrl + X,A可以切换到源代码对照调试窗口。
gdb
此时会分上下屏显示源代码和命令窗口,使用以下命令可以将设置当前键盘操作窗口:

(gdb) focus src
(gdb) focus cmd

冻结当前线程之外其它线程

在多线调试环境时,有时为了单步调试时,避免被其它线程打断,可以冻结其它线程:

(gdb) set scheduler-locking on

解冻其它线程:

(gdb) set scheduler-locking off

数据断点

为了跟踪某块内存在是哪里被修改了,可以设置数据断点,例如,假设希望在0x12345678这个4字节的内存区域在被修改时中断,可以:

(gdb) watch *(int*)0x12345678

那么,当上述4字节内存区域被修改时,触发中断。

条件断点

当指定的条件满足时break。例如,假设希望osan_lpc_submit_io函数在满足p_io->lunset_id为0时中断:

(gdb) b osan_lpc_submit_io if p_io->lunset_id==0

格式化显示

按十六进制打印变量val:

(gdb) p/x val

打印数组多个元素的值:

(gdb) p *array@len

按二进制打印变量val:

(gdb) p/t val

格式化打印结构体:

(gdb) set print pretty on

反汇编

(gdb) set disassembly-flavor intel  # 使用intel格式,默认为AT&T格式。
(gdb) disassemble main  # 反汇编
(gdb) disassemble /m main  # 反汇编与源码对照

gdb启动时执行调试命令

例如,gdb启动时给main函数打断点“b main”:

gdb ./test -ex "b main"

gdb启动时执行调试命令脚本

假设有一个脚本文件~/my_gdb,内容如下:

b main
b start_fun
r

gdb启动时执行该脚本

gdb ./test -e ~/my_gdb

gdbinit(gdb初始化脚本)

分三个级别:

/etc/gdbinit:
System-wide initialization file. It is executed unless user specified GDB option "-nx" or "-n".
    
~/.gdbinit:
User initialization file. It is executed unless user specified GDB options "-nx", "-n" or "-nh".
    
./.gdbinit:
Initialization file for current directory.

gdbinit应用举例

set scheduler-locking on和set scheduler-locking off这样的gdb指令有点长,如果经常使用不太方便,我们可定义一个短一点的命令替代之。
编辑~/.gdbinit文件,增加内容:

def lkon
    set scheduler-locking on
end
def lkoff
    set scheduler-locking off
end

这样以后就可以使用lkon和lkoff代替前面的长命令了。

查看所用线程堆栈信息

(gdb) thread apply all bt

结果输出到文件

(gdb) set logging file <file name>
(gdb) set logging on
(gdb) 。。。。。。
(gdb) set logging off

gdb非交互式

gdb -q --batch --ex "set height 0" --ex "bt" [core] [exe]

不分页

(gdb) set height 0 

打印长文本

(gdb) set print elements 0 
(gdb) show print elements 

Dump内存区到文件:

(gdb) dump binary memory <文件名> 内存起始地址 内存结束地址

捕捉异常

gdb> catch throw
catch catch

当异常抛出时中断。

加速gdb调试so时的加载速度

如果gdb index很大,那么gdb调试时,load时间会很长,那么可以在编译时使用以下命令,把gdb index追加到.so文件,这样在gdb调试时,减少了index计算时间。

gdb-add-index libtest.so

strip

去除release版本程序的符号库。

strip sql/mysqld

Linux 错误码(errno)

0 条评论 系统 Linux FairyFar

一、错误对照表

errno 0 :     Success
errno 1 :     Operation not permitted
errno 2 :     No such file or directory
errno 3 :     No such process
errno 4 :     Interrupted system call
errno 5 :     Input/output error
errno 6 :     No such device or address
errno 7 :     Argument list too long
errno 8 :     Exec format error
errno 9 :     Bad file descriptor
errno 10 :    No child processes
errno 11 :    Resource temporarily unavailable
errno 12 :    Cannot allocate memory
errno 13 :    Permission denied
errno 14 :    Bad address
errno 15 :    Block device required
errno 16 :    Device or resource busy
errno 17 :    File exists
errno 18 :    Invalid cross-device link
errno 19 :    No such device
errno 20 :    Not a directory
errno 21 :    Is a directory
errno 22 :    Invalid argument
errno 23 :    Too many open files in system
errno 24 :    Too many open files
errno 25 :    Inappropriate ioctl for device
errno 26 :    Text file busy
errno 27 :    File too large
errno 28 :    No space left on device
errno 29 :    Illegal seek
errno 30 :    Read-only file system
errno 31 :    Too many links
errno 32 :    Broken pipe
errno 33 :    Numerical argument out of domain
errno 34 :    Numerical result out of range
errno 35 :    Resource deadlock avoided
errno 36 :    File name too long
errno 37 :    No locks available
errno 38 :    Function not implemented
errno 39 :    Directory not empty
errno 40 :    Too many levels of symbolic links
errno 41 :    Unknown error 41
errno 42 :    No message of desired type
errno 43 :    Identifier removed
errno 44 :    Channel number out of range
errno 45 :    Level 2 not synchronized
errno 46 :    Level 3 halted
errno 47 :    Level 3 reset
errno 48 :    Link number out of range
errno 49 :    Protocol driver not attached
errno 50 :    No CSI structure available
errno 51 :    Level 2 halted
errno 52 :    Invalid exchange
errno 53 :    Invalid request descriptor
errno 54 :    Exchange full
errno 55 :    No anode
errno 56 :    Invalid request code
errno 57 :    Invalid slot
errno 58 :    Unknown error 58
errno 59 :    Bad font file format
errno 60 :    Device not a stream
errno 61 :    No data available
errno 62 :    Timer expired
errno 63 :    Out of streams resources
errno 64 :    Machine is not on the network
errno 65 :    Package not installed
errno 66 :    Object is remote
errno 67 :    Link has been severed
errno 68 :    Advertise error
errno 69 :    Srmount error
errno 70 :    Communication error on send
errno 71 :    Protocol error
errno 72 :    Multihop attempted
errno 73 :    RFS specific error
errno 74 :    Bad message
errno 75 :    Value too large for defined datatype
errno 76 :    Name not unique on network
errno 77 :    File descriptor in bad state
errno 78 :    Remote address changed
errno 79 :    Can not access a needed sharedlibrary
errno 80 :    Accessing a corrupted sharedlibrary
errno 81 :    .lib section in a.out corrupted
errno 82 :    Attempting to link in too manyshared libraries
errno 83 :    Cannot exec a shared librarydirectly
errno 84 :    Invalid or incomplete multibyte orwide character
errno 85 :    Interrupted system call should berestarted
errno 86 :    Streams pipe error
errno 87 :    Too many users
errno 88 :    Socket operation on non-socket
errno 89 :    Destinationaddress required
errno 90 :    Message too long
errno 91 :    Protocol wrong type for socket
errno 92 :    Protocol not available
errno 93 :    Protocol not supported
errno 94 :    Socket type not supported
errno 95 :    Operation not supported
errno 96 :    Protocol family not supported
errno 97 :    Address family not supported byprotocol
errno 98 :    Address already in use
errno 99 :    Cannot assign requested address
errno 100 :   Network is down
errno 101 :   Network is unreachable
errno 102 :   Network dropped connection onreset
errno 103 :   Software caused connection abort
errno 104 :   Connection reset by peer
errno 105 :   No buffer space available
errno 106 :   Transport endpoint is alreadyconnected
errno 107 :   Transport endpoint is notconnected
errno 108 :   Cannot send after transportendpoint shutdown
errno 109 :   Too many references: cannot splice
errno 110 :   Connection timed out
errno 111 :   Connection refused
errno 112 :   Host is down
errno 113 :   No route to host
errno 114 :   Operation already in progress
errno 115 :   Operation now in progress
errno 116 :   Stale NFS file handle
errno 117 :   Structure needs cleaning
errno 118 :   Not a XENIX named type file
errno 119 :   No XENIX semaphores available
errno 120 :   Is a named type file
errno 121 :   Remote I/O error
errno 122 :   Disk quota exceeded
errno 123 :   No medium found
errno 124 :   Wrong medium type
errno 125 :   Operation canceled
errno 126 :   Required key not available
errno 127 :   Key has expired
errno 128 :   Key has been revoked
errno 129 :   Key was rejected by service
errno 130 :   Owner died
errno 131 :   State not recoverable
errno 132 :   Operation not possible due toRF-kill
errno 133 :   Unknown error 133
errno 134 :   Unknown error 134
errno 135 :   Unknown error 135
errno 136 :   Unknown error 136
errno 137 :   Unknown error 137
errno 138 :   Unknown error 138
errno 139 :   Unknown error 139

二、使用C语言将errno转换为描述文字

#include <errno.h>
#include <string.h>
#include <stdio.h>
 
int main()
{
  int i;
  for (i = 0; i < 140; ++i)
  {
    printf("errno %d :\t\t%s\n",i,strerror(i));
  }
  return 0;
}

三、Linux终端errno转换为描述文字

Linux Shell没有专门命令转换errno,不过我们可以使用Python进行查询:

[yz@MiWiFi-R4A-srv ~]$ python
>>> import os
>>> import errno
>>> print(os.strerror(11))
Resource temporarily unavailable

DokuWiki配置秘笈

0 条评论 杂谈 wiki FairyFar

1. 存档目录支持中文字符

第1处修订:
修改文件dokuwiki/conf/local.php,新增一行配置:

$conf['fnencode'] = 'utf-8';

第2处修订:
修改文件dokuwiki/inc/pageutils.php,以下函数:

function utf8_encodeFN($file,$safe=true){
    global $conf;
    if($conf['fnencode'] == 'utf-8') return $file;

    if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
        return $file;
    }
    ......
}

修改为:

function utf8_encodeFN($file,$safe=true){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
    if($conf['fnencode'] == 'utf-8') return iconv('UTF-8','GB2312',$file);

    if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
        return $file;
    }
    ......
}

第3处修订:
以下函数:

function utf8_decodeFN($file){
    global $conf;
    if($conf['fnencode'] == 'utf-8') return $file;

    if($conf['fnencode'] == 'safe'){
        return SafeFN::decode($file);
    }

    return urldecode($file);
}

修改为:

function utf8_decodeFN($file){
    global $conf;
    //if($conf['fnencode'] == 'utf-8') return $file;
    if($conf['fnencode'] == 'utf-8') return iconv('GB2312','UTF-8',$file);

    if($conf['fnencode'] == 'safe'){
        return SafeFN::decode($file);
    }

    return urldecode($file);
}

2. 修复词条时间乱码问题

修改dokuwiki/inc/common.php文件,以下函数:

function dformat($dt = null, $format = '') {
    global $conf;

    if(is_null($dt)) $dt = time();
    $dt = (int) $dt;
    if(!$format) $format = $conf['dformat'];

    $format = str_replace('%f', datetime_h($dt), $format);
    return strftime($format, $dt);
}

修改为:

function dformat($dt = null, $format = '') {
    global $conf;

    if(is_null($dt)) $dt = time();
    $dt = (int) $dt;
    if(!$format) $format = $conf['dformat'];
    // add by fairyfar
    if($format=='%f') return str_replace('%f', datetime_h($dt), $format);

    $format = str_replace('%f', datetime_h($dt), $format);
    return strftime($format, $dt);
}