Welcome to MSDN Blogs Sign in | Join | Help

Syndication

Debugging your Agent

Depending on the complexity of your Agent, you might want to add debug code right of the bat. That makes it easier (and less painful) to find issues you will come across. Look for examples further down the post.

 How to debug your Agent:

 

Syntax: break [file:]line

Example: In the SDK, type “!break Numbers.pkg:291” (this will set a break point in the package “Numbers” at line 291)

 

Once you set a break point, enter a query that you want to investigate further. Eventually you will hit the break point you set and you can now dig in by using the debugging commands listed below.

 

While in debug mode, type “help” to see a list of possible commands:

 

Debugger static commands:

 

break [file:]line: sets a breakpoint

show breakpoints:  lists the breakpoint

show files: lists the different files that are loaded

delete number: delete a breakpoint

delete all: delete all breakpoints

show global vars: lists all the global vars

print or p expr: evaluates the expression

start: the next execution will stop at the first instruction

debugger on|off: turns on or off the debugger

 

 

Debugger execution commands:

 

continue or c: continue the execution

next or n: continue to the next line

step or s: continue to the next command, entering procedure or function

step out or so: continue until outside the routine, procedure or function

backtrace or bt: lists the call stack

up: goes up in the call stack

down or do: goes down in the call stack

frame or f number: goes to a given frame in the call stack

show vars: lists all the local vars at the current frame

quit or q: terminates the execution

 

 

Note: !d [debug_level]  // Displays/changes the debug level

 

 

How to add debug code to your Agent:

 

// Debug code to place in a .pkg file.

variable G_PROJECT_NAME_DEBUG_MODE

procedure TurnDebugMyProjectOnOff(ON_OFF)

  G_PROJECT_NAME_DEBUG_MODE = ON_OFF

  if ON_OFF

    - Debug mode turned on!

  else

    - Debug mode turned off!

 

procedure DisplayIfDebugMode(DISPLAY)

  call IncreasePresentationMaxLengthIfDebugMode()

  if G_PROJECT_NAME_DEBUG_MODE

    - DISPLAY

 

 

// Debug code to place in a .ddl file. This is to turn debug mode on/off in your project.

+ _debug_my_project ON_OFF=Anything {MACRO_PROTECTED_MATCHING} // i.e. type “_debug_my_project true” to activate debug mode.

  call TurnDebugMyProjectOnOff(ON_OFF)

 

 

If you have a lot of different domains in your Agent that interact with each other (i.e. weather, location, etc.), then it might make sense to split up the debug code accordingly. Create some per feature, i.e. procedure DisplayIfWeatherDebugMode(DISPLAY) and procedure DisplayIfLocationDebugMode(DISPLAY), etc.

 

Now, place your new procedure(s) wherever you want to display debug information throughout your code. For example:

 

function GetWeatherChangeForInitiative(WEATHER_OBJ, PRECIP, TEMP)

  call DisplayIfWeatherDebugMode(GuessWeatherLocationObject())

  CHANGE_MUCH_HIGHER_DATE = ()

  CHANGE_MUCH_LESS_DATE   = ()

  WEATHER_OBJ_KEYS        = Keys(WEATHER_OBJ)

  DAYS_W_NO_CHANGE_AHEAD  = 0

  //

  for value DATE in WEATHER_OBJ_KEYS

    if PRECIP

      CHANGE_TO_CHECK = GetWeatherObject_ForecastChangePrecipitation(WEATHER_OBJ, DATE)

    if TEMP

      CHANGE_TO_CHECK = GetWeatherObject_ForecastChangeTemperature(WEATHER_OBJ, DATE)

    call DisplayIfWeatherDebugMode(StringConcat("Condition to check: ", CHANGE_TO_CHECK))

    //much higher

    if CHANGE_TO_CHECK eq "MACRO_WEATHER_PATTERN_CHANGE_MUCH_HIGHER"

      insert last in CHANGE_MUCH_HIGHER_DATE DATE

      call DisplayIfWeatherDebugMode(StringConcat("Much higher on: ", DATE))

      break

    //much less

    if CHANGE_TO_CHECK eq "MACRO_WEATHER_PATTERN_CHANGE_MUCH_LESS"

      insert last in CHANGE_MUCH_LESS_DATE DATE

      call DisplayIfWeatherDebugMode(StringConcat("Much less on: ", DATE))

      break

    //no change

    if CHANGE_TO_CHECK eq "MACRO_WEATHER_PATTERN_CHANGE_NO_CHANGE"

      DAYS_W_NO_CHANGE_AHEAD++

      call DisplayIfWeatherDebugMode(StringConcat("Days without change: ", DAYS_W_NO_CHANGE_AHEAD))

  //

  // ...

 

 

Happy debugging! ;)

 

------------------------------------------

Blog post contributor(s): Mirco 

Published Wednesday, August 27, 2008 10:53 PM by imiluk

Filed under:

Comments

# a-foton » Debugging your Agent @ Wednesday, August 27, 2008 6:06 PM

PingBack from http://blog.a-foton.ru/2008/08/debugging-your-agent/

a-foton » Debugging your Agent

Anonymous comments are disabled
Page view tracker