2 Replies Latest reply: Apr 7, 2014 4:22 PM by sellis RSS

DS-5 Debugger Print command

wrani Null

Hi,

I'm printing with "print" command from a DS-5 debugger, I'm printing a string, this is what comes back :

 

print ( ((TC_TCB*)$list)->tc_name)

$56 = {83 'S', 67 'C', 72 'H', 69 'E', 68 'D', 84 'T', 83 'S', 0 '\0'}

 

I'd like to see just the string without the ascii code , how can I do it ?

 

Ran

  • Re: DS-5 Debugger Print command
    sellis Employee

    The Expressions view in the graphical debugger will format char arrays as strings in most cases. However, if you want to do this from the command line, then the following python script should do it (I apologise for the terseness, but you can make it prettier if you want):

     

    from arm_ds.debugger_v1 import Debugger
    import sys
    import string
    
    printable = string.ascii_letters + string.digits + string.punctuation + ' '
    
    def intStrToChar(i):
        c = chr(int(i))
        if (c in printable):
            return c
        else:
            return '\\x%02x' % ord(c)
    
    print '"' + "".join([intStrToChar(c) for c in Debugger().getCurrentExecutionContext().executeDSCommand("output /u " + sys.argv[1])[1:-1].split(", ")]) + '"'

     

    Be careful to get the single and double quotes correct there (probably best to cut & paste). So what this is doing is capturing the output of the output command and converting the numeric values back into a string. This also attempts to escape non-printable characters. Save it to a file such as print.py and use it like:

     

    source "/somedir/print.py" foo

     

    Where foo is the name of the variable that you want to print.

    • Re: DS-5 Debugger Print command
      sellis Employee

      This was confirmed as a bug, and actually only occurs when the type of variable being printed is const; plain char arrays do print fine. Thanks for reporting it. This is scheduled for fixing in the DS-5 5.19 release.