我应该使用哪些 gdb 命令来缩小标签“main”中出现分段错误的位置?

2024-04-21

这是我的汇编代码和我的主要子例程。 这是我的宏和常量:

             .text
fmt:         .string "x \t\t ln(x)\n"
sfmt:        .string "%.10lf \t %.10lf\n"
error:       .string "Error"
filename:    .string "input.bin"

             .data
LIM:         .double 0r1.0E-13
zero:        .double 0r0.0
one:         .double 0r1.0
half:        .double 0r0.5

define(i_r,w19)
define(j_r,w20)
define(n_r,w21)
define(fd_r,w22)
define(ln_x,d8)
define(cur_term,d24)
define(n_read,x25)
define(x_j,d26)

BUF_SIZE = 98*8
AT_FDCWD = -100
O_RDONLY = 0
buf_s = 16

          .bss
x_arr:    .skip   BUF_SIZE

fp        .req    x29
lr        .req    x30

          .balign 4
          .global main

这是我的主要子程序:

main:
       stp    fp,lr,[sp,-16]!
       mov    fp,sp

       ldp   fp,lr,[sp],16
       ret

我已经使用过gdb,但是它只指出SIGSEGV信号来自main()中的0x0000000000420358。我怎样才能缩小这个信号来自“主要”的位置? P.S我只知道GDB的基础知识。

GDB 的东西:(更新)

(gdb) x/i $pc
=> 0x420358:    .inst   0x00000000 ; undefined

我不知道这是否有帮助,但这是有效的 C 版本。我将其转换为程序集,因为这就是我需要提交的内容。此外,我们不能使用任何类型的转换器,因为这被认为是作弊。

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>                                                                 //Used for the keyword for flags and other predefined values for the argument on openat,etc.

#define LIM         1.0e-13                                                     
#define DOUBSIZE    100                                                         //There are 97 double values in the binary file
#define buf_size    98*8                                                        
double x[DOUBSIZE];
int main() {
    register int i = 1,j = 0,fd = openat(AT_FDCWD,"input.bin",O_RDONLY);    //int fd = openat(int dirfd,const char *pathname (basically a string),int flags,mode_t mode);
    register double ln_x = 0.0,cur_term;
//double *x;        //(only local variable)                                         //(a local variable so it must be in the stack)only assuming there are 32 double precision values in the binary file
    register long n_read = read(fd,&x,buf_size);                            //reads in 8 bytes(lost the double x[...] in this line since x is now pointing at the buffer

    if(fd == -1) {
        printf("Error!");
        return 0;
    }

    if(n_read == -1) {                                                          //Error checker
        printf("Error!");                           
        return 0;                                   
    }                                           

    printf("x \t\t ln(x)\n");                                                   //The header of the thing to be printed

    while(j < (buf_size/8)) {                                                   //note that it is implied that EOF = -1 in C
        if(x[j] <= 0.5) {                                                       //if x is less than or equal to 1/2,go to the next double value(assuming I don't know values in the bin file)
            j++;
            i = 1;
            continue;
        }

        cur_term = (1.0/i) * (pow((double)((x[j]-1.0)/(x[j])),i));
        ln_x += cur_term;

        while(cur_term >= LIM) {                                                //continue to accumulate terms until the absolute value of the term is less than 1.0E-13
            i++;                                                                //follows the pattern of the series.
            cur_term = (1.0/i)*(pow((double)((x[j]-1.0)/(x[j])),i));            //since it should start with x[1]
            ln_x += cur_term;                                                   //adds the new term to previous ln(x) value
        }

        printf("%.10lf \t %.10lf\n",x[j],ln_x);                                 //prints the current value of ln(x) and x
        j++;                                                                    //manages which x double value will be used next
        i = 1;
        ln_x = 0.0;
    }

    close(fd);
    return 0;
 }

原来你的main在里面.bss部分,不.text它所属的位置,因此它只能包含全零字节。 (并且它无法执行)。

GDB通常只想反汇编代码.text这也解释了 GDB 的奇怪之处。

这就是为什么您应该将代码简化为 MCVE (Minimal/完整/可验证的示例)使其尽可能小,同时仍然包含问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我应该使用哪些 gdb 命令来缩小标签“main”中出现分段错误的位置? 的相关文章

