gdb调试带参数程序

gdb给程序传参 一般来说GDB主要调试的是C/C++的程序。要调试C/C++的程序,首先在编译时,我们必须要 把调试信息加到可执行文件中。使用编译 器(cc/gcc/g++)的 -g 参数可以做到这一点。如: > cc -g hello.c -o hello > g++ -g hello.cpp -o hello 如果没有-g,你将看不见程序的函数名、变量名,所代替的全是 运行时的内存地址。当你用 -g把调试信息加入之后,并成功编译目标代码以后,让我们来看看如何用gdb来调试他。 启动 GDB的方法... 阅读详情
AI摘要

本文介绍如何使用GDB调试C/C++程序,包括添加调试信息、启动GDB的不同方式及调试时的各种设置。还提供了具体的调试命令示例。

一、问题
如果运行 $gdb ./a.out 1 2 3 肯定会报错。正确的做法是:

$gdb --args ./A V1 V2 V3
$gdb ./A,进入gdb后  r V1 V2 V3
$gdb ./A,进入gdb后  设置参数set args V1 V2 V3 再直接 r。

通过这三种方法,你就可以调试带参数的程序。

二、例子

    一般来说GDB主要调试的是C/C++的程序。要调试C/C++的程序,首先在编译时,我们必须要把调试信息加到可执行文件中。使用编译器(cc/gcc/g++)的 -g 参数可以做到这一点。如: 

> cc -g hello.c -o hello 
> g++ -g hello.cpp -o hello 

    如果没有-g,你将看不见程序的函数名、变量名,所代替的全是运行时的内存地址。当你用-g把调试信息加入之后,并成功编译目标代码以后,让我们来看看如何用gdb来调试他。 

启动 GDB的方法有以下几种: 

1、gdb <program> 
    program也就是你的执行文件,一般在当然目录下。 

2、gdb <program> core 
    用gdb同时调试一个运行程序和core文件,core是程序非法执行后core dump后产生的文件。 

3、gdb <program> <PID> 
    如果你的程序是一个服务程序,那么你可以指定这个服务程序运行时的进程ID。gdb会自动attach上去,并调试他。program应该在 PATH环境变量中搜索得到。 GDB启动时,可以加上一些GDB的启动开关,详细的开关可以用gdb -help查看。我在下面只例举一些比较常用的参数: 
    -symbols <file> 
    -s <file> 
从指定文件中读取符号表。 

-se file 
    从指定文件中读取符号表信息,并把他用在可执行文件中。 
-core <file> 
-c <file> 
    调试时core dump的core文件。 
-directory <directory> 
-d <directory> 
    加入一个源文件的搜索路径。默认搜索路径是环境变量中PATH所定义的路径。

    当以gdb <program>方式启动gdb后,gdb会在PATH路径和当前目录中搜索<program>的源文件。如要确认gdb是否读到源文件,可使用l或list命令,看看gdb是否能列出源代码。 

在gdb中,运行程序使用r或是run命令。 程序的运行,你有可能需要设置下面四方面的事。 

1、程序运行参数。 
    set args 可指定运行时参数。(如:set args 10 20 30 40 50) 
    show args 命令可以查看设置好的运行参数。 

2、 运行环境。 
    path <dir> 可设定程序的运行路径。 
    show paths 查看程序的运行路径。 
    set environment varname [=value] 设置环境变量。如:set env USER=hchen 
    show environment [varname] 查看环境变量。 

3、工作目录。 
    cd <dir> 相当于shell的cd命令。 
    pwd 显示当前的所在目录。 

4、程序的输入输出。 
    info terminal 显示你程序用到的终端的模式。 
    run > outfile 使用重定向控制程序输出。 
    tty /dev/ttyb tty命令可以指写输入输出的终端设备。

具体来说就是

例如一个程序名为prog 参数为 -l a -C abc 则,运行gcc/g++ -g  prog.c/cpp -o prog,就可以用gdb调试程序prog
   #gdb prog
进入gdb调试界面,输入参数命令set args 后面加上程序所要用的参数,注意,不再带有程序名,直接加参数,如:set args -l a -C abc
回车后输入:r

参考:http://www.cnblogs.com/rosesmall/archive/2012/04/10/2440514.html  
http://blog.chinaunix.net/uid-25267728-id-3475596.html
02.gdb启动调试 gdb指定参数的三种方法 调试用到的代码: https://github.com/CoderDuanGe/gdbdebug/tree/master/section1 https://github.com/CoderDuanGe/gdbdebug/tree/master/section2 1.第一种方式 启动gdb启动时传入三个参数 有空格需要用引号 2.第二种方式 在gdb没执行run之前传入三个参数 3.第三种方式 gdb运行的时候,传入参数 根据pid附加到进程 dgb attch 阅读详情

相关推荐

GDB 详细介绍

5.1.1设置断点 使用break命令(缩写 b)设置断点。调试器便利变量’$ bpnum’记录您最近设置的断点数; 有关便利变量的讨论,请参阅便利变量。 break location 在给定位置设置断点,可以指定函数名称,行号或指令的地址。(有关指定位置的所有可能方法的列表,请参阅“ 指定位置”。)断点将在执行指定位置中的任何代码之前停止程序。 当使用允许重载符号的源语言(例如C ++)时,函数...

