zoukankan      html  css  js  c++  java
  • PG-了解gdb调试

    GDB 调试

    先要在编译PostgreSQL时打开enable-debug

    1. 1查看数据库进程

    -- 查看进程号,在数据库中执行以下语句
    select pg_backend_pid(); -- pid = 3715
    select 1;
    

    1.2 gdb 调试

    启动gdb进程

    # gdb attach 进程号
    gdb attach 3715
    

    设置相应的断点进行单步调试

    # 输入b命令的话,在ExecResult可以设置断点
    (gdb) b ExecResult
    

    再开启一个psql会话并执行select 1

    select 1;
    

    返回GDB窗口,输入 c 命令,停留在断点上

    (gdb) c
    

    在gdb里执行"c"命令。执行了以后,就会在ExecResult 处停止

    gdb查看堆栈,输入bt

    (gdb) bt
    

    退出gdb的话可以用quit

    (gdb) quit
    

    附录

    GDB常用命令

    命令 简写形式 说明
    list l 查看源码
    backtrace bt, where 打印函数栈信息
    next n 执行下一行
    step s 一次执行一行,遇到函数会进入
    finish 运行到函数结束
    continue c 继续运行
    break b 设置断点
    info breakpoints 显示断点信息
    delete d 删除断点
    print p 打印表达式的值
    run r 启动程序
    until u 执行到指定行
    info i 显示信息
    help h 帮助信息

    脚本

    #!/bin/sh
    
    # Usage: gdblive [ arguments to grep output of ps ]
    
    cd $HOME
    
    # tee /dev/tty is for user to see the set of procs considered
    if [ $# -eq 0 ]
    then
        PROCS=`ps auxww | 
            grep postgres: | 
            grep -v -e 'grep postgres:' -e 'postgres: stats' -e 'postgres: writer' -e 'postgres: wal writer' -e 'postgres: checkpointer' -e 'postgres: archiver' -e 'postgres: logger' -e 'postgres: autovacuum' | 
            tee /dev/tty | 
            awk '{print $2}'`
    else
        PROCS=`ps auxww | 
            grep postgres: | 
            grep -v -e 'grep postgres:' -e 'postgres: stats' -e 'postgres: writer' -e 'postgres: wal writer' -e 'postgres: checkpointer' -e 'postgres: archiver' -e 'postgres: logger' -e 'postgres: autovacuum' | 
            grep $@ | 
            tee /dev/tty | 
            awk '{print $2}'`
    fi
    
    if [ `echo "$PROCS" | wc -w` -eq 1 ]
    then
        exec gdb $PGINSTROOT/bin/postgres -silent "$PROCS"
    else
        exec gdb $PGINSTROOT/bin/postgres -silent
    fi
    

    参考文档

    https://wiki.postgresql.org/wiki/Pgsrcstructure

  • 相关阅读:
    .Net常见面试题整理(一)——值类型和引用类型
    c#字符串常见操作
    sealed,new,virtual,abstract与override
    c#好的程序员必须掌握的编码习惯
    c#区分传值调用 传引用调用。
    C# const和readonly的区别
    .Net常见面试题整理(二)——装箱和拆箱
    C#Equals()和运算符==的区别
    private,protected,public和internal的区别
    2013应届毕业生“数码视讯”校招应聘总结
  • 原文地址:https://www.cnblogs.com/binliubiao/p/15387845.html
Copyright © 2011-2022 走看看