4747from drgn import FaultError
4848from drgn import Object
4949from drgn import Program
50+ from drgn import ProgramFlags
5051from drgn import sizeof
5152from drgn import StackTrace
5253from drgn .helpers .linux import access_remote_vm
5657from drgn .helpers .linux import for_each_online_cpu
5758from drgn .helpers .linux import for_each_task
5859from drgn .helpers .linux import for_each_vma
60+ from drgn .helpers .linux import task_on_cpu
5961from drgn .helpers .linux import task_state_to_char
6062from drgn .helpers .linux import vma_find
6163
@@ -765,9 +767,17 @@ def pstack_print_process(task: Object) -> None:
765767 tcomm = thread .comm .string_ ().decode ("utf-8" , errors = "replace" )
766768 st = task_state_to_char (thread )
767769 cpu = task_cpu (thread )
768- cpunote = "RUNNING ON " if cpu_curr (prog , cpu ) == thread else ""
770+ on_cpu = task_on_cpu (thread )
771+ cpunote = "RUNNING ON " if on_cpu else ""
769772 print (f" Thread { i } TID={ tid } [{ st } ] { cpunote } CPU={ cpu } ('{ tcomm } ')" )
770- kstack = prog .stack_trace (thread )
773+ try :
774+ kstack = prog .stack_trace (thread )
775+ except ValueError as e :
776+ if "cannot unwind stack of running task" in str (e ):
777+ print (f" { str (e )} " )
778+ continue
779+ else :
780+ raise
771781 if len (kstack ) > 0 and (kstack [0 ].pc & (1 << 63 )):
772782 # Kernel stack is indeed a kernel stack, print it
773783 print (
@@ -786,6 +796,8 @@ def pstack(prog: Program) -> None:
786796 parser = argparse .ArgumentParser (description = "print stack traces" )
787797 add_task_args (parser )
788798 args = parser .parse_args (sys .argv [2 :])
799+ if args .online and prog .flags & ProgramFlags .IS_LIVE :
800+ sys .exit ("error: --online: cannot unwind running tasks on live system" )
789801 for task in get_tasks (prog , args ):
790802 pstack_print_process (task )
791803 print ()
@@ -801,6 +813,11 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
801813 add_task_args (parser )
802814
803815 def run (self , prog : Program , args : argparse .Namespace ) -> None :
816+ if args .online and prog .flags & ProgramFlags .IS_LIVE :
817+ print (
818+ "--online: cannot unwind running tasks on live system, skipping"
819+ )
820+ return
804821 for task in get_tasks (prog , args ):
805822 pstack_print_process (task )
806823 print ()
0 commit comments