GDB调试 多线程 进程 coredump

1、调试简单多线程学习:【Linux】gdb调试多线程与多进程GDB 调试多线程程序的总结gdb调试多进程与多线程生成程序 gcc -o env threadgdb1.c -lpthread -g#include <stdio.h>#include <pthread.h>#include <stdlib.h>#include <unistd.h>static int count = 0;void *pthread_fuc(void *ar
摘要由CSDN通过智能技术生成

1、调试简单多线程

学习:【Linux】gdb调试多线程与多进程
GDB 调试多线程程序的总结
gdb调试多进程与多线程
生成程序 gcc -o env threadgdb1.c -lpthread -g

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

static int count = 0;
void *pthread_fuc(void *arg)
{
   
    int i = 0;
    while(i < 100)
    {
   
        i++;
        count += i;
        usleep(100);
    }
    return NULL;
}

int main()
{
   
    pthread_t pth1;
    pthread_t pth2;
    pthread_create(&pth1, NULL, &pthread_fuc, NULL);
    pthread_create(&pth1, NULL, &pthread_fuc, NULL);
    pthread_join(pth1, NULL);
    pthread_join(pth2, NULL);
    printf("cout: %d\n",count);
    return 0;
}

set b threadgdb1.c:8 设置断点位置文件threadgdb1.c的第8行
info b,显示断点,info thread 显示线程

(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000400752 in pthread_fuc 
                                                   at threadgdb1.c:8
	breakpoint already hit 2 times
2       breakpoint     keep y   0x00000000004007d4 in main at threadgdb1.c:26
	breakpoint already hit 1 time

(gdb) info thread
  Id   Target Id         Frame 
* 1    Thread 0x7ffff7fda700 (LWP 19331) "env" main () at threadgdb1.c:26
  2    Thread 0x7ffff77ef700 (LWP 19332) "env" pthread_fuc (arg=0x0)
    at threadgdb1.c:10
  3    Thread 0x7ffff6fee700 (LWP 19333) "env" pthread_fuc (arg=0x0)
    at threadgdb1.c:10

r(run) 运行到断点, start 运行到main函数第一句,

(gdb) start
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Temporary breakpoint 3 at 0x40078f: file threadgdb1.c, line 21.
Starting program: /home/Templates/GDB/env 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 3, main () at threadgdb1.c:21
21	{
   
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/Templates/GDB/env 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff77ef700 (LWP 19332)]
[New Thread 0x7ffff6fee700 (LWP 19333)]

Thread 2 "env" hit Breakpoint 1, pthread_fuc (arg=0x0) at threadgdb1.c:10
10	    int i = 0;
(gdb) 
Thread 3 "env
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值