gdb

作者: Jianbaozi | 来源:发表于2020-03-24 15:55 被阅读0次

使用-g选项进行编译
gcc -g 1.c
gcc -v 查看版本

Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

show version 查看gdb版本

GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
#include<stdio.h>
int foo(int);
void bar(int);
int main(void)
{
    int a;
    char *s ="hello, world";
    printf("%s\n",&s[7]);
    a=5;
    foo(a);
    return 0;
}
int foo(int n){
    int b;
    b=n;
    b*=2;
    bar(b);
    return b;
}
void bar(int m){
    printf("Hi, I'am bar!\n");
}
D:\Codes\test>gdb a.exe
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
Reading symbols from a.exe...done.
(gdb) break main
Breakpoint 1 at 0x40155d: file 1.c, line 7.
(gdb) run
Starting program: D:\Codes\test\a.exe 
[New Thread 8612.0x1cb0]
[New Thread 8612.0x15ac]

Thread 1 hit Breakpoint 1, main () at 1.c:7
warning: Source file is more recent than executable.
7           char *s ="hello, world";
(gdb) print s
$1 = 0x10 <error: Cannot access memory at address 0x10>
(gdb) print a
$2 = 0
(gdb) n   
8           printf("%s\n",&s[7]);
(gdb) print s
$3 = 0x404000 "hello, world"
(gdb) print s+13
$4 = 0x40400d "Hi, I'am bar!"
(gdb) n
world
9           a=5;
(gdb) print a
$5 = 0
(gdb) n
10          foo(a);
(gdb) print a
$6 = 5
(gdb) step
foo (n=5) at 1.c:15
15          b=n;
(gdb) print b
$7 = 0
(gdb) n
16          b*=2;
(gdb) n   
17          bar(b);
(gdb) step
bar (m=10) at 1.c:21
21          printf("Hi, I'am bar!\n");
(gdb) print m
$10 = 10
(gdb) n
Hi, I'am bar!
22      }
(gdb) continue
Continuing.
[Thread 8612.0x15ac exited with code 0]
[Inferior 1 (process 8612) exited normally]
(gdb)

相关文章

  • gdb调试

    gdb安装 安装gdb 在钥匙管理器中新建证书 配置gdb证书 添加gdb初始化文件 .gdbinit gdb 命...

  • Debugging with GDB

    Debugging with GDB GDB@wiki(GNU Debugger)GDB is a portabl...

  • GDB 配置

    摘要:调试器 GDB 的配置 GDB 配置 使用 GDB 扩展来配置 GDB 事实上我还是觉得原生的 GDB 就...

  • 2. gdb的使用

    参考链接1. GDB调试2. gdb调试方法3. gdb调试示例 1. 说说 gdb gdb 是一款 UNIX 系...

  • GDB调试记录

    gdb attach 15343 # 调试某个进程 GNU gdb (GDB) 7.12Copyrigh...

  • gdb 调试

    gdb-入门 100-gdb-tips

  • gdb调试

    使用gdb:编译的时候加 -g 参数 启动gdb:gdb app(对应的可执行程序名) 在gdb启动后:r(un)...

  • 各种linux命令(pwn)

    (gdb)bt //查看函数堆栈 (gdb)info break ...

  • GDB TO LLDB COMMAND MAP

    GDB TO LLDB COMMAND MAP Below is a table of GDB commands ...

  • GDB入门教程之如何使用GDB启动调试

    原文地址:GDB入门教程之如何使用GDB启动调试|Vim教程网 GDB (The GNU Project Debu...

网友评论

      本文标题:gdb

      本文链接:https://www.haomeiwen.com/subject/penoyhtx.html