BrightScript Debugger

16min
this page serves as a guide for accessing the brightscript debugger of brightsign players the brightscript debugger can be accessed via a physical serial connection or over the network via ssh or telnet for the physical serial connection, certain cables are recommended as described on brightsign shell docid\ fxxyu9jmocutc6xe2p7l2 what is the brightscript debugger? the brightscript debugger is sometimes referred to as the brightscript debug console however, in an effort to maintain consistency and to avoid potential confusion, the term brightscript debugger, or more simply, debugger, is predominantly used the brightscript debugger is a cli which enables interaction with the brightscript interpreter it is denoted by the prompt brightscript debugger> and is a powerful tool for troubleshooting and debugging issues with brightscript scripts or interacting with brightscript objects it is similar to the javascript console in web browsers as well as other popular debuggers (e g , gdb) developers can set stop statements (a breakpoint), step through a brightscript script, and gain access to the current scope or initialized variables if the brightscript debugger has not been enabled, runtime errors will often cause the player to reboot when the brightscript debugger is enabled, runtime errors will cause the brightsignos to stop on the line of the runtime error, allowing a step through of the script since enabling the brightscript debugger will cause the player to hang when runtime errors are encountered, the brightscript debugger should only be used in development environments or debugging situations; it should be disabled for production deployments brightsign console the brightsign console (or more simply, console) enables access to the brightsign shell, brightscript debugger, and logs over the 3 5mm serial port more information about the brightsign console and how to enable it can be found on brightsign shell docid\ fxxyu9jmocutc6xe2p7l2 enabling the debugger the debugger is enabled by writing a registry key to the player’s registry this can be done in several ways as described below from the brightsign shell type the following from the brightsign shell docid\ fxxyu9jmocutc6xe2p7l2 script debug on dws registry tab from the dws registry tab in brightauthor\ connected, submit the following command registry write brightscript debug 1 inclusion with autorun the following lines can be included as part of an autorun brs file reg = createobject("roregistrysection", "brightscript") reg write("debug","1") accessing the debugger when enabled, the debugger is denoted by the prompt brightscript debugger> and is accessible through a serial cable, telnet, or ssh navigate to the debugger through one of the methods described below if you have not enabled the debugger, any interruption to the brightscript interpreter execution will not give access to the debugger instead, the player will reboot to attempt a clean execution during runtime press ctrl c on your keyboard while the player is powered on runtime stop statement if the debugger has been enabled, the player will enter the debugger if a runtime error occurs or a stop statement is encountered while a script is running access at bootup power off the player power on the player and wait 5 15 seconds press and hold the svc button on the player for 15 30 seconds until the brightsign> prompt appears in the serial/telnet/ssh terminal app the brightsign> prompt indicates that you are in the brightsign shell you can now release the svc button if you are using telnet or ssh, you will need to restart the telnet or ssh instance additional methods press ctrl c in your terminal app that is connected to the player remove the microsd card and press either the svc button on the player or ctrl c on your computer if the serial console has been enabled (either temporarily or persistently), starting brightsign application will appear after the player reboots (note that this can take up to 30 seconds) press and hold the svc button until the brightsign> prompt displays if you have removable storage such as a microsd card, eject it reboot the player and press the svc button if you are accessing the player through telnet, you will have to restart the telnet connection after the player reboots using the telnet {{your player ip address}} 23 command place an autorun brs file containing only the word “end” (without the quotes) on the storage device the script will execute and when it ends as instructed you’ll be left at the brightsign> prompt note brightsignos does not register the svc button event if there is no autorun brs on the storage device this will break out of the application running at the moment and redirect to the brightsign prompt debugger commands the following shell commands are currently available in the debugger command description bt print a backtrace of call function context frames classes list all public classes cont or c continue script execution counts list count of brightscript component instances da show disassembly and bytecode for this function down or d move one position down the function context chain exit exit the debug shell gc run the garbage collector and show collection statistics hash print the internal hash table histograms last show the last line that executed methods \<class> list methods provided by specified class methods \<class> \<interface> list methods provided by the specified interface or class list list the current source of the current function ld show line data (source records) next show the next line to execute bsc list all allocated brightscript component instances stats show statistics step or s step one program statement t step one statement and show each executed opcode up or u move one function up the context chain var display local variables and their types/values print or p or ? print variable value or expression brightscript print messages are routed to the brightsignos which is accessible via the primary serial port or telnet/ssh switch between the shell and the debugger from the brightsign> prompt, type script to navigate to the debugger script from the brightscript debugger> prompt, type exit to navigate to the brightsign shell exit telnet and ssh the debugger can be accessed with telnet or ssh more info can be found on brightsign shell docid\ fxxyu9jmocutc6xe2p7l2 debugging brightscript code this section will cover how to debug brightscript code on a brightsign player assuming the debugger has been enabled and is accessible see brightscript docid\ r7xc0 ze4u0br662li2sj for information regarding brightsign’s documentation for brightscript our interpreter forked from roku’s brightscript language many years ago and have since diverged how to debug brightscript to begin stepping through or debugging brightscript code, add a stop statement to the line of code you want to start debugging from a stop statement is a breakpoint in the brightscript code when the brightsign player encounters a stop statement, it will break and enter the brightscript debugger when the debugger is enabled the brightscript debugger is similar to many other debuggers, e g , gdb it allows you to step through the code, inspect variables, and evaluate expressions type help in the debugger to see a list of available commands type vars to see the variables and their values debugging javascript or node js to enable the chrome devtools and add brightsign’s remote inspector, see debugging webpages docid 4qlk1krr1cnx7xypwxry5 go to chrome //inspect adding the ip address of your player on the same network as your computer troubleshooting if you’re encountering difficulties connecting your terminal application to the brightsign player, see the troubleshooting steps outlined on brightsign shell docid\ fxxyu9jmocutc6xe2p7l2