| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | 
|---|---|
| 2 | // | 
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later | 
| 4 | |
| 5 | #include "stackframe.h" | 
| 6 | |
| 7 | #include <QDebug> | 
| 8 | #include <QDir> | 
| 9 | #include <QFileInfo> | 
| 10 | |
| 11 | //////////////////////////////////////////////////////////////////////// | 
| 12 | // | 
| 13 | // StackFrame | 
| 14 | // | 
| 15 | //////////////////////////////////////////////////////////////////////// | 
| 16 | |
| 17 | StackFrameData::StackFrameData() = default; | 
| 18 | |
| 19 | void StackFrameData::clear() | 
| 20 | { | 
| 21 | line = -1; | 
| 22 | function.clear(); | 
| 23 | file.clear(); | 
| 24 | module.clear(); | 
| 25 | receiver.clear(); | 
| 26 | address = ""; | 
| 27 | } | 
| 28 | |
| 29 | bool StackFrameData::isUsable() const | 
| 30 | { | 
| 31 | return usable; | 
| 32 | } | 
| 33 | |
| 34 | QString StackFrameData::toString() const | 
| 35 | { | 
| 36 | QString res; | 
| 37 | QTextStream str(&res); | 
| 38 | str << tr( "Address:") << ' '; | 
| 39 | str.setIntegerBase(16); | 
| 40 | str << address; | 
| 41 | str.setIntegerBase(10); | 
| 42 | str << ' ' | 
| 43 | << tr( "Function:") << ' ' << function << ' ' | 
| 44 | << tr( "File:") << ' ' << file << ' ' | 
| 45 | << tr( "Line:") << ' ' << line << ' ' | 
| 46 | << tr( "From:") << ' ' << module << ' ' | 
| 47 | << tr( "To:") << ' ' << receiver; | 
| 48 | return res; | 
| 49 | } | 
| 50 | |
| 51 | QString StackFrameData::toToolTip() const | 
| 52 | { | 
| 53 | const QString filePath = QDir::toNativeSeparators(file); | 
| 54 | QString res; | 
| 55 | QTextStream str(&res); | 
| 56 | str << "<html><body><table>"; | 
| 57 | if (!address.isEmpty()) | 
| 58 | str << "<tr><td>"<< tr( "Address:") << "</td><td>" | 
| 59 | << /*formatToolTipAddress(address)*/address << "</td></tr>"; | 
| 60 | if (!function.isEmpty()) | 
| 61 | str << "<tr><td>" | 
| 62 | << tr( "Function:") | 
| 63 | << "</td><td>"<< function << "</td></tr>"; | 
| 64 | if (!file.isEmpty()) | 
| 65 | str << "<tr><td>"<< tr( "File:") << "</td><td>"<< filePath << "</td></tr>"; | 
| 66 | if (line != -1) | 
| 67 | str << "<tr><td>"<< tr( "Line:") << "</td><td>"<< line << "</td></tr>"; | 
| 68 | if (!module.isEmpty()) | 
| 69 | str << "<tr><td>"<< tr( "Module:") << "</td><td>"<< module << "</td></tr>"; | 
| 70 | if (!receiver.isEmpty()) | 
| 71 | str << "<tr><td>"<< tr( "Receiver:") << "</td><td>"<< receiver << "</td></tr>"; | 
| 72 | str << "</table>"; | 
| 73 | |
| 74 | str << "<br> <br><i>"<< tr( "Note:") << " </i> "; | 
| 75 | if (isUsable()) { | 
| 76 | str << tr( "You can double click it to reatch source."); | 
| 77 | } else if (line <= 0) { | 
| 78 | str << tr( "Binary debug information is not accessible for this " | 
| 79 | "frame. This either means the core was not compiled " | 
| 80 | "with debug information, or the debug information is not " | 
| 81 | "accessible."); | 
| 82 | } else { | 
| 83 | str << tr( "Binary debug information is accessible for this " | 
| 84 | "frame. However, matching sources have not been found."); | 
| 85 | } | 
| 86 | |
| 87 | str << "</body></html>"; | 
| 88 | return res; | 
| 89 | } | 
| 90 | |
| 91 | QDebug operator<<(QDebug d, const StackFrameData &f) | 
| 92 | { | 
| 93 | QString res; | 
| 94 | QTextStream str(&res); | 
| 95 | str << "level="<< f.level << " address="<< f.address; | 
| 96 | if (!f.function.isEmpty()) | 
| 97 | str << ' ' << f.function; | 
| 98 | if (!f.file.isEmpty()) | 
| 99 | str << ' ' << f.file << ':' << f.line; | 
| 100 | if (!f.module.isEmpty()) | 
| 101 | str << " from="<< f.module; | 
| 102 | if (!f.receiver.isEmpty()) | 
| 103 | str << " to="<< f.receiver; | 
| 104 | d.nospace() << res; | 
| 105 | return d; | 
| 106 | } | 
| 107 | 
