Android: Add Thread.sleep before loading main in Debug mode

This helps with the jdb debugging settling, and the native debugger
can hit breakpoints at the beginning of main() function or in case
of unittests at initTestCase() function.

By default in debug mode the delay is 1000ms. This value can be changed
with the environment variable: QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS

Fixes: QTCREATORBUG-30425
Pick-to: 6.7 6.7.0
Change-Id: Ica0c6080c55468579a28eecf8f45cff68d99c3a8
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
bb10
Cristian Adam 2024-03-06 16:51:24 +01:00 committed by Cristian Adam
parent 91b04d5cf1
commit 269187bfa2
3 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.system.Os;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
@ -134,6 +135,14 @@ class QtActivityLoader extends QtLoader {
String extraAppParams = extras.getString("extraappparams");
appendApplicationParameters(getDecodedUtfString(extraAppParams));
}
m_debuggerSleepMs = 1000;
if (Os.getenv("QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS") != null) {
try {
m_debuggerSleepMs = Integer.parseInt(Os.getenv("QT_ANDROID_DEBUGGER_MAIN_THREAD_SLEEP_MS"));
} catch (NumberFormatException ignored) {
}
}
} else {
Log.d(QtNative.QtTAG, "Not in debug mode! It is not allowed to use extra arguments " +
"in non-debug mode.");

View File

@ -46,6 +46,8 @@ abstract class QtLoader {
protected String m_applicationParameters = "";
protected HashMap<String, String> m_environmentVariables = new HashMap<>();
protected int m_debuggerSleepMs = 0;
/**
* Sets and initialize the basic pieces.
* Initializes the class loader since it doesn't rely on anything
@ -509,6 +511,9 @@ abstract class QtLoader {
String mainLibPath = getLibrariesFullPaths(oneEntryArray).get(0);
final boolean[] success = {true};
QtNative.getQtThread().run(() -> {
if (m_debuggerSleepMs > 0)
QtNative.getQtThread().sleep(m_debuggerSleepMs);
m_mainLibPath = loadLibraryHelper(mainLibPath);
if (m_mainLibPath == null)
success[0] = false;

View File

@ -42,6 +42,14 @@ class QtThread {
}
}
public void sleep(int milliseconds) {
try {
m_qtThread.sleep(milliseconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run(final Runnable runnable) {
final Semaphore sem = new Semaphore(0);
synchronized (m_qtThread) {