随机推荐

  • 获取 Android 中当前的活跃用户

    我正在寻找一种方法来获取 Android 中当前的活跃用户 我正在构建一个系统应用程序 以便我可以使用隐藏方法 但具体来说它必须是当前的活动用户 而不是给定进程的用户 例如 如果您使用 ADB 安装应用程序 则进程会显示用户 ID 是所有者
  • ASP.NET 5、MVC 6、Web API -> ModelState.IsValid 始终返回 true

    我看过很多关于 IsValid 的帖子总是正确的 但没有一个能帮助我解决这个问题 我也在使用 MVC5 的 ASP NET 4 中看到了这个问题 很明显我在某个地方错过了一步 控制器方法 public IHttpActionResult P
  • 从 spring-cloud-sleuth 切换到微米追踪后,Brave Baggage 无法工作

    我正在将我的 spring 项目更新到较新的版本 更新后我收到以下消息 由于以下原因 您的项目设置与我们的要求不兼容 Spring Cloud Sleuth 与此 Spring Cloud 版本系列不兼容 操作 考虑应用以下操作 从 Spr
  • 打开弹出窗口时 Chrome 扩展程序损坏 [关闭]

    Closed 这个问题需要调试细节 help minimal reproducible example 目前不接受答案 Chrome 扩展程序在尝试打开时崩溃popup https developer chrome com extensio
  • 如何使用 Warp 检查授权标头?

    我正在使用 Rust 和 Warp 构建 graphql api 我已经浏览了文档 但我仍然不知道如何链接过滤器 特别是检查authorization在请求头中 let context extractor warp any this cod
  • 通过 React Router 传递函数

    我想通过 React Router 将函数传递给子组件 我尝试了以下方法 但似乎不起作用 class App extends Component constructor props super props render return div
  • C++ 中的迭代合并排序

    我目前正在研究合并排序的迭代版本 但遇到了问题 当数组的特定大小如 34 35 36 或 100 仅几个示例 时 程序会崩溃 而它适用于其余数组 fe 适用于 2 的幂 我已经运行了一些测试并对其进行了调试 问题似乎出在我的迭代 合并排序的
  • PHP preg_functions 多字节安全吗?

    PHP 中没有可用的多字节 preg 函数 那么这是否意味着默认的 preg functions 都是 mb 安全的 在 php 文档中找不到任何提及 pcre 支持开箱即用的 utf8 请参阅 u 修饰符的文档 插图 xC3 xA4 是德
  • 下拉按钮/微调器类似于 Google 设计规范中的按钮

    我想知道如何制作一个下拉按钮 菜单 就像我们在 Google 的设计规范和下图中看到的那样 因此列表在按钮下方展开 我是否需要为其设置自定义布局而不是R layout support simple spinner dropdown item
  • 更改列表中每个字典的特定键的值 - python

    我有一个字典列表 如下所示 type df first from 2020 02 01T20 00 00 000Z to 2020 02 03T20 00 00 000Z days 0 coef 0 1 0 1 0 1 0 1 0 1 0
  • 匹配不同长度的时间向量:一个棘手的问题

    我有两组来自不同机器的测量结果 它们是随着时间的推移以略有不同的间隔进行测量的 例如一个每 5 分钟测量一次 而另一个每 3 分钟测量一次 优点是每 5 分钟计算一次 作为整个时间间隔的平均值 因此这些值应该大致对应 我想通过每 5 分钟
  • 返回 zip 以从 django 中的视图下载

    我尝试在 Django 应用程序中下载 zip 文件 我应该如何从视图中返回它 我尝试了下面的代码 但我在浏览器中收到了某种警报 其中包含我的 zip 中的文件内容 我究竟做错了什么 def download logs request da
  • 寻找优秀、可靠玩家的算法

    我有以下玩家 每个值对应于给定游戏中正确答案百分比的结果 players array A gt array 0 0 0 0 B gt array 50 50 0 0 C gt array 50 50 50 50 D gt array 75
  • 从另一个 Jenkinsfile 调用远程 jenkins 文件

    我正在我的组织中设计 Jenkins CICD 管道 我有以下问题 我来自一个 DevOps 团队 负责控制多个开发团队的 Jenkins 管道 我基本上想编写一个具有多个阶段的 Jenkins 文件 可以由多个团队运行 据我所知 这个 J
  • 两个列表中的公共元素

    我有两个ArrayList每个对象都有三个整数 我想找到一种方法来返回两个列表的共同元素 有人知道我该如何实现这一目标吗 Use Collection retainAll https docs oracle com en java java
  • 如何查找正在执行的 AppleScript 的文件名

    如何找到正在执行的 AppleScript 的名称 原因 我想创建一个根据文件名更改其行为的脚本 就像是 if myname is Joe then ACTION1 else if myname is Frank then ACTION2
  • Python 的 re 模块 - 保存状态?

    我发现 Python 中最大的烦恼之一是无法re模块来保存其状态 而无需在匹配对象中显式执行此操作 通常 人们需要解析行 如果它们符合某个正则表达式 则通过相同的正则表达式从中取出值 我想写这样的代码 if re match foo w b
  • Google Chrome 警告:密码表单应包含(可选隐藏)用户名字段以方便访问

    当访问我的单页应用程序的 重置密码 路径并查看 Chrome 浏览器控制台时 我收到以下警告 DOM 密码表单应具有 可选择隐藏 用户名字段以方便访问 更多信息 goo gl 9p2vKq
  • 如何解决 Yelp API 调用中的 CORS 错误?

    我尝试使用 AJAX 调用 Yelp Fusion API 但出现以下错误 有人可以帮我弄清楚这里发生了什么事吗 api yelp com v3 1 加载资源失败 服务器响应状态为 403 index html 1 从源 null 访问 h
  • 我应该使用哪些 gdb 命令来缩小标签“main”中出现分段错误的位置?

    这是我的汇编代码和我的主要子例程 这是我的宏和常量 text fmt string x t t ln x n sfmt string 10lf t 10lf n error string Error filename string inpu