root@ubuntu:/home/libz/share/project/gdb_test# gdb ./gdb_test.elf -q
Reading symbols from /home/libz/share/project/gdb_test/gdb_test.elf...done.
(gdb) break func
Breakpoint 1 at 0x8048946: file ./gdb_test.c, line 36.
(gdb) r
Starting program: /home/libz/share/project/gdb_test/gdb_test.elf
[Thread debugging using libthread_db enabled]
[New Thread 0xb7fecb70 (LWP 29620)]
[Switching to Thread 0xb7fecb70 (LWP 29620)]
Breakpoint 1, func () at ./gdb_test.c:36
36 pthread_mutex_lock(&g_mutex_thread);
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x08048946 in func at ./gdb_test.c:36
breakpoint already hit 1 time
(gdb) delete 1
(gdb) l
31 {
32 static INT32_T i32Num = 0;
33 static char p[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
34
35 while (1) {
36 pthread_mutex_lock(&g_mutex_thread);
37
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
39
40 pthread_mutex_unlock(&g_mutex_thread);
(gdb)
41 sleep(1);
42 }
43 }
44
45 void create_thread(void)
46 {
47 pthread_attr_t stAttr;
48 struct sched_param sched_proi;
49
50 memset(&sched_proi, 0x0, sizeof(sched_proi));
(gdb) s
__pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
47 pthread_mutex_lock.c: No such file or directory.
in pthread_mutex_lock.c
(gdb) finish
Run till exit from #0 __pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
func () at ./gdb_test.c:38
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
Value returned is $1 = 0
(gdb) s
__printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
30 printf.c: No such file or directory.
in printf.c
(gdb) finish
Run till exit from #0 __printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
g_stPid = [-1208038544] i32Num = [0]
func () at ./gdb_test.c:40
40 pthread_mutex_unlock(&g_mutex_thread);
Value returned is $2 = 37
(gdb) watch 5 == i32Num
Hardware watchpoint 2: 5 == i32Num
(gdb) c
Continuing.
g_stPid = [-1208038544] i32Num = [1]
g_stPid = [-1208038544] i32Num = [2]
g_stPid = [-1208038544] i32Num = [3]
Hardware watchpoint 2: 5 == i32Num
Old value = 0
New value = 1
0x08048961 in func () at ./gdb_test.c:38
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
(gdb) print i32Num
$3 = 5
(gdb)
Reading symbols from /home/libz/share/project/gdb_test/gdb_test.elf...done.
(gdb) break func
Breakpoint 1 at 0x8048946: file ./gdb_test.c, line 36.
(gdb) r
Starting program: /home/libz/share/project/gdb_test/gdb_test.elf
[Thread debugging using libthread_db enabled]
[New Thread 0xb7fecb70 (LWP 29620)]
[Switching to Thread 0xb7fecb70 (LWP 29620)]
Breakpoint 1, func () at ./gdb_test.c:36
36 pthread_mutex_lock(&g_mutex_thread);
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x08048946 in func at ./gdb_test.c:36
breakpoint already hit 1 time
(gdb) delete 1
(gdb) l
31 {
32 static INT32_T i32Num = 0;
33 static char p[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };
34
35 while (1) {
36 pthread_mutex_lock(&g_mutex_thread);
37
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
39
40 pthread_mutex_unlock(&g_mutex_thread);
(gdb)
41 sleep(1);
42 }
43 }
44
45 void create_thread(void)
46 {
47 pthread_attr_t stAttr;
48 struct sched_param sched_proi;
49
50 memset(&sched_proi, 0x0, sizeof(sched_proi));
(gdb) s
__pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
47 pthread_mutex_lock.c: No such file or directory.
in pthread_mutex_lock.c
(gdb) finish
Run till exit from #0 __pthread_mutex_lock (mutex=0x804a0d4) at pthread_mutex_lock.c:47
func () at ./gdb_test.c:38
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
Value returned is $1 = 0
(gdb) s
__printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
30 printf.c: No such file or directory.
in printf.c
(gdb) finish
Run till exit from #0 __printf (format=0x8048d90 "g_stPid = [%d] i32Num = [%d]\n") at printf.c:30
g_stPid = [-1208038544] i32Num = [0]
func () at ./gdb_test.c:40
40 pthread_mutex_unlock(&g_mutex_thread);
Value returned is $2 = 37
(gdb) watch 5 == i32Num
Hardware watchpoint 2: 5 == i32Num
(gdb) c
Continuing.
g_stPid = [-1208038544] i32Num = [1]
g_stPid = [-1208038544] i32Num = [2]
g_stPid = [-1208038544] i32Num = [3]
Hardware watchpoint 2: 5 == i32Num
Old value = 0
New value = 1
0x08048961 in func () at ./gdb_test.c:38
38 printf("g_stPid = [%d] i32Num = [%d]\n", (UINT32_T)g_stPid, i32Num++);
(gdb) print i32Num
$3 = 5
(gdb)