AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 739162
Accepted
L_R
L_R
Asked: 2023-03-09 16:34:51 +0800 CST2023-03-09 16:34:51 +0800 CST 2023-03-09 16:34:51 +0800 CST

GDB 无法下载 math.h 的调试信息

  • 772

我有一个使用math.h函数的简单时钟程序。我目前在Kubuntu 21.10,GCC版本是(Ubuntu 12.2.0-3ubuntu1) 12.2.0,GDB版本是(Ubuntu 12.1-3ubuntu2) 12.1。

程序源代码(虽然可能不需要):

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include "conio.h"
#include <sys/ioctl.h>
#include <stdlib.h>

#define PI 3.14159265358979323846264338327950288419716939937510
#define RAD_90 1.570796 // precomputed value of 90 degrees in radians
#define RAD_30 0.523599 // precomputed value of 30 degrees in radians
#define RAD_6 0.104720 // precomputed value of 6 degree in radians
#define RAD_1 0.017453 // precomputed value of 1 degree in radians

#define X 0 // x co-ordinate in array
#define Y 1 // y co-ordinate in array

int COLUMNS, ROWS;

#define CLOCK_RADIUS (COLUMNS/2)-1

#define FPS 24
#define MOVE_TO_HOME() (printf("\033[H"))
#define CLEAR_TERMINAL_SCREEN() (printf("\033[2J"))
#define cls() (CLEAR_TERMINAL_SCREEN())

void die(const char *s) {
    cls();
    printf("clock: error: %s: ", s);
    fflush(stdout);
    perror(NULL);
    fflush(stderr);
    exit(1);
}

char **output/*[ROWS][COLUMNS*2]*/;
struct tm *t = NULL;

void get_window_size(int *rows, int *cols) {;
    struct winsize ws;

    if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
        if(write(STDOUT_FILENO, "\x1b[999C\x1b[999B", 12) != 12) die("write");
        fflush(stdout);

        char buf[32];
        unsigned int i = 0;

        if(write(STDOUT_FILENO, "\x1b[6n", 4) != 4) die("write");
        printf("\r\n");
        fflush(stdout);

        while(i < (sizeof(buf)-1)) {
            if(read(STDIN_FILENO, &buf[i], 1) != 1) die("read");
            if(buf[i] == 'R') break;
            i++;
        }
        buf[i] = '\0';

        if((buf[0] != '\x1b') || (buf[1] != '[')) die("\\x1b[6n read failure");
        if(sscanf(&buf[2], "%d;%d", rows, cols) != 2) die("sscanf(146)");

        cls();
    } else {
        *cols = ws.ws_col;
        *rows = ws.ws_row;
    }
}

void print_char(char c, int x, int y) {
    if((x >= 0) && (y >= 0) && (x < COLUMNS) && (y < ROWS)) {
        output[y][x*2] = c;
    }
}

double deg_to_rad(int deg) {
    return deg*PI/180;
}

void clear_buffer() {
    for(int i = 0;i < ROWS;i++) {
        memset(output[i], ' ', COLUMNS*2);
    }
    output[ROWS-1][COLUMNS*2] = '\0';
}

void print_buffer() {
    for(int i = 0;i < ROWS;i++) {
        puts(output[i]);
    }
}

void print_circle(char body, int r, int center[]) {
    if(r == 0) {
        print_char(body, center[X], center[Y]);
        return;
    }

    int offset[2], prev_offset[2] = {-1, -1};
    double ang = 0, ang_leap;

    ang_leap = deg_to_rad((1*360)/(2*PI*r));

    if(ang_leap > RAD_1) {
        ang_leap = RAD_1;
    } else if(ang_leap == 0) {
        ang_leap = 0.0001;
    }

    while(ang <= RAD_90) {
        offset[X] = round(sin(ang)*r);
        offset[Y] = round(cos(ang)*r);

        if((offset[X] == prev_offset[X]) && (offset[Y] == prev_offset[Y])) {
            ang += ang_leap;
            continue;
        }

        print_char(body, center[X]+offset[X], center[Y]+offset[Y]); // 1st quadrant

        print_char(body, center[X]-offset[X], center[Y]+offset[Y]); // 2nd quadrant

        print_char(body, center[X]-offset[X], center[Y]-offset[Y]); // 3rd quadrant

        print_char(body, center[X]+offset[X], center[Y]-offset[Y]); // 4th quadrant

        prev_offset[X] = offset[X];
        prev_offset[Y] = offset[Y];

        ang += ang_leap;
    }
}

