Changeset 106:706c82fbaa8c in rrlib_util


Ignore:
Timestamp:
29.01.2014 16:29:41 (6 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Made backtrace more robust against whitespace in filenames

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exception/tTraceableExceptionBase.cpp

    r105 r106  
    122122            *end++ = 0; 
    123123            map_entries.push_back({reinterpret_cast<void *>(strtoll(begin, nullptr, 16)), reinterpret_cast<void *>(strtoll(end, nullptr, 16)), ""}); 
    124             input >> map_entries.back().filename; 
     124            std::ws(input); 
     125            std::getline(input, map_entries.back().filename); 
    125126          } 
    126127        } 
     
    171172 
    172173        std::stringstream run_addr2line; 
    173         run_addr2line << "addr2line -fpCe " << it->filename << " " << address; 
    174         std::cout << run_addr2line.str() << std::endl; 
     174        std::string filename = it->filename; 
     175        size_t position = 0; 
     176        while ((position = filename.find_first_of("\\\"", position)) != filename.npos) 
     177        { 
     178          filename.insert(position, "\\"); 
     179          position += 2; 
     180        } 
     181        run_addr2line << "addr2line -fpCe \"" << filename << "\" " << address << " 2> /dev/null"; 
    175182        FILE *pipe = popen(run_addr2line.str().c_str(), "r"); 
    176183        if (pipe) 
     
    188195        location.erase(location.find_last_not_of("\n\r\t ") + 1); 
    189196 
    190         auto unknown = location.find("at ??"); 
    191         if (unknown != location.npos) 
    192         { 
    193           location.erase(unknown); 
    194           location += "from " + it->filename; 
    195         } 
    196  
    197         return location; 
     197        if (!location.empty()) 
     198        { 
     199          auto unknown = location.find("at ??"); 
     200          if (unknown != location.npos) 
     201          { 
     202            location.erase(unknown); 
     203            location += "from " + it->filename; 
     204          } 
     205          return location; 
     206        } 
    198207      } 
    199208    } 
Note: See TracChangeset for help on using the changeset viewer.