# Command line HSDB

When debugging remote core dumps it is easier to work with command line tools instead of GUI tools. Command line HSDB (CLHSDB) tool is alternative to SA GUI tool HSDB.

There is also JavaScript based SA command line interface called jsdb. But, CLHSDB supports Unix shell-like (or dbx/gdb-like) command line interface with support for output redirection/appending (familiar >, >>), command history and so on. Each CLHSDB command can have zero or more arguments and optionally end with output redirection (or append) to a file. Commands may be stored in a file and run using source command. help command prints usage message for all supported commands (or a specific command)

### Shell/batch scripts to run command line HSDB

- clhsdbproc.sh
- clhsdbproc64.sh
- clhsdbwindbg.bat
- clhsdbwindbg64.bat

### Annotated output of CLHSDB help command

    Available commands:
      assert true | false turn on/off asserts in SA code
      attach pid | exec core  attach SA to a process or core
      buildreplayjars [all | boot | app] build jars for replay, boot.jar for bootclasses, app.jar for application classes
      class name find a Java class from debuggee and print oop
      classes print all loaded Java classes with Klass*
      detach detach SA from current target
      dis address [ length ]  disassemble (sparc/x86) specified number of instructions from given address
      dissemble address disassemble nmethod
      dumpcfg -a | id Dump the PhaseCFG for every compiler thread that has one live
      dumpclass { address | name } [ directory ] dump .class file for given Klass* or class name
      dumpcodecache dump codecache contents
      dumpheap [ file ] dump heap in hprof binary format
      dumpideal -a | id dump ideal graph like debug flag -XX:+PrintIdeal
      dumpilt -a | id dump inline tree for C2 compilation
      dumpreplaydata <address> | -a | <thread_id> [>replay.txt] dump replay data into a file
      echo [ true | false ] turn on/off command echo mode
      examine [ address/count ] | [ address,address] show contents of memory from given address
      field [ type [ name fieldtype isStatic offset address ] ] print info about a field of HotSpot type
      findpc address print info. about pointer location
      flags [ flag ] show all -XX flag name value pairs. or just show given flag
      help [ command ] print help message for all commands or just given command
      history show command history. usual !command-number syntax works.
      inspect expression inspect a given oop
      intConstant [ name [ value ] ] print out hotspot integer constant(s)
      jdis address show bytecode disassembly of a given Method*
      jhisto show Java heap histogram
      jseval script evaluate a given string as JavaScript code
      jsload file load and evaluate a JavaScript file
      jstack [-v] show Java stack trace of all Java threads. -v is verbose mode
      livenmethods show all live nmethods
      longConstant [ name [ value ] ] print out hotspot long constant(s)s
      mem address [ length ] show contents of memory -- also shows closest ELF/COFF symbol if found
      pmap show Solaris pmap-like output
      print expression print given Klass*, Method* or arbitrary address
      printas type expression print given address as given HotSpot type. eg. print JavaThread <address>
      printmdo -a | expression print method data oop
      printstatics [ type ] print static fields of given HotSpot type (or all types if none specified)
      pstack [-v] show mixed mode stack trace for all Java, non-Java threads. -v is verbose mode
      quit quit CLHSDB tool
      reattach detach and re-attach SA to current target
      revptrs  find liveness of oops
      scanoops start end [ type ] scan a Oop from given start to end address
      search [ heap | codecache | threads ] value search a value in heap or codecache or threads
      source filename load and execute CLHSDB commands from given file
      symbol name show address of a given ELF/COFF symbol
      sysprops show all Java System properties
      thread id show thread of id
      threads show all Java threads
      tokenize ...
      type [ type [ name super isOop isInteger isUnsigned size ] ] show info. on HotSpot type
      universe print gc universe
      vmstructsdump dump hotspot type library in text
      verbose true | false turn on/off verbose mode
      versioncheck [ true | false ] turn on/off debuggee VM version check
      whatis address print info about any arbitrary address
      where { -a | id } print Java stack trace of given Java thread or all Java threads (-a)

### JavaScript integration

Few CLHSDB commands are already implemented in JavaScript. It is possible to extend CLHSDB command set by implementing more commands in a JavaScript file and by loading it by jsload command. jseval command may be used to evaluate arbitrary JavaScript expression from a string. Any JavaScript function may be exposed as a CLHSDB command by registering it using JavaScript `registerCommand` function. This function accepts command name, usage and name of the JavaScript implementation function as arguments.

### Simple CLHSDB command implemented in JavaScript

File: test.js

    function helloImpl(name) {
        println("hello, " + name);
    }

    // register the above JavaScript function as CLHSDB command
    registerCommand("hello", "hello name", "helloImpl");

---------
"test.js" can be loaded in CLHSDB prompt using jsload command using

    hsdb> jsload test.js

### Compilation Replay

When a java process crashes in compiled method, usually a core file is saved. The replay function can reproduce the compiling process in the core. cireplay.html