gdb调试多进程和多线程命令

苍穹外卖项目面试总结话术 美食速递这个项目最初是我参与制作的大创项目,是一款为中南学生提供校园外卖送至宿舍服务的软件,包含系统管理后台和小程序端两部分。其中系统管理后台主要提供给食堂内部员工使用,可以对食堂各个窗口、员工、订单、菜品等进行维护管理;小程序端可以在线浏览菜品、添加购物车、下单等,由学生兼职做跑腿送餐上门服务。这是个前后端分离的项目,我主要是负责后端的用户登录、员工管理,菜品管理,订单管理模块的编码实现。 阅读详情

gdb调试多进程和多线程命令

原文地址:http://blog.youkuaiyun.com/pbymw8iwm/article/details/7876797

  1. 默认设置下,在调试多进程程序时GDB只会调试主进程。但是GDB(>V7.0)支持多进程的

分别以及同时

调试,换句话说,GDB可以同时调试多个程序。只需要设置follow-fork-mode(默认值:parent)和detach-on-fork(默认值:on)即可。

follow-fork-modedetach-on-fork说明
parenton只调试主进程(GDB默认)
childon只调试子进程
parentoff同时调试两个进程,gdb跟主进程,子进程block在fork位置
childoff同时调试两个进程,gdb跟子进程,主进程block在fork位置

设置方法:set follow-fork-mode [parent|child] set detach-on-fork [on|off]

查询正在调试的进程:info inferiors

切换调试的进程: inferior

添加新的调试进程: add-inferior [-copies n] [-exec executable] ,可以用file executable来分配给inferior可执行文件。

其他:remove-inferiors infno, detach inferior

  1. GDB默认支持调试多线程,跟主线程,子线程block在create thread。

    查询线程:info threads

    切换调试线程:thread

例程:

#include <stdio.h>

#include <pthread.h>

void processA();

void processB();

void * processAworker(void *arg);

int main(int argc, const char *argv[])

  {

  int pid;

  pid = fork();

  if(pid != 0)

    processA();

  else

    processB();

  return 0;

  }

void processA()

  {

  pid_t pid = getpid();

  char prefix[] = "ProcessA: ";

  char tprefix[] = "thread ";

  int tstatus;

  pthread_t pt;

  printf("%s%lu %s\n", prefix, pid, "step1");

  tstatus = pthread_create(&pt, NULL, processAworker, NULL);

  if( tstatus != 0 )

    {

    printf("ProcessA: Can not create new thread.");

    }

  processAworker(NULL);

  sleep(1);

  }

void * processAworker(void *arg)

  {

  pid_t pid = getpid();

  pthread_t tid = pthread_self();

  char prefix[] = "ProcessA: ";

  char tprefix[] = "thread ";

  printf("%s%lu %s%lu %s\n", prefix, pid, tprefix, tid, "step2");

  printf("%s%lu %s%lu %s\n", prefix, pid, tprefix, tid, "step3");

  return NULL;

  }

void processB()

  {

  pid_t pid = getpid();

  char prefix[] = "ProcessB: ";

  printf("%s%lu %s\n", prefix, pid, "step1");

  printf("%s%lu %s\n", prefix, pid, "step2");

  printf("%s%lu %s\n", prefix, pid, "step3");

  }

输出:

[cnwuwil@centos c-lab]$ ./test

​ ProcessA: 802 step1
​ ProcessB: 803 step1
​ ProcessB: 803 step2
​ ProcessB: 803 step3
​ ProcessA: 802 thread 3077555904 step2
​ ProcessA: 802 thread 3077555904 step3
​ ProcessA: 802 thread 3077553008 step2
​ ProcessA: 802 thread 3077553008 step3

