GDB调试

作业题⽬: gdb调试

完成下⾯任务(9 分)

0. 在 Ubuntu 活 openEuler 中完成任务(推荐openEuler)

1. https://gitee.com/下载课程代码,编译运⾏ “bestidiocs2024/ch02/c/testgdb.c”,记录编译运⾏结果(2分)

2. 参考https://www.cnblogs.com/rocedu/p/16714289.html调试代码,⾄少涵盖 4 种断点(⾏断点,函数断点,临时断点,条件断点)(5分)

3. 使⽤单步运⾏等其他命令。(2分)

root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# gcc testgdb.c
//查看代码
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# vim testgdb.c

#include <stdio.h>

int sum(int m);

int main()
{
    int *pi;
    int i, n = 0;
    pi = &i;
    int arr[3] = { 10, 20, 30 };
    pi = arr;
    sum(50);
    for (i = 0; i <= 50; i++) {
        n += i;
    }

    printf("The sum of 1-50 is %d \n", n);
}

int sum(int m)
{
    int i, n = 0;
    for (i = 1; i <= m; i++) {
        n += i;
    }

    printf("The sum of 1-50 is %d \n", n);

    return n;




root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# ls
a.out  car.c  hello.c  lib  make  project  test.c  testgdb  testgdb.c

root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# ./a.out
The sum of 1-50 is 1275
The sum of 1-50 is 1275

root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# gdb testgdb
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from testgdb...

(gdb) b *12
Breakpoint 1 at 0xc
(gdb) b sum
Breakpoint 2 at 0x800120e
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0xc
Cannot insert breakpoint 2.
Cannot access memory at address 0x800120e
(gdb)quit


root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch02/c# cgdb

(gdb) b main
Note: breakpoint 1 also set at pc 0x8001169.
Breakpoint 3 at 0x8001169
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001169

(gdb) condition 1 i == 5
(gdb)r
Starting program: /root/bestidiocs2024/ch02/c/a.out
warning: opening /proc/PID/mem file for lwp 188.188 failed: No such file or directory (2)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001169

(gdb) d 1
(gdb) d 3
(gdb) d 10
(gdb)run
Starting program: /root/bestidiocs2024/ch02/c/a.out
warning: opening /proc/PID/mem file for lwp 185.185 failed: No such file or directory (2)
Failed to read a valid object file image from memory.
The sum of 1-50 is 1275
The sum of 1-50 is 1275
[Inferior 1 (process 185) exited normally]
The sum of 1-50 is 1275


(gdb) b main   //尝试单步运行
Breakpoint 1 at 0x8001175: file testgdb.c, line 6.
(gdb)  step
The program is not being run.
(gdb) run
Starting program: /root/bestidiocs2024/ch02/c/testgdb
warning: opening /proc/PID/mem file for lwp 220.220 failed: No such file or directory (2)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001169

(gdb) c
Continuing.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001169

Command aborted.
(gdb) step
Single stepping until exit from function _start,
which has no line number information.
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x8001169

Command aborted.

作业提交要求 (1’)

  1. 记录实践过程和 AI 问答过程,尽量不要截图,给出⽂本内容
  2. (选做)推荐所有作业托管到 gitee或 github 上
  3. (必做)提交作业 markdown⽂档,命名为“学号-姓名-作业题⽬.md”
  4. (必做)提交作业 markdown⽂档转成的 PDF ⽂件,命名为“学号-姓名-作业题⽬.pdf”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值