Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4173 Change bsim command line script to not specify MAXMEM

ghidra1ad532036ab01
diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java
index e318d598f3..9b8e7137aa 100644
--- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java
+++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/BSimControlLaunchable.java
@@ -1426,27 +1426,31 @@ public class BSimControlLaunchable implements GhidraLaunchable {
}
}
+ private static void printUsage() {
+ //@formatter:off
+ System.err.println("\n" +
+ "USAGE: bsim_ctl [command] required-args... [OPTIONS...}\n\n" +
+ " start </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"] [--dn \"<distinguished-name>\"]\n" +
+ " stop </datadir-path> [--force]\n" +
+ " adduser </datadir-path> <username> [--dn \"<distinguished-name>\"]\n" +
+ " dropuser </datadir-path> <username>\n" +
+ " changeauth </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"]\n" +
+ " resetpassword <username>\n" +
+ " changeprivilege <username> admin|user\n" +
+ "\n" +
+ "Global options:\n" +
+ " --port|-p <portnum>\n" +
+ " --user|-u <username>\n" +
+ " --cert </certfile-path>\n" +
+ "\n" +
+ "NOTE: Options with values may also be specified using the form: --option=value\n");
+ //@formatter:on
+ }
+
@Override
public void launch(GhidraApplicationLayout ghidraLayout, String[] params) {
if (params.length <= 1) {
- //@formatter:off
- System.err.println("USAGE: bsim_ctl [command] required-args... [OPTIONS...}\n");
- System.err.println(" start </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"] [--dn \"<distinguished-name>\"]");
- System.err.println(" stop </datadir-path> [--force]");
- System.err.println(" adduser </datadir-path> <username> [--dn \"<distinguished-name>\"]");
- System.err.println(" dropuser </datadir-path> <username>");
- System.err.println(" changeauth </datadir-path> [--auth|-a pki|password|trust] [--noLocalAuth] [--cafile \"</cacert-path>\"]");
- System.err.println(" resetpassword <username>");
- System.err.println(" changeprivilege <username> admin|user");
- System.err.println();
- System.err.println("Global options:");
- System.err.println(" --port|-p <portnum>");
- System.err.println(" --user|-u <username>");
- System.err.println(" --cert </certfile-path>");
- System.err.println();
- System.err.println("NOTE: Options with values may also be specified using the form: --option=value\n");
- System.err.println();
- //@formatter:on
+ printUsage();
return;
}
layout = ghidraLayout; // Save layout for when we need to initialize application
diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java
index b8a5a88a7e..439cf86984 100644
--- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java
+++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java
@@ -930,9 +930,20 @@ public class BSimLaunchable implements GhidraLaunchable {
}
}
+ private static void printMaxMemory() {
+ long maxMemoryBytes = Runtime.getRuntime().maxMemory();
+ long maxMem = maxMemoryBytes >> 20; // MBytes
+ String units = " MBytes";
+ if (maxMem >= 1024) {
+ maxMem >>= 10;
+ units = " GBytes";
+ }
+ System.out.println("Max-Memory: " + maxMem + units);
+ }
+
private static void printUsage() {
//@formatter:off
- System.err.println(
+ System.err.println("\n" +
"USAGE: bsim [command] required-args... [OPTIONS...]\n" +
" createdatabase <bsimURL> <config_template> [--name|-n \"<name>\"] [--owner|-o \"<owner>\"] [--description|-d \"<text>\"] [--nocallgraph]\n" +
" setmetadata <bsimURL> [--name|-n \"<name>\"] [--owner|-o \"<owner>\"] [--description|-d \"<text>\"]\n" +
@@ -978,6 +989,9 @@ public class BSimLaunchable implements GhidraLaunchable {
@Override
public void launch(GhidraApplicationLayout ghidraLayout, String[] params) {
+
+ printMaxMemory();
+
if (params.length == 0) {
printUsage();
return;
diff --git a/Ghidra/RuntimeScripts/Linux/support/bsim b/Ghidra/RuntimeScripts/Linux/support/bsim
index 0254b785bb..a9ff1917e5 100755
--- a/Ghidra/RuntimeScripts/Linux/support/bsim
+++ b/Ghidra/RuntimeScripts/Linux/support/bsim
@@ -2,8 +2,9 @@
#
# Command-line script for interacting with a BSim database
-# maximum heap memory (may be increased)
-MAXMEM=2G
+# Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
+# the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
+#MAXMEM=2G
# launch mode (fg, bg, debug, debug-suspend)
LAUNCH_MODE=fg
@@ -17,4 +18,4 @@ VMARG_LIST="-Djava.awt.headless=true "
SCRIPT_FILE="$(readlink -f "$0" 2>/dev/null || readlink "$0" 2>/dev/null || echo "$0")"
SCRIPT_DIR="${SCRIPT_FILE%/*}"
-${SCRIPT_DIR}/launch.sh $LAUNCH_MODE jdk "BSim" $MAXMEM "" ghidra.features.bsim.query.ingest.BSimLaunchable "$@"
+${SCRIPT_DIR}/launch.sh $LAUNCH_MODE jdk "BSim" "${MAXMEM}" "" ghidra.features.bsim.query.ingest.BSimLaunchable "$@"
diff --git a/Ghidra/RuntimeScripts/Windows/support/bsim.bat b/Ghidra/RuntimeScripts/Windows/support/bsim.bat
index da05434b38..fcc059ca19 100644
--- a/Ghidra/RuntimeScripts/Windows/support/bsim.bat
+++ b/Ghidra/RuntimeScripts/Windows/support/bsim.bat
@@ -3,8 +3,9 @@
@echo off
setlocal
-:: maximum heap memory (may be increased)
-set MAXMEM=2G
+:: Maximum heap memory may be changed if default is inadequate. This will generally be up to 1/4 of
+:: the physical memory available to the OS. Uncomment MAXMEM setting if non-default value is needed.
+::set MAXMEM=2G
:: launch mode (fg, bg, debug, debug-suspend)
set LAUNCH_MODE=fg