| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
|---|---|
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "breakpointitem.h" |
| 6 | #include "breakpoint.h" |
| 7 | |
| 8 | #include <QDir> |
| 9 | #include <QTextStream> |
| 10 | |
| 11 | using namespace Internal; |
| 12 | |
| 13 | const QString empty(QLatin1Char('-')); |
| 14 | |
| 15 | BreakpointItem::BreakpointItem(const Internal::Breakpoint &_bp) |
| 16 | : bp(_bp) |
| 17 | { |
| 18 | |
| 19 | } |
| 20 | |
| 21 | BreakpointItem::BreakpointItem(const BreakpointItem &item) |
| 22 | : bp(item.breakpoint()) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | BreakpointItem::BreakpointItem() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | BreakpointItem::~BreakpointItem() |
| 31 | { |
| 32 | |
| 33 | } |
| 34 | |
| 35 | QVariant BreakpointItem::data(int row, int column, int role) const |
| 36 | { |
| 37 | switch (column) { |
| 38 | case kIndexColumn: |
| 39 | if (role == Qt::DisplayRole) |
| 40 | return QString::number(row + 1); |
| 41 | break; |
| 42 | case kFunctionNameColumn: |
| 43 | if (role == Qt::DisplayRole) |
| 44 | return QString("-"); |
| 45 | break; |
| 46 | case kFileNameColumn: |
| 47 | if (role == Qt::DisplayRole) { |
| 48 | QString str = bp.fileName; |
| 49 | if (!str.isEmpty()) |
| 50 | return QDir::toNativeSeparators(str); |
| 51 | return empty; |
| 52 | } |
| 53 | break; |
| 54 | case kLineNumberColumn: |
| 55 | if (role == Qt::DisplayRole) { |
| 56 | if (bp.lineNumber > 0) |
| 57 | return bp.lineNumber; |
| 58 | return empty; |
| 59 | } |
| 60 | break; |
| 61 | case kAddressColumn: |
| 62 | if (role == Qt::DisplayRole) { |
| 63 | return bp.address; |
| 64 | } |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | if (role == Qt::ToolTipRole) |
| 69 | return toolTip(); |
| 70 | |
| 71 | return QVariant(); |
| 72 | } |
| 73 | |
| 74 | QString BreakpointItem::markerFileName() const |
| 75 | { |
| 76 | return bp.fileName; |
| 77 | } |
| 78 | |
| 79 | int BreakpointItem::markerLineNumber() const |
| 80 | { |
| 81 | return bp.lineNumber; |
| 82 | } |
| 83 | |
| 84 | int BreakpointItem::modelId() const |
| 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static QString msgBreakpointAtSpecialFunc(const QString &func) |
| 90 | { |
| 91 | return BreakpointItem::tr("Breakpoint at \"%1\"").arg(func); |
| 92 | } |
| 93 | |
| 94 | static QString typeToString(BreakpointType type) |
| 95 | { |
| 96 | switch (type) { |
| 97 | case BreakpointByFileAndLine: |
| 98 | return BreakpointItem::tr("Breakpoint by File and Line"); |
| 99 | case BreakpointByFunction: |
| 100 | return BreakpointItem::tr("Breakpoint by Function"); |
| 101 | case BreakpointByAddress: |
| 102 | return BreakpointItem::tr("Breakpoint by Address"); |
| 103 | case BreakpointAtThrow: |
| 104 | return msgBreakpointAtSpecialFunc("throw"); |
| 105 | case BreakpointAtCatch: |
| 106 | return msgBreakpointAtSpecialFunc("catch"); |
| 107 | case BreakpointAtExec: |
| 108 | return msgBreakpointAtSpecialFunc("exec"); |
| 109 | //case BreakpointAtVFork: |
| 110 | // return msgBreakpointAtSpecialFunc("vfork"); |
| 111 | case UnknownBreakpointType: |
| 112 | case LastBreakpointType: |
| 113 | break; |
| 114 | } |
| 115 | return BreakpointItem::tr("Unknown Breakpoint Type"); |
| 116 | } |
| 117 | |
| 118 | QString BreakpointItem::toolTip() const |
| 119 | { |
| 120 | QString rc; |
| 121 | QTextStream str(&rc); |
| 122 | str << "<html><body><b>"<< BreakpointItem::tr( "Unclaimed Breakpoint") << "</b>" |
| 123 | << "<table>" |
| 124 | //<< "<tr><td>" << tr("ID:") << "</td><td>" << m_id << "</td></tr>" |
| 125 | << "<tr><td>"<< BreakpointItem::tr( "State:") |
| 126 | << "</td><td>"<< (bp.enabled ? BreakpointItem::tr( "Enabled") : BreakpointItem::tr( "Disabled")) |
| 127 | << "<tr><td>"<< BreakpointItem::tr( "Breakpoint Type:") |
| 128 | << "</td><td>"<< typeToString(bp.type) << "</td></tr>"; |
| 129 | if (bp.type == BreakpointByFunction) { |
| 130 | str << "<tr><td>"<< BreakpointItem::tr( "Function Name:") |
| 131 | << "</td><td>"<< bp.functionName |
| 132 | << "</td></tr>"; |
| 133 | } |
| 134 | if (bp.type == BreakpointByFileAndLine) { |
| 135 | str << "<tr><td>"<< BreakpointItem::tr( "File Name:") |
| 136 | << "</td><td>"<< QDir::toNativeSeparators(bp.fileName) |
| 137 | << "</td></tr>" |
| 138 | << "<tr><td>"<< BreakpointItem::tr( "Line Number:") |
| 139 | << "</td><td>"<< bp.lineNumber; |
| 140 | } |
| 141 | if (bp.type == BreakpointByFunction || bp.type == BreakpointByFileAndLine) { |
| 142 | str << "<tr><td>"<< BreakpointItem::tr( "Module:") |
| 143 | << "</td><td>"<< bp.module |
| 144 | << "</td></tr>"; |
| 145 | } |
| 146 | str << "<tr><td>"<< BreakpointItem::tr( "Breakpoint Address:") << "</td><td>"; |
| 147 | str << bp.address; |
| 148 | str << "</td></tr>"; |
| 149 | |
| 150 | str << "</table></body></html><hr>"; |
| 151 | return rc; |
| 152 | } |
| 153 | |
| 154 | int BreakpointItem::lineNumber() const |
| 155 | { |
| 156 | return bp.lineNumber; |
| 157 | } |
| 158 | |
| 159 | bool BreakpointItem::isEnabled() const |
| 160 | { |
| 161 | return bp.enabled; |
| 162 | } |
| 163 | |
| 164 | void BreakpointItem::setEnabled(bool on) |
| 165 | { |
| 166 | bp.enabled = on; |
| 167 | } |
| 168 |