Is it possible to debug deadlock with codelldb? #624
Answered
by
zchrissirhcz
zchrissirhcz
asked this question in
Q&A
-
Hi, vscode-lldb developers and contributors I'm recently learning C++ multithreading programming, and notice gdb can debug deadlock (or some deadlock case, as I know less). I do a simple try but failed to find vscode-lldb support deadlock debug. Example deadlock program#include <mutex>
#include <thread>
#include <chrono>
#include <iostream>
using std::mutex;
using std::lock_guard;
using std::thread;
mutex _mutex1;
mutex _mutex2;
int data1;
int data2;
int do_work_1()
{
std::cout << "thread function do_work_1 start" << std::endl;
//{
lock_guard<mutex> locker1(_mutex1);
data1++;
std::this_thread::sleep_for(std::chrono::seconds(1));
//}
//{
lock_guard<mutex> locker2(_mutex2);
data2++;
std::cout << "thread function do_work_1 end" << std::endl;
//}
return 0;
}
int do_work_2()
{
std::cout << "thread function do_work_2 start" << std::endl;
lock_guard<mutex> locker2(_mutex2);
data2++;
std::this_thread::sleep_for(std::chrono::seconds(1));
lock_guard<mutex> locker1(_mutex1);
data1++;
std::cout << "thread function do_work_2 end" << std::endl;
return 0;
}
int main()
{
thread t1(do_work_1);
thread t2(do_work_2);
t1.join();
t2.join();
std::cout <<"thread run end" << std::endl;
return 0;
}
gdb debug dead lock stepswith steps like: gdb ./a.out
$gdb r
$gdb # now get stuck
$gdb Ctrl+C # press Control +C key. Don't know if codelldb can do same thing?
$gdb info threads
$gdb t 1 # switch to the first thread
$gdb blablabla |
Beta Was this translation helpful? Give feedback.
Answered by
zchrissirhcz
Jan 16, 2022
Replies: 1 comment
-
Let me answer this question by myself. For gdb, use |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
zchrissirhcz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let me answer this question by myself.
The codelldb vscode plugin, when debugging C/C++, providing a lldb command console.
Just type
pro signal SIGHUP
, get same effect as "Ctrl+C" key. (Yes, for lldb).For gdb, use
signal SIGHUP
.