zoukankan      html  css  js  c++  java
  • gdb 重定位源文件目录

    问题

    在进行 gdb 调试的时候,有时候,我们会遇到使用的符号表对应的源文件目录和实际机器上的源文件目录不一致的情况。

    在这个时候,在 gdb 内输入layout src命令并不能显示出对应的源文件

    解决方案

    我们可以通过 gdb 的set substitute-path /path/to/symbol/source/dir /path/to/actual/source/dir重定位源文件目录解决

    实践方法

    1. 首先写个测试程序rcvbuf.c
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <linux/netlink.h>
    #include <unistd.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
            int sockfd;
            int32_t buflen;
            size_t len = sizeof(buflen);
            int ret;
    
            sockfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_AUDIT);
            if (sockfd < 0) {
                    fprintf(stderr, "create socket fail
    ");
                    return -1;
            }
    
            ret = getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &buflen, &len);
            if (ret < 0) {
                    fprintf(stderr, "getsockopt fail
    ");
            }
    
            printf("SO_RCVBUF is %u
    ", buflen);
            printf("sizelen is %lu
    ", len);
    out:
            close(sockfd);
            return ret;
    }
    
    1. 编译带符号表的可执行文件,并将源文件移动到新目录
    $ gcc -g -o rcvbuf rcvbuf.c
    $ mv /path/to/current/rcvbuf.c /path/to/another/rcvbuf.c
    
    1. gdb 调试可执行文件
    $ gdb rcvbuf
    (gdb) b main
    (gdb) r
    (gdb) layout src  // 这是看不到源文件
    (gdb) set substitute-path /path/to/current /path/to/another  // 这是可以看到源文件
    

    本文来自博客园,作者:Legend_Lone,转载请注明原文链接:https://www.cnblogs.com/sun-ye/p/15151813.html

  • 相关阅读:
    table标签去除默认边框
    自定义矢量图
    ClickJacking(点击劫持)
    css 字体不撑开默认块级元素问题
    meate 标签使用介绍
    intellij IDEA15 设置背景颜色
    JS 浮点数运算丢失精度解决方案
    IDEA 滚动条跳动问题
    JS
    异步变同步
  • 原文地址:https://www.cnblogs.com/sun-ye/p/15151813.html
Copyright © 2011-2022 走看看