@@ -28,7 +28,9 @@ in the source distribution for its full text.
2828#include "Macros.h"
2929#include "MainPanel.h"
3030#include "MemoryMeter.h"
31+ #include "Object.h"
3132#include "OpenFilesScreen.h"
33+ #include "Panel.h"
3234#include "Platform.h"
3335#include "Process.h"
3436#include "ProcessLocksScreen.h"
@@ -49,6 +51,10 @@ in the source distribution for its full text.
4951#include "AffinityPanel.h"
5052#endif
5153
54+ #if defined(HAVE_BACKTRACE_SCREEN )
55+ #include "BacktraceScreen.h"
56+ #endif
57+
5258
5359Object * Action_pickFromVector (State * st , Panel * list , int x , bool follow ) {
5460 MainPanel * mainPanel = st -> mainPanel ;
@@ -606,6 +612,35 @@ static Htop_Reaction actionShowLocks(State* st) {
606612 return HTOP_REFRESH | HTOP_REDRAW_BAR ;
607613}
608614
615+ #if defined(HAVE_BACKTRACE_SCREEN )
616+ static Htop_Reaction actionBacktrace (State * st ) {
617+ Process * selectedProcess = (Process * ) Panel_getSelected ((Panel * )st -> mainPanel );
618+ const Vector * allProcesses = st -> mainPanel -> super .items ;
619+
620+ Vector * processes = Vector_new (Class (Process ), false, VECTOR_DEFAULT_SIZE );
621+ if (!Process_isUserlandThread (selectedProcess )) {
622+ for (int i = 0 ; i < Vector_size (allProcesses ); i ++ ) {
623+ Process * process = (Process * )Vector_get (allProcesses , i );
624+ if (Process_getThreadGroup (process ) == Process_getThreadGroup (selectedProcess )) {
625+ Vector_add (processes , process );
626+ }
627+ }
628+ } else {
629+ Vector_add (processes , selectedProcess );
630+ }
631+
632+ BacktracePanel * panel = BacktracePanel_new (processes , st -> host -> settings );
633+ ScreenManager * screenManager = ScreenManager_new (NULL , st -> host , st , false);
634+ ScreenManager_add (screenManager , (Panel * )panel , 0 );
635+
636+ ScreenManager_run (screenManager , NULL , NULL , NULL );
637+ BacktracePanel_delete ((Object * )panel );
638+ ScreenManager_delete (screenManager );
639+
640+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR ;
641+ }
642+ #endif
643+
609644static Htop_Reaction actionStrace (State * st ) {
610645 if (!Action_writeableProcess (st ))
611646 return HTOP_OK ;
@@ -689,6 +724,9 @@ static const struct {
689724 { .key = " F8 [: " , .roInactive = true, .info = "lower priority (+ nice)" },
690725#if (defined (HAVE_LIBHWLOC ) || defined (HAVE_AFFINITY ))
691726 { .key = " a: " , .roInactive = true, .info = "set CPU affinity" },
727+ #endif
728+ #if defined(HAVE_BACKTRACE_SCREEN )
729+ { .key = " b: " , .roInactive = false, .info = "show process backtrace" },
692730#endif
693731 { .key = " e: " , .roInactive = false, .info = "show process environment" },
694732 { .key = " i: " , .roInactive = true, .info = "set IO priority" },
@@ -941,6 +979,9 @@ void Action_setBindings(Htop_Action* keys) {
941979 keys ['\\' ] = actionIncFilter ;
942980 keys [']' ] = actionHigherPriority ;
943981 keys ['a' ] = actionSetAffinity ;
982+ #if defined(HAVE_BACKTRACE_SCREEN )
983+ keys ['b' ] = actionBacktrace ;
984+ #endif
944985 keys ['c' ] = actionTagAllChildren ;
945986 keys ['e' ] = actionShowEnvScreen ;
946987 keys ['h' ] = actionHelp ;
0 commit comments