Debugging stalled threads - volatile variables, others?

scotthauck
Posts: 20
Joined: Fri Jul 26, 2019 5:50 pm

Debugging stalled threads - volatile variables, others?

Postby scotthauck » Wed Aug 07, 2019 8:55 pm

Quick questions: any good way to find out WHERE a thread is stalling out, particularly a packet event handler for Wifi?

My current plan is to put in lots of writes to a volatile variable in the code that is stalling, and have the main loop (which is still running) print out that variable's value periodically.

* Will this work? I'm assuming the compiler will NOT move the volatile writes within the code, but perhaps that isn't the case.

* Is there some other magical way to find out where a stalled thread is stalling out?

Context: I'm sending a continuous stream of UDP packets to the ESP32, and it periodically hangs the message handling. The send rate isn't high (10 a second for example). I do know UDP can drop packets, which shouldn't be an issue. Anyone see something like this before? Too early to ask about the specific code, since haven't deeply debugged it yet, but perhaps this will sound familiar to someone.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Debugging stalled threads - volatile variables, others?

Postby lbernstone » Thu Aug 08, 2019 7:38 pm

Your method should work to track the activity in the function, but is subject to Heisenberg probabilities, as Serial.print is a fairly slow method which may "unbind" timing issues :D . I would recommend using the AsyncUDP library if you are doing a lot of time sensitive UDP comms. Work has been done recently to improve reliability of the lwip stack, so use the github repo code and see https://github.com/espressif/arduino-esp32/pull/2912

scotthauck
Posts: 20
Joined: Fri Jul 26, 2019 5:50 pm

Re: Debugging stalled threads - volatile variables, others?

Postby scotthauck » Fri Aug 09, 2019 1:31 am

Thanks for the pointer. I am using AsyncUDP, but I'll try updating to the newest version - did grab the ESP32 support package just in the last few weeks, but perhaps the separate library may be newer.

Serial.print as a timing issue - when the system locks up for me, it locks up forever afterwards - tons of Serial.print's in the main loop happen with the UDP recieve side stalled.

Thanks!

scotthauck
Posts: 20
Joined: Fri Jul 26, 2019 5:50 pm

Re: Debugging stalled threads - volatile variables, others?

Postby scotthauck » Fri Aug 09, 2019 2:33 am

FYI, applying that patch seems to have fixed my problem - thanks!

Who is online

Users browsing this forum: No registered users and 76 guests