-- _debug_.e
-- debug controls
-- _debug_.e
-- debug controls
Following global constants are defined:
to be used with display_message(): makes a warning appear
to be used with display_message(): makes an error message appear
Following global procedures are defined:
displays a given message as an information, a warning or an error message according to the type provided
Params:message to display
kind of message to display:
either WARNING_MSG, ERROR_MSG are whatever else
if given type is WARNING_MSG, displays a warning
if given type is ERROR_MSG, displays an error message
if given type is anything else, displays an information message
On Windows, message is displayed in a message_box.
On Linux, message is displayed on stderr
display_message("Information", 0)
display_message("Warning", WARNING_MSG)
display_message("Error", ERROR_MSG)
error_message()
dumps a sequence in hex form to the specified output
Params:sequence to dump in hex form
output stream
global integer with_debug has to be set to get a result
hex_dump("0123456789ABCDEF"&0&1&2&3&4, 1)
Addr 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0000 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 0123456789ABCDEF
0001 00 01 02 03 04 .....
dumps an object in a hierarchical structure
Params:object to dump in a tree view. Nested sequences are allowed.
name to display at the root of the tree view
sequence of pairs {name, value}
optional "output" defines the output stream: defaults to 1
* {"output", 1} displays on the screen
* {"output", f_debug} prints in the debug file if open
optional "detailed" specifies if strings have to be displayed as an array of integers: defaults to 0
optional "translator" defines a conversion routine ID to replace item position numbers by position names: defaults to -1 (none)
* see example
elements of the sequence are displayed in a tree view with numbered items
item numbers can be replaced by strings if a conversion routine is provided
global integer with_debug has to be set to get a result
example of a conversion routine:
function identifyInstruction(sequence path, integer level, integer n, object x)
printf(f_debug, " path: '%s', level: %d, n: %d, x: %s\n", {path, level, n, object_dump(x)})
if level = 1 then
if n = 1 then return "TARGET_DEVICE"
elsif n = 2 then return "OPERATION"
elsif n = 3 then return "INSTRUCTIONS"
elsif n = 4 then return "FILTER"
end if
elsif (level = 2) and ends("[4]", path) then
if n = 1 then return "FROM"
elsif n = 2 then return "TO"
end if
end if
return sprintf("%d",n)
end function
integer rtn_ident_instr
rtn_ident_instr = routine_id("identifyInstruction")
analyze_object(endCommands, "endCommands", {{"output", 1},{"translator", rtn_ident_instr}})
would display
endCommands =
. [1]
. . [TARGET_DEVICE] 1
. . [OPERATION] ""
. . [INSTRUCTIONS] "term len 0"
. . [FILTER] 0
. [2]
. . [TARGET_DEVICE] 1
. . [OPERATION] ""
. . [INSTRUCTIONS] "sh run"
. . [FILTER]
. . . [FROM] "interface 0"
. . . [TO] "exit"
whereas
analyze_object(endCommands, "endCommands", {{"output", 1}})
would display
endCommands =
. [1]
. . [1] 1
. . [2] ""
. . [3] "term len 0"
. . [4] 0
. [2]
. . [1] 1
. . [2] ""
. . [3] "debug cwmp"
. . [4]
. . . [1] "interface 0"
. . . [2] "exit"
Following global functions are defined:
prefixes the given message by date and time for logging purposes
Params:string to prefix
sequence: given string prefixed by date and time
replaces non-printable characters in a string
Params:object to display, either an atom, an integer or a string
special characters are displayed within square brackets: [lf], [cr], [tab], ...
other non-printable characters are replaced by a dot.
sequence: a readable string
puts(1, show_printable("One\tTwo\r\n" & 253 & "abc") would display
"One[tab]Two[cr][lf].abc"
prints an object structure in a human readable way as one string
Params:object to dump
s = object_dump({12, "error", 36.8})
s takes value {12, 'error', 36.8}
s = object_dump({{1}}&"message"&10&"and"&{{8,2},4}&233)
s takes value {{1},109,101,115,115,97,103,101,10,97,110,100,{8,2},4,233} '{}message[lf]and{}.Ú'