首页 > 其他分享 >GDB:调试时传递参数

GDB:调试时传递参数

时间:2024-08-24 21:53:13浏览次数:5  
标签:GNU show int args gdb GDB 参数 configuration 调试

有时需要在通过gdb调试的时候,向程序传递命令行参数,假设如下程序:

#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    for(int i = 0; i < argc; i++)
    {
        cout << i << " :" << argv[i] << endl;
    }
    return 0;
}

可以使用以下几种方法:

1.运行gdb时通过--args传递参数

$ gdb --args main_args 1 2 3
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

标签:GNU,show,int,args,gdb,GDB,参数,configuration,调试
From: https://blog.csdn.net/jiemashizhen/article/details/141504480

相关文章