调试:

  1. 调试主进程,block子进程。

    (gdb) set detach-on-fork off
    (gdb) show detach-on-fork
    Whether gdb will detach the child of a fork is off.
    (gdb) catch fork
    Catchpoint 1 (fork)
    (gdb) r
    [Thread debugging using libthread_db enabled]
    Catchpoint 1 (forked process 3475), 0x00110424 in __kernel_vsyscall ()
    Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.i686
    (gdb) break test.c:14
    Breakpoint 2 at 0x8048546: file test.c, line 14.
    (gdb) cont
    [New process 3475]
    [Thread debugging using libthread_db enabled]
    Breakpoint 2, main (argc=1, argv=0xbffff364) at test.c:14
    Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.i686
    (gdb) info inferiors
    Num Description Executable
    2 process 3475 /home/cnwuwil/labs/c-lab/test
    * 1 process 3472 /home/cnwuwil/labs/c-lab/test

  2. 切换到子进程:

  3. 设断点继续调试主进程,主进程产生两个子线程:

    (gdb) break test.c:50
    Breakpoint 3 at 0x804867d: file test.c, line 50. (2 locations)
    (gdb) cont
    ProcessA: 3472 step1
    [New Thread 0xb7fe7b70 (LWP 3562)]
    ProcessA: 3472 thread 3086911168 step2
    Breakpoint 3, processAworker (arg=0x0) at test.c:50
    (gdb) info inferiors
    Num Description Executable
    2 process 3475 /home/cnwuwil/labs/c-lab/test
    * 1 process 3472 /home/cnwuwil/labs/c-lab/test
    (gdb) info threads
    3 Thread 0xb7fe7b70 (LWP 3562) 0x00110424 in __kernel_vsyscall ()
    2 Thread 0xb7fe86c0 (LWP 3475) 0x00110424 in ?? ()
    * 1 Thread 0xb7fe86c0 (LWP 3472) processAworker (arg=0x0) at test.c:50

  4. 切换到主进程中的子线程,注意:线程2为前面产生的子进程

    (gdb) thread 3
    [Switching to thread 3 (Thread 0xb7fe7b70 (LWP 3562))]#0 0x00110424 in __kernel_vsyscall ()
    (gdb) cont
    ProcessA: 3472 thread 3086911168 step3
    ProcessA: 3472 thread 3086908272 step2
    [Switching to Thread 0xb7fe7b70 (LWP 3562)]
    Breakpoint 3, processAworker (arg=0x0) at test.c:50
    (gdb) info threads
    * 3 Thread 0xb7fe7b70 (LWP 3562) processAworker (arg=0x0) at test.c:50
    2 Thread 0xb7fe86c0 (LWP 3475) 0x00110424 in ?? ()
    1 Thread 0xb7fe86c0 (LWP 3472) 0x00110424 in __kernel_vsyscall ()
    (gdb) thread 1

遇到一个诡异的WiFi网络问题:同一个办公室苹果电脑上不了网,其他电脑都可以 先来把问题掰开揉碎地看清楚:在一个普通的办公室WiFi网络中,所有设备——Windows电脑、安卓手机、甚至是那台老旧的Linux服务器——都能正常联网,唯独苹果电脑(可能是MacBook、iMac或者Mac mini)像被下了魔咒一样,连不上网。这种情况不仅让人抓狂,还透着一股神秘感。为什么偏偏是苹果电脑?难道WiFi路由器对苹果有“偏见”?这些症状都指向一个核心问题:苹果电脑与办公室WiFi之间,似乎存在某种“沟通障碍”。但这障碍到底出在哪里呢?是苹果电脑自己的问题,还是网络设置在“针对”它? 阅读详情

相关推荐

GEOSHIELD:分布式CPS的拜占庭容错与安全防护技术

分布式系统在关键基础设施(如轨道交通、智能电网)中面临网络延迟和恶意节点的双重挑战。拜占庭容错(BFT)技术通过算法保证系统在存在故障节点时仍能达成一致,是保障系统安全的核心机制。GEOSHIELD创新性地结合概率化网络延迟测量和TGS动态信任评分,实现了不依赖可信硬件的拜占庭 resilience。该技术通过建立节点行为的信用档案,动态识别恶意行为,在保证安全性的同时最大化系统可用性。实验证明,即使在自适应攻击策略下,GEOSHIELD仍能保持系统95.6%的正常运行时间,为CPS系统提供了可靠的安全防护

weixin_31766003的博客 348

gdb 调试+子进程+线程

一、gdb常用指令: gcc -g main.c //在目标文件加入源代码的信息 gdb a.out (gdb) start //开始调试 (gdb) n //一条一条执行 (gdb) step/s ...

salman的博客 3626

iOS开发者必备:从越狱设备里提取IPA的三种方法(含Filza、iTools实战)

本文详细介绍了iOS开发者从越狱设备提取IPA文件的三种实用方法,包括使用Filza文件管理器、AFC2配合桌面工具以及命令行高级技术。内容涵盖环境准备、操作步骤和技术原理,帮助开发者高效获取应用包文件,适用于逆向工程、测试分析等场景。

weixin_28717969的博客 822

GDB多线程调试(调试命令+调试演示)

多线程调试 (一)多线程调试命令 shell的命令: (1)查看当前运行的进程:ps aux | grep book (2)查看当前运行的轻量级进程:ps -aL | grep book (3)查看主线程和子线程的关系:pstree -p 主线程id gdb的命令: (1)查看可切换调试的线程:info threads (2)切换调试的线程:thread 线程id (3)只运行当前线程:set scheduler-locking on (4)运行全部的线程:set schedul..

weixin_42158742的博客 2万+

⭐️白嫖的阿里云认证⭐️ 【真题&参考答案】:大模型Clouder认证:利用大模型提升内容生产能力

【摘要】真题「大模型Clouder认证:利用大模型提升内容生产能力」

