@@ -826,30 +826,38 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
826
826
int width = 0 ;
827
827
for (int i = 0 ; i < depth; ++i) {
828
828
Dl_info dlinfo;
829
- dladdr (StackTrace[i], &dlinfo);
830
- const char *name = strrchr (dlinfo.dli_fname , ' /' );
831
-
832
829
int nwidth;
833
- if (!name)
834
- nwidth = strlen (dlinfo.dli_fname );
835
- else
836
- nwidth = strlen (name) - 1 ;
830
+ if (dladdr (StackTrace[i], &dlinfo) == 0 ) {
831
+ nwidth = 7 ; // "(error)"
832
+ } else {
833
+ const char *name = strrchr (dlinfo.dli_fname , ' /' );
834
+
835
+ if (!name)
836
+ nwidth = strlen (dlinfo.dli_fname );
837
+ else
838
+ nwidth = strlen (name) - 1 ;
839
+ }
837
840
838
841
if (nwidth > width)
839
842
width = nwidth;
840
843
}
841
844
842
845
for (int i = 0 ; i < depth; ++i) {
843
846
Dl_info dlinfo;
844
- dladdr (StackTrace[i], &dlinfo);
845
847
846
848
OS << format (" %-2d" , i);
847
849
848
- const char *name = strrchr (dlinfo.dli_fname , ' /' );
849
- if (!name)
850
- OS << format (" %-*s" , width, static_cast <const char *>(dlinfo.dli_fname ));
851
- else
852
- OS << format (" %-*s" , width, name + 1 );
850
+ if (dladdr (StackTrace[i], &dlinfo) == 0 ) {
851
+ OS << format (" %-*s" , width, static_cast <const char *>(" (error)" ));
852
+ dlinfo.dli_sname = nullptr ;
853
+ } else {
854
+ const char *name = strrchr (dlinfo.dli_fname , ' /' );
855
+ if (!name)
856
+ OS << format (" %-*s" , width,
857
+ static_cast <const char *>(dlinfo.dli_fname ));
858
+ else
859
+ OS << format (" %-*s" , width, name + 1 );
860
+ }
853
861
854
862
OS << format (" %#0*lx" , (int )(sizeof (void *) * 2 ) + 2 ,
855
863
(unsigned long )StackTrace[i]);
0 commit comments