Skip to content

Conversation

@marek-trtik
Copy link

Unfortutatelly, the solution with a single free function
does not work. GCC seams to ignore attributes and throws
the function away. Fortunatelly, it does not ignore
attributes, when given to non-static method, and so
the non-debug build can be as fast as before.

Here is the pretty-printer function for QTCreator:

def qdump__dstringt(d, value):
    try:
        address = address_of_value(value)
        string_no = str(gdb.parse_and_eval("(*((const dstringt*)" + address + ")).no"))
        has_no = str(gdb.parse_and_eval("get_string_container().is_number_valid(" + string_no +")"))
        if has_no == "true":
            raw_string_value = str(gdb.parse_and_eval("get_string_container().get_string_slowly(" + string_no +")"))
            string_value = raw_string_value.replace("\0", "").replace("\"", "\\\"")
            d.putValue(string_no + ": " + string_value)
        else:
            d.putValue(string_no + ": The number is invalid.")
    except Exception as e:
        d.putValue("Exception getting value of dstringt: " + str(e))

@peterschrammel
Copy link
Owner

This should rather go into cbmc/develop directly.

@marek-trtik marek-trtik force-pushed the fixed_pritty_printing_of_strings_in_srting_container branch 3 times, most recently from a7e4bd7 to 9e7ac31 Compare January 28, 2018 13:55
Unfortutatelly, the solution with a single free function
does not work. GCC seams to ignore attributes and throws
the function away. Fortunatelly, it does not ignore
attributes, when given to non-static method, and so
the non-debug build can be as fast as before.

Here is the pretty-printer function for QTCreator:

def qdump__dstringt(d, value):
    try:
        address = address_of_value(value)
        string_no = str(gdb.parse_and_eval("(*((const dstringt*)" + address + ")).no"))
        has_no = str(gdb.parse_and_eval("get_string_container().is_number_valid(" + string_no +")"))
        if has_no == "true":
            raw_string_value = str(gdb.parse_and_eval("get_string_container().get_string_slowly(" + string_no +")"))
            string_value = raw_string_value.replace("\0", "").replace("\"", "\\\"")
            d.putValue(string_no + ": " + string_value)
        else:
            d.putValue(string_no + ": The number is invalid.")
    except Exception as e:
        d.putValue("Exception getting value of dstringt: " + str(e))
@marek-trtik marek-trtik force-pushed the fixed_pritty_printing_of_strings_in_srting_container branch from 9e7ac31 to 3158e3e Compare January 29, 2018 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants