Changeset 33729 for main/trunk


Ignore:
Timestamp:
2019-11-29T22:27:25+13:00 (4 years ago)
Author:
ak19
Message:

Fixes to variants of debug function printCaller().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r33724 r33729  
    140140     */
    141141    static public void printCaller() {
    142     int parent = 1;
     142    //int parent = 1;
    143143    // this function printCaller() itself adds another layer on the callstack since
    144144    // it calls the overloaded method, so need to add 1 more to parent
    145     printCaller(parent++);
     145    //printCaller(parent++);
     146   
     147    StackTraceElement[] callstack = Thread.currentThread().getStackTrace();
     148    StackTraceElement requestor = callstack[2]; // the calling function, the function that called this one
     149    if(callstack.length > 3) {
     150        StackTraceElement caller_requested = callstack[3]; // the function requested
     151        System.err.println("\n@@@ Function " + requestor +  " called by:\n    "
     152                   + caller_requested + " at 1 ancestors back\n");
     153    } else {
     154        StackTraceElement caller_requested = callstack[callstack.length-1]; // the function requested
     155        System.err.println("\n@@@ Don't have callers beyond requestor function " + requestor + "\n");
     156    }
    146157    }
    147158   
     
    159170    StackTraceElement[] callstack = Thread.currentThread().getStackTrace();
    160171    StackTraceElement requestor = callstack[2]; // the calling function, the function that called this one
    161     StackTraceElement caller_requested = callstack[ancestor+3]; // the function requested
    162     System.err.println("@@@ Function " + requestor +  " called by:\n    "
    163                + caller_requested + " at " + ancestor + " ancestors back");
     172    if(callstack.length > (ancestor+3)) {
     173        StackTraceElement caller_requested = callstack[ancestor+3]; // the function requested
     174        System.err.println("\n@@@ Function " + requestor +  " called by:\n    "
     175                   + caller_requested + " at " + ancestor + " ancestors back\n");
     176    } else {
     177        StackTraceElement caller_requested = callstack[callstack.length-1]; // the function requested
     178        System.err.println("\n@@@ Don't have " + ancestor +  " ancestor callers. Function " + requestor +  " called by:\n    "
     179                   + caller_requested + " at max " + (callstack.length-1) + " ancestors back\n");
     180    }
    164181    }
    165182   
Note: See TracChangeset for help on using the changeset viewer.