davidkorhenn的博客 1935

[系统安全] 一.什么是逆向分析、逆向分析基础及经典扫雷游戏逆向

娜璋AI安全之家于2020年8月18日开通,将专注于Python和安全技术,主要分享Web渗透、系统安全、CVE复现、威胁情报分析、人工智能、大数据分析、恶意代码检测等文章。真心想把自己近十年的所学所做所感分享出来,与大家一起进步。 系统安全系列作者将深入研究恶意样本分析、逆向分析、攻防实战等,通过在线笔记和实践操作的形式分享与博友们学习,希望能与您一起进步。第一篇文章先带领大家学习什么是逆向分析,然后详细讲解逆向分析的典型应用,接着通过OllyDbg工具逆向分析经典的游戏扫雷,再通过Cheat Engin

杨秀璋的专栏 2万+

GDB 调试多进程或者多线程应用

GDB 是 linux 系统上常用的 c/c++ 调试工具, 功能十分强大. 对于较为复杂的系统, 比如多进程系统, 如何使用 GDB 调试呢? 考虑下面这个三进程系统 : 进程 ProcessChild 是 ProcessParent 的子进程, ProcessParentThread 又是 ProcParent 的子线程. 如何使用 GDB 调试 子进程 ProcessChild 或

omnispace的博客 1175

【HALCON工业视觉应用探索】08. C#+Halcon视觉引导机器人抓取:从入门到工业级实战(附完整代码+部署指南)

摘要:本文聚焦C#+Halcon在视觉引导机器人抓取领域的落地应用,从新手友好的“二十分钟基础引导系统”切入,逐步深入工业级场景(汽车变速箱壳体抓取)。内容涵盖核心概念(手眼标定原理、坐标转换、机器人通信协议)、完整技术流程(图像采集→目标定位→标定转换→机器人执行→结果反馈)、工业级代码实现(多目标识别、智能抓取策略、实时状态监控),以及现场部署关键技巧(硬件选型、通信配置、精度优化)。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 1265

linux ptrace 图文详解(八) gdb跟踪被调试程序的子线程、子进程

本文介绍了gdb调试程序时,如何跟踪被调试程序创建的子进程/子线程。

h_b__k的博客 990

Python 爬虫进阶:爬取 APP 数据(Charles 抓包 + Requests)

本文详细介绍了APP数据爬取的完整技术方案。首先通过Charles抓包工具配置HTTPS代理和证书,解析APP通信协议;然后分析请求参数、反爬机制和动态签名生成规则;接着使用Python的Requests库实现模拟请求、分页爬取和数据存储;最后针对证书问题、Token失效等常见问题提供解决方案。文章强调抓包分析、参数逆向和请求模拟三大核心技术,同时提醒开发者需遵守法律法规,合理控制爬取频率。该方案适用于移动端数据采集场景,为无法直接获取网页数据的情况提供了有效解决方案。

2503_91057718的博客 2120

华为OD机试双机位C卷-用户入网定期复评(C/C++/Py/Java/Js/Go)

华为OD机试(机考)双机位C卷 【用户入网定期复评】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【用户入网定期复评】。

qq_45776114的博客 840

gdb调试总结

在 root用户下,就在/root目录, 在 home用户下就在/home目录下,定义一个.gdbinit文件即可,不存在可以新建一个。然后在文件里面写上gdb命令Apache Web Server 源码为例,源码目录里面有一个.gdbinit文件set $i = 0elseendendend# 省略部分代码。

u010185392的博客 1491

YOLOv13改进:原创自研 | 卷积魔改 | 一种新颖的风车形卷积(PConv)融合注意力机制,加强微弱小目标检测能力

风车形卷积(PConv)融合注意力机制进一步提升小目标检测能力

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1057

gdb pid 线程_[转]gdb调试多进程和多线程命令

1. 默认设置下,在调试多进程程序时GDB只会调试主进程。但是GDB(>V7.0)支持多进程的分别以及同时调试,换句话说,GDB可以同时调试多个程序。只需要设置follow-fork-mode(默认值:parent)和detach-on-fork(默认值:on)即可。follow-fork-modedetach-on-fork说明parento...

weixin_42509396的博客 648

深度学习工具包 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")

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

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

GDB调试多进程和多线程命令

转自 http://blog.youkuaiyun.com/pbymw8iwm/article/details/7876797 1. 默认设置下,在调试多进程程序时GDB只会调试主进程。但是GDB(>V7.0)支持多进程的分别以及同时调试,换句话说,GDB可以同时调试多个程序。只需要设置follow-fork-mode(默认值:parent)和detach-on-fork(默认值:on)即可。

理性的幻想 1234

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: 注释转换工具
下一篇: 生产消费者模型
Findway_
博客等级 码龄10年 36粉丝 117原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值