Просмотр исходного кода

Merge pull request #33 from SummerGGift/2018_2_5

 add DEBUG_printf function
朱天龙 (Armink) 8 лет назад
Родитель
Сommit
963ec91d9d
4 измененных файлов с 25 добавлено и 4 удалено
  1. 15 0
      port/mpy_main.c
  2. 6 0
      py/bc.c
  3. 3 3
      py/malloc.c
  4. 1 1
      py/objfun.c

+ 15 - 0
port/mpy_main.c

@@ -136,6 +136,21 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
 }
 #endif
 
+#include <stdarg.h>
+
+int DEBUG_printf(const char *format, ...)
+{
+    static char log_buf[512];
+    va_list args;
+
+    /* args point to the first variable parameter */
+    va_start(args, format);
+    /* must use vprintf to print */
+    rt_vsprintf(log_buf, format, args);
+    rt_kprintf("%s", log_buf);
+    va_end(args);
+}
+
 #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
 #include <finsh.h>
 static void python(uint8_t argc, char **argv) {

+ 6 - 0
py/bc.c

@@ -26,15 +26,21 @@
  */
 
 #include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 
+#include "py/mpconfig.h"
+#include "py/misc.h"
+#include "py/mpstate.h"
 #include "py/runtime.h"
 #include "py/bc0.h"
 #include "py/bc.h"
 
 #if MICROPY_DEBUG_VERBOSE // print debugging info
 #define DEBUG_PRINT (1)
+#define DEBUG_printf DEBUG_printf
 #else // don't print debugging info
 #define DEBUG_PRINT (0)
 #define DEBUG_printf(...) (void)0

+ 3 - 3
py/malloc.c

@@ -144,7 +144,7 @@ void *m_realloc(void *ptr, size_t new_num_bytes) {
     MP_STATE_MEM(current_bytes_allocated) += diff;
     UPDATE_PEAK();
 #endif
-    DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
+    //DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
     return new_ptr;
 }
 
@@ -168,7 +168,7 @@ void *m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move) {
         UPDATE_PEAK();
     }
 #endif
-    DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
+    //DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
     return new_ptr;
 }
 
@@ -181,7 +181,7 @@ void m_free(void *ptr) {
 #if MICROPY_MEM_STATS
     MP_STATE_MEM(current_bytes_allocated) -= num_bytes;
 #endif
-    DEBUG_printf("free %p, %d\n", ptr, num_bytes);
+    //DEBUG_printf("free %p, %d\n", ptr, num_bytes);
 }
 
 #if MICROPY_MEM_STATS

+ 1 - 1
py/objfun.c

@@ -236,7 +236,7 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
     DEBUG_printf("Input kw args: ");
     dump_args(args + n_args, n_kw * 2);
     mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
-    DEBUG_printf("Func n_def_args: %d\n", self->n_def_args);
+    //DEBUG_printf("Func n_def_args: %d\n", self->n_def_args);
 
     // bytecode prelude: state size and exception stack size
     size_t n_state = mp_decode_uint_value(self->bytecode);