1414#include < QRegularExpression>
1515#include < QStandardPaths>
1616
17+ namespace {
18+ DisassemblyOutput::LinkedFunction extractLinkedFunction (const QString& disassembly)
19+ {
20+ DisassemblyOutput::LinkedFunction function = {};
21+
22+ const auto leftBracketIndex = disassembly.indexOf (QLatin1Char (' <' ));
23+ const auto rightBracketIndex = disassembly.indexOf (QLatin1Char (' >' ));
24+ if (leftBracketIndex != -1 && rightBracketIndex != -1 ) {
25+ if (leftBracketIndex < rightBracketIndex) {
26+ function.name = disassembly.mid (leftBracketIndex + 1 , rightBracketIndex - leftBracketIndex - 1 );
27+
28+ const auto atindex = function.name .indexOf (QLatin1Char (' @' ));
29+ if (atindex > 0 ) {
30+ function.name = function.name .left (atindex);
31+ }
32+
33+ const auto plusIndex = function.name .indexOf (QLatin1Char (' +' ));
34+ if (plusIndex > 0 ) {
35+ bool ok;
36+ // ignore 0x in offset
37+ const auto & offsetStr = function.name .mid (plusIndex + 3 );
38+ function.name = function.name .left (plusIndex);
39+ auto offset = offsetStr.toInt (&ok, 16 );
40+ if (ok) {
41+ function.offset = offset;
42+ }
43+ }
44+ }
45+ }
46+ return function;
47+ }
48+ }
49+
1750static QVector<DisassemblyOutput::DisassemblyLine> objdumpParse (const QByteArray &output)
1851{
1952 QVector<DisassemblyOutput::DisassemblyLine> disassemblyLines;
@@ -22,7 +55,7 @@ static QVector<DisassemblyOutput::DisassemblyLine> objdumpParse(const QByteArray
2255 QString asmLine;
2356 // detect lines like:
2457 // 4f616: 84 c0 test %al,%al
25- static const QRegularExpression disassemblyRegex (QStringLiteral (" ^ ([0-9a-f]{4,}):\t [0-9a-f ]{2,}" ));
58+ static const QRegularExpression disassemblyRegex (QStringLiteral (" ^[ ]+ ([0-9a-f]{4,}):\t [0-9a-f ]{2,}" ));
2659 while (stream.readLineInto (&asmLine))
2760 {
2861 if (asmLine.isEmpty () || asmLine.startsWith (QLatin1String (" Disassembly" )))
@@ -51,7 +84,7 @@ static QVector<DisassemblyOutput::DisassemblyLine> objdumpParse(const QByteArray
5184 }
5285 }
5386
54- disassemblyLines.push_back ({addr, asmLine});
87+ disassemblyLines.push_back ({addr, asmLine, extractLinkedFunction (asmLine) });
5588 }
5689 return disassemblyLines;
5790}
@@ -85,6 +118,7 @@ DisassemblyOutput DisassemblyOutput::disassemble(const QString& objdump, const Q
85118 auto toHex = [](quint64 addr) -> QString { return QLatin1String (" 0x" ) + QString::number (addr, 16 ); };
86119 const auto arguments = QStringList {QStringLiteral (" -d" ),
87120 QStringLiteral (" -S" ),
121+ QStringLiteral (" -C" ),
88122 QStringLiteral (" --start-address" ),
89123 toHex (symbol.relAddr ),
90124 QStringLiteral (" --stop-address" ),
0 commit comments