Skip to content

Instantly share code, notes, and snippets.

@x746e
Last active May 22, 2023 11:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x746e/66ded1066a310a880f8d to your computer and use it in GitHub Desktop.
Save x746e/66ded1066a310a880f8d to your computer and use it in GitHub Desktop.
# To print a str variable.
x/s ((PyStringObject*)str_var)->ob_sval
define ppstr
printf "%s\n", ((PyStringObject*)$arg0)->ob_sval
end
define ppr
printf "%s\n", ((PyStringObject*)PyObject_Repr($arg0))->ob_sval
end
# Print whole string.
printf "%s\n", str_var
# Print dict.
printf "%s\n", ((PyStringObject*)dict_repr((PyDictObject*)dict_var))->ob_sval
# Print dict's keys
printf "%s\n", ((PyStringObject*)list_repr((PyListObject*)((PyListObject*)PyDict_Keys((PyDictObject*)dict_var))))->ob_sval
# Print list.
printf "%s\n", ((PyStringObject*)list_repr((PyListObject*)list_var))->ob_sval
# Contents of a module (module dict)
printf "%s\n", ((PyStringObject*)dict_repr((PyDictObject*)(((PyModuleObject*)module)->md_dict)))->ob_sval
# Variable names in a module (module dict's keys)
printf "%s\n", ((PyStringObject*)list_repr((PyListObject*)((PyListObject*)PyDict_Keys((PyDictObject*)(((PyModuleObject*)module)->md_dict)))))->ob_sval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment