3

I'm currently implementing a watchdog functionality in a multithreaded program where one thread observes the others and checks if they are stuck. If a thread is stuck for a long time, the watchdog thread prints an error.

I would like to add the program counter of the hanging thread to the error message which can be in kernel land. How would I achieve this info from command line or c++?

System is yocto/poky for arm.

Regards

Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43
Desperado17
  • 835
  • 6
  • 12
  • And what is "program counter" in this context? – user7860670 Jan 15 '19 at 09:33
  • The cpu instruction pointer of the thread. – Desperado17 Jan 15 '19 at 09:39
  • have a look to this question: https://stackoverflow.com/questions/6402160/getting-a-backtrace-of-other-thread (and answers), and have a look to https://www.nongnu.org/libunwind/ - can signals be raised to threads in kernel-land? – Sigi Jan 15 '19 at 09:55
  • Printing just the instruction pointer is rarely useful. Consider the case when it is inside a common function like read(). You need to print the stack trace, ie how the program got to that pointer. – rustyx Jan 15 '19 at 11:25
  • ‘PTRACE_GETREGS’ will do exactly what you want. There is also the pid proc directory. – artless noise Jan 15 '19 at 14:43
  • why would any thread should be stuck in the first place? – Nayfe Feb 16 '19 at 11:42

0 Answers0