void print_numbers(int r, int center[]) {
    /*
    *      deg_to_rad(360/NUM_OF_NUMBERS) = ang
    *   => deg_to_rad(360/12) = ang
    *   => ang = deg_to_rad(30)
    *
    *
    *      sin(ang) = P/H
    *   =  sin(ang)*H = P
    *
    *   => offset_x = sin(ang)*r
    *      offset_y = cos(ang)*r
    */

    int offset[2];

    for(int i = 1;i <= 12;i++) {
        offset[X] = round(sin(RAD_30*i)*r);
        offset[Y] = round(cos(RAD_30*i)*r);

        if(i >= 10) {
            print_char((i/10)+'0', center[X]+offset[X], center[Y]-offset[Y]);
            print_char((i%10)+'0', center[X]+offset[X]+1, center[Y]-offset[Y]);
        } else {
            print_char(i+'0', center[X]+offset[X], center[Y]-offset[Y]);
        }
    }
}

void print_hands(int r, int center[], struct tm t) {
    int len, offset[2];
    double ang, sin_value, cos_value;
    char body;

    // second hand
    body = '.';
    len = (r*80)/100;

    ang = t.tm_sec*RAD_6;

    sin_value = sin(ang);
    cos_value = cos(ang);

    for(int i = 0;i <= len;i++) {
        offset[X] = round(sin_value*i);
        offset[Y] = round(cos_value*i);

        print_char(body, center[X]+offset[X], center[Y]-offset[Y]);
    }

    // minute hand
    body = '*';
    len = (r*65)/100;

    ang = deg_to_rad((t.tm_min*6)/*+(t.tm_sec/10)*/); // seconds adjustement causes confusion

    sin_value = sin(ang);
    cos_value = cos(ang);

    for(int i = 0;i <= len;i++) {
        offset[X] = round(sin_value*i);
        offset[Y] = round(cos_value*i);

        print_char(body, center[X]+offset[X], center[Y]-offset[Y]);
    }

    // hour hand
    body = '@';
    len = (r*40)/100;

    ang = deg_to_rad((t.tm_hour*30)+(t.tm_min/2)+(t.tm_sec/120));

    sin_value = sin(ang);
    cos_value = cos(ang);

    for(int i = 0;i <= len;i++) {
        offset[X] = round(sin_value*i);
        offset[Y] = round(cos_value*i);

        print_char(body, center[X]+offset[X], center[Y]-offset[Y]);
    }
}

struct tm *get_time() {
    time_t seconds = time(NULL);

    if(seconds == -1) {
        perror("error while calling function time()");
        return NULL;
    }

    struct tm *tm = localtime(&seconds);

    if(tm == NULL) {
        perror("error while calling function localtime()");
        return NULL;
    }

    return tm;
}

int print_clock() {
    int center[] = {COLUMNS/2, ROWS/2};

    print_circle('.', CLOCK_RADIUS, center);
    print_numbers(CLOCK_RADIUS, center);

    t = get_time();
    if(t == NULL) {
        return 1;
    }

    print_hands(CLOCK_RADIUS, center, *t);

    print_char('@', center[X], center[Y]);

    return 0;
}

void print_centered(int col_size, char *str) {
    int str_len = strlen(str);
    int start_pos = col_size-(str_len/2);
    for(int i = 0;i < start_pos;i++) {
        printf(" ");
    }
    printf("%s", str);
}

