# 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
      class name find a Java class from debuggee and print oop
      classes print all loaded Java classes with klassOop
      detach detach SA from current target
      dis address [ length ]  disassemble (sparc/x86) specified number of instructions from given address
      dumpclass { address | name } [ directory ] dump .class file for given klassOop or class name
      dumpheap [ file ] dump heap in hprof binary format
      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
      jdis address show bytecode disassembly of a given methodOop
      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
      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 klassOop, methodOop or arbitrary address
      printas type expression print given address as given HotSpot type. eg. print JavaThread <address>
      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
      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
      threads show all Java threads
      tokenize ...
      type [ type [ name super isOop isInteger isUnsigned size ] ] show info. on HotSpot type
      universe print gc universe
      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