Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: call function in multithreaded program without progressing threads

I'm debugging a multithreaded C++ program with gdb. Here's the debugging flow I'd like to achieve:

  1. run until a breakpoint, then pause execution for all threads
  2. disable [breakpoints] with the disable command
  3. call a function (defined in my program) to print the state of a vector (while keeping the other threads paused)

However, when I make the call to the function that prints the state of the system multiple times, the values of the data structure change. Unless I have some sort of other bug, this must mean that the other threads are running while my printing function is running.

Questions:

  1. do other threads resume execution while a call command is executed in gdb?
  2. assuming so, is there a way to disable this such that I can keep threads paused while I introspect program state via call commands?
like image 608
Kulluk007 Avatar asked Sep 07 '25 01:09

Kulluk007


1 Answers

See @KostasRim's comment -- set scheduler-locking on achieves the desired behavior (https://sourceware.org/gdb/onlinedocs/gdb/All_002dStop-Mode.html). By default, other threads run during stepping, function calling, etc.

like image 199
Kulluk007 Avatar answered Sep 08 '25 13:09

Kulluk007