Experimental Version of UBDebug - with String Support

UBDebug is a PC-based IDE for CHDK ubasic scripts that runs under Windows and Mac OSX (10.3 "Panther" or later). It lets you create and edit scripts, then step through them line by line while inspecting and setting variables. You can also set the values to be returned by some CHDK functions (such as get_usb_power) and any property. You can learn more about it here.

However uBASIC as currently supplied with CHDK only support integer variables and expressions (as does Adam Dunkels original uBASIC). I've recently extended the original uBASIC to add string support (see here). The obvious next step is to add this support to the CHDK version. However before trying to add the new code to the trunk, it seems a good idea to let people play with it safely in an upgraded version of UBDebug. That upgraded version is available for downloading below.

Added Features

The values of string variables and the new CHDK-related functions can be inspected and modfied while the script is running.

Sample Program

Supplied Test Program Program Output
s$ = " start of test "
for i = 1 to words(s$)
   print "'" + word(s$, i) + "'"
next i
a$= "abcdefghi"
print "Length of a$=", len(a$)
print "Length of b$=", len(b$)
if len(a$) = len(b$) then print "same length"
if a$ = trim("  abcdefghi  ") then 
  print "same string"
  print "strings differ"
c$=left$(a$+ b$,12)
print "left 12 of a$ + b$=" + c$
c$=right$(a$+b$, 12)
print "right 12 of a$+b$=",  c$
c$=mid$(a$+b$, 8,8)
print "mid 8,8 of a$+b$=", c$
print "str$(13+42)=", c$
print "len(c$)=", len(c$)
print len("this" + "that")
c$ = chr$(54)
print "chr$(54)='" + c$ + "'"
j = asc(c$)
print j
print "val('12345')=",val("12345")
i=instr(3, "123456789", "67")
print "position of '67' in '123456789' is", i
print get_buildinfo
gosub l$
press left$(k$,4)
press right$(k$,4)
print get_lastdirnum
print get_lastfilenum
print get_lastfilename
print "end of test"

   print "in sub1"
starting ...
>>> 'start'
>>> 'of'
>>> 'test'
>>> Length of a$= 9
>>> Length of b$= 9
>>> same length
>>> same string
>>> left 12 of a$ + b$=abcdefghi123
>>> right 12 of a$+b$= ghi123456789
>>> mid 8,8 of a$+b$= hi123456
>>> str$(13+42)= 55
>>> len(c$)= 2
>>> 8
>>> chr$(54)='6'
>>> 54
>>> val('12345')= 12345
>>> position of '67' in '123456789' is 6
>>> a570 100a CHDK 0.7.4
>>> in sub1
*** button press 'left' ***
*** button press 'down' ***
>>> 100
>>> 1
>>> A/DCIM/100CANON/IMG_0001.JPG
>>> end of test
Script has ended!


  1. strings are limited to 255 characters
  2. the string buffer is 4000 bytes long (so you can't have 52 strings each 255 characters long)

These restrictions are trivially easy to amend. Note that operands are checked for errors (out of range etc) and there is a garbage collector, but my testing has not been exhaustive.


Although this is an experimental program, it is a proper superset of the original UBDebug (so any script which worked before should produce the same results). As a result, the names of the class, jar and dll files have not been changed. The zip file contains:

UBDB.jar this contains the five java classes which make up the debugger
ubengine.dll the native methods and ubasic interpreter (Windows version)
libubengine.jnilib the native methods and ubasic interpreter (Mac OSX version - supports both PowerPC and Intel Macs)
stringtest.bas a simple test script

Unzip the files into any convenient directory. To run the debugger simply double-click the .jar file.
Comments, suggestions and bug reports welcome. Dave@zenoshrdlu.com

See here for other KAP and CHDK stuff of mine.