void trackNewThread(pid_t threadId)
{
int wRet = waitpid(threadId, &status, __WALL);
if (WIFEXITED(status) || !WIFSTOPPED(status))
{
// unfortunately I return sometimes as WIFEXITED(status) return true
return;
}
// some config
util::setHardwareWatchpoint(threadId, m_var.address, m_var.size);
long pRet = ptrace(PTRACE_SETOPTIONS, threadId, nullptr, PTRACE_O_TRACECLONE);
// continue
pRet = ptrace(PTRACE_CONT, threadId, nullptr, nullptr);
}
< /code>
К сожалению, waitpid () в TrackNewThread () не гарантированно будет запускаться, как указано на странице MAN для PTRACE (2): < /p>
PTRACE_O_TRACECLONE (since Linux 2.5.46)
Stop the tracee at the next clone(2) and
automatically start tracing the newly cloned
process, which will start with a SIGSTOP, or
PTRACE_EVENT_STOP if PTRACE_SEIZE was used. A
waitpid(2) by the tracer will return a status value
such that
status\>\>8 == (SIGTRAP | (PTRACE_EVENT_CLONE\
int main()
{
std::thread t(
[]()
{
std::thread tIndirect(
[]()
{
for (int i = 0; i < 1000; ++i)
{
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79777366/ptrace-track-nested-thread[/url]
// handle new threads if (event == PTRACE_EVENT_CLONE) { pid_t newTid = 0; // threadId of new thread pRet = ptrace(PTRACE_GETEVENTMSG, threadId, nullptr, &newTid);
trackNewThread(newTid); } } [/code] , где TrackNewThread () устанавливает некоторые параметры в новый поток, а в моем случае также устанавливает регистры отладки, вот упрощенный код: [code]void trackNewThread(pid_t threadId) { int wRet = waitpid(threadId, &status, __WALL);
if (WIFEXITED(status) || !WIFSTOPPED(status)) { // unfortunately I return sometimes as WIFEXITED(status) return true return; }
// some config util::setHardwareWatchpoint(threadId, m_var.address, m_var.size); long pRet = ptrace(PTRACE_SETOPTIONS, threadId, nullptr, PTRACE_O_TRACECLONE);
// continue pRet = ptrace(PTRACE_CONT, threadId, nullptr, nullptr); } < /code> К сожалению, waitpid () в TrackNewThread () не гарантированно будет запускаться, как указано на странице MAN для PTRACE (2): < /p> PTRACE_O_TRACECLONE (since Linux 2.5.46) Stop the tracee at the next clone(2) and automatically start tracing the newly cloned process, which will start with a SIGSTOP, or PTRACE_EVENT_STOP if PTRACE_SEIZE was used. A waitpid(2) by the tracer will return a status value such that
status\>\>8 == (SIGTRAP | (PTRACE_EVENT_CLONE\ int main() { std::thread t( []() { std::thread tIndirect( []() { for (int i = 0; i < 1000; ++i) { std::cout