alan711的博客 5526

gdb 调试带参数的程序

gdb 调试带参数的程序1. 编译程序2. 进入gdb3. 输入断点4. 输入参数运行 1. 编译程序 g++ -g main.cpp -o main 2. 进入gdb gdb main 3. 输入断点 4. 输入参数运行 run -a -n

田一一 6394

2023年5月青少年软件编程Python等级考试四级真题(含答案和解析)

电子学会,2023年5月,青少年软件编程,Python等级考试,四级真题(含答案和解析)

m0_37554648的博客 910

GDB调试相关教程

GDB调试相关命令,测试用例,调试过程结果,说明。

wj617906617的博客 1844

从零开始理解二极管限幅:5种典型电路设计及实际应用场景解析

本文系统解析了二极管限幅电路的五大经典拓扑,包括串联与并联型上下限幅及双向限幅。通过剖析其核心原理与二极管的单向导电性、正向压降特性,结合ADC输入保护、电源管理、音频处理等实际应用场景,提供了从器件选型到设计陷阱规避的完整实战指南,帮助工程师为信号构建可靠的“安全笼”。

2y3u4i5o6p的博客 1042

第1章:Zephyr 开发环境搭建与 Hello World

📝【摘要】本文是Zephyr RTOS开发入门指南的第一章,详细介绍了从环境搭建到首个应用运行的完整流程。主要内容包括:1️⃣ Zephyr项目结构解析与west工具链部署;2️⃣ 开发环境配置(Linux/WSL)及SDK安装;3️⃣ 两种实践路径——官方HelloWorld样例与自定义应用开发;4️⃣ 实际硬件部署方法(nRF/STM32)及常用west命令速查;5️⃣ 典型问题解决方案。通过qemu_x86模拟器演示了基础打印功能实现,为后续深度开发奠定基础。

hemoparrot的专栏 1374

gdb调试带参数的程序

转自:http://blog.chinaunix.net/uid-20554957-id-3826852.html

yasi_xi的专栏 769

FPGA开发中的操作系统

在FPGA开发中,操作系统起着关键的作用,它负责任务管理、资源管理、中断处理和设备驱动程序等功能。在实际的FPGA开发中,可以选择使用现有的操作系统,如MicroC/OS-II、FreeRTOS等,或者根据具体需求自行设计和开发操作系统。在FPGA(可编程逻辑门阵列)开发中,操作系统扮演着关键的角色,为硬件设计师提供了一种有效的方式来管理资源、调度任务并实现系统级功能。本文将介绍FPGA开发中的操作系统概念,并提供一个简单的示例代码来说明如何在FPGA平台上实现一个基本的操作系统。

CqpFsharp的博客 1168

GDB调试带参数的程序(转载+整理+实践)

GDB调试带参数的程序(转载+整理+实践) http://www.cnblogs.com/hankers/archive/2012/12/07/2806836.html 一.gdb常

dearbaba_1666的博客 236

Odoo 入门 | 什么是 Odoo?

Odoo是一套全球开源的ERP/CRM系统,最初的名字为TinyERP,08年5月之后称之为OpenERP,之后又改为Odoo。

洛阳泰山的博客 6215

29、网络支持技术:CDN、覆盖网络与无标度网络解析

本文详细解析了CDN路由方式与性能指标,探讨了覆盖网络与无标度网络的特性及其在云计算和现代网络中的应用。文章分析了CDN的关键技术与挑战,介绍了覆盖网络与小世界网络的基本原理,并深入讨论了无标度网络的构建算法、性能优化策略以及在多个领域的应用案例。最后,文章展望了未来网络技术发展趋势与无标度网络的结合潜力。

night的博客 100

GDB调试带参数的程序

一般来说GDB主要调试的是C/C++的程序。要调试C/C++的程序,首先在编译时,我们必须要  把调试信息加到可执行文件中。使用编译 器(cc/gcc/g++)的 -g 参数可以做到这一点。如:  > cc -g hello.c -o hello  > g++ -g hello.cpp -o hello  如果没有-g,你将看不见程序的函数名、变量名,所代替的全是 运行时的

ccskyer的专栏 977

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

gdb 调试解决-带参数程序-条件断点-core文件开启调试-watch监视内存-gdb多线程调试

gdb set args 和 show args命令 调试带参数程序 gdb 条件断点 gdb如何调试core文件?core 文件是什么? getopt 函数介绍 让被GDB调试的程序接收信号 让被GDB调试的程序接收信号 — gdb set args 和 show args命令 调试带参数程序 [root@(none) ~]# gdb main GNU gdb Red Hat Linux (6....

我的博客 1486

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

gdb 带参数调试可执行文件程序

假设程序此时已经出错自动暂停,界面仍然是 gdb 界面,使用。其中每行开头数字越大表示越外层,越小表示越接近出错的具体代码。此时终端会进入 gdb 界面,如下。然后回车,程序开始运行。在 gdb 界面输入。

我才是一卓的博客 3178

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

上一篇: boost 安装
下一篇: linux 查看可执行文件动态链接库的相关信息
vigoto
博客等级 码龄12年 3粉丝 5原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值