gud jdb follows source files
authorThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Thu, 31 Oct 2024 10:31:20 +0000 (10:31 +0000)
committerThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Thu, 31 Oct 2024 10:31:20 +0000 (10:31 +0000)
16 files changed:
developer/javac/IO.java
developer/javac/Mosaic.java
developer/javac/TestBench.java
developer/javac/Util.java
developer/shell/Mosaic [new file with mode: 0755]
release/Mosaic.jar [new file with mode: 0644]
tester/document/jdb.txt
tester/javac/Test0.java
tester/javac/TestMosaic_0.javax
tester/javac/Test_IO.java
tester/javac/Test_Util.java
tester/jvm/Test_Mosaic.jar
tester/tool/#run_jdb# [deleted file]
tester/tool/run_jdb
tool_shared/bespoke/cat_w_fn
tool_shared/bespoke/emacs.el [new file with mode: 0644]

index 0c80da1..90107e1 100644 (file)
@@ -21,8 +21,8 @@ public class IO{
   private ByteArrayOutputStream out_content;
   private ByteArrayOutputStream err_content;
   private ByteArrayInputStream in_content;
-  private boolean streams_foobar = false;
-  private boolean uninitialized = true;
+  private Boolean streams_foobar = false;
+  private Boolean uninitialized = true;
 
 
   // IO currently has no constructors defined, uses default
@@ -35,7 +35,7 @@ public class IO{
   // functions are used.
   //
   // This is the only method that can set the streams_foobar flag.
-  public boolean redirect(){
+  public Boolean redirect(){
 
     try{
       original_out = System.out;
@@ -95,7 +95,7 @@ public class IO{
     System.setIn(in_content);
   }
 
-  public boolean has_out_content(){
+  public Boolean has_out_content(){
     if(streams_foobar){
       throw new IllegalStateException
         (
@@ -114,7 +114,7 @@ public class IO{
     return out_content.toString();
   }
 
-  public boolean has_err_content(){
+  public Boolean has_err_content(){
     if(streams_foobar){
       throw new IllegalStateException
         (
index 8ab7fe7..aeb992e 100644 (file)
@@ -9,7 +9,7 @@ Mosaic currently does not have shell commands.
 
 public class Mosaic{
 
-  public static boolean test_is_true(){
+  public static Boolean test_is_true(){
     return true;
   }
   
index 83e0e26..8165867 100644 (file)
@@ -23,10 +23,10 @@ public class TestBench{
   private static ByteArrayOutputStream err_content;
   private static InputStream in_content;
 
-  public static boolean method_is_wellformed(Method method) {
-    // Check if the method returns boolean
-    if(!method.getReturnType().equals(boolean.class)){
-      System.out.println("Structural problem: " + method.getName() + " does not return boolean.");
+  public static Boolean method_is_wellformed(Method method) {
+    // Check if the method returns Boolean
+    if(!method.getReturnType().equals(Boolean.class)){
+      System.out.println("Structural problem: " + method.getName() + " does not return Boolean.");
       return false;
     }
 
@@ -50,16 +50,16 @@ public class TestBench{
     return true;
   }
 
-  public static boolean run_test(Object test_suite ,Method method ,IO io){
+  public static Boolean run_test(Object test_suite ,Method method ,IO io){
     String test_name = method.getName();
 
     // Ways a test can fail, these are not generally singularly exclusive.
-    boolean fail_TestBench = false;
-    boolean fail_malformed = false;
-    boolean fail_reported = false;
-    boolean fail_exception = false;
-    boolean fail_extraneous_stdout = false;
-    boolean fail_extraneous_stderr = false;
+    Boolean fail_TestBench = false;
+    Boolean fail_malformed = false;
+    Boolean fail_reported = false;
+    Boolean fail_exception = false;
+    Boolean fail_extraneous_stdout = false;
+    Boolean fail_extraneous_stderr = false;
 
     String exception_string = "";
 
@@ -75,7 +75,7 @@ public class TestBench{
     }
 
     // redirect I/O to an io instance
-    boolean successful_redirect = io.redirect();
+    Boolean successful_redirect = io.redirect();
     if( successful_redirect ){
       io.clear_buffers(); // start each test with nothing on the I/O buffers
     }else{
@@ -122,7 +122,7 @@ public class TestBench{
     }
 
     // return condition
-    boolean test_failed =
+    Boolean test_failed =
       fail_reported 
       || fail_exception 
       || fail_extraneous_stdout
index 1757275..653f626 100644 (file)
@@ -22,20 +22,20 @@ public class Util{
   }
 
   // True when it does a search and finds a true value; otherwise false.
-  public static boolean exists( Object[] elements ){
+  public static Boolean exists( Object[] elements ){
     return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null;
   }
 
   // True when it does a search and does not find a false value; otherwise false.
-  public static boolean all( Object[] elements ){
+  public static Boolean all( Object[] elements ){
     return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null;
   }
 
-  public static void all_set_false(boolean[] conditions){
-    for(boolean condition : conditions) condition = false;
+  public static void all_set_false(Boolean[] conditions){
+    for(Boolean condition : conditions) condition = false;
   }
-  public static void all_set_true(boolean[] conditions){
-    for(boolean condition : conditions) condition = true;
+  public static void all_set_true(Boolean[] conditions){
+    for(Boolean condition : conditions) condition = true;
   }
 
   public static String iso_utc_time(){
diff --git a/developer/shell/Mosaic b/developer/shell/Mosaic
new file mode 100755 (executable)
index 0000000..ba5b241
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+java com.ReasoningTechnology."Mosaic".Mosaic
diff --git a/release/Mosaic.jar b/release/Mosaic.jar
new file mode 100644 (file)
index 0000000..246a225
Binary files /dev/null and b/release/Mosaic.jar differ
index 14cceb2..1ed956a 100644 (file)
@@ -1,45 +1,54 @@
+About `jdb`
 
-1. location 
+1. setting the environment
 
-  jdb  will be in the third_party tools directory:
+  The environment should be set before running the IDE. For example,
+
+  > cd Mosaic
+  > source env_tester
+  > emacs & 
+
+  (I use emacs as my IDE. You might be using a different tool.)
+
+2. location of the executable
+
+  Provided that the project administrator installed it, jdb is located in the
+  third_party tools directory. In the tester environment the variable
+  `JAVA_HOME` should hold the jdb directory path, and this should already
+  be in the `PATH`.  For example:
+
+  > echo $ENV
+  tester/tool/env
+
+  > echo $JAVA_HOME
+  /var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11
 
-  2024-10-27T09:34:37Z[Mosaic_tester]
-  Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§
   > which jdb
   /var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin/jdb
 
-2. IDE and the environment
+3. invocation from a shell command:
 
-  The environment must be set before running the IDE or the IDE will not
-  have access to it.
+     jdb -sourcepath $SOURCEPATH <class_name>
 
-  For example Emacs will be following the PATH as it was when Emacs
-  was invoked, for file completion in the Emacs shell, etc.  Even when
-  the environment is set in a shell running inside of emacs.  
+   The `SOURCEPATH` is assigned a value in `tester/tool/env`.  In some versions
+   of jdb there is no space between `-sourcepath` and the `$SOURCDEPATH`.  
 
-      FYI, the path can be fixed but other environment settings will still be missing.
-      (setenv "PATH" (concat (getenv "PATH") ":<directory>"))
-      (setq exec-path (append exec-path '("<directory")))
+   jdb will read CLASSPATH from the environment. In contrast jdb will not read
+   `SOURCEPATH` from the environment. It must be passed as an argument.
 
-3. command line:
+   There is a `run_jdb` script in the `tool` directory.
 
-   SOURCEPATH must be defined in advance.  There is no space between -source and the
-   source path.  Typically SOURCEPATH will be `javac`.
+4. invocation inside of Emacs
 
-     jdb -sourcepath $SOURCEPATH <class_name>
+   The file `tool_shared/bespoke/emacs.el` holds a definition for the `jdbx`
+   command.  This command will read the SOURCEPATH from the environment and run
+   jdb in Emacs.
 
-     currently, in emacs, e.g.:
-     jdb -sourcepathjavac Test_Util
+   That file also holds the definition for a listener to the jdb `sourcepath`
+   command.
 
-   When invoked from Emacs M-x jdb,  there is no space between the -sourcepath and
-   the $SOURCEPATH.  
 
-   In jdb run from gud-gdb, when packages are used, the SOURCEPATH is the path
-   to the directory that holds a directory tree, where said directory tree
-   parallels the package name. Otherwise it is the directory path to the source
-   directory. Note the `distribute_sources` script.
 
-   When using packages, the <class_name> is fully qualified.
 
 
 
index 40c4ef8..e8a4810 100644 (file)
@@ -9,12 +9,12 @@ Plug it in, see if there is smoke. There usually is.
 
 public class Test0{
 
-  public static boolean test_is_true(){
+  public static Boolean test_is_true(){
     return true;
   }
   
   public static int run(){
-    boolean[] condition = new boolean[1];
+    Boolean[] condition = new Boolean[1];
     condition[0] = test_is_true();
 
     int i = 0;
index 8e1a782..85ab091 100644 (file)
@@ -19,16 +19,16 @@ public class TestTestBench extends TestBench{
     TestSuite(){
     }
 
-    public boolean test_pass(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
+    public Boolean test_pass(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
       return true;
     }
 
-    public boolean test_fail_0(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
+    public Boolean test_fail_0(ByteArrayOutputStream out_content, ByteArrayOutputStream err_content){
       return false;
     }
 
     // Tests if exception uncaught by the test correctly causes a failure from the TestBench.
-    public static boolean test_fail_1() throws Exception {
+    public static Boolean test_fail_1() throws Exception {
       int randomInt = (int) (Math.random() * 100);  // Generate a random integer
       // Always returns true, but Java will not complain that following code is unreachable
       if( 
index d6621fe..7298b1d 100644 (file)
@@ -28,7 +28,7 @@ public class Test_IO{
 
   public static int run(){
     IO io = new IO();
-    boolean[] condition = new boolean[3];
+    Boolean[] condition = new Boolean[3];
 
     // Redirect IO streams
     io.redirect();
index 0d0edba..de046ff 100644 (file)
@@ -7,33 +7,33 @@ Test_Util
 
 public class Test_Util{
 
-  public static boolean test_all(){
+  public static Boolean test_all(){
     // Test with zero conditions
-    boolean[] conditions0 = {};
-    boolean result = !Util.all(conditions0);  // Empty conditions list is false.
+    Boolean[] conditions0 = {};
+    Boolean result = !Util.all(conditions0);  // Empty conditions list is false.
 
     // Test with one condition
-    boolean[] conditions1_true = {true};
-    boolean[] conditions1_false = {false};
+    Boolean[] conditions1_true = {true};
+    Boolean[] conditions1_false = {false};
     result &= Util.all(conditions1_true);    // should return true
     result &= !Util.all(conditions1_false);  // should return false
 
     // Test with two conditions
-    boolean[] conditions2_true = {true, true};
-    boolean[] conditions2_false1 = {true, false};
-    boolean[] conditions2_false2 = {false, true};
-    boolean[] conditions2_false3 = {false, false};
+    Boolean[] conditions2_true = {true, true};
+    Boolean[] conditions2_false1 = {true, false};
+    Boolean[] conditions2_false2 = {false, true};
+    Boolean[] conditions2_false3 = {false, false};
     result &= Util.all(conditions2_true);     // should return true
     result &= !Util.all(conditions2_false1);  // should return false
     result &= !Util.all(conditions2_false2);  // should return false
     result &= !Util.all(conditions2_false3);  // should return false
 
     // Test with three conditions
-    boolean[] conditions3_false1 = {true, true, false};
-    boolean[] conditions3_true = {true, true, true};
-    boolean[] conditions3_false2 = {true, false, true};
-    boolean[] conditions3_false3 = {false, true, true};
-    boolean[] conditions3_false4 = {false, false, false};
+    Boolean[] conditions3_false1 = {true, true, false};
+    Boolean[] conditions3_true = {true, true, true};
+    Boolean[] conditions3_false2 = {true, false, true};
+    Boolean[] conditions3_false3 = {false, true, true};
+    Boolean[] conditions3_false4 = {false, false, false};
     result &= !Util.all(conditions3_false1); // should return false
     result &= Util.all(conditions3_true);    // should return true
     result &= !Util.all(conditions3_false2); // should return false
@@ -43,20 +43,20 @@ public class Test_Util{
     return result;
   }
 
-  public static boolean test_all_set_false(){
-    boolean[] conditions = {true, true, true};
+  public static Boolean test_all_set_false(){
+    Boolean[] conditions = {true, true, true};
     Util.all_set_false(conditions);
     return !Util.all(conditions);  // Should return false after setting all to false
   }
 
-  public static boolean test_all_set_true(){
-    boolean[] conditions = {false, false, false};
+  public static Boolean test_all_set_true(){
+    Boolean[] conditions = {false, false, false};
     Util.all_set_true(conditions);
     return Util.all(conditions);  // Should return true after setting all to true
   }
   
   public static int run(){
-    boolean[] condition = new boolean[3];
+    Boolean[] condition = new Boolean[3];
     condition[0] = test_all();
     condition[1] = test_all_set_false();
     condition[2] = test_all_set_true();
index 5e80583..acdaf46 100644 (file)
Binary files a/tester/jvm/Test_Mosaic.jar and b/tester/jvm/Test_Mosaic.jar differ
diff --git a/tester/tool/#run_jdb# b/tester/tool/#run_jdb#
deleted file mode 100755 (executable)
index 9c472f4..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/env bash
-script_afp=$(realpath "${BASH_SOURCE[0]}")
-
-# input guards
-env_must_be="tester/tool/env"
-if [ "$ENV" != "$env_must_be" ]; then
-  echo "$(script_fp):: error: must be run in the $env_must_be environment"
-  exit 1
-fi
-
-jdb -sourcepath "$SOURCEPATH" "$@"
-
index 65b05c4..9c472f4 100755 (executable)
@@ -9,3 +9,4 @@ if [ "$ENV" != "$env_must_be" ]; then
 fi
 
 jdb -sourcepath "$SOURCEPATH" "$@"
+
index 89166b6..3308525 100755 (executable)
@@ -3,7 +3,7 @@ script_afp=$(realpath "${BASH_SOURCE[0]}")
 
 # Check if at least one file is provided
 if [ $# -eq 0 ]; then
-  echo "Usage: $0 <filename1> [filename2] ..."
+  echo "Usage: $(script_fp) <filename1> [filename2] ..."
   exit 1
 fi
 
diff --git a/tool_shared/bespoke/emacs.el b/tool_shared/bespoke/emacs.el
new file mode 100644 (file)
index 0000000..5ca4331
--- /dev/null
@@ -0,0 +1,52 @@
+
+; The first time Emacs  encounters a link to a source file, Emacs asks if it should follow it.
+; This might suppress that initial question and follow the link.
+; (setq find-file-visit-truename t)
+
+(defun jdbx ()
+  "Set gud-jdb-sourcepath from the environment and run jdb with the correct source path."
+  (interactive)
+  (let* 
+    (
+      (sourcepath (getenv "SOURCEPATH"))
+      )
+    (if 
+      sourcepath
+      (setq gud-jdb-sourcepath (split-string sourcepath ":" t))
+      (message "Warning: SOURCEPATH is not set. `jdb` will run without source path information.")
+      )
+    (let 
+      (
+        (class-name (read-string "Enter the class to debug: " "Test_Util"))
+        )
+      (jdb (concat "jdb -sourcepath"
+             (if 
+               sourcepath 
+               (mapconcat 'identity gud-jdb-sourcepath ":") ""
+               )
+             " "
+             class-name
+             )
+        ))))
+
+(defun monitor-jdb-sourcepath (output)
+  "Monitor the jdb output for `sourcepath ARG` commands and update `gud-jdb-sourcepath` with each path in ARG."
+  (when 
+    (string-match "sourcepath \\(.+\\)" output)
+    (let* 
+      (
+        (new-paths (match-string 1 output))
+        (paths-list (split-string new-paths ":" t))
+        )
+      ;; Add each path in paths-list to gud-jdb-sourcepath if not already present
+      (dolist 
+        (path paths-list)
+        (unless 
+          (member path gud-jdb-sourcepath)
+          (setq gud-jdb-sourcepath (append gud-jdb-sourcepath (list path)))
+          )
+        )
+      (message "Updated gud-jdb-sourcepath: %s" gud-jdb-sourcepath)))
+  output)
+
+(add-hook 'gud-filter-functions 'monitor-jdb-sourcepath)