diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2022-05-28 21:57:55 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2022-06-08 20:18:08 +0000 |
commit | f8457c36810dc8cfc2acf5687b704a3c71874c80 (patch) | |
tree | 5191d39c34c3ca189d59c0b9f87fced746664d81 | |
parent | 17f5814ffe62697096d0482a43cbc35f4953e123 (diff) |
Introduce findSourceLocation utility
Move the code from perfsymboltable into perfdwarfdiecache. This
simplifies the perfsymboltable code and allows reuse of this generic
code.
Change-Id: Ibeebe2312d49095adad60f2924e1be8d74d82dfe
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | app/perfdwarfdiecache.cpp | 13 | ||||
-rw-r--r-- | app/perfdwarfdiecache.h | 19 | ||||
-rw-r--r-- | app/perfsymboltable.cpp | 13 |
3 files changed, 36 insertions, 9 deletions
diff --git a/app/perfdwarfdiecache.cpp b/app/perfdwarfdiecache.cpp index 6f9243f..123ebac 100644 --- a/app/perfdwarfdiecache.cpp +++ b/app/perfdwarfdiecache.cpp @@ -259,6 +259,19 @@ QVector<Dwarf_Die> findInlineScopes(Dwarf_Die *subprogram, Dwarf_Addr offset) return scopes; } +DwarfSourceLocation findSourceLocation(Dwarf_Die* cuDie, Dwarf_Addr offset) +{ + DwarfSourceLocation ret; + if (auto srcloc = dwarf_getsrc_die(cuDie, offset)) { + if (const char* srcfile = dwarf_linesrc(srcloc, nullptr, nullptr)) { + ret.file = srcfile; + dwarf_lineno(srcloc, &ret.line); + dwarf_linecol(srcloc, &ret.column); + } + } + return ret; +} + SubProgramDie::SubProgramDie(Dwarf_Die die) : m_ranges{die, {}} { diff --git a/app/perfdwarfdiecache.h b/app/perfdwarfdiecache.h index 26183b1..a268d94 100644 --- a/app/perfdwarfdiecache.h +++ b/app/perfdwarfdiecache.h @@ -108,6 +108,25 @@ private: */ QVector<Dwarf_Die> findInlineScopes(Dwarf_Die *subprogram, Dwarf_Addr offset); +struct DwarfSourceLocation +{ + QByteArray file; + int line = -1; + int column = -1; + + explicit operator bool() const + { + return !file.isEmpty(); + } +}; +/** + * @return the file name, line number and column for the instruction at the given @p offset in @p cuDie + * @p cuDie CU DIE that should be queried + * @p offset bias-corrected address of an instruction for which the information should be found + * @sa CuDieRangeMapping + */ +DwarfSourceLocation findSourceLocation(Dwarf_Die* cuDie, Dwarf_Addr offset); + /** * This cache makes it easily possible to find a CU DIE (i.e. Compilation Unit Debugging Information Entry) * based on a diff --git a/app/perfsymboltable.cpp b/app/perfsymboltable.cpp index 27b54ad..63eef45 100644 --- a/app/perfsymboltable.cpp +++ b/app/perfsymboltable.cpp @@ -841,15 +841,10 @@ int PerfSymbolTable::lookupFrame(Dwarf_Addr ip, bool isKernel, if (cudie) { bias = cudie->bias(); const auto offset = addressLocation.address - bias; - auto srcloc = dwarf_getsrc_die(cudie->cudie(), offset); - if (srcloc) { - const char* srcfile = dwarf_linesrc(srcloc, nullptr, nullptr); - if (srcfile) { - const QByteArray file = srcfile; - addressLocation.file = m_unwind->resolveString(file); - dwarf_lineno(srcloc, &addressLocation.line); - dwarf_linecol(srcloc, &addressLocation.column); - } + if (auto srcloc = findSourceLocation(cudie->cudie(), offset)) { + addressLocation.file = m_unwind->resolveString(srcloc.file); + addressLocation.line = srcloc.line; + addressLocation.column = srcloc.column; } auto *subprogram = cudie->findSubprogramDie(offset); |