@@ -34,34 +34,45 @@ in the source distribution for its full text.
3434#if defined(HAVE_BACKTRACE_SCREEN )
3535
3636static const char * const BacktraceScreenFunctions [] = {
37+ #if defined(HAVE_DEMANGLING )
38+ "Mangle " ,
39+ #endif
3740 "Full Path" ,
3841 "Refresh" ,
3942 "Done " ,
4043 NULL
4144};
4245
4346static const char * const BacktraceScreenKeys [] = {
47+ #if defined(HAVE_DEMANGLING )
48+ "F2" ,
49+ #endif
4450 "F3" ,
4551 "F5" ,
4652 "Esc" ,
4753 NULL
4854};
4955
5056static const int BacktraceScreenEvents [] = {
57+ #if defined(HAVE_DEMANGLING )
58+ KEY_F (2 ),
59+ #endif
5160 KEY_F (3 ),
5261 KEY_F (5 ),
5362 27 ,
5463};
5564
5665typedef enum BacktraceScreenDisplayOptions_ {
57- SHOW_FULL_PATH_OBJECT = 1 << 0 ,
66+ DEMANGLE_NAME_FUNCTION = 1 << 0 ,
67+ SHOW_FULL_PATH_OBJECT = 1 << 1 ,
5868} BacktraceScreenDisplayOptions ;
5969
6070BacktraceFrameData * BacktraceFrameData_new (void ) {
6171 BacktraceFrameData * this = AllocThis (BacktraceFrameData );
6272 this -> address = 0 ;
6373 this -> offset = 0 ;
6474 this -> functionName = NULL ;
75+ this -> demangleFunctionName = NULL ;
6576 this -> objectPath = NULL ;
6677 this -> index = 0 ;
6778 this -> isSignalFrame = false;
@@ -71,6 +82,7 @@ BacktraceFrameData* BacktraceFrameData_new(void) {
7182void BacktraceFrameData_delete (Object * object ) {
7283 BacktraceFrameData * this = (BacktraceFrameData * )object ;
7384 free (this -> functionName );
85+ free (this -> demangleFunctionName );
7486 free (this -> objectPath );
7587 free (this );
7688}
@@ -79,6 +91,8 @@ static void BacktracePanel_displayHeader(BacktracePanel* this) {
7991 const BacktracePanelPrintingHelper * printingHelper = & this -> printingHelper ;
8092 const int displayOptions = this -> displayOptions ;
8193
94+ bool showDemangledNames = (displayOptions & DEMANGLE_NAME_FUNCTION ) && printingHelper -> hasDemangledNames ;
95+
8296 bool showFullPathObject = !!(displayOptions & SHOW_FULL_PATH_OBJECT );
8397 size_t maxObjLen = showFullPathObject ? printingHelper -> maxObjPathLen : printingHelper -> maxObjNameLen ;
8498
@@ -95,7 +109,7 @@ static void BacktracePanel_displayHeader(BacktracePanel* this) {
95109 (int )printingHelper -> maxFrameNumLen , "#" ,
96110 (int )(printingHelper -> maxAddrLen + strlen ("0x" )), "ADDRESS" ,
97111 (int )maxObjLen , "FILE" ,
98- "NAME"
112+ ( showDemangledNames ? "NAME (demangled)" : "NAME" )
99113 );
100114
101115 Panel_setHeader ((Panel * )this , line );
@@ -112,12 +126,17 @@ static void BacktracePanel_makePrintingHelper(const BacktracePanel* this, Backtr
112126 unsigned int maxFrameNum = 0 ;
113127 size_t longestAddress = 0 ;
114128
129+ printingHelper -> hasDemangledNames = false;
130+
115131 for (int i = 0 ; i < Vector_size (lines ); i ++ ) {
116132 const BacktracePanelRow * row = (const BacktracePanelRow * )Vector_get (lines , i );
117133 if (row -> type != BACKTRACE_PANEL_ROW_DATA_FRAME ) {
118134 continue ;
119135 }
120136
137+ if (row -> data .frame -> demangleFunctionName )
138+ printingHelper -> hasDemangledNames = true;
139+
121140 if (row -> data .frame -> objectPath ) {
122141 const char * objectName = getBasename (row -> data .frame -> objectPath );
123142 size_t objectNameLength = strlen (objectName );
@@ -193,6 +212,18 @@ static HandlerResult BacktracePanel_eventHandler(Panel* super, int ch) {
193212 HandlerResult result = IGNORED ;
194213
195214 switch (ch ) {
215+ #if defined(HAVE_DEMANGLING )
216+ case KEY_F (2 ):
217+ * displayOptions ^= DEMANGLE_NAME_FUNCTION ;
218+
219+ bool showDemangledNames = !!(* displayOptions & DEMANGLE_NAME_FUNCTION );
220+ FunctionBar_setLabel (super -> defaultBar , KEY_F (2 ), showDemangledNames ? "Mangle " : "Demangle" );
221+
222+ this -> super .needsRedraw = true;
223+ BacktracePanel_displayHeader (this );
224+ break ;
225+ #endif
226+
196227 case 'p' :
197228 case KEY_F (3 ):
198229 * displayOptions ^= SHOW_FULL_PATH_OBJECT ;
@@ -222,9 +253,11 @@ BacktracePanel* BacktracePanel_new(Vector* processes, const Settings* settings)
222253 this -> printingHelper .maxFrameNumLen = strlen ("#" );
223254 this -> printingHelper .maxObjNameLen = strlen ("FILE" );
224255 this -> printingHelper .maxObjPathLen = strlen ("FILE" );
256+ this -> printingHelper .hasDemangledNames = false;
225257
226258 this -> settings = settings ;
227259 this -> displayOptions =
260+ DEMANGLE_NAME_FUNCTION |
228261 (settings -> showProgramPath ? SHOW_FULL_PATH_OBJECT : 0 ) |
229262 0 ;
230263
@@ -331,7 +364,12 @@ static void BacktracePanelRow_displayFrame(const Object* super, RichString* out)
331364
332365 const BacktraceFrameData * frame = row -> data .frame ;
333366
334- const char * functionName = frame -> functionName ? frame -> functionName : "???" ;
367+ const char * functionName = "???" ;
368+ if ((displayOptions & DEMANGLE_NAME_FUNCTION ) && frame -> demangleFunctionName ) {
369+ functionName = frame -> demangleFunctionName ;
370+ } else if (frame -> functionName ) {
371+ functionName = frame -> functionName ;
372+ }
335373
336374 char * completeFunctionName = NULL ;
337375 xAsprintf (& completeFunctionName , "%s+0x%zx" , functionName , frame -> offset );
0 commit comments