int main() {
    get_window_size(&ROWS, &COLUMNS);
    if(ROWS > COLUMNS/2) {
        COLUMNS -= 2;
        COLUMNS /= 2;
        ROWS = COLUMNS;
    } else if(COLUMNS/2 > ROWS) {
        ROWS -= 2;
        COLUMNS = ROWS;
    }
    output = malloc(sizeof(char*)*ROWS);
    for(int i = 0;i < ROWS;i++) {
        output[i] = malloc(sizeof(char)*((COLUMNS*2)+1));
    }
    CLEAR_TERMINAL_SCREEN();

    while(!kbhit()) {
        MOVE_TO_HOME();

        clear_buffer();

        if(print_clock()) {
            return 1;
        }

        print_buffer();

        print_centered(COLUMNS, asctime(t));

        usleep((1000*1000)/FPS);
    }

    for(int i = 0;i < ROWS;i++) {
        free(output[i]);
    }
    free(output);

    return 0;
}

当我使用 编译程序并gcc clock.c -lm -g使用 运行它时gdb ./a.out,我允许gdb从https://debuginfod.ubuntu.com. 我在line 175(使用sin函数)处设置断点,然后输入step并看到此错误:

Breakpoint 1, print_hands (r=17, center=0x7fffffffda20, t=...) at clock.c:175
175             sin_value = sin(ang);
(gdb) step
__sin_fma (x=0.83775999999999995) at ../sysdeps/ieee754/dbl-64/s_sin.c:201
Download failed: Invalid argument.  Continuing without source file ./math/../sysdeps/ieee754/dbl-64/s_sin.c.
201     ../sysdeps/ieee754/dbl-64/s_sin.c: No such file or directory.

如我所见,它无法sin在此处下载功能的调试信息。我尝试在互联网上搜索类似问题,但找不到任何类似问题。

我的问题是什么gdb,我该如何纠正?

debugging
  • 1 1 个回答
  • 15 Views

1 个回答

  • Voted
  1. Best Answer
    steeldriver
    2023-03-09T19:47:35+08:002023-03-09T19:47:35+08:00

    您需要的信息不在 math.h 头文件中,而是在 C 标准库的源代码中。不幸的是,正如Service - Debuginfod文档中所述,Ubuntu Debuginfod 服务目前不提供:

    目前,该服务仅提供 DWARF 信息。有计划让它在未来也索引和服务源代码。

    dir但是,您可以将源代码下载到本地目录,并通过命令(或其-d等效的命令行)将 gdb 指向该目录。前任。给出:

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main(int argc, char *argv[]) {
      double x = atof(argv[1]);
    
      double y = sin(x);
    
      printf("sin(%.3f) = %.3f\n", x, y);
    
      return(0);
    }
    

    然后

    mkdir -p src && cd src 
    apt-get source libc6
    cd ..
    
    gcc -g -o myprog myprog.c -lm
    
    DEBUGINFOD_URLS="https://debuginfod.ubuntu.com" gdb -d ./src/glibc-2.35 myprog
    

    导致以下交互式会话

    GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
    
    [copyright header skipped]
    
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from myprog...
    (gdb) b 8
    Breakpoint 1 at 0x11b8: file myprog.c, line 8.
    (gdb) r 3.14
    Starting program: /home/steeldriver/myprog 3.14
    
    This GDB supports auto-downloading debuginfo from the following URLs:
    https://debuginfod.ubuntu.com
    Enable debuginfod for this session? (y or [n]) y
    Debuginfod has been enabled.
    To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
    
    Breakpoint 1, main (argc=2, argv=0x7fffffffdf98) at myprog.c:8
    8         double y = sin(x);
    (gdb) s
    __sin_avx (x=3.1400000000000001) at ../sysdeps/ieee754/dbl-64/s_sin.c:201
    201     {
    (gdb) 
    
    • 1

相关问题

  • bash & 使用变量来决定何时使用“set”?[关闭]

  • lldb 在 Alpine Linux 上挂起

  • 通过内核跟踪定义故障 SD 卡的状态?

  • 什么是`bash -x`

  • 如何提高linux调试能力,熟练使用linux[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve