zoukankan      html  css  js  c++  java
  • windows下使用MinGW的调试工具gdb.exe调试C程序

    1、编译源代码

    C:MinGWin>gcc.exe -g -o program.exe program.c

      编译选项上要加上“g”,这样生成的目标程序会含有调试内容,再用gdb调试的时候才能使用。显然加上“g”选项生成的应用程序会比不加的大,但两者运行时没有差别。

    2、启动调试

    C:MinGWin>gdb.exe program.exe

    3、设置断点并启动运行

    (gdb)break main
    (gdb)start

      不能直接start,因为程序运行太快了,直接start就运行到程序停止的地方。

      break main在start命令之前,设置程序运行的断点,这样start后程序就运行到main处中断。也可以用命令“break FILENAME:LINENO",程序会在FILENAME指定的文件的LINENO指定行停下,例如"break mycode.cpp:4”。

    4、其他命令

    • print VARNAME. That's how you print values of variables, whether local, static, or global. For example, at the for loop, you can type print temp to print out the value of the temp variable.
    • step This is equivalent to "step into".
    • next or adv +1 Advance to the next line (like "step over"). You can also advance to a specific line of a specific file with, for example, adv mycode.cpp:8.
    • bt Print a backtrace. This is a stack trace, essentially.
    • continue Exactly like a "continue" operation of a visual debugger. It causes the program execution to continue until the next break point or the program exits.

    参考资料:http://stackoverflow.com/questions/4671900/how-do-i-use-the-mingw-gdb-debugger-to-debug-a-c-program-in-windows

  • 相关阅读:
    UVa10917
    T^T online judge 2952
    AcWing 105.七夕祭
    AcWing 99.激光炸弹(二维前缀和)
    AcWing 97.约数之和
    AcWing 95. 费解的开关
    ccf/csp 2018 12 小明放学
    BNUOJ 33535 Final Exam Arrangement
    分块
    sublime安装配置
  • 原文地址:https://www.cnblogs.com/amanlikethis/p/3840194.html
Copyright © 2011-2022 走看看