From b0920c43490255920f651ecc381626b599e0f7b3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 12 Jun 2014 13:34:06 -0400 Subject: [PATCH] conversions.stp: new kernel_string_quoted() function Just like user_string_quoted(), the new kernel_string_quoted() function returns the resulting string in quotes if it successfully retrieved the string and the pointer address otherwise. --- tapset/linux/conversions.stp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tapset/linux/conversions.stp b/tapset/linux/conversions.stp index 8abeb9845..b8ea3473e 100644 --- a/tapset/linux/conversions.stp +++ b/tapset/linux/conversions.stp @@ -43,6 +43,29 @@ function kernel_string2:string (addr:long, err_msg:string) { try { return kernel_string(addr) } catch { return err_msg } } +/** + * sfunction kernel_string_quoted - Retrieves and quotes string from kernel memory + * + * @addr: the kernel memory address to retrieve the string from + * + * Description: Returns the null terminated C string from a given kernel + * memory address where any ASCII characters that are not printable are + * replaced by the corresponding escape sequence in the returned string. Note + * that the string will be surrounded by double quotes. If the kernel memory + * data is not accessible at the given address, the address itself is returned + * as a string, without double quotes. + */ +function kernel_string_quoted:string (addr:long) +%{ /* pure */ /* myproc-unprivileged */ + int rc = 0; + if (STAP_ARG_addr != 0) + rc = _stp_text_str(STAP_RETVALUE, + (char *)(uintptr_t)STAP_ARG_addr, + MAXSTRINGLEN, MAXSTRINGLEN, 1, 0); + if (STAP_ARG_addr == 0 || rc < 0) + snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%p", (void *)(long)STAP_ARG_addr); +%} + /** * sfunction kernel_string_n - Retrieves string of given length from kernel memory * @addr: The kernel address to retrieve the string from -- 2.43.5