diff options
author | Noah Eisen <ncteisen@gmail.com> | 2017-04-19 16:00:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-19 16:00:46 -0700 |
commit | 8d7efef6df25355cb105683ee52ea0dd21dbe731 (patch) | |
tree | 92fff705f1eefc252ccfffc1711e77e27f0a2c5d /src/core/lib | |
parent | feaee850bf82251f3797749f9b2ef4580b1ba002 (diff) | |
parent | f88ee4f8c5139e12845c4fef7533b1111d48a15c (diff) |
Merge pull request #10691 from ncteisen/error-refcount
Fix error refcount debug logging
Diffstat (limited to 'src/core/lib')
-rw-r--r-- | src/core/lib/iomgr/error.c | 15 | ||||
-rw-r--r-- | src/core/lib/iomgr/error.h | 26 |
2 files changed, 24 insertions, 17 deletions
diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index fbbca6b493..5f2c989aad 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -217,8 +217,14 @@ static uint8_t get_placement(grpc_error **err, size_t size) { if ((*err)->arena_size + slots > (*err)->arena_capacity) { return UINT8_MAX; } +#ifdef GRPC_ERROR_REFCOUNT_DEBUG + grpc_error *orig = *err; +#endif *err = gpr_realloc( *err, sizeof(grpc_error) + (*err)->arena_capacity * sizeof(intptr_t)); +#ifdef GRPC_ERROR_REFCOUNT_DEBUG + if (*err != orig) gpr_log(GPR_DEBUG, "realloc %p -> %p", orig, *err); +#endif } uint8_t placement = (*err)->arena_size; (*err)->arena_size = (uint8_t)((*err)->arena_size + slots); @@ -313,7 +319,7 @@ static void internal_add_error(grpc_error **err, grpc_error *new) { // It is very common to include and extra int and string in an error #define SURPLUS_CAPACITY (2 * SLOTS_PER_INT + SLOTS_PER_TIME) -grpc_error *grpc_error_create(grpc_slice file, int line, grpc_slice desc, +grpc_error *grpc_error_create(const char *file, int line, grpc_slice desc, grpc_error **referencing, size_t num_referencing) { GPR_TIMER_BEGIN("grpc_error_create", 0); @@ -339,7 +345,8 @@ grpc_error *grpc_error_create(grpc_slice file, int line, grpc_slice desc, memset(err->times, UINT8_MAX, GRPC_ERROR_TIME_MAX); internal_set_int(&err, GRPC_ERROR_INT_FILE_LINE, line); - internal_set_str(&err, GRPC_ERROR_STR_FILE, file); + internal_set_str(&err, GRPC_ERROR_STR_FILE, + grpc_slice_from_static_string(file)); internal_set_str(&err, GRPC_ERROR_STR_DESCRIPTION, desc); for (size_t i = 0; i < num_referencing; ++i) { @@ -756,7 +763,7 @@ grpc_error *grpc_os_error(const char *file, int line, int err, return grpc_error_set_str( grpc_error_set_str( grpc_error_set_int( - grpc_error_create(grpc_slice_from_static_string(file), line, + grpc_error_create(file, line, grpc_slice_from_static_string("OS Error"), NULL, 0), GRPC_ERROR_INT_ERRNO, err), @@ -772,7 +779,7 @@ grpc_error *grpc_wsa_error(const char *file, int line, int err, grpc_error *error = grpc_error_set_str( grpc_error_set_str( grpc_error_set_int( - grpc_error_create(grpc_slice_from_static_string(file), line, + grpc_error_create(file, line, grpc_slice_from_static_string("OS Error"), NULL, 0), GRPC_ERROR_INT_WSA_ERROR, err), diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 2a44fcfe25..34b24d9263 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -138,7 +138,7 @@ typedef enum { const char *grpc_error_string(grpc_error *error); /// Create an error - but use GRPC_ERROR_CREATE instead -grpc_error *grpc_error_create(grpc_slice file, int line, grpc_slice desc, +grpc_error *grpc_error_create(const char *file, int line, grpc_slice desc, grpc_error **referencing, size_t num_referencing); /// Create an error (this is the preferred way of generating an error that is /// not due to a system call - for system calls, use GRPC_OS_ERROR or @@ -148,21 +148,21 @@ grpc_error *grpc_error_create(grpc_slice file, int line, grpc_slice desc, /// err = grpc_error_create(x, y, z, r, nr) is equivalent to: /// err = grpc_error_create(x, y, z, NULL, 0); /// for (i=0; i<nr; i++) err = grpc_error_add_child(err, r[i]); -#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc) \ - grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \ - grpc_slice_from_static_string(desc), NULL, 0) -#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \ - grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \ - grpc_slice_from_copied_string(desc), NULL, 0) +#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc) \ + grpc_error_create(__FILE__, __LINE__, grpc_slice_from_static_string(desc), \ + NULL, 0) +#define GRPC_ERROR_CREATE_FROM_COPIED_STRING(desc) \ + grpc_error_create(__FILE__, __LINE__, grpc_slice_from_copied_string(desc), \ + NULL, 0) // Create an error that references some other errors. This function adds a // reference to each error in errs - it does not consume an existing reference -#define GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(desc, errs, count) \ - grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \ - grpc_slice_from_static_string(desc), errs, count) -#define GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(desc, errs, count) \ - grpc_error_create(grpc_slice_from_static_string(__FILE__), __LINE__, \ - grpc_slice_from_copied_string(desc), errs, count) +#define GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(desc, errs, count) \ + grpc_error_create(__FILE__, __LINE__, grpc_slice_from_static_string(desc), \ + errs, count) +#define GRPC_ERROR_CREATE_REFERENCING_FROM_COPIED_STRING(desc, errs, count) \ + grpc_error_create(__FILE__, __LINE__, grpc_slice_from_copied_string(desc), \ + errs, count) //#define GRPC_ERROR_REFCOUNT_DEBUG #ifdef GRPC_ERROR_REFCOUNT_DEBUG |