Поток C++ завершается без предупреждения – нужна помощь в отладке с помощью GDBC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Поток C++ завершается без предупреждения – нужна помощь в отладке с помощью GDB

Сообщение Anonymous »

У меня есть многопоточная программа на C++.
Вот краткий псевдокод важных фрагментов:

Код: Выделить всё

main.cpp

main {
try {
boost::asio::io_context ioc;

// 2. Start the D-Bus server, read and handle configuration.
std::shared_ptr shared_classA = std::make_shared(ioc);

// Continue to run, should not return unless error.
ioc.run();
}
catch (const std::bad_alloc& e) {
return (-1);
}
catch (const std::exception& e)
{
return (-1);
}
return 0;

}

classA.cpp

classA::classA(boost::asio::io_context& ioc) : _ioc(ioc)
{
try
{
std::thread d( [&]() -> void {

/* Some DBUS related initialization for creating dbus objects
at a particular location on the dbus tree

*/
// Create a new dbus instance
auto b = sdbusplus::bus::new_default();

std::thread dh( [&]() -> void {
try
{
// Create DataHandler and a pointer to be accessed.
classB_sptr = std::make_shared();

// Create data poller
Poller dp(classB_sptr);

// Ready to start the poller thread (this is a separate thread)
/* this function creates a new thread with a polling function

*/
if (!dp.start())
{
// log exception to file
}

while (true)
{
std::this_thread::sleep_for(std::chrono::seconds(1)); // To prevent tight loop
}
}
catch (const std::exception& e)
{
// print exception to log file
}
});
dh.detach(); // detach inner thread

// Create DBUS PropertiesChanged handler for aforementioned object
match = std::make_unique(
/* args required for this match handler */
)
while (1) {
b.process_discard();
b.wait();
}
} );
d.detach(); // detach outer thread
}
catch (const sdbusplus::exception::SdBusError& e)
{
// print exception to log file
}
catch (const std::bad_alloc& e)
{
// print exception to log file
}
catch (const std::exception& e)
{
// print exception to log file
}
}

class B.cpp

classB::classB() {
/*
create a modbus connection and store a pointer to it in one of
classB's members
*/
}

Poller.cpp

// ctor
Poller::Poller(std::shared_ptr classB_sptr): shared_classB(classB_sptr)) {

}

Poller::start () // start the poller thread
/*
create a std::thread thread and run a loop in it polling over a modbus connection. This thread is
also detached

*/
Основной поток вызывает конструктор (ctor). Затем Ctor создает поток, используя std::thread, используя лямбда-функцию. Внутри лямбды он порождает другой поток и отсоединяет его. Этот внутренний поток создает поток опроса данных, который выполняет полужесткий цикл мониторинга системной базы данных.
В конце внешней лямбда-функции мы ожидаем сообщений в системной базе данных.
В конце внешней лямбда-функции мы ожидаем сообщений в системной базе данных.
p>
Теперь перейдем к моему подходу к отладке:
Я хочу прервать работу в точке выхода одного из этих потоков. Поэтому я открываю их с помощью GDB, ставлю точку останова на pthread_exit и pthread_enter, а также ловлю throw, чтобы перехватывать любые исключения.
Я нажимаю точка останова pthread_enter, однако ни одна из других точек останова не сработает. Я пробовал пошаговый режим, и в определенный момент все LWP завершаются, но ни одна из других точек останова не срабатывает.
Мне интересно, почему это так и как мне нужно найти причину, по которой эти темы умирают сами по себе?

Подробнее здесь: https://stackoverflow.com/questions/793 ... g-with-gdb
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»