Ask / Submit
1

[Help] Unable to profile app with valgrind [answered]

Tracked by Jolla (In release)

asked 2019-05-11 15:42:23 +0300

Alex gravatar image

updated 2019-05-30 14:43:01 +0300

I want to profile the heap of my app using valgrind, but the app does not launch and will terminate/crash everytime.

A quick research tells me that this appears to be a known issue for programs using the library libcrypto.so.

Is there a way to successfully profile the app using valgrind, e.g. by preventing the app from being killed from SIGILL? And how to do so?

I tried to profile the app on my Sony Xperia XA2 and on my Jolla Tablet, both via terminal and via the SFOS-SDK and none worked.


Terminal output:

,---
| Sailfish OS 3.0.3.9 (Hossa)
'---
[nemo@Sailfish ~]$ valgrind --leak-check=yes --gen-suppressions=all --track-origins=yes --leak-check=full harbour-app
==20226== Memcheck, a memory error detector
==20226== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==20226== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==20226== Command: harbour-app
[...]
==20226== Conditional jump or move depends on uninitialised value(s)
==20226==    at 0x8DF8C3C: ??? (in /odm/lib/libgsl.so)
==20226==  Uninitialised value was created by a stack allocation
==20226==    at 0x8DFB15C: ??? (in /odm/lib/libgsl.so)
==20226== 
{
   <insert_a_suppression_name_here>
   Memcheck:Cond
   obj:/odm/lib/libgsl.so
}
disInstr(thumb): unhandled instruction: 0xEBAD 0x1CCA
==20226== valgrind: Unrecognised instruction at address 0xdc7d23d.
==20226==    at 0xDC7D23C: bsaes_ctr32_encrypt_blocks (in /lib/libcrypto.so.1.0.2o+git2)
==20226== Your program just tried to execute an instruction that Valgrind
==20226== did not recognise.  There are two possible reasons for this.
==20226== 1. Your program has a bug and erroneously jumped to a non-code
==20226==    location.  If you are running Memcheck and you just saw a
==20226==    warning about a bad jump, it's probably your program's fault.
==20226== 2. The instruction is legitimate but Valgrind doesn't handle it,
==20226==    i.e. it's Valgrind's fault.  If you think this is the case or
==20226==    you are not sure, please let us know and we'll try to fix it.
==20226== Either way, Valgrind will now raise a SIGILL signal which will
==20226== probably kill your program.
==20226== 
==20226== Process terminating with default action of signal 4 (SIGILL)
==20226==  Illegal opcode at address 0xDC7D23D
==20226==    at 0xDC7D23C: bsaes_ctr32_encrypt_blocks (in /lib/libcrypto.so.1.0.2o+git2)
==20226== 
==20226== HEAP SUMMARY:
[...]
==20226== 
==20226== For counts of detected and suppressed errors, rerun with: -v
==20226== ERROR SUMMARY: 430 errors from 170 contexts (suppressed: 0 from 0)
Illegal instruction
[nemo@Sailfish ~]$
edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by Alex
close date 2019-05-19 13:39:55.660232

Comments

Could you provide a test project and/or binary? I've been trying to reproduce this without luck.

vige ( 2019-05-28 10:40:28 +0300 )edit

@vige Create a SFOS application from the template inside the Application SDK and put the following code into the main:

#include <sailfishapp.h>
#include <QNetworkRequest>
#include <QNetworkAccessManager>

int main(int argc, char *argv[])
{
    QNetworkRequest request(QUrl("https://google.com"));
    QNetworkAccessManager netMan;
    netMan.get(request);

    return SailfishApp::main(argc, argv);
}
Alex ( 2019-05-30 14:27:43 +0300 )edit

Thanks. With the code above I was able to reproduce and verify that the patch really works.

vige ( 2019-06-04 13:21:06 +0300 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2019-05-18 23:51:50 +0300

Alex gravatar image

Well in the end I fixed this issue by patching valgrind by myself and installing this patched version on my device.

The issue is actually that the current valgrind version 3.14.0 has a bug or an unsupported instruction, in particular the unhandled instruction: 0xEBAD 0x1CCA, that prevents my app from starting with valgrind.


How to patch valgrind :

  1. Clone the valgrind repository: https://github.com/sailfishos/valgrind
  2. Load the submodule with git submodule update --init --recursive
  3. Patch valgrind. In this specific case I used this patch to support the instruction 0xEBAD 0x1CCA
  4. Start the Sailfish OS Build Engine inside the Application SDK
  5. Follow this guide to setup the MerSDK. Besides the installation of cmake it is also needed to install autoconf and automake to successfully build valgrind
  6. Build valgrind as described in the guide
  7. Deploy the resulting rpm-package: I was not able to directly deploy the package from the build engine because of some build errors, instead I transfered the rpm package to my physical device and installed it with pkcon install-local package
edit flag offensive delete publish link more

Comments

1

make a pr to sfos valgring now

coderus ( 2019-05-30 16:42:48 +0300 )edit

@coderus It needs to be fixed in valgrinds official codebase since the issue is inside the submodule's source code.

Alex ( 2019-05-30 16:47:08 +0300 )edit

Question tools

Follow
2 followers

Stats

Asked: 2019-05-11 15:42:23 +0300

Seen: 128 times

Last updated: May 30