Skip to content

Commit

Permalink
Allow zero sized symbols in the address cache
Browse files Browse the repository at this point in the history
Apparently there are situations where the compiler generates entries
in the symbol table with zero size which are still referenced by some
callstacks. After commit fc12536 we ended up losing the symbol names
in such cases. This patch fixes it again and restores the symbol names
for such zero-size symbols.

Fixes: KDAB/hotspot#252
Change-Id: Ib11521bc88f719811559d1e20f27c275eb8e5606
  • Loading branch information
dknysh authored and milianw committed Sep 25, 2020
1 parent 617194e commit b0266cf
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/perfaddresscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ PerfAddressCache::SymbolCacheEntry PerfAddressCache::findSymbol(const QByteArray

--it;

if (it->offset <= relAddr && it->offset + it->size > relAddr) {
if (it->offset <= relAddr && (it->offset + it->size > relAddr || (it->size == 0))) {
// demangle symbols on demand instead of demangling all symbols directly
// hopefully most of the symbols we won't ever encounter after all
if (!it->demangled) {
Expand Down
2 changes: 1 addition & 1 deletion app/perfaddresscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PerfAddressCache
, symname(symname)
{}

bool isValid() const { return size != 0; }
bool isValid() const { return !symname.isEmpty(); }

quint64 offset;
quint64 size;
Expand Down
3 changes: 2 additions & 1 deletion tests/auto/addresscache/tst_addresscache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private slots:
QVERIFY(!cache.findSymbol(libfoo_a, 0).isValid());
QVERIFY(!cache.findSymbol(libfoo_b, 0).isValid());

cache.setSymbolCache(libfoo_a, {{0x100, 10, "Foo"}});
cache.setSymbolCache(libfoo_a, {{0x100, 10, "Foo"}, {0x11a, 0, "FooZ"}, {0x12a, 10, "FooN"}});
for (auto addr : {0x100, 0x100 + 9}) {
const auto cached = cache.findSymbol(libfoo_a, addr);
QVERIFY(cached.isValid());
Expand All @@ -83,6 +83,7 @@ private slots:
QVERIFY(!cache.findSymbol(libfoo_a, 0x100 + 10).isValid());
QVERIFY(!cache.findSymbol(libfoo_b, 0x100).isValid());
QVERIFY(!cache.findSymbol(libfoo_b, 0x100 + 9).isValid());
QVERIFY(cache.findSymbol(libfoo_a, 0x11a + 1).isValid());
}
};

Expand Down
3 changes: 2 additions & 1 deletion tests/auto/perfdata/vector_static_gcc/perf.data.expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ vector_static_g 349054 349054 65149.476874692
vector_static_g 349054 349054 65149.477126147
cycles: 315591

400480 <.plt+400480> vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
400480
400430 _init vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
40155c /usr/include/c++/9.1.0/bits/stl_algo.h:4449:13
40152b /usr/include/c++/9.1.0/bits/stl_algo.h:4441:5 std::generate_n<std::back_insert_iterator<std::vector<double> >, int, main()::<lambda()> > vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
40152b ../../../manual/clients/vector.cpp:16:6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ vector_static_g 267677 267677 9952.368475245
vector_static_g 267677 267677 9952.368668898
cycles: 415081

400490 <.plt+400490> vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
400490
400430 _init vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
401572 /usr/include/c++/9.1.0/bits/stl_algo.h:4449:13
40152b /usr/include/c++/9.1.0/bits/stl_algo.h:4441:5 std::generate_n<std::back_insert_iterator<std::vector<double> >, int, main()::<lambda()> > vector_static_gcc_v9.1.0 /home/milian/projects/kdab/rnd/hotspot/3rdparty/perfparser/tests/auto/perfdata/vector_static_gcc/vector_static_gcc_v9.1.0
40152b ../../../manual/clients/vector.cpp:16:6
Expand Down

0 comments on commit b0266cf

Please sign in to comment.