diff mbox series

[v1,1/5] linux-user: convert target_mprotect debug to tracepoint

Message ID 20191128194603.24818-2-alex.bennee@linaro.org
State New
Headers show
Series linux-user mmap debug cleanup | expand

Commit Message

Alex Bennée Nov. 28, 2019, 7:45 p.m. UTC
It is a pain to re-compile when you need to debug and tracepoints are
a fairly low impact way to instrument QEMU.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 linux-user/mmap.c       | 17 +++++++++--------
 linux-user/trace-events |  3 +++
 2 files changed, 12 insertions(+), 8 deletions(-)

-- 
2.20.1

Comments

Richard Henderson Dec. 2, 2019, 1:04 a.m. UTC | #1
On 11/28/19 7:45 PM, Alex Bennée wrote:
> -#ifdef DEBUG_MMAP

> -    printf("mprotect: start=0x" TARGET_ABI_FMT_lx

> -           "len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c\n", start, len,

> -           prot & PROT_READ ? 'r' : '-',

> -           prot & PROT_WRITE ? 'w' : '-',

> -           prot & PROT_EXEC ? 'x' : '-');

> -#endif

> +    if (TRACE_TARGET_MPROTECT_ENABLED) {

> +        char prot_str[4];

> +        prot_str[0] = prot & PROT_READ ? 'r' : '-';

> +        prot_str[1] = prot & PROT_WRITE ? 'w' : '-';

> +        prot_str[2] = prot & PROT_EXEC ? 'x' : '-';

> +        prot_str[3] = 0;

> +        trace_target_mprotect(start, len, prot_str);

> +    }


There are other bits in prot other than these 3.
See especially my linux-user BTI patch set, and
know that the same sort of thing will be in the
as-yet undecided abi for the MTE extension.

Unless you have a good reason otherwise, I think
we should just print the numeric value in hex.


r~
diff mbox series

Patch

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 46a6e3a761a..66868762519 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -17,7 +17,7 @@ 
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-
+#include "trace.h"
 #include "qemu.h"
 
 //#define DEBUG_MMAP
@@ -66,13 +66,14 @@  int target_mprotect(abi_ulong start, abi_ulong len, int prot)
     abi_ulong end, host_start, host_end, addr;
     int prot1, ret;
 
-#ifdef DEBUG_MMAP
-    printf("mprotect: start=0x" TARGET_ABI_FMT_lx
-           "len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c\n", start, len,
-           prot & PROT_READ ? 'r' : '-',
-           prot & PROT_WRITE ? 'w' : '-',
-           prot & PROT_EXEC ? 'x' : '-');
-#endif
+    if (TRACE_TARGET_MPROTECT_ENABLED) {
+        char prot_str[4];
+        prot_str[0] = prot & PROT_READ ? 'r' : '-';
+        prot_str[1] = prot & PROT_WRITE ? 'w' : '-';
+        prot_str[2] = prot & PROT_EXEC ? 'x' : '-';
+        prot_str[3] = 0;
+        trace_target_mprotect(start, len, prot_str);
+    }
 
     if ((start & ~TARGET_PAGE_MASK) != 0)
         return -TARGET_EINVAL;
diff --git a/linux-user/trace-events b/linux-user/trace-events
index 6df234bbb67..41d72e61abb 100644
--- a/linux-user/trace-events
+++ b/linux-user/trace-events
@@ -11,3 +11,6 @@  user_handle_signal(void *env, int target_sig) "env=%p signal %d"
 user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d (target %d("
 user_queue_signal(void *env, int target_sig) "env=%p signal %d"
 user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_addr) "env=%p frame psw.addr 0x%"PRIx64 " current psw.addr 0x%"PRIx64
+
+# mmap.c
+target_mprotect(uint64_t start, uint64_t len, char *flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=%s"