Add printx to userspace (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 22 Nov 2017 16:15:11 +0000 (11:15 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 22 Nov 2017 16:49:34 +0000 (11:49 -0500)
Userspace now has printx (to stderr) and trace_printx (to dmesg).  We also
have all the variants of I_AM_HERE (_x, _t, _tx).

Reinstall your kernel headers.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/ros/procdata.h
kern/src/monitor.c
user/parlib/include/parlib/ros_debug.h
user/parlib/include/parlib/stdio.h

index 12278c6..1480e7c 100644 (file)
@@ -19,7 +19,7 @@ typedef struct procdata {
        syscall_sring_t                 *syscallring;
        sysevent_sring_t                syseventring;
        char                                    pad2[SYSEVENTRINGSIZE - sizeof(sysevent_sring_t)];
-       bool                                    padb;
+       bool                                    printx_on;
        uint8_t                                 pad8;
        uint16_t                                pad16;
        uint32_t                                pad32;
index 1ba0c93..ffa2373 100644 (file)
@@ -1171,8 +1171,23 @@ int mon_db(int argc, char **argv, struct hw_trapframe *hw_tf)
 
 int mon_px(int argc, char **argv, struct hw_trapframe *hw_tf)
 {
-       set_printx(2);
-       printk("Printxing is now %sabled\n", printx_on ? "en" : "dis");
+       pid_t pid = 0;
+       struct proc *p;
+
+       if (argc == 2)
+               pid = strtol(argv[1], 0, 0);
+       if (!pid) {
+               set_printx(2);
+               printk("Printxing is now %sabled\n", printx_on ? "en" : "dis");
+               return 0;
+       }
+       p = pid2proc(pid);
+       if (!p) {
+               printk("No proc with pid %d\n", pid);
+               return 1;
+       }
+       p->procdata->printx_on = !p->procdata->printx_on;
+       proc_decref(p);
        return 0;
 }
 
index f86b999..c53e1c6 100644 (file)
@@ -6,8 +6,6 @@
 
 __BEGIN_DECLS
 
-void trace_printf(const char *fmt, ...);
-
 /* For a poor-mans function tracer (can add these with spatch) */
 void __print_func_entry(const char *func, const char *file);
 void __print_func_exit(const char *func, const char *file);
index 4b9467f..7c37351 100644 (file)
@@ -107,11 +107,36 @@ static inline bool __safe_to_printf(void)
        __parlib_safe_print_ret;                                                   \
 })
 
+#define debug_fprintf(f, ...) __vc_ctx_fprintf(f, __VA_ARGS__)
+#define debug_printf(...) __vc_ctx_fprintf(stdout, __VA_ARGS__)
+
+#define printx(...)                                                            \
+do {                                                                           \
+       if (__procdata.printx_on)                                                  \
+               debug_fprintf(stderr, __VA_ARGS__);                                    \
+} while (0);
+
+void trace_printf(const char *fmt, ...);
+
+#define trace_printx(...)                                                      \
+do {                                                                           \
+       if (__procdata.printx_on)                                                  \
+               trace_printf(__VA_ARGS__);                                             \
+} while (0);
+
 #define I_AM_HERE __vc_ctx_fprintf(stderr,                                     \
                                    "PID %d, vcore %d is in %s() at %s:%d\n",   \
                                    getpid(), vcore_id(), __FUNCTION__,         \
                                    __FILE__, __LINE__)
-#define debug_fprintf(f, ...) __vc_ctx_fprintf(f, __VA_ARGS__)
-#define debug_printf(...) __vc_ctx_fprintf(stdout, __VA_ARGS__)
+
+#define I_AM_HERE_x printx(stderr, "PID %d, vcore %d is in %s() at %s:%d\n",   \
+                                   getpid(), vcore_id(), __FUNCTION__,         \
+                                   __FILE__, __LINE__)
+
+#define I_AM_HERE_t trace_printf("Vcore %d is in %s() at %s:%d\n", vcore_id(), \
+                                 __FUNCTION__, __FILE__, __LINE__)
+
+#define I_AM_HERE_tx trace_printx("Vcore %d is in %s() at %s:%d\n", vcore_id(),\
+                                  __FUNCTION__, __FILE__, __LINE__)
 
 __END_DECLS